diff --git a/.gitignore b/.gitignore index 15930d4c..45937a12 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,9 @@ .*.sw? .DS_Store build/** +release/** .vscode/** -Makefile -CMakeCache.txt -cmake_install.cmake -CMakeFiles/** \ No newline at end of file +**/Makefile +**/CMakeCache.txt +**/cmake_install.cmake +**/CMakeFiles/** \ No newline at end of file diff --git a/examples/hpcontract/.gitignore b/examples/echocontract/.gitignore similarity index 100% rename from examples/hpcontract/.gitignore rename to examples/echocontract/.gitignore diff --git a/examples/hpcontract/contract.js b/examples/echocontract/contract.js similarity index 100% rename from examples/hpcontract/contract.js rename to examples/echocontract/contract.js diff --git a/examples/hpcontract/package-lock.json b/examples/echocontract/package-lock.json similarity index 100% rename from examples/hpcontract/package-lock.json rename to examples/echocontract/package-lock.json diff --git a/examples/hpcontract/package.json b/examples/echocontract/package.json similarity index 100% rename from examples/hpcontract/package.json rename to examples/echocontract/package.json diff --git a/release.sh b/release.sh new file mode 100755 index 00000000..fd82b1cf --- /dev/null +++ b/release.sh @@ -0,0 +1,51 @@ +#!/bin/bash +# Hot Pocket - create release package + +if [ -z "$1" ] +then + echo "Release Version not specified." + exit 1 +fi + +RELVERSION="hp-${1}" +RELEASEDIR=./release/$RELVERSION + +cmake . -DCMAKE_BUILD_TYPE=Release +make + +rm -rf ./release + +# Copy hpcore binary +mkdir -p $RELEASEDIR +cp build/hpcore $RELEASEDIR/hpcore +$RELEASEDIR/hpcore new $RELEASEDIR/echocontract + +# Copy example client +mkdir $RELEASEDIR/hpclient +cp -r examples/hpclient/client.js $RELEASEDIR/hpclient +cp -r examples/hpclient/package.json $RELEASEDIR/hpclient +echo "npm install hpclient" +npm --prefix $RELEASEDIR/hpclient install > /dev/null 2>&1 + +# Copy example contract +CTRPATH=./bin/contract.js +CFGPATH=${RELEASEDIR}/echocontract/cfg/hp.cfg +CFGJSON=${RELEASEDIR}/echocontract/cfg/hp.json +mv $CFGPATH $CFGJSON +node -p "JSON.stringify({...require('${CFGJSON}'), binary:'/usr/bin/node', binargs:'${CTRPATH}' }, null, 2)" > $CFGPATH +rm $CFGJSON +mkdir -p $RELEASEDIR/echocontract/bin +cp -r examples/echocontract/contract.js $RELEASEDIR/echocontract/bin +cp -r examples/echocontract/package.json $RELEASEDIR/echocontract/bin +echo "npm install echocontract" +npm --prefix $RELEASEDIR/echocontract/bin install > /dev/null 2>&1 + +echo "Creating tarball" +tar -C ./release -czf ./release/$RELVERSION.tar.gz $RELVERSION +rm -r $RELEASEDIR + +echo "Release tarball has been created at ./release/${RELVERSION}.tar.gz" + +# Switch cmake back to Debug build mode +cmake . -DCMAKE_BUILD_TYPE=Debug +exit 0 \ No newline at end of file diff --git a/src/proc.cpp b/src/proc.cpp index a8ae5ba2..a245491f 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -96,7 +97,7 @@ int exec_contract(const ContractExecArgs &args) close_unused_fds(false); // Set the contract process working directory. - chdir(conf::ctx.contractDir.data()); + std::experimental::filesystem::current_path(conf::ctx.contractDir); // Write the contract input message from HotPocket to the stdin (0) of the contract process. write_contract_args(args); @@ -204,7 +205,11 @@ int write_contract_args(const ContractExecArgs &args) close(stdinpipe[0]); // Write the json message and close write fd. - write(stdinpipe[1], json.data(), json.size()); + if (write(stdinpipe[1], json.data(), json.size()) == -1) + { + std::cerr << "Failed to write to stdin of contract process.\n"; + return -1; + } close(stdinpipe[1]); return 0;