Skip to content

Commit f94d717

Browse files
committed
Auto add feature simulator to contract
1 parent b734e60 commit f94d717

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

add-debugger/src/contract-lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#![cfg_attr(not(feature = "simulator"), no_std)]
22

33
// This file will be automatically placed in the contract file, and rename to lib.rs
4-
// TODO
5-
// Need to export main function.
6-
// At the same time, you need to add a feature to the contract's Cargo.toml.
7-
// simulator = ["ckb-std/simulator"]
84

95
// #[cfg(feature = "simulator")]
106
// pub mod entry;

workspace/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ generate:
110110
fi; \
111111
sed '/@@INSERTION_POINT@@/s/$$/\n "$(DESTINATION)\/$(CRATE)",/' Cargo.toml > Cargo.toml.new; \
112112
mv Cargo.toml.new Cargo.toml; \
113-
fi
113+
fi; \
114+
if [ "$(ALSO_ADD_DEBUGGER)" = "true" ]; then \
115+
make -C ./ add-debugger; \
116+
fi;
114117

115118
add-debugger:
116119
@set -eu; \

workspace/scripts/add-debugger

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,11 @@ cd contracts/$CONTRACT_NAME
5656
cargo generate $2 $3 add-debugger -n $CONTRACT_NAME-dbg -d contract_name=$CONTRACT_NAME -d contract_crate_name=$CONTRACT_CRATE
5757
mv $CONTRACT_NAME-dbg/src/contract-lib.rs src/lib.rs
5858
echo "Finally, you need to add a feature to the contract's Cargo.toml:"
59-
echo "simulator = ["ckb-std/simulator"]"
59+
echo "simulator = ["ckb-std/simulator"]"
60+
61+
FILE="Cargo.toml"
62+
if grep -q "\[features\]" "$FILE"; then
63+
sed -i '/\[features\]/a\simulator = ["ckb-std/simulator"]' "$FILE"
64+
else
65+
echo -e "\n[features]\nsimulator = [\"ckb-std/simulator\"]" >> "$FILE"
66+
fi

0 commit comments

Comments
 (0)