Change bool, and string properties to *bool, and *string for java,

python, and genrule.

Test: m -j checkbuild
Bug: b/68853585
Change-Id: Ic9a8083818e920dc399a4b00841e2aa496f70faa
This commit is contained in:
Nan Zhang 2017-11-08 21:20:04 -08:00
parent 99a5635733
commit ea568a4a24
7 changed files with 54 additions and 46 deletions

View file

@ -35,11 +35,11 @@ type fileGroupProperties struct {
// of the path to use. For example, when a filegroup is used as data in a cc_test rule, // of the path to use. For example, when a filegroup is used as data in a cc_test rule,
// the base path is stripped off the path and the remaining path is used as the // the base path is stripped off the path and the remaining path is used as the
// installation directory. // installation directory.
Path string Path *string
// Create a make variable with the specified name that contains the list of files in the // Create a make variable with the specified name that contains the list of files in the
// filegroup, relative to the root of the source tree. // filegroup, relative to the root of the source tree.
Export_to_make_var string Export_to_make_var *string
} }
type fileGroup struct { type fileGroup struct {
@ -65,7 +65,7 @@ func (fg *fileGroup) DepsMutator(ctx android.BottomUpMutatorContext) {
} }
func (fg *fileGroup) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (fg *fileGroup) GenerateAndroidBuildActions(ctx android.ModuleContext) {
fg.srcs = ctx.ExpandSourcesSubDir(fg.properties.Srcs, fg.properties.Exclude_srcs, fg.properties.Path) fg.srcs = ctx.ExpandSourcesSubDir(fg.properties.Srcs, fg.properties.Exclude_srcs, String(fg.properties.Path))
} }
func (fg *fileGroup) Srcs() android.Paths { func (fg *fileGroup) Srcs() android.Paths {
@ -83,7 +83,7 @@ endif
func (fg *fileGroup) AndroidMk() android.AndroidMkData { func (fg *fileGroup) AndroidMk() android.AndroidMkData {
return android.AndroidMkData{ return android.AndroidMkData{
Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
if makeVar := fg.properties.Export_to_make_var; makeVar != "" { if makeVar := String(fg.properties.Export_to_make_var); makeVar != "" {
androidMkTemplate.Execute(w, map[string]string{ androidMkTemplate.Execute(w, map[string]string{
"makeVar": makeVar, "makeVar": makeVar,
"value": strings.Join(fg.srcs.Strings(), " "), "value": strings.Join(fg.srcs.Strings(), " "),

View file

@ -20,12 +20,11 @@ import (
"github.com/google/blueprint" "github.com/google/blueprint"
"github.com/google/blueprint/bootstrap" "github.com/google/blueprint/bootstrap"
"github.com/google/blueprint/proptools"
"android/soong/android" "android/soong/android"
"android/soong/shared" "android/soong/shared"
"path/filepath" "path/filepath"
"github.com/google/blueprint/proptools"
) )
func init() { func init() {
@ -72,10 +71,10 @@ type generatorProperties struct {
// //
// All files used must be declared as inputs (to ensure proper up-to-date checks). // All files used must be declared as inputs (to ensure proper up-to-date checks).
// Use "$(in)" directly in Cmd to ensure that all inputs used are declared. // Use "$(in)" directly in Cmd to ensure that all inputs used are declared.
Cmd string Cmd *string
// Enable reading a file containing dependencies in gcc format after the command completes // Enable reading a file containing dependencies in gcc format after the command completes
Depfile bool Depfile *bool
// name of the modules (if any) that produces the host executable. Leave empty for // name of the modules (if any) that produces the host executable. Leave empty for
// prebuilts or scripts that do not need a module to build them. // prebuilts or scripts that do not need a module to build them.
@ -214,7 +213,7 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
referencedDepfile := false referencedDepfile := false
srcFiles := ctx.ExpandSources(g.properties.Srcs, nil) srcFiles := ctx.ExpandSources(g.properties.Srcs, nil)
task := g.taskGenerator(ctx, g.properties.Cmd, srcFiles) task := g.taskGenerator(ctx, String(g.properties.Cmd), srcFiles)
rawCommand, err := android.Expand(task.cmd, func(name string) (string, error) { rawCommand, err := android.Expand(task.cmd, func(name string) (string, error) {
switch name { switch name {
@ -230,7 +229,7 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
return "__SBOX_OUT_FILES__", nil return "__SBOX_OUT_FILES__", nil
case "depfile": case "depfile":
referencedDepfile = true referencedDepfile = true
if !g.properties.Depfile { if !Bool(g.properties.Depfile) {
return "", fmt.Errorf("$(depfile) used without depfile property") return "", fmt.Errorf("$(depfile) used without depfile property")
} }
return "__SBOX_DEPFILE__", nil return "__SBOX_DEPFILE__", nil
@ -249,7 +248,7 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
} }
}) })
if g.properties.Depfile && !referencedDepfile { if Bool(g.properties.Depfile) && !referencedDepfile {
ctx.PropertyErrorf("cmd", "specified depfile=true but did not include a reference to '${depfile}' in cmd") ctx.PropertyErrorf("cmd", "specified depfile=true but did not include a reference to '${depfile}' in cmd")
} }
@ -265,7 +264,7 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// recall that Sprintf replaces percent sign expressions, whereas dollar signs expressions remain as written, // recall that Sprintf replaces percent sign expressions, whereas dollar signs expressions remain as written,
// to be replaced later by ninja_strings.go // to be replaced later by ninja_strings.go
depfilePlaceholder := "" depfilePlaceholder := ""
if g.properties.Depfile { if Bool(g.properties.Depfile) {
depfilePlaceholder = "$depfileArgs" depfilePlaceholder = "$depfileArgs"
} }
@ -277,7 +276,7 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
CommandDeps: []string{"$sboxCmd"}, CommandDeps: []string{"$sboxCmd"},
} }
args := []string{"allouts"} args := []string{"allouts"}
if g.properties.Depfile { if Bool(g.properties.Depfile) {
ruleParams.Deps = blueprint.DepsGCC ruleParams.Deps = blueprint.DepsGCC
args = append(args, "depfileArgs") args = append(args, "depfileArgs")
} }
@ -298,7 +297,7 @@ func (g *Module) generateSourceFile(ctx android.ModuleContext, task generateTask
} }
var depFile android.ModuleGenPath var depFile android.ModuleGenPath
if g.properties.Depfile { if Bool(g.properties.Depfile) {
depFile = android.PathForModuleGen(ctx, task.out[0].Rel()+".d") depFile = android.PathForModuleGen(ctx, task.out[0].Rel()+".d")
} }
@ -313,7 +312,7 @@ func (g *Module) generateSourceFile(ctx android.ModuleContext, task generateTask
"allouts": strings.Join(task.out.Strings(), " "), "allouts": strings.Join(task.out.Strings(), " "),
}, },
} }
if g.properties.Depfile { if Bool(g.properties.Depfile) {
params.Depfile = android.PathForModuleGen(ctx, task.out[0].Rel()+".d") params.Depfile = android.PathForModuleGen(ctx, task.out[0].Rel()+".d")
params.Args["depfileArgs"] = "--depfile-out " + depFile.String() params.Args["depfileArgs"] = "--depfile-out " + depFile.String()
} }
@ -422,3 +421,6 @@ type genRuleProperties struct {
// names of the output files that will be generated // names of the output files that will be generated
Out []string Out []string
} }
var Bool = proptools.Bool
var String = proptools.String

View file

@ -40,7 +40,7 @@ func (library *Library) AndroidMk() android.AndroidMkData {
fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false") fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
} }
} }
fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", library.deviceProperties.Sdk_version) fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(library.deviceProperties.Sdk_version))
fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String()) fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
}, },
}, },
@ -76,7 +76,7 @@ func (prebuilt *Import) AndroidMk() android.AndroidMkData {
func(w io.Writer, outputFile android.Path) { func(w io.Writer, outputFile android.Path) {
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !proptools.Bool(prebuilt.properties.Installable)) fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !proptools.Bool(prebuilt.properties.Installable))
fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String()) fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.properties.Sdk_version) fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(prebuilt.properties.Sdk_version))
}, },
}, },
} }

