Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone committed Feb 1, 2024
1 parent e984ee7 commit 50118ed
Show file tree
Hide file tree
Showing 22 changed files with 42 additions and 73 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/goversion.yml

This file was deleted.

4 changes: 3 additions & 1 deletion internal/cmd/buildtool/android.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func androidSubcommand() *cobra.Command {
// androidBuildGomobile invokes the gomobile build.
func androidBuildGomobile(deps buildtoolmodel.Dependencies) {
deps.PsiphonMaybeCopyConfigFiles()
deps.GolangCheck()

androidHome := deps.AndroidSDKCheck()
ndkDir := deps.AndroidNDKCheck(androidHome)
Expand Down Expand Up @@ -145,6 +146,7 @@ func androidNDKCheck(androidHome string) string {
// androidBuildCLIAll builds all products in CLI mode for Android
func androidBuildCLIAll(deps buildtoolmodel.Dependencies) {
deps.PsiphonMaybeCopyConfigFiles()
deps.GolangCheck()

androidHome := deps.AndroidSDKCheck()
ndkDir := deps.AndroidNDKCheck(androidHome)
Expand Down Expand Up @@ -175,7 +177,7 @@ func androidBuildCLIProductArch(

log.Infof("building %s for android/%s", product.Pkg, ooniArch)

argv := runtimex.Try1(shellx.NewArgv(deps.GolangBinary(), "build"))
argv := runtimex.Try1(shellx.NewArgv("go", "build"))
if deps.PsiphonFilesExist() {
argv.Append("-tags", "ooni_psiphon_config,ooni_libtor")
} else {
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/buildtool/android_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestAndroidBuildGomobile(t *testing.T) {
buildtooltest.TagGOPATH: 2,
buildtooltest.TagAndroidNDKCheck: 1,
buildtooltest.TagAndroidSDKCheck: 1,
buildtooltest.TagGolangBinary: 3,
buildtooltest.TagGolangCheck: 1,
buildtooltest.TagPsiphonMaybeCopyConfigFiles: 1,
buildtooltest.TagPsiphonFilesExist: 1,
}
Expand Down Expand Up @@ -406,7 +406,7 @@ func TestAndroidBuildCLIAll(t *testing.T) {
expectCalls := map[string]int{
buildtooltest.TagAndroidNDKCheck: 1,
buildtooltest.TagAndroidSDKCheck: 1,
buildtooltest.TagGolangBinary: 8,
buildtooltest.TagGolangCheck: 1,
buildtooltest.TagPsiphonMaybeCopyConfigFiles: 1,
buildtooltest.TagPsiphonFilesExist: 8,
}
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/buildtool/builddeps.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ func (*buildDeps) GOPATH() string {
return golangGOPATH()
}

// GolangBinary implements buildtoolmodel.Dependencies
func (*buildDeps) GolangBinary() string {
return golangBinary()
// GolangCheck implements buildtoolmodel.Dependencies
func (*buildDeps) GolangCheck() {
golangCheck("GOVERSION")
}

// LinuxReadGOVERSION implements buildtoolmodel.Dependencies
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/buildtool/darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func darwinSubcommand() *cobra.Command {
// darwinBuildAll builds all the packages for darwin.
func darwinBuildAll(deps buildtoolmodel.Dependencies) {
deps.PsiphonMaybeCopyConfigFiles()
deps.GolangCheck()
archs := []string{"amd64", "arm64"}
products := []*product{productMiniooni, productOoniprobe}
for _, arch := range archs {
Expand All @@ -40,7 +41,7 @@ func darwinBuildAll(deps buildtoolmodel.Dependencies) {
func darwinBuildPackage(deps buildtoolmodel.Dependencies, goarch string, product *product) {
log.Infof("building %s for darwin/%s", product.Pkg, goarch)

argv := runtimex.Try1(shellx.NewArgv(deps.GolangBinary(), "build"))
argv := runtimex.Try1(shellx.NewArgv("go", "build"))
if deps.PsiphonFilesExist() {
argv.Append("-tags", "ooni_psiphon_config")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/buildtool/darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestDarwinBuildAll(t *testing.T) {
})

expectCalls := map[string]int{
buildtooltest.TagGolangBinary: 4,
buildtooltest.TagGolangCheck: 1,
buildtooltest.TagPsiphonMaybeCopyConfigFiles: 1,
buildtooltest.TagPsiphonFilesExist: 4,
}
Expand Down
6 changes: 4 additions & 2 deletions internal/cmd/buildtool/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ func genericSubcommand() *cobra.Command {
// genericBuildPackage is the generic function for building a package.
func genericBuildPackage(deps buildtoolmodel.Dependencies, product *product) {
deps.PsiphonMaybeCopyConfigFiles()
deps.GolangCheck()

log.Infof("building %s for %s/%s", product.Pkg, runtime.GOOS, runtime.GOARCH)

argv := runtimex.Try1(shellx.NewArgv(deps.GolangBinary(), "build"))
argv := runtimex.Try1(shellx.NewArgv("go", "build"))
if deps.PsiphonFilesExist() {
argv.Append("-tags", "ooni_psiphon_config")
}
Expand All @@ -66,6 +67,7 @@ func genericBuildPackage(deps buildtoolmodel.Dependencies, product *product) {

// genericBuildLibrary is the generic function for building a library.
func genericBuildLibrary(deps buildtoolmodel.Dependencies, product *product) {
deps.GolangCheck()
os := deps.GOOS()

log.Infof("building %s for %s/%s", product.Pkg, os, runtime.GOARCH)
Expand All @@ -74,7 +76,7 @@ func genericBuildLibrary(deps buildtoolmodel.Dependencies, product *product) {
// packages paths are separated by forward slashes!
library := runtimex.Try1(generateLibrary(path.Base(product.Pkg), os))

argv := runtimex.Try1(shellx.NewArgv(deps.GolangBinary(), "build"))
argv := runtimex.Try1(shellx.NewArgv("go", "build"))
argv.Append("-buildmode", "c-shared")
argv.Append("-o", library)
argv.Append(product.Pkg)
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/buildtool/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestGenericBuildPackage(t *testing.T) {
})

expectCalls := map[string]int{
buildtooltest.TagGolangBinary: 1,
buildtooltest.TagGolangCheck: 1,
buildtooltest.TagPsiphonMaybeCopyConfigFiles: 1,
buildtooltest.TagPsiphonFilesExist: 1,
}
Expand Down Expand Up @@ -164,8 +164,8 @@ func TestCheckGenericBuildLibrary(t *testing.T) {
})

expectCalls := map[string]int{
buildtooltest.TagGolangBinary: 1,
buildtooltest.TagGOOS: 1,
buildtooltest.TagGolangCheck: 1,
buildtooltest.TagGOOS: 1,
}

if diff := cmp.Diff(expectCalls, deps.Counter); diff != "" {
Expand Down
5 changes: 0 additions & 5 deletions internal/cmd/buildtool/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ package main
//

import (
"fmt"
"path/filepath"
"strings"
"sync"

"github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/must"
Expand All @@ -18,8 +15,6 @@ import (
// golangCorrectVersionCheckP returns whether we're using the correct golang version.
func golangCorrectVersionCheckP(filename string) bool {
expected := string(must.FirstLineBytes(must.ReadFile(filename)))

// read the version of go that we're using
firstline := string(must.FirstLineBytes(must.RunOutput(log.Log, "go", "version")))
vec := strings.Split(firstline, " ")
runtimex.Assert(len(vec) == 4, "expected four tokens")
Expand Down
5 changes: 1 addition & 4 deletions internal/cmd/buildtool/golang_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package main

import (
"os"
"path/filepath"
"testing"

"github.com/ooni/probe-cli/v3/internal/must"
"github.com/ooni/probe-cli/v3/internal/runtimex"
)

func TestGolangCheck(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/buildtool/gomobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ type gomobileConfig struct {
// gomobileBuild runs a build based on gomobile.
func gomobileBuild(config *gomobileConfig) {
// Undoes the effects of go-getting golang.org/x/mobile/cmd/gomobile
defer must.Run(log.Log, config.deps.GolangBinary(), "mod", "tidy")
defer must.Run(log.Log, "go", "mod", "tidy")

must.Run(log.Log, config.deps.GolangBinary(), "install", "golang.org/x/mobile/cmd/gomobile@latest")
must.Run(log.Log, "go", "install", "golang.org/x/mobile/cmd/gomobile@latest")

gopath := config.deps.GOPATH()
gomobile := filepath.Join(gopath, "bin", "gomobile")
must.Run(log.Log, gomobile, "init")

// Adding gomobile to go.mod as documented by golang.org/wiki/Mobile
must.Run(log.Log, config.deps.GolangBinary(), "get", "-d", "golang.org/x/mobile/cmd/gomobile")
must.Run(log.Log, "go", "get", "-d", "golang.org/x/mobile/cmd/gomobile")

argv := runtimex.Try1(shellx.NewArgv(gomobile, "bind"))
argv.Append("-target", config.target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ type Dependencies interface {
// GOPATH returns the current GOPATH.
GOPATH() string

// GolangBinary returns the golang binary to use.
GolangBinary() string
// GolangCheck ensures we have the correct
// version of golang as the "go" binary.
GolangCheck()

// LinuxWriteDockerfile writes the dockerfile for linux.
LinuxWriteDockerfile(filename string, content []byte, mode fs.FileMode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const (
TagAndroidNDKCheck = "androidNDK"
TagAndroidSDKCheck = "androidSDK"
TagGOPATH = "GOPATH"
TagGolangBinary = "golangBinary"
TagGolangCheck = "golangCheck"
TagLinuxReadGOVERSION = "linuxReadGOVERSION"
TagLinuxWriteDockerfile = "linuxWriteDockerfile"
TagMustChdir = "mustChdir"
Expand Down Expand Up @@ -188,9 +188,8 @@ func (cc *DependenciesCallCounter) GOPATH() string {
}

// golangCheck implements buildtoolmodel.Dependencies
func (cc *DependenciesCallCounter) GolangBinary() string {
cc.increment(TagGolangBinary)
return "go"
func (cc *DependenciesCallCounter) GolangCheck() {
cc.increment(TagGolangCheck)
}

// linuxReadGOVERSION implements buildtoolmodel.Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,10 @@ func TestDependenciesCallCounter(t *testing.T) {

t.Run("GolangCheck", func(t *testing.T) {
cc := &DependenciesCallCounter{}
value := cc.GolangBinary()
if cc.Counter[TagGolangBinary] != 1 {
cc.GolangCheck()
if cc.Counter[TagGolangCheck] != 1 {
t.Fatal("did not increment")
}
if value != "go" {
t.Fatal("expected 'go', got", value)
}
})

t.Run("LinuxReadGOVERSION", func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/buildtool/ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func iosSubcommand() *cobra.Command {
// iosBuildGomobile invokes the gomobile build.
func iosBuildGomobile(deps buildtoolmodel.Dependencies) {
deps.PsiphonMaybeCopyConfigFiles()
deps.GolangCheck()

config := &gomobileConfig{
deps: deps,
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/buildtool/ios_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestIOSBuildGomobile(t *testing.T) {

expectCalls := map[string]int{
buildtooltest.TagGOPATH: 1,
buildtooltest.TagGolangBinary: 3,
buildtooltest.TagGolangCheck: 1,
buildtooltest.TagPsiphonMaybeCopyConfigFiles: 1,
buildtooltest.TagPsiphonFilesExist: 1,
}
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/buildtool/linuxstatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (b *linuxStaticBuilder) main(*cobra.Command, []string) {
// linuxStaticBuildAll builds all the packages on a linux-static environment.
func linuxStaticBuilAll(deps buildtoolmodel.Dependencies, goarch string, goarm int64) {
deps.PsiphonMaybeCopyConfigFiles()
deps.GolangCheck()

// TODO(bassosimone): I am running the container with the right userID but
// apparently this is not enough to make git happy--why?
Expand All @@ -72,7 +73,7 @@ func linuxStaticBuildPackage(

ooniArch := linuxStaticBuildOONIArch(goarch, goarm)

argv := runtimex.Try1(shellx.NewArgv(deps.GolangBinary(), "build"))
argv := runtimex.Try1(shellx.NewArgv("go", "build"))
if deps.PsiphonFilesExist() {
argv.Append("-tags", "ooni_psiphon_config")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/buildtool/linuxstatic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func TestLinuxStaticBuildAll(t *testing.T) {
})

expectCalls := map[string]int{
buildtooltest.TagGolangBinary: 2,
buildtooltest.TagGolangCheck: 1,
buildtooltest.TagPsiphonMaybeCopyConfigFiles: 1,
buildtooltest.TagPsiphonFilesExist: 2,
}
Expand Down
4 changes: 3 additions & 1 deletion internal/cmd/buildtool/oohelperd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func oohelperdSubcommand() *cobra.Command {
// oohelperdBuildAndMaybeDeploy builds oohelperd for linux/amd64 and
// possibly deploys the build to the 0.th.ooni.org server.
func oohelperdBuildAndMaybeDeploy(deps buildtoolmodel.Dependencies, deploy bool) {
deps.GolangCheck()

log.Info("building oohelperd for linux/amd64")
oohelperdBinary := filepath.Join("CLI", "oohelperd-linux-amd64")

Expand All @@ -50,7 +52,7 @@ func oohelperdBuildAndMaybeDeploy(deps buildtoolmodel.Dependencies, deploy bool)
envp.Append("GOOS", "linux")
envp.Append("GOARCH", "amd64")

argv := runtimex.Try1(shellx.NewArgv(deps.GolangBinary(), "build"))
argv := runtimex.Try1(shellx.NewArgv("go", "build"))
argv.Append("-o", oohelperdBinary)
argv.Append("-tags", "netgo")
argv.Append("-ldflags", "-s -w -extldflags -static")
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/buildtool/oohelperd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestOohelperdBuildAndMaybeDeploy(t *testing.T) {
})

expectCalls := map[string]int{
buildtooltest.TagGolangBinary: 1,
buildtooltest.TagGolangCheck: 1,
}

if diff := cmp.Diff(expectCalls, deps.Counter); diff != "" {
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/buildtool/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func windowsSubcommand() *cobra.Command {
// windowsBuildAll is the main function of the windows subcommand.
func windowsBuildAll(deps buildtoolmodel.Dependencies) {
deps.PsiphonMaybeCopyConfigFiles()
deps.GolangCheck()
deps.WindowsMingwCheck()
archs := []string{"386", "amd64"}
products := []*product{productMiniooni, productOoniprobe}
Expand All @@ -47,7 +48,7 @@ func windowsBuildAll(deps buildtoolmodel.Dependencies) {
func windowsBuildPackage(deps buildtoolmodel.Dependencies, goarch string, product *product) {
log.Infof("building %s for windows/%s", product.Pkg, goarch)

argv := runtimex.Try1(shellx.NewArgv(deps.GolangBinary(), "build"))
argv := runtimex.Try1(shellx.NewArgv("go", "build"))
if deps.PsiphonFilesExist() {
argv.Append("-tags", "ooni_psiphon_config")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/buildtool/windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestWindowsBuildAll(t *testing.T) {
})

expectCalls := map[string]int{
buildtooltest.TagGolangBinary: 4,
buildtooltest.TagGolangCheck: 1,
buildtooltest.TagPsiphonMaybeCopyConfigFiles: 1,
buildtooltest.TagPsiphonFilesExist: 4,
buildtooltest.TagWindowsMingwCheck: 1,
Expand Down

0 comments on commit 50118ed

Please sign in to comment.