Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ CLAUDE.md
*.o
!cmd/shim_binary/tracer_x86_bpfel.o
!cmd/shim_binary/tracer_arm64_bpfel.o
shim_binary
6 changes: 4 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion cmd/funkoverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 24 additions & 7 deletions cmd/shim_binary/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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",
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions rpm/coverage-tools.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down