View file

@ -32,14 +32,14 @@ import (
type androidAppProperties struct { type androidAppProperties struct {
// path to a certificate, or the name of a certificate in the default // path to a certificate, or the name of a certificate in the default
// certificate directory, or blank to use the default product certificate // certificate directory, or blank to use the default product certificate
Certificate string Certificate *string
// paths to extra certificates to sign the apk with // paths to extra certificates to sign the apk with
Additional_certificates []string Additional_certificates []string
// If set, create package-export.apk, which other packages can // If set, create package-export.apk, which other packages can
// use to get PRODUCT-agnostic resource data like IDs and type definitions. // use to get PRODUCT-agnostic resource data like IDs and type definitions.
Export_package_resources bool Export_package_resources *bool
// flags passed to aapt when creating the apk // flags passed to aapt when creating the apk
Aaptflags []string Aaptflags []string
@ -69,7 +69,7 @@ func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
a.Module.deps(ctx) a.Module.deps(ctx)
if !proptools.Bool(a.properties.No_standard_libs) { if !proptools.Bool(a.properties.No_standard_libs) {
switch a.deviceProperties.Sdk_version { // TODO: Res_sdk_version? switch String(a.deviceProperties.Sdk_version) { // TODO: Res_sdk_version?
case "current", "system_current", "": case "current", "system_current", "":
ctx.AddDependency(ctx.Module(), frameworkResTag, "framework-res") ctx.AddDependency(ctx.Module(), frameworkResTag, "framework-res")
default: default:
@ -90,7 +90,7 @@ func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.aaptJavaFileList = aaptJavaFileList a.aaptJavaFileList = aaptJavaFileList
// TODO(ccross): export aapt generated java files as a src jar // TODO(ccross): export aapt generated java files as a src jar
if a.appProperties.Export_package_resources { if Bool(a.appProperties.Export_package_resources) {
aaptPackageFlags := append([]string(nil), aaptFlags...) aaptPackageFlags := append([]string(nil), aaptFlags...)
var hasProduct bool var hasProduct bool
for _, f := range aaptPackageFlags { for _, f := range aaptPackageFlags {
@ -135,7 +135,7 @@ func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
"--product "+ctx.AConfig().ProductAAPTCharacteristics()) "--product "+ctx.AConfig().ProductAAPTCharacteristics())
} }
certificate := a.appProperties.Certificate certificate := String(a.appProperties.Certificate)
if certificate == "" { if certificate == "" {
certificate = ctx.AConfig().DefaultAppCertificate(ctx).String() certificate = ctx.AConfig().DefaultAppCertificate(ctx).String()
} else if dir, _ := filepath.Split(certificate); dir == "" { } else if dir, _ := filepath.Split(certificate); dir == "" {
@ -244,7 +244,7 @@ func (a *AndroidApp) aaptFlags(ctx android.ModuleContext) ([]string, android.Pat
aaptDeps = append(aaptDeps, depFiles...) aaptDeps = append(aaptDeps, depFiles...)
}) })
sdkVersion := a.deviceProperties.Sdk_version sdkVersion := String(a.deviceProperties.Sdk_version)
if sdkVersion == "" { if sdkVersion == "" {
sdkVersion = ctx.AConfig().PlatformSdkVersion() sdkVersion = ctx.AConfig().PlatformSdkVersion()
} }

View file

@ -134,7 +134,7 @@ type CompilerDeviceProperties struct {
Dxflags []string `android:"arch_variant"` Dxflags []string `android:"arch_variant"`
// if not blank, set to the version of the sdk to compile against // if not blank, set to the version of the sdk to compile against
Sdk_version string Sdk_version *string
// directories to pass to aidl tool // directories to pass to aidl tool
Aidl_includes []string Aidl_includes []string
@ -307,7 +307,7 @@ func decodeSdkDep(ctx android.BaseContext, v string) sdkDep {
func (j *Module) deps(ctx android.BottomUpMutatorContext) { func (j *Module) deps(ctx android.BottomUpMutatorContext) {
if ctx.Device() { if ctx.Device() {
if !proptools.Bool(j.properties.No_standard_libs) { if !proptools.Bool(j.properties.No_standard_libs) {
sdkDep := decodeSdkDep(ctx, j.deviceProperties.Sdk_version) sdkDep := decodeSdkDep(ctx, String(j.deviceProperties.Sdk_version))
if sdkDep.useDefaultLibs { if sdkDep.useDefaultLibs {
ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...) ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
if ctx.AConfig().TargetOpenJDK9() { if ctx.AConfig().TargetOpenJDK9() {
@ -412,7 +412,7 @@ type deps struct {
func (j *Module) collectDeps(ctx android.ModuleContext) deps { func (j *Module) collectDeps(ctx android.ModuleContext) deps {
var deps deps var deps deps
sdkDep := decodeSdkDep(ctx, j.deviceProperties.Sdk_version) sdkDep := decodeSdkDep(ctx, String(j.deviceProperties.Sdk_version))
if sdkDep.invalidVersion { if sdkDep.invalidVersion {
ctx.AddMissingDependencies([]string{sdkDep.module}) ctx.AddMissingDependencies([]string{sdkDep.module})
} else if sdkDep.useFiles { } else if sdkDep.useFiles {
@ -493,14 +493,14 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
} }
// javaVersion flag. // javaVersion flag.
sdk := sdkStringToNumber(ctx, j.deviceProperties.Sdk_version) sdk := sdkStringToNumber(ctx, String(j.deviceProperties.Sdk_version))
if j.properties.Java_version != nil { if j.properties.Java_version != nil {
flags.javaVersion = *j.properties.Java_version flags.javaVersion = *j.properties.Java_version
} else if ctx.Device() && sdk <= 23 { } else if ctx.Device() && sdk <= 23 {
flags.javaVersion = "1.7" flags.javaVersion = "1.7"
} else if ctx.Device() && sdk <= 26 || !ctx.AConfig().TargetOpenJDK9() { } else if ctx.Device() && sdk <= 26 || !ctx.AConfig().TargetOpenJDK9() {
flags.javaVersion = "1.8" flags.javaVersion = "1.8"
} else if ctx.Device() && j.deviceProperties.Sdk_version != "" && sdk == 10000 { } else if ctx.Device() && String(j.deviceProperties.Sdk_version) != "" && sdk == 10000 {
// TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current" // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
flags.javaVersion = "1.8" flags.javaVersion = "1.8"
} else { } else {
@ -783,11 +783,11 @@ func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags,
} }
var minSdkVersion string var minSdkVersion string
switch j.deviceProperties.Sdk_version { switch String(j.deviceProperties.Sdk_version) {
case "", "current", "test_current", "system_current": case "", "current", "test_current", "system_current":
minSdkVersion = strconv.Itoa(ctx.AConfig().DefaultAppTargetSdkInt()) minSdkVersion = strconv.Itoa(ctx.AConfig().DefaultAppTargetSdkInt())
default: default:
minSdkVersion = j.deviceProperties.Sdk_version minSdkVersion = String(j.deviceProperties.Sdk_version)
} }
dxFlags = append(dxFlags, "--min-sdk-version="+minSdkVersion) dxFlags = append(dxFlags, "--min-sdk-version="+minSdkVersion)
@ -903,7 +903,7 @@ func LibraryHostFactory() android.Module {
type binaryProperties struct { type binaryProperties struct {
// installable script to execute the resulting jar // installable script to execute the resulting jar
Wrapper string Wrapper *string
} }
type Binary struct { type Binary struct {
@ -924,8 +924,8 @@ func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by // Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by
// another build rule before the jar has been installed. // another build rule before the jar has been installed.
if j.binaryProperties.Wrapper != "" { if String(j.binaryProperties.Wrapper) != "" {
j.wrapperFile = android.PathForModuleSrc(ctx, j.binaryProperties.Wrapper).SourcePath j.wrapperFile = android.PathForModuleSrc(ctx, String(j.binaryProperties.Wrapper)).SourcePath
} else { } else {
j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh") j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
} }
@ -970,7 +970,7 @@ func BinaryHostFactory() android.Module {
type ImportProperties struct { type ImportProperties struct {
Jars []string Jars []string
Sdk_version string Sdk_version *string
Installable *bool Installable *bool
} }
@ -1084,3 +1084,6 @@ func DefaultsFactory(props ...interface{}) android.Module {
return module return module
} }
var Bool = proptools.Bool
var String = proptools.String

View file

@ -33,13 +33,13 @@ type BinaryProperties struct {
// this file must also be listed in srcs. // this file must also be listed in srcs.
// If left unspecified, module name is used instead. // If left unspecified, module name is used instead.
// If name doesnt match any filename in srcs, main must be specified. // If name doesnt match any filename in srcs, main must be specified.
Main string `android:"arch_variant"` Main *string `android:"arch_variant"`
// set the name of the output binary. // set the name of the output binary.
Stem string `android:"arch_variant"` Stem *string `android:"arch_variant"`
// append to the name of the output binary. // append to the name of the output binary.
Suffix string `android:"arch_variant"` Suffix *string `android:"arch_variant"`
// list of compatibility suites (for example "cts", "vts") that the module should be // list of compatibility suites (for example "cts", "vts") that the module should be
// installed into. // installed into.
@ -179,10 +179,10 @@ func (binary *binaryDecorator) getHostInterpreterName(ctx android.ModuleContext,
func (binary *binaryDecorator) getPyMainFile(ctx android.ModuleContext, func (binary *binaryDecorator) getPyMainFile(ctx android.ModuleContext,
srcsPathMappings []pathMapping) string { srcsPathMappings []pathMapping) string {
var main string var main string
if binary.binaryProperties.Main == "" { if String(binary.binaryProperties.Main) == "" {
main = ctx.ModuleName() + pyExt main = ctx.ModuleName() + pyExt
} else { } else {
main = binary.binaryProperties.Main main = String(binary.binaryProperties.Main)
} }
for _, path := range srcsPathMappings { for _, path := range srcsPathMappings {
@ -197,11 +197,11 @@ func (binary *binaryDecorator) getPyMainFile(ctx android.ModuleContext,
func (binary *binaryDecorator) getStem(ctx android.ModuleContext) string { func (binary *binaryDecorator) getStem(ctx android.ModuleContext) string {
stem := ctx.ModuleName() stem := ctx.ModuleName()
if binary.binaryProperties.Stem != "" { if String(binary.binaryProperties.Stem) != "" {
stem = binary.binaryProperties.Stem stem = String(binary.binaryProperties.Stem)
} }
return stem + binary.binaryProperties.Suffix return stem + String(binary.binaryProperties.Suffix)
} }
// Sets the given directory and all its ancestor directories as Python packages. // Sets the given directory and all its ancestor directories as Python packages.

View file

@ -65,7 +65,7 @@ type BaseProperties struct {
// (from a.b.c import ...) statement. // (from a.b.c import ...) statement.
// if left unspecified, all the source/data files of current module are copied to // if left unspecified, all the source/data files of current module are copied to
// "runfiles/" tree directory directly. // "runfiles/" tree directory directly.
Pkg_path string `android:"arch_variant"` Pkg_path *string `android:"arch_variant"`
// true, if the Python module is used internally, eg, Python std libs. // true, if the Python module is used internally, eg, Python std libs.
Is_internal *bool `android:"arch_variant"` Is_internal *bool `android:"arch_variant"`
@ -367,14 +367,14 @@ func (p *Module) GeneratePythonBuildActions(ctx android.ModuleContext) {
expandedData := ctx.ExpandSources(p.properties.Data, nil) expandedData := ctx.ExpandSources(p.properties.Data, nil)
// sanitize pkg_path. // sanitize pkg_path.
pkg_path := p.properties.Pkg_path pkg_path := String(p.properties.Pkg_path)
if pkg_path != "" { if pkg_path != "" {
pkg_path = filepath.Clean(p.properties.Pkg_path) pkg_path = filepath.Clean(String(p.properties.Pkg_path))
if pkg_path == ".." || strings.HasPrefix(pkg_path, "../") || if pkg_path == ".." || strings.HasPrefix(pkg_path, "../") ||
strings.HasPrefix(pkg_path, "/") { strings.HasPrefix(pkg_path, "/") {
ctx.PropertyErrorf("pkg_path", ctx.PropertyErrorf("pkg_path",
"%q must be a relative path contained in par file.", "%q must be a relative path contained in par file.",
p.properties.Pkg_path) String(p.properties.Pkg_path))
return return
} }
if p.properties.Is_internal != nil && *p.properties.Is_internal { if p.properties.Is_internal != nil && *p.properties.Is_internal {
@ -557,3 +557,6 @@ func fillInMap(ctx android.ModuleContext, m map[string]string,
return true return true
} }
var Bool = proptools.Bool
var String = proptools.String