Merge "Bump default experimental from gnu++2a to gnu++2b." into main
diff --git a/OWNERS b/OWNERS
index e5374ed..58edc89 100644
--- a/OWNERS
+++ b/OWNERS
@@ -3,29 +3,13 @@
# approving build related projects.
# AMER
-agespino@google.com #{LAST_RESORT_SUGGESTION}
ccross@android.com
colefaust@google.com
-cparsons@google.com #{LAST_RESORT_SUGGESTION}
-dacek@google.com #{LAST_RESORT_SUGGESTION}
-delmerico@google.com #{LAST_RESORT_SUGGESTION}
dwillemsen@google.com
-eakammer@google.com #{LAST_RESORT_SUGGESTION}
jihoonkang@google.com
-jobredeaux@google.com #{LAST_RESORT_SUGGESTION}
joeo@google.com
-juu@google.com #{LAST_RESORT_SUGGESTION}
lamontjones@google.com
mrziwang@google.com
spandandas@google.com
-tradical@google.com #{LAST_RESORT_SUGGESTION}
-usta@google.com #{LAST_RESORT_SUGGESTION}
-vinhdaitran@google.com #{LAST_RESORT_SUGGESTION}
weiwli@google.com
-yudiliu@google.com
-
-# APAC
-jingwen@google.com #{LAST_RESORT_SUGGESTION}
-
-# EMEA
-lberki@google.com #{LAST_RESORT_SUGGESTION}
+yudiliu@google.com
\ No newline at end of file
diff --git a/aconfig/Android.bp b/aconfig/Android.bp
index faa4ddb..04de919 100644
--- a/aconfig/Android.bp
+++ b/aconfig/Android.bp
@@ -12,28 +12,19 @@
"soong",
"soong-android",
"soong-bazel",
- "soong-android",
- "soong-java",
- "soong-rust",
],
srcs: [
"aconfig_declarations.go",
"aconfig_values.go",
"aconfig_value_set.go",
"all_aconfig_declarations.go",
- "cc_aconfig_library.go",
"init.go",
- "java_aconfig_library.go",
"testing.go",
- "rust_aconfig_library.go",
],
testSrcs: [
"aconfig_declarations_test.go",
"aconfig_values_test.go",
"aconfig_value_set_test.go",
- "java_aconfig_library_test.go",
- "cc_aconfig_library_test.go",
- "rust_aconfig_library_test.go",
],
pluginFor: ["soong_build"],
}
diff --git a/aconfig/aconfig_declarations.go b/aconfig/aconfig_declarations.go
index 897f892..e662f1d 100644
--- a/aconfig/aconfig_declarations.go
+++ b/aconfig/aconfig_declarations.go
@@ -38,6 +38,9 @@
// Values from TARGET_RELEASE / RELEASE_ACONFIG_VALUE_SETS
Values []string `blueprint:"mutated"`
+
+ // Container(system/vendor/apex) that this module belongs to
+ Container string
}
intermediatePath android.WritablePath
@@ -69,6 +72,8 @@
if len(module.properties.Package) == 0 {
ctx.PropertyErrorf("package", "missing package property")
}
+ // TODO(b/311155208): Add mandatory check for container after all pre-existing
+ // ones are changed.
// Add a dependency on the aconfig_value_sets defined in
// RELEASE_ACONFIG_VALUE_SETS, and add any aconfig_values that
@@ -110,12 +115,21 @@
}
// Provider published by aconfig_value_set
-type declarationsProviderData struct {
+type DeclarationsProviderData struct {
Package string
+ Container string
IntermediatePath android.WritablePath
}
-var declarationsProviderKey = blueprint.NewProvider(declarationsProviderData{})
+var DeclarationsProviderKey = blueprint.NewProvider(DeclarationsProviderData{})
+
+// This is used to collect the aconfig declarations info on the transitive closure,
+// the data is keyed on the container.
+type TransitiveDeclarationsInfo struct {
+ AconfigFiles map[string]*android.DepSet[android.Path]
+}
+
+var TransitiveDeclarationsInfoProvider = blueprint.NewProvider(TransitiveDeclarationsInfo{})
func (module *DeclarationsModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// Get the values that came from the global RELEASE_ACONFIG_VALUE_SETS flag
@@ -156,13 +170,49 @@
},
})
- ctx.SetProvider(declarationsProviderKey, declarationsProviderData{
+ ctx.SetProvider(DeclarationsProviderKey, DeclarationsProviderData{
Package: module.properties.Package,
+ Container: module.properties.Container,
IntermediatePath: intermediatePath,
})
}
+func CollectTransitiveAconfigFiles(ctx android.ModuleContext, transitiveAconfigFiles *map[string]*android.DepSet[android.Path]) {
+ if *transitiveAconfigFiles == nil {
+ *transitiveAconfigFiles = make(map[string]*android.DepSet[android.Path])
+ }
+ ctx.VisitDirectDeps(func(module android.Module) {
+ if dep := ctx.OtherModuleProvider(module, DeclarationsProviderKey).(DeclarationsProviderData); dep.IntermediatePath != nil {
+ aconfigMap := make(map[string]*android.DepSet[android.Path])
+ aconfigMap[dep.Container] = android.NewDepSet(android.POSTORDER, []android.Path{dep.IntermediatePath}, nil)
+ mergeTransitiveAconfigFiles(aconfigMap, *transitiveAconfigFiles)
+ return
+ }
+ if dep := ctx.OtherModuleProvider(module, TransitiveDeclarationsInfoProvider).(TransitiveDeclarationsInfo); len(dep.AconfigFiles) > 0 {
+ mergeTransitiveAconfigFiles(dep.AconfigFiles, *transitiveAconfigFiles)
+ }
+ })
+
+ ctx.SetProvider(TransitiveDeclarationsInfoProvider, TransitiveDeclarationsInfo{
+ AconfigFiles: *transitiveAconfigFiles,
+ })
+}
+
+func mergeTransitiveAconfigFiles(from, to map[string]*android.DepSet[android.Path]) {
+ for fromKey, fromValue := range from {
+ if fromValue == nil {
+ continue
+ }
+ toValue, ok := to[fromKey]
+ if !ok {
+ to[fromKey] = fromValue
+ } else {
+ to[fromKey] = android.NewDepSet(android.POSTORDER, toValue.ToList(), []*android.DepSet[android.Path]{fromValue})
+ }
+ }
+}
+
type bazelAconfigDeclarationsAttributes struct {
Srcs bazel.LabelListAttribute
Package string
diff --git a/aconfig/aconfig_declarations_test.go b/aconfig/aconfig_declarations_test.go
index e0d8f7d..e6bd87c 100644
--- a/aconfig/aconfig_declarations_test.go
+++ b/aconfig/aconfig_declarations_test.go
@@ -26,6 +26,7 @@
aconfig_declarations {
name: "module_name",
package: "com.example.package",
+ container: "com.android.foo",
srcs: [
"foo.aconfig",
"bar.aconfig",
@@ -37,8 +38,9 @@
module := result.ModuleForTests("module_name", "").Module().(*DeclarationsModule)
// Check that the provider has the right contents
- depData := result.ModuleProvider(module, declarationsProviderKey).(declarationsProviderData)
+ depData := result.ModuleProvider(module, DeclarationsProviderKey).(DeclarationsProviderData)
android.AssertStringEquals(t, "package", depData.Package, "com.example.package")
+ android.AssertStringEquals(t, "container", depData.Container, "com.android.foo")
if !strings.HasSuffix(depData.IntermediatePath.String(), "/intermediate.pb") {
t.Errorf("Missing intermediates path in provider: %s", depData.IntermediatePath.String())
}
diff --git a/aconfig/all_aconfig_declarations.go b/aconfig/all_aconfig_declarations.go
index 6096c6c..7ccb81a 100644
--- a/aconfig/all_aconfig_declarations.go
+++ b/aconfig/all_aconfig_declarations.go
@@ -37,17 +37,17 @@
// Find all of the aconfig_declarations modules
var cacheFiles android.Paths
ctx.VisitAllModules(func(module android.Module) {
- if !ctx.ModuleHasProvider(module, declarationsProviderKey) {
+ if !ctx.ModuleHasProvider(module, DeclarationsProviderKey) {
return
}
- decl := ctx.ModuleProvider(module, declarationsProviderKey).(declarationsProviderData)
+ decl := ctx.ModuleProvider(module, DeclarationsProviderKey).(DeclarationsProviderData)
cacheFiles = append(cacheFiles, decl.IntermediatePath)
})
// Generate build action for aconfig
this.intermediatePath = android.PathForIntermediates(ctx, "all_aconfig_declarations.pb")
ctx.Build(pctx, android.BuildParams{
- Rule: allDeclarationsRule,
+ Rule: AllDeclarationsRule,
Inputs: cacheFiles,
Output: this.intermediatePath,
Description: "all_aconfig_declarations",
diff --git a/aconfig/codegen/Android.bp b/aconfig/codegen/Android.bp
new file mode 100644
index 0000000..494f7e6
--- /dev/null
+++ b/aconfig/codegen/Android.bp
@@ -0,0 +1,32 @@
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+bootstrap_go_package {
+ name: "soong-aconfig-codegen",
+ pkgPath: "android/soong/aconfig/codegen",
+ deps: [
+ "blueprint",
+ "blueprint-pathtools",
+ "sbox_proto",
+ "soong",
+ "soong-aconfig",
+ "soong-android",
+ "soong-bazel",
+ "soong-java",
+ "soong-rust",
+ ],
+ srcs: [
+ "cc_aconfig_library.go",
+ "init.go",
+ "java_aconfig_library.go",
+ "rust_aconfig_library.go",
+ "testing.go",
+ ],
+ testSrcs: [
+ "java_aconfig_library_test.go",
+ "cc_aconfig_library_test.go",
+ "rust_aconfig_library_test.go",
+ ],
+ pluginFor: ["soong_build"],
+}
diff --git a/aconfig/cc_aconfig_library.go b/aconfig/codegen/cc_aconfig_library.go
similarity index 91%
rename from aconfig/cc_aconfig_library.go
rename to aconfig/codegen/cc_aconfig_library.go
index 8aa696b..7b68844 100644
--- a/aconfig/cc_aconfig_library.go
+++ b/aconfig/codegen/cc_aconfig_library.go
@@ -12,9 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package aconfig
+package codegen
import (
+ "android/soong/aconfig"
"android/soong/android"
"android/soong/bazel"
"android/soong/cc"
@@ -38,10 +39,6 @@
// name of the aconfig_declarations module to generate a library for
Aconfig_declarations string
- // whether to generate test mode version of the library
- // TODO: remove "Test" property when "Mode" can be used in all the branches
- Test *bool
-
// default mode is "production", the other accepted modes are:
// "test": to generate test mode version of the library
// "exported": to generate exported mode version of the library
@@ -96,7 +93,7 @@
if len(declarationsModules) != 1 {
panic(fmt.Errorf("Exactly one aconfig_declarations property required"))
}
- declarations := ctx.OtherModuleProvider(declarationsModules[0], declarationsProviderKey).(declarationsProviderData)
+ declarations := ctx.OtherModuleProvider(declarationsModules[0], aconfig.DeclarationsProviderKey).(aconfig.DeclarationsProviderData)
// Figure out the generated file paths. This has to match aconfig's codegen_cpp.rs.
this.generatedDir = android.PathForModuleGen(ctx)
@@ -126,19 +123,13 @@
if len(declarationsModules) != 1 {
panic(fmt.Errorf("Exactly one aconfig_declarations property required"))
}
- declarations := ctx.OtherModuleProvider(declarationsModules[0], declarationsProviderKey).(declarationsProviderData)
+ declarations := ctx.OtherModuleProvider(declarationsModules[0], aconfig.DeclarationsProviderKey).(aconfig.DeclarationsProviderData)
- if this.properties.Mode != nil && this.properties.Test != nil {
- ctx.PropertyErrorf("test", "test prop should not be specified when mode prop is set")
- }
mode := proptools.StringDefault(this.properties.Mode, "production")
if !isModeSupported(mode) {
ctx.PropertyErrorf("mode", "%q is not a supported mode", mode)
}
- // TODO: remove "Test" property
- if proptools.Bool(this.properties.Test) {
- mode = "test"
- }
+
ctx.Build(pctx, android.BuildParams{
Rule: cppRule,
Input: declarations.IntermediatePath,
diff --git a/aconfig/cc_aconfig_library_test.go b/aconfig/codegen/cc_aconfig_library_test.go
similarity index 94%
rename from aconfig/cc_aconfig_library_test.go
rename to aconfig/codegen/cc_aconfig_library_test.go
index 9a819e5..0c8a969 100644
--- a/aconfig/cc_aconfig_library_test.go
+++ b/aconfig/codegen/cc_aconfig_library_test.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package aconfig
+package codegen
import (
"fmt"
@@ -71,8 +71,6 @@
setting, expectedErr string
}{
{"mode: `unsupported`,", "mode: \"unsupported\" is not a supported mode"},
- // TODO: remove this test case when test prop is removed
- {"mode: `test`, test: true", "test prop should not be specified when mode prop is set"},
}
func TestIncorrectCCCodegenMode(t *testing.T) {
diff --git a/aconfig/codegen/init.go b/aconfig/codegen/init.go
new file mode 100644
index 0000000..0bff9d2
--- /dev/null
+++ b/aconfig/codegen/init.go
@@ -0,0 +1,83 @@
+// Copyright 2023 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 codegen
+
+import (
+ "android/soong/android"
+
+ "github.com/google/blueprint"
+)
+
+var (
+ pctx = android.NewPackageContext("android/soong/aconfig/codegen")
+
+ // For java_aconfig_library: Generate java library
+ javaRule = pctx.AndroidStaticRule("java_aconfig_library",
+ blueprint.RuleParams{
+ Command: `rm -rf ${out}.tmp` +
+ ` && mkdir -p ${out}.tmp` +
+ ` && ${aconfig} create-java-lib` +
+ ` --mode ${mode}` +
+ ` --cache ${in}` +
+ ` --out ${out}.tmp` +
+ ` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` +
+ ` && rm -rf ${out}.tmp`,
+ CommandDeps: []string{
+ "$aconfig",
+ "$soong_zip",
+ },
+ Restat: true,
+ }, "mode")
+
+ // For cc_aconfig_library: Generate C++ library
+ cppRule = pctx.AndroidStaticRule("cc_aconfig_library",
+ blueprint.RuleParams{
+ Command: `rm -rf ${gendir}` +
+ ` && mkdir -p ${gendir}` +
+ ` && ${aconfig} create-cpp-lib` +
+ ` --mode ${mode}` +
+ ` --cache ${in}` +
+ ` --out ${gendir}`,
+ CommandDeps: []string{
+ "$aconfig",
+ },
+ }, "gendir", "mode")
+
+ // For rust_aconfig_library: Generate Rust library
+ rustRule = pctx.AndroidStaticRule("rust_aconfig_library",
+ blueprint.RuleParams{
+ Command: `rm -rf ${gendir}` +
+ ` && mkdir -p ${gendir}` +
+ ` && ${aconfig} create-rust-lib` +
+ ` --mode ${mode}` +
+ ` --cache ${in}` +
+ ` --out ${gendir}`,
+ CommandDeps: []string{
+ "$aconfig",
+ },
+ }, "gendir", "mode")
+)
+
+func init() {
+ RegisterBuildComponents(android.InitRegistrationContext)
+ pctx.HostBinToolVariable("aconfig", "aconfig")
+ pctx.HostBinToolVariable("soong_zip", "soong_zip")
+}
+
+func RegisterBuildComponents(ctx android.RegistrationContext) {
+ ctx.RegisterModuleType("cc_aconfig_library", CcAconfigLibraryFactory)
+ ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory)
+ ctx.RegisterModuleType("rust_aconfig_library", RustAconfigLibraryFactory)
+}
diff --git a/aconfig/java_aconfig_library.go b/aconfig/codegen/java_aconfig_library.go
similarity index 88%
rename from aconfig/java_aconfig_library.go
rename to aconfig/codegen/java_aconfig_library.go
index b6c90fc..e2fb15b 100644
--- a/aconfig/java_aconfig_library.go
+++ b/aconfig/codegen/java_aconfig_library.go
@@ -12,11 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package aconfig
+package codegen
import (
"fmt"
+ "android/soong/aconfig"
"android/soong/android"
"android/soong/bazel"
"android/soong/java"
@@ -36,10 +37,6 @@
// name of the aconfig_declarations module to generate a library for
Aconfig_declarations string
- // whether to generate test mode version of the library
- // TODO: remove "Test" property when "Mode" can be used in all the branches
- Test *bool
-
// default mode is "production", the other accepted modes are:
// "test": to generate test mode version of the library
// "exported": to generate exported mode version of the library
@@ -77,22 +74,15 @@
if len(declarationsModules) != 1 {
panic(fmt.Errorf("Exactly one aconfig_declarations property required"))
}
- declarations := ctx.OtherModuleProvider(declarationsModules[0], declarationsProviderKey).(declarationsProviderData)
+ declarations := ctx.OtherModuleProvider(declarationsModules[0], aconfig.DeclarationsProviderKey).(aconfig.DeclarationsProviderData)
// Generate the action to build the srcjar
srcJarPath := android.PathForModuleGen(ctx, ctx.ModuleName()+".srcjar")
- if callbacks.properties.Mode != nil && callbacks.properties.Test != nil {
- ctx.PropertyErrorf("test", "test prop should not be specified when mode prop is set")
- }
mode := proptools.StringDefault(callbacks.properties.Mode, "production")
if !isModeSupported(mode) {
ctx.PropertyErrorf("mode", "%q is not a supported mode", mode)
}
- // TODO: remove "Test" property
- if proptools.Bool(callbacks.properties.Test) {
- mode = "test"
- }
ctx.Build(pctx, android.BuildParams{
Rule: javaRule,
@@ -104,10 +94,6 @@
},
})
- // Tell the java module about the .aconfig files, so they can be propagated up the dependency chain.
- // TODO: It would be nice to have that propagation code here instead of on java.Module and java.JavaInfo.
- module.AddAconfigIntermediate(declarations.IntermediatePath)
-
return srcJarPath
}
diff --git a/aconfig/java_aconfig_library_test.go b/aconfig/codegen/java_aconfig_library_test.go
similarity index 82%
rename from aconfig/java_aconfig_library_test.go
rename to aconfig/codegen/java_aconfig_library_test.go
index 05532e7..cbfdc21 100644
--- a/aconfig/java_aconfig_library_test.go
+++ b/aconfig/codegen/java_aconfig_library_test.go
@@ -12,11 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package aconfig
+package codegen
import (
"fmt"
- "strings"
"testing"
"android/soong/android"
@@ -34,14 +33,25 @@
ExtendWithErrorHandler(android.FixtureExpectsNoErrors).
RunTestWithBp(t, bp+`
aconfig_declarations {
- name: "my_aconfig_declarations",
+ name: "my_aconfig_declarations_foo",
package: "com.example.package",
srcs: ["foo.aconfig"],
}
java_aconfig_library {
- name: "my_java_aconfig_library",
- aconfig_declarations: "my_aconfig_declarations",
+ name: "my_java_aconfig_library_foo",
+ aconfig_declarations: "my_aconfig_declarations_foo",
+ }
+
+ aconfig_declarations {
+ name: "my_aconfig_declarations_bar",
+ package: "com.example.package",
+ srcs: ["bar.aconfig"],
+ }
+
+ java_aconfig_library {
+ name: "my_java_aconfig_library_bar",
+ aconfig_declarations: "my_aconfig_declarations_bar",
}
`)
@@ -50,10 +60,9 @@
entry := android.AndroidMkEntriesForTest(t, result.TestContext, module)[0]
makeVar := entry.EntryMap["LOCAL_ACONFIG_FILES"]
- android.AssertIntEquals(t, "len(LOCAL_ACONFIG_FILES)", 1, len(makeVar))
- if !strings.HasSuffix(makeVar[0], "intermediate.pb") {
- t.Errorf("LOCAL_ACONFIG_FILES should end with /intermediates.pb, instead it is: %s", makeVar[0])
- }
+ android.AssertIntEquals(t, "len(LOCAL_ACONFIG_FILES)", 2, len(makeVar))
+ android.EnsureListContainsSuffix(t, makeVar, "my_aconfig_declarations_foo/intermediate.pb")
+ android.EnsureListContainsSuffix(t, makeVar, "my_aconfig_declarations_bar/intermediate.pb")
}
func TestAndroidMkJavaLibrary(t *testing.T) {
@@ -64,7 +73,8 @@
"src/foo.java",
],
static_libs: [
- "my_java_aconfig_library",
+ "my_java_aconfig_library_foo",
+ "my_java_aconfig_library_bar",
],
platform_apis: true,
}
@@ -81,7 +91,8 @@
"src/foo.java",
],
static_libs: [
- "my_java_aconfig_library",
+ "my_java_aconfig_library_foo",
+ "my_java_aconfig_library_bar",
],
platform_apis: true,
}
@@ -98,7 +109,8 @@
"src/foo.java",
],
static_libs: [
- "my_java_aconfig_library",
+ "my_java_aconfig_library_foo",
+ "my_java_aconfig_library_bar",
],
platform_apis: true,
main_class: "foo",
@@ -116,7 +128,8 @@
"src/foo.java",
],
static_libs: [
- "my_java_aconfig_library",
+ "my_java_aconfig_library_foo",
+ "my_java_aconfig_library_bar",
],
platform_apis: true,
}
@@ -134,7 +147,8 @@
"src/foo.java",
],
static_libs: [
- "my_java_aconfig_library",
+ "my_java_aconfig_library_foo",
+ "my_java_aconfig_library_bar",
],
platform_apis: true,
}
@@ -217,9 +231,3 @@
func TestUnsupportedMode(t *testing.T) {
testCodegenModeWithError(t, "mode: `unsupported`,", "mode: \"unsupported\" is not a supported mode")
}
-
-// TODO: remove this test case when test prop is removed
-func TestBothModeAndTestAreSet(t *testing.T) {
- testCodegenModeWithError(t, "mode: `test`, test: true",
- "test prop should not be specified when mode prop is set")
-}
diff --git a/aconfig/rust_aconfig_library.go b/aconfig/codegen/rust_aconfig_library.go
similarity index 86%
rename from aconfig/rust_aconfig_library.go
rename to aconfig/codegen/rust_aconfig_library.go
index 43078b6..3525de1 100644
--- a/aconfig/rust_aconfig_library.go
+++ b/aconfig/codegen/rust_aconfig_library.go
@@ -1,8 +1,9 @@
-package aconfig
+package codegen
import (
"fmt"
+ "android/soong/aconfig"
"android/soong/android"
"android/soong/rust"
@@ -20,10 +21,6 @@
// name of the aconfig_declarations module to generate a library for
Aconfig_declarations string
- // whether to generate test mode version of the library
- // TODO: remove "Test" property when "Mode" can be used in all the branches
- Test *bool
-
// default mode is "production", the other accepted modes are:
// "test": to generate test mode version of the library
// "exported": to generate exported mode version of the library
@@ -68,21 +65,13 @@
if len(declarationsModules) != 1 {
panic(fmt.Errorf("Exactly one aconfig_declarations property required"))
}
- declarations := ctx.OtherModuleProvider(declarationsModules[0], declarationsProviderKey).(declarationsProviderData)
+ declarations := ctx.OtherModuleProvider(declarationsModules[0], aconfig.DeclarationsProviderKey).(aconfig.DeclarationsProviderData)
- if a.Properties.Mode != nil && a.Properties.Test != nil {
- ctx.PropertyErrorf("test", "test prop should not be specified when mode prop is set")
- }
mode := proptools.StringDefault(a.Properties.Mode, "production")
if !isModeSupported(mode) {
ctx.PropertyErrorf("mode", "%q is not a supported mode", mode)
}
- // TODO: remove "Test" property
- if proptools.Bool(a.Properties.Test) {
- mode = "test"
- }
-
ctx.Build(pctx, android.BuildParams{
Rule: rustRule,
Input: declarations.IntermediatePath,
diff --git a/aconfig/rust_aconfig_library_test.go b/aconfig/codegen/rust_aconfig_library_test.go
similarity index 96%
rename from aconfig/rust_aconfig_library_test.go
rename to aconfig/codegen/rust_aconfig_library_test.go
index 5e630b5..c09f701 100644
--- a/aconfig/rust_aconfig_library_test.go
+++ b/aconfig/codegen/rust_aconfig_library_test.go
@@ -1,4 +1,4 @@
-package aconfig
+package codegen
import (
"fmt"
@@ -119,8 +119,6 @@
setting, expectedErr string
}{
{"mode: `unsupported`,", "mode: \"unsupported\" is not a supported mode"},
- // TODO: remove this test case when test prop is removed
- {"mode: `test`, test: true", "test prop should not be specified when mode prop is set"},
}
func TestIncorrectRustCodegenMode(t *testing.T) {
diff --git a/aconfig/codegen/testing.go b/aconfig/codegen/testing.go
new file mode 100644
index 0000000..3e1c22e
--- /dev/null
+++ b/aconfig/codegen/testing.go
@@ -0,0 +1,25 @@
+// Copyright (C) 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 codegen
+
+import (
+ "android/soong/aconfig"
+ "android/soong/android"
+)
+
+var PrepareForTestWithAconfigBuildComponents = android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
+ ctx.RegisterModuleType("aconfig_declarations", aconfig.DeclarationsFactory)
+ RegisterBuildComponents(ctx)
+})
diff --git a/aconfig/init.go b/aconfig/init.go
index 3d62714..79bf002 100644
--- a/aconfig/init.go
+++ b/aconfig/init.go
@@ -40,55 +40,8 @@
Restat: true,
}, "release_version", "package", "declarations", "values", "default-permission")
- // For java_aconfig_library: Generate java file
- javaRule = pctx.AndroidStaticRule("java_aconfig_library",
- blueprint.RuleParams{
- Command: `rm -rf ${out}.tmp` +
- ` && mkdir -p ${out}.tmp` +
- ` && ${aconfig} create-java-lib` +
- ` --mode ${mode}` +
- ` --cache ${in}` +
- ` --out ${out}.tmp` +
- ` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` +
- ` && rm -rf ${out}.tmp`,
- CommandDeps: []string{
- "$aconfig",
- "$soong_zip",
- },
- Restat: true,
- }, "mode")
-
- // For java_aconfig_library: Generate java file
- cppRule = pctx.AndroidStaticRule("cc_aconfig_library",
- blueprint.RuleParams{
- Command: `rm -rf ${gendir}` +
- ` && mkdir -p ${gendir}` +
- ` && ${aconfig} create-cpp-lib` +
- ` --mode ${mode}` +
- ` --cache ${in}` +
- ` --out ${gendir}`,
- CommandDeps: []string{
- "$aconfig",
- "$soong_zip",
- },
- }, "gendir", "mode")
-
- rustRule = pctx.AndroidStaticRule("rust_aconfig_library",
- blueprint.RuleParams{
- Command: `rm -rf ${gendir}` +
- ` && mkdir -p ${gendir}` +
- ` && ${aconfig} create-rust-lib` +
- ` --mode ${mode}` +
- ` --cache ${in}` +
- ` --out ${gendir}`,
- CommandDeps: []string{
- "$aconfig",
- "$soong_zip",
- },
- }, "gendir", "mode")
-
- // For all_aconfig_declarations
- allDeclarationsRule = pctx.AndroidStaticRule("all_aconfig_declarations_dump",
+ // For all_aconfig_declarations: Combine all parsed_flags proto files
+ AllDeclarationsRule = pctx.AndroidStaticRule("All_aconfig_declarations_dump",
blueprint.RuleParams{
Command: `${aconfig} dump --format protobuf --out ${out} ${cache_files}`,
CommandDeps: []string{
@@ -107,8 +60,5 @@
ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory)
ctx.RegisterModuleType("aconfig_values", ValuesFactory)
ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
- ctx.RegisterModuleType("cc_aconfig_library", CcAconfigLibraryFactory)
- ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory)
- ctx.RegisterModuleType("rust_aconfig_library", RustAconfigLibraryFactory)
ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory)
}
diff --git a/android/Android.bp b/android/Android.bp
index 7fbba43..62f534c 100644
--- a/android/Android.bp
+++ b/android/Android.bp
@@ -37,6 +37,7 @@
"api_levels.go",
"arch.go",
"arch_list.go",
+ "base_module_context.go",
"bazel.go",
"bazel_handler.go",
"bazel_paths.go",
@@ -51,6 +52,7 @@
"defs.go",
"depset_generic.go",
"deptag.go",
+ "early_module_context.go",
"expand.go",
"filegroup.go",
"fixture.go",
@@ -65,6 +67,7 @@
"makevars.go",
"metrics.go",
"module.go",
+ "module_context.go",
"mutator.go",
"namespace.go",
"neverallow.go",
diff --git a/android/androidmk.go b/android/androidmk.go
index 62f82f2..f6e8799 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -486,17 +486,6 @@
return generateDistContributionsForMake(distContributions)
}
-// Write the license variables to Make for AndroidMkData.Custom(..) methods that do not call WriteAndroidMkData(..)
-// It's required to propagate the license metadata even for module types that have non-standard interfaces to Make.
-func (a *AndroidMkEntries) WriteLicenseVariables(w io.Writer) {
- AndroidMkEmitAssignList(w, "LOCAL_LICENSE_KINDS", a.EntryMap["LOCAL_LICENSE_KINDS"])
- AndroidMkEmitAssignList(w, "LOCAL_LICENSE_CONDITIONS", a.EntryMap["LOCAL_LICENSE_CONDITIONS"])
- AndroidMkEmitAssignList(w, "LOCAL_NOTICE_FILE", a.EntryMap["LOCAL_NOTICE_FILE"])
- if pn, ok := a.EntryMap["LOCAL_LICENSE_PACKAGE_NAME"]; ok {
- AndroidMkEmitAssignList(w, "LOCAL_LICENSE_PACKAGE_NAME", pn)
- }
-}
-
// fillInEntries goes through the common variable processing and calls the extra data funcs to
// generate and fill in AndroidMkEntries's in-struct data, ready to be flushed to a file.
type fillInEntriesContext interface {
@@ -534,15 +523,6 @@
// Collect make variable assignment entries.
a.SetString("LOCAL_PATH", ctx.ModuleDir(mod))
a.SetString("LOCAL_MODULE", name+a.SubName)
- a.AddStrings("LOCAL_LICENSE_KINDS", base.commonProperties.Effective_license_kinds...)
- a.AddStrings("LOCAL_LICENSE_CONDITIONS", base.commonProperties.Effective_license_conditions...)
- a.AddStrings("LOCAL_NOTICE_FILE", base.commonProperties.Effective_license_text.Strings()...)
- // TODO(b/151177513): Does this code need to set LOCAL_MODULE_IS_CONTAINER ?
- if base.commonProperties.Effective_package_name != nil {
- a.SetString("LOCAL_LICENSE_PACKAGE_NAME", *base.commonProperties.Effective_package_name)
- } else if len(base.commonProperties.Effective_licenses) > 0 {
- a.SetString("LOCAL_LICENSE_PACKAGE_NAME", strings.Join(base.commonProperties.Effective_licenses, " "))
- }
a.SetString("LOCAL_MODULE_CLASS", a.Class)
a.SetString("LOCAL_PREBUILT_MODULE_FILE", a.OutputFile.String())
a.AddStrings("LOCAL_REQUIRED_MODULES", a.Required...)
diff --git a/android/apex_contributions.go b/android/apex_contributions.go
index 6eaca8b..9b188de 100644
--- a/android/apex_contributions.go
+++ b/android/apex_contributions.go
@@ -98,7 +98,7 @@
func (a *allApexContributions) SetPrebuiltSelectionInfoProvider(ctx BaseModuleContext) {
addContentsToProvider := func(p *PrebuiltSelectionInfoMap, m *apexContributions) {
for _, content := range m.Contents() {
- if !ctx.OtherModuleExists(content) {
+ if !ctx.OtherModuleExists(content) && !ctx.Config().AllowMissingDependencies() {
ctx.ModuleErrorf("%s listed in apex_contributions %s does not exist\n", content, m.Name())
}
pi := &PrebuiltSelectionInfo{
diff --git a/android/base_module_context.go b/android/base_module_context.go
new file mode 100644
index 0000000..ec9c888
--- /dev/null
+++ b/android/base_module_context.go
@@ -0,0 +1,656 @@
+// Copyright 2015 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 android
+
+import (
+ "fmt"
+ "github.com/google/blueprint"
+ "regexp"
+ "strings"
+)
+
+// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
+// a Config instead of an interface{}, and some methods have been wrapped to use an android.Module
+// instead of a blueprint.Module, plus some extra methods that return Android-specific information
+// about the current module.
+type BaseModuleContext interface {
+ EarlyModuleContext
+
+ blueprintBaseModuleContext() blueprint.BaseModuleContext
+
+ // OtherModuleName returns the name of another Module. See BaseModuleContext.ModuleName for more information.
+ // It is intended for use inside the visit functions of Visit* and WalkDeps.
+ OtherModuleName(m blueprint.Module) string
+
+ // OtherModuleDir returns the directory of another Module. See BaseModuleContext.ModuleDir for more information.
+ // It is intended for use inside the visit functions of Visit* and WalkDeps.
+ OtherModuleDir(m blueprint.Module) string
+
+ // OtherModuleErrorf reports an error on another Module. See BaseModuleContext.ModuleErrorf for more information.
+ // It is intended for use inside the visit functions of Visit* and WalkDeps.
+ OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
+
+ // OtherModuleDependencyTag returns the dependency tag used to depend on a module, or nil if there is no dependency
+ // on the module. When called inside a Visit* method with current module being visited, and there are multiple
+ // dependencies on the module being visited, it returns the dependency tag used for the current dependency.
+ OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
+
+ // OtherModuleExists returns true if a module with the specified name exists, as determined by the NameInterface
+ // passed to Context.SetNameInterface, or SimpleNameInterface if it was not called.
+ OtherModuleExists(name string) bool
+
+ // OtherModuleDependencyVariantExists returns true if a module with the
+ // specified name and variant exists. The variant must match the given
+ // variations. It must also match all the non-local variations of the current
+ // module. In other words, it checks for the module that AddVariationDependencies
+ // would add a dependency on with the same arguments.
+ OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool
+
+ // OtherModuleFarDependencyVariantExists returns true if a module with the
+ // specified name and variant exists. The variant must match the given
+ // variations, but not the non-local variations of the current module. In
+ // other words, it checks for the module that AddFarVariationDependencies
+ // would add a dependency on with the same arguments.
+ OtherModuleFarDependencyVariantExists(variations []blueprint.Variation, name string) bool
+
+ // OtherModuleReverseDependencyVariantExists returns true if a module with the
+ // specified name exists with the same variations as the current module. In
+ // other words, it checks for the module that AddReverseDependency would add a
+ // dependency on with the same argument.
+ OtherModuleReverseDependencyVariantExists(name string) bool
+
+ // OtherModuleType returns the type of another Module. See BaseModuleContext.ModuleType for more information.
+ // It is intended for use inside the visit functions of Visit* and WalkDeps.
+ OtherModuleType(m blueprint.Module) string
+
+ // OtherModuleProvider returns the value for a provider for the given module. If the value is
+ // not set it returns the zero value of the type of the provider, so the return value can always
+ // be type asserted to the type of the provider. The value returned may be a deep copy of the
+ // value originally passed to SetProvider.
+ OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{}
+
+ // OtherModuleHasProvider returns true if the provider for the given module has been set.
+ OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool
+
+ // Provider returns the value for a provider for the current module. If the value is
+ // not set it returns the zero value of the type of the provider, so the return value can always
+ // be type asserted to the type of the provider. It panics if called before the appropriate
+ // mutator or GenerateBuildActions pass for the provider. The value returned may be a deep
+ // copy of the value originally passed to SetProvider.
+ Provider(provider blueprint.ProviderKey) interface{}
+
+ // HasProvider returns true if the provider for the current module has been set.
+ HasProvider(provider blueprint.ProviderKey) bool
+
+ // SetProvider sets the value for a provider for the current module. It panics if not called
+ // during the appropriate mutator or GenerateBuildActions pass for the provider, if the value
+ // is not of the appropriate type, or if the value has already been set. The value should not
+ // be modified after being passed to SetProvider.
+ SetProvider(provider blueprint.ProviderKey, value interface{})
+
+ GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
+
+ // GetDirectDepWithTag returns the Module the direct dependency with the specified name, or nil if
+ // none exists. It panics if the dependency does not have the specified tag. It skips any
+ // dependencies that are not an android.Module.
+ GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
+
+ // GetDirectDep returns the Module and DependencyTag for the direct dependency with the specified
+ // name, or nil if none exists. If there are multiple dependencies on the same module it returns
+ // the first DependencyTag.
+ GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
+
+ ModuleFromName(name string) (blueprint.Module, bool)
+
+ // VisitDirectDepsBlueprint calls visit for each direct dependency. If there are multiple
+ // direct dependencies on the same module visit will be called multiple times on that module
+ // and OtherModuleDependencyTag will return a different tag for each.
+ //
+ // The Module passed to the visit function should not be retained outside of the visit
+ // function, it may be invalidated by future mutators.
+ VisitDirectDepsBlueprint(visit func(blueprint.Module))
+
+ // VisitDirectDeps calls visit for each direct dependency. If there are multiple
+ // direct dependencies on the same module visit will be called multiple times on that module
+ // and OtherModuleDependencyTag will return a different tag for each. It raises an error if any of the
+ // dependencies are not an android.Module.
+ //
+ // The Module passed to the visit function should not be retained outside of the visit
+ // function, it may be invalidated by future mutators.
+ VisitDirectDeps(visit func(Module))
+
+ VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
+
+ // VisitDirectDepsIf calls pred for each direct dependency, and if pred returns true calls visit. If there are
+ // multiple direct dependencies on the same module pred and visit will be called multiple times on that module and
+ // OtherModuleDependencyTag will return a different tag for each. It skips any
+ // dependencies that are not an android.Module.
+ //
+ // The Module passed to the visit function should not be retained outside of the visit function, it may be
+ // invalidated by future mutators.
+ VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
+ // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
+ VisitDepsDepthFirst(visit func(Module))
+ // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
+ VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
+
+ // WalkDeps calls visit for each transitive dependency, traversing the dependency tree in top down order. visit may
+ // be called multiple times for the same (child, parent) pair if there are multiple direct dependencies between the
+ // child and parent with different tags. OtherModuleDependencyTag will return the tag for the currently visited
+ // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down to child. It skips
+ // any dependencies that are not an android.Module.
+ //
+ // The Modules passed to the visit function should not be retained outside of the visit function, they may be
+ // invalidated by future mutators.
+ WalkDeps(visit func(child, parent Module) bool)
+
+ // WalkDepsBlueprint calls visit for each transitive dependency, traversing the dependency
+ // tree in top down order. visit may be called multiple times for the same (child, parent)
+ // pair if there are multiple direct dependencies between the child and parent with different
+ // tags. OtherModuleDependencyTag will return the tag for the currently visited
+ // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down
+ // to child.
+ //
+ // The Modules passed to the visit function should not be retained outside of the visit function, they may be
+ // invalidated by future mutators.
+ WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
+
+ // GetWalkPath is supposed to be called in visit function passed in WalkDeps()
+ // and returns a top-down dependency path from a start module to current child module.
+ GetWalkPath() []Module
+
+ // PrimaryModule returns the first variant of the current module. Variants of a module are always visited in
+ // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from the
+ // Module returned by PrimaryModule without data races. This can be used to perform singleton actions that are
+ // only done once for all variants of a module.
+ PrimaryModule() Module
+
+ // FinalModule returns the last variant of the current module. Variants of a module are always visited in
+ // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from all
+ // variants using VisitAllModuleVariants if the current module == FinalModule(). This can be used to perform
+ // singleton actions that are only done once for all variants of a module.
+ FinalModule() Module
+
+ // VisitAllModuleVariants calls visit for each variant of the current module. Variants of a module are always
+ // visited in order by mutators and GenerateBuildActions, so the data created by the current mutator can be read
+ // from all variants if the current module == FinalModule(). Otherwise, care must be taken to not access any
+ // data modified by the current mutator.
+ VisitAllModuleVariants(visit func(Module))
+
+ // GetTagPath is supposed to be called in visit function passed in WalkDeps()
+ // and returns a top-down dependency tags path from a start module to current child module.
+ // It has one less entry than GetWalkPath() as it contains the dependency tags that
+ // exist between each adjacent pair of modules in the GetWalkPath().
+ // GetTagPath()[i] is the tag between GetWalkPath()[i] and GetWalkPath()[i+1]
+ GetTagPath() []blueprint.DependencyTag
+
+ // GetPathString is supposed to be called in visit function passed in WalkDeps()
+ // and returns a multi-line string showing the modules and dependency tags
+ // among them along the top-down dependency path from a start module to current child module.
+ // skipFirst when set to true, the output doesn't include the start module,
+ // which is already printed when this function is used along with ModuleErrorf().
+ GetPathString(skipFirst bool) string
+
+ AddMissingDependencies(missingDeps []string)
+
+ // getMissingDependencies returns the list of missing dependencies.
+ // Calling this function prevents adding new dependencies.
+ getMissingDependencies() []string
+
+ // AddUnconvertedBp2buildDep stores module name of a direct dependency that was not converted via bp2build
+ AddUnconvertedBp2buildDep(dep string)
+
+ // AddMissingBp2buildDep stores the module name of a direct dependency that was not found.
+ AddMissingBp2buildDep(dep string)
+
+ Target() Target
+ TargetPrimary() bool
+
+ // The additional arch specific targets (e.g. 32/64 bit) that this module variant is
+ // responsible for creating.
+ MultiTargets() []Target
+ Arch() Arch
+ Os() OsType
+ Host() bool
+ Device() bool
+ Darwin() bool
+ Windows() bool
+ PrimaryArch() bool
+}
+
+type baseModuleContext struct {
+ bp blueprint.BaseModuleContext
+ earlyModuleContext
+ os OsType
+ target Target
+ multiTargets []Target
+ targetPrimary bool
+
+ walkPath []Module
+ tagPath []blueprint.DependencyTag
+
+ strictVisitDeps bool // If true, enforce that all dependencies are enabled
+
+ bazelConversionMode bool
+}
+
+func (b *baseModuleContext) isBazelConversionMode() bool {
+ return b.bazelConversionMode
+}
+func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string {
+ return b.bp.OtherModuleName(m)
+}
+func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string { return b.bp.OtherModuleDir(m) }
+func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) {
+ b.bp.OtherModuleErrorf(m, fmt, args...)
+}
+func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag {
+ return b.bp.OtherModuleDependencyTag(m)
+}
+func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
+func (b *baseModuleContext) OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool {
+ return b.bp.OtherModuleDependencyVariantExists(variations, name)
+}
+func (b *baseModuleContext) OtherModuleFarDependencyVariantExists(variations []blueprint.Variation, name string) bool {
+ return b.bp.OtherModuleFarDependencyVariantExists(variations, name)
+}
+func (b *baseModuleContext) OtherModuleReverseDependencyVariantExists(name string) bool {
+ return b.bp.OtherModuleReverseDependencyVariantExists(name)
+}
+func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string {
+ return b.bp.OtherModuleType(m)
+}
+func (b *baseModuleContext) OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{} {
+ return b.bp.OtherModuleProvider(m, provider)
+}
+func (b *baseModuleContext) OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool {
+ return b.bp.OtherModuleHasProvider(m, provider)
+}
+func (b *baseModuleContext) Provider(provider blueprint.ProviderKey) interface{} {
+ return b.bp.Provider(provider)
+}
+func (b *baseModuleContext) HasProvider(provider blueprint.ProviderKey) bool {
+ return b.bp.HasProvider(provider)
+}
+func (b *baseModuleContext) SetProvider(provider blueprint.ProviderKey, value interface{}) {
+ b.bp.SetProvider(provider, value)
+}
+
+func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
+ return b.bp.GetDirectDepWithTag(name, tag)
+}
+
+func (b *baseModuleContext) blueprintBaseModuleContext() blueprint.BaseModuleContext {
+ return b.bp
+}
+
+// AddUnconvertedBp2buildDep stores module name of a dependency that was not converted to Bazel.
+func (b *baseModuleContext) AddUnconvertedBp2buildDep(dep string) {
+ unconvertedDeps := &b.Module().base().commonProperties.BazelConversionStatus.UnconvertedDeps
+ *unconvertedDeps = append(*unconvertedDeps, dep)
+}
+
+// AddMissingBp2buildDep stores module name of a dependency that was not found in a Android.bp file.
+func (b *baseModuleContext) AddMissingBp2buildDep(dep string) {
+ missingDeps := &b.Module().base().commonProperties.BazelConversionStatus.MissingDeps
+ *missingDeps = append(*missingDeps, dep)
+}
+
+func (b *baseModuleContext) AddMissingDependencies(deps []string) {
+ if deps != nil {
+ missingDeps := &b.Module().base().commonProperties.MissingDeps
+ *missingDeps = append(*missingDeps, deps...)
+ *missingDeps = FirstUniqueStrings(*missingDeps)
+ }
+}
+
+func (b *baseModuleContext) checkedMissingDeps() bool {
+ return b.Module().base().commonProperties.CheckedMissingDeps
+}
+
+func (b *baseModuleContext) getMissingDependencies() []string {
+ checked := &b.Module().base().commonProperties.CheckedMissingDeps
+ *checked = true
+ var missingDeps []string
+ missingDeps = append(missingDeps, b.Module().base().commonProperties.MissingDeps...)
+ missingDeps = append(missingDeps, b.bp.EarlyGetMissingDependencies()...)
+ missingDeps = FirstUniqueStrings(missingDeps)
+ return missingDeps
+}
+
+type AllowDisabledModuleDependency interface {
+ blueprint.DependencyTag
+ AllowDisabledModuleDependency(target Module) bool
+}
+
+func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, tag blueprint.DependencyTag, strict bool) Module {
+ aModule, _ := module.(Module)
+
+ if !strict {
+ return aModule
+ }
+
+ if aModule == nil {
+ b.ModuleErrorf("module %q (%#v) not an android module", b.OtherModuleName(module), tag)
+ return nil
+ }
+
+ if !aModule.Enabled() {
+ if t, ok := tag.(AllowDisabledModuleDependency); !ok || !t.AllowDisabledModuleDependency(aModule) {
+ if b.Config().AllowMissingDependencies() {
+ b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
+ } else {
+ b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
+ }
+ }
+ return nil
+ }
+ return aModule
+}
+
+type dep struct {
+ mod blueprint.Module
+ tag blueprint.DependencyTag
+}
+
+func (b *baseModuleContext) getDirectDepsInternal(name string, tag blueprint.DependencyTag) []dep {
+ var deps []dep
+ b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
+ if aModule, _ := module.(Module); aModule != nil {
+ if aModule.base().BaseModuleName() == name {
+ returnedTag := b.bp.OtherModuleDependencyTag(aModule)
+ if tag == nil || returnedTag == tag {
+ deps = append(deps, dep{aModule, returnedTag})
+ }
+ }
+ } else if b.bp.OtherModuleName(module) == name {
+ returnedTag := b.bp.OtherModuleDependencyTag(module)
+ if tag == nil || returnedTag == tag {
+ deps = append(deps, dep{module, returnedTag})
+ }
+ }
+ })
+ return deps
+}
+
+func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
+ deps := b.getDirectDepsInternal(name, tag)
+ if len(deps) == 1 {
+ return deps[0].mod, deps[0].tag
+ } else if len(deps) >= 2 {
+ panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
+ name, b.ModuleName()))
+ } else {
+ return nil, nil
+ }
+}
+
+func (b *baseModuleContext) getDirectDepFirstTag(name string) (blueprint.Module, blueprint.DependencyTag) {
+ foundDeps := b.getDirectDepsInternal(name, nil)
+ deps := map[blueprint.Module]bool{}
+ for _, dep := range foundDeps {
+ deps[dep.mod] = true
+ }
+ if len(deps) == 1 {
+ return foundDeps[0].mod, foundDeps[0].tag
+ } else if len(deps) >= 2 {
+ // this could happen if two dependencies have the same name in different namespaces
+ // TODO(b/186554727): this should not occur if namespaces are handled within
+ // getDirectDepsInternal.
+ panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
+ name, b.ModuleName()))
+ } else {
+ return nil, nil
+ }
+}
+
+func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
+ var deps []Module
+ b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
+ if aModule, _ := module.(Module); aModule != nil {
+ if b.bp.OtherModuleDependencyTag(aModule) == tag {
+ deps = append(deps, aModule)
+ }
+ }
+ })
+ return deps
+}
+
+// GetDirectDep returns the Module and DependencyTag for the direct dependency with the specified
+// name, or nil if none exists. If there are multiple dependencies on the same module it returns the
+// first DependencyTag.
+func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
+ return b.getDirectDepFirstTag(name)
+}
+
+func (b *baseModuleContext) ModuleFromName(name string) (blueprint.Module, bool) {
+ if !b.isBazelConversionMode() {
+ panic("cannot call ModuleFromName if not in bazel conversion mode")
+ }
+ var m blueprint.Module
+ var ok bool
+ if moduleName, _ := SrcIsModuleWithTag(name); moduleName != "" {
+ m, ok = b.bp.ModuleFromName(moduleName)
+ } else {
+ m, ok = b.bp.ModuleFromName(name)
+ }
+ if !ok {
+ return m, ok
+ }
+ // If this module is not preferred, tried to get the prebuilt version instead
+ if a, aOk := m.(Module); aOk && !IsModulePrebuilt(a) && !IsModulePreferred(a) {
+ return b.ModuleFromName("prebuilt_" + name)
+ }
+ return m, ok
+}
+
+func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
+ b.bp.VisitDirectDeps(visit)
+}
+
+func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
+ b.bp.VisitDirectDeps(func(module blueprint.Module) {
+ if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
+ visit(aModule)
+ }
+ })
+}
+
+func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
+ b.bp.VisitDirectDeps(func(module blueprint.Module) {
+ if b.bp.OtherModuleDependencyTag(module) == tag {
+ if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
+ visit(aModule)
+ }
+ }
+ })
+}
+
+func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
+ b.bp.VisitDirectDepsIf(
+ // pred
+ func(module blueprint.Module) bool {
+ if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
+ return pred(aModule)
+ } else {
+ return false
+ }
+ },
+ // visit
+ func(module blueprint.Module) {
+ visit(module.(Module))
+ })
+}
+
+func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
+ b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
+ if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
+ visit(aModule)
+ }
+ })
+}
+
+func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
+ b.bp.VisitDepsDepthFirstIf(
+ // pred
+ func(module blueprint.Module) bool {
+ if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
+ return pred(aModule)
+ } else {
+ return false
+ }
+ },
+ // visit
+ func(module blueprint.Module) {
+ visit(module.(Module))
+ })
+}
+
+func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
+ b.bp.WalkDeps(visit)
+}
+
+func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
+ b.walkPath = []Module{b.Module()}
+ b.tagPath = []blueprint.DependencyTag{}
+ b.bp.WalkDeps(func(child, parent blueprint.Module) bool {
+ childAndroidModule, _ := child.(Module)
+ parentAndroidModule, _ := parent.(Module)
+ if childAndroidModule != nil && parentAndroidModule != nil {
+ // record walkPath before visit
+ for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
+ b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
+ b.tagPath = b.tagPath[0 : len(b.tagPath)-1]
+ }
+ b.walkPath = append(b.walkPath, childAndroidModule)
+ b.tagPath = append(b.tagPath, b.OtherModuleDependencyTag(childAndroidModule))
+ return visit(childAndroidModule, parentAndroidModule)
+ } else {
+ return false
+ }
+ })
+}
+
+func (b *baseModuleContext) GetWalkPath() []Module {
+ return b.walkPath
+}
+
+func (b *baseModuleContext) GetTagPath() []blueprint.DependencyTag {
+ return b.tagPath
+}
+
+func (b *baseModuleContext) VisitAllModuleVariants(visit func(Module)) {
+ b.bp.VisitAllModuleVariants(func(module blueprint.Module) {
+ visit(module.(Module))
+ })
+}
+
+func (b *baseModuleContext) PrimaryModule() Module {
+ return b.bp.PrimaryModule().(Module)
+}
+
+func (b *baseModuleContext) FinalModule() Module {
+ return b.bp.FinalModule().(Module)
+}
+
+// IsMetaDependencyTag returns true for cross-cutting metadata dependencies.
+func IsMetaDependencyTag(tag blueprint.DependencyTag) bool {
+ if tag == licenseKindTag {
+ return true
+ } else if tag == licensesTag {
+ return true
+ } else if tag == acDepTag {
+ return true
+ }
+ return false
+}
+
+// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
+// a dependency tag.
+var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:{}\E(, )?`)
+
+// PrettyPrintTag returns string representation of the tag, but prefers
+// custom String() method if available.
+func PrettyPrintTag(tag blueprint.DependencyTag) string {
+ // Use tag's custom String() method if available.
+ if stringer, ok := tag.(fmt.Stringer); ok {
+ return stringer.String()
+ }
+
+ // Otherwise, get a default string representation of the tag's struct.
+ tagString := fmt.Sprintf("%T: %+v", tag, tag)
+
+ // Remove the boilerplate from BaseDependencyTag as it adds no value.
+ tagString = tagCleaner.ReplaceAllString(tagString, "")
+ return tagString
+}
+
+func (b *baseModuleContext) GetPathString(skipFirst bool) string {
+ sb := strings.Builder{}
+ tagPath := b.GetTagPath()
+ walkPath := b.GetWalkPath()
+ if !skipFirst {
+ sb.WriteString(walkPath[0].String())
+ }
+ for i, m := range walkPath[1:] {
+ sb.WriteString("\n")
+ sb.WriteString(fmt.Sprintf(" via tag %s\n", PrettyPrintTag(tagPath[i])))
+ sb.WriteString(fmt.Sprintf(" -> %s", m.String()))
+ }
+ return sb.String()
+}
+
+func (b *baseModuleContext) Target() Target {
+ return b.target
+}
+
+func (b *baseModuleContext) TargetPrimary() bool {
+ return b.targetPrimary
+}
+
+func (b *baseModuleContext) MultiTargets() []Target {
+ return b.multiTargets
+}
+
+func (b *baseModuleContext) Arch() Arch {
+ return b.target.Arch
+}
+
+func (b *baseModuleContext) Os() OsType {
+ return b.os
+}
+
+func (b *baseModuleContext) Host() bool {
+ return b.os.Class == Host
+}
+
+func (b *baseModuleContext) Device() bool {
+ return b.os.Class == Device
+}
+
+func (b *baseModuleContext) Darwin() bool {
+ return b.os == Darwin
+}
+
+func (b *baseModuleContext) Windows() bool {
+ return b.os == Windows
+}
+
+func (b *baseModuleContext) PrimaryArch() bool {
+ if len(b.config.Targets[b.target.Os]) <= 1 {
+ return true
+ }
+ return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
+}
diff --git a/android/config.go b/android/config.go
index bf0b9de..0aad3bd 100644
--- a/android/config.go
+++ b/android/config.go
@@ -570,8 +570,6 @@
config: config,
}
- config.productVariables.Build_from_text_stub = boolPtr(config.BuildFromTextStub())
-
// Soundness check of the build and source directories. This won't catch strange
// configurations with symlinks, but at least checks the obvious case.
absBuildDir, err := filepath.Abs(cmdArgs.SoongOutDir)
@@ -693,7 +691,9 @@
"framework-location": {},
"framework-media": {},
"framework-mediaprovider": {},
+ "framework-nfc": {},
"framework-ondevicepersonalization": {},
+ "framework-pdf": {},
"framework-permission": {},
"framework-permission-s": {},
"framework-scheduling": {},
@@ -707,6 +707,8 @@
"i18n.module.public.api": {},
}
+ config.productVariables.Build_from_text_stub = boolPtr(config.BuildFromTextStub())
+
return Config{config}, err
}
@@ -2075,11 +2077,17 @@
return c.IsEnvTrue("EMMA_INSTRUMENT") || c.IsEnvTrue("EMMA_INSTRUMENT_STATIC") || c.IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK")
}
+func (c *deviceConfig) BuildFromSourceStub() bool {
+ return Bool(c.config.productVariables.BuildFromSourceStub)
+}
+
func (c *config) BuildFromTextStub() bool {
// TODO: b/302320354 - Remove the coverage build specific logic once the
// robust solution for handling native properties in from-text stub build
// is implemented.
- return !c.buildFromSourceStub && !c.JavaCoverageEnabled()
+ return !c.buildFromSourceStub &&
+ !c.JavaCoverageEnabled() &&
+ !c.deviceConfig.BuildFromSourceStub()
}
func (c *config) SetBuildFromTextStub(b bool) {
diff --git a/android/early_module_context.go b/android/early_module_context.go
new file mode 100644
index 0000000..8f75773
--- /dev/null
+++ b/android/early_module_context.go
@@ -0,0 +1,169 @@
+// Copyright 2015 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 android
+
+import (
+ "github.com/google/blueprint"
+ "os"
+ "text/scanner"
+)
+
+// EarlyModuleContext provides methods that can be called early, as soon as the properties have
+// been parsed into the module and before any mutators have run.
+type EarlyModuleContext interface {
+ // Module returns the current module as a Module. It should rarely be necessary, as the module already has a
+ // reference to itself.
+ Module() Module
+
+ // ModuleName returns the name of the module. This is generally the value that was returned by Module.Name() when
+ // the module was created, but may have been modified by calls to BaseMutatorContext.Rename.
+ ModuleName() string
+
+ // ModuleDir returns the path to the directory that contains the definition of the module.
+ ModuleDir() string
+
+ // ModuleType returns the name of the module type that was used to create the module, as specified in
+ // RegisterModuleType.
+ ModuleType() string
+
+ // BlueprintFile returns the name of the blueprint file that contains the definition of this
+ // module.
+ BlueprintsFile() string
+
+ // ContainsProperty returns true if the specified property name was set in the module definition.
+ ContainsProperty(name string) bool
+
+ // Errorf reports an error at the specified position of the module definition file.
+ Errorf(pos scanner.Position, fmt string, args ...interface{})
+
+ // ModuleErrorf reports an error at the line number of the module type in the module definition.
+ ModuleErrorf(fmt string, args ...interface{})
+
+ // PropertyErrorf reports an error at the line number of a property in the module definition.
+ PropertyErrorf(property, fmt string, args ...interface{})
+
+ // Failed returns true if any errors have been reported. In most cases the module can continue with generating
+ // build rules after an error, allowing it to report additional errors in a single run, but in cases where the error
+ // has prevented the module from creating necessary data it can return early when Failed returns true.
+ Failed() bool
+
+ // AddNinjaFileDeps adds dependencies on the specified files to the rule that creates the ninja manifest. The
+ // primary builder will be rerun whenever the specified files are modified.
+ AddNinjaFileDeps(deps ...string)
+
+ DeviceSpecific() bool
+ SocSpecific() bool
+ ProductSpecific() bool
+ SystemExtSpecific() bool
+ Platform() bool
+
+ Config() Config
+ DeviceConfig() DeviceConfig
+
+ // Deprecated: use Config()
+ AConfig() Config
+
+ // GlobWithDeps returns a list of files that match the specified pattern but do not match any
+ // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
+ // builder whenever a file matching the pattern as added or removed, without rerunning if a
+ // file that does not match the pattern is added to a searched directory.
+ GlobWithDeps(pattern string, excludes []string) ([]string, error)
+
+ Glob(globPattern string, excludes []string) Paths
+ GlobFiles(globPattern string, excludes []string) Paths
+ IsSymlink(path Path) bool
+ Readlink(path Path) string
+
+ // Namespace returns the Namespace object provided by the NameInterface set by Context.SetNameInterface, or the
+ // default SimpleNameInterface if Context.SetNameInterface was not called.
+ Namespace() *Namespace
+}
+
+// Deprecated: use EarlyModuleContext instead
+type BaseContext interface {
+ EarlyModuleContext
+}
+
+type earlyModuleContext struct {
+ blueprint.EarlyModuleContext
+
+ kind moduleKind
+ config Config
+}
+
+func (e *earlyModuleContext) Glob(globPattern string, excludes []string) Paths {
+ return Glob(e, globPattern, excludes)
+}
+
+func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
+ return GlobFiles(e, globPattern, excludes)
+}
+
+func (e *earlyModuleContext) IsSymlink(path Path) bool {
+ fileInfo, err := e.config.fs.Lstat(path.String())
+ if err != nil {
+ e.ModuleErrorf("os.Lstat(%q) failed: %s", path.String(), err)
+ }
+ return fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink
+}
+
+func (e *earlyModuleContext) Readlink(path Path) string {
+ dest, err := e.config.fs.Readlink(path.String())
+ if err != nil {
+ e.ModuleErrorf("os.Readlink(%q) failed: %s", path.String(), err)
+ }
+ return dest
+}
+
+func (e *earlyModuleContext) Module() Module {
+ module, _ := e.EarlyModuleContext.Module().(Module)
+ return module
+}
+
+func (e *earlyModuleContext) Config() Config {
+ return e.EarlyModuleContext.Config().(Config)
+}
+
+func (e *earlyModuleContext) AConfig() Config {
+ return e.config
+}
+
+func (e *earlyModuleContext) DeviceConfig() DeviceConfig {
+ return DeviceConfig{e.config.deviceConfig}
+}
+
+func (e *earlyModuleContext) Platform() bool {
+ return e.kind == platformModule
+}
+
+func (e *earlyModuleContext) DeviceSpecific() bool {
+ return e.kind == deviceSpecificModule
+}
+
+func (e *earlyModuleContext) SocSpecific() bool {
+ return e.kind == socSpecificModule
+}
+
+func (e *earlyModuleContext) ProductSpecific() bool {
+ return e.kind == productSpecificModule
+}
+
+func (e *earlyModuleContext) SystemExtSpecific() bool {
+ return e.kind == systemExtSpecificModule
+}
+
+func (e *earlyModuleContext) Namespace() *Namespace {
+ return e.EarlyModuleContext.Namespace().(*Namespace)
+}
diff --git a/android/module.go b/android/module.go
index 0d405eb..af69a1b 100644
--- a/android/module.go
+++ b/android/module.go
@@ -15,22 +15,17 @@
package android
import (
+ "android/soong/bazel"
+ "android/soong/ui/metrics/bp2build_metrics_proto"
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"net/url"
- "os"
- "path"
"path/filepath"
"reflect"
- "regexp"
"sort"
"strings"
- "text/scanner"
-
- "android/soong/bazel"
- "android/soong/ui/metrics/bp2build_metrics_proto"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -41,469 +36,6 @@
DeviceStaticLibrary = "static_library"
)
-// BuildParameters describes the set of potential parameters to build a Ninja rule.
-// In general, these correspond to a Ninja concept.
-type BuildParams struct {
- // A Ninja Rule that will be written to the Ninja file. This allows factoring out common code
- // among multiple modules to reduce repetition in the Ninja file of action requirements. A rule
- // can contain variables that should be provided in Args.
- Rule blueprint.Rule
- // Deps represents the depfile format. When using RuleBuilder, this defaults to GCC when depfiles
- // are used.
- Deps blueprint.Deps
- // Depfile is a writeable path that allows correct incremental builds when the inputs have not
- // been fully specified by the Ninja rule. Ninja supports a subset of the Makefile depfile syntax.
- Depfile WritablePath
- // A description of the build action.
- Description string
- // Output is an output file of the action. When using this field, references to $out in the Ninja
- // command will refer to this file.
- Output WritablePath
- // Outputs is a slice of output file of the action. When using this field, references to $out in
- // the Ninja command will refer to these files.
- Outputs WritablePaths
- // SymlinkOutput is an output file specifically that is a symlink.
- SymlinkOutput WritablePath
- // SymlinkOutputs is a slice of output files specifically that is a symlink.
- SymlinkOutputs WritablePaths
- // ImplicitOutput is an output file generated by the action. Note: references to `$out` in the
- // Ninja command will NOT include references to this file.
- ImplicitOutput WritablePath
- // ImplicitOutputs is a slice of output files generated by the action. Note: references to `$out`
- // in the Ninja command will NOT include references to these files.
- ImplicitOutputs WritablePaths
- // Input is an input file to the Ninja action. When using this field, references to $in in the
- // Ninja command will refer to this file.
- Input Path
- // Inputs is a slice of input files to the Ninja action. When using this field, references to $in
- // in the Ninja command will refer to these files.
- Inputs Paths
- // Implicit is an input file to the Ninja action. Note: references to `$in` in the Ninja command
- // will NOT include references to this file.
- Implicit Path
- // Implicits is a slice of input files to the Ninja action. Note: references to `$in` in the Ninja
- // command will NOT include references to these files.
- Implicits Paths
- // OrderOnly are Ninja order-only inputs to the action. When these are out of date, the output is
- // not rebuilt until they are built, but changes in order-only dependencies alone do not cause the
- // output to be rebuilt.
- OrderOnly Paths
- // Validation is an output path for a validation action. Validation outputs imply lower
- // non-blocking priority to building non-validation outputs.
- Validation Path
- // Validations is a slice of output path for a validation action. Validation outputs imply lower
- // non-blocking priority to building non-validation outputs.
- Validations Paths
- // Whether to skip outputting a default target statement which will be built by Ninja when no
- // targets are specified on Ninja's command line.
- Default bool
- // Args is a key value mapping for replacements of variables within the Rule
- Args map[string]string
-}
-
-type ModuleBuildParams BuildParams
-
-// EarlyModuleContext provides methods that can be called early, as soon as the properties have
-// been parsed into the module and before any mutators have run.
-type EarlyModuleContext interface {
- // Module returns the current module as a Module. It should rarely be necessary, as the module already has a
- // reference to itself.
- Module() Module
-
- // ModuleName returns the name of the module. This is generally the value that was returned by Module.Name() when
- // the module was created, but may have been modified by calls to BaseMutatorContext.Rename.
- ModuleName() string
-
- // ModuleDir returns the path to the directory that contains the definition of the module.
- ModuleDir() string
-
- // ModuleType returns the name of the module type that was used to create the module, as specified in
- // RegisterModuleType.
- ModuleType() string
-
- // BlueprintFile returns the name of the blueprint file that contains the definition of this
- // module.
- BlueprintsFile() string
-
- // ContainsProperty returns true if the specified property name was set in the module definition.
- ContainsProperty(name string) bool
-
- // Errorf reports an error at the specified position of the module definition file.
- Errorf(pos scanner.Position, fmt string, args ...interface{})
-
- // ModuleErrorf reports an error at the line number of the module type in the module definition.
- ModuleErrorf(fmt string, args ...interface{})
-
- // PropertyErrorf reports an error at the line number of a property in the module definition.
- PropertyErrorf(property, fmt string, args ...interface{})
-
- // Failed returns true if any errors have been reported. In most cases the module can continue with generating
- // build rules after an error, allowing it to report additional errors in a single run, but in cases where the error
- // has prevented the module from creating necessary data it can return early when Failed returns true.
- Failed() bool
-
- // AddNinjaFileDeps adds dependencies on the specified files to the rule that creates the ninja manifest. The
- // primary builder will be rerun whenever the specified files are modified.
- AddNinjaFileDeps(deps ...string)
-
- DeviceSpecific() bool
- SocSpecific() bool
- ProductSpecific() bool
- SystemExtSpecific() bool
- Platform() bool
-
- Config() Config
- DeviceConfig() DeviceConfig
-
- // Deprecated: use Config()
- AConfig() Config
-
- // GlobWithDeps returns a list of files that match the specified pattern but do not match any
- // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
- // builder whenever a file matching the pattern as added or removed, without rerunning if a
- // file that does not match the pattern is added to a searched directory.
- GlobWithDeps(pattern string, excludes []string) ([]string, error)
-
- Glob(globPattern string, excludes []string) Paths
- GlobFiles(globPattern string, excludes []string) Paths
- IsSymlink(path Path) bool
- Readlink(path Path) string
-
- // Namespace returns the Namespace object provided by the NameInterface set by Context.SetNameInterface, or the
- // default SimpleNameInterface if Context.SetNameInterface was not called.
- Namespace() *Namespace
-}
-
-// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
-// a Config instead of an interface{}, and some methods have been wrapped to use an android.Module
-// instead of a blueprint.Module, plus some extra methods that return Android-specific information
-// about the current module.
-type BaseModuleContext interface {
- EarlyModuleContext
-
- blueprintBaseModuleContext() blueprint.BaseModuleContext
-
- // OtherModuleName returns the name of another Module. See BaseModuleContext.ModuleName for more information.
- // It is intended for use inside the visit functions of Visit* and WalkDeps.
- OtherModuleName(m blueprint.Module) string
-
- // OtherModuleDir returns the directory of another Module. See BaseModuleContext.ModuleDir for more information.
- // It is intended for use inside the visit functions of Visit* and WalkDeps.
- OtherModuleDir(m blueprint.Module) string
-
- // OtherModuleErrorf reports an error on another Module. See BaseModuleContext.ModuleErrorf for more information.
- // It is intended for use inside the visit functions of Visit* and WalkDeps.
- OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
-
- // OtherModuleDependencyTag returns the dependency tag used to depend on a module, or nil if there is no dependency
- // on the module. When called inside a Visit* method with current module being visited, and there are multiple
- // dependencies on the module being visited, it returns the dependency tag used for the current dependency.
- OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
-
- // OtherModuleExists returns true if a module with the specified name exists, as determined by the NameInterface
- // passed to Context.SetNameInterface, or SimpleNameInterface if it was not called.
- OtherModuleExists(name string) bool
-
- // OtherModuleDependencyVariantExists returns true if a module with the
- // specified name and variant exists. The variant must match the given
- // variations. It must also match all the non-local variations of the current
- // module. In other words, it checks for the module that AddVariationDependencies
- // would add a dependency on with the same arguments.
- OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool
-
- // OtherModuleFarDependencyVariantExists returns true if a module with the
- // specified name and variant exists. The variant must match the given
- // variations, but not the non-local variations of the current module. In
- // other words, it checks for the module that AddFarVariationDependencies
- // would add a dependency on with the same arguments.
- OtherModuleFarDependencyVariantExists(variations []blueprint.Variation, name string) bool
-
- // OtherModuleReverseDependencyVariantExists returns true if a module with the
- // specified name exists with the same variations as the current module. In
- // other words, it checks for the module that AddReverseDependency would add a
- // dependency on with the same argument.
- OtherModuleReverseDependencyVariantExists(name string) bool
-
- // OtherModuleType returns the type of another Module. See BaseModuleContext.ModuleType for more information.
- // It is intended for use inside the visit functions of Visit* and WalkDeps.
- OtherModuleType(m blueprint.Module) string
-
- // OtherModuleProvider returns the value for a provider for the given module. If the value is
- // not set it returns the zero value of the type of the provider, so the return value can always
- // be type asserted to the type of the provider. The value returned may be a deep copy of the
- // value originally passed to SetProvider.
- OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{}
-
- // OtherModuleHasProvider returns true if the provider for the given module has been set.
- OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool
-
- // Provider returns the value for a provider for the current module. If the value is
- // not set it returns the zero value of the type of the provider, so the return value can always
- // be type asserted to the type of the provider. It panics if called before the appropriate
- // mutator or GenerateBuildActions pass for the provider. The value returned may be a deep
- // copy of the value originally passed to SetProvider.
- Provider(provider blueprint.ProviderKey) interface{}
-
- // HasProvider returns true if the provider for the current module has been set.
- HasProvider(provider blueprint.ProviderKey) bool
-
- // SetProvider sets the value for a provider for the current module. It panics if not called
- // during the appropriate mutator or GenerateBuildActions pass for the provider, if the value
- // is not of the appropriate type, or if the value has already been set. The value should not
- // be modified after being passed to SetProvider.
- SetProvider(provider blueprint.ProviderKey, value interface{})
-
- GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
-
- // GetDirectDepWithTag returns the Module the direct dependency with the specified name, or nil if
- // none exists. It panics if the dependency does not have the specified tag. It skips any
- // dependencies that are not an android.Module.
- GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
-
- // GetDirectDep returns the Module and DependencyTag for the direct dependency with the specified
- // name, or nil if none exists. If there are multiple dependencies on the same module it returns
- // the first DependencyTag.
- GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
-
- ModuleFromName(name string) (blueprint.Module, bool)
-
- // VisitDirectDepsBlueprint calls visit for each direct dependency. If there are multiple
- // direct dependencies on the same module visit will be called multiple times on that module
- // and OtherModuleDependencyTag will return a different tag for each.
- //
- // The Module passed to the visit function should not be retained outside of the visit
- // function, it may be invalidated by future mutators.
- VisitDirectDepsBlueprint(visit func(blueprint.Module))
-
- // VisitDirectDeps calls visit for each direct dependency. If there are multiple
- // direct dependencies on the same module visit will be called multiple times on that module
- // and OtherModuleDependencyTag will return a different tag for each. It raises an error if any of the
- // dependencies are not an android.Module.
- //
- // The Module passed to the visit function should not be retained outside of the visit
- // function, it may be invalidated by future mutators.
- VisitDirectDeps(visit func(Module))
-
- VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
-
- // VisitDirectDepsIf calls pred for each direct dependency, and if pred returns true calls visit. If there are
- // multiple direct dependencies on the same module pred and visit will be called multiple times on that module and
- // OtherModuleDependencyTag will return a different tag for each. It skips any
- // dependencies that are not an android.Module.
- //
- // The Module passed to the visit function should not be retained outside of the visit function, it may be
- // invalidated by future mutators.
- VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
- // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
- VisitDepsDepthFirst(visit func(Module))
- // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
- VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
-
- // WalkDeps calls visit for each transitive dependency, traversing the dependency tree in top down order. visit may
- // be called multiple times for the same (child, parent) pair if there are multiple direct dependencies between the
- // child and parent with different tags. OtherModuleDependencyTag will return the tag for the currently visited
- // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down to child. It skips
- // any dependencies that are not an android.Module.
- //
- // The Modules passed to the visit function should not be retained outside of the visit function, they may be
- // invalidated by future mutators.
- WalkDeps(visit func(child, parent Module) bool)
-
- // WalkDepsBlueprint calls visit for each transitive dependency, traversing the dependency
- // tree in top down order. visit may be called multiple times for the same (child, parent)
- // pair if there are multiple direct dependencies between the child and parent with different
- // tags. OtherModuleDependencyTag will return the tag for the currently visited
- // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down
- // to child.
- //
- // The Modules passed to the visit function should not be retained outside of the visit function, they may be
- // invalidated by future mutators.
- WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
-
- // GetWalkPath is supposed to be called in visit function passed in WalkDeps()
- // and returns a top-down dependency path from a start module to current child module.
- GetWalkPath() []Module
-
- // PrimaryModule returns the first variant of the current module. Variants of a module are always visited in
- // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from the
- // Module returned by PrimaryModule without data races. This can be used to perform singleton actions that are
- // only done once for all variants of a module.
- PrimaryModule() Module
-
- // FinalModule returns the last variant of the current module. Variants of a module are always visited in
- // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from all
- // variants using VisitAllModuleVariants if the current module == FinalModule(). This can be used to perform
- // singleton actions that are only done once for all variants of a module.
- FinalModule() Module
-
- // VisitAllModuleVariants calls visit for each variant of the current module. Variants of a module are always
- // visited in order by mutators and GenerateBuildActions, so the data created by the current mutator can be read
- // from all variants if the current module == FinalModule(). Otherwise, care must be taken to not access any
- // data modified by the current mutator.
- VisitAllModuleVariants(visit func(Module))
-
- // GetTagPath is supposed to be called in visit function passed in WalkDeps()
- // and returns a top-down dependency tags path from a start module to current child module.
- // It has one less entry than GetWalkPath() as it contains the dependency tags that
- // exist between each adjacent pair of modules in the GetWalkPath().
- // GetTagPath()[i] is the tag between GetWalkPath()[i] and GetWalkPath()[i+1]
- GetTagPath() []blueprint.DependencyTag
-
- // GetPathString is supposed to be called in visit function passed in WalkDeps()
- // and returns a multi-line string showing the modules and dependency tags
- // among them along the top-down dependency path from a start module to current child module.
- // skipFirst when set to true, the output doesn't include the start module,
- // which is already printed when this function is used along with ModuleErrorf().
- GetPathString(skipFirst bool) string
-
- AddMissingDependencies(missingDeps []string)
-
- // getMissingDependencies returns the list of missing dependencies.
- // Calling this function prevents adding new dependencies.
- getMissingDependencies() []string
-
- // AddUnconvertedBp2buildDep stores module name of a direct dependency that was not converted via bp2build
- AddUnconvertedBp2buildDep(dep string)
-
- // AddMissingBp2buildDep stores the module name of a direct dependency that was not found.
- AddMissingBp2buildDep(dep string)
-
- Target() Target
- TargetPrimary() bool
-
- // The additional arch specific targets (e.g. 32/64 bit) that this module variant is
- // responsible for creating.
- MultiTargets() []Target
- Arch() Arch
- Os() OsType
- Host() bool
- Device() bool
- Darwin() bool
- Windows() bool
- PrimaryArch() bool
-}
-
-// Deprecated: use EarlyModuleContext instead
-type BaseContext interface {
- EarlyModuleContext
-}
-
-type ModuleContext interface {
- BaseModuleContext
-
- blueprintModuleContext() blueprint.ModuleContext
-
- // Deprecated: use ModuleContext.Build instead.
- ModuleBuild(pctx PackageContext, params ModuleBuildParams)
-
- // Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
- // be tagged with `android:"path" to support automatic source module dependency resolution.
- //
- // Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
- ExpandSources(srcFiles, excludes []string) Paths
-
- // Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
- // be tagged with `android:"path" to support automatic source module dependency resolution.
- //
- // Deprecated: use PathForModuleSrc instead.
- ExpandSource(srcFile, prop string) Path
-
- ExpandOptionalSource(srcFile *string, prop string) OptionalPath
-
- // InstallExecutable creates a rule to copy srcPath to name in the installPath directory,
- // with the given additional dependencies. The file is marked executable after copying.
- //
- // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the
- // installed file will be returned by PackagingSpecs() on this module or by
- // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
- // for which IsInstallDepNeeded returns true.
- InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
-
- // InstallFile creates a rule to copy srcPath to name in the installPath directory,
- // with the given additional dependencies.
- //
- // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the
- // installed file will be returned by PackagingSpecs() on this module or by
- // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
- // for which IsInstallDepNeeded returns true.
- InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
-
- // InstallFileWithExtraFilesZip creates a rule to copy srcPath to name in the installPath
- // directory, and also unzip a zip file containing extra files to install into the same
- // directory.
- //
- // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the
- // installed file will be returned by PackagingSpecs() on this module or by
- // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
- // for which IsInstallDepNeeded returns true.
- InstallFileWithExtraFilesZip(installPath InstallPath, name string, srcPath Path, extraZip Path, deps ...Path) InstallPath
-
- // InstallSymlink creates a rule to create a symlink from src srcPath to name in the installPath
- // directory.
- //
- // The installed symlink will be returned by FilesToInstall(), and the PackagingSpec for the
- // installed file will be returned by PackagingSpecs() on this module or by
- // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
- // for which IsInstallDepNeeded returns true.
- InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath
-
- // InstallAbsoluteSymlink creates a rule to create an absolute symlink from src srcPath to name
- // in the installPath directory.
- //
- // The installed symlink will be returned by FilesToInstall(), and the PackagingSpec for the
- // installed file will be returned by PackagingSpecs() on this module or by
- // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
- // for which IsInstallDepNeeded returns true.
- InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath
-
- // PackageFile creates a PackagingSpec as if InstallFile was called, but without creating
- // the rule to copy the file. This is useful to define how a module would be packaged
- // without installing it into the global installation directories.
- //
- // The created PackagingSpec for the will be returned by PackagingSpecs() on this module or by
- // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
- // for which IsInstallDepNeeded returns true.
- PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec
-
- CheckbuildFile(srcPath Path)
-
- InstallInData() bool
- InstallInTestcases() bool
- InstallInSanitizerDir() bool
- InstallInRamdisk() bool
- InstallInVendorRamdisk() bool
- InstallInDebugRamdisk() bool
- InstallInRecovery() bool
- InstallInRoot() bool
- InstallInVendor() bool
- InstallForceOS() (*OsType, *ArchType)
-
- RequiredModuleNames() []string
- HostRequiredModuleNames() []string
- TargetRequiredModuleNames() []string
-
- ModuleSubDir() string
- SoongConfigTraceHash() string
-
- Variable(pctx PackageContext, name, value string)
- Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
- // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
- // and performs more verification.
- Build(pctx PackageContext, params BuildParams)
- // Phony creates a Make-style phony rule, a rule with no commands that can depend on other
- // phony rules or real files. Phony can be called on the same name multiple times to add
- // additional dependencies.
- Phony(phony string, deps ...Path)
-
- // GetMissingDependencies returns the list of dependencies that were passed to AddDependencies or related methods,
- // but do not exist.
- GetMissingDependencies() []string
-
- // LicenseMetadataFile returns the path where the license metadata for this module will be
- // generated.
- LicenseMetadataFile() Path
-}
-
type Module interface {
blueprint.Module
@@ -1677,18 +1209,6 @@
return m.commonProperties.BazelConversionStatus.Partition
}
-// AddUnconvertedBp2buildDep stores module name of a dependency that was not converted to Bazel.
-func (b *baseModuleContext) AddUnconvertedBp2buildDep(dep string) {
- unconvertedDeps := &b.Module().base().commonProperties.BazelConversionStatus.UnconvertedDeps
- *unconvertedDeps = append(*unconvertedDeps, dep)
-}
-
-// AddMissingBp2buildDep stores module name of a dependency that was not found in a Android.bp file.
-func (b *baseModuleContext) AddMissingBp2buildDep(dep string) {
- missingDeps := &b.Module().base().commonProperties.BazelConversionStatus.MissingDeps
- *missingDeps = append(*missingDeps, dep)
-}
-
// GetUnconvertedBp2buildDeps returns the list of module names of this module's direct dependencies that
// were not converted to Bazel.
func (m *ModuleBase) GetUnconvertedBp2buildDeps() []string {
@@ -2605,162 +2125,6 @@
}
-type earlyModuleContext struct {
- blueprint.EarlyModuleContext
-
- kind moduleKind
- config Config
-}
-
-func (e *earlyModuleContext) Glob(globPattern string, excludes []string) Paths {
- return Glob(e, globPattern, excludes)
-}
-
-func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
- return GlobFiles(e, globPattern, excludes)
-}
-
-func (e *earlyModuleContext) IsSymlink(path Path) bool {
- fileInfo, err := e.config.fs.Lstat(path.String())
- if err != nil {
- e.ModuleErrorf("os.Lstat(%q) failed: %s", path.String(), err)
- }
- return fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink
-}
-
-func (e *earlyModuleContext) Readlink(path Path) string {
- dest, err := e.config.fs.Readlink(path.String())
- if err != nil {
- e.ModuleErrorf("os.Readlink(%q) failed: %s", path.String(), err)
- }
- return dest
-}
-
-func (e *earlyModuleContext) Module() Module {
- module, _ := e.EarlyModuleContext.Module().(Module)
- return module
-}
-
-func (e *earlyModuleContext) Config() Config {
- return e.EarlyModuleContext.Config().(Config)
-}
-
-func (e *earlyModuleContext) AConfig() Config {
- return e.config
-}
-
-func (e *earlyModuleContext) DeviceConfig() DeviceConfig {
- return DeviceConfig{e.config.deviceConfig}
-}
-
-func (e *earlyModuleContext) Platform() bool {
- return e.kind == platformModule
-}
-
-func (e *earlyModuleContext) DeviceSpecific() bool {
- return e.kind == deviceSpecificModule
-}
-
-func (e *earlyModuleContext) SocSpecific() bool {
- return e.kind == socSpecificModule
-}
-
-func (e *earlyModuleContext) ProductSpecific() bool {
- return e.kind == productSpecificModule
-}
-
-func (e *earlyModuleContext) SystemExtSpecific() bool {
- return e.kind == systemExtSpecificModule
-}
-
-func (e *earlyModuleContext) Namespace() *Namespace {
- return e.EarlyModuleContext.Namespace().(*Namespace)
-}
-
-type baseModuleContext struct {
- bp blueprint.BaseModuleContext
- earlyModuleContext
- os OsType
- target Target
- multiTargets []Target
- targetPrimary bool
-
- walkPath []Module
- tagPath []blueprint.DependencyTag
-
- strictVisitDeps bool // If true, enforce that all dependencies are enabled
-
- bazelConversionMode bool
-}
-
-func (b *baseModuleContext) isBazelConversionMode() bool {
- return b.bazelConversionMode
-}
-func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string {
- return b.bp.OtherModuleName(m)
-}
-func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string { return b.bp.OtherModuleDir(m) }
-func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) {
- b.bp.OtherModuleErrorf(m, fmt, args...)
-}
-func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag {
- return b.bp.OtherModuleDependencyTag(m)
-}
-func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
-func (b *baseModuleContext) OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool {
- return b.bp.OtherModuleDependencyVariantExists(variations, name)
-}
-func (b *baseModuleContext) OtherModuleFarDependencyVariantExists(variations []blueprint.Variation, name string) bool {
- return b.bp.OtherModuleFarDependencyVariantExists(variations, name)
-}
-func (b *baseModuleContext) OtherModuleReverseDependencyVariantExists(name string) bool {
- return b.bp.OtherModuleReverseDependencyVariantExists(name)
-}
-func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string {
- return b.bp.OtherModuleType(m)
-}
-func (b *baseModuleContext) OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{} {
- return b.bp.OtherModuleProvider(m, provider)
-}
-func (b *baseModuleContext) OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool {
- return b.bp.OtherModuleHasProvider(m, provider)
-}
-func (b *baseModuleContext) Provider(provider blueprint.ProviderKey) interface{} {
- return b.bp.Provider(provider)
-}
-func (b *baseModuleContext) HasProvider(provider blueprint.ProviderKey) bool {
- return b.bp.HasProvider(provider)
-}
-func (b *baseModuleContext) SetProvider(provider blueprint.ProviderKey, value interface{}) {
- b.bp.SetProvider(provider, value)
-}
-
-func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
- return b.bp.GetDirectDepWithTag(name, tag)
-}
-
-func (b *baseModuleContext) blueprintBaseModuleContext() blueprint.BaseModuleContext {
- return b.bp
-}
-
-type moduleContext struct {
- bp blueprint.ModuleContext
- baseModuleContext
- packagingSpecs []PackagingSpec
- installFiles InstallPaths
- checkbuildFiles Paths
- module Module
- phonies map[string]Paths
-
- katiInstalls []katiInstall
- katiSymlinks []katiInstall
-
- // For tests
- buildParams []BuildParams
- ruleParams map[blueprint.Rule]blueprint.RuleParams
- variables map[string]string
-}
-
// katiInstall stores a request from Soong to Make to create an install rule.
type katiInstall struct {
from Path
@@ -2804,525 +2168,6 @@
return paths
}
-func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
- return pctx, BuildParams{
- Rule: ErrorRule,
- Description: params.Description,
- Output: params.Output,
- Outputs: params.Outputs,
- ImplicitOutput: params.ImplicitOutput,
- ImplicitOutputs: params.ImplicitOutputs,
- Args: map[string]string{
- "error": err.Error(),
- },
- }
-}
-
-func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
- m.Build(pctx, BuildParams(params))
-}
-
-func validateBuildParams(params blueprint.BuildParams) error {
- // Validate that the symlink outputs are declared outputs or implicit outputs
- allOutputs := map[string]bool{}
- for _, output := range params.Outputs {
- allOutputs[output] = true
- }
- for _, output := range params.ImplicitOutputs {
- allOutputs[output] = true
- }
- for _, symlinkOutput := range params.SymlinkOutputs {
- if !allOutputs[symlinkOutput] {
- return fmt.Errorf(
- "Symlink output %s is not a declared output or implicit output",
- symlinkOutput)
- }
- }
- return nil
-}
-
-// Convert build parameters from their concrete Android types into their string representations,
-// and combine the singular and plural fields of the same type (e.g. Output and Outputs).
-func convertBuildParams(params BuildParams) blueprint.BuildParams {
- bparams := blueprint.BuildParams{
- Rule: params.Rule,
- Description: params.Description,
- Deps: params.Deps,
- Outputs: params.Outputs.Strings(),
- ImplicitOutputs: params.ImplicitOutputs.Strings(),
- SymlinkOutputs: params.SymlinkOutputs.Strings(),
- Inputs: params.Inputs.Strings(),
- Implicits: params.Implicits.Strings(),
- OrderOnly: params.OrderOnly.Strings(),
- Validations: params.Validations.Strings(),
- Args: params.Args,
- Optional: !params.Default,
- }
-
- if params.Depfile != nil {
- bparams.Depfile = params.Depfile.String()
- }
- if params.Output != nil {
- bparams.Outputs = append(bparams.Outputs, params.Output.String())
- }
- if params.SymlinkOutput != nil {
- bparams.SymlinkOutputs = append(bparams.SymlinkOutputs, params.SymlinkOutput.String())
- }
- if params.ImplicitOutput != nil {
- bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
- }
- if params.Input != nil {
- bparams.Inputs = append(bparams.Inputs, params.Input.String())
- }
- if params.Implicit != nil {
- bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
- }
- if params.Validation != nil {
- bparams.Validations = append(bparams.Validations, params.Validation.String())
- }
-
- bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
- bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
- bparams.SymlinkOutputs = proptools.NinjaEscapeList(bparams.SymlinkOutputs)
- bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
- bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
- bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
- bparams.Validations = proptools.NinjaEscapeList(bparams.Validations)
- bparams.Depfile = proptools.NinjaEscape(bparams.Depfile)
-
- return bparams
-}
-
-func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
- if m.config.captureBuild {
- m.variables[name] = value
- }
-
- m.bp.Variable(pctx.PackageContext, name, value)
-}
-
-func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
- argNames ...string) blueprint.Rule {
-
- if m.config.UseRemoteBuild() {
- if params.Pool == nil {
- // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict
- // jobs to the local parallelism value
- params.Pool = localPool
- } else if params.Pool == remotePool {
- // remotePool is a fake pool used to identify rule that are supported for remoting. If the rule's
- // pool is the remotePool, replace with nil so that ninja runs it at NINJA_REMOTE_NUM_JOBS
- // parallelism.
- params.Pool = nil
- }
- }
-
- rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
-
- if m.config.captureBuild {
- m.ruleParams[rule] = params
- }
-
- return rule
-}
-
-func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
- if params.Description != "" {
- params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
- }
-
- if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
- pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
- m.ModuleName(), strings.Join(missingDeps, ", ")))
- }
-
- if m.config.captureBuild {
- m.buildParams = append(m.buildParams, params)
- }
-
- bparams := convertBuildParams(params)
- err := validateBuildParams(bparams)
- if err != nil {
- m.ModuleErrorf(
- "%s: build parameter validation failed: %s",
- m.ModuleName(),
- err.Error())
- }
- m.bp.Build(pctx.PackageContext, bparams)
-}
-
-func (m *moduleContext) Phony(name string, deps ...Path) {
- addPhony(m.config, name, deps...)
-}
-
-func (m *moduleContext) GetMissingDependencies() []string {
- var missingDeps []string
- missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
- missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
- missingDeps = FirstUniqueStrings(missingDeps)
- return missingDeps
-}
-
-func (b *baseModuleContext) AddMissingDependencies(deps []string) {
- if deps != nil {
- missingDeps := &b.Module().base().commonProperties.MissingDeps
- *missingDeps = append(*missingDeps, deps...)
- *missingDeps = FirstUniqueStrings(*missingDeps)
- }
-}
-
-func (b *baseModuleContext) checkedMissingDeps() bool {
- return b.Module().base().commonProperties.CheckedMissingDeps
-}
-
-func (b *baseModuleContext) getMissingDependencies() []string {
- checked := &b.Module().base().commonProperties.CheckedMissingDeps
- *checked = true
- var missingDeps []string
- missingDeps = append(missingDeps, b.Module().base().commonProperties.MissingDeps...)
- missingDeps = append(missingDeps, b.bp.EarlyGetMissingDependencies()...)
- missingDeps = FirstUniqueStrings(missingDeps)
- return missingDeps
-}
-
-type AllowDisabledModuleDependency interface {
- blueprint.DependencyTag
- AllowDisabledModuleDependency(target Module) bool
-}
-
-func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, tag blueprint.DependencyTag, strict bool) Module {
- aModule, _ := module.(Module)
-
- if !strict {
- return aModule
- }
-
- if aModule == nil {
- b.ModuleErrorf("module %q (%#v) not an android module", b.OtherModuleName(module), tag)
- return nil
- }
-
- if !aModule.Enabled() {
- if t, ok := tag.(AllowDisabledModuleDependency); !ok || !t.AllowDisabledModuleDependency(aModule) {
- if b.Config().AllowMissingDependencies() {
- b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
- } else {
- b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
- }
- }
- return nil
- }
- return aModule
-}
-
-type dep struct {
- mod blueprint.Module
- tag blueprint.DependencyTag
-}
-
-func (b *baseModuleContext) getDirectDepsInternal(name string, tag blueprint.DependencyTag) []dep {
- var deps []dep
- b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
- if aModule, _ := module.(Module); aModule != nil {
- if aModule.base().BaseModuleName() == name {
- returnedTag := b.bp.OtherModuleDependencyTag(aModule)
- if tag == nil || returnedTag == tag {
- deps = append(deps, dep{aModule, returnedTag})
- }
- }
- } else if b.bp.OtherModuleName(module) == name {
- returnedTag := b.bp.OtherModuleDependencyTag(module)
- if tag == nil || returnedTag == tag {
- deps = append(deps, dep{module, returnedTag})
- }
- }
- })
- return deps
-}
-
-func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
- deps := b.getDirectDepsInternal(name, tag)
- if len(deps) == 1 {
- return deps[0].mod, deps[0].tag
- } else if len(deps) >= 2 {
- panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
- name, b.ModuleName()))
- } else {
- return nil, nil
- }
-}
-
-func (b *baseModuleContext) getDirectDepFirstTag(name string) (blueprint.Module, blueprint.DependencyTag) {
- foundDeps := b.getDirectDepsInternal(name, nil)
- deps := map[blueprint.Module]bool{}
- for _, dep := range foundDeps {
- deps[dep.mod] = true
- }
- if len(deps) == 1 {
- return foundDeps[0].mod, foundDeps[0].tag
- } else if len(deps) >= 2 {
- // this could happen if two dependencies have the same name in different namespaces
- // TODO(b/186554727): this should not occur if namespaces are handled within
- // getDirectDepsInternal.
- panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
- name, b.ModuleName()))
- } else {
- return nil, nil
- }
-}
-
-func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
- var deps []Module
- b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
- if aModule, _ := module.(Module); aModule != nil {
- if b.bp.OtherModuleDependencyTag(aModule) == tag {
- deps = append(deps, aModule)
- }
- }
- })
- return deps
-}
-
-func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
- module, _ := m.getDirectDepInternal(name, tag)
- return module
-}
-
-// GetDirectDep returns the Module and DependencyTag for the direct dependency with the specified
-// name, or nil if none exists. If there are multiple dependencies on the same module it returns the
-// first DependencyTag.
-func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
- return b.getDirectDepFirstTag(name)
-}
-
-func (b *baseModuleContext) ModuleFromName(name string) (blueprint.Module, bool) {
- if !b.isBazelConversionMode() {
- panic("cannot call ModuleFromName if not in bazel conversion mode")
- }
- var m blueprint.Module
- var ok bool
- if moduleName, _ := SrcIsModuleWithTag(name); moduleName != "" {
- m, ok = b.bp.ModuleFromName(moduleName)
- } else {
- m, ok = b.bp.ModuleFromName(name)
- }
- if !ok {
- return m, ok
- }
- // If this module is not preferred, tried to get the prebuilt version instead
- if a, aOk := m.(Module); aOk && !IsModulePrebuilt(a) && !IsModulePreferred(a) {
- return b.ModuleFromName("prebuilt_" + name)
- }
- return m, ok
-}
-
-func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
- b.bp.VisitDirectDeps(visit)
-}
-
-func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
- b.bp.VisitDirectDeps(func(module blueprint.Module) {
- if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
- visit(aModule)
- }
- })
-}
-
-func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
- b.bp.VisitDirectDeps(func(module blueprint.Module) {
- if b.bp.OtherModuleDependencyTag(module) == tag {
- if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
- visit(aModule)
- }
- }
- })
-}
-
-func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
- b.bp.VisitDirectDepsIf(
- // pred
- func(module blueprint.Module) bool {
- if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
- return pred(aModule)
- } else {
- return false
- }
- },
- // visit
- func(module blueprint.Module) {
- visit(module.(Module))
- })
-}
-
-func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
- b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
- if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
- visit(aModule)
- }
- })
-}
-
-func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
- b.bp.VisitDepsDepthFirstIf(
- // pred
- func(module blueprint.Module) bool {
- if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
- return pred(aModule)
- } else {
- return false
- }
- },
- // visit
- func(module blueprint.Module) {
- visit(module.(Module))
- })
-}
-
-func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
- b.bp.WalkDeps(visit)
-}
-
-func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
- b.walkPath = []Module{b.Module()}
- b.tagPath = []blueprint.DependencyTag{}
- b.bp.WalkDeps(func(child, parent blueprint.Module) bool {
- childAndroidModule, _ := child.(Module)
- parentAndroidModule, _ := parent.(Module)
- if childAndroidModule != nil && parentAndroidModule != nil {
- // record walkPath before visit
- for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
- b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
- b.tagPath = b.tagPath[0 : len(b.tagPath)-1]
- }
- b.walkPath = append(b.walkPath, childAndroidModule)
- b.tagPath = append(b.tagPath, b.OtherModuleDependencyTag(childAndroidModule))
- return visit(childAndroidModule, parentAndroidModule)
- } else {
- return false
- }
- })
-}
-
-func (b *baseModuleContext) GetWalkPath() []Module {
- return b.walkPath
-}
-
-func (b *baseModuleContext) GetTagPath() []blueprint.DependencyTag {
- return b.tagPath
-}
-
-func (b *baseModuleContext) VisitAllModuleVariants(visit func(Module)) {
- b.bp.VisitAllModuleVariants(func(module blueprint.Module) {
- visit(module.(Module))
- })
-}
-
-func (b *baseModuleContext) PrimaryModule() Module {
- return b.bp.PrimaryModule().(Module)
-}
-
-func (b *baseModuleContext) FinalModule() Module {
- return b.bp.FinalModule().(Module)
-}
-
-// IsMetaDependencyTag returns true for cross-cutting metadata dependencies.
-func IsMetaDependencyTag(tag blueprint.DependencyTag) bool {
- if tag == licenseKindTag {
- return true
- } else if tag == licensesTag {
- return true
- } else if tag == acDepTag {
- return true
- }
- return false
-}
-
-// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
-// a dependency tag.
-var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:{}\E(, )?`)
-
-// PrettyPrintTag returns string representation of the tag, but prefers
-// custom String() method if available.
-func PrettyPrintTag(tag blueprint.DependencyTag) string {
- // Use tag's custom String() method if available.
- if stringer, ok := tag.(fmt.Stringer); ok {
- return stringer.String()
- }
-
- // Otherwise, get a default string representation of the tag's struct.
- tagString := fmt.Sprintf("%T: %+v", tag, tag)
-
- // Remove the boilerplate from BaseDependencyTag as it adds no value.
- tagString = tagCleaner.ReplaceAllString(tagString, "")
- return tagString
-}
-
-func (b *baseModuleContext) GetPathString(skipFirst bool) string {
- sb := strings.Builder{}
- tagPath := b.GetTagPath()
- walkPath := b.GetWalkPath()
- if !skipFirst {
- sb.WriteString(walkPath[0].String())
- }
- for i, m := range walkPath[1:] {
- sb.WriteString("\n")
- sb.WriteString(fmt.Sprintf(" via tag %s\n", PrettyPrintTag(tagPath[i])))
- sb.WriteString(fmt.Sprintf(" -> %s", m.String()))
- }
- return sb.String()
-}
-
-func (m *moduleContext) ModuleSubDir() string {
- return m.bp.ModuleSubDir()
-}
-
-func (m *moduleContext) SoongConfigTraceHash() string {
- return m.module.base().commonProperties.SoongConfigTraceHash
-}
-
-func (b *baseModuleContext) Target() Target {
- return b.target
-}
-
-func (b *baseModuleContext) TargetPrimary() bool {
- return b.targetPrimary
-}
-
-func (b *baseModuleContext) MultiTargets() []Target {
- return b.multiTargets
-}
-
-func (b *baseModuleContext) Arch() Arch {
- return b.target.Arch
-}
-
-func (b *baseModuleContext) Os() OsType {
- return b.os
-}
-
-func (b *baseModuleContext) Host() bool {
- return b.os.Class == Host
-}
-
-func (b *baseModuleContext) Device() bool {
- return b.os.Class == Device
-}
-
-func (b *baseModuleContext) Darwin() bool {
- return b.os == Darwin
-}
-
-func (b *baseModuleContext) Windows() bool {
- return b.os == Windows
-}
-
-func (b *baseModuleContext) PrimaryArch() bool {
- if len(b.config.Targets[b.target.Os]) <= 1 {
- return true
- }
- return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
-}
-
// Makes this module a platform module, i.e. not specific to soc, device,
// product, or system_ext.
func (m *ModuleBase) MakeAsPlatform() {
@@ -3346,274 +2191,6 @@
return proptools.Bool(m.commonProperties.Native_bridge_supported)
}
-func (m *moduleContext) InstallInData() bool {
- return m.module.InstallInData()
-}
-
-func (m *moduleContext) InstallInTestcases() bool {
- return m.module.InstallInTestcases()
-}
-
-func (m *moduleContext) InstallInSanitizerDir() bool {
- return m.module.InstallInSanitizerDir()
-}
-
-func (m *moduleContext) InstallInRamdisk() bool {
- return m.module.InstallInRamdisk()
-}
-
-func (m *moduleContext) InstallInVendorRamdisk() bool {
- return m.module.InstallInVendorRamdisk()
-}
-
-func (m *moduleContext) InstallInDebugRamdisk() bool {
- return m.module.InstallInDebugRamdisk()
-}
-
-func (m *moduleContext) InstallInRecovery() bool {
- return m.module.InstallInRecovery()
-}
-
-func (m *moduleContext) InstallInRoot() bool {
- return m.module.InstallInRoot()
-}
-
-func (m *moduleContext) InstallForceOS() (*OsType, *ArchType) {
- return m.module.InstallForceOS()
-}
-
-func (m *moduleContext) InstallInVendor() bool {
- return m.module.InstallInVendor()
-}
-
-func (m *moduleContext) skipInstall() bool {
- if m.module.base().commonProperties.SkipInstall {
- return true
- }
-
- if m.module.base().commonProperties.HideFromMake {
- return true
- }
-
- // We'll need a solution for choosing which of modules with the same name in different
- // namespaces to install. For now, reuse the list of namespaces exported to Make as the
- // list of namespaces to install in a Soong-only build.
- if !m.module.base().commonProperties.NamespaceExportedToMake {
- return true
- }
-
- return false
-}
-
-func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
- deps ...Path) InstallPath {
- return m.installFile(installPath, name, srcPath, deps, false, nil)
-}
-
-func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
- deps ...Path) InstallPath {
- return m.installFile(installPath, name, srcPath, deps, true, nil)
-}
-
-func (m *moduleContext) InstallFileWithExtraFilesZip(installPath InstallPath, name string, srcPath Path,
- extraZip Path, deps ...Path) InstallPath {
- return m.installFile(installPath, name, srcPath, deps, false, &extraFilesZip{
- zip: extraZip,
- dir: installPath,
- })
-}
-
-func (m *moduleContext) PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec {
- fullInstallPath := installPath.Join(m, name)
- return m.packageFile(fullInstallPath, srcPath, false)
-}
-
-func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, executable bool) PackagingSpec {
- licenseFiles := m.Module().EffectiveLicenseFiles()
- spec := PackagingSpec{
- relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
- srcPath: srcPath,
- symlinkTarget: "",
- executable: executable,
- effectiveLicenseFiles: &licenseFiles,
- partition: fullInstallPath.partition,
- }
- m.packagingSpecs = append(m.packagingSpecs, spec)
- return spec
-}
-
-func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, deps []Path,
- executable bool, extraZip *extraFilesZip) InstallPath {
-
- fullInstallPath := installPath.Join(m, name)
- m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false)
-
- if !m.skipInstall() {
- deps = append(deps, InstallPaths(m.module.base().installFilesDepSet.ToList()).Paths()...)
-
- var implicitDeps, orderOnlyDeps Paths
-
- if m.Host() {
- // Installed host modules might be used during the build, depend directly on their
- // dependencies so their timestamp is updated whenever their dependency is updated
- implicitDeps = deps
- } else {
- orderOnlyDeps = deps
- }
-
- if m.Config().KatiEnabled() {
- // When creating the install rule in Soong but embedding in Make, write the rule to a
- // makefile instead of directly to the ninja file so that main.mk can add the
- // dependencies from the `required` property that are hard to resolve in Soong.
- m.katiInstalls = append(m.katiInstalls, katiInstall{
- from: srcPath,
- to: fullInstallPath,
- implicitDeps: implicitDeps,
- orderOnlyDeps: orderOnlyDeps,
- executable: executable,
- extraFiles: extraZip,
- })
- } else {
- rule := Cp
- if executable {
- rule = CpExecutable
- }
-
- extraCmds := ""
- if extraZip != nil {
- extraCmds += fmt.Sprintf(" && ( unzip -qDD -d '%s' '%s' 2>&1 | grep -v \"zipfile is empty\"; exit $${PIPESTATUS[0]} )",
- extraZip.dir.String(), extraZip.zip.String())
- extraCmds += " || ( code=$$?; if [ $$code -ne 0 -a $$code -ne 1 ]; then exit $$code; fi )"
- implicitDeps = append(implicitDeps, extraZip.zip)
- }
-
- m.Build(pctx, BuildParams{
- Rule: rule,
- Description: "install " + fullInstallPath.Base(),
- Output: fullInstallPath,
- Input: srcPath,
- Implicits: implicitDeps,
- OrderOnly: orderOnlyDeps,
- Default: !m.Config().KatiEnabled(),
- Args: map[string]string{
- "extraCmds": extraCmds,
- },
- })
- }
-
- m.installFiles = append(m.installFiles, fullInstallPath)
- }
-
- m.packageFile(fullInstallPath, srcPath, executable)
-
- m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
-
- return fullInstallPath
-}
-
-func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
- fullInstallPath := installPath.Join(m, name)
- m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, true)
-
- relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
- if err != nil {
- panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
- }
- if !m.skipInstall() {
-
- if m.Config().KatiEnabled() {
- // When creating the symlink rule in Soong but embedding in Make, write the rule to a
- // makefile instead of directly to the ninja file so that main.mk can add the
- // dependencies from the `required` property that are hard to resolve in Soong.
- m.katiSymlinks = append(m.katiSymlinks, katiInstall{
- from: srcPath,
- to: fullInstallPath,
- })
- } else {
- // The symlink doesn't need updating when the target is modified, but we sometimes
- // have a dependency on a symlink to a binary instead of to the binary directly, and
- // the mtime of the symlink must be updated when the binary is modified, so use a
- // normal dependency here instead of an order-only dependency.
- m.Build(pctx, BuildParams{
- Rule: Symlink,
- Description: "install symlink " + fullInstallPath.Base(),
- Output: fullInstallPath,
- Input: srcPath,
- Default: !m.Config().KatiEnabled(),
- Args: map[string]string{
- "fromPath": relPath,
- },
- })
- }
-
- m.installFiles = append(m.installFiles, fullInstallPath)
- m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
- }
-
- m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
- relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
- srcPath: nil,
- symlinkTarget: relPath,
- executable: false,
- partition: fullInstallPath.partition,
- })
-
- return fullInstallPath
-}
-
-// installPath/name -> absPath where absPath might be a path that is available only at runtime
-// (e.g. /apex/...)
-func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
- fullInstallPath := installPath.Join(m, name)
- m.module.base().hooks.runInstallHooks(m, nil, fullInstallPath, true)
-
- if !m.skipInstall() {
- if m.Config().KatiEnabled() {
- // When creating the symlink rule in Soong but embedding in Make, write the rule to a
- // makefile instead of directly to the ninja file so that main.mk can add the
- // dependencies from the `required` property that are hard to resolve in Soong.
- m.katiSymlinks = append(m.katiSymlinks, katiInstall{
- absFrom: absPath,
- to: fullInstallPath,
- })
- } else {
- m.Build(pctx, BuildParams{
- Rule: Symlink,
- Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
- Output: fullInstallPath,
- Default: !m.Config().KatiEnabled(),
- Args: map[string]string{
- "fromPath": absPath,
- },
- })
- }
-
- m.installFiles = append(m.installFiles, fullInstallPath)
- }
-
- m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
- relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
- srcPath: nil,
- symlinkTarget: absPath,
- executable: false,
- partition: fullInstallPath.partition,
- })
-
- return fullInstallPath
-}
-
-func (m *moduleContext) CheckbuildFile(srcPath Path) {
- m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
-}
-
-func (m *moduleContext) blueprintModuleContext() blueprint.ModuleContext {
- return m.bp
-}
-
-func (m *moduleContext) LicenseMetadataFile() Path {
- return m.module.base().licenseMetadataFile
-}
-
// SrcIsModule decodes module references in the format ":unqualified-name" or "//namespace:name"
// into the module name, or empty string if the input was not a module reference.
func SrcIsModule(s string) (module string) {
@@ -3820,44 +2397,6 @@
HostToolPath() OptionalPath
}
-// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
-// be tagged with `android:"path" to support automatic source module dependency resolution.
-//
-// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
-func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
- return PathsForModuleSrcExcludes(m, srcFiles, excludes)
-}
-
-// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
-// be tagged with `android:"path" to support automatic source module dependency resolution.
-//
-// Deprecated: use PathForModuleSrc instead.
-func (m *moduleContext) ExpandSource(srcFile, _ string) Path {
- return PathForModuleSrc(m, srcFile)
-}
-
-// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
-// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
-// dependency resolution.
-func (m *moduleContext) ExpandOptionalSource(srcFile *string, _ string) OptionalPath {
- if srcFile != nil {
- return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
- }
- return OptionalPath{}
-}
-
-func (m *moduleContext) RequiredModuleNames() []string {
- return m.module.RequiredModuleNames()
-}
-
-func (m *moduleContext) HostRequiredModuleNames() []string {
- return m.module.HostRequiredModuleNames()
-}
-
-func (m *moduleContext) TargetRequiredModuleNames() []string {
- return m.module.TargetRequiredModuleNames()
-}
-
func init() {
RegisterParallelSingletonType("buildtarget", BuildTargetSingleton)
RegisterParallelSingletonType("soongconfigtrace", soongConfigTraceSingletonFunc)
diff --git a/android/module_context.go b/android/module_context.go
new file mode 100644
index 0000000..a0a4104
--- /dev/null
+++ b/android/module_context.go
@@ -0,0 +1,698 @@
+// Copyright 2015 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 android
+
+import (
+ "fmt"
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/proptools"
+ "path"
+ "path/filepath"
+ "strings"
+)
+
+// BuildParameters describes the set of potential parameters to build a Ninja rule.
+// In general, these correspond to a Ninja concept.
+type BuildParams struct {
+ // A Ninja Rule that will be written to the Ninja file. This allows factoring out common code
+ // among multiple modules to reduce repetition in the Ninja file of action requirements. A rule
+ // can contain variables that should be provided in Args.
+ Rule blueprint.Rule
+ // Deps represents the depfile format. When using RuleBuilder, this defaults to GCC when depfiles
+ // are used.
+ Deps blueprint.Deps
+ // Depfile is a writeable path that allows correct incremental builds when the inputs have not
+ // been fully specified by the Ninja rule. Ninja supports a subset of the Makefile depfile syntax.
+ Depfile WritablePath
+ // A description of the build action.
+ Description string
+ // Output is an output file of the action. When using this field, references to $out in the Ninja
+ // command will refer to this file.
+ Output WritablePath
+ // Outputs is a slice of output file of the action. When using this field, references to $out in
+ // the Ninja command will refer to these files.
+ Outputs WritablePaths
+ // SymlinkOutput is an output file specifically that is a symlink.
+ SymlinkOutput WritablePath
+ // SymlinkOutputs is a slice of output files specifically that is a symlink.
+ SymlinkOutputs WritablePaths
+ // ImplicitOutput is an output file generated by the action. Note: references to `$out` in the
+ // Ninja command will NOT include references to this file.
+ ImplicitOutput WritablePath
+ // ImplicitOutputs is a slice of output files generated by the action. Note: references to `$out`
+ // in the Ninja command will NOT include references to these files.
+ ImplicitOutputs WritablePaths
+ // Input is an input file to the Ninja action. When using this field, references to $in in the
+ // Ninja command will refer to this file.
+ Input Path
+ // Inputs is a slice of input files to the Ninja action. When using this field, references to $in
+ // in the Ninja command will refer to these files.
+ Inputs Paths
+ // Implicit is an input file to the Ninja action. Note: references to `$in` in the Ninja command
+ // will NOT include references to this file.
+ Implicit Path
+ // Implicits is a slice of input files to the Ninja action. Note: references to `$in` in the Ninja
+ // command will NOT include references to these files.
+ Implicits Paths
+ // OrderOnly are Ninja order-only inputs to the action. When these are out of date, the output is
+ // not rebuilt until they are built, but changes in order-only dependencies alone do not cause the
+ // output to be rebuilt.
+ OrderOnly Paths
+ // Validation is an output path for a validation action. Validation outputs imply lower
+ // non-blocking priority to building non-validation outputs.
+ Validation Path
+ // Validations is a slice of output path for a validation action. Validation outputs imply lower
+ // non-blocking priority to building non-validation outputs.
+ Validations Paths
+ // Whether to skip outputting a default target statement which will be built by Ninja when no
+ // targets are specified on Ninja's command line.
+ Default bool
+ // Args is a key value mapping for replacements of variables within the Rule
+ Args map[string]string
+}
+
+type ModuleBuildParams BuildParams
+
+type ModuleContext interface {
+ BaseModuleContext
+
+ blueprintModuleContext() blueprint.ModuleContext
+
+ // Deprecated: use ModuleContext.Build instead.
+ ModuleBuild(pctx PackageContext, params ModuleBuildParams)
+
+ // Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
+ // be tagged with `android:"path" to support automatic source module dependency resolution.
+ //
+ // Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
+ ExpandSources(srcFiles, excludes []string) Paths
+
+ // Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
+ // be tagged with `android:"path" to support automatic source module dependency resolution.
+ //
+ // Deprecated: use PathForModuleSrc instead.
+ ExpandSource(srcFile, prop string) Path
+
+ ExpandOptionalSource(srcFile *string, prop string) OptionalPath
+
+ // InstallExecutable creates a rule to copy srcPath to name in the installPath directory,
+ // with the given additional dependencies. The file is marked executable after copying.
+ //
+ // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the
+ // installed file will be returned by PackagingSpecs() on this module or by
+ // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
+ // for which IsInstallDepNeeded returns true.
+ InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...InstallPath) InstallPath
+
+ // InstallFile creates a rule to copy srcPath to name in the installPath directory,
+ // with the given additional dependencies.
+ //
+ // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the
+ // installed file will be returned by PackagingSpecs() on this module or by
+ // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
+ // for which IsInstallDepNeeded returns true.
+ InstallFile(installPath InstallPath, name string, srcPath Path, deps ...InstallPath) InstallPath
+
+ // InstallFileWithExtraFilesZip creates a rule to copy srcPath to name in the installPath
+ // directory, and also unzip a zip file containing extra files to install into the same
+ // directory.
+ //
+ // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the
+ // installed file will be returned by PackagingSpecs() on this module or by
+ // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
+ // for which IsInstallDepNeeded returns true.
+ InstallFileWithExtraFilesZip(installPath InstallPath, name string, srcPath Path, extraZip Path, deps ...InstallPath) InstallPath
+
+ // InstallSymlink creates a rule to create a symlink from src srcPath to name in the installPath
+ // directory.
+ //
+ // The installed symlink will be returned by FilesToInstall(), and the PackagingSpec for the
+ // installed file will be returned by PackagingSpecs() on this module or by
+ // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
+ // for which IsInstallDepNeeded returns true.
+ InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath
+
+ // InstallAbsoluteSymlink creates a rule to create an absolute symlink from src srcPath to name
+ // in the installPath directory.
+ //
+ // The installed symlink will be returned by FilesToInstall(), and the PackagingSpec for the
+ // installed file will be returned by PackagingSpecs() on this module or by
+ // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
+ // for which IsInstallDepNeeded returns true.
+ InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath
+
+ // PackageFile creates a PackagingSpec as if InstallFile was called, but without creating
+ // the rule to copy the file. This is useful to define how a module would be packaged
+ // without installing it into the global installation directories.
+ //
+ // The created PackagingSpec for the will be returned by PackagingSpecs() on this module or by
+ // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
+ // for which IsInstallDepNeeded returns true.
+ PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec
+
+ CheckbuildFile(srcPath Path)
+
+ InstallInData() bool
+ InstallInTestcases() bool
+ InstallInSanitizerDir() bool
+ InstallInRamdisk() bool
+ InstallInVendorRamdisk() bool
+ InstallInDebugRamdisk() bool
+ InstallInRecovery() bool
+ InstallInRoot() bool
+ InstallInVendor() bool
+ InstallForceOS() (*OsType, *ArchType)
+
+ RequiredModuleNames() []string
+ HostRequiredModuleNames() []string
+ TargetRequiredModuleNames() []string
+
+ ModuleSubDir() string
+ SoongConfigTraceHash() string
+
+ Variable(pctx PackageContext, name, value string)
+ Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
+ // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
+ // and performs more verification.
+ Build(pctx PackageContext, params BuildParams)
+ // Phony creates a Make-style phony rule, a rule with no commands that can depend on other
+ // phony rules or real files. Phony can be called on the same name multiple times to add
+ // additional dependencies.
+ Phony(phony string, deps ...Path)
+
+ // GetMissingDependencies returns the list of dependencies that were passed to AddDependencies or related methods,
+ // but do not exist.
+ GetMissingDependencies() []string
+
+ // LicenseMetadataFile returns the path where the license metadata for this module will be
+ // generated.
+ LicenseMetadataFile() Path
+}
+
+type moduleContext struct {
+ bp blueprint.ModuleContext
+ baseModuleContext
+ packagingSpecs []PackagingSpec
+ installFiles InstallPaths
+ checkbuildFiles Paths
+ module Module
+ phonies map[string]Paths
+
+ katiInstalls []katiInstall
+ katiSymlinks []katiInstall
+
+ // For tests
+ buildParams []BuildParams
+ ruleParams map[blueprint.Rule]blueprint.RuleParams
+ variables map[string]string
+}
+
+func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
+ return pctx, BuildParams{
+ Rule: ErrorRule,
+ Description: params.Description,
+ Output: params.Output,
+ Outputs: params.Outputs,
+ ImplicitOutput: params.ImplicitOutput,
+ ImplicitOutputs: params.ImplicitOutputs,
+ Args: map[string]string{
+ "error": err.Error(),
+ },
+ }
+}
+
+func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
+ m.Build(pctx, BuildParams(params))
+}
+
+func validateBuildParams(params blueprint.BuildParams) error {
+ // Validate that the symlink outputs are declared outputs or implicit outputs
+ allOutputs := map[string]bool{}
+ for _, output := range params.Outputs {
+ allOutputs[output] = true
+ }
+ for _, output := range params.ImplicitOutputs {
+ allOutputs[output] = true
+ }
+ for _, symlinkOutput := range params.SymlinkOutputs {
+ if !allOutputs[symlinkOutput] {
+ return fmt.Errorf(
+ "Symlink output %s is not a declared output or implicit output",
+ symlinkOutput)
+ }
+ }
+ return nil
+}
+
+// Convert build parameters from their concrete Android types into their string representations,
+// and combine the singular and plural fields of the same type (e.g. Output and Outputs).
+func convertBuildParams(params BuildParams) blueprint.BuildParams {
+ bparams := blueprint.BuildParams{
+ Rule: params.Rule,
+ Description: params.Description,
+ Deps: params.Deps,
+ Outputs: params.Outputs.Strings(),
+ ImplicitOutputs: params.ImplicitOutputs.Strings(),
+ SymlinkOutputs: params.SymlinkOutputs.Strings(),
+ Inputs: params.Inputs.Strings(),
+ Implicits: params.Implicits.Strings(),
+ OrderOnly: params.OrderOnly.Strings(),
+ Validations: params.Validations.Strings(),
+ Args: params.Args,
+ Optional: !params.Default,
+ }
+
+ if params.Depfile != nil {
+ bparams.Depfile = params.Depfile.String()
+ }
+ if params.Output != nil {
+ bparams.Outputs = append(bparams.Outputs, params.Output.String())
+ }
+ if params.SymlinkOutput != nil {
+ bparams.SymlinkOutputs = append(bparams.SymlinkOutputs, params.SymlinkOutput.String())
+ }
+ if params.ImplicitOutput != nil {
+ bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
+ }
+ if params.Input != nil {
+ bparams.Inputs = append(bparams.Inputs, params.Input.String())
+ }
+ if params.Implicit != nil {
+ bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
+ }
+ if params.Validation != nil {
+ bparams.Validations = append(bparams.Validations, params.Validation.String())
+ }
+
+ bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
+ bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
+ bparams.SymlinkOutputs = proptools.NinjaEscapeList(bparams.SymlinkOutputs)
+ bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
+ bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
+ bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
+ bparams.Validations = proptools.NinjaEscapeList(bparams.Validations)
+ bparams.Depfile = proptools.NinjaEscape(bparams.Depfile)
+
+ return bparams
+}
+
+func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
+ if m.config.captureBuild {
+ m.variables[name] = value
+ }
+
+ m.bp.Variable(pctx.PackageContext, name, value)
+}
+
+func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
+ argNames ...string) blueprint.Rule {
+
+ if m.config.UseRemoteBuild() {
+ if params.Pool == nil {
+ // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict
+ // jobs to the local parallelism value
+ params.Pool = localPool
+ } else if params.Pool == remotePool {
+ // remotePool is a fake pool used to identify rule that are supported for remoting. If the rule's
+ // pool is the remotePool, replace with nil so that ninja runs it at NINJA_REMOTE_NUM_JOBS
+ // parallelism.
+ params.Pool = nil
+ }
+ }
+
+ rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
+
+ if m.config.captureBuild {
+ m.ruleParams[rule] = params
+ }
+
+ return rule
+}
+
+func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
+ if params.Description != "" {
+ params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
+ }
+
+ if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
+ pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
+ m.ModuleName(), strings.Join(missingDeps, ", ")))
+ }
+
+ if m.config.captureBuild {
+ m.buildParams = append(m.buildParams, params)
+ }
+
+ bparams := convertBuildParams(params)
+ err := validateBuildParams(bparams)
+ if err != nil {
+ m.ModuleErrorf(
+ "%s: build parameter validation failed: %s",
+ m.ModuleName(),
+ err.Error())
+ }
+ m.bp.Build(pctx.PackageContext, bparams)
+}
+
+func (m *moduleContext) Phony(name string, deps ...Path) {
+ addPhony(m.config, name, deps...)
+}
+
+func (m *moduleContext) GetMissingDependencies() []string {
+ var missingDeps []string
+ missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
+ missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
+ missingDeps = FirstUniqueStrings(missingDeps)
+ return missingDeps
+}
+
+func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
+ module, _ := m.getDirectDepInternal(name, tag)
+ return module
+}
+
+func (m *moduleContext) ModuleSubDir() string {
+ return m.bp.ModuleSubDir()
+}
+
+func (m *moduleContext) SoongConfigTraceHash() string {
+ return m.module.base().commonProperties.SoongConfigTraceHash
+}
+
+func (m *moduleContext) InstallInData() bool {
+ return m.module.InstallInData()
+}
+
+func (m *moduleContext) InstallInTestcases() bool {
+ return m.module.InstallInTestcases()
+}
+
+func (m *moduleContext) InstallInSanitizerDir() bool {
+ return m.module.InstallInSanitizerDir()
+}
+
+func (m *moduleContext) InstallInRamdisk() bool {
+ return m.module.InstallInRamdisk()
+}
+
+func (m *moduleContext) InstallInVendorRamdisk() bool {
+ return m.module.InstallInVendorRamdisk()
+}
+
+func (m *moduleContext) InstallInDebugRamdisk() bool {
+ return m.module.InstallInDebugRamdisk()
+}
+
+func (m *moduleContext) InstallInRecovery() bool {
+ return m.module.InstallInRecovery()
+}
+
+func (m *moduleContext) InstallInRoot() bool {
+ return m.module.InstallInRoot()
+}
+
+func (m *moduleContext) InstallForceOS() (*OsType, *ArchType) {
+ return m.module.InstallForceOS()
+}
+
+func (m *moduleContext) InstallInVendor() bool {
+ return m.module.InstallInVendor()
+}
+
+func (m *moduleContext) skipInstall() bool {
+ if m.module.base().commonProperties.SkipInstall {
+ return true
+ }
+
+ if m.module.base().commonProperties.HideFromMake {
+ return true
+ }
+
+ // We'll need a solution for choosing which of modules with the same name in different
+ // namespaces to install. For now, reuse the list of namespaces exported to Make as the
+ // list of namespaces to install in a Soong-only build.
+ if !m.module.base().commonProperties.NamespaceExportedToMake {
+ return true
+ }
+
+ return false
+}
+
+func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
+ deps ...InstallPath) InstallPath {
+ return m.installFile(installPath, name, srcPath, deps, false, nil)
+}
+
+func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
+ deps ...InstallPath) InstallPath {
+ return m.installFile(installPath, name, srcPath, deps, true, nil)
+}
+
+func (m *moduleContext) InstallFileWithExtraFilesZip(installPath InstallPath, name string, srcPath Path,
+ extraZip Path, deps ...InstallPath) InstallPath {
+ return m.installFile(installPath, name, srcPath, deps, false, &extraFilesZip{
+ zip: extraZip,
+ dir: installPath,
+ })
+}
+
+func (m *moduleContext) PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec {
+ fullInstallPath := installPath.Join(m, name)
+ return m.packageFile(fullInstallPath, srcPath, false)
+}
+
+func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, executable bool) PackagingSpec {
+ licenseFiles := m.Module().EffectiveLicenseFiles()
+ spec := PackagingSpec{
+ relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
+ srcPath: srcPath,
+ symlinkTarget: "",
+ executable: executable,
+ effectiveLicenseFiles: &licenseFiles,
+ partition: fullInstallPath.partition,
+ }
+ m.packagingSpecs = append(m.packagingSpecs, spec)
+ return spec
+}
+
+func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, deps []InstallPath,
+ executable bool, extraZip *extraFilesZip) InstallPath {
+
+ fullInstallPath := installPath.Join(m, name)
+ m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false)
+
+ if !m.skipInstall() {
+ deps = append(deps, InstallPaths(m.module.base().installFilesDepSet.ToList())...)
+
+ var implicitDeps, orderOnlyDeps Paths
+
+ if m.Host() {
+ // Installed host modules might be used during the build, depend directly on their
+ // dependencies so their timestamp is updated whenever their dependency is updated
+ implicitDeps = InstallPaths(deps).Paths()
+ } else {
+ orderOnlyDeps = InstallPaths(deps).Paths()
+ }
+
+ if m.Config().KatiEnabled() {
+ // When creating the install rule in Soong but embedding in Make, write the rule to a
+ // makefile instead of directly to the ninja file so that main.mk can add the
+ // dependencies from the `required` property that are hard to resolve in Soong.
+ m.katiInstalls = append(m.katiInstalls, katiInstall{
+ from: srcPath,
+ to: fullInstallPath,
+ implicitDeps: implicitDeps,
+ orderOnlyDeps: orderOnlyDeps,
+ executable: executable,
+ extraFiles: extraZip,
+ })
+ } else {
+ rule := Cp
+ if executable {
+ rule = CpExecutable
+ }
+
+ extraCmds := ""
+ if extraZip != nil {
+ extraCmds += fmt.Sprintf(" && ( unzip -qDD -d '%s' '%s' 2>&1 | grep -v \"zipfile is empty\"; exit $${PIPESTATUS[0]} )",
+ extraZip.dir.String(), extraZip.zip.String())
+ extraCmds += " || ( code=$$?; if [ $$code -ne 0 -a $$code -ne 1 ]; then exit $$code; fi )"
+ implicitDeps = append(implicitDeps, extraZip.zip)
+ }
+
+ m.Build(pctx, BuildParams{
+ Rule: rule,
+ Description: "install " + fullInstallPath.Base(),
+ Output: fullInstallPath,
+ Input: srcPath,
+ Implicits: implicitDeps,
+ OrderOnly: orderOnlyDeps,
+ Default: !m.Config().KatiEnabled(),
+ Args: map[string]string{
+ "extraCmds": extraCmds,
+ },
+ })
+ }
+
+ m.installFiles = append(m.installFiles, fullInstallPath)
+ }
+
+ m.packageFile(fullInstallPath, srcPath, executable)
+
+ m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
+
+ return fullInstallPath
+}
+
+func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
+ fullInstallPath := installPath.Join(m, name)
+ m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, true)
+
+ relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
+ if err != nil {
+ panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
+ }
+ if !m.skipInstall() {
+
+ if m.Config().KatiEnabled() {
+ // When creating the symlink rule in Soong but embedding in Make, write the rule to a
+ // makefile instead of directly to the ninja file so that main.mk can add the
+ // dependencies from the `required` property that are hard to resolve in Soong.
+ m.katiSymlinks = append(m.katiSymlinks, katiInstall{
+ from: srcPath,
+ to: fullInstallPath,
+ })
+ } else {
+ // The symlink doesn't need updating when the target is modified, but we sometimes
+ // have a dependency on a symlink to a binary instead of to the binary directly, and
+ // the mtime of the symlink must be updated when the binary is modified, so use a
+ // normal dependency here instead of an order-only dependency.
+ m.Build(pctx, BuildParams{
+ Rule: Symlink,
+ Description: "install symlink " + fullInstallPath.Base(),
+ Output: fullInstallPath,
+ Input: srcPath,
+ Default: !m.Config().KatiEnabled(),
+ Args: map[string]string{
+ "fromPath": relPath,
+ },
+ })
+ }
+
+ m.installFiles = append(m.installFiles, fullInstallPath)
+ m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
+ }
+
+ m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
+ relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
+ srcPath: nil,
+ symlinkTarget: relPath,
+ executable: false,
+ partition: fullInstallPath.partition,
+ })
+
+ return fullInstallPath
+}
+
+// installPath/name -> absPath where absPath might be a path that is available only at runtime
+// (e.g. /apex/...)
+func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
+ fullInstallPath := installPath.Join(m, name)
+ m.module.base().hooks.runInstallHooks(m, nil, fullInstallPath, true)
+
+ if !m.skipInstall() {
+ if m.Config().KatiEnabled() {
+ // When creating the symlink rule in Soong but embedding in Make, write the rule to a
+ // makefile instead of directly to the ninja file so that main.mk can add the
+ // dependencies from the `required` property that are hard to resolve in Soong.
+ m.katiSymlinks = append(m.katiSymlinks, katiInstall{
+ absFrom: absPath,
+ to: fullInstallPath,
+ })
+ } else {
+ m.Build(pctx, BuildParams{
+ Rule: Symlink,
+ Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
+ Output: fullInstallPath,
+ Default: !m.Config().KatiEnabled(),
+ Args: map[string]string{
+ "fromPath": absPath,
+ },
+ })
+ }
+
+ m.installFiles = append(m.installFiles, fullInstallPath)
+ }
+
+ m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
+ relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
+ srcPath: nil,
+ symlinkTarget: absPath,
+ executable: false,
+ partition: fullInstallPath.partition,
+ })
+
+ return fullInstallPath
+}
+
+func (m *moduleContext) CheckbuildFile(srcPath Path) {
+ m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
+}
+
+func (m *moduleContext) blueprintModuleContext() blueprint.ModuleContext {
+ return m.bp
+}
+
+func (m *moduleContext) LicenseMetadataFile() Path {
+ return m.module.base().licenseMetadataFile
+}
+
+// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
+// be tagged with `android:"path" to support automatic source module dependency resolution.
+//
+// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
+func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
+ return PathsForModuleSrcExcludes(m, srcFiles, excludes)
+}
+
+// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
+// be tagged with `android:"path" to support automatic source module dependency resolution.
+//
+// Deprecated: use PathForModuleSrc instead.
+func (m *moduleContext) ExpandSource(srcFile, _ string) Path {
+ return PathForModuleSrc(m, srcFile)
+}
+
+// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
+// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
+// dependency resolution.
+func (m *moduleContext) ExpandOptionalSource(srcFile *string, _ string) OptionalPath {
+ if srcFile != nil {
+ return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
+ }
+ return OptionalPath{}
+}
+
+func (m *moduleContext) RequiredModuleNames() []string {
+ return m.module.RequiredModuleNames()
+}
+
+func (m *moduleContext) HostRequiredModuleNames() []string {
+ return m.module.HostRequiredModuleNames()
+}
+
+func (m *moduleContext) TargetRequiredModuleNames() []string {
+ return m.module.TargetRequiredModuleNames()
+}
diff --git a/android/paths.go b/android/paths.go
index a6cda38..37504b6 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -2210,6 +2210,14 @@
RelativeInstallPath string
}
+func (d *DataPath) ToRelativeInstallPath() string {
+ relPath := d.SrcPath.Rel()
+ if d.RelativeInstallPath != "" {
+ relPath = filepath.Join(d.RelativeInstallPath, relPath)
+ }
+ return relPath
+}
+
// PathsIfNonNil returns a Paths containing only the non-nil input arguments.
func PathsIfNonNil(paths ...Path) Paths {
if len(paths) == 0 {
diff --git a/android/plugin.go b/android/plugin.go
index 2c7f9ff..d62fc94 100644
--- a/android/plugin.go
+++ b/android/plugin.go
@@ -72,7 +72,6 @@
var internalPluginsPaths = []string{
"vendor/google/build/soong/internal_plugins.json",
- "vendor/google_clockwork/build/internal_plugins.json",
}
type pluginProvider interface {
diff --git a/android/testing.go b/android/testing.go
index da3b75a..c596468 100644
--- a/android/testing.go
+++ b/android/testing.go
@@ -1293,3 +1293,10 @@
func StringsRelativeToTop(config Config, command []string) []string {
return normalizeStringArrayRelativeToTop(config, command)
}
+
+func EnsureListContainsSuffix(t *testing.T, result []string, expected string) {
+ t.Helper()
+ if !SuffixInList(result, expected) {
+ t.Errorf("%q is not found in %v", expected, result)
+ }
+}
diff --git a/android/variable.go b/android/variable.go
index 648e4cf..307deaf 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -494,6 +494,8 @@
Release_expose_flagged_api *bool `json:",omitempty"`
BuildFlags map[string]string `json:",omitempty"`
+
+ BuildFromSourceStub *bool `json:",omitempty"`
}
type PartitionQualifiedVariablesType struct {
@@ -536,18 +538,17 @@
TargetUserimagesSparseSquashfsDisabled bool `json:",omitempty"`
TargetUserimagesSparseF2fsDisabled bool `json:",omitempty"`
- BoardErofsCompressor string `json:",omitempty"`
- BoardErofsCompressorHints string `json:",omitempty"`
- BoardErofsPclusterSize string `json:",omitempty"`
- BoardErofsShareDupBlocks string `json:",omitempty"`
- BoardErofsUseLegacyCompression string `json:",omitempty"`
- BoardExt4ShareDupBlocks string `json:",omitempty"`
- BoardFlashLogicalBlockSize string `json:",omitempty"`
- BoardFlashEraseBlockSize string `json:",omitempty"`
- BoardUsesRecoveryAsBoot bool `json:",omitempty"`
- BoardBuildGkiBootImageWithoutRamdisk bool `json:",omitempty"`
- ProductUseDynamicPartitionSize bool `json:",omitempty"`
- CopyImagesForTargetFilesZip bool `json:",omitempty"`
+ BoardErofsCompressor string `json:",omitempty"`
+ BoardErofsCompressorHints string `json:",omitempty"`
+ BoardErofsPclusterSize string `json:",omitempty"`
+ BoardErofsShareDupBlocks string `json:",omitempty"`
+ BoardErofsUseLegacyCompression string `json:",omitempty"`
+ BoardExt4ShareDupBlocks string `json:",omitempty"`
+ BoardFlashLogicalBlockSize string `json:",omitempty"`
+ BoardFlashEraseBlockSize string `json:",omitempty"`
+ BoardUsesRecoveryAsBoot bool `json:",omitempty"`
+ ProductUseDynamicPartitionSize bool `json:",omitempty"`
+ CopyImagesForTargetFilesZip bool `json:",omitempty"`
BoardAvbEnable bool `json:",omitempty"`
diff --git a/androidmk/androidmk/android.go b/androidmk/androidmk/android.go
index 954f8d0..276b9ab 100644
--- a/androidmk/androidmk/android.go
+++ b/androidmk/androidmk/android.go
@@ -106,6 +106,7 @@
"LOCAL_ARM_MODE_HACK": "instruction_set",
"LOCAL_SDK_VERSION": "sdk_version",
"LOCAL_MIN_SDK_VERSION": "min_sdk_version",
+ "LOCAL_TARGET_SDK_VERSION": "target_sdk_version",
"LOCAL_NDK_STL_VARIANT": "stl",
"LOCAL_JAR_MANIFEST": "manifest",
"LOCAL_CERTIFICATE": "certificate",
diff --git a/androidmk/androidmk/androidmk_test.go b/androidmk/androidmk/androidmk_test.go
index afde68b..0580ae5 100644
--- a/androidmk/androidmk/androidmk_test.go
+++ b/androidmk/androidmk/androidmk_test.go
@@ -1450,6 +1450,7 @@
LOCAL_PRODUCT_MODULE := true
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_SDK_VERSION := current
+LOCAL_TARGET_SDK_VERSION := target_version
LOCAL_RRO_THEME := FooTheme
include $(BUILD_RRO_PACKAGE)
@@ -1460,6 +1461,7 @@
product_specific: true,
sdk_version: "current",
+ target_sdk_version: "target_version",
theme: "FooTheme",
}
diff --git a/apex/Android.bp b/apex/Android.bp
index 0791497..0a5063f 100644
--- a/apex/Android.bp
+++ b/apex/Android.bp
@@ -8,6 +8,8 @@
deps: [
"blueprint",
"soong",
+ "soong-aconfig",
+ "soong-aconfig-codegen",
"soong-android",
"soong-bazel",
"soong-bpf",
diff --git a/apex/androidmk.go b/apex/androidmk.go
index 6136cbd..4e968ea 100644
--- a/apex/androidmk.go
+++ b/apex/androidmk.go
@@ -245,7 +245,6 @@
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS) # apex.apexBundle")
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
fmt.Fprintln(w, "LOCAL_MODULE :=", name)
- data.Entries.WriteLicenseVariables(w)
fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFile.String())
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.String())
diff --git a/apex/apex.go b/apex/apex.go
index f2e8a06..56f3367 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -24,6 +24,7 @@
"sort"
"strings"
+ "android/soong/aconfig"
"android/soong/bazel/cquery"
"github.com/google/blueprint"
@@ -483,8 +484,7 @@
nativeApisBackedByModuleFile android.ModuleOutPath
javaApisUsedByModuleFile android.ModuleOutPath
- // Collect the module directory for IDE info in java/jdeps.go.
- modulePaths []string
+ aconfigFiles []android.Path
}
// apexFileClass represents a type of file that can be included in APEX.
@@ -1893,7 +1893,7 @@
installSuffix = imageCapexSuffix
}
a.installedFile = ctx.InstallFile(a.installDir, a.Name()+installSuffix, a.outputFile,
- a.compatSymlinks.Paths()...)
+ a.compatSymlinks...)
// filesInfo in mixed mode must retrieve all information about the apex's
// contents completely from the Starlark providers. It should never rely on
@@ -2011,6 +2011,8 @@
// visitor skips these from this list of module names
unwantedTransitiveDeps []string
+
+ aconfigFiles []android.Path
}
func (vctx *visitorContext) normalizeFileInfo(mctx android.ModuleContext) {
@@ -2070,6 +2072,7 @@
fi := apexFileForNativeLibrary(ctx, ch, vctx.handleSpecialLibs)
fi.isJniLib = isJniLib
vctx.filesInfo = append(vctx.filesInfo, fi)
+ addAconfigFiles(vctx, ctx, child)
// Collect the list of stub-providing libs except:
// - VNDK libs are only for vendors
// - bootstrap bionic libs are treated as provided by system
@@ -2093,6 +2096,7 @@
switch ch := child.(type) {
case *cc.Module:
vctx.filesInfo = append(vctx.filesInfo, apexFileForExecutable(ctx, ch))
+ addAconfigFiles(vctx, ctx, child)
return true // track transitive dependencies
case *rust.Module:
vctx.filesInfo = append(vctx.filesInfo, apexFileForRustExecutable(ctx, ch))
@@ -2135,6 +2139,7 @@
return false
}
vctx.filesInfo = append(vctx.filesInfo, af)
+ addAconfigFiles(vctx, ctx, child)
return true // track transitive dependencies
default:
ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
@@ -2143,6 +2148,7 @@
switch ap := child.(type) {
case *java.AndroidApp:
vctx.filesInfo = append(vctx.filesInfo, apexFilesForAndroidApp(ctx, ap)...)
+ addAconfigFiles(vctx, ctx, child)
return true // track transitive dependencies
case *java.AndroidAppImport:
vctx.filesInfo = append(vctx.filesInfo, apexFilesForAndroidApp(ctx, ap)...)
@@ -2301,6 +2307,7 @@
}
vctx.filesInfo = append(vctx.filesInfo, af)
+ addAconfigFiles(vctx, ctx, child)
return true // track transitive dependencies
} else if rm, ok := child.(*rust.Module); ok {
af := apexFileForRustLibrary(ctx, rm)
@@ -2381,6 +2388,13 @@
return false
}
+func addAconfigFiles(vctx *visitorContext, ctx android.ModuleContext, module blueprint.Module) {
+ dep := ctx.OtherModuleProvider(module, aconfig.TransitiveDeclarationsInfoProvider).(aconfig.TransitiveDeclarationsInfo)
+ if len(dep.AconfigFiles) > 0 && dep.AconfigFiles[ctx.ModuleName()] != nil {
+ vctx.aconfigFiles = append(vctx.aconfigFiles, dep.AconfigFiles[ctx.ModuleName()].ToList()...)
+ }
+}
+
func (a *apexBundle) shouldCheckDuplicate(ctx android.ModuleContext) bool {
// TODO(b/263308293) remove this
if a.properties.IsCoverageVariant {
@@ -2406,8 +2420,6 @@
}
////////////////////////////////////////////////////////////////////////////////////////////
// 2) traverse the dependency tree to collect apexFile structs from them.
- // Collect the module directory for IDE info in java/jdeps.go.
- a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
// TODO(jiyong): do this using WalkPayloadDeps
// TODO(jiyong): make this clean!!!
@@ -2464,6 +2476,7 @@
// 3) some fields in apexBundle struct are configured
a.installDir = android.PathForModuleInstall(ctx, "apex")
a.filesInfo = vctx.filesInfo
+ a.aconfigFiles = android.FirstUniquePaths(vctx.aconfigFiles)
a.setPayloadFsType(ctx)
a.setSystemLibLink(ctx)
@@ -2972,7 +2985,6 @@
dpInfo.Deps = append(dpInfo.Deps, a.properties.Java_libs...)
dpInfo.Deps = append(dpInfo.Deps, a.properties.Bootclasspath_fragments...)
dpInfo.Deps = append(dpInfo.Deps, a.properties.Systemserverclasspath_fragments...)
- dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
}
var (
@@ -3037,59 +3049,6 @@
//
// Module separator
//
- m["com.android.appsearch"] = []string{
- "icing-java-proto-lite",
- }
- //
- // Module separator
- //
- m["com.android.btservices"] = []string{
- // empty
- }
- //
- // Module separator
- //
- m["com.android.cellbroadcast"] = []string{}
- //
- // Module separator
- //
- m["com.android.extservices"] = []string{
- "ExtServices-core",
- "libtextclassifier-java",
- "textclassifier-statsd",
- "TextClassifierNotificationLibNoManifest",
- "TextClassifierServiceLibNoManifest",
- }
- //
- // Module separator
- //
- m["com.android.neuralnetworks"] = []string{
- "android.hardware.neuralnetworks@1.0",
- "android.hardware.neuralnetworks@1.1",
- "android.hardware.neuralnetworks@1.2",
- "android.hardware.neuralnetworks@1.3",
- "android.hidl.allocator@1.0",
- "android.hidl.memory.token@1.0",
- "android.hidl.memory@1.0",
- "android.hidl.safe_union@1.0",
- "libarect",
- "libprocpartition",
- }
- //
- // Module separator
- //
- m["com.android.media"] = []string{
- // empty
- }
- //
- // Module separator
- //
- m["com.android.media.swcodec"] = []string{
- // empty
- }
- //
- // Module separator
- //
m["com.android.mediaprovider"] = []string{
"MediaProvider",
"MediaProviderGoogle",
diff --git a/apex/apex_test.go b/apex/apex_test.go
index ddb9a40..af643a0 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -25,6 +25,7 @@
"strings"
"testing"
+ "android/soong/aconfig/codegen"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -151,6 +152,7 @@
prebuilt_etc.PrepareForTestWithPrebuiltEtc,
rust.PrepareForTestWithRustDefaultModules,
sh.PrepareForTestWithShBuildComponents,
+ codegen.PrepareForTestWithAconfigBuildComponents,
PrepareForTestWithApexBuildComponents,
@@ -10756,3 +10758,437 @@
inputs.Strings(),
"out/soong/.intermediates/libbar/android_arm64_armv8-a_shared/libbar.so")
}
+
+var apex_default_bp = `
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+
+ filegroup {
+ name: "myapex.manifest",
+ srcs: ["apex_manifest.json"],
+ }
+
+ filegroup {
+ name: "myapex.androidmanifest",
+ srcs: ["AndroidManifest.xml"],
+ }
+`
+
+func TestAconfigFilesJavaDeps(t *testing.T) {
+ ctx := testApex(t, apex_default_bp+`
+ apex {
+ name: "myapex",
+ manifest: ":myapex.manifest",
+ androidManifest: ":myapex.androidmanifest",
+ key: "myapex.key",
+ java_libs: [
+ "my_java_library_foo",
+ "my_java_library_bar",
+ ],
+ updatable: false,
+ }
+
+ java_library {
+ name: "my_java_library_foo",
+ srcs: ["foo/bar/MyClass.java"],
+ sdk_version: "none",
+ system_modules: "none",
+ static_libs: ["my_java_aconfig_library_foo"],
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+
+ java_library {
+ name: "my_java_library_bar",
+ srcs: ["foo/bar/MyClass.java"],
+ sdk_version: "none",
+ system_modules: "none",
+ static_libs: ["my_java_aconfig_library_bar"],
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+
+ aconfig_declarations {
+ name: "my_aconfig_declarations_foo",
+ package: "com.example.package",
+ container: "myapex",
+ srcs: ["foo.aconfig"],
+ }
+
+ java_aconfig_library {
+ name: "my_java_aconfig_library_foo",
+ aconfig_declarations: "my_aconfig_declarations_foo",
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+
+ aconfig_declarations {
+ name: "my_aconfig_declarations_bar",
+ package: "com.example.package",
+ container: "myapex",
+ srcs: ["bar.aconfig"],
+ }
+
+ java_aconfig_library {
+ name: "my_java_aconfig_library_bar",
+ aconfig_declarations: "my_aconfig_declarations_bar",
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+ `)
+
+ mod := ctx.ModuleForTests("myapex", "android_common_myapex")
+ s := mod.Rule("apexRule").Args["copy_commands"]
+ copyCmds := regexp.MustCompile(" *&& *").Split(s, -1)
+ if len(copyCmds) != 5 {
+ t.Fatalf("Expected 5 commands, got %d in:\n%s", len(copyCmds), s)
+ }
+
+ ensureMatches(t, copyCmds[4], "^cp -f .*/aconfig_flags.pb .*/image.apex$")
+
+ combineAconfigRule := mod.Rule("All_aconfig_declarations_dump")
+ s = " " + combineAconfigRule.Args["cache_files"]
+ aconfigArgs := regexp.MustCompile(" --cache ").Split(s, -1)[1:]
+ if len(aconfigArgs) != 2 {
+ t.Fatalf("Expected 2 commands, got %d in:\n%s", len(aconfigArgs), s)
+ }
+ android.EnsureListContainsSuffix(t, aconfigArgs, "my_aconfig_declarations_foo/intermediate.pb")
+ android.EnsureListContainsSuffix(t, aconfigArgs, "my_aconfig_declarations_bar/intermediate.pb")
+
+ buildParams := combineAconfigRule.BuildParams
+ android.EnsureListContainsSuffix(t, buildParams.Inputs.Strings(), "my_aconfig_declarations_foo/intermediate.pb")
+ android.EnsureListContainsSuffix(t, buildParams.Inputs.Strings(), "my_aconfig_declarations_bar/intermediate.pb")
+ ensureContains(t, buildParams.Output.String(), "android_common_myapex/aconfig_flags.pb")
+}
+
+func TestAconfigFilesJavaAndCcDeps(t *testing.T) {
+ ctx := testApex(t, apex_default_bp+`
+ apex {
+ name: "myapex",
+ manifest: ":myapex.manifest",
+ androidManifest: ":myapex.androidmanifest",
+ key: "myapex.key",
+ java_libs: [
+ "my_java_library_foo",
+ ],
+ native_shared_libs: [
+ "my_cc_library_bar",
+ ],
+ binaries: [
+ "my_cc_binary_baz",
+ ],
+ updatable: false,
+ }
+
+ java_library {
+ name: "my_java_library_foo",
+ srcs: ["foo/bar/MyClass.java"],
+ sdk_version: "none",
+ system_modules: "none",
+ static_libs: ["my_java_aconfig_library_foo"],
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+
+ cc_library {
+ name: "my_cc_library_bar",
+ srcs: ["foo/bar/MyClass.cc"],
+ static_libs: ["my_cc_aconfig_library_bar"],
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+
+ cc_binary {
+ name: "my_cc_binary_baz",
+ srcs: ["foo/bar/MyClass.cc"],
+ static_libs: ["my_cc_aconfig_library_baz"],
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+
+ aconfig_declarations {
+ name: "my_aconfig_declarations_foo",
+ package: "com.example.package",
+ container: "myapex",
+ srcs: ["foo.aconfig"],
+ }
+
+ java_aconfig_library {
+ name: "my_java_aconfig_library_foo",
+ aconfig_declarations: "my_aconfig_declarations_foo",
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+
+ aconfig_declarations {
+ name: "my_aconfig_declarations_bar",
+ package: "com.example.package",
+ container: "myapex",
+ srcs: ["bar.aconfig"],
+ }
+
+ cc_aconfig_library {
+ name: "my_cc_aconfig_library_bar",
+ aconfig_declarations: "my_aconfig_declarations_bar",
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+
+ aconfig_declarations {
+ name: "my_aconfig_declarations_baz",
+ package: "com.example.package",
+ container: "myapex",
+ srcs: ["baz.aconfig"],
+ }
+
+ cc_aconfig_library {
+ name: "my_cc_aconfig_library_baz",
+ aconfig_declarations: "my_aconfig_declarations_baz",
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+
+ cc_library {
+ name: "server_configurable_flags",
+ srcs: ["server_configurable_flags.cc"],
+ }
+ `)
+
+ mod := ctx.ModuleForTests("myapex", "android_common_myapex")
+ s := mod.Rule("apexRule").Args["copy_commands"]
+ copyCmds := regexp.MustCompile(" *&& *").Split(s, -1)
+ if len(copyCmds) != 9 {
+ t.Fatalf("Expected 9 commands, got %d in:\n%s", len(copyCmds), s)
+ }
+
+ ensureMatches(t, copyCmds[8], "^cp -f .*/aconfig_flags.pb .*/image.apex$")
+
+ combineAconfigRule := mod.Rule("All_aconfig_declarations_dump")
+ s = " " + combineAconfigRule.Args["cache_files"]
+ aconfigArgs := regexp.MustCompile(" --cache ").Split(s, -1)[1:]
+ if len(aconfigArgs) != 3 {
+ t.Fatalf("Expected 3 commands, got %d in:\n%s", len(aconfigArgs), s)
+ }
+ android.EnsureListContainsSuffix(t, aconfigArgs, "my_aconfig_declarations_foo/intermediate.pb")
+ android.EnsureListContainsSuffix(t, aconfigArgs, "my_aconfig_declarations_bar/intermediate.pb")
+ android.EnsureListContainsSuffix(t, aconfigArgs, "my_aconfig_declarations_baz/intermediate.pb")
+
+ buildParams := combineAconfigRule.BuildParams
+ if len(buildParams.Inputs) != 3 {
+ t.Fatalf("Expected 3 input, got %d", len(buildParams.Inputs))
+ }
+ android.EnsureListContainsSuffix(t, buildParams.Inputs.Strings(), "my_aconfig_declarations_foo/intermediate.pb")
+ android.EnsureListContainsSuffix(t, buildParams.Inputs.Strings(), "my_aconfig_declarations_bar/intermediate.pb")
+ android.EnsureListContainsSuffix(t, buildParams.Inputs.Strings(), "my_aconfig_declarations_baz/intermediate.pb")
+ ensureContains(t, buildParams.Output.String(), "android_common_myapex/aconfig_flags.pb")
+}
+
+func TestAconfigFilesOnlyMatchCurrentApex(t *testing.T) {
+ ctx := testApex(t, apex_default_bp+`
+ apex {
+ name: "myapex",
+ manifest: ":myapex.manifest",
+ androidManifest: ":myapex.androidmanifest",
+ key: "myapex.key",
+ java_libs: [
+ "my_java_library_foo",
+ "other_java_library_bar",
+ ],
+ updatable: false,
+ }
+
+ java_library {
+ name: "my_java_library_foo",
+ srcs: ["foo/bar/MyClass.java"],
+ sdk_version: "none",
+ system_modules: "none",
+ static_libs: ["my_java_aconfig_library_foo"],
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+
+ java_library {
+ name: "other_java_library_bar",
+ srcs: ["foo/bar/MyClass.java"],
+ sdk_version: "none",
+ system_modules: "none",
+ static_libs: ["other_java_aconfig_library_bar"],
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+
+ aconfig_declarations {
+ name: "my_aconfig_declarations_foo",
+ package: "com.example.package",
+ container: "myapex",
+ srcs: ["foo.aconfig"],
+ }
+
+ java_aconfig_library {
+ name: "my_java_aconfig_library_foo",
+ aconfig_declarations: "my_aconfig_declarations_foo",
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+
+ aconfig_declarations {
+ name: "other_aconfig_declarations_bar",
+ package: "com.example.package",
+ container: "otherapex",
+ srcs: ["bar.aconfig"],
+ }
+
+ java_aconfig_library {
+ name: "other_java_aconfig_library_bar",
+ aconfig_declarations: "other_aconfig_declarations_bar",
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+ `)
+
+ mod := ctx.ModuleForTests("myapex", "android_common_myapex")
+ combineAconfigRule := mod.Rule("All_aconfig_declarations_dump")
+ s := " " + combineAconfigRule.Args["cache_files"]
+ aconfigArgs := regexp.MustCompile(" --cache ").Split(s, -1)[1:]
+ if len(aconfigArgs) != 1 {
+ t.Fatalf("Expected 1 commands, got %d in:\n%s", len(aconfigArgs), s)
+ }
+ android.EnsureListContainsSuffix(t, aconfigArgs, "my_aconfig_declarations_foo/intermediate.pb")
+
+ buildParams := combineAconfigRule.BuildParams
+ if len(buildParams.Inputs) != 1 {
+ t.Fatalf("Expected 1 input, got %d", len(buildParams.Inputs))
+ }
+ android.EnsureListContainsSuffix(t, buildParams.Inputs.Strings(), "my_aconfig_declarations_foo/intermediate.pb")
+ ensureContains(t, buildParams.Output.String(), "android_common_myapex/aconfig_flags.pb")
+}
+
+func TestAconfigFilesRemoveDuplicates(t *testing.T) {
+ ctx := testApex(t, apex_default_bp+`
+ apex {
+ name: "myapex",
+ manifest: ":myapex.manifest",
+ androidManifest: ":myapex.androidmanifest",
+ key: "myapex.key",
+ java_libs: [
+ "my_java_library_foo",
+ "my_java_library_bar",
+ ],
+ updatable: false,
+ }
+
+ java_library {
+ name: "my_java_library_foo",
+ srcs: ["foo/bar/MyClass.java"],
+ sdk_version: "none",
+ system_modules: "none",
+ static_libs: ["my_java_aconfig_library_foo"],
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+
+ java_library {
+ name: "my_java_library_bar",
+ srcs: ["foo/bar/MyClass.java"],
+ sdk_version: "none",
+ system_modules: "none",
+ static_libs: ["my_java_aconfig_library_bar"],
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+
+ aconfig_declarations {
+ name: "my_aconfig_declarations_foo",
+ package: "com.example.package",
+ container: "myapex",
+ srcs: ["foo.aconfig"],
+ }
+
+ java_aconfig_library {
+ name: "my_java_aconfig_library_foo",
+ aconfig_declarations: "my_aconfig_declarations_foo",
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+
+ java_aconfig_library {
+ name: "my_java_aconfig_library_bar",
+ aconfig_declarations: "my_aconfig_declarations_foo",
+ // TODO: remove //apex_available:platform
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+ `)
+
+ mod := ctx.ModuleForTests("myapex", "android_common_myapex")
+ combineAconfigRule := mod.Rule("All_aconfig_declarations_dump")
+ s := " " + combineAconfigRule.Args["cache_files"]
+ aconfigArgs := regexp.MustCompile(" --cache ").Split(s, -1)[1:]
+ if len(aconfigArgs) != 1 {
+ t.Fatalf("Expected 1 commands, got %d in:\n%s", len(aconfigArgs), s)
+ }
+ android.EnsureListContainsSuffix(t, aconfigArgs, "my_aconfig_declarations_foo/intermediate.pb")
+
+ buildParams := combineAconfigRule.BuildParams
+ if len(buildParams.Inputs) != 1 {
+ t.Fatalf("Expected 1 input, got %d", len(buildParams.Inputs))
+ }
+ android.EnsureListContainsSuffix(t, buildParams.Inputs.Strings(), "my_aconfig_declarations_foo/intermediate.pb")
+ ensureContains(t, buildParams.Output.String(), "android_common_myapex/aconfig_flags.pb")
+}
diff --git a/apex/builder.go b/apex/builder.go
index afbfa1c..3078863 100644
--- a/apex/builder.go
+++ b/apex/builder.go
@@ -24,6 +24,7 @@
"strconv"
"strings"
+ "android/soong/aconfig"
"android/soong/android"
"android/soong/java"
@@ -36,6 +37,7 @@
)
func init() {
+ pctx.Import("android/soong/aconfig")
pctx.Import("android/soong/android")
pctx.Import("android/soong/cc/config")
pctx.Import("android/soong/java")
@@ -80,6 +82,7 @@
pctx.HostBinToolVariable("conv_linker_config", "conv_linker_config")
pctx.HostBinToolVariable("assemble_vintf", "assemble_vintf")
pctx.HostBinToolVariable("apex_elf_checker", "apex_elf_checker")
+ pctx.HostBinToolVariable("aconfig", "aconfig")
}
var (
@@ -344,10 +347,12 @@
func (a *apexBundle) buildFileContexts(ctx android.ModuleContext) android.OutputPath {
var fileContexts android.Path
var fileContextsDir string
+ isFileContextsModule := false
if a.properties.File_contexts == nil {
fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
} else {
if m, t := android.SrcIsModuleWithTag(*a.properties.File_contexts); m != "" {
+ isFileContextsModule = true
otherModule := android.GetModuleFromPathDep(ctx, m, t)
fileContextsDir = ctx.OtherModuleDir(otherModule)
}
@@ -363,7 +368,7 @@
ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but found in %q", fileContextsDir)
}
}
- if !android.ExistentPathForSource(ctx, fileContexts.String()).Valid() {
+ if !isFileContextsModule && !android.ExistentPathForSource(ctx, fileContexts.String()).Valid() {
ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", fileContexts.String())
}
@@ -372,12 +377,12 @@
output := android.PathForModuleOut(ctx, "file_contexts")
rule := android.NewRuleBuilder(pctx, ctx)
- forceLabel := "u:object_r:system_file:s0"
+ labelForRoot := "u:object_r:system_file:s0"
+ labelForManifest := "u:object_r:system_file:s0"
if a.SocSpecific() && !a.vndkApex {
- // APEX on /vendor should label ./ and ./apex_manifest.pb as vendor_apex_metadata_file.
- // The reason why we skip VNDK APEX is that aosp_{pixel device} targets install VNDK APEX on /vendor
- // even though VNDK APEX is supposed to be installed on /system. (See com.android.vndk.current.on_vendor)
- forceLabel = "u:object_r:vendor_apex_metadata_file:s0"
+ // APEX on /vendor should label ./ and ./apex_manifest.pb as vendor file.
+ labelForRoot = "u:object_r:vendor_file:s0"
+ labelForManifest = "u:object_r:vendor_apex_metadata_file:s0"
}
// remove old file
rule.Command().Text("rm").FlagWithOutput("-f ", output)
@@ -387,8 +392,8 @@
rule.Command().Text("echo").Text(">>").Output(output)
if !useFileContextsAsIs {
// force-label /apex_manifest.pb and /
- rule.Command().Text("echo").Text("/apex_manifest\\\\.pb").Text(forceLabel).Text(">>").Output(output)
- rule.Command().Text("echo").Text("/").Text(forceLabel).Text(">>").Output(output)
+ rule.Command().Text("echo").Text("/apex_manifest\\\\.pb").Text(labelForManifest).Text(">>").Output(output)
+ rule.Command().Text("echo").Text("/").Text(labelForRoot).Text(">>").Output(output)
}
rule.Build("file_contexts."+a.Name(), "Generate file_contexts")
@@ -563,13 +568,8 @@
// Copy the test files (if any)
for _, d := range fi.dataPaths {
// TODO(eakammer): This is now the third repetition of ~this logic for test paths, refactoring should be possible
- relPath := d.SrcPath.Rel()
- dataPath := d.SrcPath.String()
- if !strings.HasSuffix(dataPath, relPath) {
- panic(fmt.Errorf("path %q does not end with %q", dataPath, relPath))
- }
-
- dataDest := imageDir.Join(ctx, fi.apexRelativePath(relPath), d.RelativeInstallPath).String()
+ relPath := d.ToRelativeInstallPath()
+ dataDest := imageDir.Join(ctx, fi.apexRelativePath(relPath)).String()
copyCommands = append(copyCommands, "cp -f "+d.SrcPath.String()+" "+dataDest)
implicitInputs = append(implicitInputs, d.SrcPath)
@@ -577,6 +577,7 @@
installMapSet[installMapPath.String()+":"+fi.installDir+"/"+fi.builtFile.Base()] = true
}
+
implicitInputs = append(implicitInputs, a.manifestPbOut)
if len(installMapSet) > 0 {
@@ -631,10 +632,28 @@
outHostBinDir := ctx.Config().HostToolPath(ctx, "").String()
prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
+ defaultReadOnlyFiles := []string{"apex_manifest.json", "apex_manifest.pb"}
+ if len(a.aconfigFiles) > 0 {
+ apexAconfigFile := android.PathForModuleOut(ctx, "aconfig_flags.pb")
+ ctx.Build(pctx, android.BuildParams{
+ Rule: aconfig.AllDeclarationsRule,
+ Inputs: a.aconfigFiles,
+ Output: apexAconfigFile,
+ Description: "combine_aconfig_declarations",
+ Args: map[string]string{
+ "cache_files": android.JoinPathsWithPrefix(a.aconfigFiles, "--cache "),
+ },
+ })
+
+ copyCommands = append(copyCommands, "cp -f "+apexAconfigFile.String()+" "+imageDir.String())
+ implicitInputs = append(implicitInputs, apexAconfigFile)
+ defaultReadOnlyFiles = append(defaultReadOnlyFiles, apexAconfigFile.Base())
+ }
+
////////////////////////////////////////////////////////////////////////////////////
// Step 2: create canned_fs_config which encodes filemode,uid,gid of each files
// in this APEX. The file will be used by apexer in later steps.
- cannedFsConfig := a.buildCannedFsConfig(ctx)
+ cannedFsConfig := a.buildCannedFsConfig(ctx, defaultReadOnlyFiles)
implicitInputs = append(implicitInputs, cannedFsConfig)
////////////////////////////////////////////////////////////////////////////////////
@@ -956,7 +975,7 @@
// Install to $OUT/soong/{target,host}/.../apex.
a.installedFile = ctx.InstallFile(a.installDir, a.Name()+installSuffix, a.outputFile,
- a.compatSymlinks.Paths()...)
+ a.compatSymlinks...)
// installed-files.txt is dist'ed
a.installedFilesFile = a.buildInstalledFilesFile(ctx, a.outputFile, imageDir)
@@ -1085,8 +1104,8 @@
a.lintReports = java.BuildModuleLintReportZips(ctx, depSetsBuilder.Build())
}
-func (a *apexBundle) buildCannedFsConfig(ctx android.ModuleContext) android.OutputPath {
- var readOnlyPaths = []string{"apex_manifest.json", "apex_manifest.pb"}
+func (a *apexBundle) buildCannedFsConfig(ctx android.ModuleContext, defaultReadOnlyFiles []string) android.OutputPath {
+ var readOnlyPaths = defaultReadOnlyFiles
var executablePaths []string // this also includes dirs
var appSetDirs []string
appSetFiles := make(map[string]android.Path)
@@ -1095,7 +1114,8 @@
if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
executablePaths = append(executablePaths, pathInApex)
for _, d := range f.dataPaths {
- readOnlyPaths = append(readOnlyPaths, filepath.Join(f.installDir, d.RelativeInstallPath, d.SrcPath.Rel()))
+ rel := d.ToRelativeInstallPath()
+ readOnlyPaths = append(readOnlyPaths, filepath.Join(f.installDir, rel))
}
for _, s := range f.symlinks {
executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
diff --git a/apex/prebuilt.go b/apex/prebuilt.go
index 7a9d23e..7d339d5 100644
--- a/apex/prebuilt.go
+++ b/apex/prebuilt.go
@@ -794,7 +794,7 @@
}
if p.installable() {
- p.installedFile = ctx.InstallFile(p.installDir, p.installFilename, p.inputApex, p.compatSymlinks.Paths()...)
+ p.installedFile = ctx.InstallFile(p.installDir, p.installFilename, p.inputApex, p.compatSymlinks...)
p.provenanceMetaDataFile = provenance.GenerateArtifactProvenanceMetaData(ctx, p.inputApex, p.installedFile)
}
}
diff --git a/bp2build/Android.bp b/bp2build/Android.bp
index 14e32ed..64ee01f 100644
--- a/bp2build/Android.bp
+++ b/bp2build/Android.bp
@@ -6,6 +6,7 @@
name: "soong-bp2build",
pkgPath: "android/soong/bp2build",
srcs: [
+ "aconfig_conversion_test.go",
"androidbp_to_build_templates.go",
"bp2build.go",
"bp2build_product_config.go",
@@ -21,6 +22,7 @@
deps: [
"blueprint-bootstrap",
"soong-aidl-library",
+ "soong-aconfig",
"soong-android",
"soong-android-allowlists",
"soong-android-soongconfig",
diff --git a/bp2build/aconfig_conversion_test.go b/bp2build/aconfig_conversion_test.go
index ca41680..d6e20df 100644
--- a/bp2build/aconfig_conversion_test.go
+++ b/bp2build/aconfig_conversion_test.go
@@ -156,7 +156,7 @@
name: "foo",
aconfig_declarations: "foo_aconfig_declarations",
libs: ["foo_java_library"],
- test: true,
+ mode: "test",
}
`
expectedBazelTargets := []string{
@@ -184,7 +184,6 @@
AttrNameToString{
"aconfig_declarations": `":foo_aconfig_declarations"`,
"libs": `[":foo_java_library-neverlink"]`,
- "test": `True`,
"sdk_version": `"system_current"`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
},
@@ -213,7 +212,7 @@
java_aconfig_library {
name: "foo_aconfig_library",
aconfig_declarations: "foo_aconfig_declarations",
- test: true,
+ mode: "test",
}
`
expectedBazelTargets := []string{
@@ -230,7 +229,6 @@
"foo_aconfig_library",
AttrNameToString{
"aconfig_declarations": `":foo_aconfig_declarations"`,
- "test": `True`,
"sdk_version": `"system_current"`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
},
diff --git a/bp2build/bp2build_product_config.go b/bp2build/bp2build_product_config.go
index 7f26bef..0d1e433 100644
--- a/bp2build/bp2build_product_config.go
+++ b/bp2build/bp2build_product_config.go
@@ -793,9 +793,6 @@
if variables.BoardUsesRecoveryAsBoot {
ret["recovery_as_boot"] = "true"
}
- if variables.BoardBuildGkiBootImageWithoutRamdisk {
- ret["gki_boot_image_without_ramdisk"] = "true"
- }
if variables.ProductUseDynamicPartitionSize {
ret["use_dynamic_partition_size"] = "true"
}
diff --git a/bpf/bpf.go b/bpf/bpf.go
index ba825cf..58213aa 100644
--- a/bpf/bpf.go
+++ b/bpf/bpf.go
@@ -229,7 +229,6 @@
names = append(names, objName)
fmt.Fprintln(w, "include $(CLEAR_VARS)", " # bpf.bpf.obj")
fmt.Fprintln(w, "LOCAL_MODULE := ", objName)
- data.Entries.WriteLicenseVariables(w)
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", obj.String())
fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", obj.Base())
fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC")
@@ -239,7 +238,6 @@
}
fmt.Fprintln(w, "include $(CLEAR_VARS)", " # bpf.bpf")
fmt.Fprintln(w, "LOCAL_MODULE := ", name)
- data.Entries.WriteLicenseVariables(w)
android.AndroidMkEmitAssignList(w, "LOCAL_REQUIRED_MODULES", names)
fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
},
diff --git a/cc/Android.bp b/cc/Android.bp
index 8fa0fbe..351f3f6 100644
--- a/cc/Android.bp
+++ b/cc/Android.bp
@@ -9,6 +9,7 @@
"blueprint",
"blueprint-pathtools",
"soong",
+ "soong-aconfig",
"soong-aidl-library",
"soong-android",
"soong-bazel",
@@ -19,6 +20,7 @@
"soong-multitree",
"soong-snapshot",
"soong-sysprop-bp2build",
+ "soong-testing",
"soong-tradefed",
],
srcs: [
@@ -39,7 +41,6 @@
"lto.go",
"makevars.go",
"orderfile.go",
- "pgo.go",
"prebuilt.go",
"proto.go",
"rs.go",
diff --git a/cc/afdo.go b/cc/afdo.go
index ac210d4..91cf0b8 100644
--- a/cc/afdo.go
+++ b/cc/afdo.go
@@ -35,7 +35,7 @@
var afdoProfileProjectsConfigKey = android.NewOnceKey("AfdoProfileProjects")
// This flag needs to be in both CFlags and LdFlags to ensure correct symbol ordering
-const afdoFlagsFormat = "-fprofile-sample-use=%s"
+const afdoFlagsFormat = "-fprofile-sample-use=%s -fprofile-sample-accurate"
func recordMissingAfdoProfileFile(ctx android.BaseModuleContext, missing string) {
getNamedMapForConfig(ctx.Config(), modulesMissingProfileFileKey).Store(missing, true)
diff --git a/cc/builder.go b/cc/builder.go
index 3f582fa..69cf75b 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -681,16 +681,11 @@
tidyCmd := "${config.ClangBin}/clang-tidy"
rule := clangTidy
- reducedCFlags := moduleFlags
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_CLANG_TIDY") {
rule = clangTidyRE
- // b/248371171, work around RBE input processor problem
- // some cflags rejected by input processor, but usually
- // do not affect included files or clang-tidy
- reducedCFlags = config.TidyReduceCFlags(reducedCFlags)
}
- sharedCFlags := shareFlags("cFlags", reducedCFlags)
+ sharedCFlags := shareFlags("cFlags", moduleFlags)
srcRelPath := srcFile.Rel()
// Add the .tidy rule
diff --git a/cc/cc.go b/cc/cc.go
index 814a66c..867a59c 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -24,11 +24,13 @@
"strconv"
"strings"
+ "android/soong/testing"
"android/soong/ui/metrics/bp2build_metrics_proto"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
+ "android/soong/aconfig"
"android/soong/aidl_library"
"android/soong/android"
"android/soong/bazel/cquery"
@@ -140,6 +142,8 @@
// List of libs that need to be excluded for APEX variant
ExcludeLibsForApex []string
+ // List of libs that need to be excluded for non-APEX variant
+ ExcludeLibsForNonApex []string
}
// PathDeps is a struct containing file paths to dependencies of a module.
@@ -528,7 +532,6 @@
baseModuleName() string
getVndkExtendsModuleName() string
isAfdoCompile() bool
- isPgoCompile() bool
isOrderfileCompile() bool
isCfi() bool
isFuzzer() bool
@@ -727,6 +730,8 @@
// Whether or not this dependency has to be followed for the apex variants
excludeInApex bool
+ // Whether or not this dependency has to be followed for the non-apex variants
+ excludeInNonApex bool
// If true, don't automatically export symbols from the static library into a shared library.
unexportedSymbols bool
@@ -862,9 +867,10 @@
Properties BaseProperties
// initialize before calling Init
- hod android.HostOrDeviceSupported
- multilib android.Multilib
- bazelable bool
+ hod android.HostOrDeviceSupported
+ multilib android.Multilib
+ bazelable bool
+ testModule bool
// Allowable SdkMemberTypes of this module type.
sdkMemberTypes []android.SdkMemberType
@@ -889,7 +895,6 @@
vndkdep *vndkdep
lto *lto
afdo *afdo
- pgo *pgo
orderfile *orderfile
library libraryInterface
@@ -921,6 +926,9 @@
apexSdkVersion android.ApiLevel
hideApexVariantFromMake bool
+
+ // Aconfig files for all transitive deps. Also exposed via TransitiveDeclarationsInfo
+ transitiveAconfigFiles map[string]*android.DepSet[android.Path]
}
func (c *Module) AddJSONData(d *map[string]interface{}) {
@@ -1272,9 +1280,6 @@
if c.afdo != nil {
c.AddProperties(c.afdo.props()...)
}
- if c.pgo != nil {
- c.AddProperties(c.pgo.props()...)
- }
if c.orderfile != nil {
c.AddProperties(c.orderfile.props()...)
}
@@ -1404,13 +1409,6 @@
return false
}
-func (c *Module) isPgoCompile() bool {
- if pgo := c.pgo; pgo != nil {
- return pgo.Properties.PgoCompile
- }
- return false
-}
-
func (c *Module) isOrderfileCompile() bool {
if orderfile := c.orderfile; orderfile != nil {
return orderfile.Properties.OrderfileLoad
@@ -1719,10 +1717,6 @@
return ctx.mod.isAfdoCompile()
}
-func (ctx *moduleContextImpl) isPgoCompile() bool {
- return ctx.mod.isPgoCompile()
-}
-
func (ctx *moduleContextImpl) isOrderfileCompile() bool {
return ctx.mod.isOrderfileCompile()
}
@@ -1835,7 +1829,6 @@
module.vndkdep = &vndkdep{}
module.lto = <o{}
module.afdo = &afdo{}
- module.pgo = &pgo{}
module.orderfile = &orderfile{}
return module
}
@@ -2261,9 +2254,6 @@
if c.afdo != nil {
flags = c.afdo.flags(ctx, flags)
}
- if c.pgo != nil {
- flags = c.pgo.flags(ctx, flags)
- }
if c.orderfile != nil {
flags = c.orderfile.flags(ctx, flags)
}
@@ -2329,6 +2319,11 @@
}
}
}
+ if c.testModule {
+ ctx.SetProvider(testing.TestModuleProviderKey, testing.TestModuleProviderData{})
+ }
+
+ aconfig.CollectTransitiveAconfigFiles(ctx, &c.transitiveAconfigFiles)
c.maybeInstall(ctx, apexInfo)
}
@@ -2412,9 +2407,6 @@
if c.orderfile != nil {
c.orderfile.begin(ctx)
}
- if c.pgo != nil {
- c.pgo.begin(ctx)
- }
if ctx.useSdk() && c.IsSdkVariant() {
version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion())
if err != nil {
@@ -2814,6 +2806,9 @@
if inList(lib, deps.ExcludeLibsForApex) {
depTag.excludeInApex = true
}
+ if inList(lib, deps.ExcludeLibsForNonApex) {
+ depTag.excludeInNonApex = true
+ }
name, version := StubsLibNameAndVersion(lib)
if apiLibraryName, ok := apiImportInfo.SharedLibs[name]; ok && !ctx.OtherModuleExists(name) {
@@ -3330,6 +3325,9 @@
if !apexInfo.IsForPlatform() && libDepTag.excludeInApex {
return
}
+ if apexInfo.IsForPlatform() && libDepTag.excludeInNonApex {
+ return
+ }
depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
@@ -4318,7 +4316,6 @@
&VndkProperties{},
<OProperties{},
&AfdoProperties{},
- &PgoProperties{},
&OrderfileProperties{},
&android.ProtoProperties{},
// RustBindgenProperties is included here so that cc_defaults can be used for rust_bindgen modules.
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 14817a1..ed13e22 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -720,7 +720,7 @@
return
}
if len(testBinary.dataPaths()) != 1 {
- t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
+ t.Errorf("expected exactly one test data file. test data files: [%v]", testBinary.dataPaths())
return
}
@@ -777,7 +777,7 @@
t.Fatalf("expected exactly one output file. output files: [%s]", outputFiles)
}
if len(testBinary.dataPaths()) != 2 {
- t.Fatalf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
+ t.Fatalf("expected exactly one test data file. test data files: [%v]", testBinary.dataPaths())
}
outputPath := outputFiles[0].String()
@@ -3332,7 +3332,7 @@
t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
}
if len(testBinary.dataPaths()) != 1 {
- t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
+ t.Errorf("expected exactly one test data file. test data files: [%v]", testBinary.dataPaths())
}
outputPath := outputFiles[0].String()
diff --git a/cc/config/tidy.go b/cc/config/tidy.go
index efa4549..b40557a 100644
--- a/cc/config/tidy.go
+++ b/cc/config/tidy.go
@@ -16,7 +16,6 @@
import (
"android/soong/android"
- "regexp"
"strings"
)
@@ -281,11 +280,3 @@
}
return flags
}
-
-var (
- removedCFlags = regexp.MustCompile(" -fsanitize=[^ ]*memtag-[^ ]* ")
-)
-
-func TidyReduceCFlags(flags string) string {
- return removedCFlags.ReplaceAllString(flags, " ")
-}
diff --git a/cc/fuzz.go b/cc/fuzz.go
index df9f21a..8fc4898 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -96,6 +96,7 @@
// your device, or $ANDROID_PRODUCT_OUT/data/fuzz in your build tree.
func LibFuzzFactory() android.Module {
module := NewFuzzer(android.HostAndDeviceSupported)
+ module.testModule = true
return module.Init()
}
diff --git a/cc/linker.go b/cc/linker.go
index 257fe86..357d1ce 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -214,6 +214,11 @@
// variant of the C/C++ module.
Exclude_static_libs []string
}
+ Non_apex struct {
+ // list of shared libs that should not be used to build the non-apex
+ // variant of the C/C++ module.
+ Exclude_shared_libs []string
+ }
} `android:"arch_variant"`
// make android::build:GetBuildNumber() available containing the build ID.
@@ -300,6 +305,10 @@
// variants.
deps.ExcludeLibsForApex = append(deps.ExcludeLibsForApex, linker.Properties.Target.Apex.Exclude_shared_libs...)
deps.ExcludeLibsForApex = append(deps.ExcludeLibsForApex, linker.Properties.Target.Apex.Exclude_static_libs...)
+ // Record the libraries that need to be excluded when building for non-APEX variants
+ // for the same reason above. This is used for marking deps and marked deps are
+ // ignored for non-apex variants.
+ deps.ExcludeLibsForNonApex = append(deps.ExcludeLibsForNonApex, linker.Properties.Target.Non_apex.Exclude_shared_libs...)
if Bool(linker.Properties.Use_version_lib) {
deps.WholeStaticLibs = append(deps.WholeStaticLibs, "libbuildversion")
diff --git a/cc/lto.go b/cc/lto.go
index fb3b485..d2a43d2 100644
--- a/cc/lto.go
+++ b/cc/lto.go
@@ -140,17 +140,18 @@
// Reduce the inlining threshold for a better balance of binary size and
// performance.
if !ctx.Darwin() {
- if ctx.isPgoCompile() || ctx.isAfdoCompile() {
+ if ctx.isAfdoCompile() {
ltoLdFlags = append(ltoLdFlags, "-Wl,-plugin-opt,-import-instr-limit=40")
} else {
ltoLdFlags = append(ltoLdFlags, "-Wl,-plugin-opt,-import-instr-limit=5")
}
}
- // Register allocation MLGO flags for ARM64.
- if ctx.Arch().ArchType == android.Arm64 {
- ltoCFlags = append(ltoCFlags, "-mllvm -regalloc-enable-advisor=release")
- ltoLdFlags = append(ltoLdFlags, "-Wl,-mllvm,-regalloc-enable-advisor=release")
+ if !ctx.Config().IsEnvFalse("THINLTO_USE_MLGO") {
+ // Register allocation MLGO flags for ARM64.
+ if ctx.Arch().ArchType == android.Arm64 {
+ ltoLdFlags = append(ltoLdFlags, "-Wl,-mllvm,-regalloc-enable-advisor=release")
+ }
// Flags for training MLGO model.
if ctx.Config().IsEnvTrue("THINLTO_EMIT_INDEXES_AND_IMPORTS") {
ltoLdFlags = append(ltoLdFlags, "-Wl,--save-temps=import")
diff --git a/cc/pgo.go b/cc/pgo.go
deleted file mode 100644
index 463e2e6..0000000
--- a/cc/pgo.go
+++ /dev/null
@@ -1,294 +0,0 @@
-// Copyright 2017 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"
- "path/filepath"
- "strings"
-
- "github.com/google/blueprint/proptools"
-
- "android/soong/android"
-)
-
-var (
- // Add flags to ignore warnings that profiles are old or missing for
- // some functions.
- profileUseOtherFlags = []string{
- "-Wno-backend-plugin",
- }
-
- globalPgoProfileProjects = []string{
- "toolchain/pgo-profiles/pgo",
- "vendor/google_data/pgo_profile/pgo",
- }
-)
-
-var pgoProfileProjectsConfigKey = android.NewOnceKey("PgoProfileProjects")
-
-const profileInstrumentFlag = "-fprofile-generate=/data/local/tmp"
-const profileUseInstrumentFormat = "-fprofile-use=%s"
-
-func getPgoProfileProjects(config android.DeviceConfig) []string {
- return config.OnceStringSlice(pgoProfileProjectsConfigKey, func() []string {
- return append(globalPgoProfileProjects, config.PgoAdditionalProfileDirs()...)
- })
-}
-
-func recordMissingProfileFile(ctx BaseModuleContext, missing string) {
- getNamedMapForConfig(ctx.Config(), modulesMissingProfileFileKey).Store(missing, true)
-}
-
-type PgoProperties struct {
- Pgo struct {
- Instrumentation *bool
- Profile_file *string `android:"arch_variant"`
- Benchmarks []string
- Enable_profile_use *bool `android:"arch_variant"`
- // Additional compiler flags to use when building this module
- // for profiling.
- Cflags []string `android:"arch_variant"`
- } `android:"arch_variant"`
-
- PgoPresent bool `blueprint:"mutated"`
- ShouldProfileModule bool `blueprint:"mutated"`
- PgoCompile bool `blueprint:"mutated"`
- PgoInstrLink bool `blueprint:"mutated"`
-}
-
-type pgo struct {
- Properties PgoProperties
-}
-
-func (props *PgoProperties) isInstrumentation() bool {
- return props.Pgo.Instrumentation != nil && *props.Pgo.Instrumentation == true
-}
-
-func (pgo *pgo) props() []interface{} {
- return []interface{}{&pgo.Properties}
-}
-
-func (props *PgoProperties) addInstrumentationProfileGatherFlags(ctx ModuleContext, flags Flags) Flags {
- // Add to C flags iff PGO is explicitly enabled for this module.
- if props.ShouldProfileModule {
- flags.Local.CFlags = append(flags.Local.CFlags, props.Pgo.Cflags...)
- flags.Local.CFlags = append(flags.Local.CFlags, profileInstrumentFlag)
- }
- flags.Local.LdFlags = append(flags.Local.LdFlags, profileInstrumentFlag)
- return flags
-}
-
-func (props *PgoProperties) getPgoProfileFile(ctx BaseModuleContext) android.OptionalPath {
- profileFile := *props.Pgo.Profile_file
-
- // Test if the profile_file is present in any of the PGO profile projects
- for _, profileProject := range getPgoProfileProjects(ctx.DeviceConfig()) {
- // Bug: http://b/74395273 If the profile_file is unavailable,
- // use a versioned file named
- // <profile_file>.<arbitrary-version> when available. This
- // works around an issue where ccache serves stale cache
- // entries when the profile file has changed.
- globPattern := filepath.Join(profileProject, profileFile+".*")
- versionedProfiles, err := ctx.GlobWithDeps(globPattern, nil)
- if err != nil {
- ctx.ModuleErrorf("glob: %s", err.Error())
- }
-
- path := android.ExistentPathForSource(ctx, profileProject, profileFile)
- if path.Valid() {
- if len(versionedProfiles) != 0 {
- ctx.PropertyErrorf("pgo.profile_file", "Profile_file has multiple versions: "+filepath.Join(profileProject, profileFile)+", "+strings.Join(versionedProfiles, ", "))
- }
- return path
- }
-
- if len(versionedProfiles) > 1 {
- ctx.PropertyErrorf("pgo.profile_file", "Profile_file has multiple versions: "+strings.Join(versionedProfiles, ", "))
- } else if len(versionedProfiles) == 1 {
- return android.OptionalPathForPath(android.PathForSource(ctx, versionedProfiles[0]))
- }
- }
-
- // Record that this module's profile file is absent
- missing := *props.Pgo.Profile_file + ":" + ctx.ModuleDir() + "/Android.bp:" + ctx.ModuleName()
- recordMissingProfileFile(ctx, missing)
-
- return android.OptionalPathForPath(nil)
-}
-
-func (props *PgoProperties) profileUseFlags(ctx ModuleContext, file string) []string {
- flags := []string{fmt.Sprintf(profileUseInstrumentFormat, file)}
- flags = append(flags, profileUseOtherFlags...)
- return flags
-}
-
-func (props *PgoProperties) addProfileUseFlags(ctx ModuleContext, flags Flags) Flags {
- // Return if 'pgo' property is not present in this module.
- if !props.PgoPresent {
- return flags
- }
-
- if props.PgoCompile {
- profileFile := props.getPgoProfileFile(ctx)
- profileFilePath := profileFile.Path()
- profileUseFlags := props.profileUseFlags(ctx, profileFilePath.String())
-
- flags.Local.CFlags = append(flags.Local.CFlags, profileUseFlags...)
- flags.Local.LdFlags = append(flags.Local.LdFlags, profileUseFlags...)
-
- // 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
-}
-
-func (props *PgoProperties) isPGO(ctx BaseModuleContext) bool {
- isInstrumentation := props.isInstrumentation()
-
- profileKindPresent := isInstrumentation
- filePresent := props.Pgo.Profile_file != nil
- benchmarksPresent := len(props.Pgo.Benchmarks) > 0
-
- // If all three properties are absent, PGO is OFF for this module
- if !profileKindPresent && !filePresent && !benchmarksPresent {
- return false
- }
-
- // profileKindPresent and filePresent are mandatory properties.
- if !profileKindPresent || !filePresent {
- var missing []string
- if !profileKindPresent {
- missing = append(missing, "profile kind")
- }
- if !filePresent {
- missing = append(missing, "profile_file property")
- }
- missingProps := strings.Join(missing, ", ")
- ctx.ModuleErrorf("PGO specification is missing properties: " + missingProps)
- }
-
- // Benchmark property is mandatory for instrumentation PGO.
- if isInstrumentation && !benchmarksPresent {
- ctx.ModuleErrorf("Instrumentation PGO specification is missing benchmark property")
- }
-
- return true
-}
-
-func (pgo *pgo) begin(ctx BaseModuleContext) {
- // TODO Evaluate if we need to support PGO for host modules
- if ctx.Host() {
- return
- }
-
- // Check if PGO is needed for this module
- pgo.Properties.PgoPresent = pgo.Properties.isPGO(ctx)
-
- if !pgo.Properties.PgoPresent {
- return
- }
-
- // This module should be instrumented if ANDROID_PGO_INSTRUMENT is set
- // and includes 'all', 'ALL' or a benchmark listed for this module.
- //
- // TODO Validate that each benchmark instruments at least one module
- pgo.Properties.ShouldProfileModule = false
- pgoBenchmarks := ctx.Config().Getenv("ANDROID_PGO_INSTRUMENT")
- pgoBenchmarksMap := make(map[string]bool)
- for _, b := range strings.Split(pgoBenchmarks, ",") {
- pgoBenchmarksMap[b] = true
- }
-
- if pgoBenchmarksMap["all"] == true || pgoBenchmarksMap["ALL"] == true {
- pgo.Properties.ShouldProfileModule = true
- pgo.Properties.PgoInstrLink = pgo.Properties.isInstrumentation()
- } else {
- for _, b := range pgo.Properties.Pgo.Benchmarks {
- if pgoBenchmarksMap[b] == true {
- pgo.Properties.ShouldProfileModule = true
- pgo.Properties.PgoInstrLink = pgo.Properties.isInstrumentation()
- break
- }
- }
- }
-
- // PGO profile use is not feasible for a Clang coverage build because
- // -fprofile-use and -fprofile-instr-generate are incompatible.
- if ctx.DeviceConfig().ClangCoverageEnabled() {
- return
- }
-
- if !ctx.Config().IsEnvTrue("ANDROID_PGO_NO_PROFILE_USE") &&
- proptools.BoolDefault(pgo.Properties.Pgo.Enable_profile_use, true) {
- if profileFile := pgo.Properties.getPgoProfileFile(ctx); profileFile.Valid() {
- pgo.Properties.PgoCompile = true
- }
- }
-}
-
-func (pgo *pgo) flags(ctx ModuleContext, flags Flags) Flags {
- if ctx.Host() {
- return flags
- }
-
- // Deduce PgoInstrLink property i.e. whether this module needs to be
- // linked with profile-generation flags. Here, we're setting it if any
- // dependency needs PGO instrumentation. It is initially set in
- // begin() if PGO is directly enabled for this module.
- if ctx.static() && !ctx.staticBinary() {
- // For static libraries, check if any whole_static_libs are
- // linked with profile generation
- ctx.VisitDirectDeps(func(m android.Module) {
- if depTag, ok := ctx.OtherModuleDependencyTag(m).(libraryDependencyTag); ok {
- if depTag.static() && depTag.wholeStatic {
- if cc, ok := m.(*Module); ok {
- if cc.pgo.Properties.PgoInstrLink {
- pgo.Properties.PgoInstrLink = true
- }
- }
- }
- }
- })
- } else {
- // For executables and shared libraries, check all static dependencies.
- ctx.VisitDirectDeps(func(m android.Module) {
- if depTag, ok := ctx.OtherModuleDependencyTag(m).(libraryDependencyTag); ok {
- if depTag.static() {
- if cc, ok := m.(*Module); ok {
- if cc.pgo.Properties.PgoInstrLink {
- pgo.Properties.PgoInstrLink = true
- }
- }
- }
- }
- })
- }
-
- props := pgo.Properties
- // Add flags to profile this module based on its profile_kind
- if (props.ShouldProfileModule && props.isInstrumentation()) || props.PgoInstrLink {
- // Instrumentation PGO use and gather flags cannot coexist.
- return props.addInstrumentationProfileGatherFlags(ctx, flags)
- }
-
- if !ctx.Config().IsEnvTrue("ANDROID_PGO_NO_PROFILE_USE") {
- flags = props.addProfileUseFlags(ctx, flags)
- }
-
- return flags
-}
diff --git a/cc/test.go b/cc/test.go
index 5b778dc..a4224c3 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -158,6 +158,7 @@
// binary.
func BenchmarkFactory() android.Module {
module := NewBenchmark(android.HostAndDeviceSupported)
+ module.testModule = true
return module.Init()
}
@@ -489,6 +490,7 @@
module, binary := newBinary(hod, bazelable)
module.bazelable = bazelable
module.multilib = android.MultilibBoth
+ module.testModule = true
binary.baseInstaller = NewTestInstaller()
test := &testBinary{
diff --git a/dexpreopt/config.go b/dexpreopt/config.go
index c871e85..6163952 100644
--- a/dexpreopt/config.go
+++ b/dexpreopt/config.go
@@ -184,8 +184,6 @@
PreoptBootClassPathDexFiles android.Paths // file paths of boot class path files
PreoptBootClassPathDexLocations []string // virtual locations of boot class path files
- PreoptExtractedApk bool // Overrides OnlyPreoptModules
-
NoCreateAppImage bool
ForceCreateAppImage bool
diff --git a/dexpreopt/dexpreopt.go b/dexpreopt/dexpreopt.go
index c13e14a..94707ba 100644
--- a/dexpreopt/dexpreopt.go
+++ b/dexpreopt/dexpreopt.go
@@ -124,7 +124,7 @@
return true
}
- if global.OnlyPreoptArtBootImage && !module.PreoptExtractedApk {
+ if global.OnlyPreoptArtBootImage {
return true
}
diff --git a/dexpreopt/dexpreopt_test.go b/dexpreopt/dexpreopt_test.go
index 2b19c9d..230fbb4 100644
--- a/dexpreopt/dexpreopt_test.go
+++ b/dexpreopt/dexpreopt_test.go
@@ -87,7 +87,6 @@
DexPreoptImageLocationsOnHost: []string{},
PreoptBootClassPathDexFiles: nil,
PreoptBootClassPathDexLocations: nil,
- PreoptExtractedApk: false,
NoCreateAppImage: false,
ForceCreateAppImage: false,
PresignedPrebuilt: false,
diff --git a/filesystem/avb_add_hash_footer.go b/filesystem/avb_add_hash_footer.go
index dabbc46..ead579f 100644
--- a/filesystem/avb_add_hash_footer.go
+++ b/filesystem/avb_add_hash_footer.go
@@ -25,6 +25,7 @@
type avbAddHashFooter struct {
android.ModuleBase
+ android.DefaultableModuleBase
properties avbAddHashFooterProperties
@@ -80,6 +81,7 @@
module := &avbAddHashFooter{}
module.AddProperties(&module.properties)
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
+ android.InitDefaultableModule(module)
return module
}
@@ -206,3 +208,19 @@
func (a *avbAddHashFooter) Srcs() android.Paths {
return append(android.Paths{}, a.output)
}
+
+type avbAddHashFooterDefaults struct {
+ android.ModuleBase
+ android.DefaultsModuleBase
+}
+
+// avb_add_hash_footer_defaults provides a set of properties that can be inherited by other
+// avb_add_hash_footer modules. A module can use the properties from an avb_add_hash_footer_defaults
+// using `defaults: ["<:default_module_name>"]`. Properties of both modules are erged (when
+// possible) by prepending the default module's values to the depending module's values.
+func avbAddHashFooterDefaultsFactory() android.Module {
+ module := &avbAddHashFooterDefaults{}
+ module.AddProperties(&avbAddHashFooterProperties{})
+ android.InitDefaultsModule(module)
+ return module
+}
diff --git a/filesystem/avb_gen_vbmeta_image.go b/filesystem/avb_gen_vbmeta_image.go
index 0f331f9..985f0ea 100644
--- a/filesystem/avb_gen_vbmeta_image.go
+++ b/filesystem/avb_gen_vbmeta_image.go
@@ -24,6 +24,7 @@
type avbGenVbmetaImage struct {
android.ModuleBase
+ android.DefaultableModuleBase
properties avbGenVbmetaImageProperties
@@ -47,6 +48,7 @@
module := &avbGenVbmetaImage{}
module.AddProperties(&module.properties)
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
+ android.InitDefaultableModule(module)
return module
}
@@ -106,3 +108,20 @@
}
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
}
+
+type avbGenVbmetaImageDefaults struct {
+ android.ModuleBase
+ android.DefaultsModuleBase
+}
+
+// avb_gen_vbmeta_image_defaults provides a set of properties that can be inherited by other
+// avb_gen_vbmeta_image modules. A module can use the properties from an
+// avb_gen_vbmeta_image_defaults using `defaults: ["<:default_module_name>"]`. Properties of both
+// modules are erged (when possible) by prepending the default module's values to the depending
+// module's values.
+func avbGenVbmetaImageDefaultsFactory() android.Module {
+ module := &avbGenVbmetaImageDefaults{}
+ module.AddProperties(&avbGenVbmetaImageProperties{})
+ android.InitDefaultsModule(module)
+ return module
+}
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go
index 3d49114..7b207d6 100644
--- a/filesystem/filesystem.go
+++ b/filesystem/filesystem.go
@@ -36,7 +36,9 @@
ctx.RegisterModuleType("android_filesystem", filesystemFactory)
ctx.RegisterModuleType("android_system_image", systemImageFactory)
ctx.RegisterModuleType("avb_add_hash_footer", avbAddHashFooterFactory)
+ ctx.RegisterModuleType("avb_add_hash_footer_defaults", avbAddHashFooterDefaultsFactory)
ctx.RegisterModuleType("avb_gen_vbmeta_image", avbGenVbmetaImageFactory)
+ ctx.RegisterModuleType("avb_gen_vbmeta_image_defaults", avbGenVbmetaImageDefaultsFactory)
}
type filesystem struct {
diff --git a/filesystem/vbmeta.go b/filesystem/vbmeta.go
index 63e0aba..43a2f37 100644
--- a/filesystem/vbmeta.go
+++ b/filesystem/vbmeta.go
@@ -63,6 +63,17 @@
// List of chained partitions that this vbmeta deletages the verification.
Chained_partitions []chainedPartitionProperties
+
+ // List of key-value pair of avb properties
+ Avb_properties []avbProperty
+}
+
+type avbProperty struct {
+ // Key of given avb property
+ Key *string
+
+ // Value of given avb property
+ Value *string
}
type chainedPartitionProperties struct {
@@ -135,6 +146,20 @@
}
cmd.FlagWithArg("--rollback_index_location ", strconv.Itoa(ril))
+ for _, avb_prop := range v.properties.Avb_properties {
+ key := proptools.String(avb_prop.Key)
+ if key == "" {
+ ctx.PropertyErrorf("avb_properties", "key must be specified")
+ continue
+ }
+ value := proptools.String(avb_prop.Value)
+ if value == "" {
+ ctx.PropertyErrorf("avb_properties", "value must be specified")
+ continue
+ }
+ cmd.FlagWithArg("--prop ", key+":"+value)
+ }
+
for _, p := range ctx.GetDirectDepsWithTag(vbmetaPartitionDep) {
f, ok := p.(Filesystem)
if !ok {
diff --git a/genrule/allowlists.go b/genrule/allowlists.go
index d308f75..d8819b2 100644
--- a/genrule/allowlists.go
+++ b/genrule/allowlists.go
@@ -18,144 +18,21 @@
DepfileAllowList = []string{
// go/keep-sorted start
"depfile_allowed_for_test",
- "gen_uwb_core_proto",
- "libtextclassifier_fbgen_actions_actions-entity-data",
- "libtextclassifier_fbgen_actions_actions_model",
- "libtextclassifier_fbgen_annotator_datetime_datetime",
- "libtextclassifier_fbgen_annotator_entity-data",
- "libtextclassifier_fbgen_annotator_experimental_experimental",
- "libtextclassifier_fbgen_annotator_model",
- "libtextclassifier_fbgen_annotator_person_name_person_name_model",
- "libtextclassifier_fbgen_lang_id_common_flatbuffers_embedding-network",
- "libtextclassifier_fbgen_lang_id_common_flatbuffers_model",
- "libtextclassifier_fbgen_utils_codepoint-range",
- "libtextclassifier_fbgen_utils_container_bit-vector",
- "libtextclassifier_fbgen_utils_flatbuffers_flatbuffers",
- "libtextclassifier_fbgen_utils_flatbuffers_flatbuffers_test",
- "libtextclassifier_fbgen_utils_grammar_rules",
- "libtextclassifier_fbgen_utils_grammar_semantics_expression",
- "libtextclassifier_fbgen_utils_grammar_testing_value",
- "libtextclassifier_fbgen_utils_i18n_language-tag",
- "libtextclassifier_fbgen_utils_intents_intent-config",
- "libtextclassifier_fbgen_utils_lua_utils_tests",
- "libtextclassifier_fbgen_utils_normalization",
- "libtextclassifier_fbgen_utils_resources",
- "libtextclassifier_fbgen_utils_tflite_text_encoder_config",
- "libtextclassifier_fbgen_utils_tokenizer",
- "libtextclassifier_fbgen_utils_zlib_buffer",
- "tflite_support_metadata_schema",
- "tflite_support_spm_config",
- "tflite_support_spm_encoder_config",
// go/keep-sorted end
}
SandboxingDenyModuleList = []string{
// go/keep-sorted start
- "ControlEnvProxyServerProto_cc",
- "ControlEnvProxyServerProto_h",
"CtsApkVerityTestDebugFiles",
- "FrontendStub_cc",
- "FrontendStub_h",
- "ImageProcessing-rscript",
- "ImageProcessing2-rscript",
- "ImageProcessingJB-rscript",
- "MultiDexLegacyTestApp_genrule",
- "PackageManagerServiceServerTests_apks_as_resources",
- "PacketStreamerStub_cc",
- "PacketStreamerStub_h",
- "RSTest-rscript",
- "RSTest_v11-rscript",
- "RSTest_v14-rscript",
- "RSTest_v16-rscript",
- "Refocus-rscript",
- "RsBalls-rscript",
- "ScriptGroupTest-rscript",
- "TracingVMProtoStub_cc",
- "TracingVMProtoStub_h",
- "VehicleServerProtoStub_cc",
- "VehicleServerProtoStub_cc@2.0-grpc-trout",
- "VehicleServerProtoStub_cc@default-grpc",
- "VehicleServerProtoStub_h",
- "VehicleServerProtoStub_h@2.0-grpc-trout",
- "VehicleServerProtoStub_h@default-grpc",
- "aidl-golden-test-build-hook-gen",
"aidl_camera_build_version",
- "android-cts-verifier",
- "android-support-multidex-instrumentation-version",
- "android-support-multidex-version",
- "angle_commit_id",
- "apexer_test_host_tools",
- "atest_integration_fake_src",
- "authfs_test_apk_assets",
- "awkgram.tab.h",
- "c2hal_test_genc++",
- "c2hal_test_genc++_headers",
"camera-its",
- "checkIn-service-stub-lite",
- "chre_atoms_log.h",
- "common-profile-text-protos",
- "core-tests-smali-dex",
- "cronet_aml_base_android_runtime_jni_headers",
- "cronet_aml_base_android_runtime_jni_headers__testing",
- "cronet_aml_base_android_runtime_unchecked_jni_headers",
- "cronet_aml_base_android_runtime_unchecked_jni_headers__testing",
- "deqp_spvtools_update_build_version",
- "egl_extensions_functions_hdr",
- "egl_functions_hdr",
- "emp_ematch.yacc.c",
- "emp_ematch.yacc.h",
- "fdt_test_tree_empty_memory_range_dtb",
- "fdt_test_tree_multiple_memory_ranges_dtb",
- "fdt_test_tree_one_memory_range_dtb",
- "futility_cmds",
- "gen_corrupt_rebootless_apex",
- "gen_corrupt_superblock_apex",
- "gen_key_mismatch_capex",
- "gen_manifest_mismatch_apex_no_hashtree",
- "generate_hash_v1",
- "gles1_core_functions_hdr",
- "gles1_extensions_functions_hdr",
- "gles2_core_functions_hdr",
- "gles2_extensions_functions_hdr",
- "gles31_only_functions_hdr",
- "gles3_only_functions_hdr",
- "lib-test-profile-text-protos",
- "libbssl_sys_src_nostd",
- "libc_musl_sysroot_bits",
- "libchrome-crypto-include",
- "libchrome-include",
"libcore-non-cts-tests-txt",
- "libmojo_jni_headers",
- "libxml2_schema_fuzz_corpus",
- "libxml2_xml_fuzz_corpus",
- "measure_io_as_jar",
- "pandora-python-gen-src",
- "pixelatoms_defs.h",
- "pixelstatsatoms.cpp",
- "pixelstatsatoms.h",
- "pvmfw_fdt_template_rs",
- "r8retrace-dexdump-sample-app",
- "r8retrace-run-retrace",
- "sample-profile-text-protos",
- "seller-frontend-service-stub-lite",
- "services.core.protologsrc",
- "statsd-config-protos",
- "swiftshader_spvtools_update_build_version",
- "temp_layoutlib",
- "ue_unittest_erofs_imgs",
- "uwb_core_artifacts",
- "vm-tests-tf-lib",
- "vndk_abi_dump_zip",
- "vts_vndk_abi_dump_zip",
- "wm_shell_protolog_src",
- "wmtests.protologsrc",
// go/keep-sorted end
}
SandboxingDenyPathList = []string{
// go/keep-sorted start
"art/test",
- "external/cronet",
// go/keep-sorted end
}
)
diff --git a/genrule/genrule.go b/genrule/genrule.go
index 01cac5b..8f2c047 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -189,9 +189,6 @@
subName string
subDir string
-
- // Collect the module directory for IDE info in java/jdeps.go.
- modulePaths []string
}
var _ android.MixedBuildBuildable = (*Module)(nil)
@@ -289,9 +286,6 @@
func (g *Module) generateCommonBuildActions(ctx android.ModuleContext) {
g.subName = ctx.ModuleSubDir()
- // Collect the module directory for IDE info in java/jdeps.go.
- g.modulePaths = append(g.modulePaths, ctx.ModuleDir())
-
if len(g.properties.Export_include_dirs) > 0 {
for _, dir := range g.properties.Export_include_dirs {
g.exportedIncludeDirs = append(g.exportedIncludeDirs,
@@ -668,7 +662,6 @@
dpInfo.Deps = append(dpInfo.Deps, src)
}
}
- dpInfo.Paths = append(dpInfo.Paths, g.modulePaths...)
}
func (g *Module) AndroidMk() android.AndroidMkData {
diff --git a/java/Android.bp b/java/Android.bp
index 4450c42..aa63aa3 100644
--- a/java/Android.bp
+++ b/java/Android.bp
@@ -9,12 +9,14 @@
"blueprint",
"blueprint-pathtools",
"soong",
+ "soong-aconfig",
"soong-android",
"soong-bazel",
"soong-cc",
"soong-dexpreopt",
"soong-genrule",
"soong-java-config",
+ "soong-testing",
"soong-provenance",
"soong-python",
"soong-remoteexec",
@@ -66,7 +68,6 @@
"plugin.go",
"prebuilt_apis.go",
"proto.go",
- "resourceshrinker.go",
"robolectric.go",
"rro.go",
"sdk.go",
@@ -106,12 +107,12 @@
"plugin_test.go",
"prebuilt_apis_test.go",
"proto_test.go",
- "resourceshrinker_test.go",
"rro_test.go",
"sdk_test.go",
"sdk_library_test.go",
"system_modules_test.go",
"systemserver_classpath_fragment_test.go",
+ "test_spec_test.go",
],
pluginFor: ["soong_build"],
}
diff --git a/java/aapt2.go b/java/aapt2.go
index 3bb70b5..17ee6ee 100644
--- a/java/aapt2.go
+++ b/java/aapt2.go
@@ -25,17 +25,23 @@
"android/soong/android"
)
+func isPathValueResource(res android.Path) bool {
+ subDir := filepath.Dir(res.String())
+ subDir, lastDir := filepath.Split(subDir)
+ return strings.HasPrefix(lastDir, "values")
+}
+
// Convert input resource file path to output file path.
// values-[config]/<file>.xml -> values-[config]_<file>.arsc.flat;
// For other resource file, just replace the last "/" with "_" and add .flat extension.
func pathToAapt2Path(ctx android.ModuleContext, res android.Path) android.WritablePath {
name := res.Base()
- subDir := filepath.Dir(res.String())
- subDir, lastDir := filepath.Split(subDir)
- if strings.HasPrefix(lastDir, "values") {
+ if isPathValueResource(res) {
name = strings.TrimSuffix(name, ".xml") + ".arsc"
}
+ subDir := filepath.Dir(res.String())
+ subDir, lastDir := filepath.Split(subDir)
name = lastDir + "_" + name + ".flat"
return android.PathForModuleOut(ctx, "aapt2", subDir, name)
}
@@ -63,7 +69,21 @@
// aapt2Compile compiles resources and puts the results in the requested directory.
func aapt2Compile(ctx android.ModuleContext, dir android.Path, paths android.Paths,
- flags []string) android.WritablePaths {
+ flags []string, productToFilter string) android.WritablePaths {
+ if productToFilter != "" && productToFilter != "default" {
+ // --filter-product leaves only product-specific resources. Product-specific resources only exist
+ // in value resources (values/*.xml), so filter value resource files only. Ignore other types of
+ // resources as they don't need to be in product characteristics RRO (and they will cause aapt2
+ // compile errors)
+ filteredPaths := android.Paths{}
+ for _, path := range paths {
+ if isPathValueResource(path) {
+ filteredPaths = append(filteredPaths, path)
+ }
+ }
+ paths = filteredPaths
+ flags = append([]string{"--filter-product " + productToFilter}, flags...)
+ }
// Shard the input paths so that they can be processed in parallel. If we shard them into too
// small chunks, the additional cost of spinning up aapt2 outweighs the performance gain. The
diff --git a/java/aar.go b/java/aar.go
index 6b89129..57a05d4 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -17,6 +17,7 @@
import (
"fmt"
"path/filepath"
+ "slices"
"strconv"
"strings"
@@ -102,29 +103,32 @@
// true if RRO is enforced for any of the dependent modules
RROEnforcedForDependent bool `blueprint:"mutated"`
+
+ // Filter only specified product and ignore other products
+ Filter_product *string `blueprint:"mutated"`
}
type aapt struct {
- aaptSrcJar android.Path
- transitiveAaptRJars android.Paths
- transitiveAaptResourcePackages android.Paths
- exportPackage android.Path
- manifestPath android.Path
- proguardOptionsFile android.Path
- rTxt android.Path
- rJar android.Path
- extraAaptPackagesFile android.Path
- mergedManifestFile android.Path
- noticeFile android.OptionalPath
- assetPackage android.OptionalPath
- isLibrary bool
- defaultManifestVersion string
- useEmbeddedNativeLibs bool
- useEmbeddedDex bool
- usesNonSdkApis bool
- hasNoCode bool
- LoggingParent string
- resourceFiles android.Paths
+ aaptSrcJar android.Path
+ transitiveAaptRJars android.Paths
+ transitiveAaptResourcePackagesFile android.Path
+ exportPackage android.Path
+ manifestPath android.Path
+ proguardOptionsFile android.Path
+ rTxt android.Path
+ rJar android.Path
+ extraAaptPackagesFile android.Path
+ mergedManifestFile android.Path
+ noticeFile android.OptionalPath
+ assetPackage android.OptionalPath
+ isLibrary bool
+ defaultManifestVersion string
+ useEmbeddedNativeLibs bool
+ useEmbeddedDex bool
+ usesNonSdkApis bool
+ hasNoCode bool
+ LoggingParent string
+ resourceFiles android.Paths
splitNames []string
splits []split
@@ -162,6 +166,10 @@
return BoolDefault(a.aaptProperties.Use_resource_processor, false)
}
+func (a *aapt) filterProduct() string {
+ return String(a.aaptProperties.Filter_product)
+}
+
func (a *aapt) ExportPackage() android.Path {
return a.exportPackage
}
@@ -432,7 +440,7 @@
var compiledResDirs []android.Paths
for _, dir := range resDirs {
a.resourceFiles = append(a.resourceFiles, dir.files...)
- compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths())
+ compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files, compileFlags, a.filterProduct()).Paths())
}
for i, zip := range resZips {
@@ -491,7 +499,7 @@
}
for _, dir := range overlayDirs {
- compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths()...)
+ compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files, compileFlags, a.filterProduct()).Paths()...)
}
var splitPackages android.WritablePaths
@@ -545,9 +553,16 @@
aapt2ExtractExtraPackages(ctx, extraPackages, srcJar)
}
+ transitiveAaptResourcePackages := staticDeps.resPackages().Strings()
+ transitiveAaptResourcePackages = slices.DeleteFunc(transitiveAaptResourcePackages, func(p string) bool {
+ return p == packageRes.String()
+ })
+ transitiveAaptResourcePackagesFile := android.PathForModuleOut(ctx, "transitive-res-packages")
+ android.WriteFileRule(ctx, transitiveAaptResourcePackagesFile, strings.Join(transitiveAaptResourcePackages, "\n"))
+
a.aaptSrcJar = srcJar
a.transitiveAaptRJars = transitiveRJars
- a.transitiveAaptResourcePackages = staticDeps.resPackages()
+ a.transitiveAaptResourcePackagesFile = transitiveAaptResourcePackagesFile
a.exportPackage = packageRes
a.manifestPath = manifestPath
a.proguardOptionsFile = proguardOptionsFile
@@ -813,9 +828,13 @@
proguardSpecInfo := a.collectProguardSpecInfo(ctx)
ctx.SetProvider(ProguardSpecInfoProvider, proguardSpecInfo)
- a.exportedProguardFlagFiles = proguardSpecInfo.ProguardFlagsFiles.ToList()
- a.extraProguardFlagFiles = append(a.extraProguardFlagFiles, a.exportedProguardFlagFiles...)
- a.extraProguardFlagFiles = append(a.extraProguardFlagFiles, a.proguardOptionsFile)
+ exportedProguardFlagsFiles := proguardSpecInfo.ProguardFlagsFiles.ToList()
+ a.extraProguardFlagsFiles = append(a.extraProguardFlagsFiles, exportedProguardFlagsFiles...)
+ a.extraProguardFlagsFiles = append(a.extraProguardFlagsFiles, a.proguardOptionsFile)
+
+ combinedExportedProguardFlagFile := android.PathForModuleOut(ctx, "export_proguard_flags")
+ writeCombinedProguardFlagsFile(ctx, combinedExportedProguardFlagFile, exportedProguardFlagsFiles)
+ a.combinedExportedProguardFlagsFile = combinedExportedProguardFlagFile
var extraSrcJars android.Paths
var extraCombinedJars android.Paths
@@ -933,15 +952,15 @@
properties AARImportProperties
- classpathFile android.WritablePath
- proguardFlags android.WritablePath
- exportPackage android.WritablePath
- transitiveAaptResourcePackages android.Paths
- extraAaptPackagesFile android.WritablePath
- manifest android.WritablePath
- assetsPackage android.WritablePath
- rTxt android.WritablePath
- rJar android.WritablePath
+ classpathFile android.WritablePath
+ proguardFlags android.WritablePath
+ exportPackage android.WritablePath
+ transitiveAaptResourcePackagesFile android.Path
+ extraAaptPackagesFile android.WritablePath
+ manifest android.WritablePath
+ assetsPackage android.WritablePath
+ rTxt android.WritablePath
+ rJar android.WritablePath
resourcesNodesDepSet *android.DepSet[*resourcesNode]
manifestsDepSet *android.DepSet[android.Path]
@@ -1204,7 +1223,13 @@
_ = staticManifestsDepSet
a.manifestsDepSet = manifestDepSetBuilder.Build()
- a.transitiveAaptResourcePackages = staticDeps.resPackages()
+ transitiveAaptResourcePackages := staticDeps.resPackages().Strings()
+ transitiveAaptResourcePackages = slices.DeleteFunc(transitiveAaptResourcePackages, func(p string) bool {
+ return p == a.exportPackage.String()
+ })
+ transitiveAaptResourcePackagesFile := android.PathForModuleOut(ctx, "transitive-res-packages")
+ android.WriteFileRule(ctx, transitiveAaptResourcePackagesFile, strings.Join(transitiveAaptResourcePackages, "\n"))
+ a.transitiveAaptResourcePackagesFile = transitiveAaptResourcePackagesFile
a.collectTransitiveHeaderJars(ctx)
ctx.SetProvider(JavaInfoProvider, JavaInfo{
diff --git a/java/androidmk.go b/java/androidmk.go
index 97b303d..4da40d2 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -128,8 +128,8 @@
if library.dexpreopter.configPath != nil {
entries.SetPath("LOCAL_SOONG_DEXPREOPT_CONFIG", library.dexpreopter.configPath)
}
-
- entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", library.getTransitiveAconfigFiles().ToList())
+ // TODO(b/311155208): The container here should be system.
+ entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", library.getTransitiveAconfigFiles(""))
},
},
})
@@ -274,7 +274,7 @@
entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.classpathFile)
entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.classpathFile)
entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", prebuilt.exportPackage)
- entries.SetPaths("LOCAL_SOONG_TRANSITIVE_RES_PACKAGES", prebuilt.transitiveAaptResourcePackages)
+ entries.SetPath("LOCAL_SOONG_TRANSITIVE_RES_PACKAGES", prebuilt.transitiveAaptResourcePackagesFile)
entries.SetPath("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", prebuilt.proguardFlags)
entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", prebuilt.extraAaptPackagesFile)
entries.SetPath("LOCAL_FULL_MANIFEST_FILE", prebuilt.manifest)
@@ -306,7 +306,8 @@
if len(binary.dexpreopter.builtInstalled) > 0 {
entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", binary.dexpreopter.builtInstalled)
}
- entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", binary.getTransitiveAconfigFiles().ToList())
+ // TODO(b/311155208): The container here should be system.
+ entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", binary.getTransitiveAconfigFiles(""))
},
},
ExtraFooters: []android.AndroidMkExtraFootersFunc{
@@ -343,10 +344,15 @@
Disabled: true,
}}
}
+ var required []string
+ if proptools.Bool(app.appProperties.Generate_product_characteristics_rro) {
+ required = []string{app.productCharacteristicsRROPackageName()}
+ }
return []android.AndroidMkEntries{android.AndroidMkEntries{
Class: "APPS",
OutputFile: android.OptionalPathForPath(app.outputFile),
Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
+ Required: required,
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
// App module names can be overridden.
@@ -454,7 +460,8 @@
entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", app.linter.reports)
if app.Name() != "framework-res" {
- entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", app.getTransitiveAconfigFiles().ToList())
+ // TODO(b/311155208): The container here should be system.
+ entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", app.getTransitiveAconfigFiles(""))
}
},
},
@@ -527,12 +534,13 @@
}
entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", a.exportPackage)
- entries.SetPaths("LOCAL_SOONG_TRANSITIVE_RES_PACKAGES", a.transitiveAaptResourcePackages)
+ entries.SetPath("LOCAL_SOONG_TRANSITIVE_RES_PACKAGES", a.transitiveAaptResourcePackagesFile)
entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", a.extraAaptPackagesFile)
entries.SetPath("LOCAL_FULL_MANIFEST_FILE", a.mergedManifestFile)
- entries.AddStrings("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", a.exportedProguardFlagFiles.Strings()...)
+ entries.SetPath("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", a.combinedExportedProguardFlagsFile)
entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true)
- entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", a.getTransitiveAconfigFiles().ToList())
+ // TODO(b/311155208): The container here should be system.
+ entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", a.getTransitiveAconfigFiles(""))
})
return entriesList
diff --git a/java/app.go b/java/app.go
index 2271378..0f46b4e 100755
--- a/java/app.go
+++ b/java/app.go
@@ -22,6 +22,7 @@
"path/filepath"
"strings"
+ "android/soong/testing"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -130,6 +131,16 @@
// Specifies the file that contains the allowlist for this app.
Privapp_allowlist *string `android:"path"`
+
+ // If set, create an RRO package which contains only resources having PRODUCT_CHARACTERISTICS
+ // and install the RRO package to /product partition, instead of passing --product argument
+ // to aapt2. Default is false.
+ // Setting this will make this APK identical to all targets, regardless of
+ // PRODUCT_CHARACTERISTICS.
+ Generate_product_characteristics_rro *bool
+
+ ProductCharacteristicsRROPackageName *string `blueprint:"mutated"`
+ ProductCharacteristicsRROManifestModuleName *string `blueprint:"mutated"`
}
// android_app properties that can be overridden by override_android_app
@@ -454,8 +465,9 @@
aaptLinkFlags := []string{}
// Add TARGET_AAPT_CHARACTERISTICS values to AAPT link flags if they exist and --product flags were not provided.
+ autogenerateRRO := proptools.Bool(a.appProperties.Generate_product_characteristics_rro)
hasProduct := android.PrefixInList(a.aaptProperties.Aaptflags, "--product")
- if !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 {
+ if !autogenerateRRO && !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 {
aaptLinkFlags = append(aaptLinkFlags, "--product", ctx.Config().ProductAAPTCharacteristics())
}
@@ -514,8 +526,8 @@
staticLibProguardFlagFiles = android.FirstUniquePaths(staticLibProguardFlagFiles)
- a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...)
- a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile)
+ a.Module.extraProguardFlagsFiles = append(a.Module.extraProguardFlagsFiles, staticLibProguardFlagFiles...)
+ a.Module.extraProguardFlagsFiles = append(a.Module.extraProguardFlagsFiles, a.proguardOptionsFile)
}
func (a *AndroidApp) installPath(ctx android.ModuleContext) android.InstallPath {
@@ -532,7 +544,7 @@
return android.PathForModuleInstall(ctx, installDir, a.installApkName+".apk")
}
-func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path {
+func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) (android.Path, android.Path) {
a.dexpreopter.installPath = a.installPath(ctx)
a.dexpreopter.isApp = true
if a.dexProperties.Uncompress_dex == nil {
@@ -545,7 +557,15 @@
a.dexpreopter.manifestFile = a.mergedManifestFile
a.dexpreopter.preventInstall = a.appProperties.PreventInstall
+ var packageResources = a.exportPackage
+
if ctx.ModuleName() != "framework-res" {
+ if Bool(a.dexProperties.Optimize.Shrink_resources) {
+ protoFile := android.PathForModuleOut(ctx, packageResources.Base()+".proto.apk")
+ aapt2Convert(ctx, protoFile, packageResources, "proto")
+ a.dexer.resourcesInput = android.OptionalPathForPath(protoFile)
+ }
+
var extraSrcJars android.Paths
var extraClasspathJars android.Paths
var extraCombinedJars android.Paths
@@ -563,9 +583,14 @@
}
a.Module.compile(ctx, extraSrcJars, extraClasspathJars, extraCombinedJars)
+ if Bool(a.dexProperties.Optimize.Shrink_resources) {
+ binaryResources := android.PathForModuleOut(ctx, packageResources.Base()+".binary.out.apk")
+ aapt2Convert(ctx, binaryResources, a.dexer.resourcesOutput.Path(), "binary")
+ packageResources = binaryResources
+ }
}
- return a.dexJarFile.PathOrNil()
+ return a.dexJarFile.PathOrNil(), packageResources
}
func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, prebuiltJniPackages android.Paths, ctx android.ModuleContext) android.WritablePath {
@@ -750,7 +775,6 @@
// Process all building blocks, from AAPT to certificates.
a.aaptBuildActions(ctx)
-
// The decision to enforce <uses-library> checks is made before adding implicit SDK libraries.
a.usesLibrary.freezeEnforceUsesLibraries()
@@ -776,7 +800,7 @@
a.linter.resources = a.aapt.resourceFiles
a.linter.buildModuleReportZip = ctx.Config().UnbundledBuildApps()
- dexJarFile := a.dexBuildActions(ctx)
+ dexJarFile, packageResources := a.dexBuildActions(ctx)
jniLibs, prebuiltJniPackages, certificates := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis))
jniJarFile := a.jniBuildActions(jniLibs, prebuiltJniPackages, ctx)
@@ -800,7 +824,7 @@
}
rotationMinSdkVersion := String(a.overridableAppProperties.RotationMinSdkVersion)
- CreateAndSignAppPackage(ctx, packageFile, a.exportPackage, jniJarFile, dexJarFile, certificates, apkDeps, v4SignatureFile, lineageFile, rotationMinSdkVersion, Bool(a.dexProperties.Optimize.Shrink_resources))
+ CreateAndSignAppPackage(ctx, packageFile, packageResources, jniJarFile, dexJarFile, certificates, apkDeps, v4SignatureFile, lineageFile, rotationMinSdkVersion)
a.outputFile = packageFile
if v4SigningRequested {
a.extraOutputFiles = append(a.extraOutputFiles, v4SignatureFile)
@@ -829,7 +853,7 @@
if v4SigningRequested {
v4SignatureFile = android.PathForModuleOut(ctx, a.installApkName+"_"+split.suffix+".apk.idsig")
}
- CreateAndSignAppPackage(ctx, packageFile, split.path, nil, nil, certificates, apkDeps, v4SignatureFile, lineageFile, rotationMinSdkVersion, false)
+ CreateAndSignAppPackage(ctx, packageFile, split.path, nil, nil, certificates, apkDeps, v4SignatureFile, lineageFile, rotationMinSdkVersion)
a.extraOutputFiles = append(a.extraOutputFiles, packageFile)
if v4SigningRequested {
a.extraOutputFiles = append(a.extraOutputFiles, v4SignatureFile)
@@ -857,7 +881,7 @@
ctx.InstallFile(allowlistInstallPath, allowlistInstallFilename, a.privAppAllowlist.Path())
}
- var extraInstalledPaths android.Paths
+ var extraInstalledPaths android.InstallPaths
for _, extra := range a.extraOutputFiles {
installed := ctx.InstallFile(a.installDir, extra.Base(), extra)
extraInstalledPaths = append(extraInstalledPaths, installed)
@@ -1056,6 +1080,8 @@
}
case ".export-package.apk":
return []android.Path{a.exportPackage}, nil
+ case ".manifest.xml":
+ return []android.Path{a.aapt.manifestPath}, nil
}
return a.Library.OutputFiles(tag)
}
@@ -1085,6 +1111,14 @@
a.aapt.IDEInfo(dpInfo)
}
+func (a *AndroidApp) productCharacteristicsRROPackageName() string {
+ return proptools.String(a.appProperties.ProductCharacteristicsRROPackageName)
+}
+
+func (a *AndroidApp) productCharacteristicsRROManifestModuleName() string {
+ return proptools.String(a.appProperties.ProductCharacteristicsRROManifestModuleName)
+}
+
// android_app compiles sources and Android resources into an Android application package `.apk` file.
func AndroidAppFactory() android.Module {
module := &AndroidApp{}
@@ -1111,6 +1145,57 @@
android.InitApexModule(module)
android.InitBazelModule(module)
+ android.AddLoadHook(module, func(ctx android.LoadHookContext) {
+ a := ctx.Module().(*AndroidApp)
+
+ characteristics := ctx.Config().ProductAAPTCharacteristics()
+ if characteristics == "default" || characteristics == "" {
+ module.appProperties.Generate_product_characteristics_rro = nil
+ // no need to create RRO
+ return
+ }
+
+ if !proptools.Bool(module.appProperties.Generate_product_characteristics_rro) {
+ return
+ }
+
+ rroPackageName := a.Name() + "__" + strings.ReplaceAll(characteristics, ",", "_") + "__auto_generated_characteristics_rro"
+ rroManifestName := rroPackageName + "_manifest"
+
+ a.appProperties.ProductCharacteristicsRROPackageName = proptools.StringPtr(rroPackageName)
+ a.appProperties.ProductCharacteristicsRROManifestModuleName = proptools.StringPtr(rroManifestName)
+
+ rroManifestProperties := struct {
+ Name *string
+ Tools []string
+ Out []string
+ Srcs []string
+ Cmd *string
+ }{
+ Name: proptools.StringPtr(rroManifestName),
+ Tools: []string{"characteristics_rro_generator"},
+ Out: []string{"AndroidManifest.xml"},
+ Srcs: []string{":" + a.Name() + "{.manifest.xml}"},
+ Cmd: proptools.StringPtr("$(location characteristics_rro_generator) $(in) $(out)"),
+ }
+ ctx.CreateModule(genrule.GenRuleFactory, &rroManifestProperties)
+
+ rroProperties := struct {
+ Name *string
+ Filter_product *string
+ Aaptflags []string
+ Manifest *string
+ Resource_dirs []string
+ }{
+ Name: proptools.StringPtr(rroPackageName),
+ Filter_product: proptools.StringPtr(characteristics),
+ Aaptflags: []string{"--auto-add-overlay"},
+ Manifest: proptools.StringPtr(":" + rroManifestName),
+ Resource_dirs: a.aaptProperties.Resource_dirs,
+ }
+ ctx.CreateModule(RuntimeResourceOverlayFactory, &rroProperties)
+ })
+
return module
}
@@ -1193,6 +1278,7 @@
a.testConfig = a.FixTestConfig(ctx, testConfig)
a.extraTestConfigs = android.PathsForModuleSrc(ctx, a.testProperties.Test_options.Extra_test_configs)
a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
+ ctx.SetProvider(testing.TestModuleProviderKey, testing.TestModuleProviderData{})
}
func (a *AndroidTest) FixTestConfig(ctx android.ModuleContext, testConfig android.Path) android.Path {
diff --git a/java/app_builder.go b/java/app_builder.go
index d397ff7..943ce31 100644
--- a/java/app_builder.go
+++ b/java/app_builder.go
@@ -52,7 +52,7 @@
})
func CreateAndSignAppPackage(ctx android.ModuleContext, outputFile android.WritablePath,
- packageFile, jniJarFile, dexJarFile android.Path, certificates []Certificate, deps android.Paths, v4SignatureFile android.WritablePath, lineageFile android.Path, rotationMinSdkVersion string, shrinkResources bool) {
+ packageFile, jniJarFile, dexJarFile android.Path, certificates []Certificate, deps android.Paths, v4SignatureFile android.WritablePath, lineageFile android.Path, rotationMinSdkVersion string) {
unsignedApkName := strings.TrimSuffix(outputFile.Base(), ".apk") + "-unsigned.apk"
unsignedApk := android.PathForModuleOut(ctx, unsignedApkName)
@@ -71,12 +71,6 @@
Output: unsignedApk,
Implicits: deps,
})
-
- if shrinkResources {
- shrunkenApk := android.PathForModuleOut(ctx, "resource-shrunken", unsignedApk.Base())
- ShrinkResources(ctx, unsignedApk, shrunkenApk)
- unsignedApk = shrunkenApk
- }
SignAppPackage(ctx, outputFile, unsignedApk, certificates, v4SignatureFile, lineageFile, rotationMinSdkVersion)
}
diff --git a/java/base.go b/java/base.go
index 3d7d3de..295340d 100644
--- a/java/base.go
+++ b/java/base.go
@@ -25,6 +25,7 @@
"github.com/google/blueprint/pathtools"
"github.com/google/blueprint/proptools"
+ "android/soong/aconfig"
"android/soong/android"
"android/soong/dexpreopt"
"android/soong/java/config"
@@ -497,9 +498,6 @@
// list of the xref extraction files
kytheFiles android.Paths
- // Collect the module directory for IDE info in java/jdeps.go.
- modulePaths []string
-
hideApexVariantFromMake bool
sdkVersion android.SdkSpec
@@ -515,13 +513,8 @@
// or the module should override Stem().
stem string
- // Aconfig "cache files" that went directly into this module. Transitive ones are
- // tracked via JavaInfo.TransitiveAconfigFiles
- // TODO: Extract to something standalone to propagate tags via GeneratedJavaLibraryModule
- aconfigIntermediates android.Paths
-
- // Aconfig files for all transitive deps. Also exposed via JavaInfo
- transitiveAconfigFiles *android.DepSet[android.Path]
+ // Aconfig files for all transitive deps. Also exposed via TransitiveDeclarationsInfo
+ transitiveAconfigFiles map[string]*android.DepSet[android.Path]
}
func (j *Module) CheckStableSdkVersion(ctx android.BaseModuleContext) error {
@@ -1618,7 +1611,7 @@
if ctx.Device() && (Bool(j.properties.Installable) || Bool(compileDex)) {
if j.hasCode(ctx) {
if j.shouldInstrumentStatic(ctx) {
- j.dexer.extraProguardFlagFiles = append(j.dexer.extraProguardFlagFiles,
+ j.dexer.extraProguardFlagsFiles = append(j.dexer.extraProguardFlagsFiles,
android.PathForSource(ctx, "build/make/core/proguard.jacoco.flags"))
}
// Dex compilation
@@ -1726,7 +1719,7 @@
ctx.CheckbuildFile(outputFile)
- j.collectTransitiveAconfigFiles(ctx)
+ aconfig.CollectTransitiveAconfigFiles(ctx, &j.transitiveAconfigFiles)
ctx.SetProvider(JavaInfoProvider, JavaInfo{
HeaderJars: android.PathsIfNonNil(j.headerJarFile),
@@ -1743,7 +1736,6 @@
ExportedPluginClasses: j.exportedPluginClasses,
ExportedPluginDisableTurbine: j.exportedDisableTurbine,
JacocoReportClassesFile: j.jacocoReportClassesFile,
- TransitiveAconfigFiles: j.transitiveAconfigFiles,
})
// Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
@@ -2015,7 +2007,6 @@
if j.expandJarjarRules != nil {
dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
}
- dpInfo.Paths = append(dpInfo.Paths, j.modulePaths...)
dpInfo.Static_libs = append(dpInfo.Static_libs, j.properties.Static_libs...)
dpInfo.Libs = append(dpInfo.Libs, j.properties.Libs...)
dpInfo.SrcJars = append(dpInfo.SrcJars, j.annoSrcJars.Strings()...)
@@ -2085,32 +2076,8 @@
return Bool(j.properties.Installable)
}
-func (j *Module) collectTransitiveAconfigFiles(ctx android.ModuleContext) {
- // Aconfig files from this module
- mine := j.aconfigIntermediates
-
- // Aconfig files from transitive dependencies
- fromDeps := []*android.DepSet[android.Path]{}
- ctx.VisitDirectDeps(func(module android.Module) {
- dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
- if dep.TransitiveAconfigFiles != nil {
- fromDeps = append(fromDeps, dep.TransitiveAconfigFiles)
- }
- })
-
- // DepSet containing aconfig files myself and from dependencies
- j.transitiveAconfigFiles = android.NewDepSet(android.POSTORDER, mine, fromDeps)
-}
-
-func (j *Module) AddAconfigIntermediate(path android.Path) {
- j.aconfigIntermediates = append(j.aconfigIntermediates, path)
-}
-
-func (j *Module) getTransitiveAconfigFiles() *android.DepSet[android.Path] {
- if j.transitiveAconfigFiles == nil {
- panic(fmt.Errorf("java.Moduile: getTransitiveAconfigFiles called before collectTransitiveAconfigFiles module=%s", j.Name()))
- }
- return j.transitiveAconfigFiles
+func (j *Module) getTransitiveAconfigFiles(container string) []android.Path {
+ return j.transitiveAconfigFiles[container].ToList()
}
type sdkLinkType int
diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go
index 7d8a9f7..191a65e 100644
--- a/java/bootclasspath_fragment.go
+++ b/java/bootclasspath_fragment.go
@@ -23,6 +23,7 @@
"android/soong/android"
"android/soong/dexpreopt"
+ "android/soong/testing"
"github.com/google/blueprint/proptools"
@@ -238,9 +239,6 @@
sourceOnlyProperties SourceOnlyBootclasspathProperties
- // Collect the module directory for IDE info in java/jdeps.go.
- modulePaths []string
-
// Path to the boot image profile.
profilePath android.WritablePath
}
@@ -471,9 +469,6 @@
// Generate classpaths.proto config
b.generateClasspathProtoBuildActions(ctx)
- // Collect the module directory for IDE info in java/jdeps.go.
- b.modulePaths = append(b.modulePaths, ctx.ModuleDir())
-
// Gather the bootclasspath fragment's contents.
var contents []android.Module
ctx.VisitDirectDeps(func(module android.Module) {
@@ -505,6 +500,7 @@
if ctx.Module() != ctx.FinalModule() {
b.HideFromMake()
}
+ ctx.SetProvider(testing.TestModuleProviderKey, testing.TestModuleProviderData{})
}
// getProfileProviderApex returns the name of the apex that provides a boot image profile, or an
@@ -582,7 +578,7 @@
// So ignore it even if it is not in PRODUCT_APEX_BOOT_JARS.
// TODO(b/202896428): Add better way to handle this.
_, unknown = android.RemoveFromList("android.car-module", unknown)
- if len(unknown) > 0 {
+ if isActiveModule(ctx.Module()) && len(unknown) > 0 {
ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_APEX_BOOT_JARS", unknown)
}
}
@@ -801,7 +797,6 @@
// Collect information for opening IDE project files in java/jdeps.go.
func (b *BootclasspathFragmentModule) IDEInfo(dpInfo *android.IdeInfo) {
dpInfo.Deps = append(dpInfo.Deps, b.properties.Contents...)
- dpInfo.Paths = append(dpInfo.Paths, b.modulePaths...)
}
type bootclasspathFragmentMemberType struct {
diff --git a/java/builder.go b/java/builder.go
index ee7e225..d03c8e5 100644
--- a/java/builder.go
+++ b/java/builder.go
@@ -264,6 +264,16 @@
Command: `${config.Zip2ZipCmd} -i ${in} -o ${out} -x 'META-INF/services/**/*'`,
CommandDeps: []string{"${config.Zip2ZipCmd}"},
})
+
+ writeCombinedProguardFlagsFileRule = pctx.AndroidStaticRule("writeCombinedProguardFlagsFileRule",
+ blueprint.RuleParams{
+ Command: `rm -f $out && ` +
+ `for f in $in; do ` +
+ ` echo && ` +
+ ` echo "# including $$f" && ` +
+ ` cat $$f; ` +
+ `done > $out`,
+ })
)
func init() {
@@ -686,6 +696,15 @@
})
}
+func writeCombinedProguardFlagsFile(ctx android.ModuleContext, outputFile android.WritablePath, files android.Paths) {
+ ctx.Build(pctx, android.BuildParams{
+ Rule: writeCombinedProguardFlagsFileRule,
+ Description: "write combined proguard flags file",
+ Inputs: files,
+ Output: outputFile,
+ })
+}
+
type classpath android.Paths
func (x *classpath) formJoinedClassPath(optName string, sep string) string {
diff --git a/java/config/config.go b/java/config/config.go
index 83c27d3..0098130 100644
--- a/java/config/config.go
+++ b/java/config/config.go
@@ -133,7 +133,12 @@
if override := ctx.Config().Getenv("OVERRIDE_JLINK_VERSION_NUMBER"); override != "" {
return override
}
- return "17"
+ switch ctx.Config().Getenv("EXPERIMENTAL_USE_OPENJDK21_TOOLCHAIN") {
+ case "true":
+ return "21"
+ default:
+ return "17"
+ }
})
pctx.SourcePathVariable("JavaToolchain", "${JavaHome}/bin")
diff --git a/java/dex.go b/java/dex.go
index aa01783..6f1c09d 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -91,10 +91,12 @@
dexProperties DexProperties
// list of extra proguard flag files
- extraProguardFlagFiles android.Paths
- proguardDictionary android.OptionalPath
- proguardConfiguration android.OptionalPath
- proguardUsageZip android.OptionalPath
+ extraProguardFlagsFiles android.Paths
+ proguardDictionary android.OptionalPath
+ proguardConfiguration android.OptionalPath
+ proguardUsageZip android.OptionalPath
+ resourcesInput android.OptionalPath
+ resourcesOutput android.OptionalPath
providesTransitiveHeaderJars
}
@@ -106,7 +108,7 @@
var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8",
blueprint.RuleParams{
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
- `$d8Template${config.D8Cmd} ${config.D8Flags} --output $outDir $d8Flags --no-dex-input-jar $in && ` +
+ `$d8Template${config.D8Cmd} ${config.D8Flags} $d8Flags --output $outDir --no-dex-input-jar $in && ` +
`$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
`${config.MergeZipsCmd} -D -stripFile "**/*.class" $mergeZipsFlags $out $outDir/classes.dex.jar $in && ` +
`rm -f "$outDir/classes*.dex" "$outDir/classes.dex.jar"`,
@@ -137,13 +139,12 @@
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
`rm -f "$outDict" && rm -f "$outConfig" && rm -rf "${outUsageDir}" && ` +
`mkdir -p $$(dirname ${outUsage}) && ` +
- `$r8Template${config.R8Cmd} ${config.R8Flags} -injars $in --output $outDir ` +
+ `$r8Template${config.R8Cmd} ${config.R8Flags} $r8Flags -injars $in --output $outDir ` +
`--no-data-resources ` +
`-printmapping ${outDict} ` +
`-printconfiguration ${outConfig} ` +
`-printusage ${outUsage} ` +
- `--deps-file ${out}.d ` +
- `$r8Flags && ` +
+ `--deps-file ${out}.d && ` +
`touch "${outDict}" "${outConfig}" "${outUsage}" && ` +
`${config.SoongZipCmd} -o ${outUsageZip} -C ${outUsageDir} -f ${outUsage} && ` +
`rm -rf ${outUsageDir} && ` +
@@ -161,7 +162,7 @@
"$r8Template": &remoteexec.REParams{
Labels: map[string]string{"type": "compile", "compiler": "r8"},
Inputs: []string{"$implicits", "${config.R8Jar}"},
- OutputFiles: []string{"${outUsage}", "${outConfig}", "${outDict}"},
+ OutputFiles: []string{"${outUsage}", "${outConfig}", "${outDict}", "${resourcesOutput}"},
ExecStrategy: "${config.RER8ExecStrategy}",
ToolchainInputs: []string{"${config.JavaCmd}"},
Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
@@ -181,7 +182,7 @@
Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
},
}, []string{"outDir", "outDict", "outConfig", "outUsage", "outUsageZip", "outUsageDir",
- "r8Flags", "zipFlags", "mergeZipsFlags"}, []string{"implicits"})
+ "r8Flags", "zipFlags", "mergeZipsFlags", "resourcesOutput"}, []string{"implicits"})
func (d *dexer) dexCommonFlags(ctx android.ModuleContext,
dexParams *compileDexParams) (flags []string, deps android.Paths) {
@@ -295,7 +296,7 @@
android.PathForSource(ctx, "build/make/core/proguard.flags"),
}
- flagFiles = append(flagFiles, d.extraProguardFlagFiles...)
+ flagFiles = append(flagFiles, d.extraProguardFlagsFiles...)
// TODO(ccross): static android library proguard files
flagFiles = append(flagFiles, android.PathsForModuleSrc(ctx, opt.Proguard_flags_files)...)
@@ -350,6 +351,12 @@
r8Flags = append(r8Flags, "-ignorewarnings")
}
+ if d.resourcesInput.Valid() {
+ r8Flags = append(r8Flags, "--resource-input", d.resourcesInput.Path().String())
+ r8Deps = append(r8Deps, d.resourcesInput.Path())
+ r8Flags = append(r8Flags, "--resource-output", d.resourcesOutput.Path().String())
+ }
+
return r8Flags, r8Deps
}
@@ -391,6 +398,8 @@
android.ModuleNameWithPossibleOverride(ctx), "unused.txt")
proguardUsageZip := android.PathForModuleOut(ctx, "proguard_usage.zip")
d.proguardUsageZip = android.OptionalPathForPath(proguardUsageZip)
+ resourcesOutput := android.PathForModuleOut(ctx, "package-res-shrunken.apk")
+ d.resourcesOutput = android.OptionalPathForPath(resourcesOutput)
r8Flags, r8Deps := d.r8Flags(ctx, dexParams.flags)
r8Deps = append(r8Deps, commonDeps...)
rule := r8
@@ -409,17 +418,22 @@
rule = r8RE
args["implicits"] = strings.Join(r8Deps.Strings(), ",")
}
+ implicitOutputs := android.WritablePaths{
+ proguardDictionary,
+ proguardUsageZip,
+ proguardConfiguration}
+ if d.resourcesInput.Valid() {
+ implicitOutputs = append(implicitOutputs, resourcesOutput)
+ args["resourcesOutput"] = resourcesOutput.String()
+ }
ctx.Build(pctx, android.BuildParams{
- Rule: rule,
- Description: "r8",
- Output: javalibJar,
- ImplicitOutputs: android.WritablePaths{
- proguardDictionary,
- proguardUsageZip,
- proguardConfiguration},
- Input: dexParams.classesJar,
- Implicits: r8Deps,
- Args: args,
+ Rule: rule,
+ Description: "r8",
+ Output: javalibJar,
+ ImplicitOutputs: implicitOutputs,
+ Input: dexParams.classesJar,
+ Implicits: r8Deps,
+ Args: args,
})
} else {
d8Flags, d8Deps := d8Flags(dexParams.flags)
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
index 998730e..fe8c5fb 100644
--- a/java/dexpreopt.go
+++ b/java/dexpreopt.go
@@ -374,8 +374,6 @@
PreoptBootClassPathDexFiles: dexFiles.Paths(),
PreoptBootClassPathDexLocations: dexLocations,
- PreoptExtractedApk: false,
-
NoCreateAppImage: !BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, true),
ForceCreateAppImage: BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, false),
diff --git a/java/droidstubs.go b/java/droidstubs.go
index 180ba92..6b8d21f 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -19,7 +19,6 @@
"path/filepath"
"regexp"
"sort"
- "strconv"
"strings"
"github.com/google/blueprint/proptools"
@@ -500,18 +499,20 @@
if metalavaUseRbe(ctx) {
rule.Remoteable(android.RemoteRuleSupports{RBE: true})
execStrategy := ctx.Config().GetenvWithDefault("RBE_METALAVA_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
- compare, _ := strconv.ParseBool(ctx.Config().GetenvWithDefault("RBE_METALAVA_COMPARE", "false"))
+ compare := ctx.Config().IsEnvTrue("RBE_METALAVA_COMPARE")
+ remoteUpdateCache := !ctx.Config().IsEnvFalse("RBE_METALAVA_REMOTE_UPDATE_CACHE")
labels := map[string]string{"type": "tool", "name": "metalava"}
// TODO: metalava pool rejects these jobs
pool := ctx.Config().GetenvWithDefault("RBE_METALAVA_POOL", "java16")
rule.Rewrapper(&remoteexec.REParams{
- Labels: labels,
- ExecStrategy: execStrategy,
- ToolchainInputs: []string{config.JavaCmd(ctx).String()},
- Platform: map[string]string{remoteexec.PoolKey: pool},
- Compare: compare,
- NumLocalRuns: 1,
- NumRemoteRuns: 1,
+ Labels: labels,
+ ExecStrategy: execStrategy,
+ ToolchainInputs: []string{config.JavaCmd(ctx).String()},
+ Platform: map[string]string{remoteexec.PoolKey: pool},
+ Compare: compare,
+ NumLocalRuns: 1,
+ NumRemoteRuns: 1,
+ NoRemoteUpdateCache: !remoteUpdateCache,
})
}
diff --git a/java/generated_java_library_test.go b/java/generated_java_library_test.go
index 7fbbfee..ac9524e 100644
--- a/java/generated_java_library_test.go
+++ b/java/generated_java_library_test.go
@@ -37,7 +37,6 @@
}
func (callbacks *JavaGenLibTestCallbacks) GenerateSourceJarBuildActions(module *GeneratedJavaLibraryModule, ctx android.ModuleContext) android.Path {
- module.AddAconfigIntermediate(android.PathForOutput(ctx, "aconfig_cache_file"))
return android.PathForOutput(ctx, "blah.srcjar")
}
diff --git a/java/java.go b/java/java.go
index dd04188..2236d05 100644
--- a/java/java.go
+++ b/java/java.go
@@ -27,6 +27,7 @@
"android/soong/bazel"
"android/soong/bazel/cquery"
"android/soong/remoteexec"
+ "android/soong/testing"
"android/soong/ui/metrics/bp2build_metrics_proto"
"github.com/google/blueprint"
@@ -296,15 +297,6 @@
// JacocoReportClassesFile is the path to a jar containing uninstrumented classes that will be
// instrumented by jacoco.
JacocoReportClassesFile android.Path
-
- // set of aconfig flags for all transitive libs deps
- // TODO(joeo): It would be nice if this were over in the aconfig package instead of here.
- // In order to do that, generated_java_library would need a way doing
- // collectTransitiveAconfigFiles with one of the callbacks, and having that automatically
- // propagated. If we were to clean up more of the stuff on JavaInfo that's not part of
- // core java rules (e.g. AidlIncludeDirs), then maybe adding more framework to do that would be
- // worth it.
- TransitiveAconfigFiles *android.DepSet[android.Path]
}
var JavaInfoProvider = blueprint.NewProvider(JavaInfo{})
@@ -638,9 +630,9 @@
type Library struct {
Module
- exportedProguardFlagFiles android.Paths
+ combinedExportedProguardFlagsFile android.Path
- InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths)
+ InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.InstallPaths)
}
var _ android.ApexModule = (*Library)(nil)
@@ -699,8 +691,12 @@
proguardSpecInfo := j.collectProguardSpecInfo(ctx)
ctx.SetProvider(ProguardSpecInfoProvider, proguardSpecInfo)
- j.exportedProguardFlagFiles = proguardSpecInfo.ProguardFlagsFiles.ToList()
- j.extraProguardFlagFiles = append(j.extraProguardFlagFiles, j.exportedProguardFlagFiles...)
+ exportedProguardFlagsFiles := proguardSpecInfo.ProguardFlagsFiles.ToList()
+ j.extraProguardFlagsFiles = append(j.extraProguardFlagsFiles, exportedProguardFlagsFiles...)
+
+ combinedExportedProguardFlagFile := android.PathForModuleOut(ctx, "export_proguard_flags")
+ writeCombinedProguardFlagsFile(ctx, combinedExportedProguardFlagFile, exportedProguardFlagsFiles)
+ j.combinedExportedProguardFlagsFile = combinedExportedProguardFlagFile
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
if !apexInfo.IsForPlatform() {
@@ -719,12 +715,9 @@
}
j.compile(ctx, nil, nil, nil)
- // Collect the module directory for IDE info in java/jdeps.go.
- j.modulePaths = append(j.modulePaths, ctx.ModuleDir())
-
exclusivelyForApex := !apexInfo.IsForPlatform()
if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex {
- var extraInstallDeps android.Paths
+ var extraInstallDeps android.InstallPaths
if j.InstallMixin != nil {
extraInstallDeps = j.InstallMixin(ctx, j.outputFile)
}
@@ -1228,10 +1221,12 @@
}
j.Test.generateAndroidBuildActionsWithConfig(ctx, configs)
+ ctx.SetProvider(testing.TestModuleProviderKey, testing.TestModuleProviderData{})
}
func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.generateAndroidBuildActionsWithConfig(ctx, nil)
+ ctx.SetProvider(testing.TestModuleProviderKey, testing.TestModuleProviderData{})
}
func (j *Test) generateAndroidBuildActionsWithConfig(ctx android.ModuleContext, configs []tradefed.Config) {
diff --git a/java/jdeps.go b/java/jdeps.go
index 4c8c11c..7e3a14f 100644
--- a/java/jdeps.go
+++ b/java/jdeps.go
@@ -75,7 +75,7 @@
dpInfo.Jarjar_rules = android.FirstUniqueStrings(dpInfo.Jarjar_rules)
dpInfo.Jars = android.FirstUniqueStrings(dpInfo.Jars)
dpInfo.SrcJars = android.FirstUniqueStrings(dpInfo.SrcJars)
- dpInfo.Paths = android.FirstUniqueStrings(dpInfo.Paths)
+ dpInfo.Paths = []string{ctx.ModuleDir(module)}
dpInfo.Static_libs = android.FirstUniqueStrings(dpInfo.Static_libs)
dpInfo.Libs = android.FirstUniqueStrings(dpInfo.Libs)
moduleInfos[name] = dpInfo
diff --git a/java/resourceshrinker.go b/java/resourceshrinker.go
deleted file mode 100644
index bf1b04d..0000000
--- a/java/resourceshrinker.go
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2022 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 (
- "android/soong/android"
-
- "github.com/google/blueprint"
-)
-
-var shrinkResources = pctx.AndroidStaticRule("shrinkResources",
- blueprint.RuleParams{
- // Note that we suppress stdout to avoid successful log confirmations.
- Command: `${config.ResourceShrinkerCmd} --output $out --input $in --raw_resources $raw_resources >/dev/null`,
- CommandDeps: []string{"${config.ResourceShrinkerCmd}"},
- }, "raw_resources")
-
-func ShrinkResources(ctx android.ModuleContext, apk android.Path, outputFile android.WritablePath) {
- protoFile := android.PathForModuleOut(ctx, apk.Base()+".proto.apk")
- aapt2Convert(ctx, protoFile, apk, "proto")
- strictModeFile := android.PathForSource(ctx, "prebuilts/cmdline-tools/shrinker.xml")
- protoOut := android.PathForModuleOut(ctx, apk.Base()+".proto.out.apk")
- ctx.Build(pctx, android.BuildParams{
- Rule: shrinkResources,
- Input: protoFile,
- Output: protoOut,
- Args: map[string]string{
- "raw_resources": strictModeFile.String(),
- },
- })
- aapt2Convert(ctx, outputFile, protoOut, "binary")
-}
diff --git a/java/resourceshrinker_test.go b/java/resourceshrinker_test.go
deleted file mode 100644
index 3bbf116..0000000
--- a/java/resourceshrinker_test.go
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2022 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 (
- "testing"
-
- "android/soong/android"
-)
-
-func TestShrinkResourcesArgs(t *testing.T) {
- result := android.GroupFixturePreparers(
- PrepareForTestWithJavaDefaultModules,
- ).RunTestWithBp(t, `
- android_app {
- name: "app_shrink",
- platform_apis: true,
- optimize: {
- shrink_resources: true,
- }
- }
-
- android_app {
- name: "app_no_shrink",
- platform_apis: true,
- optimize: {
- shrink_resources: false,
- }
- }
- `)
-
- appShrink := result.ModuleForTests("app_shrink", "android_common")
- appShrinkResources := appShrink.Rule("shrinkResources")
- android.AssertStringDoesContain(t, "expected shrinker.xml in app_shrink resource shrinker flags",
- appShrinkResources.Args["raw_resources"], "shrinker.xml")
-
- appNoShrink := result.ModuleForTests("app_no_shrink", "android_common")
- if appNoShrink.MaybeRule("shrinkResources").Rule != nil {
- t.Errorf("unexpected shrinkResources rule for app_no_shrink")
- }
-}
diff --git a/java/robolectric.go b/java/robolectric.go
index af56339..a66b310 100644
--- a/java/robolectric.go
+++ b/java/robolectric.go
@@ -22,6 +22,7 @@
"android/soong/android"
"android/soong/java/config"
+ "android/soong/testing"
"android/soong/tradefed"
"github.com/google/blueprint/proptools"
@@ -225,7 +226,7 @@
}
installPath := android.PathForModuleInstall(ctx, r.BaseModuleName())
- var installDeps android.Paths
+ var installDeps android.InstallPaths
if r.manifest != nil {
r.data = append(r.data, r.manifest)
@@ -253,6 +254,7 @@
}
r.installFile = ctx.InstallFile(installPath, ctx.ModuleName()+".jar", r.combinedJar, installDeps...)
+ ctx.SetProvider(testing.TestModuleProviderKey, testing.TestModuleProviderData{})
}
func generateRoboTestConfig(ctx android.ModuleContext, outputFile android.WritablePath,
diff --git a/java/sdk_library.go b/java/sdk_library.go
index ea45174..fbfe509 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -624,6 +624,13 @@
Legacy_errors_allowed *bool
}
+ // Determines if the module contributes to any api surfaces.
+ // This property should be set to true only if the module is listed under
+ // frameworks-base-api.bootclasspath in frameworks/base/api/Android.bp.
+ // Otherwise, this property should be set to false.
+ // Defaults to false.
+ Contribute_to_android_api *bool
+
// TODO: determines whether to create HTML doc or not
// Html_doc *bool
}
@@ -1966,6 +1973,10 @@
return module.uniqueApexVariations()
}
+func (module *SdkLibrary) ContributeToApi() bool {
+ return proptools.BoolDefault(module.sdkLibraryProperties.Contribute_to_android_api, false)
+}
+
// Creates the xml file that publicizes the runtime library
func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) {
moduleMinApiLevel := module.Library.MinSdkVersion(mctx)
@@ -1982,6 +1993,7 @@
Min_device_sdk *string
Max_device_sdk *string
Sdk_library_min_api_level *string
+ Uses_libs_dependencies []string
}{
Name: proptools.StringPtr(module.xmlPermissionsModuleName()),
Lib_name: proptools.StringPtr(module.BaseModuleName()),
@@ -1991,6 +2003,7 @@
Min_device_sdk: module.commonSdkLibraryProperties.Min_device_sdk,
Max_device_sdk: module.commonSdkLibraryProperties.Max_device_sdk,
Sdk_library_min_api_level: &moduleMinApiLevelStr,
+ Uses_libs_dependencies: module.usesLibraryProperties.Uses_libs,
}
mctx.CreateModule(sdkLibraryXmlFactory, &props)
@@ -2957,6 +2970,11 @@
//
// This value comes from the ApiLevel of the MinSdkVersion property.
Sdk_library_min_api_level *string
+
+ // Uses-libs dependencies that the shared library requires to work correctly.
+ //
+ // This will add dependency="foo:bar" to the <library> section.
+ Uses_libs_dependencies []string
}
// java_sdk_library_xml builds the permission xml file for a java_sdk_library.
@@ -3065,6 +3083,13 @@
return fmt.Sprintf(` %s=\"%s\"\n`, attrName, *value)
}
+func formattedDependenciesAttribute(dependencies []string) string {
+ if dependencies == nil {
+ return ""
+ }
+ return fmt.Sprintf(` dependency=\"%s\"\n`, strings.Join(dependencies, ":"))
+}
+
func (module *sdkLibraryXml) permissionsContents(ctx android.ModuleContext) string {
libName := proptools.String(module.properties.Lib_name)
libNameAttr := formattedOptionalAttribute("name", &libName)
@@ -3074,6 +3099,7 @@
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)
+ dependenciesAttr := formattedDependenciesAttribute(module.properties.Uses_libs_dependencies)
// <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
@@ -3107,6 +3133,7 @@
implicitUntilAttr,
minSdkAttr,
maxSdkAttr,
+ dependenciesAttr,
` />\n`,
`</permissions>\n`}, "")
}
diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go
index 82f8a4d..a136818 100644
--- a/java/sdk_library_test.go
+++ b/java/sdk_library_test.go
@@ -1665,3 +1665,35 @@
}
`)
}
+
+func TestSdkLibraryDependency(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ prepareForJavaTest,
+ PrepareForTestWithJavaSdkLibraryFiles,
+ FixtureWithPrebuiltApis(map[string][]string{
+ "30": {"bar", "foo"},
+ }),
+ ).RunTestWithBp(t,
+ `
+ java_sdk_library {
+ name: "foo",
+ srcs: ["a.java", "b.java"],
+ api_packages: ["foo"],
+ }
+
+ java_sdk_library {
+ name: "bar",
+ srcs: ["c.java", "b.java"],
+ libs: [
+ "foo",
+ ],
+ uses_libs: [
+ "foo",
+ ],
+ }
+`)
+
+ barPermissions := result.ModuleForTests("bar.xml", "android_common").Rule("java_sdk_xml")
+
+ android.AssertStringDoesContain(t, "bar.xml java_sdk_xml command", barPermissions.RuleParams.Command, `dependency=\"foo\"`)
+}
diff --git a/java/systemserver_classpath_fragment.go b/java/systemserver_classpath_fragment.go
index 17d301b..30dd55f 100644
--- a/java/systemserver_classpath_fragment.go
+++ b/java/systemserver_classpath_fragment.go
@@ -87,9 +87,6 @@
ClasspathFragmentBase
properties systemServerClasspathFragmentProperties
-
- // Collect the module directory for IDE info in java/jdeps.go.
- modulePaths []string
}
func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
@@ -129,9 +126,6 @@
configuredJars = configuredJars.AppendList(&standaloneConfiguredJars)
classpathJars = append(classpathJars, standaloneClasspathJars...)
s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
-
- // Collect the module directory for IDE info in java/jdeps.go.
- s.modulePaths = append(s.modulePaths, ctx.ModuleDir())
}
func (s *SystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
@@ -242,7 +236,6 @@
func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) {
dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...)
dpInfo.Deps = append(dpInfo.Deps, s.properties.Standalone_contents...)
- dpInfo.Paths = append(dpInfo.Paths, s.modulePaths...)
}
type systemServerClasspathFragmentMemberType struct {
diff --git a/java/test_spec_test.go b/java/test_spec_test.go
new file mode 100644
index 0000000..39aff4c
--- /dev/null
+++ b/java/test_spec_test.go
@@ -0,0 +1,133 @@
+package java
+
+import (
+ "strings"
+ "testing"
+
+ "android/soong/android"
+ soongTesting "android/soong/testing"
+ "android/soong/testing/test_spec_proto"
+ "google.golang.org/protobuf/proto"
+)
+
+func TestTestSpec(t *testing.T) {
+ bp := `test_spec {
+ name: "module-name",
+ teamId: "12345",
+ tests: [
+ "java-test-module-name-one",
+ "java-test-module-name-two"
+ ]
+ }
+
+ java_test {
+ name: "java-test-module-name-one",
+ }
+
+ java_test {
+ name: "java-test-module-name-two",
+ }`
+ result := runTest(t, android.FixtureExpectsNoErrors, bp)
+
+ module := result.ModuleForTests(
+ "module-name", "",
+ ).Module().(*soongTesting.TestSpecModule)
+
+ // Check that the provider has the right contents
+ data := result.ModuleProvider(
+ module, soongTesting.TestSpecProviderKey,
+ ).(soongTesting.TestSpecProviderData)
+ if !strings.HasSuffix(
+ data.IntermediatePath.String(), "/intermediateTestSpecMetadata.pb",
+ ) {
+ t.Errorf(
+ "Missing intermediates path in provider: %s",
+ data.IntermediatePath.String(),
+ )
+ }
+
+ buildParamsSlice := module.BuildParamsForTests()
+ var metadata = ""
+ for _, params := range buildParamsSlice {
+ if params.Rule.String() == "android/soong/android.writeFile" {
+ metadata = params.Args["content"]
+ }
+ }
+
+ metadataList := make([]*test_spec_proto.TestSpec_OwnershipMetadata, 0, 2)
+ teamId := "12345"
+ bpFilePath := "Android.bp"
+ targetNames := []string{
+ "java-test-module-name-one", "java-test-module-name-two",
+ }
+
+ for _, test := range targetNames {
+ targetName := test
+ metadata := test_spec_proto.TestSpec_OwnershipMetadata{
+ TrendyTeamId: &teamId,
+ TargetName: &targetName,
+ Path: &bpFilePath,
+ }
+ metadataList = append(metadataList, &metadata)
+ }
+ testSpecMetadata := test_spec_proto.TestSpec{OwnershipMetadataList: metadataList}
+ protoData, _ := proto.Marshal(&testSpecMetadata)
+ rawData := string(protoData)
+ formattedData := strings.ReplaceAll(rawData, "\n", "\\n")
+ expectedMetadata := "'" + formattedData + "\\n'"
+
+ if metadata != expectedMetadata {
+ t.Errorf(
+ "Retrieved metadata: %s is not equal to expectedMetadata: %s", metadata,
+ expectedMetadata,
+ )
+ }
+
+ // Tests for all_test_spec singleton.
+ singleton := result.SingletonForTests("all_test_specs")
+ rule := singleton.Rule("all_test_specs_rule")
+ prebuiltOs := result.Config.PrebuiltOS()
+ expectedCmd := "out/soong/host/" + prebuiltOs + "/bin/metadata -rule test_spec -inputFile out/soong/all_test_spec_paths.rsp -outputFile out/soong/ownership/all_test_specs.pb"
+ expectedOutputFile := "out/soong/ownership/all_test_specs.pb"
+ expectedInputFile := "out/soong/.intermediates/module-name/intermediateTestSpecMetadata.pb"
+ if !strings.Contains(
+ strings.TrimSpace(rule.Output.String()),
+ expectedOutputFile,
+ ) {
+ t.Errorf(
+ "Retrieved singletonOutputFile: %s is not equal to expectedSingletonOutputFile: %s",
+ rule.Output.String(), expectedOutputFile,
+ )
+ }
+
+ if !strings.Contains(
+ strings.TrimSpace(rule.Inputs[0].String()),
+ expectedInputFile,
+ ) {
+ t.Errorf(
+ "Retrieved singletonInputFile: %s is not equal to expectedSingletonInputFile: %s",
+ rule.Inputs[0].String(), expectedInputFile,
+ )
+ }
+
+ if !strings.Contains(
+ strings.TrimSpace(rule.RuleParams.Command),
+ expectedCmd,
+ ) {
+ t.Errorf(
+ "Retrieved cmd: %s is not equal to expectedCmd: %s",
+ rule.RuleParams.Command, expectedCmd,
+ )
+ }
+}
+
+func runTest(
+ t *testing.T, errorHandler android.FixtureErrorHandler, bp string,
+) *android.TestResult {
+ return android.GroupFixturePreparers(
+ soongTesting.PrepareForTestWithTestSpecBuildComponents,
+ PrepareForIntegrationTestWithJava,
+ ).
+ ExtendWithErrorHandler(errorHandler).
+ RunTestWithBp(t, bp)
+}
diff --git a/java/tradefed.go b/java/tradefed.go
index ebbdec1..349b327 100644
--- a/java/tradefed.go
+++ b/java/tradefed.go
@@ -30,8 +30,8 @@
return module
}
-func tradefedJavaLibraryInstall(ctx android.ModuleContext, path android.Path) android.Paths {
+func tradefedJavaLibraryInstall(ctx android.ModuleContext, path android.Path) android.InstallPaths {
installedPath := ctx.InstallFile(android.PathForModuleInstall(ctx, "tradefed"),
ctx.ModuleName()+".jar", path)
- return android.Paths{installedPath}
+ return android.InstallPaths{installedPath}
}
diff --git a/kernel/prebuilt_kernel_modules.go b/kernel/prebuilt_kernel_modules.go
index 5bcca04..e200ee2 100644
--- a/kernel/prebuilt_kernel_modules.go
+++ b/kernel/prebuilt_kernel_modules.go
@@ -50,6 +50,9 @@
// Kernel version that these modules are for. Kernel modules are installed to
// /lib/modules/<kernel_version> directory in the corresponding partition. Default is "".
Kernel_version *string
+
+ // Whether this module is directly installable to one of the partitions. Default is true
+ Installable *bool
}
// prebuilt_kernel_modules installs a set of prebuilt kernel module files to the correct directory.
@@ -62,6 +65,10 @@
return module
}
+func (pkm *prebuiltKernelModules) installable() bool {
+ return proptools.BoolDefault(pkm.properties.Installable, true)
+}
+
func (pkm *prebuiltKernelModules) KernelVersion() string {
return proptools.StringDefault(pkm.properties.Kernel_version, "")
}
@@ -71,6 +78,9 @@
}
func (pkm *prebuiltKernelModules) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ if !pkm.installable() {
+ pkm.SkipInstall()
+ }
modules := android.PathsForModuleSrc(ctx, pkm.properties.Srcs)
depmodOut := runDepmod(ctx, modules)
diff --git a/phony/phony.go b/phony/phony.go
index 760b79b..a8b651a 100644
--- a/phony/phony.go
+++ b/phony/phony.go
@@ -52,7 +52,6 @@
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)", " # phony.phony")
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
fmt.Fprintln(w, "LOCAL_MODULE :=", name)
- data.Entries.WriteLicenseVariables(w)
if p.Host() {
fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
}
diff --git a/python/Android.bp b/python/Android.bp
index 7578673..87810c9 100644
--- a/python/Android.bp
+++ b/python/Android.bp
@@ -10,6 +10,7 @@
"soong-android",
"soong-tradefed",
"soong-cc",
+ "soong-testing",
],
srcs: [
"binary.go",
diff --git a/python/test.go b/python/test.go
index 6e23a44..cd7c73b 100644
--- a/python/test.go
+++ b/python/test.go
@@ -17,6 +17,7 @@
import (
"fmt"
+ "android/soong/testing"
"github.com/google/blueprint/proptools"
"android/soong/android"
@@ -205,6 +206,7 @@
p.data = append(p.data, android.DataPath{SrcPath: javaDataSrcPath})
}
}
+ ctx.SetProvider(testing.TestModuleProviderKey, testing.TestModuleProviderData{})
}
func (p *PythonTestModule) AndroidMkEntries() []android.AndroidMkEntries {
diff --git a/remoteexec/remoteexec.go b/remoteexec/remoteexec.go
index 690b47b..8294c3f 100644
--- a/remoteexec/remoteexec.go
+++ b/remoteexec/remoteexec.go
@@ -30,7 +30,7 @@
// DefaultImage is the default container image used for Android remote execution. The
// image was built with the Dockerfile at
// https://android.googlesource.com/platform/prebuilts/remoteexecution-client/+/refs/heads/master/docker/Dockerfile
- DefaultImage = "docker://gcr.io/androidbuild-re-dockerimage/android-build-remoteexec-image@sha256:953fed4a6b2501256a0d17f055dc17884ff71b024e50ade773e0b348a6c303e6"
+ DefaultImage = "docker://gcr.io/androidbuild-re-dockerimage/android-build-remoteexec-image@sha256:1eb7f64b9e17102b970bd7a1af7daaebdb01c3fb777715899ef462d6c6d01a45"
// DefaultWrapperPath is the default path to the remote execution wrapper.
DefaultWrapperPath = "prebuilts/remoteexecution-client/live/rewrapper"
@@ -91,6 +91,8 @@
NumLocalRuns int
// Number of times the action should be rerun remotely.
NumRemoteRuns int
+ // Boolean indicating whether to update remote cache entry. Rewrapper defaults to true, so the name is negated here.
+ NoRemoteUpdateCache bool
}
func init() {
@@ -146,6 +148,10 @@
args += fmt.Sprintf(" --compare=true --num_local_reruns=%d --num_remote_reruns=%d", r.NumLocalRuns, r.NumRemoteRuns)
}
+ if r.NoRemoteUpdateCache {
+ args += " --remote_update_cache=false"
+ }
+
if len(r.Inputs) > 0 {
args += " --inputs=" + strings.Join(r.Inputs, ",")
}
diff --git a/rust/Android.bp b/rust/Android.bp
index b01a94a..c5b2000 100644
--- a/rust/Android.bp
+++ b/rust/Android.bp
@@ -12,6 +12,7 @@
"soong-cc",
"soong-rust-config",
"soong-snapshot",
+ "soong-testing",
],
srcs: [
"afdo.go",
diff --git a/rust/binary.go b/rust/binary.go
index 860dc94..5e7e922 100644
--- a/rust/binary.go
+++ b/rust/binary.go
@@ -137,12 +137,7 @@
fileName := binary.getStem(ctx) + ctx.toolchain().ExecutableSuffix()
outputFile := android.PathForModuleOut(ctx, fileName)
ret := buildOutput{outputFile: outputFile}
- var crateRootPath android.Path
- if binary.baseCompiler.Properties.Crate_root == nil {
- crateRootPath, _ = srcPathFromModuleSrcs(ctx, binary.baseCompiler.Properties.Srcs)
- } else {
- crateRootPath = android.PathForModuleSrc(ctx, *binary.baseCompiler.Properties.Crate_root)
- }
+ crateRootPath := crateRootPath(ctx, binary)
flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
flags.LinkFlags = append(flags.LinkFlags, deps.depLinkFlags...)
diff --git a/rust/builder.go b/rust/builder.go
index 162d1aa..c855cfb 100644
--- a/rust/builder.go
+++ b/rust/builder.go
@@ -196,7 +196,7 @@
}
if len(deps.SrcDeps) > 0 {
- moduleGenDir := ctx.RustModule().compiler.CargoOutDir()
+ moduleGenDir := ctx.RustModule().compiler.cargoOutDir()
// We must calculate an absolute path for OUT_DIR since Rust's include! macro (which normally consumes this)
// assumes that paths are relative to the source file.
var outDirPrefix string
@@ -215,13 +215,13 @@
envVars = append(envVars, "ANDROID_RUST_VERSION="+config.GetRustVersion(ctx))
- if ctx.RustModule().compiler.CargoEnvCompat() {
+ if ctx.RustModule().compiler.cargoEnvCompat() {
if bin, ok := ctx.RustModule().compiler.(*binaryDecorator); ok {
envVars = append(envVars, "CARGO_BIN_NAME="+bin.getStem(ctx))
}
envVars = append(envVars, "CARGO_CRATE_NAME="+ctx.RustModule().CrateName())
envVars = append(envVars, "CARGO_PKG_NAME="+ctx.RustModule().CrateName())
- pkgVersion := ctx.RustModule().compiler.CargoPkgVersion()
+ pkgVersion := ctx.RustModule().compiler.cargoPkgVersion()
if pkgVersion != "" {
envVars = append(envVars, "CARGO_PKG_VERSION="+pkgVersion)
@@ -327,7 +327,7 @@
orderOnly = append(orderOnly, deps.SharedLibs...)
if len(deps.SrcDeps) > 0 {
- moduleGenDir := ctx.RustModule().compiler.CargoOutDir()
+ moduleGenDir := ctx.RustModule().compiler.cargoOutDir()
var outputs android.WritablePaths
for _, genSrc := range deps.SrcDeps {
diff --git a/rust/compiler.go b/rust/compiler.go
index b3f574d..d453a5d 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -16,6 +16,7 @@
import (
"android/soong/cc"
+ "errors"
"fmt"
"path/filepath"
"strings"
@@ -34,6 +35,48 @@
DylibLinkage
)
+type compiler interface {
+ initialize(ctx ModuleContext)
+ compilerFlags(ctx ModuleContext, flags Flags) Flags
+ cfgFlags(ctx ModuleContext, flags Flags) Flags
+ featureFlags(ctx ModuleContext, flags Flags) Flags
+ compilerProps() []interface{}
+ compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput
+ compilerDeps(ctx DepsContext, deps Deps) Deps
+ crateName() string
+ edition() string
+ features() []string
+ rustdoc(ctx ModuleContext, flags Flags, deps PathDeps) android.OptionalPath
+
+ // Output directory in which source-generated code from dependencies is
+ // copied. This is equivalent to Cargo's OUT_DIR variable.
+ cargoOutDir() android.OptionalPath
+
+ // cargoPkgVersion returns the value of the Cargo_pkg_version property.
+ cargoPkgVersion() string
+
+ // cargoEnvCompat returns whether Cargo environment variables should be used.
+ cargoEnvCompat() bool
+
+ inData() bool
+ install(ctx ModuleContext)
+ relativeInstallPath() string
+ everInstallable() bool
+
+ nativeCoverage() bool
+
+ Disabled() bool
+ SetDisabled()
+
+ stdLinkage(ctx *depsContext) RustLinkage
+ noStdlibs() bool
+
+ unstrippedOutputFilePath() android.Path
+ strippedOutputFilePath() android.OptionalPath
+
+ checkedCrateRootPath() (android.Path, error)
+}
+
func (compiler *baseCompiler) edition() string {
return proptools.StringDefault(compiler.Properties.Edition, config.DefaultEdition)
}
@@ -160,7 +203,7 @@
Relative_install_path *string `android:"arch_variant"`
// whether to suppress inclusion of standard crates - defaults to false
- No_stdlibs *bool
+ No_stdlibs *bool `android:"arch_variant"`
// Change the rustlibs linkage to select rlib linkage by default for device targets.
// Also link libstd as an rlib as well on device targets.
@@ -204,7 +247,16 @@
// If a crate has a source-generated dependency, a copy of the source file
// will be available in cargoOutDir (equivalent to Cargo OUT_DIR).
- cargoOutDir android.ModuleOutPath
+ // This is stored internally because it may not be available during
+ // singleton-generation passes like rustdoc/rust_project.json, but should
+ // be stashed during initial generation.
+ cachedCargoOutDir android.ModuleOutPath
+ // Calculated crate root cached internally because ModuleContext is not
+ // available to singleton targets like rustdoc/rust_project.json
+ cachedCrateRootPath android.Path
+ // If cachedCrateRootPath is nil after initialization, this will contain
+ // an explanation of why
+ cachedCrateRootError error
}
func (compiler *baseCompiler) Disabled() bool {
@@ -257,9 +309,13 @@
return flags
}
+func (compiler *baseCompiler) features() []string {
+ return compiler.Properties.Features
+}
+
func (compiler *baseCompiler) featuresToFlags() []string {
flags := []string{}
- for _, feature := range compiler.Properties.Features {
+ for _, feature := range compiler.features() {
flags = append(flags, "--cfg 'feature=\""+feature+"\"'")
}
@@ -355,18 +411,24 @@
}
func (compiler *baseCompiler) initialize(ctx ModuleContext) {
- compiler.cargoOutDir = android.PathForModuleOut(ctx, genSubDir)
+ compiler.cachedCargoOutDir = android.PathForModuleOut(ctx, genSubDir)
+ if compiler.Properties.Crate_root == nil {
+ compiler.cachedCrateRootPath, compiler.cachedCrateRootError = srcPathFromModuleSrcs(ctx, compiler.Properties.Srcs)
+ } else {
+ compiler.cachedCrateRootPath = android.PathForModuleSrc(ctx, *compiler.Properties.Crate_root)
+ compiler.cachedCrateRootError = nil
+ }
}
-func (compiler *baseCompiler) CargoOutDir() android.OptionalPath {
- return android.OptionalPathForPath(compiler.cargoOutDir)
+func (compiler *baseCompiler) cargoOutDir() android.OptionalPath {
+ return android.OptionalPathForPath(compiler.cachedCargoOutDir)
}
-func (compiler *baseCompiler) CargoEnvCompat() bool {
+func (compiler *baseCompiler) cargoEnvCompat() bool {
return Bool(compiler.Properties.Cargo_env_compat)
}
-func (compiler *baseCompiler) CargoPkgVersion() string {
+func (compiler *baseCompiler) cargoPkgVersion() string {
return String(compiler.Properties.Cargo_pkg_version)
}
@@ -496,12 +558,20 @@
return String(compiler.Properties.Relative_install_path)
}
-// Returns the Path for the main source file along with Paths for generated source files from modules listed in srcs.
-func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) (android.Path, android.Paths) {
- if len(srcs) == 0 {
- ctx.PropertyErrorf("srcs", "srcs must not be empty")
- }
+func (compiler *baseCompiler) checkedCrateRootPath() (android.Path, error) {
+ return compiler.cachedCrateRootPath, compiler.cachedCrateRootError
+}
+func crateRootPath(ctx ModuleContext, compiler compiler) android.Path {
+ root, err := compiler.checkedCrateRootPath()
+ if err != nil {
+ ctx.PropertyErrorf("srcs", err.Error())
+ }
+ return root
+}
+
+// Returns the Path for the main source file along with Paths for generated source files from modules listed in srcs.
+func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) (android.Path, error) {
// The srcs can contain strings with prefix ":".
// They are dependent modules of this module, with android.SourceDepTag.
// They are not the main source file compiled by rustc.
@@ -514,19 +584,22 @@
}
}
if numSrcs > 1 {
- ctx.PropertyErrorf("srcs", incorrectSourcesError)
+ return nil, errors.New(incorrectSourcesError)
}
// If a main source file is not provided we expect only a single SourceProvider module to be defined
// within srcs, with the expectation that the first source it provides is the entry point.
if srcIndex != 0 {
- ctx.PropertyErrorf("srcs", "main source file must be the first in srcs")
+ return nil, errors.New("main source file must be the first in srcs")
} else if numSrcs > 1 {
- ctx.PropertyErrorf("srcs", "only a single generated source module can be defined without a main source file.")
+ return nil, errors.New("only a single generated source module can be defined without a main source file.")
}
// TODO: b/297264540 - once all modules are sandboxed, we need to select the proper
// entry point file from Srcs rather than taking the first one
paths := android.PathsForModuleSrc(ctx, srcs)
- return paths[srcIndex], paths[1:]
+ if len(paths) == 0 {
+ return nil, errors.New("srcs must not be empty")
+ }
+ return paths[srcIndex], nil
}
diff --git a/rust/compiler_test.go b/rust/compiler_test.go
index ec6829a..89f4d1a 100644
--- a/rust/compiler_test.go
+++ b/rust/compiler_test.go
@@ -67,6 +67,7 @@
func TestEnforceSingleSourceFile(t *testing.T) {
singleSrcError := "srcs can only contain one path for a rust file and source providers prefixed by \":\""
+ prebuiltSingleSrcError := "prebuilt libraries can only have one entry in srcs"
// Test libraries
testRustError(t, singleSrcError, `
@@ -90,7 +91,7 @@
}`)
// Test prebuilts
- testRustError(t, singleSrcError, `
+ testRustError(t, prebuiltSingleSrcError, `
rust_prebuilt_dylib {
name: "foo-bar-prebuilt",
srcs: ["liby.so", "libz.so"],
diff --git a/rust/config/global.go b/rust/config/global.go
index 64c9460..3e189b5 100644
--- a/rust/config/global.go
+++ b/rust/config/global.go
@@ -25,7 +25,7 @@
pctx = android.NewPackageContext("android/soong/rust/config")
ExportedVars = android.NewExportedVariables(pctx)
- RustDefaultVersion = "1.72.1"
+ RustDefaultVersion = "1.73.0"
RustDefaultBase = "prebuilts/rust/"
DefaultEdition = "2021"
Stdlibs = []string{
@@ -72,6 +72,8 @@
"-C panic=abort",
// Generate additional debug info for AutoFDO
"-Z debug-info-for-profiling",
+ // Android has ELF TLS on platform
+ "-Z tls-model=global-dynamic",
}
deviceGlobalLinkFlags = []string{
diff --git a/rust/library.go b/rust/library.go
index 18bf0a0..c0ff741 100644
--- a/rust/library.go
+++ b/rust/library.go
@@ -15,6 +15,7 @@
package rust
import (
+ "errors"
"fmt"
"regexp"
"strings"
@@ -489,7 +490,7 @@
var outputFile android.ModuleOutPath
var ret buildOutput
var fileName string
- crateRootPath := library.crateRootPath(ctx, deps)
+ crateRootPath := crateRootPath(ctx, library)
if library.sourceProvider != nil {
deps.srcProviderFiles = append(deps.srcProviderFiles, library.sourceProvider.Srcs()...)
@@ -584,15 +585,16 @@
return ret
}
-func (library *libraryDecorator) crateRootPath(ctx ModuleContext, _ PathDeps) android.Path {
+func (library *libraryDecorator) checkedCrateRootPath() (android.Path, error) {
if library.sourceProvider != nil {
+ srcs := library.sourceProvider.Srcs()
+ if len(srcs) == 0 {
+ return nil, errors.New("Source provider generated 0 sources")
+ }
// Assume the first source from the source provider is the library entry point.
- return library.sourceProvider.Srcs()[0]
- } else if library.baseCompiler.Properties.Crate_root == nil {
- path, _ := srcPathFromModuleSrcs(ctx, library.baseCompiler.Properties.Srcs)
- return path
+ return srcs[0], nil
} else {
- return android.PathForModuleSrc(ctx, *library.baseCompiler.Properties.Crate_root)
+ return library.baseCompiler.checkedCrateRootPath()
}
}
@@ -607,7 +609,7 @@
return android.OptionalPath{}
}
- return android.OptionalPathForPath(Rustdoc(ctx, library.crateRootPath(ctx, deps),
+ return android.OptionalPathForPath(Rustdoc(ctx, crateRootPath(ctx, library),
deps, flags))
}
diff --git a/rust/prebuilt.go b/rust/prebuilt.go
index fe9d0b5..e35e510 100644
--- a/rust/prebuilt.go
+++ b/rust/prebuilt.go
@@ -76,6 +76,17 @@
var _ exportedFlagsProducer = (*prebuiltProcMacroDecorator)(nil)
var _ rustPrebuilt = (*prebuiltProcMacroDecorator)(nil)
+func prebuiltPath(ctx ModuleContext, prebuilt rustPrebuilt) android.Path {
+ srcs := android.PathsForModuleSrc(ctx, prebuilt.prebuiltSrcs())
+ if len(srcs) == 0 {
+ ctx.PropertyErrorf("srcs", "srcs must not be empty")
+ }
+ if len(srcs) > 1 {
+ ctx.PropertyErrorf("srcs", "prebuilt libraries can only have one entry in srcs (the prebuilt path)")
+ }
+ return srcs[0]
+}
+
func PrebuiltLibraryFactory() android.Module {
module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
return module.Init()
@@ -148,11 +159,7 @@
func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
prebuilt.flagExporter.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...)
prebuilt.flagExporter.setProvider(ctx)
-
- srcPath, paths := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs())
- if len(paths) > 0 {
- ctx.PropertyErrorf("srcs", "prebuilt libraries can only have one entry in srcs (the prebuilt path)")
- }
+ srcPath := prebuiltPath(ctx, prebuilt)
prebuilt.baseCompiler.unstrippedOutputFile = srcPath
return buildOutput{outputFile: srcPath}
}
@@ -205,11 +212,7 @@
func (prebuilt *prebuiltProcMacroDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
prebuilt.flagExporter.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...)
prebuilt.flagExporter.setProvider(ctx)
-
- srcPath, paths := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs())
- if len(paths) > 0 {
- ctx.PropertyErrorf("srcs", "prebuilt libraries can only have one entry in srcs (the prebuilt path)")
- }
+ srcPath := prebuiltPath(ctx, prebuilt)
prebuilt.baseCompiler.unstrippedOutputFile = srcPath
return buildOutput{outputFile: srcPath}
}
diff --git a/rust/proc_macro.go b/rust/proc_macro.go
index b93b24f..c18d5ec 100644
--- a/rust/proc_macro.go
+++ b/rust/proc_macro.go
@@ -78,8 +78,7 @@
func (procMacro *procMacroDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
fileName := procMacro.getStem(ctx) + ctx.toolchain().ProcMacroSuffix()
outputFile := android.PathForModuleOut(ctx, fileName)
-
- srcPath, _ := srcPathFromModuleSrcs(ctx, procMacro.baseCompiler.Properties.Srcs)
+ srcPath := crateRootPath(ctx, procMacro)
ret := TransformSrctoProcMacro(ctx, srcPath, deps, flags, outputFile)
procMacro.baseCompiler.unstrippedOutputFile = outputFile
return ret
diff --git a/rust/project_json.go b/rust/project_json.go
index 40aa7c7..ad9b690 100644
--- a/rust/project_json.go
+++ b/rust/project_json.go
@@ -17,7 +17,6 @@
import (
"encoding/json"
"fmt"
- "path"
"android/soong/android"
)
@@ -60,8 +59,9 @@
// crateInfo is used during the processing to keep track of the known crates.
type crateInfo struct {
- Idx int // Index of the crate in rustProjectJson.Crates slice.
- Deps map[string]int // The keys are the module names and not the crate names.
+ Idx int // Index of the crate in rustProjectJson.Crates slice.
+ Deps map[string]int // The keys are the module names and not the crate names.
+ Device bool // True if the crate at idx was a device crate
}
type projectGeneratorSingleton struct {
@@ -77,85 +77,6 @@
android.RegisterParallelSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
}
-// sourceProviderVariantSource returns the path to the source file if this
-// module variant should be used as a priority.
-//
-// SourceProvider modules may have multiple variants considered as source
-// (e.g., x86_64 and armv8). For a module available on device, use the source
-// generated for the target. For a host-only module, use the source generated
-// for the host.
-func sourceProviderVariantSource(ctx android.SingletonContext, rModule *Module) (string, bool) {
- rustLib, ok := rModule.compiler.(*libraryDecorator)
- if !ok {
- return "", false
- }
- if rustLib.source() {
- switch rModule.hod {
- case android.HostSupported, android.HostSupportedNoCross:
- if rModule.Target().String() == ctx.Config().BuildOSTarget.String() {
- src := rustLib.sourceProvider.Srcs()[0]
- return src.String(), true
- }
- default:
- if rModule.Target().String() == ctx.Config().AndroidFirstDeviceTarget.String() {
- src := rustLib.sourceProvider.Srcs()[0]
- return src.String(), true
- }
- }
- }
- return "", false
-}
-
-// sourceProviderSource finds the main source file of a source-provider crate.
-func sourceProviderSource(ctx android.SingletonContext, rModule *Module) (string, bool) {
- rustLib, ok := rModule.compiler.(*libraryDecorator)
- if !ok {
- return "", false
- }
- if rustLib.source() {
- // This is a source-variant, check if we are the right variant
- // depending on the module configuration.
- if src, ok := sourceProviderVariantSource(ctx, rModule); ok {
- return src, true
- }
- }
- foundSource := false
- sourceSrc := ""
- // Find the variant with the source and return its.
- ctx.VisitAllModuleVariants(rModule, func(variant android.Module) {
- if foundSource {
- return
- }
- // All variants of a source provider library are libraries.
- rVariant, _ := variant.(*Module)
- variantLib, _ := rVariant.compiler.(*libraryDecorator)
- if variantLib.source() {
- sourceSrc, ok = sourceProviderVariantSource(ctx, rVariant)
- if ok {
- foundSource = true
- }
- }
- })
- if !foundSource {
- ctx.Errorf("No valid source for source provider found: %v\n", rModule)
- }
- return sourceSrc, foundSource
-}
-
-// crateSource finds the main source file (.rs) for a crate.
-func crateSource(ctx android.SingletonContext, rModule *Module, comp *baseCompiler) (string, bool) {
- // Basic libraries, executables and tests.
- srcs := comp.Properties.Srcs
- if len(srcs) != 0 {
- return path.Join(ctx.ModuleDir(rModule), srcs[0]), true
- }
- // SourceProvider libraries.
- if rModule.sourceProvider != nil {
- return sourceProviderSource(ctx, rModule)
- }
- return "", false
-}
-
// mergeDependencies visits all the dependencies for module and updates crate and deps
// with any new dependency.
func (singleton *projectGeneratorSingleton) mergeDependencies(ctx android.SingletonContext,
@@ -167,7 +88,7 @@
return
}
// Skip unsupported modules.
- rChild, compChild, ok := isModuleSupported(ctx, child)
+ rChild, ok := isModuleSupported(ctx, child)
if !ok {
return
}
@@ -175,7 +96,7 @@
var childId int
cInfo, known := singleton.knownCrates[rChild.Name()]
if !known {
- childId, ok = singleton.addCrate(ctx, rChild, compChild)
+ childId, ok = singleton.addCrate(ctx, rChild, make(map[string]int))
if !ok {
return
}
@@ -191,41 +112,25 @@
})
}
-// isModuleSupported returns the RustModule and baseCompiler if the module
+// isModuleSupported returns the RustModule if the module
// should be considered for inclusion in rust-project.json.
-func isModuleSupported(ctx android.SingletonContext, module android.Module) (*Module, *baseCompiler, bool) {
+func isModuleSupported(ctx android.SingletonContext, module android.Module) (*Module, bool) {
rModule, ok := module.(*Module)
if !ok {
- return nil, nil, false
+ return nil, false
}
- if rModule.compiler == nil {
- return nil, nil, false
+ if !rModule.Enabled() {
+ return nil, false
}
- var comp *baseCompiler
- switch c := rModule.compiler.(type) {
- case *libraryDecorator:
- comp = c.baseCompiler
- case *binaryDecorator:
- comp = c.baseCompiler
- case *testDecorator:
- comp = c.binaryDecorator.baseCompiler
- case *procMacroDecorator:
- comp = c.baseCompiler
- case *toolchainLibraryDecorator:
- comp = c.baseCompiler
- default:
- return nil, nil, false
- }
- return rModule, comp, true
+ return rModule, true
}
// addCrate adds a crate to singleton.project.Crates ensuring that required
// dependencies are also added. It returns the index of the new crate in
// singleton.project.Crates
-func (singleton *projectGeneratorSingleton) addCrate(ctx android.SingletonContext, rModule *Module, comp *baseCompiler) (int, bool) {
- rootModule, ok := crateSource(ctx, rModule, comp)
- if !ok {
- ctx.Errorf("Unable to find source for valid module: %v", rModule)
+func (singleton *projectGeneratorSingleton) addCrate(ctx android.SingletonContext, rModule *Module, deps map[string]int) (int, bool) {
+ rootModule, err := rModule.compiler.checkedCrateRootPath()
+ if err != nil {
return 0, false
}
@@ -233,28 +138,33 @@
crate := rustProjectCrate{
DisplayName: rModule.Name(),
- RootModule: rootModule,
- Edition: comp.edition(),
+ RootModule: rootModule.String(),
+ Edition: rModule.compiler.edition(),
Deps: make([]rustProjectDep, 0),
Cfg: make([]string, 0),
Env: make(map[string]string),
ProcMacro: procMacro,
}
- if comp.CargoOutDir().Valid() {
- crate.Env["OUT_DIR"] = comp.CargoOutDir().String()
+ if rModule.compiler.cargoOutDir().Valid() {
+ crate.Env["OUT_DIR"] = rModule.compiler.cargoOutDir().String()
}
- for _, feature := range comp.Properties.Features {
+ for _, feature := range rModule.compiler.features() {
crate.Cfg = append(crate.Cfg, "feature=\""+feature+"\"")
}
- deps := make(map[string]int)
singleton.mergeDependencies(ctx, rModule, &crate, deps)
- idx := len(singleton.project.Crates)
- singleton.knownCrates[rModule.Name()] = crateInfo{Idx: idx, Deps: deps}
- singleton.project.Crates = append(singleton.project.Crates, crate)
+ var idx int
+ if cInfo, ok := singleton.knownCrates[rModule.Name()]; ok {
+ idx = cInfo.Idx
+ singleton.project.Crates[idx] = crate
+ } else {
+ idx = len(singleton.project.Crates)
+ singleton.project.Crates = append(singleton.project.Crates, crate)
+ }
+ singleton.knownCrates[rModule.Name()] = crateInfo{Idx: idx, Deps: deps, Device: rModule.Device()}
return idx, true
}
@@ -262,18 +172,23 @@
// It visits the dependencies of the module depth-first so the dependency ID can be added to the current module. If the
// current module is already in singleton.knownCrates, its dependencies are merged.
func (singleton *projectGeneratorSingleton) appendCrateAndDependencies(ctx android.SingletonContext, module android.Module) {
- rModule, comp, ok := isModuleSupported(ctx, module)
+ rModule, ok := isModuleSupported(ctx, module)
if !ok {
return
}
// If we have seen this crate already; merge any new dependencies.
if cInfo, ok := singleton.knownCrates[module.Name()]; ok {
+ // If we have a new device variant, override the old one
+ if !cInfo.Device && rModule.Device() {
+ singleton.addCrate(ctx, rModule, cInfo.Deps)
+ return
+ }
crate := singleton.project.Crates[cInfo.Idx]
singleton.mergeDependencies(ctx, rModule, &crate, cInfo.Deps)
singleton.project.Crates[cInfo.Idx] = crate
return
}
- singleton.addCrate(ctx, rModule, comp)
+ singleton.addCrate(ctx, rModule, make(map[string]int))
}
func (singleton *projectGeneratorSingleton) GenerateBuildActions(ctx android.SingletonContext) {
diff --git a/rust/rust.go b/rust/rust.go
index 19c5230..d4d33c7 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -20,6 +20,7 @@
"android/soong/bazel"
"android/soong/bloaty"
+ "android/soong/testing"
"android/soong/ui/metrics/bp2build_metrics_proto"
"github.com/google/blueprint"
@@ -144,8 +145,9 @@
Properties BaseProperties
- hod android.HostOrDeviceSupported
- multilib android.Multilib
+ hod android.HostOrDeviceSupported
+ multilib android.Multilib
+ testModule bool
makeLinkType string
@@ -485,44 +487,6 @@
CrateName string
}
-type compiler interface {
- initialize(ctx ModuleContext)
- compilerFlags(ctx ModuleContext, flags Flags) Flags
- cfgFlags(ctx ModuleContext, flags Flags) Flags
- featureFlags(ctx ModuleContext, flags Flags) Flags
- compilerProps() []interface{}
- compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput
- compilerDeps(ctx DepsContext, deps Deps) Deps
- crateName() string
- rustdoc(ctx ModuleContext, flags Flags, deps PathDeps) android.OptionalPath
-
- // Output directory in which source-generated code from dependencies is
- // copied. This is equivalent to Cargo's OUT_DIR variable.
- CargoOutDir() android.OptionalPath
-
- // CargoPkgVersion returns the value of the Cargo_pkg_version property.
- CargoPkgVersion() string
-
- // CargoEnvCompat returns whether Cargo environment variables should be used.
- CargoEnvCompat() bool
-
- inData() bool
- install(ctx ModuleContext)
- relativeInstallPath() string
- everInstallable() bool
-
- nativeCoverage() bool
-
- Disabled() bool
- SetDisabled()
-
- stdLinkage(ctx *depsContext) RustLinkage
- noStdlibs() bool
-
- unstrippedOutputFilePath() android.Path
- strippedOutputFilePath() android.OptionalPath
-}
-
type exportedFlagsProducer interface {
exportLinkDirs(...string)
exportLinkObjects(...string)
@@ -1038,6 +1002,9 @@
ctx.Phony("rust", ctx.RustModule().OutputFile().Path())
}
+ if mod.testModule {
+ ctx.SetProvider(testing.TestModuleProviderKey, testing.TestModuleProviderData{})
+ }
}
func (mod *Module) deps(ctx DepsContext) Deps {
diff --git a/rust/test.go b/rust/test.go
index 4b5296e..7ffc367 100644
--- a/rust/test.go
+++ b/rust/test.go
@@ -222,11 +222,13 @@
// rustTestHostMultilib load hook to set MultilibFirst for the
// host target.
android.AddLoadHook(module, rustTestHostMultilib)
+ module.testModule = true
return module.Init()
}
func RustTestHostFactory() android.Module {
module, _ := NewRustTest(android.HostSupported)
+ module.testModule = true
return module.Init()
}
diff --git a/rust/test_test.go b/rust/test_test.go
index 8906f1c..6d0ebcf 100644
--- a/rust/test_test.go
+++ b/rust/test_test.go
@@ -38,7 +38,7 @@
dataPaths := testingModule.Module().(*Module).compiler.(*testDecorator).dataPaths()
if len(dataPaths) != 1 {
- t.Errorf("expected exactly one test data file. test data files: [%s]", dataPaths)
+ t.Errorf("expected exactly one test data file. test data files: [%v]", dataPaths)
return
}
}
@@ -116,7 +116,7 @@
t.Fatalf("expected exactly one output file. output files: [%s]", outputFiles)
}
if len(testBinary.dataPaths()) != 2 {
- t.Fatalf("expected exactly two test data files. test data files: [%s]", testBinary.dataPaths())
+ t.Fatalf("expected exactly two test data files. test data files: [%v]", testBinary.dataPaths())
}
outputPath := outputFiles[0].String()
@@ -178,7 +178,7 @@
t.Fatalf("expected exactly one output file. output files: [%s]", outputFiles)
}
if len(testBinary.dataPaths()) != 3 {
- t.Fatalf("expected exactly two test data files. test data files: [%s]", testBinary.dataPaths())
+ t.Fatalf("expected exactly two test data files. test data files: [%v]", testBinary.dataPaths())
}
outputPath := outputFiles[0].String()
diff --git a/sh/Android.bp b/sh/Android.bp
index 1deedc7..930fcf5 100644
--- a/sh/Android.bp
+++ b/sh/Android.bp
@@ -11,6 +11,7 @@
"soong-android",
"soong-cc",
"soong-java",
+ "soong-testing",
"soong-tradefed",
],
srcs: [
diff --git a/sh/sh_binary.go b/sh/sh_binary.go
index 2e869f4..1bebc60 100644
--- a/sh/sh_binary.go
+++ b/sh/sh_binary.go
@@ -20,6 +20,7 @@
"sort"
"strings"
+ "android/soong/testing"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -452,6 +453,7 @@
ctx.PropertyErrorf(property, "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep))
}
})
+ ctx.SetProvider(testing.TestModuleProviderKey, testing.TestModuleProviderData{})
}
func (s *ShTest) InstallInData() bool {
diff --git a/sysprop/sysprop_library.go b/sysprop/sysprop_library.go
index fe2cc9c..8bf5f14 100644
--- a/sysprop/sysprop_library.go
+++ b/sysprop/sysprop_library.go
@@ -351,7 +351,6 @@
// Actual implementation libraries are created on LoadHookMutator
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)", " # sysprop.syspropLibrary")
fmt.Fprintln(w, "LOCAL_MODULE :=", m.Name())
- data.Entries.WriteLicenseVariables(w)
fmt.Fprintf(w, "LOCAL_MODULE_CLASS := FAKE\n")
fmt.Fprintf(w, "LOCAL_MODULE_TAGS := optional\n")
fmt.Fprintf(w, "include $(BUILD_SYSTEM)/base_rules.mk\n\n")
diff --git a/testing/Android.bp b/testing/Android.bp
new file mode 100644
index 0000000..18dccb3
--- /dev/null
+++ b/testing/Android.bp
@@ -0,0 +1,21 @@
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+bootstrap_go_package {
+ name: "soong-testing",
+ pkgPath: "android/soong/testing",
+ deps: [
+ "blueprint",
+ "soong-android",
+ "soong-testing-test_spec_proto",
+
+ ],
+ srcs: [
+ "all_test_specs.go",
+ "test_spec.go",
+ "init.go",
+ "test.go",
+ ],
+ pluginFor: ["soong_build"],
+}
diff --git a/testing/all_test_specs.go b/testing/all_test_specs.go
new file mode 100644
index 0000000..9d4645b
--- /dev/null
+++ b/testing/all_test_specs.go
@@ -0,0 +1,45 @@
+package testing
+
+import (
+ "android/soong/android"
+)
+
+const ownershipDirectory = "ownership"
+const fileContainingFilePaths = "all_test_spec_paths.rsp"
+const allTestSpecsFile = "all_test_specs.pb"
+
+func AllTestSpecsFactory() android.Singleton {
+ return &allTestSpecsSingleton{}
+}
+
+type allTestSpecsSingleton struct {
+ // Path where the collected metadata is stored after successful validation.
+ outputPath android.OutputPath
+}
+
+func (this *allTestSpecsSingleton) GenerateBuildActions(ctx android.SingletonContext) {
+ var intermediateMetadataPaths android.Paths
+
+ ctx.VisitAllModules(func(module android.Module) {
+ if !ctx.ModuleHasProvider(module, TestSpecProviderKey) {
+ return
+ }
+ intermediateMetadataPaths = append(intermediateMetadataPaths, ctx.ModuleProvider(module, TestSpecProviderKey).(TestSpecProviderData).IntermediatePath)
+ })
+
+ rspFile := android.PathForOutput(ctx, fileContainingFilePaths)
+ this.outputPath = android.PathForOutput(ctx, ownershipDirectory, allTestSpecsFile)
+
+ rule := android.NewRuleBuilder(pctx, ctx)
+ cmd := rule.Command().
+ BuiltTool("metadata").
+ FlagWithArg("-rule ", "test_spec").
+ FlagWithRspFileInputList("-inputFile ", rspFile, intermediateMetadataPaths)
+ cmd.FlagWithOutput("-outputFile ", this.outputPath)
+ rule.Build("all_test_specs_rule", "Generate all test specifications")
+ ctx.Phony("all_test_specs", this.outputPath)
+}
+
+func (this *allTestSpecsSingleton) MakeVars(ctx android.MakeVarsContext) {
+ ctx.DistForGoal("test_specs", this.outputPath)
+}
diff --git a/testing/init.go b/testing/init.go
new file mode 100644
index 0000000..206b430
--- /dev/null
+++ b/testing/init.go
@@ -0,0 +1,33 @@
+// Copyright 2022 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 testing
+
+import (
+ "android/soong/android"
+)
+
+var (
+ pctx = android.NewPackageContext("android/soong/testing")
+)
+
+func init() {
+ RegisterBuildComponents(android.InitRegistrationContext)
+ pctx.HostBinToolVariable("metadata", "metadata")
+}
+
+func RegisterBuildComponents(ctx android.RegistrationContext) {
+ ctx.RegisterModuleType("test_spec", TestSpecFactory)
+ ctx.RegisterParallelSingletonType("all_test_specs", AllTestSpecsFactory)
+}
diff --git a/testing/test.go b/testing/test.go
new file mode 100644
index 0000000..44824e4
--- /dev/null
+++ b/testing/test.go
@@ -0,0 +1,21 @@
+// Copyright 2023 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 testing
+
+import (
+ "android/soong/android"
+)
+
+var PrepareForTestWithTestSpecBuildComponents = android.FixtureRegisterWithContext(RegisterBuildComponents)
diff --git a/testing/test_spec.go b/testing/test_spec.go
new file mode 100644
index 0000000..c370f71
--- /dev/null
+++ b/testing/test_spec.go
@@ -0,0 +1,127 @@
+// Copyright 2020 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 testing
+
+import (
+ "path/filepath"
+ "strconv"
+
+ "android/soong/android"
+ "android/soong/testing/test_spec_proto"
+ "github.com/google/blueprint"
+ "google.golang.org/protobuf/proto"
+)
+
+// ErrTestModuleDataNotFound is the error message for missing test module provider data.
+const ErrTestModuleDataNotFound = "The module '%s' does not provide test specification data. Hint: This issue could arise if either the module is not a valid testing module or if it lacks the required 'TestModuleProviderKey' provider.\n"
+
+func TestSpecFactory() android.Module {
+ module := &TestSpecModule{}
+
+ android.InitAndroidModule(module)
+ android.InitDefaultableModule(module)
+ module.AddProperties(&module.properties)
+
+ return module
+}
+
+type TestSpecModule struct {
+ android.ModuleBase
+ android.DefaultableModuleBase
+ android.BazelModuleBase
+
+ // Properties for "test_spec"
+ properties struct {
+ // Specifies the name of the test config.
+ Name string
+ // Specifies the team ID.
+ TeamId string
+ // Specifies the list of tests covered under this module.
+ Tests []string
+ }
+}
+
+type testsDepTagType struct {
+ blueprint.BaseDependencyTag
+}
+
+var testsDepTag = testsDepTagType{}
+
+func (module *TestSpecModule) DepsMutator(ctx android.BottomUpMutatorContext) {
+ // Validate Properties
+ if len(module.properties.TeamId) == 0 {
+ ctx.PropertyErrorf("TeamId", "Team Id not found in the test_spec module. Hint: Maybe the TeamId property hasn't been properly specified.")
+ }
+ if !isInt(module.properties.TeamId) {
+ ctx.PropertyErrorf("TeamId", "Invalid value for Team ID. The Team ID must be an integer.")
+ }
+ if len(module.properties.Tests) == 0 {
+ ctx.PropertyErrorf("Tests", "Expected to attribute some test but none found. Hint: Maybe the test property hasn't been properly specified.")
+ }
+ ctx.AddDependency(ctx.Module(), testsDepTag, module.properties.Tests...)
+}
+func isInt(s string) bool {
+ _, err := strconv.Atoi(s)
+ return err == nil
+}
+
+// Provider published by TestSpec
+type TestSpecProviderData struct {
+ IntermediatePath android.WritablePath
+}
+
+var TestSpecProviderKey = blueprint.NewProvider(TestSpecProviderData{})
+
+type TestModuleProviderData struct {
+}
+
+var TestModuleProviderKey = blueprint.NewProvider(TestModuleProviderData{})
+
+func (module *TestSpecModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ for _, m := range ctx.GetDirectDepsWithTag(testsDepTag) {
+ if !ctx.OtherModuleHasProvider(m, TestModuleProviderKey) {
+ ctx.ModuleErrorf(ErrTestModuleDataNotFound, m.Name())
+ }
+ }
+ bpFilePath := filepath.Join(ctx.ModuleDir(), ctx.BlueprintsFile())
+ metadataList := make(
+ []*test_spec_proto.TestSpec_OwnershipMetadata, 0,
+ len(module.properties.Tests),
+ )
+ for _, test := range module.properties.Tests {
+ targetName := test
+ metadata := test_spec_proto.TestSpec_OwnershipMetadata{
+ TrendyTeamId: &module.properties.TeamId,
+ TargetName: &targetName,
+ Path: &bpFilePath,
+ }
+ metadataList = append(metadataList, &metadata)
+ }
+ intermediatePath := android.PathForModuleOut(
+ ctx, "intermediateTestSpecMetadata.pb",
+ )
+ testSpecMetadata := test_spec_proto.TestSpec{OwnershipMetadataList: metadataList}
+ protoData, err := proto.Marshal(&testSpecMetadata)
+ if err != nil {
+ ctx.ModuleErrorf("Error: %s", err.Error())
+ }
+ android.WriteFileRule(ctx, intermediatePath, string(protoData))
+
+ ctx.SetProvider(
+ TestSpecProviderKey, TestSpecProviderData{
+ IntermediatePath: intermediatePath,
+ },
+ )
+}
diff --git a/testing/test_spec_proto/Android.bp b/testing/test_spec_proto/Android.bp
new file mode 100644
index 0000000..1cac492
--- /dev/null
+++ b/testing/test_spec_proto/Android.bp
@@ -0,0 +1,29 @@
+// Copyright 2022 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 {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+bootstrap_go_package {
+ name: "soong-testing-test_spec_proto",
+ pkgPath: "android/soong/testing/test_spec_proto",
+ deps: [
+ "golang-protobuf-reflect-protoreflect",
+ "golang-protobuf-runtime-protoimpl",
+ ],
+ srcs: [
+ "test_spec.pb.go",
+ ],
+}
diff --git a/testing/test_spec_proto/OWNERS b/testing/test_spec_proto/OWNERS
new file mode 100644
index 0000000..03bcdf1
--- /dev/null
+++ b/testing/test_spec_proto/OWNERS
@@ -0,0 +1,4 @@
+dariofreni@google.com
+joeo@google.com
+ronish@google.com
+caditya@google.com
diff --git a/testing/test_spec_proto/regen.sh b/testing/test_spec_proto/regen.sh
new file mode 100644
index 0000000..2cf8203
--- /dev/null
+++ b/testing/test_spec_proto/regen.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+aprotoc --go_out=paths=source_relative:. test_spec.proto
diff --git a/testing/test_spec_proto/test_spec.pb.go b/testing/test_spec_proto/test_spec.pb.go
new file mode 100644
index 0000000..5cce600
--- /dev/null
+++ b/testing/test_spec_proto/test_spec.pb.go
@@ -0,0 +1,244 @@
+// 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.
+
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// versions:
+// protoc-gen-go v1.30.0
+// protoc v3.21.12
+// source: test_spec.proto
+
+package test_spec_proto
+
+import (
+ protoreflect "google.golang.org/protobuf/reflect/protoreflect"
+ protoimpl "google.golang.org/protobuf/runtime/protoimpl"
+ reflect "reflect"
+ sync "sync"
+)
+
+const (
+ // Verify that this generated code is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
+ // Verify that runtime/protoimpl is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
+)
+
+type TestSpec struct {
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
+ // List of all test targets and their metadata.
+ OwnershipMetadataList []*TestSpec_OwnershipMetadata `protobuf:"bytes,1,rep,name=ownership_metadata_list,json=ownershipMetadataList" json:"ownership_metadata_list,omitempty"`
+}
+
+func (x *TestSpec) Reset() {
+ *x = TestSpec{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_spec_proto_msgTypes[0]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
+}
+
+func (x *TestSpec) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*TestSpec) ProtoMessage() {}
+
+func (x *TestSpec) ProtoReflect() protoreflect.Message {
+ mi := &file_test_spec_proto_msgTypes[0]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use TestSpec.ProtoReflect.Descriptor instead.
+func (*TestSpec) Descriptor() ([]byte, []int) {
+ return file_test_spec_proto_rawDescGZIP(), []int{0}
+}
+
+func (x *TestSpec) GetOwnershipMetadataList() []*TestSpec_OwnershipMetadata {
+ if x != nil {
+ return x.OwnershipMetadataList
+ }
+ return nil
+}
+
+type TestSpec_OwnershipMetadata struct {
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
+ TargetName *string `protobuf:"bytes,1,opt,name=target_name,json=targetName" json:"target_name,omitempty"`
+ Path *string `protobuf:"bytes,2,opt,name=path" json:"path,omitempty"`
+ TrendyTeamId *string `protobuf:"bytes,3,opt,name=trendy_team_id,json=trendyTeamId" json:"trendy_team_id,omitempty"`
+}
+
+func (x *TestSpec_OwnershipMetadata) Reset() {
+ *x = TestSpec_OwnershipMetadata{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_spec_proto_msgTypes[1]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
+}
+
+func (x *TestSpec_OwnershipMetadata) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*TestSpec_OwnershipMetadata) ProtoMessage() {}
+
+func (x *TestSpec_OwnershipMetadata) ProtoReflect() protoreflect.Message {
+ mi := &file_test_spec_proto_msgTypes[1]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use TestSpec_OwnershipMetadata.ProtoReflect.Descriptor instead.
+func (*TestSpec_OwnershipMetadata) Descriptor() ([]byte, []int) {
+ return file_test_spec_proto_rawDescGZIP(), []int{0, 0}
+}
+
+func (x *TestSpec_OwnershipMetadata) GetTargetName() string {
+ if x != nil && x.TargetName != nil {
+ return *x.TargetName
+ }
+ return ""
+}
+
+func (x *TestSpec_OwnershipMetadata) GetPath() string {
+ if x != nil && x.Path != nil {
+ return *x.Path
+ }
+ return ""
+}
+
+func (x *TestSpec_OwnershipMetadata) GetTrendyTeamId() string {
+ if x != nil && x.TrendyTeamId != nil {
+ return *x.TrendyTeamId
+ }
+ return ""
+}
+
+var File_test_spec_proto protoreflect.FileDescriptor
+
+var file_test_spec_proto_rawDesc = []byte{
+ 0x0a, 0x0f, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74,
+ 0x6f, 0x12, 0x0f, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x5f, 0x70, 0x72, 0x6f,
+ 0x74, 0x6f, 0x22, 0xdf, 0x01, 0x0a, 0x08, 0x54, 0x65, 0x73, 0x74, 0x53, 0x70, 0x65, 0x63, 0x12,
+ 0x63, 0x0a, 0x17, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x5f, 0x6d, 0x65, 0x74,
+ 0x61, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b,
+ 0x32, 0x2b, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x5f, 0x70, 0x72, 0x6f,
+ 0x74, 0x6f, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x53, 0x70, 0x65, 0x63, 0x2e, 0x4f, 0x77, 0x6e, 0x65,
+ 0x72, 0x73, 0x68, 0x69, 0x70, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x15, 0x6f,
+ 0x77, 0x6e, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61,
+ 0x4c, 0x69, 0x73, 0x74, 0x1a, 0x6e, 0x0a, 0x11, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x73, 0x68, 0x69,
+ 0x70, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1f, 0x0a, 0x0b, 0x74, 0x61, 0x72,
+ 0x67, 0x65, 0x74, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a,
+ 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61,
+ 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x24,
+ 0x0a, 0x0e, 0x74, 0x72, 0x65, 0x6e, 0x64, 0x79, 0x5f, 0x74, 0x65, 0x61, 0x6d, 0x5f, 0x69, 0x64,
+ 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x74, 0x72, 0x65, 0x6e, 0x64, 0x79, 0x54, 0x65,
+ 0x61, 0x6d, 0x49, 0x64, 0x42, 0x27, 0x5a, 0x25, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2f,
+ 0x73, 0x6f, 0x6f, 0x6e, 0x67, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x2f, 0x74, 0x65,
+ 0x73, 0x74, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
+}
+
+var (
+ file_test_spec_proto_rawDescOnce sync.Once
+ file_test_spec_proto_rawDescData = file_test_spec_proto_rawDesc
+)
+
+func file_test_spec_proto_rawDescGZIP() []byte {
+ file_test_spec_proto_rawDescOnce.Do(func() {
+ file_test_spec_proto_rawDescData = protoimpl.X.CompressGZIP(file_test_spec_proto_rawDescData)
+ })
+ return file_test_spec_proto_rawDescData
+}
+
+var file_test_spec_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
+var file_test_spec_proto_goTypes = []interface{}{
+ (*TestSpec)(nil), // 0: test_spec_proto.TestSpec
+ (*TestSpec_OwnershipMetadata)(nil), // 1: test_spec_proto.TestSpec.OwnershipMetadata
+}
+var file_test_spec_proto_depIdxs = []int32{
+ 1, // 0: test_spec_proto.TestSpec.ownership_metadata_list:type_name -> test_spec_proto.TestSpec.OwnershipMetadata
+ 1, // [1:1] is the sub-list for method output_type
+ 1, // [1:1] is the sub-list for method input_type
+ 1, // [1:1] is the sub-list for extension type_name
+ 1, // [1:1] is the sub-list for extension extendee
+ 0, // [0:1] is the sub-list for field type_name
+}
+
+func init() { file_test_spec_proto_init() }
+func file_test_spec_proto_init() {
+ if File_test_spec_proto != nil {
+ return
+ }
+ if !protoimpl.UnsafeEnabled {
+ file_test_spec_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
+ switch v := v.(*TestSpec); i {
+ case 0:
+ return &v.state
+ case 1:
+ return &v.sizeCache
+ case 2:
+ return &v.unknownFields
+ default:
+ return nil
+ }
+ }
+ file_test_spec_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
+ switch v := v.(*TestSpec_OwnershipMetadata); i {
+ case 0:
+ return &v.state
+ case 1:
+ return &v.sizeCache
+ case 2:
+ return &v.unknownFields
+ default:
+ return nil
+ }
+ }
+ }
+ type x struct{}
+ out := protoimpl.TypeBuilder{
+ File: protoimpl.DescBuilder{
+ GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
+ RawDescriptor: file_test_spec_proto_rawDesc,
+ NumEnums: 0,
+ NumMessages: 2,
+ NumExtensions: 0,
+ NumServices: 0,
+ },
+ GoTypes: file_test_spec_proto_goTypes,
+ DependencyIndexes: file_test_spec_proto_depIdxs,
+ MessageInfos: file_test_spec_proto_msgTypes,
+ }.Build()
+ File_test_spec_proto = out.File
+ file_test_spec_proto_rawDesc = nil
+ file_test_spec_proto_goTypes = nil
+ file_test_spec_proto_depIdxs = nil
+}
diff --git a/testing/test_spec_proto/test_spec.proto b/testing/test_spec_proto/test_spec.proto
new file mode 100644
index 0000000..86bc789
--- /dev/null
+++ b/testing/test_spec_proto/test_spec.proto
@@ -0,0 +1,33 @@
+// 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.
+
+syntax = "proto2";
+package test_spec_proto;
+option go_package = "android/soong/testing/test_spec_proto";
+
+message TestSpec {
+
+ message OwnershipMetadata {
+ // REQUIRED: Name of the build target
+ optional string target_name = 1;
+
+ // REQUIRED: Code location of the target.
+ // To be used to support legacy/backup systems that use OWNERS file and is
+ // also required for our dashboard to support per code location basis UI
+ optional string path = 2;
+
+ // REQUIRED: Team ID of the team that owns this target.
+ optional string trendy_team_id = 3;
+ }
+
+ // List of all test targets and their metadata.
+ repeated OwnershipMetadata ownership_metadata_list = 1;
+}
diff --git a/tests/genrule_sandbox_test.py b/tests/genrule_sandbox_test.py
index 874859a..3799e92 100755
--- a/tests/genrule_sandbox_test.py
+++ b/tests/genrule_sandbox_test.py
@@ -15,12 +15,14 @@
# limitations under the License.
import argparse
+import asyncio
import collections
import json
import os
+import socket
import subprocess
import sys
-import tempfile
+import textwrap
def get_top() -> str:
path = '.'
@@ -30,39 +32,65 @@
path = os.path.join(path, '..')
return os.path.abspath(path)
-def _build_with_soong(targets, target_product, *, keep_going = False, extra_env={}):
- env = {
- **os.environ,
- "TARGET_PRODUCT": target_product,
- "TARGET_BUILD_VARIANT": "userdebug",
- }
- env.update(extra_env)
+async def _build_with_soong(out_dir, targets, *, extra_env={}):
+ env = os.environ | extra_env
+
+ # Use nsjail to remap the out_dir to out/, because some genrules write the path to the out
+ # dir into their artifacts, so if the out directories were different it would cause a diff
+ # that doesn't really matter.
args = [
+ 'prebuilts/build-tools/linux-x86/bin/nsjail',
+ '-q',
+ '--cwd',
+ os.getcwd(),
+ '-e',
+ '-B',
+ '/',
+ '-B',
+ f'{os.path.abspath(out_dir)}:{os.path.abspath("out")}',
+ '--time_limit',
+ '0',
+ '--skip_setsid',
+ '--keep_caps',
+ '--disable_clone_newcgroup',
+ '--disable_clone_newnet',
+ '--rlimit_as',
+ 'soft',
+ '--rlimit_core',
+ 'soft',
+ '--rlimit_cpu',
+ 'soft',
+ '--rlimit_fsize',
+ 'soft',
+ '--rlimit_nofile',
+ 'soft',
+ '--proc_rw',
+ '--hostname',
+ socket.gethostname(),
+ '--',
"build/soong/soong_ui.bash",
"--make-mode",
"--skip-soong-tests",
]
- if keep_going:
- args.append("-k")
args.extend(targets)
- try:
- subprocess.check_output(
- args,
- env=env,
- )
- except subprocess.CalledProcessError as e:
- print(e)
- print(e.stdout)
- print(e.stderr)
- exit(1)
+ process = await asyncio.create_subprocess_exec(
+ *args,
+ stdout=asyncio.subprocess.PIPE,
+ stderr=asyncio.subprocess.PIPE,
+ env=env,
+ )
+ stdout, stderr = await process.communicate()
+ if process.returncode != 0:
+ print(stdout)
+ print(stderr)
+ sys.exit(process.returncode)
-def _find_outputs_for_modules(modules, out_dir, target_product):
- module_path = os.path.join(out_dir, "soong", "module-actions.json")
+async def _find_outputs_for_modules(modules):
+ module_path = "out/soong/module-actions.json"
if not os.path.exists(module_path):
- # Use GENRULE_SANDBOXING=false so that we don't cause re-analysis later when we do the no-sandboxing build
- _build_with_soong(["json-module-graph"], target_product, extra_env={"GENRULE_SANDBOXING": "false"})
+ await _build_with_soong('out', ["json-module-graph"])
with open(module_path) as f:
action_graph = json.load(f)
@@ -71,7 +99,7 @@
for mod in action_graph:
name = mod["Name"]
if name in modules:
- for act in mod["Module"]["Actions"]:
+ for act in (mod["Module"]["Actions"] or []):
if "}generate" in act["Desc"]:
module_to_outs[name].update(act["Outputs"])
return module_to_outs
@@ -89,20 +117,19 @@
return different_modules
-def main():
+async def main():
parser = argparse.ArgumentParser()
parser.add_argument(
- "--target_product",
- "-t",
- default="aosp_cf_arm64_phone",
- help="optional, target product, always runs as eng",
- )
- parser.add_argument(
"modules",
nargs="+",
help="modules to compare builds with genrule sandboxing enabled/not",
)
parser.add_argument(
+ "--check-determinism",
+ action="store_true",
+ help="Don't check for working sandboxing. Instead, run two default builds, and compare their outputs. This is used to check for nondeterminsim, which would also affect the sandboxed test.",
+ )
+ parser.add_argument(
"--show-diff",
"-d",
action="store_true",
@@ -117,10 +144,13 @@
args = parser.parse_args()
os.chdir(get_top())
- out_dir = os.environ.get("OUT_DIR", "out")
+ if "TARGET_PRODUCT" not in os.environ:
+ sys.exit("Please run lunch first")
+ if os.environ.get("OUT_DIR", "out") != "out":
+ sys.exit(f"This script expects OUT_DIR to be 'out', got: '{os.environ.get('OUT_DIR')}'")
print("finding output files for the modules...")
- module_to_outs = _find_outputs_for_modules(set(args.modules), out_dir, args.target_product)
+ module_to_outs = await _find_outputs_for_modules(set(args.modules))
if not module_to_outs:
sys.exit("No outputs found")
@@ -130,33 +160,48 @@
sys.exit(0)
all_outs = list(set.union(*module_to_outs.values()))
+ for i, out in enumerate(all_outs):
+ if not out.startswith("out/"):
+ sys.exit("Expected output file to start with out/, found: " + out)
- print("building without sandboxing...")
- _build_with_soong(all_outs, args.target_product, extra_env={"GENRULE_SANDBOXING": "false"})
- with tempfile.TemporaryDirectory() as tempdir:
- for f in all_outs:
- subprocess.check_call(["cp", "--parents", f, tempdir])
+ other_out_dir = "out_check_determinism" if args.check_determinism else "out_not_sandboxed"
+ other_env = {"GENRULE_SANDBOXING": "false"}
+ if args.check_determinism:
+ other_env = {}
- print("building with sandboxing...")
- _build_with_soong(
- all_outs,
- args.target_product,
- # We've verified these build without sandboxing already, so do the sandboxing build
- # with keep_going = True so that we can find all the genrules that fail to build with
- # sandboxing.
- keep_going = True,
- extra_env={"GENRULE_SANDBOXING": "true"},
- )
+ # nsjail will complain if the out dir doesn't exist
+ os.makedirs("out", exist_ok=True)
+ os.makedirs(other_out_dir, exist_ok=True)
- diffs = _compare_outputs(module_to_outs, tempdir)
- if len(diffs) == 0:
- print("All modules are correct")
- elif args.show_diff:
- for m, d in diffs.items():
- print(f"Module {m} has diffs {d}")
- else:
- print(f"Modules {list(diffs.keys())} have diffs")
+ print("building...")
+ await asyncio.gather(
+ _build_with_soong("out", all_outs),
+ _build_with_soong(other_out_dir, all_outs, extra_env=other_env)
+ )
+
+ diffs = collections.defaultdict(dict)
+ for module, outs in module_to_outs.items():
+ for out in outs:
+ try:
+ subprocess.check_output(["diff", os.path.join(other_out_dir, out.removeprefix("out/")), out])
+ except subprocess.CalledProcessError as e:
+ diffs[module][out] = e.stdout
+
+ if len(diffs) == 0:
+ print("All modules are correct")
+ elif args.show_diff:
+ for m, files in diffs.items():
+ print(f"Module {m} has diffs:")
+ for f, d in files.items():
+ print(" "+f+":")
+ print(textwrap.indent(d, " "))
+ else:
+ print(f"Modules {list(diffs.keys())} have diffs in these files:")
+ all_diff_files = [f for m in diffs.values() for f in m]
+ for f in all_diff_files:
+ print(f)
+
if __name__ == "__main__":
- main()
+ asyncio.run(main())
diff --git a/ui/build/config.go b/ui/build/config.go
index d345415..613fc65 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -384,10 +384,14 @@
// Configure Java-related variables, including adding it to $PATH
java8Home := filepath.Join("prebuilts/jdk/jdk8", ret.HostPrebuiltTag())
java17Home := filepath.Join("prebuilts/jdk/jdk17", ret.HostPrebuiltTag())
+ java21Home := filepath.Join("prebuilts/jdk/jdk21", ret.HostPrebuiltTag())
javaHome := func() string {
if override, ok := ret.environ.Get("OVERRIDE_ANDROID_JAVA_HOME"); ok {
return override
}
+ if ret.environ.IsEnvTrue("EXPERIMENTAL_USE_OPENJDK21_TOOLCHAIN") {
+ return java21Home
+ }
if toolchain11, ok := ret.environ.Get("EXPERIMENTAL_USE_OPENJDK11_TOOLCHAIN"); ok && toolchain11 != "true" {
ctx.Fatalln("The environment variable EXPERIMENTAL_USE_OPENJDK11_TOOLCHAIN is no longer supported. An OpenJDK 11 toolchain is now the global default.")
}
diff --git a/ui/status/ninja.go b/ui/status/ninja.go
index 7b25d50..1e97908 100644
--- a/ui/status/ninja.go
+++ b/ui/status/ninja.go
@@ -20,6 +20,7 @@
"io"
"os"
"regexp"
+ "runtime"
"strings"
"syscall"
"time"
@@ -178,7 +179,28 @@
// msgChan is closed
break
}
- // Ignore msg.BuildStarted
+
+ if msg.BuildStarted != nil {
+ parallelism := uint32(runtime.NumCPU())
+ if msg.BuildStarted.GetParallelism() > 0 {
+ parallelism = msg.BuildStarted.GetParallelism()
+ }
+ // It is estimated from total time / parallelism assumming the build is packing enough.
+ estimatedDurationFromTotal := time.Duration(msg.BuildStarted.GetEstimatedTotalTime()/parallelism) * time.Millisecond
+ // It is estimated from critical path time which is useful for small size build.
+ estimatedDurationFromCriticalPath := time.Duration(msg.BuildStarted.GetCriticalPathTime()) * time.Millisecond
+ // Select the longer one.
+ estimatedDuration := max(estimatedDurationFromTotal, estimatedDurationFromCriticalPath)
+
+ if estimatedDuration > 0 {
+ n.status.SetEstimatedTime(time.Now().Add(estimatedDuration))
+ n.status.Verbose(fmt.Sprintf("parallelism: %d, estimiated from total time: %s, critical path time: %s",
+ parallelism,
+ estimatedDurationFromTotal,
+ estimatedDurationFromCriticalPath))
+
+ }
+ }
if msg.TotalEdges != nil {
n.status.SetTotalActions(int(msg.TotalEdges.GetTotalEdges()))
}
diff --git a/ui/status/ninja_frontend/frontend.pb.go b/ui/status/ninja_frontend/frontend.pb.go
index d0c4953..d8344c8 100644
--- a/ui/status/ninja_frontend/frontend.pb.go
+++ b/ui/status/ninja_frontend/frontend.pb.go
@@ -14,7 +14,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
-// protoc-gen-go v1.28.1
+// protoc-gen-go v1.30.0
// protoc v3.21.12
// source: frontend.proto
@@ -240,6 +240,10 @@
Parallelism *uint32 `protobuf:"varint,1,opt,name=parallelism" json:"parallelism,omitempty"`
// Verbose value passed to ninja.
Verbose *bool `protobuf:"varint,2,opt,name=verbose" json:"verbose,omitempty"`
+ // Critical path's running time in milliseconds
+ CriticalPathTime *uint32 `protobuf:"varint,3,opt,name=critical_path_time,json=criticalPathTime" json:"critical_path_time,omitempty"`
+ // Total running time of every need-to-build edge in milliseconds
+ EstimatedTotalTime *uint32 `protobuf:"varint,4,opt,name=estimated_total_time,json=estimatedTotalTime" json:"estimated_total_time,omitempty"`
}
func (x *Status_BuildStarted) Reset() {
@@ -288,6 +292,20 @@
return false
}
+func (x *Status_BuildStarted) GetCriticalPathTime() uint32 {
+ if x != nil && x.CriticalPathTime != nil {
+ return *x.CriticalPathTime
+ }
+ return 0
+}
+
+func (x *Status_BuildStarted) GetEstimatedTotalTime() uint32 {
+ if x != nil && x.EstimatedTotalTime != nil {
+ return *x.EstimatedTotalTime
+ }
+ return 0
+}
+
type Status_BuildFinished struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@@ -660,7 +678,7 @@
var file_frontend_proto_rawDesc = []byte{
0x0a, 0x0e, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
- 0x12, 0x05, 0x6e, 0x69, 0x6e, 0x6a, 0x61, 0x22, 0xc8, 0x0a, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74,
+ 0x12, 0x05, 0x6e, 0x69, 0x6e, 0x6a, 0x61, 0x22, 0xa9, 0x0b, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74,
0x75, 0x73, 0x12, 0x39, 0x0a, 0x0b, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x65, 0x64, 0x67, 0x65,
0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6e, 0x69, 0x6e, 0x6a, 0x61, 0x2e,
0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x2e, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x45, 0x64, 0x67, 0x65,
@@ -687,67 +705,73 @@
0x67, 0x65, 0x1a, 0x2d, 0x0a, 0x0a, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x45, 0x64, 0x67, 0x65, 0x73,
0x12, 0x1f, 0x0a, 0x0b, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x65, 0x64, 0x67, 0x65, 0x73, 0x18,
0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x45, 0x64, 0x67, 0x65,
- 0x73, 0x1a, 0x4a, 0x0a, 0x0c, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x53, 0x74, 0x61, 0x72, 0x74, 0x65,
- 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x61, 0x6c, 0x6c, 0x65, 0x6c, 0x69, 0x73, 0x6d,
- 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0b, 0x70, 0x61, 0x72, 0x61, 0x6c, 0x6c, 0x65, 0x6c,
- 0x69, 0x73, 0x6d, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x62, 0x6f, 0x73, 0x65, 0x18, 0x02,
- 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x76, 0x65, 0x72, 0x62, 0x6f, 0x73, 0x65, 0x1a, 0x0f, 0x0a,
- 0x0d, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x46, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x1a, 0xb6,
- 0x01, 0x0a, 0x0b, 0x45, 0x64, 0x67, 0x65, 0x53, 0x74, 0x61, 0x72, 0x74, 0x65, 0x64, 0x12, 0x0e,
- 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1d,
- 0x0a, 0x0a, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01,
- 0x28, 0x0d, 0x52, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x16, 0x0a,
- 0x06, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x69,
- 0x6e, 0x70, 0x75, 0x74, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x73,
- 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x73, 0x12,
- 0x12, 0x0a, 0x04, 0x64, 0x65, 0x73, 0x63, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64,
- 0x65, 0x73, 0x63, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x18, 0x06,
- 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x18, 0x0a,
- 0x07, 0x63, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07,
- 0x63, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x1a, 0xf3, 0x03, 0x0a, 0x0c, 0x45, 0x64, 0x67, 0x65,
- 0x46, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01,
- 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x65, 0x6e, 0x64, 0x5f,
- 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x65, 0x6e, 0x64, 0x54,
- 0x69, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x03, 0x20,
- 0x01, 0x28, 0x11, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x6f,
- 0x75, 0x74, 0x70, 0x75, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x75, 0x74,
- 0x70, 0x75, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x74, 0x69, 0x6d, 0x65,
- 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x54, 0x69, 0x6d, 0x65,
- 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18,
- 0x06, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x54, 0x69, 0x6d,
- 0x65, 0x12, 0x1c, 0x0a, 0x0a, 0x6d, 0x61, 0x78, 0x5f, 0x72, 0x73, 0x73, 0x5f, 0x6b, 0x62, 0x18,
- 0x07, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x6d, 0x61, 0x78, 0x52, 0x73, 0x73, 0x4b, 0x62, 0x12,
- 0x2a, 0x0a, 0x11, 0x6d, 0x69, 0x6e, 0x6f, 0x72, 0x5f, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x66, 0x61,
- 0x75, 0x6c, 0x74, 0x73, 0x18, 0x08, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x6d, 0x69, 0x6e, 0x6f,
- 0x72, 0x50, 0x61, 0x67, 0x65, 0x46, 0x61, 0x75, 0x6c, 0x74, 0x73, 0x12, 0x2a, 0x0a, 0x11, 0x6d,
- 0x61, 0x6a, 0x6f, 0x72, 0x5f, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x73,
- 0x18, 0x09, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x6d, 0x61, 0x6a, 0x6f, 0x72, 0x50, 0x61, 0x67,
- 0x65, 0x46, 0x61, 0x75, 0x6c, 0x74, 0x73, 0x12, 0x1e, 0x0a, 0x0b, 0x69, 0x6f, 0x5f, 0x69, 0x6e,
- 0x70, 0x75, 0x74, 0x5f, 0x6b, 0x62, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x69, 0x6f,
- 0x49, 0x6e, 0x70, 0x75, 0x74, 0x4b, 0x62, 0x12, 0x20, 0x0a, 0x0c, 0x69, 0x6f, 0x5f, 0x6f, 0x75,
- 0x74, 0x70, 0x75, 0x74, 0x5f, 0x6b, 0x62, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0a, 0x69,
- 0x6f, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x4b, 0x62, 0x12, 0x3c, 0x0a, 0x1a, 0x76, 0x6f, 0x6c,
- 0x75, 0x6e, 0x74, 0x61, 0x72, 0x79, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x5f, 0x73,
- 0x77, 0x69, 0x74, 0x63, 0x68, 0x65, 0x73, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x04, 0x52, 0x18, 0x76,
- 0x6f, 0x6c, 0x75, 0x6e, 0x74, 0x61, 0x72, 0x79, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x53,
- 0x77, 0x69, 0x74, 0x63, 0x68, 0x65, 0x73, 0x12, 0x40, 0x0a, 0x1c, 0x69, 0x6e, 0x76, 0x6f, 0x6c,
- 0x75, 0x6e, 0x74, 0x61, 0x72, 0x79, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x5f, 0x73,
- 0x77, 0x69, 0x74, 0x63, 0x68, 0x65, 0x73, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x04, 0x52, 0x1a, 0x69,
- 0x6e, 0x76, 0x6f, 0x6c, 0x75, 0x6e, 0x74, 0x61, 0x72, 0x79, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78,
- 0x74, 0x53, 0x77, 0x69, 0x74, 0x63, 0x68, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x61, 0x67,
- 0x73, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x61, 0x67, 0x73, 0x1a, 0x92, 0x01,
- 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x37, 0x0a, 0x05, 0x6c, 0x65, 0x76,
- 0x65, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x6e, 0x69, 0x6e, 0x6a, 0x61,
- 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e,
- 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x3a, 0x04, 0x49, 0x4e, 0x46, 0x4f, 0x52, 0x05, 0x6c, 0x65, 0x76,
- 0x65, 0x6c, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20,
- 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x34, 0x0a, 0x05,
- 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x08, 0x0a, 0x04, 0x49, 0x4e, 0x46, 0x4f, 0x10, 0x00, 0x12,
- 0x0b, 0x0a, 0x07, 0x57, 0x41, 0x52, 0x4e, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05,
- 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x44, 0x45, 0x42, 0x55, 0x47,
- 0x10, 0x03, 0x42, 0x2a, 0x48, 0x03, 0x5a, 0x26, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2f,
- 0x73, 0x6f, 0x6f, 0x6e, 0x67, 0x2f, 0x75, 0x69, 0x2f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x2f,
- 0x6e, 0x69, 0x6e, 0x6a, 0x61, 0x5f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64,
+ 0x73, 0x1a, 0xaa, 0x01, 0x0a, 0x0c, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x53, 0x74, 0x61, 0x72, 0x74,
+ 0x65, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x61, 0x6c, 0x6c, 0x65, 0x6c, 0x69, 0x73,
+ 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0b, 0x70, 0x61, 0x72, 0x61, 0x6c, 0x6c, 0x65,
+ 0x6c, 0x69, 0x73, 0x6d, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x62, 0x6f, 0x73, 0x65, 0x18,
+ 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x76, 0x65, 0x72, 0x62, 0x6f, 0x73, 0x65, 0x12, 0x2c,
+ 0x0a, 0x12, 0x63, 0x72, 0x69, 0x74, 0x69, 0x63, 0x61, 0x6c, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x5f,
+ 0x74, 0x69, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x10, 0x63, 0x72, 0x69, 0x74,
+ 0x69, 0x63, 0x61, 0x6c, 0x50, 0x61, 0x74, 0x68, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x30, 0x0a, 0x14,
+ 0x65, 0x73, 0x74, 0x69, 0x6d, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f,
+ 0x74, 0x69, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x12, 0x65, 0x73, 0x74, 0x69,
+ 0x6d, 0x61, 0x74, 0x65, 0x64, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x54, 0x69, 0x6d, 0x65, 0x1a, 0x0f,
+ 0x0a, 0x0d, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x46, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x1a,
+ 0xb6, 0x01, 0x0a, 0x0b, 0x45, 0x64, 0x67, 0x65, 0x53, 0x74, 0x61, 0x72, 0x74, 0x65, 0x64, 0x12,
+ 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12,
+ 0x1d, 0x0a, 0x0a, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20,
+ 0x01, 0x28, 0x0d, 0x52, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x16,
+ 0x0a, 0x06, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06,
+ 0x69, 0x6e, 0x70, 0x75, 0x74, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74,
+ 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x73,
+ 0x12, 0x12, 0x0a, 0x04, 0x64, 0x65, 0x73, 0x63, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
+ 0x64, 0x65, 0x73, 0x63, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x18,
+ 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x18,
+ 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52,
+ 0x07, 0x63, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x1a, 0xf3, 0x03, 0x0a, 0x0c, 0x45, 0x64, 0x67,
+ 0x65, 0x46, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18,
+ 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x65, 0x6e, 0x64,
+ 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x65, 0x6e, 0x64,
+ 0x54, 0x69, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x03,
+ 0x20, 0x01, 0x28, 0x11, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06,
+ 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x75,
+ 0x74, 0x70, 0x75, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x74, 0x69, 0x6d,
+ 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x54, 0x69, 0x6d,
+ 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x5f, 0x74, 0x69, 0x6d, 0x65,
+ 0x18, 0x06, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x54, 0x69,
+ 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x0a, 0x6d, 0x61, 0x78, 0x5f, 0x72, 0x73, 0x73, 0x5f, 0x6b, 0x62,
+ 0x18, 0x07, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x6d, 0x61, 0x78, 0x52, 0x73, 0x73, 0x4b, 0x62,
+ 0x12, 0x2a, 0x0a, 0x11, 0x6d, 0x69, 0x6e, 0x6f, 0x72, 0x5f, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x66,
+ 0x61, 0x75, 0x6c, 0x74, 0x73, 0x18, 0x08, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x6d, 0x69, 0x6e,
+ 0x6f, 0x72, 0x50, 0x61, 0x67, 0x65, 0x46, 0x61, 0x75, 0x6c, 0x74, 0x73, 0x12, 0x2a, 0x0a, 0x11,
+ 0x6d, 0x61, 0x6a, 0x6f, 0x72, 0x5f, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x66, 0x61, 0x75, 0x6c, 0x74,
+ 0x73, 0x18, 0x09, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x6d, 0x61, 0x6a, 0x6f, 0x72, 0x50, 0x61,
+ 0x67, 0x65, 0x46, 0x61, 0x75, 0x6c, 0x74, 0x73, 0x12, 0x1e, 0x0a, 0x0b, 0x69, 0x6f, 0x5f, 0x69,
+ 0x6e, 0x70, 0x75, 0x74, 0x5f, 0x6b, 0x62, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x69,
+ 0x6f, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x4b, 0x62, 0x12, 0x20, 0x0a, 0x0c, 0x69, 0x6f, 0x5f, 0x6f,
+ 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x6b, 0x62, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0a,
+ 0x69, 0x6f, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x4b, 0x62, 0x12, 0x3c, 0x0a, 0x1a, 0x76, 0x6f,
+ 0x6c, 0x75, 0x6e, 0x74, 0x61, 0x72, 0x79, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x5f,
+ 0x73, 0x77, 0x69, 0x74, 0x63, 0x68, 0x65, 0x73, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x04, 0x52, 0x18,
+ 0x76, 0x6f, 0x6c, 0x75, 0x6e, 0x74, 0x61, 0x72, 0x79, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74,
+ 0x53, 0x77, 0x69, 0x74, 0x63, 0x68, 0x65, 0x73, 0x12, 0x40, 0x0a, 0x1c, 0x69, 0x6e, 0x76, 0x6f,
+ 0x6c, 0x75, 0x6e, 0x74, 0x61, 0x72, 0x79, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x5f,
+ 0x73, 0x77, 0x69, 0x74, 0x63, 0x68, 0x65, 0x73, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x04, 0x52, 0x1a,
+ 0x69, 0x6e, 0x76, 0x6f, 0x6c, 0x75, 0x6e, 0x74, 0x61, 0x72, 0x79, 0x43, 0x6f, 0x6e, 0x74, 0x65,
+ 0x78, 0x74, 0x53, 0x77, 0x69, 0x74, 0x63, 0x68, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x61,
+ 0x67, 0x73, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x61, 0x67, 0x73, 0x1a, 0x92,
+ 0x01, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x37, 0x0a, 0x05, 0x6c, 0x65,
+ 0x76, 0x65, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x6e, 0x69, 0x6e, 0x6a,
+ 0x61, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
+ 0x2e, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x3a, 0x04, 0x49, 0x4e, 0x46, 0x4f, 0x52, 0x05, 0x6c, 0x65,
+ 0x76, 0x65, 0x6c, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02,
+ 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x34, 0x0a,
+ 0x05, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x08, 0x0a, 0x04, 0x49, 0x4e, 0x46, 0x4f, 0x10, 0x00,
+ 0x12, 0x0b, 0x0a, 0x07, 0x57, 0x41, 0x52, 0x4e, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x09, 0x0a,
+ 0x05, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x44, 0x45, 0x42, 0x55,
+ 0x47, 0x10, 0x03, 0x42, 0x2a, 0x48, 0x03, 0x5a, 0x26, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64,
+ 0x2f, 0x73, 0x6f, 0x6f, 0x6e, 0x67, 0x2f, 0x75, 0x69, 0x2f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73,
+ 0x2f, 0x6e, 0x69, 0x6e, 0x6a, 0x61, 0x5f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64,
}
var (
diff --git a/ui/status/ninja_frontend/frontend.proto b/ui/status/ninja_frontend/frontend.proto
index 6cb4a0d..42b251b 100644
--- a/ui/status/ninja_frontend/frontend.proto
+++ b/ui/status/ninja_frontend/frontend.proto
@@ -30,6 +30,10 @@
optional uint32 parallelism = 1;
// Verbose value passed to ninja.
optional bool verbose = 2;
+ // Critical path's running time in milliseconds
+ optional uint32 critical_path_time = 3;
+ // Total running time of every need-to-build edge in milliseconds
+ optional uint32 estimated_total_time = 4;
}
message BuildFinished {
diff --git a/ui/status/status.go b/ui/status/status.go
index f3e58b6..da78994 100644
--- a/ui/status/status.go
+++ b/ui/status/status.go
@@ -19,6 +19,7 @@
import (
"sync"
+ "time"
)
// Action describes an action taken (or as Ninja calls them, Edges).
@@ -107,6 +108,8 @@
// FinishedActions are the number of actions that have been finished
// with FinishAction.
FinishedActions int
+
+ EstimatedTime time.Time
}
// ToolStatus is the interface used by tools to report on their Actions, and to
@@ -118,6 +121,7 @@
// This call be will ignored if it sets a number that is less than the
// current number of started actions.
SetTotalActions(total int)
+ SetEstimatedTime(estimatedTime time.Time)
// StartAction specifies that the associated action has been started by
// the tool.
@@ -267,6 +271,13 @@
s.counts.TotalActions += diff
}
+func (s *Status) SetEstimatedTime(estimatedTime time.Time) {
+ s.lock.Lock()
+ defer s.lock.Unlock()
+
+ s.counts.EstimatedTime = estimatedTime
+}
+
func (s *Status) startAction(action *Action) {
s.lock.Lock()
defer s.lock.Unlock()
@@ -329,6 +340,10 @@
}
}
+func (d *toolStatus) SetEstimatedTime(estimatedTime time.Time) {
+ d.status.SetEstimatedTime(estimatedTime)
+}
+
func (d *toolStatus) StartAction(action *Action) {
totalDiff := 0
diff --git a/ui/terminal/format.go b/ui/terminal/format.go
index 4205bdc..5391023 100644
--- a/ui/terminal/format.go
+++ b/ui/terminal/format.go
@@ -25,6 +25,7 @@
type formatter struct {
format string
quiet bool
+ smart bool
start time.Time
}
@@ -32,10 +33,11 @@
// the terminal in a format similar to Ninja.
// format takes nearly all the same options as NINJA_STATUS.
// %c is currently unsupported.
-func newFormatter(format string, quiet bool) formatter {
+func newFormatter(format string, quiet bool, smart bool) formatter {
return formatter{
format: format,
quiet: quiet,
+ smart: smart,
start: time.Now(),
}
}
@@ -51,9 +53,23 @@
return ""
}
+func remainingTimeString(t time.Time) string {
+ now := time.Now()
+ if t.After(now) {
+ return t.Sub(now).Round(time.Duration(time.Second)).String()
+ }
+ return time.Duration(0).Round(time.Duration(time.Second)).String()
+}
func (s formatter) progress(counts status.Counts) string {
if s.format == "" {
- return fmt.Sprintf("[%3d%% %d/%d] ", 100*counts.FinishedActions/counts.TotalActions, counts.FinishedActions, counts.TotalActions)
+ output := fmt.Sprintf("[%3d%% %d/%d", 100*counts.FinishedActions/counts.TotalActions, counts.FinishedActions, counts.TotalActions)
+ // Not to break parsing logic in the build bot
+ // TODO(b/313981966): make buildbot more flexible for output format
+ if s.smart && !counts.EstimatedTime.IsZero() {
+ output += fmt.Sprintf(" %s remaining", remainingTimeString(counts.EstimatedTime))
+ }
+ output += "] "
+ return output
}
buf := &strings.Builder{}
@@ -93,6 +109,13 @@
fmt.Fprintf(buf, "%3d%%", 100*counts.FinishedActions/counts.TotalActions)
case 'e':
fmt.Fprintf(buf, "%.3f", time.Since(s.start).Seconds())
+ case 'l':
+ if counts.EstimatedTime.IsZero() {
+ // No esitimated data
+ buf.WriteRune('?')
+ } else {
+ fmt.Fprintf(buf, "%s", remainingTimeString(counts.EstimatedTime))
+ }
default:
buf.WriteString("unknown placeholder '")
buf.WriteByte(c)
diff --git a/ui/terminal/status.go b/ui/terminal/status.go
index 2ad174f..810e3c9 100644
--- a/ui/terminal/status.go
+++ b/ui/terminal/status.go
@@ -27,9 +27,10 @@
// statusFormat takes nearly all the same options as NINJA_STATUS.
// %c is currently unsupported.
func NewStatusOutput(w io.Writer, statusFormat string, forceSimpleOutput, quietBuild, forceKeepANSI bool) status.StatusOutput {
- formatter := newFormatter(statusFormat, quietBuild)
+ useSmartStatus := !forceSimpleOutput && isSmartTerminal(w)
+ formatter := newFormatter(statusFormat, quietBuild, useSmartStatus)
- if !forceSimpleOutput && isSmartTerminal(w) {
+ if useSmartStatus {
return NewSmartStatusOutput(w, formatter)
} else {
return NewSimpleStatusOutput(w, formatter, forceKeepANSI)