Enable goma in soong

When the UseGoma flag is set, put all rules except the C compilation
rule in an externally defined local_pool, which will have been created
by kati.  The gomacc wrapper will already be in the CC_WRAPPER
environment variable.

Bug: 31142427
Change-Id: I699d4edff2e302eee398dad8692ceb14721a628c
This commit is contained in:
Colin Cross
2016-08-29 16:14:13 -07:00
parent 3cfaba1654
commit 9d45bb78c5
11 changed files with 74 additions and 34 deletions

View File

@@ -369,6 +369,10 @@ func (c *config) Android64() bool {
return false return false
} }
func (c *config) UseGoma() bool {
return Bool(c.ProductVariables.UseGoma)
}
func (c *config) LibartImgHostBaseAddress() string { func (c *config) LibartImgHostBaseAddress() string {
return "0x60000000" return "0x60000000"
} }

View File

@@ -28,7 +28,7 @@ var (
// A phony rule that is not the built-in Ninja phony rule. The built-in // A phony rule that is not the built-in Ninja phony rule. The built-in
// phony rule has special behavior that is sometimes not desired. See the // phony rule has special behavior that is sometimes not desired. See the
// Ninja docs for more details. // Ninja docs for more details.
Phony = pctx.StaticRule("Phony", Phony = pctx.AndroidStaticRule("Phony",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "# phony $out", Command: "# phony $out",
Description: "phony $out", Description: "phony $out",
@@ -37,7 +37,7 @@ var (
// GeneratedFile is a rule for indicating that a given file was generated // GeneratedFile is a rule for indicating that a given file was generated
// while running soong. This allows the file to be cleaned up if it ever // while running soong. This allows the file to be cleaned up if it ever
// stops being generated by soong. // stops being generated by soong.
GeneratedFile = pctx.StaticRule("GeneratedFile", GeneratedFile = pctx.AndroidStaticRule("GeneratedFile",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "# generated $out", Command: "# generated $out",
Description: "generated $out", Description: "generated $out",
@@ -45,7 +45,7 @@ var (
}) })
// A copy rule. // A copy rule.
Cp = pctx.StaticRule("Cp", Cp = pctx.AndroidStaticRule("Cp",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "cp $cpPreserveSymlinks $cpFlags $in $out", Command: "cp $cpPreserveSymlinks $cpFlags $in $out",
Description: "cp $out", Description: "cp $out",
@@ -53,26 +53,29 @@ var (
"cpFlags") "cpFlags")
// A timestamp touch rule. // A timestamp touch rule.
Touch = pctx.StaticRule("Touch", Touch = pctx.AndroidStaticRule("Touch",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "touch $out", Command: "touch $out",
Description: "touch $out", Description: "touch $out",
}) })
// A symlink rule. // A symlink rule.
Symlink = pctx.StaticRule("Symlink", Symlink = pctx.AndroidStaticRule("Symlink",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "ln -f -s $fromPath $out", Command: "ln -f -s $fromPath $out",
Description: "symlink $out", Description: "symlink $out",
}, },
"fromPath") "fromPath")
ErrorRule = pctx.StaticRule("Error", ErrorRule = pctx.AndroidStaticRule("Error",
blueprint.RuleParams{ blueprint.RuleParams{
Command: `echo "$error" && false`, Command: `echo "$error" && false`,
Description: "error building $out", Description: "error building $out",
}, },
"error") "error")
// Used only when USE_GOMA=true is set, to restrict non-goma jobs to the local parallelism value
localPool = blueprint.NewBuiltinPool("local_pool")
) )
func init() { func init() {

View File

@@ -43,7 +43,7 @@ var (
// globRule rule traverses directories to produce a list of files that match $glob // globRule rule traverses directories to produce a list of files that match $glob
// and writes it to $out if it has changed, and writes the directories to $out.d // and writes it to $out if it has changed, and writes the directories to $out.d
globRule = pctx.StaticRule("globRule", globRule = pctx.AndroidStaticRule("globRule",
blueprint.RuleParams{ blueprint.RuleParams{
Command: fmt.Sprintf(`%s -o $out $excludes "$glob"`, globCmd), Command: fmt.Sprintf(`%s -o $out $excludes "$glob"`, globCmd),
CommandDeps: []string{globCmd}, CommandDeps: []string{globCmd},

View File

@@ -131,3 +131,35 @@ func (p AndroidPackageContext) PrefixedPathsForOptionalSourceVariable(
return JoinWithPrefix(paths.Strings(), prefix), nil return JoinWithPrefix(paths.Strings(), prefix), nil
}) })
} }
type RuleParams struct {
blueprint.RuleParams
GomaSupported bool
}
// AndroidStaticRule wraps blueprint.StaticRule and provides a default Pool if none is specified
func (p AndroidPackageContext) AndroidStaticRule(name string, params blueprint.RuleParams,
argNames ...string) blueprint.Rule {
return p.AndroidRuleFunc(name, func(interface{}) (blueprint.RuleParams, error) {
return params, nil
}, argNames...)
}
// AndroidGomaStaticRule wraps blueprint.StaticRule but uses goma's parallelism if goma is enabled
func (p AndroidPackageContext) AndroidGomaStaticRule(name string, params blueprint.RuleParams,
argNames ...string) blueprint.Rule {
return p.StaticRule(name, params, argNames...)
}
func (p AndroidPackageContext) AndroidRuleFunc(name string,
f func(interface{}) (blueprint.RuleParams, error), argNames ...string) blueprint.Rule {
return p.PackageContext.RuleFunc(name, func(config interface{}) (blueprint.RuleParams, error) {
params, err := f(config)
if config.(Config).UseGoma() && params.Pool == nil {
// When USE_GOMA=true is set and the rule is not supported by goma, restrict jobs to the
// local parallelism value
params.Pool = localPool
}
return params, err
}, argNames...)
}

View File

@@ -101,6 +101,7 @@ type productVariables struct {
Cpusets *bool `json:",omitempty"` Cpusets *bool `json:",omitempty"`
Schedboost *bool `json:",omitempty"` Schedboost *bool `json:",omitempty"`
Binder32bit *bool `json:",omitempty"` Binder32bit *bool `json:",omitempty"`
UseGoma *bool `json:",omitempty"`
DevicePrefer32BitExecutables *bool `json:",omitempty"` DevicePrefer32BitExecutables *bool `json:",omitempty"`
HostPrefer32BitExecutables *bool `json:",omitempty"` HostPrefer32BitExecutables *bool `json:",omitempty"`

View File

@@ -39,7 +39,7 @@ const (
var ( var (
pctx = android.NewPackageContext("android/soong/cc") pctx = android.NewPackageContext("android/soong/cc")
cc = pctx.StaticRule("cc", cc = pctx.AndroidGomaStaticRule("cc",
blueprint.RuleParams{ blueprint.RuleParams{
Depfile: "${out}.d", Depfile: "${out}.d",
Deps: blueprint.DepsGCC, Deps: blueprint.DepsGCC,
@@ -49,7 +49,7 @@ var (
}, },
"ccCmd", "cFlags") "ccCmd", "cFlags")
ld = pctx.StaticRule("ld", ld = pctx.AndroidStaticRule("ld",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "$ldCmd ${crtBegin} @${out}.rsp " + Command: "$ldCmd ${crtBegin} @${out}.rsp " +
"${libFlags} ${crtEnd} -o ${out} ${ldFlags}", "${libFlags} ${crtEnd} -o ${out} ${ldFlags}",
@@ -60,7 +60,7 @@ var (
}, },
"ldCmd", "crtBegin", "libFlags", "crtEnd", "ldFlags") "ldCmd", "crtBegin", "libFlags", "crtEnd", "ldFlags")
partialLd = pctx.StaticRule("partialLd", partialLd = pctx.AndroidStaticRule("partialLd",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "$ldCmd -nostdlib -Wl,-r ${in} -o ${out} ${ldFlags}", Command: "$ldCmd -nostdlib -Wl,-r ${in} -o ${out} ${ldFlags}",
CommandDeps: []string{"$ldCmd"}, CommandDeps: []string{"$ldCmd"},
@@ -68,7 +68,7 @@ var (
}, },
"ldCmd", "ldFlags") "ldCmd", "ldFlags")
ar = pctx.StaticRule("ar", ar = pctx.AndroidStaticRule("ar",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "rm -f ${out} && $arCmd $arFlags $out @${out}.rsp", Command: "rm -f ${out} && $arCmd $arFlags $out @${out}.rsp",
CommandDeps: []string{"$arCmd"}, CommandDeps: []string{"$arCmd"},
@@ -78,7 +78,7 @@ var (
}, },
"arCmd", "arFlags") "arCmd", "arFlags")
darwinAr = pctx.StaticRule("darwinAr", darwinAr = pctx.AndroidStaticRule("darwinAr",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "rm -f ${out} && ${config.MacArPath} $arFlags $out $in", Command: "rm -f ${out} && ${config.MacArPath} $arFlags $out $in",
CommandDeps: []string{"${config.MacArPath}"}, CommandDeps: []string{"${config.MacArPath}"},
@@ -86,7 +86,7 @@ var (
}, },
"arFlags") "arFlags")
darwinAppendAr = pctx.StaticRule("darwinAppendAr", darwinAppendAr = pctx.AndroidStaticRule("darwinAppendAr",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "cp -f ${inAr} ${out}.tmp && ${config.MacArPath} $arFlags ${out}.tmp $in && mv ${out}.tmp ${out}", Command: "cp -f ${inAr} ${out}.tmp && ${config.MacArPath} $arFlags ${out}.tmp $in && mv ${out}.tmp ${out}",
CommandDeps: []string{"${config.MacArPath}", "${inAr}"}, CommandDeps: []string{"${config.MacArPath}", "${inAr}"},
@@ -94,14 +94,14 @@ var (
}, },
"arFlags", "inAr") "arFlags", "inAr")
darwinStrip = pctx.StaticRule("darwinStrip", darwinStrip = pctx.AndroidStaticRule("darwinStrip",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "${config.MacStripPath} -u -r -o $out $in", Command: "${config.MacStripPath} -u -r -o $out $in",
CommandDeps: []string{"${config.MacStripPath}"}, CommandDeps: []string{"${config.MacStripPath}"},
Description: "strip $out", Description: "strip $out",
}) })
prefixSymbols = pctx.StaticRule("prefixSymbols", prefixSymbols = pctx.AndroidStaticRule("prefixSymbols",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "$objcopyCmd --prefix-symbols=${prefix} ${in} ${out}", Command: "$objcopyCmd --prefix-symbols=${prefix} ${in} ${out}",
CommandDeps: []string{"$objcopyCmd"}, CommandDeps: []string{"$objcopyCmd"},
@@ -111,7 +111,7 @@ var (
stripPath = pctx.SourcePathVariable("stripPath", "build/soong/scripts/strip.sh") stripPath = pctx.SourcePathVariable("stripPath", "build/soong/scripts/strip.sh")
strip = pctx.StaticRule("strip", strip = pctx.AndroidStaticRule("strip",
blueprint.RuleParams{ blueprint.RuleParams{
Depfile: "${out}.d", Depfile: "${out}.d",
Deps: blueprint.DepsGCC, Deps: blueprint.DepsGCC,
@@ -121,7 +121,7 @@ var (
}, },
"args", "crossCompile") "args", "crossCompile")
emptyFile = pctx.StaticRule("emptyFile", emptyFile = pctx.AndroidStaticRule("emptyFile",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "rm -f $out && touch $out", Command: "rm -f $out && touch $out",
Description: "empty file $out", Description: "empty file $out",
@@ -129,7 +129,7 @@ var (
copyGccLibPath = pctx.SourcePathVariable("copyGccLibPath", "build/soong/scripts/copygcclib.sh") copyGccLibPath = pctx.SourcePathVariable("copyGccLibPath", "build/soong/scripts/copygcclib.sh")
copyGccLib = pctx.StaticRule("copyGccLib", copyGccLib = pctx.AndroidStaticRule("copyGccLib",
blueprint.RuleParams{ blueprint.RuleParams{
Depfile: "${out}.d", Depfile: "${out}.d",
Deps: blueprint.DepsGCC, Deps: blueprint.DepsGCC,

View File

@@ -31,7 +31,7 @@ func init() {
} }
var ( var (
yacc = pctx.StaticRule("yacc", yacc = pctx.AndroidStaticRule("yacc",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "BISON_PKGDATADIR=$yaccDataDir $yaccCmd -d $yaccFlags --defines=$hFile -o $cFile $in", Command: "BISON_PKGDATADIR=$yaccDataDir $yaccCmd -d $yaccFlags --defines=$hFile -o $cFile $in",
CommandDeps: []string{"$yaccCmd"}, CommandDeps: []string{"$yaccCmd"},
@@ -39,7 +39,7 @@ var (
}, },
"yaccFlags", "cFile", "hFile") "yaccFlags", "cFile", "hFile")
lex = pctx.StaticRule("lex", lex = pctx.AndroidStaticRule("lex",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "$lexCmd -o$out $in", Command: "$lexCmd -o$out $in",
CommandDeps: []string{"$lexCmd"}, CommandDeps: []string{"$lexCmd"},

View File

@@ -28,7 +28,7 @@ import (
var ( var (
toolPath = pctx.SourcePathVariable("toolPath", "build/soong/cc/gen_stub_libs.py") toolPath = pctx.SourcePathVariable("toolPath", "build/soong/cc/gen_stub_libs.py")
genStubSrc = pctx.StaticRule("genStubSrc", genStubSrc = pctx.AndroidStaticRule("genStubSrc",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "$toolPath --arch $arch --api $apiLevel $in $out", Command: "$toolPath --arch $arch --api $apiLevel $in $out",
Description: "genStubSrc $out", Description: "genStubSrc $out",

View File

@@ -27,7 +27,7 @@ import (
) )
var ( var (
aaptCreateResourceJavaFile = pctx.StaticRule("aaptCreateResourceJavaFile", aaptCreateResourceJavaFile = pctx.AndroidStaticRule("aaptCreateResourceJavaFile",
blueprint.RuleParams{ blueprint.RuleParams{
Command: `rm -rf "$javaDir" && mkdir -p "$javaDir" && ` + Command: `rm -rf "$javaDir" && mkdir -p "$javaDir" && ` +
`$aaptCmd package -m $aaptFlags -P $publicResourcesFile -G $proguardOptionsFile ` + `$aaptCmd package -m $aaptFlags -P $publicResourcesFile -G $proguardOptionsFile ` +
@@ -38,7 +38,7 @@ var (
}, },
"aaptFlags", "publicResourcesFile", "proguardOptionsFile", "javaDir", "javaFileList") "aaptFlags", "publicResourcesFile", "proguardOptionsFile", "javaDir", "javaFileList")
aaptCreateAssetsPackage = pctx.StaticRule("aaptCreateAssetsPackage", aaptCreateAssetsPackage = pctx.AndroidStaticRule("aaptCreateAssetsPackage",
blueprint.RuleParams{ blueprint.RuleParams{
Command: `rm -f $out && $aaptCmd package $aaptFlags -F $out`, Command: `rm -f $out && $aaptCmd package $aaptFlags -F $out`,
CommandDeps: []string{"$aaptCmd"}, CommandDeps: []string{"$aaptCmd"},
@@ -46,7 +46,7 @@ var (
}, },
"aaptFlags", "publicResourcesFile", "proguardOptionsFile", "javaDir", "javaFileList") "aaptFlags", "publicResourcesFile", "proguardOptionsFile", "javaDir", "javaFileList")
aaptAddResources = pctx.StaticRule("aaptAddResources", aaptAddResources = pctx.AndroidStaticRule("aaptAddResources",
blueprint.RuleParams{ blueprint.RuleParams{
// TODO: add-jni-shared-libs-to-package // TODO: add-jni-shared-libs-to-package
Command: `cp -f $in $out.tmp && $aaptCmd package -u $aaptFlags -F $out.tmp && mv $out.tmp $out`, Command: `cp -f $in $out.tmp && $aaptCmd package -u $aaptFlags -F $out.tmp && mv $out.tmp $out`,
@@ -55,7 +55,7 @@ var (
}, },
"aaptFlags") "aaptFlags")
signapk = pctx.StaticRule("signapk", signapk = pctx.AndroidStaticRule("signapk",
blueprint.RuleParams{ blueprint.RuleParams{
Command: `java -jar $signapkCmd $certificates $in $out`, Command: `java -jar $signapkCmd $certificates $in $out`,
CommandDeps: []string{"$signapkCmd"}, CommandDeps: []string{"$signapkCmd"},
@@ -63,7 +63,7 @@ var (
}, },
"certificates") "certificates")
androidManifestMerger = pctx.StaticRule("androidManifestMerger", androidManifestMerger = pctx.AndroidStaticRule("androidManifestMerger",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "java -classpath $androidManifestMergerCmd com.android.manifmerger.Main merge " + Command: "java -classpath $androidManifestMergerCmd com.android.manifmerger.Main merge " +
"--main $in --libs $libsManifests --out $out", "--main $in --libs $libsManifests --out $out",

View File

@@ -37,7 +37,7 @@ var (
// this, all java rules write into separate directories and then a post-processing step lists // this, all java rules write into separate directories and then a post-processing step lists
// the files in the the directory into a list file that later rules depend on (and sometimes // the files in the the directory into a list file that later rules depend on (and sometimes
// read from directly using @<listfile>) // read from directly using @<listfile>)
javac = pctx.StaticRule("javac", javac = pctx.AndroidStaticRule("javac",
blueprint.RuleParams{ blueprint.RuleParams{
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` + Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
`$javacCmd -encoding UTF-8 $javacFlags $bootClasspath $classpath ` + `$javacCmd -encoding UTF-8 $javacFlags $bootClasspath $classpath ` +
@@ -49,7 +49,7 @@ var (
}, },
"javacCmd", "javacFlags", "bootClasspath", "classpath", "outDir") "javacCmd", "javacFlags", "bootClasspath", "classpath", "outDir")
jar = pctx.StaticRule("jar", jar = pctx.AndroidStaticRule("jar",
blueprint.RuleParams{ blueprint.RuleParams{
Command: `$jarCmd -o $out $jarArgs`, Command: `$jarCmd -o $out $jarArgs`,
CommandDeps: []string{"$jarCmd"}, CommandDeps: []string{"$jarCmd"},
@@ -57,7 +57,7 @@ var (
}, },
"jarCmd", "jarArgs") "jarCmd", "jarArgs")
dx = pctx.StaticRule("dx", dx = pctx.AndroidStaticRule("dx",
blueprint.RuleParams{ blueprint.RuleParams{
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` + Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
`$dxCmd --dex --output=$outDir $dxFlags $in || ( rm -rf "$outDir"; exit 41 ) && ` + `$dxCmd --dex --output=$outDir $dxFlags $in || ( rm -rf "$outDir"; exit 41 ) && ` +
@@ -67,7 +67,7 @@ var (
}, },
"outDir", "dxFlags") "outDir", "dxFlags")
jarjar = pctx.StaticRule("jarjar", jarjar = pctx.AndroidStaticRule("jarjar",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "java -jar $jarjarCmd process $rulesFile $in $out", Command: "java -jar $jarjarCmd process $rulesFile $in $out",
CommandDeps: []string{"$jarjarCmd", "$rulesFile"}, CommandDeps: []string{"$jarjarCmd", "$rulesFile"},
@@ -75,7 +75,7 @@ var (
}, },
"rulesFile") "rulesFile")
extractPrebuilt = pctx.StaticRule("extractPrebuilt", extractPrebuilt = pctx.AndroidStaticRule("extractPrebuilt",
blueprint.RuleParams{ blueprint.RuleParams{
Command: `rm -rf $outDir && unzip -qo $in -d $outDir && ` + Command: `rm -rf $outDir && unzip -qo $in -d $outDir && ` +
`find $outDir -name "*.class" > $classFile && ` + `find $outDir -name "*.class" > $classFile && ` +

View File

@@ -33,7 +33,7 @@ func init() {
} }
var ( var (
aidl = pctx.StaticRule("aidl", aidl = pctx.AndroidStaticRule("aidl",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "$aidlCmd -d$depFile $aidlFlags $in $out", Command: "$aidlCmd -d$depFile $aidlFlags $in $out",
CommandDeps: []string{"$aidlCmd"}, CommandDeps: []string{"$aidlCmd"},
@@ -41,14 +41,14 @@ var (
}, },
"depFile", "aidlFlags") "depFile", "aidlFlags")
logtags = pctx.StaticRule("logtags", logtags = pctx.AndroidStaticRule("logtags",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "$logtagsCmd -o $out $in $allLogtagsFile", Command: "$logtagsCmd -o $out $in $allLogtagsFile",
CommandDeps: []string{"$logtagsCmd"}, CommandDeps: []string{"$logtagsCmd"},
Description: "logtags $out", Description: "logtags $out",
}) })
mergeLogtags = pctx.StaticRule("mergeLogtags", mergeLogtags = pctx.AndroidStaticRule("mergeLogtags",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "$mergeLogtagsCmd -o $out $in", Command: "$mergeLogtagsCmd -o $out $in",
CommandDeps: []string{"$mergeLogtagsCmd"}, CommandDeps: []string{"$mergeLogtagsCmd"},