diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 271f1454..885843fd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -114,3 +114,22 @@ Debug with IDEs: Following these instructions, using your favorite IDE like VSCode,GoLand or just terminal to debug: image +# Release xgo +Each new release will have two tags, for example: `v1.0.49` and `runtime/v1.0.49`. + +The general rule is to make these two tags remain the same with each other, and with the one in [cmd/xgo/version.go](cmd/xgo/version.go). + +Here is a guide on how to make a new release: +- update `VERSION` in [cmd/xgo/version.go](cmd/xgo/version.go). +- update `CORE_VERSION` to match `VERSION` if there is a change in this version that makes `cmd/xgo` depends on the newest runtime, otherwise, keep in untouched. +- run `go generate`. +- check whether `CORE_REVISION`,`CORE_NUMBER` matches `REVISION`,`NUMBER` if `CORE_VERSION` is updated to the same with `VERSION`, if not, run `go generate` again and check, and manually update if necessary. +- run `git add -A`. +- run `git commit -m "release v1.0.49"`, this will run git hooks that copies `CORE_VERSION`,`CORE_REVISION`,`CORE_NUMBER` to [runtime/core/version.go](runtime/core/version.go) so that if a runtime is running with an older xgo, it will print warnings. +- run `git tag v1.0.49 && git tag runtime/v1.0.49`. +- run `git push --tags`. +- go to github release page to draft a new release +- run `go run ./script/build-release`, run this in a standalone worktree if necessary. +- upload built binaries. +- update release notes. +- release. \ No newline at end of file diff --git a/cmd/xgo/main.go b/cmd/xgo/main.go index c32ea412..7e861c30 100644 --- a/cmd/xgo/main.go +++ b/cmd/xgo/main.go @@ -194,13 +194,31 @@ func handleBuild(cmd string, args []string) error { logDebug("effective GOROOT: %s", goroot) // create a tmp dir for communication with exec_tool - tmpDir, err := os.MkdirTemp("", "xgo-"+cmd) + tmpRoot, err := getTmpDir() if err != nil { return err } - defer os.RemoveAll(tmpDir) + // the xgoTmpDir can be thought as a shortly-stable cache dir + // - it won't gets deleted in a short period + // - the system will reclaim it if out of storage + // it will hold: + // - instrumentation + // - build cache + xgoTmpDir := filepath.Join(tmpRoot, "xgo") + logDebug("xgoTmpDir: %s", xgoTmpDir) + err = os.MkdirAll(xgoTmpDir, 0755) + if err != nil { + return err + } + // sessionTmpDir is specifically for this run session + sessionTmpDir, err := os.MkdirTemp(xgoTmpDir, "session-"+cmd+"-") + logDebug("sessionTmpDir: %s", sessionTmpDir) + if err != nil { + return err + } + defer os.RemoveAll(sessionTmpDir) - optionsFromFile, optionsFromFileContent, err := mergeOptionFiles(tmpDir, opts.optionsFromFile, opts.mockRules) + optionsFromFile, optionsFromFileContent, err := mergeOptionFiles(sessionTmpDir, opts.optionsFromFile, opts.mockRules) if err != nil { return err } @@ -209,7 +227,7 @@ func handleBuild(cmd string, args []string) error { var vscodeDebugFileSuffix string if !noInstrument && debugTarget != "" { var err error - vscodeDebugFile, vscodeDebugFileSuffix, err = getVscodeDebugFile(tmpDir, vscode) + vscodeDebugFile, vscodeDebugFileSuffix, err = getVscodeDebugFile(sessionTmpDir, vscode) if err != nil { return err } @@ -219,10 +237,10 @@ func handleBuild(cmd string, args []string) error { var tmpASTFile string if !noInstrument { if dumpIR != "" { - tmpIRFile = filepath.Join(tmpDir, "dump-ir") + tmpIRFile = filepath.Join(sessionTmpDir, "dump-ir") } if dumpAST != "" { - tmpASTFile = filepath.Join(tmpDir, "dump-ast") + tmpASTFile = filepath.Join(sessionTmpDir, "dump-ast") } } @@ -240,17 +258,17 @@ func handleBuild(cmd string, args []string) error { } // abs xgo dir - xgoDir, err := getXgoHome(xgoHome) + xgoDir, err := getOrMakeAbsXgoHome(xgoHome) if err != nil { return err } binDir := filepath.Join(xgoDir, "bin") - logDir := filepath.Join(xgoDir, "log") + logDir := filepath.Join(xgoTmpDir, "log") instrumentSuffix := "" if isDevelopment { instrumentSuffix = "-dev" } - instrumentDir := filepath.Join(xgoDir, "go-instrument"+instrumentSuffix, mappedGorootName) + instrumentDir := filepath.Join(xgoTmpDir, "go-instrument"+instrumentSuffix, mappedGorootName) logDebug("instrument dir: %s", instrumentDir) exeSuffix := osinfo.EXE_SUFFIX @@ -466,7 +484,7 @@ func handleBuild(cmd string, args []string) error { } debugCompilePkg = pkgs[0] } - debugCompileLogFile = filepath.Join(tmpDir, "debug-compile.log") + debugCompileLogFile = filepath.Join(sessionTmpDir, "debug-compile.log") go tailLog(debugCompileLogFile) logDebug("debug compile package: %s", debugCompilePkg) } @@ -551,7 +569,7 @@ func handleBuild(cmd string, args []string) error { if cmdBuild || (cmdTest && flagC) || debugMode { // output if !debugMode && noBuildOutput { - discardOut := filepath.Join(tmpDir, "discard.out") + discardOut := filepath.Join(sessionTmpDir, "discard.out") buildCmdArgs = append(buildCmdArgs, "-o", discardOut) } else if output != "" { finalBuildOutput = output @@ -564,7 +582,7 @@ func handleBuild(cmd string, args []string) error { finalBuildOutput = absOutput } } else if debugMode { - finalBuildOutput = filepath.Join(tmpDir, "debug.bin") + finalBuildOutput = filepath.Join(sessionTmpDir, "debug.bin") } if finalBuildOutput != "" { buildCmdArgs = append(buildCmdArgs, "-o", finalBuildOutput) @@ -749,8 +767,8 @@ func checkGoVersion(goroot string, noInstrument bool) (*goinfo.GoVersion, error) return goVersion, nil } -// getXgoHome returns absolute path to xgo homoe -func getXgoHome(xgoHome string) (string, error) { +// getOrMakeAbsXgoHome returns absolute path to xgo homoe +func getOrMakeAbsXgoHome(xgoHome string) (string, error) { if xgoHome == "" { homeDir, err := os.UserHomeDir() if err != nil { @@ -774,6 +792,23 @@ func getXgoHome(xgoHome string) (string, error) { return absHome, nil } +// getTmpDir for build caches +func getTmpDir() (string, error) { + if runtime.GOOS != "windows" { + // the publicly konwn /tmp dir + const KNOWN_TMP = "/tmp" + info, err := os.Stat(KNOWN_TMP) + if err == nil && info.IsDir() { + return KNOWN_TMP, nil + } + } + tmpDir := os.TempDir() + if tmpDir == "" { + return "", fmt.Errorf("cannot get tmp dir") + } + return tmpDir, nil +} + func getNakedGo() string { if nakedGoReplacement != "" { return nakedGoReplacement diff --git a/cmd/xgo/shadow.go b/cmd/xgo/shadow.go index 6d41e2c2..3c161d0d 100644 --- a/cmd/xgo/shadow.go +++ b/cmd/xgo/shadow.go @@ -15,7 +15,7 @@ import ( var shadowFS embed.FS func handleShadow() error { - xgoHome, err := getXgoHome("") + xgoHome, err := getOrMakeAbsXgoHome("") if err != nil { return err } diff --git a/cmd/xgo/version.go b/cmd/xgo/version.go index d8ede6dc..27f14a5f 100644 --- a/cmd/xgo/version.go +++ b/cmd/xgo/version.go @@ -6,8 +6,8 @@ import "fmt" // VERSION is manually updated when needed a new tag // see also runtime/core/version.go const VERSION = "1.0.49" -const REVISION = "0851e4edf6d78c3da276a587656c19e489590d3f+1" -const NUMBER = 312 +const REVISION = "847f7f1a887cb48c1bfd94612ac3c648080d63cb+1" +const NUMBER = 313 // the matching runtime/core's version // manually updated diff --git a/script/git-hooks/main.go b/script/git-hooks/main.go index 4d56ba56..1d18f722 100644 --- a/script/git-hooks/main.go +++ b/script/git-hooks/main.go @@ -116,7 +116,9 @@ func preCommitCheck(noCommit bool, amend bool, noUpdateVersion bool) error { // suffix "+1" to indicate this rev := commitHash + "+1" + // cmd/xgo/version.go xgoVersionRelFile := revision.GetXgoVersionFile("") + // runtime/core/version.go runtimeVersionRelFile := revision.GetRuntimeVersionFile("") xgoVersionFile := filepath.Join(rootDir, xgoVersionRelFile)