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

chore(buildtool): add ios-build unit tests #1371

Merged
merged 5 commits into from
Oct 12, 2023
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
32 changes: 18 additions & 14 deletions internal/cmd/buildtool/android.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func androidSubcommand() *cobra.Command {
Use: "gomobile",
Short: "Builds oonimkall for android using gomobile",
Run: func(cmd *cobra.Command, args []string) {
// Implementation note: perform the check here such that we can
// run unit test for the building code from any system
runtimex.Assert(
runtime.GOOS == "darwin" || runtime.GOOS == "linux",
"this command requires darwin or linux",
)
androidBuildGomobile(&buildDeps{})
},
})
Expand All @@ -39,6 +45,12 @@ func androidSubcommand() *cobra.Command {
Use: "cli",
Short: "Builds ooniprobe and miniooni for usage within termux",
Run: func(cmd *cobra.Command, args []string) {
// Implementation note: perform the check here such that we can
// run unit test for the building code from any system
runtimex.Assert(
runtime.GOOS == "darwin" || runtime.GOOS == "linux",
"this command requires darwin or linux",
)
androidBuildCLIAll(&buildDeps{})
},
})
Expand All @@ -48,6 +60,12 @@ func androidSubcommand() *cobra.Command {
Short: "Cross compiles C dependencies for Android",
Run: func(cmd *cobra.Command, args []string) {
for _, arg := range args {
// Implementation note: perform the check here such that we can
// run unit test for the building code from any system
runtimex.Assert(
runtime.GOOS == "darwin" || runtime.GOOS == "linux",
"this command requires darwin or linux",
)
androidCdepsBuildMain(arg, &buildDeps{})
}
},
Expand All @@ -59,11 +77,6 @@ func androidSubcommand() *cobra.Command {

// androidBuildGomobile invokes the gomobile build.
func androidBuildGomobile(deps buildtoolmodel.Dependencies) {
runtimex.Assert(
runtime.GOOS == "darwin" || runtime.GOOS == "linux",
"this command requires darwin or linux",
)

deps.PsiphonMaybeCopyConfigFiles()
deps.GolangCheck()

Expand Down Expand Up @@ -132,11 +145,6 @@ func androidNDKCheck(androidHome string) string {

// androidBuildCLIAll builds all products in CLI mode for Android
func androidBuildCLIAll(deps buildtoolmodel.Dependencies) {
runtimex.Assert(
runtime.GOOS == "darwin" || runtime.GOOS == "linux",
"this command requires darwin or linux",
)

deps.PsiphonMaybeCopyConfigFiles()
deps.GolangCheck()

Expand Down Expand Up @@ -379,10 +387,6 @@ func androidNDKBinPath(ndkDir string) string {

// androidCdepsBuildMain builds C dependencies for android.
func androidCdepsBuildMain(name string, deps buildtoolmodel.Dependencies) {
runtimex.Assert(
runtime.GOOS == "darwin" || runtime.GOOS == "linux",
"this command requires darwin or linux",
)
androidHome := deps.AndroidSDKCheck()
ndkDir := deps.AndroidNDKCheck(androidHome)
archs := []string{"arm", "arm64", "386", "amd64"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func CheckSingleCommand(cmd *execabs.Cmd, tee ExecExpectations) error {
return err
}
if err := CompareEnv(tee.Env, shellxtesting.CmdEnvironMinusOsEnviron(cmd)); err != nil {
return err
return fmt.Errorf("in %v: %w", tee.Argv, err)
}
return nil
}
Expand Down Expand Up @@ -253,12 +253,12 @@ func (*DependenciesCallCounter) XCRun(args ...string) string {
case "-sdk":
runtimex.Assert(len(args) == 3, "expected three arguments")
runtimex.Assert(args[2] == "--show-sdk-path", "the third argument must be --show-sdk-path")
return filepath.Join("Developer", "SDKs", args[1])
return string(filepath.Separator) + filepath.Join("Developer", "SDKs", args[1])

case "-find":
runtimex.Assert(len(args) == 4, "expected four arguments")
runtimex.Assert(args[1] == "-sdk", "the second argument must be -sdk")
return filepath.Join("Developer", "SDKs", args[2], "bin", args[3])
return string(filepath.Separator) + filepath.Join("Developer", "SDKs", args[2], "bin", args[3])

default:
panic(errors.New("the first argument must be -sdk or -find"))
Expand Down
7 changes: 4 additions & 3 deletions internal/cmd/buildtool/ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func iosSubcommand() *cobra.Command {
Use: "cdeps [zlib|openssl|libevent|tor...]",
Short: "Cross compiles C dependencies for iOS",
Run: func(cmd *cobra.Command, args []string) {
// Implementation note: perform the check here such that we can
// run unit test for the building code from any system
runtimex.Assert(runtime.GOOS == "darwin", "this command requires darwin")
for _, arg := range args {
iosCdepsBuildMain(arg, &buildDeps{})
}
Expand Down Expand Up @@ -66,8 +69,6 @@ func iosBuildGomobile(deps buildtoolmodel.Dependencies) {

// iosCdepsBuildMain builds C dependencies for ios.
func iosCdepsBuildMain(name string, deps buildtoolmodel.Dependencies) {
runtimex.Assert(runtime.GOOS == "darwin", "this command requires darwin")

// The ooni/probe-ios app explicitly only targets amd64 and arm64. It also targets
// as the minimum version iOS 12, while one cannot target a version of iOS > 10 when
// building for 32-bit targets. Hence, using only 64 bit archs here is fine.
Expand Down Expand Up @@ -150,9 +151,9 @@ func iosNewCBuildEnv(deps buildtoolmodel.Dependencies, ooniArch string) *cBuildE
CFLAGS: []string{
"-isysroot", isysroot,
minVersionFlag + iosMinVersion, // tricky: they must be concatenated
"-O2",
"-arch", appleArch,
"-fembed-bitcode",
"-O2",
},
CONFIGURE_HOST: "", // later
DESTDIR: destdir,
Expand Down
Loading