Merge "Revert "bp2build: convert host & prebuilt header libraries""
diff --git a/android/arch.go b/android/arch.go
index e08fd5c..96a4cbf 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -993,8 +993,6 @@
base := m.base()
- // Store the original list of top level property structs
- base.generalProperties = m.GetProperties()
if len(base.archProperties) != 0 {
panic(fmt.Errorf("module %s already has archProperties", m.Name()))
}
@@ -1015,7 +1013,7 @@
return t
}
- for _, properties := range base.generalProperties {
+ for _, properties := range m.GetProperties() {
t := getStructType(properties)
// Get or create the arch-specific property struct types for this property struct type.
archPropTypes := archPropTypeMap.Once(NewCustomOnceKey(t), func() interface{} {
@@ -1036,9 +1034,6 @@
m.AddProperties(archProperties...)
}
- // Update the list of properties that can be set by a defaults module or a call to
- // AppendMatchingProperties or PrependMatchingProperties.
- base.customizableProperties = m.GetProperties()
}
func maybeBlueprintEmbed(src reflect.Value) reflect.Value {
@@ -1111,8 +1106,8 @@
func (m *ModuleBase) setOSProperties(ctx BottomUpMutatorContext) {
os := m.commonProperties.CompileOS
- for i := range m.generalProperties {
- genProps := m.generalProperties[i]
+ for i := range m.archProperties {
+ genProps := m.GetProperties()[i]
if m.archProperties[i] == nil {
continue
}
@@ -1439,8 +1434,8 @@
arch := m.Arch()
os := m.Os()
- for i := range m.generalProperties {
- genProps := m.generalProperties[i]
+ for i := range m.archProperties {
+ genProps := m.GetProperties()[i]
if m.archProperties[i] == nil {
continue
}
@@ -2018,8 +2013,8 @@
var archProperties []interface{}
// First find the property set in the module that corresponds to the requested
- // one. m.archProperties[i] corresponds to m.generalProperties[i].
- for i, generalProp := range m.generalProperties {
+ // one. m.archProperties[i] corresponds to m.GetProperties()[i].
+ for i, generalProp := range m.GetProperties() {
srcType := reflect.ValueOf(generalProp).Type()
if srcType == dstType {
archProperties = m.archProperties[i]
diff --git a/android/config.go b/android/config.go
index 5c0e5ae..afc138b 100644
--- a/android/config.go
+++ b/android/config.go
@@ -1245,6 +1245,10 @@
return coverage
}
+func (c *deviceConfig) AfdoAdditionalProfileDirs() []string {
+ return c.config.productVariables.AfdoAdditionalProfileDirs
+}
+
func (c *deviceConfig) PgoAdditionalProfileDirs() []string {
return c.config.productVariables.PgoAdditionalProfileDirs
}
@@ -1465,6 +1469,10 @@
return String(c.config.productVariables.TotSepolicyVersion)
}
+func (c *deviceConfig) PlatformSepolicyCompatVersions() []string {
+ return c.config.productVariables.PlatformSepolicyCompatVersions
+}
+
func (c *deviceConfig) BoardSepolicyVers() string {
if ver := String(c.config.productVariables.BoardSepolicyVers); ver != "" {
return ver
diff --git a/android/defaults.go b/android/defaults.go
index 5677638..8b121f6 100644
--- a/android/defaults.go
+++ b/android/defaults.go
@@ -96,8 +96,6 @@
module.setProperties(module.GetProperties(), module.base().variableProperties)
module.AddProperties(module.defaults())
-
- module.base().customizableProperties = module.GetProperties()
}
// A restricted subset of context methods, similar to LoadHookContext.
diff --git a/android/hooks.go b/android/hooks.go
index 9eaa1ac..bded764 100644
--- a/android/hooks.go
+++ b/android/hooks.go
@@ -68,7 +68,7 @@
func (l *loadHookContext) appendPrependHelper(props []interface{},
extendFn func([]interface{}, interface{}, proptools.ExtendPropertyFilterFunc) error) {
for _, p := range props {
- err := extendFn(l.Module().base().customizableProperties, p, nil)
+ err := extendFn(l.Module().base().GetProperties(), p, nil)
if err != nil {
if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
l.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
diff --git a/android/license.go b/android/license.go
index 8bfd3ba..587cb36 100644
--- a/android/license.go
+++ b/android/license.go
@@ -80,9 +80,6 @@
base := module.base()
module.AddProperties(&base.nameProperties, &module.properties)
- base.generalProperties = module.GetProperties()
- base.customizableProperties = module.GetProperties()
-
// The visibility property needs to be checked and parsed by the visibility module.
setPrimaryVisibilityProperty(module, "visibility", &module.properties.Visibility)
diff --git a/android/license_kind.go b/android/license_kind.go
index ddecd77..838dedd 100644
--- a/android/license_kind.go
+++ b/android/license_kind.go
@@ -53,9 +53,6 @@
base := module.base()
module.AddProperties(&base.nameProperties, &module.properties)
- base.generalProperties = module.GetProperties()
- base.customizableProperties = module.GetProperties()
-
// The visibility property needs to be checked and parsed by the visibility module.
setPrimaryVisibilityProperty(module, "visibility", &module.properties.Visibility)
diff --git a/android/licenses_test.go b/android/licenses_test.go
index d05b0a3..70160fa 100644
--- a/android/licenses_test.go
+++ b/android/licenses_test.go
@@ -779,9 +779,6 @@
base := m.base()
m.AddProperties(&base.nameProperties, &m.properties)
- base.generalProperties = m.GetProperties()
- base.customizableProperties = m.GetProperties()
-
// The default_visibility property needs to be checked and parsed by the visibility module during
// its checking and parsing phases so make it the primary visibility property.
setPrimaryVisibilityProperty(m, "visibility", &m.properties.Visibility)
diff --git a/android/module.go b/android/module.go
index 2750131..c2fa848 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1032,9 +1032,6 @@
initProductVariableModule(m)
- base.generalProperties = m.GetProperties()
- base.customizableProperties = m.GetProperties()
-
// The default_visibility property needs to be checked and parsed by the visibility module during
// its checking and parsing phases so make it the primary visibility property.
setPrimaryVisibilityProperty(m, "visibility", &base.commonProperties.Visibility)
@@ -1208,17 +1205,14 @@
distProperties distProperties
variableProperties interface{}
hostAndDeviceProperties hostAndDeviceProperties
- generalProperties []interface{}
- // Arch specific versions of structs in generalProperties. The outer index
- // has the same order as generalProperties as initialized in
- // InitAndroidArchModule, and the inner index chooses the props specific to
- // the architecture. The interface{} value is an archPropRoot that is
- // filled with arch specific values by the arch mutator.
+ // Arch specific versions of structs in GetProperties() prior to
+ // initialization in InitAndroidArchModule, lets call it `generalProperties`.
+ // The outer index has the same order as generalProperties and the inner index
+ // chooses the props specific to the architecture. The interface{} value is an
+ // archPropRoot that is filled with arch specific values by the arch mutator.
archProperties [][]interface{}
- customizableProperties []interface{}
-
// Properties specific to the Blueprint to BUILD migration.
bazelTargetModuleProperties bazel.BazelTargetModuleProperties
diff --git a/android/neverallow.go b/android/neverallow.go
index 4bb3e57..6f9ae58 100644
--- a/android/neverallow.go
+++ b/android/neverallow.go
@@ -134,7 +134,6 @@
NeverAllow().
Without("name", "libhidlbase-combined-impl").
Without("name", "libhidlbase").
- Without("name", "libhidlbase_pgo").
With("product_variables.enforce_vintf_manifest.cflags", "*").
Because("manifest enforcement should be independent of ."),
@@ -215,11 +214,8 @@
return []Rule{
NeverAllow().
ModuleType("makefile_goal").
- // TODO(b/33691272): remove this after migrating seapp to Soong
- Without("product_out_path", "obj/ETC/plat_seapp_contexts_intermediates/plat_seapp_contexts").
- Without("product_out_path", "obj/ETC/plat_seapp_neverallows_intermediates/plat_seapp_neverallows").
WithoutMatcher("product_out_path", Regexp("^boot[0-9a-zA-Z.-]*[.]img$")).
- Because("Only boot images and seapp contexts may be imported as a makefile goal."),
+ Because("Only boot images may be imported as a makefile goal."),
}
}
diff --git a/android/neverallow_test.go b/android/neverallow_test.go
index 58a90b3..59016d4 100644
--- a/android/neverallow_test.go
+++ b/android/neverallow_test.go
@@ -324,7 +324,7 @@
`),
},
expectedErrors: []string{
- "Only boot images and seapp contexts may be imported as a makefile goal.",
+ "Only boot images may be imported as a makefile goal.",
},
},
{
diff --git a/android/path_properties.go b/android/path_properties.go
index 3976880..fdc4d91 100644
--- a/android/path_properties.go
+++ b/android/path_properties.go
@@ -33,7 +33,7 @@
// The pathDepsMutator automatically adds dependencies on any module that is listed with the
// ":module" module reference syntax in a property that is tagged with `android:"path"`.
func pathDepsMutator(ctx BottomUpMutatorContext) {
- props := ctx.Module().base().generalProperties
+ props := ctx.Module().base().GetProperties()
addPathDepsForProps(ctx, props)
}
diff --git a/android/prebuilt.go b/android/prebuilt.go
index b0a4f43..ade92f7 100644
--- a/android/prebuilt.go
+++ b/android/prebuilt.go
@@ -183,7 +183,6 @@
func initPrebuiltModuleCommon(module PrebuiltInterface) *Prebuilt {
p := module.Prebuilt()
module.AddProperties(&p.properties)
- module.base().customizableProperties = module.GetProperties()
return p
}
diff --git a/android/variable.go b/android/variable.go
index bc93835..b300267 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -124,6 +124,9 @@
Shared_libs []string
Cmdline []string
+
+ Srcs []string
+ Exclude_srcs []string
}
// eng is true for -eng builds, and can be used to turn on additionaly heavyweight debugging
@@ -327,7 +330,8 @@
NamespacesToExport []string `json:",omitempty"`
- PgoAdditionalProfileDirs []string `json:",omitempty"`
+ AfdoAdditionalProfileDirs []string `json:",omitempty"`
+ PgoAdditionalProfileDirs []string `json:",omitempty"`
VndkUseCoreVariant *bool `json:",omitempty"`
VndkSnapshotBuildArtifacts *bool `json:",omitempty"`
@@ -360,6 +364,8 @@
PlatformSepolicyVersion *string `json:",omitempty"`
TotSepolicyVersion *string `json:",omitempty"`
+ PlatformSepolicyCompatVersions []string `json:",omitempty"`
+
VendorVars map[string]map[string]string `json:",omitempty"`
Ndk_abis *bool `json:",omitempty"`
@@ -1025,7 +1031,7 @@
printfIntoProperties(ctx, prefix, productVariablePropertyValue, variableValue)
- err := proptools.AppendMatchingProperties(m.generalProperties,
+ err := proptools.AppendMatchingProperties(m.GetProperties(),
productVariablePropertyValue.Addr().Interface(), nil)
if err != nil {
if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
diff --git a/bazel/properties.go b/bazel/properties.go
index d8b3a3a..870d293 100644
--- a/bazel/properties.go
+++ b/bazel/properties.go
@@ -736,6 +736,24 @@
return true
}
+// IsNil returns true if the attribute has not been set for any configuration.
+func (lla LabelListAttribute) IsNil() bool {
+ if lla.Value.Includes != nil {
+ return false
+ }
+ return !lla.HasConfigurableValues()
+}
+
+// Exclude for the given axis, config, removes Includes in labelList from Includes and appends them
+// to Excludes. This is to special case any excludes that are not specified in a bp file but need to
+// be removed, e.g. if they could cause duplicate element failures.
+func (lla *LabelListAttribute) Exclude(axis ConfigurationAxis, config string, labelList LabelList) {
+ val := lla.SelectValue(axis, config)
+ newList := SubtractBazelLabelList(val, labelList)
+ newList.Excludes = append(newList.Excludes, labelList.Includes...)
+ lla.SetSelectValue(axis, config, newList)
+}
+
// ResolveExcludes handles excludes across the various axes, ensuring that items are removed from
// the base value and included in default values as appropriate.
func (lla *LabelListAttribute) ResolveExcludes() {
diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go
index e65a1fa..fac741c 100644
--- a/bp2build/cc_library_static_conversion_test.go
+++ b/bp2build/cc_library_static_conversion_test.go
@@ -65,7 +65,6 @@
t.Fatalf("Expected load statements to be %s, got %s", expected, actual)
}
}
-
}
func registerCcLibraryStaticModuleTypes(ctx android.RegistrationContext) {
@@ -1395,6 +1394,54 @@
})
}
+func TestCcLibrarystatic_SystemSharedLibUsedAsDep(t *testing.T) {
+ runCcLibraryStaticTestCase(t, bp2buildTestCase{
+ description: "cc_library_static system_shared_lib empty for linux_bionic variant",
+ blueprint: soongCcLibraryStaticPreamble +
+ simpleModuleDoNotConvertBp2build("cc_library", "libc") + `
+cc_library_static {
+ name: "used_in_bionic_oses",
+ target: {
+ android: {
+ shared_libs: ["libc"],
+ },
+ linux_bionic: {
+ shared_libs: ["libc"],
+ },
+ },
+ include_build_directory: false,
+}
+
+cc_library_static {
+ name: "all",
+ shared_libs: ["libc"],
+ include_build_directory: false,
+}
+
+cc_library_static {
+ name: "keep_for_empty_system_shared_libs",
+ shared_libs: ["libc"],
+ system_shared_libs: [],
+ include_build_directory: false,
+}
+`,
+ expectedBazelTargets: []string{
+ makeBazelTarget("cc_library_static", "all", attrNameToString{
+ "implementation_dynamic_deps": `select({
+ "//build/bazel/platforms/os:android": [],
+ "//build/bazel/platforms/os:linux_bionic": [],
+ "//conditions:default": [":libc"],
+ })`,
+ }),
+ makeBazelTarget("cc_library_static", "keep_for_empty_system_shared_libs", attrNameToString{
+ "implementation_dynamic_deps": `[":libc"]`,
+ "system_dynamic_deps": `[]`,
+ }),
+ makeBazelTarget("cc_library_static", "used_in_bionic_oses", attrNameToString{}),
+ },
+ })
+}
+
func TestCcLibraryStaticProto(t *testing.T) {
runCcLibraryStaticTestCase(t, bp2buildTestCase{
blueprint: soongCcProtoPreamble + `cc_library_static {
diff --git a/bp2build/java_binary_host_conversion_test.go b/bp2build/java_binary_host_conversion_test.go
index 96b8958..c683b25 100644
--- a/bp2build/java_binary_host_conversion_test.go
+++ b/bp2build/java_binary_host_conversion_test.go
@@ -41,7 +41,7 @@
func TestJavaBinaryHost(t *testing.T) {
runJavaBinaryHostTestCase(t, bp2buildTestCase{
- description: "java_binary_host with srcs, exclude_srcs, jni_libs and manifest.",
+ description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.",
filesystem: fs,
blueprint: `java_binary_host {
name: "java-binary-host-1",
@@ -49,6 +49,7 @@
exclude_srcs: ["b.java"],
manifest: "test.mf",
jni_libs: ["jni-lib-1"],
+ javacflags: ["-Xdoclint:all/protected"],
bazel_module: { bp2build_available: true },
}`,
expectedBazelTargets: []string{
@@ -57,6 +58,7 @@
"main_class": `"com.android.test.MainClass"`,
"deps": `["//other:jni-lib-1"]`,
"jvm_flags": `["-Djava.library.path=$${RUNPATH}other"]`,
+ "javacopts": `["-Xdoclint:all/protected"]`,
}),
},
})
diff --git a/bp2build/testing.go b/bp2build/testing.go
index 8ae1a38..53b60fa 100644
--- a/bp2build/testing.go
+++ b/bp2build/testing.go
@@ -43,7 +43,7 @@
if len(errs) != 1 {
return false
}
- if errs[0].Error() == expectedErr.Error() {
+ if strings.Contains(errs[0].Error(), expectedErr.Error()) {
return true
}
@@ -127,8 +127,12 @@
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
codegenCtx.unconvertedDepMode = tc.unconvertedDepsMode
bazelTargets, errs := generateBazelTargetsForDir(codegenCtx, checkDir)
- if tc.expectedErr != nil && checkError(t, errs, tc.expectedErr) {
- return
+ if tc.expectedErr != nil {
+ if checkError(t, errs, tc.expectedErr) {
+ return
+ } else {
+ t.Errorf("Expected error: %q, got: %q", tc.expectedErr, errs)
+ }
} else {
android.FailIfErrored(t, errs)
}
diff --git a/bpf/bpf.go b/bpf/bpf.go
index fa1a84d..9f0c86c 100644
--- a/bpf/bpf.go
+++ b/bpf/bpf.go
@@ -83,9 +83,9 @@
// The architecture doesn't matter here, but asm/types.h is included by linux/types.h.
"-isystem bionic/libc/kernel/uapi/asm-arm64",
"-isystem bionic/libc/kernel/android/uapi",
+ "-I frameworks/libs/net/common/native/bpf_headers/include/bpf",
// TODO(b/149785767): only give access to specific file with AID_* constants
"-I system/core/libcutils/include",
- "-I system/bpf/progs/include",
"-I " + ctx.ModuleDir(),
}
diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go
index c0925fe..b683472 100644
--- a/bpfix/bpfix/bpfix.go
+++ b/bpfix/bpfix/bpfix.go
@@ -641,7 +641,7 @@
// 'srcs' --> 'src' conversion
convertToSingleSource(mod, "src")
- renameProperty(mod, "sub_dir", "relative_install_dir")
+ renameProperty(mod, "sub_dir", "relative_install_path")
// The rewriter converts LOCAL_MODULE_PATH attribute into a struct attribute
// 'local_module_path'. Analyze its contents and create the correct sub_dir:,
@@ -1484,7 +1484,7 @@
ok := hasFile(relativePath+"/Android.mk", fs)
// some modules in the existing test cases in the androidmk_test.go do not have a valid path
if !ok && len(relativePath) > 0 {
- return fmt.Errorf("Cannot find an Android.mk file at path %s", relativePath)
+ return fmt.Errorf("Cannot find an Android.mk file at path %q", relativePath)
}
licenseKindsPropertyName := "android_license_kinds"
@@ -1661,9 +1661,12 @@
// if empty
return "", fmt.Errorf("Cannot find the value of the %s.%s property", mod.Type, property)
}
+ if relativePath == "" {
+ relativePath = "."
+ }
_, isDir, _ := fs.Exists(relativePath)
if !isDir {
- return "", fmt.Errorf("Cannot find the path %s", relativePath)
+ return "", fmt.Errorf("Cannot find the path %q", relativePath)
}
path := relativePath
for {
@@ -1675,7 +1678,7 @@
}
_, isDir, _ = fs.Exists(path)
if !isDir {
- return "", fmt.Errorf("Cannot find the path %s", path)
+ return "", fmt.Errorf("Cannot find the path %q", path)
}
return path, nil
}
diff --git a/bpfix/bpfix/bpfix_test.go b/bpfix/bpfix/bpfix_test.go
index 221df45..69f5967 100644
--- a/bpfix/bpfix/bpfix_test.go
+++ b/bpfix/bpfix/bpfix_test.go
@@ -824,7 +824,7 @@
out: `prebuilt_etc {
name: "foo",
src: "bar",
- relative_install_dir: "baz",
+ relative_install_path: "baz",
}
`,
},
@@ -1936,7 +1936,7 @@
fs: mockFs,
path: relativePathErr,
expectedErr: `
- Cannot find an Android.mk file at path a/b/c
+ Cannot find an Android.mk file at path "a/b/c"
`,
},
}
diff --git a/cc/Android.bp b/cc/Android.bp
index 07aa7cb..0bf0045 100644
--- a/cc/Android.bp
+++ b/cc/Android.bp
@@ -19,10 +19,11 @@
"soong-tradefed",
],
srcs: [
+ "afdo.go",
"androidmk.go",
"api_level.go",
- "builder.go",
"bp2build.go",
+ "builder.go",
"cc.go",
"ccdeps.go",
"check.go",
diff --git a/cc/afdo.go b/cc/afdo.go
new file mode 100644
index 0000000..022f283
--- /dev/null
+++ b/cc/afdo.go
@@ -0,0 +1,194 @@
+// Copyright 2021 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package cc
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/google/blueprint/proptools"
+
+ "android/soong/android"
+)
+
+var (
+ globalAfdoProfileProjects = []string{
+ "vendor/google_data/pgo_profile/sampling/",
+ "toolchain/pgo-profiles/sampling/",
+ }
+)
+
+var afdoProfileProjectsConfigKey = android.NewOnceKey("AfdoProfileProjects")
+
+const afdoCFlagsFormat = "-fprofile-sample-accurate -fprofile-sample-use=%s"
+
+func getAfdoProfileProjects(config android.DeviceConfig) []string {
+ return config.OnceStringSlice(afdoProfileProjectsConfigKey, func() []string {
+ return append(globalAfdoProfileProjects, config.AfdoAdditionalProfileDirs()...)
+ })
+}
+
+func recordMissingAfdoProfileFile(ctx BaseModuleContext, missing string) {
+ getNamedMapForConfig(ctx.Config(), modulesMissingProfileFileKey).Store(missing, true)
+}
+
+type AfdoProperties struct {
+ Afdo bool
+
+ AfdoTarget *string `blueprint:"mutated"`
+ AfdoDeps []string `blueprint:"mutated"`
+}
+
+type afdo struct {
+ Properties AfdoProperties
+}
+
+func (afdo *afdo) props() []interface{} {
+ return []interface{}{&afdo.Properties}
+}
+
+func (afdo *afdo) AfdoEnabled() bool {
+ return afdo != nil && afdo.Properties.Afdo && afdo.Properties.AfdoTarget != nil
+}
+
+// Get list of profile file names, ordered by level of specialisation. For example:
+// 1. libfoo_arm64.afdo
+// 2. libfoo.afdo
+// Add more specialisation as needed.
+func getProfileFiles(ctx BaseModuleContext, moduleName string) []string {
+ var files []string
+ files = append(files, moduleName+"_"+ctx.Arch().ArchType.String()+".afdo")
+ files = append(files, moduleName+".afdo")
+ return files
+}
+
+func (props *AfdoProperties) getAfdoProfileFile(ctx BaseModuleContext, module string) android.OptionalPath {
+ // Test if the profile_file is present in any of the Afdo profile projects
+ for _, profileFile := range getProfileFiles(ctx, module) {
+ for _, profileProject := range getAfdoProfileProjects(ctx.DeviceConfig()) {
+ path := android.ExistentPathForSource(ctx, profileProject, profileFile)
+ if path.Valid() {
+ return path
+ }
+ }
+ }
+
+ // Record that this module's profile file is absent
+ missing := ctx.ModuleDir() + ":" + module
+ recordMissingAfdoProfileFile(ctx, missing)
+
+ return android.OptionalPathForPath(nil)
+}
+
+func (afdo *afdo) begin(ctx BaseModuleContext) {
+ if afdo.Properties.Afdo && !ctx.static() && !ctx.Host() {
+ module := ctx.ModuleName()
+ if afdo.Properties.getAfdoProfileFile(ctx, module).Valid() {
+ afdo.Properties.AfdoTarget = proptools.StringPtr(module)
+ }
+ }
+}
+
+func (afdo *afdo) flags(ctx ModuleContext, flags Flags) Flags {
+ if profile := afdo.Properties.AfdoTarget; profile != nil {
+ if profileFile := afdo.Properties.getAfdoProfileFile(ctx, *profile); profileFile.Valid() {
+ profileFilePath := profileFile.Path()
+
+ profileUseFlag := fmt.Sprintf(afdoCFlagsFormat, profileFile)
+ flags.Local.CFlags = append(flags.Local.CFlags, profileUseFlag)
+ flags.Local.LdFlags = append(flags.Local.LdFlags, profileUseFlag)
+ flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-mllvm,-no-warn-sample-unused=true")
+
+ // Update CFlagsDeps and LdFlagsDeps so the module is rebuilt
+ // if profileFile gets updated
+ flags.CFlagsDeps = append(flags.CFlagsDeps, profileFilePath)
+ flags.LdFlagsDeps = append(flags.LdFlagsDeps, profileFilePath)
+ }
+ }
+
+ return flags
+}
+
+// Propagate afdo requirements down from binaries
+func afdoDepsMutator(mctx android.TopDownMutatorContext) {
+ if m, ok := mctx.Module().(*Module); ok && m.afdo.AfdoEnabled() {
+ afdoTarget := *m.afdo.Properties.AfdoTarget
+ mctx.WalkDeps(func(dep android.Module, parent android.Module) bool {
+ tag := mctx.OtherModuleDependencyTag(dep)
+ libTag, isLibTag := tag.(libraryDependencyTag)
+
+ // Do not recurse down non-static dependencies
+ if isLibTag {
+ if !libTag.static() {
+ return false
+ }
+ } else {
+ if tag != objDepTag && tag != reuseObjTag {
+ return false
+ }
+ }
+
+ if dep, ok := dep.(*Module); ok {
+ dep.afdo.Properties.AfdoDeps = append(dep.afdo.Properties.AfdoDeps, afdoTarget)
+ }
+
+ return true
+ })
+ }
+}
+
+// Create afdo variants for modules that need them
+func afdoMutator(mctx android.BottomUpMutatorContext) {
+ if m, ok := mctx.Module().(*Module); ok && m.afdo != nil {
+ if m.afdo.AfdoEnabled() && !m.static() {
+ afdoTarget := *m.afdo.Properties.AfdoTarget
+ mctx.SetDependencyVariation(encodeTarget(afdoTarget))
+ }
+
+ variationNames := []string{""}
+ afdoDeps := android.FirstUniqueStrings(m.afdo.Properties.AfdoDeps)
+ for _, dep := range afdoDeps {
+ variationNames = append(variationNames, encodeTarget(dep))
+ }
+ if len(variationNames) > 1 {
+ modules := mctx.CreateVariations(variationNames...)
+ for i, name := range variationNames {
+ if name == "" {
+ continue
+ }
+ variation := modules[i].(*Module)
+ variation.Properties.PreventInstall = true
+ variation.Properties.HideFromMake = true
+ variation.afdo.Properties.AfdoTarget = proptools.StringPtr(decodeTarget(name))
+ }
+ }
+ }
+}
+
+// Encode target name to variation name.
+func encodeTarget(target string) string {
+ if target == "" {
+ return ""
+ }
+ return "afdo-" + target
+}
+
+// Decode target name from variation name.
+func decodeTarget(variation string) string {
+ if variation == "" {
+ return ""
+ }
+ return strings.TrimPrefix(variation, "afdo-")
+}
diff --git a/cc/bp2build.go b/cc/bp2build.go
index e4762a0..cc2e60e 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -531,7 +531,7 @@
(&linkerAttrs).convertProductVariables(ctx, productVariableProps)
(&compilerAttrs).finalize(ctx, implementationHdrs)
- (&linkerAttrs).finalize()
+ (&linkerAttrs).finalize(ctx)
protoDep := bp2buildProto(ctx, module, compilerAttrs.protoSrcs)
@@ -550,13 +550,14 @@
// Convenience struct to hold all attributes parsed from linker properties.
type linkerAttributes struct {
- deps bazel.LabelListAttribute
- implementationDeps bazel.LabelListAttribute
- dynamicDeps bazel.LabelListAttribute
- implementationDynamicDeps bazel.LabelListAttribute
- wholeArchiveDeps bazel.LabelListAttribute
- implementationWholeArchiveDeps bazel.LabelListAttribute
- systemDynamicDeps bazel.LabelListAttribute
+ deps bazel.LabelListAttribute
+ implementationDeps bazel.LabelListAttribute
+ dynamicDeps bazel.LabelListAttribute
+ implementationDynamicDeps bazel.LabelListAttribute
+ wholeArchiveDeps bazel.LabelListAttribute
+ implementationWholeArchiveDeps bazel.LabelListAttribute
+ systemDynamicDeps bazel.LabelListAttribute
+ usedSystemDynamicDepAsDynamicDep map[string]bool
linkCrt bazel.BoolAttribute
useLibcrt bazel.BoolAttribute
@@ -571,6 +572,10 @@
features bazel.StringListAttribute
}
+var (
+ soongSystemSharedLibs = []string{"libc", "libm", "libdl"}
+)
+
func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversionPathContext, isBinary bool, axis bazel.ConfigurationAxis, config string, props *BaseLinkerProperties) {
// Use a single variable to capture usage of nocrt in arch variants, so there's only 1 error message for this module
var axisFeatures []string
@@ -602,6 +607,17 @@
la.systemDynamicDeps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, systemSharedLibs))
sharedLibs := android.FirstUniqueStrings(props.Shared_libs)
+ excludeSharedLibs := props.Exclude_shared_libs
+ usedSystem := android.FilterListPred(sharedLibs, func(s string) bool {
+ return android.InList(s, soongSystemSharedLibs) && !android.InList(s, excludeSharedLibs)
+ })
+ for _, el := range usedSystem {
+ if la.usedSystemDynamicDepAsDynamicDep == nil {
+ la.usedSystemDynamicDepAsDynamicDep = map[string]bool{}
+ }
+ la.usedSystemDynamicDepAsDynamicDep[el] = true
+ }
+
sharedDeps := maybePartitionExportedAndImplementationsDepsExcludes(ctx, !isBinary, sharedLibs, props.Exclude_shared_libs, props.Export_shared_lib_headers, bazelLabelForSharedDepsExcludes)
la.dynamicDeps.SetSelectValue(axis, config, sharedDeps.export)
la.implementationDynamicDeps.SetSelectValue(axis, config, sharedDeps.implementation)
@@ -721,13 +737,25 @@
}
}
-func (la *linkerAttributes) finalize() {
+func (la *linkerAttributes) finalize(ctx android.BazelConversionPathContext) {
+ // if system dynamic deps have the default value, any use of a system dynamic library used will
+ // result in duplicate library errors for bionic OSes. Here, we explicitly exclude those libraries
+ // from bionic OSes.
+ if la.systemDynamicDeps.IsNil() && len(la.usedSystemDynamicDepAsDynamicDep) > 0 {
+ toRemove := bazelLabelForSharedDeps(ctx, android.SortedStringKeys(la.usedSystemDynamicDepAsDynamicDep))
+ la.dynamicDeps.Exclude(bazel.OsConfigurationAxis, "android", toRemove)
+ la.dynamicDeps.Exclude(bazel.OsConfigurationAxis, "linux_bionic", toRemove)
+ la.implementationDynamicDeps.Exclude(bazel.OsConfigurationAxis, "android", toRemove)
+ la.implementationDynamicDeps.Exclude(bazel.OsConfigurationAxis, "linux_bionic", toRemove)
+ }
+
la.deps.ResolveExcludes()
la.implementationDeps.ResolveExcludes()
la.dynamicDeps.ResolveExcludes()
la.implementationDynamicDeps.ResolveExcludes()
la.wholeArchiveDeps.ResolveExcludes()
la.systemDynamicDeps.ForceSpecifyEmptyList = true
+
}
// Relativize a list of root-relative paths with respect to the module's
diff --git a/cc/cc.go b/cc/cc.go
index 281ebc1..a4b7c9c 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -64,6 +64,9 @@
ctx.BottomUp("coverage", coverageMutator).Parallel()
+ ctx.TopDown("afdo_deps", afdoDepsMutator)
+ ctx.BottomUp("afdo", afdoMutator).Parallel()
+
ctx.TopDown("lto_deps", ltoDepsMutator)
ctx.BottomUp("lto", ltoMutator).Parallel()
@@ -810,6 +813,7 @@
sabi *sabi
vndkdep *vndkdep
lto *lto
+ afdo *afdo
pgo *pgo
library libraryInterface
@@ -1143,6 +1147,9 @@
if c.lto != nil {
c.AddProperties(c.lto.props()...)
}
+ if c.afdo != nil {
+ c.AddProperties(c.afdo.props()...)
+ }
if c.pgo != nil {
c.AddProperties(c.pgo.props()...)
}
@@ -1620,6 +1627,7 @@
module.sabi = &sabi{}
module.vndkdep = &vndkdep{}
module.lto = <o{}
+ module.afdo = &afdo{}
module.pgo = &pgo{}
return module
}
@@ -1815,6 +1823,9 @@
if c.lto != nil {
flags = c.lto.flags(ctx, flags)
}
+ if c.afdo != nil {
+ flags = c.afdo.flags(ctx, flags)
+ }
if c.pgo != nil {
flags = c.pgo.flags(ctx, flags)
}
@@ -1942,6 +1953,9 @@
if c.lto != nil {
c.lto.begin(ctx)
}
+ if c.afdo != nil {
+ c.afdo.begin(ctx)
+ }
if c.pgo != nil {
c.pgo.begin(ctx)
}
@@ -3541,6 +3555,7 @@
&SAbiProperties{},
&VndkProperties{},
<OProperties{},
+ &AfdoProperties{},
&PgoProperties{},
&android.ProtoProperties{},
// RustBindgenProperties is included here so that cc_defaults can be used for rust_bindgen modules.
diff --git a/cc/config/global.go b/cc/config/global.go
index 7f2c23e..e46ac96 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -279,8 +279,8 @@
// prebuilts/clang default settings.
ClangDefaultBase = "prebuilts/clang/host"
- ClangDefaultVersion = "clang-r437112"
- ClangDefaultShortVersion = "14.0.0"
+ ClangDefaultVersion = "clang-r437112b"
+ ClangDefaultShortVersion = "14.0.1"
// Directories with warnings from Android.bp files.
WarningAllowedProjects = []string{
diff --git a/cc/coverage.go b/cc/coverage.go
index 8dd2db1..59c8864 100644
--- a/cc/coverage.go
+++ b/cc/coverage.go
@@ -22,6 +22,7 @@
"android/soong/android"
)
+// Add '%c' to default specifier after we resolve http://b/210012154
const profileInstrFlag = "-fprofile-instr-generate=/data/misc/trace/clang-%p-%m.profraw"
type CoverageProperties struct {
@@ -77,6 +78,11 @@
return deps
}
+func EnableContinuousCoverage(ctx android.BaseModuleContext) bool {
+ // http://b/210012154 Disable continuous coverage if we're instrumenting bionic/libc.
+ return !ctx.DeviceConfig().NativeCoverageEnabledForPath("bionic/libc")
+}
+
func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) {
clangCoverage := ctx.DeviceConfig().ClangCoverageEnabled()
gcovCoverage := ctx.DeviceConfig().GcovCoverageEnabled()
@@ -98,6 +104,9 @@
} else if clangCoverage {
flags.Local.CommonFlags = append(flags.Local.CommonFlags, profileInstrFlag,
"-fcoverage-mapping", "-Wno-pass-failed", "-D__ANDROID_CLANG_COVERAGE__")
+ if EnableContinuousCoverage(ctx) {
+ flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-mllvm", "-runtime-counter-relocation")
+ }
}
}
@@ -149,6 +158,9 @@
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--wrap,getenv")
} else if clangCoverage {
flags.Local.LdFlags = append(flags.Local.LdFlags, profileInstrFlag)
+ if EnableContinuousCoverage(ctx) {
+ flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-mllvm=-runtime-counter-relocation")
+ }
coverage := ctx.GetDirectDepWithTag(getClangProfileLibraryName(ctx), CoverageDepTag).(*Module)
deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path())
diff --git a/cc/sanitize.go b/cc/sanitize.go
index d7b1ade..6c68822 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -539,11 +539,6 @@
if Bool(s.Hwaddress) {
s.Address = nil
s.Thread = nil
- // Disable ubsan diagnosic as a workaround for a compiler bug.
- // TODO(b/191808836): re-enable.
- s.Diag.Undefined = nil
- s.Diag.Integer_overflow = nil
- s.Diag.Misc_undefined = nil
}
// TODO(b/131771163): CFI transiently depends on LTO, and thus Fuzzer is
diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go
index 83de65f..377a566 100644
--- a/etc/prebuilt_etc.go
+++ b/etc/prebuilt_etc.go
@@ -439,6 +439,7 @@
// This module is host-only
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
android.InitDefaultableModule(module)
+ android.InitBazelModule(module)
return module
}
@@ -665,7 +666,7 @@
// ConvertWithBp2build performs bp2build conversion of PrebuiltEtc
func (p *PrebuiltEtc) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
// All prebuilt_* modules are PrebuiltEtc, but at this time, we only convert prebuilt_etc modules.
- if ctx.ModuleType() != "prebuilt_etc" {
+ if p.installDirBase != "etc" {
return
}
diff --git a/filesystem/bootimg.go b/filesystem/bootimg.go
index fc973a4..33beb37 100644
--- a/filesystem/bootimg.go
+++ b/filesystem/bootimg.go
@@ -145,12 +145,10 @@
}
dtbName := proptools.String(b.properties.Dtb_prebuilt)
- if dtbName == "" {
- ctx.PropertyErrorf("dtb_prebuilt", "must be set")
- return output
+ if dtbName != "" {
+ dtb := android.PathForModuleSrc(ctx, dtbName)
+ cmd.FlagWithInput("--dtb ", dtb)
}
- dtb := android.PathForModuleSrc(ctx, dtbName)
- cmd.FlagWithInput("--dtb ", dtb)
cmdline := strings.Join(b.properties.Cmdline, " ")
if cmdline != "" {
@@ -178,20 +176,18 @@
cmd.FlagWithArg("--header_version ", headerVersion)
ramdiskName := proptools.String(b.properties.Ramdisk_module)
- if ramdiskName == "" {
- ctx.PropertyErrorf("ramdisk_module", "must be set")
- return output
- }
- ramdisk := ctx.GetDirectDepWithTag(ramdiskName, bootimgRamdiskDep)
- if filesystem, ok := ramdisk.(*filesystem); ok {
- flag := "--ramdisk "
- if vendor {
- flag = "--vendor_ramdisk "
+ if ramdiskName != "" {
+ ramdisk := ctx.GetDirectDepWithTag(ramdiskName, bootimgRamdiskDep)
+ if filesystem, ok := ramdisk.(*filesystem); ok {
+ flag := "--ramdisk "
+ if vendor {
+ flag = "--vendor_ramdisk "
+ }
+ cmd.FlagWithInput(flag, filesystem.OutputPath())
+ } else {
+ ctx.PropertyErrorf("ramdisk", "%q is not android_filesystem module", ramdisk.Name())
+ return output
}
- cmd.FlagWithInput(flag, filesystem.OutputPath())
- } else {
- ctx.PropertyErrorf("ramdisk", "%q is not android_filesystem module", ramdisk.Name())
- return output
}
bootconfig := proptools.String(b.properties.Bootconfig)
diff --git a/java/Android.bp b/java/Android.bp
index 8835b44..c062941 100644
--- a/java/Android.bp
+++ b/java/Android.bp
@@ -44,6 +44,7 @@
"dexpreopt_config.go",
"droiddoc.go",
"droidstubs.go",
+ "fuzz.go",
"gen.go",
"genrule.go",
"hiddenapi.go",
diff --git a/java/aar.go b/java/aar.go
index 13390db..aabbec6 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -616,6 +616,7 @@
exportPackage android.WritablePath
extraAaptPackagesFile android.WritablePath
manifest android.WritablePath
+ assetsPackage android.WritablePath
exportedStaticPackages android.Paths
@@ -686,9 +687,8 @@
return android.Paths{a.manifest}
}
-// TODO(jungjw): Decide whether we want to implement this.
func (a *AARImport) ExportedAssets() android.OptionalPath {
- return android.OptionalPath{}
+ return android.OptionalPathForPath(a.assetsPackage)
}
// RRO enforcement is not available on aar_import since its RRO dirs are not
@@ -732,10 +732,11 @@
blueprint.RuleParams{
Command: `rm -rf $outDir && mkdir -p $outDir && ` +
`unzip -qoDD -d $outDir $in && rm -rf $outDir/res && touch $out && ` +
+ `${config.Zip2ZipCmd} -i $in -o $assetsPackage 'assets/**/*' && ` +
`${config.MergeZipsCmd} $combinedClassesJar $$(ls $outDir/classes.jar 2> /dev/null) $$(ls $outDir/libs/*.jar 2> /dev/null)`,
- CommandDeps: []string{"${config.MergeZipsCmd}"},
+ CommandDeps: []string{"${config.MergeZipsCmd}", "${config.Zip2ZipCmd}"},
},
- "outDir", "combinedClassesJar")
+ "outDir", "combinedClassesJar", "assetsPackage")
func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if len(a.properties.Aars) != 1 {
@@ -761,15 +762,17 @@
a.classpathFile = extractedAARDir.Join(ctx, "classes-combined.jar")
a.proguardFlags = extractedAARDir.Join(ctx, "proguard.txt")
a.manifest = extractedAARDir.Join(ctx, "AndroidManifest.xml")
+ a.assetsPackage = android.PathForModuleOut(ctx, "assets.zip")
ctx.Build(pctx, android.BuildParams{
Rule: unzipAAR,
Input: a.aarPath,
- Outputs: android.WritablePaths{a.classpathFile, a.proguardFlags, a.manifest},
+ Outputs: android.WritablePaths{a.classpathFile, a.proguardFlags, a.manifest, a.assetsPackage},
Description: "unzip AAR",
Args: map[string]string{
"outDir": extractedAARDir.String(),
"combinedClassesJar": a.classpathFile.String(),
+ "assetsPackage": a.assetsPackage.String(),
},
})
@@ -812,6 +815,19 @@
aapt2Link(ctx, a.exportPackage, srcJar, proguardOptionsFile, rTxt, a.extraAaptPackagesFile,
linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil)
+ // Merge this import's assets with its dependencies' assets (if there are any).
+ if len(transitiveAssets) > 0 {
+ mergedAssets := android.PathForModuleOut(ctx, "merged-assets.zip")
+ inputZips := append(android.Paths{a.assetsPackage}, transitiveAssets...)
+ ctx.Build(pctx, android.BuildParams{
+ Rule: mergeAssetsRule,
+ Inputs: inputZips,
+ Output: mergedAssets,
+ Description: "merge assets from dependencies and self",
+ })
+ a.assetsPackage = mergedAssets
+ }
+
ctx.SetProvider(JavaInfoProvider, JavaInfo{
HeaderJars: android.PathsIfNonNil(a.classpathFile),
ImplementationAndResourcesJars: android.PathsIfNonNil(a.classpathFile),
diff --git a/java/androidmk.go b/java/androidmk.go
index 19fe7e2..b930441 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -433,8 +433,10 @@
if len(a.appProperties.Overrides) > 0 {
overridden = append(overridden, a.appProperties.Overrides...)
}
- if a.Name() != a.installApkName {
- overridden = append(overridden, a.Name())
+ // When APK name is overridden via PRODUCT_PACKAGE_NAME_OVERRIDES
+ // ensure that the original name is overridden.
+ if a.Stem() != a.installApkName {
+ overridden = append(overridden, a.Stem())
}
return overridden
}
diff --git a/java/app.go b/java/app.go
index 1c69aeb..f574599 100755
--- a/java/app.go
+++ b/java/app.go
@@ -621,7 +621,7 @@
a.aapt.useEmbeddedDex = Bool(a.appProperties.Use_embedded_dex)
// Check if the install APK name needs to be overridden.
- a.installApkName = ctx.DeviceConfig().OverridePackageNameFor(a.Name())
+ a.installApkName = ctx.DeviceConfig().OverridePackageNameFor(a.Stem())
if ctx.ModuleName() == "framework-res" {
// framework-res.apk is installed as system/framework/framework-res.apk
@@ -1006,6 +1006,7 @@
command := rule.Command().BuiltTool("test_config_fixer").Input(testConfig).Output(fixedConfig)
fixNeeded := false
+ // Auto-generated test config uses `ModuleName` as the APK name. So fix it if it is not the case.
if ctx.ModuleName() != a.installApkName {
fixNeeded = true
command.FlagWithArg("--test-file-name ", a.installApkName+".apk")
@@ -1162,7 +1163,10 @@
// some of its properties.
func OverrideAndroidAppModuleFactory() android.Module {
m := &OverrideAndroidApp{}
- m.AddProperties(&overridableAppProperties{})
+ m.AddProperties(
+ &OverridableDeviceProperties{},
+ &overridableAppProperties{},
+ )
android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
android.InitOverrideModule(m)
diff --git a/java/app_test.go b/java/app_test.go
index 4da7c3d..d9667b9 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -1707,7 +1707,7 @@
},
},
{
- name: "overridden",
+ name: "overridden via PRODUCT_PACKAGE_NAME_OVERRIDES",
bp: `
android_app {
name: "foo",
@@ -1722,6 +1722,22 @@
"out/soong/target/product/test_device/system/app/bar/bar.apk",
},
},
+ {
+ name: "overridden via stem",
+ bp: `
+ android_app {
+ name: "foo",
+ srcs: ["a.java"],
+ sdk_version: "current",
+ stem: "bar",
+ }
+ `,
+ packageNameOverride: "",
+ expected: []string{
+ "out/soong/.intermediates/foo/android_common/bar.apk",
+ "out/soong/target/product/test_device/system/app/bar/bar.apk",
+ },
+ },
}
for _, test := range testCases {
@@ -1965,6 +1981,80 @@
}
}
+func TestOverrideAndroidAppStem(t *testing.T) {
+ ctx, _ := testJava(t, `
+ android_app {
+ name: "foo",
+ srcs: ["a.java"],
+ sdk_version: "current",
+ }
+ override_android_app {
+ name: "bar",
+ base: "foo",
+ }
+ override_android_app {
+ name: "baz",
+ base: "foo",
+ stem: "baz_stem",
+ }
+ android_app {
+ name: "foo2",
+ srcs: ["a.java"],
+ sdk_version: "current",
+ stem: "foo2_stem",
+ }
+ override_android_app {
+ name: "bar2",
+ base: "foo2",
+ }
+ override_android_app {
+ name: "baz2",
+ base: "foo2",
+ stem: "baz2_stem",
+ }
+ `)
+ for _, expected := range []struct {
+ moduleName string
+ variantName string
+ apkPath string
+ }{
+ {
+ moduleName: "foo",
+ variantName: "android_common",
+ apkPath: "out/soong/target/product/test_device/system/app/foo/foo.apk",
+ },
+ {
+ moduleName: "foo",
+ variantName: "android_common_bar",
+ apkPath: "out/soong/target/product/test_device/system/app/bar/bar.apk",
+ },
+ {
+ moduleName: "foo",
+ variantName: "android_common_baz",
+ apkPath: "out/soong/target/product/test_device/system/app/baz_stem/baz_stem.apk",
+ },
+ {
+ moduleName: "foo2",
+ variantName: "android_common",
+ apkPath: "out/soong/target/product/test_device/system/app/foo2_stem/foo2_stem.apk",
+ },
+ {
+ moduleName: "foo2",
+ variantName: "android_common_bar2",
+ // Note that this may cause the duplicate output error.
+ apkPath: "out/soong/target/product/test_device/system/app/foo2_stem/foo2_stem.apk",
+ },
+ {
+ moduleName: "foo2",
+ variantName: "android_common_baz2",
+ apkPath: "out/soong/target/product/test_device/system/app/baz2_stem/baz2_stem.apk",
+ },
+ } {
+ variant := ctx.ModuleForTests(expected.moduleName, expected.variantName)
+ variant.Output(expected.apkPath)
+ }
+}
+
func TestOverrideAndroidAppDependency(t *testing.T) {
ctx, _ := testJava(t, `
android_app {
diff --git a/java/base.go b/java/base.go
index 7cd71a2..bc8da9a 100644
--- a/java/base.go
+++ b/java/base.go
@@ -253,9 +253,6 @@
// otherwise provides defaults libraries to add to the bootclasspath.
System_modules *string
- // set the name of the output
- Stem *string
-
IsSDKLibrary bool `blueprint:"mutated"`
// If true, generate the signature file of APK Signing Scheme V4, along side the signed APK file.
@@ -267,6 +264,15 @@
SyspropPublicStub string `blueprint:"mutated"`
}
+// Device properties that can be overridden by overriding module (e.g. override_android_app)
+type OverridableDeviceProperties struct {
+ // set the name of the output. If not set, `name` is used.
+ // To override a module with this property set, overriding module might need to set this as well.
+ // Otherwise, both the overridden and the overriding modules will have the same output name, which
+ // can cause the duplicate output error.
+ Stem *string
+}
+
// Functionality common to Module and Import
//
// It is embedded in Module so its functionality can be used by methods in Module
@@ -389,6 +395,8 @@
protoProperties android.ProtoProperties
deviceProperties DeviceProperties
+ overridableDeviceProperties OverridableDeviceProperties
+
// jar file containing header classes including static library dependencies, suitable for
// inserting into the bootclasspath/classpath of another compile
headerJarFile android.Path
@@ -544,6 +552,7 @@
j.addHostProperties()
j.AddProperties(
&j.deviceProperties,
+ &j.overridableDeviceProperties,
&j.dexer.dexProperties,
&j.dexpreoptProperties,
&j.linter.properties,
@@ -1671,7 +1680,7 @@
}
func (j *Module) Stem() string {
- return proptools.StringDefault(j.deviceProperties.Stem, j.Name())
+ return proptools.StringDefault(j.overridableDeviceProperties.Stem, j.Name())
}
func (j *Module) JacocoReportClassesFile() android.Path {
diff --git a/java/dex.go b/java/dex.go
index 8045b5c..c59c339 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -254,6 +254,15 @@
if BoolDefault(opt.Proguard_compatibility, true) {
r8Flags = append(r8Flags, "--force-proguard-compatibility")
+ } else {
+ // TODO(b/213833843): Allow configuration of the prefix via a build variable.
+ var sourceFilePrefix = "go/retraceme "
+ var sourceFileTemplate = "\"" + sourceFilePrefix + "%MAP_ID\""
+ // TODO(b/200967150): Also tag the source file in compat builds.
+ if Bool(opt.Optimize) || Bool(opt.Obfuscate) {
+ r8Flags = append(r8Flags, "--map-id-template", "%MAP_HASH")
+ r8Flags = append(r8Flags, "--source-file-template", sourceFileTemplate)
+ }
}
// TODO(ccross): Don't shrink app instrumentation tests by default.
diff --git a/java/dexpreopt_check.go b/java/dexpreopt_check.go
index 149cbb7..83c088c 100644
--- a/java/dexpreopt_check.go
+++ b/java/dexpreopt_check.go
@@ -72,8 +72,7 @@
return
}
- // TODO(b/203198541): Check all system server jars.
- systemServerJars := global.AllSystemServerClasspathJars(ctx)
+ systemServerJars := global.AllSystemServerJars(ctx)
for _, jar := range systemServerJars.CopyOfJars() {
dexLocation := dexpreopt.GetSystemServerDexLocation(ctx, global, jar)
odexLocation := dexpreopt.ToOdexPath(dexLocation, targets[0].Arch.ArchType)
diff --git a/java/droidstubs.go b/java/droidstubs.go
index 7ad316f..5a84e05 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -19,6 +19,7 @@
"path/filepath"
"strings"
+ "github.com/google/blueprint"
"github.com/google/blueprint/proptools"
"android/soong/android"
@@ -806,7 +807,8 @@
properties PrebuiltStubsSourcesProperties
- stubsSrcJar android.Path
+ stubsSrcJar android.Path
+ jsonDataActions []blueprint.JSONDataAction
}
func (p *PrebuiltStubsSources) OutputFiles(tag string) (android.Paths, error) {
@@ -822,6 +824,13 @@
return d.stubsSrcJar
}
+// AddJSONData is a temporary solution for droidstubs module to put action
+// related data into the module json graph.
+func (p *PrebuiltStubsSources) AddJSONData(d *map[string]interface{}) {
+ p.ModuleBase.AddJSONData(d)
+ (*d)["Actions"] = blueprint.FormatJSONDataActions(p.jsonDataActions)
+}
+
func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if len(p.properties.Srcs) != 1 {
ctx.PropertyErrorf("srcs", "must only specify one directory path or srcjar, contains %d paths", len(p.properties.Srcs))
@@ -829,9 +838,12 @@
}
src := p.properties.Srcs[0]
+ var jsonDataAction blueprint.JSONDataAction
if filepath.Ext(src) == ".srcjar" {
// This is a srcjar. We can use it directly.
p.stubsSrcJar = android.PathForModuleSrc(ctx, src)
+ jsonDataAction.Inputs = []string{src}
+ jsonDataAction.Outputs = []string{src}
} else {
outPath := android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
@@ -855,7 +867,10 @@
rule.Restat()
rule.Build("zip src", "Create srcjar from prebuilt source")
p.stubsSrcJar = outPath
+ jsonDataAction.Inputs = srcPaths.Strings()
+ jsonDataAction.Outputs = []string{outPath.String()}
}
+ p.jsonDataActions = []blueprint.JSONDataAction{jsonDataAction}
}
func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {
diff --git a/java/droidstubs_test.go b/java/droidstubs_test.go
index 10d99f3..5738217 100644
--- a/java/droidstubs_test.go
+++ b/java/droidstubs_test.go
@@ -21,6 +21,8 @@
"strings"
"testing"
+ "github.com/google/blueprint"
+
"android/soong/android"
)
@@ -232,6 +234,30 @@
checkSystemModulesUseByDroidstubs(t, ctx, "stubs-prebuilt-system-modules", "prebuilt-jar.jar")
}
+func TestAddJSONData(t *testing.T) {
+ prebuiltStubsSources := PrebuiltStubsSources{}
+ prebuiltStubsSources.jsonDataActions = []blueprint.JSONDataAction{
+ blueprint.JSONDataAction{
+ Inputs: []string{},
+ Outputs: []string{},
+ },
+ }
+ jsonData := map[string]interface{}{}
+ prebuiltStubsSources.AddJSONData(&jsonData)
+ if fmt.Sprint(jsonData) != fmt.Sprint(
+ map[string]interface{}{
+ "Android": map[string]interface{}{},
+ "Actions": []map[string]interface{}{
+ map[string]interface{}{
+ "Inputs": []string{},
+ "Outputs": []string{},
+ },
+ },
+ }) {
+ t.Errorf("The JSON data map isn't as expected %s.", jsonData)
+ }
+}
+
func checkSystemModulesUseByDroidstubs(t *testing.T, ctx *android.TestContext, moduleName string, systemJar string) {
metalavaRule := ctx.ModuleForTests(moduleName, "android_common").Rule("metalava")
var systemJars []string
diff --git a/java/fuzz.go b/java/fuzz.go
new file mode 100644
index 0000000..f72bfff
--- /dev/null
+++ b/java/fuzz.go
@@ -0,0 +1,72 @@
+// Copyright 2021 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package java
+
+import (
+ "github.com/google/blueprint/proptools"
+
+ "android/soong/android"
+ "android/soong/fuzz"
+)
+
+func init() {
+ RegisterJavaFuzzBuildComponents(android.InitRegistrationContext)
+}
+
+func RegisterJavaFuzzBuildComponents(ctx android.RegistrationContext) {
+ ctx.RegisterModuleType("java_fuzz_host", FuzzFactory)
+}
+
+type JavaFuzzLibrary struct {
+ Library
+ fuzzPackagedModule fuzz.FuzzPackagedModule
+}
+
+func (j *JavaFuzzLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ j.Library.GenerateAndroidBuildActions(ctx)
+
+ if j.fuzzPackagedModule.FuzzProperties.Corpus != nil {
+ j.fuzzPackagedModule.Corpus = android.PathsForModuleSrc(ctx, j.fuzzPackagedModule.FuzzProperties.Corpus)
+ }
+ if j.fuzzPackagedModule.FuzzProperties.Data != nil {
+ j.fuzzPackagedModule.Data = android.PathsForModuleSrc(ctx, j.fuzzPackagedModule.FuzzProperties.Data)
+ }
+ if j.fuzzPackagedModule.FuzzProperties.Dictionary != nil {
+ j.fuzzPackagedModule.Dictionary = android.PathForModuleSrc(ctx, *j.fuzzPackagedModule.FuzzProperties.Dictionary)
+ }
+
+ if j.fuzzPackagedModule.FuzzProperties.Fuzz_config != nil {
+ configPath := android.PathForModuleOut(ctx, "config").Join(ctx, "config.json")
+ android.WriteFileRule(ctx, configPath, j.fuzzPackagedModule.FuzzProperties.Fuzz_config.String())
+ j.fuzzPackagedModule.Config = configPath
+ }
+}
+
+// java_fuzz builds and links sources into a `.jar` file for the host.
+//
+// By default, a java_fuzz produces a `.jar` file containing `.class` files.
+// This jar is not suitable for installing on a device.
+func FuzzFactory() android.Module {
+ module := &JavaFuzzLibrary{}
+
+ module.addHostProperties()
+ module.Module.properties.Installable = proptools.BoolPtr(false)
+ module.AddProperties(&module.fuzzPackagedModule.FuzzProperties)
+
+ module.initModuleAndImport(module)
+ android.InitSdkAwareModule(module)
+ InitJavaModule(module, android.HostSupported)
+ return module
+}
diff --git a/java/fuzz_test.go b/java/fuzz_test.go
new file mode 100644
index 0000000..cf063eb
--- /dev/null
+++ b/java/fuzz_test.go
@@ -0,0 +1,65 @@
+// Copyright 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package java
+
+import (
+ "android/soong/android"
+ "path/filepath"
+ "testing"
+)
+
+var prepForJavaFuzzTest = android.GroupFixturePreparers(
+ PrepareForTestWithJavaDefaultModules,
+ android.FixtureRegisterWithContext(RegisterJavaFuzzBuildComponents),
+)
+
+func TestJavaFuzz(t *testing.T) {
+ result := prepForJavaFuzzTest.RunTestWithBp(t, `
+ java_fuzz_host {
+ name: "foo",
+ srcs: ["a.java"],
+ libs: ["bar"],
+ static_libs: ["baz"],
+ }
+
+ java_library_host {
+ name: "bar",
+ srcs: ["b.java"],
+ }
+
+ java_library_host {
+ name: "baz",
+ srcs: ["c.java"],
+ }`)
+
+ osCommonTarget := result.Config.BuildOSCommonTarget.String()
+ javac := result.ModuleForTests("foo", osCommonTarget).Rule("javac")
+ combineJar := result.ModuleForTests("foo", osCommonTarget).Description("for javac")
+
+ if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" {
+ t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs)
+ }
+
+ baz := result.ModuleForTests("baz", osCommonTarget).Rule("javac").Output.String()
+ barOut := filepath.Join("out", "soong", ".intermediates", "bar", osCommonTarget, "javac", "bar.jar")
+ bazOut := filepath.Join("out", "soong", ".intermediates", "baz", osCommonTarget, "javac", "baz.jar")
+
+ android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], barOut)
+ android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], bazOut)
+
+ if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz {
+ t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, baz)
+ }
+}
diff --git a/java/java.go b/java/java.go
index 9b4a005..bb7c32b 100644
--- a/java/java.go
+++ b/java/java.go
@@ -24,6 +24,7 @@
"strings"
"android/soong/bazel"
+
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -1866,6 +1867,7 @@
module.AddProperties(
&CommonProperties{},
&DeviceProperties{},
+ &OverridableDeviceProperties{},
&DexProperties{},
&DexpreoptProperties{},
&android.ProtoProperties{},
@@ -2000,6 +2002,7 @@
Deps bazel.LabelListAttribute
Main_class string
Jvm_flags bazel.StringListAttribute
+ Javacopts bazel.StringListAttribute
}
// JavaBinaryHostBp2Build is for java_binary_host bp2build.
@@ -2021,6 +2024,10 @@
Main_class: mainClass,
}
+ if m.properties.Javacflags != nil {
+ attrs.Javacopts = bazel.MakeStringListAttribute(m.properties.Javacflags)
+ }
+
// Attribute deps
deps := []string{}
if m.properties.Static_libs != nil {
diff --git a/java/sdk_library.go b/java/sdk_library.go
index 0bc8895..7849f96 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -2579,11 +2579,11 @@
implicitUntilAttr := formattedOptionalSdkLevelAttribute(ctx, "on-bootclasspath-before", module.properties.On_bootclasspath_before)
minSdkAttr := formattedOptionalSdkLevelAttribute(ctx, "min-device-sdk", module.properties.Min_device_sdk)
maxSdkAttr := formattedOptionalSdkLevelAttribute(ctx, "max-device-sdk", module.properties.Max_device_sdk)
- // <library> is understood in all android versions whereas <updatable-library> is only understood from API T (and ignored before that).
- // similarly, min_device_sdk is only understood from T. So if a library is using that, we need to use the updatable-library to make sure this library is not loaded before T
+ // <library> is understood in all android versions whereas <apex-library> is only understood from API T (and ignored before that).
+ // similarly, min_device_sdk is only understood from T. So if a library is using that, we need to use the apex-library to make sure this library is not loaded before T
var libraryTag string
if module.properties.Min_device_sdk != nil {
- libraryTag = ` <updatable-library\n`
+ libraryTag = ` <apex-library\n`
} else {
libraryTag = ` <library\n`
}
diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go
index f3a19e9..e60ca00 100644
--- a/java/sdk_library_test.go
+++ b/java/sdk_library_test.go
@@ -338,7 +338,7 @@
`)
// test that updatability attributes are passed on correctly
fooUpdatable := result.ModuleForTests("foo.xml", "android_common").Rule("java_sdk_xml")
- android.AssertStringDoesContain(t, "foo.xml java_sdk_xml command", fooUpdatable.RuleParams.Command, `<updatable-library`)
+ android.AssertStringDoesContain(t, "foo.xml java_sdk_xml command", fooUpdatable.RuleParams.Command, `<apex-library`)
android.AssertStringDoesNotContain(t, "foo.xml java_sdk_xml command", fooUpdatable.RuleParams.Command, `<library`)
}
diff --git a/mk2rbc/expr.go b/mk2rbc/expr.go
index 7cd4899..3f355ac 100644
--- a/mk2rbc/expr.go
+++ b/mk2rbc/expr.go
@@ -119,6 +119,29 @@
}
}
+type globalsExpr struct {
+}
+
+func (g *globalsExpr) emit(gctx *generationContext) {
+ gctx.write("g")
+}
+
+func (g *globalsExpr) typ() starlarkType {
+ return starlarkTypeUnknown
+}
+
+func (g *globalsExpr) emitListVarCopy(gctx *generationContext) {
+ g.emit(gctx)
+}
+
+func (g *globalsExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr {
+ if replacement := transformer(g); replacement != nil {
+ return replacement
+ } else {
+ return g
+ }
+}
+
// interpolateExpr represents Starlark's interpolation operator <string> % list
// we break <string> into a list of chunks, i.e., "first%second%third" % (X, Y)
// will have chunks = ["first", "second", "third"] and args = [X, Y]
@@ -322,35 +345,6 @@
}
func (eq *eqExpr) emit(gctx *generationContext) {
- var stringOperand string
- var otherOperand starlarkExpr
- if s, ok := maybeString(eq.left); ok {
- stringOperand = s
- otherOperand = eq.right
- } else if s, ok := maybeString(eq.right); ok {
- stringOperand = s
- otherOperand = eq.left
- }
-
- // If we've identified one of the operands as being a string literal, check
- // for some special cases we can do to simplify the resulting expression.
- if otherOperand != nil {
- if stringOperand == "" {
- if eq.isEq {
- gctx.write("not ")
- }
- otherOperand.emit(gctx)
- return
- }
- if stringOperand == "true" && otherOperand.typ() == starlarkTypeBool {
- if !eq.isEq {
- gctx.write("not ")
- }
- otherOperand.emit(gctx)
- return
- }
- }
-
if eq.left.typ() != eq.right.typ() {
eq.left = &toStringExpr{expr: eq.left}
eq.right = &toStringExpr{expr: eq.right}
@@ -594,29 +588,15 @@
}
func (cx *callExpr) emit(gctx *generationContext) {
- sep := ""
if cx.object != nil {
gctx.write("(")
cx.object.emit(gctx)
gctx.write(")")
gctx.write(".", cx.name, "(")
} else {
- kf, found := knownFunctions[cx.name]
- if !found {
- panic(fmt.Errorf("callExpr with unknown function %q", cx.name))
- }
- if kf.runtimeName[0] == '!' {
- panic(fmt.Errorf("callExpr for %q should not be there", cx.name))
- }
- gctx.write(kf.runtimeName, "(")
- if kf.hiddenArg == hiddenArgGlobal {
- gctx.write("g")
- sep = ", "
- } else if kf.hiddenArg == hiddenArgConfig {
- gctx.write("cfg")
- sep = ", "
- }
+ gctx.write(cx.name, "(")
}
+ sep := ""
for _, arg := range cx.args {
gctx.write(sep)
arg.emit(gctx)
@@ -748,6 +728,36 @@
}
}
+type binaryOpExpr struct {
+ left, right starlarkExpr
+ op string
+ returnType starlarkType
+}
+
+func (b *binaryOpExpr) emit(gctx *generationContext) {
+ b.left.emit(gctx)
+ gctx.write(" " + b.op + " ")
+ b.right.emit(gctx)
+}
+
+func (b *binaryOpExpr) typ() starlarkType {
+ return b.returnType
+}
+
+func (b *binaryOpExpr) emitListVarCopy(gctx *generationContext) {
+ b.emit(gctx)
+}
+
+func (b *binaryOpExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr {
+ b.left = b.left.transform(transformer)
+ b.right = b.right.transform(transformer)
+ if replacement := transformer(b); replacement != nil {
+ return replacement
+ } else {
+ return b
+ }
+}
+
type badExpr struct {
errorLocation ErrorLocation
message string
diff --git a/mk2rbc/mk2rbc.go b/mk2rbc/mk2rbc.go
index 2a80e56..14988e7 100644
--- a/mk2rbc/mk2rbc.go
+++ b/mk2rbc/mk2rbc.go
@@ -54,7 +54,6 @@
cfnMain = baseName + ".product_configuration"
cfnBoardMain = baseName + ".board_configuration"
cfnPrintVars = baseName + ".printvars"
- cfnPrintGlobals = baseName + ".printglobals"
cfnWarning = baseName + ".warning"
cfnLocalAppend = baseName + ".local_append"
cfnLocalSetDefault = baseName + ".local_set_default"
@@ -63,92 +62,78 @@
)
const (
- // Phony makefile functions, they are eventually rewritten
- // according to knownFunctions map
- fileExistsPhony = "$file_exists"
- // The following two macros are obsolete, and will we deleted once
- // there are deleted from the makefiles:
- soongConfigNamespaceOld = "add_soong_config_namespace"
- soongConfigVarSetOld = "add_soong_config_var_value"
- soongConfigAppend = "soong_config_append"
- soongConfigAssign = "soong_config_set"
- soongConfigGet = "soong_config_get"
- wildcardExistsPhony = "$wildcard_exists"
+ soongConfigAppend = "soong_config_append"
+ soongConfigAssign = "soong_config_set"
)
-const (
- callLoadAlways = "inherit-product"
- callLoadIf = "inherit-product-if-exists"
-)
-
-var knownFunctions = map[string]struct {
- // The name of the runtime function this function call in makefiles maps to.
- // If it starts with !, then this makefile function call is rewritten to
- // something else.
- runtimeName string
- returnType starlarkType
- hiddenArg hiddenArgType
+var knownFunctions = map[string]interface {
+ parse(ctx *parseContext, node mkparser.Node, args *mkparser.MakeString) starlarkExpr
}{
- "abspath": {baseName + ".abspath", starlarkTypeString, hiddenArgNone},
- fileExistsPhony: {baseName + ".file_exists", starlarkTypeBool, hiddenArgNone},
- wildcardExistsPhony: {baseName + ".file_wildcard_exists", starlarkTypeBool, hiddenArgNone},
- soongConfigNamespaceOld: {baseName + ".soong_config_namespace", starlarkTypeVoid, hiddenArgGlobal},
- soongConfigVarSetOld: {baseName + ".soong_config_set", starlarkTypeVoid, hiddenArgGlobal},
- soongConfigAssign: {baseName + ".soong_config_set", starlarkTypeVoid, hiddenArgGlobal},
- soongConfigAppend: {baseName + ".soong_config_append", starlarkTypeVoid, hiddenArgGlobal},
- soongConfigGet: {baseName + ".soong_config_get", starlarkTypeString, hiddenArgGlobal},
- "add-to-product-copy-files-if-exists": {baseName + ".copy_if_exists", starlarkTypeList, hiddenArgNone},
- "addprefix": {baseName + ".addprefix", starlarkTypeList, hiddenArgNone},
- "addsuffix": {baseName + ".addsuffix", starlarkTypeList, hiddenArgNone},
- "copy-files": {baseName + ".copy_files", starlarkTypeList, hiddenArgNone},
- "dir": {baseName + ".dir", starlarkTypeList, hiddenArgNone},
- "dist-for-goals": {baseName + ".mkdist_for_goals", starlarkTypeVoid, hiddenArgGlobal},
- "enforce-product-packages-exist": {baseName + ".enforce_product_packages_exist", starlarkTypeVoid, hiddenArgNone},
- "error": {baseName + ".mkerror", starlarkTypeVoid, hiddenArgNone},
- "findstring": {baseName + ".findstring", starlarkTypeString, hiddenArgNone},
- "find-copy-subdir-files": {baseName + ".find_and_copy", starlarkTypeList, hiddenArgNone},
- "find-word-in-list": {"!find-word-in-list", starlarkTypeUnknown, hiddenArgNone}, // internal macro
- "filter": {baseName + ".filter", starlarkTypeList, hiddenArgNone},
- "filter-out": {baseName + ".filter_out", starlarkTypeList, hiddenArgNone},
- "firstword": {"!firstword", starlarkTypeString, hiddenArgNone},
- "foreach": {"!foreach", starlarkTypeList, hiddenArgNone},
- "get-vendor-board-platforms": {"!get-vendor-board-platforms", starlarkTypeList, hiddenArgNone}, // internal macro, used by is-board-platform, etc.
- "if": {"!if", starlarkTypeUnknown, hiddenArgNone},
- "info": {baseName + ".mkinfo", starlarkTypeVoid, hiddenArgNone},
- "is-android-codename": {"!is-android-codename", starlarkTypeBool, hiddenArgNone}, // unused by product config
- "is-android-codename-in-list": {"!is-android-codename-in-list", starlarkTypeBool, hiddenArgNone}, // unused by product config
- "is-board-platform": {"!is-board-platform", starlarkTypeBool, hiddenArgNone},
- "is-board-platform2": {baseName + ".board_platform_is", starlarkTypeBool, hiddenArgGlobal},
- "is-board-platform-in-list": {"!is-board-platform-in-list", starlarkTypeBool, hiddenArgNone},
- "is-board-platform-in-list2": {baseName + ".board_platform_in", starlarkTypeBool, hiddenArgGlobal},
- "is-chipset-in-board-platform": {"!is-chipset-in-board-platform", starlarkTypeUnknown, hiddenArgNone}, // unused by product config
- "is-chipset-prefix-in-board-platform": {"!is-chipset-prefix-in-board-platform", starlarkTypeBool, hiddenArgNone}, // unused by product config
- "is-not-board-platform": {"!is-not-board-platform", starlarkTypeBool, hiddenArgNone}, // defined but never used
- "is-platform-sdk-version-at-least": {"!is-platform-sdk-version-at-least", starlarkTypeBool, hiddenArgNone}, // unused by product config
- "is-product-in-list": {"!is-product-in-list", starlarkTypeBool, hiddenArgNone},
- "is-vendor-board-platform": {"!is-vendor-board-platform", starlarkTypeBool, hiddenArgNone},
- "is-vendor-board-qcom": {"!is-vendor-board-qcom", starlarkTypeBool, hiddenArgNone},
- callLoadAlways: {"!inherit-product", starlarkTypeVoid, hiddenArgNone},
- callLoadIf: {"!inherit-product-if-exists", starlarkTypeVoid, hiddenArgNone},
- "lastword": {"!lastword", starlarkTypeString, hiddenArgNone},
- "match-prefix": {"!match-prefix", starlarkTypeUnknown, hiddenArgNone}, // internal macro
- "match-word": {"!match-word", starlarkTypeUnknown, hiddenArgNone}, // internal macro
- "match-word-in-list": {"!match-word-in-list", starlarkTypeUnknown, hiddenArgNone}, // internal macro
- "notdir": {baseName + ".notdir", starlarkTypeString, hiddenArgNone},
- "my-dir": {"!my-dir", starlarkTypeString, hiddenArgNone},
- "patsubst": {baseName + ".mkpatsubst", starlarkTypeString, hiddenArgNone},
- "product-copy-files-by-pattern": {baseName + ".product_copy_files_by_pattern", starlarkTypeList, hiddenArgNone},
- "require-artifacts-in-path": {baseName + ".require_artifacts_in_path", starlarkTypeVoid, hiddenArgNone},
- "require-artifacts-in-path-relaxed": {baseName + ".require_artifacts_in_path_relaxed", starlarkTypeVoid, hiddenArgNone},
+ "abspath": &simpleCallParser{name: baseName + ".abspath", returnType: starlarkTypeString, addGlobals: false},
+ "add_soong_config_namespace": &simpleCallParser{name: baseName + ".soong_config_namespace", returnType: starlarkTypeVoid, addGlobals: true},
+ "add_soong_config_var_value": &simpleCallParser{name: baseName + ".soong_config_set", returnType: starlarkTypeVoid, addGlobals: true},
+ soongConfigAssign: &simpleCallParser{name: baseName + ".soong_config_set", returnType: starlarkTypeVoid, addGlobals: true},
+ soongConfigAppend: &simpleCallParser{name: baseName + ".soong_config_append", returnType: starlarkTypeVoid, addGlobals: true},
+ "soong_config_get": &simpleCallParser{name: baseName + ".soong_config_get", returnType: starlarkTypeString, addGlobals: true},
+ "add-to-product-copy-files-if-exists": &simpleCallParser{name: baseName + ".copy_if_exists", returnType: starlarkTypeList, addGlobals: false},
+ "addprefix": &simpleCallParser{name: baseName + ".addprefix", returnType: starlarkTypeList, addGlobals: false},
+ "addsuffix": &simpleCallParser{name: baseName + ".addsuffix", returnType: starlarkTypeList, addGlobals: false},
+ "copy-files": &simpleCallParser{name: baseName + ".copy_files", returnType: starlarkTypeList, addGlobals: false},
+ "dir": &simpleCallParser{name: baseName + ".dir", returnType: starlarkTypeList, addGlobals: false},
+ "dist-for-goals": &simpleCallParser{name: baseName + ".mkdist_for_goals", returnType: starlarkTypeVoid, addGlobals: true},
+ "enforce-product-packages-exist": &simpleCallParser{name: baseName + ".enforce_product_packages_exist", returnType: starlarkTypeVoid, addGlobals: false},
+ "error": &makeControlFuncParser{name: baseName + ".mkerror"},
+ "findstring": &simpleCallParser{name: baseName + ".findstring", returnType: starlarkTypeInt, addGlobals: false},
+ "find-copy-subdir-files": &simpleCallParser{name: baseName + ".find_and_copy", returnType: starlarkTypeList, addGlobals: false},
+ "filter": &simpleCallParser{name: baseName + ".filter", returnType: starlarkTypeList, addGlobals: false},
+ "filter-out": &simpleCallParser{name: baseName + ".filter_out", returnType: starlarkTypeList, addGlobals: false},
+ "firstword": &firstOrLastwordCallParser{isLastWord: false},
+ "foreach": &foreachCallPaser{},
+ "if": &ifCallParser{},
+ "info": &makeControlFuncParser{name: baseName + ".mkinfo"},
+ "is-board-platform": &simpleCallParser{name: baseName + ".board_platform_is", returnType: starlarkTypeBool, addGlobals: true},
+ "is-board-platform2": &simpleCallParser{name: baseName + ".board_platform_is", returnType: starlarkTypeBool, addGlobals: true},
+ "is-board-platform-in-list": &simpleCallParser{name: baseName + ".board_platform_in", returnType: starlarkTypeBool, addGlobals: true},
+ "is-board-platform-in-list2": &simpleCallParser{name: baseName + ".board_platform_in", returnType: starlarkTypeBool, addGlobals: true},
+ "is-product-in-list": &isProductInListCallParser{},
+ "is-vendor-board-platform": &isVendorBoardPlatformCallParser{},
+ "is-vendor-board-qcom": &isVendorBoardQcomCallParser{},
+ "lastword": &firstOrLastwordCallParser{isLastWord: true},
+ "notdir": &simpleCallParser{name: baseName + ".notdir", returnType: starlarkTypeString, addGlobals: false},
+ "math_max": &mathMaxOrMinCallParser{function: "max"},
+ "math_min": &mathMaxOrMinCallParser{function: "min"},
+ "math_gt_or_eq": &mathComparisonCallParser{op: ">="},
+ "math_gt": &mathComparisonCallParser{op: ">"},
+ "math_lt": &mathComparisonCallParser{op: "<"},
+ "my-dir": &myDirCallParser{},
+ "patsubst": &substCallParser{fname: "patsubst"},
+ "product-copy-files-by-pattern": &simpleCallParser{name: baseName + ".product_copy_files_by_pattern", returnType: starlarkTypeList, addGlobals: false},
+ "require-artifacts-in-path": &simpleCallParser{name: baseName + ".require_artifacts_in_path", returnType: starlarkTypeVoid, addGlobals: false},
+ "require-artifacts-in-path-relaxed": &simpleCallParser{name: baseName + ".require_artifacts_in_path_relaxed", returnType: starlarkTypeVoid, addGlobals: false},
// TODO(asmundak): remove it once all calls are removed from configuration makefiles. see b/183161002
- "shell": {baseName + ".shell", starlarkTypeString, hiddenArgNone},
- "strip": {baseName + ".mkstrip", starlarkTypeString, hiddenArgNone},
- "tb-modules": {"!tb-modules", starlarkTypeUnknown, hiddenArgNone}, // defined in hardware/amlogic/tb_modules/tb_detect.mk, unused
- "subst": {baseName + ".mksubst", starlarkTypeString, hiddenArgNone},
- "warning": {baseName + ".mkwarning", starlarkTypeVoid, hiddenArgNone},
- "word": {baseName + "!word", starlarkTypeString, hiddenArgNone},
- "wildcard": {baseName + ".expand_wildcard", starlarkTypeList, hiddenArgNone},
- "words": {baseName + ".words", starlarkTypeList, hiddenArgNone},
+ "shell": &shellCallParser{},
+ "strip": &simpleCallParser{name: baseName + ".mkstrip", returnType: starlarkTypeString, addGlobals: false},
+ "subst": &substCallParser{fname: "subst"},
+ "warning": &makeControlFuncParser{name: baseName + ".mkwarning"},
+ "word": &wordCallParser{},
+ "wildcard": &simpleCallParser{name: baseName + ".expand_wildcard", returnType: starlarkTypeList, addGlobals: false},
+}
+
+// These are functions that we don't implement conversions for, but
+// we allow seeing their definitions in the product config files.
+var ignoredDefines = map[string]bool{
+ "find-word-in-list": true, // internal macro
+ "get-vendor-board-platforms": true, // internal macro, used by is-board-platform, etc.
+ "is-android-codename": true, // unused by product config
+ "is-android-codename-in-list": true, // unused by product config
+ "is-chipset-in-board-platform": true, // unused by product config
+ "is-chipset-prefix-in-board-platform": true, // unused by product config
+ "is-not-board-platform": true, // defined but never used
+ "is-platform-sdk-version-at-least": true, // unused by product config
+ "match-prefix": true, // internal macro
+ "match-word": true, // internal macro
+ "match-word-in-list": true, // internal macro
+ "tb-modules": true, // defined in hardware/amlogic/tb_modules/tb_detect.mk, unused
}
var identifierFullMatchRegex = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$")
@@ -466,7 +451,7 @@
variables: make(map[string]variable),
dependentModules: make(map[string]*moduleInfo),
soongNamespaces: make(map[string]map[string]bool),
- includeTops: []string{"vendor/google-devices"},
+ includeTops: []string{},
}
ctx.pushVarAssignments()
for _, item := range predefined {
@@ -641,8 +626,8 @@
for _, ns := range strings.Fields(s) {
ctx.addSoongNamespace(ns)
ctx.receiver.newNode(&exprNode{&callExpr{
- name: soongConfigNamespaceOld,
- args: []starlarkExpr{&stringLiteralExpr{ns}},
+ name: baseName + ".soong_config_namespace",
+ args: []starlarkExpr{&globalsExpr{}, &stringLiteralExpr{ns}},
returnType: starlarkTypeVoid,
}})
}
@@ -691,13 +676,13 @@
ctx.errorf(asgn, "no %s variable in %s namespace, please use add_soong_config_var_value instead", varName, namespaceName)
return
}
- fname := soongConfigAssign
+ fname := baseName + "." + soongConfigAssign
if asgn.Type == "+=" {
- fname = soongConfigAppend
+ fname = baseName + "." + soongConfigAppend
}
ctx.receiver.newNode(&exprNode{&callExpr{
name: fname,
- args: []starlarkExpr{&stringLiteralExpr{namespaceName}, &stringLiteralExpr{varName}, val},
+ args: []starlarkExpr{&globalsExpr{}, &stringLiteralExpr{namespaceName}, &stringLiteralExpr{varName}, val},
returnType: starlarkTypeVoid,
}})
}
@@ -829,6 +814,10 @@
}
}
if pathPattern[0] == "" {
+ if len(ctx.includeTops) == 0 {
+ ctx.errorf(v, "inherit-product/include statements must not be prefixed with a variable, or must include a #RBC# include_top comment beforehand giving a root directory to search.")
+ return
+ }
// If pattern starts from the top. restrict it to the directories where
// we know inherit-product uses dynamically calculated path.
for _, p := range ctx.includeTops {
@@ -878,7 +867,13 @@
return res
}
-func (ctx *parseContext) handleInheritModule(v mkparser.Node, pathExpr starlarkExpr, loadAlways bool) {
+func (ctx *parseContext) handleInheritModule(v mkparser.Node, args *mkparser.MakeString, loadAlways bool) {
+ args.TrimLeftSpaces()
+ args.TrimRightSpaces()
+ pathExpr := ctx.parseMakeString(v, args)
+ if _, ok := pathExpr.(*badExpr); ok {
+ ctx.errorf(v, "Unable to parse argument to inherit")
+ }
ctx.handleSubConfig(v, pathExpr, loadAlways, func(im inheritedModule) {
ctx.receiver.newNode(&inheritNode{im, loadAlways})
})
@@ -897,36 +892,40 @@
// $(info xxx)
// $(warning xxx)
// $(error xxx)
+ // $(call other-custom-functions,...)
+
+ // inherit-product(-if-exists) gets converted to a series of statements,
+ // not just a single expression like parseReference returns. So handle it
+ // separately at the beginning here.
+ if strings.HasPrefix(v.Name.Dump(), "call inherit-product,") {
+ args := v.Name.Clone()
+ args.ReplaceLiteral("call inherit-product,", "")
+ ctx.handleInheritModule(v, args, true)
+ return
+ }
+ if strings.HasPrefix(v.Name.Dump(), "call inherit-product-if-exists,") {
+ args := v.Name.Clone()
+ args.ReplaceLiteral("call inherit-product-if-exists,", "")
+ ctx.handleInheritModule(v, args, false)
+ return
+ }
expr := ctx.parseReference(v, v.Name)
switch x := expr.(type) {
case *callExpr:
- if x.name == callLoadAlways || x.name == callLoadIf {
- ctx.handleInheritModule(v, x.args[0], x.name == callLoadAlways)
- } else if isMakeControlFunc(x.name) {
- // File name is the first argument
- args := []starlarkExpr{
- &stringLiteralExpr{ctx.script.mkFile},
- x.args[0],
- }
- ctx.receiver.newNode(&exprNode{
- &callExpr{name: x.name, args: args, returnType: starlarkTypeUnknown},
- })
- } else {
- ctx.receiver.newNode(&exprNode{expr})
- }
+ ctx.receiver.newNode(&exprNode{expr})
case *badExpr:
ctx.wrapBadExpr(x)
- return
default:
ctx.errorf(v, "cannot handle %s", v.Dump())
- return
}
}
func (ctx *parseContext) handleDefine(directive *mkparser.Directive) {
macro_name := strings.Fields(directive.Args.Strings[0])[0]
// Ignore the macros that we handle
- if _, ok := knownFunctions[macro_name]; !ok {
+ _, ignored := ignoredDefines[macro_name]
+ _, known := knownFunctions[macro_name]
+ if !ignored && !known {
ctx.errorf(directive, "define is not supported: %s", macro_name)
}
}
@@ -1056,6 +1055,72 @@
return expr
}
+ var stringOperand string
+ var otherOperand starlarkExpr
+ if s, ok := maybeString(xLeft); ok {
+ stringOperand = s
+ otherOperand = xRight
+ } else if s, ok := maybeString(xRight); ok {
+ stringOperand = s
+ otherOperand = xLeft
+ }
+
+ not := func(expr starlarkExpr) starlarkExpr {
+ switch typedExpr := expr.(type) {
+ case *inExpr:
+ typedExpr.isNot = !typedExpr.isNot
+ return typedExpr
+ case *eqExpr:
+ typedExpr.isEq = !typedExpr.isEq
+ return typedExpr
+ case *binaryOpExpr:
+ switch typedExpr.op {
+ case ">":
+ typedExpr.op = "<="
+ return typedExpr
+ case "<":
+ typedExpr.op = ">="
+ return typedExpr
+ case ">=":
+ typedExpr.op = "<"
+ return typedExpr
+ case "<=":
+ typedExpr.op = ">"
+ return typedExpr
+ default:
+ return ¬Expr{expr: expr}
+ }
+ default:
+ return ¬Expr{expr: expr}
+ }
+ }
+
+ // If we've identified one of the operands as being a string literal, check
+ // for some special cases we can do to simplify the resulting expression.
+ if otherOperand != nil {
+ if stringOperand == "" {
+ if isEq {
+ return not(otherOperand)
+ } else {
+ return otherOperand
+ }
+ }
+ if stringOperand == "true" && otherOperand.typ() == starlarkTypeBool {
+ if !isEq {
+ return not(otherOperand)
+ } else {
+ return otherOperand
+ }
+ }
+ if intOperand, err := strconv.Atoi(strings.TrimSpace(stringOperand)); err == nil && otherOperand.typ() == starlarkTypeInt {
+ return &eqExpr{
+ left: otherOperand,
+ right: &intLiteralExpr{literal: intOperand},
+ isEq: isEq,
+ }
+ }
+ }
+
return &eqExpr{left: xLeft, right: xRight, isEq: isEq}
}
@@ -1089,97 +1154,15 @@
return nil, false
}
- checkIsSomethingFunction := func(xCall *callExpr) starlarkExpr {
- s, ok := maybeString(value)
- if !ok || s != "true" {
- return ctx.newBadExpr(directive,
- fmt.Sprintf("the result of %s can be compared only to 'true'", xCall.name))
- }
- if len(xCall.args) < 1 {
- return ctx.newBadExpr(directive, "%s requires an argument", xCall.name)
- }
- return nil
- }
-
switch call.name {
- case "filter", "filter-out":
+ case baseName + ".filter", baseName + ".filter-out":
return ctx.parseCompareFilterFuncResult(directive, call, value, isEq), true
- case "wildcard":
+ case baseName + ".expand_wildcard":
return ctx.parseCompareWildcardFuncResult(directive, call, value, !isEq), true
- case "findstring":
+ case baseName + ".findstring":
return ctx.parseCheckFindstringFuncResult(directive, call, value, !isEq), true
- case "strip":
+ case baseName + ".strip":
return ctx.parseCompareStripFuncResult(directive, call, value, !isEq), true
- case "is-board-platform":
- if xBad := checkIsSomethingFunction(call); xBad != nil {
- return xBad, true
- }
- return &eqExpr{
- left: NewVariableRefExpr(ctx.addVariable("TARGET_BOARD_PLATFORM"), false),
- right: call.args[0],
- isEq: isEq,
- }, true
- case "is-board-platform-in-list":
- if xBad := checkIsSomethingFunction(call); xBad != nil {
- return xBad, true
- }
- return &inExpr{
- expr: NewVariableRefExpr(ctx.addVariable("TARGET_BOARD_PLATFORM"), false),
- list: maybeConvertToStringList(call.args[0]),
- isNot: !isEq,
- }, true
- case "is-product-in-list":
- if xBad := checkIsSomethingFunction(call); xBad != nil {
- return xBad, true
- }
- return &inExpr{
- expr: NewVariableRefExpr(ctx.addVariable("TARGET_PRODUCT"), true),
- list: maybeConvertToStringList(call.args[0]),
- isNot: !isEq,
- }, true
- case "is-vendor-board-platform":
- if xBad := checkIsSomethingFunction(call); xBad != nil {
- return xBad, true
- }
- s, ok := maybeString(call.args[0])
- if !ok {
- return ctx.newBadExpr(directive, "cannot handle non-constant argument to is-vendor-board-platform"), true
- }
- return &inExpr{
- expr: NewVariableRefExpr(ctx.addVariable("TARGET_BOARD_PLATFORM"), false),
- list: NewVariableRefExpr(ctx.addVariable(s+"_BOARD_PLATFORMS"), true),
- isNot: !isEq,
- }, true
-
- case "is-board-platform2", "is-board-platform-in-list2":
- if s, ok := maybeString(value); !ok || s != "" {
- return ctx.newBadExpr(directive,
- fmt.Sprintf("the result of %s can be compared only to empty", call.name)), true
- }
- if len(call.args) != 1 {
- return ctx.newBadExpr(directive, "%s requires an argument", call.name), true
- }
- cc := &callExpr{
- name: call.name,
- args: []starlarkExpr{call.args[0]},
- returnType: starlarkTypeBool,
- }
- if isEq {
- return ¬Expr{cc}, true
- }
- return cc, true
- case "is-vendor-board-qcom":
- if s, ok := maybeString(value); !ok || s != "" {
- return ctx.newBadExpr(directive,
- fmt.Sprintf("the result of %s can be compared only to empty", call.name)), true
- }
- // if the expression is ifneq (,$(call is-vendor-board-platform,...)), negate==true,
- // so we should set inExpr.isNot to false
- return &inExpr{
- expr: NewVariableRefExpr(ctx.addVariable("TARGET_BOARD_PLATFORM"), false),
- list: NewVariableRefExpr(ctx.addVariable("QCOM_BOARD_PLATFORMS"), true),
- isNot: isEq,
- }, true
}
return nil, false
}
@@ -1254,9 +1237,9 @@
if !isEmptyString(xValue) {
return ctx.newBadExpr(directive, "wildcard result can be compared only to empty: %s", xValue)
}
- callFunc := wildcardExistsPhony
+ callFunc := baseName + ".file_wildcard_exists"
if s, ok := xCall.args[0].(*stringLiteralExpr); ok && !strings.ContainsAny(s.literal, "*?{[") {
- callFunc = fileExistsPhony
+ callFunc = baseName + ".file_exists"
}
var cc starlarkExpr = &callExpr{name: callFunc, args: xCall.args, returnType: starlarkTypeBool}
if !negate {
@@ -1323,14 +1306,7 @@
// If it is a single word, it can be a simple variable
// reference or a function call
- if len(words) == 1 {
- if isMakeControlFunc(refDump) || refDump == "shell" {
- return &callExpr{
- name: refDump,
- args: []starlarkExpr{&stringLiteralExpr{""}},
- returnType: starlarkTypeUnknown,
- }
- }
+ if len(words) == 1 && !isMakeControlFunc(refDump) && refDump != "shell" {
if strings.HasPrefix(refDump, soongNsPrefix) {
// TODO (asmundak): if we find many, maybe handle them.
return ctx.newBadExpr(node, "SOONG_CONFIG_ variables cannot be referenced, use soong_config_get instead: %s", refDump)
@@ -1354,8 +1330,8 @@
return ctx.newBadExpr(node, "unknown variable %s", refDump)
}
return &callExpr{
- name: "patsubst",
- returnType: knownFunctions["patsubst"].returnType,
+ name: baseName + ".mkpatsubst",
+ returnType: starlarkTypeString,
args: []starlarkExpr{
&stringLiteralExpr{literal: substParts[0]},
&stringLiteralExpr{literal: substParts[1]},
@@ -1370,18 +1346,11 @@
}
expr := &callExpr{name: words[0].Dump(), returnType: starlarkTypeUnknown}
- args := words[1]
- args.TrimLeftSpaces()
- // Make control functions and shell need special treatment as everything
- // after the name is a single text argument
- if isMakeControlFunc(expr.name) || expr.name == "shell" {
- x := ctx.parseMakeString(node, args)
- if xBad, ok := x.(*badExpr); ok {
- return xBad
- }
- expr.args = []starlarkExpr{x}
- return expr
+ args := mkparser.SimpleMakeString("", words[0].Pos())
+ if len(words) >= 2 {
+ args = words[1]
}
+ args.TrimLeftSpaces()
if expr.name == "call" {
words = args.SplitN(",", 2)
if words[0].Empty() || !words[0].Const() {
@@ -1395,41 +1364,128 @@
}
}
if kf, found := knownFunctions[expr.name]; found {
- expr.returnType = kf.returnType
+ return kf.parse(ctx, node, args)
} else {
return ctx.newBadExpr(node, "cannot handle invoking %s", expr.name)
}
- switch expr.name {
- case "if":
- return ctx.parseIfFunc(node, args)
- case "foreach":
- return ctx.parseForeachFunc(node, args)
- case "word":
- return ctx.parseWordFunc(node, args)
- case "firstword", "lastword":
- return ctx.parseFirstOrLastwordFunc(node, expr.name, args)
- case "my-dir":
- return NewVariableRefExpr(ctx.addVariable("LOCAL_PATH"), true)
- case "subst", "patsubst":
- return ctx.parseSubstFunc(node, expr.name, args)
- default:
- for _, arg := range args.Split(",") {
- arg.TrimLeftSpaces()
- arg.TrimRightSpaces()
- x := ctx.parseMakeString(node, arg)
- if xBad, ok := x.(*badExpr); ok {
- return xBad
- }
- expr.args = append(expr.args, x)
+}
+
+type simpleCallParser struct {
+ name string
+ returnType starlarkType
+ addGlobals bool
+}
+
+func (p *simpleCallParser) parse(ctx *parseContext, node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
+ expr := &callExpr{name: p.name, returnType: p.returnType}
+ if p.addGlobals {
+ expr.args = append(expr.args, &globalsExpr{})
+ }
+ for _, arg := range args.Split(",") {
+ arg.TrimLeftSpaces()
+ arg.TrimRightSpaces()
+ x := ctx.parseMakeString(node, arg)
+ if xBad, ok := x.(*badExpr); ok {
+ return xBad
}
+ expr.args = append(expr.args, x)
}
return expr
}
-func (ctx *parseContext) parseSubstFunc(node mkparser.Node, fname string, args *mkparser.MakeString) starlarkExpr {
+type makeControlFuncParser struct {
+ name string
+}
+
+func (p *makeControlFuncParser) parse(ctx *parseContext, node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
+ // Make control functions need special treatment as everything
+ // after the name is a single text argument
+ x := ctx.parseMakeString(node, args)
+ if xBad, ok := x.(*badExpr); ok {
+ return xBad
+ }
+ return &callExpr{
+ name: p.name,
+ args: []starlarkExpr{
+ &stringLiteralExpr{ctx.script.mkFile},
+ x,
+ },
+ returnType: starlarkTypeUnknown,
+ }
+}
+
+type shellCallParser struct{}
+
+func (p *shellCallParser) parse(ctx *parseContext, node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
+ // Shell functions need special treatment as everything
+ // after the name is a single text argument
+ x := ctx.parseMakeString(node, args)
+ if xBad, ok := x.(*badExpr); ok {
+ return xBad
+ }
+ return &callExpr{
+ name: baseName + ".shell",
+ args: []starlarkExpr{x},
+ returnType: starlarkTypeUnknown,
+ }
+}
+
+type myDirCallParser struct{}
+
+func (p *myDirCallParser) parse(ctx *parseContext, node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
+ if !args.Empty() {
+ return ctx.newBadExpr(node, "my-dir function cannot have any arguments passed to it.")
+ }
+ return &variableRefExpr{ctx.addVariable("LOCAL_PATH"), true}
+}
+
+type isProductInListCallParser struct{}
+
+func (p *isProductInListCallParser) parse(ctx *parseContext, node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
+ if args.Empty() {
+ return ctx.newBadExpr(node, "is-product-in-list requires an argument")
+ }
+ return &inExpr{
+ expr: &variableRefExpr{ctx.addVariable("TARGET_PRODUCT"), true},
+ list: maybeConvertToStringList(ctx.parseMakeString(node, args)),
+ isNot: false,
+ }
+}
+
+type isVendorBoardPlatformCallParser struct{}
+
+func (p *isVendorBoardPlatformCallParser) parse(ctx *parseContext, node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
+ if args.Empty() || !identifierFullMatchRegex.MatchString(args.Dump()) {
+ return ctx.newBadExpr(node, "cannot handle non-constant argument to is-vendor-board-platform")
+ }
+ return &inExpr{
+ expr: &variableRefExpr{ctx.addVariable("TARGET_BOARD_PLATFORM"), false},
+ list: &variableRefExpr{ctx.addVariable(args.Dump() + "_BOARD_PLATFORMS"), true},
+ isNot: false,
+ }
+}
+
+type isVendorBoardQcomCallParser struct{}
+
+func (p *isVendorBoardQcomCallParser) parse(ctx *parseContext, node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
+ if !args.Empty() {
+ return ctx.newBadExpr(node, "is-vendor-board-qcom does not accept any arguments")
+ }
+ return &inExpr{
+ expr: &variableRefExpr{ctx.addVariable("TARGET_BOARD_PLATFORM"), false},
+ list: &variableRefExpr{ctx.addVariable("QCOM_BOARD_PLATFORMS"), true},
+ isNot: false,
+ }
+}
+
+type substCallParser struct {
+ fname string
+}
+
+func (p *substCallParser) parse(ctx *parseContext, node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
words := args.Split(",")
if len(words) != 3 {
- return ctx.newBadExpr(node, "%s function should have 3 arguments", fname)
+ return ctx.newBadExpr(node, "%s function should have 3 arguments", p.fname)
}
from := ctx.parseMakeString(node, words[0])
if xBad, ok := from.(*badExpr); ok {
@@ -1443,7 +1499,7 @@
words[2].TrimRightSpaces()
obj := ctx.parseMakeString(node, words[2])
typ := obj.typ()
- if typ == starlarkTypeString && fname == "subst" {
+ if typ == starlarkTypeString && p.fname == "subst" {
// Optimization: if it's $(subst from, to, string), emit string.replace(from, to)
return &callExpr{
object: obj,
@@ -1453,13 +1509,15 @@
}
}
return &callExpr{
- name: fname,
+ name: baseName + ".mk" + p.fname,
args: []starlarkExpr{from, to, obj},
returnType: obj.typ(),
}
}
-func (ctx *parseContext) parseIfFunc(node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
+type ifCallParser struct{}
+
+func (p *ifCallParser) parse(ctx *parseContext, node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
words := args.Split(",")
if len(words) != 2 && len(words) != 3 {
return ctx.newBadExpr(node, "if function should have 2 or 3 arguments, found "+strconv.Itoa(len(words)))
@@ -1488,7 +1546,9 @@
}
}
-func (ctx *parseContext) parseForeachFunc(node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
+type foreachCallPaser struct{}
+
+func (p *foreachCallPaser) parse(ctx *parseContext, node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
words := args.Split(",")
if len(words) != 3 {
return ctx.newBadExpr(node, "foreach function should have 3 arguments, found "+strconv.Itoa(len(words)))
@@ -1507,8 +1567,8 @@
if list.typ() != starlarkTypeList {
list = &callExpr{
- name: "words",
- returnType: knownFunctions["words"].returnType,
+ name: baseName + ".words",
+ returnType: starlarkTypeList,
args: []starlarkExpr{list},
}
}
@@ -1520,7 +1580,9 @@
}
}
-func (ctx *parseContext) parseWordFunc(node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
+type wordCallParser struct{}
+
+func (p *wordCallParser) parse(ctx *parseContext, node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
words := args.Split(",")
if len(words) != 2 {
return ctx.newBadExpr(node, "word function should have 2 arguments")
@@ -1544,13 +1606,17 @@
return &indexExpr{array, &intLiteralExpr{int(index - 1)}}
}
-func (ctx *parseContext) parseFirstOrLastwordFunc(node mkparser.Node, name string, args *mkparser.MakeString) starlarkExpr {
+type firstOrLastwordCallParser struct {
+ isLastWord bool
+}
+
+func (p *firstOrLastwordCallParser) parse(ctx *parseContext, node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
arg := ctx.parseMakeString(node, args)
if bad, ok := arg.(*badExpr); ok {
return bad
}
index := &intLiteralExpr{0}
- if name == "lastword" {
+ if p.isLastWord {
if v, ok := arg.(*variableRefExpr); ok && v.ref.name() == "MAKEFILE_LIST" {
return &stringLiteralExpr{ctx.script.mkFile}
}
@@ -1562,6 +1628,68 @@
return &indexExpr{&callExpr{object: arg, name: "split", returnType: starlarkTypeList}, index}
}
+func parseIntegerArguments(ctx *parseContext, node mkparser.Node, args *mkparser.MakeString, expectedArgs int) ([]starlarkExpr, error) {
+ parsedArgs := make([]starlarkExpr, 0)
+ for _, arg := range args.Split(",") {
+ expr := ctx.parseMakeString(node, arg)
+ if expr.typ() == starlarkTypeList {
+ return nil, fmt.Errorf("argument to math argument has type list, which cannot be converted to int")
+ }
+ if s, ok := maybeString(expr); ok {
+ intVal, err := strconv.Atoi(strings.TrimSpace(s))
+ if err != nil {
+ return nil, err
+ }
+ expr = &intLiteralExpr{literal: intVal}
+ } else if expr.typ() != starlarkTypeInt {
+ expr = &callExpr{
+ name: "int",
+ args: []starlarkExpr{expr},
+ returnType: starlarkTypeInt,
+ }
+ }
+ parsedArgs = append(parsedArgs, expr)
+ }
+ if len(parsedArgs) != expectedArgs {
+ return nil, fmt.Errorf("function should have %d arguments", expectedArgs)
+ }
+ return parsedArgs, nil
+}
+
+type mathComparisonCallParser struct {
+ op string
+}
+
+func (p *mathComparisonCallParser) parse(ctx *parseContext, node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
+ parsedArgs, err := parseIntegerArguments(ctx, node, args, 2)
+ if err != nil {
+ return ctx.newBadExpr(node, err.Error())
+ }
+ return &binaryOpExpr{
+ left: parsedArgs[0],
+ right: parsedArgs[1],
+ op: p.op,
+ returnType: starlarkTypeBool,
+ }
+}
+
+type mathMaxOrMinCallParser struct {
+ function string
+}
+
+func (p *mathMaxOrMinCallParser) parse(ctx *parseContext, node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
+ parsedArgs, err := parseIntegerArguments(ctx, node, args, 2)
+ if err != nil {
+ return ctx.newBadExpr(node, err.Error())
+ }
+ return &callExpr{
+ object: nil,
+ name: p.function,
+ args: parsedArgs,
+ returnType: starlarkTypeInt,
+ }
+}
+
func (ctx *parseContext) parseMakeString(node mkparser.Node, mk *mkparser.MakeString) starlarkExpr {
if mk.Const() {
return &stringLiteralExpr{mk.Dump()}
@@ -1612,6 +1740,13 @@
default:
ctx.errorf(x, "unsupported line %s", strings.ReplaceAll(x.Dump(), "\n", "\n#"))
}
+
+ // Clear the includeTops after each non-comment statement
+ // so that include annotations placed on certain statements don't apply
+ // globally for the rest of the makefile was well.
+ if _, wasComment := node.(*mkparser.Comment); !wasComment && len(ctx.includeTops) > 0 {
+ ctx.includeTops = []string{}
+ }
}
// Processes annotation. An annotation is a comment that starts with #RBC# and provides
diff --git a/mk2rbc/mk2rbc_test.go b/mk2rbc/mk2rbc_test.go
index 1e53c30..ec6dfd0 100644
--- a/mk2rbc/mk2rbc_test.go
+++ b/mk2rbc/mk2rbc_test.go
@@ -598,9 +598,9 @@
def init(g, handle):
cfg = rblf.cfg(handle)
- if g.get("TARGET_BOARD_PLATFORM", "") in ["msm8998"]:
+ if rblf.board_platform_in(g, "msm8998"):
pass
- elif g.get("TARGET_BOARD_PLATFORM", "") != "copper":
+ elif not rblf.board_platform_is(g, "copper"):
pass
elif g.get("TARGET_BOARD_PLATFORM", "") not in g["QCOM_BOARD_PLATFORMS"]:
pass
@@ -1049,7 +1049,7 @@
}.get("vendor/%s/cfg.mk" % g["MY_PATH"])
(_varmod, _varmod_init) = _entry if _entry else (None, None)
if not _varmod_init:
- rblf.mkerror("cannot")
+ rblf.mkerror("product.mk", "Cannot find %s" % ("vendor/%s/cfg.mk" % g["MY_PATH"]))
rblf.inherit(handle, _varmod, _varmod_init)
`,
},
@@ -1073,7 +1073,7 @@
}.get("%s/cfg.mk" % g["MY_PATH"])
(_varmod, _varmod_init) = _entry if _entry else (None, None)
if not _varmod_init:
- rblf.mkerror("cannot")
+ rblf.mkerror("product.mk", "Cannot find %s" % ("%s/cfg.mk" % g["MY_PATH"]))
rblf.inherit(handle, _varmod, _varmod_init)
`,
},
@@ -1099,7 +1099,7 @@
}.get("%s/cfg.mk" % g["MY_PATH"])
(_varmod, _varmod_init) = _entry if _entry else (None, None)
if not _varmod_init:
- rblf.mkerror("cannot")
+ rblf.mkerror("product.mk", "Cannot find %s" % ("%s/cfg.mk" % g["MY_PATH"]))
rblf.inherit(handle, _varmod, _varmod_init)
#RBC# include_top vendor/foo1
_entry = {
@@ -1107,11 +1107,51 @@
}.get("%s/cfg.mk" % g["MY_PATH"])
(_varmod, _varmod_init) = _entry if _entry else (None, None)
if not _varmod_init:
- rblf.mkerror("cannot")
+ rblf.mkerror("product.mk", "Cannot find %s" % ("%s/cfg.mk" % g["MY_PATH"]))
rblf.inherit(handle, _varmod, _varmod_init)
`,
},
{
+ desc: "Dynamic inherit path that lacks necessary hint",
+ mkname: "product.mk",
+ in: `
+#RBC# include_top foo
+$(call inherit-product,$(MY_VAR)/font.mk)
+
+#RBC# include_top foo
+
+# There's some space and even this comment between the include_top and the inherit-product
+
+$(call inherit-product,$(MY_VAR)/font.mk)
+
+$(call inherit-product,$(MY_VAR)/font.mk)
+`,
+ expected: `#RBC# include_top foo
+load("//build/make/core:product_config.rbc", "rblf")
+load("//foo:font.star|init", _font_init = "init")
+
+def init(g, handle):
+ cfg = rblf.cfg(handle)
+ _entry = {
+ "foo/font.mk": ("_font", _font_init),
+ }.get("%s/font.mk" % g.get("MY_VAR", ""))
+ (_varmod, _varmod_init) = _entry if _entry else (None, None)
+ if not _varmod_init:
+ rblf.mkerror("product.mk", "Cannot find %s" % ("%s/font.mk" % g.get("MY_VAR", "")))
+ rblf.inherit(handle, _varmod, _varmod_init)
+ #RBC# include_top foo
+ # There's some space and even this comment between the include_top and the inherit-product
+ _entry = {
+ "foo/font.mk": ("_font", _font_init),
+ }.get("%s/font.mk" % g.get("MY_VAR", ""))
+ (_varmod, _varmod_init) = _entry if _entry else (None, None)
+ if not _varmod_init:
+ rblf.mkerror("product.mk", "Cannot find %s" % ("%s/font.mk" % g.get("MY_VAR", "")))
+ rblf.inherit(handle, _varmod, _varmod_init)
+ rblf.mk2rbc_error("product.mk:11", "inherit-product/include statements must not be prefixed with a variable, or must include a #RBC# include_top comment beforehand giving a root directory to search.")
+`,
+ },
+ {
desc: "Ignore make rules",
mkname: "product.mk",
in: `
@@ -1214,6 +1254,90 @@
g["BOOT_KERNEL_MODULES_FILTER_2"] = ["%%/%s" % m for m in g["BOOT_KERNEL_MODULES_LIST"]]
`,
},
+ {
+ desc: "List appended to string",
+ mkname: "product.mk",
+ in: `
+NATIVE_BRIDGE_PRODUCT_PACKAGES := \
+ libnative_bridge_vdso.native_bridge \
+ native_bridge_guest_app_process.native_bridge \
+ native_bridge_guest_linker.native_bridge
+
+NATIVE_BRIDGE_MODIFIED_GUEST_LIBS := \
+ libaaudio \
+ libamidi \
+ libandroid \
+ libandroid_runtime
+
+NATIVE_BRIDGE_PRODUCT_PACKAGES += \
+ $(addsuffix .native_bridge,$(NATIVE_BRIDGE_ORIG_GUEST_LIBS))
+`,
+ expected: `load("//build/make/core:product_config.rbc", "rblf")
+
+def init(g, handle):
+ cfg = rblf.cfg(handle)
+ g["NATIVE_BRIDGE_PRODUCT_PACKAGES"] = "libnative_bridge_vdso.native_bridge native_bridge_guest_app_process.native_bridge native_bridge_guest_linker.native_bridge"
+ g["NATIVE_BRIDGE_MODIFIED_GUEST_LIBS"] = "libaaudio libamidi libandroid libandroid_runtime"
+ g["NATIVE_BRIDGE_PRODUCT_PACKAGES"] += " " + " ".join(rblf.addsuffix(".native_bridge", g.get("NATIVE_BRIDGE_ORIG_GUEST_LIBS", "")))
+`,
+ },
+ {
+ desc: "Math functions",
+ mkname: "product.mk",
+ in: `
+# Test the math functions defined in build/make/common/math.mk
+ifeq ($(call math_max,2,5),5)
+endif
+ifeq ($(call math_min,2,5),2)
+endif
+ifeq ($(call math_gt_or_eq,2,5),true)
+endif
+ifeq ($(call math_gt,2,5),true)
+endif
+ifeq ($(call math_lt,2,5),true)
+endif
+ifeq ($(call math_gt_or_eq,2,5),)
+endif
+ifeq ($(call math_gt,2,5),)
+endif
+ifeq ($(call math_lt,2,5),)
+endif
+ifeq ($(call math_gt_or_eq,$(MY_VAR), 5),true)
+endif
+ifeq ($(call math_gt_or_eq,$(MY_VAR),$(MY_OTHER_VAR)),true)
+endif
+ifeq ($(call math_gt_or_eq,100$(MY_VAR),10),true)
+endif
+`,
+ expected: `# Test the math functions defined in build/make/common/math.mk
+load("//build/make/core:product_config.rbc", "rblf")
+
+def init(g, handle):
+ cfg = rblf.cfg(handle)
+ if max(2, 5) == 5:
+ pass
+ if min(2, 5) == 2:
+ pass
+ if 2 >= 5:
+ pass
+ if 2 > 5:
+ pass
+ if 2 < 5:
+ pass
+ if 2 < 5:
+ pass
+ if 2 <= 5:
+ pass
+ if 2 >= 5:
+ pass
+ if int(g.get("MY_VAR", "")) >= 5:
+ pass
+ if int(g.get("MY_VAR", "")) >= int(g.get("MY_OTHER_VAR", "")):
+ pass
+ if int("100%s" % g.get("MY_VAR", "")) >= 10:
+ pass
+`,
+ },
}
var known_variables = []struct {
diff --git a/mk2rbc/node.go b/mk2rbc/node.go
index d38299d..ebc57b2 100644
--- a/mk2rbc/node.go
+++ b/mk2rbc/node.go
@@ -110,7 +110,9 @@
gctx.writef("if not %s:", i.entryName())
gctx.indentLevel++
gctx.newLine()
- gctx.write(`rblf.mkerror("cannot")`)
+ gctx.write(`rblf.mkerror("`, gctx.starScript.mkFile, `", "Cannot find %s" % (`)
+ i.path.emit(gctx)
+ gctx.write("))")
gctx.indentLevel--
}
}
diff --git a/mk2rbc/variable.go b/mk2rbc/variable.go
index 6b67a7c..f7adca5 100644
--- a/mk2rbc/variable.go
+++ b/mk2rbc/variable.go
@@ -81,10 +81,12 @@
emitAppend := func() {
pcv.emitGet(gctx, true)
gctx.write(" += ")
+ value := asgn.value
if pcv.valueType() == starlarkTypeString {
gctx.writef(`" " + `)
+ value = &toStringExpr{expr: value}
}
- asgn.value.emit(gctx)
+ value.emit(gctx)
}
switch asgn.flavor {
@@ -136,10 +138,12 @@
emitAppend := func() {
scv.emitGet(gctx, true)
gctx.write(" += ")
+ value := asgn.value
if scv.valueType() == starlarkTypeString {
gctx.writef(`" " + `)
+ value = &toStringExpr{expr: value}
}
- asgn.value.emit(gctx)
+ value.emit(gctx)
}
switch asgn.flavor {
@@ -193,10 +197,12 @@
case asgnAppend:
lv.emitGet(gctx, false)
gctx.write(" += ")
+ value := asgn.value
if lv.valueType() == starlarkTypeString {
gctx.writef(`" " + `)
+ value = &toStringExpr{expr: value}
}
- asgn.value.emit(gctx)
+ value.emit(gctx)
case asgnMaybeAppend:
gctx.writef("%s(%q, ", cfnLocalAppend, lv)
asgn.value.emit(gctx)
diff --git a/rust/bindgen.go b/rust/bindgen.go
index 5e1b4b7..ef5702b 100644
--- a/rust/bindgen.go
+++ b/rust/bindgen.go
@@ -30,7 +30,7 @@
defaultBindgenFlags = []string{""}
// bindgen should specify its own Clang revision so updating Clang isn't potentially blocked on bindgen failures.
- bindgenClangVersion = "clang-r437112"
+ bindgenClangVersion = "clang-r437112b"
_ = pctx.VariableFunc("bindgenClangVersion", func(ctx android.PackageVarContext) string {
if override := ctx.Config().Getenv("LLVM_BINDGEN_PREBUILTS_VERSION"); override != "" {
diff --git a/rust/coverage.go b/rust/coverage.go
index 8fdfa23..91d34ac 100644
--- a/rust/coverage.go
+++ b/rust/coverage.go
@@ -22,6 +22,7 @@
var CovLibraryName = "libprofile-clang-extras"
+// Add '%c' to default specifier after we resolve http://b/210012154
const profileInstrFlag = "-fprofile-instr-generate=/data/misc/trace/clang-%p-%m.profraw"
type coverage struct {
@@ -70,6 +71,10 @@
"-Wl,-z,nostart-stop-gc",
)
deps.StaticLibs = append(deps.StaticLibs, coverage.OutputFile().Path())
+ if cc.EnableContinuousCoverage(ctx) {
+ flags.RustFlags = append(flags.RustFlags, "-C llvm-args=--runtime-counter-relocation")
+ flags.LinkFlags = append(flags.LinkFlags, "-Wl,-mllvm,-runtime-counter-relocation")
+ }
}
return flags, deps
diff --git a/rust/protobuf.go b/rust/protobuf.go
index b91fea8..9fe27c4c 100644
--- a/rust/protobuf.go
+++ b/rust/protobuf.go
@@ -188,6 +188,12 @@
lines,
"pub mod empty {",
" pub use protobuf::well_known_types::Empty;",
+ "}",
+ "pub mod wrappers {",
+ " pub use protobuf::well_known_types::{",
+ " DoubleValue, FloatValue, Int64Value, UInt64Value, Int32Value, UInt32Value,",
+ " BoolValue, StringValue, BytesValue",
+ " };",
"}")
}
diff --git a/rust/rust.go b/rust/rust.go
index c2585f2..778000d 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -901,6 +901,9 @@
bloaty.MeasureSizeForPaths(ctx, mod.compiler.strippedOutputFilePath(), android.OptionalPathForPath(mod.compiler.unstrippedOutputFilePath()))
mod.docTimestampFile = mod.compiler.rustdoc(ctx, flags, deps)
+ if mod.docTimestampFile.Valid() {
+ ctx.CheckbuildFile(mod.docTimestampFile.Path())
+ }
// glob exported headers for snapshot, if BOARD_VNDK_VERSION is current or
// RECOVERY_SNAPSHOT_VERSION is current.
diff --git a/ui/build/soong.go b/ui/build/soong.go
index 5360342..8133762 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -166,10 +166,22 @@
}
commonArgs = append(commonArgs, "-l", filepath.Join(config.FileListDir(), "Android.bp.list"))
+ invocationEnv := make(map[string]string)
+ debugMode := os.Getenv("SOONG_DELVE") != ""
- if os.Getenv("SOONG_DELVE") != "" {
+ if debugMode {
commonArgs = append(commonArgs, "--delve_listen", os.Getenv("SOONG_DELVE"))
commonArgs = append(commonArgs, "--delve_path", shared.ResolveDelveBinary())
+ // GODEBUG=asyncpreemptoff=1 disables the preemption of goroutines. This
+ // is useful because the preemption happens by sending SIGURG to the OS
+ // thread hosting the goroutine in question and each signal results in
+ // work that needs to be done by Delve; it uses ptrace to debug the Go
+ // process and the tracer process must deal with every signal (it is not
+ // possible to selectively ignore SIGURG). This makes debugging slower,
+ // sometimes by an order of magnitude depending on luck.
+ // The original reason for adding async preemption to Go is here:
+ // https://github.com/golang/proposal/blob/master/design/24543-non-cooperative-preemption.md
+ invocationEnv["GODEBUG"] = "asyncpreemptoff=1"
}
allArgs := make([]string, 0, 0)
@@ -187,6 +199,12 @@
Outputs: []string{output},
Args: allArgs,
Description: description,
+ // NB: Changing the value of this environment variable will not result in a
+ // rebuild. The bootstrap Ninja file will change, but apparently Ninja does
+ // not consider changing the pool specified in a statement a change that's
+ // worth rebuilding for.
+ Console: os.Getenv("SOONG_UNBUFFERED_OUTPUT") == "1",
+ Env: invocationEnv,
}
}