Merge "Merge multiple compat_config.xml's."
diff --git a/Android.bp b/Android.bp
index d469f41..7576102 100644
--- a/Android.bp
+++ b/Android.bp
@@ -298,6 +298,7 @@
"java/sdk.go",
"java/sdk_library.go",
"java/support_libraries.go",
+ "java/sysprop.go",
"java/system_modules.go",
"java/testing.go",
"java/tradefed.go",
diff --git a/android/androidmk_test.go b/android/androidmk_test.go
index 940e324..71f8020 100644
--- a/android/androidmk_test.go
+++ b/android/androidmk_test.go
@@ -43,14 +43,6 @@
}
func TestAndroidMkSingleton_PassesUpdatedAndroidMkDataToCustomCallback(t *testing.T) {
- config := TestConfig(buildDir, nil)
- config.inMake = true // Enable androidmk Singleton
-
- ctx := NewTestContext()
- ctx.RegisterSingletonType("androidmk", AndroidMkSingleton)
- ctx.RegisterModuleType("custom", customModuleFactory)
- ctx.Register()
-
bp := `
custom {
name: "foo",
@@ -60,9 +52,13 @@
}
`
- ctx.MockFileSystem(map[string][]byte{
- "Android.bp": []byte(bp),
- })
+ config := TestConfig(buildDir, nil, bp, nil)
+ config.inMake = true // Enable androidmk Singleton
+
+ ctx := NewTestContext()
+ ctx.RegisterSingletonType("androidmk", AndroidMkSingleton)
+ ctx.RegisterModuleType("custom", customModuleFactory)
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
diff --git a/android/arch.go b/android/arch.go
index 276dd3b..131d3b9 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -824,7 +824,10 @@
osTargets := mctx.Config().Targets[os]
image := base.commonProperties.ImageVariation
// Filter NativeBridge targets unless they are explicitly supported
- if os == Android && !Bool(base.commonProperties.Native_bridge_supported) {
+ // Skip creating native bridge variants for vendor modules
+ if os == Android &&
+ !(Bool(base.commonProperties.Native_bridge_supported) && image == CoreVariation) {
+
var targets []Target
for _, t := range osTargets {
if !t.NativeBridge {
diff --git a/android/arch_test.go b/android/arch_test.go
index b41e1ab..98b0534 100644
--- a/android/arch_test.go
+++ b/android/arch_test.go
@@ -289,10 +289,6 @@
}
`
- mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
- }
-
testCases := []struct {
name string
config func(Config)
@@ -337,11 +333,11 @@
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
+ config := TestArchConfig(buildDir, nil, bp, nil)
+
ctx := NewTestArchContext()
ctx.RegisterModuleType("module", archTestModuleFactory)
- ctx.MockFileSystem(mockFS)
- ctx.Register()
- config := TestArchConfig(buildDir, nil)
+ ctx.Register(config)
if tt.config != nil {
tt.config(config)
}
diff --git a/android/config.go b/android/config.go
index e1db55d..a9833da 100644
--- a/android/config.go
+++ b/android/config.go
@@ -25,7 +25,9 @@
"strings"
"sync"
+ "github.com/google/blueprint"
"github.com/google/blueprint/bootstrap"
+ "github.com/google/blueprint/pathtools"
"github.com/google/blueprint/proptools"
)
@@ -115,6 +117,9 @@
stopBefore bootstrap.StopBefore
+ fs pathtools.FileSystem
+ mockBpList string
+
OncePer
}
@@ -200,7 +205,7 @@
}
// TestConfig returns a Config object suitable for using for tests
-func TestConfig(buildDir string, env map[string]string) Config {
+func TestConfig(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config {
envCopy := make(map[string]string)
for k, v := range env {
envCopy[k] = v
@@ -231,6 +236,8 @@
}
config.TestProductVariables = &config.productVariables
+ config.mockFileSystem(bp, fs)
+
if err := config.fromEnv(); err != nil {
panic(err)
}
@@ -238,8 +245,8 @@
return Config{config}
}
-func TestArchConfigNativeBridge(buildDir string, env map[string]string) Config {
- testConfig := TestArchConfig(buildDir, env)
+func TestArchConfigNativeBridge(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config {
+ testConfig := TestArchConfig(buildDir, env, bp, fs)
config := testConfig.config
config.Targets[Android] = []Target{
@@ -252,8 +259,8 @@
return testConfig
}
-func TestArchConfigFuchsia(buildDir string, env map[string]string) Config {
- testConfig := TestConfig(buildDir, env)
+func TestArchConfigFuchsia(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config {
+ testConfig := TestConfig(buildDir, env, bp, fs)
config := testConfig.config
config.Targets = map[OsType][]Target{
@@ -269,8 +276,8 @@
}
// TestConfig returns a Config object suitable for using for tests that need to run the arch mutator
-func TestArchConfig(buildDir string, env map[string]string) Config {
- testConfig := TestConfig(buildDir, env)
+func TestArchConfig(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config {
+ testConfig := TestConfig(buildDir, env, bp, fs)
config := testConfig.config
config.Targets = map[OsType][]Target{
@@ -312,6 +319,8 @@
srcDir: srcDir,
buildDir: buildDir,
multilibConflicts: make(map[ArchType]bool),
+
+ fs: pathtools.OsFs,
}
config.deviceConfig = &deviceConfig{
@@ -387,6 +396,36 @@
return Config{config}, nil
}
+// mockFileSystem replaces all reads with accesses to the provided map of
+// filenames to contents stored as a byte slice.
+func (c *config) mockFileSystem(bp string, fs map[string][]byte) {
+ mockFS := map[string][]byte{}
+
+ if _, exists := mockFS["Android.bp"]; !exists {
+ mockFS["Android.bp"] = []byte(bp)
+ }
+
+ for k, v := range fs {
+ mockFS[k] = v
+ }
+
+ // no module list file specified; find every file named Blueprints or Android.bp
+ pathsToParse := []string{}
+ for candidate := range mockFS {
+ base := filepath.Base(candidate)
+ if base == "Blueprints" || base == "Android.bp" {
+ pathsToParse = append(pathsToParse, candidate)
+ }
+ }
+ if len(pathsToParse) < 1 {
+ panic(fmt.Sprintf("No Blueprint or Android.bp files found in mock filesystem: %v\n", mockFS))
+ }
+ mockFS[blueprint.MockModuleListFile] = []byte(strings.Join(pathsToParse, "\n"))
+
+ c.fs = pathtools.MockFs(mockFS)
+ c.mockBpList = blueprint.MockModuleListFile
+}
+
func (c *config) fromEnv() error {
switch c.Getenv("EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9") {
case "", "true":
diff --git a/android/csuite_config_test.go b/android/csuite_config_test.go
index 5f86bbb..bf1a19a 100644
--- a/android/csuite_config_test.go
+++ b/android/csuite_config_test.go
@@ -19,15 +19,11 @@
)
func testCSuiteConfig(test *testing.T, bpFileContents string) *TestContext {
- config := TestArchConfig(buildDir, nil)
+ config := TestArchConfig(buildDir, nil, bpFileContents, nil)
ctx := NewTestArchContext()
ctx.RegisterModuleType("csuite_config", CSuiteConfigFactory)
- ctx.Register()
- mockFiles := map[string][]byte{
- "Android.bp": []byte(bpFileContents),
- }
- ctx.MockFileSystem(mockFiles)
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(test, errs)
_, errs = ctx.PrepareBuildActions(config)
diff --git a/android/defaults_test.go b/android/defaults_test.go
index 80980f7..ba607ef 100644
--- a/android/defaults_test.go
+++ b/android/defaults_test.go
@@ -58,19 +58,6 @@
}
func TestDefaultsAllowMissingDependencies(t *testing.T) {
- config := TestConfig(buildDir, nil)
- config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
-
- ctx := NewTestContext()
- ctx.SetAllowMissingDependencies(true)
-
- ctx.RegisterModuleType("test", defaultsTestModuleFactory)
- ctx.RegisterModuleType("defaults", defaultsTestDefaultsFactory)
-
- ctx.PreArchMutators(RegisterDefaultsPreArchMutators)
-
- ctx.Register()
-
bp := `
defaults {
name: "defaults",
@@ -91,9 +78,18 @@
}
`
- ctx.MockFileSystem(map[string][]byte{
- "Android.bp": []byte(bp),
- })
+ config := TestConfig(buildDir, nil, bp, nil)
+ config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
+
+ ctx := NewTestContext()
+ ctx.SetAllowMissingDependencies(true)
+
+ ctx.RegisterModuleType("test", defaultsTestModuleFactory)
+ ctx.RegisterModuleType("defaults", defaultsTestDefaultsFactory)
+
+ ctx.PreArchMutators(RegisterDefaultsPreArchMutators)
+
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
diff --git a/android/module_test.go b/android/module_test.go
index fef1766..6e648d7 100644
--- a/android/module_test.go
+++ b/android/module_test.go
@@ -178,15 +178,9 @@
}
`
- mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
- }
+ config := TestConfig(buildDir, nil, bp, nil)
- ctx.MockFileSystem(mockFS)
-
- ctx.Register()
-
- config := TestConfig(buildDir, nil)
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
diff --git a/android/mutator_test.go b/android/mutator_test.go
index 2350fdb..d179f9d 100644
--- a/android/mutator_test.go
+++ b/android/mutator_test.go
@@ -56,7 +56,15 @@
}
func TestMutatorAddMissingDependencies(t *testing.T) {
- config := TestConfig(buildDir, nil)
+ bp := `
+ test {
+ name: "foo",
+ deps_missing_deps: ["regular_missing_dep"],
+ mutator_missing_deps: ["added_missing_dep"],
+ }
+ `
+
+ config := TestConfig(buildDir, nil, bp, nil)
config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
ctx := NewTestContext()
@@ -67,21 +75,7 @@
ctx.TopDown("add_missing_dependencies", addMissingDependenciesMutator)
})
- bp := `
- test {
- name: "foo",
- deps_missing_deps: ["regular_missing_dep"],
- mutator_missing_deps: ["added_missing_dep"],
- }
- `
-
- mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
- }
-
- ctx.MockFileSystem(mockFS)
-
- ctx.Register()
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
@@ -139,15 +133,9 @@
}
`
- mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
- }
+ config := TestConfig(buildDir, nil, bp, nil)
- ctx.MockFileSystem(mockFS)
-
- ctx.Register()
-
- config := TestConfig(buildDir, nil)
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
diff --git a/android/namespace_test.go b/android/namespace_test.go
index 90058e3..66c0d89 100644
--- a/android/namespace_test.go
+++ b/android/namespace_test.go
@@ -633,10 +633,9 @@
}
func setupTestFromFiles(bps map[string][]byte) (ctx *TestContext, errs []error) {
- config := TestConfig(buildDir, nil)
+ config := TestConfig(buildDir, nil, "", bps)
ctx = NewTestContext()
- ctx.MockFileSystem(bps)
ctx.RegisterModuleType("test_module", newTestModule)
ctx.RegisterModuleType("soong_namespace", NamespaceFactory)
ctx.Context.RegisterModuleType("blueprint_test_module", newBlueprintTestModule)
@@ -644,7 +643,7 @@
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
ctx.BottomUp("rename", renameMutator)
})
- ctx.Register()
+ ctx.Register(config)
_, errs = ctx.ParseBlueprintsFiles("Android.bp")
if len(errs) > 0 {
diff --git a/android/neverallow_test.go b/android/neverallow_test.go
index bd94e37..6f07a4a 100644
--- a/android/neverallow_test.go
+++ b/android/neverallow_test.go
@@ -44,11 +44,11 @@
NeverAllow().InDirectDeps("not_allowed_in_direct_deps"),
},
fs: map[string][]byte{
- "top/Blueprints": []byte(`
+ "top/Android.bp": []byte(`
cc_library {
name: "not_allowed_in_direct_deps",
}`),
- "other/Blueprints": []byte(`
+ "other/Android.bp": []byte(`
cc_library {
name: "libother",
static_libs: ["not_allowed_in_direct_deps"],
@@ -65,7 +65,7 @@
{
name: "include_dir not allowed to reference art",
fs: map[string][]byte{
- "other/Blueprints": []byte(`
+ "other/Android.bp": []byte(`
cc_library {
name: "libother",
include_dirs: ["art/libdexfile/include"],
@@ -78,7 +78,7 @@
{
name: "include_dir can reference another location",
fs: map[string][]byte{
- "other/Blueprints": []byte(`
+ "other/Android.bp": []byte(`
cc_library {
name: "libother",
include_dirs: ["another/include"],
@@ -89,7 +89,7 @@
{
name: "no vndk.enabled under vendor directory",
fs: map[string][]byte{
- "vendor/Blueprints": []byte(`
+ "vendor/Android.bp": []byte(`
cc_library {
name: "libvndk",
vendor_available: true,
@@ -105,7 +105,7 @@
{
name: "no vndk.enabled under device directory",
fs: map[string][]byte{
- "device/Blueprints": []byte(`
+ "device/Android.bp": []byte(`
cc_library {
name: "libvndk",
vendor_available: true,
@@ -121,7 +121,7 @@
{
name: "vndk-ext under vendor or device directory",
fs: map[string][]byte{
- "device/Blueprints": []byte(`
+ "device/Android.bp": []byte(`
cc_library {
name: "libvndk1_ext",
vendor: true,
@@ -129,7 +129,7 @@
enabled: true,
},
}`),
- "vendor/Blueprints": []byte(`
+ "vendor/Android.bp": []byte(`
cc_library {
name: "libvndk2_ext",
vendor: true,
@@ -143,7 +143,7 @@
{
name: "no enforce_vintf_manifest.cflags",
fs: map[string][]byte{
- "Blueprints": []byte(`
+ "Android.bp": []byte(`
cc_library {
name: "libexample",
product_variables: {
@@ -161,7 +161,7 @@
{
name: "no treble_linker_namespaces.cflags",
fs: map[string][]byte{
- "Blueprints": []byte(`
+ "Android.bp": []byte(`
cc_library {
name: "libexample",
product_variables: {
@@ -178,7 +178,7 @@
{
name: "libc_bionic_ndk treble_linker_namespaces.cflags",
fs: map[string][]byte{
- "Blueprints": []byte(`
+ "Android.bp": []byte(`
cc_library {
name: "libc_bionic_ndk",
product_variables: {
@@ -192,7 +192,7 @@
{
name: "dependency on updatable-media",
fs: map[string][]byte{
- "Blueprints": []byte(`
+ "Android.bp": []byte(`
java_library {
name: "needs_updatable_media",
libs: ["updatable-media"],
@@ -205,7 +205,7 @@
{
name: "java_device_for_host",
fs: map[string][]byte{
- "Blueprints": []byte(`
+ "Android.bp": []byte(`
java_device_for_host {
name: "device_for_host",
libs: ["core-libart"],
@@ -219,7 +219,7 @@
{
name: "sdk_version: \"none\" inside core libraries",
fs: map[string][]byte{
- "libcore/Blueprints": []byte(`
+ "libcore/Android.bp": []byte(`
java_library {
name: "inside_core_libraries",
sdk_version: "none",
@@ -229,7 +229,7 @@
{
name: "sdk_version: \"none\" outside core libraries",
fs: map[string][]byte{
- "Blueprints": []byte(`
+ "Android.bp": []byte(`
java_library {
name: "outside_core_libraries",
sdk_version: "none",
@@ -242,7 +242,7 @@
{
name: "sdk_version: \"current\"",
fs: map[string][]byte{
- "Blueprints": []byte(`
+ "Android.bp": []byte(`
java_library {
name: "outside_core_libraries",
sdk_version: "current",
@@ -254,31 +254,29 @@
func TestNeverallow(t *testing.T) {
for _, test := range neverallowTests {
// Create a test per config to allow for test specific config, e.g. test rules.
- config := TestConfig(buildDir, nil)
+ config := TestConfig(buildDir, nil, "", test.fs)
t.Run(test.name, func(t *testing.T) {
// If the test has its own rules then use them instead of the default ones.
if test.rules != nil {
setTestNeverallowRules(config, test.rules)
}
- _, errs := testNeverallow(config, test.fs)
+ _, errs := testNeverallow(config)
CheckErrorsAgainstExpectations(t, errs, test.expectedErrors)
})
}
}
-func testNeverallow(config Config, fs map[string][]byte) (*TestContext, []error) {
+func testNeverallow(config Config) (*TestContext, []error) {
ctx := NewTestContext()
ctx.RegisterModuleType("cc_library", newMockCcLibraryModule)
ctx.RegisterModuleType("java_library", newMockJavaLibraryModule)
ctx.RegisterModuleType("java_library_host", newMockJavaLibraryModule)
ctx.RegisterModuleType("java_device_for_host", newMockJavaLibraryModule)
ctx.PostDepsMutators(registerNeverallowMutator)
- ctx.Register()
+ ctx.Register(config)
- ctx.MockFileSystem(fs)
-
- _, errs := ctx.ParseBlueprintsFiles("Blueprints")
+ _, errs := ctx.ParseBlueprintsFiles("Android.bp")
if len(errs) > 0 {
return ctx, errs
}
diff --git a/android/package_test.go b/android/package_test.go
index 8071c51..bc66928 100644
--- a/android/package_test.go
+++ b/android/package_test.go
@@ -84,14 +84,12 @@
func testPackage(fs map[string][]byte) (*TestContext, []error) {
// Create a new config per test as visibility information is stored in the config.
- config := TestArchConfig(buildDir, nil)
+ config := TestArchConfig(buildDir, nil, "", fs)
ctx := NewTestArchContext()
ctx.RegisterModuleType("package", PackageFactory)
ctx.PreArchMutators(RegisterPackageRenamer)
- ctx.Register()
-
- ctx.MockFileSystem(fs)
+ ctx.Register(config)
_, errs := ctx.ParseBlueprintsFiles(".")
if len(errs) > 0 {
diff --git a/android/path_properties_test.go b/android/path_properties_test.go
index c859bc5..f367b82 100644
--- a/android/path_properties_test.go
+++ b/android/path_properties_test.go
@@ -97,12 +97,6 @@
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- config := TestArchConfig(buildDir, nil)
- ctx := NewTestArchContext()
-
- ctx.RegisterModuleType("test", pathDepsMutatorTestModuleFactory)
- ctx.RegisterModuleType("filegroup", FileGroupFactory)
-
bp := test.bp + `
filegroup {
name: "a",
@@ -121,13 +115,13 @@
}
`
- mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
- }
+ config := TestArchConfig(buildDir, nil, bp, nil)
+ ctx := NewTestArchContext()
- ctx.MockFileSystem(mockFS)
+ ctx.RegisterModuleType("test", pathDepsMutatorTestModuleFactory)
+ ctx.RegisterModuleType("filegroup", FileGroupFactory)
- ctx.Register()
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
diff --git a/android/paths.go b/android/paths.go
index 85c861d..a04dc6b 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -1353,19 +1353,17 @@
type testPathContext struct {
config Config
- fs pathtools.FileSystem
}
-func (x *testPathContext) Fs() pathtools.FileSystem { return x.fs }
+func (x *testPathContext) Fs() pathtools.FileSystem { return x.config.fs }
func (x *testPathContext) Config() Config { return x.config }
func (x *testPathContext) AddNinjaFileDeps(...string) {}
// PathContextForTesting returns a PathContext that can be used in tests, for example to create an OutputPath with
// PathForOutput.
-func PathContextForTesting(config Config, fs map[string][]byte) PathContext {
+func PathContextForTesting(config Config) PathContext {
return &testPathContext{
config: config,
- fs: pathtools.MockFs(fs),
}
}
diff --git a/android/paths_test.go b/android/paths_test.go
index a8560a1..5ff5f99 100644
--- a/android/paths_test.go
+++ b/android/paths_test.go
@@ -241,8 +241,12 @@
return false
}
+func pathTestConfig(buildDir string) Config {
+ return TestConfig(buildDir, nil, "", nil)
+}
+
func TestPathForModuleInstall(t *testing.T) {
- testConfig := TestConfig("", nil)
+ testConfig := pathTestConfig("")
hostTarget := Target{Os: Linux}
deviceTarget := Target{Os: Android}
@@ -579,18 +583,19 @@
}
func TestDirectorySortedPaths(t *testing.T) {
- config := TestConfig("out", nil)
-
- ctx := PathContextForTesting(config, map[string][]byte{
- "a.txt": nil,
- "a/txt": nil,
- "a/b/c": nil,
- "a/b/d": nil,
- "b": nil,
- "b/b.txt": nil,
- "a/a.txt": nil,
+ config := TestConfig("out", nil, "", map[string][]byte{
+ "Android.bp": nil,
+ "a.txt": nil,
+ "a/txt": nil,
+ "a/b/c": nil,
+ "a/b/d": nil,
+ "b": nil,
+ "b/b.txt": nil,
+ "a/a.txt": nil,
})
+ ctx := PathContextForTesting(config)
+
makePaths := func() Paths {
return Paths{
PathForSource(ctx, "a.txt"),
@@ -754,7 +759,7 @@
t.Run(f.name, func(t *testing.T) {
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
- testConfig := TestConfig(test.buildDir, nil)
+ testConfig := pathTestConfig(test.buildDir)
ctx := &configErrorWrapper{config: testConfig}
_, err := f.f(ctx, test.src)
if len(ctx.errors) > 0 {
@@ -886,7 +891,6 @@
func testPathForModuleSrc(t *testing.T, buildDir string, tests []pathForModuleSrcTestCase) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- config := TestConfig(buildDir, nil)
ctx := NewTestContext()
ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory)
@@ -920,9 +924,9 @@
"foo/src_special/$": nil,
}
- ctx.MockFileSystem(mockFS)
+ config := TestConfig(buildDir, nil, "", mockFS)
- ctx.Register()
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"fg/Android.bp", "foo/Android.bp", "ofp/Android.bp"})
FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
@@ -1097,14 +1101,6 @@
}
func TestPathsForModuleSrc_AllowMissingDependencies(t *testing.T) {
- config := TestConfig(buildDir, nil)
- config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
-
- ctx := NewTestContext()
- ctx.SetAllowMissingDependencies(true)
-
- ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory)
-
bp := `
test {
name: "foo",
@@ -1121,13 +1117,16 @@
}
`
- mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
- }
+ config := TestConfig(buildDir, nil, bp, nil)
+ config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
- ctx.MockFileSystem(mockFS)
+ ctx := NewTestContext()
+ ctx.SetAllowMissingDependencies(true)
- ctx.Register()
+ ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory)
+
+ ctx.Register(config)
+
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
@@ -1160,7 +1159,7 @@
func ExampleOutputPath_ReplaceExtension() {
ctx := &configErrorWrapper{
- config: TestConfig("out", nil),
+ config: TestConfig("out", nil, "", nil),
}
p := PathForOutput(ctx, "system/framework").Join(ctx, "boot.art")
p2 := p.ReplaceExtension(ctx, "oat")
@@ -1174,7 +1173,7 @@
func ExampleOutputPath_FileInSameDir() {
ctx := &configErrorWrapper{
- config: TestConfig("out", nil),
+ config: TestConfig("out", nil, "", nil),
}
p := PathForOutput(ctx, "system/framework").Join(ctx, "boot.art")
p2 := p.InSameDir(ctx, "oat", "arm", "boot.vdex")
diff --git a/android/prebuilt_etc_test.go b/android/prebuilt_etc_test.go
index 3c466a1..6e751e7 100644
--- a/android/prebuilt_etc_test.go
+++ b/android/prebuilt_etc_test.go
@@ -21,7 +21,14 @@
)
func testPrebuiltEtc(t *testing.T, bp string) (*TestContext, Config) {
- config := TestArchConfig(buildDir, nil)
+ fs := map[string][]byte{
+ "foo.conf": nil,
+ "bar.conf": nil,
+ "baz.conf": nil,
+ }
+
+ config := TestArchConfig(buildDir, nil, bp, fs)
+
ctx := NewTestArchContext()
ctx.RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory)
ctx.RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory)
@@ -29,14 +36,7 @@
ctx.RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory)
ctx.RegisterModuleType("prebuilt_font", PrebuiltFontFactory)
ctx.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory)
- ctx.Register()
- mockFiles := map[string][]byte{
- "Android.bp": []byte(bp),
- "foo.conf": nil,
- "bar.conf": nil,
- "baz.conf": nil,
- }
- ctx.MockFileSystem(mockFiles)
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
diff --git a/android/prebuilt_test.go b/android/prebuilt_test.go
index 81fb278..600f078 100644
--- a/android/prebuilt_test.go
+++ b/android/prebuilt_test.go
@@ -125,29 +125,30 @@
}
func TestPrebuilts(t *testing.T) {
- config := TestConfig(buildDir, nil)
+ fs := map[string][]byte{
+ "prebuilt_file": nil,
+ "source_file": nil,
+ }
for _, test := range prebuiltsTests {
t.Run(test.name, func(t *testing.T) {
+ bp := `
+ source {
+ name: "foo",
+ deps: [":bar"],
+ }
+ ` + test.modules
+ config := TestConfig(buildDir, nil, bp, fs)
+
ctx := NewTestContext()
ctx.PreArchMutators(RegisterPrebuiltsPreArchMutators)
ctx.PostDepsMutators(RegisterPrebuiltsPostDepsMutators)
ctx.RegisterModuleType("filegroup", FileGroupFactory)
ctx.RegisterModuleType("prebuilt", newPrebuiltModule)
ctx.RegisterModuleType("source", newSourceModule)
- ctx.Register()
- ctx.MockFileSystem(map[string][]byte{
- "prebuilt_file": nil,
- "source_file": nil,
- "Blueprints": []byte(`
- source {
- name: "foo",
- deps: [":bar"],
- }
- ` + test.modules),
- })
+ ctx.Register(config)
- _, errs := ctx.ParseBlueprintsFiles("Blueprints")
+ _, errs := ctx.ParseBlueprintsFiles("Android.bp")
FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
FailIfErrored(t, errs)
diff --git a/android/rule_builder_test.go b/android/rule_builder_test.go
index 52c32df..acf8127 100644
--- a/android/rule_builder_test.go
+++ b/android/rule_builder_test.go
@@ -27,19 +27,18 @@
)
func pathContext() PathContext {
- return PathContextForTesting(TestConfig("out", nil),
- map[string][]byte{
- "ld": nil,
- "a.o": nil,
- "b.o": nil,
- "cp": nil,
- "a": nil,
- "b": nil,
- "ls": nil,
- "turbine": nil,
- "java": nil,
- "javac": nil,
- })
+ return PathContextForTesting(TestConfig("out", nil, "", map[string][]byte{
+ "ld": nil,
+ "a.o": nil,
+ "b.o": nil,
+ "cp": nil,
+ "a": nil,
+ "b": nil,
+ "ls": nil,
+ "turbine": nil,
+ "java": nil,
+ "javac": nil,
+ }))
}
func ExampleRuleBuilder() {
@@ -276,7 +275,7 @@
"input3": nil,
}
- ctx := PathContextForTesting(TestConfig("out", nil), fs)
+ ctx := PathContextForTesting(TestConfig("out", nil, "", fs))
addCommands := func(rule *RuleBuilder) {
cmd := rule.Command().
@@ -445,6 +444,11 @@
}
func TestRuleBuilder_Build(t *testing.T) {
+ fs := map[string][]byte{
+ "bar": nil,
+ "cp": nil,
+ }
+
bp := `
rule_builder_test {
name: "foo",
@@ -458,16 +462,11 @@
}
`
- config := TestConfig(buildDir, nil)
+ config := TestConfig(buildDir, nil, bp, fs)
ctx := NewTestContext()
- ctx.MockFileSystem(map[string][]byte{
- "Android.bp": []byte(bp),
- "bar": nil,
- "cp": nil,
- })
ctx.RegisterModuleType("rule_builder_test", testRuleBuilderFactory)
ctx.RegisterSingletonType("rule_builder_test", testRuleBuilderSingletonFactory)
- ctx.Register()
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
diff --git a/android/sh_binary_test.go b/android/sh_binary_test.go
index 8488fe4..137e773 100644
--- a/android/sh_binary_test.go
+++ b/android/sh_binary_test.go
@@ -6,19 +6,18 @@
)
func testShBinary(t *testing.T, bp string) (*TestContext, Config) {
- config := TestArchConfig(buildDir, nil)
-
- ctx := NewTestArchContext()
- ctx.RegisterModuleType("sh_test", ShTestFactory)
- ctx.RegisterModuleType("sh_test_host", ShTestHostFactory)
- ctx.Register()
- mockFiles := map[string][]byte{
- "Android.bp": []byte(bp),
+ fs := map[string][]byte{
"test.sh": nil,
"testdata/data1": nil,
"testdata/sub/data2": nil,
}
- ctx.MockFileSystem(mockFiles)
+
+ config := TestArchConfig(buildDir, nil, bp, fs)
+
+ ctx := NewTestArchContext()
+ ctx.RegisterModuleType("sh_test", ShTestFactory)
+ ctx.RegisterModuleType("sh_test_host", ShTestHostFactory)
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
diff --git a/android/testing.go b/android/testing.go
index 26f1e4d..aaf98f5 100644
--- a/android/testing.go
+++ b/android/testing.go
@@ -16,7 +16,6 @@
import (
"fmt"
- "path/filepath"
"regexp"
"strings"
"testing"
@@ -68,7 +67,11 @@
ctx.postDeps = append(ctx.postDeps, f)
}
-func (ctx *TestContext) Register() {
+func (ctx *TestContext) Register(config Config) {
+ ctx.SetFs(config.fs)
+ if config.mockBpList != "" {
+ ctx.SetModuleListFile(config.mockBpList)
+ }
registerMutators(ctx.Context.Context, ctx.preArch, ctx.preDeps, ctx.postDeps)
ctx.RegisterSingletonType("env", EnvSingleton)
@@ -132,25 +135,6 @@
"\nall singletons: %v", name, allSingletonNames))
}
-// MockFileSystem causes the Context to replace all reads with accesses to the provided map of
-// filenames to contents stored as a byte slice.
-func (ctx *TestContext) MockFileSystem(files map[string][]byte) {
- // no module list file specified; find every file named Blueprints or Android.bp
- pathsToParse := []string{}
- for candidate := range files {
- base := filepath.Base(candidate)
- if base == "Blueprints" || base == "Android.bp" {
- pathsToParse = append(pathsToParse, candidate)
- }
- }
- if len(pathsToParse) < 1 {
- panic(fmt.Sprintf("No Blueprint or Android.bp files found in mock filesystem: %v\n", files))
- }
- files[blueprint.MockModuleListFile] = []byte(strings.Join(pathsToParse, "\n"))
-
- ctx.Context.MockFileSystem(files)
-}
-
type testBuildProvider interface {
BuildParamsForTests() []BuildParams
RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
diff --git a/android/variable_test.go b/android/variable_test.go
index 1826e39..451d43d 100644
--- a/android/variable_test.go
+++ b/android/variable_test.go
@@ -198,18 +198,11 @@
name: "baz",
}
`
-
- mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
- }
-
- ctx.MockFileSystem(mockFS)
-
- ctx.Register()
-
- config := TestConfig(buildDir, nil)
+ config := TestConfig(buildDir, nil, bp, nil)
config.TestProductVariables.Eng = proptools.BoolPtr(true)
+ ctx.Register(config)
+
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
diff --git a/android/visibility_test.go b/android/visibility_test.go
index 1984a21..fbf2fb7 100644
--- a/android/visibility_test.go
+++ b/android/visibility_test.go
@@ -868,7 +868,7 @@
func testVisibility(buildDir string, fs map[string][]byte) (*TestContext, []error) {
// Create a new config per test as visibility information is stored in the config.
- config := TestArchConfig(buildDir, nil)
+ config := TestArchConfig(buildDir, nil, "", fs)
ctx := NewTestArchContext()
ctx.RegisterModuleType("package", PackageFactory)
@@ -879,9 +879,7 @@
ctx.PreArchMutators(RegisterDefaultsPreArchMutators)
ctx.PreArchMutators(RegisterVisibilityRuleGatherer)
ctx.PostDepsMutators(RegisterVisibilityRuleEnforcer)
- ctx.Register()
-
- ctx.MockFileSystem(fs)
+ ctx.Register(config)
_, errs := ctx.ParseBlueprintsFiles(".")
if len(errs) > 0 {
diff --git a/android/vts_config_test.go b/android/vts_config_test.go
index 162944d..254fa92 100644
--- a/android/vts_config_test.go
+++ b/android/vts_config_test.go
@@ -19,15 +19,11 @@
)
func testVtsConfig(test *testing.T, bpFileContents string) *TestContext {
- config := TestArchConfig(buildDir, nil)
+ config := TestArchConfig(buildDir, nil, bpFileContents, nil)
ctx := NewTestArchContext()
ctx.RegisterModuleType("vts_config", VtsConfigFactory)
- ctx.Register()
- mockFiles := map[string][]byte{
- "Android.bp": []byte(bpFileContents),
- }
- ctx.MockFileSystem(mockFiles)
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(test, errs)
_, errs = ctx.PrepareBuildActions(config)
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 34547a2..b2d891d 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -93,69 +93,6 @@
func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
android.ClearApexDependency()
- config := android.TestArchConfig(buildDir, nil)
- config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
- config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
- config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
- config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q")
- config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false)
- config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
-
- ctx := android.NewTestArchContext()
- ctx.RegisterModuleType("apex", BundleFactory)
- ctx.RegisterModuleType("apex_test", testApexBundleFactory)
- ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
- ctx.RegisterModuleType("apex_key", ApexKeyFactory)
- ctx.RegisterModuleType("apex_defaults", defaultsFactory)
- ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
- ctx.RegisterModuleType("override_apex", overrideApexFactory)
-
- ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
- ctx.RegisterModuleType("cc_library_shared", cc.LibrarySharedFactory)
- ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
- ctx.RegisterModuleType("cc_prebuilt_library_shared", cc.PrebuiltSharedLibraryFactory)
- ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory)
- ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
- ctx.RegisterModuleType("cc_object", cc.ObjectFactory)
- ctx.RegisterModuleType("cc_defaults", func() android.Module {
- return cc.DefaultsFactory()
- })
- ctx.RegisterModuleType("cc_test", cc.TestFactory)
- ctx.RegisterModuleType("llndk_library", cc.LlndkLibraryFactory)
- ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory)
- ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory)
- ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory)
- ctx.RegisterModuleType("prebuilt_etc", android.PrebuiltEtcFactory)
- ctx.RegisterModuleType("sh_binary", android.ShBinaryFactory)
- ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
- ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
- ctx.RegisterModuleType("java_library", java.LibraryFactory)
- ctx.RegisterModuleType("java_import", java.ImportFactory)
- ctx.RegisterModuleType("java_system_modules", java.SystemModulesFactory)
- ctx.RegisterModuleType("android_app", java.AndroidAppFactory)
- ctx.RegisterModuleType("android_app_import", java.AndroidAppImportFactory)
- ctx.RegisterModuleType("override_android_app", java.OverrideAndroidAppModuleFactory)
-
- ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
- ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
- ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel()
- })
- ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
- ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
- ctx.BottomUp("link", cc.LinkageMutator).Parallel()
- ctx.BottomUp("test_per_src", cc.TestPerSrcMutator).Parallel()
- ctx.BottomUp("version", cc.VersionMutator).Parallel()
- ctx.BottomUp("begin", cc.BeginMutator).Parallel()
- })
- ctx.PreDepsMutators(RegisterPreDepsMutators)
- ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
- ctx.PostDepsMutators(RegisterPostDepsMutators)
- ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
- ctx.TopDown("prebuilt_select", android.PrebuiltSelectModuleMutator).Parallel()
- ctx.BottomUp("prebuilt_postdeps", android.PrebuiltPostDepsMutator).Parallel()
- })
-
- ctx.Register()
bp = bp + `
toolchain_library {
@@ -271,10 +208,10 @@
],
}
`
+
bp = bp + java.GatherRequiredDepsForTest()
fs := map[string][]byte{
- "Android.bp": []byte(bp),
"a.java": nil,
"PrebuiltAppFoo.apk": nil,
"PrebuiltAppFooPriv.apk": nil,
@@ -285,42 +222,116 @@
"system/sepolicy/apex/otherapex-file_contexts": nil,
"system/sepolicy/apex/commonapex-file_contexts": nil,
"system/sepolicy/apex/com.android.vndk-file_contexts": nil,
- "mylib.cpp": nil,
- "mylib_common.cpp": nil,
- "mytest.cpp": nil,
- "mytest1.cpp": nil,
- "mytest2.cpp": nil,
- "mytest3.cpp": nil,
- "myprebuilt": nil,
- "my_include": nil,
- "foo/bar/MyClass.java": nil,
- "prebuilt.jar": nil,
- "vendor/foo/devkeys/test.x509.pem": nil,
- "vendor/foo/devkeys/test.pk8": nil,
- "testkey.x509.pem": nil,
- "testkey.pk8": nil,
- "testkey.override.x509.pem": nil,
- "testkey.override.pk8": nil,
- "vendor/foo/devkeys/testkey.avbpubkey": nil,
- "vendor/foo/devkeys/testkey.pem": nil,
- "NOTICE": nil,
- "custom_notice": nil,
- "testkey2.avbpubkey": nil,
- "testkey2.pem": nil,
- "myapex-arm64.apex": nil,
- "myapex-arm.apex": nil,
- "frameworks/base/api/current.txt": nil,
- "framework/aidl/a.aidl": nil,
- "build/make/core/proguard.flags": nil,
- "build/make/core/proguard_basic_keeps.flags": nil,
- "dummy.txt": nil,
+ "mylib.cpp": nil,
+ "mylib_common.cpp": nil,
+ "mytest.cpp": nil,
+ "mytest1.cpp": nil,
+ "mytest2.cpp": nil,
+ "mytest3.cpp": nil,
+ "myprebuilt": nil,
+ "my_include": nil,
+ "foo/bar/MyClass.java": nil,
+ "prebuilt.jar": nil,
+ "vendor/foo/devkeys/test.x509.pem": nil,
+ "vendor/foo/devkeys/test.pk8": nil,
+ "testkey.x509.pem": nil,
+ "testkey.pk8": nil,
+ "testkey.override.x509.pem": nil,
+ "testkey.override.pk8": nil,
+ "vendor/foo/devkeys/testkey.avbpubkey": nil,
+ "vendor/foo/devkeys/testkey.pem": nil,
+ "NOTICE": nil,
+ "custom_notice": nil,
+ "testkey2.avbpubkey": nil,
+ "testkey2.pem": nil,
+ "myapex-arm64.apex": nil,
+ "myapex-arm.apex": nil,
+ "frameworks/base/api/current.txt": nil,
+ "framework/aidl/a.aidl": nil,
+ "build/make/core/proguard.flags": nil,
+ "build/make/core/proguard_basic_keeps.flags": nil,
+ "dummy.txt": nil,
}
for _, handler := range handlers {
- handler(fs, config)
+ // The fs now needs to be populated before creating the config, call handlers twice
+ // for now, once to get any fs changes, and later after the config was created to
+ // set product variables or targets.
+ tempConfig := android.TestArchConfig(buildDir, nil, bp, fs)
+ handler(fs, tempConfig)
}
- ctx.MockFileSystem(fs)
+ config := android.TestArchConfig(buildDir, nil, bp, fs)
+ config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
+ config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
+ config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
+ config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q")
+ config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false)
+ config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
+
+ for _, handler := range handlers {
+ // The fs now needs to be populated before creating the config, call handlers twice
+ // for now, earlier to get any fs changes, and now after the config was created to
+ // set product variables or targets.
+ tempFS := map[string][]byte{}
+ handler(tempFS, config)
+ }
+
+ ctx := android.NewTestArchContext()
+ ctx.RegisterModuleType("apex", BundleFactory)
+ ctx.RegisterModuleType("apex_test", testApexBundleFactory)
+ ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
+ ctx.RegisterModuleType("apex_key", ApexKeyFactory)
+ ctx.RegisterModuleType("apex_defaults", defaultsFactory)
+ ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
+ ctx.RegisterModuleType("override_apex", overrideApexFactory)
+
+ ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
+ ctx.RegisterModuleType("cc_library_shared", cc.LibrarySharedFactory)
+ ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
+ ctx.RegisterModuleType("cc_prebuilt_library_shared", cc.PrebuiltSharedLibraryFactory)
+ ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory)
+ ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
+ ctx.RegisterModuleType("cc_object", cc.ObjectFactory)
+ ctx.RegisterModuleType("cc_defaults", func() android.Module {
+ return cc.DefaultsFactory()
+ })
+ ctx.RegisterModuleType("cc_test", cc.TestFactory)
+ ctx.RegisterModuleType("llndk_library", cc.LlndkLibraryFactory)
+ ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory)
+ ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory)
+ ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory)
+ ctx.RegisterModuleType("prebuilt_etc", android.PrebuiltEtcFactory)
+ ctx.RegisterModuleType("sh_binary", android.ShBinaryFactory)
+ ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
+ ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
+ ctx.RegisterModuleType("java_library", java.LibraryFactory)
+ ctx.RegisterModuleType("java_import", java.ImportFactory)
+ ctx.RegisterModuleType("java_system_modules", java.SystemModulesFactory)
+ ctx.RegisterModuleType("android_app", java.AndroidAppFactory)
+ ctx.RegisterModuleType("android_app_import", java.AndroidAppImportFactory)
+ ctx.RegisterModuleType("override_android_app", java.OverrideAndroidAppModuleFactory)
+
+ ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
+ ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
+ ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel()
+ })
+ ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
+ ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
+ ctx.BottomUp("link", cc.LinkageMutator).Parallel()
+ ctx.BottomUp("test_per_src", cc.TestPerSrcMutator).Parallel()
+ ctx.BottomUp("version", cc.VersionMutator).Parallel()
+ ctx.BottomUp("begin", cc.BeginMutator).Parallel()
+ })
+ ctx.PreDepsMutators(RegisterPreDepsMutators)
+ ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
+ ctx.PostDepsMutators(RegisterPostDepsMutators)
+ ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
+ ctx.TopDown("prebuilt_select", android.PrebuiltSelectModuleMutator).Parallel()
+ ctx.BottomUp("prebuilt_postdeps", android.PrebuiltPostDepsMutator).Parallel()
+ })
+
+ ctx.Register(config)
return ctx, config
}
diff --git a/apex/builder.go b/apex/builder.go
index d24885e..fe465f5 100644
--- a/apex/builder.go
+++ b/apex/builder.go
@@ -138,7 +138,6 @@
Command: `${zip2zip} -i $in -o $out ` +
`apex_payload.img:apex/${abi}.img ` +
`apex_manifest.json:root/apex_manifest.json ` +
- `apex_pubkey:root/apex_pubkey ` +
`apex_manifest.pb:root/apex_manifest.pb ` +
`AndroidManifest.xml:manifest/AndroidManifest.xml ` +
`assets/NOTICE.html.gz:assets/NOTICE.html.gz`,
diff --git a/bpf/bpf_test.go b/bpf/bpf_test.go
index 73b90ba..eeca057 100644
--- a/bpf/bpf_test.go
+++ b/bpf/bpf_test.go
@@ -48,21 +48,24 @@
os.Exit(run())
}
-func testContext(bp string) *android.TestContext {
+func testConfig(buildDir string, env map[string]string, bp string) android.Config {
mockFS := map[string][]byte{
"bpf.c": nil,
"BpfTest.cpp": nil,
}
- ctx := cc.CreateTestContext(bp, mockFS, android.Android)
+ return cc.TestConfig(buildDir, android.Android, env, bp, mockFS)
+}
+
+func testContext(config android.Config) *android.TestContext {
+ ctx := cc.CreateTestContext()
ctx.RegisterModuleType("bpf", bpfFactory)
- ctx.Register()
+ ctx.Register(config)
return ctx
}
func TestBpfDataDependency(t *testing.T) {
- config := android.TestArchConfig(buildDir, nil)
bp := `
bpf {
name: "bpf.o",
@@ -77,7 +80,9 @@
}
`
- ctx := testContext(bp)
+ config := testConfig(buildDir, nil, bp)
+ ctx := testContext(config)
+
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
if errs == nil {
_, errs = ctx.PrepareBuildActions(config)
diff --git a/cc/cc.go b/cc/cc.go
index 77bd7cc..4c9d42b 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -42,7 +42,7 @@
ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
ctx.BottomUp("version", VersionMutator).Parallel()
ctx.BottomUp("begin", BeginMutator).Parallel()
- ctx.BottomUp("sysprop", SyspropMutator).Parallel()
+ ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
})
android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
@@ -755,7 +755,7 @@
return c.coverage.Properties.IsCoverageVariant
}
-func (c *Module) isNdk() bool {
+func (c *Module) IsNdk() bool {
return inList(c.Name(), ndkMigratedLibs)
}
@@ -995,7 +995,7 @@
}
func (ctx *moduleContextImpl) isNdk() bool {
- return ctx.mod.isNdk()
+ return ctx.mod.IsNdk()
}
func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
@@ -2572,9 +2572,6 @@
// If the device isn't compiling against the VNDK, we always
// use the core mode.
coreVariantNeeded = true
- } else if m.Target().NativeBridge == android.NativeBridgeEnabled {
- // Skip creating vendor variants for natvie bridge modules
- coreVariantNeeded = true
} else if _, ok := m.linker.(*llndkStubDecorator); ok {
// LL-NDK stubs only exist in the vendor variant, since the
// real libraries will be used in the core variant.
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 3e9f73e..d73dac5 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -52,15 +52,10 @@
os.Exit(run())
}
-func testCcWithConfig(t *testing.T, bp string, config android.Config) *android.TestContext {
+func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext {
t.Helper()
- return testCcWithConfigForOs(t, bp, config, android.Android)
-}
-
-func testCcWithConfigForOs(t *testing.T, bp string, config android.Config, os android.OsType) *android.TestContext {
- t.Helper()
- ctx := CreateTestContext(bp, nil, os)
- ctx.Register()
+ ctx := CreateTestContext()
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
android.FailIfErrored(t, errs)
@@ -72,29 +67,29 @@
func testCc(t *testing.T, bp string) *android.TestContext {
t.Helper()
- config := android.TestArchConfig(buildDir, nil)
+ config := TestConfig(buildDir, android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
- return testCcWithConfig(t, bp, config)
+ return testCcWithConfig(t, config)
}
func testCcNoVndk(t *testing.T, bp string) *android.TestContext {
t.Helper()
- config := android.TestArchConfig(buildDir, nil)
+ config := TestConfig(buildDir, android.Android, nil, bp, nil)
config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
- return testCcWithConfig(t, bp, config)
+ return testCcWithConfig(t, config)
}
func testCcError(t *testing.T, pattern string, bp string) {
t.Helper()
- config := android.TestArchConfig(buildDir, nil)
+ config := TestConfig(buildDir, android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
- ctx := CreateTestContext(bp, nil, android.Android)
- ctx.Register()
+ ctx := CreateTestContext()
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
if len(errs) > 0 {
@@ -131,8 +126,8 @@
},
}`
- config := android.TestArchConfigFuchsia(buildDir, nil)
- ctx := testCcWithConfigForOs(t, bp, config, android.Fuchsia)
+ config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil)
+ ctx := testCcWithConfig(t, config)
rt := false
fb := false
@@ -168,8 +163,8 @@
},
}`
- config := android.TestArchConfigFuchsia(buildDir, nil)
- ctx := testCcWithConfigForOs(t, bp, config, android.Fuchsia)
+ config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil)
+ ctx := testCcWithConfig(t, config)
ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
var objs []string
for _, o := range ld.Inputs {
@@ -290,11 +285,7 @@
}
func TestVndk(t *testing.T) {
- config := android.TestArchConfig(buildDir, nil)
- config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
-
- ctx := testCcWithConfig(t, `
+ bp := `
cc_library {
name: "libvndk",
vendor_available: true,
@@ -354,7 +345,13 @@
vndk_libraries_txt {
name: "vndkcorevariant.libraries.txt",
}
- `, config)
+ `
+
+ config := TestConfig(buildDir, android.Android, nil, bp, nil)
+ config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+
+ ctx := testCcWithConfig(t, config)
checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "")
checkVndkModule(t, ctx, "libvndk_private", "vndk-VER", false, "")
@@ -412,13 +409,14 @@
}
func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
- config := android.TestArchConfig(buildDir, nil)
- config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
- ctx := testCcWithConfig(t, `
+ bp := `
vndk_libraries_txt {
name: "llndk.libraries.txt",
- }`, config)
+ }`
+ config := TestConfig(buildDir, android.Android, nil, bp, nil)
+ config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ ctx := testCcWithConfig(t, config)
module := ctx.ModuleForTests("llndk.libraries.txt", "")
entries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0]
@@ -426,14 +424,7 @@
}
func TestVndkUsingCoreVariant(t *testing.T) {
- config := android.TestArchConfig(buildDir, nil)
- config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
- config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
-
- setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
-
- ctx := testCcWithConfig(t, `
+ bp := `
cc_library {
name: "libvndk",
vendor_available: true,
@@ -465,7 +456,16 @@
vndk_libraries_txt {
name: "vndkcorevariant.libraries.txt",
}
- `, config)
+ `
+
+ config := TestConfig(buildDir, android.Android, nil, bp, nil)
+ config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
+
+ setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
+
+ ctx := testCcWithConfig(t, config)
checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
}
@@ -1446,75 +1446,77 @@
}
func TestMakeLinkType(t *testing.T) {
- config := android.TestArchConfig(buildDir, nil)
+ bp := `
+ cc_library {
+ name: "libvndk",
+ vendor_available: true,
+ vndk: {
+ enabled: true,
+ },
+ }
+ cc_library {
+ name: "libvndksp",
+ vendor_available: true,
+ vndk: {
+ enabled: true,
+ support_system_process: true,
+ },
+ }
+ cc_library {
+ name: "libvndkprivate",
+ vendor_available: false,
+ vndk: {
+ enabled: true,
+ },
+ }
+ cc_library {
+ name: "libvendor",
+ vendor: true,
+ }
+ cc_library {
+ name: "libvndkext",
+ vendor: true,
+ vndk: {
+ enabled: true,
+ extends: "libvndk",
+ },
+ }
+ vndk_prebuilt_shared {
+ name: "prevndk",
+ version: "27",
+ target_arch: "arm",
+ binder32bit: true,
+ vendor_available: true,
+ vndk: {
+ enabled: true,
+ },
+ arch: {
+ arm: {
+ srcs: ["liba.so"],
+ },
+ },
+ }
+ cc_library {
+ name: "libllndk",
+ }
+ llndk_library {
+ name: "libllndk",
+ symbol_file: "",
+ }
+ cc_library {
+ name: "libllndkprivate",
+ }
+ llndk_library {
+ name: "libllndkprivate",
+ vendor_available: false,
+ symbol_file: "",
+ }`
+
+ config := TestConfig(buildDir, android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
// native:vndk
- ctx := testCcWithConfig(t, `
- cc_library {
- name: "libvndk",
- vendor_available: true,
- vndk: {
- enabled: true,
- },
- }
- cc_library {
- name: "libvndksp",
- vendor_available: true,
- vndk: {
- enabled: true,
- support_system_process: true,
- },
- }
- cc_library {
- name: "libvndkprivate",
- vendor_available: false,
- vndk: {
- enabled: true,
- },
- }
- cc_library {
- name: "libvendor",
- vendor: true,
- }
- cc_library {
- name: "libvndkext",
- vendor: true,
- vndk: {
- enabled: true,
- extends: "libvndk",
- },
- }
- vndk_prebuilt_shared {
- name: "prevndk",
- version: "27",
- target_arch: "arm",
- binder32bit: true,
- vendor_available: true,
- vndk: {
- enabled: true,
- },
- arch: {
- arm: {
- srcs: ["liba.so"],
- },
- },
- }
- cc_library {
- name: "libllndk",
- }
- llndk_library {
- name: "libllndk",
- symbol_file: "",
- }
- cc_library {
- name: "libllndkprivate",
- }
- llndk_library {
- name: "libllndkprivate",
- vendor_available: false,
- symbol_file: "",
- }`, config)
+ ctx := testCcWithConfig(t, config)
assertMapKeys(t, vndkCoreLibraries(config),
[]string{"libvndk", "libvndkprivate"})
diff --git a/cc/genrule_test.go b/cc/genrule_test.go
index 785e3e1..d38cf27 100644
--- a/cc/genrule_test.go
+++ b/cc/genrule_test.go
@@ -21,31 +21,20 @@
"android/soong/android"
)
-func testGenruleContext(config android.Config, bp string,
- fs map[string][]byte) *android.TestContext {
-
+func testGenruleContext(config android.Config) *android.TestContext {
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("cc_genrule", genRuleFactory)
- ctx.Register()
-
- mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
- "tool": nil,
- "foo": nil,
- "bar": nil,
- }
-
- for k, v := range fs {
- mockFS[k] = v
- }
-
- ctx.MockFileSystem(mockFS)
+ ctx.Register(config)
return ctx
}
func TestArchGenruleCmd(t *testing.T) {
- config := android.TestArchConfig(buildDir, nil)
+ fs := map[string][]byte{
+ "tool": nil,
+ "foo": nil,
+ "bar": nil,
+ }
bp := `
cc_genrule {
name: "gen",
@@ -63,8 +52,9 @@
},
}
`
+ config := android.TestArchConfig(buildDir, nil, bp, fs)
- ctx := testGenruleContext(config, bp, nil)
+ ctx := testGenruleContext(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
if errs == nil {
diff --git a/cc/prebuilt_test.go b/cc/prebuilt_test.go
index 7ddf6eb..31db2df 100644
--- a/cc/prebuilt_test.go
+++ b/cc/prebuilt_test.go
@@ -68,9 +68,9 @@
"libe.a": nil,
}
- config := android.TestArchConfig(buildDir, nil)
+ config := TestConfig(buildDir, android.Android, nil, bp, fs)
- ctx := CreateTestContext(bp, fs, android.Android)
+ ctx := CreateTestContext()
ctx.RegisterModuleType("cc_prebuilt_library_shared", PrebuiltSharedLibraryFactory)
ctx.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory)
@@ -79,7 +79,7 @@
ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
ctx.PostDepsMutators(android.RegisterPrebuiltsPostDepsMutators)
- ctx.Register()
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
android.FailIfErrored(t, errs)
diff --git a/cc/test_data_test.go b/cc/test_data_test.go
index 962ff26..ae59e2f 100644
--- a/cc/test_data_test.go
+++ b/cc/test_data_test.go
@@ -115,20 +115,17 @@
}
defer os.RemoveAll(buildDir)
- config := android.TestConfig(buildDir, nil)
-
for _, test := range testDataTests {
t.Run(test.name, func(t *testing.T) {
- ctx := android.NewTestContext()
- ctx.MockFileSystem(map[string][]byte{
- "Blueprints": []byte(`subdirs = ["dir"]`),
- "dir/Blueprints": []byte(test.modules),
+ config := android.TestConfig(buildDir, nil, "", map[string][]byte{
+ "dir/Android.bp": []byte(test.modules),
"dir/baz": nil,
"dir/bar/baz": nil,
})
+ ctx := android.NewTestContext()
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
ctx.RegisterModuleType("test", newTest)
- ctx.Register()
+ ctx.Register(config)
_, errs := ctx.ParseBlueprintsFiles("Blueprints")
android.FailIfErrored(t, errs)
diff --git a/cc/testing.go b/cc/testing.go
index 417ea4a..93f27cd 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -249,9 +249,41 @@
return ret
}
-func CreateTestContext(bp string, fs map[string][]byte,
- os android.OsType) *android.TestContext {
+func TestConfig(buildDir string, os android.OsType, env map[string]string,
+ bp string, fs map[string][]byte) android.Config {
+ // add some modules that are required by the compiler and/or linker
+ bp = bp + GatherRequiredDepsForTest(os)
+
+ mockFS := map[string][]byte{
+ "foo.c": nil,
+ "foo.lds": nil,
+ "bar.c": nil,
+ "baz.c": nil,
+ "baz.o": nil,
+ "a.proto": nil,
+ "b.aidl": nil,
+ "sub/c.aidl": nil,
+ "my_include": nil,
+ "foo.map.txt": nil,
+ "liba.so": nil,
+ }
+
+ for k, v := range fs {
+ mockFS[k] = v
+ }
+
+ var config android.Config
+ if os == android.Fuchsia {
+ config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
+ } else {
+ config = android.TestArchConfig(buildDir, env, bp, mockFS)
+ }
+
+ return config
+}
+
+func CreateTestContext() *android.TestContext {
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("cc_defaults", defaultsFactory)
ctx.RegisterModuleType("cc_binary", BinaryFactory)
@@ -283,29 +315,5 @@
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
- // add some modules that are required by the compiler and/or linker
- bp = bp + GatherRequiredDepsForTest(os)
-
- mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
- "foo.c": nil,
- "foo.lds": nil,
- "bar.c": nil,
- "baz.c": nil,
- "baz.o": nil,
- "a.proto": nil,
- "b.aidl": nil,
- "sub/c.aidl": nil,
- "my_include": nil,
- "foo.map.txt": nil,
- "liba.so": nil,
- }
-
- for k, v := range fs {
- mockFS[k] = v
- }
-
- ctx.MockFileSystem(mockFS)
-
return ctx
}
diff --git a/dexpreopt/dexpreopt_gen/dexpreopt_gen.go b/dexpreopt/dexpreopt_gen/dexpreopt_gen.go
index 009e906..6f51080 100644
--- a/dexpreopt/dexpreopt_gen/dexpreopt_gen.go
+++ b/dexpreopt/dexpreopt_gen/dexpreopt_gen.go
@@ -71,7 +71,7 @@
usage("path to module configuration file is required")
}
- ctx := &pathContext{android.TestConfig(*outDir, nil)}
+ ctx := &pathContext{android.TestConfig(*outDir, nil, "", nil)}
globalConfig, _, err := dexpreopt.LoadGlobalConfig(ctx, *globalConfigPath)
if err != nil {
diff --git a/dexpreopt/dexpreopt_test.go b/dexpreopt/dexpreopt_test.go
index 3264d6a..a128dc0 100644
--- a/dexpreopt/dexpreopt_test.go
+++ b/dexpreopt/dexpreopt_test.go
@@ -61,7 +61,7 @@
}
func TestDexPreopt(t *testing.T) {
- ctx := android.PathContextForTesting(android.TestConfig("out", nil), nil)
+ ctx := android.PathContextForTesting(android.TestConfig("out", nil, "", nil))
global, module := GlobalConfigForTests(ctx), testSystemModuleConfig(ctx, "test")
rule, err := GenerateDexpreoptRule(ctx, global, module)
@@ -80,7 +80,7 @@
}
func TestDexPreoptSystemOther(t *testing.T) {
- ctx := android.PathContextForTesting(android.TestConfig("out", nil), nil)
+ ctx := android.PathContextForTesting(android.TestConfig("out", nil, "", nil))
global := GlobalConfigForTests(ctx)
systemModule := testSystemModuleConfig(ctx, "Stest")
systemProductModule := testSystemProductModuleConfig(ctx, "SPtest")
@@ -138,7 +138,7 @@
}
func TestDexPreoptProfile(t *testing.T) {
- ctx := android.PathContextForTesting(android.TestConfig("out", nil), nil)
+ ctx := android.PathContextForTesting(android.TestConfig("out", nil, "", nil))
global, module := GlobalConfigForTests(ctx), testSystemModuleConfig(ctx, "test")
module.ProfileClassListing = android.OptionalPathForPath(android.PathForTesting("profile"))
diff --git a/genrule/genrule_test.go b/genrule/genrule_test.go
index 07de999..ea49e08 100644
--- a/genrule/genrule_test.go
+++ b/genrule/genrule_test.go
@@ -51,8 +51,7 @@
os.Exit(run())
}
-func testContext(config android.Config, bp string,
- fs map[string][]byte) *android.TestContext {
+func testContext(config android.Config) *android.TestContext {
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
@@ -61,8 +60,12 @@
ctx.RegisterModuleType("genrule_defaults", defaultsFactory)
ctx.RegisterModuleType("tool", toolFactory)
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
- ctx.Register()
+ ctx.Register(config)
+ return ctx
+}
+
+func testConfig(bp string, fs map[string][]byte) android.Config {
bp += `
tool {
name: "tool",
@@ -104,7 +107,6 @@
`
mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
"tool": nil,
"tool_file1": nil,
"tool_file2": nil,
@@ -119,9 +121,7 @@
mockFS[k] = v
}
- ctx.MockFileSystem(mockFS)
-
- return ctx
+ return android.TestArchConfig(buildDir, nil, bp, mockFS)
}
func TestGenruleCmd(t *testing.T) {
@@ -461,15 +461,15 @@
for _, test := range testcases {
t.Run(test.name, func(t *testing.T) {
- config := android.TestArchConfig(buildDir, nil)
bp := "genrule {\n"
bp += "name: \"gen\",\n"
bp += test.prop
bp += "}\n"
+ config := testConfig(bp, nil)
config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(test.allowMissingDependencies)
- ctx := testContext(config, bp, nil)
+ ctx := testContext(config)
ctx.SetAllowMissingDependencies(test.allowMissingDependencies)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
@@ -546,14 +546,14 @@
for _, test := range testcases {
t.Run(test.name, func(t *testing.T) {
- config := android.TestArchConfig(buildDir, nil)
bp := "gensrcs {\n"
bp += `name: "gen",` + "\n"
bp += `output_extension: "h",` + "\n"
bp += test.prop
bp += "}\n"
- ctx := testContext(config, bp, nil)
+ config := testConfig(bp, nil)
+ ctx := testContext(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
if errs == nil {
@@ -595,7 +595,6 @@
}
func TestGenruleDefaults(t *testing.T) {
- config := android.TestArchConfig(buildDir, nil)
bp := `
genrule_defaults {
name: "gen_defaults1",
@@ -613,7 +612,8 @@
defaults: ["gen_defaults1", "gen_defaults2"],
}
`
- ctx := testContext(config, bp, nil)
+ config := testConfig(bp, nil)
+ ctx := testContext(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
if errs == nil {
_, errs = ctx.PrepareBuildActions(config)
diff --git a/java/app.go b/java/app.go
index 9fa7179..ae637fd 100755
--- a/java/app.go
+++ b/java/app.go
@@ -167,18 +167,11 @@
a.aapt.deps(ctx, sdkDep)
}
+ tag := &jniDependencyTag{}
for _, jniTarget := range ctx.MultiTargets() {
variation := append(jniTarget.Variations(),
blueprint.Variation{Mutator: "link", Variation: "shared"})
- tag := &jniDependencyTag{
- target: jniTarget,
- }
ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...)
- if String(a.appProperties.Stl) == "c++_shared" {
- if a.shouldEmbedJnis(ctx) {
- ctx.AddFarVariationDependencies(variation, tag, "ndk_libc++_shared")
- }
- }
}
a.usesLibrary.deps(ctx, sdkDep.hasFrameworkLibs())
@@ -471,7 +464,7 @@
dexJarFile := a.dexBuildActions(ctx)
- jniLibs, certificateDeps := collectAppDeps(ctx)
+ jniLibs, certificateDeps := collectAppDeps(ctx, a.shouldEmbedJnis(ctx))
jniJarFile := a.jniBuildActions(jniLibs, ctx)
if ctx.Failed() {
@@ -507,22 +500,33 @@
}
}
-func collectAppDeps(ctx android.ModuleContext) ([]jniLib, []Certificate) {
+func collectAppDeps(ctx android.ModuleContext, shouldCollectRecursiveNativeDeps bool) ([]jniLib, []Certificate) {
var jniLibs []jniLib
var certificates []Certificate
+ seenModulePaths := make(map[string]bool)
- ctx.VisitDirectDeps(func(module android.Module) {
+ ctx.WalkDeps(func(module android.Module, parent android.Module) bool {
otherName := ctx.OtherModuleName(module)
tag := ctx.OtherModuleDependencyTag(module)
- if jniTag, ok := tag.(*jniDependencyTag); ok {
+ if IsJniDepTag(tag) || tag == cc.SharedDepTag {
if dep, ok := module.(*cc.Module); ok {
+ if dep.IsNdk() || dep.IsStubs() {
+ return false
+ }
+
lib := dep.OutputFile()
+ path := lib.Path()
+ if seenModulePaths[path.String()] {
+ return false
+ }
+ seenModulePaths[path.String()] = true
+
if lib.Valid() {
jniLibs = append(jniLibs, jniLib{
name: ctx.OtherModuleName(module),
- path: lib.Path(),
- target: jniTag.target,
+ path: path,
+ target: module.Target(),
})
} else {
ctx.ModuleErrorf("dependency %q missing output file", otherName)
@@ -530,13 +534,19 @@
} else {
ctx.ModuleErrorf("jni_libs dependency %q must be a cc library", otherName)
}
- } else if tag == certificateTag {
+
+ return shouldCollectRecursiveNativeDeps
+ }
+
+ if tag == certificateTag {
if dep, ok := module.(*AndroidAppCertificate); ok {
certificates = append(certificates, dep.Certificate)
} else {
ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", otherName)
}
}
+
+ return false
})
return jniLibs, certificates
@@ -968,7 +978,7 @@
ctx.ModuleErrorf("One and only one of certficate, presigned, and default_dev_cert properties must be set")
}
- _, certificates := collectAppDeps(ctx)
+ _, certificates := collectAppDeps(ctx, false)
// TODO: LOCAL_EXTRACT_APK/LOCAL_EXTRACT_DPI_APK
// TODO: LOCAL_PACKAGE_SPLITS
diff --git a/java/app_builder.go b/java/app_builder.go
index ec2f6da..5e7fbe6 100644
--- a/java/app_builder.go
+++ b/java/app_builder.go
@@ -200,14 +200,14 @@
}
if uncompressJNI {
- jarArgs = append(jarArgs, "-L 0")
+ jarArgs = append(jarArgs, "-L", "0")
}
for _, j := range jniLibs {
deps = append(deps, j.path)
jarArgs = append(jarArgs,
- "-P "+targetToJniDir(j.target),
- "-f "+j.path.String())
+ "-P", targetToJniDir(j.target),
+ "-f", j.path.String())
}
ctx.Build(pctx, android.BuildParams{
diff --git a/java/app_test.go b/java/app_test.go
index 1800bb7..9bdef4e 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -43,7 +43,7 @@
}
)
-func testAppContext(bp string, fs map[string][]byte) *android.TestContext {
+func testAppConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
appFS := map[string][]byte{}
for k, v := range fs {
appFS[k] = v
@@ -53,13 +53,13 @@
appFS[file] = nil
}
- return testContext(bp, appFS)
+ return testConfig(env, bp, appFS)
}
func testApp(t *testing.T, bp string) *android.TestContext {
- config := testConfig(nil)
+ config := testAppConfig(nil, bp, nil)
- ctx := testAppContext(bp, nil)
+ ctx := testContext()
run(t, ctx, config)
@@ -301,8 +301,8 @@
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
- config := testConfig(nil)
- ctx := testContext(fmt.Sprintf(bp, testCase.prop), fs)
+ config := testConfig(nil, fmt.Sprintf(bp, testCase.prop), fs)
+ ctx := testContext()
run(t, ctx, config)
module := ctx.ModuleForTests("foo", "android_common")
@@ -509,7 +509,7 @@
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
- config := testConfig(nil)
+ config := testAppConfig(nil, bp, fs)
config.TestProductVariables.DeviceResourceOverlays = deviceResourceOverlays
config.TestProductVariables.ProductResourceOverlays = productResourceOverlays
if testCase.enforceRROTargets != nil {
@@ -519,7 +519,7 @@
config.TestProductVariables.EnforceRROExcludedOverlays = testCase.enforceRROExcludedOverlays
}
- ctx := testAppContext(bp, fs)
+ ctx := testContext()
run(t, ctx, config)
resourceListToFiles := func(module android.TestingModule, list []string) (files []string) {
@@ -649,12 +649,12 @@
%s
}`, moduleType, test.sdkVersion, platformApiProp)
- config := testConfig(nil)
+ config := testAppConfig(nil, bp, nil)
config.TestProductVariables.Platform_sdk_version = &test.platformSdkInt
config.TestProductVariables.Platform_sdk_codename = &test.platformSdkCodename
config.TestProductVariables.Platform_sdk_final = &test.platformSdkFinal
- ctx := testAppContext(bp, nil)
+ ctx := testContext()
run(t, ctx, config)
@@ -777,9 +777,6 @@
`)
for _, enforce := range []bool{true, false} {
-
- config := testConfig(nil)
- config.TestProductVariables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce)
bp := `
android_app {
name: "foo",
@@ -788,10 +785,13 @@
platform_apis: true,
}
`
+
+ config := testAppConfig(nil, bp, nil)
+ config.TestProductVariables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce)
if enforce {
- testJavaErrorWithConfig(t, "sdk_version must have a value when the module is located at vendor or product", bp, config)
+ testJavaErrorWithConfig(t, "sdk_version must have a value when the module is located at vendor or product", config)
} else {
- testJavaWithConfig(t, bp, config)
+ testJavaWithConfig(t, config)
}
}
}
@@ -954,11 +954,11 @@
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
- config := testConfig(nil)
+ config := testAppConfig(nil, test.bp, nil)
if test.certificateOverride != "" {
config.TestProductVariables.CertificateOverrides = []string{test.certificateOverride}
}
- ctx := testAppContext(test.bp, nil)
+ ctx := testContext()
run(t, ctx, config)
foo := ctx.ModuleForTests("foo", "android_common")
@@ -1014,11 +1014,11 @@
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
- config := testConfig(nil)
+ config := testAppConfig(nil, test.bp, nil)
if test.packageNameOverride != "" {
config.TestProductVariables.PackageNameOverrides = []string{test.packageNameOverride}
}
- ctx := testAppContext(test.bp, nil)
+ ctx := testContext()
run(t, ctx, config)
foo := ctx.ModuleForTests("foo", "android_common")
@@ -1051,9 +1051,9 @@
sdk_version: "current",
}
`
- config := testConfig(nil)
+ config := testAppConfig(nil, bp, nil)
config.TestProductVariables.ManifestPackageNameOverrides = []string{"foo:org.dandroid.bp"}
- ctx := testAppContext(bp, nil)
+ ctx := testContext()
run(t, ctx, config)
@@ -1471,10 +1471,10 @@
jniRuleRe := regexp.MustCompile("^if \\(zipinfo (\\S+)")
for _, test := range testCases {
- config := testConfig(nil)
+ config := testAppConfig(nil, bp, nil)
config.TestProductVariables.AAPTPreferredConfig = test.aaptPreferredConfig
config.TestProductVariables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI
- ctx := testAppContext(bp, nil)
+ ctx := testContext()
run(t, ctx, config)
@@ -1631,7 +1631,45 @@
func TestStl(t *testing.T) {
ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
cc_library {
+ name: "ndk_libunwind",
+ sdk_version: "current",
+ stl: "none",
+ system_shared_libs: [],
+ }
+
+ cc_library {
+ name: "libc.ndk.current",
+ sdk_version: "current",
+ stl: "none",
+ system_shared_libs: [],
+ }
+
+ cc_library {
+ name: "libm.ndk.current",
+ sdk_version: "current",
+ stl: "none",
+ system_shared_libs: [],
+ }
+
+ cc_library {
+ name: "libdl.ndk.current",
+ sdk_version: "current",
+ stl: "none",
+ system_shared_libs: [],
+ }
+
+ cc_object {
+ name: "ndk_crtbegin_so.27",
+ }
+
+ cc_object {
+ name: "ndk_crtend_so.27",
+ }
+
+ cc_library {
name: "libjni",
+ sdk_version: "current",
+ stl: "c++_shared",
}
android_test {
@@ -1732,10 +1770,10 @@
}
`
- config := testConfig(nil)
+ config := testAppConfig(nil, bp, nil)
config.TestProductVariables.MissingUsesLibraries = []string{"baz"}
- ctx := testAppContext(bp, nil)
+ ctx := testContext()
run(t, ctx, config)
@@ -2006,12 +2044,12 @@
test := func(t *testing.T, bp string, want bool, unbundled bool) {
t.Helper()
- config := testConfig(nil)
+ config := testAppConfig(nil, bp, nil)
if unbundled {
config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
}
- ctx := testAppContext(bp, nil)
+ ctx := testContext()
run(t, ctx, config)
diff --git a/java/dexpreopt_bootjars_test.go b/java/dexpreopt_bootjars_test.go
index 29a5abe..8f29e9e 100644
--- a/java/dexpreopt_bootjars_test.go
+++ b/java/dexpreopt_bootjars_test.go
@@ -44,14 +44,14 @@
}
`
- config := testConfig(nil)
+ config := testConfig(nil, bp, nil)
- pathCtx := android.PathContextForTesting(config, nil)
+ pathCtx := android.PathContextForTesting(config)
dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)
dexpreoptConfig.ArtApexJars = []string{"foo", "bar", "baz"}
setDexpreoptTestGlobalConfig(config, dexpreoptConfig)
- ctx := testContext(bp, nil)
+ ctx := testContext()
ctx.RegisterSingletonType("dex_bootjars", dexpreoptBootJarsFactory)
diff --git a/java/hiddenapi_singleton.go b/java/hiddenapi_singleton.go
index e9e4a45..ad84cde 100644
--- a/java/hiddenapi_singleton.go
+++ b/java/hiddenapi_singleton.go
@@ -16,7 +16,6 @@
import (
"fmt"
- "strings"
"android/soong/android"
)
@@ -153,23 +152,11 @@
// Collect dex jar paths for modules that had hiddenapi encode called on them.
if h, ok := module.(hiddenAPIIntf); ok {
if jar := h.bootDexJar(); jar != nil {
- // Don't add multiple variants of the same library to bootDexJars, otherwise
- // hiddenapi tool will complain about duplicated classes. Such multiple variants
- // of the same library can happen when the library is included in one or more APEXes.
- // TODO(b/146308764): remove this heuristic
- if a, ok := module.(android.ApexModule); ok && android.InAnyApex(module.Name()) {
- if a.AvailableFor("//apex_available:platform") && !a.IsForPlatform() {
- // skip the apex variants if the jar is available for the platform
- return
- }
- apexName := a.ApexName()
- if strings.Contains(apexName, "test") {
- // skip the if the jar is in test APEX
- return
- }
-
- if strings.Contains(apexName, "com.android.art") && apexName != "com.android.art.release" {
- // skip the ART APEX variants other than com.android.art.release
+ // For a java lib included in an APEX, only take the one built for
+ // the platform variant, and skip the variants for APEXes.
+ // Otherwise, the hiddenapi tool will complain about duplicated classes
+ if a, ok := module.(android.ApexModule); ok {
+ if android.InAnyApex(module.Name()) && !a.IsForPlatform() {
return
}
}
diff --git a/java/java.go b/java/java.go
index 59bfaf7..052e06f 100644
--- a/java/java.go
+++ b/java/java.go
@@ -466,7 +466,6 @@
type jniDependencyTag struct {
blueprint.BaseDependencyTag
- target android.Target
}
func IsJniDepTag(depTag blueprint.DependencyTag) bool {
@@ -595,8 +594,36 @@
}
}
- ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
- ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
+ syspropPublicStubs := syspropPublicStubs(ctx.Config())
+
+ // rewriteSyspropLibs validates if a java module can link against platform's sysprop_library,
+ // and redirects dependency to public stub depending on the link type.
+ rewriteSyspropLibs := func(libs []string, prop string) []string {
+ // make a copy
+ ret := android.CopyOf(libs)
+
+ for idx, lib := range libs {
+ stub, ok := syspropPublicStubs[lib]
+
+ if !ok {
+ continue
+ }
+
+ linkType, _ := j.getLinkType(ctx.ModuleName())
+ if linkType == javaSystem {
+ ret[idx] = stub
+ } else if linkType != javaPlatform {
+ ctx.PropertyErrorf("sdk_version",
+ "can't link against sysprop_library %q from a module using public or core API",
+ lib)
+ }
+ }
+
+ return ret
+ }
+
+ ctx.AddVariationDependencies(nil, libTag, rewriteSyspropLibs(j.properties.Libs, "libs")...)
+ ctx.AddVariationDependencies(nil, staticLibTag, rewriteSyspropLibs(j.properties.Static_libs, "static_libs")...)
ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...)
ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), exportedPluginTag, j.properties.Exported_plugins...)
diff --git a/java/java_test.go b/java/java_test.go
index 4a549e6..49838c7 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -56,11 +56,11 @@
os.Exit(run())
}
-func testConfig(env map[string]string) android.Config {
- return TestConfig(buildDir, env)
+func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
+ return TestConfig(buildDir, env, bp, fs)
}
-func testContext(bp string, fs map[string][]byte) *android.TestContext {
+func testContext() *android.TestContext {
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("android_app", AndroidAppFactory)
@@ -116,119 +116,16 @@
ctx.BottomUp("begin", cc.BeginMutator).Parallel()
})
- bp += GatherRequiredDepsForTest()
-
- mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
- "a.java": nil,
- "b.java": nil,
- "c.java": nil,
- "b.kt": nil,
- "a.jar": nil,
- "b.jar": nil,
- "APP_NOTICE": nil,
- "GENRULE_NOTICE": nil,
- "LIB_NOTICE": nil,
- "TOOL_NOTICE": nil,
- "java-res/a/a": nil,
- "java-res/b/b": nil,
- "java-res2/a": nil,
- "java-fg/a.java": nil,
- "java-fg/b.java": nil,
- "java-fg/c.java": nil,
- "api/current.txt": nil,
- "api/removed.txt": nil,
- "api/system-current.txt": nil,
- "api/system-removed.txt": nil,
- "api/test-current.txt": nil,
- "api/test-removed.txt": nil,
- "framework/aidl/a.aidl": nil,
-
- "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so": nil,
-
- "prebuilts/sdk/14/public/android.jar": nil,
- "prebuilts/sdk/14/public/framework.aidl": nil,
- "prebuilts/sdk/14/system/android.jar": nil,
- "prebuilts/sdk/17/public/android.jar": nil,
- "prebuilts/sdk/17/public/framework.aidl": nil,
- "prebuilts/sdk/17/system/android.jar": nil,
- "prebuilts/sdk/29/public/android.jar": nil,
- "prebuilts/sdk/29/public/framework.aidl": nil,
- "prebuilts/sdk/29/system/android.jar": nil,
- "prebuilts/sdk/current/core/android.jar": nil,
- "prebuilts/sdk/current/public/android.jar": nil,
- "prebuilts/sdk/current/public/framework.aidl": nil,
- "prebuilts/sdk/current/public/core.jar": nil,
- "prebuilts/sdk/current/system/android.jar": nil,
- "prebuilts/sdk/current/test/android.jar": nil,
- "prebuilts/sdk/28/public/api/foo.txt": nil,
- "prebuilts/sdk/28/system/api/foo.txt": nil,
- "prebuilts/sdk/28/test/api/foo.txt": nil,
- "prebuilts/sdk/28/public/api/foo-removed.txt": nil,
- "prebuilts/sdk/28/system/api/foo-removed.txt": nil,
- "prebuilts/sdk/28/test/api/foo-removed.txt": nil,
- "prebuilts/sdk/28/public/api/bar.txt": nil,
- "prebuilts/sdk/28/system/api/bar.txt": nil,
- "prebuilts/sdk/28/test/api/bar.txt": nil,
- "prebuilts/sdk/28/public/api/bar-removed.txt": nil,
- "prebuilts/sdk/28/system/api/bar-removed.txt": nil,
- "prebuilts/sdk/28/test/api/bar-removed.txt": nil,
- "prebuilts/sdk/tools/core-lambda-stubs.jar": nil,
- "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "current"],}`),
-
- "prebuilts/apk/app.apk": nil,
- "prebuilts/apk/app_arm.apk": nil,
- "prebuilts/apk/app_arm64.apk": nil,
- "prebuilts/apk/app_xhdpi.apk": nil,
- "prebuilts/apk/app_xxhdpi.apk": nil,
-
- // For framework-res, which is an implicit dependency for framework
- "AndroidManifest.xml": nil,
- "build/make/target/product/security/testkey": nil,
-
- "build/soong/scripts/jar-wrapper.sh": nil,
-
- "build/make/core/verify_uses_libraries.sh": nil,
-
- "build/make/core/proguard.flags": nil,
- "build/make/core/proguard_basic_keeps.flags": nil,
-
- "jdk8/jre/lib/jce.jar": nil,
- "jdk8/jre/lib/rt.jar": nil,
- "jdk8/lib/tools.jar": nil,
-
- "bar-doc/a.java": nil,
- "bar-doc/b.java": nil,
- "bar-doc/IFoo.aidl": nil,
- "bar-doc/IBar.aidl": nil,
- "bar-doc/known_oj_tags.txt": nil,
- "external/doclava/templates-sdk": nil,
-
- "cert/new_cert.x509.pem": nil,
- "cert/new_cert.pk8": nil,
-
- "testdata/data": nil,
-
- "stubs-sources/foo/Foo.java": nil,
- "stubs/sources/foo/Foo.java": nil,
- }
-
- for k, v := range fs {
- mockFS[k] = v
- }
-
- ctx.MockFileSystem(mockFS)
-
return ctx
}
func run(t *testing.T, ctx *android.TestContext, config android.Config) {
t.Helper()
- pathCtx := android.PathContextForTesting(config, nil)
+ pathCtx := android.PathContextForTesting(config)
setDexpreoptTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx))
- ctx.Register()
+ ctx.Register(config)
_, errs := ctx.ParseBlueprintsFiles("Android.bp")
android.FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
@@ -237,17 +134,17 @@
func testJavaError(t *testing.T, pattern string, bp string) (*android.TestContext, android.Config) {
t.Helper()
- return testJavaErrorWithConfig(t, pattern, bp, testConfig(nil))
+ return testJavaErrorWithConfig(t, pattern, testConfig(nil, bp, nil))
}
-func testJavaErrorWithConfig(t *testing.T, pattern string, bp string, config android.Config) (*android.TestContext, android.Config) {
+func testJavaErrorWithConfig(t *testing.T, pattern string, config android.Config) (*android.TestContext, android.Config) {
t.Helper()
- ctx := testContext(bp, nil)
+ ctx := testContext()
- pathCtx := android.PathContextForTesting(config, nil)
+ pathCtx := android.PathContextForTesting(config)
setDexpreoptTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx))
- ctx.Register()
+ ctx.Register(config)
_, errs := ctx.ParseBlueprintsFiles("Android.bp")
if len(errs) > 0 {
android.FailIfNoMatchingErrors(t, pattern, errs)
@@ -266,12 +163,12 @@
func testJava(t *testing.T, bp string) (*android.TestContext, android.Config) {
t.Helper()
- return testJavaWithConfig(t, bp, testConfig(nil))
+ return testJavaWithConfig(t, testConfig(nil, bp, nil))
}
-func testJavaWithConfig(t *testing.T, bp string, config android.Config) (*android.TestContext, android.Config) {
+func testJavaWithConfig(t *testing.T, config android.Config) (*android.TestContext, android.Config) {
t.Helper()
- ctx := testContext(bp, nil)
+ ctx := testContext()
run(t, ctx, config)
return ctx, config
@@ -520,9 +417,6 @@
`)
for _, enforce := range []bool{true, false} {
-
- config := testConfig(nil)
- config.TestProductVariables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce)
bp := `
java_library {
name: "foo",
@@ -530,10 +424,13 @@
product_specific: true,
}
`
+
+ config := testConfig(nil, bp, nil)
+ config.TestProductVariables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce)
if enforce {
- testJavaErrorWithConfig(t, "sdk_version must have a value when the module is located at vendor or product", bp, config)
+ testJavaErrorWithConfig(t, "sdk_version must have a value when the module is located at vendor or product", config)
} else {
- testJavaWithConfig(t, bp, config)
+ testJavaWithConfig(t, config)
}
}
}
@@ -1127,8 +1024,7 @@
}
func TestJavaLibrary(t *testing.T) {
- config := testConfig(nil)
- ctx := testContext("", map[string][]byte{
+ config := testConfig(nil, "", map[string][]byte{
"libcore/Android.bp": []byte(`
java_library {
name: "core",
@@ -1136,6 +1032,7 @@
system_modules: "none",
}`),
})
+ ctx := testContext()
run(t, ctx, config)
}
diff --git a/java/sdk_test.go b/java/sdk_test.go
index 525c898..9cabd77 100644
--- a/java/sdk_test.go
+++ b/java/sdk_test.go
@@ -327,14 +327,14 @@
// Test with legacy javac -source 1.8 -target 1.8
t.Run("Java language level 8", func(t *testing.T) {
- config := testConfig(nil)
+ config := testConfig(nil, bpJava8, nil)
if testcase.unbundled {
config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
}
if testcase.pdk {
config.TestProductVariables.Pdk = proptools.BoolPtr(true)
}
- ctx := testContext(bpJava8, nil)
+ ctx := testContext()
run(t, ctx, config)
checkClasspath(t, ctx, true /* isJava8 */)
@@ -350,14 +350,14 @@
// Test with default javac -source 9 -target 9
t.Run("Java language level 9", func(t *testing.T) {
- config := testConfig(nil)
+ config := testConfig(nil, bp, nil)
if testcase.unbundled {
config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
}
if testcase.pdk {
config.TestProductVariables.Pdk = proptools.BoolPtr(true)
}
- ctx := testContext(bp, nil)
+ ctx := testContext()
run(t, ctx, config)
checkClasspath(t, ctx, false /* isJava8 */)
@@ -373,7 +373,7 @@
// Test again with PLATFORM_VERSION_CODENAME=REL, javac -source 8 -target 8
t.Run("REL + Java language level 8", func(t *testing.T) {
- config := testConfig(nil)
+ config := testConfig(nil, bpJava8, nil)
config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("REL")
config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(true)
@@ -383,7 +383,7 @@
if testcase.pdk {
config.TestProductVariables.Pdk = proptools.BoolPtr(true)
}
- ctx := testContext(bpJava8, nil)
+ ctx := testContext()
run(t, ctx, config)
checkClasspath(t, ctx, true /* isJava8 */)
@@ -391,7 +391,7 @@
// Test again with PLATFORM_VERSION_CODENAME=REL, javac -source 9 -target 9
t.Run("REL + Java language level 9", func(t *testing.T) {
- config := testConfig(nil)
+ config := testConfig(nil, bp, nil)
config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("REL")
config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(true)
@@ -401,7 +401,7 @@
if testcase.pdk {
config.TestProductVariables.Pdk = proptools.BoolPtr(true)
}
- ctx := testContext(bp, nil)
+ ctx := testContext()
run(t, ctx, config)
checkClasspath(t, ctx, false /* isJava8 */)
diff --git a/java/sysprop.go b/java/sysprop.go
new file mode 100644
index 0000000..1a70499
--- /dev/null
+++ b/java/sysprop.go
@@ -0,0 +1,60 @@
+// Copyright (C) 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package java
+
+import (
+ "sync"
+
+ "android/soong/android"
+)
+
+type syspropLibraryInterface interface {
+ BaseModuleName() string
+ Owner() string
+ HasPublicStub() bool
+ JavaPublicStubName() string
+}
+
+var (
+ syspropPublicStubsKey = android.NewOnceKey("syspropPublicStubsJava")
+ syspropPublicStubsLock sync.Mutex
+)
+
+func init() {
+ android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
+ ctx.BottomUp("sysprop_java", SyspropMutator).Parallel()
+ })
+}
+
+func syspropPublicStubs(config android.Config) map[string]string {
+ return config.Once(syspropPublicStubsKey, func() interface{} {
+ return make(map[string]string)
+ }).(map[string]string)
+}
+
+// gather list of sysprop libraries owned by platform.
+func SyspropMutator(mctx android.BottomUpMutatorContext) {
+ if m, ok := mctx.Module().(syspropLibraryInterface); ok {
+ if m.Owner() != "Platform" || !m.HasPublicStub() {
+ return
+ }
+
+ syspropPublicStubs := syspropPublicStubs(mctx.Config())
+ syspropPublicStubsLock.Lock()
+ defer syspropPublicStubsLock.Unlock()
+
+ syspropPublicStubs[m.BaseModuleName()] = m.JavaPublicStubName()
+ }
+}
diff --git a/java/testing.go b/java/testing.go
index acbefb9..c9f5905 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -20,14 +20,114 @@
"android/soong/android"
)
-func TestConfig(buildDir string, env map[string]string) android.Config {
+func TestConfig(buildDir string, env map[string]string, bp string, fs map[string][]byte) android.Config {
+ bp += GatherRequiredDepsForTest()
+
+ mockFS := map[string][]byte{
+ "a.java": nil,
+ "b.java": nil,
+ "c.java": nil,
+ "b.kt": nil,
+ "a.jar": nil,
+ "b.jar": nil,
+ "APP_NOTICE": nil,
+ "GENRULE_NOTICE": nil,
+ "LIB_NOTICE": nil,
+ "TOOL_NOTICE": nil,
+ "java-res/a/a": nil,
+ "java-res/b/b": nil,
+ "java-res2/a": nil,
+ "java-fg/a.java": nil,
+ "java-fg/b.java": nil,
+ "java-fg/c.java": nil,
+ "api/current.txt": nil,
+ "api/removed.txt": nil,
+ "api/system-current.txt": nil,
+ "api/system-removed.txt": nil,
+ "api/test-current.txt": nil,
+ "api/test-removed.txt": nil,
+ "framework/aidl/a.aidl": nil,
+
+ "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so": nil,
+
+ "prebuilts/sdk/14/public/android.jar": nil,
+ "prebuilts/sdk/14/public/framework.aidl": nil,
+ "prebuilts/sdk/14/system/android.jar": nil,
+ "prebuilts/sdk/17/public/android.jar": nil,
+ "prebuilts/sdk/17/public/framework.aidl": nil,
+ "prebuilts/sdk/17/system/android.jar": nil,
+ "prebuilts/sdk/29/public/android.jar": nil,
+ "prebuilts/sdk/29/public/framework.aidl": nil,
+ "prebuilts/sdk/29/system/android.jar": nil,
+ "prebuilts/sdk/current/core/android.jar": nil,
+ "prebuilts/sdk/current/public/android.jar": nil,
+ "prebuilts/sdk/current/public/framework.aidl": nil,
+ "prebuilts/sdk/current/public/core.jar": nil,
+ "prebuilts/sdk/current/system/android.jar": nil,
+ "prebuilts/sdk/current/test/android.jar": nil,
+ "prebuilts/sdk/28/public/api/foo.txt": nil,
+ "prebuilts/sdk/28/system/api/foo.txt": nil,
+ "prebuilts/sdk/28/test/api/foo.txt": nil,
+ "prebuilts/sdk/28/public/api/foo-removed.txt": nil,
+ "prebuilts/sdk/28/system/api/foo-removed.txt": nil,
+ "prebuilts/sdk/28/test/api/foo-removed.txt": nil,
+ "prebuilts/sdk/28/public/api/bar.txt": nil,
+ "prebuilts/sdk/28/system/api/bar.txt": nil,
+ "prebuilts/sdk/28/test/api/bar.txt": nil,
+ "prebuilts/sdk/28/public/api/bar-removed.txt": nil,
+ "prebuilts/sdk/28/system/api/bar-removed.txt": nil,
+ "prebuilts/sdk/28/test/api/bar-removed.txt": nil,
+ "prebuilts/sdk/tools/core-lambda-stubs.jar": nil,
+ "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "current"],}`),
+
+ "prebuilts/apk/app.apk": nil,
+ "prebuilts/apk/app_arm.apk": nil,
+ "prebuilts/apk/app_arm64.apk": nil,
+ "prebuilts/apk/app_xhdpi.apk": nil,
+ "prebuilts/apk/app_xxhdpi.apk": nil,
+
+ // For framework-res, which is an implicit dependency for framework
+ "AndroidManifest.xml": nil,
+ "build/make/target/product/security/testkey": nil,
+
+ "build/soong/scripts/jar-wrapper.sh": nil,
+
+ "build/make/core/verify_uses_libraries.sh": nil,
+
+ "build/make/core/proguard.flags": nil,
+ "build/make/core/proguard_basic_keeps.flags": nil,
+
+ "jdk8/jre/lib/jce.jar": nil,
+ "jdk8/jre/lib/rt.jar": nil,
+ "jdk8/lib/tools.jar": nil,
+
+ "bar-doc/a.java": nil,
+ "bar-doc/b.java": nil,
+ "bar-doc/IFoo.aidl": nil,
+ "bar-doc/IBar.aidl": nil,
+ "bar-doc/known_oj_tags.txt": nil,
+ "external/doclava/templates-sdk": nil,
+
+ "cert/new_cert.x509.pem": nil,
+ "cert/new_cert.pk8": nil,
+
+ "testdata/data": nil,
+
+ "stubs-sources/foo/Foo.java": nil,
+ "stubs/sources/foo/Foo.java": nil,
+ }
+
+ for k, v := range fs {
+ mockFS[k] = v
+ }
+
if env == nil {
env = make(map[string]string)
}
if env["ANDROID_JAVA8_HOME"] == "" {
env["ANDROID_JAVA8_HOME"] = "jdk8"
}
- config := android.TestArchConfig(buildDir, env)
+ config := android.TestArchConfig(buildDir, env, bp, mockFS)
return config
}
diff --git a/python/python_test.go b/python/python_test.go
index ba5e7fa..1245ca1 100644
--- a/python/python_test.go
+++ b/python/python_test.go
@@ -28,6 +28,8 @@
"android/soong/android"
)
+var buildDir string
+
type pyModule struct {
name string
actualVersion string
@@ -50,7 +52,7 @@
noSrcFileErr = moduleVariantErrTemplate + "doesn't have any source files!"
badSrcFileExtErr = moduleVariantErrTemplate + "srcs: found non (.py|.proto) file: %q!"
badDataFileExtErr = moduleVariantErrTemplate + "data: found (.py|.proto) file: %q!"
- bpFile = "Blueprints"
+ bpFile = "Android.bp"
data = []struct {
desc string
@@ -71,7 +73,7 @@
},
errors: []string{
fmt.Sprintf(noSrcFileErr,
- "dir/Blueprints:1:1", "lib1", "PY3"),
+ "dir/Android.bp:1:1", "lib1", "PY3"),
},
},
{
@@ -90,7 +92,7 @@
},
errors: []string{
fmt.Sprintf(badSrcFileExtErr,
- "dir/Blueprints:3:11", "lib1", "PY3", "dir/file1.exe"),
+ "dir/Android.bp:3:11", "lib1", "PY3", "dir/file1.exe"),
},
},
{
@@ -113,7 +115,7 @@
},
errors: []string{
fmt.Sprintf(badDataFileExtErr,
- "dir/Blueprints:6:11", "lib1", "PY3", "dir/file2.py"),
+ "dir/Android.bp:6:11", "lib1", "PY3", "dir/file2.py"),
},
},
{
@@ -149,9 +151,9 @@
},
errors: []string{
fmt.Sprintf(pkgPathErrTemplate,
- "dir/Blueprints:11:15", "lib2", "PY3", "a/c/../../../"),
+ "dir/Android.bp:11:15", "lib2", "PY3", "a/c/../../../"),
fmt.Sprintf(pkgPathErrTemplate,
- "dir/Blueprints:19:15", "lib3", "PY3", "/a/c/../../"),
+ "dir/Android.bp:19:15", "lib3", "PY3", "/a/c/../../"),
},
},
{
@@ -174,11 +176,11 @@
"dir/-e/f/file1.py": nil,
},
errors: []string{
- fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11",
+ fmt.Sprintf(badIdentifierErrTemplate, "dir/Android.bp:4:11",
"lib1", "PY3", "a/b/c/-e/f/file1.py", "-e"),
- fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11",
+ fmt.Sprintf(badIdentifierErrTemplate, "dir/Android.bp:4:11",
"lib1", "PY3", "a/b/c/.file1.py", ".file1"),
- fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11",
+ fmt.Sprintf(badIdentifierErrTemplate, "dir/Android.bp:4:11",
"lib1", "PY3", "a/b/c/123/file1.py", "123"),
},
},
@@ -211,7 +213,7 @@
"dir/file1.py": nil,
},
errors: []string{
- fmt.Sprintf(dupRunfileErrTemplate, "dir/Blueprints:9:6",
+ fmt.Sprintf(dupRunfileErrTemplate, "dir/Android.bp:9:6",
"lib2", "PY3", "a/b/c/file1.py", "lib2", "dir/file1.py",
"lib1", "dir/c/file1.py"),
},
@@ -324,10 +326,9 @@
)
func TestPythonModule(t *testing.T) {
- config, buildDir := setupBuildEnv(t)
- defer tearDownBuildEnv(buildDir)
for _, d := range data {
t.Run(d.desc, func(t *testing.T) {
+ config := android.TestConfig(buildDir, nil, "", d.mockFiles)
ctx := android.NewTestContext()
ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
ctx.BottomUp("version_split", versionSplitMutator()).Parallel()
@@ -336,8 +337,7 @@
ctx.RegisterModuleType("python_binary_host", PythonBinaryHostFactory)
ctx.RegisterModuleType("python_defaults", defaultsFactory)
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
- ctx.Register()
- ctx.MockFileSystem(d.mockFiles)
+ ctx.Register(config)
_, testErrs := ctx.ParseBlueprintsFiles(bpFile)
android.FailIfErrored(t, testErrs)
_, actErrs := ctx.PrepareBuildActions(config)
@@ -425,17 +425,25 @@
return
}
-func setupBuildEnv(t *testing.T) (config android.Config, buildDir string) {
- buildDir, err := ioutil.TempDir("", buildNamePrefix)
+func setUp() {
+ var err error
+ buildDir, err = ioutil.TempDir("", "soong_python_test")
if err != nil {
- t.Fatal(err)
+ panic(err)
}
-
- config = android.TestConfig(buildDir, nil)
-
- return
}
-func tearDownBuildEnv(buildDir string) {
+func tearDown() {
os.RemoveAll(buildDir)
}
+
+func TestMain(m *testing.M) {
+ run := func() int {
+ setUp()
+ defer tearDown()
+
+ return m.Run()
+ }
+
+ os.Exit(run())
+}
diff --git a/rust/rust_test.go b/rust/rust_test.go
index 01b89db..3be9ee7 100644
--- a/rust/rust_test.go
+++ b/rust/rust_test.go
@@ -51,6 +51,19 @@
os.Exit(run())
}
+func testConfig(bp string) android.Config {
+ bp = bp + GatherRequiredDepsForTest()
+
+ fs := map[string][]byte{
+ "foo.rs": nil,
+ "src/bar.rs": nil,
+ "liby.so": nil,
+ "libz.so": nil,
+ }
+
+ return android.TestArchConfig(buildDir, nil, bp, fs)
+}
+
func testRust(t *testing.T, bp string) *android.TestContext {
// TODO (b/140435149)
if runtime.GOOS != "linux" {
@@ -58,11 +71,11 @@
}
t.Helper()
- config := android.TestArchConfig(buildDir, nil)
+ config := testConfig(bp)
t.Helper()
- ctx := CreateTestContext(bp)
- ctx.Register()
+ ctx := CreateTestContext()
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
android.FailIfErrored(t, errs)
@@ -79,10 +92,10 @@
}
t.Helper()
- config := android.TestArchConfig(buildDir, nil)
+ config := testConfig(bp)
- ctx := CreateTestContext(bp)
- ctx.Register()
+ ctx := CreateTestContext()
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
if len(errs) > 0 {
diff --git a/rust/testing.go b/rust/testing.go
index 2067f82..1dd16cf 100644
--- a/rust/testing.go
+++ b/rust/testing.go
@@ -162,7 +162,7 @@
return bp
}
-func CreateTestContext(bp string) *android.TestContext {
+func CreateTestContext() *android.TestContext {
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
ctx.RegisterModuleType("cc_object", cc.ObjectFactory)
@@ -193,17 +193,6 @@
ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
ctx.BottomUp("rust_unit_tests", TestPerSrcMutator).Parallel()
})
- bp = bp + GatherRequiredDepsForTest()
-
- mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
- "foo.rs": nil,
- "src/bar.rs": nil,
- "liby.so": nil,
- "libz.so": nil,
- }
-
- ctx.MockFileSystem(mockFS)
return ctx
}
diff --git a/sdk/testing.go b/sdk/testing.go
index 5082ab4..77ba2e6 100644
--- a/sdk/testing.go
+++ b/sdk/testing.go
@@ -29,7 +29,36 @@
)
func testSdkContext(bp string, fs map[string][]byte) (*android.TestContext, android.Config) {
- config := android.TestArchConfig(buildDir, nil)
+ bp = bp + `
+ apex_key {
+ name: "myapex.key",
+ public_key: "myapex.avbpubkey",
+ private_key: "myapex.pem",
+ }
+
+ android_app_certificate {
+ name: "myapex.cert",
+ certificate: "myapex",
+ }
+ ` + cc.GatherRequiredDepsForTest(android.Android)
+
+ mockFS := map[string][]byte{
+ "build/make/target/product/security": nil,
+ "apex_manifest.json": nil,
+ "system/sepolicy/apex/myapex-file_contexts": nil,
+ "system/sepolicy/apex/myapex2-file_contexts": nil,
+ "myapex.avbpubkey": nil,
+ "myapex.pem": nil,
+ "myapex.x509.pem": nil,
+ "myapex.pk8": nil,
+ }
+
+ for k, v := range fs {
+ mockFS[k] = v
+ }
+
+ config := android.TestArchConfig(buildDir, nil, bp, mockFS)
+
ctx := android.NewTestArchContext()
// from android package
@@ -84,38 +113,7 @@
ctx.PreDepsMutators(RegisterPreDepsMutators)
ctx.PostDepsMutators(RegisterPostDepsMutators)
- ctx.Register()
-
- bp = bp + `
- apex_key {
- name: "myapex.key",
- public_key: "myapex.avbpubkey",
- private_key: "myapex.pem",
- }
-
- android_app_certificate {
- name: "myapex.cert",
- certificate: "myapex",
- }
- ` + cc.GatherRequiredDepsForTest(android.Android)
-
- mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
- "build/make/target/product/security": nil,
- "apex_manifest.json": nil,
- "system/sepolicy/apex/myapex-file_contexts": nil,
- "system/sepolicy/apex/myapex2-file_contexts": nil,
- "myapex.avbpubkey": nil,
- "myapex.pem": nil,
- "myapex.x509.pem": nil,
- "myapex.pk8": nil,
- }
-
- for k, v := range fs {
- mockFS[k] = v
- }
-
- ctx.MockFileSystem(mockFS)
+ ctx.Register(config)
return ctx, config
}
diff --git a/sysprop/sysprop_library.go b/sysprop/sysprop_library.go
index 1fc94db..ce404f8 100644
--- a/sysprop/sysprop_library.go
+++ b/sysprop/sysprop_library.go
@@ -35,6 +35,7 @@
type syspropGenProperties struct {
Srcs []string `android:"path"`
Scope string
+ Name *string
}
type syspropJavaGenRule struct {
@@ -142,6 +143,9 @@
// list of .sysprop files which defines the properties.
Srcs []string `android:"path"`
+
+ // Whether public stub exists or not.
+ Public_stub *bool `blueprint:"mutated"`
}
var (
@@ -157,18 +161,37 @@
return m.BaseModuleName() + "_sysprop_library"
}
+func (m *syspropLibrary) Owner() string {
+ return m.properties.Property_owner
+}
+
func (m *syspropLibrary) CcModuleName() string {
return "lib" + m.BaseModuleName()
}
+func (m *syspropLibrary) JavaPublicStubName() string {
+ if proptools.Bool(m.properties.Public_stub) {
+ return m.BaseModuleName() + "_public"
+ }
+ return ""
+}
+
func (m *syspropLibrary) javaGenModuleName() string {
return m.BaseModuleName() + "_java_gen"
}
+func (m *syspropLibrary) javaGenPublicStubName() string {
+ return m.BaseModuleName() + "_java_gen_public"
+}
+
func (m *syspropLibrary) BaseModuleName() string {
return m.ModuleBase.Name()
}
+func (m *syspropLibrary) HasPublicStub() bool {
+ return proptools.Bool(m.properties.Public_stub)
+}
+
func (m *syspropLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
baseModuleName := m.BaseModuleName()
@@ -274,6 +297,36 @@
return m
}
+type ccLibraryProperties struct {
+ Name *string
+ Srcs []string
+ Soc_specific *bool
+ Device_specific *bool
+ Product_specific *bool
+ Sysprop struct {
+ Platform *bool
+ }
+ Header_libs []string
+ Shared_libs []string
+ Required []string
+ Recovery *bool
+ Recovery_available *bool
+ Vendor_available *bool
+}
+
+type javaLibraryProperties struct {
+ Name *string
+ Srcs []string
+ Soc_specific *bool
+ Device_specific *bool
+ Product_specific *bool
+ Required []string
+ Sdk_version *string
+ Installable *bool
+ Libs []string
+ Stem *string
+}
+
func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
if len(m.properties.Srcs) == 0 {
ctx.PropertyErrorf("srcs", "sysprop_library must specify srcs")
@@ -304,120 +357,107 @@
return
}
- socSpecific := ctx.SocSpecific()
- deviceSpecific := ctx.DeviceSpecific()
- productSpecific := ctx.ProductSpecific()
-
- owner := m.properties.Property_owner
+ // ctx's Platform or Specific functions represent where this sysprop_library installed.
+ installedInSystem := ctx.Platform() || ctx.SystemExtSpecific()
+ installedInVendorOrOdm := ctx.SocSpecific() || ctx.DeviceSpecific()
+ isOwnerPlatform := false
stub := "sysprop-library-stub-"
- switch owner {
+ switch m.Owner() {
case "Platform":
// Every partition can access platform-defined properties
stub += "platform"
+ isOwnerPlatform = true
case "Vendor":
// System can't access vendor's properties
- if !socSpecific && !deviceSpecific && !productSpecific {
+ if installedInSystem {
ctx.ModuleErrorf("None of soc_specific, device_specific, product_specific is true. " +
"System can't access sysprop_library owned by Vendor")
}
stub += "vendor"
case "Odm":
// Only vendor can access Odm-defined properties
- if !socSpecific && !deviceSpecific {
+ if !installedInVendorOrOdm {
ctx.ModuleErrorf("Neither soc_speicifc nor device_specific is true. " +
"Odm-defined properties should be accessed only in Vendor or Odm")
}
stub += "vendor"
default:
ctx.PropertyErrorf("property_owner",
- "Unknown value %s: must be one of Platform, Vendor or Odm", owner)
+ "Unknown value %s: must be one of Platform, Vendor or Odm", m.Owner())
}
- ccProps := struct {
- Name *string
- Srcs []string
- Soc_specific *bool
- Device_specific *bool
- Product_specific *bool
- Sysprop struct {
- Platform *bool
- }
- Header_libs []string
- Shared_libs []string
- Required []string
- Recovery *bool
- Recovery_available *bool
- Vendor_available *bool
- }{}
-
+ ccProps := ccLibraryProperties{}
ccProps.Name = proptools.StringPtr(m.CcModuleName())
ccProps.Srcs = m.properties.Srcs
- ccProps.Soc_specific = proptools.BoolPtr(socSpecific)
- ccProps.Device_specific = proptools.BoolPtr(deviceSpecific)
- ccProps.Product_specific = proptools.BoolPtr(productSpecific)
- ccProps.Sysprop.Platform = proptools.BoolPtr(owner == "Platform")
+ ccProps.Soc_specific = proptools.BoolPtr(ctx.SocSpecific())
+ ccProps.Device_specific = proptools.BoolPtr(ctx.DeviceSpecific())
+ ccProps.Product_specific = proptools.BoolPtr(ctx.ProductSpecific())
+ ccProps.Sysprop.Platform = proptools.BoolPtr(isOwnerPlatform)
ccProps.Header_libs = []string{"libbase_headers"}
ccProps.Shared_libs = []string{"liblog"}
ccProps.Recovery_available = m.properties.Recovery_available
ccProps.Vendor_available = m.properties.Vendor_available
-
ctx.CreateModule(cc.LibraryFactory, &ccProps)
- // internal scope contains all properties
- // public scope only contains public properties
- // use public if the owner is different from client
scope := "internal"
- isProduct := ctx.ProductSpecific()
- isVendor := ctx.SocSpecific()
- isOwnerPlatform := owner == "Platform"
- if isProduct {
- // product can't own any sysprop_library now, so product must use public scope
+ // We need to only use public version, if the partition where sysprop_library will be installed
+ // is different from owner.
+
+ if ctx.ProductSpecific() {
+ // Currently product partition can't own any sysprop_library.
scope = "public"
- } else if isVendor && isOwnerPlatform {
- // vendor and odm can only use the public properties from the platform
+ } else if isOwnerPlatform && installedInVendorOrOdm {
+ // Vendor or Odm should use public version of Platform's sysprop_library.
scope = "public"
}
- javaGenProps := struct {
- Srcs []string
- Scope string
- Name *string
- }{
+ ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{
Srcs: m.properties.Srcs,
Scope: scope,
Name: proptools.StringPtr(m.javaGenModuleName()),
+ })
+
+ ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{
+ Name: proptools.StringPtr(m.BaseModuleName()),
+ Srcs: []string{":" + m.javaGenModuleName()},
+ Soc_specific: proptools.BoolPtr(ctx.SocSpecific()),
+ Device_specific: proptools.BoolPtr(ctx.DeviceSpecific()),
+ Product_specific: proptools.BoolPtr(ctx.ProductSpecific()),
+ Installable: m.properties.Installable,
+ Sdk_version: proptools.StringPtr("core_current"),
+ Libs: []string{stub},
+ })
+
+ // if platform sysprop_library is installed in /system or /system-ext, we regard it as an API
+ // and allow any modules (even from different partition) to link against the sysprop_library.
+ // To do that, we create a public stub and expose it to modules with sdk_version: system_*.
+ if isOwnerPlatform && installedInSystem {
+ m.properties.Public_stub = proptools.BoolPtr(true)
+ ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{
+ Srcs: m.properties.Srcs,
+ Scope: "public",
+ Name: proptools.StringPtr(m.javaGenPublicStubName()),
+ })
+
+ ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{
+ Name: proptools.StringPtr(m.JavaPublicStubName()),
+ Srcs: []string{":" + m.javaGenPublicStubName()},
+ Installable: proptools.BoolPtr(false),
+ Sdk_version: proptools.StringPtr("core_current"),
+ Libs: []string{stub},
+ Stem: proptools.StringPtr(m.BaseModuleName()),
+ })
}
-
- ctx.CreateModule(syspropJavaGenFactory, &javaGenProps)
-
- javaProps := struct {
- Name *string
- Srcs []string
- Soc_specific *bool
- Device_specific *bool
- Product_specific *bool
- Required []string
- Sdk_version *string
- Installable *bool
- Libs []string
- }{}
-
- javaProps.Name = proptools.StringPtr(m.BaseModuleName())
- javaProps.Srcs = []string{":" + *javaGenProps.Name}
- javaProps.Soc_specific = proptools.BoolPtr(socSpecific)
- javaProps.Device_specific = proptools.BoolPtr(deviceSpecific)
- javaProps.Product_specific = proptools.BoolPtr(productSpecific)
- javaProps.Installable = m.properties.Installable
- javaProps.Sdk_version = proptools.StringPtr("core_current")
- javaProps.Libs = []string{stub}
-
- ctx.CreateModule(java.LibraryFactory, &javaProps)
}
func syspropDepsMutator(ctx android.BottomUpMutatorContext) {
if m, ok := ctx.Module().(*syspropLibrary); ok {
ctx.AddReverseDependency(m, nil, m.javaGenModuleName())
+
+ if proptools.Bool(m.properties.Public_stub) {
+ ctx.AddReverseDependency(m, nil, m.javaGenPublicStubName())
+ }
}
}
diff --git a/sysprop/sysprop_test.go b/sysprop/sysprop_test.go
index 5446bdc..6ac3f4c 100644
--- a/sysprop/sysprop_test.go
+++ b/sysprop/sysprop_test.go
@@ -24,6 +24,7 @@
"strings"
"testing"
+ "github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
@@ -52,8 +53,7 @@
os.Exit(run())
}
-func testContext(config android.Config, bp string,
- fs map[string][]byte) *android.TestContext {
+func testContext(config android.Config) *android.TestContext {
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("android_app", java.AndroidAppFactory)
@@ -77,18 +77,29 @@
ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
ctx.BottomUp("version", cc.VersionMutator).Parallel()
ctx.BottomUp("begin", cc.BeginMutator).Parallel()
- ctx.BottomUp("sysprop", cc.SyspropMutator).Parallel()
+ ctx.BottomUp("sysprop_cc", cc.SyspropMutator).Parallel()
+ ctx.BottomUp("sysprop_java", java.SyspropMutator).Parallel()
})
ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory)
- ctx.Register()
+ ctx.Register(config)
- bp += java.GatherRequiredDepsForTest()
+ return ctx
+}
+
+func run(t *testing.T, ctx *android.TestContext, config android.Config) {
+ t.Helper()
+ _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
+ android.FailIfErrored(t, errs)
+ _, errs = ctx.PrepareBuildActions(config)
+ android.FailIfErrored(t, errs)
+}
+
+func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
bp += cc.GatherRequiredDepsForTest(android.Android)
mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
"a.java": nil,
"b.java": nil,
"c.java": nil,
@@ -134,21 +145,7 @@
mockFS[k] = v
}
- ctx.MockFileSystem(mockFS)
-
- return ctx
-}
-
-func run(t *testing.T, ctx *android.TestContext, config android.Config) {
- t.Helper()
- _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
- android.FailIfErrored(t, errs)
- _, errs = ctx.PrepareBuildActions(config)
- android.FailIfErrored(t, errs)
-}
-
-func testConfig(env map[string]string) android.Config {
- config := java.TestConfig(buildDir, env)
+ config := java.TestConfig(buildDir, env, bp, mockFS)
config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
@@ -160,8 +157,8 @@
func test(t *testing.T, bp string) *android.TestContext {
t.Helper()
- config := testConfig(nil)
- ctx := testContext(config, bp, nil)
+ config := testConfig(nil, bp, nil)
+ ctx := testContext(config)
run(t, ctx, config)
return ctx
@@ -210,6 +207,13 @@
}
java_library {
+ name: "java-platform-private",
+ srcs: ["c.java"],
+ platform_apis: true,
+ libs: ["sysprop-platform"],
+ }
+
+ java_library {
name: "java-product",
srcs: ["c.java"],
sdk_version: "system_current",
@@ -307,6 +311,7 @@
}
ctx.ModuleForTests("sysprop-platform", "android_common")
+ ctx.ModuleForTests("sysprop-platform_public", "android_common")
ctx.ModuleForTests("sysprop-vendor", "android_common")
// Check for exported includes
@@ -359,4 +364,17 @@
t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
platformPublicVendorPath, vendorInternalPath, vendorFlags)
}
+
+ // Java modules linking against system API should use public stub
+ javaSystemApiClient := ctx.ModuleForTests("java-platform", "android_common")
+ publicStubFound := false
+ ctx.VisitDirectDeps(javaSystemApiClient.Module(), func(dep blueprint.Module) {
+ if dep.Name() == "sysprop-platform_public" {
+ publicStubFound = true
+ }
+ })
+ if !publicStubFound {
+ t.Errorf("system api client should use public stub")
+ }
+
}
diff --git a/xml/xml_test.go b/xml/xml_test.go
index 0a11566..f8ec823 100644
--- a/xml/xml_test.go
+++ b/xml/xml_test.go
@@ -48,20 +48,18 @@
}
func testXml(t *testing.T, bp string) *android.TestContext {
- config := android.TestArchConfig(buildDir, nil)
+ fs := map[string][]byte{
+ "foo.xml": nil,
+ "foo.dtd": nil,
+ "bar.xml": nil,
+ "bar.xsd": nil,
+ "baz.xml": nil,
+ }
+ config := android.TestArchConfig(buildDir, nil, bp, fs)
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("prebuilt_etc", android.PrebuiltEtcFactory)
ctx.RegisterModuleType("prebuilt_etc_xml", PrebuiltEtcXmlFactory)
- ctx.Register()
- mockFiles := map[string][]byte{
- "Android.bp": []byte(bp),
- "foo.xml": nil,
- "foo.dtd": nil,
- "bar.xml": nil,
- "bar.xsd": nil,
- "baz.xml": nil,
- }
- ctx.MockFileSystem(mockFiles)
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
android.FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)