Skip to content

Commit

Permalink
add --include-local to build-release
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed Mar 30, 2024
1 parent ed7cbd5 commit d5a5e38
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ jobs:
run: cd runtime && go tool cover --func ../cover-runtime.out

- name: Build Release
run: go run ./script/build-release
run: go run ./script/build-release --include-install-src --include-local

# - name: Check Version
# run: ~/.xgo/bin/xgo revision
- name: Check Version
run: ~/.xgo/bin/xgo revision

# - name: Check Go Version
# run: ~/.xgo/bin/xgo exec go version
- name: Check Go Version
run: ~/.xgo/bin/xgo exec go version
4 changes: 2 additions & 2 deletions cmd/xgo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import "fmt"

const VERSION = "1.0.11"
const REVISION = "1bc959ae70c34e189c36b8cb3f7b2e1a8665756c+1"
const NUMBER = 136
const REVISION = "bdfb5083555459e8a25ce31cdde1706aaa58bc43+1"
const NUMBER = 137

func getRevision() string {
return fmt.Sprintf("%s %s BUILD_%d", VERSION, REVISION, NUMBER)
Expand Down
4 changes: 2 additions & 2 deletions runtime/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

const VERSION = "1.0.11"
const REVISION = "1bc959ae70c34e189c36b8cb3f7b2e1a8665756c+1"
const NUMBER = 136
const REVISION = "bdfb5083555459e8a25ce31cdde1706aaa58bc43+1"
const NUMBER = 137

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
29 changes: 22 additions & 7 deletions script/build-release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// go run ./script/build-release
// go run ./script/build-release --local --local-name xgo_dev
// go run ./script/build-release --local --local-name xgo_dev --debug
// go run ./script/build-release --include-install-src
// go run ./script/build-release --include-install-src --include-local

func main() {
args := os.Args[1:]
Expand All @@ -29,6 +29,7 @@ func main() {
var localName string
var debug bool
var includeInstallSrc bool
var includeLocal bool
for i := 0; i < n; i++ {
arg := args[i]
if arg == "--local" {
Expand All @@ -48,6 +49,10 @@ func main() {
includeInstallSrc = true
continue
}
if arg == "--include-local" {
includeLocal = true
continue
}
fmt.Fprintf(os.Stderr, "unrecognized option: %s\n", arg)
os.Exit(1)
}
Expand All @@ -70,7 +75,7 @@ func main() {
}
}

err := buildRelease("xgo-release", installLocal, localName, debug, archs, includeInstallSrc)
err := buildRelease("xgo-release", installLocal, localName, debug, archs, includeInstallSrc, includeLocal)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
Expand All @@ -82,7 +87,7 @@ type osArch struct {
goarch string
}

func buildRelease(releaseDirName string, installLocal bool, localName string, debug bool, osArches []*osArch, includeInstallSrc bool) error {
func buildRelease(releaseDirName string, installLocal bool, localName string, debug bool, osArches []*osArch, includeInstallSrc bool, includeLocal bool) error {
if installLocal && len(osArches) != 1 {
return fmt.Errorf("--install-local requires only one target")
}
Expand Down Expand Up @@ -176,7 +181,7 @@ func buildRelease(releaseDirName string, installLocal bool, localName string, de
}

for _, osArch := range osArches {
err := buildBinaryRelease(dir, tmpSrcDir, xgoVersionStr, osArch.goos, osArch.goarch, installLocal, localName, extraBuildFlags)
err := buildBinaryRelease(dir, tmpSrcDir, xgoVersionStr, osArch.goos, osArch.goarch, installLocal, includeLocal, localName, extraBuildFlags)
if err != nil {
return fmt.Errorf("GOOS=%s GOARCH=%s:%w", osArch.goos, osArch.goarch, err)
}
Expand Down Expand Up @@ -247,7 +252,7 @@ func generateSums(dir string, sumFile string) error {
// c2876990b545be8396b7d13f0f9c3e23b38236de8f0c9e79afe04bcf1d03742e xgo1.0.0-darwin-arm64.tar.gz
// 6ae476cb4c3ab2c81a94d1661070e34833e4a8bda3d95211570391fb5e6a3cc0 xgo1.0.0-darwin-amd64.tar.gz

func buildBinaryRelease(dir string, srcDir string, version string, goos string, goarch string, installLocal bool, localName string, extraBuildFlags []string) error {
func buildBinaryRelease(dir string, srcDir string, version string, goos string, goarch string, installLocal bool, includeLocal bool, localName string, extraBuildFlags []string) error {
if version == "" {
return fmt.Errorf("requires version")
}
Expand Down Expand Up @@ -293,8 +298,16 @@ func buildBinaryRelease(dir string, srcDir string, version string, goos string,
return err
}
}

var needInstall bool
if installLocal {
needInstall = true
} else if includeLocal {
if runtime.GOOS == goos && runtime.GOARCH == goarch {
needInstall = true
}
}

if needInstall {
homeDir, err := os.UserHomeDir()
if err != nil {
return err
Expand Down Expand Up @@ -327,7 +340,9 @@ func buildBinaryRelease(dir string, srcDir string, version string, goos string,
if lookPathErr != nil {
fmt.Printf("%s built successfully, you may need to add %s to your PATH variables\n", xgoExeName, binDir)
}
return nil
if installLocal {
return nil
}
}

// package it as a tar.gz
Expand Down

0 comments on commit d5a5e38

Please sign in to comment.