Merge "Added write only sanitizer for ASAN and HWASAN"
diff --git a/OWNERS b/OWNERS
index dbb491d..8355d10 100644
--- a/OWNERS
+++ b/OWNERS
@@ -6,9 +6,8 @@
per-file * = patricearruda@google.com
per-file * = paulduffin@google.com
-per-file ndk_*.go, *gen_stub_libs.py = danalbert@google.com
+per-file ndk_*.go = danalbert@google.com
per-file clang.go,global.go = srhines@google.com, chh@google.com, pirama@google.com, yikong@google.com
per-file tidy.go = srhines@google.com, chh@google.com
per-file lto.go,pgo.go = srhines@google.com, pirama@google.com, yikong@google.com
per-file docs/map_files.md = danalbert@google.com, enh@google.com, jiyong@google.com
-per-file *ndk_api_coverage_parser.py = sophiez@google.com
\ No newline at end of file
diff --git a/android/Android.bp b/android/Android.bp
index 487372b..50faa44 100644
--- a/android/Android.bp
+++ b/android/Android.bp
@@ -19,10 +19,12 @@
"csuite_config.go",
"defaults.go",
"defs.go",
+ "depset.go",
"expand.go",
"filegroup.go",
"hooks.go",
"image.go",
+ "makefile_goal.go",
"makevars.go",
"metrics.go",
"module.go",
@@ -45,6 +47,7 @@
"sdk.go",
"singleton.go",
"soong_config_modules.go",
+ "test_suites.go",
"testing.go",
"util.go",
"variable.go",
@@ -61,6 +64,7 @@
"arch_test.go",
"config_test.go",
"csuite_config_test.go",
+ "depset_test.go",
"expand_test.go",
"module_test.go",
"mutator_test.go",
diff --git a/android/androidmk.go b/android/androidmk.go
index 045cb59..7e86140 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -107,6 +107,45 @@
a.EntryMap[name] = []string{path.String()}
}
+func (a *AndroidMkEntries) SetOptionalPath(name string, path OptionalPath) {
+ if path.Valid() {
+ a.SetPath(name, path.Path())
+ }
+}
+
+func (a *AndroidMkEntries) AddPath(name string, path Path) {
+ if _, ok := a.EntryMap[name]; !ok {
+ a.entryOrder = append(a.entryOrder, name)
+ }
+ a.EntryMap[name] = append(a.EntryMap[name], path.String())
+}
+
+func (a *AndroidMkEntries) AddOptionalPath(name string, path OptionalPath) {
+ if path.Valid() {
+ a.AddPath(name, path.Path())
+ }
+}
+
+func (a *AndroidMkEntries) SetPaths(name string, paths Paths) {
+ if _, ok := a.EntryMap[name]; !ok {
+ a.entryOrder = append(a.entryOrder, name)
+ }
+ a.EntryMap[name] = paths.Strings()
+}
+
+func (a *AndroidMkEntries) SetOptionalPaths(name string, paths Paths) {
+ if len(paths) > 0 {
+ a.SetPaths(name, paths)
+ }
+}
+
+func (a *AndroidMkEntries) AddPaths(name string, paths Paths) {
+ if _, ok := a.EntryMap[name]; !ok {
+ a.entryOrder = append(a.entryOrder, name)
+ }
+ a.EntryMap[name] = append(a.EntryMap[name], paths.Strings()...)
+}
+
func (a *AndroidMkEntries) SetBoolIfTrue(name string, flag bool) {
if flag {
if _, ok := a.EntryMap[name]; !ok {
@@ -146,7 +185,7 @@
var ret []string
availableTaggedDists := TaggedDistFiles{}
- if a.DistFiles != nil && len(a.DistFiles[""]) > 0 {
+ if a.DistFiles != nil {
availableTaggedDists = a.DistFiles
} else if a.OutputFile.Valid() {
availableTaggedDists = MakeDefaultDistFiles(a.OutputFile.Path())
diff --git a/android/androidmk_test.go b/android/androidmk_test.go
index 250f086..a558f45 100644
--- a/android/androidmk_test.go
+++ b/android/androidmk_test.go
@@ -45,6 +45,8 @@
return PathsForTesting("one.out"), nil
case ".multiple":
return PathsForTesting("two.out", "three/four.out"), nil
+ case ".another-tag":
+ return PathsForTesting("another.out"), nil
default:
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
}
@@ -123,6 +125,38 @@
bp: `
custom {
name: "foo",
+ dist: {
+ targets: ["my_goal"],
+ tag: ".another-tag",
+ }
+ }
+ `,
+ expectedAndroidMkLines: []string{
+ ".PHONY: my_goal\n",
+ "$(call dist-for-goals,my_goal,another.out:another.out)\n",
+ },
+ },
+ {
+ bp: `
+ custom {
+ name: "foo",
+ dists: [
+ {
+ targets: ["my_goal"],
+ tag: ".another-tag",
+ },
+ ],
+ }
+ `,
+ expectedAndroidMkLines: []string{
+ ".PHONY: my_goal\n",
+ "$(call dist-for-goals,my_goal,another.out:another.out)\n",
+ },
+ },
+ {
+ bp: `
+ custom {
+ name: "foo",
dists: [
{
targets: ["my_goal"],
diff --git a/android/apex.go b/android/apex.go
index 47f07ca..cd84f8a 100644
--- a/android/apex.go
+++ b/android/apex.go
@@ -65,9 +65,9 @@
apexModuleBase() *ApexModuleBase
- // Marks that this module should be built for the specified APEXes.
+ // Marks that this module should be built for the specified APEX.
// Call this before apex.apexMutator is run.
- BuildForApexes(apexes []ApexInfo)
+ BuildForApex(apex ApexInfo)
// Returns the APEXes that this module will be built for
ApexVariations() []ApexInfo
@@ -96,7 +96,7 @@
IsInstallableToApex() bool
// Mutate this module into one or more variants each of which is built
- // for an APEX marked via BuildForApexes().
+ // for an APEX marked via BuildForApex().
CreateApexVariations(mctx BottomUpMutatorContext) []Module
// Tests if this module is available for the specified APEX or ":platform"
@@ -137,6 +137,7 @@
//
// "//apex_available:anyapex" is a pseudo APEX name that matches to any APEX.
// "//apex_available:platform" refers to non-APEX partitions like "system.img".
+ // "com.android.gki.*" matches any APEX module name with the prefix "com.android.gki.".
// Default is ["//apex_available:platform"].
Apex_available []string
@@ -178,18 +179,15 @@
return nil
}
-func (m *ApexModuleBase) BuildForApexes(apexes []ApexInfo) {
+func (m *ApexModuleBase) BuildForApex(apex ApexInfo) {
m.apexVariationsLock.Lock()
defer m.apexVariationsLock.Unlock()
-nextApex:
- for _, apex := range apexes {
- for _, v := range m.apexVariations {
- if v.ApexName == apex.ApexName {
- continue nextApex
- }
+ for _, v := range m.apexVariations {
+ if v.ApexName == apex.ApexName {
+ return
}
- m.apexVariations = append(m.apexVariations, apex)
}
+ m.apexVariations = append(m.apexVariations, apex)
}
func (m *ApexModuleBase) ApexVariations() []ApexInfo {
@@ -216,6 +214,7 @@
const (
AvailableToPlatform = "//apex_available:platform"
AvailableToAnyApex = "//apex_available:anyapex"
+ AvailableToGkiApex = "com.android.gki.*"
)
func CheckAvailableForApex(what string, apex_available []string) bool {
@@ -225,7 +224,8 @@
return what == AvailableToPlatform
}
return InList(what, apex_available) ||
- (what != AvailableToPlatform && InList(AvailableToAnyApex, apex_available))
+ (what != AvailableToPlatform && InList(AvailableToAnyApex, apex_available)) ||
+ (strings.HasPrefix(what, "com.android.gki.") && InList(AvailableToGkiApex, apex_available))
}
func (m *ApexModuleBase) AvailableFor(what string) bool {
@@ -259,7 +259,7 @@
func (m *ApexModuleBase) checkApexAvailableProperty(mctx BaseModuleContext) {
for _, n := range m.ApexProperties.Apex_available {
- if n == AvailableToPlatform || n == AvailableToAnyApex {
+ if n == AvailableToPlatform || n == AvailableToAnyApex || n == AvailableToGkiApex {
continue
}
if !mctx.OtherModuleExists(n) && !mctx.Config().AllowMissingDependencies() {
@@ -327,17 +327,15 @@
// depended on by the specified APEXes. Directly depending means that a module
// is explicitly listed in the build definition of the APEX via properties like
// native_shared_libs, java_libs, etc.
-func UpdateApexDependency(apexes []ApexInfo, moduleName string, directDep bool) {
+func UpdateApexDependency(apex ApexInfo, moduleName string, directDep bool) {
apexNamesMapMutex.Lock()
defer apexNamesMapMutex.Unlock()
- for _, apex := range apexes {
- apexesForModule, ok := apexNamesMap()[moduleName]
- if !ok {
- apexesForModule = make(map[string]bool)
- apexNamesMap()[moduleName] = apexesForModule
- }
- apexesForModule[apex.ApexName] = apexesForModule[apex.ApexName] || directDep
+ apexesForModule, ok := apexNamesMap()[moduleName]
+ if !ok {
+ apexesForModule = make(map[string]bool)
+ apexNamesMap()[moduleName] = apexesForModule
}
+ apexesForModule[apex.ApexName] = apexesForModule[apex.ApexName] || directDep
}
// TODO(b/146393795): remove this when b/146393795 is fixed
diff --git a/android/config.go b/android/config.go
index 7073a49..92a21a7 100644
--- a/android/config.go
+++ b/android/config.go
@@ -337,8 +337,8 @@
config: config,
}
- // Sanity check the build and source directories. This won't catch strange
- // configurations with symlinks, but at least checks the obvious cases.
+ // Soundness check of the build and source directories. This won't catch strange
+ // configurations with symlinks, but at least checks the obvious case.
absBuildDir, err := filepath.Abs(buildDir)
if err != nil {
return Config{}, err
@@ -875,12 +875,12 @@
enforceList := c.productVariables.EnforceRROTargets
// TODO(b/150820813) Some modules depend on static overlay, remove this after eliminating the dependency.
exemptedList := c.productVariables.EnforceRROExemptedTargets
- if exemptedList != nil {
+ if len(exemptedList) > 0 {
if InList(name, exemptedList) {
return false
}
}
- if enforceList != nil {
+ if len(enforceList) > 0 {
if InList("*", enforceList) {
return true
}
@@ -891,7 +891,7 @@
func (c *config) EnforceRROExcludedOverlay(path string) bool {
excluded := c.productVariables.EnforceRROExcludedOverlays
- if excluded != nil {
+ if len(excluded) > 0 {
return HasAnyPrefix(path, excluded)
}
return false
@@ -913,34 +913,6 @@
return c.productVariables.ModulesLoadedByPrivilegedModules
}
-// Expected format for apexJarValue = <apex name>:<jar name>
-func SplitApexJarPair(ctx PathContext, str string) (string, string) {
- pair := strings.SplitN(str, ":", 2)
- if len(pair) == 2 {
- return pair[0], pair[1]
- } else {
- reportPathErrorf(ctx, "malformed (apex, jar) pair: '%s', expected format: <apex>:<jar>", str)
- return "error-apex", "error-jar"
- }
-}
-
-func GetJarsFromApexJarPairs(ctx PathContext, apexJarPairs []string) []string {
- modules := make([]string, len(apexJarPairs))
- for i, p := range apexJarPairs {
- _, jar := SplitApexJarPair(ctx, p)
- modules[i] = jar
- }
- return modules
-}
-
-func (c *config) BootJars() []string {
- ctx := NullPathContext{Config{
- config: c,
- }}
- return append(GetJarsFromApexJarPairs(ctx, c.productVariables.BootJars),
- GetJarsFromApexJarPairs(ctx, c.productVariables.UpdatableBootJars)...)
-}
-
func (c *config) DexpreoptGlobalConfig(ctx PathContext) ([]byte, error) {
if c.productVariables.DexpreoptGlobalConfig == nil {
return nil, nil
@@ -1059,7 +1031,7 @@
HasAnyPrefix(path, c.config.productVariables.JavaCoveragePaths) {
coverage = true
}
- if coverage && c.config.productVariables.JavaCoverageExcludePaths != nil {
+ if coverage && len(c.config.productVariables.JavaCoverageExcludePaths) > 0 {
if HasAnyPrefix(path, c.config.productVariables.JavaCoverageExcludePaths) {
coverage = false
}
@@ -1088,12 +1060,12 @@
// NativeCoveragePaths represents any path.
func (c *deviceConfig) NativeCoverageEnabledForPath(path string) bool {
coverage := false
- if c.config.productVariables.NativeCoveragePaths != nil {
+ if len(c.config.productVariables.NativeCoveragePaths) > 0 {
if InList("*", c.config.productVariables.NativeCoveragePaths) || HasAnyPrefix(path, c.config.productVariables.NativeCoveragePaths) {
coverage = true
}
}
- if coverage && c.config.productVariables.NativeCoverageExcludePaths != nil {
+ if coverage && len(c.config.productVariables.NativeCoverageExcludePaths) > 0 {
if HasAnyPrefix(path, c.config.productVariables.NativeCoverageExcludePaths) {
coverage = false
}
@@ -1164,21 +1136,21 @@
}
func (c *config) IntegerOverflowDisabledForPath(path string) bool {
- if c.productVariables.IntegerOverflowExcludePaths == nil {
+ if len(c.productVariables.IntegerOverflowExcludePaths) == 0 {
return false
}
return HasAnyPrefix(path, c.productVariables.IntegerOverflowExcludePaths)
}
func (c *config) CFIDisabledForPath(path string) bool {
- if c.productVariables.CFIExcludePaths == nil {
+ if len(c.productVariables.CFIExcludePaths) == 0 {
return false
}
return HasAnyPrefix(path, c.productVariables.CFIExcludePaths)
}
func (c *config) CFIEnabledForPath(path string) bool {
- if c.productVariables.CFIIncludePaths == nil {
+ if len(c.productVariables.CFIIncludePaths) == 0 {
return false
}
return HasAnyPrefix(path, c.productVariables.CFIIncludePaths)
@@ -1252,10 +1224,6 @@
return c.productVariables.MissingUsesLibraries
}
-func (c *deviceConfig) BoardVndkRuntimeDisable() bool {
- return Bool(c.config.productVariables.BoardVndkRuntimeDisable)
-}
-
func (c *deviceConfig) DeviceArch() string {
return String(c.config.productVariables.DeviceArch)
}
@@ -1275,3 +1243,185 @@
func (c *deviceConfig) BoardUsesRecoveryAsBoot() bool {
return Bool(c.config.productVariables.BoardUsesRecoveryAsBoot)
}
+
+func (c *deviceConfig) BoardKernelBinaries() []string {
+ return c.config.productVariables.BoardKernelBinaries
+}
+
+// The ConfiguredJarList struct provides methods for handling a list of (apex, jar) pairs.
+// Such lists are used in the build system for things like bootclasspath jars or system server jars.
+// The apex part is either an apex name, or a special names "platform" or "system_ext". Jar is a
+// module name. The pairs come from Make product variables as a list of colon-separated strings.
+//
+// Examples:
+// - "com.android.art:core-oj"
+// - "platform:framework"
+// - "system_ext:foo"
+//
+type ConfiguredJarList struct {
+ apexes []string // A list of apex components.
+ jars []string // A list of jar components.
+}
+
+// The length of the list.
+func (l *ConfiguredJarList) Len() int {
+ return len(l.jars)
+}
+
+// Apex component of idx-th pair on the list.
+func (l *ConfiguredJarList) apex(idx int) string {
+ return l.apexes[idx]
+}
+
+// Jar component of idx-th pair on the list.
+func (l *ConfiguredJarList) Jar(idx int) string {
+ return l.jars[idx]
+}
+
+// If the list contains a pair with the given jar.
+func (l *ConfiguredJarList) ContainsJar(jar string) bool {
+ return InList(jar, l.jars)
+}
+
+// If the list contains the given (apex, jar) pair.
+func (l *ConfiguredJarList) containsApexJarPair(apex, jar string) bool {
+ for i := 0; i < l.Len(); i++ {
+ if apex == l.apex(i) && jar == l.Jar(i) {
+ return true
+ }
+ }
+ return false
+}
+
+// Index of the first pair with the given jar on the list, or -1 if none.
+func (l *ConfiguredJarList) IndexOfJar(jar string) int {
+ return IndexList(jar, l.jars)
+}
+
+// Append an (apex, jar) pair to the list.
+func (l *ConfiguredJarList) Append(apex string, jar string) {
+ l.apexes = append(l.apexes, apex)
+ l.jars = append(l.jars, jar)
+}
+
+// Filter out sublist.
+func (l *ConfiguredJarList) RemoveList(list ConfiguredJarList) {
+ apexes := make([]string, 0, l.Len())
+ jars := make([]string, 0, l.Len())
+
+ for i, jar := range l.jars {
+ apex := l.apex(i)
+ if !list.containsApexJarPair(apex, jar) {
+ apexes = append(apexes, apex)
+ jars = append(jars, jar)
+ }
+ }
+
+ l.apexes = apexes
+ l.jars = jars
+}
+
+// A copy of itself.
+func (l *ConfiguredJarList) CopyOf() ConfiguredJarList {
+ return ConfiguredJarList{CopyOf(l.apexes), CopyOf(l.jars)}
+}
+
+// A copy of the list of strings containing jar components.
+func (l *ConfiguredJarList) CopyOfJars() []string {
+ return CopyOf(l.jars)
+}
+
+// A copy of the list of strings with colon-separated (apex, jar) pairs.
+func (l *ConfiguredJarList) CopyOfApexJarPairs() []string {
+ pairs := make([]string, 0, l.Len())
+
+ for i, jar := range l.jars {
+ apex := l.apex(i)
+ pairs = append(pairs, apex+":"+jar)
+ }
+
+ return pairs
+}
+
+// A list of build paths based on the given directory prefix.
+func (l *ConfiguredJarList) BuildPaths(ctx PathContext, dir OutputPath) WritablePaths {
+ paths := make(WritablePaths, l.Len())
+ for i, jar := range l.jars {
+ paths[i] = dir.Join(ctx, ModuleStem(jar)+".jar")
+ }
+ return paths
+}
+
+func ModuleStem(module string) string {
+ // b/139391334: the stem of framework-minus-apex is framework. This is hard coded here until we
+ // find a good way to query the stem of a module before any other mutators are run.
+ if module == "framework-minus-apex" {
+ return "framework"
+ }
+ return module
+}
+
+// A list of on-device paths.
+func (l *ConfiguredJarList) DevicePaths(cfg Config, ostype OsType) []string {
+ paths := make([]string, l.Len())
+ for i, jar := range l.jars {
+ apex := l.apexes[i]
+ name := ModuleStem(jar) + ".jar"
+
+ var subdir string
+ if apex == "platform" {
+ subdir = "system/framework"
+ } else if apex == "system_ext" {
+ subdir = "system_ext/framework"
+ } else {
+ subdir = filepath.Join("apex", apex, "javalib")
+ }
+
+ if ostype.Class == Host {
+ paths[i] = filepath.Join(cfg.Getenv("OUT_DIR"), "host", cfg.PrebuiltOS(), subdir, name)
+ } else {
+ paths[i] = filepath.Join("/", subdir, name)
+ }
+ }
+ return paths
+}
+
+// Expected format for apexJarValue = <apex name>:<jar name>
+func splitConfiguredJarPair(ctx PathContext, str string) (string, string) {
+ pair := strings.SplitN(str, ":", 2)
+ if len(pair) == 2 {
+ return pair[0], pair[1]
+ } else {
+ reportPathErrorf(ctx, "malformed (apex, jar) pair: '%s', expected format: <apex>:<jar>", str)
+ return "error-apex", "error-jar"
+ }
+}
+
+func CreateConfiguredJarList(ctx PathContext, list []string) ConfiguredJarList {
+ apexes := make([]string, 0, len(list))
+ jars := make([]string, 0, len(list))
+
+ l := ConfiguredJarList{apexes, jars}
+
+ for _, apexjar := range list {
+ apex, jar := splitConfiguredJarPair(ctx, apexjar)
+ l.Append(apex, jar)
+ }
+
+ return l
+}
+
+func EmptyConfiguredJarList() ConfiguredJarList {
+ return ConfiguredJarList{}
+}
+
+var earlyBootJarsKey = NewOnceKey("earlyBootJars")
+
+func (c *config) BootJars() []string {
+ return c.Once(earlyBootJarsKey, func() interface{} {
+ ctx := NullPathContext{Config{c}}
+ list := CreateConfiguredJarList(ctx,
+ append(CopyOf(c.productVariables.BootJars), c.productVariables.UpdatableBootJars...))
+ return list.CopyOfJars()
+ }).([]string)
+}
diff --git a/android/depset.go b/android/depset.go
new file mode 100644
index 0000000..f707094
--- /dev/null
+++ b/android/depset.go
@@ -0,0 +1,190 @@
+// Copyright 2020 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package android
+
+import "fmt"
+
+// DepSet is designed to be conceptually compatible with Bazel's depsets:
+// https://docs.bazel.build/versions/master/skylark/depsets.html
+
+// A DepSet efficiently stores Paths from transitive dependencies without copying. It is stored
+// as a DAG of DepSet nodes, each of which has some direct contents and a list of dependency
+// DepSet nodes.
+//
+// A DepSet has an order that will be used to walk the DAG when ToList() is called. The order
+// can be POSTORDER, PREORDER, or TOPOLOGICAL. POSTORDER and PREORDER orders return a postordered
+// or preordered left to right flattened list. TOPOLOGICAL returns a list that guarantees that
+// elements of children are listed after all of their parents (unless there are duplicate direct
+// elements in the DepSet or any of its transitive dependencies, in which case the ordering of the
+// duplicated element is not guaranteed).
+//
+// A DepSet is created by NewDepSet or NewDepSetBuilder.Build from the Paths for direct contents
+// and the *DepSets of dependencies. A DepSet is immutable once created.
+type DepSet struct {
+ preorder bool
+ reverse bool
+ order DepSetOrder
+ direct Paths
+ transitive []*DepSet
+}
+
+// DepSetBuilder is used to create an immutable DepSet.
+type DepSetBuilder struct {
+ order DepSetOrder
+ direct Paths
+ transitive []*DepSet
+}
+
+type DepSetOrder int
+
+const (
+ PREORDER DepSetOrder = iota
+ POSTORDER
+ TOPOLOGICAL
+)
+
+func (o DepSetOrder) String() string {
+ switch o {
+ case PREORDER:
+ return "PREORDER"
+ case POSTORDER:
+ return "POSTORDER"
+ case TOPOLOGICAL:
+ return "TOPOLOGICAL"
+ default:
+ panic(fmt.Errorf("Invalid DepSetOrder %d", o))
+ }
+}
+
+// NewDepSet returns an immutable DepSet with the given order, direct and transitive contents.
+func NewDepSet(order DepSetOrder, direct Paths, transitive []*DepSet) *DepSet {
+ var directCopy Paths
+ var transitiveCopy []*DepSet
+ if order == TOPOLOGICAL {
+ directCopy = ReversePaths(direct)
+ transitiveCopy = reverseDepSets(transitive)
+ } else {
+ // Use copy instead of append(nil, ...) to make a slice that is exactly the size of the input
+ // slice. The DepSet is immutable, there is no need for additional capacity.
+ directCopy = make(Paths, len(direct))
+ copy(directCopy, direct)
+ transitiveCopy = make([]*DepSet, len(transitive))
+ copy(transitiveCopy, transitive)
+ }
+
+ for _, dep := range transitive {
+ if dep.order != order {
+ panic(fmt.Errorf("incompatible order, new DepSet is %s but transitive DepSet is %s",
+ order, dep.order))
+ }
+ }
+
+ return &DepSet{
+ preorder: order == PREORDER,
+ reverse: order == TOPOLOGICAL,
+ order: order,
+ direct: directCopy,
+ transitive: transitiveCopy,
+ }
+}
+
+// NewDepSetBuilder returns a DepSetBuilder to create an immutable DepSet with the given order.
+func NewDepSetBuilder(order DepSetOrder) *DepSetBuilder {
+ return &DepSetBuilder{order: order}
+}
+
+// Direct adds direct contents to the DepSet being built by a DepSetBuilder. Newly added direct
+// contents are to the right of any existing direct contents.
+func (b *DepSetBuilder) Direct(direct ...Path) *DepSetBuilder {
+ b.direct = append(b.direct, direct...)
+ return b
+}
+
+// Transitive adds transitive contents to the DepSet being built by a DepSetBuilder. Newly added
+// transitive contents are to the right of any existing transitive contents.
+func (b *DepSetBuilder) Transitive(transitive ...*DepSet) *DepSetBuilder {
+ b.transitive = append(b.transitive, transitive...)
+ return b
+}
+
+// Returns the DepSet being built by this DepSetBuilder. The DepSetBuilder retains its contents
+// for creating more DepSets.
+func (b *DepSetBuilder) Build() *DepSet {
+ return NewDepSet(b.order, b.direct, b.transitive)
+}
+
+// walk calls the visit method in depth-first order on a DepSet, preordered if d.preorder is set,
+// otherwise postordered.
+func (d *DepSet) walk(visit func(Paths)) {
+ visited := make(map[*DepSet]bool)
+
+ var dfs func(d *DepSet)
+ dfs = func(d *DepSet) {
+ visited[d] = true
+ if d.preorder {
+ visit(d.direct)
+ }
+ for _, dep := range d.transitive {
+ if !visited[dep] {
+ dfs(dep)
+ }
+ }
+
+ if !d.preorder {
+ visit(d.direct)
+ }
+ }
+
+ dfs(d)
+}
+
+// ToList returns the DepSet flattened to a list. The order in the list is based on the order
+// of the DepSet. POSTORDER and PREORDER orders return a postordered or preordered left to right
+// flattened list. TOPOLOGICAL returns a list that guarantees that elements of children are listed
+// after all of their parents (unless there are duplicate direct elements in the DepSet or any of
+// its transitive dependencies, in which case the ordering of the duplicated element is not
+// guaranteed).
+func (d *DepSet) ToList() Paths {
+ var list Paths
+ d.walk(func(paths Paths) {
+ list = append(list, paths...)
+ })
+ list = FirstUniquePaths(list)
+ if d.reverse {
+ reversePathsInPlace(list)
+ }
+ return list
+}
+
+// ToSortedList returns the direct and transitive contents of a DepSet in lexically sorted order
+// with duplicates removed.
+func (d *DepSet) ToSortedList() Paths {
+ list := d.ToList()
+ return SortedUniquePaths(list)
+}
+
+func reversePathsInPlace(list Paths) {
+ for i, j := 0, len(list)-1; i < j; i, j = i+1, j-1 {
+ list[i], list[j] = list[j], list[i]
+ }
+}
+
+func reverseDepSets(list []*DepSet) []*DepSet {
+ ret := make([]*DepSet, len(list))
+ for i := range list {
+ ret[i] = list[len(list)-1-i]
+ }
+ return ret
+}
diff --git a/android/depset_test.go b/android/depset_test.go
new file mode 100644
index 0000000..c328127
--- /dev/null
+++ b/android/depset_test.go
@@ -0,0 +1,304 @@
+// Copyright 2020 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package android
+
+import (
+ "fmt"
+ "reflect"
+ "strings"
+ "testing"
+)
+
+func ExampleDepSet_ToList_postordered() {
+ a := NewDepSetBuilder(POSTORDER).Direct(PathForTesting("a")).Build()
+ b := NewDepSetBuilder(POSTORDER).Direct(PathForTesting("b")).Transitive(a).Build()
+ c := NewDepSetBuilder(POSTORDER).Direct(PathForTesting("c")).Transitive(a).Build()
+ d := NewDepSetBuilder(POSTORDER).Direct(PathForTesting("d")).Transitive(b, c).Build()
+
+ fmt.Println(d.ToList().Strings())
+ // Output: [a b c d]
+}
+
+func ExampleDepSet_ToList_preordered() {
+ a := NewDepSetBuilder(PREORDER).Direct(PathForTesting("a")).Build()
+ b := NewDepSetBuilder(PREORDER).Direct(PathForTesting("b")).Transitive(a).Build()
+ c := NewDepSetBuilder(PREORDER).Direct(PathForTesting("c")).Transitive(a).Build()
+ d := NewDepSetBuilder(PREORDER).Direct(PathForTesting("d")).Transitive(b, c).Build()
+
+ fmt.Println(d.ToList().Strings())
+ // Output: [d b a c]
+}
+
+func ExampleDepSet_ToList_topological() {
+ a := NewDepSetBuilder(TOPOLOGICAL).Direct(PathForTesting("a")).Build()
+ b := NewDepSetBuilder(TOPOLOGICAL).Direct(PathForTesting("b")).Transitive(a).Build()
+ c := NewDepSetBuilder(TOPOLOGICAL).Direct(PathForTesting("c")).Transitive(a).Build()
+ d := NewDepSetBuilder(TOPOLOGICAL).Direct(PathForTesting("d")).Transitive(b, c).Build()
+
+ fmt.Println(d.ToList().Strings())
+ // Output: [d b c a]
+}
+
+func ExampleDepSet_ToSortedList() {
+ a := NewDepSetBuilder(POSTORDER).Direct(PathForTesting("a")).Build()
+ b := NewDepSetBuilder(POSTORDER).Direct(PathForTesting("b")).Transitive(a).Build()
+ c := NewDepSetBuilder(POSTORDER).Direct(PathForTesting("c")).Transitive(a).Build()
+ d := NewDepSetBuilder(POSTORDER).Direct(PathForTesting("d")).Transitive(b, c).Build()
+
+ fmt.Println(d.ToSortedList().Strings())
+ // Output: [a b c d]
+}
+
+// Tests based on Bazel's ExpanderTestBase.java to ensure compatibility
+// https://github.com/bazelbuild/bazel/blob/master/src/test/java/com/google/devtools/build/lib/collect/nestedset/ExpanderTestBase.java
+func TestDepSet(t *testing.T) {
+ a := PathForTesting("a")
+ b := PathForTesting("b")
+ c := PathForTesting("c")
+ c2 := PathForTesting("c2")
+ d := PathForTesting("d")
+ e := PathForTesting("e")
+
+ tests := []struct {
+ name string
+ depSet func(t *testing.T, order DepSetOrder) *DepSet
+ postorder, preorder, topological []string
+ }{
+ {
+ name: "simple",
+ depSet: func(t *testing.T, order DepSetOrder) *DepSet {
+ return NewDepSet(order, Paths{c, a, b}, nil)
+ },
+ postorder: []string{"c", "a", "b"},
+ preorder: []string{"c", "a", "b"},
+ topological: []string{"c", "a", "b"},
+ },
+ {
+ name: "simpleNoDuplicates",
+ depSet: func(t *testing.T, order DepSetOrder) *DepSet {
+ return NewDepSet(order, Paths{c, a, a, a, b}, nil)
+ },
+ postorder: []string{"c", "a", "b"},
+ preorder: []string{"c", "a", "b"},
+ topological: []string{"c", "a", "b"},
+ },
+ {
+ name: "nesting",
+ depSet: func(t *testing.T, order DepSetOrder) *DepSet {
+ subset := NewDepSet(order, Paths{c, a, e}, nil)
+ return NewDepSet(order, Paths{b, d}, []*DepSet{subset})
+ },
+ postorder: []string{"c", "a", "e", "b", "d"},
+ preorder: []string{"b", "d", "c", "a", "e"},
+ topological: []string{"b", "d", "c", "a", "e"},
+ },
+ {
+ name: "builderReuse",
+ depSet: func(t *testing.T, order DepSetOrder) *DepSet {
+ assertEquals := func(t *testing.T, w, g Paths) {
+ if !reflect.DeepEqual(w, g) {
+ t.Errorf("want %q, got %q", w, g)
+ }
+ }
+ builder := NewDepSetBuilder(order)
+ assertEquals(t, nil, builder.Build().ToList())
+
+ builder.Direct(b)
+ assertEquals(t, Paths{b}, builder.Build().ToList())
+
+ builder.Direct(d)
+ assertEquals(t, Paths{b, d}, builder.Build().ToList())
+
+ child := NewDepSetBuilder(order).Direct(c, a, e).Build()
+ builder.Transitive(child)
+ return builder.Build()
+ },
+ postorder: []string{"c", "a", "e", "b", "d"},
+ preorder: []string{"b", "d", "c", "a", "e"},
+ topological: []string{"b", "d", "c", "a", "e"},
+ },
+ {
+ name: "builderChaining",
+ depSet: func(t *testing.T, order DepSetOrder) *DepSet {
+ return NewDepSetBuilder(order).Direct(b).Direct(d).
+ Transitive(NewDepSetBuilder(order).Direct(c, a, e).Build()).Build()
+ },
+ postorder: []string{"c", "a", "e", "b", "d"},
+ preorder: []string{"b", "d", "c", "a", "e"},
+ topological: []string{"b", "d", "c", "a", "e"},
+ },
+ {
+ name: "transitiveDepsHandledSeparately",
+ depSet: func(t *testing.T, order DepSetOrder) *DepSet {
+ subset := NewDepSetBuilder(order).Direct(c, a, e).Build()
+ builder := NewDepSetBuilder(order)
+ // The fact that we add the transitive subset between the Direct(b) and Direct(d)
+ // calls should not change the result.
+ builder.Direct(b)
+ builder.Transitive(subset)
+ builder.Direct(d)
+ return builder.Build()
+ },
+ postorder: []string{"c", "a", "e", "b", "d"},
+ preorder: []string{"b", "d", "c", "a", "e"},
+ topological: []string{"b", "d", "c", "a", "e"},
+ },
+ {
+ name: "nestingNoDuplicates",
+ depSet: func(t *testing.T, order DepSetOrder) *DepSet {
+ subset := NewDepSetBuilder(order).Direct(c, a, e).Build()
+ return NewDepSetBuilder(order).Direct(b, d, e).Transitive(subset).Build()
+ },
+ postorder: []string{"c", "a", "e", "b", "d"},
+ preorder: []string{"b", "d", "e", "c", "a"},
+ topological: []string{"b", "d", "c", "a", "e"},
+ },
+ {
+ name: "chain",
+ depSet: func(t *testing.T, order DepSetOrder) *DepSet {
+ c := NewDepSetBuilder(order).Direct(c).Build()
+ b := NewDepSetBuilder(order).Direct(b).Transitive(c).Build()
+ a := NewDepSetBuilder(order).Direct(a).Transitive(b).Build()
+
+ return a
+ },
+ postorder: []string{"c", "b", "a"},
+ preorder: []string{"a", "b", "c"},
+ topological: []string{"a", "b", "c"},
+ },
+ {
+ name: "diamond",
+ depSet: func(t *testing.T, order DepSetOrder) *DepSet {
+ d := NewDepSetBuilder(order).Direct(d).Build()
+ c := NewDepSetBuilder(order).Direct(c).Transitive(d).Build()
+ b := NewDepSetBuilder(order).Direct(b).Transitive(d).Build()
+ a := NewDepSetBuilder(order).Direct(a).Transitive(b).Transitive(c).Build()
+
+ return a
+ },
+ postorder: []string{"d", "b", "c", "a"},
+ preorder: []string{"a", "b", "d", "c"},
+ topological: []string{"a", "b", "c", "d"},
+ },
+ {
+ name: "extendedDiamond",
+ depSet: func(t *testing.T, order DepSetOrder) *DepSet {
+ d := NewDepSetBuilder(order).Direct(d).Build()
+ e := NewDepSetBuilder(order).Direct(e).Build()
+ b := NewDepSetBuilder(order).Direct(b).Transitive(d).Transitive(e).Build()
+ c := NewDepSetBuilder(order).Direct(c).Transitive(e).Transitive(d).Build()
+ a := NewDepSetBuilder(order).Direct(a).Transitive(b).Transitive(c).Build()
+ return a
+ },
+ postorder: []string{"d", "e", "b", "c", "a"},
+ preorder: []string{"a", "b", "d", "e", "c"},
+ topological: []string{"a", "b", "c", "e", "d"},
+ },
+ {
+ name: "extendedDiamondRightArm",
+ depSet: func(t *testing.T, order DepSetOrder) *DepSet {
+ d := NewDepSetBuilder(order).Direct(d).Build()
+ e := NewDepSetBuilder(order).Direct(e).Build()
+ b := NewDepSetBuilder(order).Direct(b).Transitive(d).Transitive(e).Build()
+ c2 := NewDepSetBuilder(order).Direct(c2).Transitive(e).Transitive(d).Build()
+ c := NewDepSetBuilder(order).Direct(c).Transitive(c2).Build()
+ a := NewDepSetBuilder(order).Direct(a).Transitive(b).Transitive(c).Build()
+ return a
+ },
+ postorder: []string{"d", "e", "b", "c2", "c", "a"},
+ preorder: []string{"a", "b", "d", "e", "c", "c2"},
+ topological: []string{"a", "b", "c", "c2", "e", "d"},
+ },
+ {
+ name: "orderConflict",
+ depSet: func(t *testing.T, order DepSetOrder) *DepSet {
+ child1 := NewDepSetBuilder(order).Direct(a, b).Build()
+ child2 := NewDepSetBuilder(order).Direct(b, a).Build()
+ parent := NewDepSetBuilder(order).Transitive(child1).Transitive(child2).Build()
+ return parent
+ },
+ postorder: []string{"a", "b"},
+ preorder: []string{"a", "b"},
+ topological: []string{"b", "a"},
+ },
+ {
+ name: "orderConflictNested",
+ depSet: func(t *testing.T, order DepSetOrder) *DepSet {
+ a := NewDepSetBuilder(order).Direct(a).Build()
+ b := NewDepSetBuilder(order).Direct(b).Build()
+ child1 := NewDepSetBuilder(order).Transitive(a).Transitive(b).Build()
+ child2 := NewDepSetBuilder(order).Transitive(b).Transitive(a).Build()
+ parent := NewDepSetBuilder(order).Transitive(child1).Transitive(child2).Build()
+ return parent
+ },
+ postorder: []string{"a", "b"},
+ preorder: []string{"a", "b"},
+ topological: []string{"b", "a"},
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ t.Run("postorder", func(t *testing.T) {
+ depSet := tt.depSet(t, POSTORDER)
+ if g, w := depSet.ToList().Strings(), tt.postorder; !reflect.DeepEqual(g, w) {
+ t.Errorf("expected ToList() = %q, got %q", w, g)
+ }
+ })
+ t.Run("preorder", func(t *testing.T) {
+ depSet := tt.depSet(t, PREORDER)
+ if g, w := depSet.ToList().Strings(), tt.preorder; !reflect.DeepEqual(g, w) {
+ t.Errorf("expected ToList() = %q, got %q", w, g)
+ }
+ })
+ t.Run("topological", func(t *testing.T) {
+ depSet := tt.depSet(t, TOPOLOGICAL)
+ if g, w := depSet.ToList().Strings(), tt.topological; !reflect.DeepEqual(g, w) {
+ t.Errorf("expected ToList() = %q, got %q", w, g)
+ }
+ })
+ })
+ }
+}
+
+func TestDepSetInvalidOrder(t *testing.T) {
+ orders := []DepSetOrder{POSTORDER, PREORDER, TOPOLOGICAL}
+
+ run := func(t *testing.T, order1, order2 DepSetOrder) {
+ defer func() {
+ if r := recover(); r != nil {
+ if err, ok := r.(error); !ok {
+ t.Fatalf("expected panic error, got %v", err)
+ } else if !strings.Contains(err.Error(), "incompatible order") {
+ t.Fatalf("expected incompatible order error, got %v", err)
+ }
+ }
+ }()
+ NewDepSet(order1, nil, []*DepSet{NewDepSet(order2, nil, nil)})
+ t.Fatal("expected panic")
+ }
+
+ for _, order1 := range orders {
+ t.Run(order1.String(), func(t *testing.T) {
+ for _, order2 := range orders {
+ t.Run(order2.String(), func(t *testing.T) {
+ if order1 != order2 {
+ run(t, order1, order2)
+ }
+ })
+ }
+ })
+ }
+}
diff --git a/android/makefile_goal.go b/android/makefile_goal.go
new file mode 100644
index 0000000..eae3976
--- /dev/null
+++ b/android/makefile_goal.go
@@ -0,0 +1,99 @@
+// Copyright 2020 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package android
+
+import (
+ "fmt"
+ "io"
+ "path/filepath"
+
+ "github.com/google/blueprint/proptools"
+)
+
+func init() {
+ RegisterModuleType("makefile_goal", MakefileGoalFactory)
+}
+
+type makefileGoalProperties struct {
+ // Sources.
+
+ // Makefile goal output file path, relative to PRODUCT_OUT.
+ Product_out_path *string
+}
+
+type makefileGoal struct {
+ ModuleBase
+
+ properties makefileGoalProperties
+
+ // Destination. Output file path of this module.
+ outputFilePath OutputPath
+}
+
+var _ AndroidMkEntriesProvider = (*makefileGoal)(nil)
+var _ OutputFileProducer = (*makefileGoal)(nil)
+
+// Input file of this makefile_goal module. Nil if none specified. May use variable names in makefiles.
+func (p *makefileGoal) inputPath() *string {
+ if p.properties.Product_out_path != nil {
+ return proptools.StringPtr(filepath.Join("$(PRODUCT_OUT)", proptools.String(p.properties.Product_out_path)))
+ }
+ return nil
+}
+
+// OutputFileProducer
+func (p *makefileGoal) OutputFiles(tag string) (Paths, error) {
+ if tag != "" {
+ return nil, fmt.Errorf("unsupported tag %q", tag)
+ }
+ return Paths{p.outputFilePath}, nil
+}
+
+// AndroidMkEntriesProvider
+func (p *makefileGoal) DepsMutator(ctx BottomUpMutatorContext) {
+ if p.inputPath() == nil {
+ ctx.PropertyErrorf("product_out_path", "Path relative to PRODUCT_OUT required")
+ }
+}
+
+func (p *makefileGoal) GenerateAndroidBuildActions(ctx ModuleContext) {
+ filename := filepath.Base(proptools.String(p.inputPath()))
+ p.outputFilePath = PathForModuleOut(ctx, filename).OutputPath
+
+ ctx.InstallFile(PathForModuleInstall(ctx, "etc"), ctx.ModuleName(), p.outputFilePath)
+}
+
+func (p *makefileGoal) AndroidMkEntries() []AndroidMkEntries {
+ return []AndroidMkEntries{AndroidMkEntries{
+ Class: "ETC",
+ OutputFile: OptionalPathForPath(p.outputFilePath),
+ ExtraFooters: []AndroidMkExtraFootersFunc{
+ func(w io.Writer, name, prefix, moduleDir string, entries *AndroidMkEntries) {
+ // Can't use Cp because inputPath() is not a valid Path.
+ fmt.Fprintf(w, "$(eval $(call copy-one-file,%s,%s))\n", proptools.String(p.inputPath()), p.outputFilePath)
+ },
+ },
+ }}
+}
+
+// Import a Makefile goal to Soong by copying the file built by
+// the goal to a path visible to Soong. This rule only works on boot images.
+func MakefileGoalFactory() Module {
+ module := &makefileGoal{}
+ module.AddProperties(&module.properties)
+ // This module is device-only
+ InitAndroidArchModule(module, DeviceSupported, MultilibFirst)
+ return module
+}
diff --git a/android/module.go b/android/module.go
index f80f37e..8605954 100644
--- a/android/module.go
+++ b/android/module.go
@@ -50,6 +50,8 @@
Implicit Path
Implicits Paths
OrderOnly Paths
+ Validation Path
+ Validations Paths
Default bool
Args map[string]string
}
@@ -546,6 +548,9 @@
SkipInstall bool `blueprint:"mutated"`
+ // Disabled by mutators. If set to true, it overrides Enabled property.
+ ForcedDisabled bool `blueprint:"mutated"`
+
NamespaceExportedToMake bool `blueprint:"mutated"`
MissingDeps []string `blueprint:"mutated"`
@@ -1020,6 +1025,9 @@
}
func (m *ModuleBase) Enabled() bool {
+ if m.commonProperties.ForcedDisabled {
+ return false
+ }
if m.commonProperties.Enabled == nil {
return !m.Os().DefaultDisabled
}
@@ -1027,7 +1035,7 @@
}
func (m *ModuleBase) Disable() {
- m.commonProperties.Enabled = proptools.BoolPtr(false)
+ m.commonProperties.ForcedDisabled = true
}
func (m *ModuleBase) SkipInstall() {
@@ -1561,6 +1569,7 @@
Inputs: params.Inputs.Strings(),
Implicits: params.Implicits.Strings(),
OrderOnly: params.OrderOnly.Strings(),
+ Validations: params.Validations.Strings(),
Args: params.Args,
Optional: !params.Default,
}
@@ -1580,13 +1589,17 @@
if params.Implicit != nil {
bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
}
+ if params.Validation != nil {
+ bparams.Validations = append(bparams.Validations, params.Validation.String())
+ }
bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
- bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
+ bparams.Validations = proptools.NinjaEscapeList(bparams.Validations)
+ bparams.Depfile = proptools.NinjaEscape(bparams.Depfile)
return bparams
}
@@ -1826,7 +1839,7 @@
// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
// a dependency tag.
-var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
+var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:{}\E(, )?`)
// PrettyPrintTag returns string representation of the tag, but prefers
// custom String() method if available.
@@ -1837,7 +1850,7 @@
}
// Otherwise, get a default string representation of the tag's struct.
- tagString := fmt.Sprintf("%#v", tag)
+ tagString := fmt.Sprintf("%T: %+v", tag, tag)
// Remove the boilerplate from BaseDependencyTag as it adds no value.
tagString = tagCleaner.ReplaceAllString(tagString, "")
diff --git a/android/neverallow.go b/android/neverallow.go
index 526d399..73829f1 100644
--- a/android/neverallow.go
+++ b/android/neverallow.go
@@ -56,6 +56,7 @@
AddNeverAllowRules(createJavaDeviceForHostRules()...)
AddNeverAllowRules(createCcSdkVariantRules()...)
AddNeverAllowRules(createUncompressDexRules()...)
+ AddNeverAllowRules(createMakefileGoalRules()...)
}
// Add a NeverAllow rule to the set of rules to apply.
@@ -231,6 +232,15 @@
}
}
+func createMakefileGoalRules() []Rule {
+ return []Rule{
+ NeverAllow().
+ ModuleType("makefile_goal").
+ WithoutMatcher("product_out_path", Regexp("^boot[0-9a-zA-Z.-]*[.]img$")).
+ Because("Only boot images may be imported as a makefile goal."),
+ }
+}
+
func neverallowMutator(ctx BottomUpMutatorContext) {
m, ok := ctx.Module().(Module)
if !ok {
diff --git a/android/neverallow_test.go b/android/neverallow_test.go
index 45d36a6..56a07dc 100644
--- a/android/neverallow_test.go
+++ b/android/neverallow_test.go
@@ -326,6 +326,20 @@
"module \"outside_art_libraries\": violates neverallow",
},
},
+ {
+ name: "disallowed makefile_goal",
+ fs: map[string][]byte{
+ "Android.bp": []byte(`
+ makefile_goal {
+ name: "foo",
+ product_out_path: "boot/trap.img"
+ }
+ `),
+ },
+ expectedErrors: []string{
+ "Only boot images may be imported as a makefile goal.",
+ },
+ },
}
func TestNeverallow(t *testing.T) {
@@ -350,6 +364,7 @@
ctx.RegisterModuleType("java_library", newMockJavaLibraryModule)
ctx.RegisterModuleType("java_library_host", newMockJavaLibraryModule)
ctx.RegisterModuleType("java_device_for_host", newMockJavaLibraryModule)
+ ctx.RegisterModuleType("makefile_goal", newMockMakefileGoalModule)
ctx.PostDepsMutators(RegisterNeverallowMutator)
ctx.Register(config)
@@ -438,3 +453,22 @@
func (p *mockJavaLibraryModule) GenerateAndroidBuildActions(ModuleContext) {
}
+
+type mockMakefileGoalProperties struct {
+ Product_out_path *string
+}
+
+type mockMakefileGoalModule struct {
+ ModuleBase
+ properties mockMakefileGoalProperties
+}
+
+func newMockMakefileGoalModule() Module {
+ m := &mockMakefileGoalModule{}
+ m.AddProperties(&m.properties)
+ InitAndroidModule(m)
+ return m
+}
+
+func (p *mockMakefileGoalModule) GenerateAndroidBuildActions(ModuleContext) {
+}
diff --git a/android/paths.go b/android/paths.go
index d13b6d8..65f129c 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -486,6 +486,10 @@
return ret
}
+func CopyOfPaths(paths Paths) Paths {
+ return append(Paths(nil), paths...)
+}
+
// FirstUniquePaths returns all unique elements of a Paths, keeping the first copy of each. It
// modifies the Paths slice contents in place, and returns a subslice of the original slice.
func FirstUniquePaths(list Paths) Paths {
@@ -496,7 +500,8 @@
return firstUniquePathsList(list)
}
-// SortedUniquePaths returns what its name says
+// SortedUniquePaths returns all unique elements of a Paths in sorted order. It modifies the
+// Paths slice contents in place, and returns a subslice of the original slice.
func SortedUniquePaths(list Paths) Paths {
unique := FirstUniquePaths(list)
sort.Slice(unique, func(i, j int) bool {
@@ -1550,3 +1555,15 @@
}
return filepath.Join(absSrcDir, path)
}
+
+// A DataPath represents the path of a file to be used as data, for example
+// a test library to be installed alongside a test.
+// The data file should be installed (copied from `<SrcPath>`) to
+// `<install_root>/<RelativeInstallPath>/<filename>`, or
+// `<install_root>/<filename>` if RelativeInstallPath is empty.
+type DataPath struct {
+ // The path of the data file that should be copied into the data directory
+ SrcPath Path
+ // The install path of the data file, relative to the install root.
+ RelativeInstallPath string
+}
diff --git a/android/prebuilt.go b/android/prebuilt.go
index 9f4df28..269ad5d 100644
--- a/android/prebuilt.go
+++ b/android/prebuilt.go
@@ -225,7 +225,7 @@
// PrebuiltSourceDepsMutator adds dependencies to the prebuilt module from the
// corresponding source module, if one exists for the same variant.
func PrebuiltSourceDepsMutator(ctx BottomUpMutatorContext) {
- if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Prebuilt() != nil {
+ if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Enabled() && m.Prebuilt() != nil {
p := m.Prebuilt()
if !p.properties.PrebuiltRenamedToSource {
name := m.base().BaseModuleName()
diff --git a/android/prebuilt_test.go b/android/prebuilt_test.go
index 8029b85..6c3cd9e 100644
--- a/android/prebuilt_test.go
+++ b/android/prebuilt_test.go
@@ -22,9 +22,10 @@
)
var prebuiltsTests = []struct {
- name string
- modules string
- prebuilt []OsClass
+ name string
+ replaceBp bool // modules is added to default bp boilerplate if false.
+ modules string
+ prebuilt []OsType
}{
{
name: "no prebuilt",
@@ -42,7 +43,7 @@
prefer: false,
srcs: ["prebuilt_file"],
}`,
- prebuilt: []OsClass{Device, Host},
+ prebuilt: []OsType{Android, BuildOs},
},
{
name: "no source prebuilt preferred",
@@ -52,7 +53,7 @@
prefer: true,
srcs: ["prebuilt_file"],
}`,
- prebuilt: []OsClass{Device, Host},
+ prebuilt: []OsType{Android, BuildOs},
},
{
name: "prebuilt not preferred",
@@ -80,7 +81,7 @@
prefer: true,
srcs: ["prebuilt_file"],
}`,
- prebuilt: []OsClass{Device, Host},
+ prebuilt: []OsType{Android, BuildOs},
},
{
name: "prebuilt no file not preferred",
@@ -120,7 +121,7 @@
prefer: true,
srcs: [":fg"],
}`,
- prebuilt: []OsClass{Device, Host},
+ prebuilt: []OsType{Android, BuildOs},
},
{
name: "prebuilt module for device only",
@@ -135,7 +136,7 @@
prefer: true,
srcs: ["prebuilt_file"],
}`,
- prebuilt: []OsClass{Device},
+ prebuilt: []OsType{Android},
},
{
name: "prebuilt file for host only",
@@ -153,7 +154,7 @@
},
},
}`,
- prebuilt: []OsClass{Host},
+ prebuilt: []OsType{BuildOs},
},
{
name: "prebuilt override not preferred",
@@ -191,7 +192,72 @@
prefer: true,
srcs: ["prebuilt_file"],
}`,
- prebuilt: []OsClass{Device, Host},
+ prebuilt: []OsType{Android, BuildOs},
+ },
+ {
+ name: "prebuilt including default-disabled OS",
+ replaceBp: true,
+ modules: `
+ source {
+ name: "foo",
+ deps: [":bar"],
+ target: {
+ windows: {
+ enabled: true,
+ },
+ },
+ }
+
+ source {
+ name: "bar",
+ target: {
+ windows: {
+ enabled: true,
+ },
+ },
+ }
+
+ prebuilt {
+ name: "bar",
+ prefer: true,
+ srcs: ["prebuilt_file"],
+ target: {
+ windows: {
+ enabled: true,
+ },
+ },
+ }`,
+ prebuilt: []OsType{Android, BuildOs, Windows},
+ },
+ {
+ name: "fall back to source for default-disabled OS",
+ replaceBp: true,
+ modules: `
+ source {
+ name: "foo",
+ deps: [":bar"],
+ target: {
+ windows: {
+ enabled: true,
+ },
+ },
+ }
+
+ source {
+ name: "bar",
+ target: {
+ windows: {
+ enabled: true,
+ },
+ },
+ }
+
+ prebuilt {
+ name: "bar",
+ prefer: true,
+ srcs: ["prebuilt_file"],
+ }`,
+ prebuilt: []OsType{Android, BuildOs},
},
}
@@ -203,14 +269,25 @@
for _, test := range prebuiltsTests {
t.Run(test.name, func(t *testing.T) {
- bp := `
- source {
- name: "foo",
- deps: [":bar"],
- }
- ` + test.modules
+ bp := test.modules
+ if !test.replaceBp {
+ bp = bp + `
+ source {
+ name: "foo",
+ deps: [":bar"],
+ }`
+ }
config := TestArchConfig(buildDir, nil, bp, fs)
+ // Add windows to the target list to test the logic when a variant is
+ // disabled by default.
+ if !Windows.DefaultDisabled {
+ t.Errorf("windows is assumed to be disabled by default")
+ }
+ config.config.Targets[Windows] = []Target{
+ {Windows, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", ""},
+ }
+
ctx := NewTestArchContext()
registerTestPrebuiltBuildComponents(ctx)
ctx.RegisterModuleType("filegroup", FileGroupFactory)
@@ -223,7 +300,7 @@
for _, variant := range ctx.ModuleVariantsForTests("foo") {
foo := ctx.ModuleForTests("foo", variant)
- t.Run(foo.Module().Target().Os.Class.String(), func(t *testing.T) {
+ t.Run(foo.Module().Target().Os.String(), func(t *testing.T) {
var dependsOnSourceModule, dependsOnPrebuiltModule bool
ctx.VisitDirectDeps(foo.Module(), func(m blueprint.Module) {
if _, ok := m.(*sourceModule); ok {
@@ -237,26 +314,38 @@
}
})
+ moduleIsDisabled := !foo.Module().Enabled()
deps := foo.Module().(*sourceModule).deps
- if deps == nil || len(deps) != 1 {
- t.Errorf("deps does not have single path, but is %v", deps)
+ if moduleIsDisabled {
+ if len(deps) > 0 {
+ t.Errorf("disabled module got deps: %v", deps)
+ }
+ } else {
+ if len(deps) != 1 {
+ t.Errorf("deps does not have single path, but is %v", deps)
+ }
}
+
var usingSourceFile, usingPrebuiltFile bool
- if deps[0].String() == "source_file" {
+ if len(deps) > 0 && deps[0].String() == "source_file" {
usingSourceFile = true
}
- if deps[0].String() == "prebuilt_file" {
+ if len(deps) > 0 && deps[0].String() == "prebuilt_file" {
usingPrebuiltFile = true
}
prebuilt := false
for _, os := range test.prebuilt {
- if os == foo.Module().Target().Os.Class {
+ if os == foo.Module().Target().Os {
prebuilt = true
}
}
if prebuilt {
+ if moduleIsDisabled {
+ t.Errorf("dependent module for prebuilt is disabled")
+ }
+
if !dependsOnPrebuiltModule {
t.Errorf("doesn't depend on prebuilt module")
}
@@ -270,7 +359,7 @@
if usingSourceFile {
t.Errorf("using source_file")
}
- } else {
+ } else if !moduleIsDisabled {
if dependsOnPrebuiltModule {
t.Errorf("depends on prebuilt module")
}
diff --git a/android/sdk.go b/android/sdk.go
index 8115b69..9ea7ff4 100644
--- a/android/sdk.go
+++ b/android/sdk.go
@@ -34,10 +34,8 @@
RequiredSdks() SdkRefs
}
-// SdkAware is the interface that must be supported by any module to become a member of SDK or to be
-// built with SDK
-type SdkAware interface {
- Module
+// Provided to improve code navigation with the IDE.
+type sdkAwareWithoutModule interface {
RequiredSdks
sdkBase() *SdkBase
@@ -48,6 +46,13 @@
BuildWithSdks(sdks SdkRefs)
}
+// SdkAware is the interface that must be supported by any module to become a member of SDK or to be
+// built with SDK
+type SdkAware interface {
+ Module
+ sdkAwareWithoutModule
+}
+
// SdkRef refers to a version of an SDK
type SdkRef struct {
Name string
@@ -322,6 +327,12 @@
// SdkAware and be added with an SdkMemberTypeDependencyTag tag.
HasTransitiveSdkMembers() bool
+ // Return true if prebuilt host artifacts may be specific to the host OS. Only
+ // applicable to modules where HostSupported() is true. If this is true,
+ // snapshots will list each host OS variant explicitly and disable all other
+ // host OS'es.
+ IsHostOsDependent() bool
+
// Add dependencies from the SDK module to all the module variants the member
// type contributes to the SDK. `names` is the list of module names given in
// the member type property (as returned by SdkPropertyName()) in the SDK
@@ -384,6 +395,7 @@
PropertyName string
SupportsSdk bool
TransitiveSdkMembers bool
+ HostOsDependent bool
}
func (b *SdkMemberTypeBase) SdkPropertyName() string {
@@ -398,6 +410,10 @@
return b.TransitiveSdkMembers
}
+func (b *SdkMemberTypeBase) IsHostOsDependent() bool {
+ return b.HostOsDependent
+}
+
// Encapsulates the information about registered SdkMemberTypes.
type SdkMemberTypesRegistry struct {
// The list of types sorted by property name.
@@ -466,8 +482,7 @@
// Base structure for all implementations of SdkMemberProperties.
//
-// Contains common properties that apply across many different member types. These
-// are not affected by the optimization to extract common values.
+// Contains common properties that apply across many different member types.
type SdkMemberPropertiesBase struct {
// The number of unique os types supported by the member variants.
//
@@ -489,9 +504,7 @@
Os OsType `sdk:"keep"`
// The setting to use for the compile_multilib property.
- //
- // This property is set after optimization so there is no point in trying to optimize it.
- Compile_multilib string `sdk:"keep"`
+ Compile_multilib string `android:"arch_variant"`
}
// The os prefix to use for any file paths in the sdk.
diff --git a/android/test_suites.go b/android/test_suites.go
new file mode 100644
index 0000000..7b2d7dc
--- /dev/null
+++ b/android/test_suites.go
@@ -0,0 +1,75 @@
+// Copyright 2020 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package android
+
+func init() {
+ RegisterSingletonType("testsuites", testSuiteFilesFactory)
+}
+
+func testSuiteFilesFactory() Singleton {
+ return &testSuiteFiles{}
+}
+
+type testSuiteFiles struct {
+ robolectric WritablePath
+}
+
+type TestSuiteModule interface {
+ Module
+ TestSuites() []string
+}
+
+func (t *testSuiteFiles) GenerateBuildActions(ctx SingletonContext) {
+ files := make(map[string]map[string]InstallPaths)
+
+ ctx.VisitAllModules(func(m Module) {
+ if tsm, ok := m.(TestSuiteModule); ok {
+ for _, testSuite := range tsm.TestSuites() {
+ if files[testSuite] == nil {
+ files[testSuite] = make(map[string]InstallPaths)
+ }
+ name := ctx.ModuleName(m)
+ files[testSuite][name] = append(files[testSuite][name], tsm.filesToInstall()...)
+ }
+ }
+ })
+
+ t.robolectric = robolectricTestSuite(ctx, files["robolectric-tests"])
+
+ ctx.Phony("robolectric-tests", t.robolectric)
+}
+
+func (t *testSuiteFiles) MakeVars(ctx MakeVarsContext) {
+ ctx.DistForGoal("robolectric-tests", t.robolectric)
+}
+
+func robolectricTestSuite(ctx SingletonContext, files map[string]InstallPaths) WritablePath {
+ var installedPaths InstallPaths
+ for _, module := range SortedStringKeys(files) {
+ installedPaths = append(installedPaths, files[module]...)
+ }
+ testCasesDir := pathForInstall(ctx, BuildOs, "testcases", false).ToMakePath()
+
+ outputFile := PathForOutput(ctx, "packaging", "robolectric-tests.zip")
+ rule := NewRuleBuilder()
+ rule.Command().BuiltTool(ctx, "soong_zip").
+ FlagWithOutput("-o ", outputFile).
+ FlagWithArg("-P ", "host/testcases").
+ FlagWithArg("-C ", testCasesDir.String()).
+ FlagWithRspFileInputList("-l ", installedPaths.Paths())
+ rule.Build(pctx, ctx, "robolectric_tests_zip", "robolectric-tests.zip")
+
+ return outputFile
+}
diff --git a/android/variable.go b/android/variable.go
index 2c8bd07..c1e1b42 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -308,8 +308,6 @@
BoardPlatPrivateSepolicyDirs []string `json:",omitempty"`
BoardSepolicyM4Defs []string `json:",omitempty"`
- BoardVndkRuntimeDisable *bool `json:",omitempty"`
-
VendorVars map[string]map[string]string `json:",omitempty"`
Ndk_abis *bool `json:",omitempty"`
@@ -346,6 +344,8 @@
InstallExtraFlattenedApexes *bool `json:",omitempty"`
BoardUsesRecoveryAsBoot *bool `json:",omitempty"`
+
+ BoardKernelBinaries []string `json:",omitempty"`
}
func boolPtr(v bool) *bool {
diff --git a/apex/androidmk.go b/apex/androidmk.go
index 7595238..5c6d6cc 100644
--- a/apex/androidmk.go
+++ b/apex/androidmk.go
@@ -50,6 +50,11 @@
return moduleNames
}
+ // b/162366062. Prevent GKI APEXes to emit make rules to avoid conflicts.
+ if strings.HasPrefix(apexName, "com.android.gki.") && apexType != flattenedApex {
+ return moduleNames
+ }
+
// b/140136207. When there are overriding APEXes for a VNDK APEX, the symbols file for the overridden
// APEX and the overriding APEX will have the same installation paths at /apex/com.android.vndk.v<ver>
// as their apexName will be the same. To avoid the path conflicts, skip installing the symbol files
@@ -82,9 +87,9 @@
var moduleName string
if linkToSystemLib {
- moduleName = fi.moduleName
+ moduleName = fi.androidMkModuleName
} else {
- moduleName = fi.moduleName + "." + apexBundleName + a.suffix
+ moduleName = fi.androidMkModuleName + "." + apexBundleName + a.suffix
}
if !android.InList(moduleName, moduleNames) {
@@ -105,9 +110,10 @@
fmt.Fprintln(w, "LOCAL_MODULE :=", moduleName)
// /apex/<apex_name>/{lib|framework|...}
pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex", apexName, fi.installDir)
+ var modulePath string
if apexType == flattenedApex {
// /system/apex/<name>/{lib|framework|...}
- modulePath := filepath.Join(a.installDir.ToMakePath().String(), apexBundleName, fi.installDir)
+ modulePath = filepath.Join(a.installDir.ToMakePath().String(), apexBundleName, fi.installDir)
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", modulePath)
if a.primaryApexType && !symbolFilesNotNeeded {
fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
@@ -115,9 +121,9 @@
if len(fi.symlinks) > 0 {
fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
}
- newDataPaths := []android.Path{}
+ newDataPaths := []android.DataPath{}
for _, path := range fi.dataPaths {
- dataOutPath := modulePath + ":" + path.Rel()
+ dataOutPath := modulePath + ":" + path.SrcPath.Rel()
if ok := seenDataOutPaths[dataOutPath]; !ok {
newDataPaths = append(newDataPaths, path)
seenDataOutPaths[dataOutPath] = true
@@ -131,6 +137,7 @@
fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", strings.Join(fi.module.NoticeFiles().Strings(), " "))
}
} else {
+ modulePath = pathWhenActivated
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
// For non-flattend APEXes, the merged notice file is attached to the APEX itself.
@@ -193,8 +200,13 @@
// we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
// we will have foo.apk.apk
fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.Stem(), ".apk"))
- if app, ok := fi.module.(*java.AndroidApp); ok && len(app.JniCoverageOutputs()) > 0 {
- fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", strings.Join(app.JniCoverageOutputs().Strings(), " "))
+ if app, ok := fi.module.(*java.AndroidApp); ok {
+ if jniCoverageOutputs := app.JniCoverageOutputs(); len(jniCoverageOutputs) > 0 {
+ fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", strings.Join(jniCoverageOutputs.Strings(), " "))
+ }
+ if jniLibSymbols := app.JNISymbolsInstalls(modulePath); len(jniLibSymbols) > 0 {
+ fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_SYMBOLS :=", jniLibSymbols.String())
+ }
}
fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_app_prebuilt.mk")
case appSet:
@@ -202,7 +214,8 @@
if !ok {
panic(fmt.Sprintf("Expected %s to be AndroidAppSet", fi.module))
}
- fmt.Fprintln(w, "LOCAL_APK_SET_MASTER_FILE :=", as.MasterFile())
+ fmt.Fprintln(w, "LOCAL_APK_SET_INSTALL_FILE :=", as.InstallFile())
+ fmt.Fprintln(w, "LOCAL_APKCERTS_FILE :=", as.APKCertsFile().String())
fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_android_app_set.mk")
case nativeSharedLib, nativeExecutable, nativeTest:
fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.Stem())
@@ -242,9 +255,9 @@
}
// m <module_name> will build <module_name>.<apex_name> as well.
- if fi.moduleName != moduleName && a.primaryApexType {
- fmt.Fprintln(w, ".PHONY: "+fi.moduleName)
- fmt.Fprintln(w, fi.moduleName+": "+moduleName)
+ if fi.androidMkModuleName != moduleName && a.primaryApexType {
+ fmt.Fprintf(w, ".PHONY: %s\n", fi.androidMkModuleName)
+ fmt.Fprintf(w, "%s: %s\n", fi.androidMkModuleName, moduleName)
}
}
return moduleNames
@@ -345,6 +358,10 @@
if apexType == imageApex {
fmt.Fprintln(w, "ALL_MODULES.$(my_register_name).BUNDLE :=", a.bundleModuleFile.String())
}
+ if len(a.lintReports) > 0 {
+ fmt.Fprintln(w, "ALL_MODULES.$(my_register_name).LINT_REPORTS :=",
+ strings.Join(a.lintReports.Strings(), " "))
+ }
if a.installedFilesFile != nil {
goal := "checkbuild"
diff --git a/apex/apex.go b/apex/apex.go
index b29017d..9905b79 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -669,7 +669,7 @@
}
func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
- ctx.TopDown("apex_deps", apexDepsMutator)
+ ctx.TopDown("apex_deps", apexDepsMutator).Parallel()
ctx.BottomUp("apex", apexMutator).Parallel()
ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
@@ -682,33 +682,43 @@
if !mctx.Module().Enabled() {
return
}
- var apexBundles []android.ApexInfo
- var directDep bool
- if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
- apexBundles = []android.ApexInfo{{
- ApexName: mctx.ModuleName(),
- MinSdkVersion: a.minSdkVersion(mctx),
- Updatable: a.Updatable(),
- }}
- directDep = true
- } else if am, ok := mctx.Module().(android.ApexModule); ok {
- apexBundles = am.ApexVariations()
- directDep = false
+ a, ok := mctx.Module().(*apexBundle)
+ if !ok || a.vndkApex {
+ return
+ }
+ apexInfo := android.ApexInfo{
+ ApexName: mctx.ModuleName(),
+ MinSdkVersion: a.minSdkVersion(mctx),
+ Updatable: a.Updatable(),
}
- if len(apexBundles) == 0 {
+ useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
+ excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
+ if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
+ mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
return
}
- cur := mctx.Module().(android.DepIsInSameApex)
-
- mctx.VisitDirectDeps(func(child android.Module) {
- depName := mctx.OtherModuleName(child)
- if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
- (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
- android.UpdateApexDependency(apexBundles, depName, directDep)
- am.BuildForApexes(apexBundles)
+ mctx.WalkDeps(func(child, parent android.Module) bool {
+ am, ok := child.(android.ApexModule)
+ if !ok || !am.CanHaveApexVariants() {
+ return false
}
+ if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) {
+ return false
+ }
+ if excludeVndkLibs {
+ if c, ok := child.(*cc.Module); ok && c.IsVndk() {
+ return false
+ }
+ }
+
+ depName := mctx.OtherModuleName(child)
+ // If the parent is apexBundle, this child is directly depended.
+ _, directDep := parent.(*apexBundle)
+ android.UpdateApexDependency(apexInfo, depName, directDep)
+ am.BuildForApex(apexInfo)
+ return true
})
}
@@ -1012,6 +1022,11 @@
// The minimum SDK version that this apex must be compatibile with.
Min_sdk_version *string
+
+ // If set true, VNDK libs are considered as stable libs and are not included in this apex.
+ // Should be only used in non-system apexes (e.g. vendor: true).
+ // Default is false.
+ Use_vndk_as_stable *bool
}
type apexTargetBundleProperties struct {
@@ -1137,15 +1152,17 @@
// apexFile represents a file in an APEX bundle
type apexFile struct {
- builtFile android.Path
- stem string
- moduleName string
- installDir string
- class apexFileClass
- module android.Module
+ builtFile android.Path
+ stem string
+ // Module name of `module` in AndroidMk. Note the generated AndroidMk module for
+ // apexFile is named something like <AndroidMk module name>.<apex name>[<apex suffix>]
+ androidMkModuleName string
+ installDir string
+ class apexFileClass
+ module android.Module
// list of symlinks that will be created in installDir that point to this apexFile
symlinks []string
- dataPaths android.Paths
+ dataPaths []android.DataPath
transitiveDep bool
moduleDir string
@@ -1154,19 +1171,20 @@
hostRequiredModuleNames []string
jacocoReportClassesFile android.Path // only for javalibs and apps
+ lintDepSets java.LintDepSets // only for javalibs and apps
certificate java.Certificate // only for apps
overriddenPackageName string // only for apps
isJniLib bool
}
-func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
+func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
ret := apexFile{
- builtFile: builtFile,
- moduleName: moduleName,
- installDir: installDir,
- class: class,
- module: module,
+ builtFile: builtFile,
+ androidMkModuleName: androidMkModuleName,
+ installDir: installDir,
+ class: class,
+ module: module,
}
if module != nil {
ret.moduleDir = ctx.OtherModuleDir(module)
@@ -1278,6 +1296,9 @@
// Struct holding the merged notice file paths in different formats
mergedNotices android.NoticeOutputs
+
+ // Optional list of lint report zip files for apexes that contain java or app modules
+ lintReports android.Paths
}
func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
@@ -1620,7 +1641,8 @@
}
fileToCopy := ccMod.OutputFile().Path()
- return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
+ androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
+ return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
}
func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
@@ -1630,7 +1652,8 @@
}
dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
fileToCopy := cc.OutputFile().Path()
- af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
+ androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
+ af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
af.symlinks = cc.Symlinks()
af.dataPaths = cc.DataPaths()
return af
@@ -1639,7 +1662,7 @@
func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
dirInApex := "bin"
fileToCopy := py.HostToolPath().Path()
- return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
+ return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
}
func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
dirInApex := "bin"
@@ -1658,25 +1681,33 @@
func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
dirInApex := filepath.Join("bin", sh.SubDir())
fileToCopy := sh.OutputFile()
- af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
+ af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
af.symlinks = sh.Symlinks()
return af
}
-type javaDependency interface {
+type javaModule interface {
+ android.Module
+ BaseModuleName() string
DexJarBuildPath() android.Path
JacocoReportClassesFile() android.Path
+ LintDepSets() java.LintDepSets
+
Stem() string
}
-func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaDependency, module android.Module) apexFile {
+var _ javaModule = (*java.Library)(nil)
+var _ javaModule = (*java.SdkLibrary)(nil)
+var _ javaModule = (*java.DexImport)(nil)
+var _ javaModule = (*java.SdkLibraryImport)(nil)
+
+func apexFileForJavaLibrary(ctx android.BaseModuleContext, module javaModule) apexFile {
dirInApex := "javalib"
- fileToCopy := lib.DexJarBuildPath()
- // Remove prebuilt_ if necessary so the source and prebuilt modules have the same name.
- name := strings.TrimPrefix(module.Name(), "prebuilt_")
- af := newApexFile(ctx, fileToCopy, name, dirInApex, javaSharedLib, module)
- af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
- af.stem = lib.Stem() + ".jar"
+ fileToCopy := module.DexJarBuildPath()
+ af := newApexFile(ctx, fileToCopy, module.BaseModuleName(), dirInApex, javaSharedLib, module)
+ af.jacocoReportClassesFile = module.JacocoReportClassesFile()
+ af.lintDepSets = module.LintDepSets()
+ af.stem = module.Stem() + ".jar"
return af
}
@@ -1699,6 +1730,7 @@
OutputFile() android.Path
JacocoReportClassesFile() android.Path
Certificate() java.Certificate
+ BaseModuleName() string
}) apexFile {
appDir := "app"
if aapp.Privileged() {
@@ -1706,7 +1738,7 @@
}
dirInApex := filepath.Join(appDir, aapp.InstallApkName())
fileToCopy := aapp.OutputFile()
- af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
+ af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
af.certificate = aapp.Certificate()
@@ -1812,7 +1844,8 @@
// Because APEXes targeting other than system/system_ext partitions
// can't set apex_available, we skip checks for these APEXes
- if ctx.SocSpecific() || ctx.DeviceSpecific() || ctx.ProductSpecific() {
+ if a.SocSpecific() || a.DeviceSpecific() ||
+ (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
return
}
@@ -2031,7 +2064,7 @@
case javaLibTag:
switch child.(type) {
case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport:
- af := apexFileForJavaLibrary(ctx, child.(javaDependency), child.(android.Module))
+ af := apexFileForJavaLibrary(ctx, child.(javaModule))
if !af.Ok() {
ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
return false
@@ -2054,7 +2087,7 @@
if ap.Privileged() {
appDir = "priv-app"
}
- af := newApexFile(ctx, ap.OutputFile(), ap.Name(),
+ af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
af.certificate = java.PresignedCertificate
filesInfo = append(filesInfo, af)
@@ -2112,7 +2145,7 @@
case android.PrebuiltDepTag:
// If the prebuilt is force disabled, remember to delete the prebuilt file
// that might have been installed in the previous builds
- if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
+ if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
a.prebuiltFileToDelete = prebuilt.InstallFilename()
}
}
@@ -2128,6 +2161,10 @@
// don't include it in this APEX
return false
}
+ if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
+ requireNativeLibs = append(requireNativeLibs, ":vndk")
+ return false
+ }
af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
af.transitiveDep = true
if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
@@ -2164,7 +2201,7 @@
// use the name of the generated test binary (`fileToCopy`) instead of the name
// of the original test module (`depName`, shared by all `test_per_src`
// variations of that module).
- af.moduleName = filepath.Base(af.builtFile.String())
+ af.androidMkModuleName = filepath.Base(af.builtFile.String())
// these are not considered transitive dep
af.transitiveDep = false
filesInfo = append(filesInfo, af)
@@ -2245,7 +2282,8 @@
// APEXes targeting other than system/system_ext partitions use vendor/product variants.
// So we can't link them to /system/lib libs which are core variants.
- if a.SocSpecific() || a.DeviceSpecific() || a.ProductSpecific() {
+ if a.SocSpecific() || a.DeviceSpecific() ||
+ (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
a.linkToSystemLib = false
}
@@ -2275,6 +2313,8 @@
a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
a.buildApexDependencyInfo(ctx)
+
+ a.buildLintReports(ctx)
}
// Enforce that Java deps of the apex are using stable SDKs to compile
diff --git a/apex/apex_test.go b/apex/apex_test.go
index f064338..d13ec5f 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -236,13 +236,15 @@
ctx.PreArchMutators(android.RegisterComponentsMutator)
ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
- cc.RegisterRequiredBuildComponentsForTest(ctx)
+ android.RegisterPrebuiltMutators(ctx)
- // Register this after the prebuilt mutators have been registered (in
- // cc.RegisterRequiredBuildComponentsForTest) to match what happens at runtime.
+ // Register these after the prebuilt mutators have been registered to match what
+ // happens at runtime.
ctx.PreArchMutators(android.RegisterVisibilityRuleGatherer)
ctx.PostDepsMutators(android.RegisterVisibilityRuleEnforcer)
+ cc.RegisterRequiredBuildComponentsForTest(ctx)
+
ctx.RegisterModuleType("cc_test", cc.TestFactory)
ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory)
ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory)
@@ -412,7 +414,14 @@
system_shared_libs: [],
static_executable: true,
stl: "none",
- apex_available: [ "myapex" ],
+ apex_available: [ "myapex", "com.android.gki.*" ],
+ }
+
+ apex {
+ name: "com.android.gki.fake",
+ binaries: ["foo"],
+ key: "myapex.key",
+ file_contexts: ":myapex-file_contexts",
}
cc_library_shared {
@@ -2201,6 +2210,63 @@
data.Custom(&builder, name, prefix, "", data)
androidMk := builder.String()
ensureContains(t, androidMk, `LOCAL_MODULE_PATH := /tmp/target/product/test_device/vendor/apex`)
+
+ apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
+ requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"])
+ ensureListNotContains(t, requireNativeLibs, ":vndk")
+}
+
+func TestVendorApex_use_vndk_as_stable(t *testing.T) {
+ ctx, _ := testApex(t, `
+ apex {
+ name: "myapex",
+ key: "myapex.key",
+ binaries: ["mybin"],
+ vendor: true,
+ use_vndk_as_stable: true,
+ }
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+ cc_binary {
+ name: "mybin",
+ vendor: true,
+ shared_libs: ["libvndk", "libvendor"],
+ }
+ cc_library {
+ name: "libvndk",
+ vndk: {
+ enabled: true,
+ },
+ vendor_available: true,
+ }
+ cc_library {
+ name: "libvendor",
+ vendor: true,
+ }
+ `)
+
+ vendorVariant := "android_vendor.VER_arm64_armv8-a"
+
+ ldRule := ctx.ModuleForTests("mybin", vendorVariant+"_myapex").Rule("ld")
+ libs := names(ldRule.Args["libFlags"])
+ // VNDK libs(libvndk/libc++) as they are
+ ensureListContains(t, libs, buildDir+"/.intermediates/libvndk/"+vendorVariant+"_shared/libvndk.so")
+ ensureListContains(t, libs, buildDir+"/.intermediates/libc++/"+vendorVariant+"_shared/libc++.so")
+ // non-stable Vendor libs as APEX variants
+ ensureListContains(t, libs, buildDir+"/.intermediates/libvendor/"+vendorVariant+"_shared_myapex/libvendor.so")
+
+ // VNDK libs are not included when use_vndk_as_stable: true
+ ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
+ "bin/mybin",
+ "lib64/libvendor.so",
+ })
+
+ apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
+ requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"])
+ ensureListContains(t, requireNativeLibs, ":vndk")
}
func TestAndroidMk_UseVendorRequired(t *testing.T) {
@@ -4384,11 +4450,11 @@
func TestApexAvailable_IndirectDep(t *testing.T) {
// libbbaz is an indirect dep
testApexError(t, `requires "libbaz" that is not available for the APEX. Dependency path:
-.*via tag apex\.dependencyTag.*"sharedLib".*
+.*via tag apex\.dependencyTag.*name:sharedLib.*
.*-> libfoo.*link:shared.*
-.*via tag cc\.DependencyTag.*"shared".*
+.*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.*
.*-> libbar.*link:shared.*
-.*via tag cc\.DependencyTag.*"shared".*
+.*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.*
.*-> libbaz.*link:shared.*`, `
apex {
name: "myapex",
@@ -5179,6 +5245,57 @@
ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file
}
+func TestSymlinksFromApexToSystemRequiredModuleNames(t *testing.T) {
+ ctx, config := testApex(t, `
+ apex {
+ name: "myapex",
+ key: "myapex.key",
+ native_shared_libs: ["mylib"],
+ }
+
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+
+ cc_library_shared {
+ name: "mylib",
+ srcs: ["mylib.cpp"],
+ shared_libs: ["myotherlib"],
+ system_shared_libs: [],
+ stl: "none",
+ apex_available: [
+ "myapex",
+ "//apex_available:platform",
+ ],
+ }
+
+ cc_prebuilt_library_shared {
+ name: "myotherlib",
+ srcs: ["prebuilt.so"],
+ system_shared_libs: [],
+ stl: "none",
+ apex_available: [
+ "myapex",
+ "//apex_available:platform",
+ ],
+ }
+ `)
+
+ apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
+ data := android.AndroidMkDataForTest(t, config, "", apexBundle)
+ var builder strings.Builder
+ data.Custom(&builder, apexBundle.BaseModuleName(), "TARGET_", "", data)
+ androidMk := builder.String()
+ // `myotherlib` is added to `myapex` as symlink
+ ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n")
+ ensureNotContains(t, androidMk, "LOCAL_MODULE := prebuilt_myotherlib.myapex\n")
+ ensureNotContains(t, androidMk, "LOCAL_MODULE := myotherlib.myapex\n")
+ // `myapex` should have `myotherlib` in its required line, not `prebuilt_myotherlib`
+ ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += mylib.myapex myotherlib apex_manifest.pb.myapex apex_pubkey.myapex\n")
+}
+
func TestApexWithJniLibs(t *testing.T) {
ctx, _ := testApex(t, `
apex {
@@ -5434,6 +5551,7 @@
ctx.RegisterModuleType("apex_key", ApexKeyFactory)
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
+ android.RegisterPrebuiltMutators(ctx)
cc.RegisterRequiredBuildComponentsForTest(ctx)
java.RegisterJavaBuildComponents(ctx)
java.RegisterSystemModulesBuildComponents(ctx)
@@ -5484,13 +5602,15 @@
}
func TestNoUpdatableJarsInBootImage(t *testing.T) {
-
var err string
var transform func(*dexpreopt.GlobalConfig)
+ config := android.TestArchConfig(buildDir, nil, "", nil)
+ ctx := android.PathContextForTesting(config)
+
t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) {
transform = func(config *dexpreopt.GlobalConfig) {
- config.ArtApexJars = []string{"com.android.art.something:some-art-lib"}
+ config.ArtApexJars = android.CreateConfiguredJarList(ctx, []string{"com.android.art.something:some-art-lib"})
}
testNoUpdatableJarsInBootImage(t, "", transform)
})
@@ -5498,7 +5618,7 @@
t.Run("updatable jar from ART apex in the framework boot image => error", func(t *testing.T) {
err = "module 'some-art-lib' from updatable apex 'com.android.art.something' is not allowed in the framework boot image"
transform = func(config *dexpreopt.GlobalConfig) {
- config.BootJars = []string{"com.android.art.something:some-art-lib"}
+ config.BootJars = android.CreateConfiguredJarList(ctx, []string{"com.android.art.something:some-art-lib"})
}
testNoUpdatableJarsInBootImage(t, err, transform)
})
@@ -5506,7 +5626,7 @@
t.Run("updatable jar from some other apex in the ART boot image => error", func(t *testing.T) {
err = "module 'some-updatable-apex-lib' from updatable apex 'some-updatable-apex' is not allowed in the ART boot image"
transform = func(config *dexpreopt.GlobalConfig) {
- config.ArtApexJars = []string{"some-updatable-apex:some-updatable-apex-lib"}
+ config.ArtApexJars = android.CreateConfiguredJarList(ctx, []string{"some-updatable-apex:some-updatable-apex-lib"})
}
testNoUpdatableJarsInBootImage(t, err, transform)
})
@@ -5514,7 +5634,7 @@
t.Run("non-updatable jar from some other apex in the ART boot image => error", func(t *testing.T) {
err = "module 'some-non-updatable-apex-lib' is not allowed in the ART boot image"
transform = func(config *dexpreopt.GlobalConfig) {
- config.ArtApexJars = []string{"some-non-updatable-apex:some-non-updatable-apex-lib"}
+ config.ArtApexJars = android.CreateConfiguredJarList(ctx, []string{"some-non-updatable-apex:some-non-updatable-apex-lib"})
}
testNoUpdatableJarsInBootImage(t, err, transform)
})
@@ -5522,14 +5642,14 @@
t.Run("updatable jar from some other apex in the framework boot image => error", func(t *testing.T) {
err = "module 'some-updatable-apex-lib' from updatable apex 'some-updatable-apex' is not allowed in the framework boot image"
transform = func(config *dexpreopt.GlobalConfig) {
- config.BootJars = []string{"some-updatable-apex:some-updatable-apex-lib"}
+ config.BootJars = android.CreateConfiguredJarList(ctx, []string{"some-updatable-apex:some-updatable-apex-lib"})
}
testNoUpdatableJarsInBootImage(t, err, transform)
})
t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) {
transform = func(config *dexpreopt.GlobalConfig) {
- config.BootJars = []string{"some-non-updatable-apex:some-non-updatable-apex-lib"}
+ config.BootJars = android.CreateConfiguredJarList(ctx, []string{"some-non-updatable-apex:some-non-updatable-apex-lib"})
}
testNoUpdatableJarsInBootImage(t, "", transform)
})
@@ -5537,7 +5657,7 @@
t.Run("nonexistent jar in the ART boot image => error", func(t *testing.T) {
err = "failed to find a dex jar path for module 'nonexistent'"
transform = func(config *dexpreopt.GlobalConfig) {
- config.ArtApexJars = []string{"platform:nonexistent"}
+ config.ArtApexJars = android.CreateConfiguredJarList(ctx, []string{"platform:nonexistent"})
}
testNoUpdatableJarsInBootImage(t, err, transform)
})
@@ -5545,7 +5665,7 @@
t.Run("nonexistent jar in the framework boot image => error", func(t *testing.T) {
err = "failed to find a dex jar path for module 'nonexistent'"
transform = func(config *dexpreopt.GlobalConfig) {
- config.BootJars = []string{"platform:nonexistent"}
+ config.BootJars = android.CreateConfiguredJarList(ctx, []string{"platform:nonexistent"})
}
testNoUpdatableJarsInBootImage(t, err, transform)
})
@@ -5553,14 +5673,14 @@
t.Run("platform jar in the ART boot image => error", func(t *testing.T) {
err = "module 'some-platform-lib' is not allowed in the ART boot image"
transform = func(config *dexpreopt.GlobalConfig) {
- config.ArtApexJars = []string{"platform:some-platform-lib"}
+ config.ArtApexJars = android.CreateConfiguredJarList(ctx, []string{"platform:some-platform-lib"})
}
testNoUpdatableJarsInBootImage(t, err, transform)
})
t.Run("platform jar in the framework boot image => ok", func(t *testing.T) {
transform = func(config *dexpreopt.GlobalConfig) {
- config.BootJars = []string{"platform:some-platform-lib"}
+ config.BootJars = android.CreateConfiguredJarList(ctx, []string{"platform:some-platform-lib"})
}
testNoUpdatableJarsInBootImage(t, "", transform)
})
diff --git a/apex/builder.go b/apex/builder.go
index 5fb9a5f..0a1ec3e 100644
--- a/apex/builder.go
+++ b/apex/builder.go
@@ -390,7 +390,7 @@
} else {
if fi.class == appSet {
copyCommands = append(copyCommands,
- fmt.Sprintf("unzip -q -d %s %s", destPathDir, fi.builtFile.String()))
+ fmt.Sprintf("unzip -qDD -d %s %s", destPathDir, fi.builtFile.String()))
} else {
copyCommands = append(copyCommands, "cp -f "+fi.builtFile.String()+" "+destPath)
}
@@ -403,16 +403,16 @@
}
for _, d := range fi.dataPaths {
// TODO(eakammer): This is now the third repetition of ~this logic for test paths, refactoring should be possible
- relPath := d.Rel()
- dataPath := d.String()
+ relPath := d.SrcPath.Rel()
+ dataPath := d.SrcPath.String()
if !strings.HasSuffix(dataPath, relPath) {
panic(fmt.Errorf("path %q does not end with %q", dataPath, relPath))
}
- dataDest := android.PathForModuleOut(ctx, "image"+suffix, fi.apexRelativePath(relPath)).String()
+ dataDest := android.PathForModuleOut(ctx, "image"+suffix, fi.apexRelativePath(relPath), d.RelativeInstallPath).String()
- copyCommands = append(copyCommands, "cp -f "+d.String()+" "+dataDest)
- implicitInputs = append(implicitInputs, d)
+ copyCommands = append(copyCommands, "cp -f "+d.SrcPath.String()+" "+dataDest)
+ implicitInputs = append(implicitInputs, d.SrcPath)
}
}
@@ -473,7 +473,7 @@
if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
executablePaths = append(executablePaths, pathInApex)
for _, d := range f.dataPaths {
- readOnlyPaths = append(readOnlyPaths, filepath.Join(f.installDir, d.Rel()))
+ readOnlyPaths = append(readOnlyPaths, filepath.Join(f.installDir, d.RelativeInstallPath, d.SrcPath.Rel()))
}
for _, s := range f.symlinks {
executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
@@ -815,3 +815,12 @@
},
})
}
+
+func (a *apexBundle) buildLintReports(ctx android.ModuleContext) {
+ depSetsBuilder := java.NewLintDepSetBuilder()
+ for _, fi := range a.filesInfo {
+ depSetsBuilder.Transitive(fi.lintDepSets)
+ }
+
+ a.lintReports = java.BuildModuleLintReportZips(ctx, depSetsBuilder.Build())
+}
diff --git a/apex/prebuilt.go b/apex/prebuilt.go
index bf574dc..d459f87 100644
--- a/apex/prebuilt.go
+++ b/apex/prebuilt.go
@@ -21,6 +21,7 @@
"android/soong/android"
"android/soong/java"
+
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -39,9 +40,55 @@
"abis", "allow-prereleased", "sdk-version")
)
+type prebuilt interface {
+ isForceDisabled() bool
+ InstallFilename() string
+}
+
+type prebuiltCommon struct {
+ prebuilt android.Prebuilt
+ properties prebuiltCommonProperties
+}
+
+type prebuiltCommonProperties struct {
+ ForceDisable bool `blueprint:"mutated"`
+}
+
+func (p *prebuiltCommon) Prebuilt() *android.Prebuilt {
+ return &p.prebuilt
+}
+
+func (p *prebuiltCommon) isForceDisabled() bool {
+ return p.properties.ForceDisable
+}
+
+func (p *prebuiltCommon) checkForceDisable(ctx android.ModuleContext) bool {
+ // If the device is configured to use flattened APEX, force disable the prebuilt because
+ // the prebuilt is a non-flattened one.
+ forceDisable := ctx.Config().FlattenApex()
+
+ // Force disable the prebuilts when we are doing unbundled build. We do unbundled build
+ // to build the prebuilts themselves.
+ forceDisable = forceDisable || ctx.Config().UnbundledBuild()
+
+ // Force disable the prebuilts when coverage is enabled.
+ forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled()
+ forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
+
+ // b/137216042 don't use prebuilts when address sanitizer is on
+ forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) ||
+ android.InList("hwaddress", ctx.Config().SanitizeDevice())
+
+ if forceDisable && p.prebuilt.SourceExists() {
+ p.properties.ForceDisable = true
+ return true
+ }
+ return false
+}
+
type Prebuilt struct {
android.ModuleBase
- prebuilt android.Prebuilt
+ prebuiltCommon
properties PrebuiltProperties
@@ -57,8 +104,7 @@
type PrebuiltProperties struct {
// the path to the prebuilt .apex file to import.
- Source string `blueprint:"mutated"`
- ForceDisable bool `blueprint:"mutated"`
+ Source string `blueprint:"mutated"`
Src *string
Arch struct {
@@ -93,10 +139,6 @@
return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
}
-func (p *Prebuilt) isForceDisabled() bool {
- return p.properties.ForceDisable
-}
-
func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
switch tag {
case "":
@@ -110,12 +152,8 @@
return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix)
}
-func (p *Prebuilt) Prebuilt() *android.Prebuilt {
- return &p.prebuilt
-}
-
func (p *Prebuilt) Name() string {
- return p.prebuilt.Name(p.ModuleBase.Name())
+ return p.prebuiltCommon.prebuilt.Name(p.ModuleBase.Name())
}
// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
@@ -128,27 +166,6 @@
}
func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
- // If the device is configured to use flattened APEX, force disable the prebuilt because
- // the prebuilt is a non-flattened one.
- forceDisable := ctx.Config().FlattenApex()
-
- // Force disable the prebuilts when we are doing unbundled build. We do unbundled build
- // to build the prebuilts themselves.
- forceDisable = forceDisable || ctx.Config().UnbundledBuild()
-
- // Force disable the prebuilts when coverage is enabled.
- forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled()
- forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
-
- // b/137216042 don't use prebuilts when address sanitizer is on
- forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) ||
- android.InList("hwaddress", ctx.Config().SanitizeDevice())
-
- if forceDisable && p.prebuilt.SourceExists() {
- p.properties.ForceDisable = true
- return
- }
-
// This is called before prebuilt_select and prebuilt_postdeps mutators
// The mutators requires that src to be set correctly for each arch so that
// arch variants are disabled when src is not provided for the arch.
@@ -177,10 +194,6 @@
}
func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
- if p.properties.ForceDisable {
- return
- }
-
// TODO(jungjw): Check the key validity.
p.inputApex = p.Prebuilt().SingleSourcePath(ctx)
p.installDir = android.PathForModuleInstall(ctx, "apex")
@@ -194,6 +207,12 @@
Input: p.inputApex,
Output: p.outputApex,
})
+
+ if p.prebuiltCommon.checkForceDisable(ctx) {
+ p.SkipInstall()
+ return
+ }
+
if p.installable() {
ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
}
@@ -227,7 +246,7 @@
type ApexSet struct {
android.ModuleBase
- prebuilt android.Prebuilt
+ prebuiltCommon
properties ApexSetProperties
@@ -270,12 +289,8 @@
return proptools.StringDefault(a.properties.Filename, a.BaseModuleName()+imageApexSuffix)
}
-func (a *ApexSet) Prebuilt() *android.Prebuilt {
- return &a.prebuilt
-}
-
func (a *ApexSet) Name() string {
- return a.prebuilt.Name(a.ModuleBase.Name())
+ return a.prebuiltCommon.prebuilt.Name(a.ModuleBase.Name())
}
func (a *ApexSet) Overrides() []string {
@@ -297,7 +312,7 @@
ctx.ModuleErrorf("filename should end in %s for apex_set", imageApexSuffix)
}
- apexSet := a.prebuilt.SingleSourcePath(ctx)
+ apexSet := a.prebuiltCommon.prebuilt.SingleSourcePath(ctx)
a.outputApex = android.PathForModuleOut(ctx, a.installFilename)
ctx.Build(pctx,
android.BuildParams{
@@ -311,6 +326,12 @@
"sdk-version": ctx.Config().PlatformSdkVersion(),
},
})
+
+ if a.prebuiltCommon.checkForceDisable(ctx) {
+ a.SkipInstall()
+ return
+ }
+
a.installDir = android.PathForModuleInstall(ctx, "apex")
if a.installable() {
ctx.InstallFile(a.installDir, a.installFilename, a.outputApex)
diff --git a/cc/Android.bp b/cc/Android.bp
index 9ece05f..831911e 100644
--- a/cc/Android.bp
+++ b/cc/Android.bp
@@ -19,6 +19,7 @@
"check.go",
"coverage.go",
"gen.go",
+ "image.go",
"linkable.go",
"lto.go",
"makevars.go",
diff --git a/cc/androidmk.go b/cc/androidmk.go
index 3f812c2..e91b40a 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -149,21 +149,25 @@
return []android.AndroidMkEntries{entries}
}
-func AndroidMkDataPaths(data android.Paths) []string {
+func AndroidMkDataPaths(data []android.DataPath) []string {
var testFiles []string
for _, d := range data {
- rel := d.Rel()
- path := d.String()
+ rel := d.SrcPath.Rel()
+ path := d.SrcPath.String()
if !strings.HasSuffix(path, rel) {
panic(fmt.Errorf("path %q does not end with %q", path, rel))
}
path = strings.TrimSuffix(path, rel)
- testFiles = append(testFiles, path+":"+rel)
+ testFileString := path + ":" + rel
+ if len(d.RelativeInstallPath) > 0 {
+ testFileString += ":" + d.RelativeInstallPath
+ }
+ testFiles = append(testFiles, testFileString)
}
return testFiles
}
-func androidMkWriteTestData(data android.Paths, ctx AndroidMkContext, entries *android.AndroidMkEntries) {
+func androidMkWriteTestData(data []android.DataPath, ctx AndroidMkContext, entries *android.AndroidMkEntries) {
testFiles := AndroidMkDataPaths(data)
if len(testFiles) > 0 {
entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
@@ -357,8 +361,11 @@
entries.SetBool("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", true)
}
})
-
- androidMkWriteTestData(benchmark.data, ctx, entries)
+ dataPaths := []android.DataPath{}
+ for _, srcPath := range benchmark.data {
+ dataPaths = append(dataPaths, android.DataPath{SrcPath: srcPath})
+ }
+ androidMkWriteTestData(dataPaths, ctx, entries)
}
func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
diff --git a/cc/binary_sdk_member.go b/cc/binary_sdk_member.go
index 372a72e..337de55 100644
--- a/cc/binary_sdk_member.go
+++ b/cc/binary_sdk_member.go
@@ -29,7 +29,8 @@
var ccBinarySdkMemberType = &binarySdkMemberType{
SdkMemberTypeBase: android.SdkMemberTypeBase{
- PropertyName: "native_binaries",
+ PropertyName: "native_binaries",
+ HostOsDependent: true,
},
}
@@ -140,10 +141,6 @@
}
func (p *nativeBinaryInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
- if p.Compile_multilib != "" {
- propertySet.AddProperty("compile_multilib", p.Compile_multilib)
- }
-
builder := ctx.SnapshotBuilder()
if p.outputFile != nil {
propertySet.AddProperty("srcs", []string{nativeBinaryPathFor(*p)})
diff --git a/cc/cc.go b/cc/cc.go
index 0d5b6bd..4b36218 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -425,44 +425,130 @@
XrefCcFiles() android.Paths
}
+type libraryDependencyKind int
+
+const (
+ headerLibraryDependency = iota
+ sharedLibraryDependency
+ staticLibraryDependency
+)
+
+func (k libraryDependencyKind) String() string {
+ switch k {
+ case headerLibraryDependency:
+ return "headerLibraryDependency"
+ case sharedLibraryDependency:
+ return "sharedLibraryDependency"
+ case staticLibraryDependency:
+ return "staticLibraryDependency"
+ default:
+ panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
+ }
+}
+
+type libraryDependencyOrder int
+
+const (
+ earlyLibraryDependency = -1
+ normalLibraryDependency = 0
+ lateLibraryDependency = 1
+)
+
+func (o libraryDependencyOrder) String() string {
+ switch o {
+ case earlyLibraryDependency:
+ return "earlyLibraryDependency"
+ case normalLibraryDependency:
+ return "normalLibraryDependency"
+ case lateLibraryDependency:
+ return "lateLibraryDependency"
+ default:
+ panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
+ }
+}
+
+// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
+// tags that have a set of predefined tag objects that are reused for each dependency, a
+// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
+// That means that comparing a libraryDependencyTag for equality will only be equal if all
+// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
+// then check individual metadata fields instead.
+type libraryDependencyTag struct {
+ blueprint.BaseDependencyTag
+
+ // These are exported so that fmt.Printf("%#v") can call their String methods.
+ Kind libraryDependencyKind
+ Order libraryDependencyOrder
+
+ wholeStatic bool
+
+ reexportFlags bool
+ explicitlyVersioned bool
+ dataLib bool
+ ndk bool
+
+ staticUnwinder bool
+
+ makeSuffix string
+}
+
+// header returns true if the libraryDependencyTag is tagging a header lib dependency.
+func (d libraryDependencyTag) header() bool {
+ return d.Kind == headerLibraryDependency
+}
+
+// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
+func (d libraryDependencyTag) shared() bool {
+ return d.Kind == sharedLibraryDependency
+}
+
+// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
+func (d libraryDependencyTag) static() bool {
+ return d.Kind == staticLibraryDependency
+}
+
+// dependencyTag is used for tagging miscellanous dependency types that don't fit into
+// libraryDependencyTag. Each tag object is created globally and reused for multiple
+// dependencies (although since the object contains no references, assigning a tag to a
+// variable and modifying it will not modify the original). Users can compare the tag
+// returned by ctx.OtherModuleDependencyTag against the global original
+type dependencyTag struct {
+ blueprint.BaseDependencyTag
+ name string
+}
+
var (
- dataLibDepTag = DependencyTag{Name: "data_lib", Library: true, Shared: true}
- sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
- earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
- lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
- staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
- lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
- staticUnwinderDepTag = DependencyTag{Name: "static unwinder", Library: true}
- wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
- headerDepTag = DependencyTag{Name: "header", Library: true}
- headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
- genSourceDepTag = DependencyTag{Name: "gen source"}
- genHeaderDepTag = DependencyTag{Name: "gen header"}
- genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
- objDepTag = DependencyTag{Name: "obj"}
- linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
- dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
- reuseObjTag = DependencyTag{Name: "reuse objects"}
- staticVariantTag = DependencyTag{Name: "static variant"}
- ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
- ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
- vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
- runtimeDepTag = DependencyTag{Name: "runtime lib"}
- testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
+ genSourceDepTag = dependencyTag{name: "gen source"}
+ genHeaderDepTag = dependencyTag{name: "gen header"}
+ genHeaderExportDepTag = dependencyTag{name: "gen header export"}
+ objDepTag = dependencyTag{name: "obj"}
+ linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
+ dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
+ reuseObjTag = dependencyTag{name: "reuse objects"}
+ staticVariantTag = dependencyTag{name: "static variant"}
+ vndkExtDepTag = dependencyTag{name: "vndk extends"}
+ dataLibDepTag = dependencyTag{name: "data lib"}
+ runtimeDepTag = dependencyTag{name: "runtime lib"}
+ testPerSrcDepTag = dependencyTag{name: "test_per_src"}
)
func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
- ccDepTag, ok := depTag.(DependencyTag)
- return ok && ccDepTag.Shared
+ ccLibDepTag, ok := depTag.(libraryDependencyTag)
+ return ok && ccLibDepTag.shared()
+}
+
+func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
+ ccLibDepTag, ok := depTag.(libraryDependencyTag)
+ return ok && ccLibDepTag.static()
}
func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
- ccDepTag, ok := depTag.(DependencyTag)
+ ccDepTag, ok := depTag.(dependencyTag)
return ok && ccDepTag == runtimeDepTag
}
func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
- ccDepTag, ok := depTag.(DependencyTag)
+ ccDepTag, ok := depTag.(dependencyTag)
return ok && ccDepTag == testPerSrcDepTag
}
@@ -941,48 +1027,6 @@
return ""
}
-// Returns true only when this module is configured to have core, product and vendor
-// variants.
-func (c *Module) HasVendorVariant() bool {
- return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
-}
-
-const (
- // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
- // against the VNDK.
- VendorVariationPrefix = "vendor."
-
- // ProductVariationPrefix is the variant prefix used for /product code that compiles
- // against the VNDK.
- ProductVariationPrefix = "product."
-)
-
-// Returns true if the module is "product" variant. Usually these modules are installed in /product
-func (c *Module) inProduct() bool {
- return c.Properties.ImageVariationPrefix == ProductVariationPrefix
-}
-
-// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
-func (c *Module) inVendor() bool {
- return c.Properties.ImageVariationPrefix == VendorVariationPrefix
-}
-
-func (c *Module) InRamdisk() bool {
- return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
-}
-
-func (c *Module) InRecovery() bool {
- return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
-}
-
-func (c *Module) OnlyInRamdisk() bool {
- return c.ModuleBase.InstallInRamdisk()
-}
-
-func (c *Module) OnlyInRecovery() bool {
- return c.ModuleBase.InstallInRecovery()
-}
-
func (c *Module) IsStubs() bool {
if library, ok := c.linker.(*libraryDecorator); ok {
return library.buildStubs()
@@ -1090,16 +1134,6 @@
moduleContextImpl
}
-func (ctx *moduleContext) ProductSpecific() bool {
- return ctx.ModuleContext.ProductSpecific() ||
- (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
-}
-
-func (ctx *moduleContext) SocSpecific() bool {
- return ctx.ModuleContext.SocSpecific() ||
- (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
-}
-
type moduleContextImpl struct {
mod *Module
ctx BaseModuleContext
@@ -1195,22 +1229,6 @@
return ctx.mod.MustUseVendorVariant()
}
-func (ctx *moduleContextImpl) inProduct() bool {
- return ctx.mod.inProduct()
-}
-
-func (ctx *moduleContextImpl) inVendor() bool {
- return ctx.mod.inVendor()
-}
-
-func (ctx *moduleContextImpl) inRamdisk() bool {
- return ctx.mod.InRamdisk()
-}
-
-func (ctx *moduleContextImpl) inRecovery() bool {
- return ctx.mod.InRecovery()
-}
-
// Check whether ABI dumps should be created for this module.
func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
@@ -1401,9 +1419,9 @@
return ok && test.isAllTestsVariation()
}
-func (c *Module) DataPaths() android.Paths {
+func (c *Module) DataPaths() []android.DataPath {
if p, ok := c.installer.(interface {
- dataPaths() android.Paths
+ dataPaths() []android.DataPath
}); ok {
return p.dataPaths()
}
@@ -1859,9 +1877,9 @@
vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
for _, lib := range deps.HeaderLibs {
- depTag := headerDepTag
+ depTag := libraryDependencyTag{Kind: headerLibraryDependency}
if inList(lib, deps.ReexportHeaderLibHeaders) {
- depTag = headerExportDepTag
+ depTag.reexportFlags = true
}
lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
@@ -1884,7 +1902,7 @@
vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
for _, lib := range deps.WholeStaticLibs {
- depTag := wholeStaticDepTag
+ depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
if impl, ok := syspropImplLibraries[lib]; ok {
lib = impl
}
@@ -1897,9 +1915,9 @@
}
for _, lib := range deps.StaticLibs {
- depTag := StaticDepTag
+ depTag := libraryDependencyTag{Kind: staticLibraryDependency}
if inList(lib, deps.ReexportStaticLibHeaders) {
- depTag = staticExportDepTag
+ depTag.reexportFlags = true
}
if impl, ok := syspropImplLibraries[lib]; ok {
@@ -1917,24 +1935,26 @@
// so that native libraries/binaries are linked with static unwinder
// because Q libc doesn't have unwinder APIs
if deps.StaticUnwinderIfLegacy {
+ depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
actx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "link", Variation: "static"},
- }, staticUnwinderDepTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
+ }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
}
for _, lib := range deps.LateStaticLibs {
+ depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
actx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "link", Variation: "static"},
- }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
+ }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
}
- addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
+ addSharedLibDependencies := func(depTag libraryDependencyTag, name string, version string) {
var variations []blueprint.Variation
variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
if version != "" && VersionVariantAvailable(c) {
// Version is explicitly specified. i.e. libFoo#30
variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
- depTag.ExplicitlyVersioned = true
+ depTag.explicitlyVersioned = true
}
actx.AddVariationDependencies(variations, depTag, name)
@@ -1956,12 +1976,9 @@
var sharedLibNames []string
for _, lib := range deps.SharedLibs {
- depTag := SharedDepTag
- if c.static() {
- depTag = SharedFromStaticDepTag
- }
+ depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
if inList(lib, deps.ReexportSharedLibHeaders) {
- depTag = sharedExportDepTag
+ depTag.reexportFlags = true
}
if impl, ok := syspropImplLibraries[lib]; ok {
@@ -1981,7 +1998,8 @@
// linking against both the stubs lib and the non-stubs lib at the same time.
continue
}
- addSharedLibDependencies(lateSharedDepTag, lib, "")
+ depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
+ addSharedLibDependencies(depTag, lib, "")
}
actx.AddVariationDependencies([]blueprint.Variation{
@@ -2020,10 +2038,14 @@
}
version := ctx.sdkVersion()
+
+ ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
actx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "ndk_api", Variation: version},
{Mutator: "link", Variation: "shared"},
}, ndkStubDepTag, variantNdkLibs...)
+
+ ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
actx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "ndk_api", Variation: version},
{Mutator: "link", Variation: "shared"},
@@ -2047,7 +2069,19 @@
// Whether a module can link to another module, taking into
// account NDK linking.
-func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
+func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface,
+ tag blueprint.DependencyTag) {
+
+ switch t := tag.(type) {
+ case dependencyTag:
+ if t != vndkExtDepTag {
+ return
+ }
+ case libraryDependencyTag:
+ default:
+ return
+ }
+
if from.Module().Target().Os != android.Android {
// Host code is not restricted
return
@@ -2205,8 +2239,6 @@
directStaticDeps := []LinkableInterface{}
directSharedDeps := []LinkableInterface{}
- vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
-
reexportExporter := func(exporter exportedFlagsProducer) {
depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
@@ -2215,6 +2247,19 @@
depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
}
+ // For the dependency from platform to apex, use the latest stubs
+ c.apexSdkVersion = android.FutureApiLevel
+ if !c.IsForPlatform() {
+ c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
+ }
+
+ if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
+ // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
+ // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
+ // (b/144430859)
+ c.apexSdkVersion = android.FutureApiLevel
+ }
+
ctx.VisitDirectDeps(func(dep android.Module) {
depName := ctx.OtherModuleName(dep)
depTag := ctx.OtherModuleDependencyTag(dep)
@@ -2303,52 +2348,24 @@
}
}
- // For the dependency from platform to apex, use the latest stubs
- c.apexSdkVersion = android.FutureApiLevel
- if !c.IsForPlatform() {
- c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
- }
+ checkLinkType(ctx, c, ccDep, depTag)
- if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
- // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
- // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
- // (b/144430859)
- c.apexSdkVersion = android.FutureApiLevel
- }
+ linkFile := ccDep.OutputFile()
- if depTag == staticUnwinderDepTag {
- // Use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
- if c.apexSdkVersion <= android.SdkVersion_Android10 {
- depTag = StaticDepTag
- } else {
+ if libDepTag, ok := depTag.(libraryDependencyTag); ok {
+ // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
+ if libDepTag.staticUnwinder && c.apexSdkVersion > android.SdkVersion_Android10 {
return
}
- }
- // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
- // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
- // won't be matched to SharedDepTag and lateSharedDepTag.
- explicitlyVersioned := false
- if t, ok := depTag.(DependencyTag); ok {
- explicitlyVersioned = t.ExplicitlyVersioned
- t.ExplicitlyVersioned = false
- depTag = t
- }
-
- if t, ok := depTag.(DependencyTag); ok && t.Library {
- depIsStatic := false
- switch depTag {
- case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
- depIsStatic = true
- }
- if ccDep.CcLibrary() && !depIsStatic {
+ if ccDep.CcLibrary() && !libDepTag.static() {
depIsStubs := ccDep.BuildStubs()
depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
var useThisDep bool
- if depIsStubs && explicitlyVersioned {
+ if depIsStubs && libDepTag.explicitlyVersioned {
// Always respect dependency to the versioned stubs (i.e. libX#10)
useThisDep = true
} else if !depHasStubs {
@@ -2380,7 +2397,7 @@
}
// when to use (unspecified) stubs, check min_sdk_version and choose the right one
- if useThisDep && depIsStubs && !explicitlyVersioned {
+ if useThisDep && depIsStubs && !libDepTag.explicitlyVersioned {
versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
if err != nil {
ctx.OtherModuleErrorf(dep, err.Error())
@@ -2425,7 +2442,7 @@
depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
- if t.ReexportFlags {
+ if libDepTag.reexportFlags {
reexportExporter(i)
// Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
// Re-exported shared library headers must be included as well since they can help us with type information
@@ -2437,210 +2454,178 @@
}
}
}
- checkLinkType(ctx, c, ccDep, t)
- }
- var ptr *android.Paths
- var depPtr *android.Paths
+ var ptr *android.Paths
+ var depPtr *android.Paths
- linkFile := ccDep.OutputFile()
- depFile := android.OptionalPath{}
+ depFile := android.OptionalPath{}
- switch depTag {
- case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
- ptr = &depPaths.SharedLibs
- depPtr = &depPaths.SharedLibsDeps
- depFile = ccDep.Toc()
- directSharedDeps = append(directSharedDeps, ccDep)
-
- case earlySharedDepTag:
- ptr = &depPaths.EarlySharedLibs
- depPtr = &depPaths.EarlySharedLibsDeps
- depFile = ccDep.Toc()
- directSharedDeps = append(directSharedDeps, ccDep)
- case lateSharedDepTag, ndkLateStubDepTag:
- ptr = &depPaths.LateSharedLibs
- depPtr = &depPaths.LateSharedLibsDeps
- depFile = ccDep.Toc()
- case StaticDepTag, staticExportDepTag:
- ptr = nil
- directStaticDeps = append(directStaticDeps, ccDep)
- case lateStaticDepTag:
- ptr = &depPaths.LateStaticLibs
- case wholeStaticDepTag:
- ptr = &depPaths.WholeStaticLibs
- if !ccDep.CcLibraryInterface() || !ccDep.Static() {
- ctx.ModuleErrorf("module %q not a static library", depName)
- return
- }
-
- // Because the static library objects are included, this only makes sense
- // in the context of proper cc.Modules.
- if ccWholeStaticLib, ok := ccDep.(*Module); ok {
- staticLib := ccWholeStaticLib.linker.(libraryInterface)
- if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
- postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
- for i := range missingDeps {
- missingDeps[i] += postfix
- }
- ctx.AddMissingDependencies(missingDeps)
+ switch {
+ case libDepTag.header():
+ // nothing
+ case libDepTag.shared():
+ ptr = &depPaths.SharedLibs
+ switch libDepTag.Order {
+ case earlyLibraryDependency:
+ ptr = &depPaths.EarlySharedLibs
+ depPtr = &depPaths.EarlySharedLibsDeps
+ case normalLibraryDependency:
+ ptr = &depPaths.SharedLibs
+ depPtr = &depPaths.SharedLibsDeps
+ directSharedDeps = append(directSharedDeps, ccDep)
+ case lateLibraryDependency:
+ ptr = &depPaths.LateSharedLibs
+ depPtr = &depPaths.LateSharedLibsDeps
+ default:
+ panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
}
- if _, ok := ccWholeStaticLib.linker.(prebuiltLinkerInterface); ok {
- depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
- } else {
- depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
- }
- } else {
- ctx.ModuleErrorf(
- "non-cc.Modules cannot be included as whole static libraries.", depName)
- return
- }
- case headerDepTag:
- // Nothing
- case objDepTag:
- depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
- case CrtBeginDepTag:
- depPaths.CrtBegin = linkFile
- case CrtEndDepTag:
- depPaths.CrtEnd = linkFile
- case dynamicLinkerDepTag:
- depPaths.DynamicLinker = linkFile
- }
-
- switch depTag {
- case StaticDepTag, staticExportDepTag, lateStaticDepTag:
- if !ccDep.CcLibraryInterface() || !ccDep.Static() {
- ctx.ModuleErrorf("module %q not a static library", depName)
- return
- }
-
- // When combining coverage files for shared libraries and executables, coverage files
- // in static libraries act as if they were whole static libraries. The same goes for
- // source based Abi dump files.
- if c, ok := ccDep.(*Module); ok {
- staticLib := c.linker.(libraryInterface)
- depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
- staticLib.objs().coverageFiles...)
- depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
- staticLib.objs().sAbiDumpFiles...)
- } else if c, ok := ccDep.(LinkableInterface); ok {
- // Handle non-CC modules here
- depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
- c.CoverageFiles()...)
- }
- }
-
- if ptr != nil {
- if !linkFile.Valid() {
- if !ctx.Config().AllowMissingDependencies() {
- ctx.ModuleErrorf("module %q missing output file", depName)
- } else {
- ctx.AddMissingDependencies([]string{depName})
- }
- return
- }
- *ptr = append(*ptr, linkFile.Path())
- }
-
- if depPtr != nil {
- dep := depFile
- if !dep.Valid() {
- dep = linkFile
- }
- *depPtr = append(*depPtr, dep.Path())
- }
-
- vendorSuffixModules := vendorSuffixModules(ctx.Config())
-
- baseLibName := func(depName string) string {
- libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
- libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
- libName = strings.TrimPrefix(libName, "prebuilt_")
- return libName
- }
-
- makeLibName := func(depName string) string {
- libName := baseLibName(depName)
- isLLndk := isLlndkLibrary(libName, ctx.Config())
- isVendorPublicLib := inList(libName, *vendorPublicLibraries)
- bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
-
- if c, ok := ccDep.(*Module); ok {
- // Use base module name for snapshots when exporting to Makefile.
- if c.isSnapshotPrebuilt() {
- baseName := c.BaseModuleName()
-
- if c.IsVndk() {
- return baseName + ".vendor"
+ depFile = ccDep.Toc()
+ case libDepTag.static():
+ if libDepTag.wholeStatic {
+ ptr = &depPaths.WholeStaticLibs
+ if !ccDep.CcLibraryInterface() || !ccDep.Static() {
+ ctx.ModuleErrorf("module %q not a static library", depName)
+ return
}
- if vendorSuffixModules[baseName] {
- return baseName + ".vendor"
+ // Because the static library objects are included, this only makes sense
+ // in the context of proper cc.Modules.
+ if ccWholeStaticLib, ok := ccDep.(*Module); ok {
+ staticLib := ccWholeStaticLib.linker.(libraryInterface)
+ if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
+ postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
+ for i := range missingDeps {
+ missingDeps[i] += postfix
+ }
+ ctx.AddMissingDependencies(missingDeps)
+ }
+ if _, ok := ccWholeStaticLib.linker.(prebuiltLinkerInterface); ok {
+ depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
+ } else {
+ depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
+ }
} else {
- return baseName
+ ctx.ModuleErrorf(
+ "non-cc.Modules cannot be included as whole static libraries.", depName)
+ return
+ }
+
+ } else {
+ switch libDepTag.Order {
+ case earlyLibraryDependency:
+ panic(fmt.Errorf("early static libs not suppported"))
+ case normalLibraryDependency:
+ // static dependencies will be handled separately so they can be ordered
+ // using transitive dependencies.
+ ptr = nil
+ directStaticDeps = append(directStaticDeps, ccDep)
+ case lateLibraryDependency:
+ ptr = &depPaths.LateStaticLibs
+ default:
+ panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
}
}
}
- if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
- // The vendor module is a no-vendor-variant VNDK library. Depend on the
- // core module instead.
- return libName
- } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
- // The vendor module in Make will have been renamed to not conflict with the core
- // module, so update the dependency name here accordingly.
- return libName + c.getNameSuffixWithVndkVersion(ctx)
- } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
- return libName + vendorPublicLibrarySuffix
- } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
- return libName + ramdiskSuffix
- } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
- return libName + recoverySuffix
- } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
- return libName + nativeBridgeSuffix
- } else {
- return libName
- }
- }
+ if libDepTag.static() && !libDepTag.wholeStatic {
+ if !ccDep.CcLibraryInterface() || !ccDep.Static() {
+ ctx.ModuleErrorf("module %q not a static library", depName)
+ return
+ }
- // Export the shared libs to Make.
- switch depTag {
- case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
- if ccDep.CcLibrary() {
- if ccDep.BuildStubs() && android.InAnyApex(depName) {
- // Add the dependency to the APEX(es) providing the library so that
- // m <module> can trigger building the APEXes as well.
- for _, an := range android.GetApexesForModule(depName) {
- c.Properties.ApexesProvidingSharedLibs = append(
- c.Properties.ApexesProvidingSharedLibs, an)
- }
+ // When combining coverage files for shared libraries and executables, coverage files
+ // in static libraries act as if they were whole static libraries. The same goes for
+ // source based Abi dump files.
+ if c, ok := ccDep.(*Module); ok {
+ staticLib := c.linker.(libraryInterface)
+ depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
+ staticLib.objs().coverageFiles...)
+ depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
+ staticLib.objs().sAbiDumpFiles...)
+ } else if c, ok := ccDep.(LinkableInterface); ok {
+ // Handle non-CC modules here
+ depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
+ c.CoverageFiles()...)
}
}
- // Note: the order of libs in this list is not important because
- // they merely serve as Make dependencies and do not affect this lib itself.
- c.Properties.AndroidMkSharedLibs = append(
- c.Properties.AndroidMkSharedLibs, makeLibName(depName))
- // Record baseLibName for snapshots.
- c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
- case ndkStubDepTag, ndkLateStubDepTag:
- c.Properties.AndroidMkSharedLibs = append(
- c.Properties.AndroidMkSharedLibs,
- depName+"."+ccDep.ApiLevel())
- case StaticDepTag, staticExportDepTag, lateStaticDepTag:
- c.Properties.AndroidMkStaticLibs = append(
- c.Properties.AndroidMkStaticLibs, makeLibName(depName))
- case runtimeDepTag:
- c.Properties.AndroidMkRuntimeLibs = append(
- c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
- // Record baseLibName for snapshots.
- c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
- case wholeStaticDepTag:
- c.Properties.AndroidMkWholeStaticLibs = append(
- c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
- case headerDepTag:
- c.Properties.AndroidMkHeaderLibs = append(
- c.Properties.AndroidMkHeaderLibs, makeLibName(depName))
+ if ptr != nil {
+ if !linkFile.Valid() {
+ if !ctx.Config().AllowMissingDependencies() {
+ ctx.ModuleErrorf("module %q missing output file", depName)
+ } else {
+ ctx.AddMissingDependencies([]string{depName})
+ }
+ return
+ }
+ *ptr = append(*ptr, linkFile.Path())
+ }
+
+ if depPtr != nil {
+ dep := depFile
+ if !dep.Valid() {
+ dep = linkFile
+ }
+ *depPtr = append(*depPtr, dep.Path())
+ }
+
+ makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
+ switch {
+ case libDepTag.header():
+ // TODO(ccross): The reexportFlags check is there to maintain previous
+ // behavior when adding libraryDependencyTag and should be removed.
+ if !libDepTag.reexportFlags {
+ c.Properties.AndroidMkHeaderLibs = append(
+ c.Properties.AndroidMkHeaderLibs, makeLibName)
+ }
+ case libDepTag.shared():
+ if ccDep.CcLibrary() {
+ if ccDep.BuildStubs() && android.InAnyApex(depName) {
+ // Add the dependency to the APEX(es) providing the library so that
+ // m <module> can trigger building the APEXes as well.
+ for _, an := range android.GetApexesForModule(depName) {
+ c.Properties.ApexesProvidingSharedLibs = append(
+ c.Properties.ApexesProvidingSharedLibs, an)
+ }
+ }
+ }
+
+ // Note: the order of libs in this list is not important because
+ // they merely serve as Make dependencies and do not affect this lib itself.
+ // TODO(ccross): The reexportFlags, order and ndk checks are there to
+ // maintain previous behavior when adding libraryDependencyTag and
+ // should be removed.
+ if !c.static() || libDepTag.reexportFlags || libDepTag.Order == lateLibraryDependency || libDepTag.ndk {
+ c.Properties.AndroidMkSharedLibs = append(
+ c.Properties.AndroidMkSharedLibs, makeLibName)
+ }
+ // Record baseLibName for snapshots.
+ c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
+ case libDepTag.static():
+ if libDepTag.wholeStatic {
+ c.Properties.AndroidMkWholeStaticLibs = append(
+ c.Properties.AndroidMkWholeStaticLibs, makeLibName)
+ } else {
+ c.Properties.AndroidMkStaticLibs = append(
+ c.Properties.AndroidMkStaticLibs, makeLibName)
+ }
+ }
+ } else {
+ switch depTag {
+ case runtimeDepTag:
+ c.Properties.AndroidMkRuntimeLibs = append(
+ c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
+ // Record baseLibName for snapshots.
+ c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
+ case objDepTag:
+ depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
+ case CrtBeginDepTag:
+ depPaths.CrtBegin = linkFile
+ case CrtEndDepTag:
+ depPaths.CrtEnd = linkFile
+ case dynamicLinkerDepTag:
+ depPaths.DynamicLinker = linkFile
+ }
}
})
@@ -2665,6 +2650,61 @@
return depPaths
}
+// baseLibName trims known prefixes and suffixes
+func baseLibName(depName string) string {
+ libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
+ libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
+ libName = strings.TrimPrefix(libName, "prebuilt_")
+ return libName
+}
+
+func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
+ vendorSuffixModules := vendorSuffixModules(ctx.Config())
+ vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
+
+ libName := baseLibName(depName)
+ isLLndk := isLlndkLibrary(libName, ctx.Config())
+ isVendorPublicLib := inList(libName, *vendorPublicLibraries)
+ bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
+
+ if c, ok := ccDep.(*Module); ok {
+ // Use base module name for snapshots when exporting to Makefile.
+ if c.isSnapshotPrebuilt() {
+ baseName := c.BaseModuleName()
+
+ if c.IsVndk() {
+ return baseName + ".vendor"
+ }
+
+ if vendorSuffixModules[baseName] {
+ return baseName + ".vendor"
+ } else {
+ return baseName
+ }
+ }
+ }
+
+ if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
+ // The vendor module is a no-vendor-variant VNDK library. Depend on the
+ // core module instead.
+ return libName
+ } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
+ // The vendor module in Make will have been renamed to not conflict with the core
+ // module, so update the dependency name here accordingly.
+ return libName + c.getNameSuffixWithVndkVersion(ctx)
+ } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
+ return libName + vendorPublicLibrarySuffix
+ } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
+ return libName + ramdiskSuffix
+ } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
+ return libName + recoverySuffix
+ } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
+ return libName + nativeBridgeSuffix
+ } else {
+ return libName
+ }
+}
+
func (c *Module) InstallInData() bool {
if c.installer == nil {
return false
@@ -2876,26 +2916,30 @@
}
func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
- if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
- if cc, ok := dep.(*Module); ok {
- if cc.HasStubsVariants() {
- if depTag.Shared && depTag.Library {
- // dynamic dep to a stubs lib crosses APEX boundary
- return false
- }
- if IsRuntimeDepTag(depTag) {
- // runtime dep to a stubs lib also crosses APEX boundary
- return false
- }
+ depTag := ctx.OtherModuleDependencyTag(dep)
+ libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
+
+ if cc, ok := dep.(*Module); ok {
+ if cc.HasStubsVariants() {
+ if isLibDepTag && libDepTag.shared() {
+ // dynamic dep to a stubs lib crosses APEX boundary
+ return false
}
- if depTag.FromStatic {
- // shared_lib dependency from a static lib is considered as crossing
- // the APEX boundary because the dependency doesn't actually is
- // linked; the dependency is used only during the compilation phase.
+ if IsRuntimeDepTag(depTag) {
+ // runtime dep to a stubs lib also crosses APEX boundary
return false
}
}
- } else if ctx.OtherModuleDependencyTag(dep) == llndkImplDep {
+ // TODO(ccross): The libDepTag.reexportFlags is there to maintain previous behavior
+ // when adding libraryDependencyTag and should be removed.
+ if isLibDepTag && c.static() && libDepTag.shared() && !libDepTag.reexportFlags {
+ // shared_lib dependency from a static lib is considered as crossing
+ // the APEX boundary because the dependency doesn't actually is
+ // linked; the dependency is used only during the compilation phase.
+ return false
+ }
+ }
+ if depTag == llndkImplDep {
// We don't track beyond LLNDK
return false
}
@@ -3031,236 +3075,6 @@
}
}
-var _ android.ImageInterface = (*Module)(nil)
-
-func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
- // Sanity check
- vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
- productSpecific := mctx.ProductSpecific()
-
- if m.VendorProperties.Vendor_available != nil && vendorSpecific {
- mctx.PropertyErrorf("vendor_available",
- "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
- }
-
- if vndkdep := m.vndkdep; vndkdep != nil {
- if vndkdep.isVndk() {
- if vendorSpecific || productSpecific {
- if !vndkdep.isVndkExt() {
- mctx.PropertyErrorf("vndk",
- "must set `extends: \"...\"` to vndk extension")
- } else if m.VendorProperties.Vendor_available != nil {
- mctx.PropertyErrorf("vendor_available",
- "must not set at the same time as `vndk: {extends: \"...\"}`")
- }
- } else {
- if vndkdep.isVndkExt() {
- mctx.PropertyErrorf("vndk",
- "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
- m.getVndkExtendsModuleName())
- }
- if m.VendorProperties.Vendor_available == nil {
- mctx.PropertyErrorf("vndk",
- "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
- }
- }
- } else {
- if vndkdep.isVndkSp() {
- mctx.PropertyErrorf("vndk",
- "must set `enabled: true` to set `support_system_process: true`")
- }
- if vndkdep.isVndkExt() {
- mctx.PropertyErrorf("vndk",
- "must set `enabled: true` to set `extends: %q`",
- m.getVndkExtendsModuleName())
- }
- }
- }
-
- var coreVariantNeeded bool = false
- var ramdiskVariantNeeded bool = false
- var recoveryVariantNeeded bool = false
-
- var vendorVariants []string
- var productVariants []string
-
- platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
- boardVndkVersion := mctx.DeviceConfig().VndkVersion()
- productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
- if boardVndkVersion == "current" {
- boardVndkVersion = platformVndkVersion
- }
- if productVndkVersion == "current" {
- productVndkVersion = platformVndkVersion
- }
-
- if boardVndkVersion == "" {
- // If the device isn't compiling against the VNDK, we always
- // use the core mode.
- coreVariantNeeded = true
- } else if _, ok := m.linker.(*llndkStubDecorator); ok {
- // LL-NDK stubs only exist in the vendor and product variants,
- // since the real libraries will be used in the core variant.
- vendorVariants = append(vendorVariants,
- platformVndkVersion,
- boardVndkVersion,
- )
- productVariants = append(productVariants,
- platformVndkVersion,
- productVndkVersion,
- )
- } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
- // ... and LL-NDK headers as well
- vendorVariants = append(vendorVariants,
- platformVndkVersion,
- boardVndkVersion,
- )
- productVariants = append(productVariants,
- platformVndkVersion,
- productVndkVersion,
- )
- } else if m.isSnapshotPrebuilt() {
- // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
- // PRODUCT_EXTRA_VNDK_VERSIONS.
- if snapshot, ok := m.linker.(interface {
- version() string
- }); ok {
- vendorVariants = append(vendorVariants, snapshot.version())
- } else {
- mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
- }
- } else if m.HasVendorVariant() && !m.isVndkExt() {
- // This will be available in /system, /vendor and /product
- // or a /system directory that is available to vendor and product.
- coreVariantNeeded = true
-
- // We assume that modules under proprietary paths are compatible for
- // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or
- // PLATFORM_VNDK_VERSION.
- if isVendorProprietaryPath(mctx.ModuleDir()) {
- vendorVariants = append(vendorVariants, boardVndkVersion)
- } else {
- vendorVariants = append(vendorVariants, platformVndkVersion)
- }
-
- // vendor_available modules are also available to /product.
- productVariants = append(productVariants, platformVndkVersion)
- // VNDK is always PLATFORM_VNDK_VERSION
- if !m.IsVndk() {
- productVariants = append(productVariants, productVndkVersion)
- }
- } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
- // This will be available in /vendor (or /odm) only
-
- // kernel_headers is a special module type whose exported headers
- // are coming from DeviceKernelHeaders() which is always vendor
- // dependent. They'll always have both vendor variants.
- // For other modules, we assume that modules under proprietary
- // paths are compatible for BOARD_VNDK_VERSION. The other modules
- // are regarded as AOSP, which is PLATFORM_VNDK_VERSION.
- if _, ok := m.linker.(*kernelHeadersDecorator); ok {
- vendorVariants = append(vendorVariants,
- platformVndkVersion,
- boardVndkVersion,
- )
- } else if isVendorProprietaryPath(mctx.ModuleDir()) {
- vendorVariants = append(vendorVariants, boardVndkVersion)
- } else {
- vendorVariants = append(vendorVariants, platformVndkVersion)
- }
- } else {
- // This is either in /system (or similar: /data), or is a
- // modules built with the NDK. Modules built with the NDK
- // will be restricted using the existing link type checks.
- coreVariantNeeded = true
- }
-
- if boardVndkVersion != "" && productVndkVersion != "" {
- if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
- // The module has "product_specific: true" that does not create core variant.
- coreVariantNeeded = false
- productVariants = append(productVariants, productVndkVersion)
- }
- } else {
- // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
- // restriction to use system libs.
- // No product variants defined in this case.
- productVariants = []string{}
- }
-
- if Bool(m.Properties.Ramdisk_available) {
- ramdiskVariantNeeded = true
- }
-
- if m.ModuleBase.InstallInRamdisk() {
- ramdiskVariantNeeded = true
- coreVariantNeeded = false
- }
-
- if Bool(m.Properties.Recovery_available) {
- recoveryVariantNeeded = true
- }
-
- if m.ModuleBase.InstallInRecovery() {
- recoveryVariantNeeded = true
- coreVariantNeeded = false
- }
-
- for _, variant := range android.FirstUniqueStrings(vendorVariants) {
- m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
- }
-
- for _, variant := range android.FirstUniqueStrings(productVariants) {
- m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
- }
-
- m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
- m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
- m.Properties.CoreVariantNeeded = coreVariantNeeded
-}
-
-func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
- return c.Properties.CoreVariantNeeded
-}
-
-func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
- return c.Properties.RamdiskVariantNeeded
-}
-
-func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
- return c.Properties.RecoveryVariantNeeded
-}
-
-func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
- return c.Properties.ExtraVariants
-}
-
-func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
- m := module.(*Module)
- if variant == android.RamdiskVariation {
- m.MakeAsPlatform()
- } else if variant == android.RecoveryVariation {
- m.MakeAsPlatform()
- squashRecoverySrcs(m)
- } else if strings.HasPrefix(variant, VendorVariationPrefix) {
- m.Properties.ImageVariationPrefix = VendorVariationPrefix
- m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
- squashVendorSrcs(m)
-
- // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
- // Hide other vendor variants to avoid collision.
- vndkVersion := ctx.DeviceConfig().VndkVersion()
- if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
- m.Properties.HideFromMake = true
- m.SkipInstall()
- }
- } else if strings.HasPrefix(variant, ProductVariationPrefix) {
- m.Properties.ImageVariationPrefix = ProductVariationPrefix
- m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
- squashVendorSrcs(m)
- }
-}
-
func (c *Module) IsSdkVariant() bool {
return c.Properties.IsSdkVariant
}
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 8a1c8ed..38a5c2d 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -539,7 +539,7 @@
data_libs: ["test_lib"],
gtest: false,
}
- `
+ `
config := TestConfig(buildDir, android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
@@ -564,7 +564,7 @@
}
outputPath := outputFiles[0].String()
- testBinaryPath := testBinary.dataPaths()[0].String()
+ testBinaryPath := testBinary.dataPaths()[0].SrcPath.String()
if !strings.HasSuffix(outputPath, "/main_test") {
t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
@@ -576,6 +576,53 @@
}
}
+func TestDataLibsRelativeInstallPath(t *testing.T) {
+ bp := `
+ cc_test_library {
+ name: "test_lib",
+ srcs: ["test_lib.cpp"],
+ relative_install_path: "foo/bar/baz",
+ gtest: false,
+ }
+
+ cc_test {
+ name: "main_test",
+ data_libs: ["test_lib"],
+ gtest: false,
+ }
+ `
+
+ config := TestConfig(buildDir, android.Android, nil, bp, nil)
+ config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
+
+ ctx := testCcWithConfig(t, config)
+ module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
+ testBinary := module.(*Module).linker.(*testBinary)
+ outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
+ if err != nil {
+ t.Fatalf("Expected cc_test to produce output files, error: %s", err)
+ }
+ if len(outputFiles) != 1 {
+ t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
+ }
+ if len(testBinary.dataPaths()) != 1 {
+ t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
+ }
+
+ outputPath := outputFiles[0].String()
+
+ if !strings.HasSuffix(outputPath, "/main_test") {
+ t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
+ }
+ entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
+ if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
+ t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
+ " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
+ }
+}
+
func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
ctx := testCcNoVndk(t, `
cc_library {
@@ -2919,6 +2966,52 @@
}
}
+func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
+ bp := `
+ cc_prebuilt_test_library_shared {
+ name: "test_lib",
+ relative_install_path: "foo/bar/baz",
+ srcs: ["srcpath/dontusethispath/baz.so"],
+ }
+
+ cc_test {
+ name: "main_test",
+ data_libs: ["test_lib"],
+ gtest: false,
+ }
+ `
+
+ config := TestConfig(buildDir, android.Android, nil, bp, nil)
+ config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
+
+ ctx := testCcWithConfig(t, config)
+ module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
+ testBinary := module.(*Module).linker.(*testBinary)
+ outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
+ if err != nil {
+ t.Fatalf("Expected cc_test to produce output files, error: %s", err)
+ }
+ if len(outputFiles) != 1 {
+ t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
+ }
+ if len(testBinary.dataPaths()) != 1 {
+ t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
+ }
+
+ outputPath := outputFiles[0].String()
+
+ if !strings.HasSuffix(outputPath, "/main_test") {
+ t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
+ }
+ entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
+ if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
+ t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
+ " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
+ }
+}
+
func TestVersionedStubs(t *testing.T) {
ctx := testCc(t, `
cc_library_shared {
diff --git a/cc/config/integer_overflow_blacklist.txt b/cc/config/integer_overflow_blocklist.txt
similarity index 100%
rename from cc/config/integer_overflow_blacklist.txt
rename to cc/config/integer_overflow_blocklist.txt
diff --git a/cc/config/x86_darwin_host.go b/cc/config/x86_darwin_host.go
index 8eb79e3..81c907d 100644
--- a/cc/config/x86_darwin_host.go
+++ b/cc/config/x86_darwin_host.go
@@ -66,6 +66,7 @@
"10.13",
"10.14",
"10.15",
+ "11.0",
}
darwinAvailableLibraries = append(
diff --git a/cc/coverage.go b/cc/coverage.go
index c823324..aa1fdf6 100644
--- a/cc/coverage.go
+++ b/cc/coverage.go
@@ -22,6 +22,8 @@
"android/soong/android"
)
+const profileInstrFlag = "-fprofile-instr-generate=/data/misc/trace/clang-%p-%m.profraw"
+
type CoverageProperties struct {
Native_coverage *bool
@@ -92,7 +94,7 @@
// flags that the module may use.
flags.Local.CFlags = append(flags.Local.CFlags, "-Wno-frame-larger-than=", "-O0")
} else if clangCoverage {
- flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-fprofile-instr-generate", "-fcoverage-mapping", "-Wno-pass-failed")
+ flags.Local.CommonFlags = append(flags.Local.CommonFlags, profileInstrFlag, "-fcoverage-mapping", "-Wno-pass-failed")
}
}
@@ -103,10 +105,14 @@
// For static libraries, the only thing that changes our object files
// are included whole static libraries, so check to see if any of
// those have coverage enabled.
- ctx.VisitDirectDepsWithTag(wholeStaticDepTag, func(m android.Module) {
- if cc, ok := m.(*Module); ok && cc.coverage != nil {
- if cc.coverage.linkCoverage {
- cov.linkCoverage = true
+ ctx.VisitDirectDeps(func(m android.Module) {
+ if depTag, ok := ctx.OtherModuleDependencyTag(m).(libraryDependencyTag); ok {
+ if depTag.static() && depTag.wholeStatic {
+ if cc, ok := m.(*Module); ok && cc.coverage != nil {
+ if cc.coverage.linkCoverage {
+ cov.linkCoverage = true
+ }
+ }
}
}
})
@@ -139,7 +145,7 @@
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--wrap,getenv")
} else if clangCoverage {
- flags.Local.LdFlags = append(flags.Local.LdFlags, "-fprofile-instr-generate")
+ flags.Local.LdFlags = append(flags.Local.LdFlags, profileInstrFlag)
coverage := ctx.GetDirectDepWithTag(getClangProfileLibraryName(ctx), CoverageDepTag).(*Module)
deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path())
diff --git a/cc/image.go b/cc/image.go
new file mode 100644
index 0000000..4daed7c
--- /dev/null
+++ b/cc/image.go
@@ -0,0 +1,348 @@
+// Copyright 2020 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 cc
+
+// This file contains image variant related things, including image mutator functions, utility
+// functions to determine where a module is installed, etc.
+
+import (
+ "strings"
+
+ "android/soong/android"
+)
+
+var _ android.ImageInterface = (*Module)(nil)
+
+type imageVariantType string
+
+const (
+ coreImageVariant imageVariantType = "core"
+ vendorImageVariant imageVariantType = "vendor"
+ productImageVariant imageVariantType = "product"
+ ramdiskImageVariant imageVariantType = "ramdisk"
+ recoveryImageVariant imageVariantType = "recovery"
+ hostImageVariant imageVariantType = "host"
+)
+
+func (c *Module) getImageVariantType() imageVariantType {
+ if c.Host() {
+ return hostImageVariant
+ } else if c.inVendor() {
+ return vendorImageVariant
+ } else if c.inProduct() {
+ return productImageVariant
+ } else if c.InRamdisk() {
+ return ramdiskImageVariant
+ } else if c.InRecovery() {
+ return recoveryImageVariant
+ } else {
+ return coreImageVariant
+ }
+}
+
+const (
+ // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
+ // against the VNDK.
+ VendorVariationPrefix = "vendor."
+
+ // ProductVariationPrefix is the variant prefix used for /product code that compiles
+ // against the VNDK.
+ ProductVariationPrefix = "product."
+)
+
+func (ctx *moduleContext) ProductSpecific() bool {
+ return ctx.ModuleContext.ProductSpecific() ||
+ (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
+}
+
+func (ctx *moduleContext) SocSpecific() bool {
+ return ctx.ModuleContext.SocSpecific() ||
+ (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
+}
+
+func (ctx *moduleContextImpl) inProduct() bool {
+ return ctx.mod.inProduct()
+}
+
+func (ctx *moduleContextImpl) inVendor() bool {
+ return ctx.mod.inVendor()
+}
+
+func (ctx *moduleContextImpl) inRamdisk() bool {
+ return ctx.mod.InRamdisk()
+}
+
+func (ctx *moduleContextImpl) inRecovery() bool {
+ return ctx.mod.InRecovery()
+}
+
+// Returns true only when this module is configured to have core, product and vendor
+// variants.
+func (c *Module) HasVendorVariant() bool {
+ return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
+}
+
+// Returns true if the module is "product" variant. Usually these modules are installed in /product
+func (c *Module) inProduct() bool {
+ return c.Properties.ImageVariationPrefix == ProductVariationPrefix
+}
+
+// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
+func (c *Module) inVendor() bool {
+ return c.Properties.ImageVariationPrefix == VendorVariationPrefix
+}
+
+func (c *Module) InRamdisk() bool {
+ return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
+}
+
+func (c *Module) InRecovery() bool {
+ return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
+}
+
+func (c *Module) OnlyInRamdisk() bool {
+ return c.ModuleBase.InstallInRamdisk()
+}
+
+func (c *Module) OnlyInRecovery() bool {
+ return c.ModuleBase.InstallInRecovery()
+}
+
+func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
+ // Validation check
+ vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
+ productSpecific := mctx.ProductSpecific()
+
+ if m.VendorProperties.Vendor_available != nil && vendorSpecific {
+ mctx.PropertyErrorf("vendor_available",
+ "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
+ }
+
+ if vndkdep := m.vndkdep; vndkdep != nil {
+ if vndkdep.isVndk() {
+ if vendorSpecific || productSpecific {
+ if !vndkdep.isVndkExt() {
+ mctx.PropertyErrorf("vndk",
+ "must set `extends: \"...\"` to vndk extension")
+ } else if m.VendorProperties.Vendor_available != nil {
+ mctx.PropertyErrorf("vendor_available",
+ "must not set at the same time as `vndk: {extends: \"...\"}`")
+ }
+ } else {
+ if vndkdep.isVndkExt() {
+ mctx.PropertyErrorf("vndk",
+ "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
+ m.getVndkExtendsModuleName())
+ }
+ if m.VendorProperties.Vendor_available == nil {
+ mctx.PropertyErrorf("vndk",
+ "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
+ }
+ }
+ } else {
+ if vndkdep.isVndkSp() {
+ mctx.PropertyErrorf("vndk",
+ "must set `enabled: true` to set `support_system_process: true`")
+ }
+ if vndkdep.isVndkExt() {
+ mctx.PropertyErrorf("vndk",
+ "must set `enabled: true` to set `extends: %q`",
+ m.getVndkExtendsModuleName())
+ }
+ }
+ }
+
+ var coreVariantNeeded bool = false
+ var ramdiskVariantNeeded bool = false
+ var recoveryVariantNeeded bool = false
+
+ var vendorVariants []string
+ var productVariants []string
+
+ platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
+ boardVndkVersion := mctx.DeviceConfig().VndkVersion()
+ productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
+ if boardVndkVersion == "current" {
+ boardVndkVersion = platformVndkVersion
+ }
+ if productVndkVersion == "current" {
+ productVndkVersion = platformVndkVersion
+ }
+
+ if boardVndkVersion == "" {
+ // If the device isn't compiling against the VNDK, we always
+ // use the core mode.
+ coreVariantNeeded = true
+ } else if _, ok := m.linker.(*llndkStubDecorator); ok {
+ // LL-NDK stubs only exist in the vendor and product variants,
+ // since the real libraries will be used in the core variant.
+ vendorVariants = append(vendorVariants,
+ platformVndkVersion,
+ boardVndkVersion,
+ )
+ productVariants = append(productVariants,
+ platformVndkVersion,
+ productVndkVersion,
+ )
+ } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
+ // ... and LL-NDK headers as well
+ vendorVariants = append(vendorVariants,
+ platformVndkVersion,
+ boardVndkVersion,
+ )
+ productVariants = append(productVariants,
+ platformVndkVersion,
+ productVndkVersion,
+ )
+ } else if m.isSnapshotPrebuilt() {
+ // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
+ // PRODUCT_EXTRA_VNDK_VERSIONS.
+ if snapshot, ok := m.linker.(interface {
+ version() string
+ }); ok {
+ vendorVariants = append(vendorVariants, snapshot.version())
+ } else {
+ mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
+ }
+ } else if m.HasVendorVariant() && !m.isVndkExt() {
+ // This will be available in /system, /vendor and /product
+ // or a /system directory that is available to vendor and product.
+ coreVariantNeeded = true
+
+ // We assume that modules under proprietary paths are compatible for
+ // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or
+ // PLATFORM_VNDK_VERSION.
+ if isVendorProprietaryPath(mctx.ModuleDir()) {
+ vendorVariants = append(vendorVariants, boardVndkVersion)
+ } else {
+ vendorVariants = append(vendorVariants, platformVndkVersion)
+ }
+
+ // vendor_available modules are also available to /product.
+ productVariants = append(productVariants, platformVndkVersion)
+ // VNDK is always PLATFORM_VNDK_VERSION
+ if !m.IsVndk() {
+ productVariants = append(productVariants, productVndkVersion)
+ }
+ } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
+ // This will be available in /vendor (or /odm) only
+
+ // kernel_headers is a special module type whose exported headers
+ // are coming from DeviceKernelHeaders() which is always vendor
+ // dependent. They'll always have both vendor variants.
+ // For other modules, we assume that modules under proprietary
+ // paths are compatible for BOARD_VNDK_VERSION. The other modules
+ // are regarded as AOSP, which is PLATFORM_VNDK_VERSION.
+ if _, ok := m.linker.(*kernelHeadersDecorator); ok {
+ vendorVariants = append(vendorVariants,
+ platformVndkVersion,
+ boardVndkVersion,
+ )
+ } else if isVendorProprietaryPath(mctx.ModuleDir()) {
+ vendorVariants = append(vendorVariants, boardVndkVersion)
+ } else {
+ vendorVariants = append(vendorVariants, platformVndkVersion)
+ }
+ } else {
+ // This is either in /system (or similar: /data), or is a
+ // modules built with the NDK. Modules built with the NDK
+ // will be restricted using the existing link type checks.
+ coreVariantNeeded = true
+ }
+
+ if boardVndkVersion != "" && productVndkVersion != "" {
+ if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
+ // The module has "product_specific: true" that does not create core variant.
+ coreVariantNeeded = false
+ productVariants = append(productVariants, productVndkVersion)
+ }
+ } else {
+ // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
+ // restriction to use system libs.
+ // No product variants defined in this case.
+ productVariants = []string{}
+ }
+
+ if Bool(m.Properties.Ramdisk_available) {
+ ramdiskVariantNeeded = true
+ }
+
+ if m.ModuleBase.InstallInRamdisk() {
+ ramdiskVariantNeeded = true
+ coreVariantNeeded = false
+ }
+
+ if Bool(m.Properties.Recovery_available) {
+ recoveryVariantNeeded = true
+ }
+
+ if m.ModuleBase.InstallInRecovery() {
+ recoveryVariantNeeded = true
+ coreVariantNeeded = false
+ }
+
+ for _, variant := range android.FirstUniqueStrings(vendorVariants) {
+ m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
+ }
+
+ for _, variant := range android.FirstUniqueStrings(productVariants) {
+ m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
+ }
+
+ m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
+ m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
+ m.Properties.CoreVariantNeeded = coreVariantNeeded
+}
+
+func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
+ return c.Properties.CoreVariantNeeded
+}
+
+func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
+ return c.Properties.RamdiskVariantNeeded
+}
+
+func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
+ return c.Properties.RecoveryVariantNeeded
+}
+
+func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
+ return c.Properties.ExtraVariants
+}
+
+func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
+ m := module.(*Module)
+ if variant == android.RamdiskVariation {
+ m.MakeAsPlatform()
+ } else if variant == android.RecoveryVariation {
+ m.MakeAsPlatform()
+ squashRecoverySrcs(m)
+ } else if strings.HasPrefix(variant, VendorVariationPrefix) {
+ m.Properties.ImageVariationPrefix = VendorVariationPrefix
+ m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
+ squashVendorSrcs(m)
+
+ // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
+ // Hide other vendor variants to avoid collision.
+ vndkVersion := ctx.DeviceConfig().VndkVersion()
+ if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
+ m.Properties.HideFromMake = true
+ m.SkipInstall()
+ }
+ } else if strings.HasPrefix(variant, ProductVariationPrefix) {
+ m.Properties.ImageVariationPrefix = ProductVariationPrefix
+ m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
+ squashVendorSrcs(m)
+ }
+}
diff --git a/cc/library.go b/cc/library.go
index 98f4d48..2a329ac 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -1633,8 +1633,7 @@
// TODO(b/137267623): Remove this in favor of a cc_genrule when they support operating on shared libraries.
injectBoringSSLHash := Bool(inject)
ctx.VisitDirectDeps(func(dep android.Module) {
- tag := ctx.OtherModuleDependencyTag(dep)
- if tag == StaticDepTag || tag == staticExportDepTag || tag == wholeStaticDepTag || tag == lateStaticDepTag {
+ if tag, ok := ctx.OtherModuleDependencyTag(dep).(libraryDependencyTag); ok && tag.static() {
if cc, ok := dep.(*Module); ok {
if library, ok := cc.linker.(*libraryDecorator); ok {
if Bool(library.Properties.Inject_bssl_hash) {
diff --git a/cc/library_headers.go b/cc/library_headers.go
index b7ab390..8b3dbeb 100644
--- a/cc/library_headers.go
+++ b/cc/library_headers.go
@@ -25,8 +25,9 @@
var headersLibrarySdkMemberType = &librarySdkMemberType{
SdkMemberTypeBase: android.SdkMemberTypeBase{
- PropertyName: "native_header_libs",
- SupportsSdk: true,
+ PropertyName: "native_header_libs",
+ SupportsSdk: true,
+ HostOsDependent: true,
},
prebuiltModuleType: "cc_prebuilt_library_headers",
noOutputFiles: true,
diff --git a/cc/library_sdk_member.go b/cc/library_sdk_member.go
index 9c54399..cff00b6 100644
--- a/cc/library_sdk_member.go
+++ b/cc/library_sdk_member.go
@@ -27,8 +27,9 @@
var sharedLibrarySdkMemberType = &librarySdkMemberType{
SdkMemberTypeBase: android.SdkMemberTypeBase{
- PropertyName: "native_shared_libs",
- SupportsSdk: true,
+ PropertyName: "native_shared_libs",
+ SupportsSdk: true,
+ HostOsDependent: true,
},
prebuiltModuleType: "cc_prebuilt_library_shared",
linkTypes: []string{"shared"},
@@ -36,8 +37,9 @@
var staticLibrarySdkMemberType = &librarySdkMemberType{
SdkMemberTypeBase: android.SdkMemberTypeBase{
- PropertyName: "native_static_libs",
- SupportsSdk: true,
+ PropertyName: "native_static_libs",
+ SupportsSdk: true,
+ HostOsDependent: true,
},
prebuiltModuleType: "cc_prebuilt_library_static",
linkTypes: []string{"static"},
@@ -45,8 +47,9 @@
var staticAndSharedLibrarySdkMemberType = &librarySdkMemberType{
SdkMemberTypeBase: android.SdkMemberTypeBase{
- PropertyName: "native_libs",
- SupportsSdk: true,
+ PropertyName: "native_libs",
+ SupportsSdk: true,
+ HostOsDependent: true,
},
prebuiltModuleType: "cc_prebuilt_library",
linkTypes: []string{"static", "shared"},
@@ -234,7 +237,7 @@
for _, propertyInfo := range includeDirProperties {
// Calculate the base directory in the snapshot into which the files will be copied.
// lib.ArchType is "" for common properties.
- targetDir := filepath.Join(libInfo.archType, propertyInfo.snapshotDir)
+ targetDir := filepath.Join(libInfo.OsPrefix(), libInfo.archType, propertyInfo.snapshotDir)
propertyName := propertyInfo.propertyName
diff --git a/cc/linkable.go b/cc/linkable.go
index 66b1c3f..4c84163 100644
--- a/cc/linkable.go
+++ b/cc/linkable.go
@@ -1,9 +1,9 @@
package cc
import (
- "github.com/google/blueprint"
-
"android/soong/android"
+
+ "github.com/google/blueprint"
)
type LinkableInterface interface {
@@ -63,27 +63,16 @@
StubDecorator() bool
}
-type DependencyTag struct {
- blueprint.BaseDependencyTag
- Name string
- Library bool
- Shared bool
+var (
+ CrtBeginDepTag = dependencyTag{name: "crtbegin"}
+ CrtEndDepTag = dependencyTag{name: "crtend"}
+ CoverageDepTag = dependencyTag{name: "coverage"}
+)
- ReexportFlags bool
-
- ExplicitlyVersioned bool
-
- FromStatic bool
+func SharedDepTag() blueprint.DependencyTag {
+ return libraryDependencyTag{Kind: sharedLibraryDependency}
}
-var (
- SharedDepTag = DependencyTag{Name: "shared", Library: true, Shared: true}
- StaticDepTag = DependencyTag{Name: "static", Library: true}
-
- // Same as SharedDepTag, but from a static lib
- SharedFromStaticDepTag = DependencyTag{Name: "shared from static", Library: true, Shared: true, FromStatic: true}
-
- CrtBeginDepTag = DependencyTag{Name: "crtbegin"}
- CrtEndDepTag = DependencyTag{Name: "crtend"}
- CoverageDepTag = DependencyTag{Name: "coverage"}
-)
+func StaticDepTag() blueprint.DependencyTag {
+ return libraryDependencyTag{Kind: staticLibraryDependency}
+}
diff --git a/cc/llndk_library.go b/cc/llndk_library.go
index 7ff20f4..71c9204 100644
--- a/cc/llndk_library.go
+++ b/cc/llndk_library.go
@@ -225,6 +225,8 @@
func llndkHeadersFactory() android.Module {
module, library := NewLibrary(android.DeviceSupported)
library.HeaderOnly()
+ module.stl = nil
+ module.sanitize = nil
decorator := &llndkHeadersDecorator{
libraryDecorator: library,
diff --git a/cc/lto.go b/cc/lto.go
index 4489fc7..ed3abe7 100644
--- a/cc/lto.go
+++ b/cc/lto.go
@@ -148,24 +148,33 @@
mctx.WalkDeps(func(dep android.Module, parent android.Module) bool {
tag := mctx.OtherModuleDependencyTag(dep)
- switch tag {
- case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag, objDepTag, reuseObjTag:
- if dep, ok := dep.(*Module); ok && dep.lto != nil &&
- !dep.lto.Disabled() {
- if full && !Bool(dep.lto.Properties.Lto.Full) {
- dep.lto.Properties.FullDep = true
- }
- if thin && !Bool(dep.lto.Properties.Lto.Thin) {
- dep.lto.Properties.ThinDep = true
- }
- }
-
- // Recursively walk static dependencies
- return true
- }
+ libTag, isLibTag := tag.(libraryDependencyTag)
// Do not recurse down non-static dependencies
- return false
+ if isLibTag {
+ // TODO(ccross): the staticUnwinder check is there to maintain existing behavior
+ // when adding libraryDependencyTag and should be removed.
+ if !libTag.static() || libTag.staticUnwinder {
+ return false
+ }
+ } else {
+ if tag != objDepTag && tag != reuseObjTag {
+ return false
+ }
+ }
+
+ if dep, ok := dep.(*Module); ok && dep.lto != nil &&
+ !dep.lto.Disabled() {
+ if full && !Bool(dep.lto.Properties.Lto.Full) {
+ dep.lto.Properties.FullDep = true
+ }
+ if thin && !Bool(dep.lto.Properties.Lto.Thin) {
+ dep.lto.Properties.ThinDep = true
+ }
+ }
+
+ // Recursively walk static dependencies
+ return true
})
}
}
diff --git a/cc/ndk_api_coverage_parser/.gitignore b/cc/ndk_api_coverage_parser/.gitignore
new file mode 100644
index 0000000..fd94eac
--- /dev/null
+++ b/cc/ndk_api_coverage_parser/.gitignore
@@ -0,0 +1,140 @@
+# From https://github.com/github/gitignore/blob/master/Python.gitignore
+
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+share/python-wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+MANIFEST
+
+# PyInstaller
+# Usually these files are written by a python script from a template
+# before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.nox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*.cover
+*.py,cover
+.hypothesis/
+.pytest_cache/
+cover/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+db.sqlite3
+db.sqlite3-journal
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+.pybuilder/
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# IPython
+profile_default/
+ipython_config.py
+
+# pyenv
+# For a library or package, you might want to ignore these files since the code is
+# intended to run in multiple environments; otherwise, check them in:
+# .python-version
+
+# pipenv
+# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
+# However, in case of collaboration, if having platform-specific dependencies or dependencies
+# having no cross-platform support, pipenv may install dependencies that don't work, or not
+# install all needed dependencies.
+#Pipfile.lock
+
+# PEP 582; used by e.g. github.com/David-OConnor/pyflow
+__pypackages__/
+
+# Celery stuff
+celerybeat-schedule
+celerybeat.pid
+
+# SageMath parsed files
+*.sage.py
+
+# Environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
+
+# Spyder project settings
+.spyderproject
+.spyproject
+
+# Rope project settings
+.ropeproject
+
+# mkdocs documentation
+/site
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# Pyre type checker
+.pyre/
+
+# pytype static type analyzer
+.pytype/
+
+# Cython debug symbols
+cython_debug/
diff --git a/cc/scriptlib/Android.bp b/cc/ndk_api_coverage_parser/Android.bp
similarity index 73%
rename from cc/scriptlib/Android.bp
rename to cc/ndk_api_coverage_parser/Android.bp
index ff9a2f0..8d9827c 100644
--- a/cc/scriptlib/Android.bp
+++ b/cc/ndk_api_coverage_parser/Android.bp
@@ -14,19 +14,33 @@
// limitations under the License.
//
+python_library_host {
+ name: "ndk_api_coverage_parser_lib",
+ pkg_path: "ndk_api_coverage_parser",
+ srcs: [
+ "__init__.py",
+ ],
+}
+
python_test_host {
name: "test_ndk_api_coverage_parser",
main: "test_ndk_api_coverage_parser.py",
srcs: [
"test_ndk_api_coverage_parser.py",
],
+ libs: [
+ "ndk_api_coverage_parser_lib",
+ "symbolfile",
+ ],
}
python_binary_host {
name: "ndk_api_coverage_parser",
- main: "ndk_api_coverage_parser.py",
+ main: "__init__.py",
srcs: [
- "gen_stub_libs.py",
- "ndk_api_coverage_parser.py",
+ "__init__.py",
+ ],
+ libs: [
+ "symbolfile",
],
}
diff --git a/cc/ndk_api_coverage_parser/OWNERS b/cc/ndk_api_coverage_parser/OWNERS
new file mode 100644
index 0000000..a90c48c
--- /dev/null
+++ b/cc/ndk_api_coverage_parser/OWNERS
@@ -0,0 +1 @@
+sophiez@google.com
diff --git a/cc/scriptlib/ndk_api_coverage_parser.py b/cc/ndk_api_coverage_parser/__init__.py
similarity index 96%
rename from cc/scriptlib/ndk_api_coverage_parser.py
rename to cc/ndk_api_coverage_parser/__init__.py
index d74035b..7817c78 100755
--- a/cc/scriptlib/ndk_api_coverage_parser.py
+++ b/cc/ndk_api_coverage_parser/__init__.py
@@ -21,7 +21,7 @@
import sys
from xml.etree.ElementTree import Element, SubElement, tostring
-from gen_stub_libs import ALL_ARCHITECTURES, FUTURE_API_LEVEL, MultiplyDefinedSymbolError, SymbolFileParser
+from symbolfile import ALL_ARCHITECTURES, FUTURE_API_LEVEL, MultiplyDefinedSymbolError, SymbolFileParser
ROOT_ELEMENT_TAG = 'ndk-library'
diff --git a/cc/ndk_api_coverage_parser/test_ndk_api_coverage_parser.py b/cc/ndk_api_coverage_parser/test_ndk_api_coverage_parser.py
new file mode 100644
index 0000000..3ec14c1
--- /dev/null
+++ b/cc/ndk_api_coverage_parser/test_ndk_api_coverage_parser.py
@@ -0,0 +1,90 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2016 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.
+#
+"""Tests for ndk_api_coverage_parser.py."""
+import io
+import textwrap
+import unittest
+
+from xml.etree.ElementTree import fromstring
+from symbolfile import FUTURE_API_LEVEL, SymbolFileParser
+import ndk_api_coverage_parser as nparser
+
+
+# pylint: disable=missing-docstring
+
+
+# https://stackoverflow.com/a/24349916/632035
+def etree_equal(elem1, elem2):
+ """Returns true if the two XML elements are equal.
+
+ xml.etree.ElementTree's comparison operator cares about the ordering of
+ elements and attributes, but they are stored in an unordered dict so the
+ ordering is not deterministic.
+
+ lxml is apparently API compatible with xml and does use an OrderedDict, but
+ we don't have it in the tree.
+ """
+ if elem1.tag != elem2.tag:
+ return False
+ if elem1.text != elem2.text:
+ return False
+ if elem1.tail != elem2.tail:
+ return False
+ if elem1.attrib != elem2.attrib:
+ return False
+ if len(elem1) != len(elem2):
+ return False
+ return all(etree_equal(c1, c2) for c1, c2 in zip(elem1, elem2))
+
+
+class ApiCoverageSymbolFileParserTest(unittest.TestCase):
+ def test_parse(self):
+ input_file = io.StringIO(textwrap.dedent(u"""\
+ LIBLOG { # introduced-arm64=24 introduced-x86=24 introduced-x86_64=24
+ global:
+ android_name_to_log_id; # apex llndk introduced=23
+ android_log_id_to_name; # llndk arm
+ __android_log_assert; # introduced-x86=23
+ __android_log_buf_print; # var
+ __android_log_buf_write;
+ local:
+ *;
+ };
+
+ LIBLOG_PLATFORM {
+ android_fdtrack; # llndk
+ android_net; # introduced=23
+ };
+
+ LIBLOG_FOO { # var
+ android_var;
+ };
+ """))
+ parser = SymbolFileParser(input_file, {}, "", FUTURE_API_LEVEL, True, True)
+ generator = nparser.XmlGenerator(io.StringIO())
+ result = generator.convertToXml(parser.parse())
+ expected = fromstring('<ndk-library><symbol apex="True" arch="" introduced="23" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" llndk="True" name="android_name_to_log_id" /><symbol arch="arm" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" llndk="True" name="android_log_id_to_name" /><symbol arch="" introduced-arm64="24" introduced-x86="23" introduced-x86_64="24" is_deprecated="False" is_platform="False" name="__android_log_assert" /><symbol arch="" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" name="__android_log_buf_write" /><symbol arch="" is_deprecated="False" is_platform="True" llndk="True" name="android_fdtrack" /><symbol arch="" introduced="23" is_deprecated="False" is_platform="True" name="android_net" /></ndk-library>')
+ self.assertTrue(etree_equal(expected, result))
+
+
+def main():
+ suite = unittest.TestLoader().loadTestsFromName(__name__)
+ unittest.TextTestRunner(verbosity=3).run(suite)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index 6299b00..22e3ec3 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -26,17 +26,16 @@
)
func init() {
+ pctx.HostBinToolVariable("ndkStubGenerator", "ndkstubgen")
pctx.HostBinToolVariable("ndk_api_coverage_parser", "ndk_api_coverage_parser")
}
var (
- toolPath = pctx.SourcePathVariable("toolPath", "build/soong/cc/scriptlib/gen_stub_libs.py")
-
genStubSrc = pctx.AndroidStaticRule("genStubSrc",
blueprint.RuleParams{
- Command: "$toolPath --arch $arch --api $apiLevel --api-map " +
- "$apiMap $flags $in $out",
- CommandDeps: []string{"$toolPath"},
+ Command: "$ndkStubGenerator --arch $arch --api $apiLevel " +
+ "--api-map $apiMap $flags $in $out",
+ CommandDeps: []string{"$ndkStubGenerator"},
}, "arch", "apiLevel", "apiMap", "flags")
parseNdkApiRule = pctx.AndroidStaticRule("parseNdkApiRule",
@@ -78,9 +77,9 @@
// https://github.com/android-ndk/ndk/issues/265.
Unversioned_until *string
- // Private property for use by the mutator that splits per-API level.
- // can be one of <number:sdk_version> or <codename> or "current"
- // passed to "gen_stub_libs.py" as it is
+ // Private property for use by the mutator that splits per-API level. Can be
+ // one of <number:sdk_version> or <codename> or "current" passed to
+ // "ndkstubgen.py" as it is
ApiLevel string `blueprint:"mutated"`
// True if this API is not yet ready to be shipped in the NDK. It will be
@@ -397,8 +396,8 @@
return module
}
-// ndk_library creates a stub library that exposes dummy implementation
-// of functions and variables for use at build time only.
+// ndk_library creates a library that exposes a stub implementation of functions
+// and variables for use at build time only.
func NdkLibraryFactory() android.Module {
module := newStubLibrary()
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth)
diff --git a/cc/ndkstubgen/.gitignore b/cc/ndkstubgen/.gitignore
new file mode 100644
index 0000000..fd94eac
--- /dev/null
+++ b/cc/ndkstubgen/.gitignore
@@ -0,0 +1,140 @@
+# From https://github.com/github/gitignore/blob/master/Python.gitignore
+
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+share/python-wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+MANIFEST
+
+# PyInstaller
+# Usually these files are written by a python script from a template
+# before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.nox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*.cover
+*.py,cover
+.hypothesis/
+.pytest_cache/
+cover/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+db.sqlite3
+db.sqlite3-journal
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+.pybuilder/
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# IPython
+profile_default/
+ipython_config.py
+
+# pyenv
+# For a library or package, you might want to ignore these files since the code is
+# intended to run in multiple environments; otherwise, check them in:
+# .python-version
+
+# pipenv
+# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
+# However, in case of collaboration, if having platform-specific dependencies or dependencies
+# having no cross-platform support, pipenv may install dependencies that don't work, or not
+# install all needed dependencies.
+#Pipfile.lock
+
+# PEP 582; used by e.g. github.com/David-OConnor/pyflow
+__pypackages__/
+
+# Celery stuff
+celerybeat-schedule
+celerybeat.pid
+
+# SageMath parsed files
+*.sage.py
+
+# Environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
+
+# Spyder project settings
+.spyderproject
+.spyproject
+
+# Rope project settings
+.ropeproject
+
+# mkdocs documentation
+/site
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# Pyre type checker
+.pyre/
+
+# pytype static type analyzer
+.pytype/
+
+# Cython debug symbols
+cython_debug/
diff --git a/cc/scriptlib/Android.bp b/cc/ndkstubgen/Android.bp
similarity index 63%
copy from cc/scriptlib/Android.bp
copy to cc/ndkstubgen/Android.bp
index ff9a2f0..85dfaee 100644
--- a/cc/scriptlib/Android.bp
+++ b/cc/ndkstubgen/Android.bp
@@ -14,19 +14,35 @@
// limitations under the License.
//
-python_test_host {
- name: "test_ndk_api_coverage_parser",
- main: "test_ndk_api_coverage_parser.py",
+python_binary_host {
+ name: "ndkstubgen",
+ pkg_path: "ndkstubgen",
+ main: "__init__.py",
srcs: [
- "test_ndk_api_coverage_parser.py",
+ "__init__.py",
+ ],
+ libs: [
+ "symbolfile",
],
}
-python_binary_host {
- name: "ndk_api_coverage_parser",
- main: "ndk_api_coverage_parser.py",
+python_library_host {
+ name: "ndkstubgenlib",
+ pkg_path: "ndkstubgen",
srcs: [
- "gen_stub_libs.py",
- "ndk_api_coverage_parser.py",
+ "__init__.py",
+ ],
+ libs: [
+ "symbolfile",
+ ],
+}
+
+python_test_host {
+ name: "test_ndkstubgen",
+ srcs: [
+ "test_ndkstubgen.py",
+ ],
+ libs: [
+ "ndkstubgenlib",
],
}
diff --git a/cc/ndkstubgen/OWNERS b/cc/ndkstubgen/OWNERS
new file mode 100644
index 0000000..f0d8733
--- /dev/null
+++ b/cc/ndkstubgen/OWNERS
@@ -0,0 +1 @@
+danalbert@google.com
diff --git a/cc/ndkstubgen/__init__.py b/cc/ndkstubgen/__init__.py
new file mode 100755
index 0000000..2f4326a
--- /dev/null
+++ b/cc/ndkstubgen/__init__.py
@@ -0,0 +1,149 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2016 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.
+#
+"""Generates source for stub shared libraries for the NDK."""
+import argparse
+import json
+import logging
+import os
+import sys
+
+import symbolfile
+
+
+class Generator:
+ """Output generator that writes stub source files and version scripts."""
+ def __init__(self, src_file, version_script, arch, api, llndk, apex):
+ self.src_file = src_file
+ self.version_script = version_script
+ self.arch = arch
+ self.api = api
+ self.llndk = llndk
+ self.apex = apex
+
+ def write(self, versions):
+ """Writes all symbol data to the output files."""
+ for version in versions:
+ self.write_version(version)
+
+ def write_version(self, version):
+ """Writes a single version block's data to the output files."""
+ if symbolfile.should_omit_version(version, self.arch, self.api,
+ self.llndk, self.apex):
+ return
+
+ section_versioned = symbolfile.symbol_versioned_in_api(
+ version.tags, self.api)
+ version_empty = True
+ pruned_symbols = []
+ for symbol in version.symbols:
+ if symbolfile.should_omit_symbol(symbol, self.arch, self.api,
+ self.llndk, self.apex):
+ continue
+
+ if symbolfile.symbol_versioned_in_api(symbol.tags, self.api):
+ version_empty = False
+ pruned_symbols.append(symbol)
+
+ if len(pruned_symbols) > 0:
+ if not version_empty and section_versioned:
+ self.version_script.write(version.name + ' {\n')
+ self.version_script.write(' global:\n')
+ for symbol in pruned_symbols:
+ emit_version = symbolfile.symbol_versioned_in_api(
+ symbol.tags, self.api)
+ if section_versioned and emit_version:
+ self.version_script.write(' ' + symbol.name + ';\n')
+
+ weak = ''
+ if 'weak' in symbol.tags:
+ weak = '__attribute__((weak)) '
+
+ if 'var' in symbol.tags:
+ self.src_file.write('{}int {} = 0;\n'.format(
+ weak, symbol.name))
+ else:
+ self.src_file.write('{}void {}() {{}}\n'.format(
+ weak, symbol.name))
+
+ if not version_empty and section_versioned:
+ base = '' if version.base is None else ' ' + version.base
+ self.version_script.write('}' + base + ';\n')
+
+
+def parse_args():
+ """Parses and returns command line arguments."""
+ parser = argparse.ArgumentParser()
+
+ parser.add_argument('-v', '--verbose', action='count', default=0)
+
+ parser.add_argument(
+ '--api', required=True, help='API level being targeted.')
+ parser.add_argument(
+ '--arch', choices=symbolfile.ALL_ARCHITECTURES, required=True,
+ help='Architecture being targeted.')
+ parser.add_argument(
+ '--llndk', action='store_true', help='Use the LLNDK variant.')
+ parser.add_argument(
+ '--apex', action='store_true', help='Use the APEX variant.')
+
+ parser.add_argument(
+ '--api-map', type=os.path.realpath, required=True,
+ help='Path to the API level map JSON file.')
+
+ parser.add_argument(
+ 'symbol_file', type=os.path.realpath, help='Path to symbol file.')
+ parser.add_argument(
+ 'stub_src', type=os.path.realpath,
+ help='Path to output stub source file.')
+ parser.add_argument(
+ 'version_script', type=os.path.realpath,
+ help='Path to output version script.')
+
+ return parser.parse_args()
+
+
+def main():
+ """Program entry point."""
+ args = parse_args()
+
+ with open(args.api_map) as map_file:
+ api_map = json.load(map_file)
+ api = symbolfile.decode_api_level(args.api, api_map)
+
+ verbose_map = (logging.WARNING, logging.INFO, logging.DEBUG)
+ verbosity = args.verbose
+ if verbosity > 2:
+ verbosity = 2
+ logging.basicConfig(level=verbose_map[verbosity])
+
+ with open(args.symbol_file) as symbol_file:
+ try:
+ versions = symbolfile.SymbolFileParser(symbol_file, api_map,
+ args.arch, api, args.llndk,
+ args.apex).parse()
+ except symbolfile.MultiplyDefinedSymbolError as ex:
+ sys.exit('{}: error: {}'.format(args.symbol_file, ex))
+
+ with open(args.stub_src, 'w') as src_file:
+ with open(args.version_script, 'w') as version_file:
+ generator = Generator(src_file, version_file, args.arch, api,
+ args.llndk, args.apex)
+ generator.write(versions)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/cc/ndkstubgen/test_ndkstubgen.py b/cc/ndkstubgen/test_ndkstubgen.py
new file mode 100755
index 0000000..70bcf78
--- /dev/null
+++ b/cc/ndkstubgen/test_ndkstubgen.py
@@ -0,0 +1,378 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2016 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.
+#
+"""Tests for ndkstubgen.py."""
+import io
+import textwrap
+import unittest
+
+import ndkstubgen
+import symbolfile
+
+
+# pylint: disable=missing-docstring
+
+
+class GeneratorTest(unittest.TestCase):
+ def test_omit_version(self):
+ # Thorough testing of the cases involved here is handled by
+ # OmitVersionTest, PrivateVersionTest, and SymbolPresenceTest.
+ src_file = io.StringIO()
+ version_file = io.StringIO()
+ generator = ndkstubgen.Generator(src_file, version_file, 'arm', 9,
+ False, False)
+
+ version = symbolfile.Version('VERSION_PRIVATE', None, [], [
+ symbolfile.Symbol('foo', []),
+ ])
+ generator.write_version(version)
+ self.assertEqual('', src_file.getvalue())
+ self.assertEqual('', version_file.getvalue())
+
+ version = symbolfile.Version('VERSION', None, ['x86'], [
+ symbolfile.Symbol('foo', []),
+ ])
+ generator.write_version(version)
+ self.assertEqual('', src_file.getvalue())
+ self.assertEqual('', version_file.getvalue())
+
+ version = symbolfile.Version('VERSION', None, ['introduced=14'], [
+ symbolfile.Symbol('foo', []),
+ ])
+ generator.write_version(version)
+ self.assertEqual('', src_file.getvalue())
+ self.assertEqual('', version_file.getvalue())
+
+ def test_omit_symbol(self):
+ # Thorough testing of the cases involved here is handled by
+ # SymbolPresenceTest.
+ src_file = io.StringIO()
+ version_file = io.StringIO()
+ generator = ndkstubgen.Generator(src_file, version_file, 'arm', 9,
+ False, False)
+
+ version = symbolfile.Version('VERSION_1', None, [], [
+ symbolfile.Symbol('foo', ['x86']),
+ ])
+ generator.write_version(version)
+ self.assertEqual('', src_file.getvalue())
+ self.assertEqual('', version_file.getvalue())
+
+ version = symbolfile.Version('VERSION_1', None, [], [
+ symbolfile.Symbol('foo', ['introduced=14']),
+ ])
+ generator.write_version(version)
+ self.assertEqual('', src_file.getvalue())
+ self.assertEqual('', version_file.getvalue())
+
+ version = symbolfile.Version('VERSION_1', None, [], [
+ symbolfile.Symbol('foo', ['llndk']),
+ ])
+ generator.write_version(version)
+ self.assertEqual('', src_file.getvalue())
+ self.assertEqual('', version_file.getvalue())
+
+ version = symbolfile.Version('VERSION_1', None, [], [
+ symbolfile.Symbol('foo', ['apex']),
+ ])
+ generator.write_version(version)
+ self.assertEqual('', src_file.getvalue())
+ self.assertEqual('', version_file.getvalue())
+
+ def test_write(self):
+ src_file = io.StringIO()
+ version_file = io.StringIO()
+ generator = ndkstubgen.Generator(src_file, version_file, 'arm', 9,
+ False, False)
+
+ versions = [
+ symbolfile.Version('VERSION_1', None, [], [
+ symbolfile.Symbol('foo', []),
+ symbolfile.Symbol('bar', ['var']),
+ symbolfile.Symbol('woodly', ['weak']),
+ symbolfile.Symbol('doodly', ['weak', 'var']),
+ ]),
+ symbolfile.Version('VERSION_2', 'VERSION_1', [], [
+ symbolfile.Symbol('baz', []),
+ ]),
+ symbolfile.Version('VERSION_3', 'VERSION_1', [], [
+ symbolfile.Symbol('qux', ['versioned=14']),
+ ]),
+ ]
+
+ generator.write(versions)
+ expected_src = textwrap.dedent("""\
+ void foo() {}
+ int bar = 0;
+ __attribute__((weak)) void woodly() {}
+ __attribute__((weak)) int doodly = 0;
+ void baz() {}
+ void qux() {}
+ """)
+ self.assertEqual(expected_src, src_file.getvalue())
+
+ expected_version = textwrap.dedent("""\
+ VERSION_1 {
+ global:
+ foo;
+ bar;
+ woodly;
+ doodly;
+ };
+ VERSION_2 {
+ global:
+ baz;
+ } VERSION_1;
+ """)
+ self.assertEqual(expected_version, version_file.getvalue())
+
+
+class IntegrationTest(unittest.TestCase):
+ def test_integration(self):
+ api_map = {
+ 'O': 9000,
+ 'P': 9001,
+ }
+
+ input_file = io.StringIO(textwrap.dedent("""\
+ VERSION_1 {
+ global:
+ foo; # var
+ bar; # x86
+ fizz; # introduced=O
+ buzz; # introduced=P
+ local:
+ *;
+ };
+
+ VERSION_2 { # arm
+ baz; # introduced=9
+ qux; # versioned=14
+ } VERSION_1;
+
+ VERSION_3 { # introduced=14
+ woodly;
+ doodly; # var
+ } VERSION_2;
+
+ VERSION_4 { # versioned=9
+ wibble;
+ wizzes; # llndk
+ waggle; # apex
+ } VERSION_2;
+
+ VERSION_5 { # versioned=14
+ wobble;
+ } VERSION_4;
+ """))
+ parser = symbolfile.SymbolFileParser(input_file, api_map, 'arm', 9,
+ False, False)
+ versions = parser.parse()
+
+ src_file = io.StringIO()
+ version_file = io.StringIO()
+ generator = ndkstubgen.Generator(src_file, version_file, 'arm', 9,
+ False, False)
+ generator.write(versions)
+
+ expected_src = textwrap.dedent("""\
+ int foo = 0;
+ void baz() {}
+ void qux() {}
+ void wibble() {}
+ void wobble() {}
+ """)
+ self.assertEqual(expected_src, src_file.getvalue())
+
+ expected_version = textwrap.dedent("""\
+ VERSION_1 {
+ global:
+ foo;
+ };
+ VERSION_2 {
+ global:
+ baz;
+ } VERSION_1;
+ VERSION_4 {
+ global:
+ wibble;
+ } VERSION_2;
+ """)
+ self.assertEqual(expected_version, version_file.getvalue())
+
+ def test_integration_future_api(self):
+ api_map = {
+ 'O': 9000,
+ 'P': 9001,
+ 'Q': 9002,
+ }
+
+ input_file = io.StringIO(textwrap.dedent("""\
+ VERSION_1 {
+ global:
+ foo; # introduced=O
+ bar; # introduced=P
+ baz; # introduced=Q
+ local:
+ *;
+ };
+ """))
+ parser = symbolfile.SymbolFileParser(input_file, api_map, 'arm', 9001,
+ False, False)
+ versions = parser.parse()
+
+ src_file = io.StringIO()
+ version_file = io.StringIO()
+ generator = ndkstubgen.Generator(src_file, version_file, 'arm', 9001,
+ False, False)
+ generator.write(versions)
+
+ expected_src = textwrap.dedent("""\
+ void foo() {}
+ void bar() {}
+ """)
+ self.assertEqual(expected_src, src_file.getvalue())
+
+ expected_version = textwrap.dedent("""\
+ VERSION_1 {
+ global:
+ foo;
+ bar;
+ };
+ """)
+ self.assertEqual(expected_version, version_file.getvalue())
+
+ def test_multiple_definition(self):
+ input_file = io.StringIO(textwrap.dedent("""\
+ VERSION_1 {
+ global:
+ foo;
+ foo;
+ bar;
+ baz;
+ qux; # arm
+ local:
+ *;
+ };
+
+ VERSION_2 {
+ global:
+ bar;
+ qux; # arm64
+ } VERSION_1;
+
+ VERSION_PRIVATE {
+ global:
+ baz;
+ } VERSION_2;
+
+ """))
+ parser = symbolfile.SymbolFileParser(input_file, {}, 'arm', 16, False,
+ False)
+
+ with self.assertRaises(
+ symbolfile.MultiplyDefinedSymbolError) as ex_context:
+ parser.parse()
+ self.assertEqual(['bar', 'foo'],
+ ex_context.exception.multiply_defined_symbols)
+
+ def test_integration_with_apex(self):
+ api_map = {
+ 'O': 9000,
+ 'P': 9001,
+ }
+
+ input_file = io.StringIO(textwrap.dedent("""\
+ VERSION_1 {
+ global:
+ foo; # var
+ bar; # x86
+ fizz; # introduced=O
+ buzz; # introduced=P
+ local:
+ *;
+ };
+
+ VERSION_2 { # arm
+ baz; # introduced=9
+ qux; # versioned=14
+ } VERSION_1;
+
+ VERSION_3 { # introduced=14
+ woodly;
+ doodly; # var
+ } VERSION_2;
+
+ VERSION_4 { # versioned=9
+ wibble;
+ wizzes; # llndk
+ waggle; # apex
+ bubble; # apex llndk
+ duddle; # llndk apex
+ } VERSION_2;
+
+ VERSION_5 { # versioned=14
+ wobble;
+ } VERSION_4;
+ """))
+ parser = symbolfile.SymbolFileParser(input_file, api_map, 'arm', 9,
+ False, True)
+ versions = parser.parse()
+
+ src_file = io.StringIO()
+ version_file = io.StringIO()
+ generator = ndkstubgen.Generator(src_file, version_file, 'arm', 9,
+ False, True)
+ generator.write(versions)
+
+ expected_src = textwrap.dedent("""\
+ int foo = 0;
+ void baz() {}
+ void qux() {}
+ void wibble() {}
+ void waggle() {}
+ void bubble() {}
+ void duddle() {}
+ void wobble() {}
+ """)
+ self.assertEqual(expected_src, src_file.getvalue())
+
+ expected_version = textwrap.dedent("""\
+ VERSION_1 {
+ global:
+ foo;
+ };
+ VERSION_2 {
+ global:
+ baz;
+ } VERSION_1;
+ VERSION_4 {
+ global:
+ wibble;
+ waggle;
+ bubble;
+ duddle;
+ } VERSION_2;
+ """)
+ self.assertEqual(expected_version, version_file.getvalue())
+
+def main():
+ suite = unittest.TestLoader().loadTestsFromName(__name__)
+ unittest.TextTestRunner(verbosity=3).run(suite)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/cc/pgo.go b/cc/pgo.go
index 9298e7a..674e1bb 100644
--- a/cc/pgo.go
+++ b/cc/pgo.go
@@ -199,8 +199,8 @@
return false
}
- // If at least one property exists, validate that all properties exist
- if !profileKindPresent || !filePresent || !benchmarksPresent {
+ // profileKindPresent and filePresent are mandatory properties.
+ if !profileKindPresent || !filePresent {
var missing []string
if !profileKindPresent {
missing = append(missing, "profile kind (either \"instrumentation\" or \"sampling\" property)")
@@ -208,13 +208,15 @@
if !filePresent {
missing = append(missing, "profile_file property")
}
- if !benchmarksPresent {
- missing = append(missing, "non-empty benchmarks property")
- }
missingProps := strings.Join(missing, ", ")
ctx.ModuleErrorf("PGO specification is missing properties: " + missingProps)
}
+ // Benchmark property is mandatory for instrumentation PGO.
+ if isInstrumentation && !benchmarksPresent {
+ ctx.ModuleErrorf("Instrumentation PGO specification is missing benchmark property")
+ }
+
if isSampling && isInstrumentation {
ctx.PropertyErrorf("pgo", "Exactly one of \"instrumentation\" and \"sampling\" properties must be set")
}
@@ -288,15 +290,17 @@
// Add flags to profile this module based on its profile_kind
if props.ShouldProfileModule && props.isInstrumentation() {
- return props.addInstrumentationProfileGatherFlags(ctx, flags)
+ props.addInstrumentationProfileGatherFlags(ctx, flags)
+ // Instrumentation PGO use and gather flags cannot coexist.
+ return flags
} else if props.ShouldProfileModule && props.isSampling() {
- return props.addSamplingProfileGatherFlags(ctx, flags)
+ props.addSamplingProfileGatherFlags(ctx, flags)
} else if ctx.DeviceConfig().SamplingPGO() {
- return props.addSamplingProfileGatherFlags(ctx, flags)
+ props.addSamplingProfileGatherFlags(ctx, flags)
}
if !ctx.Config().IsEnvTrue("ANDROID_PGO_NO_PROFILE_USE") {
- return props.addProfileUseFlags(ctx, flags)
+ props.addProfileUseFlags(ctx, flags)
}
return flags
diff --git a/cc/prebuilt.go b/cc/prebuilt.go
index 0751f1c..653b43e 100644
--- a/cc/prebuilt.go
+++ b/cc/prebuilt.go
@@ -26,6 +26,7 @@
ctx.RegisterModuleType("cc_prebuilt_library", PrebuiltLibraryFactory)
ctx.RegisterModuleType("cc_prebuilt_library_shared", PrebuiltSharedLibraryFactory)
ctx.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory)
+ ctx.RegisterModuleType("cc_prebuilt_test_library_shared", PrebuiltSharedTestLibraryFactory)
ctx.RegisterModuleType("cc_prebuilt_object", prebuiltObjectFactory)
ctx.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory)
}
@@ -243,6 +244,16 @@
return module.Init()
}
+// cc_prebuilt_test_library_shared installs a precompiled shared library
+// to be used as a data dependency of a test-related module (such as cc_test, or
+// cc_test_library).
+func PrebuiltSharedTestLibraryFactory() android.Module {
+ module, library := NewPrebuiltLibrary(android.HostAndDeviceSupported)
+ library.BuildOnlyShared()
+ library.baseInstaller = NewTestInstaller()
+ return module.Init()
+}
+
func NewPrebuiltSharedLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
module, library := NewPrebuiltLibrary(hod)
library.BuildOnlyShared()
diff --git a/cc/pylintrc b/cc/pylintrc
index ed49dd7..2032d4e 100644
--- a/cc/pylintrc
+++ b/cc/pylintrc
@@ -1,280 +1,11 @@
-[MASTER]
-
-# Specify a configuration file.
-#rcfile=
-
-# Python code to execute, usually for sys.path manipulation such as
-# pygtk.require().
-#init-hook=
-
-# Profiled execution.
-profile=no
-
-# Add files or directories to the blacklist. They should be base names, not
-# paths.
-ignore=CVS
-
-# Pickle collected data for later comparisons.
-persistent=yes
-
-# List of plugins (as comma separated values of python modules names) to load,
-# usually to register additional checkers.
-load-plugins=
-
-
[MESSAGES CONTROL]
-
-# Enable the message, report, category or checker with the given id(s). You can
-# either give multiple identifier separated by comma (,) or put this option
-# multiple time. See also the "--disable" option for examples.
-#enable=
-
-# Disable the message, report, category or checker with the given id(s). You
-# can either give multiple identifiers separated by comma (,) or put this
-# option multiple times (only on the command line, not in the configuration
-# file where it should appear only once).You can also use "--disable=all" to
-# disable everything first and then reenable specific checks. For example, if
-# you want to run only the similarities checker, you can use "--disable=all
-# --enable=similarities". If you want to run only the classes checker, but have
-# no Warning level messages displayed, use"--disable=all --enable=classes
-# --disable=W"
disable=design,fixme
-
-[REPORTS]
-
-# Set the output format. Available formats are text, parseable, colorized, msvs
-# (visual studio) and html. You can also give a reporter class, eg
-# mypackage.mymodule.MyReporterClass.
-output-format=text
-
-# Put messages in a separate file for each module / package specified on the
-# command line instead of printing them on stdout. Reports (if any) will be
-# written in a file name "pylint_global.[txt|html]".
-files-output=no
-
-# Tells whether to display a full report or only the messages
-reports=yes
-
-# Python expression which should return a note less than 10 (10 is the highest
-# note). You have access to the variables errors warning, statement which
-# respectively contain the number of errors / warnings messages and the total
-# number of statements analyzed. This is used by the global evaluation report
-# (RP0004).
-evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
-
-# Add a comment according to your evaluation note. This is used by the global
-# evaluation report (RP0004).
-comment=no
-
-# Template used to display messages. This is a python new-style format string
-# used to format the message information. See doc for all details
-#msg-template=
-
-
[BASIC]
-
-# Required attributes for module, separated by a comma
-required-attributes=
-
-# List of builtins function names that should not be used, separated by a comma
-bad-functions=map,filter,apply,input
-
-# Regular expression which should only match correct module names
-module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
-
-# Regular expression which should only match correct module level names
-const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
-
-# Regular expression which should only match correct class names
-class-rgx=[A-Z_][a-zA-Z0-9]+$
-
-# Regular expression which should only match correct function names
-function-rgx=[a-z_][a-z0-9_]{2,30}$
-
-# Regular expression which should only match correct method names
-method-rgx=[a-z_][a-z0-9_]{2,30}$
-
-# Regular expression which should only match correct instance attribute names
-attr-rgx=[a-z_][a-z0-9_]{2,30}$
-
-# Regular expression which should only match correct argument names
-argument-rgx=[a-z_][a-z0-9_]{2,30}$
-
-# Regular expression which should only match correct variable names
-variable-rgx=[a-z_][a-z0-9_]{2,30}$
-
-# Regular expression which should only match correct attribute names in class
-# bodies
-class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
-
-# Regular expression which should only match correct list comprehension /
-# generator expression variable names
-inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
-
-# Good variable names which should always be accepted, separated by a comma
good-names=i,j,k,ex,Run,_
-# Bad variable names which should always be refused, separated by a comma
-bad-names=foo,bar,baz,toto,tutu,tata
-
-# Regular expression which should only match function or class names that do
-# not require a docstring.
-no-docstring-rgx=__.*__
-
-# Minimum line length for functions/classes that require docstrings, shorter
-# ones are exempt.
-docstring-min-length=-1
-
-
-[TYPECHECK]
-
-# Tells whether missing members accessed in mixin class should be ignored. A
-# mixin class is detected if its name ends with "mixin" (case insensitive).
-ignore-mixin-members=yes
-
-# List of classes names for which member attributes should not be checked
-# (useful for classes with attributes dynamically set).
-ignored-classes=SQLObject
-
-# When zope mode is activated, add a predefined set of Zope acquired attributes
-# to generated-members.
-zope=no
-
-# List of members which are set dynamically and missed by pylint inference
-# system, and so shouldn't trigger E0201 when accessed. Python regular
-# expressions are accepted.
-generated-members=REQUEST,acl_users,aq_parent
-
-
-[MISCELLANEOUS]
-
-# List of note tags to take in consideration, separated by a comma.
-notes=FIXME,XXX,TODO
-
-
[SIMILARITIES]
-
-# Minimum lines number of a similarity.
-min-similarity-lines=4
-
-# Ignore comments when computing similarities.
-ignore-comments=yes
-
-# Ignore docstrings when computing similarities.
-ignore-docstrings=yes
-
-# Ignore imports when computing similarities.
-ignore-imports=no
-
+ignore-imports=yes
[VARIABLES]
-
-# Tells whether we should check for unused import in __init__ files.
-init-import=no
-
-# A regular expression matching the beginning of the name of dummy variables
-# (i.e. not used).
dummy-variables-rgx=_|dummy
-
-# List of additional names supposed to be defined in builtins. Remember that
-# you should avoid to define new builtins when possible.
-additional-builtins=
-
-
-[FORMAT]
-
-# Maximum number of characters on a single line.
-max-line-length=80
-
-# Regexp for a line that is allowed to be longer than the limit.
-ignore-long-lines=^\s*(# )?<?https?://\S+>?$
-
-# Allow the body of an if to be on the same line as the test if there is no
-# else.
-single-line-if-stmt=no
-
-# List of optional constructs for which whitespace checking is disabled
-no-space-check=trailing-comma,dict-separator
-
-# Maximum number of lines in a module
-max-module-lines=1000
-
-# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
-# tab).
-indent-string=' '
-
-
-[IMPORTS]
-
-# Deprecated modules which should not be used, separated by a comma
-deprecated-modules=regsub,TERMIOS,Bastion,rexec
-
-# Create a graph of every (i.e. internal and external) dependencies in the
-# given file (report RP0402 must not be disabled)
-import-graph=
-
-# Create a graph of external dependencies in the given file (report RP0402 must
-# not be disabled)
-ext-import-graph=
-
-# Create a graph of internal dependencies in the given file (report RP0402 must
-# not be disabled)
-int-import-graph=
-
-
-[DESIGN]
-
-# Maximum number of arguments for function / method
-max-args=5
-
-# Argument names that match this expression will be ignored. Default to name
-# with leading underscore
-ignored-argument-names=_.*
-
-# Maximum number of locals for function / method body
-max-locals=15
-
-# Maximum number of return / yield for function / method body
-max-returns=6
-
-# Maximum number of branch for function / method body
-max-branches=12
-
-# Maximum number of statements in function / method body
-max-statements=50
-
-# Maximum number of parents for a class (see R0901).
-max-parents=7
-
-# Maximum number of attributes for a class (see R0902).
-max-attributes=7
-
-# Minimum number of public methods for a class (see R0903).
-min-public-methods=2
-
-# Maximum number of public methods for a class (see R0904).
-max-public-methods=20
-
-
-[CLASSES]
-
-# List of interface methods to ignore, separated by a comma. This is used for
-# instance to not check methods defines in Zope's Interface base class.
-ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by
-
-# List of method names used to declare (i.e. assign) instance attributes.
-defining-attr-methods=__init__,__new__,setUp
-
-# List of valid names for the first argument in a class method.
-valid-classmethod-first-arg=cls
-
-# List of valid names for the first argument in a metaclass class method.
-valid-metaclass-classmethod-first-arg=mcs
-
-
-[EXCEPTIONS]
-
-# Exceptions that will emit a warning when being caught. Defaults to
-# "Exception"
-overgeneral-exceptions=Exception
diff --git a/cc/sabi.go b/cc/sabi.go
index 8cef170..ef6bead 100644
--- a/cc/sabi.go
+++ b/cc/sabi.go
@@ -83,10 +83,7 @@
((c.IsVndk() && c.UseVndk()) || c.isLlndk(mctx.Config()) ||
(c.sabi != nil && c.sabi.Properties.CreateSAbiDumps)) {
mctx.VisitDirectDeps(func(m android.Module) {
- tag := mctx.OtherModuleDependencyTag(m)
- switch tag {
- case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
-
+ if tag, ok := mctx.OtherModuleDependencyTag(m).(libraryDependencyTag); ok && tag.static() {
cc, _ := m.(*Module)
if cc == nil {
return
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 136a510..3433dd3 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -51,17 +51,15 @@
}
cfiCflags = []string{"-flto", "-fsanitize-cfi-cross-dso",
- "-fsanitize-blacklist=external/compiler-rt/lib/cfi/cfi_blacklist.txt"}
+ "-fsanitize-blacklist=external/compiler-rt/lib/cfi/cfi_blocklist.txt"}
// -flto and -fvisibility are required by clang when -fsanitize=cfi is
// used, but have no effect on assembly files
cfiAsflags = []string{"-flto", "-fvisibility=default"}
cfiLdflags = []string{"-flto", "-fsanitize-cfi-cross-dso", "-fsanitize=cfi",
"-Wl,-plugin-opt,O1"}
- cfiExportsMapPath = "build/soong/cc/config/cfi_exports.map"
- cfiStaticLibsMutex sync.Mutex
- hwasanStaticLibsMutex sync.Mutex
+ cfiExportsMapPath = "build/soong/cc/config/cfi_exports.map"
- intOverflowCflags = []string{"-fsanitize-blacklist=build/soong/cc/config/integer_overflow_blacklist.txt"}
+ intOverflowCflags = []string{"-fsanitize-blacklist=build/soong/cc/config/integer_overflow_blocklist.txt"}
minimalRuntimeFlags = []string{"-fsanitize-minimal-runtime", "-fno-sanitize-trap=integer,undefined",
"-fno-sanitize-recover=integer,undefined"}
@@ -177,6 +175,8 @@
// value to pass to -fsanitize-blacklist
Blacklist *string
+ // value to pass to -fsanitize-blacklist
+ Blocklist *string
} `android:"arch_variant"`
SanitizerEnabled bool `blueprint:"mutated"`
@@ -615,6 +615,12 @@
flags.CFlagsDeps = append(flags.CFlagsDeps, blacklist.Path())
}
+ blocklist := android.OptionalPathForModuleSrc(ctx, sanitize.Properties.Sanitize.Blocklist)
+ if blocklist.Valid() {
+ flags.Local.CFlags = append(flags.Local.CFlags, "-fsanitize-blacklist="+blocklist.String())
+ flags.CFlagsDeps = append(flags.CFlagsDeps, blocklist.Path())
+ }
+
return flags
}
@@ -725,8 +731,14 @@
}
func isSanitizableDependencyTag(tag blueprint.DependencyTag) bool {
- t, ok := tag.(DependencyTag)
- return ok && t.Library || t == reuseObjTag || t == objDepTag
+ switch t := tag.(type) {
+ case dependencyTag:
+ return t == reuseObjTag || t == objDepTag
+ case libraryDependencyTag:
+ return true
+ default:
+ return false
+ }
}
// Propagate sanitizer requirements down from binaries
@@ -968,10 +980,11 @@
}
// static executable gets static runtime libs
+ depTag := libraryDependencyTag{Kind: staticLibraryDependency}
mctx.AddFarVariationDependencies(append(mctx.Target().Variations(), []blueprint.Variation{
{Mutator: "link", Variation: "static"},
c.ImageVariation(),
- }...), StaticDepTag, deps...)
+ }...), depTag, deps...)
} else if !c.static() && !c.header() {
// If we're using snapshots and in vendor, redirect to snapshot whenever possible
if c.VndkVersion() == mctx.DeviceConfig().VndkVersion() {
@@ -982,10 +995,11 @@
}
// dynamic executable and shared libs get shared runtime libs
+ depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: earlyLibraryDependency}
mctx.AddFarVariationDependencies(append(mctx.Target().Variations(), []blueprint.Variation{
{Mutator: "link", Variation: "shared"},
c.ImageVariation(),
- }...), earlySharedDepTag, runtimeLibrary)
+ }...), depTag, runtimeLibrary)
}
// static lib does not have dependency to the runtime library. The
// dependency will be added to the executables or shared libs using
@@ -1053,15 +1067,9 @@
// Export the static lib name to make
if c.static() && c.ExportedToMake() {
if t == cfi {
- appendStringSync(c.Name(), cfiStaticLibs(mctx.Config()), &cfiStaticLibsMutex)
+ cfiStaticLibs(mctx.Config()).add(c, c.Name())
} else if t == hwasan {
- if c.UseVndk() {
- appendStringSync(c.Name(), hwasanVendorStaticLibs(mctx.Config()),
- &hwasanStaticLibsMutex)
- } else {
- appendStringSync(c.Name(), hwasanStaticLibs(mctx.Config()),
- &hwasanStaticLibsMutex)
- }
+ hwasanStaticLibs(mctx.Config()).add(c, c.Name())
}
}
} else {
@@ -1091,34 +1099,74 @@
}
}
+type sanitizerStaticLibsMap struct {
+ // libsMap contains one list of modules per each image and each arch.
+ // e.g. libs[vendor]["arm"] contains arm modules installed to vendor
+ libsMap map[imageVariantType]map[string][]string
+ libsMapLock sync.Mutex
+ sanitizerType sanitizerType
+}
+
+func newSanitizerStaticLibsMap(t sanitizerType) *sanitizerStaticLibsMap {
+ return &sanitizerStaticLibsMap{
+ sanitizerType: t,
+ libsMap: make(map[imageVariantType]map[string][]string),
+ }
+}
+
+// Add the current module to sanitizer static libs maps
+// Each module should pass its exported name as names of Make and Soong can differ.
+func (s *sanitizerStaticLibsMap) add(c *Module, name string) {
+ image := c.getImageVariantType()
+ arch := c.Arch().ArchType.String()
+
+ s.libsMapLock.Lock()
+ defer s.libsMapLock.Unlock()
+
+ if _, ok := s.libsMap[image]; !ok {
+ s.libsMap[image] = make(map[string][]string)
+ }
+
+ s.libsMap[image][arch] = append(s.libsMap[image][arch], name)
+}
+
+// Exports makefile variables in the following format:
+// SOONG_{sanitizer}_{image}_{arch}_STATIC_LIBRARIES
+// e.g. SOONG_cfi_core_x86_STATIC_LIBRARIES
+// These are to be used by use_soong_sanitized_static_libraries.
+// See build/make/core/binary.mk for more details.
+func (s *sanitizerStaticLibsMap) exportToMake(ctx android.MakeVarsContext) {
+ for _, image := range android.SortedStringKeys(s.libsMap) {
+ archMap := s.libsMap[imageVariantType(image)]
+ for _, arch := range android.SortedStringKeys(archMap) {
+ libs := archMap[arch]
+ sort.Strings(libs)
+
+ key := fmt.Sprintf(
+ "SOONG_%s_%s_%s_STATIC_LIBRARIES",
+ s.sanitizerType.variationName(),
+ image, // already upper
+ arch)
+
+ ctx.Strict(key, strings.Join(libs, " "))
+ }
+ }
+}
+
var cfiStaticLibsKey = android.NewOnceKey("cfiStaticLibs")
-func cfiStaticLibs(config android.Config) *[]string {
+func cfiStaticLibs(config android.Config) *sanitizerStaticLibsMap {
return config.Once(cfiStaticLibsKey, func() interface{} {
- return &[]string{}
- }).(*[]string)
+ return newSanitizerStaticLibsMap(cfi)
+ }).(*sanitizerStaticLibsMap)
}
var hwasanStaticLibsKey = android.NewOnceKey("hwasanStaticLibs")
-func hwasanStaticLibs(config android.Config) *[]string {
+func hwasanStaticLibs(config android.Config) *sanitizerStaticLibsMap {
return config.Once(hwasanStaticLibsKey, func() interface{} {
- return &[]string{}
- }).(*[]string)
-}
-
-var hwasanVendorStaticLibsKey = android.NewOnceKey("hwasanVendorStaticLibs")
-
-func hwasanVendorStaticLibs(config android.Config) *[]string {
- return config.Once(hwasanVendorStaticLibsKey, func() interface{} {
- return &[]string{}
- }).(*[]string)
-}
-
-func appendStringSync(item string, list *[]string, mutex *sync.Mutex) {
- mutex.Lock()
- *list = append(*list, item)
- mutex.Unlock()
+ return newSanitizerStaticLibsMap(hwasan)
+ }).(*sanitizerStaticLibsMap)
}
func enableMinimalRuntime(sanitize *sanitize) bool {
@@ -1148,17 +1196,9 @@
}
func cfiMakeVarsProvider(ctx android.MakeVarsContext) {
- cfiStaticLibs := cfiStaticLibs(ctx.Config())
- sort.Strings(*cfiStaticLibs)
- ctx.Strict("SOONG_CFI_STATIC_LIBRARIES", strings.Join(*cfiStaticLibs, " "))
+ cfiStaticLibs(ctx.Config()).exportToMake(ctx)
}
func hwasanMakeVarsProvider(ctx android.MakeVarsContext) {
- hwasanStaticLibs := hwasanStaticLibs(ctx.Config())
- sort.Strings(*hwasanStaticLibs)
- ctx.Strict("SOONG_HWASAN_STATIC_LIBRARIES", strings.Join(*hwasanStaticLibs, " "))
-
- hwasanVendorStaticLibs := hwasanVendorStaticLibs(ctx.Config())
- sort.Strings(*hwasanVendorStaticLibs)
- ctx.Strict("SOONG_HWASAN_VENDOR_STATIC_LIBRARIES", strings.Join(*hwasanVendorStaticLibs, " "))
+ hwasanStaticLibs(ctx.Config()).exportToMake(ctx)
}
diff --git a/cc/scriptlib/__init__.py b/cc/scriptlib/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/cc/scriptlib/__init__.py
+++ /dev/null
diff --git a/cc/scriptlib/test_gen_stub_libs.py b/cc/scriptlib/test_gen_stub_libs.py
deleted file mode 100755
index 0b45e71..0000000
--- a/cc/scriptlib/test_gen_stub_libs.py
+++ /dev/null
@@ -1,807 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2016 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.
-#
-"""Tests for gen_stub_libs.py."""
-import io
-import textwrap
-import unittest
-
-import gen_stub_libs as gsl
-
-
-# pylint: disable=missing-docstring
-
-
-class DecodeApiLevelTest(unittest.TestCase):
- def test_decode_api_level(self):
- self.assertEqual(9, gsl.decode_api_level('9', {}))
- self.assertEqual(9000, gsl.decode_api_level('O', {'O': 9000}))
-
- with self.assertRaises(KeyError):
- gsl.decode_api_level('O', {})
-
-
-class TagsTest(unittest.TestCase):
- def test_get_tags_no_tags(self):
- self.assertEqual([], gsl.get_tags(''))
- self.assertEqual([], gsl.get_tags('foo bar baz'))
-
- def test_get_tags(self):
- self.assertEqual(['foo', 'bar'], gsl.get_tags('# foo bar'))
- self.assertEqual(['bar', 'baz'], gsl.get_tags('foo # bar baz'))
-
- def test_split_tag(self):
- self.assertTupleEqual(('foo', 'bar'), gsl.split_tag('foo=bar'))
- self.assertTupleEqual(('foo', 'bar=baz'), gsl.split_tag('foo=bar=baz'))
- with self.assertRaises(ValueError):
- gsl.split_tag('foo')
-
- def test_get_tag_value(self):
- self.assertEqual('bar', gsl.get_tag_value('foo=bar'))
- self.assertEqual('bar=baz', gsl.get_tag_value('foo=bar=baz'))
- with self.assertRaises(ValueError):
- gsl.get_tag_value('foo')
-
- def test_is_api_level_tag(self):
- self.assertTrue(gsl.is_api_level_tag('introduced=24'))
- self.assertTrue(gsl.is_api_level_tag('introduced-arm=24'))
- self.assertTrue(gsl.is_api_level_tag('versioned=24'))
-
- # Shouldn't try to process things that aren't a key/value tag.
- self.assertFalse(gsl.is_api_level_tag('arm'))
- self.assertFalse(gsl.is_api_level_tag('introduced'))
- self.assertFalse(gsl.is_api_level_tag('versioned'))
-
- # We don't support arch specific `versioned` tags.
- self.assertFalse(gsl.is_api_level_tag('versioned-arm=24'))
-
- def test_decode_api_level_tags(self):
- api_map = {
- 'O': 9000,
- 'P': 9001,
- }
-
- tags = [
- 'introduced=9',
- 'introduced-arm=14',
- 'versioned=16',
- 'arm',
- 'introduced=O',
- 'introduced=P',
- ]
- expected_tags = [
- 'introduced=9',
- 'introduced-arm=14',
- 'versioned=16',
- 'arm',
- 'introduced=9000',
- 'introduced=9001',
- ]
- self.assertListEqual(
- expected_tags, gsl.decode_api_level_tags(tags, api_map))
-
- with self.assertRaises(gsl.ParseError):
- gsl.decode_api_level_tags(['introduced=O'], {})
-
-
-class PrivateVersionTest(unittest.TestCase):
- def test_version_is_private(self):
- self.assertFalse(gsl.version_is_private('foo'))
- self.assertFalse(gsl.version_is_private('PRIVATE'))
- self.assertFalse(gsl.version_is_private('PLATFORM'))
- self.assertFalse(gsl.version_is_private('foo_private'))
- self.assertFalse(gsl.version_is_private('foo_platform'))
- self.assertFalse(gsl.version_is_private('foo_PRIVATE_'))
- self.assertFalse(gsl.version_is_private('foo_PLATFORM_'))
-
- self.assertTrue(gsl.version_is_private('foo_PRIVATE'))
- self.assertTrue(gsl.version_is_private('foo_PLATFORM'))
-
-
-class SymbolPresenceTest(unittest.TestCase):
- def test_symbol_in_arch(self):
- self.assertTrue(gsl.symbol_in_arch([], 'arm'))
- self.assertTrue(gsl.symbol_in_arch(['arm'], 'arm'))
-
- self.assertFalse(gsl.symbol_in_arch(['x86'], 'arm'))
-
- def test_symbol_in_api(self):
- self.assertTrue(gsl.symbol_in_api([], 'arm', 9))
- self.assertTrue(gsl.symbol_in_api(['introduced=9'], 'arm', 9))
- self.assertTrue(gsl.symbol_in_api(['introduced=9'], 'arm', 14))
- self.assertTrue(gsl.symbol_in_api(['introduced-arm=9'], 'arm', 14))
- self.assertTrue(gsl.symbol_in_api(['introduced-arm=9'], 'arm', 14))
- self.assertTrue(gsl.symbol_in_api(['introduced-x86=14'], 'arm', 9))
- self.assertTrue(gsl.symbol_in_api(
- ['introduced-arm=9', 'introduced-x86=21'], 'arm', 14))
- self.assertTrue(gsl.symbol_in_api(
- ['introduced=9', 'introduced-x86=21'], 'arm', 14))
- self.assertTrue(gsl.symbol_in_api(
- ['introduced=21', 'introduced-arm=9'], 'arm', 14))
- self.assertTrue(gsl.symbol_in_api(
- ['future'], 'arm', gsl.FUTURE_API_LEVEL))
-
- self.assertFalse(gsl.symbol_in_api(['introduced=14'], 'arm', 9))
- self.assertFalse(gsl.symbol_in_api(['introduced-arm=14'], 'arm', 9))
- self.assertFalse(gsl.symbol_in_api(['future'], 'arm', 9))
- self.assertFalse(gsl.symbol_in_api(
- ['introduced=9', 'future'], 'arm', 14))
- self.assertFalse(gsl.symbol_in_api(
- ['introduced-arm=9', 'future'], 'arm', 14))
- self.assertFalse(gsl.symbol_in_api(
- ['introduced-arm=21', 'introduced-x86=9'], 'arm', 14))
- self.assertFalse(gsl.symbol_in_api(
- ['introduced=9', 'introduced-arm=21'], 'arm', 14))
- self.assertFalse(gsl.symbol_in_api(
- ['introduced=21', 'introduced-x86=9'], 'arm', 14))
-
- # Interesting edge case: this symbol should be omitted from the
- # library, but this call should still return true because none of the
- # tags indiciate that it's not present in this API level.
- self.assertTrue(gsl.symbol_in_api(['x86'], 'arm', 9))
-
- def test_verioned_in_api(self):
- self.assertTrue(gsl.symbol_versioned_in_api([], 9))
- self.assertTrue(gsl.symbol_versioned_in_api(['versioned=9'], 9))
- self.assertTrue(gsl.symbol_versioned_in_api(['versioned=9'], 14))
-
- self.assertFalse(gsl.symbol_versioned_in_api(['versioned=14'], 9))
-
-
-class OmitVersionTest(unittest.TestCase):
- def test_omit_private(self):
- self.assertFalse(
- gsl.should_omit_version(
- gsl.Version('foo', None, [], []), 'arm', 9, False, False))
-
- self.assertTrue(
- gsl.should_omit_version(
- gsl.Version('foo_PRIVATE', None, [], []), 'arm', 9, False, False))
- self.assertTrue(
- gsl.should_omit_version(
- gsl.Version('foo_PLATFORM', None, [], []), 'arm', 9, False, False))
-
- self.assertTrue(
- gsl.should_omit_version(
- gsl.Version('foo', None, ['platform-only'], []), 'arm', 9,
- False, False))
-
- def test_omit_llndk(self):
- self.assertTrue(
- gsl.should_omit_version(
- gsl.Version('foo', None, ['llndk'], []), 'arm', 9, False, False))
-
- self.assertFalse(
- gsl.should_omit_version(
- gsl.Version('foo', None, [], []), 'arm', 9, True, False))
- self.assertFalse(
- gsl.should_omit_version(
- gsl.Version('foo', None, ['llndk'], []), 'arm', 9, True, False))
-
- def test_omit_apex(self):
- self.assertTrue(
- gsl.should_omit_version(
- gsl.Version('foo', None, ['apex'], []), 'arm', 9, False, False))
-
- self.assertFalse(
- gsl.should_omit_version(
- gsl.Version('foo', None, [], []), 'arm', 9, False, True))
- self.assertFalse(
- gsl.should_omit_version(
- gsl.Version('foo', None, ['apex'], []), 'arm', 9, False, True))
-
- def test_omit_arch(self):
- self.assertFalse(
- gsl.should_omit_version(
- gsl.Version('foo', None, [], []), 'arm', 9, False, False))
- self.assertFalse(
- gsl.should_omit_version(
- gsl.Version('foo', None, ['arm'], []), 'arm', 9, False, False))
-
- self.assertTrue(
- gsl.should_omit_version(
- gsl.Version('foo', None, ['x86'], []), 'arm', 9, False, False))
-
- def test_omit_api(self):
- self.assertFalse(
- gsl.should_omit_version(
- gsl.Version('foo', None, [], []), 'arm', 9, False, False))
- self.assertFalse(
- gsl.should_omit_version(
- gsl.Version('foo', None, ['introduced=9'], []), 'arm', 9,
- False, False))
-
- self.assertTrue(
- gsl.should_omit_version(
- gsl.Version('foo', None, ['introduced=14'], []), 'arm', 9,
- False, False))
-
-
-class OmitSymbolTest(unittest.TestCase):
- def test_omit_llndk(self):
- self.assertTrue(
- gsl.should_omit_symbol(
- gsl.Symbol('foo', ['llndk']), 'arm', 9, False, False))
-
- self.assertFalse(
- gsl.should_omit_symbol(gsl.Symbol('foo', []), 'arm', 9, True, False))
- self.assertFalse(
- gsl.should_omit_symbol(
- gsl.Symbol('foo', ['llndk']), 'arm', 9, True, False))
-
- def test_omit_apex(self):
- self.assertTrue(
- gsl.should_omit_symbol(
- gsl.Symbol('foo', ['apex']), 'arm', 9, False, False))
-
- self.assertFalse(
- gsl.should_omit_symbol(gsl.Symbol('foo', []), 'arm', 9, False, True))
- self.assertFalse(
- gsl.should_omit_symbol(
- gsl.Symbol('foo', ['apex']), 'arm', 9, False, True))
-
- def test_omit_arch(self):
- self.assertFalse(
- gsl.should_omit_symbol(gsl.Symbol('foo', []), 'arm', 9, False, False))
- self.assertFalse(
- gsl.should_omit_symbol(
- gsl.Symbol('foo', ['arm']), 'arm', 9, False, False))
-
- self.assertTrue(
- gsl.should_omit_symbol(
- gsl.Symbol('foo', ['x86']), 'arm', 9, False, False))
-
- def test_omit_api(self):
- self.assertFalse(
- gsl.should_omit_symbol(gsl.Symbol('foo', []), 'arm', 9, False, False))
- self.assertFalse(
- gsl.should_omit_symbol(
- gsl.Symbol('foo', ['introduced=9']), 'arm', 9, False, False))
-
- self.assertTrue(
- gsl.should_omit_symbol(
- gsl.Symbol('foo', ['introduced=14']), 'arm', 9, False, False))
-
-
-class SymbolFileParseTest(unittest.TestCase):
- def test_next_line(self):
- input_file = io.StringIO(textwrap.dedent("""\
- foo
-
- bar
- # baz
- qux
- """))
- parser = gsl.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
- self.assertIsNone(parser.current_line)
-
- self.assertEqual('foo', parser.next_line().strip())
- self.assertEqual('foo', parser.current_line.strip())
-
- self.assertEqual('bar', parser.next_line().strip())
- self.assertEqual('bar', parser.current_line.strip())
-
- self.assertEqual('qux', parser.next_line().strip())
- self.assertEqual('qux', parser.current_line.strip())
-
- self.assertEqual('', parser.next_line())
- self.assertEqual('', parser.current_line)
-
- def test_parse_version(self):
- input_file = io.StringIO(textwrap.dedent("""\
- VERSION_1 { # foo bar
- baz;
- qux; # woodly doodly
- };
-
- VERSION_2 {
- } VERSION_1; # asdf
- """))
- parser = gsl.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
-
- parser.next_line()
- version = parser.parse_version()
- self.assertEqual('VERSION_1', version.name)
- self.assertIsNone(version.base)
- self.assertEqual(['foo', 'bar'], version.tags)
-
- expected_symbols = [
- gsl.Symbol('baz', []),
- gsl.Symbol('qux', ['woodly', 'doodly']),
- ]
- self.assertEqual(expected_symbols, version.symbols)
-
- parser.next_line()
- version = parser.parse_version()
- self.assertEqual('VERSION_2', version.name)
- self.assertEqual('VERSION_1', version.base)
- self.assertEqual([], version.tags)
-
- def test_parse_version_eof(self):
- input_file = io.StringIO(textwrap.dedent("""\
- VERSION_1 {
- """))
- parser = gsl.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
- parser.next_line()
- with self.assertRaises(gsl.ParseError):
- parser.parse_version()
-
- def test_unknown_scope_label(self):
- input_file = io.StringIO(textwrap.dedent("""\
- VERSION_1 {
- foo:
- }
- """))
- parser = gsl.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
- parser.next_line()
- with self.assertRaises(gsl.ParseError):
- parser.parse_version()
-
- def test_parse_symbol(self):
- input_file = io.StringIO(textwrap.dedent("""\
- foo;
- bar; # baz qux
- """))
- parser = gsl.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
-
- parser.next_line()
- symbol = parser.parse_symbol()
- self.assertEqual('foo', symbol.name)
- self.assertEqual([], symbol.tags)
-
- parser.next_line()
- symbol = parser.parse_symbol()
- self.assertEqual('bar', symbol.name)
- self.assertEqual(['baz', 'qux'], symbol.tags)
-
- def test_wildcard_symbol_global(self):
- input_file = io.StringIO(textwrap.dedent("""\
- VERSION_1 {
- *;
- };
- """))
- parser = gsl.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
- parser.next_line()
- with self.assertRaises(gsl.ParseError):
- parser.parse_version()
-
- def test_wildcard_symbol_local(self):
- input_file = io.StringIO(textwrap.dedent("""\
- VERSION_1 {
- local:
- *;
- };
- """))
- parser = gsl.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
- parser.next_line()
- version = parser.parse_version()
- self.assertEqual([], version.symbols)
-
- def test_missing_semicolon(self):
- input_file = io.StringIO(textwrap.dedent("""\
- VERSION_1 {
- foo
- };
- """))
- parser = gsl.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
- parser.next_line()
- with self.assertRaises(gsl.ParseError):
- parser.parse_version()
-
- def test_parse_fails_invalid_input(self):
- with self.assertRaises(gsl.ParseError):
- input_file = io.StringIO('foo')
- parser = gsl.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
- parser.parse()
-
- def test_parse(self):
- input_file = io.StringIO(textwrap.dedent("""\
- VERSION_1 {
- local:
- hidden1;
- global:
- foo;
- bar; # baz
- };
-
- VERSION_2 { # wasd
- # Implicit global scope.
- woodly;
- doodly; # asdf
- local:
- qwerty;
- } VERSION_1;
- """))
- parser = gsl.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
- versions = parser.parse()
-
- expected = [
- gsl.Version('VERSION_1', None, [], [
- gsl.Symbol('foo', []),
- gsl.Symbol('bar', ['baz']),
- ]),
- gsl.Version('VERSION_2', 'VERSION_1', ['wasd'], [
- gsl.Symbol('woodly', []),
- gsl.Symbol('doodly', ['asdf']),
- ]),
- ]
-
- self.assertEqual(expected, versions)
-
- def test_parse_llndk_apex_symbol(self):
- input_file = io.StringIO(textwrap.dedent("""\
- VERSION_1 {
- foo;
- bar; # llndk
- baz; # llndk apex
- qux; # apex
- };
- """))
- parser = gsl.SymbolFileParser(input_file, {}, 'arm', 16, False, True)
-
- parser.next_line()
- version = parser.parse_version()
- self.assertEqual('VERSION_1', version.name)
- self.assertIsNone(version.base)
-
- expected_symbols = [
- gsl.Symbol('foo', []),
- gsl.Symbol('bar', ['llndk']),
- gsl.Symbol('baz', ['llndk', 'apex']),
- gsl.Symbol('qux', ['apex']),
- ]
- self.assertEqual(expected_symbols, version.symbols)
-
-
-class GeneratorTest(unittest.TestCase):
- def test_omit_version(self):
- # Thorough testing of the cases involved here is handled by
- # OmitVersionTest, PrivateVersionTest, and SymbolPresenceTest.
- src_file = io.StringIO()
- version_file = io.StringIO()
- generator = gsl.Generator(src_file, version_file, 'arm', 9, False, False)
-
- version = gsl.Version('VERSION_PRIVATE', None, [], [
- gsl.Symbol('foo', []),
- ])
- generator.write_version(version)
- self.assertEqual('', src_file.getvalue())
- self.assertEqual('', version_file.getvalue())
-
- version = gsl.Version('VERSION', None, ['x86'], [
- gsl.Symbol('foo', []),
- ])
- generator.write_version(version)
- self.assertEqual('', src_file.getvalue())
- self.assertEqual('', version_file.getvalue())
-
- version = gsl.Version('VERSION', None, ['introduced=14'], [
- gsl.Symbol('foo', []),
- ])
- generator.write_version(version)
- self.assertEqual('', src_file.getvalue())
- self.assertEqual('', version_file.getvalue())
-
- def test_omit_symbol(self):
- # Thorough testing of the cases involved here is handled by
- # SymbolPresenceTest.
- src_file = io.StringIO()
- version_file = io.StringIO()
- generator = gsl.Generator(src_file, version_file, 'arm', 9, False, False)
-
- version = gsl.Version('VERSION_1', None, [], [
- gsl.Symbol('foo', ['x86']),
- ])
- generator.write_version(version)
- self.assertEqual('', src_file.getvalue())
- self.assertEqual('', version_file.getvalue())
-
- version = gsl.Version('VERSION_1', None, [], [
- gsl.Symbol('foo', ['introduced=14']),
- ])
- generator.write_version(version)
- self.assertEqual('', src_file.getvalue())
- self.assertEqual('', version_file.getvalue())
-
- version = gsl.Version('VERSION_1', None, [], [
- gsl.Symbol('foo', ['llndk']),
- ])
- generator.write_version(version)
- self.assertEqual('', src_file.getvalue())
- self.assertEqual('', version_file.getvalue())
-
- version = gsl.Version('VERSION_1', None, [], [
- gsl.Symbol('foo', ['apex']),
- ])
- generator.write_version(version)
- self.assertEqual('', src_file.getvalue())
- self.assertEqual('', version_file.getvalue())
-
- def test_write(self):
- src_file = io.StringIO()
- version_file = io.StringIO()
- generator = gsl.Generator(src_file, version_file, 'arm', 9, False, False)
-
- versions = [
- gsl.Version('VERSION_1', None, [], [
- gsl.Symbol('foo', []),
- gsl.Symbol('bar', ['var']),
- gsl.Symbol('woodly', ['weak']),
- gsl.Symbol('doodly', ['weak', 'var']),
- ]),
- gsl.Version('VERSION_2', 'VERSION_1', [], [
- gsl.Symbol('baz', []),
- ]),
- gsl.Version('VERSION_3', 'VERSION_1', [], [
- gsl.Symbol('qux', ['versioned=14']),
- ]),
- ]
-
- generator.write(versions)
- expected_src = textwrap.dedent("""\
- void foo() {}
- int bar = 0;
- __attribute__((weak)) void woodly() {}
- __attribute__((weak)) int doodly = 0;
- void baz() {}
- void qux() {}
- """)
- self.assertEqual(expected_src, src_file.getvalue())
-
- expected_version = textwrap.dedent("""\
- VERSION_1 {
- global:
- foo;
- bar;
- woodly;
- doodly;
- };
- VERSION_2 {
- global:
- baz;
- } VERSION_1;
- """)
- self.assertEqual(expected_version, version_file.getvalue())
-
-
-class IntegrationTest(unittest.TestCase):
- def test_integration(self):
- api_map = {
- 'O': 9000,
- 'P': 9001,
- }
-
- input_file = io.StringIO(textwrap.dedent("""\
- VERSION_1 {
- global:
- foo; # var
- bar; # x86
- fizz; # introduced=O
- buzz; # introduced=P
- local:
- *;
- };
-
- VERSION_2 { # arm
- baz; # introduced=9
- qux; # versioned=14
- } VERSION_1;
-
- VERSION_3 { # introduced=14
- woodly;
- doodly; # var
- } VERSION_2;
-
- VERSION_4 { # versioned=9
- wibble;
- wizzes; # llndk
- waggle; # apex
- } VERSION_2;
-
- VERSION_5 { # versioned=14
- wobble;
- } VERSION_4;
- """))
- parser = gsl.SymbolFileParser(input_file, api_map, 'arm', 9, False, False)
- versions = parser.parse()
-
- src_file = io.StringIO()
- version_file = io.StringIO()
- generator = gsl.Generator(src_file, version_file, 'arm', 9, False, False)
- generator.write(versions)
-
- expected_src = textwrap.dedent("""\
- int foo = 0;
- void baz() {}
- void qux() {}
- void wibble() {}
- void wobble() {}
- """)
- self.assertEqual(expected_src, src_file.getvalue())
-
- expected_version = textwrap.dedent("""\
- VERSION_1 {
- global:
- foo;
- };
- VERSION_2 {
- global:
- baz;
- } VERSION_1;
- VERSION_4 {
- global:
- wibble;
- } VERSION_2;
- """)
- self.assertEqual(expected_version, version_file.getvalue())
-
- def test_integration_future_api(self):
- api_map = {
- 'O': 9000,
- 'P': 9001,
- 'Q': 9002,
- }
-
- input_file = io.StringIO(textwrap.dedent("""\
- VERSION_1 {
- global:
- foo; # introduced=O
- bar; # introduced=P
- baz; # introduced=Q
- local:
- *;
- };
- """))
- parser = gsl.SymbolFileParser(input_file, api_map, 'arm', 9001, False, False)
- versions = parser.parse()
-
- src_file = io.StringIO()
- version_file = io.StringIO()
- generator = gsl.Generator(src_file, version_file, 'arm', 9001, False, False)
- generator.write(versions)
-
- expected_src = textwrap.dedent("""\
- void foo() {}
- void bar() {}
- """)
- self.assertEqual(expected_src, src_file.getvalue())
-
- expected_version = textwrap.dedent("""\
- VERSION_1 {
- global:
- foo;
- bar;
- };
- """)
- self.assertEqual(expected_version, version_file.getvalue())
-
- def test_multiple_definition(self):
- input_file = io.StringIO(textwrap.dedent("""\
- VERSION_1 {
- global:
- foo;
- foo;
- bar;
- baz;
- qux; # arm
- local:
- *;
- };
-
- VERSION_2 {
- global:
- bar;
- qux; # arm64
- } VERSION_1;
-
- VERSION_PRIVATE {
- global:
- baz;
- } VERSION_2;
-
- """))
- parser = gsl.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
-
- with self.assertRaises(gsl.MultiplyDefinedSymbolError) as cm:
- parser.parse()
- self.assertEquals(['bar', 'foo'],
- cm.exception.multiply_defined_symbols)
-
- def test_integration_with_apex(self):
- api_map = {
- 'O': 9000,
- 'P': 9001,
- }
-
- input_file = io.StringIO(textwrap.dedent("""\
- VERSION_1 {
- global:
- foo; # var
- bar; # x86
- fizz; # introduced=O
- buzz; # introduced=P
- local:
- *;
- };
-
- VERSION_2 { # arm
- baz; # introduced=9
- qux; # versioned=14
- } VERSION_1;
-
- VERSION_3 { # introduced=14
- woodly;
- doodly; # var
- } VERSION_2;
-
- VERSION_4 { # versioned=9
- wibble;
- wizzes; # llndk
- waggle; # apex
- bubble; # apex llndk
- duddle; # llndk apex
- } VERSION_2;
-
- VERSION_5 { # versioned=14
- wobble;
- } VERSION_4;
- """))
- parser = gsl.SymbolFileParser(input_file, api_map, 'arm', 9, False, True)
- versions = parser.parse()
-
- src_file = io.StringIO()
- version_file = io.StringIO()
- generator = gsl.Generator(src_file, version_file, 'arm', 9, False, True)
- generator.write(versions)
-
- expected_src = textwrap.dedent("""\
- int foo = 0;
- void baz() {}
- void qux() {}
- void wibble() {}
- void waggle() {}
- void bubble() {}
- void duddle() {}
- void wobble() {}
- """)
- self.assertEqual(expected_src, src_file.getvalue())
-
- expected_version = textwrap.dedent("""\
- VERSION_1 {
- global:
- foo;
- };
- VERSION_2 {
- global:
- baz;
- } VERSION_1;
- VERSION_4 {
- global:
- wibble;
- waggle;
- bubble;
- duddle;
- } VERSION_2;
- """)
- self.assertEqual(expected_version, version_file.getvalue())
-
-def main():
- suite = unittest.TestLoader().loadTestsFromName(__name__)
- unittest.TextTestRunner(verbosity=3).run(suite)
-
-
-if __name__ == '__main__':
- main()
diff --git a/cc/scriptlib/test_ndk_api_coverage_parser.py b/cc/scriptlib/test_ndk_api_coverage_parser.py
deleted file mode 100644
index a3c9b70..0000000
--- a/cc/scriptlib/test_ndk_api_coverage_parser.py
+++ /dev/null
@@ -1,66 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2016 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.
-#
-"""Tests for ndk_api_coverage_parser.py."""
-import io
-import textwrap
-import unittest
-
-from xml.etree.ElementTree import tostring
-from gen_stub_libs import FUTURE_API_LEVEL, SymbolFileParser
-import ndk_api_coverage_parser as nparser
-
-
-# pylint: disable=missing-docstring
-
-
-class ApiCoverageSymbolFileParserTest(unittest.TestCase):
- def test_parse(self):
- input_file = io.StringIO(textwrap.dedent(u"""\
- LIBLOG { # introduced-arm64=24 introduced-x86=24 introduced-x86_64=24
- global:
- android_name_to_log_id; # apex llndk introduced=23
- android_log_id_to_name; # llndk arm
- __android_log_assert; # introduced-x86=23
- __android_log_buf_print; # var
- __android_log_buf_write;
- local:
- *;
- };
-
- LIBLOG_PLATFORM {
- android_fdtrack; # llndk
- android_net; # introduced=23
- };
-
- LIBLOG_FOO { # var
- android_var;
- };
- """))
- parser = SymbolFileParser(input_file, {}, "", FUTURE_API_LEVEL, True, True)
- generator = nparser.XmlGenerator(io.StringIO())
- result = tostring(generator.convertToXml(parser.parse())).decode()
- expected = '<ndk-library><symbol apex="True" arch="" introduced="23" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" llndk="True" name="android_name_to_log_id" /><symbol arch="arm" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" llndk="True" name="android_log_id_to_name" /><symbol arch="" introduced-arm64="24" introduced-x86="23" introduced-x86_64="24" is_deprecated="False" is_platform="False" name="__android_log_assert" /><symbol arch="" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" name="__android_log_buf_write" /><symbol arch="" is_deprecated="False" is_platform="True" llndk="True" name="android_fdtrack" /><symbol arch="" introduced="23" is_deprecated="False" is_platform="True" name="android_net" /></ndk-library>'
- self.assertEqual(expected, result)
-
-
-def main():
- suite = unittest.TestLoader().loadTestsFromName(__name__)
- unittest.TextTestRunner(verbosity=3).run(suite)
-
-
-if __name__ == '__main__':
- main()
diff --git a/cc/symbolfile/.gitignore b/cc/symbolfile/.gitignore
new file mode 100644
index 0000000..fd94eac
--- /dev/null
+++ b/cc/symbolfile/.gitignore
@@ -0,0 +1,140 @@
+# From https://github.com/github/gitignore/blob/master/Python.gitignore
+
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+share/python-wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+MANIFEST
+
+# PyInstaller
+# Usually these files are written by a python script from a template
+# before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.nox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*.cover
+*.py,cover
+.hypothesis/
+.pytest_cache/
+cover/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+db.sqlite3
+db.sqlite3-journal
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+.pybuilder/
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# IPython
+profile_default/
+ipython_config.py
+
+# pyenv
+# For a library or package, you might want to ignore these files since the code is
+# intended to run in multiple environments; otherwise, check them in:
+# .python-version
+
+# pipenv
+# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
+# However, in case of collaboration, if having platform-specific dependencies or dependencies
+# having no cross-platform support, pipenv may install dependencies that don't work, or not
+# install all needed dependencies.
+#Pipfile.lock
+
+# PEP 582; used by e.g. github.com/David-OConnor/pyflow
+__pypackages__/
+
+# Celery stuff
+celerybeat-schedule
+celerybeat.pid
+
+# SageMath parsed files
+*.sage.py
+
+# Environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
+
+# Spyder project settings
+.spyderproject
+.spyproject
+
+# Rope project settings
+.ropeproject
+
+# mkdocs documentation
+/site
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# Pyre type checker
+.pyre/
+
+# pytype static type analyzer
+.pytype/
+
+# Cython debug symbols
+cython_debug/
diff --git a/cc/scriptlib/Android.bp b/cc/symbolfile/Android.bp
similarity index 69%
copy from cc/scriptlib/Android.bp
copy to cc/symbolfile/Android.bp
index ff9a2f0..5b43309 100644
--- a/cc/scriptlib/Android.bp
+++ b/cc/symbolfile/Android.bp
@@ -14,19 +14,20 @@
// limitations under the License.
//
-python_test_host {
- name: "test_ndk_api_coverage_parser",
- main: "test_ndk_api_coverage_parser.py",
+python_library_host {
+ name: "symbolfile",
+ pkg_path: "symbolfile",
srcs: [
- "test_ndk_api_coverage_parser.py",
+ "__init__.py",
],
}
-python_binary_host {
- name: "ndk_api_coverage_parser",
- main: "ndk_api_coverage_parser.py",
+python_test_host {
+ name: "test_symbolfile",
srcs: [
- "gen_stub_libs.py",
- "ndk_api_coverage_parser.py",
+ "test_symbolfile.py",
+ ],
+ libs: [
+ "symbolfile",
],
}
diff --git a/cc/symbolfile/OWNERS b/cc/symbolfile/OWNERS
new file mode 100644
index 0000000..f0d8733
--- /dev/null
+++ b/cc/symbolfile/OWNERS
@@ -0,0 +1 @@
+danalbert@google.com
diff --git a/cc/scriptlib/gen_stub_libs.py b/cc/symbolfile/__init__.py
old mode 100755
new mode 100644
similarity index 72%
rename from cc/scriptlib/gen_stub_libs.py
rename to cc/symbolfile/__init__.py
index d61dfbb..faa3823
--- a/cc/scriptlib/gen_stub_libs.py
+++ b/cc/symbolfile/__init__.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
#
# Copyright (C) 2016 The Android Open Source Project
#
@@ -14,13 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-"""Generates source for stub shared libraries for the NDK."""
-import argparse
-import json
+"""Parser for Android's version script information."""
import logging
-import os
import re
-import sys
ALL_ARCHITECTURES = (
@@ -57,6 +52,24 @@
return False
+def decode_api_level(api, api_map):
+ """Decodes the API level argument into the API level number.
+
+ For the average case, this just decodes the integer value from the string,
+ but for unreleased APIs we need to translate from the API codename (like
+ "O") to the future API level for that codename.
+ """
+ try:
+ return int(api)
+ except ValueError:
+ pass
+
+ if api == "current":
+ return FUTURE_API_LEVEL
+
+ return api_map[api]
+
+
def decode_api_level_tags(tags, api_map):
"""Decodes API level code names in a list of tags.
@@ -118,7 +131,8 @@
if 'platform-only' in version.tags:
return True
- no_llndk_no_apex = 'llndk' not in version.tags and 'apex' not in version.tags
+ no_llndk_no_apex = ('llndk' not in version.tags
+ and 'apex' not in version.tags)
keep = no_llndk_no_apex or \
('llndk' in version.tags and llndk) or \
('apex' in version.tags and apex)
@@ -205,7 +219,6 @@
class ParseError(RuntimeError):
"""An error that occurred while parsing a symbol file."""
- pass
class MultiplyDefinedSymbolError(RuntimeError):
@@ -217,7 +230,7 @@
self.multiply_defined_symbols = multiply_defined_symbols
-class Version(object):
+class Version:
"""A version block of a symbol file."""
def __init__(self, name, base, tags, symbols):
self.name = name
@@ -237,7 +250,7 @@
return True
-class Symbol(object):
+class Symbol:
"""A symbol definition from a symbol file."""
def __init__(self, name, tags):
self.name = name
@@ -247,7 +260,7 @@
return self.name == other.name and set(self.tags) == set(other.tags)
-class SymbolFileParser(object):
+class SymbolFileParser:
"""Parses NDK symbol files."""
def __init__(self, input_file, api_map, arch, api, llndk, apex):
self.input_file = input_file
@@ -283,11 +296,13 @@
symbol_names = set()
multiply_defined_symbols = set()
for version in versions:
- if should_omit_version(version, self.arch, self.api, self.llndk, self.apex):
+ if should_omit_version(version, self.arch, self.api, self.llndk,
+ self.apex):
continue
for symbol in version.symbols:
- if should_omit_symbol(symbol, self.arch, self.api, self.llndk, self.apex):
+ if should_omit_symbol(symbol, self.arch, self.api, self.llndk,
+ self.apex):
continue
if symbol.name in symbol_names:
@@ -367,141 +382,3 @@
break
self.current_line = line
return self.current_line
-
-
-class Generator(object):
- """Output generator that writes stub source files and version scripts."""
- def __init__(self, src_file, version_script, arch, api, llndk, apex):
- self.src_file = src_file
- self.version_script = version_script
- self.arch = arch
- self.api = api
- self.llndk = llndk
- self.apex = apex
-
- def write(self, versions):
- """Writes all symbol data to the output files."""
- for version in versions:
- self.write_version(version)
-
- def write_version(self, version):
- """Writes a single version block's data to the output files."""
- if should_omit_version(version, self.arch, self.api, self.llndk, self.apex):
- return
-
- section_versioned = symbol_versioned_in_api(version.tags, self.api)
- version_empty = True
- pruned_symbols = []
- for symbol in version.symbols:
- if should_omit_symbol(symbol, self.arch, self.api, self.llndk, self.apex):
- continue
-
- if symbol_versioned_in_api(symbol.tags, self.api):
- version_empty = False
- pruned_symbols.append(symbol)
-
- if len(pruned_symbols) > 0:
- if not version_empty and section_versioned:
- self.version_script.write(version.name + ' {\n')
- self.version_script.write(' global:\n')
- for symbol in pruned_symbols:
- emit_version = symbol_versioned_in_api(symbol.tags, self.api)
- if section_versioned and emit_version:
- self.version_script.write(' ' + symbol.name + ';\n')
-
- weak = ''
- if 'weak' in symbol.tags:
- weak = '__attribute__((weak)) '
-
- if 'var' in symbol.tags:
- self.src_file.write('{}int {} = 0;\n'.format(
- weak, symbol.name))
- else:
- self.src_file.write('{}void {}() {{}}\n'.format(
- weak, symbol.name))
-
- if not version_empty and section_versioned:
- base = '' if version.base is None else ' ' + version.base
- self.version_script.write('}' + base + ';\n')
-
-
-def decode_api_level(api, api_map):
- """Decodes the API level argument into the API level number.
-
- For the average case, this just decodes the integer value from the string,
- but for unreleased APIs we need to translate from the API codename (like
- "O") to the future API level for that codename.
- """
- try:
- return int(api)
- except ValueError:
- pass
-
- if api == "current":
- return FUTURE_API_LEVEL
-
- return api_map[api]
-
-
-def parse_args():
- """Parses and returns command line arguments."""
- parser = argparse.ArgumentParser()
-
- parser.add_argument('-v', '--verbose', action='count', default=0)
-
- parser.add_argument(
- '--api', required=True, help='API level being targeted.')
- parser.add_argument(
- '--arch', choices=ALL_ARCHITECTURES, required=True,
- help='Architecture being targeted.')
- parser.add_argument(
- '--llndk', action='store_true', help='Use the LLNDK variant.')
- parser.add_argument(
- '--apex', action='store_true', help='Use the APEX variant.')
-
- parser.add_argument(
- '--api-map', type=os.path.realpath, required=True,
- help='Path to the API level map JSON file.')
-
- parser.add_argument(
- 'symbol_file', type=os.path.realpath, help='Path to symbol file.')
- parser.add_argument(
- 'stub_src', type=os.path.realpath,
- help='Path to output stub source file.')
- parser.add_argument(
- 'version_script', type=os.path.realpath,
- help='Path to output version script.')
-
- return parser.parse_args()
-
-
-def main():
- """Program entry point."""
- args = parse_args()
-
- with open(args.api_map) as map_file:
- api_map = json.load(map_file)
- api = decode_api_level(args.api, api_map)
-
- verbose_map = (logging.WARNING, logging.INFO, logging.DEBUG)
- verbosity = args.verbose
- if verbosity > 2:
- verbosity = 2
- logging.basicConfig(level=verbose_map[verbosity])
-
- with open(args.symbol_file) as symbol_file:
- try:
- versions = SymbolFileParser(symbol_file, api_map, args.arch, api,
- args.llndk, args.apex).parse()
- except MultiplyDefinedSymbolError as ex:
- sys.exit('{}: error: {}'.format(args.symbol_file, ex))
-
- with open(args.stub_src, 'w') as src_file:
- with open(args.version_script, 'w') as version_file:
- generator = Generator(src_file, version_file, args.arch, api,
- args.llndk, args.apex)
- generator.write(versions)
-
-
-if __name__ == '__main__':
- main()
diff --git a/cc/symbolfile/test_symbolfile.py b/cc/symbolfile/test_symbolfile.py
new file mode 100644
index 0000000..c91131f
--- /dev/null
+++ b/cc/symbolfile/test_symbolfile.py
@@ -0,0 +1,493 @@
+#
+# Copyright (C) 2016 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.
+#
+"""Tests for symbolfile."""
+import io
+import textwrap
+import unittest
+
+import symbolfile
+
+# pylint: disable=missing-docstring
+
+
+class DecodeApiLevelTest(unittest.TestCase):
+ def test_decode_api_level(self):
+ self.assertEqual(9, symbolfile.decode_api_level('9', {}))
+ self.assertEqual(9000, symbolfile.decode_api_level('O', {'O': 9000}))
+
+ with self.assertRaises(KeyError):
+ symbolfile.decode_api_level('O', {})
+
+
+class TagsTest(unittest.TestCase):
+ def test_get_tags_no_tags(self):
+ self.assertEqual([], symbolfile.get_tags(''))
+ self.assertEqual([], symbolfile.get_tags('foo bar baz'))
+
+ def test_get_tags(self):
+ self.assertEqual(['foo', 'bar'], symbolfile.get_tags('# foo bar'))
+ self.assertEqual(['bar', 'baz'], symbolfile.get_tags('foo # bar baz'))
+
+ def test_split_tag(self):
+ self.assertTupleEqual(('foo', 'bar'), symbolfile.split_tag('foo=bar'))
+ self.assertTupleEqual(('foo', 'bar=baz'), symbolfile.split_tag('foo=bar=baz'))
+ with self.assertRaises(ValueError):
+ symbolfile.split_tag('foo')
+
+ def test_get_tag_value(self):
+ self.assertEqual('bar', symbolfile.get_tag_value('foo=bar'))
+ self.assertEqual('bar=baz', symbolfile.get_tag_value('foo=bar=baz'))
+ with self.assertRaises(ValueError):
+ symbolfile.get_tag_value('foo')
+
+ def test_is_api_level_tag(self):
+ self.assertTrue(symbolfile.is_api_level_tag('introduced=24'))
+ self.assertTrue(symbolfile.is_api_level_tag('introduced-arm=24'))
+ self.assertTrue(symbolfile.is_api_level_tag('versioned=24'))
+
+ # Shouldn't try to process things that aren't a key/value tag.
+ self.assertFalse(symbolfile.is_api_level_tag('arm'))
+ self.assertFalse(symbolfile.is_api_level_tag('introduced'))
+ self.assertFalse(symbolfile.is_api_level_tag('versioned'))
+
+ # We don't support arch specific `versioned` tags.
+ self.assertFalse(symbolfile.is_api_level_tag('versioned-arm=24'))
+
+ def test_decode_api_level_tags(self):
+ api_map = {
+ 'O': 9000,
+ 'P': 9001,
+ }
+
+ tags = [
+ 'introduced=9',
+ 'introduced-arm=14',
+ 'versioned=16',
+ 'arm',
+ 'introduced=O',
+ 'introduced=P',
+ ]
+ expected_tags = [
+ 'introduced=9',
+ 'introduced-arm=14',
+ 'versioned=16',
+ 'arm',
+ 'introduced=9000',
+ 'introduced=9001',
+ ]
+ self.assertListEqual(
+ expected_tags, symbolfile.decode_api_level_tags(tags, api_map))
+
+ with self.assertRaises(symbolfile.ParseError):
+ symbolfile.decode_api_level_tags(['introduced=O'], {})
+
+
+class PrivateVersionTest(unittest.TestCase):
+ def test_version_is_private(self):
+ self.assertFalse(symbolfile.version_is_private('foo'))
+ self.assertFalse(symbolfile.version_is_private('PRIVATE'))
+ self.assertFalse(symbolfile.version_is_private('PLATFORM'))
+ self.assertFalse(symbolfile.version_is_private('foo_private'))
+ self.assertFalse(symbolfile.version_is_private('foo_platform'))
+ self.assertFalse(symbolfile.version_is_private('foo_PRIVATE_'))
+ self.assertFalse(symbolfile.version_is_private('foo_PLATFORM_'))
+
+ self.assertTrue(symbolfile.version_is_private('foo_PRIVATE'))
+ self.assertTrue(symbolfile.version_is_private('foo_PLATFORM'))
+
+
+class SymbolPresenceTest(unittest.TestCase):
+ def test_symbol_in_arch(self):
+ self.assertTrue(symbolfile.symbol_in_arch([], 'arm'))
+ self.assertTrue(symbolfile.symbol_in_arch(['arm'], 'arm'))
+
+ self.assertFalse(symbolfile.symbol_in_arch(['x86'], 'arm'))
+
+ def test_symbol_in_api(self):
+ self.assertTrue(symbolfile.symbol_in_api([], 'arm', 9))
+ self.assertTrue(symbolfile.symbol_in_api(['introduced=9'], 'arm', 9))
+ self.assertTrue(symbolfile.symbol_in_api(['introduced=9'], 'arm', 14))
+ self.assertTrue(symbolfile.symbol_in_api(['introduced-arm=9'], 'arm', 14))
+ self.assertTrue(symbolfile.symbol_in_api(['introduced-arm=9'], 'arm', 14))
+ self.assertTrue(symbolfile.symbol_in_api(['introduced-x86=14'], 'arm', 9))
+ self.assertTrue(symbolfile.symbol_in_api(
+ ['introduced-arm=9', 'introduced-x86=21'], 'arm', 14))
+ self.assertTrue(symbolfile.symbol_in_api(
+ ['introduced=9', 'introduced-x86=21'], 'arm', 14))
+ self.assertTrue(symbolfile.symbol_in_api(
+ ['introduced=21', 'introduced-arm=9'], 'arm', 14))
+ self.assertTrue(symbolfile.symbol_in_api(
+ ['future'], 'arm', symbolfile.FUTURE_API_LEVEL))
+
+ self.assertFalse(symbolfile.symbol_in_api(['introduced=14'], 'arm', 9))
+ self.assertFalse(symbolfile.symbol_in_api(['introduced-arm=14'], 'arm', 9))
+ self.assertFalse(symbolfile.symbol_in_api(['future'], 'arm', 9))
+ self.assertFalse(symbolfile.symbol_in_api(
+ ['introduced=9', 'future'], 'arm', 14))
+ self.assertFalse(symbolfile.symbol_in_api(
+ ['introduced-arm=9', 'future'], 'arm', 14))
+ self.assertFalse(symbolfile.symbol_in_api(
+ ['introduced-arm=21', 'introduced-x86=9'], 'arm', 14))
+ self.assertFalse(symbolfile.symbol_in_api(
+ ['introduced=9', 'introduced-arm=21'], 'arm', 14))
+ self.assertFalse(symbolfile.symbol_in_api(
+ ['introduced=21', 'introduced-x86=9'], 'arm', 14))
+
+ # Interesting edge case: this symbol should be omitted from the
+ # library, but this call should still return true because none of the
+ # tags indiciate that it's not present in this API level.
+ self.assertTrue(symbolfile.symbol_in_api(['x86'], 'arm', 9))
+
+ def test_verioned_in_api(self):
+ self.assertTrue(symbolfile.symbol_versioned_in_api([], 9))
+ self.assertTrue(symbolfile.symbol_versioned_in_api(['versioned=9'], 9))
+ self.assertTrue(symbolfile.symbol_versioned_in_api(['versioned=9'], 14))
+
+ self.assertFalse(symbolfile.symbol_versioned_in_api(['versioned=14'], 9))
+
+
+class OmitVersionTest(unittest.TestCase):
+ def test_omit_private(self):
+ self.assertFalse(
+ symbolfile.should_omit_version(
+ symbolfile.Version('foo', None, [], []), 'arm', 9, False,
+ False))
+
+ self.assertTrue(
+ symbolfile.should_omit_version(
+ symbolfile.Version('foo_PRIVATE', None, [], []), 'arm', 9,
+ False, False))
+ self.assertTrue(
+ symbolfile.should_omit_version(
+ symbolfile.Version('foo_PLATFORM', None, [], []), 'arm', 9,
+ False, False))
+
+ self.assertTrue(
+ symbolfile.should_omit_version(
+ symbolfile.Version('foo', None, ['platform-only'], []), 'arm',
+ 9, False, False))
+
+ def test_omit_llndk(self):
+ self.assertTrue(
+ symbolfile.should_omit_version(
+ symbolfile.Version('foo', None, ['llndk'], []), 'arm', 9,
+ False, False))
+
+ self.assertFalse(
+ symbolfile.should_omit_version(
+ symbolfile.Version('foo', None, [], []), 'arm', 9, True,
+ False))
+ self.assertFalse(
+ symbolfile.should_omit_version(
+ symbolfile.Version('foo', None, ['llndk'], []), 'arm', 9, True,
+ False))
+
+ def test_omit_apex(self):
+ self.assertTrue(
+ symbolfile.should_omit_version(
+ symbolfile.Version('foo', None, ['apex'], []), 'arm', 9, False,
+ False))
+
+ self.assertFalse(
+ symbolfile.should_omit_version(
+ symbolfile.Version('foo', None, [], []), 'arm', 9, False,
+ True))
+ self.assertFalse(
+ symbolfile.should_omit_version(
+ symbolfile.Version('foo', None, ['apex'], []), 'arm', 9, False,
+ True))
+
+ def test_omit_arch(self):
+ self.assertFalse(
+ symbolfile.should_omit_version(
+ symbolfile.Version('foo', None, [], []), 'arm', 9, False,
+ False))
+ self.assertFalse(
+ symbolfile.should_omit_version(
+ symbolfile.Version('foo', None, ['arm'], []), 'arm', 9, False,
+ False))
+
+ self.assertTrue(
+ symbolfile.should_omit_version(
+ symbolfile.Version('foo', None, ['x86'], []), 'arm', 9, False,
+ False))
+
+ def test_omit_api(self):
+ self.assertFalse(
+ symbolfile.should_omit_version(
+ symbolfile.Version('foo', None, [], []), 'arm', 9, False,
+ False))
+ self.assertFalse(
+ symbolfile.should_omit_version(
+ symbolfile.Version('foo', None, ['introduced=9'], []), 'arm',
+ 9, False, False))
+
+ self.assertTrue(
+ symbolfile.should_omit_version(
+ symbolfile.Version('foo', None, ['introduced=14'], []), 'arm',
+ 9, False, False))
+
+
+class OmitSymbolTest(unittest.TestCase):
+ def test_omit_llndk(self):
+ self.assertTrue(
+ symbolfile.should_omit_symbol(symbolfile.Symbol('foo', ['llndk']),
+ 'arm', 9, False, False))
+
+ self.assertFalse(
+ symbolfile.should_omit_symbol(symbolfile.Symbol('foo', []), 'arm',
+ 9, True, False))
+ self.assertFalse(
+ symbolfile.should_omit_symbol(symbolfile.Symbol('foo', ['llndk']),
+ 'arm', 9, True, False))
+
+ def test_omit_apex(self):
+ self.assertTrue(
+ symbolfile.should_omit_symbol(symbolfile.Symbol('foo', ['apex']),
+ 'arm', 9, False, False))
+
+ self.assertFalse(
+ symbolfile.should_omit_symbol(symbolfile.Symbol('foo', []), 'arm',
+ 9, False, True))
+ self.assertFalse(
+ symbolfile.should_omit_symbol(symbolfile.Symbol('foo', ['apex']),
+ 'arm', 9, False, True))
+
+ def test_omit_arch(self):
+ self.assertFalse(
+ symbolfile.should_omit_symbol(symbolfile.Symbol('foo', []), 'arm',
+ 9, False, False))
+ self.assertFalse(
+ symbolfile.should_omit_symbol(symbolfile.Symbol('foo', ['arm']),
+ 'arm', 9, False, False))
+
+ self.assertTrue(
+ symbolfile.should_omit_symbol(symbolfile.Symbol('foo', ['x86']),
+ 'arm', 9, False, False))
+
+ def test_omit_api(self):
+ self.assertFalse(
+ symbolfile.should_omit_symbol(symbolfile.Symbol('foo', []), 'arm',
+ 9, False, False))
+ self.assertFalse(
+ symbolfile.should_omit_symbol(
+ symbolfile.Symbol('foo', ['introduced=9']), 'arm', 9, False,
+ False))
+
+ self.assertTrue(
+ symbolfile.should_omit_symbol(
+ symbolfile.Symbol('foo', ['introduced=14']), 'arm', 9, False,
+ False))
+
+
+class SymbolFileParseTest(unittest.TestCase):
+ def test_next_line(self):
+ input_file = io.StringIO(textwrap.dedent("""\
+ foo
+
+ bar
+ # baz
+ qux
+ """))
+ parser = symbolfile.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
+ self.assertIsNone(parser.current_line)
+
+ self.assertEqual('foo', parser.next_line().strip())
+ self.assertEqual('foo', parser.current_line.strip())
+
+ self.assertEqual('bar', parser.next_line().strip())
+ self.assertEqual('bar', parser.current_line.strip())
+
+ self.assertEqual('qux', parser.next_line().strip())
+ self.assertEqual('qux', parser.current_line.strip())
+
+ self.assertEqual('', parser.next_line())
+ self.assertEqual('', parser.current_line)
+
+ def test_parse_version(self):
+ input_file = io.StringIO(textwrap.dedent("""\
+ VERSION_1 { # foo bar
+ baz;
+ qux; # woodly doodly
+ };
+
+ VERSION_2 {
+ } VERSION_1; # asdf
+ """))
+ parser = symbolfile.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
+
+ parser.next_line()
+ version = parser.parse_version()
+ self.assertEqual('VERSION_1', version.name)
+ self.assertIsNone(version.base)
+ self.assertEqual(['foo', 'bar'], version.tags)
+
+ expected_symbols = [
+ symbolfile.Symbol('baz', []),
+ symbolfile.Symbol('qux', ['woodly', 'doodly']),
+ ]
+ self.assertEqual(expected_symbols, version.symbols)
+
+ parser.next_line()
+ version = parser.parse_version()
+ self.assertEqual('VERSION_2', version.name)
+ self.assertEqual('VERSION_1', version.base)
+ self.assertEqual([], version.tags)
+
+ def test_parse_version_eof(self):
+ input_file = io.StringIO(textwrap.dedent("""\
+ VERSION_1 {
+ """))
+ parser = symbolfile.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
+ parser.next_line()
+ with self.assertRaises(symbolfile.ParseError):
+ parser.parse_version()
+
+ def test_unknown_scope_label(self):
+ input_file = io.StringIO(textwrap.dedent("""\
+ VERSION_1 {
+ foo:
+ }
+ """))
+ parser = symbolfile.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
+ parser.next_line()
+ with self.assertRaises(symbolfile.ParseError):
+ parser.parse_version()
+
+ def test_parse_symbol(self):
+ input_file = io.StringIO(textwrap.dedent("""\
+ foo;
+ bar; # baz qux
+ """))
+ parser = symbolfile.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
+
+ parser.next_line()
+ symbol = parser.parse_symbol()
+ self.assertEqual('foo', symbol.name)
+ self.assertEqual([], symbol.tags)
+
+ parser.next_line()
+ symbol = parser.parse_symbol()
+ self.assertEqual('bar', symbol.name)
+ self.assertEqual(['baz', 'qux'], symbol.tags)
+
+ def test_wildcard_symbol_global(self):
+ input_file = io.StringIO(textwrap.dedent("""\
+ VERSION_1 {
+ *;
+ };
+ """))
+ parser = symbolfile.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
+ parser.next_line()
+ with self.assertRaises(symbolfile.ParseError):
+ parser.parse_version()
+
+ def test_wildcard_symbol_local(self):
+ input_file = io.StringIO(textwrap.dedent("""\
+ VERSION_1 {
+ local:
+ *;
+ };
+ """))
+ parser = symbolfile.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
+ parser.next_line()
+ version = parser.parse_version()
+ self.assertEqual([], version.symbols)
+
+ def test_missing_semicolon(self):
+ input_file = io.StringIO(textwrap.dedent("""\
+ VERSION_1 {
+ foo
+ };
+ """))
+ parser = symbolfile.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
+ parser.next_line()
+ with self.assertRaises(symbolfile.ParseError):
+ parser.parse_version()
+
+ def test_parse_fails_invalid_input(self):
+ with self.assertRaises(symbolfile.ParseError):
+ input_file = io.StringIO('foo')
+ parser = symbolfile.SymbolFileParser(input_file, {}, 'arm', 16,
+ False, False)
+ parser.parse()
+
+ def test_parse(self):
+ input_file = io.StringIO(textwrap.dedent("""\
+ VERSION_1 {
+ local:
+ hidden1;
+ global:
+ foo;
+ bar; # baz
+ };
+
+ VERSION_2 { # wasd
+ # Implicit global scope.
+ woodly;
+ doodly; # asdf
+ local:
+ qwerty;
+ } VERSION_1;
+ """))
+ parser = symbolfile.SymbolFileParser(input_file, {}, 'arm', 16, False, False)
+ versions = parser.parse()
+
+ expected = [
+ symbolfile.Version('VERSION_1', None, [], [
+ symbolfile.Symbol('foo', []),
+ symbolfile.Symbol('bar', ['baz']),
+ ]),
+ symbolfile.Version('VERSION_2', 'VERSION_1', ['wasd'], [
+ symbolfile.Symbol('woodly', []),
+ symbolfile.Symbol('doodly', ['asdf']),
+ ]),
+ ]
+
+ self.assertEqual(expected, versions)
+
+ def test_parse_llndk_apex_symbol(self):
+ input_file = io.StringIO(textwrap.dedent("""\
+ VERSION_1 {
+ foo;
+ bar; # llndk
+ baz; # llndk apex
+ qux; # apex
+ };
+ """))
+ parser = symbolfile.SymbolFileParser(input_file, {}, 'arm', 16, False, True)
+
+ parser.next_line()
+ version = parser.parse_version()
+ self.assertEqual('VERSION_1', version.name)
+ self.assertIsNone(version.base)
+
+ expected_symbols = [
+ symbolfile.Symbol('foo', []),
+ symbolfile.Symbol('bar', ['llndk']),
+ symbolfile.Symbol('baz', ['llndk', 'apex']),
+ symbolfile.Symbol('qux', ['apex']),
+ ]
+ self.assertEqual(expected_symbols, version.symbols)
+
+
+def main():
+ suite = unittest.TestLoader().loadTestsFromName(__name__)
+ unittest.TextTestRunner(verbosity=3).run(suite)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/cc/test.go b/cc/test.go
index 37afb0c..9b6864a 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -165,7 +165,7 @@
return test.baseCompiler.Properties.Srcs
}
-func (test *testBinary) dataPaths() android.Paths {
+func (test *testBinary) dataPaths() []android.DataPath {
return test.data
}
@@ -310,7 +310,7 @@
*binaryDecorator
*baseCompiler
Properties TestBinaryProperties
- data android.Paths
+ data []android.DataPath
testConfig android.Path
}
@@ -339,7 +339,11 @@
}
func (test *testBinary) install(ctx ModuleContext, file android.Path) {
- test.data = android.PathsForModuleSrc(ctx, test.Properties.Data)
+ dataSrcPaths := android.PathsForModuleSrc(ctx, test.Properties.Data)
+
+ for _, dataSrcPath := range dataSrcPaths {
+ test.data = append(test.data, android.DataPath{SrcPath: dataSrcPath})
+ }
ctx.VisitDirectDepsWithTag(dataLibDepTag, func(dep android.Module) {
depName := ctx.OtherModuleName(dep)
@@ -348,10 +352,14 @@
if !ok {
ctx.ModuleErrorf("data_lib %q is not a linkable cc module", depName)
}
+ ccModule, ok := dep.(*Module)
+ if !ok {
+ ctx.ModuleErrorf("data_lib %q is not a cc module", depName)
+ }
if ccDep.OutputFile().Valid() {
- test.data = append(test.data, ccDep.OutputFile().Path())
- } else {
- ctx.ModuleErrorf("data_lib %q has no output file", depName)
+ test.data = append(test.data,
+ android.DataPath{SrcPath: ccDep.OutputFile().Path(),
+ RelativeInstallPath: ccModule.installer.relativeInstallPath()})
}
})
diff --git a/cc/testing.go b/cc/testing.go
index a106d46..c2353d8 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -20,8 +20,6 @@
func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
RegisterPrebuiltBuildComponents(ctx)
- android.RegisterPrebuiltMutators(ctx)
-
RegisterCCBuildComponents(ctx)
RegisterBinaryBuildComponents(ctx)
RegisterLibraryBuildComponents(ctx)
@@ -30,6 +28,7 @@
ctx.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
ctx.RegisterModuleType("llndk_library", LlndkLibraryFactory)
ctx.RegisterModuleType("cc_object", ObjectFactory)
+ ctx.RegisterModuleType("cc_genrule", genRuleFactory)
ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
ctx.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory)
ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
@@ -39,6 +38,7 @@
ret := `
toolchain_library {
name: "libatomic",
+ defaults: ["linux_bionic_supported"],
vendor_available: true,
recovery_available: true,
native_bridge_supported: true,
@@ -92,6 +92,7 @@
toolchain_library {
name: "libclang_rt.builtins-x86_64-android",
+ defaults: ["linux_bionic_supported"],
vendor_available: true,
recovery_available: true,
native_bridge_supported: true,
@@ -121,6 +122,7 @@
toolchain_library {
name: "libclang_rt.fuzzer-x86_64-android",
+ defaults: ["linux_bionic_supported"],
vendor_available: true,
recovery_available: true,
src: "",
@@ -144,6 +146,7 @@
toolchain_library {
name: "libgcc",
+ defaults: ["linux_bionic_supported"],
vendor_available: true,
recovery_available: true,
src: "",
@@ -151,6 +154,7 @@
toolchain_library {
name: "libgcc_stripped",
+ defaults: ["linux_bionic_supported"],
vendor_available: true,
recovery_available: true,
sdk_version: "current",
@@ -159,6 +163,7 @@
cc_library {
name: "libc",
+ defaults: ["linux_bionic_supported"],
no_libcrt: true,
nocrt: true,
stl: "none",
@@ -175,6 +180,7 @@
}
cc_library {
name: "libm",
+ defaults: ["linux_bionic_supported"],
no_libcrt: true,
nocrt: true,
stl: "none",
@@ -234,6 +240,7 @@
cc_library {
name: "libdl",
+ defaults: ["linux_bionic_supported"],
no_libcrt: true,
nocrt: true,
stl: "none",
@@ -326,6 +333,7 @@
cc_defaults {
name: "crt_defaults",
+ defaults: ["linux_bionic_supported"],
recovery_available: true,
vendor_available: true,
native_bridge_supported: true,
@@ -437,6 +445,7 @@
}
`
+ supportLinuxBionic := false
for _, os := range oses {
if os == android.Fuchsia {
ret += `
@@ -465,7 +474,59 @@
}
`
}
+ if os == android.LinuxBionic {
+ supportLinuxBionic = true
+ ret += `
+ cc_binary {
+ name: "linker",
+ defaults: ["linux_bionic_supported"],
+ recovery_available: true,
+ stl: "none",
+ nocrt: true,
+ static_executable: true,
+ native_coverage: false,
+ system_shared_libs: [],
+ }
+
+ cc_genrule {
+ name: "host_bionic_linker_flags",
+ host_supported: true,
+ device_supported: false,
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_bionic: {
+ enabled: true,
+ },
+ },
+ out: ["linker.flags"],
+ }
+
+ cc_defaults {
+ name: "linux_bionic_supported",
+ host_supported: true,
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_bionic: {
+ enabled: true,
+ },
+ },
+ }
+ `
+ }
}
+
+ if !supportLinuxBionic {
+ ret += `
+ cc_defaults {
+ name: "linux_bionic_supported",
+ }
+ `
+ }
+
return ret
}
@@ -507,6 +568,7 @@
ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
+ android.RegisterPrebuiltMutators(ctx)
RegisterRequiredBuildComponentsForTest(ctx)
ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
ctx.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go
index fec0c8b..6df940c 100644
--- a/cc/vendor_snapshot.go
+++ b/cc/vendor_snapshot.go
@@ -484,18 +484,22 @@
var (
// Modules under following directories are ignored. They are OEM's and vendor's
- // proprietary modules(device/, vendor/, and hardware/).
+ // proprietary modules(device/, kernel/, vendor/, and hardware/).
// TODO(b/65377115): Clean up these with more maintainable way
vendorProprietaryDirs = []string{
"device",
+ "kernel",
"vendor",
"hardware",
}
// Modules under following directories are included as they are in AOSP,
- // although hardware/ is normally for vendor's own.
+ // although hardware/ and kernel/ are normally for vendor's own.
// TODO(b/65377115): Clean up these with more maintainable way
aospDirsUnderProprietary = []string{
+ "kernel/configs",
+ "kernel/prebuilts",
+ "kernel/tests",
"hardware/interfaces",
"hardware/libhardware",
"hardware/libhardware_legacy",
@@ -552,6 +556,13 @@
if _, ok := m.linker.(*kernelHeadersDecorator); ok {
return false
}
+ // skip llndk_library and llndk_headers which are backward compatible
+ if _, ok := m.linker.(*llndkStubDecorator); ok {
+ return false
+ }
+ if _, ok := m.linker.(*llndkHeadersDecorator); ok {
+ return false
+ }
// Libraries
if l, ok := m.linker.(snapshotLibraryInterface); ok {
diff --git a/cc/vndk.go b/cc/vndk.go
index 4adf9d2..23bb095 100644
--- a/cc/vndk.go
+++ b/cc/vndk.go
@@ -26,6 +26,8 @@
"android/soong/android"
"android/soong/cc/config"
"android/soong/etc"
+
+ "github.com/google/blueprint"
)
const (
@@ -127,7 +129,7 @@
return "native:vendor:vndkspext"
}
-func (vndk *vndkdep) vndkCheckLinkType(ctx android.ModuleContext, to *Module, tag DependencyTag) {
+func (vndk *vndkdep) vndkCheckLinkType(ctx android.ModuleContext, to *Module, tag blueprint.DependencyTag) {
if to.linker == nil {
return
}
@@ -340,7 +342,7 @@
}
}
-// Sanity check for modules that mustn't be VNDK
+// Check for modules that mustn't be VNDK
func shouldSkipVndkMutator(m *Module) bool {
if !m.Enabled() {
return true
@@ -559,10 +561,6 @@
return
}
- if ctx.DeviceConfig().BoardVndkRuntimeDisable() {
- return
- }
-
var snapshotOutputs android.Paths
/*
diff --git a/cmd/diff_target_files/Android.bp b/cmd/diff_target_files/Android.bp
index 5397f4b..bc6b068 100644
--- a/cmd/diff_target_files/Android.bp
+++ b/cmd/diff_target_files/Android.bp
@@ -5,12 +5,12 @@
"diff_target_files.go",
"glob.go",
"target_files.go",
- "whitelist.go",
+ "allow_list.go",
"zip_artifact.go",
],
testSrcs: [
"compare_test.go",
"glob_test.go",
- "whitelist_test.go",
+ "allow_list_test.go",
],
}
diff --git a/cmd/diff_target_files/whitelist.go b/cmd/diff_target_files/allow_list.go
similarity index 77%
rename from cmd/diff_target_files/whitelist.go
rename to cmd/diff_target_files/allow_list.go
index f00fc1e..ca55b43 100644
--- a/cmd/diff_target_files/whitelist.go
+++ b/cmd/diff_target_files/allow_list.go
@@ -25,18 +25,13 @@
"unicode"
)
-type jsonWhitelist struct {
- Paths []string
- IgnoreMatchingLines []string
-}
-
-type whitelist struct {
+type allowList struct {
path string
ignoreMatchingLines []string
}
-func parseWhitelists(whitelists []string, whitelistFiles []string) ([]whitelist, error) {
- var ret []whitelist
+func parseAllowLists(allowLists []string, allowListFiles []string) ([]allowList, error) {
+ var ret []allowList
add := func(path string, ignoreMatchingLines []string) {
for _, x := range ret {
@@ -46,24 +41,24 @@
}
}
- ret = append(ret, whitelist{
+ ret = append(ret, allowList{
path: path,
ignoreMatchingLines: ignoreMatchingLines,
})
}
- for _, file := range whitelistFiles {
- newWhitelists, err := parseWhitelistFile(file)
+ for _, file := range allowListFiles {
+ newAllowlists, err := parseAllowListFile(file)
if err != nil {
return nil, err
}
- for _, w := range newWhitelists {
+ for _, w := range newAllowlists {
add(w.path, w.ignoreMatchingLines)
}
}
- for _, s := range whitelists {
+ for _, s := range allowLists {
colon := strings.IndexRune(s, ':')
var ignoreMatchingLines []string
if colon >= 0 {
@@ -75,7 +70,7 @@
return ret, nil
}
-func parseWhitelistFile(file string) ([]whitelist, error) {
+func parseAllowListFile(file string) ([]allowList, error) {
r, err := os.Open(file)
if err != nil {
return nil, err
@@ -84,27 +79,32 @@
d := json.NewDecoder(newJSONCommentStripper(r))
- var jsonWhitelists []jsonWhitelist
+ var jsonAllowLists []struct {
+ Paths []string
+ IgnoreMatchingLines []string
+ }
- err = d.Decode(&jsonWhitelists)
+ if err := d.Decode(&jsonAllowLists); err != nil {
+ return nil, err
+ }
- var whitelists []whitelist
- for _, w := range jsonWhitelists {
+ var allowLists []allowList
+ for _, w := range jsonAllowLists {
for _, p := range w.Paths {
- whitelists = append(whitelists, whitelist{
+ allowLists = append(allowLists, allowList{
path: p,
ignoreMatchingLines: w.IgnoreMatchingLines,
})
}
}
- return whitelists, err
+ return allowLists, err
}
-func filterModifiedPaths(l [][2]*ZipArtifactFile, whitelists []whitelist) ([][2]*ZipArtifactFile, error) {
+func filterModifiedPaths(l [][2]*ZipArtifactFile, allowLists []allowList) ([][2]*ZipArtifactFile, error) {
outer:
for i := 0; i < len(l); i++ {
- for _, w := range whitelists {
+ for _, w := range allowLists {
if match, err := Match(w.path, l[i][0].Name); err != nil {
return l, err
} else if match {
@@ -126,10 +126,10 @@
return l, nil
}
-func filterNewPaths(l []*ZipArtifactFile, whitelists []whitelist) ([]*ZipArtifactFile, error) {
+func filterNewPaths(l []*ZipArtifactFile, allowLists []allowList) ([]*ZipArtifactFile, error) {
outer:
for i := 0; i < len(l); i++ {
- for _, w := range whitelists {
+ for _, w := range allowLists {
if match, err := Match(w.path, l[i].Name); err != nil {
return l, err
} else if match && len(w.ignoreMatchingLines) == 0 {
@@ -192,18 +192,18 @@
return bytes.Compare(bufA, bufB) == 0, nil
}
-func applyWhitelists(diff zipDiff, whitelists []whitelist) (zipDiff, error) {
+func applyAllowLists(diff zipDiff, allowLists []allowList) (zipDiff, error) {
var err error
- diff.modified, err = filterModifiedPaths(diff.modified, whitelists)
+ diff.modified, err = filterModifiedPaths(diff.modified, allowLists)
if err != nil {
return diff, err
}
- diff.onlyInA, err = filterNewPaths(diff.onlyInA, whitelists)
+ diff.onlyInA, err = filterNewPaths(diff.onlyInA, allowLists)
if err != nil {
return diff, err
}
- diff.onlyInB, err = filterNewPaths(diff.onlyInB, whitelists)
+ diff.onlyInB, err = filterNewPaths(diff.onlyInB, allowLists)
if err != nil {
return diff, err
}
diff --git a/cmd/diff_target_files/whitelist_test.go b/cmd/diff_target_files/allow_list_test.go
similarity index 82%
rename from cmd/diff_target_files/whitelist_test.go
rename to cmd/diff_target_files/allow_list_test.go
index 4b19fdd..8410e5a 100644
--- a/cmd/diff_target_files/whitelist_test.go
+++ b/cmd/diff_target_files/allow_list_test.go
@@ -57,10 +57,10 @@
var f2 = bytesToZipArtifactFile("dir/f2", nil)
-func Test_applyWhitelists(t *testing.T) {
+func Test_applyAllowLists(t *testing.T) {
type args struct {
diff zipDiff
- whitelists []whitelist
+ allowLists []allowList
}
tests := []struct {
name string
@@ -74,7 +74,7 @@
diff: zipDiff{
onlyInA: []*ZipArtifactFile{f1a, f2},
},
- whitelists: []whitelist{{path: "dir/f1"}},
+ allowLists: []allowList{{path: "dir/f1"}},
},
want: zipDiff{
onlyInA: []*ZipArtifactFile{f2},
@@ -86,7 +86,7 @@
diff: zipDiff{
onlyInA: []*ZipArtifactFile{f1a, f2},
},
- whitelists: []whitelist{{path: "dir/*"}},
+ allowLists: []allowList{{path: "dir/*"}},
},
want: zipDiff{},
},
@@ -96,7 +96,7 @@
diff: zipDiff{
modified: [][2]*ZipArtifactFile{{f1a, f1b}},
},
- whitelists: []whitelist{{path: "dir/*"}},
+ allowLists: []allowList{{path: "dir/*"}},
},
want: zipDiff{},
},
@@ -106,20 +106,20 @@
diff: zipDiff{
modified: [][2]*ZipArtifactFile{{f1a, f1b}},
},
- whitelists: []whitelist{{path: "dir/*", ignoreMatchingLines: []string{"foo: .*"}}},
+ allowLists: []allowList{{path: "dir/*", ignoreMatchingLines: []string{"foo: .*"}}},
},
want: zipDiff{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- got, err := applyWhitelists(tt.args.diff, tt.args.whitelists)
+ got, err := applyAllowLists(tt.args.diff, tt.args.allowLists)
if (err != nil) != tt.wantErr {
- t.Errorf("applyWhitelists() error = %v, wantErr %v", err, tt.wantErr)
+ t.Errorf("Test_applyAllowLists() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("applyWhitelists() = %v, want %v", got, tt.want)
+ t.Errorf("Test_applyAllowLists() = %v, want %v", got, tt.want)
}
})
}
diff --git a/cmd/diff_target_files/compare.go b/cmd/diff_target_files/compare.go
index 00cd9ca..45b6d6b 100644
--- a/cmd/diff_target_files/compare.go
+++ b/cmd/diff_target_files/compare.go
@@ -21,7 +21,7 @@
// compareTargetFiles takes two ZipArtifacts and compares the files they contain by examining
// the path, size, and CRC of each file.
-func compareTargetFiles(priZip, refZip ZipArtifact, artifact string, whitelists []whitelist, filters []string) (zipDiff, error) {
+func compareTargetFiles(priZip, refZip ZipArtifact, artifact string, allowLists []allowList, filters []string) (zipDiff, error) {
priZipFiles, err := priZip.Files()
if err != nil {
return zipDiff{}, fmt.Errorf("error fetching target file lists from primary zip %v", err)
@@ -45,7 +45,7 @@
// Compare the file lists from both builds
diff := diffTargetFilesLists(refZipFiles, priZipFiles)
- return applyWhitelists(diff, whitelists)
+ return applyAllowLists(diff, allowLists)
}
// zipDiff contains the list of files that differ between two zip files.
diff --git a/cmd/diff_target_files/diff_target_files.go b/cmd/diff_target_files/diff_target_files.go
index 75bc8ee..634565b 100644
--- a/cmd/diff_target_files/diff_target_files.go
+++ b/cmd/diff_target_files/diff_target_files.go
@@ -22,8 +22,8 @@
)
var (
- whitelists = newMultiString("whitelist", "whitelist patterns in the form <pattern>[:<regex of line to ignore>]")
- whitelistFiles = newMultiString("whitelist_file", "files containing whitelist definitions")
+ allowLists = newMultiString("allowlist", "allowlist patterns in the form <pattern>[:<regex of line to ignore>]")
+ allowListFiles = newMultiString("allowlist_file", "files containing allowlist definitions")
filters = newMultiString("filter", "filter patterns to apply to files in target-files.zip before comparing")
)
@@ -47,9 +47,9 @@
os.Exit(1)
}
- whitelists, err := parseWhitelists(*whitelists, *whitelistFiles)
+ allowLists, err := parseAllowLists(*allowLists, *allowListFiles)
if err != nil {
- fmt.Fprintf(os.Stderr, "Error parsing whitelists: %v\n", err)
+ fmt.Fprintf(os.Stderr, "Error parsing allowlists: %v\n", err)
os.Exit(1)
}
@@ -67,7 +67,7 @@
}
defer refZip.Close()
- diff, err := compareTargetFiles(priZip, refZip, targetFilesPattern, whitelists, *filters)
+ diff, err := compareTargetFiles(priZip, refZip, targetFilesPattern, allowLists, *filters)
if err != nil {
fmt.Fprintf(os.Stderr, "Error comparing zip files: %v\n", err)
os.Exit(1)
diff --git a/cmd/merge_zips/merge_zips.go b/cmd/merge_zips/merge_zips.go
index a95aca9..274c8ee 100644
--- a/cmd/merge_zips/merge_zips.go
+++ b/cmd/merge_zips/merge_zips.go
@@ -429,7 +429,7 @@
if maxOpenZips < 3 {
panic(fmt.Errorf("open zips limit should be above 3"))
}
- // In the dummy element .older points to the most recently opened InputZip, and .newer points to the oldest.
+ // In the fake element .older points to the most recently opened InputZip, and .newer points to the oldest.
head := new(ManagedInputZip)
head.older = head
head.newer = head
diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go
index d3802f9..69e4f69 100644
--- a/cmd/soong_ui/main.go
+++ b/cmd/soong_ui/main.go
@@ -35,14 +35,14 @@
// A command represents an operation to be executed in the soong build
// system.
type command struct {
- // the flag name (must have double dashes)
+ // The flag name (must have double dashes).
flag string
- // description for the flag (to display when running help)
+ // Description for the flag (to display when running help).
description string
- // Forces the status output into dumb terminal mode.
- forceDumbOutput bool
+ // Stream the build status output into the simple terminal mode.
+ simpleOutput bool
// Sets a prefix string to use for filenames of log files.
logsPrefix string
@@ -70,21 +70,21 @@
stdio: stdio,
run: make,
}, {
- flag: "--dumpvar-mode",
- description: "print the value of the legacy make variable VAR to stdout",
- forceDumbOutput: true,
- logsPrefix: "dumpvars-",
- config: dumpVarConfig,
- stdio: customStdio,
- run: dumpVar,
+ flag: "--dumpvar-mode",
+ description: "print the value of the legacy make variable VAR to stdout",
+ simpleOutput: true,
+ logsPrefix: "dumpvars-",
+ config: dumpVarConfig,
+ stdio: customStdio,
+ run: dumpVar,
}, {
- flag: "--dumpvars-mode",
- description: "dump the values of one or more legacy make variables, in shell syntax",
- forceDumbOutput: true,
- logsPrefix: "dumpvars-",
- config: dumpVarConfig,
- stdio: customStdio,
- run: dumpVars,
+ flag: "--dumpvars-mode",
+ description: "dump the values of one or more legacy make variables, in shell syntax",
+ simpleOutput: true,
+ logsPrefix: "dumpvars-",
+ config: dumpVarConfig,
+ stdio: customStdio,
+ run: dumpVars,
}, {
flag: "--build-mode",
description: "build modules based on the specified build action",
@@ -117,7 +117,7 @@
// Command is the type of soong_ui execution. Only one type of
// execution is specified. The args are specific to the command.
func main() {
- buildStartedMilli := time.Now().UnixNano() / int64(time.Millisecond)
+ buildStarted := time.Now()
c, args := getCommand(os.Args)
if c == nil {
@@ -125,7 +125,7 @@
os.Exit(1)
}
- output := terminal.NewStatusOutput(c.stdio().Stdout(), os.Getenv("NINJA_STATUS"), c.forceDumbOutput,
+ output := terminal.NewStatusOutput(c.stdio().Stdout(), os.Getenv("NINJA_STATUS"), c.simpleOutput,
build.OsEnvironment().IsEnvTrue("ANDROID_QUIET_BUILD"))
log := logger.New(output)
@@ -138,6 +138,7 @@
defer trace.Close()
met := metrics.New()
+ met.SetBuildDateTime(buildStarted)
stat := &status.Status{}
defer stat.Finish()
@@ -171,7 +172,7 @@
buildErrorFile := filepath.Join(logsDir, c.logsPrefix+"build_error")
rbeMetricsFile := filepath.Join(logsDir, c.logsPrefix+"rbe_metrics.pb")
soongMetricsFile := filepath.Join(logsDir, c.logsPrefix+"soong_metrics")
- defer build.UploadMetrics(buildCtx, config, c.forceDumbOutput, buildStartedMilli, buildErrorFile, rbeMetricsFile, soongMetricsFile)
+ defer build.UploadMetrics(buildCtx, config, c.simpleOutput, buildStarted, buildErrorFile, rbeMetricsFile, soongMetricsFile)
os.MkdirAll(logsDir, 0777)
log.SetOutput(filepath.Join(logsDir, c.logsPrefix+"soong.log"))
diff --git a/dexpreopt/config.go b/dexpreopt/config.go
index 2cf65fe..db5e97a 100644
--- a/dexpreopt/config.go
+++ b/dexpreopt/config.go
@@ -40,15 +40,15 @@
DisableGenerateProfile bool // don't generate profiles
ProfileDir string // directory to find profiles in
- BootJars []string // modules for jars that form the boot class path
- UpdatableBootJars []string // jars within apex that form the boot class path
+ BootJars android.ConfiguredJarList // modules for jars that form the boot class path
+ UpdatableBootJars android.ConfiguredJarList // jars within apex that form the boot class path
- ArtApexJars []string // modules for jars that are in the ART APEX
+ ArtApexJars android.ConfiguredJarList // modules for jars that are in the ART APEX
- SystemServerJars []string // jars that form the system server
- SystemServerApps []string // apps that are loaded into system server
- UpdatableSystemServerJars []string // jars within apex that are loaded into system server
- SpeedApps []string // apps that should be speed optimized
+ SystemServerJars []string // jars that form the system server
+ SystemServerApps []string // apps that are loaded into system server
+ UpdatableSystemServerJars android.ConfiguredJarList // jars within apex that are loaded into system server
+ SpeedApps []string // apps that should be speed optimized
BrokenSuboptimalOrderOfSystemServerJars bool // if true, sub-optimal order does not cause a build error
@@ -189,8 +189,12 @@
// Copies of entries in GlobalConfig that are not constructable without extra parameters. They will be
// used to construct the real value manually below.
- DirtyImageObjects string
- BootImageProfiles []string
+ BootJars []string
+ UpdatableBootJars []string
+ ArtApexJars []string
+ UpdatableSystemServerJars []string
+ DirtyImageObjects string
+ BootImageProfiles []string
}
config := GlobalJSONConfig{}
@@ -200,6 +204,10 @@
}
// Construct paths that require a PathContext.
+ config.GlobalConfig.BootJars = android.CreateConfiguredJarList(ctx, config.BootJars)
+ config.GlobalConfig.UpdatableBootJars = android.CreateConfiguredJarList(ctx, config.UpdatableBootJars)
+ config.GlobalConfig.ArtApexJars = android.CreateConfiguredJarList(ctx, config.ArtApexJars)
+ config.GlobalConfig.UpdatableSystemServerJars = android.CreateConfiguredJarList(ctx, config.UpdatableSystemServerJars)
config.GlobalConfig.DirtyImageObjects = android.OptionalPathForPath(constructPath(ctx, config.DirtyImageObjects))
config.GlobalConfig.BootImageProfiles = constructPaths(ctx, config.BootImageProfiles)
@@ -530,12 +538,12 @@
PatternsOnSystemOther: nil,
DisableGenerateProfile: false,
ProfileDir: "",
- BootJars: nil,
- UpdatableBootJars: nil,
- ArtApexJars: nil,
+ BootJars: android.EmptyConfiguredJarList(),
+ UpdatableBootJars: android.EmptyConfiguredJarList(),
+ ArtApexJars: android.EmptyConfiguredJarList(),
SystemServerJars: nil,
SystemServerApps: nil,
- UpdatableSystemServerJars: nil,
+ UpdatableSystemServerJars: android.EmptyConfiguredJarList(),
SpeedApps: nil,
PreoptFlags: nil,
DefaultCompilerFilter: "",
diff --git a/dexpreopt/dexpreopt.go b/dexpreopt/dexpreopt.go
index e49fa98..8c9f0a2 100644
--- a/dexpreopt/dexpreopt.go
+++ b/dexpreopt/dexpreopt.go
@@ -83,7 +83,7 @@
if !dexpreoptDisabled(ctx, global, module) {
// Don't preopt individual boot jars, they will be preopted together.
- if !contains(android.GetJarsFromApexJarPairs(ctx, global.BootJars), module.Name) {
+ if !global.BootJars.ContainsJar(module.Name) {
appImage := (generateProfile || module.ForceCreateAppImage || global.DefaultAppImages) &&
!module.NoCreateAppImage
@@ -104,17 +104,15 @@
}
// Don't preopt system server jars that are updatable.
- for _, p := range global.UpdatableSystemServerJars {
- if _, jar := android.SplitApexJarPair(ctx, p); jar == module.Name {
- return true
- }
+ if global.UpdatableSystemServerJars.ContainsJar(module.Name) {
+ return true
}
// If OnlyPreoptBootImageAndSystemServer=true and module is not in boot class path skip
// Also preopt system server jars since selinux prevents system server from loading anything from
// /data. If we don't do this they will need to be extracted which is not favorable for RAM usage
// or performance. If PreoptExtractedApk is true, we ignore the only preopt boot image options.
- if global.OnlyPreoptBootImageAndSystemServer && !contains(android.GetJarsFromApexJarPairs(ctx, global.BootJars), module.Name) &&
+ if global.OnlyPreoptBootImageAndSystemServer && !global.BootJars.ContainsJar(module.Name) &&
!contains(global.SystemServerJars, module.Name) && !module.PreoptExtractedApk {
return true
}
@@ -571,20 +569,13 @@
}
}
-// Expected format for apexJarValue = <apex name>:<jar name>
-func GetJarLocationFromApexJarPair(ctx android.PathContext, apexJarValue string) string {
- apex, jar := android.SplitApexJarPair(ctx, apexJarValue)
- return filepath.Join("/apex", apex, "javalib", jar+".jar")
-}
-
var nonUpdatableSystemServerJarsKey = android.NewOnceKey("nonUpdatableSystemServerJars")
// TODO: eliminate the superficial global config parameter by moving global config definition
// from java subpackage to dexpreopt.
func NonUpdatableSystemServerJars(ctx android.PathContext, global *GlobalConfig) []string {
return ctx.Config().Once(nonUpdatableSystemServerJarsKey, func() interface{} {
- return android.RemoveListFromList(global.SystemServerJars,
- android.GetJarsFromApexJarPairs(ctx, global.UpdatableSystemServerJars))
+ return android.RemoveListFromList(global.SystemServerJars, global.UpdatableSystemServerJars.CopyOfJars())
}).([]string)
}
diff --git a/genrule/genrule.go b/genrule/genrule.go
index 00baa57..1cec289 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -259,9 +259,9 @@
// If AllowMissingDependencies is enabled, the build will not have stopped when
// AddFarVariationDependencies was called on a missing tool, which will result in nonsensical
- // "cmd: unknown location label ..." errors later. Add a dummy file to the local label. The
- // command that uses this dummy file will never be executed because the rule will be replaced with
- // an android.Error rule reporting the missing dependencies.
+ // "cmd: unknown location label ..." errors later. Add a placeholder file to the local label.
+ // The command that uses this placeholder file will never be executed because the rule will be
+ // replaced with an android.Error rule reporting the missing dependencies.
if ctx.Config().AllowMissingDependencies() {
for _, tool := range g.properties.Tools {
if !seenTools[tool] {
@@ -292,9 +292,9 @@
// If AllowMissingDependencies is enabled, the build will not have stopped when
// the dependency was added on a missing SourceFileProducer module, which will result in nonsensical
- // "cmd: label ":..." has no files" errors later. Add a dummy file to the local label. The
- // command that uses this dummy file will never be executed because the rule will be replaced with
- // an android.Error rule reporting the missing dependencies.
+ // "cmd: label ":..." has no files" errors later. Add a placeholder file to the local label.
+ // The command that uses this placeholder file will never be executed because the rule will be
+ // replaced with an android.Error rule reporting the missing dependencies.
ctx.AddMissingDependencies(missingDeps)
addLocationLabel(in, []string{"***missing srcs " + in + "***"})
} else {
diff --git a/java/Android.bp b/java/Android.bp
index 1fda7f7..e345014 100644
--- a/java/Android.bp
+++ b/java/Android.bp
@@ -10,6 +10,7 @@
"soong-dexpreopt",
"soong-genrule",
"soong-java-config",
+ "soong-python",
"soong-remoteexec",
"soong-tradefed",
],
@@ -38,6 +39,7 @@
"java_resources.go",
"kotlin.go",
"lint.go",
+ "legacy_core_platform_api_usage.go",
"platform_compat_config.go",
"plugin.go",
"prebuilt_apis.go",
diff --git a/java/aar.go b/java/aar.go
index 500788f..ad9b5e7 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -641,7 +641,7 @@
var unzipAAR = pctx.AndroidStaticRule("unzipAAR",
blueprint.RuleParams{
Command: `rm -rf $outDir && mkdir -p $outDir && ` +
- `unzip -qo -d $outDir $in && rm -rf $outDir/res && touch $out`,
+ `unzip -qoDD -d $outDir $in && rm -rf $outDir/res && touch $out`,
},
"outDir")
diff --git a/java/android_manifest.go b/java/android_manifest.go
index 8280cb1..84dee16 100644
--- a/java/android_manifest.go
+++ b/java/android_manifest.go
@@ -130,7 +130,7 @@
},
})
- return fixedManifest
+ return fixedManifest.WithoutRel()
}
func manifestMerger(ctx android.ModuleContext, manifest android.Path, staticLibManifests android.Paths,
@@ -155,5 +155,5 @@
},
})
- return mergedManifest
+ return mergedManifest.WithoutRel()
}
diff --git a/java/androidmk.go b/java/androidmk.go
index 618e15d..650d126 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -127,10 +127,12 @@
entries.AddStrings("LOCAL_ADDITIONAL_CHECKED_MODULE", library.additionalCheckedModules.Strings()...)
}
- if library.proguardDictionary != nil {
- entries.SetPath("LOCAL_SOONG_PROGUARD_DICT", library.proguardDictionary)
+ if library.dexer.proguardDictionary.Valid() {
+ entries.SetPath("LOCAL_SOONG_PROGUARD_DICT", library.dexer.proguardDictionary.Path())
}
entries.SetString("LOCAL_MODULE_STEM", library.Stem())
+
+ entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", library.linter.reports)
},
},
}
@@ -330,8 +332,8 @@
if app.jacocoReportClassesFile != nil {
entries.SetPath("LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR", app.jacocoReportClassesFile)
}
- if app.proguardDictionary != nil {
- entries.SetPath("LOCAL_SOONG_PROGUARD_DICT", app.proguardDictionary)
+ if app.dexer.proguardDictionary.Valid() {
+ entries.SetPath("LOCAL_SOONG_PROGUARD_DICT", app.dexer.proguardDictionary.Path())
}
if app.Name() == "framework-res" {
@@ -370,9 +372,15 @@
entries.SetString("LOCAL_CERTIFICATE", app.certificate.AndroidMkString())
entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", app.getOverriddenPackages()...)
- for _, jniLib := range app.installJniLibs {
- entries.AddStrings("LOCAL_SOONG_JNI_LIBS_"+jniLib.target.Arch.ArchType.String(), jniLib.name)
+ if app.embeddedJniLibs {
+ jniSymbols := app.JNISymbolsInstalls(app.installPathForJNISymbols.String())
+ entries.SetString("LOCAL_SOONG_JNI_LIBS_SYMBOLS", jniSymbols.String())
+ } else {
+ for _, jniLib := range app.jniLibs {
+ entries.AddStrings("LOCAL_SOONG_JNI_LIBS_"+jniLib.target.Arch.ArchType.String(), jniLib.name)
+ }
}
+
if len(app.jniCoverageOutputs) > 0 {
entries.AddStrings("LOCAL_PREBUILT_COVERAGE_ARCHIVE", app.jniCoverageOutputs.Strings()...)
}
@@ -383,6 +391,8 @@
install := app.onDeviceDir + "/" + extra.Base()
entries.AddStrings("LOCAL_SOONG_BUILT_INSTALLED", extra.String()+":"+install)
}
+
+ entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", app.linter.reports)
},
},
ExtraFooters: []android.AndroidMkExtraFootersFunc{
@@ -718,7 +728,7 @@
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
func(entries *android.AndroidMkEntries) {
entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", apkSet.Privileged())
- entries.SetString("LOCAL_APK_SET_MASTER_FILE", apkSet.masterFile)
+ entries.SetString("LOCAL_APK_SET_INSTALL_FILE", apkSet.InstallFile())
entries.SetPath("LOCAL_APKCERTS_FILE", apkSet.apkcertsFile)
entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", apkSet.properties.Overrides...)
},
diff --git a/java/app.go b/java/app.go
index 98bce94..8a0b3db 100755
--- a/java/app.go
+++ b/java/app.go
@@ -78,7 +78,7 @@
properties AndroidAppSetProperties
packedOutput android.WritablePath
- masterFile string
+ installFile string
apkcertsFile android.ModuleOutPath
}
@@ -102,8 +102,12 @@
return as.packedOutput
}
-func (as *AndroidAppSet) MasterFile() string {
- return as.masterFile
+func (as *AndroidAppSet) InstallFile() string {
+ return as.installFile
+}
+
+func (as *AndroidAppSet) APKCertsFile() android.Path {
+ return as.apkcertsFile
}
var TargetCpuAbi = map[string]string{
@@ -132,10 +136,10 @@
func (as *AndroidAppSet) GenerateAndroidBuildActions(ctx android.ModuleContext) {
as.packedOutput = android.PathForModuleOut(ctx, ctx.ModuleName()+".zip")
as.apkcertsFile = android.PathForModuleOut(ctx, "apkcerts.txt")
- // We are assuming here that the master file in the APK
+ // We are assuming here that the install file in the APK
// set has `.apk` suffix. If it doesn't the build will fail.
// APK sets containing APEX files are handled elsewhere.
- as.masterFile = as.BaseModuleName() + ".apk"
+ as.installFile = as.BaseModuleName() + ".apk"
screenDensities := "all"
if dpis := ctx.Config().ProductAAPTPrebuiltDPI(); len(dpis) > 0 {
screenDensities = strings.ToUpper(strings.Join(dpis, ","))
@@ -163,7 +167,7 @@
// android_app_set extracts a set of APKs based on the target device
// configuration and installs this set as "split APKs".
-// The extracted set always contains 'master' APK whose name is
+// The extracted set always contains an APK whose name is
// _module_name_.apk and every split APK matching target device.
// The extraction of the density-specific splits depends on
// PRODUCT_AAPT_PREBUILT_DPI variable. If present (its value should
@@ -288,8 +292,10 @@
overridableAppProperties overridableAppProperties
- installJniLibs []jniLib
- jniCoverageOutputs android.Paths
+ jniLibs []jniLib
+ installPathForJNISymbols android.Path
+ embeddedJniLibs bool
+ jniCoverageOutputs android.Paths
bundleFile android.Path
@@ -566,8 +572,7 @@
a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile)
}
-func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path {
-
+func (a *AndroidApp) installPath(ctx android.ModuleContext) android.InstallPath {
var installDir string
if ctx.ModuleName() == "framework-res" {
// framework-res.apk is installed as system/framework/framework-res.apk
@@ -577,12 +582,17 @@
} else {
installDir = filepath.Join("app", a.installApkName)
}
- a.dexpreopter.installPath = android.PathForModuleInstall(ctx, installDir, a.installApkName+".apk")
- if a.deviceProperties.Uncompress_dex == nil {
+
+ return android.PathForModuleInstall(ctx, installDir, a.installApkName+".apk")
+}
+
+func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path {
+ a.dexpreopter.installPath = a.installPath(ctx)
+ if a.dexProperties.Uncompress_dex == nil {
// If the value was not force-set by the user, use reasonable default based on the module.
- a.deviceProperties.Uncompress_dex = proptools.BoolPtr(a.shouldUncompressDex(ctx))
+ a.dexProperties.Uncompress_dex = proptools.BoolPtr(a.shouldUncompressDex(ctx))
}
- a.dexpreopter.uncompressedDex = *a.deviceProperties.Uncompress_dex
+ a.dexpreopter.uncompressedDex = *a.dexProperties.Uncompress_dex
a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries()
a.dexpreopter.usesLibs = a.usesLibrary.usesLibraryProperties.Uses_libs
a.dexpreopter.optionalUsesLibs = a.usesLibrary.presentOptionalUsesLibs(ctx)
@@ -599,8 +609,10 @@
func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, ctx android.ModuleContext) android.WritablePath {
var jniJarFile android.WritablePath
if len(jniLibs) > 0 {
+ a.jniLibs = jniLibs
if a.shouldEmbedJnis(ctx) {
jniJarFile = android.PathForModuleOut(ctx, "jnilibs.zip")
+ a.installPathForJNISymbols = a.installPath(ctx).ToMakePath()
TransformJniLibsToJar(ctx, jniJarFile, jniLibs, a.useEmbeddedNativeLibs(ctx))
for _, jni := range jniLibs {
if jni.coverageFile.Valid() {
@@ -618,13 +630,25 @@
}
}
}
- } else {
- a.installJniLibs = jniLibs
+ a.embeddedJniLibs = true
}
}
return jniJarFile
}
+func (a *AndroidApp) JNISymbolsInstalls(installPath string) android.RuleBuilderInstalls {
+ var jniSymbols android.RuleBuilderInstalls
+ for _, jniLib := range a.jniLibs {
+ if jniLib.unstrippedFile != nil {
+ jniSymbols = append(jniSymbols, android.RuleBuilderInstall{
+ From: jniLib.unstrippedFile,
+ To: filepath.Join(installPath, targetToJniDir(jniLib.target), jniLib.unstrippedFile.Base()),
+ })
+ }
+ }
+ return jniSymbols
+}
+
func (a *AndroidApp) noticeBuildActions(ctx android.ModuleContext) {
// Collect NOTICE files from all dependencies.
seenModules := make(map[android.Module]bool)
@@ -752,6 +776,7 @@
a.linter.mergedManifest = a.aapt.mergedManifestFile
a.linter.manifest = a.aapt.manifestPath
a.linter.resources = a.aapt.resourceFiles
+ a.linter.buildModuleReportZip = ctx.Config().UnbundledBuildApps()
dexJarFile := a.dexBuildActions(ctx)
@@ -820,7 +845,9 @@
otherName := ctx.OtherModuleName(module)
tag := ctx.OtherModuleDependencyTag(module)
- if IsJniDepTag(tag) || tag == cc.SharedDepTag {
+ // TODO(ccross): The tag == cc.SharedDepTag() check should be cc.IsSharedDepTag(tag) but
+ // was left to maintain behavior when adding libraryDependencyTag.
+ if IsJniDepTag(tag) || tag == cc.SharedDepTag() {
if dep, ok := module.(*cc.Module); ok {
if dep.IsNdk() || dep.IsStubs() {
return false
@@ -840,10 +867,11 @@
if lib.Valid() {
jniLibs = append(jniLibs, jniLib{
- name: ctx.OtherModuleName(module),
- path: path,
- target: module.Target(),
- coverageFile: dep.CoverageOutputFile(),
+ name: ctx.OtherModuleName(module),
+ path: path,
+ target: module.Target(),
+ coverageFile: dep.CoverageOutputFile(),
+ unstrippedFile: dep.UnstrippedOutputFile(),
})
} else {
ctx.ModuleErrorf("dependency %q missing output file", otherName)
@@ -969,8 +997,8 @@
func AndroidAppFactory() android.Module {
module := &AndroidApp{}
- module.Module.deviceProperties.Optimize.EnabledByDefault = true
- module.Module.deviceProperties.Optimize.Shrink = proptools.BoolPtr(true)
+ module.Module.dexProperties.Optimize.EnabledByDefault = true
+ module.Module.dexProperties.Optimize.Shrink = proptools.BoolPtr(true)
module.Module.properties.Instrument = true
module.Module.properties.Installable = proptools.BoolPtr(true)
@@ -1084,7 +1112,7 @@
func AndroidTestFactory() android.Module {
module := &AndroidTest{}
- module.Module.deviceProperties.Optimize.EnabledByDefault = true
+ module.Module.dexProperties.Optimize.EnabledByDefault = true
module.Module.properties.Instrument = true
module.Module.properties.Installable = proptools.BoolPtr(true)
@@ -1135,7 +1163,7 @@
func AndroidTestHelperAppFactory() android.Module {
module := &AndroidTestHelperApp{}
- module.Module.deviceProperties.Optimize.EnabledByDefault = true
+ module.Module.dexProperties.Optimize.EnabledByDefault = true
module.Module.properties.Installable = proptools.BoolPtr(true)
module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
diff --git a/java/app_test.go b/java/app_test.go
index d4323bb..efb4fd2 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -161,11 +161,11 @@
t.Errorf("wrong partition value: '%s', expected 'system'", s)
}
mkEntries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0]
- actualMaster := mkEntries.EntryMap["LOCAL_APK_SET_MASTER_FILE"]
- expectedMaster := []string{"foo.apk"}
- if !reflect.DeepEqual(actualMaster, expectedMaster) {
- t.Errorf("Unexpected LOCAL_APK_SET_MASTER_FILE value: '%s', expected: '%s',",
- actualMaster, expectedMaster)
+ actualInstallFile := mkEntries.EntryMap["LOCAL_APK_SET_INSTALL_FILE"]
+ expectedInstallFile := []string{"foo.apk"}
+ if !reflect.DeepEqual(actualInstallFile, expectedInstallFile) {
+ t.Errorf("Unexpected LOCAL_APK_SET_INSTALL_FILE value: '%s', expected: '%s',",
+ actualInstallFile, expectedInstallFile)
}
}
diff --git a/java/config/config.go b/java/config/config.go
index 0fe74c8..d2f4513 100644
--- a/java/config/config.go
+++ b/java/config/config.go
@@ -30,6 +30,8 @@
LegacyCorePlatformBootclasspathLibraries = []string{"legacy.core.platform.api.stubs", "core-lambda-stubs"}
LegacyCorePlatformSystemModules = "legacy-core-platform-api-stubs-system-modules"
+ StableCorePlatformBootclasspathLibraries = []string{"stable.core.platform.api.stubs", "core-lambda-stubs"}
+ StableCorePlatformSystemModules = "stable-core-platform-api-stubs-system-modules"
FrameworkLibraries = []string{"ext", "framework"}
DefaultLambdaStubsLibrary = "core-lambda-stubs"
SdkLambdaStubsPath = "prebuilts/sdk/tools/core-lambda-stubs.jar"
diff --git a/java/dex.go b/java/dex.go
index 9e61e95..cd45a93 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -24,6 +24,60 @@
"android/soong/remoteexec"
)
+type DexProperties struct {
+ // If set to true, compile dex regardless of installable. Defaults to false.
+ Compile_dex *bool
+
+ // list of module-specific flags that will be used for dex compiles
+ Dxflags []string `android:"arch_variant"`
+
+ Optimize struct {
+ // If false, disable all optimization. Defaults to true for android_app and android_test
+ // modules, false for java_library and java_test modules.
+ Enabled *bool
+ // True if the module containing this has it set by default.
+ EnabledByDefault bool `blueprint:"mutated"`
+
+ // If true, optimize for size by removing unused code. Defaults to true for apps,
+ // false for libraries and tests.
+ Shrink *bool
+
+ // If true, optimize bytecode. Defaults to false.
+ Optimize *bool
+
+ // If true, obfuscate bytecode. Defaults to false.
+ Obfuscate *bool
+
+ // If true, do not use the flag files generated by aapt that automatically keep
+ // classes referenced by the app manifest. Defaults to false.
+ No_aapt_flags *bool
+
+ // Flags to pass to proguard.
+ Proguard_flags []string
+
+ // Specifies the locations of files containing proguard flags.
+ Proguard_flags_files []string `android:"path"`
+ }
+
+ // Keep the data uncompressed. We always need uncompressed dex for execution,
+ // so this might actually save space by avoiding storing the same data twice.
+ // This defaults to reasonable value based on module and should not be set.
+ // It exists only to support ART tests.
+ Uncompress_dex *bool
+}
+
+type dexer struct {
+ dexProperties DexProperties
+
+ // list of extra proguard flag files
+ extraProguardFlagFiles android.Paths
+ proguardDictionary android.OptionalPath
+}
+
+func (d *dexer) effectiveOptimizeEnabled() bool {
+ return BoolDefault(d.dexProperties.Optimize.Enabled, d.dexProperties.Optimize.EnabledByDefault)
+}
+
var d8, d8RE = remoteexec.MultiCommandStaticRules(pctx, "d8",
blueprint.RuleParams{
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
@@ -86,8 +140,8 @@
},
}, []string{"outDir", "outDict", "r8Flags", "zipFlags"}, []string{"implicits"})
-func (j *Module) dexCommonFlags(ctx android.ModuleContext) []string {
- flags := j.deviceProperties.Dxflags
+func (d *dexer) dexCommonFlags(ctx android.ModuleContext, minSdkVersion sdkSpec) []string {
+ flags := d.dexProperties.Dxflags
// Translate all the DX flags to D8 ones until all the build files have been migrated
// to D8 flags. See: b/69377755
flags = android.RemoveListFromList(flags,
@@ -103,30 +157,27 @@
"--verbose")
}
- minSdkVersion, err := j.minSdkVersion().effectiveVersion(ctx)
+ effectiveVersion, err := minSdkVersion.effectiveVersion(ctx)
if err != nil {
ctx.PropertyErrorf("min_sdk_version", "%s", err)
}
- flags = append(flags, "--min-api "+minSdkVersion.asNumberString())
+ flags = append(flags, "--min-api "+effectiveVersion.asNumberString())
return flags
}
-func (j *Module) d8Flags(ctx android.ModuleContext, flags javaBuilderFlags) ([]string, android.Paths) {
- d8Flags := j.dexCommonFlags(ctx)
-
+func d8Flags(flags javaBuilderFlags) (d8Flags []string, d8Deps android.Paths) {
d8Flags = append(d8Flags, flags.bootClasspath.FormRepeatedClassPath("--lib ")...)
d8Flags = append(d8Flags, flags.classpath.FormRepeatedClassPath("--lib ")...)
- var d8Deps android.Paths
d8Deps = append(d8Deps, flags.bootClasspath...)
d8Deps = append(d8Deps, flags.classpath...)
return d8Flags, d8Deps
}
-func (j *Module) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Flags []string, r8Deps android.Paths) {
- opt := j.deviceProperties.Optimize
+func (d *dexer) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Flags []string, r8Deps android.Paths) {
+ opt := d.dexProperties.Optimize
// When an app contains references to APIs that are not in the SDK specified by
// its LOCAL_SDK_VERSION for example added by support library or by runtime
@@ -140,8 +191,6 @@
proguardRaiseDeps = append(proguardRaiseDeps, dep.(Dependency).HeaderJars()...)
})
- r8Flags = append(r8Flags, j.dexCommonFlags(ctx)...)
-
r8Flags = append(r8Flags, proguardRaiseDeps.FormJavaClassPath("-libraryjars"))
r8Flags = append(r8Flags, flags.bootClasspath.FormJavaClassPath("-libraryjars"))
r8Flags = append(r8Flags, flags.classpath.FormJavaClassPath("-libraryjars"))
@@ -154,15 +203,10 @@
android.PathForSource(ctx, "build/make/core/proguard.flags"),
}
- if j.shouldInstrumentStatic(ctx) {
- flagFiles = append(flagFiles,
- android.PathForSource(ctx, "build/make/core/proguard.jacoco.flags"))
- }
-
- flagFiles = append(flagFiles, j.extraProguardFlagFiles...)
+ flagFiles = append(flagFiles, d.extraProguardFlagFiles...)
// TODO(ccross): static android library proguard files
- flagFiles = append(flagFiles, android.PathsForModuleSrc(ctx, j.deviceProperties.Optimize.Proguard_flags_files)...)
+ flagFiles = append(flagFiles, android.PathsForModuleSrc(ctx, opt.Proguard_flags_files)...)
r8Flags = append(r8Flags, android.JoinWithPrefix(flagFiles.Strings(), "-include "))
r8Deps = append(r8Deps, flagFiles...)
@@ -171,7 +215,7 @@
r8Deps = append(r8Deps, android.PathForSource(ctx,
"build/make/core/proguard_basic_keeps.flags"))
- r8Flags = append(r8Flags, j.deviceProperties.Optimize.Proguard_flags...)
+ r8Flags = append(r8Flags, opt.Proguard_flags...)
// TODO(ccross): Don't shrink app instrumentation tests by default.
if !Bool(opt.Shrink) {
@@ -197,29 +241,30 @@
return r8Flags, r8Deps
}
-func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags,
+func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, minSdkVersion sdkSpec,
classesJar android.Path, jarName string) android.ModuleOutPath {
- useR8 := j.deviceProperties.EffectiveOptimizeEnabled()
-
// Compile classes.jar into classes.dex and then javalib.jar
javalibJar := android.PathForModuleOut(ctx, "dex", jarName)
outDir := android.PathForModuleOut(ctx, "dex")
zipFlags := "--ignore_missing_files"
- if proptools.Bool(j.deviceProperties.Uncompress_dex) {
+ if proptools.Bool(d.dexProperties.Uncompress_dex) {
zipFlags += " -L 0"
}
+ commonFlags := d.dexCommonFlags(ctx, minSdkVersion)
+
+ useR8 := d.effectiveOptimizeEnabled()
if useR8 {
proguardDictionary := android.PathForModuleOut(ctx, "proguard_dictionary")
- j.proguardDictionary = proguardDictionary
- r8Flags, r8Deps := j.r8Flags(ctx, flags)
+ d.proguardDictionary = android.OptionalPathForPath(proguardDictionary)
+ r8Flags, r8Deps := d.r8Flags(ctx, flags)
rule := r8
args := map[string]string{
- "r8Flags": strings.Join(r8Flags, " "),
+ "r8Flags": strings.Join(append(commonFlags, r8Flags...), " "),
"zipFlags": zipFlags,
- "outDict": j.proguardDictionary.String(),
+ "outDict": proguardDictionary.String(),
"outDir": outDir.String(),
}
if ctx.Config().IsEnvTrue("RBE_R8") {
@@ -236,7 +281,7 @@
Args: args,
})
} else {
- d8Flags, d8Deps := j.d8Flags(ctx, flags)
+ d8Flags, d8Deps := d8Flags(flags)
rule := d8
if ctx.Config().IsEnvTrue("RBE_D8") {
rule = d8RE
@@ -248,13 +293,13 @@
Input: classesJar,
Implicits: d8Deps,
Args: map[string]string{
- "d8Flags": strings.Join(d8Flags, " "),
+ "d8Flags": strings.Join(append(commonFlags, d8Flags...), " "),
"zipFlags": zipFlags,
"outDir": outDir.String(),
},
})
}
- if proptools.Bool(j.deviceProperties.Uncompress_dex) {
+ if proptools.Bool(d.dexProperties.Uncompress_dex) {
alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", jarName)
TransformZipAlign(ctx, alignedJavalibJar, javalibJar)
javalibJar = alignedJavalibJar
diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go
index 4120559..3abe782 100644
--- a/java/dexpreopt_bootjars.go
+++ b/java/dexpreopt_bootjars.go
@@ -49,8 +49,8 @@
// Subdirectory where the image files are installed.
installSubdir string
- // The names of jars that constitute this image.
- modules []string
+ // A list of (location, jar) pairs for the Java modules in this image.
+ modules android.ConfiguredJarList
// File paths to jars.
dexPaths android.WritablePaths // for this image
@@ -113,16 +113,16 @@
// Dexpreopt on the boot class path produces multiple files. The first dex file
// is converted into 'name'.art (to match the legacy assumption that 'name'.art
// exists), and the rest are converted to 'name'-<jar>.art.
- _, m := android.SplitApexJarPair(ctx, image.modules[idx])
+ m := image.modules.Jar(idx)
name := image.stem
if idx != 0 || image.extends != nil {
- name += "-" + stemOf(m)
+ name += "-" + android.ModuleStem(m)
}
return name
}
func (image bootImageConfig) firstModuleNameOrStem(ctx android.PathContext) string {
- if len(image.modules) > 0 {
+ if image.modules.Len() > 0 {
return image.moduleName(ctx, 0)
} else {
return image.stem
@@ -130,8 +130,8 @@
}
func (image bootImageConfig) moduleFiles(ctx android.PathContext, dir android.OutputPath, exts ...string) android.OutputPaths {
- ret := make(android.OutputPaths, 0, len(image.modules)*len(exts))
- for i := range image.modules {
+ ret := make(android.OutputPaths, 0, image.modules.Len()*len(exts))
+ for i := 0; i < image.modules.Len(); i++ {
name := image.moduleName(ctx, i)
for _, ext := range exts {
ret = append(ret, dir.Join(ctx, name+ext))
@@ -253,7 +253,7 @@
}
name := ctx.ModuleName(module)
- index := android.IndexList(name, android.GetJarsFromApexJarPairs(ctx, image.modules))
+ index := image.modules.IndexOfJar(name)
if index == -1 {
return -1, nil
}
@@ -295,7 +295,7 @@
func buildBootImage(ctx android.SingletonContext, image *bootImageConfig) *bootImageConfig {
// Collect dex jar paths for the boot image modules.
// This logic is tested in the apex package to avoid import cycle apex <-> java.
- bootDexJars := make(android.Paths, len(image.modules))
+ bootDexJars := make(android.Paths, image.modules.Len())
ctx.VisitAllModules(func(module android.Module) {
if i, j := getBootImageJar(ctx, image, module); i != -1 {
bootDexJars[i] = j
@@ -306,7 +306,7 @@
// Ensure all modules were converted to paths
for i := range bootDexJars {
if bootDexJars[i] == nil {
- _, m := android.SplitApexJarPair(ctx, image.modules[i])
+ m := image.modules.Jar(i)
if ctx.Config().AllowMissingDependencies() {
missingDeps = append(missingDeps, m)
bootDexJars[i] = android.PathForOutput(ctx, "missing")
@@ -608,7 +608,7 @@
return ctx.Config().Once(updatableBcpPackagesRuleKey, func() interface{} {
global := dexpreopt.GetGlobalConfig(ctx)
- updatableModules := android.GetJarsFromApexJarPairs(ctx, global.UpdatableBootJars)
+ updatableModules := global.UpdatableBootJars.CopyOfJars()
// Collect `permitted_packages` for updatable boot jars.
var updatablePackages []string
diff --git a/java/dexpreopt_bootjars_test.go b/java/dexpreopt_bootjars_test.go
index 9670c7f..4a8d3cd 100644
--- a/java/dexpreopt_bootjars_test.go
+++ b/java/dexpreopt_bootjars_test.go
@@ -48,7 +48,7 @@
pathCtx := android.PathContextForTesting(config)
dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)
- dexpreoptConfig.BootJars = []string{"platform:foo", "platform:bar", "platform:baz"}
+ dexpreoptConfig.BootJars = android.CreateConfiguredJarList(pathCtx, []string{"platform:foo", "platform:bar", "platform:baz"})
dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
ctx := testContext()
diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go
index f13d9f2..f0d82ff 100644
--- a/java/dexpreopt_config.go
+++ b/java/dexpreopt_config.go
@@ -37,14 +37,12 @@
filepath.Join("/system/framework", m+".jar"))
}
// 2) The jars that are from an updatable apex.
- for _, m := range global.UpdatableSystemServerJars {
- systemServerClasspathLocations = append(systemServerClasspathLocations,
- dexpreopt.GetJarLocationFromApexJarPair(ctx, m))
- }
- if len(systemServerClasspathLocations) != len(global.SystemServerJars)+len(global.UpdatableSystemServerJars) {
+ systemServerClasspathLocations = append(systemServerClasspathLocations,
+ global.UpdatableSystemServerJars.DevicePaths(ctx.Config(), android.Android)...)
+ if len(systemServerClasspathLocations) != len(global.SystemServerJars)+global.UpdatableSystemServerJars.Len() {
panic(fmt.Errorf("Wrong number of system server jars, got %d, expected %d",
len(systemServerClasspathLocations),
- len(global.SystemServerJars)+len(global.UpdatableSystemServerJars)))
+ len(global.SystemServerJars)+global.UpdatableSystemServerJars.Len()))
}
return systemServerClasspathLocations
})
@@ -69,39 +67,6 @@
return targets
}
-func stemOf(moduleName string) string {
- // b/139391334: the stem of framework-minus-apex is framework
- // This is hard coded here until we find a good way to query the stem
- // of a module before any other mutators are run
- if moduleName == "framework-minus-apex" {
- return "framework"
- }
- return moduleName
-}
-
-func getDexLocation(ctx android.PathContext, target android.Target, module string) string {
- apex, jar := android.SplitApexJarPair(ctx, module)
-
- name := stemOf(jar) + ".jar"
-
- var subdir string
- if apex == "platform" {
- // Special apex name "platform" denotes jars do not come from an apex, but are part
- // of the platform. Such jars are installed on the /system partition on device.
- subdir = "system/framework"
- } else if apex == "system_ext" {
- subdir = "system_ext/framework"
- } else {
- subdir = filepath.Join("apex", apex, "javalib")
- }
-
- if target.Os.Class == android.Host {
- return filepath.Join(ctx.Config().Getenv("OUT_DIR"), "host", ctx.Config().PrebuiltOS(), subdir, name)
- } else {
- return filepath.Join("/", subdir, name)
- }
-}
-
var (
bootImageConfigKey = android.NewOnceKey("bootImageConfig")
artBootImageName = "art"
@@ -116,12 +81,13 @@
targets := dexpreoptTargets(ctx)
deviceDir := android.PathForOutput(ctx, ctx.Config().DeviceName())
- artModules := global.ArtApexJars
+ artModules := global.ArtApexJars.CopyOf()
// With EMMA_INSTRUMENT_FRAMEWORK=true the Core libraries depend on jacoco.
if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
- artModules = append(artModules, "com.android.art:jacocoagent")
+ artModules.Append("com.android.art", "jacocoagent")
}
- frameworkModules := android.RemoveListFromList(global.BootJars, artModules)
+ frameworkModules := global.BootJars.CopyOf()
+ frameworkModules.RemoveList(artModules)
artSubdir := "apex/com.android.art/javalib"
frameworkSubdir := "system/framework"
@@ -163,10 +129,7 @@
// Set up known paths for them, the singleton rules will copy them there.
// TODO(b/143682396): use module dependencies instead
inputDir := deviceDir.Join(ctx, "dex_"+c.name+"jars_input")
- for _, m := range c.modules {
- _, jar := android.SplitApexJarPair(ctx, m)
- c.dexPaths = append(c.dexPaths, inputDir.Join(ctx, stemOf(jar)+".jar"))
- }
+ c.dexPaths = c.modules.BuildPaths(ctx, inputDir)
c.dexPathsDeps = c.dexPaths
// Create target-specific variants.
@@ -178,9 +141,7 @@
target: target,
images: imageDir.Join(ctx, imageName),
imagesDeps: c.moduleFiles(ctx, imageDir, ".art", ".oat", ".vdex"),
- }
- for _, m := range c.modules {
- variant.dexLocations = append(variant.dexLocations, getDexLocation(ctx, target, m))
+ dexLocations: c.modules.DevicePaths(ctx.Config(), target.Os),
}
variant.dexLocationsDeps = variant.dexLocations
c.variants = append(c.variants, variant)
@@ -213,10 +174,7 @@
global := dexpreopt.GetGlobalConfig(ctx)
image := defaultBootImageConfig(ctx)
- updatableBootclasspath := make([]string, len(global.UpdatableBootJars))
- for i, p := range global.UpdatableBootJars {
- updatableBootclasspath[i] = dexpreopt.GetJarLocationFromApexJarPair(ctx, p)
- }
+ updatableBootclasspath := global.UpdatableBootJars.DevicePaths(ctx.Config(), android.Android)
bootclasspath := append(copyOf(image.getAnyAndroidVariant().dexLocationsDeps), updatableBootclasspath...)
return bootclasspath
@@ -236,5 +194,5 @@
ctx.Strict("PRODUCT_DEX2OAT_BOOTCLASSPATH", strings.Join(defaultBootImageConfig(ctx).getAnyAndroidVariant().dexLocationsDeps, ":"))
ctx.Strict("PRODUCT_SYSTEM_SERVER_CLASSPATH", strings.Join(systemServerClasspath(ctx), ":"))
- ctx.Strict("DEXPREOPT_BOOT_JARS_MODULES", strings.Join(defaultBootImageConfig(ctx).modules, ":"))
+ ctx.Strict("DEXPREOPT_BOOT_JARS_MODULES", strings.Join(defaultBootImageConfig(ctx).modules.CopyOfApexJarPairs(), ":"))
}
diff --git a/java/droiddoc.go b/java/droiddoc.go
index 99bfb6d..0840d50 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -112,13 +112,20 @@
// local files that are used within user customized droiddoc options.
Arg_files []string `android:"path"`
- // user customized droiddoc args.
+ // user customized droiddoc args. Deprecated, use flags instead.
// Available variables for substitution:
//
// $(location <label>): the path to the arg_files with name <label>
// $$: a literal $
Args *string
+ // user customized droiddoc args. Not compatible with property args.
+ // Available variables for substitution:
+ //
+ // $(location <label>): the path to the arg_files with name <label>
+ // $$: a literal $
+ Flags []string
+
// names of the output files used in args that will be generated
Out []string
@@ -191,7 +198,7 @@
// the generated removed Dex API filename by Doclava.
Removed_dex_api_filename *string
- // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
+ // if set to false, don't allow droiddoc to generate stubs source files. Defaults to false.
Create_stubs *bool
Check_api struct {
@@ -287,6 +294,9 @@
// the dirs which Metalava extracts API levels annotations from.
Api_levels_annotations_dirs []string
+ // the filename which Metalava extracts API levels annotations from. Defaults to android.jar.
+ Api_levels_jar_filename *string
+
// if set to true, collect the values used by the Dev tools and
// write them in files packaged with the SDK. Defaults to false.
Write_sdk_values *bool
@@ -382,7 +392,7 @@
argFiles android.Paths
implicits android.Paths
- args string
+ args []string
docZip android.WritablePath
stubsSrcJar android.WritablePath
@@ -619,8 +629,8 @@
}
srcFiles = filterHtml(srcFiles)
- flags := j.collectAidlFlags(ctx, deps)
- srcFiles = j.genSources(ctx, srcFiles, flags)
+ aidlFlags := j.collectAidlFlags(ctx, deps)
+ srcFiles = j.genSources(ctx, srcFiles, aidlFlags)
// srcs may depend on some genrule output.
j.srcJars = srcFiles.FilterByExt(".srcjar")
@@ -649,24 +659,38 @@
}
}
- var err error
- j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
- if strings.HasPrefix(name, "location ") {
- label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
- if paths, ok := argFilesMap[label]; ok {
- return paths, nil
- } else {
- return "", fmt.Errorf("unknown location label %q, expecting one of %q",
- label, strings.Join(argFileLabels, ", "))
- }
- } else if name == "genDir" {
- return android.PathForModuleGen(ctx).String(), nil
- }
- return "", fmt.Errorf("unknown variable '$(%s)'", name)
- })
+ var argsPropertyName string
+ flags := make([]string, 0)
+ if j.properties.Args != nil && j.properties.Flags != nil {
+ ctx.PropertyErrorf("args", "flags is set. Cannot set args")
+ } else if args := proptools.String(j.properties.Args); args != "" {
+ flags = append(flags, args)
+ argsPropertyName = "args"
+ } else {
+ flags = append(flags, j.properties.Flags...)
+ argsPropertyName = "flags"
+ }
- if err != nil {
- ctx.PropertyErrorf("args", "%s", err.Error())
+ for _, flag := range flags {
+ args, err := android.Expand(flag, func(name string) (string, error) {
+ if strings.HasPrefix(name, "location ") {
+ label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
+ if paths, ok := argFilesMap[label]; ok {
+ return paths, nil
+ } else {
+ return "", fmt.Errorf("unknown location label %q, expecting one of %q",
+ label, strings.Join(argFileLabels, ", "))
+ }
+ } else if name == "genDir" {
+ return android.PathForModuleGen(ctx).String(), nil
+ }
+ return "", fmt.Errorf("unknown variable '$(%s)'", name)
+ })
+
+ if err != nil {
+ ctx.PropertyErrorf(argsPropertyName, "%s", err.Error())
+ }
+ j.args = append(j.args, args)
}
return deps
@@ -849,6 +873,10 @@
}
}
+func (d *Droiddoc) createStubs() bool {
+ return BoolDefault(d.properties.Create_stubs, false)
+}
+
func (d *Droiddoc) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
@@ -871,7 +899,7 @@
cmd.FlagWithOutput("-removedDexApi ", d.removedDexApiFile)
}
- if BoolDefault(d.properties.Create_stubs, true) {
+ if d.createStubs() {
cmd.FlagWithArg("-stubs ", stubsDir.String())
}
@@ -1010,7 +1038,7 @@
d.stubsFlags(ctx, cmd, stubsDir)
- cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
+ cmd.Flag(strings.Join(d.Javadoc.args, " ")).Implicits(d.Javadoc.argFiles)
if d.properties.Compat_config != nil {
compatConfig := android.PathForModuleSrc(ctx, String(d.properties.Compat_config))
@@ -1327,7 +1355,7 @@
cmd.Flag("--include-annotations")
validatingNullability :=
- strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
+ android.InList("--validate-nullability-from-merged-stubs", d.Javadoc.args) ||
String(d.properties.Validate_nullability_from_list) != ""
migratingNullability := String(d.properties.Previous_api) != ""
@@ -1382,34 +1410,37 @@
}
func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
- if Bool(d.properties.Api_levels_annotations_enabled) {
- d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
-
- if len(d.properties.Api_levels_annotations_dirs) == 0 {
- ctx.PropertyErrorf("api_levels_annotations_dirs",
- "has to be non-empty if api levels annotations was enabled!")
- }
-
- cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml)
- cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml)
- cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion())
- cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())
-
- ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
- if t, ok := m.(*ExportedDroiddocDir); ok {
- for _, dep := range t.deps {
- if strings.HasSuffix(dep.String(), "android.jar") {
- cmd.Implicit(dep)
- }
- }
- cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/android.jar")
- } else {
- ctx.PropertyErrorf("api_levels_annotations_dirs",
- "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
- }
- })
-
+ if !Bool(d.properties.Api_levels_annotations_enabled) {
+ return
}
+
+ d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
+
+ if len(d.properties.Api_levels_annotations_dirs) == 0 {
+ ctx.PropertyErrorf("api_levels_annotations_dirs",
+ "has to be non-empty if api levels annotations was enabled!")
+ }
+
+ cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml)
+ cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml)
+ cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion())
+ cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())
+
+ filename := proptools.StringDefault(d.properties.Api_levels_jar_filename, "android.jar")
+
+ ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
+ if t, ok := m.(*ExportedDroiddocDir); ok {
+ for _, dep := range t.deps {
+ if strings.HasSuffix(dep.String(), filename) {
+ cmd.Implicit(dep)
+ }
+ }
+ cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/"+filename)
+ } else {
+ ctx.PropertyErrorf("api_levels_annotations_dirs",
+ "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
+ }
+ })
}
func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
@@ -1498,7 +1529,9 @@
cmd.Flag("--no-banner").
Flag("--color").
Flag("--quiet").
- Flag("--format=v2")
+ Flag("--format=v2").
+ FlagWithArg("--repeat-errors-max ", "10").
+ FlagWithArg("--hide ", "UnresolvedImport")
return cmd
}
@@ -1539,14 +1572,14 @@
d.apiLevelsAnnotationsFlags(ctx, cmd)
d.apiToXmlFlags(ctx, cmd)
- if strings.Contains(d.Javadoc.args, "--generate-documentation") {
+ if android.InList("--generate-documentation", d.Javadoc.args) {
// Currently Metalava have the ability to invoke Javadoc in a seperate process.
// Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
// "--generate-documentation" arg. This is not needed when Metalava removes this feature.
- d.Javadoc.args = d.Javadoc.args + " -nodocs "
+ d.Javadoc.args = append(d.Javadoc.args, "-nodocs")
}
- cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
+ cmd.Flag(strings.Join(d.Javadoc.args, " ")).Implicits(d.Javadoc.argFiles)
for _, o := range d.Javadoc.properties.Out {
cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
}
@@ -1651,7 +1684,7 @@
impRule := android.NewRuleBuilder()
impCmd := impRule.Command()
- // A dummy action that copies the ninja generated rsp file to a new location. This allows us to
+ // An action that copies the ninja generated rsp file to a new location. This allows us to
// add a large number of inputs to a file without exceeding bash command length limits (which
// would happen if we use the WriteFile rule). The cp is needed because RuleBuilder sets the
// rsp file to be ${output}.rsp.
diff --git a/java/hiddenapi.go b/java/hiddenapi.go
index 130b634..b5a0217 100644
--- a/java/hiddenapi.go
+++ b/java/hiddenapi.go
@@ -146,7 +146,7 @@
var hiddenAPIEncodeDexRule = pctx.AndroidStaticRule("hiddenAPIEncodeDex", blueprint.RuleParams{
Command: `rm -rf $tmpDir && mkdir -p $tmpDir && mkdir $tmpDir/dex-input && mkdir $tmpDir/dex-output &&
- unzip -o -q $in 'classes*.dex' -d $tmpDir/dex-input &&
+ unzip -qoDD $in 'classes*.dex' -d $tmpDir/dex-input &&
for INPUT_DEX in $$(find $tmpDir/dex-input -maxdepth 1 -name 'classes*.dex' | sort); do
echo "--input-dex=$${INPUT_DEX}";
echo "--output-dex=$tmpDir/dex-output/$$(basename $${INPUT_DEX})";
diff --git a/java/hiddenapi_singleton.go b/java/hiddenapi_singleton.go
index bff591c..1e6becb 100644
--- a/java/hiddenapi_singleton.go
+++ b/java/hiddenapi_singleton.go
@@ -208,7 +208,7 @@
}
// flagsRule creates a rule to build hiddenapi-flags.csv out of flags.csv files generated for boot image modules and
-// the greylists.
+// the unsupported API.
func flagsRule(ctx android.SingletonContext) android.Path {
var flagsCSV android.Paths
var greylistRemovedApis android.Paths
@@ -247,19 +247,19 @@
Tool(android.PathForSource(ctx, "frameworks/base/tools/hiddenapi/generate_hiddenapi_lists.py")).
FlagWithInput("--csv ", stubFlags).
Inputs(flagsCSV).
- FlagWithInput("--greylist ",
- android.PathForSource(ctx, "frameworks/base/config/hiddenapi-greylist.txt")).
- FlagWithInput("--greylist-ignore-conflicts ", combinedRemovedApis).
- FlagWithInput("--greylist-max-q ",
- android.PathForSource(ctx, "frameworks/base/config/hiddenapi-greylist-max-q.txt")).
- FlagWithInput("--greylist-max-p ",
- android.PathForSource(ctx, "frameworks/base/config/hiddenapi-greylist-max-p.txt")).
- FlagWithInput("--greylist-max-o-ignore-conflicts ",
- android.PathForSource(ctx, "frameworks/base/config/hiddenapi-greylist-max-o.txt")).
- FlagWithInput("--blacklist ",
- android.PathForSource(ctx, "frameworks/base/config/hiddenapi-force-blacklist.txt")).
- FlagWithInput("--greylist-packages ",
- android.PathForSource(ctx, "frameworks/base/config/hiddenapi-greylist-packages.txt")).
+ FlagWithInput("--unsupported ",
+ android.PathForSource(ctx, "frameworks/base/config/hiddenapi-unsupported.txt")).
+ FlagWithInput("--unsupported-ignore-conflicts ", combinedRemovedApis).
+ FlagWithInput("--max-target-q ",
+ android.PathForSource(ctx, "frameworks/base/config/hiddenapi-max-target-q.txt")).
+ FlagWithInput("--max-target-p ",
+ android.PathForSource(ctx, "frameworks/base/config/hiddenapi-max-target-p.txt")).
+ FlagWithInput("--max-target-o-ignore-conflicts ",
+ android.PathForSource(ctx, "frameworks/base/config/hiddenapi-max-target-o.txt")).
+ FlagWithInput("--blocked ",
+ android.PathForSource(ctx, "frameworks/base/config/hiddenapi-force-blocked.txt")).
+ FlagWithInput("--unsupported-packages ",
+ android.PathForSource(ctx, "frameworks/base/config/hiddenapi-unsupported-packages.txt")).
FlagWithOutput("--output ", tempPath)
commitChangeForRestat(rule, tempPath, outputPath)
diff --git a/java/java.go b/java/java.go
index 46ef98b..d5375a5 100644
--- a/java/java.go
+++ b/java/java.go
@@ -264,9 +264,6 @@
}
type CompilerDeviceProperties struct {
- // list of module-specific flags that will be used for dex compiles
- Dxflags []string `android:"arch_variant"`
-
// if not blank, set to the version of the sdk to compile against.
// Defaults to compiling against the current platform.
Sdk_version *string
@@ -312,37 +309,6 @@
}
}
- // If set to true, compile dex regardless of installable. Defaults to false.
- Compile_dex *bool
-
- Optimize struct {
- // If false, disable all optimization. Defaults to true for android_app and android_test
- // modules, false for java_library and java_test modules.
- Enabled *bool
- // True if the module containing this has it set by default.
- EnabledByDefault bool `blueprint:"mutated"`
-
- // If true, optimize for size by removing unused code. Defaults to true for apps,
- // false for libraries and tests.
- Shrink *bool
-
- // If true, optimize bytecode. Defaults to false.
- Optimize *bool
-
- // If true, obfuscate bytecode. Defaults to false.
- Obfuscate *bool
-
- // If true, do not use the flag files generated by aapt that automatically keep
- // classes referenced by the app manifest. Defaults to false.
- No_aapt_flags *bool
-
- // Flags to pass to proguard.
- Proguard_flags []string
-
- // Specifies the locations of files containing proguard flags.
- Proguard_flags_files []string `android:"path"`
- }
-
// When targeting 1.9 and above, override the modules to use with --system,
// otherwise provides defaults libraries to add to the bootclasspath.
System_modules *string
@@ -356,19 +322,9 @@
// set the name of the output
Stem *string
- // Keep the data uncompressed. We always need uncompressed dex for execution,
- // so this might actually save space by avoiding storing the same data twice.
- // This defaults to reasonable value based on module and should not be set.
- // It exists only to support ART tests.
- Uncompress_dex *bool
-
IsSDKLibrary bool `blueprint:"mutated"`
}
-func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool {
- return BoolDefault(me.Optimize.Enabled, me.Optimize.EnabledByDefault)
-}
-
// Functionality common to Module and Import
//
// It is embedded in Module so its functionality can be used by methods in Module
@@ -437,9 +393,6 @@
// output file containing uninstrumented classes that will be instrumented by jacoco
jacocoReportClassesFile android.Path
- // output file containing mapping of obfuscated names
- proguardDictionary android.Path
-
// output file of the module, which may be a classes jar or a dex jar
outputFile android.Path
extraOutputFiles android.Paths
@@ -455,9 +408,6 @@
compiledJavaSrcs android.Paths
compiledSrcJars android.Paths
- // list of extra progurad flag files
- extraProguardFlagFiles android.Paths
-
// manifest file to use instead of properties.Manifest
overrideManifest android.OptionalPath
@@ -484,6 +434,7 @@
extraResources android.Paths
hiddenAPI
+ dexer
dexpreopter
linter
@@ -507,6 +458,7 @@
j.addHostProperties()
j.AddProperties(
&j.deviceProperties,
+ &j.dexer.dexProperties,
&j.dexpreoptProperties,
&j.linter.properties,
)
@@ -519,7 +471,10 @@
case ".jar":
return android.Paths{j.implementationAndResourcesJar}, nil
case ".proguard_map":
- return android.Paths{j.proguardDictionary}, nil
+ if j.dexer.proguardDictionary.Valid() {
+ return android.Paths{j.dexer.proguardDictionary.Path()}, nil
+ }
+ return nil, fmt.Errorf("%q was requested, but no output file was found.", tag)
default:
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
}
@@ -556,7 +511,20 @@
}
func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
- android.InitAndroidArchModule(module, hod, android.MultilibCommon)
+ initJavaModule(module, hod, false)
+}
+
+func InitJavaModuleMultiTargets(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
+ initJavaModule(module, hod, true)
+}
+
+func initJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported, multiTargets bool) {
+ multilib := android.MultilibCommon
+ if multiTargets {
+ android.InitAndroidMultiTargetsArchModule(module, hod, multilib)
+ } else {
+ android.InitAndroidArchModule(module, hod, multilib)
+ }
android.InitDefaultableModule(module)
}
@@ -575,6 +543,7 @@
}
var (
+ dataNativeBinsTag = dependencyTag{name: "dataNativeBins"}
staticLibTag = dependencyTag{name: "staticlib"}
libTag = dependencyTag{name: "javalib"}
java9LibTag = dependencyTag{name: "java9lib"}
@@ -635,10 +604,11 @@
}
type jniLib struct {
- name string
- path android.Path
- target android.Target
- coverageFile android.OptionalPath
+ name string
+ path android.Path
+ target android.Target
+ coverageFile android.OptionalPath
+ unstrippedFile android.Path
}
func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool {
@@ -713,10 +683,10 @@
ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
ctx.AddVariationDependencies(nil, libTag, sdkDep.classpath...)
- if j.deviceProperties.EffectiveOptimizeEnabled() && sdkDep.hasStandardLibs() {
+ if j.effectiveOptimizeEnabled() && sdkDep.hasStandardLibs() {
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.LegacyCorePlatformBootclasspathLibraries...)
}
- if j.deviceProperties.EffectiveOptimizeEnabled() && sdkDep.hasFrameworkLibs() {
+ if j.effectiveOptimizeEnabled() && sdkDep.hasFrameworkLibs() {
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.FrameworkLibraries...)
}
}
@@ -1632,8 +1602,8 @@
// Enable dex compilation for the APEX variants, unless it is disabled explicitly
if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !j.IsForPlatform() {
- if j.deviceProperties.Compile_dex == nil {
- j.deviceProperties.Compile_dex = proptools.BoolPtr(true)
+ if j.dexProperties.Compile_dex == nil {
+ j.dexProperties.Compile_dex = proptools.BoolPtr(true)
}
if j.deviceProperties.Hostdex == nil {
j.deviceProperties.Hostdex = proptools.BoolPtr(true)
@@ -1641,10 +1611,14 @@
}
if ctx.Device() && j.hasCode(ctx) &&
- (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
+ (Bool(j.properties.Installable) || Bool(j.dexProperties.Compile_dex)) {
+ if j.shouldInstrumentStatic(ctx) {
+ j.dexer.extraProguardFlagFiles = append(j.dexer.extraProguardFlagFiles,
+ android.PathForSource(ctx, "build/make/core/proguard.jacoco.flags"))
+ }
// Dex compilation
var dexOutputFile android.ModuleOutPath
- dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
+ dexOutputFile = j.dexer.compileDex(ctx, flags, j.minSdkVersion(), outputFile, jarName)
if ctx.Failed() {
return
}
@@ -1654,7 +1628,7 @@
// Hidden API CSV generation and dex encoding
dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, configurationName, primary, dexOutputFile, j.implementationJarFile,
- proptools.Bool(j.deviceProperties.Uncompress_dex))
+ proptools.Bool(j.dexProperties.Uncompress_dex))
// merge dex jar with resources if necessary
if j.resourceJar != nil {
@@ -1662,7 +1636,7 @@
combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
false, nil, nil)
- if *j.deviceProperties.Uncompress_dex {
+ if *j.dexProperties.Uncompress_dex {
combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
dexOutputFile = combinedAlignedJar
@@ -1706,6 +1680,9 @@
j.linter.compileSdkVersion = lintSDKVersionString(j.sdkVersion())
j.linter.javaLanguageLevel = flags.javaVersion.String()
j.linter.kotlinLanguageLevel = "1.3"
+ if j.ApexName() != "" && ctx.Config().UnbundledBuildApps() {
+ j.linter.buildModuleReportZip = true
+ }
j.linter.lint(ctx)
}
@@ -1990,11 +1967,11 @@
j.checkSdkVersions(ctx)
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
- if j.deviceProperties.Uncompress_dex == nil {
+ if j.dexProperties.Uncompress_dex == nil {
// If the value was not force-set by the user, use reasonable default based on the module.
- j.deviceProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter))
+ j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter))
}
- j.dexpreopter.uncompressedDex = *j.deviceProperties.Uncompress_dex
+ j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
j.compile(ctx, nil)
// Collect the module directory for IDE info in java/jdeps.go.
@@ -2189,6 +2166,11 @@
Test_mainline_modules []string
}
+type hostTestProperties struct {
+ // list of native binary modules that should be installed alongside the test
+ Data_native_bins []string `android:"arch_variant"`
+}
+
type testHelperLibraryProperties struct {
// list of compatibility suites (for example "cts", "vts") that the module should be
// installed into.
@@ -2214,6 +2196,12 @@
data android.Paths
}
+type TestHost struct {
+ Test
+
+ testHostProperties hostTestProperties
+}
+
type TestHelperLibrary struct {
Library
@@ -2228,11 +2216,26 @@
testConfig android.Path
}
+func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) {
+ if len(j.testHostProperties.Data_native_bins) > 0 {
+ for _, target := range ctx.MultiTargets() {
+ ctx.AddVariationDependencies(target.Variations(), dataNativeBinsTag, j.testHostProperties.Data_native_bins...)
+ }
+ }
+
+ j.deps(ctx)
+}
+
func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template,
j.testProperties.Test_suites, j.testProperties.Auto_gen_config)
+
j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data)
+ ctx.VisitDirectDepsWithTag(dataNativeBinsTag, func(dep android.Module) {
+ j.data = append(j.data, android.OutputFileForModule(ctx, dep, ""))
+ })
+
j.Library.GenerateAndroidBuildActions(ctx)
}
@@ -2373,14 +2376,15 @@
// A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were
// compiled against the host bootclasspath.
func TestHostFactory() android.Module {
- module := &Test{}
+ module := &TestHost{}
module.addHostProperties()
module.AddProperties(&module.testProperties)
+ module.AddProperties(&module.testHostProperties)
module.Module.properties.Installable = proptools.BoolPtr(true)
- InitJavaModule(module, android.HostSupported)
+ InitJavaModuleMultiTargets(module, android.HostSupported)
return module
}
@@ -2788,6 +2792,10 @@
return nil
}
+func (a *DexImport) LintDepSets() LintDepSets {
+ return LintDepSets{}
+}
+
func (j *DexImport) IsInstallable() bool {
return true
}
@@ -2921,6 +2929,7 @@
module.AddProperties(
&CompilerProperties{},
&CompilerDeviceProperties{},
+ &DexProperties{},
&DexpreoptProperties{},
&android.ProtoProperties{},
&aaptProperties{},
diff --git a/java/java_test.go b/java/java_test.go
index fb00361..50c40c3 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -31,6 +31,7 @@
"android/soong/cc"
"android/soong/dexpreopt"
"android/soong/genrule"
+ "android/soong/python"
)
var buildDir string
@@ -81,6 +82,7 @@
ctx.RegisterModuleType("java_plugin", PluginFactory)
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
+ ctx.RegisterModuleType("python_binary_host", python.PythonBinaryHostFactory)
RegisterDocsBuildComponents(ctx)
RegisterStubsBuildComponents(ctx)
RegisterSdkLibraryBuildComponents(ctx)
@@ -89,10 +91,13 @@
RegisterPrebuiltApisBuildComponents(ctx)
+ ctx.PreDepsMutators(python.RegisterPythonPreDepsMutators)
ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
ctx.RegisterPreSingletonType("overlay", android.SingletonFactoryAdaptor(OverlaySingletonFactory))
ctx.RegisterPreSingletonType("sdk_versions", android.SingletonFactoryAdaptor(sdkPreSingletonFactory))
+ android.RegisterPrebuiltMutators(ctx)
+
// Register module types and mutators from cc needed for JNI testing
cc.RegisterRequiredBuildComponentsForTest(ctx)
@@ -486,7 +491,7 @@
ctx, _ := testJavaWithConfig(t, config)
- // first, sanity check that the -g flag is added to target modules
+ // first, check that the -g flag is added to target modules
targetLibrary := ctx.ModuleForTests("target_library", "android_common")
targetJavaFlags := targetLibrary.Module().VariablesForTests()["javacFlags"]
if !strings.Contains(targetJavaFlags, "-g:source,lines") {
@@ -1097,15 +1102,20 @@
],
proofread_file: "libcore-proofread.txt",
todo_file: "libcore-docs-todo.html",
- args: "-offlinemode -title \"libcore\"",
+ flags: ["-offlinemode -title \"libcore\""],
}
`,
map[string][]byte{
"bar-doc/a.java": nil,
"bar-doc/b.java": nil,
})
+ barDocModule := ctx.ModuleForTests("bar-doc", "android_common")
+ barDoc := barDocModule.Rule("javadoc")
+ notExpected := " -stubs "
+ if strings.Contains(barDoc.RuleParams.Command, notExpected) {
+ t.Errorf("bar-doc command contains flag %q to create stubs, but should not", notExpected)
+ }
- barDoc := ctx.ModuleForTests("bar-doc", "android_common").Rule("javadoc")
var javaSrcs []string
for _, i := range barDoc.Inputs {
javaSrcs = append(javaSrcs, i.Base())
@@ -1114,7 +1124,7 @@
t.Errorf("inputs of bar-doc must be []string{\"a.java\"}, but was %#v.", javaSrcs)
}
- aidl := ctx.ModuleForTests("bar-doc", "android_common").Rule("aidl")
+ aidl := barDocModule.Rule("aidl")
if g, w := barDoc.Implicits.Strings(), aidl.Output.String(); !inList(w, g) {
t.Errorf("implicits of bar-doc must contain %q, but was %q.", w, g)
}
@@ -1124,6 +1134,98 @@
}
}
+func TestDroiddocArgsAndFlagsCausesError(t *testing.T) {
+ testJavaError(t, "flags is set. Cannot set args", `
+ droiddoc_exported_dir {
+ name: "droiddoc-templates-sdk",
+ path: ".",
+ }
+ filegroup {
+ name: "bar-doc-aidl-srcs",
+ srcs: ["bar-doc/IBar.aidl"],
+ path: "bar-doc",
+ }
+ droiddoc {
+ name: "bar-doc",
+ srcs: [
+ "bar-doc/a.java",
+ "bar-doc/IFoo.aidl",
+ ":bar-doc-aidl-srcs",
+ ],
+ exclude_srcs: [
+ "bar-doc/b.java"
+ ],
+ custom_template: "droiddoc-templates-sdk",
+ hdf: [
+ "android.whichdoc offline",
+ ],
+ knowntags: [
+ "bar-doc/known_oj_tags.txt",
+ ],
+ proofread_file: "libcore-proofread.txt",
+ todo_file: "libcore-docs-todo.html",
+ flags: ["-offlinemode -title \"libcore\""],
+ args: "-offlinemode -title \"libcore\"",
+ }
+ `)
+}
+
+func TestDroidstubs(t *testing.T) {
+ ctx, _ := testJavaWithFS(t, `
+ droiddoc_exported_dir {
+ name: "droiddoc-templates-sdk",
+ path: ".",
+ }
+
+ droidstubs {
+ name: "bar-stubs",
+ srcs: [
+ "bar-doc/a.java",
+ ],
+ api_levels_annotations_dirs: [
+ "droiddoc-templates-sdk",
+ ],
+ api_levels_annotations_enabled: true,
+ }
+
+ droidstubs {
+ name: "bar-stubs-other",
+ srcs: [
+ "bar-doc/a.java",
+ ],
+ api_levels_annotations_dirs: [
+ "droiddoc-templates-sdk",
+ ],
+ api_levels_annotations_enabled: true,
+ api_levels_jar_filename: "android.other.jar",
+ }
+ `,
+ map[string][]byte{
+ "bar-doc/a.java": nil,
+ })
+ testcases := []struct {
+ moduleName string
+ expectedJarFilename string
+ }{
+ {
+ moduleName: "bar-stubs",
+ expectedJarFilename: "android.jar",
+ },
+ {
+ moduleName: "bar-stubs-other",
+ expectedJarFilename: "android.other.jar",
+ },
+ }
+ for _, c := range testcases {
+ m := ctx.ModuleForTests(c.moduleName, "android_common")
+ metalava := m.Rule("metalava")
+ expected := "--android-jar-pattern ./%/public/" + c.expectedJarFilename
+ if actual := metalava.RuleParams.Command; !strings.Contains(actual, expected) {
+ t.Errorf("For %q, expected metalava argument %q, but was not found %q", c.moduleName, expected, actual)
+ }
+ }
+}
+
func TestDroidstubsWithSystemModules(t *testing.T) {
ctx, _ := testJava(t, `
droidstubs {
@@ -1972,3 +2074,28 @@
t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
}
}
+
+func TestDataNativeBinaries(t *testing.T) {
+ ctx, config := testJava(t, `
+ java_test_host {
+ name: "foo",
+ srcs: ["a.java"],
+ data_native_bins: ["bin"]
+ }
+
+ python_binary_host {
+ name: "bin",
+ srcs: ["bin.py"],
+ }
+ `)
+
+ buildOS := android.BuildOs.String()
+
+ test := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost)
+ entries := android.AndroidMkEntriesForTest(t, config, "", test)[0]
+ expected := []string{buildDir + "/.intermediates/bin/" + buildOS + "_x86_64_PY3/bin:bin"}
+ actual := entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"]
+ if !reflect.DeepEqual(expected, actual) {
+ t.Errorf("Unexpected test data - expected: %q, actual: %q", expected, actual)
+ }
+}
diff --git a/java/legacy_core_platform_api_usage.go b/java/legacy_core_platform_api_usage.go
new file mode 100644
index 0000000..8af66d0
--- /dev/null
+++ b/java/legacy_core_platform_api_usage.go
@@ -0,0 +1,162 @@
+// Copyright 2020 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package java
+
+import (
+ "android/soong/android"
+ "android/soong/java/config"
+)
+
+var legacyCorePlatformApiModules = []string{
+ "ahat-test-dump",
+ "android.car",
+ "android.test.mock",
+ "android.test.mock.impl",
+ "AoapTestDeviceApp",
+ "AoapTestHostApp",
+ "api-stubs-docs",
+ "art_cts_jvmti_test_library",
+ "art-gtest-jars-MyClassNatives",
+ "BackupFrameworksServicesRoboTests",
+ "BandwidthEnforcementTest",
+ "BlockedNumberProvider",
+ "BluetoothInstrumentationTests",
+ "BluetoothMidiService",
+ "car-apps-common",
+ "CertInstaller",
+ "ConnectivityManagerTest",
+ "ContactsProvider",
+ "core-tests-support",
+ "CtsContentTestCases",
+ "CtsIkeTestCases",
+ "CtsLibcoreWycheproofBCTestCases",
+ "CtsMediaTestCases",
+ "CtsNetTestCases",
+ "CtsNetTestCasesLatestSdk",
+ "CtsSecurityTestCases",
+ "CtsUsageStatsTestCases",
+ "DisplayCutoutEmulationEmu01Overlay",
+ "DocumentsUIPerfTests",
+ "DocumentsUITests",
+ "DownloadProvider",
+ "DownloadProviderTests",
+ "DownloadProviderUi",
+ "DynamicSystemInstallationService",
+ "EmergencyInfo-lib",
+ "ethernet-service",
+ "EthernetServiceTests",
+ "ExternalStorageProvider",
+ "ExtServices",
+ "ExtServices-core",
+ "framework-all",
+ "framework-minus-apex",
+ "FrameworksCoreTests",
+ "FrameworksIkeTests",
+ "FrameworksNetCommonTests",
+ "FrameworksNetTests",
+ "FrameworksServicesRoboTests",
+ "FrameworksServicesTests",
+ "FrameworksUtilTests",
+ "hid",
+ "hidl_test_java_java",
+ "hwbinder",
+ "ims",
+ "KeyChain",
+ "ksoap2",
+ "LocalTransport",
+ "lockagent",
+ "mediaframeworktest",
+ "MediaProvider",
+ "MmsService",
+ "MtpDocumentsProvider",
+ "MultiDisplayProvider",
+ "NetworkStackIntegrationTestsLib",
+ "NetworkStackNextIntegrationTests",
+ "NetworkStackNextTests",
+ "NetworkStackTests",
+ "NetworkStackTestsLib",
+ "NfcNci",
+ "platform_library-docs",
+ "PrintSpooler",
+ "RollbackTest",
+ "services",
+ "services.accessibility",
+ "services.backup",
+ "services.core.unboosted",
+ "services.devicepolicy",
+ "services.print",
+ "services.usage",
+ "services.usb",
+ "Settings-core",
+ "SettingsLib",
+ "SettingsProvider",
+ "SettingsProviderTest",
+ "SettingsRoboTests",
+ "Shell",
+ "ShellTests",
+ "sl4a.Common",
+ "StatementService",
+ "SystemUI-core",
+ "SystemUISharedLib",
+ "SystemUI-tests",
+ "Telecom",
+ "TelecomUnitTests",
+ "telephony-common",
+ "TelephonyProvider",
+ "TelephonyProviderTests",
+ "TeleService",
+ "testables",
+ "TetheringTests",
+ "TetheringTestsLib",
+ "time_zone_distro_installer",
+ "time_zone_distro_installer-tests",
+ "time_zone_distro-tests",
+ "time_zone_updater",
+ "TvProvider",
+ "uiautomator-stubs-docs",
+ "UsbHostExternalManagementTestApp",
+ "UserDictionaryProvider",
+ "WallpaperBackup",
+ "wifi-service",
+}
+
+var legacyCorePlatformApiLookup = make(map[string]struct{})
+
+func init() {
+ for _, module := range legacyCorePlatformApiModules {
+ legacyCorePlatformApiLookup[module] = struct{}{}
+ }
+}
+
+func useLegacyCorePlatformApi(ctx android.EarlyModuleContext) bool {
+ _, found := legacyCorePlatformApiLookup[ctx.ModuleName()]
+ return found
+}
+
+func corePlatformSystemModules(ctx android.EarlyModuleContext) string {
+ if useLegacyCorePlatformApi(ctx) {
+ return config.LegacyCorePlatformSystemModules
+ } else {
+ return config.StableCorePlatformSystemModules
+ }
+}
+
+func corePlatformBootclasspathLibraries(ctx android.EarlyModuleContext) []string {
+ if useLegacyCorePlatformApi(ctx) {
+ return config.LegacyCorePlatformBootclasspathLibraries
+ } else {
+ return config.StableCorePlatformBootclasspathLibraries
+ }
+}
diff --git a/java/lint.go b/java/lint.go
index b73d6a5..1bf7f69 100644
--- a/java/lint.go
+++ b/java/lint.go
@@ -17,6 +17,7 @@
import (
"fmt"
"sort"
+ "strings"
"android/soong/android"
)
@@ -67,12 +68,82 @@
kotlinLanguageLevel string
outputs lintOutputs
properties LintProperties
+
+ reports android.Paths
+
+ buildModuleReportZip bool
}
type lintOutputs struct {
- html android.ModuleOutPath
- text android.ModuleOutPath
- xml android.ModuleOutPath
+ html android.Path
+ text android.Path
+ xml android.Path
+
+ depSets LintDepSets
+}
+
+type lintOutputsIntf interface {
+ lintOutputs() *lintOutputs
+}
+
+type lintDepSetsIntf interface {
+ LintDepSets() LintDepSets
+}
+
+type LintDepSets struct {
+ HTML, Text, XML *android.DepSet
+}
+
+type LintDepSetsBuilder struct {
+ HTML, Text, XML *android.DepSetBuilder
+}
+
+func NewLintDepSetBuilder() LintDepSetsBuilder {
+ return LintDepSetsBuilder{
+ HTML: android.NewDepSetBuilder(android.POSTORDER),
+ Text: android.NewDepSetBuilder(android.POSTORDER),
+ XML: android.NewDepSetBuilder(android.POSTORDER),
+ }
+}
+
+func (l LintDepSetsBuilder) Direct(html, text, xml android.Path) LintDepSetsBuilder {
+ l.HTML.Direct(html)
+ l.Text.Direct(text)
+ l.XML.Direct(xml)
+ return l
+}
+
+func (l LintDepSetsBuilder) Transitive(depSets LintDepSets) LintDepSetsBuilder {
+ if depSets.HTML != nil {
+ l.HTML.Transitive(depSets.HTML)
+ }
+ if depSets.Text != nil {
+ l.Text.Transitive(depSets.Text)
+ }
+ if depSets.XML != nil {
+ l.XML.Transitive(depSets.XML)
+ }
+ return l
+}
+
+func (l LintDepSetsBuilder) Build() LintDepSets {
+ return LintDepSets{
+ HTML: l.HTML.Build(),
+ Text: l.Text.Build(),
+ XML: l.XML.Build(),
+ }
+}
+
+func (l *linter) LintDepSets() LintDepSets {
+ return l.outputs.depSets
+}
+
+var _ lintDepSetsIntf = (*linter)(nil)
+
+var _ lintOutputsIntf = (*linter)(nil)
+
+func (l *linter) lintOutputs() *lintOutputs {
+ return &l.outputs
}
func (l *linter) enabled() bool {
@@ -84,7 +155,16 @@
return
}
- ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), extraLintCheckTag, l.properties.Lint.Extra_check_modules...)
+ extraCheckModules := l.properties.Lint.Extra_check_modules
+
+ if checkOnly := ctx.Config().Getenv("ANDROID_LINT_CHECK"); checkOnly != "" {
+ if checkOnlyModules := ctx.Config().Getenv("ANDROID_LINT_CHECK_EXTRA_MODULES"); checkOnlyModules != "" {
+ extraCheckModules = strings.Split(checkOnlyModules, ",")
+ }
+ }
+
+ ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(),
+ extraLintCheckTag, extraCheckModules...)
}
func (l *linter) writeLintProjectXML(ctx android.ModuleContext,
@@ -172,7 +252,7 @@
return projectXMLPath, configXMLPath, cacheDir, homeDir, deps
}
-// generateManifest adds a command to the rule to write a dummy manifest cat contains the
+// generateManifest adds a command to the rule to write a simple manifest that contains the
// minSdkVersion and targetSdkVersion for modules (like java_library) that don't have a manifest.
func (l *linter) generateManifest(ctx android.ModuleContext, rule *android.RuleBuilder) android.Path {
manifestPath := android.PathForModuleOut(ctx, "lint", "AndroidManifest.xml")
@@ -213,51 +293,95 @@
projectXML, lintXML, cacheDir, homeDir, deps := l.writeLintProjectXML(ctx, rule)
- l.outputs.html = android.PathForModuleOut(ctx, "lint-report.html")
- l.outputs.text = android.PathForModuleOut(ctx, "lint-report.txt")
- l.outputs.xml = android.PathForModuleOut(ctx, "lint-report.xml")
+ html := android.PathForModuleOut(ctx, "lint-report.html")
+ text := android.PathForModuleOut(ctx, "lint-report.txt")
+ xml := android.PathForModuleOut(ctx, "lint-report.xml")
+
+ depSetsBuilder := NewLintDepSetBuilder().Direct(html, text, xml)
+
+ ctx.VisitDirectDepsWithTag(staticLibTag, func(dep android.Module) {
+ if depLint, ok := dep.(lintDepSetsIntf); ok {
+ depSetsBuilder.Transitive(depLint.LintDepSets())
+ }
+ })
rule.Command().Text("rm -rf").Flag(cacheDir.String()).Flag(homeDir.String())
rule.Command().Text("mkdir -p").Flag(cacheDir.String()).Flag(homeDir.String())
- rule.Command().
+ var annotationsZipPath, apiVersionsXMLPath android.Path
+ if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
+ annotationsZipPath = android.PathForSource(ctx, "prebuilts/sdk/current/public/data/annotations.zip")
+ apiVersionsXMLPath = android.PathForSource(ctx, "prebuilts/sdk/current/public/data/api-versions.xml")
+ } else {
+ annotationsZipPath = copiedAnnotationsZipPath(ctx)
+ apiVersionsXMLPath = copiedAPIVersionsXmlPath(ctx)
+ }
+
+ cmd := rule.Command().
Text("(").
Flag("JAVA_OPTS=-Xmx2048m").
FlagWithArg("ANDROID_SDK_HOME=", homeDir.String()).
- FlagWithInput("SDK_ANNOTATIONS=", annotationsZipPath(ctx)).
- FlagWithInput("LINT_OPTS=-DLINT_API_DATABASE=", apiVersionsXmlPath(ctx)).
+ FlagWithInput("SDK_ANNOTATIONS=", annotationsZipPath).
+ FlagWithInput("LINT_OPTS=-DLINT_API_DATABASE=", apiVersionsXMLPath).
Tool(android.PathForSource(ctx, "prebuilts/cmdline-tools/tools/bin/lint")).
Implicit(android.PathForSource(ctx, "prebuilts/cmdline-tools/tools/lib/lint-classpath.jar")).
Flag("--quiet").
FlagWithInput("--project ", projectXML).
FlagWithInput("--config ", lintXML).
- FlagWithOutput("--html ", l.outputs.html).
- FlagWithOutput("--text ", l.outputs.text).
- FlagWithOutput("--xml ", l.outputs.xml).
+ FlagWithOutput("--html ", html).
+ FlagWithOutput("--text ", text).
+ FlagWithOutput("--xml ", xml).
FlagWithArg("--compile-sdk-version ", l.compileSdkVersion).
FlagWithArg("--java-language-level ", l.javaLanguageLevel).
FlagWithArg("--kotlin-language-level ", l.kotlinLanguageLevel).
FlagWithArg("--url ", fmt.Sprintf(".=.,%s=out", android.PathForOutput(ctx).String())).
Flag("--exitcode").
Flags(l.properties.Lint.Flags).
- Implicits(deps).
- Text("|| (").Text("cat").Input(l.outputs.text).Text("; exit 7)").
- Text(")")
+ Implicits(deps)
+
+ if checkOnly := ctx.Config().Getenv("ANDROID_LINT_CHECK"); checkOnly != "" {
+ cmd.FlagWithArg("--check ", checkOnly)
+ }
+
+ cmd.Text("|| (").Text("cat").Input(text).Text("; exit 7)").Text(")")
rule.Command().Text("rm -rf").Flag(cacheDir.String()).Flag(homeDir.String())
rule.Build(pctx, ctx, "lint", "lint")
+
+ l.outputs = lintOutputs{
+ html: html,
+ text: text,
+ xml: xml,
+
+ depSets: depSetsBuilder.Build(),
+ }
+
+ if l.buildModuleReportZip {
+ l.reports = BuildModuleLintReportZips(ctx, l.LintDepSets())
+ }
}
-func (l *linter) lintOutputs() *lintOutputs {
- return &l.outputs
-}
+func BuildModuleLintReportZips(ctx android.ModuleContext, depSets LintDepSets) android.Paths {
+ htmlList := depSets.HTML.ToSortedList()
+ textList := depSets.Text.ToSortedList()
+ xmlList := depSets.XML.ToSortedList()
-type lintOutputIntf interface {
- lintOutputs() *lintOutputs
-}
+ if len(htmlList) == 0 && len(textList) == 0 && len(xmlList) == 0 {
+ return nil
+ }
-var _ lintOutputIntf = (*linter)(nil)
+ htmlZip := android.PathForModuleOut(ctx, "lint-report-html.zip")
+ lintZip(ctx, htmlList, htmlZip)
+
+ textZip := android.PathForModuleOut(ctx, "lint-report-text.zip")
+ lintZip(ctx, textList, textZip)
+
+ xmlZip := android.PathForModuleOut(ctx, "lint-report-xml.zip")
+ lintZip(ctx, xmlList, xmlZip)
+
+ return android.Paths{htmlZip, textZip, xmlZip}
+}
type lintSingleton struct {
htmlZip android.WritablePath
@@ -271,7 +395,7 @@
}
func (l *lintSingleton) copyLintDependencies(ctx android.SingletonContext) {
- if ctx.Config().UnbundledBuild() {
+ if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
return
}
@@ -297,25 +421,29 @@
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Input: android.OutputFileForModule(ctx, frameworkDocStubs, ".annotations.zip"),
- Output: annotationsZipPath(ctx),
+ Output: copiedAnnotationsZipPath(ctx),
})
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Input: android.OutputFileForModule(ctx, frameworkDocStubs, ".api_versions.xml"),
- Output: apiVersionsXmlPath(ctx),
+ Output: copiedAPIVersionsXmlPath(ctx),
})
}
-func annotationsZipPath(ctx android.PathContext) android.WritablePath {
+func copiedAnnotationsZipPath(ctx android.PathContext) android.WritablePath {
return android.PathForOutput(ctx, "lint", "annotations.zip")
}
-func apiVersionsXmlPath(ctx android.PathContext) android.WritablePath {
+func copiedAPIVersionsXmlPath(ctx android.PathContext) android.WritablePath {
return android.PathForOutput(ctx, "lint", "api_versions.xml")
}
func (l *lintSingleton) generateLintReportZips(ctx android.SingletonContext) {
+ if ctx.Config().UnbundledBuild() {
+ return
+ }
+
var outputs []*lintOutputs
var dirs []string
ctx.VisitAllModules(func(m android.Module) {
@@ -329,7 +457,7 @@
return
}
- if l, ok := m.(lintOutputIntf); ok {
+ if l, ok := m.(lintOutputsIntf); ok {
outputs = append(outputs, l.lintOutputs())
}
})
@@ -340,21 +468,12 @@
var paths android.Paths
for _, output := range outputs {
- paths = append(paths, get(output))
+ if p := get(output); p != nil {
+ paths = append(paths, p)
+ }
}
- sort.Slice(paths, func(i, j int) bool {
- return paths[i].String() < paths[j].String()
- })
-
- rule := android.NewRuleBuilder()
-
- rule.Command().BuiltTool(ctx, "soong_zip").
- FlagWithOutput("-o ", outputPath).
- FlagWithArg("-C ", android.PathForIntermediates(ctx).String()).
- FlagWithRspFileInputList("-l ", paths)
-
- rule.Build(pctx, ctx, outputPath.Base(), outputPath.Base())
+ lintZip(ctx, paths, outputPath)
}
l.htmlZip = android.PathForOutput(ctx, "lint-report-html.zip")
@@ -370,7 +489,9 @@
}
func (l *lintSingleton) MakeVars(ctx android.MakeVarsContext) {
- ctx.DistForGoal("lint-check", l.htmlZip, l.textZip, l.xmlZip)
+ if !ctx.Config().UnbundledBuild() {
+ ctx.DistForGoal("lint-check", l.htmlZip, l.textZip, l.xmlZip)
+ }
}
var _ android.SingletonMakeVarsProvider = (*lintSingleton)(nil)
@@ -379,3 +500,20 @@
android.RegisterSingletonType("lint",
func() android.Singleton { return &lintSingleton{} })
}
+
+func lintZip(ctx android.BuilderContext, paths android.Paths, outputPath android.WritablePath) {
+ paths = android.SortedUniquePaths(android.CopyOfPaths(paths))
+
+ sort.Slice(paths, func(i, j int) bool {
+ return paths[i].String() < paths[j].String()
+ })
+
+ rule := android.NewRuleBuilder()
+
+ rule.Command().BuiltTool(ctx, "soong_zip").
+ FlagWithOutput("-o ", outputPath).
+ FlagWithArg("-C ", android.PathForIntermediates(ctx).String()).
+ FlagWithRspFileInputList("-l ", paths)
+
+ rule.Build(pctx, ctx, outputPath.Base(), outputPath.Base())
+}
diff --git a/java/prebuilt_apis.go b/java/prebuilt_apis.go
index 999c72f..b10e6c7 100644
--- a/java/prebuilt_apis.go
+++ b/java/prebuilt_apis.go
@@ -83,8 +83,7 @@
}{}
props.Name = proptools.StringPtr(prebuiltApiModuleName(mctx, module, scope, apiver))
props.Jars = append(props.Jars, path)
- // TODO(hansson): change to scope after migration is done.
- props.Sdk_version = proptools.StringPtr("current")
+ props.Sdk_version = proptools.StringPtr(scope)
props.Installable = proptools.BoolPtr(false)
mctx.CreateModule(ImportFactory, &props)
diff --git a/java/robolectric.go b/java/robolectric.go
index c6b07a1..4d68fd9 100644
--- a/java/robolectric.go
+++ b/java/robolectric.go
@@ -21,10 +21,13 @@
"strings"
"android/soong/android"
+ "android/soong/java/config"
+ "android/soong/tradefed"
)
func init() {
android.RegisterModuleType("android_robolectric_test", RobolectricTestFactory)
+ android.RegisterModuleType("android_robolectric_runtimes", robolectricRuntimesFactory)
}
var robolectricDefaultLibs = []string{
@@ -32,10 +35,13 @@
"Robolectric_all-target",
"mockito-robolectric-prebuilt",
"truth-prebuilt",
+ // TODO(ccross): this is not needed at link time
+ "junitxml",
}
var (
- roboCoverageLibsTag = dependencyTag{name: "roboSrcs"}
+ roboCoverageLibsTag = dependencyTag{name: "roboCoverageLibs"}
+ roboRuntimesTag = dependencyTag{name: "roboRuntimes"}
)
type robolectricProperties struct {
@@ -58,13 +64,28 @@
Library
robolectricProperties robolectricProperties
+ testProperties testProperties
libs []string
tests []string
+ manifest android.Path
+ resourceApk android.Path
+
+ combinedJar android.WritablePath
+
roboSrcJar android.Path
+
+ testConfig android.Path
+ data android.Paths
}
+func (r *robolectricTest) TestSuites() []string {
+ return r.testProperties.Test_suites
+}
+
+var _ android.TestSuiteModule = (*robolectricTest)(nil)
+
func (r *robolectricTest) DepsMutator(ctx android.BottomUpMutatorContext) {
r.Library.DepsMutator(ctx)
@@ -77,9 +98,16 @@
ctx.AddVariationDependencies(nil, libTag, robolectricDefaultLibs...)
ctx.AddVariationDependencies(nil, roboCoverageLibsTag, r.robolectricProperties.Coverage_libs...)
+
+ ctx.AddVariationDependencies(nil, roboRuntimesTag, "robolectric-android-all-prebuilts")
}
func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ r.testConfig = tradefed.AutoGenRobolectricTestConfig(ctx, r.testProperties.Test_config,
+ r.testProperties.Test_config_template, r.testProperties.Test_suites,
+ r.testProperties.Auto_gen_config)
+ r.data = android.PathsForModuleSrc(ctx, r.testProperties.Data)
+
roboTestConfig := android.PathForModuleGen(ctx, "robolectric").
Join(ctx, "com/android/tools/test_config.properties")
@@ -95,6 +123,9 @@
ctx.PropertyErrorf("instrumentation_for", "dependency must be an android_app")
}
+ r.manifest = instrumentedApp.mergedManifestFile
+ r.resourceApk = instrumentedApp.outputFile
+
generateRoboTestConfig(ctx, roboTestConfig, instrumentedApp)
r.extraResources = android.Paths{roboTestConfig}
@@ -104,10 +135,30 @@
r.generateRoboSrcJar(ctx, roboSrcJar, instrumentedApp)
r.roboSrcJar = roboSrcJar
- for _, dep := range ctx.GetDirectDepsWithTag(libTag) {
- r.libs = append(r.libs, dep.(Dependency).BaseModuleName())
+ roboTestConfigJar := android.PathForModuleOut(ctx, "robolectric_samedir", "samedir_config.jar")
+ generateSameDirRoboTestConfigJar(ctx, roboTestConfigJar)
+
+ combinedJarJars := android.Paths{
+ // roboTestConfigJar comes first so that its com/android/tools/test_config.properties
+ // overrides the one from r.extraResources. The r.extraResources one can be removed
+ // once the Make test runner is removed.
+ roboTestConfigJar,
+ r.outputFile,
+ instrumentedApp.implementationAndResourcesJar,
}
+ for _, dep := range ctx.GetDirectDepsWithTag(libTag) {
+ m := dep.(Dependency)
+ r.libs = append(r.libs, m.BaseModuleName())
+ if !android.InList(m.BaseModuleName(), config.FrameworkLibraries) {
+ combinedJarJars = append(combinedJarJars, m.ImplementationAndResourcesJars()...)
+ }
+ }
+
+ r.combinedJar = android.PathForModuleOut(ctx, "robolectric_combined", r.outputFile.Base())
+ TransformJarsToJar(ctx, r.combinedJar, "combine jars", combinedJarJars, android.OptionalPath{},
+ false, nil, nil)
+
// TODO: this could all be removed if tradefed was used as the test runner, it will find everything
// annotated as a test and run it.
for _, src := range r.compiledJavaSrcs {
@@ -121,14 +172,38 @@
}
r.tests = append(r.tests, s)
}
+
+ r.data = append(r.data, r.manifest, r.resourceApk)
+
+ runtimes := ctx.GetDirectDepWithTag("robolectric-android-all-prebuilts", roboRuntimesTag)
+
+ installPath := android.PathForModuleInstall(ctx, r.BaseModuleName())
+
+ installedResourceApk := ctx.InstallFile(installPath, ctx.ModuleName()+".apk", r.resourceApk)
+ installedManifest := ctx.InstallFile(installPath, ctx.ModuleName()+"-AndroidManifest.xml", r.manifest)
+ installedConfig := ctx.InstallFile(installPath, ctx.ModuleName()+".config", r.testConfig)
+
+ var installDeps android.Paths
+ for _, runtime := range runtimes.(*robolectricRuntimes).runtimes {
+ installDeps = append(installDeps, runtime)
+ }
+ installDeps = append(installDeps, installedResourceApk, installedManifest, installedConfig)
+
+ for _, data := range android.PathsForModuleSrc(ctx, r.testProperties.Data) {
+ installedData := ctx.InstallFile(installPath, data.Rel(), data)
+ installDeps = append(installDeps, installedData)
+ }
+
+ ctx.InstallFile(installPath, ctx.ModuleName()+".jar", r.combinedJar, installDeps...)
}
-func generateRoboTestConfig(ctx android.ModuleContext, outputFile android.WritablePath, instrumentedApp *AndroidApp) {
+func generateRoboTestConfig(ctx android.ModuleContext, outputFile android.WritablePath,
+ instrumentedApp *AndroidApp) {
+ rule := android.NewRuleBuilder()
+
manifest := instrumentedApp.mergedManifestFile
resourceApk := instrumentedApp.outputFile
- rule := android.NewRuleBuilder()
-
rule.Command().Text("rm -f").Output(outputFile)
rule.Command().
Textf(`echo "android_merged_manifest=%s" >>`, manifest.String()).Output(outputFile).Text("&&").
@@ -141,6 +216,28 @@
rule.Build(pctx, ctx, "generate_test_config", "generate test_config.properties")
}
+func generateSameDirRoboTestConfigJar(ctx android.ModuleContext, outputFile android.ModuleOutPath) {
+ rule := android.NewRuleBuilder()
+
+ outputDir := outputFile.InSameDir(ctx)
+ configFile := outputDir.Join(ctx, "com/android/tools/test_config.properties")
+ rule.Temporary(configFile)
+ rule.Command().Text("rm -f").Output(outputFile).Output(configFile)
+ rule.Command().Textf("mkdir -p $(dirname %s)", configFile.String())
+ rule.Command().
+ Text("(").
+ Textf(`echo "android_merged_manifest=%s-AndroidManifest.xml" &&`, ctx.ModuleName()).
+ Textf(`echo "android_resource_apk=%s.apk"`, ctx.ModuleName()).
+ Text(") >>").Output(configFile)
+ rule.Command().
+ BuiltTool(ctx, "soong_zip").
+ FlagWithArg("-C ", outputDir.String()).
+ FlagWithInput("-f ", configFile).
+ FlagWithOutput("-o ", outputFile)
+
+ rule.Build(pctx, ctx, "generate_test_config_samedir", "generate test_config.properties")
+}
+
func (r *robolectricTest) generateRoboSrcJar(ctx android.ModuleContext, outputFile android.WritablePath,
instrumentedApp *AndroidApp) {
@@ -202,7 +299,6 @@
fmt.Fprintln(w, "LOCAL_ROBOTEST_TIMEOUT :=", *t)
}
fmt.Fprintln(w, "-include external/robolectric-shadows/run_robotests.mk")
-
}
// An android_robolectric_test module compiles tests against the Robolectric framework that can run on the local host
@@ -218,11 +314,74 @@
module.addHostProperties()
module.AddProperties(
&module.Module.deviceProperties,
- &module.robolectricProperties)
+ &module.robolectricProperties,
+ &module.testProperties)
module.Module.dexpreopter.isTest = true
module.Module.linter.test = true
+ module.testProperties.Test_suites = []string{"robolectric-tests"}
+
InitJavaModule(module, android.DeviceSupported)
return module
}
+
+func (r *robolectricTest) InstallBypassMake() bool { return true }
+func (r *robolectricTest) InstallInTestcases() bool { return true }
+func (r *robolectricTest) InstallForceOS() *android.OsType { return &android.BuildOs }
+
+func robolectricRuntimesFactory() android.Module {
+ module := &robolectricRuntimes{}
+ module.AddProperties(&module.props)
+ android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
+ return module
+}
+
+type robolectricRuntimesProperties struct {
+ Jars []string `android:"path"`
+ Lib *string
+}
+
+type robolectricRuntimes struct {
+ android.ModuleBase
+
+ props robolectricRuntimesProperties
+
+ runtimes []android.InstallPath
+}
+
+func (r *robolectricRuntimes) TestSuites() []string {
+ return []string{"robolectric-tests"}
+}
+
+var _ android.TestSuiteModule = (*robolectricRuntimes)(nil)
+
+func (r *robolectricRuntimes) DepsMutator(ctx android.BottomUpMutatorContext) {
+ if !ctx.Config().UnbundledBuildUsePrebuiltSdks() && r.props.Lib != nil {
+ ctx.AddVariationDependencies(nil, libTag, String(r.props.Lib))
+ }
+}
+
+func (r *robolectricRuntimes) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ files := android.PathsForModuleSrc(ctx, r.props.Jars)
+
+ androidAllDir := android.PathForModuleInstall(ctx, "android-all")
+ for _, from := range files {
+ installedRuntime := ctx.InstallFile(androidAllDir, from.Base(), from)
+ r.runtimes = append(r.runtimes, installedRuntime)
+ }
+
+ if !ctx.Config().UnbundledBuildUsePrebuiltSdks() && r.props.Lib != nil {
+ runtimeFromSourceModule := ctx.GetDirectDepWithTag(String(r.props.Lib), libTag)
+ runtimeFromSourceJar := android.OutputFileForModule(ctx, runtimeFromSourceModule, "")
+
+ runtimeName := fmt.Sprintf("android-all-%s-robolectric-r0.jar",
+ ctx.Config().PlatformSdkCodename())
+ installedRuntime := ctx.InstallFile(androidAllDir, runtimeName, runtimeFromSourceJar)
+ r.runtimes = append(r.runtimes, installedRuntime)
+ }
+}
+
+func (r *robolectricRuntimes) InstallBypassMake() bool { return true }
+func (r *robolectricRuntimes) InstallInTestcases() bool { return true }
+func (r *robolectricRuntimes) InstallForceOS() *android.OsType { return &android.BuildOs }
diff --git a/java/sdk.go b/java/sdk.go
index 6564f6d..5d79d1d 100644
--- a/java/sdk.go
+++ b/java/sdk.go
@@ -214,7 +214,7 @@
// "current" can be built from source and be from prebuilt SDK
return ctx.Config().UnbundledBuildUsePrebuiltSdks()
} else if s.version.isNumbered() {
- // sanity check
+ // validation check
if s.kind != sdkPublic && s.kind != sdkSystem && s.kind != sdkTest {
panic(fmt.Errorf("prebuilt SDK is not not available for sdkKind=%q", s.kind))
return false
@@ -413,8 +413,8 @@
case sdkPrivate:
return sdkDep{
useModule: true,
- systemModules: config.LegacyCorePlatformSystemModules,
- bootclasspath: config.LegacyCorePlatformBootclasspathLibraries,
+ systemModules: corePlatformSystemModules(ctx),
+ bootclasspath: corePlatformBootclasspathLibraries(ctx),
classpath: config.FrameworkLibraries,
frameworkResModule: "framework-res",
}
@@ -438,8 +438,8 @@
case sdkCorePlatform:
return sdkDep{
useModule: true,
- systemModules: config.LegacyCorePlatformSystemModules,
- bootclasspath: config.LegacyCorePlatformBootclasspathLibraries,
+ systemModules: corePlatformSystemModules(ctx),
+ bootclasspath: corePlatformBootclasspathLibraries(ctx),
noFrameworksLibs: true,
}
case sdkPublic:
diff --git a/java/sdk_library.go b/java/sdk_library.go
index a5aa328..0379a31 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -126,24 +126,23 @@
// the prebuilt jar.
sdkVersion string
+ // The annotation that identifies this API level, empty for the public API scope.
+ annotation string
+
// Extra arguments to pass to droidstubs for this scope.
- droidstubsArgs []string
-
- // The args that must be passed to droidstubs to generate the stubs source
- // for this scope.
//
- // The stubs source must include the definitions of everything that is in this
- // api scope and all the scopes that this one extends.
- droidstubsArgsForGeneratingStubsSource []string
+ // This is not used directly but is used to construct the droidstubsArgs.
+ extraArgs []string
- // The args that must be passed to droidstubs to generate the API for this scope.
+ // The args that must be passed to droidstubs to generate the API and stubs source
+ // for this scope, constructed dynamically by initApiScope().
//
// The API only includes the additional members that this scope adds over the scope
// that it extends.
- droidstubsArgsForGeneratingApi []string
-
- // True if the stubs source and api can be created by the same metalava invocation.
- createStubsSourceAndApiTogether bool
+ //
+ // The stubs source must include the definitions of everything that is in this
+ // api scope and all the scopes that this one extends.
+ droidstubsArgs []string
// Whether the api scope can be treated as unstable, and should skip compat checks.
unstable bool
@@ -180,21 +179,23 @@
// To get the args needed to generate the stubs source append all the args from
// this scope and all the scopes it extends as each set of args adds additional
// members to the stubs.
- var stubsSourceArgs []string
- for s := scope; s != nil; s = s.extends {
- stubsSourceArgs = append(stubsSourceArgs, s.droidstubsArgs...)
+ var scopeSpecificArgs []string
+ if scope.annotation != "" {
+ scopeSpecificArgs = []string{"--show-annotation", scope.annotation}
}
- scope.droidstubsArgsForGeneratingStubsSource = stubsSourceArgs
+ for s := scope; s != nil; s = s.extends {
+ scopeSpecificArgs = append(scopeSpecificArgs, s.extraArgs...)
- // Currently the args needed to generate the API are the same as the args
- // needed to add additional members.
- apiArgs := scope.droidstubsArgs
- scope.droidstubsArgsForGeneratingApi = apiArgs
+ // Ensure that the generated stubs includes all the API elements from the API scope
+ // that this scope extends.
+ if s != scope && s.annotation != "" {
+ scopeSpecificArgs = append(scopeSpecificArgs, "--show-for-stub-purposes-annotation", s.annotation)
+ }
+ }
- // If the args needed to generate the stubs and API are the same then they
- // can be generated in a single invocation of metalava, otherwise they will
- // need separate invocations.
- scope.createStubsSourceAndApiTogether = reflect.DeepEqual(stubsSourceArgs, apiArgs)
+ // Escape any special characters in the arguments. This is needed because droidstubs
+ // passes these directly to the shell command.
+ scope.droidstubsArgs = proptools.ShellEscapeList(scopeSpecificArgs)
return scope
}
@@ -249,10 +250,10 @@
scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
return &module.sdkLibraryProperties.System
},
- apiFilePrefix: "system-",
- moduleSuffix: ".system",
- sdkVersion: "system_current",
- droidstubsArgs: []string{"-showAnnotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.PRIVILEGED_APPS\\)"},
+ apiFilePrefix: "system-",
+ moduleSuffix: ".system",
+ sdkVersion: "system_current",
+ annotation: "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.PRIVILEGED_APPS)",
})
apiScopeTest = initApiScope(&apiScope{
name: "test",
@@ -261,11 +262,11 @@
scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
return &module.sdkLibraryProperties.Test
},
- apiFilePrefix: "test-",
- moduleSuffix: ".test",
- sdkVersion: "test_current",
- droidstubsArgs: []string{"-showAnnotation android.annotation.TestApi"},
- unstable: true,
+ apiFilePrefix: "test-",
+ moduleSuffix: ".test",
+ sdkVersion: "test_current",
+ annotation: "android.annotation.TestApi",
+ unstable: true,
})
apiScopeModuleLib = initApiScope(&apiScope{
name: "module-lib",
@@ -282,9 +283,7 @@
apiFilePrefix: "module-lib-",
moduleSuffix: ".module_lib",
sdkVersion: "module_current",
- droidstubsArgs: []string{
- "--show-annotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.MODULE_LIBRARIES\\)",
- },
+ annotation: "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.MODULE_LIBRARIES)",
})
apiScopeSystemServer = initApiScope(&apiScope{
name: "system-server",
@@ -301,11 +300,11 @@
apiFilePrefix: "system-server-",
moduleSuffix: ".system_server",
sdkVersion: "system_server_current",
- droidstubsArgs: []string{
- "--show-annotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.SYSTEM_SERVER\\) ",
- "--hide-annotation android.annotation.Hide",
+ annotation: "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.SYSTEM_SERVER)",
+ extraArgs: []string{
+ "--hide-annotation", "android.annotation.Hide",
// com.android.* classes are okay in this interface"
- "--hide InternalClasses",
+ "--hide", "InternalClasses",
},
})
allApiScopes = apiScopes{
@@ -985,16 +984,8 @@
// Add dependencies to the stubs library
ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope))
- // If the stubs source and API cannot be generated together then add an additional dependency on
- // the API module.
- if apiScope.createStubsSourceAndApiTogether {
- // Add a dependency on the stubs source in order to access both stubs source and api information.
- ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.stubsSourceModuleName(apiScope))
- } else {
- // Add separate dependencies on the creators of the stubs source files and the API.
- ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, module.stubsSourceModuleName(apiScope))
- ctx.AddVariationDependencies(nil, apiScope.apiFileTag, module.apiModuleName(apiScope))
- }
+ // Add a dependency on the stubs source in order to access both stubs source and api information.
+ ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.stubsSourceModuleName(apiScope))
}
if module.requiresRuntimeImplementationLibrary() {
@@ -1121,6 +1112,7 @@
&module.properties,
&module.protoProperties,
&module.deviceProperties,
+ &module.dexProperties,
&module.dexpreoptProperties,
&module.linter.properties,
&props,
@@ -1180,8 +1172,8 @@
// We compile the stubs for 1.8 in line with the main android.jar stubs, and potential
// interop with older developer tools that don't support 1.9.
props.Java_version = proptools.StringPtr("1.8")
- if module.deviceProperties.Compile_dex != nil {
- props.Compile_dex = module.deviceProperties.Compile_dex
+ if module.dexProperties.Compile_dex != nil {
+ props.Compile_dex = module.dexProperties.Compile_dex
}
// Dist the class jar artifact for sdk builds.
@@ -1197,7 +1189,7 @@
// Creates a droidstubs module that creates stubs source files from the given full source
// files and also updates and checks the API specification files.
-func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookContext, apiScope *apiScope, name string, createStubSources, createApi bool, scopeSpecificDroidstubsArgs []string) {
+func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookContext, apiScope *apiScope, name string, scopeSpecificDroidstubsArgs []string) {
props := struct {
Name *string
Visibility []string
@@ -1284,64 +1276,57 @@
}
droidstubsArgs = append(droidstubsArgs, android.JoinWithPrefix(disabledWarnings, "--hide "))
- if !createStubSources {
- // Stubs are not required.
- props.Generate_stubs = proptools.BoolPtr(false)
- }
-
// Add in scope specific arguments.
droidstubsArgs = append(droidstubsArgs, scopeSpecificDroidstubsArgs...)
props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
props.Args = proptools.StringPtr(strings.Join(droidstubsArgs, " "))
- if createApi {
- // List of APIs identified from the provided source files are created. They are later
- // compared against to the not-yet-released (a.k.a current) list of APIs and to the
- // last-released (a.k.a numbered) list of API.
- currentApiFileName := apiScope.apiFilePrefix + "current.txt"
- removedApiFileName := apiScope.apiFilePrefix + "removed.txt"
- apiDir := module.getApiDir()
- currentApiFileName = path.Join(apiDir, currentApiFileName)
- removedApiFileName = path.Join(apiDir, removedApiFileName)
+ // List of APIs identified from the provided source files are created. They are later
+ // compared against to the not-yet-released (a.k.a current) list of APIs and to the
+ // last-released (a.k.a numbered) list of API.
+ currentApiFileName := apiScope.apiFilePrefix + "current.txt"
+ removedApiFileName := apiScope.apiFilePrefix + "removed.txt"
+ apiDir := module.getApiDir()
+ currentApiFileName = path.Join(apiDir, currentApiFileName)
+ removedApiFileName = path.Join(apiDir, removedApiFileName)
- // check against the not-yet-release API
- props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
- props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
+ // check against the not-yet-release API
+ props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
+ props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
- if !apiScope.unstable {
- // check against the latest released API
- latestApiFilegroupName := proptools.StringPtr(module.latestApiFilegroupName(apiScope))
- props.Check_api.Last_released.Api_file = latestApiFilegroupName
- props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
- module.latestRemovedApiFilegroupName(apiScope))
- props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
+ if !apiScope.unstable {
+ // check against the latest released API
+ latestApiFilegroupName := proptools.StringPtr(module.latestApiFilegroupName(apiScope))
+ props.Check_api.Last_released.Api_file = latestApiFilegroupName
+ props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
+ module.latestRemovedApiFilegroupName(apiScope))
+ props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
- if proptools.Bool(module.sdkLibraryProperties.Api_lint.Enabled) {
- // Enable api lint.
- props.Check_api.Api_lint.Enabled = proptools.BoolPtr(true)
- props.Check_api.Api_lint.New_since = latestApiFilegroupName
+ if proptools.Bool(module.sdkLibraryProperties.Api_lint.Enabled) {
+ // Enable api lint.
+ props.Check_api.Api_lint.Enabled = proptools.BoolPtr(true)
+ props.Check_api.Api_lint.New_since = latestApiFilegroupName
- // If it exists then pass a lint-baseline.txt through to droidstubs.
- baselinePath := path.Join(apiDir, apiScope.apiFilePrefix+"lint-baseline.txt")
- baselinePathRelativeToRoot := path.Join(mctx.ModuleDir(), baselinePath)
- paths, err := mctx.GlobWithDeps(baselinePathRelativeToRoot, nil)
- if err != nil {
- mctx.ModuleErrorf("error checking for presence of %s: %s", baselinePathRelativeToRoot, err)
- }
- if len(paths) == 1 {
- props.Check_api.Api_lint.Baseline_file = proptools.StringPtr(baselinePath)
- } else if len(paths) != 0 {
- mctx.ModuleErrorf("error checking for presence of %s: expected one path, found: %v", baselinePathRelativeToRoot, paths)
- }
+ // If it exists then pass a lint-baseline.txt through to droidstubs.
+ baselinePath := path.Join(apiDir, apiScope.apiFilePrefix+"lint-baseline.txt")
+ baselinePathRelativeToRoot := path.Join(mctx.ModuleDir(), baselinePath)
+ paths, err := mctx.GlobWithDeps(baselinePathRelativeToRoot, nil)
+ if err != nil {
+ mctx.ModuleErrorf("error checking for presence of %s: %s", baselinePathRelativeToRoot, err)
+ }
+ if len(paths) == 1 {
+ props.Check_api.Api_lint.Baseline_file = proptools.StringPtr(baselinePath)
+ } else if len(paths) != 0 {
+ mctx.ModuleErrorf("error checking for presence of %s: expected one path, found: %v", baselinePathRelativeToRoot, paths)
}
}
+ }
- // Dist the api txt artifact for sdk builds.
- if !Bool(module.sdkLibraryProperties.No_dist) {
- props.Dist.Targets = []string{"sdk", "win_sdk"}
- props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.txt", module.BaseModuleName()))
- props.Dist.Dir = proptools.StringPtr(path.Join(module.apiDistPath(apiScope), "api"))
- }
+ // Dist the api txt artifact for sdk builds.
+ if !Bool(module.sdkLibraryProperties.No_dist) {
+ props.Dist.Targets = []string{"sdk", "win_sdk"}
+ props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.txt", module.BaseModuleName()))
+ props.Dist.Dir = proptools.StringPtr(path.Join(module.apiDistPath(apiScope), "api"))
}
mctx.CreateModule(DroidstubsFactory, &props)
@@ -1524,22 +1509,8 @@
}
for _, scope := range generatedScopes {
- stubsSourceArgs := scope.droidstubsArgsForGeneratingStubsSource
- stubsSourceModuleName := module.stubsSourceModuleName(scope)
-
- // If the args needed to generate the stubs and API are the same then they
- // can be generated in a single invocation of metalava, otherwise they will
- // need separate invocations.
- if scope.createStubsSourceAndApiTogether {
- // Use the stubs source name for legacy reasons.
- module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, true, stubsSourceArgs)
- } else {
- module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, false, stubsSourceArgs)
-
- apiArgs := scope.droidstubsArgsForGeneratingApi
- apiName := module.apiModuleName(scope)
- module.createStubsSourcesAndApi(mctx, scope, apiName, false, true, apiArgs)
- }
+ // Use the stubs source name for legacy reasons.
+ module.createStubsSourcesAndApi(mctx, scope, module.stubsSourceModuleName(scope), scope.droidstubsArgs)
module.createStubsLibrary(mctx, scope)
}
@@ -2026,6 +1997,15 @@
}
// to satisfy apex.javaDependency interface
+func (module *SdkLibraryImport) LintDepSets() LintDepSets {
+ if module.implLibraryModule == nil {
+ return LintDepSets{}
+ } else {
+ return module.implLibraryModule.LintDepSets()
+ }
+}
+
+// to satisfy apex.javaDependency interface
func (module *SdkLibraryImport) Stem() string {
return module.BaseModuleName()
}
diff --git a/java/sdk_test.go b/java/sdk_test.go
index 1f23b14..395da79 100644
--- a/java/sdk_test.go
+++ b/java/sdk_test.go
@@ -49,8 +49,8 @@
}{
{
name: "default",
- bootclasspath: config.LegacyCorePlatformBootclasspathLibraries,
- system: config.LegacyCorePlatformSystemModules,
+ bootclasspath: config.StableCorePlatformBootclasspathLibraries,
+ system: config.StableCorePlatformSystemModules,
java8classpath: config.FrameworkLibraries,
java9classpath: config.FrameworkLibraries,
aidl: "-Iframework/aidl",
@@ -58,16 +58,16 @@
{
name: `sdk_version:"core_platform"`,
properties: `sdk_version:"core_platform"`,
- bootclasspath: config.LegacyCorePlatformBootclasspathLibraries,
- system: config.LegacyCorePlatformSystemModules,
+ bootclasspath: config.StableCorePlatformBootclasspathLibraries,
+ system: config.StableCorePlatformSystemModules,
java8classpath: []string{},
aidl: "",
},
{
name: "blank sdk version",
properties: `sdk_version: "",`,
- bootclasspath: config.LegacyCorePlatformBootclasspathLibraries,
- system: config.LegacyCorePlatformSystemModules,
+ bootclasspath: config.StableCorePlatformBootclasspathLibraries,
+ system: config.StableCorePlatformSystemModules,
java8classpath: config.FrameworkLibraries,
java9classpath: config.FrameworkLibraries,
aidl: "-Iframework/aidl",
@@ -155,9 +155,9 @@
{
name: "nostdlib system_modules",
- properties: `sdk_version: "none", system_modules: "legacy-core-platform-api-stubs-system-modules"`,
- system: "legacy-core-platform-api-stubs-system-modules",
- bootclasspath: []string{"legacy-core-platform-api-stubs-system-modules-lib"},
+ properties: `sdk_version: "none", system_modules: "stable-core-platform-api-stubs-system-modules"`,
+ system: "stable-core-platform-api-stubs-system-modules",
+ bootclasspath: []string{"stable-core-platform-api-stubs-system-modules-lib"},
java8classpath: []string{},
},
{
diff --git a/java/testing.go b/java/testing.go
index 94f054e..1e725fa 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -22,6 +22,8 @@
"android/soong/android"
"android/soong/cc"
+ "android/soong/python"
+
"github.com/google/blueprint"
)
@@ -85,6 +87,10 @@
"prebuilts/sdk/tools/core-lambda-stubs.jar": nil,
"prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "30", "current"],}`),
+ "bin.py": nil,
+ python.StubTemplateHost: []byte(`PYTHON_BINARY = '%interpreter%'
+ MAIN_FILE = '%main%'`),
+
// For java_sdk_library
"api/module-lib-current.txt": nil,
"api/module-lib-removed.txt": nil,
@@ -136,7 +142,7 @@
name: "%s",
srcs: ["a.java"],
sdk_version: "none",
- system_modules: "legacy-core-platform-api-stubs-system-modules",
+ system_modules: "stable-core-platform-api-stubs-system-modules",
}
`, extra)
}
@@ -146,7 +152,7 @@
name: "framework",
srcs: ["a.java"],
sdk_version: "none",
- system_modules: "legacy-core-platform-api-stubs-system-modules",
+ system_modules: "stable-core-platform-api-stubs-system-modules",
aidl: {
export_include_dirs: ["framework/aidl"],
},
@@ -161,7 +167,7 @@
name: "android.hidl.base-V1.0-java",
srcs: ["a.java"],
sdk_version: "none",
- system_modules: "legacy-core-platform-api-stubs-system-modules",
+ system_modules: "stable-core-platform-api-stubs-system-modules",
installable: true,
}
@@ -169,7 +175,7 @@
name: "android.hidl.manager-V1.0-java",
srcs: ["a.java"],
sdk_version: "none",
- system_modules: "legacy-core-platform-api-stubs-system-modules",
+ system_modules: "stable-core-platform-api-stubs-system-modules",
installable: true,
}
@@ -177,7 +183,7 @@
name: "org.apache.http.legacy",
srcs: ["a.java"],
sdk_version: "none",
- system_modules: "legacy-core-platform-api-stubs-system-modules",
+ system_modules: "stable-core-platform-api-stubs-system-modules",
installable: true,
}
@@ -185,7 +191,7 @@
name: "android.test.base",
srcs: ["a.java"],
sdk_version: "none",
- system_modules: "legacy-core-platform-api-stubs-system-modules",
+ system_modules: "stable-core-platform-api-stubs-system-modules",
installable: true,
}
@@ -193,7 +199,7 @@
name: "android.test.mock",
srcs: ["a.java"],
sdk_version: "none",
- system_modules: "legacy-core-platform-api-stubs-system-modules",
+ system_modules: "stable-core-platform-api-stubs-system-modules",
installable: true,
}
`
diff --git a/phony/phony.go b/phony/phony.go
index 305a434..cb60b9f 100644
--- a/phony/phony.go
+++ b/phony/phony.go
@@ -44,11 +44,6 @@
p.requiredModuleNames = ctx.RequiredModuleNames()
p.hostRequiredModuleNames = ctx.HostRequiredModuleNames()
p.targetRequiredModuleNames = ctx.TargetRequiredModuleNames()
- if len(p.requiredModuleNames) == 0 &&
- len(p.hostRequiredModuleNames) == 0 && len(p.targetRequiredModuleNames) == 0 {
- ctx.PropertyErrorf("required", "phony must not have empty required dependencies "+
- "in order to be useful(and therefore permitted).")
- }
}
func (p *phony) AndroidMk() android.AndroidMkData {
diff --git a/python/binary.go b/python/binary.go
index 695fa12..5a74926 100644
--- a/python/binary.go
+++ b/python/binary.go
@@ -65,7 +65,7 @@
}
var (
- stubTemplateHost = "build/soong/python/scripts/stub_template_host.txt"
+ StubTemplateHost = "build/soong/python/scripts/stub_template_host.txt"
)
func NewBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
diff --git a/python/builder.go b/python/builder.go
index 36baecd..dc2d1f1 100644
--- a/python/builder.go
+++ b/python/builder.go
@@ -91,7 +91,7 @@
if !embeddedLauncher {
// the path of stub_template_host.txt from source tree.
- template := android.PathForSource(ctx, stubTemplateHost)
+ template := android.PathForSource(ctx, StubTemplateHost)
implicits = append(implicits, template)
// intermediate output path for __main__.py
diff --git a/python/python.go b/python/python.go
index a6c9e2a..479c729 100644
--- a/python/python.go
+++ b/python/python.go
@@ -30,9 +30,11 @@
)
func init() {
- android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
- ctx.BottomUp("version_split", versionSplitMutator()).Parallel()
- })
+ android.PreDepsMutators(RegisterPythonPreDepsMutators)
+}
+
+func RegisterPythonPreDepsMutators(ctx android.RegisterMutatorsContext) {
+ ctx.BottomUp("version_split", versionSplitMutator()).Parallel()
}
// the version properties that apply to python libraries and binaries.
@@ -226,15 +228,20 @@
return func(mctx android.BottomUpMutatorContext) {
if base, ok := mctx.Module().(*Module); ok {
versionNames := []string{}
- if base.properties.Version.Py2.Enabled != nil &&
- *(base.properties.Version.Py2.Enabled) == true {
- versionNames = append(versionNames, pyVersion2)
- }
+ // PY3 is first so that we alias the PY3 variant rather than PY2 if both
+ // are available
if !(base.properties.Version.Py3.Enabled != nil &&
*(base.properties.Version.Py3.Enabled) == false) {
versionNames = append(versionNames, pyVersion3)
}
+ if base.properties.Version.Py2.Enabled != nil &&
+ *(base.properties.Version.Py2.Enabled) == true {
+ versionNames = append(versionNames, pyVersion2)
+ }
modules := mctx.CreateVariations(versionNames...)
+ if len(versionNames) > 0 {
+ mctx.AliasVariation(versionNames[0])
+ }
for i, v := range versionNames {
// set the actual version for Python module.
modules[i].(*Module).properties.Actual_version = v
diff --git a/python/python_test.go b/python/python_test.go
index 1245ca1..23db24e 100644
--- a/python/python_test.go
+++ b/python/python_test.go
@@ -301,7 +301,7 @@
filepath.Join("dir", "file2.py"): nil,
filepath.Join("dir", "bin.py"): nil,
filepath.Join("dir", "file4.py"): nil,
- stubTemplateHost: []byte(`PYTHON_BINARY = '%interpreter%'
+ StubTemplateHost: []byte(`PYTHON_BINARY = '%interpreter%'
MAIN_FILE = '%main%'`),
},
expectedBinaries: []pyModule{
@@ -330,9 +330,7 @@
t.Run(d.desc, func(t *testing.T) {
config := android.TestConfig(buildDir, nil, "", d.mockFiles)
ctx := android.NewTestContext()
- ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
- ctx.BottomUp("version_split", versionSplitMutator()).Parallel()
- })
+ ctx.PreDepsMutators(RegisterPythonPreDepsMutators)
ctx.RegisterModuleType("python_library_host", PythonLibraryHostFactory)
ctx.RegisterModuleType("python_binary_host", PythonBinaryHostFactory)
ctx.RegisterModuleType("python_defaults", defaultsFactory)
diff --git a/rust/Android.bp b/rust/Android.bp
index d56de87..bbeb28d 100644
--- a/rust/Android.bp
+++ b/rust/Android.bp
@@ -10,6 +10,7 @@
srcs: [
"androidmk.go",
"binary.go",
+ "bindgen.go",
"builder.go",
"clippy.go",
"compiler.go",
@@ -19,17 +20,21 @@
"proc_macro.go",
"project_json.go",
"rust.go",
+ "source_provider.go",
"test.go",
"testing.go",
],
testSrcs: [
"binary_test.go",
+ "bindgen_test.go",
+ "builder_test.go",
"clippy_test.go",
"compiler_test.go",
"coverage_test.go",
"library_test.go",
"project_json_test.go",
"rust_test.go",
+ "source_provider_test.go",
"test_test.go",
],
pluginFor: ["soong_build"],
diff --git a/rust/androidmk.go b/rust/androidmk.go
index aea899b..5806017 100644
--- a/rust/androidmk.go
+++ b/rust/androidmk.go
@@ -76,8 +76,12 @@
},
}
- mod.subAndroidMk(&ret, mod.compiler)
-
+ if mod.compiler != nil && !mod.compiler.Disabled() {
+ mod.subAndroidMk(&ret, mod.compiler)
+ } else if mod.sourceProvider != nil {
+ // If the compiler is disabled, this is a SourceProvider.
+ mod.subAndroidMk(&ret, mod.sourceProvider)
+ }
ret.SubName += mod.Properties.SubName
return ret
@@ -155,6 +159,26 @@
}
+func (sourceProvider *baseSourceProvider) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
+ outFile := sourceProvider.outputFile
+ ret.Class = "ETC"
+ ret.OutputFile = android.OptionalPathForPath(outFile)
+ ret.SubName += sourceProvider.subName
+ ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
+ _, file := filepath.Split(outFile.String())
+ stem, suffix, _ := android.SplitFileExt(file)
+ fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
+ fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
+ })
+}
+
+func (bindgen *bindgenDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
+ ctx.subAndroidMk(ret, bindgen.baseSourceProvider)
+ ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
+ fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
+ })
+}
+
func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
// Soong installation is only supported for host modules. Have Make
// installation trigger Soong installation.
diff --git a/rust/binary.go b/rust/binary.go
index a1cd410..1a82c92 100644
--- a/rust/binary.go
+++ b/rust/binary.go
@@ -86,7 +86,7 @@
deps = binary.baseCompiler.compilerDeps(ctx, deps)
if ctx.toolchain().Bionic() {
- deps = binary.baseCompiler.bionicDeps(ctx, deps)
+ deps = bionicDeps(deps)
deps.CrtBegin = "crtbegin_dynamic"
deps.CrtEnd = "crtend_android"
}
@@ -106,7 +106,7 @@
func (binary *binaryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
fileName := binary.getStem(ctx) + ctx.toolchain().ExecutableSuffix()
- srcPath := srcPathFromModuleSrcs(ctx, binary.baseCompiler.Properties.Srcs)
+ srcPath, _ := srcPathFromModuleSrcs(ctx, binary.baseCompiler.Properties.Srcs)
outputFile := android.PathForModuleOut(ctx, fileName)
binary.unstrippedOutputFile = outputFile
diff --git a/rust/bindgen.go b/rust/bindgen.go
new file mode 100644
index 0000000..2224a9c
--- /dev/null
+++ b/rust/bindgen.go
@@ -0,0 +1,212 @@
+// Copyright 2020 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 rust
+
+import (
+ "strings"
+
+ "github.com/google/blueprint"
+
+ "android/soong/android"
+ ccConfig "android/soong/cc/config"
+)
+
+var (
+ defaultBindgenFlags = []string{""}
+
+ // bindgen should specify its own Clang revision so updating Clang isn't potentially blocked on bindgen failures.
+ bindgenClangVersion = "clang-r383902c"
+ bindgenLibClangSoGit = "11git"
+
+ //TODO(b/160803703) Use a prebuilt bindgen instead of the built bindgen.
+ _ = pctx.SourcePathVariable("bindgenCmd", "out/host/${config.HostPrebuiltTag}/bin/bindgen")
+ _ = pctx.SourcePathVariable("bindgenClang",
+ "${ccConfig.ClangBase}/${config.HostPrebuiltTag}/"+bindgenClangVersion+"/bin/clang")
+ _ = pctx.SourcePathVariable("bindgenLibClang",
+ "${ccConfig.ClangBase}/${config.HostPrebuiltTag}/"+bindgenClangVersion+"/lib64/libclang.so."+bindgenLibClangSoGit)
+
+ //TODO(ivanlozano) Switch this to RuleBuilder
+ bindgen = pctx.AndroidStaticRule("bindgen",
+ blueprint.RuleParams{
+ Command: "CLANG_PATH=$bindgenClang LIBCLANG_PATH=$bindgenLibClang RUSTFMT=${config.RustBin}/rustfmt " +
+ "$cmd $flags $in -o $out -- -MD -MF $out.d $cflags",
+ CommandDeps: []string{"$cmd"},
+ Deps: blueprint.DepsGCC,
+ Depfile: "$out.d",
+ },
+ "cmd", "flags", "cflags")
+)
+
+func init() {
+ android.RegisterModuleType("rust_bindgen", RustBindgenFactory)
+ android.RegisterModuleType("rust_bindgen_host", RustBindgenHostFactory)
+}
+
+var _ SourceProvider = (*bindgenDecorator)(nil)
+
+type BindgenProperties struct {
+ // The wrapper header file
+ Wrapper_src *string `android:"path,arch_variant"`
+
+ // list of bindgen-specific flags and options
+ Bindgen_flags []string `android:"arch_variant"`
+
+ // list of clang flags required to correctly interpret the headers.
+ Cflags []string `android:"arch_variant"`
+
+ // list of directories relative to the Blueprints file that will
+ // be added to the include path using -I
+ Local_include_dirs []string `android:"arch_variant,variant_prepend"`
+
+ // list of static libraries that provide headers for this binding.
+ Static_libs []string `android:"arch_variant,variant_prepend"`
+
+ // list of shared libraries that provide headers for this binding.
+ Shared_libs []string `android:"arch_variant"`
+
+ // module name of a custom binary/script which should be used instead of the 'bindgen' binary. This custom
+ // binary must expect arguments in a similar fashion to bindgen, e.g.
+ //
+ // "my_bindgen [flags] wrapper_header.h -o [output_path] -- [clang flags]"
+ Custom_bindgen string `android:"path"`
+
+ //TODO(b/161141999) Add support for headers from cc_library_header modules.
+}
+
+type bindgenDecorator struct {
+ *baseSourceProvider
+
+ Properties BindgenProperties
+}
+
+func (b *bindgenDecorator) generateSource(ctx android.ModuleContext, deps PathDeps) android.Path {
+ ccToolchain := ccConfig.FindToolchain(ctx.Os(), ctx.Arch())
+
+ var cflags []string
+ var implicits android.Paths
+
+ implicits = append(implicits, deps.depIncludePaths...)
+ implicits = append(implicits, deps.depSystemIncludePaths...)
+
+ // Default clang flags
+ cflags = append(cflags, "${ccConfig.CommonClangGlobalCflags}")
+ if ctx.Device() {
+ cflags = append(cflags, "${ccConfig.DeviceClangGlobalCflags}")
+ }
+
+ // Toolchain clang flags
+ cflags = append(cflags, "-target "+ccToolchain.ClangTriple())
+ cflags = append(cflags, strings.ReplaceAll(ccToolchain.ToolchainClangCflags(), "${config.", "${ccConfig."))
+
+ // Dependency clang flags and include paths
+ cflags = append(cflags, deps.depClangFlags...)
+ for _, include := range deps.depIncludePaths {
+ cflags = append(cflags, "-I"+include.String())
+ }
+ for _, include := range deps.depSystemIncludePaths {
+ cflags = append(cflags, "-isystem "+include.String())
+ }
+
+ // Module defined clang flags and include paths
+ cflags = append(cflags, b.Properties.Cflags...)
+ for _, include := range b.Properties.Local_include_dirs {
+ cflags = append(cflags, "-I"+android.PathForModuleSrc(ctx, include).String())
+ implicits = append(implicits, android.PathForModuleSrc(ctx, include))
+ }
+
+ bindgenFlags := defaultBindgenFlags
+ bindgenFlags = append(bindgenFlags, strings.Join(b.Properties.Bindgen_flags, " "))
+
+ wrapperFile := android.OptionalPathForModuleSrc(ctx, b.Properties.Wrapper_src)
+ if !wrapperFile.Valid() {
+ ctx.PropertyErrorf("wrapper_src", "invalid path to wrapper source")
+ }
+
+ outputFile := android.PathForModuleOut(ctx, b.baseSourceProvider.getStem(ctx)+".rs")
+
+ var cmd, cmdDesc string
+ if b.Properties.Custom_bindgen != "" {
+ cmd = ctx.GetDirectDepWithTag(b.Properties.Custom_bindgen, customBindgenDepTag).(*Module).HostToolPath().String()
+ cmdDesc = b.Properties.Custom_bindgen
+ } else {
+ cmd = "$bindgenCmd"
+ cmdDesc = "bindgen"
+ }
+
+ ctx.Build(pctx, android.BuildParams{
+ Rule: bindgen,
+ Description: strings.Join([]string{cmdDesc, wrapperFile.Path().Rel()}, " "),
+ Output: outputFile,
+ Input: wrapperFile.Path(),
+ Implicits: implicits,
+ Args: map[string]string{
+ "cmd": cmd,
+ "flags": strings.Join(bindgenFlags, " "),
+ "cflags": strings.Join(cflags, " "),
+ },
+ })
+
+ b.baseSourceProvider.outputFile = outputFile
+ return outputFile
+}
+
+func (b *bindgenDecorator) sourceProviderProps() []interface{} {
+ return append(b.baseSourceProvider.sourceProviderProps(),
+ &b.Properties)
+}
+
+// rust_bindgen generates Rust FFI bindings to C libraries using bindgen given a wrapper header as the primary input.
+// Bindgen has a number of flags to control the generated source, and additional flags can be passed to clang to ensure
+// the header and generated source is appropriately handled.
+func RustBindgenFactory() android.Module {
+ module, _ := NewRustBindgen(android.HostAndDeviceSupported)
+ return module.Init()
+}
+
+func RustBindgenHostFactory() android.Module {
+ module, _ := NewRustBindgen(android.HostSupported)
+ return module.Init()
+}
+
+func NewRustBindgen(hod android.HostOrDeviceSupported) (*Module, *bindgenDecorator) {
+ module := newModule(hod, android.MultilibBoth)
+
+ bindgen := &bindgenDecorator{
+ baseSourceProvider: NewSourceProvider(),
+ Properties: BindgenProperties{},
+ }
+
+ _, library := NewRustLibrary(hod)
+ library.BuildOnlyRust()
+ library.setNoLint()
+ library.sourceProvider = bindgen
+
+ module.sourceProvider = bindgen
+ module.compiler = library
+ module.setClippy(false)
+
+ return module, bindgen
+}
+
+func (b *bindgenDecorator) sourceProviderDeps(ctx DepsContext, deps Deps) Deps {
+ deps = b.baseSourceProvider.sourceProviderDeps(ctx, deps)
+ if ctx.toolchain().Bionic() {
+ deps = bionicDeps(deps)
+ }
+
+ deps.SharedLibs = append(deps.SharedLibs, b.Properties.Shared_libs...)
+ deps.StaticLibs = append(deps.StaticLibs, b.Properties.Static_libs...)
+ return deps
+}
diff --git a/rust/bindgen_test.go b/rust/bindgen_test.go
new file mode 100644
index 0000000..0b529ca
--- /dev/null
+++ b/rust/bindgen_test.go
@@ -0,0 +1,83 @@
+// Copyright 2020 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 rust
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestRustBindgen(t *testing.T) {
+ ctx := testRust(t, `
+ rust_bindgen {
+ name: "libbindgen",
+ wrapper_src: "src/any.h",
+ crate_name: "bindgen",
+ stem: "libbindgen",
+ source_stem: "bindings",
+ bindgen_flags: ["--bindgen-flag"],
+ cflags: ["--clang-flag"],
+ shared_libs: ["libfoo_shared"],
+ static_libs: ["libfoo_static"],
+ }
+ cc_library_shared {
+ name: "libfoo_shared",
+ export_include_dirs: ["shared_include"],
+ }
+ cc_library_static {
+ name: "libfoo_static",
+ export_include_dirs: ["static_include"],
+ }
+ `)
+ libbindgen := ctx.ModuleForTests("libbindgen", "android_arm64_armv8-a").Output("bindings.rs")
+ if !strings.Contains(libbindgen.Args["flags"], "--bindgen-flag") {
+ t.Errorf("missing bindgen flags in rust_bindgen rule: flags %#v", libbindgen.Args["flags"])
+ }
+ if !strings.Contains(libbindgen.Args["cflags"], "--clang-flag") {
+ t.Errorf("missing clang cflags in rust_bindgen rule: cflags %#v", libbindgen.Args["cflags"])
+ }
+ if !strings.Contains(libbindgen.Args["cflags"], "-Ishared_include") {
+ t.Errorf("missing shared_libs exported includes in rust_bindgen rule: cflags %#v", libbindgen.Args["cflags"])
+ }
+ if !strings.Contains(libbindgen.Args["cflags"], "-Istatic_include") {
+ t.Errorf("missing static_libs exported includes in rust_bindgen rule: cflags %#v", libbindgen.Args["cflags"])
+ }
+}
+
+func TestRustBindgenCustomBindgen(t *testing.T) {
+ ctx := testRust(t, `
+ rust_bindgen {
+ name: "libbindgen",
+ wrapper_src: "src/any.h",
+ crate_name: "bindgen",
+ stem: "libbindgen",
+ source_stem: "bindings",
+ custom_bindgen: "my_bindgen"
+ }
+ rust_binary_host {
+ name: "my_bindgen",
+ srcs: ["foo.rs"],
+ }
+ `)
+
+ libbindgen := ctx.ModuleForTests("libbindgen", "android_arm64_armv8-a").Output("bindings.rs")
+
+ // The rule description should contain the custom binary name rather than bindgen, so checking the description
+ // should be sufficient.
+ if !strings.Contains(libbindgen.Description, "my_bindgen") {
+ t.Errorf("Custom bindgen binary %s not used for libbindgen: rule description %#v", "my_bindgen",
+ libbindgen.Description)
+ }
+}
diff --git a/rust/builder.go b/rust/builder.go
index 16d7306..45cd268 100644
--- a/rust/builder.go
+++ b/rust/builder.go
@@ -28,7 +28,7 @@
_ = pctx.SourcePathVariable("rustcCmd", "${config.RustBin}/rustc")
rustc = pctx.AndroidStaticRule("rustc",
blueprint.RuleParams{
- Command: "$rustcCmd " +
+ Command: "$envVars $rustcCmd " +
"-C linker=${config.RustLinker} " +
"-C link-args=\"${crtBegin} ${config.RustLinkerArgs} ${linkFlags} ${crtEnd}\" " +
"--emit link -o $out --emit dep-info=$out.d $in ${libFlags} $rustcFlags",
@@ -37,19 +37,19 @@
Deps: blueprint.DepsGCC,
Depfile: "$out.d",
},
- "rustcFlags", "linkFlags", "libFlags", "crtBegin", "crtEnd")
+ "rustcFlags", "linkFlags", "libFlags", "crtBegin", "crtEnd", "envVars")
_ = pctx.SourcePathVariable("clippyCmd", "${config.RustBin}/clippy-driver")
clippyDriver = pctx.AndroidStaticRule("clippy",
blueprint.RuleParams{
- Command: "$clippyCmd " +
+ Command: "$envVars $clippyCmd " +
// Because clippy-driver uses rustc as backend, we need to have some output even during the linting.
// Use the metadata output as it has the smallest footprint.
"--emit metadata -o $out $in ${libFlags} " +
"$rustcFlags $clippyFlags",
CommandDeps: []string{"$clippyCmd"},
},
- "rustcFlags", "libFlags", "clippyFlags")
+ "rustcFlags", "libFlags", "clippyFlags", "envVars")
zip = pctx.AndroidStaticRule("zip",
blueprint.RuleParams{
@@ -58,6 +58,14 @@
Rspfile: "$out.rsp",
RspfileContent: "$in",
})
+
+ cp = pctx.AndroidStaticRule("cp",
+ blueprint.RuleParams{
+ Command: "cp `cat $outDir.rsp` $outDir",
+ Rspfile: "${outDir}.rsp",
+ RspfileContent: "$in",
+ },
+ "outDir")
)
type buildOutput struct {
@@ -116,6 +124,7 @@
var inputs android.Paths
var implicits android.Paths
+ var envVars []string
var output buildOutput
var libFlags, rustcFlags, linkFlags []string
var implicitOutputs android.WritablePaths
@@ -166,6 +175,7 @@
implicits = append(implicits, rustLibsToPaths(deps.ProcMacros)...)
implicits = append(implicits, deps.StaticLibs...)
implicits = append(implicits, deps.SharedLibs...)
+
if deps.CrtBegin.Valid() {
implicits = append(implicits, deps.CrtBegin.Path(), deps.CrtEnd.Path())
}
@@ -189,6 +199,32 @@
output.coverageFile = gcnoFile
}
+ if len(deps.SrcDeps) > 0 {
+ genSubDir := "out/"
+ moduleGenDir := android.PathForModuleOut(ctx, genSubDir)
+ var outputs android.WritablePaths
+
+ for _, genSrc := range deps.SrcDeps {
+ if android.SuffixInList(outputs.Strings(), genSubDir+genSrc.Base()) {
+ ctx.PropertyErrorf("srcs",
+ "multiple source providers generate the same filename output: "+genSrc.Base())
+ }
+ outputs = append(outputs, android.PathForModuleOut(ctx, genSubDir+genSrc.Base()))
+ }
+
+ ctx.Build(pctx, android.BuildParams{
+ Rule: cp,
+ Description: "cp " + moduleGenDir.Rel(),
+ Outputs: outputs,
+ Inputs: deps.SrcDeps,
+ Args: map[string]string{
+ "outDir": moduleGenDir.String(),
+ },
+ })
+ implicits = append(implicits, outputs.Paths()...)
+ envVars = append(envVars, "OUT_DIR=$$PWD/"+moduleGenDir.String())
+ }
+
if flags.Clippy {
clippyFile := android.PathForModuleOut(ctx, outputFile.Base()+".clippy")
ctx.Build(pctx, android.BuildParams{
@@ -202,6 +238,7 @@
"rustcFlags": strings.Join(rustcFlags, " "),
"libFlags": strings.Join(libFlags, " "),
"clippyFlags": strings.Join(flags.ClippyFlags, " "),
+ "envVars": strings.Join(envVars, " "),
},
})
// Declare the clippy build as an implicit dependency of the original crate.
@@ -221,6 +258,7 @@
"libFlags": strings.Join(libFlags, " "),
"crtBegin": deps.CrtBegin.String(),
"crtEnd": deps.CrtEnd.String(),
+ "envVars": strings.Join(envVars, " "),
},
})
diff --git a/rust/builder_test.go b/rust/builder_test.go
new file mode 100644
index 0000000..5c11cb7
--- /dev/null
+++ b/rust/builder_test.go
@@ -0,0 +1,42 @@
+// Copyright 2020 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 rust
+
+import "testing"
+
+func TestSourceProviderCollision(t *testing.T) {
+ testRustError(t, "multiple source providers generate the same filename output: bindings.rs", `
+ rust_binary {
+ name: "source_collider",
+ srcs: [
+ "foo.rs",
+ ":libbindings1",
+ ":libbindings2",
+ ],
+ }
+ rust_bindgen {
+ name: "libbindings1",
+ source_stem: "bindings",
+ crate_name: "bindings1",
+ wrapper_src: "src/any.h",
+ }
+ rust_bindgen {
+ name: "libbindings2",
+ source_stem: "bindings",
+ crate_name: "bindings2",
+ wrapper_src: "src/any.h",
+ }
+ `)
+}
diff --git a/rust/compiler.go b/rust/compiler.go
index 92a3b07..0274015 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -24,7 +24,7 @@
"android/soong/rust/config"
)
-func getEdition(compiler *baseCompiler) string {
+func (compiler *baseCompiler) edition() string {
return proptools.StringDefault(compiler.Properties.Edition, config.DefaultEdition)
}
@@ -32,6 +32,10 @@
compiler.Properties.No_stdlibs = proptools.BoolPtr(true)
}
+func (compiler *baseCompiler) setNoLint() {
+ compiler.Properties.No_lint = proptools.BoolPtr(true)
+}
+
func NewBaseCompiler(dir, dir64 string, location installLocation) *baseCompiler {
return &baseCompiler{
Properties: BaseCompilerProperties{},
@@ -46,6 +50,8 @@
const (
InstallInSystem installLocation = 0
InstallInData = iota
+
+ incorrectSourcesError = "srcs can only contain one path for a rust file and source providers prefixed by \":\""
)
type BaseCompilerProperties struct {
@@ -79,7 +85,10 @@
// list of C static library dependencies
Static_libs []string `android:"arch_variant"`
- // crate name, required for libraries. This must be the expected extern crate name used in source
+ // crate name, required for modules which produce Rust libraries: rust_library, rust_ffi and SourceProvider
+ // modules which create library variants (rust_bindgen). This must be the expected extern crate name used in
+ // source, and is required to conform to an enforced format matching library output files (if the output file is
+ // lib<someName><suffix>, the crate_name property must be <someName>).
Crate_name string `android:"arch_variant"`
// list of features to enable for this crate
@@ -118,6 +127,14 @@
distFile android.OptionalPath
}
+func (compiler *baseCompiler) Disabled() bool {
+ return false
+}
+
+func (compiler *baseCompiler) SetDisabled() {
+ panic("baseCompiler does not implement SetDisabled()")
+}
+
func (compiler *baseCompiler) coverageOutputZipPath() android.OptionalPath {
panic("baseCompiler does not implement coverageOutputZipPath()")
}
@@ -147,7 +164,7 @@
}
flags.RustFlags = append(flags.RustFlags, compiler.Properties.Flags...)
flags.RustFlags = append(flags.RustFlags, compiler.featuresToFlags(compiler.Properties.Features)...)
- flags.RustFlags = append(flags.RustFlags, "--edition="+getEdition(compiler))
+ flags.RustFlags = append(flags.RustFlags, "--edition="+compiler.edition())
flags.LinkFlags = append(flags.LinkFlags, compiler.Properties.Ld_flags...)
flags.GlobalRustFlags = append(flags.GlobalRustFlags, config.GlobalRustFlags...)
flags.GlobalRustFlags = append(flags.GlobalRustFlags, ctx.toolchain().ToolchainRustFlags())
@@ -197,7 +214,7 @@
return deps
}
-func (compiler *baseCompiler) bionicDeps(ctx DepsContext, deps Deps) Deps {
+func bionicDeps(deps Deps) Deps {
deps.SharedLibs = append(deps.SharedLibs, "liblog")
deps.SharedLibs = append(deps.SharedLibs, "libc")
deps.SharedLibs = append(deps.SharedLibs, "libm")
@@ -253,10 +270,25 @@
return String(compiler.Properties.Relative_install_path)
}
-func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) android.Path {
- srcPaths := android.PathsForModuleSrc(ctx, srcs)
- if len(srcPaths) != 1 {
- ctx.PropertyErrorf("srcs", "srcs can only contain one path for rust modules")
+// Returns the Path for the main source file along with Paths for generated source files from modules listed in srcs.
+func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) (android.Path, android.Paths) {
+ // The srcs can contain strings with prefix ":".
+ // They are dependent modules of this module, with android.SourceDepTag.
+ // They are not the main source file compiled by rustc.
+ numSrcs := 0
+ srcIndex := 0
+ for i, s := range srcs {
+ if android.SrcIsModule(s) == "" {
+ numSrcs++
+ srcIndex = i
+ }
}
- return srcPaths[0]
+ if numSrcs != 1 {
+ ctx.PropertyErrorf("srcs", incorrectSourcesError)
+ }
+ if srcIndex != 0 {
+ ctx.PropertyErrorf("srcs", "main source file must be the first in srcs")
+ }
+ paths := android.PathsForModuleSrc(ctx, srcs)
+ return paths[srcIndex], paths[1:]
}
diff --git a/rust/compiler_test.go b/rust/compiler_test.go
index bcde757..b853196 100644
--- a/rust/compiler_test.go
+++ b/rust/compiler_test.go
@@ -43,7 +43,7 @@
// Test that we reject multiple source files.
func TestEnforceSingleSourceFile(t *testing.T) {
- singleSrcError := "srcs can only contain one path for rust modules"
+ singleSrcError := "srcs can only contain one path for a rust file and source providers prefixed by \":\""
// Test libraries
testRustError(t, singleSrcError, `
diff --git a/rust/config/allowed_list.go b/rust/config/allowed_list.go
index 0204cd2..9c9a136 100644
--- a/rust/config/allowed_list.go
+++ b/rust/config/allowed_list.go
@@ -7,6 +7,7 @@
"external/crosvm",
"external/adhd",
"prebuilts/rust",
+ "system/security",
}
RustModuleTypes = []string{
diff --git a/rust/config/global.go b/rust/config/global.go
index e1b1775..2020f46 100644
--- a/rust/config/global.go
+++ b/rust/config/global.go
@@ -54,6 +54,9 @@
"-Wl,--pack-dyn-relocs=android+relr",
"-Wl,--no-undefined",
"-Wl,--hash-style=gnu",
+
+ "-B${ccConfig.ClangBin}",
+ "-fuse-ld=lld",
}
)
@@ -80,7 +83,7 @@
pctx.ImportAs("ccConfig", "android/soong/cc/config")
pctx.StaticVariable("RustLinker", "${ccConfig.ClangBin}/clang++")
- pctx.StaticVariable("RustLinkerArgs", "-B ${ccConfig.ClangBin} -fuse-ld=lld")
+ pctx.StaticVariable("RustLinkerArgs", "")
pctx.StaticVariable("DeviceGlobalLinkFlags", strings.Join(deviceGlobalLinkFlags, " "))
diff --git a/rust/config/x86_darwin_host.go b/rust/config/x86_darwin_host.go
index 4c16693..4104400 100644
--- a/rust/config/x86_darwin_host.go
+++ b/rust/config/x86_darwin_host.go
@@ -21,8 +21,10 @@
)
var (
- DarwinRustFlags = []string{}
- DarwinRustLinkFlags = []string{}
+ DarwinRustFlags = []string{}
+ DarwinRustLinkFlags = []string{
+ "-B${ccConfig.MacToolPath}",
+ }
darwinX8664Rustflags = []string{}
darwinX8664Linkflags = []string{}
)
@@ -66,6 +68,10 @@
return ".dylib"
}
+func (t *toolchainDarwin) DylibSuffix() string {
+ return ".rustlib.dylib"
+}
+
func (t *toolchainDarwin) ProcMacroSuffix() string {
return ".dylib"
}
diff --git a/rust/config/x86_linux_host.go b/rust/config/x86_linux_host.go
index 5376e5b..acc99e1 100644
--- a/rust/config/x86_linux_host.go
+++ b/rust/config/x86_linux_host.go
@@ -21,8 +21,11 @@
)
var (
- LinuxRustFlags = []string{}
- LinuxRustLinkFlags = []string{}
+ LinuxRustFlags = []string{}
+ LinuxRustLinkFlags = []string{
+ "-B${ccConfig.ClangBin}",
+ "-fuse-ld=lld",
+ }
linuxX86Rustflags = []string{}
linuxX86Linkflags = []string{}
linuxX8664Rustflags = []string{}
diff --git a/rust/library.go b/rust/library.go
index 8b8e797..6766d61 100644
--- a/rust/library.go
+++ b/rust/library.go
@@ -69,6 +69,10 @@
VariantIsShared bool `blueprint:"mutated"`
// This variant is a static library
VariantIsStatic bool `blueprint:"mutated"`
+
+ // This variant is disabled and should not be compiled
+ // (used for SourceProvider variants that produce only source)
+ VariantIsDisabled bool `blueprint:"mutated"`
}
type libraryDecorator struct {
@@ -78,6 +82,7 @@
Properties LibraryCompilerProperties
MutatedProperties LibraryMutatedProperties
includeDirs android.Paths
+ sourceProvider SourceProvider
}
type libraryInterface interface {
@@ -340,7 +345,7 @@
deps = library.baseCompiler.compilerDeps(ctx, deps)
if ctx.toolchain().Bionic() && (library.dylib() || library.shared()) {
- deps = library.baseCompiler.bionicDeps(ctx, deps)
+ deps = bionicDeps(deps)
deps.CrtBegin = "crtbegin_so"
deps.CrtEnd = "crtend_so"
}
@@ -367,8 +372,13 @@
func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
var outputFile android.WritablePath
+ var srcPath android.Path
- srcPath := srcPathFromModuleSrcs(ctx, library.baseCompiler.Properties.Srcs)
+ if library.sourceProvider != nil {
+ srcPath = library.sourceProvider.Srcs()[0]
+ } else {
+ srcPath, _ = srcPathFromModuleSrcs(ctx, library.baseCompiler.Properties.Srcs)
+ }
flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
@@ -430,6 +440,14 @@
return stem + String(library.baseCompiler.Properties.Suffix)
}
+func (library *libraryDecorator) Disabled() bool {
+ return library.MutatedProperties.VariantIsDisabled
+}
+
+func (library *libraryDecorator) SetDisabled() {
+ library.MutatedProperties.VariantIsDisabled = true
+}
+
var validCrateName = regexp.MustCompile("[^a-zA-Z0-9_]+")
func validateLibraryStem(ctx BaseModuleContext, filename string, crate_name string) {
@@ -454,25 +472,35 @@
if m, ok := mctx.Module().(*Module); ok && m.compiler != nil {
switch library := m.compiler.(type) {
case libraryInterface:
-
- // We only build the rust library variants here. This assumes that
- // LinkageMutator runs first and there's an empty variant
- // if rust variants are required.
- if !library.static() && !library.shared() {
- if library.buildRlib() && library.buildDylib() {
- modules := mctx.CreateLocalVariations("rlib", "dylib")
- rlib := modules[0].(*Module)
- dylib := modules[1].(*Module)
-
- rlib.compiler.(libraryInterface).setRlib()
- dylib.compiler.(libraryInterface).setDylib()
- } else if library.buildRlib() {
- modules := mctx.CreateLocalVariations("rlib")
- modules[0].(*Module).compiler.(libraryInterface).setRlib()
- } else if library.buildDylib() {
- modules := mctx.CreateLocalVariations("dylib")
- modules[0].(*Module).compiler.(libraryInterface).setDylib()
+ if library.buildRlib() && library.buildDylib() {
+ variants := []string{"rlib", "dylib"}
+ if m.sourceProvider != nil {
+ variants = append(variants, "")
}
+ modules := mctx.CreateLocalVariations(variants...)
+
+ rlib := modules[0].(*Module)
+ dylib := modules[1].(*Module)
+ rlib.compiler.(libraryInterface).setRlib()
+ dylib.compiler.(libraryInterface).setDylib()
+
+ if m.sourceProvider != nil {
+ // This library is SourceProvider generated, so the non-library-producing
+ // variant needs to disable it's compiler and skip installation.
+ sourceProvider := modules[2].(*Module)
+ sourceProvider.compiler.SetDisabled()
+ }
+ } else if library.buildRlib() {
+ modules := mctx.CreateLocalVariations("rlib")
+ modules[0].(*Module).compiler.(libraryInterface).setRlib()
+ } else if library.buildDylib() {
+ modules := mctx.CreateLocalVariations("dylib")
+ modules[0].(*Module).compiler.(libraryInterface).setDylib()
+ }
+
+ if m.sourceProvider != nil {
+ // Alias the non-library variant to the empty-string variant.
+ mctx.AliasVariation("")
}
}
}
diff --git a/rust/prebuilt.go b/rust/prebuilt.go
index 67d649d..3d081c1 100644
--- a/rust/prebuilt.go
+++ b/rust/prebuilt.go
@@ -95,7 +95,10 @@
func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
prebuilt.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...)
- srcPath := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs())
+ srcPath, paths := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs())
+ if len(paths) > 0 {
+ ctx.PropertyErrorf("srcs", "prebuilt libraries can only have one entry in srcs (the prebuilt path)")
+ }
prebuilt.unstrippedOutputFile = srcPath
diff --git a/rust/proc_macro.go b/rust/proc_macro.go
index 2719161..3dd2521 100644
--- a/rust/proc_macro.go
+++ b/rust/proc_macro.go
@@ -65,7 +65,7 @@
fileName := procMacro.getStem(ctx) + ctx.toolchain().ProcMacroSuffix()
outputFile := android.PathForModuleOut(ctx, fileName)
- srcPath := srcPathFromModuleSrcs(ctx, procMacro.baseCompiler.Properties.Srcs)
+ srcPath, _ := srcPathFromModuleSrcs(ctx, procMacro.baseCompiler.Properties.Srcs)
procMacro.unstrippedOutputFile = outputFile
diff --git a/rust/project_json.go b/rust/project_json.go
index a50e73a..41dd194 100644
--- a/rust/project_json.go
+++ b/rust/project_json.go
@@ -92,7 +92,7 @@
// appendLibraryAndDeps creates a rustProjectCrate for the module argument and
// appends it to the rustProjectJson struct. It visits the dependencies of the
// module depth-first. If the current module is already in knownCrates, its
-// its dependencies are merged. Returns a tuple (id, crate_name, ok).
+// dependencies are merged. Returns a tuple (id, crate_name, ok).
func appendLibraryAndDeps(ctx android.SingletonContext, project *rustProjectJson,
knownCrates map[string]crateInfo, module android.Module) (int, string, bool) {
rModule, ok := module.(*Module)
@@ -111,12 +111,13 @@
// We have seen this crate already; merge any new dependencies.
crate := project.Crates[cInfo.ID]
mergeDependencies(ctx, project, knownCrates, module, &crate, cInfo.Deps)
+ project.Crates[cInfo.ID] = crate
return cInfo.ID, crateName, true
}
crate := rustProjectCrate{Deps: make([]rustProjectDep, 0), Cfgs: make([]string, 0)}
src := rustLib.baseCompiler.Properties.Srcs[0]
crate.RootModule = path.Join(ctx.ModuleDir(rModule), src)
- crate.Edition = getEdition(rustLib.baseCompiler)
+ crate.Edition = rustLib.baseCompiler.edition()
deps := make(map[string]int)
mergeDependencies(ctx, project, knownCrates, module, &crate, deps)
diff --git a/rust/rust.go b/rust/rust.go
index 72301a7..edfa5d8 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -42,6 +42,7 @@
ctx.BottomUp("rust_begin", BeginMutator).Parallel()
})
pctx.Import("android/soong/rust/config")
+ pctx.ImportAs("ccConfig", "android/soong/cc/config")
}
type Flags struct {
@@ -61,9 +62,11 @@
AndroidMkProcMacroLibs []string
AndroidMkSharedLibs []string
AndroidMkStaticLibs []string
- SubName string `blueprint:"mutated"`
- PreventInstall bool
- HideFromMake bool
+
+ SubName string `blueprint:"mutated"`
+
+ PreventInstall bool
+ HideFromMake bool
}
type Module struct {
@@ -79,8 +82,27 @@
coverage *coverage
clippy *clippy
cachedToolchain config.Toolchain
+ sourceProvider SourceProvider
subAndroidMkOnce map[subAndroidMkProvider]bool
- outputFile android.OptionalPath
+
+ outputFile android.OptionalPath
+ generatedFile android.OptionalPath
+}
+
+func (mod *Module) OutputFiles(tag string) (android.Paths, error) {
+ switch tag {
+ case "":
+ if mod.sourceProvider != nil {
+ return mod.sourceProvider.Srcs(), nil
+ } else {
+ if mod.outputFile.Valid() {
+ return android.Paths{mod.outputFile.Path()}, nil
+ }
+ return android.Paths{}, nil
+ }
+ default:
+ return nil, fmt.Errorf("unsupported module reference tag %q", tag)
+ }
}
var _ android.ImageInterface = (*Module)(nil)
@@ -120,12 +142,8 @@
func (mod *Module) NonCcVariants() bool {
if mod.compiler != nil {
- if library, ok := mod.compiler.(libraryInterface); ok {
- if library.buildRlib() || library.buildDylib() {
- return true
- } else {
- return false
- }
+ if _, ok := mod.compiler.(libraryInterface); ok {
+ return false
}
}
panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName()))
@@ -141,16 +159,16 @@
return library.static()
}
}
- panic(fmt.Errorf("Static called on non-library module: %q", mod.BaseModuleName()))
+ return false
}
func (mod *Module) Shared() bool {
if mod.compiler != nil {
if library, ok := mod.compiler.(libraryInterface); ok {
- return library.static()
+ return library.shared()
}
}
- panic(fmt.Errorf("Shared called on non-library module: %q", mod.BaseModuleName()))
+ return false
}
func (mod *Module) Toc() android.OptionalPath {
@@ -235,10 +253,18 @@
depFlags []string
//ReexportedDeps android.Paths
+ // Used by bindgen modules which call clang
+ depClangFlags []string
+ depIncludePaths android.Paths
+ depSystemIncludePaths android.Paths
+
coverageFiles android.Paths
CrtBegin android.OptionalPath
CrtEnd android.OptionalPath
+
+ // Paths to generated source files
+ SrcDeps android.Paths
}
type RustLibraries []RustLibrary
@@ -260,6 +286,9 @@
relativeInstallPath() string
nativeCoverage() bool
+
+ Disabled() bool
+ SetDisabled()
}
type exportedFlagsProducer interface {
@@ -345,6 +374,7 @@
&LibraryCompilerProperties{},
&ProcMacroCompilerProperties{},
&PrebuiltProperties{},
+ &SourceProviderProperties{},
&TestProperties{},
&cc.CoverageProperties{},
&ClippyProperties{},
@@ -369,7 +399,9 @@
func (mod *Module) CcLibraryInterface() bool {
if mod.compiler != nil {
- if _, ok := mod.compiler.(libraryInterface); ok {
+ // use build{Static,Shared}() instead of {static,shared}() here because this might be called before
+ // VariantIs{Static,Shared} is set.
+ if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) {
return true
}
}
@@ -504,6 +536,9 @@
if mod.clippy != nil {
mod.AddProperties(mod.clippy.props()...)
}
+ if mod.sourceProvider != nil {
+ mod.AddProperties(mod.sourceProvider.sourceProviderProps()...)
+ }
android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
@@ -636,10 +671,19 @@
flags, deps = mod.clippy.flags(ctx, flags, deps)
}
- if mod.compiler != nil {
+ // SourceProvider needs to call generateSource() before compiler calls compile() so it can provide the source.
+ // TODO(b/162588681) This shouldn't have to run for every variant.
+ if mod.sourceProvider != nil {
+ generatedFile := mod.sourceProvider.generateSource(ctx, deps)
+ mod.generatedFile = android.OptionalPathForPath(generatedFile)
+ mod.sourceProvider.setSubName(ctx.ModuleSubDir())
+ }
+
+ if mod.compiler != nil && !mod.compiler.Disabled() {
outputFile := mod.compiler.compile(ctx, flags, deps)
+
mod.outputFile = android.OptionalPathForPath(outputFile)
- if !mod.Properties.PreventInstall {
+ if mod.outputFile.Valid() && !mod.Properties.PreventInstall {
mod.compiler.install(ctx, mod.outputFile.Path())
}
}
@@ -651,6 +695,9 @@
if mod.compiler != nil {
deps = mod.compiler.compilerDeps(ctx, deps)
}
+ if mod.sourceProvider != nil {
+ deps = mod.sourceProvider.sourceProviderDeps(ctx, deps)
+ }
if mod.coverage != nil {
deps = mod.coverage.deps(ctx, deps)
@@ -675,10 +722,11 @@
}
var (
- rlibDepTag = dependencyTag{name: "rlibTag", library: true}
- dylibDepTag = dependencyTag{name: "dylib", library: true}
- procMacroDepTag = dependencyTag{name: "procMacro", proc_macro: true}
- testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
+ customBindgenDepTag = dependencyTag{name: "customBindgenTag"}
+ rlibDepTag = dependencyTag{name: "rlibTag", library: true}
+ dylibDepTag = dependencyTag{name: "dylib", library: true}
+ procMacroDepTag = dependencyTag{name: "procMacro", proc_macro: true}
+ testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
)
type autoDep struct {
@@ -709,18 +757,15 @@
directProcMacroDeps := []*Module{}
directSharedLibDeps := [](cc.LinkableInterface){}
directStaticLibDeps := [](cc.LinkableInterface){}
+ directSrcProvidersDeps := []*Module{}
+ directSrcDeps := [](android.SourceFileProducer){}
ctx.VisitDirectDeps(func(dep android.Module) {
depName := ctx.OtherModuleName(dep)
depTag := ctx.OtherModuleDependencyTag(dep)
- if rustDep, ok := dep.(*Module); ok {
+ if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() {
//Handle Rust Modules
- linkFile := rustDep.outputFile
- if !linkFile.Valid() {
- ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
- }
-
switch depTag {
case dylibDepTag:
dylib, ok := rustDep.compiler.(libraryInterface)
@@ -742,6 +787,24 @@
case procMacroDepTag:
directProcMacroDeps = append(directProcMacroDeps, rustDep)
mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, depName)
+ case android.SourceDepTag:
+ // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct
+ // OS/Arch variant is used.
+ var helper string
+ if ctx.Host() {
+ helper = "missing 'host_supported'?"
+ } else {
+ helper = "device module defined?"
+ }
+
+ if dep.Target().Os != ctx.Os() {
+ ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper)
+ return
+ } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
+ ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper)
+ return
+ }
+ directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep)
}
//Append the dependencies exportedDirs
@@ -751,15 +814,19 @@
}
if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
+ linkFile := rustDep.outputFile
+ if !linkFile.Valid() {
+ ctx.ModuleErrorf("Invalid output file when adding dep %q to %q",
+ depName, ctx.ModuleName())
+ return
+ }
linkDir := linkPathFromFilePath(linkFile.Path())
if lib, ok := mod.compiler.(exportedFlagsProducer); ok {
lib.exportLinkDirs(linkDir)
}
}
- }
-
- if ccDep, ok := dep.(cc.LinkableInterface); ok {
+ } else if ccDep, ok := dep.(cc.LinkableInterface); ok {
//Handle C dependencies
if _, ok := ccDep.(*Module); !ok {
if ccDep.Module().Target().Os != ctx.Os() {
@@ -771,7 +838,6 @@
return
}
}
-
linkFile := ccDep.OutputFile()
linkPath := linkPathFromFilePath(linkFile.Path())
libName := libNameFromFilePath(linkFile.Path())
@@ -782,24 +848,34 @@
}
exportDep := false
- switch depTag {
- case cc.StaticDepTag:
+ switch {
+ case cc.IsStaticDepTag(depTag):
depFlag = "-lstatic=" + libName
depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
depPaths.depFlags = append(depPaths.depFlags, depFlag)
+ depPaths.depIncludePaths = append(depPaths.depIncludePaths, ccDep.IncludeDirs()...)
+ if mod, ok := ccDep.(*cc.Module); ok {
+ depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, mod.ExportedSystemIncludeDirs()...)
+ depPaths.depClangFlags = append(depPaths.depClangFlags, mod.ExportedFlags()...)
+ }
depPaths.coverageFiles = append(depPaths.coverageFiles, ccDep.CoverageFiles()...)
directStaticLibDeps = append(directStaticLibDeps, ccDep)
mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, depName)
- case cc.SharedDepTag:
+ case cc.IsSharedDepTag(depTag):
depFlag = "-ldylib=" + libName
depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
depPaths.depFlags = append(depPaths.depFlags, depFlag)
+ depPaths.depIncludePaths = append(depPaths.depIncludePaths, ccDep.IncludeDirs()...)
+ if mod, ok := ccDep.(*cc.Module); ok {
+ depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, mod.ExportedSystemIncludeDirs()...)
+ depPaths.depClangFlags = append(depPaths.depClangFlags, mod.ExportedFlags()...)
+ }
directSharedLibDeps = append(directSharedLibDeps, ccDep)
mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName)
exportDep = true
- case cc.CrtBeginDepTag:
+ case depTag == cc.CrtBeginDepTag:
depPaths.CrtBegin = linkFile
- case cc.CrtEndDepTag:
+ case depTag == cc.CrtEndDepTag:
depPaths.CrtEnd = linkFile
}
@@ -809,6 +885,14 @@
lib.exportDepFlags(depFlag)
}
}
+
+ if srcDep, ok := dep.(android.SourceFileProducer); ok {
+ switch depTag {
+ case android.SourceDepTag:
+ // These are usually genrules which don't have per-target variants.
+ directSrcDeps = append(directSrcDeps, srcDep)
+ }
+ }
})
var rlibDepFiles RustLibraries
@@ -834,15 +918,29 @@
sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path())
}
+ var srcProviderDepFiles android.Paths
+ for _, dep := range directSrcProvidersDeps {
+ srcs, _ := dep.OutputFiles("")
+ srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
+ }
+ for _, dep := range directSrcDeps {
+ srcs := dep.Srcs()
+ srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
+ }
+
depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...)
depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...)
depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...)
depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...)
depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...)
+ depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...)
// Dedup exported flags from dependencies
depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
+ depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags)
+ depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)
+ depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths)
return depPaths
}
@@ -883,30 +981,27 @@
}
actx.AddVariationDependencies(
append(commonDepVariations, []blueprint.Variation{
- {Mutator: "rust_libraries", Variation: "rlib"},
- {Mutator: "link", Variation: ""}}...),
+ {Mutator: "rust_libraries", Variation: "rlib"}}...),
rlibDepTag, deps.Rlibs...)
actx.AddVariationDependencies(
append(commonDepVariations, []blueprint.Variation{
- {Mutator: "rust_libraries", Variation: "dylib"},
- {Mutator: "link", Variation: ""}}...),
+ {Mutator: "rust_libraries", Variation: "dylib"}}...),
dylibDepTag, deps.Dylibs...)
if deps.Rustlibs != nil {
autoDep := mod.compiler.(autoDeppable).autoDep()
actx.AddVariationDependencies(
append(commonDepVariations, []blueprint.Variation{
- {Mutator: "rust_libraries", Variation: autoDep.variation},
- {Mutator: "link", Variation: ""}}...),
+ {Mutator: "rust_libraries", Variation: autoDep.variation}}...),
autoDep.depTag, deps.Rustlibs...)
}
actx.AddVariationDependencies(append(commonDepVariations,
blueprint.Variation{Mutator: "link", Variation: "shared"}),
- cc.SharedDepTag, deps.SharedLibs...)
+ cc.SharedDepTag(), deps.SharedLibs...)
actx.AddVariationDependencies(append(commonDepVariations,
blueprint.Variation{Mutator: "link", Variation: "static"}),
- cc.StaticDepTag, deps.StaticLibs...)
+ cc.StaticDepTag(), deps.StaticLibs...)
if deps.CrtBegin != "" {
actx.AddVariationDependencies(commonDepVariations, cc.CrtBeginDepTag, deps.CrtBegin)
@@ -915,6 +1010,13 @@
actx.AddVariationDependencies(commonDepVariations, cc.CrtEndDepTag, deps.CrtEnd)
}
+ if mod.sourceProvider != nil {
+ if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok &&
+ bindgen.Properties.Custom_bindgen != "" {
+ actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag,
+ bindgen.Properties.Custom_bindgen)
+ }
+ }
// proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy.
actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
}
@@ -943,6 +1045,12 @@
return name
}
+func (mod *Module) setClippy(clippy bool) {
+ if mod.clippy != nil {
+ mod.clippy.Properties.Clippy = proptools.BoolPtr(clippy)
+ }
+}
+
var _ android.HostToolProvider = (*Module)(nil)
func (mod *Module) HostToolPath() android.OptionalPath {
@@ -959,3 +1067,5 @@
var BoolDefault = proptools.BoolDefault
var String = proptools.String
var StringPtr = proptools.StringPtr
+
+var _ android.OutputFileProducer = (*Module)(nil)
diff --git a/rust/rust_test.go b/rust/rust_test.go
index 08bc8ca..04de48b 100644
--- a/rust/rust_test.go
+++ b/rust/rust_test.go
@@ -61,6 +61,7 @@
"foo.rs": nil,
"foo.c": nil,
"src/bar.rs": nil,
+ "src/any.h": nil,
"liby.so": nil,
"libz.so": nil,
}
@@ -223,6 +224,114 @@
}
}
+func TestSourceProviderDeps(t *testing.T) {
+ ctx := testRust(t, `
+ rust_binary {
+ name: "fizz-buzz-dep",
+ srcs: [
+ "foo.rs",
+ ":my_generator",
+ ":libbindings",
+ ],
+ rlibs: ["libbindings"],
+ }
+ rust_proc_macro {
+ name: "libprocmacro",
+ srcs: [
+ "foo.rs",
+ ":my_generator",
+ ":libbindings",
+ ],
+ rlibs: ["libbindings"],
+ crate_name: "procmacro",
+ }
+ rust_library {
+ name: "libfoo",
+ srcs: [
+ "foo.rs",
+ ":my_generator",
+ ":libbindings",
+ ],
+ rlibs: ["libbindings"],
+ crate_name: "foo",
+ }
+ genrule {
+ name: "my_generator",
+ tools: ["any_rust_binary"],
+ cmd: "$(location) -o $(out) $(in)",
+ srcs: ["src/any.h"],
+ out: ["src/any.rs"],
+ }
+ rust_bindgen {
+ name: "libbindings",
+ crate_name: "bindings",
+ source_stem: "bindings",
+ host_supported: true,
+ wrapper_src: "src/any.h",
+ }
+ `)
+
+ libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib").Rule("rustc")
+ if !android.SuffixInList(libfoo.Implicits.Strings(), "/out/bindings.rs") {
+ t.Errorf("rust_bindgen generated source not included as implicit input for libfoo; Implicits %#v", libfoo.Implicits.Strings())
+ }
+ if !android.SuffixInList(libfoo.Implicits.Strings(), "/out/any.rs") {
+ t.Errorf("genrule generated source not included as implicit input for libfoo; Implicits %#v", libfoo.Implicits.Strings())
+ }
+
+ fizzBuzz := ctx.ModuleForTests("fizz-buzz-dep", "android_arm64_armv8-a").Rule("rustc")
+ if !android.SuffixInList(fizzBuzz.Implicits.Strings(), "/out/bindings.rs") {
+ t.Errorf("rust_bindgen generated source not included as implicit input for fizz-buzz-dep; Implicits %#v", libfoo.Implicits.Strings())
+ }
+ if !android.SuffixInList(fizzBuzz.Implicits.Strings(), "/out/any.rs") {
+ t.Errorf("genrule generated source not included as implicit input for fizz-buzz-dep; Implicits %#v", libfoo.Implicits.Strings())
+ }
+
+ libprocmacro := ctx.ModuleForTests("libprocmacro", "linux_glibc_x86_64").Rule("rustc")
+ if !android.SuffixInList(libprocmacro.Implicits.Strings(), "/out/bindings.rs") {
+ t.Errorf("rust_bindgen generated source not included as implicit input for libprocmacro; Implicits %#v", libfoo.Implicits.Strings())
+ }
+ if !android.SuffixInList(libprocmacro.Implicits.Strings(), "/out/any.rs") {
+ t.Errorf("genrule generated source not included as implicit input for libprocmacro; Implicits %#v", libfoo.Implicits.Strings())
+ }
+
+ // Check that our bindings are picked up as crate dependencies as well
+ libfooMod := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").Module().(*Module)
+ if !android.InList("libbindings", libfooMod.Properties.AndroidMkRlibs) {
+ t.Errorf("bindgen dependency not detected as a rlib dependency (dependency missing from AndroidMkRlibs)")
+ }
+ fizzBuzzMod := ctx.ModuleForTests("fizz-buzz-dep", "android_arm64_armv8-a").Module().(*Module)
+ if !android.InList("libbindings", fizzBuzzMod.Properties.AndroidMkRlibs) {
+ t.Errorf("bindgen dependency not detected as a rlib dependency (dependency missing from AndroidMkRlibs)")
+ }
+ libprocmacroMod := ctx.ModuleForTests("libprocmacro", "linux_glibc_x86_64").Module().(*Module)
+ if !android.InList("libbindings", libprocmacroMod.Properties.AndroidMkRlibs) {
+ t.Errorf("bindgen dependency not detected as a rlib dependency (dependency missing from AndroidMkRlibs)")
+ }
+
+}
+
+func TestSourceProviderTargetMismatch(t *testing.T) {
+ // This might error while building the dependency tree or when calling depsToPaths() depending on the lunched
+ // target, which results in two different errors. So don't check the error, just confirm there is one.
+ testRustError(t, ".*", `
+ rust_proc_macro {
+ name: "libprocmacro",
+ srcs: [
+ "foo.rs",
+ ":libbindings",
+ ],
+ crate_name: "procmacro",
+ }
+ rust_bindgen {
+ name: "libbindings",
+ crate_name: "bindings",
+ source_stem: "bindings",
+ wrapper_src: "src/any.h",
+ }
+ `)
+}
+
// Test to make sure proc_macros use host variants when building device modules.
func TestProcMacroDeviceDeps(t *testing.T) {
ctx := testRust(t, `
diff --git a/rust/source_provider.go b/rust/source_provider.go
new file mode 100644
index 0000000..503880f
--- /dev/null
+++ b/rust/source_provider.go
@@ -0,0 +1,80 @@
+// Copyright 2020 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 rust
+
+import (
+ "android/soong/android"
+)
+
+type SourceProviderProperties struct {
+ // filename for the generated source file (<source_stem>.rs). This field is required.
+ // The inherited "stem" property sets the output filename for the generated library variants only.
+ Source_stem *string `android:"arch_variant"`
+
+ // crate name, used for the library variant of this source provider. See additional details in rust_library.
+ Crate_name string `android:"arch_variant"`
+}
+
+type baseSourceProvider struct {
+ Properties SourceProviderProperties
+
+ outputFile android.Path
+ subAndroidMkOnce map[subAndroidMkProvider]bool
+ subName string
+}
+
+var _ SourceProvider = (*baseSourceProvider)(nil)
+
+type SourceProvider interface {
+ generateSource(ctx android.ModuleContext, deps PathDeps) android.Path
+ Srcs() android.Paths
+ sourceProviderProps() []interface{}
+ sourceProviderDeps(ctx DepsContext, deps Deps) Deps
+ setSubName(subName string)
+}
+
+func (sp *baseSourceProvider) Srcs() android.Paths {
+ return android.Paths{sp.outputFile}
+}
+
+func (sp *baseSourceProvider) generateSource(ctx android.ModuleContext, deps PathDeps) android.Path {
+ panic("baseSourceProviderModule does not implement generateSource()")
+}
+
+func (sp *baseSourceProvider) sourceProviderProps() []interface{} {
+ return []interface{}{&sp.Properties}
+}
+
+func NewSourceProvider() *baseSourceProvider {
+ return &baseSourceProvider{
+ Properties: SourceProviderProperties{},
+ }
+}
+
+func (sp *baseSourceProvider) getStem(ctx android.ModuleContext) string {
+ if String(sp.Properties.Source_stem) == "" {
+ ctx.PropertyErrorf("source_stem",
+ "source_stem property is undefined but required for rust_bindgen modules")
+ }
+ return String(sp.Properties.Source_stem)
+}
+
+func (sp *baseSourceProvider) sourceProviderDeps(ctx DepsContext, deps Deps) Deps {
+ return deps
+}
+
+func (sp *baseSourceProvider) setSubName(subName string) {
+ sp.subName = subName
+}
diff --git a/rust/source_provider_test.go b/rust/source_provider_test.go
new file mode 100644
index 0000000..6e68ae6
--- /dev/null
+++ b/rust/source_provider_test.go
@@ -0,0 +1,31 @@
+// Copyright 2020 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 rust
+
+import (
+ "testing"
+)
+
+var stemRequiredError = "source_stem property is undefined but required for rust_bindgen modules"
+
+func TestSourceProviderRequiredFields(t *testing.T) {
+ testRustError(t, stemRequiredError, `
+ rust_bindgen {
+ name: "libbindgen",
+ wrapper_src: "src/any.h",
+ crate_name: "bindgen",
+ }
+ `)
+}
diff --git a/rust/test.go b/rust/test.go
index e27a70c..05c361e 100644
--- a/rust/test.go
+++ b/rust/test.go
@@ -41,6 +41,9 @@
// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
// explicitly.
Auto_gen_config *bool
+
+ // if set, build with the standard Rust test harness. Defaults to true.
+ Test_harness *bool
}
// A test module is a binary module with extra --test compiler flag
@@ -56,6 +59,10 @@
return true
}
+func (test *testDecorator) testHarness() bool {
+ return BoolDefault(test.Properties.Test_harness, true)
+}
+
func NewRustTest(hod android.HostOrDeviceSupported) (*Module, *testDecorator) {
// Build both 32 and 64 targets for device tests.
// Cannot build both for host tests yet if the test depends on
@@ -101,7 +108,9 @@
func (test *testDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
flags = test.binaryDecorator.compilerFlags(ctx, flags)
- flags.RustFlags = append(flags.RustFlags, "--test")
+ if test.testHarness() {
+ flags.RustFlags = append(flags.RustFlags, "--test")
+ }
return flags
}
diff --git a/rust/testing.go b/rust/testing.go
index 3d583e1..83b2828 100644
--- a/rust/testing.go
+++ b/rust/testing.go
@@ -17,6 +17,7 @@
import (
"android/soong/android"
"android/soong/cc"
+ "android/soong/genrule"
)
func GatherRequiredDepsForTest() string {
@@ -76,9 +77,12 @@
func CreateTestContext() *android.TestContext {
ctx := android.NewTestArchContext()
+ android.RegisterPrebuiltMutators(ctx)
cc.RegisterRequiredBuildComponentsForTest(ctx)
+ ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
+ ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
ctx.RegisterModuleType("rust_test", RustTestFactory)
ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
ctx.RegisterModuleType("rust_library", RustLibraryFactory)
diff --git a/scripts/build-mainline-modules.sh b/scripts/build-mainline-modules.sh
index 1bc78e6..c5ec8d1 100755
--- a/scripts/build-mainline-modules.sh
+++ b/scripts/build-mainline-modules.sh
@@ -24,7 +24,7 @@
i18n-module-test-exports
i18n-module-sdk
platform-mainline-sdk
- platform-mainline-host-exports
+ platform-mainline-test-exports
)
# List of libraries installed on the platform that are needed for ART chroot
@@ -52,6 +52,13 @@
"$@"
}
+lib_dir() {
+ case $1 in
+ (aosp_arm|aosp_x86) echo "lib";;
+ (aosp_arm64|aosp_x86_64) echo "lib64";;
+ esac
+}
+
OUT_DIR=$(source build/envsetup.sh > /dev/null; TARGET_PRODUCT= get_build_var OUT_DIR)
DIST_DIR=$(source build/envsetup.sh > /dev/null; TARGET_PRODUCT= get_build_var DIST_DIR)
@@ -69,7 +76,8 @@
echo_and_run cp ${PWD}/${PRODUCT_OUT}/system/apex/${module}.apex ${DIST_DIR}/${TARGET_ARCH}/
done
for library in "${PLATFORM_LIBRARIES[@]}"; do
- echo_and_run cp ${PWD}/${PRODUCT_OUT}/system/lib/${library}.so ${DIST_DIR}/${TARGET_ARCH}/
+ libdir=$(lib_dir $product)
+ echo_and_run cp ${PWD}/${PRODUCT_OUT}/system/${libdir}/${library}.so ${DIST_DIR}/${TARGET_ARCH}/
done
done
diff --git a/sdk/cc_sdk_test.go b/sdk/cc_sdk_test.go
index c59cd30..9501d88 100644
--- a/sdk/cc_sdk_test.go
+++ b/sdk/cc_sdk_test.go
@@ -21,24 +21,38 @@
"android/soong/cc"
)
+var ccTestFs = map[string][]byte{
+ "Test.cpp": nil,
+ "include/Test.h": nil,
+ "include-android/AndroidTest.h": nil,
+ "include-host/HostTest.h": nil,
+ "arm64/include/Arm64Test.h": nil,
+ "libfoo.so": nil,
+ "aidl/foo/bar/Test.aidl": nil,
+ "some/where/stubslib.map.txt": nil,
+}
+
func testSdkWithCc(t *testing.T, bp string) *testSdkResult {
t.Helper()
-
- fs := map[string][]byte{
- "Test.cpp": nil,
- "include/Test.h": nil,
- "include-android/AndroidTest.h": nil,
- "include-host/HostTest.h": nil,
- "arm64/include/Arm64Test.h": nil,
- "libfoo.so": nil,
- "aidl/foo/bar/Test.aidl": nil,
- "some/where/stubslib.map.txt": nil,
- }
- return testSdkWithFs(t, bp, fs)
+ return testSdkWithFs(t, bp, ccTestFs)
}
// Contains tests for SDK members provided by the cc package.
+func TestSingleDeviceOsAssumption(t *testing.T) {
+ // Mock a module with DeviceSupported() == true.
+ s := &sdk{}
+ android.InitAndroidArchModule(s, android.DeviceSupported, android.MultilibCommon)
+
+ osTypes := s.getPossibleOsTypes()
+ if len(osTypes) != 1 {
+ // The snapshot generation assumes there is a single device OS. If more are
+ // added it might need to disable them by default, like it does for host
+ // OS'es.
+ t.Errorf("expected a single device OS, got %v", osTypes)
+ }
+}
+
func TestSdkIsCompileMultilibBoth(t *testing.T) {
result := testSdkWithCc(t, `
sdk {
@@ -73,12 +87,14 @@
result := testSdkWithCc(t, `
sdk {
name: "mysdk",
+ host_supported: true,
native_shared_libs: ["sdkmember"],
compile_multilib: "64",
}
cc_library_shared {
name: "sdkmember",
+ host_supported: true,
srcs: ["Test.cpp"],
stl: "none",
compile_multilib: "64",
@@ -86,8 +102,72 @@
`)
result.CheckSnapshot("mysdk", "",
+ checkAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+cc_prebuilt_library_shared {
+ name: "mysdk_sdkmember@current",
+ sdk_member_name: "sdkmember",
+ host_supported: true,
+ installable: false,
+ stl: "none",
+ compile_multilib: "64",
+ target: {
+ host: {
+ enabled: false,
+ },
+ android_arm64: {
+ srcs: ["android/arm64/lib/sdkmember.so"],
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ linux_glibc_x86_64: {
+ srcs: ["linux_glibc/x86_64/lib/sdkmember.so"],
+ },
+ },
+}
+
+cc_prebuilt_library_shared {
+ name: "sdkmember",
+ prefer: false,
+ host_supported: true,
+ stl: "none",
+ compile_multilib: "64",
+ target: {
+ host: {
+ enabled: false,
+ },
+ android_arm64: {
+ srcs: ["android/arm64/lib/sdkmember.so"],
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ linux_glibc_x86_64: {
+ srcs: ["linux_glibc/x86_64/lib/sdkmember.so"],
+ },
+ },
+}
+
+sdk_snapshot {
+ name: "mysdk@current",
+ host_supported: true,
+ native_shared_libs: ["mysdk_sdkmember@current"],
+ compile_multilib: "64",
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ },
+}
+`),
checkAllCopyRules(`
-.intermediates/sdkmember/android_arm64_armv8-a_shared/sdkmember.so -> arm64/lib/sdkmember.so
+.intermediates/sdkmember/android_arm64_armv8-a_shared/sdkmember.so -> android/arm64/lib/sdkmember.so
+.intermediates/sdkmember/linux_glibc_x86_64_shared/sdkmember.so -> linux_glibc/x86_64/lib/sdkmember.so
`))
}
@@ -271,6 +351,7 @@
name: "mysdk_crtobj@current",
sdk_member_name: "crtobj",
stl: "none",
+ compile_multilib: "both",
arch: {
arm64: {
srcs: ["arm64/lib/crtobj.o"],
@@ -285,6 +366,7 @@
name: "crtobj",
prefer: false,
stl: "none",
+ compile_multilib: "both",
arch: {
arm64: {
srcs: ["arm64/lib/crtobj.o"],
@@ -378,6 +460,7 @@
sdk_member_name: "mynativelib",
installable: false,
stl: "none",
+ compile_multilib: "both",
export_include_dirs: ["include/include"],
arch: {
arm64: {
@@ -394,6 +477,7 @@
name: "mynativelib",
prefer: false,
stl: "none",
+ compile_multilib: "both",
export_include_dirs: ["include/include"],
arch: {
arm64: {
@@ -481,9 +565,6 @@
}
func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithCc(t, `
module_exports {
name: "myexports",
@@ -526,7 +607,11 @@
installable: false,
stl: "none",
target: {
+ host: {
+ enabled: false,
+ },
linux_glibc: {
+ enabled: true,
compile_multilib: "both",
},
linux_glibc_x86_64: {
@@ -536,6 +621,7 @@
srcs: ["linux_glibc/x86/bin/mynativebinary"],
},
windows: {
+ enabled: true,
compile_multilib: "64",
},
windows_x86_64: {
@@ -551,7 +637,11 @@
host_supported: true,
stl: "none",
target: {
+ host: {
+ enabled: false,
+ },
linux_glibc: {
+ enabled: true,
compile_multilib: "both",
},
linux_glibc_x86_64: {
@@ -561,6 +651,7 @@
srcs: ["linux_glibc/x86/bin/mynativebinary"],
},
windows: {
+ enabled: true,
compile_multilib: "64",
},
windows_x86_64: {
@@ -575,7 +666,14 @@
host_supported: true,
native_binaries: ["myexports_mynativebinary@current"],
target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
windows: {
+ enabled: true,
compile_multilib: "64",
},
},
@@ -589,12 +687,165 @@
)
}
+func TestSnapshotWithSingleHostOsType(t *testing.T) {
+ ctx, config := testSdkContext(`
+ cc_defaults {
+ name: "mydefaults",
+ device_supported: false,
+ host_supported: true,
+ compile_multilib: "64",
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_bionic: {
+ enabled: true,
+ },
+ },
+ }
+
+ module_exports {
+ name: "myexports",
+ defaults: ["mydefaults"],
+ native_shared_libs: ["mynativelib"],
+ native_binaries: ["mynativebinary"],
+ compile_multilib: "64", // The built-in default in sdk.go overrides mydefaults.
+ }
+
+ cc_library {
+ name: "mynativelib",
+ defaults: ["mydefaults"],
+ srcs: [
+ "Test.cpp",
+ ],
+ stl: "none",
+ }
+
+ cc_binary {
+ name: "mynativebinary",
+ defaults: ["mydefaults"],
+ srcs: [
+ "Test.cpp",
+ ],
+ stl: "none",
+ }
+ `, ccTestFs, []android.OsType{android.LinuxBionic})
+
+ result := runTests(t, ctx, config)
+
+ result.CheckSnapshot("myexports", "",
+ checkAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+cc_prebuilt_binary {
+ name: "myexports_mynativebinary@current",
+ sdk_member_name: "mynativebinary",
+ device_supported: false,
+ host_supported: true,
+ installable: false,
+ stl: "none",
+ compile_multilib: "64",
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_bionic: {
+ enabled: true,
+ },
+ linux_bionic_x86_64: {
+ srcs: ["x86_64/bin/mynativebinary"],
+ },
+ },
+}
+
+cc_prebuilt_binary {
+ name: "mynativebinary",
+ prefer: false,
+ device_supported: false,
+ host_supported: true,
+ stl: "none",
+ compile_multilib: "64",
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_bionic: {
+ enabled: true,
+ },
+ linux_bionic_x86_64: {
+ srcs: ["x86_64/bin/mynativebinary"],
+ },
+ },
+}
+
+cc_prebuilt_library_shared {
+ name: "myexports_mynativelib@current",
+ sdk_member_name: "mynativelib",
+ device_supported: false,
+ host_supported: true,
+ installable: false,
+ stl: "none",
+ compile_multilib: "64",
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_bionic: {
+ enabled: true,
+ },
+ linux_bionic_x86_64: {
+ srcs: ["x86_64/lib/mynativelib.so"],
+ },
+ },
+}
+
+cc_prebuilt_library_shared {
+ name: "mynativelib",
+ prefer: false,
+ device_supported: false,
+ host_supported: true,
+ stl: "none",
+ compile_multilib: "64",
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_bionic: {
+ enabled: true,
+ },
+ linux_bionic_x86_64: {
+ srcs: ["x86_64/lib/mynativelib.so"],
+ },
+ },
+}
+
+module_exports_snapshot {
+ name: "myexports@current",
+ device_supported: false,
+ host_supported: true,
+ native_binaries: ["myexports_mynativebinary@current"],
+ native_shared_libs: ["myexports_mynativelib@current"],
+ compile_multilib: "64",
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_bionic: {
+ enabled: true,
+ },
+ },
+}
+`),
+ checkAllCopyRules(`
+.intermediates/mynativebinary/linux_bionic_x86_64/mynativebinary -> x86_64/bin/mynativebinary
+.intermediates/mynativelib/linux_bionic_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
+`),
+ )
+}
+
// Test that we support the necessary flags for the linker binary, which is
// special in several ways.
func TestSnapshotWithCcStaticNocrtBinary(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithCc(t, `
module_exports {
name: "mymodule_exports",
@@ -627,14 +878,20 @@
host_supported: true,
installable: false,
stl: "none",
+ compile_multilib: "both",
static_executable: true,
nocrt: true,
- compile_multilib: "both",
- arch: {
- x86_64: {
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ linux_glibc_x86_64: {
srcs: ["x86_64/bin/linker"],
},
- x86: {
+ linux_glibc_x86: {
srcs: ["x86/bin/linker"],
},
},
@@ -646,14 +903,20 @@
device_supported: false,
host_supported: true,
stl: "none",
+ compile_multilib: "both",
static_executable: true,
nocrt: true,
- compile_multilib: "both",
- arch: {
- x86_64: {
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ linux_glibc_x86_64: {
srcs: ["x86_64/bin/linker"],
},
- x86: {
+ linux_glibc_x86: {
srcs: ["x86/bin/linker"],
},
},
@@ -664,6 +927,14 @@
device_supported: false,
host_supported: true,
native_binaries: ["mymodule_exports_linker@current"],
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ },
}
`),
checkAllCopyRules(`
@@ -708,6 +979,7 @@
],
installable: false,
stl: "none",
+ compile_multilib: "both",
export_include_dirs: ["include/include"],
arch: {
arm64: {
@@ -729,6 +1001,7 @@
"apex2",
],
stl: "none",
+ compile_multilib: "both",
export_include_dirs: ["include/include"],
arch: {
arm64: {
@@ -830,6 +1103,7 @@
sdk_member_name: "mynativelib",
installable: false,
stl: "none",
+ compile_multilib: "both",
shared_libs: [
"mysdk_myothernativelib@current",
"libc",
@@ -848,6 +1122,7 @@
name: "mynativelib",
prefer: false,
stl: "none",
+ compile_multilib: "both",
shared_libs: [
"myothernativelib",
"libc",
@@ -867,6 +1142,7 @@
sdk_member_name: "myothernativelib",
installable: false,
stl: "none",
+ compile_multilib: "both",
system_shared_libs: ["libm"],
arch: {
arm64: {
@@ -882,6 +1158,7 @@
name: "myothernativelib",
prefer: false,
stl: "none",
+ compile_multilib: "both",
system_shared_libs: ["libm"],
arch: {
arm64: {
@@ -898,6 +1175,7 @@
sdk_member_name: "mysystemnativelib",
installable: false,
stl: "none",
+ compile_multilib: "both",
arch: {
arm64: {
srcs: ["arm64/lib/mysystemnativelib.so"],
@@ -912,6 +1190,7 @@
name: "mysystemnativelib",
prefer: false,
stl: "none",
+ compile_multilib: "both",
arch: {
arm64: {
srcs: ["arm64/lib/mysystemnativelib.so"],
@@ -943,9 +1222,6 @@
}
func TestHostSnapshotWithCcSharedLibrary(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithCc(t, `
sdk {
name: "mysdk",
@@ -983,13 +1259,20 @@
installable: false,
sdk_version: "minimum",
stl: "none",
+ compile_multilib: "both",
export_include_dirs: ["include/include"],
- arch: {
- x86_64: {
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ linux_glibc_x86_64: {
srcs: ["x86_64/lib/mynativelib.so"],
export_include_dirs: ["x86_64/include_gen/mynativelib"],
},
- x86: {
+ linux_glibc_x86: {
srcs: ["x86/lib/mynativelib.so"],
export_include_dirs: ["x86/include_gen/mynativelib"],
},
@@ -1003,13 +1286,20 @@
host_supported: true,
sdk_version: "minimum",
stl: "none",
+ compile_multilib: "both",
export_include_dirs: ["include/include"],
- arch: {
- x86_64: {
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ linux_glibc_x86_64: {
srcs: ["x86_64/lib/mynativelib.so"],
export_include_dirs: ["x86_64/include_gen/mynativelib"],
},
- x86: {
+ linux_glibc_x86: {
srcs: ["x86/lib/mynativelib.so"],
export_include_dirs: ["x86/include_gen/mynativelib"],
},
@@ -1021,6 +1311,14 @@
device_supported: false,
host_supported: true,
native_shared_libs: ["mysdk_mynativelib@current"],
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ },
}
`),
checkAllCopyRules(`
@@ -1038,9 +1336,6 @@
}
func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithCc(t, `
sdk {
name: "mysdk",
@@ -1082,12 +1377,23 @@
installable: false,
stl: "none",
target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ compile_multilib: "both",
+ },
linux_glibc_x86_64: {
srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
},
linux_glibc_x86: {
srcs: ["linux_glibc/x86/lib/mynativelib.so"],
},
+ windows: {
+ enabled: true,
+ compile_multilib: "64",
+ },
windows_x86_64: {
srcs: ["windows/x86_64/lib/mynativelib.dll"],
},
@@ -1101,12 +1407,23 @@
host_supported: true,
stl: "none",
target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ compile_multilib: "both",
+ },
linux_glibc_x86_64: {
srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
},
linux_glibc_x86: {
srcs: ["linux_glibc/x86/lib/mynativelib.so"],
},
+ windows: {
+ enabled: true,
+ compile_multilib: "64",
+ },
windows_x86_64: {
srcs: ["windows/x86_64/lib/mynativelib.dll"],
},
@@ -1119,7 +1436,14 @@
host_supported: true,
native_shared_libs: ["mysdk_mynativelib@current"],
target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
windows: {
+ enabled: true,
compile_multilib: "64",
},
},
@@ -1163,6 +1487,7 @@
sdk_member_name: "mynativelib",
installable: false,
stl: "none",
+ compile_multilib: "both",
export_include_dirs: ["include/include"],
arch: {
arm64: {
@@ -1180,6 +1505,7 @@
name: "mynativelib",
prefer: false,
stl: "none",
+ compile_multilib: "both",
export_include_dirs: ["include/include"],
arch: {
arm64: {
@@ -1213,9 +1539,6 @@
}
func TestHostSnapshotWithCcStaticLibrary(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithCc(t, `
module_exports {
name: "myexports",
@@ -1251,13 +1574,20 @@
host_supported: true,
installable: false,
stl: "none",
+ compile_multilib: "both",
export_include_dirs: ["include/include"],
- arch: {
- x86_64: {
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ linux_glibc_x86_64: {
srcs: ["x86_64/lib/mynativelib.a"],
export_include_dirs: ["x86_64/include_gen/mynativelib"],
},
- x86: {
+ linux_glibc_x86: {
srcs: ["x86/lib/mynativelib.a"],
export_include_dirs: ["x86/include_gen/mynativelib"],
},
@@ -1270,13 +1600,20 @@
device_supported: false,
host_supported: true,
stl: "none",
+ compile_multilib: "both",
export_include_dirs: ["include/include"],
- arch: {
- x86_64: {
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ linux_glibc_x86_64: {
srcs: ["x86_64/lib/mynativelib.a"],
export_include_dirs: ["x86_64/include_gen/mynativelib"],
},
- x86: {
+ linux_glibc_x86: {
srcs: ["x86/lib/mynativelib.a"],
export_include_dirs: ["x86/include_gen/mynativelib"],
},
@@ -1288,6 +1625,14 @@
device_supported: false,
host_supported: true,
native_static_libs: ["myexports_mynativelib@current"],
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ },
}
`),
checkAllCopyRules(`
@@ -1330,6 +1675,7 @@
sdk_member_name: "mynativelib",
installable: false,
stl: "none",
+ compile_multilib: "both",
export_include_dirs: ["include/include"],
arch: {
arm64: {
@@ -1355,6 +1701,7 @@
name: "mynativelib",
prefer: false,
stl: "none",
+ compile_multilib: "both",
export_include_dirs: ["include/include"],
arch: {
arm64: {
@@ -1391,9 +1738,6 @@
}
func TestHostSnapshotWithMultiLib64(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithCc(t, `
module_exports {
name: "myexports",
@@ -1434,9 +1778,16 @@
host_supported: true,
installable: false,
stl: "none",
+ compile_multilib: "64",
export_include_dirs: ["include/include"],
- arch: {
- x86_64: {
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ linux_glibc_x86_64: {
srcs: ["x86_64/lib/mynativelib.a"],
export_include_dirs: ["x86_64/include_gen/mynativelib"],
},
@@ -1449,9 +1800,16 @@
device_supported: false,
host_supported: true,
stl: "none",
+ compile_multilib: "64",
export_include_dirs: ["include/include"],
- arch: {
- x86_64: {
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ linux_glibc_x86_64: {
srcs: ["x86_64/lib/mynativelib.a"],
export_include_dirs: ["x86_64/include_gen/mynativelib"],
},
@@ -1463,9 +1821,13 @@
device_supported: false,
host_supported: true,
native_static_libs: ["myexports_mynativelib@current"],
+ compile_multilib: "64",
target: {
+ host: {
+ enabled: false,
+ },
linux_glibc: {
- compile_multilib: "64",
+ enabled: true,
},
},
}`),
@@ -1501,6 +1863,7 @@
name: "mysdk_mynativeheaders@current",
sdk_member_name: "mynativeheaders",
stl: "none",
+ compile_multilib: "both",
export_include_dirs: ["include/include"],
}
@@ -1508,6 +1871,7 @@
name: "mynativeheaders",
prefer: false,
stl: "none",
+ compile_multilib: "both",
export_include_dirs: ["include/include"],
}
@@ -1523,9 +1887,6 @@
}
func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithCc(t, `
sdk {
name: "mysdk",
@@ -1553,7 +1914,16 @@
device_supported: false,
host_supported: true,
stl: "none",
+ compile_multilib: "both",
export_include_dirs: ["include/include"],
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ },
}
cc_prebuilt_library_headers {
@@ -1562,7 +1932,16 @@
device_supported: false,
host_supported: true,
stl: "none",
+ compile_multilib: "both",
export_include_dirs: ["include/include"],
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ },
}
sdk_snapshot {
@@ -1570,6 +1949,14 @@
device_supported: false,
host_supported: true,
native_header_libs: ["mysdk_mynativeheaders@current"],
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ },
}
`),
checkAllCopyRules(`
@@ -1579,9 +1966,6 @@
}
func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithCc(t, `
sdk {
name: "mysdk",
@@ -1614,13 +1998,18 @@
sdk_member_name: "mynativeheaders",
host_supported: true,
stl: "none",
- export_system_include_dirs: ["include/include"],
+ compile_multilib: "both",
+ export_system_include_dirs: ["common_os/include/include"],
target: {
+ host: {
+ enabled: false,
+ },
android: {
- export_include_dirs: ["include/include-android"],
+ export_include_dirs: ["android/include/include-android"],
},
linux_glibc: {
- export_include_dirs: ["include/include-host"],
+ enabled: true,
+ export_include_dirs: ["linux_glibc/include/include-host"],
},
},
}
@@ -1630,13 +2019,18 @@
prefer: false,
host_supported: true,
stl: "none",
- export_system_include_dirs: ["include/include"],
+ compile_multilib: "both",
+ export_system_include_dirs: ["common_os/include/include"],
target: {
+ host: {
+ enabled: false,
+ },
android: {
- export_include_dirs: ["include/include-android"],
+ export_include_dirs: ["android/include/include-android"],
},
linux_glibc: {
- export_include_dirs: ["include/include-host"],
+ enabled: true,
+ export_include_dirs: ["linux_glibc/include/include-host"],
},
},
}
@@ -1645,20 +2039,25 @@
name: "mysdk@current",
host_supported: true,
native_header_libs: ["mysdk_mynativeheaders@current"],
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ },
}
`),
checkAllCopyRules(`
-include/Test.h -> include/include/Test.h
-include-android/AndroidTest.h -> include/include-android/AndroidTest.h
-include-host/HostTest.h -> include/include-host/HostTest.h
+include/Test.h -> common_os/include/include/Test.h
+include-android/AndroidTest.h -> android/include/include-android/AndroidTest.h
+include-host/HostTest.h -> linux_glibc/include/include-host/HostTest.h
`),
)
}
func TestSystemSharedLibPropagation(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithCc(t, `
sdk {
name: "mysdk",
@@ -1689,6 +2088,7 @@
name: "mysdk_sslnil@current",
sdk_member_name: "sslnil",
installable: false,
+ compile_multilib: "both",
arch: {
arm64: {
srcs: ["arm64/lib/sslnil.so"],
@@ -1702,6 +2102,7 @@
cc_prebuilt_library_shared {
name: "sslnil",
prefer: false,
+ compile_multilib: "both",
arch: {
arm64: {
srcs: ["arm64/lib/sslnil.so"],
@@ -1716,6 +2117,7 @@
name: "mysdk_sslempty@current",
sdk_member_name: "sslempty",
installable: false,
+ compile_multilib: "both",
system_shared_libs: [],
arch: {
arm64: {
@@ -1730,6 +2132,7 @@
cc_prebuilt_library_shared {
name: "sslempty",
prefer: false,
+ compile_multilib: "both",
system_shared_libs: [],
arch: {
arm64: {
@@ -1745,6 +2148,7 @@
name: "mysdk_sslnonempty@current",
sdk_member_name: "sslnonempty",
installable: false,
+ compile_multilib: "both",
system_shared_libs: ["mysdk_sslnil@current"],
arch: {
arm64: {
@@ -1759,6 +2163,7 @@
cc_prebuilt_library_shared {
name: "sslnonempty",
prefer: false,
+ compile_multilib: "both",
system_shared_libs: ["sslnil"],
arch: {
arm64: {
@@ -1807,7 +2212,11 @@
sdk_member_name: "sslvariants",
host_supported: true,
installable: false,
+ compile_multilib: "both",
target: {
+ host: {
+ enabled: false,
+ },
android: {
system_shared_libs: [],
},
@@ -1817,6 +2226,9 @@
android_arm: {
srcs: ["android/arm/lib/sslvariants.so"],
},
+ linux_glibc: {
+ enabled: true,
+ },
linux_glibc_x86_64: {
srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
},
@@ -1830,7 +2242,11 @@
name: "sslvariants",
prefer: false,
host_supported: true,
+ compile_multilib: "both",
target: {
+ host: {
+ enabled: false,
+ },
android: {
system_shared_libs: [],
},
@@ -1840,6 +2256,9 @@
android_arm: {
srcs: ["android/arm/lib/sslvariants.so"],
},
+ linux_glibc: {
+ enabled: true,
+ },
linux_glibc_x86_64: {
srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
},
@@ -1853,6 +2272,14 @@
name: "mysdk@current",
host_supported: true,
native_shared_libs: ["mysdk_sslvariants@current"],
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ },
}
`))
}
@@ -1886,6 +2313,7 @@
name: "mysdk_stubslib@current",
sdk_member_name: "stubslib",
installable: false,
+ compile_multilib: "both",
stubs: {
versions: ["3"],
},
@@ -1902,6 +2330,7 @@
cc_prebuilt_library_shared {
name: "stubslib",
prefer: false,
+ compile_multilib: "both",
stubs: {
versions: ["3"],
},
@@ -1923,9 +2352,6 @@
}
func TestDeviceAndHostSnapshotWithStubsLibrary(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithCc(t, `
sdk {
name: "mysdk",
@@ -1958,16 +2384,23 @@
sdk_member_name: "stubslib",
host_supported: true,
installable: false,
+ compile_multilib: "both",
stubs: {
versions: ["3"],
},
target: {
+ host: {
+ enabled: false,
+ },
android_arm64: {
srcs: ["android/arm64/lib/stubslib.so"],
},
android_arm: {
srcs: ["android/arm/lib/stubslib.so"],
},
+ linux_glibc: {
+ enabled: true,
+ },
linux_glibc_x86_64: {
srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
},
@@ -1981,16 +2414,23 @@
name: "stubslib",
prefer: false,
host_supported: true,
+ compile_multilib: "both",
stubs: {
versions: ["3"],
},
target: {
+ host: {
+ enabled: false,
+ },
android_arm64: {
srcs: ["android/arm64/lib/stubslib.so"],
},
android_arm: {
srcs: ["android/arm/lib/stubslib.so"],
},
+ linux_glibc: {
+ enabled: true,
+ },
linux_glibc_x86_64: {
srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
},
@@ -2004,14 +2444,19 @@
name: "mysdk@current",
host_supported: true,
native_shared_libs: ["mysdk_stubslib@current"],
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ },
}
`))
}
func TestUniqueHostSoname(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithCc(t, `
sdk {
name: "mysdk",
@@ -2036,13 +2481,20 @@
host_supported: true,
installable: false,
unique_host_soname: true,
+ compile_multilib: "both",
target: {
+ host: {
+ enabled: false,
+ },
android_arm64: {
srcs: ["android/arm64/lib/mylib.so"],
},
android_arm: {
srcs: ["android/arm/lib/mylib.so"],
},
+ linux_glibc: {
+ enabled: true,
+ },
linux_glibc_x86_64: {
srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
},
@@ -2057,13 +2509,20 @@
prefer: false,
host_supported: true,
unique_host_soname: true,
+ compile_multilib: "both",
target: {
+ host: {
+ enabled: false,
+ },
android_arm64: {
srcs: ["android/arm64/lib/mylib.so"],
},
android_arm: {
srcs: ["android/arm/lib/mylib.so"],
},
+ linux_glibc: {
+ enabled: true,
+ },
linux_glibc_x86_64: {
srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
},
@@ -2077,6 +2536,14 @@
name: "mysdk@current",
host_supported: true,
native_shared_libs: ["mysdk_mylib@current"],
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_glibc: {
+ enabled: true,
+ },
+ },
}
`),
checkAllCopyRules(`
diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go
index 79da3f0..931ca3c 100644
--- a/sdk/java_sdk_test.go
+++ b/sdk/java_sdk_test.go
@@ -51,10 +51,10 @@
name: "core-current-stubs-system-modules",
}
java_system_modules_import {
- name: "legacy-core-platform-api-stubs-system-modules",
+ name: "stable-core-platform-api-stubs-system-modules",
}
java_import {
- name: "legacy.core.platform.api.stubs",
+ name: "stable.core.platform.api.stubs",
}
java_import {
name: "android_stubs_current",
@@ -204,8 +204,8 @@
}
`)
- sdkMemberV1 := result.ctx.ModuleForTests("sdkmember_mysdk_1", "android_common_myapex").Rule("combineJar").Output
- sdkMemberV2 := result.ctx.ModuleForTests("sdkmember_mysdk_2", "android_common_myapex2").Rule("combineJar").Output
+ sdkMemberV1 := result.ctx.ModuleForTests("sdkmember_mysdk_1", "android_common").Rule("combineJar").Output
+ sdkMemberV2 := result.ctx.ModuleForTests("sdkmember_mysdk_2", "android_common").Rule("combineJar").Output
javalibForMyApex := result.ctx.ModuleForTests("myjavalib", "android_common_myapex")
javalibForMyApex2 := result.ctx.ModuleForTests("myjavalib", "android_common_myapex2")
@@ -265,9 +265,6 @@
}
func TestHostSnapshotWithJavaHeaderLibrary(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithJava(t, `
sdk {
name: "mysdk",
@@ -325,9 +322,6 @@
}
func TestDeviceAndHostSnapshotWithJavaHeaderLibrary(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithJava(t, `
sdk {
name: "mysdk",
@@ -441,9 +435,6 @@
}
func TestHostSnapshotWithJavaImplLibrary(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithJava(t, `
module_exports {
name: "myexports",
@@ -548,9 +539,6 @@
}
func TestHostSnapshotWithJavaTest(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithJava(t, `
module_exports {
name: "myexports",
@@ -692,9 +680,6 @@
}
func TestHostSnapshotWithDroidstubs(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithDroidstubs(t, `
module_exports {
name: "myexports",
@@ -835,9 +820,6 @@
}
func TestHostSnapshotWithJavaSystemModules(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithJava(t, `
sdk {
name: "mysdk",
@@ -913,9 +895,6 @@
}
func TestDeviceAndHostSnapshotWithOsSpecificMembers(t *testing.T) {
- // b/145598135 - Generating host snapshots for anything other than linux is not supported.
- SkipIfNotLinux(t)
-
result := testSdkWithJava(t, `
module_exports {
name: "myexports",
@@ -1445,8 +1424,8 @@
.intermediates/myjavalib.stubs.source.system/android_common/myjavalib.stubs.source.system_api.txt -> sdk_library/system/myjavalib.txt
.intermediates/myjavalib.stubs.source.system/android_common/myjavalib.stubs.source.system_removed.txt -> sdk_library/system/myjavalib-removed.txt
.intermediates/myjavalib.stubs.module_lib/android_common/javac/myjavalib.stubs.module_lib.jar -> sdk_library/module-lib/myjavalib-stubs.jar
-.intermediates/myjavalib.api.module_lib/android_common/myjavalib.api.module_lib_api.txt -> sdk_library/module-lib/myjavalib.txt
-.intermediates/myjavalib.api.module_lib/android_common/myjavalib.api.module_lib_removed.txt -> sdk_library/module-lib/myjavalib-removed.txt
+.intermediates/myjavalib.stubs.source.module_lib/android_common/myjavalib.stubs.source.module_lib_api.txt -> sdk_library/module-lib/myjavalib.txt
+.intermediates/myjavalib.stubs.source.module_lib/android_common/myjavalib.stubs.source.module_lib_removed.txt -> sdk_library/module-lib/myjavalib-removed.txt
`),
checkMergeZips(
".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip",
diff --git a/sdk/sdk.go b/sdk/sdk.go
index 3e76008..7591020 100644
--- a/sdk/sdk.go
+++ b/sdk/sdk.go
@@ -406,13 +406,17 @@
// Step 4: transitively ripple down the SDK requirements from the root modules like APEX to its
// descendants
func sdkDepsMutator(mctx android.TopDownMutatorContext) {
- if m, ok := mctx.Module().(android.SdkAware); ok {
+ if parent, ok := mctx.Module().(interface {
+ android.DepIsInSameApex
+ android.RequiredSdks
+ }); ok {
// Module types for Mainline modules (e.g. APEX) are expected to implement RequiredSdks()
// by reading its own properties like `uses_sdks`.
- requiredSdks := m.RequiredSdks()
+ requiredSdks := parent.RequiredSdks()
if len(requiredSdks) > 0 {
mctx.VisitDirectDeps(func(m android.Module) {
- if dep, ok := m.(android.SdkAware); ok {
+ // Only propagate required sdks from the apex onto its contents.
+ if dep, ok := m.(android.SdkAware); ok && parent.DepIsInSameApex(mctx, dep) {
dep.BuildWithSdks(requiredSdks)
}
})
@@ -423,15 +427,28 @@
// Step 5: if libfoo.mysdk.11 is in the context where version 11 of mysdk is requested, the
// versioned module is used instead of the un-versioned (in-development) module libfoo
func sdkDepsReplaceMutator(mctx android.BottomUpMutatorContext) {
- if m, ok := mctx.Module().(android.SdkAware); ok && m.IsInAnySdk() {
- if sdk := m.ContainingSdk(); !sdk.Unversioned() {
- if m.RequiredSdks().Contains(sdk) {
- // Note that this replacement is done only for the modules that have the same
- // variations as the current module. Since current module is already mutated for
- // apex references in other APEXes are not affected by this replacement.
- memberName := m.MemberName()
- mctx.ReplaceDependencies(memberName)
- }
+ if versionedSdkMember, ok := mctx.Module().(android.SdkAware); ok && versionedSdkMember.IsInAnySdk() {
+ if sdk := versionedSdkMember.ContainingSdk(); !sdk.Unversioned() {
+ // Only replace dependencies to <sdkmember> with <sdkmember@required-version>
+ // if the depending module requires it. e.g.
+ // foo -> sdkmember
+ // will be transformed to:
+ // foo -> sdkmember@1
+ // if and only if foo is a member of an APEX that requires version 1 of the
+ // sdk containing sdkmember.
+ memberName := versionedSdkMember.MemberName()
+
+ // Replace dependencies on sdkmember with a dependency on the current module which
+ // is a versioned prebuilt of the sdkmember if required.
+ mctx.ReplaceDependenciesIf(memberName, func(from blueprint.Module, tag blueprint.DependencyTag, to blueprint.Module) bool {
+ // from - foo
+ // to - sdkmember
+ replace := false
+ if parent, ok := from.(android.RequiredSdks); ok {
+ replace = parent.RequiredSdks().Contains(sdk)
+ }
+ return replace
+ })
}
}
}
diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go
index 56be741..ef62b79 100644
--- a/sdk/sdk_test.go
+++ b/sdk/sdk_test.go
@@ -15,6 +15,9 @@
package sdk
import (
+ "android/soong/android"
+ "log"
+ "os"
"testing"
"github.com/google/blueprint/proptools"
@@ -22,6 +25,12 @@
// Needed in an _test.go file in this package to ensure tests run correctly, particularly in IDE.
func TestMain(m *testing.M) {
+ if android.BuildOs != android.Linux {
+ // b/145598135 - Generating host snapshots for anything other than linux is not supported.
+ log.Printf("Skipping as sdk snapshot generation is only supported on %s not %s", android.Linux, android.BuildOs)
+ os.Exit(0)
+ }
+
runTestWithBuildDir(m)
}
diff --git a/sdk/testing.go b/sdk/testing.go
index 4d029e4..b53558d 100644
--- a/sdk/testing.go
+++ b/sdk/testing.go
@@ -29,7 +29,9 @@
"android/soong/java"
)
-func testSdkContext(bp string, fs map[string][]byte) (*android.TestContext, android.Config) {
+func testSdkContext(bp string, fs map[string][]byte, extraOsTypes []android.OsType) (*android.TestContext, android.Config) {
+ extraOsTypes = append(extraOsTypes, android.Android, android.Windows)
+
bp = bp + `
apex_key {
name: "myapex.key",
@@ -41,7 +43,7 @@
name: "myapex.cert",
certificate: "myapex",
}
- ` + cc.GatherRequiredDepsForTest(android.Android, android.Windows)
+ ` + cc.GatherRequiredDepsForTest(extraOsTypes...)
mockFS := map[string][]byte{
"build/make/target/product/security": nil,
@@ -69,6 +71,15 @@
{android.Windows, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", ""},
}
+ 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, "", ""},
+ }
+ }
+ }
+
ctx := android.NewTestArchContext()
// Enable androidmk support.
@@ -86,6 +97,11 @@
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)
@@ -117,9 +133,8 @@
return ctx, config
}
-func testSdkWithFs(t *testing.T, bp string, fs map[string][]byte) *testSdkResult {
+func runTests(t *testing.T, ctx *android.TestContext, config android.Config) *testSdkResult {
t.Helper()
- ctx, config := testSdkContext(bp, fs)
_, errs := ctx.ParseBlueprintsFiles(".")
android.FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
@@ -131,9 +146,15 @@
}
}
+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)
+}
+
func testSdkError(t *testing.T, pattern, bp string) {
t.Helper()
- ctx, config := testSdkContext(bp, nil)
+ ctx, config := testSdkContext(bp, nil, nil)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
if len(errs) > 0 {
android.FailIfNoMatchingErrors(t, pattern, errs)
@@ -422,10 +443,3 @@
os.Exit(run())
}
-
-func SkipIfNotLinux(t *testing.T) {
- t.Helper()
- if android.BuildOs != android.Linux {
- t.Skipf("Skipping as sdk snapshot generation is only supported on %s not %s", android.Linux, android.BuildOs)
- }
-}
diff --git a/sdk/update.go b/sdk/update.go
index 8241151..936696a 100644
--- a/sdk/update.go
+++ b/sdk/update.go
@@ -262,7 +262,7 @@
memberCtx := &memberContext{ctx, builder, memberType, member.name}
prebuiltModule := memberType.AddPrebuiltModule(memberCtx, member)
- s.createMemberSnapshot(memberCtx, member, prebuiltModule)
+ s.createMemberSnapshot(memberCtx, member, prebuiltModule.(*bpModule))
}
// Create a transformer that will transform an unversioned module into a versioned module.
@@ -323,19 +323,62 @@
// Add properties common to all os types.
s.addMemberPropertiesToPropertySet(builder, snapshotModule, commonDynamicMemberProperties)
- // Iterate over the os types in a fixed order.
+ // Optimize other per-variant properties, besides the dynamic member lists.
+ type variantProperties struct {
+ Compile_multilib string `android:"arch_variant"`
+ }
+ var variantPropertiesContainers []propertiesContainer
+ variantToProperties := make(map[*sdk]*variantProperties)
+ for _, sdkVariant := range sdkVariants {
+ props := &variantProperties{
+ Compile_multilib: sdkVariant.multilibUsages.String(),
+ }
+ variantPropertiesContainers = append(variantPropertiesContainers, &dynamicMemberPropertiesContainer{sdkVariant, props})
+ variantToProperties[sdkVariant] = props
+ }
+ commonVariantProperties := variantProperties{}
+ extractor = newCommonValueExtractor(commonVariantProperties)
+ extractCommonProperties(ctx, extractor, &commonVariantProperties, variantPropertiesContainers)
+ if commonVariantProperties.Compile_multilib != "" && commonVariantProperties.Compile_multilib != "both" {
+ // Compile_multilib defaults to both so only needs to be set when it's
+ // specified and not both.
+ snapshotModule.AddProperty("compile_multilib", commonVariantProperties.Compile_multilib)
+ }
+
targetPropertySet := snapshotModule.AddPropertySet("target")
+
+ // If host is supported and any member is host OS dependent then disable host
+ // by default, so that we can enable each host OS variant explicitly. This
+ // avoids problems with implicitly enabled OS variants when the snapshot is
+ // used, which might be different from this run (e.g. different build OS).
+ hasHostOsDependentMember := false
+ if s.HostSupported() {
+ for _, memberRef := range memberRefs {
+ if memberRef.memberType.IsHostOsDependent() {
+ hasHostOsDependentMember = true
+ break
+ }
+ }
+ if hasHostOsDependentMember {
+ hostPropertySet := targetPropertySet.AddPropertySet("host")
+ hostPropertySet.AddProperty("enabled", false)
+ }
+ }
+
+ // Iterate over the os types in a fixed order.
for _, osType := range s.getPossibleOsTypes() {
if sdkVariant, ok := osTypeToMemberProperties[osType]; ok {
osPropertySet := targetPropertySet.AddPropertySet(sdkVariant.Target().Os.Name)
- // Compile_multilib defaults to both and must always be set to both on the
- // device and so only needs to be set when targeted at the host and is neither
- // unspecified or both.
- multilib := sdkVariant.multilibUsages
- if (osType.Class == android.Host || osType.Class == android.HostCross) &&
- multilib != multilibNone && multilib != multilibBoth {
- osPropertySet.AddProperty("compile_multilib", multilib.String())
+ // Enable the variant explicitly when we've disabled it by default on host.
+ if hasHostOsDependentMember &&
+ (osType.Class == android.Host || osType.Class == android.HostCross) {
+ osPropertySet.AddProperty("enabled", true)
+ }
+
+ variantProps := variantToProperties[sdkVariant]
+ if variantProps.Compile_multilib != "" && variantProps.Compile_multilib != "both" {
+ osPropertySet.AddProperty("compile_multilib", variantProps.Compile_multilib)
}
s.addMemberPropertiesToPropertySet(builder, osPropertySet, sdkVariant.dynamicMemberTypeListProperties)
@@ -794,6 +837,17 @@
return !ok
}
+// Add the properties from the given SdkMemberProperties to the blueprint
+// property set. This handles common properties in SdkMemberPropertiesBase and
+// calls the member-specific AddToPropertySet for the rest.
+func addSdkMemberPropertiesToSet(ctx *memberContext, memberProperties android.SdkMemberProperties, targetPropertySet android.BpPropertySet) {
+ if memberProperties.Base().Compile_multilib != "" {
+ targetPropertySet.AddProperty("compile_multilib", memberProperties.Base().Compile_multilib)
+ }
+
+ memberProperties.AddToPropertySet(ctx, targetPropertySet)
+}
+
type sdkMemberRef struct {
memberType android.SdkMemberType
variant android.SdkAware
@@ -911,7 +965,7 @@
if commonVariants, ok := variantsByArchName["common"]; ok {
if len(osTypeVariants) != 1 {
- panic("Expected to only have 1 variant when arch type is common but found " + string(len(osTypeVariants)))
+ panic(fmt.Errorf("Expected to only have 1 variant when arch type is common but found %d", len(osTypeVariants)))
}
// A common arch type only has one variant and its properties should be treated
@@ -964,9 +1018,12 @@
var osPropertySet android.BpPropertySet
var archPropertySet android.BpPropertySet
var archOsPrefix string
- if osInfo.Properties.Base().Os_count == 1 {
- // There is only one os type present in the variants so don't bother
- // with adding target specific properties.
+ if osInfo.Properties.Base().Os_count == 1 &&
+ (osInfo.osType.Class == android.Device || !ctx.memberType.IsHostOsDependent()) {
+ // There is only one OS type present in the variants and it shouldn't have a
+ // variant-specific target. The latter is the case if it's either for device
+ // where there is only one OS (android), or for host and the member type
+ // isn't host OS dependent.
// Create a structure that looks like:
// module_type {
@@ -1003,13 +1060,19 @@
osPropertySet = targetPropertySet.AddPropertySet(osType.Name)
archPropertySet = targetPropertySet
+ // Enable the variant explicitly when we've disabled it by default on host.
+ if ctx.memberType.IsHostOsDependent() &&
+ (osType.Class == android.Host || osType.Class == android.HostCross) {
+ osPropertySet.AddProperty("enabled", true)
+ }
+
// Arch specific properties need to be added to an os and arch specific
// section prefixed with <os>_.
archOsPrefix = osType.Name + "_"
}
// Add the os specific but arch independent properties to the module.
- osInfo.Properties.AddToPropertySet(ctx, osPropertySet)
+ addSdkMemberPropertiesToSet(ctx, osInfo.Properties, osPropertySet)
// Add arch (and possibly os) specific sections for each set of arch (and possibly
// os) specific properties.
@@ -1111,11 +1174,11 @@
func (archInfo *archTypeSpecificInfo) addToPropertySet(ctx *memberContext, archPropertySet android.BpPropertySet, archOsPrefix string) {
archTypeName := archInfo.archType.Name
archTypePropertySet := archPropertySet.AddPropertySet(archOsPrefix + archTypeName)
- archInfo.Properties.AddToPropertySet(ctx, archTypePropertySet)
+ addSdkMemberPropertiesToSet(ctx, archInfo.Properties, archTypePropertySet)
for _, linkInfo := range archInfo.linkInfos {
linkPropertySet := archTypePropertySet.AddPropertySet(linkInfo.linkType)
- linkInfo.Properties.AddToPropertySet(ctx, linkPropertySet)
+ addSdkMemberPropertiesToSet(ctx, linkInfo.Properties, linkPropertySet)
}
}
@@ -1173,7 +1236,7 @@
return m.name
}
-func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModule android.BpModule) {
+func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModule *bpModule) {
memberType := member.memberType
@@ -1221,12 +1284,24 @@
extractCommonProperties(ctx.sdkMemberContext, commonValueExtractor, commonProperties, osSpecificPropertiesContainers)
// Add the common properties to the module.
- commonProperties.AddToPropertySet(ctx, bpModule)
+ addSdkMemberPropertiesToSet(ctx, commonProperties, bpModule)
// Create a target property set into which target specific properties can be
// added.
targetPropertySet := bpModule.AddPropertySet("target")
+ // If the member is host OS dependent and has host_supported then disable by
+ // default and enable each host OS variant explicitly. This avoids problems
+ // with implicitly enabled OS variants when the snapshot is used, which might
+ // be different from this run (e.g. different build OS).
+ if ctx.memberType.IsHostOsDependent() {
+ hostSupported := bpModule.getValue("host_supported") == true // Missing means false.
+ if hostSupported {
+ hostPropertySet := targetPropertySet.AddPropertySet("host")
+ hostPropertySet.AddProperty("enabled", false)
+ }
+ }
+
// Iterate over the os types in a fixed order.
for _, osType := range s.getPossibleOsTypes() {
osInfo := osTypeToInfo[osType]
diff --git a/sysprop/sysprop_test.go b/sysprop/sysprop_test.go
index 8503386..711129c 100644
--- a/sysprop/sysprop_test.go
+++ b/sysprop/sysprop_test.go
@@ -67,6 +67,8 @@
ctx.BottomUp("sysprop_deps", syspropDepsMutator).Parallel()
})
+ android.RegisterPrebuiltMutators(ctx)
+
cc.RegisterRequiredBuildComponentsForTest(ctx)
ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
ctx.BottomUp("sysprop_java", java.SyspropMutator).Parallel()
diff --git a/third_party/zip/zip_test.go b/third_party/zip/zip_test.go
index 7373660..559c914 100644
--- a/third_party/zip/zip_test.go
+++ b/third_party/zip/zip_test.go
@@ -219,7 +219,7 @@
}
}
-// fakeHash32 is a dummy Hash32 that always returns 0.
+// fakeHash32 is a fake Hash32 that always returns 0.
type fakeHash32 struct {
hash.Hash32
}
diff --git a/tradefed/autogen.go b/tradefed/autogen.go
index 1cb874d..798fc40 100644
--- a/tradefed/autogen.go
+++ b/tradefed/autogen.go
@@ -239,6 +239,21 @@
return path
}
+func AutoGenRobolectricTestConfig(ctx android.ModuleContext, testConfigProp *string, testConfigTemplateProp *string,
+ testSuites []string, autoGenConfig *bool) android.Path {
+ path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp)
+ if autogenPath != nil {
+ templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
+ if templatePath.Valid() {
+ autogenTemplate(ctx, autogenPath, templatePath.String(), nil)
+ } else {
+ autogenTemplate(ctx, autogenPath, "${RobolectricTestConfigTemplate}", nil)
+ }
+ return autogenPath
+ }
+ return path
+}
+
var autogenInstrumentationTest = pctx.StaticRule("autogenInstrumentationTest", blueprint.RuleParams{
Command: "${AutoGenTestConfigScript} $out $in ${EmptyTestConfig} $template ${extraConfigs}",
CommandDeps: []string{
diff --git a/tradefed/config.go b/tradefed/config.go
index 34195c3..f7e8349 100644
--- a/tradefed/config.go
+++ b/tradefed/config.go
@@ -33,6 +33,7 @@
pctx.SourcePathVariable("PythonBinaryHostTestConfigTemplate", "build/make/core/python_binary_host_test_config_template.xml")
pctx.SourcePathVariable("RustDeviceTestConfigTemplate", "build/make/core/rust_device_test_config_template.xml")
pctx.SourcePathVariable("RustHostTestConfigTemplate", "build/make/core/rust_host_test_config_template.xml")
+ pctx.SourcePathVariable("RobolectricTestConfigTemplate", "build/make/core/robolectric_test_config_template.xml")
pctx.SourcePathVariable("ShellTestConfigTemplate", "build/make/core/shell_test_config_template.xml")
pctx.SourcePathVariable("EmptyTestConfig", "build/make/core/empty_test_config.xml")
diff --git a/ui/build/config.go b/ui/build/config.go
index e567e40..3fa0479 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -96,7 +96,7 @@
environ: OsEnvironment(),
}
- // Sane default matching ninja
+ // Default matching ninja
ret.parallel = runtime.NumCPU() + 2
ret.keepGoing = 1
@@ -184,7 +184,8 @@
// Tell python not to spam the source tree with .pyc files.
ret.environ.Set("PYTHONDONTWRITEBYTECODE", "1")
- ret.environ.Set("TMPDIR", absPath(ctx, ret.TempDir()))
+ tmpDir := absPath(ctx, ret.TempDir())
+ ret.environ.Set("TMPDIR", tmpDir)
// Always set ASAN_SYMBOLIZER_PATH so that ASAN-based tools can symbolize any crashes
symbolizerPath := filepath.Join("prebuilts/clang/host", ret.HostPrebuiltTag(),
@@ -256,11 +257,14 @@
ret.buildDateTime = strconv.FormatInt(time.Now().Unix(), 10)
}
- if ctx.Metrics != nil {
- ctx.Metrics.SetBuildDateTime(ret.buildDateTime)
- }
ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile)
+ if ret.UseRBE() {
+ for k, v := range getRBEVars(ctx, tmpDir) {
+ ret.environ.Set(k, v)
+ }
+ }
+
return Config{ret}
}
diff --git a/ui/build/paths/config.go b/ui/build/paths/config.go
index 5717401..81c500d 100644
--- a/ui/build/paths/config.go
+++ b/ui/build/paths/config.go
@@ -88,7 +88,6 @@
"javap": Allowed,
"lsof": Allowed,
"openssl": Allowed,
- "patch": Allowed,
"pstree": Allowed,
"rsync": Allowed,
"sh": Allowed,
diff --git a/ui/build/rbe.go b/ui/build/rbe.go
index fcdab3b..fd3b7ab 100644
--- a/ui/build/rbe.go
+++ b/ui/build/rbe.go
@@ -15,8 +15,11 @@
package build
import (
+ "fmt"
+ "math/rand"
"os"
"path/filepath"
+ "time"
"android/soong/ui/metrics"
)
@@ -49,6 +52,11 @@
return cmdPath
}
+func getRBEVars(ctx Context, tmpDir string) map[string]string {
+ rand.Seed(time.Now().UnixNano())
+ return map[string]string{"RBE_server_address": fmt.Sprintf("unix://%v/reproxy_%v.sock", tmpDir, rand.Intn(1000))}
+}
+
func startRBE(ctx Context, config Config) {
ctx.BeginTrace(metrics.RunSetupTool, "rbe_bootstrap")
defer ctx.EndTrace()
diff --git a/ui/build/rbe_test.go b/ui/build/rbe_test.go
index 2c4995b..23a53b4 100644
--- a/ui/build/rbe_test.go
+++ b/ui/build/rbe_test.go
@@ -94,12 +94,12 @@
}, {
description: "stopRBE failed",
rbeOutputDirDefined: true,
- bootstrapProgram: "#!/bin/bash\nexit 1",
+ bootstrapProgram: "#!/bin/bash\nexit 1\n",
expectedErr: "shutdown failed",
}, {
description: "failed to copy metrics file",
rbeOutputDirDefined: true,
- bootstrapProgram: "#!/bin/bash",
+ bootstrapProgram: "#!/bin/bash\n",
expectedErr: "failed to copy",
}}
@@ -139,4 +139,4 @@
}
}
-var rbeBootstrapProgram = fmt.Sprintf("#!/bin/bash\necho 1 > $RBE_output_dir/%s", rbeMetricsPBFilename)
+var rbeBootstrapProgram = fmt.Sprintf("#!/bin/bash\necho 1 > $RBE_output_dir/%s\n", rbeMetricsPBFilename)
diff --git a/ui/build/soong.go b/ui/build/soong.go
index 749acb3..fb21430 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -38,7 +38,7 @@
ctx.BeginTrace(metrics.RunSoong, "blueprint bootstrap")
defer ctx.EndTrace()
- cmd := Command(ctx, config, "blueprint bootstrap", "build/blueprint/bootstrap.bash", "-t")
+ cmd := Command(ctx, config, "blueprint bootstrap", "build/blueprint/bootstrap.bash", "-t", "-n")
cmd.Environment.Set("BLUEPRINTDIR", "./build/blueprint")
cmd.Environment.Set("BOOTSTRAP", "./build/blueprint/bootstrap.bash")
cmd.Environment.Set("BUILDDIR", config.SoongOutDir())
diff --git a/ui/build/upload.go b/ui/build/upload.go
index 3a23a80..a9346e0 100644
--- a/ui/build/upload.go
+++ b/ui/build/upload.go
@@ -44,7 +44,7 @@
// environment variable. The metrics files are copied to a temporary directory
// and the uploader is then executed in the background to allow the user to continue
// working.
-func UploadMetrics(ctx Context, config Config, forceDumbOutput bool, buildStartedMilli int64, files ...string) {
+func UploadMetrics(ctx Context, config Config, simpleOutput bool, buildStarted time.Time, files ...string) {
ctx.BeginTrace(metrics.RunSetupTool, "upload_metrics")
defer ctx.EndTrace()
@@ -86,7 +86,7 @@
// For platform builds, the branch and target name is hardcoded to specific
// values for later extraction of the metrics in the data metrics pipeline.
data, err := proto.Marshal(&upload_proto.Upload{
- CreationTimestampMs: proto.Uint64(uint64(buildStartedMilli)),
+ CreationTimestampMs: proto.Uint64(uint64(buildStarted.UnixNano() / int64(time.Millisecond))),
CompletionTimestampMs: proto.Uint64(uint64(time.Now().UnixNano() / int64(time.Millisecond))),
BranchName: proto.String("developer-metrics"),
TargetName: proto.String("platform-build-systems-metrics"),
@@ -105,7 +105,7 @@
// Start the uploader in the background as it takes several milliseconds to start the uploader
// and prepare the metrics for upload. This affects small commands like "lunch".
cmd := Command(ctx, config, "upload metrics", uploader, "--upload-metrics", pbFile)
- if forceDumbOutput {
+ if simpleOutput {
cmd.RunOrFatal()
} else {
cmd.RunAndStreamOrFatal()
diff --git a/ui/build/upload_test.go b/ui/build/upload_test.go
index c812730..dccf156 100644
--- a/ui/build/upload_test.go
+++ b/ui/build/upload_test.go
@@ -97,7 +97,7 @@
buildDateTime: strconv.FormatInt(time.Now().UnixNano()/int64(time.Millisecond), 10),
}}
- UploadMetrics(ctx, config, false, 1591031903, metricsFiles...)
+ UploadMetrics(ctx, config, false, time.Now(), metricsFiles...)
})
}
}
@@ -151,7 +151,7 @@
"OUT_DIR=/bad",
}}}
- UploadMetrics(ctx, config, true, 1591031903, metricsFile)
+ UploadMetrics(ctx, config, true, time.Now(), metricsFile)
t.Errorf("got nil, expecting %q as a failure", tt.expectedErr)
})
}
diff --git a/ui/metrics/Android.bp b/ui/metrics/Android.bp
index 3596e10..8188a69 100644
--- a/ui/metrics/Android.bp
+++ b/ui/metrics/Android.bp
@@ -25,6 +25,9 @@
"metrics.go",
"time.go",
],
+ testSrcs: [
+ "time_test.go",
+ ],
}
bootstrap_go_package {
diff --git a/ui/metrics/metrics.go b/ui/metrics/metrics.go
index e055b76..2b5c4c3 100644
--- a/ui/metrics/metrics.go
+++ b/ui/metrics/metrics.go
@@ -17,7 +17,7 @@
import (
"io/ioutil"
"os"
- "strconv"
+ "time"
"github.com/golang/protobuf/proto"
@@ -131,14 +131,8 @@
}
}
-func (m *Metrics) SetBuildDateTime(date_time string) {
- if date_time != "" {
- date_time_timestamp, err := strconv.ParseInt(date_time, 10, 64)
- if err != nil {
- panic(err)
- }
- m.metrics.BuildDateTimestamp = &date_time_timestamp
- }
+func (m *Metrics) SetBuildDateTime(buildTimestamp time.Time) {
+ m.metrics.BuildDateTimestamp = proto.Int64(buildTimestamp.UnixNano() / int64(time.Second))
}
// exports the output to the file at outputPath
diff --git a/ui/metrics/time.go b/ui/metrics/time.go
index b8baf16..4016563 100644
--- a/ui/metrics/time.go
+++ b/ui/metrics/time.go
@@ -19,13 +19,18 @@
"android/soong/ui/metrics/metrics_proto"
"android/soong/ui/tracer"
+ "github.com/golang/protobuf/proto"
)
+// for testing purpose only
+var _now = now
+
type timeEvent struct {
desc string
name string
- atNanos uint64 // timestamp measured in nanoseconds since the reference date
+ // the time that the event started to occur.
+ start time.Time
}
type TimeTracer interface {
@@ -39,33 +44,26 @@
var _ TimeTracer = &timeTracerImpl{}
-func (t *timeTracerImpl) now() uint64 {
- return uint64(time.Now().UnixNano())
+func now() time.Time {
+ return time.Now()
}
-func (t *timeTracerImpl) Begin(name, desc string, thread tracer.Thread) {
- t.beginAt(name, desc, t.now())
+func (t *timeTracerImpl) Begin(name, desc string, _ tracer.Thread) {
+ t.activeEvents = append(t.activeEvents, timeEvent{name: name, desc: desc, start: _now()})
}
-func (t *timeTracerImpl) beginAt(name, desc string, atNanos uint64) {
- t.activeEvents = append(t.activeEvents, timeEvent{name: name, desc: desc, atNanos: atNanos})
-}
-
-func (t *timeTracerImpl) End(thread tracer.Thread) soong_metrics_proto.PerfInfo {
- return t.endAt(t.now())
-}
-
-func (t *timeTracerImpl) endAt(atNanos uint64) soong_metrics_proto.PerfInfo {
+func (t *timeTracerImpl) End(tracer.Thread) soong_metrics_proto.PerfInfo {
if len(t.activeEvents) < 1 {
panic("Internal error: No pending events for endAt to end!")
}
lastEvent := t.activeEvents[len(t.activeEvents)-1]
t.activeEvents = t.activeEvents[:len(t.activeEvents)-1]
- realTime := atNanos - lastEvent.atNanos
+ realTime := uint64(_now().Sub(lastEvent.start).Nanoseconds())
return soong_metrics_proto.PerfInfo{
- Desc: &lastEvent.desc,
- Name: &lastEvent.name,
- StartTime: &lastEvent.atNanos,
- RealTime: &realTime}
+ Desc: proto.String(lastEvent.desc),
+ Name: proto.String(lastEvent.name),
+ StartTime: proto.Uint64(uint64(lastEvent.start.UnixNano())),
+ RealTime: proto.Uint64(realTime),
+ }
}
diff --git a/ui/metrics/time_test.go b/ui/metrics/time_test.go
new file mode 100644
index 0000000..d73080a
--- /dev/null
+++ b/ui/metrics/time_test.go
@@ -0,0 +1,42 @@
+// Copyright 2020 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package metrics
+
+import (
+ "testing"
+ "time"
+
+ "android/soong/ui/tracer"
+)
+
+func TestEnd(t *testing.T) {
+ startTime := time.Date(2020, time.July, 13, 13, 0, 0, 0, time.UTC)
+ dur := time.Nanosecond * 10
+ initialNow := _now
+ _now = func() time.Time { return startTime.Add(dur) }
+ defer func() { _now = initialNow }()
+
+ timeTracer := &timeTracerImpl{}
+ timeTracer.activeEvents = append(timeTracer.activeEvents, timeEvent{
+ desc: "test",
+ name: "test",
+ start: startTime,
+ })
+
+ perf := timeTracer.End(tracer.Thread(0))
+ if perf.GetRealTime() != uint64(dur.Nanoseconds()) {
+ t.Errorf("got %d, want %d nanoseconds for event duration", perf.GetRealTime(), dur.Nanoseconds())
+ }
+}
diff --git a/ui/terminal/Android.bp b/ui/terminal/Android.bp
index b533b0d..aa6e35d 100644
--- a/ui/terminal/Android.bp
+++ b/ui/terminal/Android.bp
@@ -17,7 +17,7 @@
pkgPath: "android/soong/ui/terminal",
deps: ["soong-ui-status"],
srcs: [
- "dumb_status.go",
+ "simple_status.go",
"format.go",
"smart_status.go",
"status.go",
diff --git a/ui/terminal/dumb_status.go b/ui/terminal/simple_status.go
similarity index 70%
rename from ui/terminal/dumb_status.go
rename to ui/terminal/simple_status.go
index 201770f..4e8c568 100644
--- a/ui/terminal/dumb_status.go
+++ b/ui/terminal/simple_status.go
@@ -21,31 +21,31 @@
"android/soong/ui/status"
)
-type dumbStatusOutput struct {
+type simpleStatusOutput struct {
writer io.Writer
formatter formatter
}
-// NewDumbStatusOutput returns a StatusOutput that represents the
+// NewSimpleStatusOutput returns a StatusOutput that represents the
// current build status similarly to Ninja's built-in terminal
// output.
-func NewDumbStatusOutput(w io.Writer, formatter formatter) status.StatusOutput {
- return &dumbStatusOutput{
+func NewSimpleStatusOutput(w io.Writer, formatter formatter) status.StatusOutput {
+ return &simpleStatusOutput{
writer: w,
formatter: formatter,
}
}
-func (s *dumbStatusOutput) Message(level status.MsgLevel, message string) {
+func (s *simpleStatusOutput) Message(level status.MsgLevel, message string) {
if level >= status.StatusLvl {
fmt.Fprintln(s.writer, s.formatter.message(level, message))
}
}
-func (s *dumbStatusOutput) StartAction(action *status.Action, counts status.Counts) {
+func (s *simpleStatusOutput) StartAction(action *status.Action, counts status.Counts) {
}
-func (s *dumbStatusOutput) FinishAction(result status.ActionResult, counts status.Counts) {
+func (s *simpleStatusOutput) FinishAction(result status.ActionResult, counts status.Counts) {
str := result.Description
if str == "" {
str = result.Command
@@ -63,9 +63,9 @@
}
}
-func (s *dumbStatusOutput) Flush() {}
+func (s *simpleStatusOutput) Flush() {}
-func (s *dumbStatusOutput) Write(p []byte) (int, error) {
+func (s *simpleStatusOutput) Write(p []byte) (int, error) {
fmt.Fprint(s.writer, string(p))
return len(p), nil
}
diff --git a/ui/terminal/status.go b/ui/terminal/status.go
index 60dfc70..d8e7392 100644
--- a/ui/terminal/status.go
+++ b/ui/terminal/status.go
@@ -26,12 +26,12 @@
//
// statusFormat takes nearly all the same options as NINJA_STATUS.
// %c is currently unsupported.
-func NewStatusOutput(w io.Writer, statusFormat string, forceDumbOutput, quietBuild bool) status.StatusOutput {
+func NewStatusOutput(w io.Writer, statusFormat string, forceSimpleOutput, quietBuild bool) status.StatusOutput {
formatter := newFormatter(statusFormat, quietBuild)
- if !forceDumbOutput && isSmartTerminal(w) {
+ if !forceSimpleOutput && isSmartTerminal(w) {
return NewSmartStatusOutput(w, formatter)
} else {
- return NewDumbStatusOutput(w, formatter)
+ return NewSimpleStatusOutput(w, formatter)
}
}
diff --git a/ui/terminal/status_test.go b/ui/terminal/status_test.go
index 9f60829..aa69dff 100644
--- a/ui/terminal/status_test.go
+++ b/ui/terminal/status_test.go
@@ -26,64 +26,64 @@
func TestStatusOutput(t *testing.T) {
tests := []struct {
- name string
- calls func(stat status.StatusOutput)
- smart string
- dumb string
+ name string
+ calls func(stat status.StatusOutput)
+ smart string
+ simple string
}{
{
- name: "two actions",
- calls: twoActions,
- smart: "\r\x1b[1m[ 0% 0/2] action1\x1b[0m\x1b[K\r\x1b[1m[ 50% 1/2] action1\x1b[0m\x1b[K\r\x1b[1m[ 50% 1/2] action2\x1b[0m\x1b[K\r\x1b[1m[100% 2/2] action2\x1b[0m\x1b[K\n",
- dumb: "[ 50% 1/2] action1\n[100% 2/2] action2\n",
+ name: "two actions",
+ calls: twoActions,
+ smart: "\r\x1b[1m[ 0% 0/2] action1\x1b[0m\x1b[K\r\x1b[1m[ 50% 1/2] action1\x1b[0m\x1b[K\r\x1b[1m[ 50% 1/2] action2\x1b[0m\x1b[K\r\x1b[1m[100% 2/2] action2\x1b[0m\x1b[K\n",
+ simple: "[ 50% 1/2] action1\n[100% 2/2] action2\n",
},
{
- name: "two parallel actions",
- calls: twoParallelActions,
- smart: "\r\x1b[1m[ 0% 0/2] action1\x1b[0m\x1b[K\r\x1b[1m[ 0% 0/2] action2\x1b[0m\x1b[K\r\x1b[1m[ 50% 1/2] action1\x1b[0m\x1b[K\r\x1b[1m[100% 2/2] action2\x1b[0m\x1b[K\n",
- dumb: "[ 50% 1/2] action1\n[100% 2/2] action2\n",
+ name: "two parallel actions",
+ calls: twoParallelActions,
+ smart: "\r\x1b[1m[ 0% 0/2] action1\x1b[0m\x1b[K\r\x1b[1m[ 0% 0/2] action2\x1b[0m\x1b[K\r\x1b[1m[ 50% 1/2] action1\x1b[0m\x1b[K\r\x1b[1m[100% 2/2] action2\x1b[0m\x1b[K\n",
+ simple: "[ 50% 1/2] action1\n[100% 2/2] action2\n",
},
{
- name: "action with output",
- calls: actionsWithOutput,
- smart: "\r\x1b[1m[ 0% 0/3] action1\x1b[0m\x1b[K\r\x1b[1m[ 33% 1/3] action1\x1b[0m\x1b[K\r\x1b[1m[ 33% 1/3] action2\x1b[0m\x1b[K\r\x1b[1m[ 66% 2/3] action2\x1b[0m\x1b[K\noutput1\noutput2\n\r\x1b[1m[ 66% 2/3] action3\x1b[0m\x1b[K\r\x1b[1m[100% 3/3] action3\x1b[0m\x1b[K\n",
- dumb: "[ 33% 1/3] action1\n[ 66% 2/3] action2\noutput1\noutput2\n[100% 3/3] action3\n",
+ name: "action with output",
+ calls: actionsWithOutput,
+ smart: "\r\x1b[1m[ 0% 0/3] action1\x1b[0m\x1b[K\r\x1b[1m[ 33% 1/3] action1\x1b[0m\x1b[K\r\x1b[1m[ 33% 1/3] action2\x1b[0m\x1b[K\r\x1b[1m[ 66% 2/3] action2\x1b[0m\x1b[K\noutput1\noutput2\n\r\x1b[1m[ 66% 2/3] action3\x1b[0m\x1b[K\r\x1b[1m[100% 3/3] action3\x1b[0m\x1b[K\n",
+ simple: "[ 33% 1/3] action1\n[ 66% 2/3] action2\noutput1\noutput2\n[100% 3/3] action3\n",
},
{
- name: "action with output without newline",
- calls: actionsWithOutputWithoutNewline,
- smart: "\r\x1b[1m[ 0% 0/3] action1\x1b[0m\x1b[K\r\x1b[1m[ 33% 1/3] action1\x1b[0m\x1b[K\r\x1b[1m[ 33% 1/3] action2\x1b[0m\x1b[K\r\x1b[1m[ 66% 2/3] action2\x1b[0m\x1b[K\noutput1\noutput2\n\r\x1b[1m[ 66% 2/3] action3\x1b[0m\x1b[K\r\x1b[1m[100% 3/3] action3\x1b[0m\x1b[K\n",
- dumb: "[ 33% 1/3] action1\n[ 66% 2/3] action2\noutput1\noutput2\n[100% 3/3] action3\n",
+ name: "action with output without newline",
+ calls: actionsWithOutputWithoutNewline,
+ smart: "\r\x1b[1m[ 0% 0/3] action1\x1b[0m\x1b[K\r\x1b[1m[ 33% 1/3] action1\x1b[0m\x1b[K\r\x1b[1m[ 33% 1/3] action2\x1b[0m\x1b[K\r\x1b[1m[ 66% 2/3] action2\x1b[0m\x1b[K\noutput1\noutput2\n\r\x1b[1m[ 66% 2/3] action3\x1b[0m\x1b[K\r\x1b[1m[100% 3/3] action3\x1b[0m\x1b[K\n",
+ simple: "[ 33% 1/3] action1\n[ 66% 2/3] action2\noutput1\noutput2\n[100% 3/3] action3\n",
},
{
- name: "action with error",
- calls: actionsWithError,
- smart: "\r\x1b[1m[ 0% 0/3] action1\x1b[0m\x1b[K\r\x1b[1m[ 33% 1/3] action1\x1b[0m\x1b[K\r\x1b[1m[ 33% 1/3] action2\x1b[0m\x1b[K\r\x1b[1m[ 66% 2/3] action2\x1b[0m\x1b[K\nFAILED: f1 f2\ntouch f1 f2\nerror1\nerror2\n\r\x1b[1m[ 66% 2/3] action3\x1b[0m\x1b[K\r\x1b[1m[100% 3/3] action3\x1b[0m\x1b[K\n",
- dumb: "[ 33% 1/3] action1\n[ 66% 2/3] action2\nFAILED: f1 f2\ntouch f1 f2\nerror1\nerror2\n[100% 3/3] action3\n",
+ name: "action with error",
+ calls: actionsWithError,
+ smart: "\r\x1b[1m[ 0% 0/3] action1\x1b[0m\x1b[K\r\x1b[1m[ 33% 1/3] action1\x1b[0m\x1b[K\r\x1b[1m[ 33% 1/3] action2\x1b[0m\x1b[K\r\x1b[1m[ 66% 2/3] action2\x1b[0m\x1b[K\nFAILED: f1 f2\ntouch f1 f2\nerror1\nerror2\n\r\x1b[1m[ 66% 2/3] action3\x1b[0m\x1b[K\r\x1b[1m[100% 3/3] action3\x1b[0m\x1b[K\n",
+ simple: "[ 33% 1/3] action1\n[ 66% 2/3] action2\nFAILED: f1 f2\ntouch f1 f2\nerror1\nerror2\n[100% 3/3] action3\n",
},
{
- name: "action with empty description",
- calls: actionWithEmptyDescription,
- smart: "\r\x1b[1m[ 0% 0/1] command1\x1b[0m\x1b[K\r\x1b[1m[100% 1/1] command1\x1b[0m\x1b[K\n",
- dumb: "[100% 1/1] command1\n",
+ name: "action with empty description",
+ calls: actionWithEmptyDescription,
+ smart: "\r\x1b[1m[ 0% 0/1] command1\x1b[0m\x1b[K\r\x1b[1m[100% 1/1] command1\x1b[0m\x1b[K\n",
+ simple: "[100% 1/1] command1\n",
},
{
- name: "messages",
- calls: actionsWithMessages,
- smart: "\r\x1b[1m[ 0% 0/2] action1\x1b[0m\x1b[K\r\x1b[1m[ 50% 1/2] action1\x1b[0m\x1b[K\r\x1b[1mstatus\x1b[0m\x1b[K\r\x1b[Kprint\nFAILED: error\n\r\x1b[1m[ 50% 1/2] action2\x1b[0m\x1b[K\r\x1b[1m[100% 2/2] action2\x1b[0m\x1b[K\n",
- dumb: "[ 50% 1/2] action1\nstatus\nprint\nFAILED: error\n[100% 2/2] action2\n",
+ name: "messages",
+ calls: actionsWithMessages,
+ smart: "\r\x1b[1m[ 0% 0/2] action1\x1b[0m\x1b[K\r\x1b[1m[ 50% 1/2] action1\x1b[0m\x1b[K\r\x1b[1mstatus\x1b[0m\x1b[K\r\x1b[Kprint\nFAILED: error\n\r\x1b[1m[ 50% 1/2] action2\x1b[0m\x1b[K\r\x1b[1m[100% 2/2] action2\x1b[0m\x1b[K\n",
+ simple: "[ 50% 1/2] action1\nstatus\nprint\nFAILED: error\n[100% 2/2] action2\n",
},
{
- name: "action with long description",
- calls: actionWithLongDescription,
- smart: "\r\x1b[1m[ 0% 0/2] action with very long descrip\x1b[0m\x1b[K\r\x1b[1m[ 50% 1/2] action with very long descrip\x1b[0m\x1b[K\n",
- dumb: "[ 50% 1/2] action with very long description to test eliding\n",
+ name: "action with long description",
+ calls: actionWithLongDescription,
+ smart: "\r\x1b[1m[ 0% 0/2] action with very long descrip\x1b[0m\x1b[K\r\x1b[1m[ 50% 1/2] action with very long descrip\x1b[0m\x1b[K\n",
+ simple: "[ 50% 1/2] action with very long description to test eliding\n",
},
{
- name: "action with output with ansi codes",
- calls: actionWithOuptutWithAnsiCodes,
- smart: "\r\x1b[1m[ 0% 0/1] action1\x1b[0m\x1b[K\r\x1b[1m[100% 1/1] action1\x1b[0m\x1b[K\n\x1b[31mcolor\x1b[0m\n",
- dumb: "[100% 1/1] action1\ncolor\n",
+ name: "action with output with ansi codes",
+ calls: actionWithOuptutWithAnsiCodes,
+ smart: "\r\x1b[1m[ 0% 0/1] action1\x1b[0m\x1b[K\r\x1b[1m[100% 1/1] action1\x1b[0m\x1b[K\n\x1b[31mcolor\x1b[0m\n",
+ simple: "[100% 1/1] action1\ncolor\n",
},
}
@@ -103,24 +103,24 @@
}
})
- t.Run("dumb", func(t *testing.T) {
- dumb := &bytes.Buffer{}
- stat := NewStatusOutput(dumb, "", false, false)
+ t.Run("simple", func(t *testing.T) {
+ simple := &bytes.Buffer{}
+ stat := NewStatusOutput(simple, "", false, false)
tt.calls(stat)
stat.Flush()
- if g, w := dumb.String(), tt.dumb; g != w {
+ if g, w := simple.String(), tt.simple; g != w {
t.Errorf("want:\n%q\ngot:\n%q", w, g)
}
})
- t.Run("force dumb", func(t *testing.T) {
+ t.Run("force simple", func(t *testing.T) {
smart := &fakeSmartTerminal{termWidth: 40}
stat := NewStatusOutput(smart, "", true, false)
tt.calls(stat)
stat.Flush()
- if g, w := smart.String(), tt.dumb; g != w {
+ if g, w := smart.String(), tt.simple; g != w {
t.Errorf("want:\n%q\ngot:\n%q", w, g)
}
})