Merge "Add a way to remove duplicates from Bazel label lists, to e.g. avoid duplicate deps."
diff --git a/android/Android.bp b/android/Android.bp
index f17a8a0..588ad5e 100644
--- a/android/Android.bp
+++ b/android/Android.bp
@@ -67,6 +67,7 @@
"singleton.go",
"singleton_module.go",
"soong_config_modules.go",
+ "test_asserts.go",
"test_suites.go",
"testing.go",
"util.go",
diff --git a/android/apex.go b/android/apex.go
index a014592..79d8cdd 100644
--- a/android/apex.go
+++ b/android/apex.go
@@ -719,6 +719,8 @@
// Generate two module out files:
// 1. FullList with transitive deps and their parents in the dep graph
// 2. FlatList with a flat list of transitive deps
+// In both cases transitive deps of external deps are not included. Neither are deps that are only
+// available to APEXes; they are developed with updatability in mind and don't need manual approval.
func (d *ApexBundleDepsInfo) BuildDepsInfoLists(ctx ModuleContext, minSdkVersion string, depInfos DepNameToDepInfoMap) {
var fullContent strings.Builder
var flatContent strings.Builder
diff --git a/android/fixture.go b/android/fixture.go
index 552c8f5..d8893f7 100644
--- a/android/fixture.go
+++ b/android/fixture.go
@@ -16,8 +16,6 @@
import (
"fmt"
- "reflect"
- "strings"
"testing"
)
@@ -237,8 +235,14 @@
// A set of mock files to add to the mock file system.
type MockFS map[string][]byte
+// Merge adds the extra entries from the supplied map to this one.
+//
+// Fails if the supplied map files with the same paths are present in both of them.
func (fs MockFS) Merge(extra map[string][]byte) {
for p, c := range extra {
+ if _, ok := fs[p]; ok {
+ panic(fmt.Errorf("attempted to add file %s to the mock filesystem but it already exists", p))
+ }
fs[p] = c
}
}
@@ -289,17 +293,40 @@
}
// Add a file to the mock filesystem
+//
+// Fail if the filesystem already contains a file with that path, use FixtureOverrideFile instead.
func FixtureAddFile(path string, contents []byte) FixturePreparer {
return FixtureModifyMockFS(func(fs MockFS) {
+ if _, ok := fs[path]; ok {
+ panic(fmt.Errorf("attempted to add file %s to the mock filesystem but it already exists, use FixtureOverride*File instead", path))
+ }
fs[path] = contents
})
}
// Add a text file to the mock filesystem
+//
+// Fail if the filesystem already contains a file with that path.
func FixtureAddTextFile(path string, contents string) FixturePreparer {
return FixtureAddFile(path, []byte(contents))
}
+// Override a file in the mock filesystem
+//
+// If the file does not exist this behaves as FixtureAddFile.
+func FixtureOverrideFile(path string, contents []byte) FixturePreparer {
+ return FixtureModifyMockFS(func(fs MockFS) {
+ fs[path] = contents
+ })
+}
+
+// Override a text file in the mock filesystem
+//
+// If the file does not exist this behaves as FixtureAddTextFile.
+func FixtureOverrideTextFile(path string, contents string) FixturePreparer {
+ return FixtureOverrideFile(path, []byte(contents))
+}
+
// Add the root Android.bp file with the supplied contents.
func FixtureWithRootAndroidBp(contents string) FixturePreparer {
return FixtureAddTextFile("Android.bp", contents)
@@ -440,16 +467,16 @@
// The supplied result can be used to access the state of the code under test just as the main
// body of the test would but if any errors other than ones expected are reported the state may
// be indeterminate.
- CheckErrors(result *TestResult)
+ CheckErrors(t *testing.T, result *TestResult)
}
type simpleErrorHandler struct {
- function func(result *TestResult)
+ function func(t *testing.T, result *TestResult)
}
-func (h simpleErrorHandler) CheckErrors(result *TestResult) {
- result.Helper()
- h.function(result)
+func (h simpleErrorHandler) CheckErrors(t *testing.T, result *TestResult) {
+ t.Helper()
+ h.function(t, result)
}
// The default fixture error handler.
@@ -459,9 +486,9 @@
// If the test fails this handler will call `result.FailNow()` which will exit the goroutine within
// which the test is being run which means that the RunTest() method will not return.
var FixtureExpectsNoErrors = FixtureCustomErrorHandler(
- func(result *TestResult) {
- result.Helper()
- FailIfErrored(result.T, result.Errs)
+ func(t *testing.T, result *TestResult) {
+ t.Helper()
+ FailIfErrored(t, result.Errs)
},
)
@@ -478,10 +505,10 @@
// If the test fails this handler will call `result.FailNow()` which will exit the goroutine within
// which the test is being run which means that the RunTest() method will not return.
func FixtureExpectsAtLeastOneErrorMatchingPattern(pattern string) FixtureErrorHandler {
- return FixtureCustomErrorHandler(func(result *TestResult) {
- result.Helper()
- if !FailIfNoMatchingErrors(result.T, pattern, result.Errs) {
- result.FailNow()
+ return FixtureCustomErrorHandler(func(t *testing.T, result *TestResult) {
+ t.Helper()
+ if !FailIfNoMatchingErrors(t, pattern, result.Errs) {
+ t.FailNow()
}
})
}
@@ -500,14 +527,14 @@
// If the test fails this handler will call `result.FailNow()` which will exit the goroutine within
// which the test is being run which means that the RunTest() method will not return.
func FixtureExpectsAllErrorsToMatchAPattern(patterns []string) FixtureErrorHandler {
- return FixtureCustomErrorHandler(func(result *TestResult) {
- result.Helper()
- CheckErrorsAgainstExpectations(result.T, result.Errs, patterns)
+ return FixtureCustomErrorHandler(func(t *testing.T, result *TestResult) {
+ t.Helper()
+ CheckErrorsAgainstExpectations(t, result.Errs, patterns)
})
}
// FixtureCustomErrorHandler creates a custom error handler
-func FixtureCustomErrorHandler(function func(result *TestResult)) FixtureErrorHandler {
+func FixtureCustomErrorHandler(function func(t *testing.T, result *TestResult)) FixtureErrorHandler {
return simpleErrorHandler{
function: function,
}
@@ -519,122 +546,6 @@
RunTest() *TestResult
}
-// Provides general test support.
-type TestHelper struct {
- *testing.T
-}
-
-// AssertBoolEquals checks if the expected and actual values are equal and if they are not then it
-// reports an error prefixed with the supplied message and including a reason for why it failed.
-func (h *TestHelper) AssertBoolEquals(message string, expected bool, actual bool) {
- h.Helper()
- if actual != expected {
- h.Errorf("%s: expected %t, actual %t", message, expected, actual)
- }
-}
-
-// AssertStringEquals checks if the expected and actual values are equal and if they are not then
-// it reports an error prefixed with the supplied message and including a reason for why it failed.
-func (h *TestHelper) AssertStringEquals(message string, expected string, actual string) {
- h.Helper()
- if actual != expected {
- h.Errorf("%s: expected %s, actual %s", message, expected, actual)
- }
-}
-
-// AssertErrorMessageEquals checks if the error is not nil and has the expected message. If it does
-// not then this reports an error prefixed with the supplied message and including a reason for why
-// it failed.
-func (h *TestHelper) AssertErrorMessageEquals(message string, expected string, actual error) {
- h.Helper()
- if actual == nil {
- h.Errorf("Expected error but was nil")
- } else if actual.Error() != expected {
- h.Errorf("%s: expected %s, actual %s", message, expected, actual.Error())
- }
-}
-
-// AssertTrimmedStringEquals checks if the expected and actual values are the same after trimming
-// leading and trailing spaces from them both. If they are not then it reports an error prefixed
-// with the supplied message and including a reason for why it failed.
-func (h *TestHelper) AssertTrimmedStringEquals(message string, expected string, actual string) {
- h.Helper()
- h.AssertStringEquals(message, strings.TrimSpace(expected), strings.TrimSpace(actual))
-}
-
-// AssertStringDoesContain checks if the string contains the expected substring. If it does not
-// then it reports an error prefixed with the supplied message and including a reason for why it
-// failed.
-func (h *TestHelper) AssertStringDoesContain(message string, s string, expectedSubstring string) {
- h.Helper()
- if !strings.Contains(s, expectedSubstring) {
- h.Errorf("%s: could not find %q within %q", message, expectedSubstring, s)
- }
-}
-
-// AssertStringDoesNotContain checks if the string contains the expected substring. If it does then
-// it reports an error prefixed with the supplied message and including a reason for why it failed.
-func (h *TestHelper) AssertStringDoesNotContain(message string, s string, unexpectedSubstring string) {
- h.Helper()
- if strings.Contains(s, unexpectedSubstring) {
- h.Errorf("%s: unexpectedly found %q within %q", message, unexpectedSubstring, s)
- }
-}
-
-// AssertStringListContains checks if the list of strings contains the expected string. If it does
-// not then it reports an error prefixed with the supplied message and including a reason for why it
-// failed.
-func (h *TestHelper) AssertStringListContains(message string, list []string, expected string) {
- h.Helper()
- if !InList(expected, list) {
- h.Errorf("%s: could not find %q within %q", message, expected, list)
- }
-}
-
-// AssertArrayString checks if the expected and actual values are equal and if they are not then it
-// reports an error prefixed with the supplied message and including a reason for why it failed.
-func (h *TestHelper) AssertArrayString(message string, expected, actual []string) {
- h.Helper()
- if len(actual) != len(expected) {
- h.Errorf("%s: expected %d (%q), actual (%d) %q", message, len(expected), expected, len(actual), actual)
- return
- }
- for i := range actual {
- if actual[i] != expected[i] {
- h.Errorf("%s: expected %d-th, %q (%q), actual %q (%q)",
- message, i, expected[i], expected, actual[i], actual)
- return
- }
- }
-}
-
-// AssertDeepEquals checks if the expected and actual values are equal using reflect.DeepEqual and
-// if they are not then it reports an error prefixed with the supplied message and including a
-// reason for why it failed.
-func (h *TestHelper) AssertDeepEquals(message string, expected interface{}, actual interface{}) {
- h.Helper()
- if !reflect.DeepEqual(actual, expected) {
- h.Errorf("%s: expected:\n %#v\n got:\n %#v", message, expected, actual)
- }
-}
-
-// AssertPanic checks that the supplied function panics as expected.
-func (h *TestHelper) AssertPanic(message string, funcThatShouldPanic func()) {
- h.Helper()
- panicked := false
- func() {
- defer func() {
- if x := recover(); x != nil {
- panicked = true
- }
- }()
- funcThatShouldPanic()
- }()
- if !panicked {
- h.Error(message)
- }
-}
-
// Struct to allow TestResult to embed a *TestContext and allow call forwarding to its methods.
type testContext struct {
*TestContext
@@ -642,7 +553,6 @@
// The result of running a test.
type TestResult struct {
- TestHelper
testContext
fixture *fixture
@@ -787,14 +697,13 @@
}
result := &TestResult{
- TestHelper: TestHelper{T: f.t},
testContext: testContext{ctx},
fixture: f,
Config: f.config,
Errs: errs,
}
- f.errorHandler.CheckErrors(result)
+ f.errorHandler.CheckErrors(f.t, result)
return result
}
@@ -830,36 +739,7 @@
return result
}
-// NewFixture creates a new test fixture that is based on the one that created this result. It is
-// intended to test the output of module types that generate content to be processed by the build,
-// e.g. sdk snapshots.
-func (r *TestResult) NewFixture(preparers ...FixturePreparer) Fixture {
- return r.fixture.factory.Fixture(r.T, preparers...)
-}
-
-// RunTest is shorthand for NewFixture(preparers...).RunTest().
-func (r *TestResult) RunTest(preparers ...FixturePreparer) *TestResult {
- r.Helper()
- return r.fixture.factory.Fixture(r.T, preparers...).RunTest()
-}
-
// Module returns the module with the specific name and of the specified variant.
func (r *TestResult) Module(name string, variant string) Module {
return r.ModuleForTests(name, variant).Module()
}
-
-// Create a *TestResult object suitable for use within a subtest.
-//
-// This ensures that any errors reported by the TestResult, e.g. from within one of its
-// Assert... methods, will be associated with the sub test and not the main test.
-//
-// result := ....RunTest()
-// t.Run("subtest", func(t *testing.T) {
-// subResult := result.ResultForSubTest(t)
-// subResult.AssertStringEquals("something", ....)
-// })
-func (r *TestResult) ResultForSubTest(t *testing.T) *TestResult {
- subTestResult := *r
- r.T = t
- return &subTestResult
-}
diff --git a/android/fixture_test.go b/android/fixture_test.go
index 5a7bf3b..a31ef16 100644
--- a/android/fixture_test.go
+++ b/android/fixture_test.go
@@ -43,7 +43,6 @@
extension.Fixture(t, preparer1, preparer2, preparer2Then1, preparer3)
- h := TestHelper{t}
- h.AssertDeepEquals("preparers called in wrong order",
+ AssertDeepEquals(t, "preparers called in wrong order",
[]string{"preparer1", "preparer2", "preparer4", "preparer3"}, list)
}
diff --git a/android/licenses_test.go b/android/licenses_test.go
index d0e3533..a581932 100644
--- a/android/licenses_test.go
+++ b/android/licenses_test.go
@@ -482,33 +482,33 @@
RunTest(t)
if test.effectiveLicenses != nil {
- checkEffectiveLicenses(result, test.effectiveLicenses)
+ checkEffectiveLicenses(t, result, test.effectiveLicenses)
}
if test.effectivePackage != nil {
- checkEffectivePackage(result, test.effectivePackage)
+ checkEffectivePackage(t, result, test.effectivePackage)
}
if test.effectiveNotices != nil {
- checkEffectiveNotices(result, test.effectiveNotices)
+ checkEffectiveNotices(t, result, test.effectiveNotices)
}
if test.effectiveKinds != nil {
- checkEffectiveKinds(result, test.effectiveKinds)
+ checkEffectiveKinds(t, result, test.effectiveKinds)
}
if test.effectiveConditions != nil {
- checkEffectiveConditions(result, test.effectiveConditions)
+ checkEffectiveConditions(t, result, test.effectiveConditions)
}
if test.effectiveInheritedLicenses != nil {
- checkEffectiveInheritedLicenses(result, test.effectiveInheritedLicenses)
+ checkEffectiveInheritedLicenses(t, result, test.effectiveInheritedLicenses)
}
})
}
}
-func checkEffectiveLicenses(result *TestResult, effectiveLicenses map[string][]string) {
+func checkEffectiveLicenses(t *testing.T, result *TestResult, effectiveLicenses map[string][]string) {
actualLicenses := make(map[string][]string)
result.Context.Context.VisitAllModules(func(m blueprint.Module) {
if _, ok := m.(*licenseModule); ok {
@@ -522,7 +522,7 @@
}
module, ok := m.(Module)
if !ok {
- result.Errorf("%q not a module", m.Name())
+ t.Errorf("%q not a module", m.Name())
return
}
base := module.base()
@@ -538,12 +538,12 @@
licenses = []string{}
}
if !compareUnorderedStringArrays(expectedLicenses, licenses) {
- result.Errorf("effective licenses mismatch for module %q: expected %q, found %q", moduleName, expectedLicenses, licenses)
+ t.Errorf("effective licenses mismatch for module %q: expected %q, found %q", moduleName, expectedLicenses, licenses)
}
}
}
-func checkEffectiveInheritedLicenses(result *TestResult, effectiveInheritedLicenses map[string][]string) {
+func checkEffectiveInheritedLicenses(t *testing.T, result *TestResult, effectiveInheritedLicenses map[string][]string) {
actualLicenses := make(map[string][]string)
result.Context.Context.VisitAllModules(func(m blueprint.Module) {
if _, ok := m.(*licenseModule); ok {
@@ -557,7 +557,7 @@
}
module, ok := m.(Module)
if !ok {
- result.Errorf("%q not a module", m.Name())
+ t.Errorf("%q not a module", m.Name())
return
}
base := module.base()
@@ -580,7 +580,7 @@
}
cmodule, ok := c.(Module)
if !ok {
- result.Errorf("%q not a module", c.Name())
+ t.Errorf("%q not a module", c.Name())
return
}
cbase := cmodule.base()
@@ -603,12 +603,12 @@
licenses = []string{}
}
if !compareUnorderedStringArrays(expectedInheritedLicenses, licenses) {
- result.Errorf("effective inherited licenses mismatch for module %q: expected %q, found %q", moduleName, expectedInheritedLicenses, licenses)
+ t.Errorf("effective inherited licenses mismatch for module %q: expected %q, found %q", moduleName, expectedInheritedLicenses, licenses)
}
}
}
-func checkEffectivePackage(result *TestResult, effectivePackage map[string]string) {
+func checkEffectivePackage(t *testing.T, result *TestResult, effectivePackage map[string]string) {
actualPackage := make(map[string]string)
result.Context.Context.VisitAllModules(func(m blueprint.Module) {
if _, ok := m.(*licenseModule); ok {
@@ -622,7 +622,7 @@
}
module, ok := m.(Module)
if !ok {
- result.Errorf("%q not a module", m.Name())
+ t.Errorf("%q not a module", m.Name())
return
}
base := module.base()
@@ -643,12 +643,12 @@
packageName = ""
}
if expectedPackage != packageName {
- result.Errorf("effective package mismatch for module %q: expected %q, found %q", moduleName, expectedPackage, packageName)
+ t.Errorf("effective package mismatch for module %q: expected %q, found %q", moduleName, expectedPackage, packageName)
}
}
}
-func checkEffectiveNotices(result *TestResult, effectiveNotices map[string][]string) {
+func checkEffectiveNotices(t *testing.T, result *TestResult, effectiveNotices map[string][]string) {
actualNotices := make(map[string][]string)
result.Context.Context.VisitAllModules(func(m blueprint.Module) {
if _, ok := m.(*licenseModule); ok {
@@ -662,7 +662,7 @@
}
module, ok := m.(Module)
if !ok {
- result.Errorf("%q not a module", m.Name())
+ t.Errorf("%q not a module", m.Name())
return
}
base := module.base()
@@ -678,12 +678,12 @@
notices = []string{}
}
if !compareUnorderedStringArrays(expectedNotices, notices) {
- result.Errorf("effective notice files mismatch for module %q: expected %q, found %q", moduleName, expectedNotices, notices)
+ t.Errorf("effective notice files mismatch for module %q: expected %q, found %q", moduleName, expectedNotices, notices)
}
}
}
-func checkEffectiveKinds(result *TestResult, effectiveKinds map[string][]string) {
+func checkEffectiveKinds(t *testing.T, result *TestResult, effectiveKinds map[string][]string) {
actualKinds := make(map[string][]string)
result.Context.Context.VisitAllModules(func(m blueprint.Module) {
if _, ok := m.(*licenseModule); ok {
@@ -697,7 +697,7 @@
}
module, ok := m.(Module)
if !ok {
- result.Errorf("%q not a module", m.Name())
+ t.Errorf("%q not a module", m.Name())
return
}
base := module.base()
@@ -713,12 +713,12 @@
kinds = []string{}
}
if !compareUnorderedStringArrays(expectedKinds, kinds) {
- result.Errorf("effective license kinds mismatch for module %q: expected %q, found %q", moduleName, expectedKinds, kinds)
+ t.Errorf("effective license kinds mismatch for module %q: expected %q, found %q", moduleName, expectedKinds, kinds)
}
}
}
-func checkEffectiveConditions(result *TestResult, effectiveConditions map[string][]string) {
+func checkEffectiveConditions(t *testing.T, result *TestResult, effectiveConditions map[string][]string) {
actualConditions := make(map[string][]string)
result.Context.Context.VisitAllModules(func(m blueprint.Module) {
if _, ok := m.(*licenseModule); ok {
@@ -732,7 +732,7 @@
}
module, ok := m.(Module)
if !ok {
- result.Errorf("%q not a module", m.Name())
+ t.Errorf("%q not a module", m.Name())
return
}
base := module.base()
@@ -748,7 +748,7 @@
conditions = []string{}
}
if !compareUnorderedStringArrays(expectedConditions, conditions) {
- result.Errorf("effective license conditions mismatch for module %q: expected %q, found %q", moduleName, expectedConditions, conditions)
+ t.Errorf("effective license conditions mismatch for module %q: expected %q, found %q", moduleName, expectedConditions, conditions)
}
}
}
diff --git a/android/test_asserts.go b/android/test_asserts.go
new file mode 100644
index 0000000..d0de523
--- /dev/null
+++ b/android/test_asserts.go
@@ -0,0 +1,134 @@
+// Copyright 2021 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package android
+
+import (
+ "reflect"
+ "strings"
+ "testing"
+)
+
+// This file contains general purpose test assert functions.
+
+// AssertBoolEquals checks if the expected and actual values are equal and if they are not then it
+// reports an error prefixed with the supplied message and including a reason for why it failed.
+func AssertBoolEquals(t *testing.T, message string, expected bool, actual bool) {
+ t.Helper()
+ if actual != expected {
+ t.Errorf("%s: expected %t, actual %t", message, expected, actual)
+ }
+}
+
+// AssertStringEquals checks if the expected and actual values are equal and if they are not then
+// it reports an error prefixed with the supplied message and including a reason for why it failed.
+func AssertStringEquals(t *testing.T, message string, expected string, actual string) {
+ t.Helper()
+ if actual != expected {
+ t.Errorf("%s: expected %s, actual %s", message, expected, actual)
+ }
+}
+
+// AssertErrorMessageEquals checks if the error is not nil and has the expected message. If it does
+// not then this reports an error prefixed with the supplied message and including a reason for why
+// it failed.
+func AssertErrorMessageEquals(t *testing.T, message string, expected string, actual error) {
+ t.Helper()
+ if actual == nil {
+ t.Errorf("Expected error but was nil")
+ } else if actual.Error() != expected {
+ t.Errorf("%s: expected %s, actual %s", message, expected, actual.Error())
+ }
+}
+
+// AssertTrimmedStringEquals checks if the expected and actual values are the same after trimming
+// leading and trailing spaces from them both. If they are not then it reports an error prefixed
+// with the supplied message and including a reason for why it failed.
+func AssertTrimmedStringEquals(t *testing.T, message string, expected string, actual string) {
+ t.Helper()
+ AssertStringEquals(t, message, strings.TrimSpace(expected), strings.TrimSpace(actual))
+}
+
+// AssertStringDoesContain checks if the string contains the expected substring. If it does not
+// then it reports an error prefixed with the supplied message and including a reason for why it
+// failed.
+func AssertStringDoesContain(t *testing.T, message string, s string, expectedSubstring string) {
+ t.Helper()
+ if !strings.Contains(s, expectedSubstring) {
+ t.Errorf("%s: could not find %q within %q", message, expectedSubstring, s)
+ }
+}
+
+// AssertStringDoesNotContain checks if the string contains the expected substring. If it does then
+// it reports an error prefixed with the supplied message and including a reason for why it failed.
+func AssertStringDoesNotContain(t *testing.T, message string, s string, unexpectedSubstring string) {
+ t.Helper()
+ if strings.Contains(s, unexpectedSubstring) {
+ t.Errorf("%s: unexpectedly found %q within %q", message, unexpectedSubstring, s)
+ }
+}
+
+// AssertStringListContains checks if the list of strings contains the expected string. If it does
+// not then it reports an error prefixed with the supplied message and including a reason for why it
+// failed.
+func AssertStringListContains(t *testing.T, message string, list []string, expected string) {
+ t.Helper()
+ if !InList(expected, list) {
+ t.Errorf("%s: could not find %q within %q", message, expected, list)
+ }
+}
+
+// AssertArrayString checks if the expected and actual values are equal and if they are not then it
+// reports an error prefixed with the supplied message and including a reason for why it failed.
+func AssertArrayString(t *testing.T, message string, expected, actual []string) {
+ t.Helper()
+ if len(actual) != len(expected) {
+ t.Errorf("%s: expected %d (%q), actual (%d) %q", message, len(expected), expected, len(actual), actual)
+ return
+ }
+ for i := range actual {
+ if actual[i] != expected[i] {
+ t.Errorf("%s: expected %d-th, %q (%q), actual %q (%q)",
+ message, i, expected[i], expected, actual[i], actual)
+ return
+ }
+ }
+}
+
+// AssertDeepEquals checks if the expected and actual values are equal using reflect.DeepEqual and
+// if they are not then it reports an error prefixed with the supplied message and including a
+// reason for why it failed.
+func AssertDeepEquals(t *testing.T, message string, expected interface{}, actual interface{}) {
+ t.Helper()
+ if !reflect.DeepEqual(actual, expected) {
+ t.Errorf("%s: expected:\n %#v\n got:\n %#v", message, expected, actual)
+ }
+}
+
+// AssertPanic checks that the supplied function panics as expected.
+func AssertPanic(t *testing.T, message string, funcThatShouldPanic func()) {
+ t.Helper()
+ panicked := false
+ func() {
+ defer func() {
+ if x := recover(); x != nil {
+ panicked = true
+ }
+ }()
+ funcThatShouldPanic()
+ }()
+ if !panicked {
+ t.Error(message)
+ }
+}
diff --git a/android/visibility_test.go b/android/visibility_test.go
index eb4071e..fdf18ce 100644
--- a/android/visibility_test.go
+++ b/android/visibility_test.go
@@ -1166,17 +1166,17 @@
RunTest(t)
if test.effectiveVisibility != nil {
- checkEffectiveVisibility(result, test.effectiveVisibility)
+ checkEffectiveVisibility(t, result, test.effectiveVisibility)
}
})
}
}
-func checkEffectiveVisibility(result *TestResult, effectiveVisibility map[qualifiedModuleName][]string) {
+func checkEffectiveVisibility(t *testing.T, result *TestResult, effectiveVisibility map[qualifiedModuleName][]string) {
for moduleName, expectedRules := range effectiveVisibility {
rule := effectiveVisibilityRules(result.Config, moduleName)
stringRules := rule.Strings()
- result.AssertDeepEquals("effective rules mismatch", expectedRules, stringRules)
+ AssertDeepEquals(t, "effective rules mismatch", expectedRules, stringRules)
}
}
diff --git a/apex/Android.bp b/apex/Android.bp
index 8a2edeb..1890b89 100644
--- a/apex/Android.bp
+++ b/apex/Android.bp
@@ -25,6 +25,7 @@
"deapexer.go",
"key.go",
"prebuilt.go",
+ "testing.go",
"vndk.go",
],
testSrcs: [
diff --git a/apex/allowed_deps.txt b/apex/allowed_deps.txt
index 170302c..154b9aa 100644
--- a/apex/allowed_deps.txt
+++ b/apex/allowed_deps.txt
@@ -408,6 +408,7 @@
libring(minSdkVersion:29)
libring-core(minSdkVersion:29)
librustc_demangle.rust_sysroot(minSdkVersion:29)
+libruy_static(minSdkVersion:30)
libsdk_proto(minSdkVersion:30)
libsfplugin_ccodec_utils(minSdkVersion:29)
libsonivoxwithoutjet(minSdkVersion:29)
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 08f54f7..dd290d3 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -127,6 +127,96 @@
config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
}
+var emptyFixtureFactory = android.NewFixtureFactory(&buildDir)
+
+var apexFixtureFactory = android.NewFixtureFactory(
+ &buildDir,
+ // General preparers in alphabetical order as test infrastructure will enforce correct
+ // registration order.
+ android.PrepareForTestWithAndroidBuildComponents,
+ bpf.PrepareForTestWithBpf,
+ cc.PrepareForTestWithCcBuildComponents,
+ java.PrepareForTestWithJavaDefaultModules,
+ prebuilt_etc.PrepareForTestWithPrebuiltEtc,
+ rust.PrepareForTestWithRustDefaultModules,
+ sh.PrepareForTestWithShBuildComponents,
+
+ PrepareForTestWithApexBuildComponents,
+
+ // Additional apex test specific preparers.
+ android.FixtureAddTextFile("system/sepolicy/Android.bp", `
+ filegroup {
+ name: "myapex-file_contexts",
+ srcs: [
+ "apex/myapex-file_contexts",
+ ],
+ }
+ `),
+ android.FixtureMergeMockFs(android.MockFS{
+ "a.java": nil,
+ "PrebuiltAppFoo.apk": nil,
+ "PrebuiltAppFooPriv.apk": nil,
+ "build/make/target/product/security": nil,
+ "apex_manifest.json": nil,
+ "AndroidManifest.xml": nil,
+ "system/sepolicy/apex/myapex-file_contexts": nil,
+ "system/sepolicy/apex/myapex.updatable-file_contexts": nil,
+ "system/sepolicy/apex/myapex2-file_contexts": nil,
+ "system/sepolicy/apex/otherapex-file_contexts": nil,
+ "system/sepolicy/apex/com.android.vndk-file_contexts": nil,
+ "system/sepolicy/apex/com.android.vndk.current-file_contexts": nil,
+ "mylib.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,
+ "prebuilt.so": 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,
+ "custom_notice_for_static_lib": nil,
+ "testkey2.avbpubkey": nil,
+ "testkey2.pem": nil,
+ "myapex-arm64.apex": nil,
+ "myapex-arm.apex": nil,
+ "myapex.apks": 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,
+ "baz": nil,
+ "bar/baz": nil,
+ "testdata/baz": nil,
+ "AppSet.apks": nil,
+ "foo.rs": nil,
+ "libfoo.jar": nil,
+ "libbar.jar": nil,
+ },
+ ),
+
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ variables.DeviceVndkVersion = proptools.StringPtr("current")
+ variables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
+ variables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
+ variables.Platform_sdk_codename = proptools.StringPtr("Q")
+ variables.Platform_sdk_final = proptools.BoolPtr(false)
+ variables.Platform_version_active_codenames = []string{"Q"}
+ variables.Platform_vndk_version = proptools.StringPtr("VER")
+ }),
+)
+
func testApexContext(_ *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
bp = bp + `
filegroup {
@@ -432,7 +522,7 @@
}
rust_binary {
- name: "foo.rust",
+ name: "foo.rust",
srcs: ["foo.rs"],
rlibs: ["libfoo.rlib.rust"],
dylibs: ["libfoo.dylib.rust"],
@@ -440,14 +530,14 @@
}
rust_library_rlib {
- name: "libfoo.rlib.rust",
+ name: "libfoo.rlib.rust",
srcs: ["foo.rs"],
crate_name: "foo",
apex_available: ["myapex"],
}
rust_library_dylib {
- name: "libfoo.dylib.rust",
+ name: "libfoo.dylib.rust",
srcs: ["foo.rs"],
crate_name: "foo",
apex_available: ["myapex"],
@@ -642,14 +732,12 @@
fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n")
ensureListContains(t, fullDepsInfo, " myjar(minSdkVersion:(no version)) <- myapex")
- ensureListContains(t, fullDepsInfo, " mylib(minSdkVersion:(no version)) <- myapex")
ensureListContains(t, fullDepsInfo, " mylib2(minSdkVersion:(no version)) <- mylib")
ensureListContains(t, fullDepsInfo, " myotherjar(minSdkVersion:(no version)) <- myjar")
ensureListContains(t, fullDepsInfo, " mysharedjar(minSdkVersion:(no version)) (external) <- myjar")
flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n")
ensureListContains(t, flatDepsInfo, "myjar(minSdkVersion:(no version))")
- ensureListContains(t, flatDepsInfo, "mylib(minSdkVersion:(no version))")
ensureListContains(t, flatDepsInfo, "mylib2(minSdkVersion:(no version))")
ensureListContains(t, flatDepsInfo, "myotherjar(minSdkVersion:(no version))")
ensureListContains(t, flatDepsInfo, "mysharedjar(minSdkVersion:(no version)) (external)")
@@ -1148,13 +1236,9 @@
ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n")
- ensureListContains(t, fullDepsInfo, " mylib(minSdkVersion:(no version)) <- myapex2")
- ensureListContains(t, fullDepsInfo, " libbaz(minSdkVersion:(no version)) <- mylib")
ensureListContains(t, fullDepsInfo, " libfoo(minSdkVersion:(no version)) (external) <- mylib")
flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n")
- ensureListContains(t, flatDepsInfo, "mylib(minSdkVersion:(no version))")
- ensureListContains(t, flatDepsInfo, "libbaz(minSdkVersion:(no version))")
ensureListContains(t, flatDepsInfo, "libfoo(minSdkVersion:(no version)) (external)")
}
@@ -1228,9 +1312,10 @@
}
-func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) {
- ctx := testApex(t, "", func(fs map[string][]byte, config android.Config) {
- bp := `
+var prepareForTestOfRuntimeApexWithHwasan = android.GroupFixturePreparers(
+ cc.PrepareForTestWithCcBuildComponents,
+ PrepareForTestWithApexBuildComponents,
+ android.FixtureAddTextFile("bionic/apex/Android.bp", `
apex {
name: "com.android.runtime",
key: "com.android.runtime.key",
@@ -1243,7 +1328,12 @@
public_key: "testkey.avbpubkey",
private_key: "testkey.pem",
}
+ `),
+ android.FixtureAddFile("system/sepolicy/apex/com.android.runtime-file_contexts", nil),
+)
+func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) {
+ result := emptyFixtureFactory.Extend(prepareForTestOfRuntimeApexWithHwasan).RunTestWithBp(t, `
cc_library {
name: "libc",
no_libcrt: true,
@@ -1270,12 +1360,8 @@
sanitize: {
never: true,
},
- }
- `
- // override bp to use hard-coded names: com.android.runtime and libc
- fs["Android.bp"] = []byte(bp)
- fs["system/sepolicy/apex/com.android.runtime-file_contexts"] = nil
- })
+ } `)
+ ctx := result.TestContext
ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{
"lib64/bionic/libc.so",
@@ -1293,21 +1379,12 @@
}
func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) {
- ctx := testApex(t, "", func(fs map[string][]byte, config android.Config) {
- bp := `
- apex {
- name: "com.android.runtime",
- key: "com.android.runtime.key",
- native_shared_libs: ["libc"],
- updatable: false,
- }
-
- apex_key {
- name: "com.android.runtime.key",
- public_key: "testkey.avbpubkey",
- private_key: "testkey.pem",
- }
-
+ result := emptyFixtureFactory.Extend(
+ prepareForTestOfRuntimeApexWithHwasan,
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ variables.SanitizeDevice = []string{"hwaddress"}
+ }),
+ ).RunTestWithBp(t, `
cc_library {
name: "libc",
no_libcrt: true,
@@ -1331,13 +1408,8 @@
never: true,
},
}
- `
- // override bp to use hard-coded names: com.android.runtime and libc
- fs["Android.bp"] = []byte(bp)
- fs["system/sepolicy/apex/com.android.runtime-file_contexts"] = nil
-
- config.TestProductVariables.SanitizeDevice = []string{"hwaddress"}
- })
+ `)
+ ctx := result.TestContext
ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{
"lib64/bionic/libc.so",
@@ -1961,7 +2033,7 @@
java_library {
name: "myjar",
srcs: ["foo/bar/MyClass.java"],
- sdk_version: "core_platform",
+ sdk_version: "test_current",
apex_available: ["myapex"],
}
`,
@@ -2008,13 +2080,16 @@
java_library {
name: "myjar",
srcs: ["foo/bar/MyClass.java"],
- sdk_version: "core_platform",
+ sdk_version: "test_current",
apex_available: ["myapex"],
}
`,
},
{
- name: "Updatable apex with non-stable transitive dep",
+ name: "Updatable apex with non-stable transitive dep",
+ // This is not actually detecting that the transitive dependency is unstable, rather it is
+ // detecting that the transitive dependency is building against a wider API surface than the
+ // module that depends on it is using.
expectedError: "compiles against Android API, but dependency \"transitive-jar\" is compiling against private API.",
bp: `
apex {
diff --git a/apex/builder.go b/apex/builder.go
index 2663a67..da800d4 100644
--- a/apex/builder.go
+++ b/apex/builder.go
@@ -926,9 +926,15 @@
return !externalDep
}
+ // Skip dependencies that are only available to APEXes; they are developed with updatability
+ // in mind and don't need manual approval.
+ if to.(android.ApexModule).NotAvailableForPlatform() {
+ return !externalDep
+ }
+
depTag := ctx.OtherModuleDependencyTag(to)
+ // Check to see if dependency been marked to skip the dependency check
if skipDepCheck, ok := depTag.(android.SkipApexAllowedDependenciesCheck); ok && skipDepCheck.SkipApexAllowedDependenciesCheck() {
- // Check to see if dependency been marked to skip the dependency check
return !externalDep
}
diff --git a/apex/testing.go b/apex/testing.go
new file mode 100644
index 0000000..e662cad
--- /dev/null
+++ b/apex/testing.go
@@ -0,0 +1,22 @@
+// Copyright 2021 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package apex
+
+import "android/soong/android"
+
+var PrepareForTestWithApexBuildComponents = android.GroupFixturePreparers(
+ android.FixtureRegisterWithContext(registerApexBuildComponents),
+ android.FixtureRegisterWithContext(registerApexKeyBuildComponents),
+)
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 7d9fa47..16ae7ee 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -222,7 +222,7 @@
for _, o := range ld.Inputs {
objs = append(objs, o.Base())
}
- result.AssertArrayString("libTest inputs", []string{"foo.o", "bar.o"}, objs)
+ android.AssertArrayString(t, "libTest inputs", []string{"foo.o", "bar.o"}, objs)
}
func TestVendorSrc(t *testing.T) {
@@ -3429,7 +3429,7 @@
).RunTestWithBp(t, bp)
libfoo := result.Module("libfoo", "android_arm64_armv8-a_static").(*Module)
- result.AssertStringListContains("cppflags", libfoo.flags.Local.CppFlags, "-DBAR")
+ android.AssertStringListContains(t, "cppflags", libfoo.flags.Local.CppFlags, "-DBAR")
}
func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
@@ -3452,12 +3452,12 @@
).RunTestWithBp(t, bp)
libbar := result.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
- result.AssertDeepEquals("libbar rule", android.ErrorRule, libbar.Rule)
+ android.AssertDeepEquals(t, "libbar rule", android.ErrorRule, libbar.Rule)
- result.AssertStringDoesContain("libbar error", libbar.Args["error"], "missing dependencies: libmissing")
+ android.AssertStringDoesContain(t, "libbar error", libbar.Args["error"], "missing dependencies: libmissing")
libfoo := result.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
- result.AssertStringListContains("libfoo.a dependencies", libfoo.Inputs.Strings(), libbar.Output.String())
+ android.AssertStringListContains(t, "libfoo.a dependencies", libfoo.Inputs.Strings(), libbar.Output.String())
}
func TestInstallSharedLibs(t *testing.T) {
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 8218d97..cd09e6e 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -404,12 +404,6 @@
s.Diag.Cfi = boolPtr(false)
}
- // Also disable CFI for arm32 until b/35157333 is fixed.
- if ctx.Arch().ArchType == android.Arm {
- s.Cfi = boolPtr(false)
- s.Diag.Cfi = boolPtr(false)
- }
-
// HWASan requires AArch64 hardware feature (top-byte-ignore).
if ctx.Arch().ArchType != android.Arm64 {
s.Hwaddress = nil
diff --git a/cc/testing.go b/cc/testing.go
index 6840ef4..d8adc61 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -649,8 +649,11 @@
// The preparer to include if running a cc related test for linux bionic.
var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
- // Enable linux bionic.
- android.FixtureAddTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
+ // Enable linux bionic
+ //
+ // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
+ // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
+ android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
)
// The preparer to include if running a cc related test for fuchsia.
diff --git a/etc/prebuilt_etc_test.go b/etc/prebuilt_etc_test.go
index 6727e59..09f2e8c 100644
--- a/etc/prebuilt_etc_test.go
+++ b/etc/prebuilt_etc_test.go
@@ -103,7 +103,7 @@
`)
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
- result.AssertStringEquals("output file path", "foo.installed.conf", p.outputFilePath.Base())
+ android.AssertStringEquals(t, "output file path", "foo.installed.conf", p.outputFilePath.Base())
}
func TestPrebuiltEtcGlob(t *testing.T) {
@@ -120,10 +120,10 @@
`)
p := result.Module("my_foo", "android_arm64_armv8-a").(*PrebuiltEtc)
- result.AssertStringEquals("my_foo output file path", "my_foo", p.outputFilePath.Base())
+ android.AssertStringEquals(t, "my_foo output file path", "my_foo", p.outputFilePath.Base())
p = result.Module("my_bar", "android_arm64_armv8-a").(*PrebuiltEtc)
- result.AssertStringEquals("my_bar output file path", "bar.conf", p.outputFilePath.Base())
+ android.AssertStringEquals(t, "my_bar output file path", "bar.conf", p.outputFilePath.Base())
}
func TestPrebuiltEtcAndroidMk(t *testing.T) {
@@ -153,7 +153,7 @@
entries := android.AndroidMkEntriesForTest(t, result.TestContext, mod)[0]
for k, expectedValue := range expected {
if value, ok := entries.EntryMap[k]; ok {
- result.AssertDeepEquals(k, expectedValue, value)
+ android.AssertDeepEquals(t, k, expectedValue, value)
} else {
t.Errorf("No %s defined, saw %q", k, entries.EntryMap)
}
@@ -171,7 +171,7 @@
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
expected := buildDir + "/target/product/test_device/system/etc/bar"
- result.AssertStringEquals("install dir", expected, p.installDirPath.String())
+ android.AssertStringEquals(t, "install dir", expected, p.installDirPath.String())
}
func TestPrebuiltEtcCannotSetRelativeInstallPathAndSubDir(t *testing.T) {
@@ -213,7 +213,7 @@
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
expected := buildDir + "/target/product/test_device/system/usr/share/bar"
- result.AssertStringEquals("install dir", expected, p.installDirPath.String())
+ android.AssertStringEquals(t, "install dir", expected, p.installDirPath.String())
}
func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) {
@@ -228,7 +228,7 @@
buildOS := android.BuildOs.String()
p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc)
expected := filepath.Join(buildDir, "host", result.Config.PrebuiltOS(), "usr", "share", "bar")
- result.AssertStringEquals("install dir", expected, p.installDirPath.String())
+ android.AssertStringEquals(t, "install dir", expected, p.installDirPath.String())
}
func TestPrebuiltFontInstallDirPath(t *testing.T) {
@@ -241,7 +241,7 @@
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
expected := buildDir + "/target/product/test_device/system/fonts"
- result.AssertStringEquals("install dir", expected, p.installDirPath.String())
+ android.AssertStringEquals(t, "install dir", expected, p.installDirPath.String())
}
func TestPrebuiltFirmwareDirPath(t *testing.T) {
@@ -273,7 +273,7 @@
t.Run(tt.description, func(t *testing.T) {
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, tt.config)
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
- result.AssertStringEquals("install dir", tt.expectedPath, p.installDirPath.String())
+ android.AssertStringEquals(t, "install dir", tt.expectedPath, p.installDirPath.String())
})
}
}
@@ -307,7 +307,7 @@
t.Run(tt.description, func(t *testing.T) {
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, tt.config)
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
- result.AssertStringEquals("install dir", tt.expectedPath, p.installDirPath.String())
+ android.AssertStringEquals(t, "install dir", tt.expectedPath, p.installDirPath.String())
})
}
}
diff --git a/filesystem/bootimg.go b/filesystem/bootimg.go
index 8e2c554..876e189 100644
--- a/filesystem/bootimg.go
+++ b/filesystem/bootimg.go
@@ -153,7 +153,7 @@
if vendor {
flag = "--vendor_cmdline "
}
- cmd.FlagWithArg(flag, "\""+proptools.ShellEscape(cmdline)+"\"")
+ cmd.FlagWithArg(flag, proptools.ShellEscapeIncludingSpaces(cmdline))
}
headerVersion := proptools.String(b.properties.Header_version)
diff --git a/genrule/genrule_test.go b/genrule/genrule_test.go
index 0873704..690277c 100644
--- a/genrule/genrule_test.go
+++ b/genrule/genrule_test.go
@@ -477,7 +477,7 @@
}
gen := result.Module("gen", "").(*Module)
- result.AssertStringEquals("raw commands", test.expect, gen.rawCommands[0])
+ android.AssertStringEquals(t, "raw commands", test.expect, gen.rawCommands[0])
})
}
}
@@ -541,12 +541,11 @@
for _, test := range testcases {
t.Run(test.name, func(t *testing.T) {
- subResult := result.ResultForSubTest(t)
- gen := subResult.ModuleForTests(test.name, "")
+ gen := result.ModuleForTests(test.name, "")
manifest := android.RuleBuilderSboxProtoForTests(t, gen.Output("genrule.sbox.textproto"))
hash := manifest.Commands[0].GetInputHash()
- subResult.AssertStringEquals("hash", test.expectedHash, hash)
+ android.AssertStringEquals(t, "hash", test.expectedHash, hash)
})
}
}
@@ -615,11 +614,11 @@
}
gen := result.Module("gen", "").(*Module)
- result.AssertDeepEquals("cmd", test.cmds, gen.rawCommands)
+ android.AssertDeepEquals(t, "cmd", test.cmds, gen.rawCommands)
- result.AssertDeepEquals("deps", test.deps, gen.outputDeps.Strings())
+ android.AssertDeepEquals(t, "deps", test.deps, gen.outputDeps.Strings())
- result.AssertDeepEquals("files", test.files, gen.outputFiles.Strings())
+ android.AssertDeepEquals(t, "files", test.files, gen.outputFiles.Strings())
})
}
}
@@ -648,10 +647,10 @@
gen := result.Module("gen", "").(*Module)
expectedCmd := "cp in1 __SBOX_SANDBOX_DIR__/out/out"
- result.AssertStringEquals("cmd", expectedCmd, gen.rawCommands[0])
+ android.AssertStringEquals(t, "cmd", expectedCmd, gen.rawCommands[0])
expectedSrcs := []string{"in1"}
- result.AssertDeepEquals("srcs", expectedSrcs, gen.properties.Srcs)
+ android.AssertDeepEquals(t, "srcs", expectedSrcs, gen.properties.Srcs)
}
func TestGenruleWithBazel(t *testing.T) {
@@ -673,8 +672,8 @@
expectedOutputFiles := []string{"outputbase/execroot/__main__/bazelone.txt",
"outputbase/execroot/__main__/bazeltwo.txt"}
- result.AssertDeepEquals("output files", expectedOutputFiles, gen.outputFiles.Strings())
- result.AssertDeepEquals("output deps", expectedOutputFiles, gen.outputDeps.Strings())
+ android.AssertDeepEquals(t, "output files", expectedOutputFiles, gen.outputFiles.Strings())
+ android.AssertDeepEquals(t, "output deps", expectedOutputFiles, gen.outputDeps.Strings())
}
type testTool struct {
diff --git a/java/app.go b/java/app.go
index e98fe31..eef627c 100755
--- a/java/app.go
+++ b/java/app.go
@@ -812,6 +812,13 @@
depsInfo := android.DepNameToDepInfoMap{}
a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
depName := to.Name()
+
+ // Skip dependencies that are only available to APEXes; they are developed with updatability
+ // in mind and don't need manual approval.
+ if to.(android.ApexModule).NotAvailableForPlatform() {
+ return true
+ }
+
if info, exist := depsInfo[depName]; exist {
info.From = append(info.From, from.Name())
info.IsExternal = info.IsExternal && externalDep
diff --git a/java/boot_image.go b/java/boot_image.go
index 8a1e3c9..12e2874 100644
--- a/java/boot_image.go
+++ b/java/boot_image.go
@@ -25,10 +25,18 @@
func init() {
RegisterBootImageBuildComponents(android.InitRegistrationContext)
+
+ android.RegisterSdkMemberType(&bootImageMemberType{
+ SdkMemberTypeBase: android.SdkMemberTypeBase{
+ PropertyName: "boot_images",
+ SupportsSdk: true,
+ },
+ })
}
func RegisterBootImageBuildComponents(ctx android.RegistrationContext) {
ctx.RegisterModuleType("boot_image", bootImageFactory)
+ ctx.RegisterModuleType("prebuilt_boot_image", prebuiltBootImageFactory)
}
type bootImageProperties struct {
@@ -41,7 +49,7 @@
type BootImageModule struct {
android.ModuleBase
android.ApexModuleBase
-
+ android.SdkBase
properties bootImageProperties
}
@@ -50,6 +58,7 @@
m.AddProperties(&m.properties)
android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
android.InitApexModule(m)
+ android.InitSdkAwareModule(m)
return m
}
@@ -138,3 +147,74 @@
// Make it available for other modules.
ctx.SetProvider(BootImageInfoProvider, info)
}
+
+type bootImageMemberType struct {
+ android.SdkMemberTypeBase
+}
+
+func (b *bootImageMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
+ mctx.AddVariationDependencies(nil, dependencyTag, names...)
+}
+
+func (b *bootImageMemberType) IsInstance(module android.Module) bool {
+ _, ok := module.(*BootImageModule)
+ return ok
+}
+
+func (b *bootImageMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
+ return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_boot_image")
+}
+
+func (b *bootImageMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
+ return &bootImageSdkMemberProperties{}
+}
+
+type bootImageSdkMemberProperties struct {
+ android.SdkMemberPropertiesBase
+
+ Image_name string
+}
+
+func (b *bootImageSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
+ module := variant.(*BootImageModule)
+
+ b.Image_name = module.properties.Image_name
+}
+
+func (b *bootImageSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
+ if b.Image_name != "" {
+ propertySet.AddProperty("image_name", b.Image_name)
+ }
+}
+
+var _ android.SdkMemberType = (*bootImageMemberType)(nil)
+
+// A prebuilt version of the boot image module.
+//
+// At the moment this is basically just a boot image module that can be used as a prebuilt.
+// Eventually as more functionality is migrated into the boot image module from the singleton then
+// this will diverge.
+type prebuiltBootImageModule struct {
+ BootImageModule
+ prebuilt android.Prebuilt
+}
+
+func (module *prebuiltBootImageModule) Prebuilt() *android.Prebuilt {
+ return &module.prebuilt
+}
+
+func (module *prebuiltBootImageModule) Name() string {
+ return module.prebuilt.Name(module.ModuleBase.Name())
+}
+
+func prebuiltBootImageFactory() android.Module {
+ m := &prebuiltBootImageModule{}
+ m.AddProperties(&m.properties)
+ android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
+ // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
+ // array.
+ android.InitPrebuiltModule(m, &[]string{"placeholder"})
+ android.InitApexModule(m)
+ android.InitSdkAwareModule(m)
+ return m
+}
diff --git a/java/boot_image_test.go b/java/boot_image_test.go
index a295782..65e590d 100644
--- a/java/boot_image_test.go
+++ b/java/boot_image_test.go
@@ -29,3 +29,12 @@
}
`)
}
+
+func TestUnknownPrebuiltBootImage(t *testing.T) {
+ testJavaError(t, "image_name: Unknown image name \\\"unknown\\\", expected one of art, boot", `
+ prebuilt_boot_image {
+ name: "unknown-boot-image",
+ image_name: "unknown",
+ }
+`)
+}
diff --git a/java/dexpreopt_bootjars_test.go b/java/dexpreopt_bootjars_test.go
index 48bc244..1b910fa 100644
--- a/java/dexpreopt_bootjars_test.go
+++ b/java/dexpreopt_bootjars_test.go
@@ -16,7 +16,6 @@
import (
"path/filepath"
- "reflect"
"sort"
"testing"
@@ -44,17 +43,11 @@
}
`
- config := testConfig(nil, bp, nil)
+ result := javaFixtureFactory.
+ Extend(dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar", "platform:baz")).
+ RunTestWithBp(t, bp)
- pathCtx := android.PathContextForTesting(config)
- dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)
- dexpreoptConfig.BootJars = android.CreateTestConfiguredJarList([]string{"platform:foo", "platform:bar", "platform:baz"})
- dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
-
- ctx := testContext(config)
- run(t, ctx, config)
-
- dexpreoptBootJars := ctx.SingletonForTests("dex_bootjars")
+ dexpreoptBootJars := result.SingletonForTests("dex_bootjars")
rule := dexpreoptBootJars.Output(ruleFile)
for i := range expectedInputs {
@@ -73,13 +66,9 @@
sort.Strings(outputs)
sort.Strings(expectedOutputs)
- if !reflect.DeepEqual(inputs, expectedInputs) {
- t.Errorf("want inputs %q\n got inputs %q", expectedInputs, inputs)
- }
+ android.AssertDeepEquals(t, "inputs", expectedInputs, inputs)
- if !reflect.DeepEqual(outputs, expectedOutputs) {
- t.Errorf("want outputs %q\n got outputs %q", expectedOutputs, outputs)
- }
+ android.AssertDeepEquals(t, "outputs", expectedOutputs, outputs)
}
func TestDexpreoptBootJars(t *testing.T) {
diff --git a/java/java.go b/java/java.go
index 9e35835..036c7af 100644
--- a/java/java.go
+++ b/java/java.go
@@ -122,7 +122,16 @@
if sdkVersion.stable() {
return nil
}
- return fmt.Errorf("non stable SDK %v", sdkVersion)
+ if sdkVersion.kind == sdkCorePlatform {
+ if useLegacyCorePlatformApiByName(j.BaseModuleName()) {
+ return fmt.Errorf("non stable SDK %v - uses legacy core platform", sdkVersion)
+ } else {
+ // Treat stable core platform as stable.
+ return nil
+ }
+ } else {
+ return fmt.Errorf("non stable SDK %v", sdkVersion)
+ }
}
func (j *Module) checkSdkVersions(ctx android.ModuleContext) {
@@ -2499,7 +2508,7 @@
func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if j.testProperties.Test_options.Unit_test == nil && ctx.Host() {
// TODO(b/): Clean temporary heuristic to avoid unexpected onboarding.
- defaultUnitTest := !inList("tradefed", j.properties.Static_libs) && !inList("tradefed", j.properties.Libs) && !inList("cts", j.testProperties.Test_suites) && !inList("robolectric-host-android_all", j.properties.Static_libs) && !inList("robolectric-host-android_all", j.properties.Libs)
+ defaultUnitTest := !inList("tradefed", j.properties.Static_libs) && !inList("tradefed", j.properties.Libs) && !inList("cts", j.testProperties.Test_suites)
j.testProperties.Test_options.Unit_test = proptools.BoolPtr(defaultUnitTest)
}
j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template,
@@ -3319,10 +3328,6 @@
// ],
// javacflags: ["-Xlint:all"],
// }
-func defaultsFactory() android.Module {
- return DefaultsFactory()
-}
-
func DefaultsFactory() android.Module {
module := &Defaults{}
diff --git a/java/legacy_core_platform_api_usage.go b/java/legacy_core_platform_api_usage.go
index 874338d..cae9dc5 100644
--- a/java/legacy_core_platform_api_usage.go
+++ b/java/legacy_core_platform_api_usage.go
@@ -108,7 +108,7 @@
"PrintSpooler",
"RollbackTest",
"service-blobstore",
- "service-connectivity",
+ "service-connectivity-pre-jarjar",
"service-jobscheduler",
"services",
"services.accessibility",
@@ -160,7 +160,11 @@
}
func useLegacyCorePlatformApi(ctx android.EarlyModuleContext) bool {
- _, found := legacyCorePlatformApiLookup[ctx.ModuleName()]
+ return useLegacyCorePlatformApiByName(ctx.ModuleName())
+}
+
+func useLegacyCorePlatformApiByName(name string) bool {
+ _, found := legacyCorePlatformApiLookup[name]
return found
}
diff --git a/java/system_modules_test.go b/java/system_modules_test.go
index 44049ee..3d9f398 100644
--- a/java/system_modules_test.go
+++ b/java/system_modules_test.go
@@ -20,7 +20,7 @@
"android/soong/android"
)
-func normalizedPathsToHeaderJars(result *android.TestResult, moduleNames ...string) []string {
+func getModuleHeaderJarsAsNormalizedPaths(result *android.TestResult, moduleNames ...string) []string {
paths := []string{}
for _, moduleName := range moduleNames {
module := result.Module(moduleName, "android_common")
@@ -57,8 +57,8 @@
sourceInputs := sourceSystemModules.Rule("jarsTosystemModules").Inputs
// The expected paths are the header jars from the source input modules.
- expectedSourcePaths := normalizedPathsToHeaderJars(result, "system-module1", "system-module2")
- result.AssertArrayString("source system modules inputs", expectedSourcePaths, result.NormalizePathsForTesting(sourceInputs))
+ expectedSourcePaths := getModuleHeaderJarsAsNormalizedPaths(result, "system-module1", "system-module2")
+ android.AssertArrayString(t, "source system modules inputs", expectedSourcePaths, result.NormalizePathsForTesting(sourceInputs))
}
var addPrebuiltSystemModules = android.FixtureAddTextFile("prebuilts/Android.bp", `
@@ -84,8 +84,8 @@
prebuiltInputs := prebuiltSystemModules.Rule("jarsTosystemModules").Inputs
// The expected paths are the header jars from the renamed prebuilt input modules.
- expectedPrebuiltPaths := normalizedPathsToHeaderJars(result, "system-module1", "system-module2")
- result.AssertArrayString("renamed prebuilt system modules inputs", expectedPrebuiltPaths, result.NormalizePathsForTesting(prebuiltInputs))
+ expectedPrebuiltPaths := getModuleHeaderJarsAsNormalizedPaths(result, "system-module1", "system-module2")
+ android.AssertArrayString(t, "renamed prebuilt system modules inputs", expectedPrebuiltPaths, result.NormalizePathsForTesting(prebuiltInputs))
}
func TestJavaSystemModulesMixSourceAndPrebuilt(t *testing.T) {
@@ -99,14 +99,14 @@
sourceInputs := sourceSystemModules.Rule("jarsTosystemModules").Inputs
// The expected paths are the header jars from the source input modules.
- expectedSourcePaths := normalizedPathsToHeaderJars(result, "system-module1", "system-module2")
- result.AssertArrayString("source system modules inputs", expectedSourcePaths, result.NormalizePathsForTesting(sourceInputs))
+ expectedSourcePaths := getModuleHeaderJarsAsNormalizedPaths(result, "system-module1", "system-module2")
+ android.AssertArrayString(t, "source system modules inputs", expectedSourcePaths, result.NormalizePathsForTesting(sourceInputs))
// check the existence of the renamed prebuilt module
prebuiltSystemModules := result.ModuleForTests("prebuilt_system-modules", "android_common")
prebuiltInputs := prebuiltSystemModules.Rule("jarsTosystemModules").Inputs
// The expected paths are the header jars from the renamed prebuilt input modules.
- expectedPrebuiltPaths := normalizedPathsToHeaderJars(result, "prebuilt_system-module1", "prebuilt_system-module2")
- result.AssertArrayString("prebuilt system modules inputs", expectedPrebuiltPaths, result.NormalizePathsForTesting(prebuiltInputs))
+ expectedPrebuiltPaths := getModuleHeaderJarsAsNormalizedPaths(result, "prebuilt_system-module1", "prebuilt_system-module2")
+ android.AssertArrayString(t, "prebuilt system modules inputs", expectedPrebuiltPaths, result.NormalizePathsForTesting(prebuiltInputs))
}
diff --git a/rust/builder.go b/rust/builder.go
index 6326124..9d462d4 100644
--- a/rust/builder.go
+++ b/rust/builder.go
@@ -194,8 +194,7 @@
}
if len(deps.SrcDeps) > 0 {
- genSubDir := "out/"
- moduleGenDir := android.PathForModuleOut(ctx, genSubDir)
+ moduleGenDir := ctx.RustModule().compiler.CargoOutDir()
var outputs android.WritablePaths
for _, genSrc := range deps.SrcDeps {
@@ -208,7 +207,7 @@
ctx.Build(pctx, android.BuildParams{
Rule: cp,
- Description: "cp " + moduleGenDir.Rel(),
+ Description: "cp " + moduleGenDir.Path().Rel(),
Outputs: outputs,
Inputs: deps.SrcDeps,
Args: map[string]string{
diff --git a/rust/compiler.go b/rust/compiler.go
index c26f208..98ad7ad 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -60,6 +60,7 @@
InstallInData = iota
incorrectSourcesError = "srcs can only contain one path for a rust file and source providers prefixed by \":\""
+ genSubDir = "out/"
)
type BaseCompilerProperties struct {
@@ -154,6 +155,10 @@
distFile android.OptionalPath
// Stripped output file. If Valid(), this file will be installed instead of outputFile.
strippedOutputFile android.OptionalPath
+
+ // If a crate has a source-generated dependency, a copy of the source file
+ // will be available in cargoOutDir (equivalent to Cargo OUT_DIR).
+ cargoOutDir android.ModuleOutPath
}
func (compiler *baseCompiler) Disabled() bool {
@@ -243,6 +248,14 @@
panic(fmt.Errorf("baseCrater doesn't know how to crate things!"))
}
+func (compiler *baseCompiler) initialize(ctx ModuleContext) {
+ compiler.cargoOutDir = android.PathForModuleOut(ctx, genSubDir)
+}
+
+func (compiler *baseCompiler) CargoOutDir() android.OptionalPath {
+ return android.OptionalPathForPath(compiler.cargoOutDir)
+}
+
func (compiler *baseCompiler) isDependencyRoot() bool {
return false
}
diff --git a/rust/project_json.go b/rust/project_json.go
index 32ce6f4..8d3d250 100644
--- a/rust/project_json.go
+++ b/rust/project_json.go
@@ -45,11 +45,12 @@
}
type rustProjectCrate struct {
- DisplayName string `json:"display_name"`
- RootModule string `json:"root_module"`
- Edition string `json:"edition,omitempty"`
- Deps []rustProjectDep `json:"deps"`
- Cfgs []string `json:"cfgs"`
+ DisplayName string `json:"display_name"`
+ RootModule string `json:"root_module"`
+ Edition string `json:"edition,omitempty"`
+ Deps []rustProjectDep `json:"deps"`
+ Cfgs []string `json:"cfgs"`
+ Env map[string]string `json:"env"`
}
type rustProjectJson struct {
@@ -136,7 +137,7 @@
}
})
if !foundSource {
- fmt.Errorf("No valid source for source provider found: %v\n", rModule)
+ ctx.Errorf("No valid source for source provider found: %v\n", rModule)
}
return sourceSrc, foundSource
}
@@ -220,7 +221,7 @@
func (singleton *projectGeneratorSingleton) addCrate(ctx android.SingletonContext, rModule *Module, comp *baseCompiler) (int, bool) {
rootModule, ok := crateSource(ctx, rModule, comp)
if !ok {
- fmt.Errorf("Unable to find source for valid module: %v", rModule)
+ ctx.Errorf("Unable to find source for valid module: %v", rModule)
return 0, false
}
@@ -230,6 +231,11 @@
Edition: comp.edition(),
Deps: make([]rustProjectDep, 0),
Cfgs: make([]string, 0),
+ Env: make(map[string]string),
+ }
+
+ if comp.CargoOutDir().Valid() {
+ crate.Env["OUT_DIR"] = comp.CargoOutDir().String()
}
deps := make(map[string]int)
diff --git a/rust/project_json_test.go b/rust/project_json_test.go
index ba66215..289bcb8 100644
--- a/rust/project_json_test.go
+++ b/rust/project_json_test.go
@@ -190,8 +190,8 @@
}
}
}
- // Check that liba depends on libbindings1
if strings.Contains(rootModule, "d/src/lib.rs") {
+ // Check that libd depends on libbindings1
found := false
for _, depName := range validateDependencies(t, crate) {
if depName == "bindings1" {
@@ -200,8 +200,17 @@
}
}
if !found {
- t.Errorf("liba does not depend on libbindings1: %v", crate)
+ t.Errorf("libd does not depend on libbindings1: %v", crate)
}
+ // Check that OUT_DIR is populated.
+ env, ok := crate["env"].(map[string]interface{})
+ if !ok {
+ t.Errorf("libd does not have its environment variables set: %v", crate)
+ }
+ if _, ok = env["OUT_DIR"]; !ok {
+ t.Errorf("libd does not have its OUT_DIR set: %v", env)
+ }
+
}
}
}
diff --git a/rust/rust.go b/rust/rust.go
index dc23abb..8ebdb72 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -320,12 +320,16 @@
}
type compiler interface {
+ initialize(ctx ModuleContext)
compilerFlags(ctx ModuleContext, flags Flags) Flags
compilerProps() []interface{}
compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path
compilerDeps(ctx DepsContext, deps Deps) Deps
crateName() string
+ // Output directory in which source-generated code from dependencies is
+ // copied. This is equivalent to Cargo's OUT_DIR variable.
+ CargoOutDir() android.OptionalPath
inData() bool
install(ctx ModuleContext)
relativeInstallPath() string
@@ -711,6 +715,7 @@
}
if mod.compiler != nil && !mod.compiler.Disabled() {
+ mod.compiler.initialize(ctx)
outputFile := mod.compiler.compile(ctx, flags, deps)
mod.outputFile = android.OptionalPathForPath(outputFile)
diff --git a/sdk/Android.bp b/sdk/Android.bp
index 8a3119c..6e49c6d 100644
--- a/sdk/Android.bp
+++ b/sdk/Android.bp
@@ -20,6 +20,7 @@
"update.go",
],
testSrcs: [
+ "boot_image_sdk_test.go",
"bp_test.go",
"cc_sdk_test.go",
"exports_test.go",
diff --git a/sdk/boot_image_sdk_test.go b/sdk/boot_image_sdk_test.go
new file mode 100644
index 0000000..9805a6a
--- /dev/null
+++ b/sdk/boot_image_sdk_test.go
@@ -0,0 +1,62 @@
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package sdk
+
+import "testing"
+
+func TestSnapshotWithBootImage(t *testing.T) {
+ result := testSdkWithJava(t, `
+ sdk {
+ name: "mysdk",
+ boot_images: ["mybootimage"],
+ }
+
+ boot_image {
+ name: "mybootimage",
+ image_name: "art",
+ }
+ `)
+
+ CheckSnapshot(t, result, "mysdk", "",
+ checkUnversionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+prebuilt_boot_image {
+ name: "mybootimage",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
+ image_name: "art",
+}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+prebuilt_boot_image {
+ name: "mysdk_mybootimage@current",
+ sdk_member_name: "mybootimage",
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
+ image_name: "art",
+}
+
+sdk_snapshot {
+ name: "mysdk@current",
+ visibility: ["//visibility:public"],
+ boot_images: ["mysdk_mybootimage@current"],
+}
+`),
+ checkAllCopyRules(""))
+}
diff --git a/sdk/bp_test.go b/sdk/bp_test.go
index a7164a5..2bd8a43 100644
--- a/sdk/bp_test.go
+++ b/sdk/bp_test.go
@@ -54,26 +54,25 @@
return str
}
-func checkPropertySetFixture(h android.TestHelper, val interface{}, hasTags bool) {
+func checkPropertySetFixture(t *testing.T, val interface{}, hasTags bool) {
set := val.(*bpPropertySet)
- h.AssertDeepEquals("wrong x value", "taxi", set.getValue("x"))
- h.AssertDeepEquals("wrong y value", 1729, set.getValue("y"))
+ android.AssertDeepEquals(t, "wrong x value", "taxi", set.getValue("x"))
+ android.AssertDeepEquals(t, "wrong y value", 1729, set.getValue("y"))
subset := set.getValue("sub").(*bpPropertySet)
- h.AssertDeepEquals("wrong sub.x value", "taxi", subset.getValue("x"))
- h.AssertDeepEquals("wrong sub.y value", 1729, subset.getValue("y"))
+ android.AssertDeepEquals(t, "wrong sub.x value", "taxi", subset.getValue("x"))
+ android.AssertDeepEquals(t, "wrong sub.y value", 1729, subset.getValue("y"))
if hasTags {
- h.AssertDeepEquals("wrong y tag", "tag_y", set.getTag("y"))
- h.AssertDeepEquals("wrong sub.x tag", "tag_x", subset.getTag("x"))
+ android.AssertDeepEquals(t, "wrong y tag", "tag_y", set.getTag("y"))
+ android.AssertDeepEquals(t, "wrong sub.x tag", "tag_x", subset.getTag("x"))
} else {
- h.AssertDeepEquals("wrong y tag", nil, set.getTag("y"))
- h.AssertDeepEquals("wrong sub.x tag", nil, subset.getTag("x"))
+ android.AssertDeepEquals(t, "wrong y tag", nil, set.getTag("y"))
+ android.AssertDeepEquals(t, "wrong sub.x tag", nil, subset.getTag("x"))
}
}
func TestAddPropertySimple(t *testing.T) {
- h := android.TestHelper{t}
set := newPropertySet()
for name, val := range map[string]interface{}{
"x": "taxi",
@@ -83,16 +82,15 @@
"arr": []string{"a", "b", "c"},
} {
set.AddProperty(name, val)
- h.AssertDeepEquals("wrong value", val, set.getValue(name))
+ android.AssertDeepEquals(t, "wrong value", val, set.getValue(name))
}
- h.AssertPanic("adding x again should panic",
+ android.AssertPanic(t, "adding x again should panic",
func() { set.AddProperty("x", "taxi") })
- h.AssertPanic("adding arr again should panic",
+ android.AssertPanic(t, "adding arr again should panic",
func() { set.AddProperty("arr", []string{"d"}) })
}
func TestAddPropertySubset(t *testing.T) {
- h := android.TestHelper{t}
getFixtureMap := map[string]func() interface{}{
"property set": propertySetFixture,
"property struct": propertyStructFixture,
@@ -103,8 +101,8 @@
t.Run(name, func(t *testing.T) {
set := propertySetFixture().(*bpPropertySet)
set.AddProperty("new", getFixture())
- checkPropertySetFixture(h, set, true)
- checkPropertySetFixture(h, set.getValue("new"), name == "property set")
+ checkPropertySetFixture(t, set, true)
+ checkPropertySetFixture(t, set.getValue("new"), name == "property set")
})
}
})
@@ -118,40 +116,38 @@
subset.AddPropertySet("sub")
set.AddProperty("sub", getFixture())
merged := set.getValue("sub").(*bpPropertySet)
- h.AssertDeepEquals("wrong flag value", false, merged.getValue("flag"))
- checkPropertySetFixture(h, merged, name == "property set")
+ android.AssertDeepEquals(t, "wrong flag value", false, merged.getValue("flag"))
+ checkPropertySetFixture(t, merged, name == "property set")
})
}
})
t.Run("add conflicting subset", func(t *testing.T) {
set := propertySetFixture().(*bpPropertySet)
- h.AssertPanic("adding x again should panic",
+ android.AssertPanic(t, "adding x again should panic",
func() { set.AddProperty("x", propertySetFixture()) })
})
t.Run("add non-pointer struct", func(t *testing.T) {
set := propertySetFixture().(*bpPropertySet)
str := propertyStructFixture().(*propertyStruct)
- h.AssertPanic("adding a non-pointer struct should panic",
+ android.AssertPanic(t, "adding a non-pointer struct should panic",
func() { set.AddProperty("new", *str) })
})
}
func TestAddPropertySetNew(t *testing.T) {
- h := android.TestHelper{t}
set := newPropertySet()
subset := set.AddPropertySet("sub")
subset.AddProperty("new", "d^^b")
- h.AssertDeepEquals("wrong sub.new value", "d^^b", set.getValue("sub").(*bpPropertySet).getValue("new"))
+ android.AssertDeepEquals(t, "wrong sub.new value", "d^^b", set.getValue("sub").(*bpPropertySet).getValue("new"))
}
func TestAddPropertySetExisting(t *testing.T) {
- h := android.TestHelper{t}
set := propertySetFixture().(*bpPropertySet)
subset := set.AddPropertySet("sub")
subset.AddProperty("new", "d^^b")
- h.AssertDeepEquals("wrong sub.new value", "d^^b", set.getValue("sub").(*bpPropertySet).getValue("new"))
+ android.AssertDeepEquals(t, "wrong sub.new value", "d^^b", set.getValue("sub").(*bpPropertySet).getValue("new"))
}
type removeFredTransformation struct {
@@ -180,9 +176,6 @@
}
func TestTransformRemoveProperty(t *testing.T) {
-
- helper := android.TestHelper{t}
-
set := newPropertySet()
set.AddProperty("name", "name")
set.AddProperty("fred", "12")
@@ -191,13 +184,10 @@
contents := &generatedContents{}
outputPropertySet(contents, set)
- helper.AssertTrimmedStringEquals("removing property failed", "name: \"name\",\n", contents.content.String())
+ android.AssertTrimmedStringEquals(t, "removing property failed", "name: \"name\",\n", contents.content.String())
}
func TestTransformRemovePropertySet(t *testing.T) {
-
- helper := android.TestHelper{t}
-
set := newPropertySet()
set.AddProperty("name", "name")
set.AddPropertySet("fred")
@@ -206,5 +196,5 @@
contents := &generatedContents{}
outputPropertySet(contents, set)
- helper.AssertTrimmedStringEquals("removing property set failed", "name: \"name\",\n", contents.content.String())
+ android.AssertTrimmedStringEquals(t, "removing property set failed", "name: \"name\",\n", contents.content.String())
}
diff --git a/sdk/cc_sdk_test.go b/sdk/cc_sdk_test.go
index 6da135a..a2539c9 100644
--- a/sdk/cc_sdk_test.go
+++ b/sdk/cc_sdk_test.go
@@ -21,7 +21,7 @@
"android/soong/cc"
)
-var ccTestFs = map[string][]byte{
+var ccTestFs = android.MockFS{
"Test.cpp": nil,
"myinclude/Test.h": nil,
"myinclude-android/AndroidTest.h": nil,
@@ -32,7 +32,7 @@
"some/where/stubslib.map.txt": nil,
}
-func testSdkWithCc(t *testing.T, bp string) *testSdkResult {
+func testSdkWithCc(t *testing.T, bp string) *android.TestResult {
t.Helper()
return testSdkWithFs(t, bp, ccTestFs)
}
@@ -101,7 +101,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -353,7 +353,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -440,7 +440,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkAllCopyRules(`
myinclude/Test.h -> include/myinclude/Test.h
.intermediates/mynativelib1/android_arm64_armv8-a_shared/mynativelib1.so -> arm64/lib/mynativelib1.so
@@ -486,7 +486,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -556,7 +556,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -615,7 +615,7 @@
}
`)
- CheckSnapshot(result, "mymodule_exports", "",
+ CheckSnapshot(t, result, "mymodule_exports", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -700,7 +700,7 @@
}
`)
- CheckSnapshot(result, "myexports", "",
+ CheckSnapshot(t, result, "myexports", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -808,7 +808,15 @@
}
func TestSnapshotWithSingleHostOsType(t *testing.T) {
- ctx, config := testSdkContext(`
+ result := sdkFixtureFactory.Extend(
+ ccTestFs.AddToFixture(),
+ cc.PrepareForTestOnLinuxBionic,
+ android.FixtureModifyConfig(func(config android.Config) {
+ config.Targets[android.LinuxBionic] = []android.Target{
+ {android.LinuxBionic, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", "", false},
+ }
+ }),
+ ).RunTestWithBp(t, `
cc_defaults {
name: "mydefaults",
device_supported: false,
@@ -849,11 +857,9 @@
],
stl: "none",
}
- `, ccTestFs, []android.OsType{android.LinuxBionic})
+ `)
- result := runTests(t, ctx, config)
-
- CheckSnapshot(result, "myexports", "",
+ CheckSnapshot(t, result, "myexports", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -991,7 +997,7 @@
}
`)
- CheckSnapshot(result, "mymodule_exports", "",
+ CheckSnapshot(t, result, "mymodule_exports", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1099,7 +1105,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1200,7 +1206,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1297,7 +1303,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1424,7 +1430,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1552,7 +1558,7 @@
}
`)
- CheckSnapshot(result, "myexports", "",
+ CheckSnapshot(t, result, "myexports", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1615,7 +1621,7 @@
}
`)
- CheckSnapshot(result, "myexports", "",
+ CheckSnapshot(t, result, "myexports", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1729,7 +1735,7 @@
}
`)
- CheckSnapshot(result, "myexports", "",
+ CheckSnapshot(t, result, "myexports", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1843,7 +1849,7 @@
}
`)
- CheckSnapshot(result, "myexports", "",
+ CheckSnapshot(t, result, "myexports", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1940,7 +1946,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1978,7 +1984,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -2080,7 +2086,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -2112,7 +2118,6 @@
},
}
`),
- // Verifi
checkVersionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -2193,7 +2198,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -2266,7 +2271,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -2377,7 +2382,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -2430,7 +2435,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -2543,7 +2548,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -2658,7 +2663,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
diff --git a/sdk/exports_test.go b/sdk/exports_test.go
index 54a40d2..fd7741c 100644
--- a/sdk/exports_test.go
+++ b/sdk/exports_test.go
@@ -42,7 +42,7 @@
"package/Android.bp": []byte(packageBp),
})
- CheckSnapshot(result, "myexports", "package",
+ CheckSnapshot(t, result, "myexports", "package",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go
index ef8e4a0..f4e9380 100644
--- a/sdk/java_sdk_test.go
+++ b/sdk/java_sdk_test.go
@@ -17,10 +17,11 @@
import (
"testing"
+ "android/soong/android"
"android/soong/java"
)
-func testSdkWithJava(t *testing.T, bp string) *testSdkResult {
+func testSdkWithJava(t *testing.T, bp string) *android.TestResult {
t.Helper()
fs := map[string][]byte{
@@ -127,7 +128,7 @@
// Make sure that the mysdk module depends on "sdkmember" and not "prebuilt_sdkmember".
java.CheckModuleDependencies(t, result.TestContext, "mysdk", "android_common", []string{"sdkmember"})
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkAndroidBpContents(`// This is auto-generated. DO NOT EDIT.
java_import {
@@ -255,7 +256,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -312,7 +313,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -369,7 +370,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -440,7 +441,7 @@
}
`)
- CheckSnapshot(result, "myexports", "",
+ CheckSnapshot(t, result, "myexports", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -496,7 +497,7 @@
}
`)
- CheckSnapshot(result, "myexports", "",
+ CheckSnapshot(t, result, "myexports", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -551,7 +552,7 @@
}
`)
- CheckSnapshot(result, "myexports", "",
+ CheckSnapshot(t, result, "myexports", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -607,7 +608,7 @@
}
`)
- CheckSnapshot(result, "myexports", "",
+ CheckSnapshot(t, result, "myexports", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -662,7 +663,7 @@
}
`)
- CheckSnapshot(result, "myexports", "",
+ CheckSnapshot(t, result, "myexports", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -731,7 +732,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -827,7 +828,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -918,7 +919,7 @@
}
`)
- CheckSnapshot(result, "myexports", "",
+ CheckSnapshot(t, result, "myexports", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1032,7 +1033,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1133,7 +1134,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1202,7 +1203,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1274,7 +1275,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1367,7 +1368,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1475,7 +1476,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1563,7 +1564,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -1639,7 +1640,7 @@
}
`)
- CheckSnapshot(result, "mysdk", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go
index 65a9001..05d8bdb 100644
--- a/sdk/sdk_test.go
+++ b/sdk/sdk_test.go
@@ -169,7 +169,7 @@
"package/Android.bp": []byte(packageBp),
})
- CheckSnapshot(result, "mysdk", "package",
+ CheckSnapshot(t, result, "mysdk", "package",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -317,9 +317,8 @@
`
result := testSdkWithFs(t, sdk, nil)
- CheckSnapshot(result, "mysdk", "",
- checkAllOtherCopyRules(`.intermediates/mysdk/common_os/mysdk-current.zip -> mysdk-current.zip`),
- )
+ CheckSnapshot(t, result, "mysdk", "",
+ checkAllOtherCopyRules(`.intermediates/mysdk/common_os/mysdk-current.zip -> mysdk-current.zip`))
}
type EmbeddedPropertiesStruct struct {
@@ -387,12 +386,10 @@
extractor := newCommonValueExtractor(common)
- h := android.TestHelper{t}
-
err := extractor.extractCommonProperties(common, structs)
- h.AssertDeepEquals("unexpected error", nil, err)
+ android.AssertDeepEquals(t, "unexpected error", nil, err)
- h.AssertDeepEquals("common properties not correct",
+ android.AssertDeepEquals(t, "common properties not correct",
&testPropertiesStruct{
name: "common",
private: "",
@@ -410,7 +407,7 @@
},
common)
- h.AssertDeepEquals("updated properties[0] not correct",
+ android.AssertDeepEquals(t, "updated properties[0] not correct",
&testPropertiesStruct{
name: "struct-0",
private: "common",
@@ -428,7 +425,7 @@
},
structs[0])
- h.AssertDeepEquals("updated properties[1] not correct",
+ android.AssertDeepEquals(t, "updated properties[1] not correct",
&testPropertiesStruct{
name: "struct-1",
private: "common",
@@ -462,10 +459,8 @@
extractor := newCommonValueExtractor(common)
- h := android.TestHelper{t}
-
err := extractor.extractCommonProperties(common, structs)
- h.AssertErrorMessageEquals("unexpected error", `field "S_Common" is not tagged as "arch_variant" but has arch specific properties:
+ android.AssertErrorMessageEquals(t, "unexpected error", `field "S_Common" is not tagged as "arch_variant" but has arch specific properties:
"struct-0" has value "should-be-but-is-not-common0"
"struct-1" has value "should-be-but-is-not-common1"`, err)
}
diff --git a/sdk/testing.go b/sdk/testing.go
index 3fb27ca..a5519f8 100644
--- a/sdk/testing.go
+++ b/sdk/testing.go
@@ -29,10 +29,15 @@
"android/soong/java"
)
-func testSdkContext(bp string, fs map[string][]byte, extraOsTypes []android.OsType) (*android.TestContext, android.Config) {
- extraOsTypes = append(extraOsTypes, android.Android, android.Windows)
+var sdkFixtureFactory = android.NewFixtureFactory(
+ &buildDir,
+ apex.PrepareForTestWithApexBuildComponents,
+ cc.PrepareForTestWithCcDefaultModules,
+ genrule.PrepareForTestWithGenRuleBuildComponents,
+ java.PrepareForTestWithJavaBuildComponents,
+ PrepareForTestWithSdkBuildComponents,
- bp = bp + `
+ android.FixtureAddTextFile("sdk/tests/Android.bp", `
apex_key {
name: "myapex.key",
public_key: "myapex.avbpubkey",
@@ -43,9 +48,9 @@
name: "myapex.cert",
certificate: "myapex",
}
- ` + cc.GatherRequiredDepsForTest(extraOsTypes...)
+ `),
- mockFS := map[string][]byte{
+ android.FixtureMergeMockFs(map[string][]byte{
"build/make/target/product/security": nil,
"apex_manifest.json": nil,
"system/sepolicy/apex/myapex-file_contexts": nil,
@@ -55,113 +60,33 @@
"myapex.pem": nil,
"myapex.x509.pem": nil,
"myapex.pk8": nil,
- }
+ }),
- cc.GatherRequiredFilesForTest(mockFS)
-
- for k, v := range fs {
- mockFS[k] = v
- }
-
- config := android.TestArchConfig(buildDir, nil, bp, mockFS)
-
- // Add windows as a default disable OS to test behavior when some OS variants
- // are disabled.
- config.Targets[android.Windows] = []android.Target{
- {android.Windows, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", "", true},
- }
-
- for _, extraOsType := range extraOsTypes {
- switch extraOsType {
- case android.LinuxBionic:
- config.Targets[android.LinuxBionic] = []android.Target{
- {android.LinuxBionic, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", "", false},
- }
+ cc.PrepareForTestOnWindows,
+ android.FixtureModifyConfig(func(config android.Config) {
+ // Add windows as a default disable OS to test behavior when some OS variants
+ // are disabled.
+ config.Targets[android.Windows] = []android.Target{
+ {android.Windows, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", "", true},
}
- }
+ }),
+)
- ctx := android.NewTestArchContext(config)
+var PrepareForTestWithSdkBuildComponents = android.GroupFixturePreparers(
+ android.FixtureRegisterWithContext(registerModuleExportsBuildComponents),
+ android.FixtureRegisterWithContext(registerSdkBuildComponents),
+)
- // Enable androidmk support.
- // * Register the singleton
- // * Configure that we are inside make
- // * Add CommonOS to ensure that androidmk processing works.
- android.RegisterAndroidMkBuildComponents(ctx)
- android.SetKatiEnabledForTests(config)
- config.Targets[android.CommonOS] = []android.Target{
- {android.CommonOS, android.Arch{ArchType: android.Common}, android.NativeBridgeDisabled, "", "", true},
- }
-
- // from android package
- android.RegisterPackageBuildComponents(ctx)
- ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
- ctx.PreArchMutators(android.RegisterVisibilityRuleChecker)
- ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
- ctx.PreArchMutators(android.RegisterComponentsMutator)
-
- android.RegisterPrebuiltMutators(ctx)
-
- // Register these after the prebuilt mutators have been registered to match what
- // happens at runtime.
- ctx.PreArchMutators(android.RegisterVisibilityRuleGatherer)
- ctx.PostDepsMutators(android.RegisterVisibilityRuleEnforcer)
-
- // from java package
- java.RegisterRequiredBuildComponentsForTest(ctx)
-
- // from genrule package
- genrule.RegisterGenruleBuildComponents(ctx)
-
- // from cc package
- cc.RegisterRequiredBuildComponentsForTest(ctx)
-
- // from apex package
- ctx.RegisterModuleType("apex", apex.BundleFactory)
- ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
- ctx.PostDepsMutators(apex.RegisterPostDepsMutators)
-
- // from this package
- registerModuleExportsBuildComponents(ctx)
- registerSdkBuildComponents(ctx)
-
- ctx.Register()
-
- return ctx, config
-}
-
-func runTests(t *testing.T, ctx *android.TestContext, config android.Config) *testSdkResult {
+func testSdkWithFs(t *testing.T, bp string, fs android.MockFS) *android.TestResult {
t.Helper()
- _, errs := ctx.ParseBlueprintsFiles(".")
- android.FailIfErrored(t, errs)
- _, errs = ctx.PrepareBuildActions(config)
- android.FailIfErrored(t, errs)
- return &testSdkResult{
- TestHelper: android.TestHelper{T: t},
- TestContext: ctx,
- }
-}
-
-func testSdkWithFs(t *testing.T, bp string, fs map[string][]byte) *testSdkResult {
- t.Helper()
- ctx, config := testSdkContext(bp, fs, nil)
- return runTests(t, ctx, config)
+ return sdkFixtureFactory.RunTest(t, fs.AddToFixture(), android.FixtureWithRootAndroidBp(bp))
}
func testSdkError(t *testing.T, pattern, bp string) {
t.Helper()
- ctx, config := testSdkContext(bp, nil, nil)
- _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
- if len(errs) > 0 {
- android.FailIfNoMatchingErrors(t, pattern, errs)
- return
- }
- _, errs = ctx.PrepareBuildActions(config)
- if len(errs) > 0 {
- android.FailIfNoMatchingErrors(t, pattern, errs)
- return
- }
-
- t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
+ sdkFixtureFactory.
+ ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)).
+ RunTestWithBp(t, bp)
}
func ensureListContains(t *testing.T, result []string, expected string) {
@@ -179,23 +104,13 @@
return ret
}
-// Encapsulates result of processing an SDK definition. Provides support for
-// checking the state of the build structures.
-type testSdkResult struct {
- android.TestHelper
- *android.TestContext
-}
-
-func (result *testSdkResult) Module(name string, variant string) android.Module {
- return result.ModuleForTests(name, variant).Module()
-}
-
// Analyse the sdk build rules to extract information about what it is doing.
//
// e.g. find the src/dest pairs from each cp command, the various zip files
// generated, etc.
-func getSdkSnapshotBuildInfo(result *testSdkResult, sdk *sdk) *snapshotBuildInfo {
+func getSdkSnapshotBuildInfo(t *testing.T, result *android.TestResult, sdk *sdk) *snapshotBuildInfo {
info := &snapshotBuildInfo{
+ t: t,
r: result,
androidBpContents: sdk.GetAndroidBpContentsForTests(),
androidUnversionedBpContents: sdk.GetUnversionedAndroidBpContentsForTests(),
@@ -239,7 +154,7 @@
info.intermediateZip = info.outputZip
mergeInput := android.NormalizePathForTesting(bp.Input)
if info.intermediateZip != mergeInput {
- result.Errorf("Expected intermediate zip %s to be an input to merge zips but found %s instead",
+ t.Errorf("Expected intermediate zip %s to be an input to merge zips but found %s instead",
info.intermediateZip, mergeInput)
}
@@ -263,15 +178,15 @@
// Takes a list of functions which check different facets of the snapshot build rules.
// Allows each test to customize what is checked without duplicating lots of code
// or proliferating check methods of different flavors.
-func CheckSnapshot(result *testSdkResult, name string, dir string, checkers ...snapshotBuildInfoChecker) {
- result.Helper()
+func CheckSnapshot(t *testing.T, result *android.TestResult, name string, dir string, checkers ...snapshotBuildInfoChecker) {
+ t.Helper()
// The sdk CommonOS variant is always responsible for generating the snapshot.
variant := android.CommonOS.Name
sdk := result.Module(name, variant).(*sdk)
- snapshotBuildInfo := getSdkSnapshotBuildInfo(result, sdk)
+ snapshotBuildInfo := getSdkSnapshotBuildInfo(t, result, sdk)
// Check state of the snapshot build.
for _, checker := range checkers {
@@ -283,7 +198,7 @@
if dir != "" {
dir = filepath.Clean(dir) + "/"
}
- result.AssertStringEquals("Snapshot zip file in wrong place",
+ android.AssertStringEquals(t, "Snapshot zip file in wrong place",
fmt.Sprintf(".intermediates/%s%s/%s/%s-current.zip", dir, name, variant, name), actual)
// Populate a mock filesystem with the files that would have been copied by
@@ -294,7 +209,7 @@
}
// Process the generated bp file to make sure it is valid.
- testSdkWithFs(result.T, snapshotBuildInfo.androidBpContents, fs)
+ testSdkWithFs(t, snapshotBuildInfo.androidBpContents, fs)
}
type snapshotBuildInfoChecker func(info *snapshotBuildInfo)
@@ -304,8 +219,8 @@
// Both the expected and actual string are both trimmed before comparing.
func checkAndroidBpContents(expected string) snapshotBuildInfoChecker {
return func(info *snapshotBuildInfo) {
- info.r.Helper()
- info.r.AssertTrimmedStringEquals("Android.bp contents do not match", expected, info.androidBpContents)
+ info.t.Helper()
+ android.AssertTrimmedStringEquals(info.t, "Android.bp contents do not match", expected, info.androidBpContents)
}
}
@@ -316,8 +231,8 @@
// Both the expected and actual string are both trimmed before comparing.
func checkUnversionedAndroidBpContents(expected string) snapshotBuildInfoChecker {
return func(info *snapshotBuildInfo) {
- info.r.Helper()
- info.r.AssertTrimmedStringEquals("unversioned Android.bp contents do not match", expected, info.androidUnversionedBpContents)
+ info.t.Helper()
+ android.AssertTrimmedStringEquals(info.t, "unversioned Android.bp contents do not match", expected, info.androidUnversionedBpContents)
}
}
@@ -331,8 +246,8 @@
// Both the expected and actual string are both trimmed before comparing.
func checkVersionedAndroidBpContents(expected string) snapshotBuildInfoChecker {
return func(info *snapshotBuildInfo) {
- info.r.Helper()
- info.r.AssertTrimmedStringEquals("versioned Android.bp contents do not match", expected, info.androidVersionedBpContents)
+ info.t.Helper()
+ android.AssertTrimmedStringEquals(info.t, "versioned Android.bp contents do not match", expected, info.androidVersionedBpContents)
}
}
@@ -343,27 +258,27 @@
// before comparing.
func checkAllCopyRules(expected string) snapshotBuildInfoChecker {
return func(info *snapshotBuildInfo) {
- info.r.Helper()
- info.r.AssertTrimmedStringEquals("Incorrect copy rules", expected, info.copyRules)
+ info.t.Helper()
+ android.AssertTrimmedStringEquals(info.t, "Incorrect copy rules", expected, info.copyRules)
}
}
func checkAllOtherCopyRules(expected string) snapshotBuildInfoChecker {
return func(info *snapshotBuildInfo) {
- info.r.Helper()
- info.r.AssertTrimmedStringEquals("Incorrect copy rules", expected, info.otherCopyRules)
+ info.t.Helper()
+ android.AssertTrimmedStringEquals(info.t, "Incorrect copy rules", expected, info.otherCopyRules)
}
}
// Check that the specified paths match the list of zips to merge with the intermediate zip.
func checkMergeZips(expected ...string) snapshotBuildInfoChecker {
return func(info *snapshotBuildInfo) {
- info.r.Helper()
+ info.t.Helper()
if info.intermediateZip == "" {
- info.r.Errorf("No intermediate zip file was created")
+ info.t.Errorf("No intermediate zip file was created")
}
- info.r.AssertDeepEquals("mismatching merge zip files", expected, info.mergeZips)
+ android.AssertDeepEquals(info.t, "mismatching merge zip files", expected, info.mergeZips)
}
}
@@ -373,7 +288,10 @@
// All source/input paths are relative either the build directory. All dest/output paths are
// relative to the snapshot root directory.
type snapshotBuildInfo struct {
- r *testSdkResult
+ t *testing.T
+
+ // The result from RunTest()
+ r *android.TestResult
// The contents of the generated Android.bp file
androidBpContents string