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

Commit

Permalink
clean up root.go basic kelp binary invocation logic, closes #568 (#658)
Browse files Browse the repository at this point in the history
* 1 - remove windows startup bat file and copy script

* 2 - add isGuiBinary flag from build.sh script and recognize in code

* 3 - force set noElectron=false for windows

* 4 - add comment in server_noop.go about the purpose of that file

* 5 - use (buildType string) instead of (isGuiBinary bool) because of error building

compiling ... # github.com/stellar/kelp
github.com/stellar/kelp/cmd.isGuiBinary: cannot set with -X: not a var of type string (type.bool)
  • Loading branch information
nikhilsaraf authored Feb 12, 2021
1 parent d591f8f commit 23631df
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
10 changes: 8 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/spf13/cobra"

"github.com/stellar/kelp/support/networking"
"github.com/stellar/kelp/support/sdk"
"github.com/stellar/kelp/support/utils"
Expand All @@ -21,6 +22,7 @@ var buildDate string
var env string
var amplitudeAPIKey string
var goarm string
var buildType string // set from the build script, cli or gui

const envRelease = "release"
const envDev = "dev"
Expand Down Expand Up @@ -49,13 +51,17 @@ var RootCmd = &cobra.Command{
`
fmt.Println(intro)

if hasUICapability {
if buildType == "gui" {
// if this is the GUI binary then we want to start off with the server command
serverCmd.Run(ccmd, args)
} else {
} else if buildType == "cli" {
// else start off with the help command
e := ccmd.Help()
if e != nil {
panic(e)
}
} else {
panic(fmt.Sprintf("unrecognized buildType: %s", buildType))
}
},
}
Expand Down
9 changes: 7 additions & 2 deletions cmd/server_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ type serverInputs struct {
}

func init() {
hasUICapability = true

options := serverInputs{}
options.port = serverCmd.Flags().Uint16P("port", "p", 8000, "port on which to serve")
options.dev = serverCmd.Flags().Bool("dev", false, "run in dev mode for hot-reloading of JS code")
Expand Down Expand Up @@ -126,6 +124,13 @@ func init() {
}
}

if runtime.GOOS == "windows" {
if *options.noElectron {
log.Printf("input options had specified noElectron=true for winndows, but that is not supported on windows yet. force setting noElectron=false for windows.\n")
*options.noElectron = false
}
}

// create a latch to trigger the browser opening once the backend server is loaded
openBrowserWg := &sync.WaitGroup{}
openBrowserWg.Add(1)
Expand Down
4 changes: 2 additions & 2 deletions cmd/server_noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/spf13/cobra"
)

var hasUICapability = false

// load the basic serverCmd for all architectures. Default action is a noop action.
// This is overriden for platforms that support this command, example: server_amd64.go
var serverCmd = &cobra.Command{
Use: "server",
Short: "Serves the Kelp GUI",
Expand Down
1 change: 1 addition & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var versionCmd = &cobra.Command{
fmt.Printf(" git branch: %s\n", gitBranch)
fmt.Printf(" git hash: %s\n", gitHash)
fmt.Printf(" build date: %s\n", buildDate)
fmt.Printf(" build type: %s\n", buildType)
fmt.Printf(" env: %s\n", env)
fmt.Printf(" GOOS: %s\n", runtime.GOOS)
fmt.Printf(" GOARCH: %s\n", runtime.GOARCH)
Expand Down
1 change: 0 additions & 1 deletion gui/windows-bat-file/kelp-start.bat

This file was deleted.

24 changes: 15 additions & 9 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,12 @@ then
gen_bind_files
echo ""

# manually set buildType for CLI
DYNAMIC_LDFLAGS="$LDFLAGS -X github.com/stellar/kelp/cmd.buildType=cli"

# cannot set goarm because not accessible (need to figure out a way)
echo -n "compiling ... "
go build -ldflags "$LDFLAGS" -o $OUTFILE
go build -ldflags "$DYNAMIC_LDFLAGS" -o $OUTFILE
check_build_result $?
echo "successful: $OUTFILE"
echo ""
Expand Down Expand Up @@ -320,11 +323,13 @@ do
BINARY="$OUTFILE.exe"
fi

DYNAMIC_LDFLAGS="$LDFLAGS"
# manually set buildType for CLI
DYNAMIC_LDFLAGS="$LDFLAGS -X github.com/stellar/kelp/cmd.buildType=cli"

if [[ "$GOARM" != "" ]]
then
GOARM_FLAGS="-X github.com/stellar/kelp/cmd.goarm=$GOARM"
echo "adding GOARM_FLAGS to ldflags: $GOARM_FLAGS"
echo "adding GOARM_FLAGS to DYNAMIC_LDFLAGS: $GOARM_FLAGS"
DYNAMIC_LDFLAGS="$DYNAMIC_LDFLAGS $GOARM_FLAGS"
fi

Expand Down Expand Up @@ -406,20 +411,21 @@ do
# generate bundler.json for platform
gen_bundler_json -p $GOOS

# manually set buildType for GUI build
DYNAMIC_LDFLAGS="$LDFLAGS -X github.com/stellar/kelp/cmd.buildType=gui"
# manually set buildType for GUI build
DYNAMIC_LDFLAGS_UI="$LDFLAGS_UI -ldflags X:github.com/stellar/kelp/cmd.buildType=gui"

if [[ $GOOS == "windows" ]]
then
gen_bind_files
# compile
# need to use cli tool for windows because building a GUI version will trigger the command prompt to open every time we invoke a "bash -c" command which is too frequent
echo -n "compiling UI for windows using cli tool instead of using astilectron-bundler (GOOS=$GOOS, GOARCH=$GOARCH) ... "
env GOOS=$GOOS GOARCH=$GOARCH GOARM=$GOARM go build -ldflags "$LDFLAGS" -o $ARCHIVE_DIR_SOURCE_UI/$GOOS-$GOARCH/kelp.exe
env GOOS=$GOOS GOARCH=$GOARCH GOARM=$GOARM go build -ldflags "$DYNAMIC_LDFLAGS" -o $ARCHIVE_DIR_SOURCE_UI/$GOOS-$GOARCH/kelp.exe
check_build_result $?
echo "successful"

echo -n "copying over kelp-start.bat file to the windows build ..."
cp $KELP/gui/windows-bat-file/kelp-start.bat $ARCHIVE_DIR_SOURCE_UI/$GOOS-$GOARCH/
echo "done"

# set paths needed for unzipping the vendor and ccxt files
VENDOR_FILENAME=""
CCXT_FILENAME="ccxt-rest_linux-x64.zip"
Expand All @@ -429,7 +435,7 @@ do
# compile
echo "no need to generate bind files separately since we build using astilectron bundler directly for GUI"
echo -n "compiling UI for $GOOS via astilectron-bundler (GOOS=$GOOS, GOARCH=$GOARCH) ... "
astilectron-bundler $FLAG -o $ARCHIVE_DIR_SOURCE_UI $LDFLAGS_UI
astilectron-bundler $FLAG -o $ARCHIVE_DIR_SOURCE_UI $DYNAMIC_LDFLAGS_UI
check_build_result $?
echo "successful"

Expand Down

0 comments on commit 23631df

Please sign in to comment.