Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: register extra information during build #390

Merged
merged 3 commits into from
Nov 15, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/e2e-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
go-version: 1.22.x
- name: Checkout code
uses: actions/checkout@v2
- name: Go build
Expand All @@ -33,5 +33,5 @@ jobs:
./goc build -o ./gocc .
- name: run e2e test
run: |
go get github.com/onsi/ginkgo/ginkgo
go install github.com/onsi/ginkgo/ginkgo
make e2e
4 changes: 2 additions & 2 deletions .github/workflows/e2e-wins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
go-version: 1.22.x
- name: Checkout code
uses: actions/checkout@v2
- name: Go build
Expand All @@ -33,5 +33,5 @@ jobs:
.\goc.exe build -o gocc .
- name: run e2e test
run: |
go get github.com/onsi/ginkgo/ginkgo
go install github.com/onsi/ginkgo/ginkgo
ginkgo tests/e2e/...
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
go-version: 1.22.x
- name: compile and release
run: |
./hack/release.sh
Expand All @@ -28,7 +28,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
go-version: 1.22.x
- name: compile and release
run: |
./hack/release.sh
Expand All @@ -45,7 +45,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
go-version: 1.22.x
- name: compile and release
run: |
./hack/release.sh
Expand All @@ -62,7 +62,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
go-version: 1.22.x
- name: compile and release
run: |
./hack/release.sh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/style_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: vet and gofmt
strategy:
matrix:
go-version: [1.16.x]
go-version: [1.22.x]
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ut-check-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: go test on windows
strategy:
matrix:
go-version: [1.16.x]
go-version: [1.22.x]
runs-on: windows-latest
steps:
- name: Install Go
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ut-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: go test on linux
strategy:
matrix:
go-version: [1.16.x]
go-version: [1.22.x]
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand Down
7 changes: 5 additions & 2 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ var buildCmd = &cobra.Command{
}

var (
gocmode string
gochost string
gocmode string
gochost string
gocextra string
)

func init() {
buildCmd.Flags().StringVarP(&gocmode, "gocmode", "", "count", "coverage mode: set, count, atomic, watch")
buildCmd.Flags().StringVarP(&gochost, "gochost", "", "127.0.0.1:7777", "specify the host of the goc sever")
buildCmd.Flags().StringVarP(&gocextra, "gocextra", "", "", "specify the extra information injected into the build")
rootCmd.AddCommand(buildCmd)
}

Expand All @@ -47,6 +49,7 @@ func buildAction(cmd *cobra.Command, args []string) {
build.WithArgs(args),
build.WithBuild(),
build.WithDebug(globalDebug),
build.WithExtra(gocextra),
)
b.Build()

Expand Down
2 changes: 2 additions & 0 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var installCmd = &cobra.Command{
func init() {
installCmd.Flags().StringVarP(&gocmode, "gocmode", "", "count", "coverage mode: set, count, atomic, watch")
installCmd.Flags().StringVarP(&gochost, "gochost", "", "127.0.0.1:7777", "specify the host of the goc sever")
installCmd.Flags().StringVarP(&gocextra, "gocextra", "", "", "specify the extra information injected into the build")
rootCmd.AddCommand(installCmd)
}

Expand All @@ -42,6 +43,7 @@ func installAction(cmd *cobra.Command, args []string) {
build.WithArgs(args),
build.WithInstall(),
build.WithDebug(globalDebug),
build.WithExtra(gocextra),
)
b.Install()

Expand Down
7 changes: 6 additions & 1 deletion pkg/build/agent.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var (
token string
id string
cond = sync.NewCond(&sync.Mutex{})
register_extra = os.Getenv("GOC_REGISTER_EXTRA")
register_extra = "{{.Extra}}"
)

func init() {
Expand All @@ -55,6 +55,11 @@ func init() {
host = host_env
}

// init extra information
if os.Getenv("GOC_REGISTER_EXTRA") != "" {
register_extra = os.Getenv("GOC_REGISTER_EXTRA")
}

var dialer = websocket.DefaultDialer

go func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Build struct {
Debug bool
Host string
Mode string // cover mode
Extra string

GOPATH string
GOBIN string
Expand All @@ -53,7 +54,6 @@ type Build struct {
}

// NewBuild creates a Build struct
//
func NewBuild(opts ...gocOption) *Build {
b := &Build{}

Expand Down
8 changes: 8 additions & 0 deletions pkg/build/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package build

import (
"strings"

"github.com/spf13/pflag"
)

Expand Down Expand Up @@ -60,3 +62,9 @@ func WithDebug(enable bool) gocOption {
b.Debug = enable
}
}

func WithExtra(extra string) gocOption {
return func(b *Build) {
b.Extra = strings.TrimSpace(extra)
}
}
18 changes: 10 additions & 8 deletions pkg/build/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ func (b *Build) getPkgTmpDir(pkgDir string) string {

// injectGocAgent inject handlers like following
//
// - xxx.go
// - yyy_package
// - main.go
// - goc-cover-agent-apis-auto-generated-11111-22222-bridge.go
// - goc-cover-agent-apis-auto-generated-11111-22222-package
// |
// -- rpcagent.go
// -- watchagent.go
// - xxx.go
// - yyy_package
// - main.go
// - goc-cover-agent-apis-auto-generated-11111-22222-bridge.go
// - goc-cover-agent-apis-auto-generated-11111-22222-package
// |
// -- rpcagent.go
// -- watchagent.go
//
// 11111_22222_bridge.go 仅仅用于引用 11111_22222_package, where package contains ws agent main logic.
// 使用 bridge.go 文件是为了避免插桩逻辑中的变量名污染 main 包
Expand Down Expand Up @@ -195,12 +195,14 @@ func (b *Build) injectGocAgent(where string, covers []*PackageCover) {
Package string
Host string
Mode string
Extra string
}{
Covers: covers,
GlobalCoverVarImportPath: b.GlobalCoverVarImportPath,
Package: injectPkgName,
Host: b.Host,
Mode: _coverMode,
Extra: b.Extra,
}

if err := coverMainTmpl.Execute(f2, tmplData); err != nil {
Expand Down
Loading