@@ -14,7 +14,7 @@ if [ "$CONTRACT_NAME" = "_" ]; then
14
14
contracts=()
15
15
for i in " ${! folders[@]} " ; do
16
16
contract_name=$( echo " ${folders[$i]} " | awk -F' /' ' {print $(NF-1)}' )
17
- if [ ! -d " ${folders[$i]} /${contract_name} -dbg " ]; then
17
+ if [ ! -d " ${folders[$i]} /${contract_name} -sim " ]; then
18
18
contracts+=(" ${contract_name} " )
19
19
fi
20
20
done
@@ -54,15 +54,22 @@ SIMULATOR_NAME=${CONTRACT_NAME}-sim
54
54
cargo generate $2 $3 native-simulator -n $SIMULATOR_NAME --destination native-simulators -d contract_name=$CONTRACT_NAME -d contract_crate_name=$CONTRACT_CRATE
55
55
mv native-simulators/$SIMULATOR_NAME /src/contract-lib.rs contracts/$CONTRACT_NAME /src/lib.rs
56
56
57
+ if [ ! -d ' native-simulators/Makefile' ]; then
58
+ mv native-simulators/$SIMULATOR_NAME /GlobalMakefile native-simulators/Makefile
59
+ else
60
+ rm -f native-simulators/$SIMULATOR_NAME /GlobalMakefile
61
+ fi
62
+
63
+ # Insert feature: simulator into Cargo.toml
57
64
FILE=contracts/$CONTRACT_NAME /Cargo.toml
58
65
if grep -q " \[features\]" " $FILE " ; then
59
66
sed -i ' /\[features\]/a\simulator = ["ckb-std/simulator"]' " $FILE "
60
67
else
61
68
echo -e " \n[features]\nsimulator = [\" ckb-std/simulator\" ]" >> " $FILE "
62
69
fi
63
70
64
- if [ ! -d ' native-simulators/Makefile ' ] ; then
65
- mv native-simulators/ $SIMULATOR_NAME /GlobalMakefile native-simulators/Makefile
66
- else
67
- rm -f native-simulators/ $SIMULATOR_NAME /GlobalMakefile
68
- fi
71
+ FILE=contracts/ $CONTRACT_NAME /src/main.rs
72
+ sed -i ' s/#!\[no_std\]/#!\[cfg_attr(not(feature = "simulator"), no_std)\]/ ' $FILE
73
+ sed -i ' s/#!\[cfg_attr(not(test), no_main)\]/#!\[cfg_attr(not(any(feature = "simulator", test)), no_main)\]/ ' $FILE
74
+ sed -i ' s/#\[cfg(test)\]/#\[cfg(any(feature = "simulator", test))\]/ ' $FILE
75
+ sed -i ' s/#\[cfg(not(test))\]/#\[cfg(not(any(feature = "simulator", test)))\]/ ' $FILE
0 commit comments