Skip to content

Commit

Permalink
Merge pull request #45 from RetricSu/add-clerkb-submodule
Browse files Browse the repository at this point in the history
Add clerkb submodule
  • Loading branch information
RetricSu authored May 28, 2021
2 parents b0b7741 + a919982 commit cd0dabf
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
path = godwoken-scripts
url = https://github.com/nervosnetwork/godwoken-scripts.git
branch = master
[submodule "clerkb"]
path = clerkb
url = https://github.com/nervosnetwork/clerkb.git
44 changes: 23 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ install:
make rebuild-gw-scripts-and-bin ; \
else make copy-gw-scripts-and-bin-from-docker ; \
fi
# if manual build clerkb for POA
if [ "$(MANUAL_BUILD_CLERKB)" = true ] ; then \
make rebuild-poa-scripts ; \
else \
source ./gw_util.sh && copy_poa_scripts_from_docker_or_abort ;\
fi

init:
make install
Expand Down Expand Up @@ -212,27 +218,13 @@ prepare-money:
cd godwoken-examples && yarn clean && yarn prepare-money:normal

########### manual-build-mode #############
### gw and polyjuice all in one
### rebuild components's scripts and bin all in one
rebuild-scripts:
make prepare-prebuild-scripts
make paste-prebuild-scripts

prepare-prebuild-scripts:
cd godwoken-scripts && cd c && make && cd - && capsule build --release --debug-output
cd godwoken-polyjuice && make all-via-docker

paste-prebuild-scripts:
# godwoken-scripts
cp godwoken-scripts/c/build/meta-contract-generator config/meta-contract-generator
cp godwoken-scripts/c/build/meta-contract-validator config/meta-contract-validator
cp godwoken-scripts/c/build/sudt-generator config/sudt-generator
cp godwoken-scripts/c/build/sudt-validator config/sudt-validator
cp godwoken-scripts/build/release/* config/scripts/release/
# godwoken-polyjuice
cp godwoken-polyjuice/build/generator_log config/polyjuice-generator
cp godwoken-polyjuice/build/validator_log config/polyjuice-validator
make rebuild-polyjuice-bin
make rebuild-gw-scripts-and-bin
make rebuild-poa-scripts

#### gw and polyjucie standalone
#### rebuild components's scripts and bin standalone
rebuild-polyjuice-bin:
cd godwoken-polyjuice && make all-via-docker
cp godwoken-polyjuice/build/generator_log config/polyjuice-generator
Expand All @@ -246,6 +238,11 @@ rebuild-gw-scripts-and-bin:
cp godwoken-scripts/c/build/sudt-validator config/sudt-validator
cp godwoken-scripts/build/release/* config/scripts/release/

rebuild-poa-scripts:
cd clerkb && yarn && make all-via-docker
cp clerkb/build/debug/poa config/scripts/release/
cp clerkb/build/debug/state config/scripts/release/

########## prebuild-quick-mode #############
copy-polyjuice-bin-from-docker:
mkdir -p `pwd`/quick-mode/polyjuice
Expand Down Expand Up @@ -276,5 +273,10 @@ copy-gw-scripts-and-bin-from-docker:
cp quick-mode/godwoken/deposition-lock config/scripts/release/
cp quick-mode/godwoken/always-success config/scripts/release/



copy-poa-scripts-from-docker:
mkdir -p `pwd`/quick-mode/clerkb
docker run -it -d --name dummy $$DOCKER_PREBUILD_IMAGE_NAME:$$DOCKER_PREBUILD_IMAGE_TAG
docker cp dummy:/scripts/clerkb/. `pwd`/quick-mode/clerkb
docker rm -f dummy
# paste the prebuild scripts to config dir for use
cp quick-mode/clerkb/* config/scripts/release/
1 change: 1 addition & 0 deletions clerkb
Submodule clerkb added at b2f09c
1 change: 1 addition & 0 deletions docker/.build.mode.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ MANUAL_BUILD_GODWOKEN=false
MANUAL_BUILD_WEB3=false
MANUAL_BUILD_SCRIPTS=false
MANUAL_BUILD_POLYJUICE=false
MANUAL_BUILD_CLERKB=false

####[images]
DOCKER_PREBUILD_IMAGE_NAME=nervos/godwoken-prebuilds
Expand Down
64 changes: 62 additions & 2 deletions gw_util.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# if docker-prebuild-image version is lower than this, then it is legacy
# which doesnt have poa scripts built-in.
LEGACY_PREBUILD_IMAGE_VERSION=0.2.4

# how to use:
# parese_toml_with_section file_path section_name key_name
Expand Down Expand Up @@ -135,7 +138,7 @@ generateSubmodulesEnvFile(){
git submodule update --init --recursive
fi

local -a arr=("godwoken" "godwoken-web3" "godwoken-polyjuice" "godwoken-examples" "godwoken-scripts")
local -a arr=("godwoken" "godwoken-web3" "godwoken-polyjuice" "godwoken-examples" "godwoken-scripts" "clerkb")
for i in "${arr[@]}"
do
# get origin url
Expand Down Expand Up @@ -182,7 +185,7 @@ update_submodules(){
# use these env varibles to update the desired submodules
source docker/.submodule.list.env

local -a arr=("godwoken" "godwoken-web3" "godwoken-polyjuice" "godwoken-examples" "godwoken-scripts")
local -a arr=("godwoken" "godwoken-web3" "godwoken-polyjuice" "godwoken-examples" "godwoken-scripts" "clerkb")
for i in "${arr[@]}"
do
# set url for submodule
Expand Down Expand Up @@ -262,3 +265,60 @@ isGodwokenRpcRunning(){
return 1
fi
}

version_comp () {
if [[ $1 == $2 ]]
then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}

test_version_comp () {
verion_comp $1 $2
case $? in
0) op='=';;
1) op='>';;
2) op='<';;
esac
if [[ $op != $3 ]]
then
echo "FAIL: Expected '$3', Actual '$op', Arg1 '$1', Arg2 '$2'"
else
echo "Pass: '$1 $op $2'"
fi
}

copy_poa_scripts_from_docker_or_abort(){
version_comp "${DOCKER_PREBUILD_IMAGE_TAG//v}" $LEGACY_PREBUILD_IMAGE_VERSION
# if version large than legacy_version
if [ "$?" = 1 ]; then
echo "copy poa scripts from docker image..."
make copy-poa-scripts-from-docker
else
echo "prebuild image version is lower than v0.2.5, there is no poa scripts in docker. instead, use poa scripts in config folder. do nothing."
fi
}
Empty file added v0.2.4
Empty file.

0 comments on commit cd0dabf

Please sign in to comment.