-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(buildtool): merge cdeps and android build envs
At the end of the day, there's just a unique kind of build env that makes sense for both cdeps and android. While there, write better code for merging global and local environment and make sure we have unit tests for that. See ooni/probe#2401
- Loading branch information
1 parent
2b2d9e0
commit 522fb7b
Showing
9 changed files
with
159 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package main | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/ooni/probe-cli/v3/internal/shellx" | ||
) | ||
|
||
// cBuildEnv describes the C build environment. We use | ||
// this structure for more complex C and CGO builds. | ||
type cBuildEnv struct { | ||
// binpath is the path containing the C and C++ compilers. | ||
binpath string | ||
|
||
// cc is the full path to the C compiler. | ||
cc string | ||
|
||
// cflags contains the extra CFLAGS to set. | ||
cflags []string | ||
|
||
// configureHost is the value to pass to ./configure's --host option. | ||
configureHost string | ||
|
||
// destdir is the directory where to install. | ||
destdir string | ||
|
||
// cxx is the full path to the CXX compiler. | ||
cxx string | ||
|
||
// cxxflags contains the extra CXXFLAGS to set. | ||
cxxflags []string | ||
|
||
// goarch is the GOARCH we're building for. | ||
goarch string | ||
|
||
// goarm is the GOARM subarchitecture. | ||
goarm string | ||
|
||
// lfdlags contains the LDFLAGS to use when compiling. | ||
ldflags []string | ||
|
||
// openSSLAPIDefine is an extra define we need to add on Android. | ||
openSSLAPIDefine string | ||
|
||
// openSSLCompiler is the compiler name for OpenSSL. | ||
openSSLCompiler string | ||
} | ||
|
||
// cBuildExportEnviron merges the gloval and the local c build environment | ||
// to produce the environment variables to export for the build. More specifically, | ||
// this appends the local variables to the remote variables for any string slice | ||
// type inside [cBuildEnv]. We ignore all the other variables. | ||
func cBuildExportEnviron(global, local *cBuildEnv) *shellx.Envp { | ||
envp := &shellx.Envp{} | ||
|
||
cflags := append([]string{}, global.cflags...) | ||
cflags = append(cflags, local.cflags...) | ||
envp.Append("CFLAGS", strings.Join(cflags, " ")) | ||
|
||
cxxflags := append([]string{}, global.cxxflags...) | ||
cxxflags = append(cxxflags, local.cxxflags...) | ||
envp.Append("CXXFLAGS", strings.Join(cxxflags, " ")) | ||
|
||
ldflags := append([]string{}, global.ldflags...) | ||
ldflags = append(ldflags, local.ldflags...) | ||
envp.Append("LDFLAGS", strings.Join(ldflags, " ")) | ||
|
||
return envp | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestCBuildEnv(t *testing.T) { | ||
t.Run("we can correctly merge build flags", func(t *testing.T) { | ||
global := &cBuildEnv{ | ||
cflags: []string{"a", "b", "c"}, | ||
cxxflags: []string{"A", "B", "C"}, | ||
ldflags: []string{"1", "2", "3"}, | ||
} | ||
local := &cBuildEnv{ | ||
cflags: []string{"d", "e"}, | ||
cxxflags: []string{"D", "E"}, | ||
ldflags: []string{"4", "5"}, | ||
} | ||
envp := cBuildExportEnviron(global, local) | ||
expected := []string{ | ||
"CFLAGS=a b c d e", | ||
"CXXFLAGS=A B C D E", | ||
"LDFLAGS=1 2 3 4 5", | ||
} | ||
if diff := cmp.Diff(expected, envp.V); diff != "" { | ||
t.Fatal(diff) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.