@@ -14,7 +14,7 @@ if [ "$CONTRACT_NAME" = "_" ]; then
1414 contracts=()
1515 for i in " ${! folders[@]} " ; do
1616 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
1818 contracts+=(" ${contract_name} " )
1919 fi
2020 done
@@ -54,15 +54,22 @@ SIMULATOR_NAME=${CONTRACT_NAME}-sim
5454cargo generate $2 $3 native-simulator -n $SIMULATOR_NAME --destination native-simulators -d contract_name=$CONTRACT_NAME -d contract_crate_name=$CONTRACT_CRATE
5555mv native-simulators/$SIMULATOR_NAME /src/contract-lib.rs contracts/$CONTRACT_NAME /src/lib.rs
5656
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
5764FILE=contracts/$CONTRACT_NAME /Cargo.toml
5865if grep -q " \[features\]" " $FILE " ; then
5966 sed -i ' /\[features\]/a\simulator = ["ckb-std/simulator"]' " $FILE "
6067else
6168 echo -e " \n[features]\nsimulator = [\" ckb-std/simulator\" ]" >> " $FILE "
6269fi
6370
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