From 206b411ee16c5012a575a2f7f5d97977593f027a Mon Sep 17 00:00:00 2001 From: Andrea Manzini Date: Sat, 16 May 2026 11:32:00 +0200 Subject: [PATCH] feat: update versioning and improve build process - Set version to "dev" in funkoverage and updated build script to include git hash in the version string. - Adjusted .gitignore to include shim_binary directory. - Modified environment variable handling in shim_binary for better clarity and safety. - Updated RPM spec file version to 0.7.2 and adjusted build command accordingly. --- .gitignore | 1 + build.sh | 6 ++++-- cmd/funkoverage.go | 2 +- cmd/shim_binary/main.go | 31 ++++++++++++++++++++++++------- rpm/coverage-tools.spec | 8 ++++---- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index f4935d6..9b9fcbf 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ CLAUDE.md *.o !cmd/shim_binary/tracer_x86_bpfel.o !cmd/shim_binary/tracer_arm64_bpfel.o +shim_binary diff --git a/build.sh b/build.sh index 320233d..9a8499e 100755 --- a/build.sh +++ b/build.sh @@ -23,8 +23,10 @@ if [[ "${REGEN_BPF:-0}" == "1" ]]; then go generate ./cmd/shim_binary/ fi -echo "Building funkoverage CLI..." -go build -buildvcs=false -ldflags="-s -w" -o funkoverage ./cmd/ +GIT_HASH=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") +VERSION="dev-${GIT_HASH}" +echo "Building funkoverage CLI (${VERSION})..." +go build -buildvcs=false -ldflags="-s -w -X main.versionString=${VERSION}" -o funkoverage ./cmd/ echo "Building funkoverage-shim..." go build -buildvcs=false -ldflags="-s -w" -o funkoverage-shim ./cmd/shim_binary/ diff --git a/cmd/funkoverage.go b/cmd/funkoverage.go index 8739c18..45c3407 100644 --- a/cmd/funkoverage.go +++ b/cmd/funkoverage.go @@ -10,7 +10,7 @@ import ( "strings" ) -const versionString = "0.7.1" +var versionString = "dev" // command is one funkoverage subcommand. run receives the args after the // subcommand name (so for "funkoverage install -no-libs foo", run sees diff --git a/cmd/shim_binary/main.go b/cmd/shim_binary/main.go index cd62518..db80051 100644 --- a/cmd/shim_binary/main.go +++ b/cmd/shim_binary/main.go @@ -14,10 +14,10 @@ import ( ) const ( - activeEnvVar = "FUNKOVERAGE_ACTIVE" - childEnvVar = "FUNKOVERAGE_CHILD" - waitFdEnvVar = "FUNKOVERAGE_WAIT_FD" - arg0EnvVar = "FUNKOVERAGE_ARG0" + activeEnvPrefix = "FUNKOVERAGE_ACTIVE_" + childEnvVar = "FUNKOVERAGE_CHILD" + waitFdEnvVar = "FUNKOVERAGE_WAIT_FD" + arg0EnvVar = "FUNKOVERAGE_ARG0" ) func realBinaryPath() string { @@ -40,7 +40,8 @@ func main() { realBin := realBinaryPath() - // Recursion guard: already tracing, exec real binary directly. + // Recursion guard: already tracing this specific binary, exec real binary directly. + activeEnvVar := activeEnvPrefix + envSafeName(filepath.Base(realBin)) if os.Getenv(activeEnvVar) != "" { if err := syscall.Exec(realBin, os.Args, os.Environ()); err != nil { fmt.Fprintf(os.Stderr, "funkoverage-shim: exec %s: %v\n", realBin, err) @@ -174,7 +175,8 @@ func buildChildEnv(realBin string) []string { if arg0 == "" { arg0 = os.Args[0] } - env := cleanEnv() + activeEnvVar := activeEnvPrefix + envSafeName(filepath.Base(realBin)) + env := cleanEnv(activeEnvVar) env = append(env, childEnvVar+"=1", waitFdEnvVar+"=3", @@ -188,8 +190,23 @@ func buildChildEnv(realBin string) []string { return env } -func cleanEnv() []string { +func envSafeName(s string) string { + return strings.Map(func(r rune) rune { + if (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') { + return r + } + if r >= 'a' && r <= 'z' { + return r - 32 + } + return '_' + }, s) +} + +func cleanEnv(extra ...string) []string { skip := map[string]bool{childEnvVar: true, waitFdEnvVar: true, arg0EnvVar: true} + for _, k := range extra { + skip[k] = true + } src := os.Environ() env := make([]string, 0, len(src)) for _, e := range src { diff --git a/rpm/coverage-tools.spec b/rpm/coverage-tools.spec index 04f128d..b4b8f22 100644 --- a/rpm/coverage-tools.spec +++ b/rpm/coverage-tools.spec @@ -14,10 +14,10 @@ # Please submit bugfixes or comments via https://bugs.opensuse.org/ -%define bversion 0.7.1 +%define bversion 0.7.2 %define dname BinaryCoverage-%{bversion} Name: coverage-tools -Version: 0.7.1 +Version: 0.7.2 Release: 0 Summary: Tools to test binary coverage of different packages License: MIT AND GPL-2.0-only @@ -50,8 +50,8 @@ to generate HTML / XML / text coverage reports. %build export GOFLAGS="-buildmode=pie -trimpath -mod=vendor" -#mv %{_builddir}/vendor . -go build -ldflags="-s -w" -o funkoverage ./cmd/ +mv %{_builddir}/vendor . +go build -ldflags="-s -w -X main.versionString=%{version}" -o funkoverage ./cmd/ go build -ldflags="-s -w" -o funkoverage-shim ./cmd/shim_binary/ %check