Only add darwin specific rules/variables when building on mac.
To support skipping ninja file writing during incremental build, we
add all the global rules/variable/pools from static sources because
when we restore from cache we don't have the build defs available to
build the globals. This means all the global rules and variables are
added blindly, so we need to exclude these darwin specific ones since
they will fail due to they depends on the tool that only exists on MAC.
Bug: 335718784
Test: local tests and CI
Change-Id: Ife835545f0f76ffaec77e48bdd89ab7384a1b995
diff --git a/cc/builder.go b/cc/builder.go
index 367bda3..a05a16d 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -156,11 +156,17 @@
"args")
// Rule to invoke `strip` (to discard symbols and data from object files) on darwin architecture.
- darwinStrip = pctx.AndroidStaticRule("darwinStrip",
- blueprint.RuleParams{
- Command: "${config.MacStripPath} -u -r -o $out $in",
- CommandDeps: []string{"${config.MacStripPath}"},
- })
+ darwinStrip = func() blueprint.Rule {
+ if runtime.GOOS == "darwin" {
+ return pctx.AndroidStaticRule("darwinStrip",
+ blueprint.RuleParams{
+ Command: "${config.MacStripPath} -u -r -o $out $in",
+ CommandDeps: []string{"${config.MacStripPath}"},
+ })
+ } else {
+ return nil
+ }
+ }()
// b/132822437: objcopy uses a file descriptor per .o file when called on .a files, which runs the system out of
// file descriptors on darwin. Limit concurrent calls to 5 on darwin.
@@ -174,11 +180,17 @@
}
}()
- darwinLipo = pctx.AndroidStaticRule("darwinLipo",
- blueprint.RuleParams{
- Command: "${config.MacLipoPath} -create -output $out $in",
- CommandDeps: []string{"${config.MacLipoPath}"},
- })
+ darwinLipo = func() blueprint.Rule {
+ if runtime.GOOS == "darwin" {
+ return pctx.AndroidStaticRule("darwinLipo",
+ blueprint.RuleParams{
+ Command: "${config.MacLipoPath} -create -output $out $in",
+ CommandDeps: []string{"${config.MacLipoPath}"},
+ })
+ } else {
+ return nil
+ }
+ }()
_ = pctx.SourcePathVariable("archiveRepackPath", "build/soong/scripts/archive_repack.sh")