Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
fix generation of bundler.json and bind files to reduce redundant ast…
Browse files Browse the repository at this point in the history
…ilectron builds
  • Loading branch information
nikhilsaraf committed Mar 29, 2020
1 parent 3ca2e42 commit 5a5967c
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 35 deletions.
53 changes: 29 additions & 24 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ function gen_ccxt_binary() {
echo "successful"
}

# takes in the ARGS for which to build
function gen_bundler_json() {
echo -n "generating the bundler.json file in / to create missing files for '$@' platforms ... "
go run ./scripts/gen_bundler_json/gen_bundler_json.go $@ > $KELP/bundler.json
check_build_result $?
echo "done"
}

# takes in no args
function gen_bind_files() {
echo -n "generating the bind file in /cmd to create missing files for platforms specified in the bundler.json ... "
astilectron-bundler bd -c $KELP/bundler.json
check_build_result $?
echo "done"
}

if [[ $(basename $("pwd")) != "kelp" ]]
then
echo "need to invoke from the root 'kelp' directory"
Expand Down Expand Up @@ -178,20 +194,12 @@ check_build_result $?
echo "... finished embedding contents of gui/web/build into a .go file (env=$ENV)"
echo ""

echo -n "generating the bundler.json file in / to create missing files for current platform ... "
go run ./scripts/gen_bundler_json/gen_bundler_json.go > $KELP/bundler.json
check_build_result $?
echo "done"
echo -n "generating the bind file in /cmd to create missing files for current platform ... "
astilectron-bundler bd -c $KELP/bundler.json
check_build_result $?
echo "done"
echo ""

if [[ $ENV == "dev" ]]
then
echo "GOOS: $(go env GOOS)"
echo "GOARCH: $(go env GOARCH)"
GOOS="$(go env GOOS)"
GOARCH="$(go env GOARCH)"
echo "GOOS: $GOOS"
echo "GOARCH: $GOARCH"
echo ""

# explicit check for windows
Expand All @@ -205,6 +213,10 @@ then
OUTFILE=bin/kelp$EXTENSION
mkdir -p bin

gen_bundler_json
gen_bind_files
echo ""

echo -n "compiling ... "
go build -ldflags "$LDFLAGS" -o $OUTFILE
check_build_result $?
Expand All @@ -215,18 +227,7 @@ then
fi
# else, we are in deploy mode

echo -n "generating the bundler.json file in / to create missing files for all remaining platforms ... "
go run ./scripts/gen_bundler_json/gen_bundler_json.go -a > $KELP/bundler.json
check_build_result $?
echo "done"
echo -n "generating the bind file in /cmd to create missing files for all remaining platforms ... "
astilectron-bundler bd -c $KELP/bundler.json
check_build_result $?
echo "done"
echo ""

ARCHIVE_DIR=build/$DATE

ARCHIVE_FOLDER_NAME=kelp-$VERSION
ARCHIVE_DIR_SOURCE=$ARCHIVE_DIR/$ARCHIVE_FOLDER_NAME
mkdir -p $ARCHIVE_DIR_SOURCE
Expand All @@ -243,7 +244,6 @@ do
GOOS=`echo $args | cut -d' ' -f1 | tr -d ' '`
GOARCH=`echo $args | cut -d' ' -f2 | tr -d ' '`
GOARM=`echo $args | cut -d' ' -f3 | tr -d ' '`
echo -n "compiling for (GOOS=$GOOS, GOARCH=$GOARCH, GOARM=$GOARM) ... "

# explicit check for windows
BINARY="$OUTFILE"
Expand All @@ -252,7 +252,10 @@ do
BINARY="$OUTFILE.exe"
fi

gen_bundler_json -p $GOOS
gen_bind_files
# compile
echo -n "compiling for (GOOS=$GOOS, GOARCH=$GOARCH, GOARM=$GOARM) ... "
env GOOS=$GOOS GOARCH=$GOARCH GOARM=$GOARM go build -ldflags "$LDFLAGS" -o $BINARY
check_build_result $?
echo "successful"
Expand Down Expand Up @@ -308,6 +311,8 @@ do
GOARCH=amd64
unset GOARM

gen_bundler_json -p $GOOS
echo "no need to generate bind files separately since we build using astilectron bundler directly for GUI"
# compile
echo -n "compiling UI for (GOOS=$GOOS, GOARCH=$GOARCH, FLAG=$FLAG) ... "
astilectron-bundler $FLAG -o $ARCHIVE_DIR_SOURCE_UI $LDFLAGS_UI
Expand Down
51 changes: 40 additions & 11 deletions scripts/gen_bundler_json/gen_bundler_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,27 @@ var environments = `{
]
}`

var environmentsDarwin = `{
"environments": [
{"os": "darwin", "arch": "amd64"}
]
}`

var environmentsLinux = `{
"environments": [
{"os": "linux", "arch": "amd64"}
]
}`

var environmentsWindows = `{
"environments": [
{"os": "windows", "arch": "amd64"}
]
}`

func main() {
buildAllP := flag.Bool("a", false, "whether to build for all platforms (default builds only for native platform)")
buildPlatformP := flag.String("p", "", "explicitly specify a specific platform to build for")
flag.Parse()
buildAll := *buildAllP

Expand All @@ -36,17 +55,15 @@ func main() {
panic(e)
}

if buildAll {
var environmentsJSON map[string]interface{}
e := json.Unmarshal([]byte(environments), &environmentsJSON)
if e != nil {
panic(e)
}

for k, v := range environmentsJSON {
bundlerJSON[k] = v
}
}
if *buildPlatformP == "darwin" {
setPlatform(environmentsDarwin, bundlerJSON)
} else if *buildPlatformP == "linux" {
setPlatform(environmentsLinux, bundlerJSON)
} else if *buildPlatformP == "windows" {
setPlatform(environmentsWindows, bundlerJSON)
} else if buildAll {
setPlatform(environments, bundlerJSON)
} // else only for native platform

jsonBytes, e := json.MarshalIndent(bundlerJSON, "", " ")
if e != nil {
Expand All @@ -55,3 +72,15 @@ func main() {
jsonString := string(jsonBytes)
fmt.Println(jsonString)
}

func setPlatform(envs string, bundlerJSON map[string]interface{}) {
var environmentsJSON map[string]interface{}
e := json.Unmarshal([]byte(envs), &environmentsJSON)
if e != nil {
panic(e)
}

for k, v := range environmentsJSON {
bundlerJSON[k] = v
}
}

0 comments on commit 5a5967c

Please sign in to comment.