Merge "platform_bootclasspath: aggregate hidden API flag files from fragments"
diff --git a/android/Android.bp b/android/Android.bp
index f5e5606..62d5e20 100644
--- a/android/Android.bp
+++ b/android/Android.bp
@@ -26,6 +26,7 @@
"arch_list.go",
"bazel.go",
"bazel_handler.go",
+ "bazel_paths.go",
"config.go",
"csuite_config.go",
"deapexer.go",
diff --git a/android/androidmk.go b/android/androidmk.go
index 66a1036..618e4be 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -505,6 +505,8 @@
// TODO(b/151177513): Does this code need to set LOCAL_MODULE_IS_CONTAINER ?
if amod.commonProperties.Effective_package_name != nil {
a.SetString("LOCAL_LICENSE_PACKAGE_NAME", *amod.commonProperties.Effective_package_name)
+ } else if len(amod.commonProperties.Effective_licenses) > 0 {
+ a.SetString("LOCAL_LICENSE_PACKAGE_NAME", strings.Join(amod.commonProperties.Effective_licenses, " "))
}
a.SetString("LOCAL_MODULE_CLASS", a.Class)
a.SetString("LOCAL_PREBUILT_MODULE_FILE", a.OutputFile.String())
diff --git a/android/apex.go b/android/apex.go
index cfda2aa..25a07b8 100644
--- a/android/apex.go
+++ b/android/apex.go
@@ -43,10 +43,8 @@
// mergeApexVariations.
ApexVariationName string
- // Serialized ApiLevel that this module has to support at minimum. Should be accessed via
- // MinSdkVersion() method. Cannot be stored in its struct form because this is cloned into
- // properties structs, and ApiLevel has private members.
- MinSdkVersionStr string
+ // ApiLevel that this module has to support at minimum.
+ MinSdkVersion ApiLevel
// True if this module comes from an updatable apexBundle.
Updatable bool
@@ -82,19 +80,13 @@
// have to be built twice, but only once. In that case, the two apex variations apex.a and apex.b
// are configured to have the same alias variation named apex29.
func (i ApexInfo) mergedName(ctx PathContext) string {
- name := "apex" + strconv.Itoa(i.MinSdkVersion(ctx).FinalOrFutureInt())
+ name := "apex" + strconv.Itoa(i.MinSdkVersion.FinalOrFutureInt())
for _, sdk := range i.RequiredSdks {
name += "_" + sdk.Name + "_" + sdk.Version
}
return name
}
-// MinSdkVersion gives the api level that this module has to support at minimum. This is from the
-// min_sdk_version property of the containing apexBundle.
-func (i ApexInfo) MinSdkVersion(ctx PathContext) ApiLevel {
- return ApiLevelOrPanic(ctx, i.MinSdkVersionStr)
-}
-
// IsForPlatform tells whether this module is for the platform or not. If false is returned, it
// means that this apex variant of the module is built for an APEX.
func (i ApexInfo) IsForPlatform() bool {
diff --git a/android/apex_test.go b/android/apex_test.go
index b5323e8..109b1c8 100644
--- a/android/apex_test.go
+++ b/android/apex_test.go
@@ -33,10 +33,10 @@
{
name: "single",
in: []ApexInfo{
- {"foo", "current", false, nil, []string{"foo"}, nil, NotForPrebuiltApex},
+ {"foo", FutureApiLevel, false, nil, []string{"foo"}, nil, NotForPrebuiltApex},
},
wantMerged: []ApexInfo{
- {"apex10000", "current", false, nil, []string{"foo"}, nil, NotForPrebuiltApex},
+ {"apex10000", FutureApiLevel, false, nil, []string{"foo"}, nil, NotForPrebuiltApex},
},
wantAliases: [][2]string{
{"foo", "apex10000"},
@@ -45,11 +45,11 @@
{
name: "merge",
in: []ApexInfo{
- {"foo", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}, nil, NotForPrebuiltApex},
- {"bar", "current", false, SdkRefs{{"baz", "1"}}, []string{"bar"}, nil, NotForPrebuiltApex},
+ {"foo", FutureApiLevel, false, SdkRefs{{"baz", "1"}}, []string{"foo"}, nil, NotForPrebuiltApex},
+ {"bar", FutureApiLevel, false, SdkRefs{{"baz", "1"}}, []string{"bar"}, nil, NotForPrebuiltApex},
},
wantMerged: []ApexInfo{
- {"apex10000_baz_1", "current", false, SdkRefs{{"baz", "1"}}, []string{"bar", "foo"}, nil, false}},
+ {"apex10000_baz_1", FutureApiLevel, false, SdkRefs{{"baz", "1"}}, []string{"bar", "foo"}, nil, false}},
wantAliases: [][2]string{
{"bar", "apex10000_baz_1"},
{"foo", "apex10000_baz_1"},
@@ -58,12 +58,12 @@
{
name: "don't merge version",
in: []ApexInfo{
- {"foo", "current", false, nil, []string{"foo"}, nil, NotForPrebuiltApex},
- {"bar", "30", false, nil, []string{"bar"}, nil, NotForPrebuiltApex},
+ {"foo", FutureApiLevel, false, nil, []string{"foo"}, nil, NotForPrebuiltApex},
+ {"bar", uncheckedFinalApiLevel(30), false, nil, []string{"bar"}, nil, NotForPrebuiltApex},
},
wantMerged: []ApexInfo{
- {"apex30", "30", false, nil, []string{"bar"}, nil, NotForPrebuiltApex},
- {"apex10000", "current", false, nil, []string{"foo"}, nil, NotForPrebuiltApex},
+ {"apex30", uncheckedFinalApiLevel(30), false, nil, []string{"bar"}, nil, NotForPrebuiltApex},
+ {"apex10000", FutureApiLevel, false, nil, []string{"foo"}, nil, NotForPrebuiltApex},
},
wantAliases: [][2]string{
{"bar", "apex30"},
@@ -73,11 +73,11 @@
{
name: "merge updatable",
in: []ApexInfo{
- {"foo", "current", false, nil, []string{"foo"}, nil, NotForPrebuiltApex},
- {"bar", "current", true, nil, []string{"bar"}, nil, NotForPrebuiltApex},
+ {"foo", FutureApiLevel, false, nil, []string{"foo"}, nil, NotForPrebuiltApex},
+ {"bar", FutureApiLevel, true, nil, []string{"bar"}, nil, NotForPrebuiltApex},
},
wantMerged: []ApexInfo{
- {"apex10000", "current", true, nil, []string{"bar", "foo"}, nil, NotForPrebuiltApex},
+ {"apex10000", FutureApiLevel, true, nil, []string{"bar", "foo"}, nil, NotForPrebuiltApex},
},
wantAliases: [][2]string{
{"bar", "apex10000"},
@@ -87,12 +87,12 @@
{
name: "don't merge sdks",
in: []ApexInfo{
- {"foo", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}, nil, NotForPrebuiltApex},
- {"bar", "current", false, SdkRefs{{"baz", "2"}}, []string{"bar"}, nil, NotForPrebuiltApex},
+ {"foo", FutureApiLevel, false, SdkRefs{{"baz", "1"}}, []string{"foo"}, nil, NotForPrebuiltApex},
+ {"bar", FutureApiLevel, false, SdkRefs{{"baz", "2"}}, []string{"bar"}, nil, NotForPrebuiltApex},
},
wantMerged: []ApexInfo{
- {"apex10000_baz_2", "current", false, SdkRefs{{"baz", "2"}}, []string{"bar"}, nil, NotForPrebuiltApex},
- {"apex10000_baz_1", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}, nil, NotForPrebuiltApex},
+ {"apex10000_baz_2", FutureApiLevel, false, SdkRefs{{"baz", "2"}}, []string{"bar"}, nil, NotForPrebuiltApex},
+ {"apex10000_baz_1", FutureApiLevel, false, SdkRefs{{"baz", "1"}}, []string{"foo"}, nil, NotForPrebuiltApex},
},
wantAliases: [][2]string{
{"bar", "apex10000_baz_2"},
@@ -102,15 +102,15 @@
{
name: "don't merge when for prebuilt_apex",
in: []ApexInfo{
- {"foo", "current", false, nil, []string{"foo"}, nil, NotForPrebuiltApex},
- {"bar", "current", true, nil, []string{"bar"}, nil, NotForPrebuiltApex},
+ {"foo", FutureApiLevel, false, nil, []string{"foo"}, nil, NotForPrebuiltApex},
+ {"bar", FutureApiLevel, true, nil, []string{"bar"}, nil, NotForPrebuiltApex},
// This one should not be merged in with the others because it is for
// a prebuilt_apex.
- {"baz", "current", true, nil, []string{"baz"}, nil, ForPrebuiltApex},
+ {"baz", FutureApiLevel, true, nil, []string{"baz"}, nil, ForPrebuiltApex},
},
wantMerged: []ApexInfo{
- {"apex10000", "current", true, nil, []string{"bar", "foo"}, nil, NotForPrebuiltApex},
- {"baz", "current", true, nil, []string{"baz"}, nil, ForPrebuiltApex},
+ {"apex10000", FutureApiLevel, true, nil, []string{"bar", "foo"}, nil, NotForPrebuiltApex},
+ {"baz", FutureApiLevel, true, nil, []string{"baz"}, nil, ForPrebuiltApex},
},
wantAliases: [][2]string{
{"bar", "apex10000"},
diff --git a/android/arch.go b/android/arch.go
index e40b6f5..9f93752 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -19,7 +19,6 @@
"fmt"
"reflect"
"runtime"
- "strconv"
"strings"
"github.com/google/blueprint"
@@ -176,7 +175,7 @@
// MarshalText allows an ArchType to be serialized through any encoder that supports
// encoding.TextMarshaler.
func (a ArchType) MarshalText() ([]byte, error) {
- return []byte(strconv.Quote(a.String())), nil
+ return []byte(a.String()), nil
}
var _ encoding.TextMarshaler = ArchType{}
diff --git a/android/bazel.go b/android/bazel.go
index 9468891..1f7f7e6 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -134,7 +134,7 @@
"system/logging/liblog": Bp2BuildDefaultTrueRecursively,
}
- // Per-module denylist to always opt modules out.
+ // Per-module denylist to always opt modules out of both bp2build and mixed builds.
bp2buildModuleDoNotConvertList = []string{
"libBionicBenchmarksUtils", // ruperts@, cc_library_static, 'map' file not found
"libbionic_spawn_benchmark", // ruperts@, cc_library_static, depends on //system/libbase
@@ -168,6 +168,10 @@
"liblinker_debuggerd_stub", // ruperts@, cc_library_static, depends on //system/libbase
"libbionic_tests_headers_posix", // ruperts@, cc_library_static, 'complex.h' file not found
"libc_dns", // ruperts@, cc_library_static, 'android/log.h' file not found
+ "libc_static_dispatch", // eakammer@, cc_library_static, 'private/bionic_asm.h' file not found
+ "libc_dynamic_dispatch", // eakammer@, cc_library_static, 'private/bionic_ifuncs.h' file not found
+ "note_memtag_heap_async", // jingwen@, cc_library_static, 'private/bionic_asm.h' file not found (arm64)
+ "note_memtag_heap_sync", // jingwen@, cc_library_static, 'private/bionic_asm.h' file not found (arm64)
// List of all full_cc_libraries in //bionic, with their immediate failures
"libc", // jingwen@, cc_library, depends on //external/gwp_asan
@@ -177,21 +181,39 @@
"libm", // jingwen@, cc_library, fatal error: 'freebsd-compat.h' file not found
"libseccomp_policy", // jingwen@, cc_library, fatal error: 'seccomp_policy.h' file not found
"libstdc++", // jingwen@, cc_library, depends on //external/gwp_asan
+ }
- // For mixed builds specifically
- "note_memtag_heap_async", // jingwen@, cc_library_static, OK for bp2build but features.h includes not found for mixed builds (b/185079815)
- "note_memtag_heap_sync", // jingwen@, cc_library_static, OK for bp2build but features.h includes not found for mixed builds (b/185079815)
- "libc_gdtoa", // ruperts@, cc_library_static, OK for bp2build but undefined symbol: __strtorQ for mixed builds
+ // Per-module denylist to opt modules out of mixed builds. Such modules will
+ // still be generated via bp2build.
+ mixedBuildsDisabledList = []string{
+ "libc_gdtoa", // ruperts@, cc_library_static, OK for bp2build but undefined symbol: __strtorQ for mixed builds
}
// Used for quicker lookups
bp2buildModuleDoNotConvert = map[string]bool{}
+ mixedBuildsDisabled = map[string]bool{}
)
func init() {
for _, moduleName := range bp2buildModuleDoNotConvertList {
bp2buildModuleDoNotConvert[moduleName] = true
}
+
+ for _, moduleName := range mixedBuildsDisabledList {
+ mixedBuildsDisabled[moduleName] = true
+ }
+}
+
+// MixedBuildsEnabled checks that a module is ready to be replaced by a
+// converted or handcrafted Bazel target.
+func (b *BazelModuleBase) MixedBuildsEnabled(ctx BazelConversionPathContext) bool {
+ if !ctx.Config().BazelContext.BazelEnabled() {
+ return false
+ }
+ if len(b.GetBazelLabel(ctx, ctx.Module())) == 0 {
+ return false
+ }
+ return !mixedBuildsDisabled[ctx.Module().Name()]
}
// ConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build.
diff --git a/android/bazel_paths.go b/android/bazel_paths.go
new file mode 100644
index 0000000..13f4949
--- /dev/null
+++ b/android/bazel_paths.go
@@ -0,0 +1,353 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package android
+
+import (
+ "android/soong/bazel"
+ "fmt"
+ "path/filepath"
+ "strings"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/pathtools"
+)
+
+// bazel_paths contains methods to:
+// * resolve Soong path and module references into bazel.LabelList
+// * resolve Bazel path references into Soong-compatible paths
+//
+// There is often a similar method for Bazel as there is for Soong path handling and should be used
+// in similar circumstances
+//
+// Bazel Soong
+//
+// BazelLabelForModuleSrc PathForModuleSrc
+// BazelLabelForModuleSrcExcludes PathForModuleSrcExcludes
+// BazelLabelForModuleDeps n/a
+// tbd PathForSource
+// tbd ExistentPathsForSources
+// PathForBazelOut PathForModuleOut
+//
+// Use cases:
+// * Module contains a property (often tagged `android:"path"`) that expects paths *relative to the
+// module directory*:
+// * BazelLabelForModuleSrcExcludes, if the module also contains an excludes_<propname> property
+// * BazelLabelForModuleSrc, otherwise
+// * Converting references to other modules to Bazel Labels:
+// BazelLabelForModuleDeps
+// * Converting a path obtained from bazel_handler cquery results:
+// PathForBazelOut
+//
+// NOTE: all Soong globs are expanded within Soong rather than being converted to a Bazel glob
+// syntax. This occurs because Soong does not have a concept of crossing package boundaries,
+// so the glob as computed by Soong may contain paths that cross package-boundaries. These
+// would be unknowingly omitted if the glob were handled by Bazel. By expanding globs within
+// Soong, we support identification and detection (within Bazel) use of paths that cross
+// package boundaries.
+//
+// Path resolution:
+// * filepath/globs: resolves as itself or is converted to an absolute Bazel label (e.g.
+// //path/to/dir:<filepath>) if path exists in a separate package or subpackage.
+// * references to other modules (using the ":name{.tag}" syntax). These resolve as a Bazel label
+// for a target. If the Bazel target is in the local module directory, it will be returned
+// relative to the current package (e.g. ":<target>"). Otherwise, it will be returned as an
+// absolute Bazel label (e.g. "//path/to/dir:<target>"). If the reference to another module
+// cannot be resolved,the function will panic. This is often due to the dependency not being added
+// via an AddDependency* method.
+
+// A subset of the ModuleContext methods which are sufficient to resolve references to paths/deps in
+// order to form a Bazel-compatible label for conversion.
+type BazelConversionPathContext interface {
+ EarlyModulePathContext
+
+ GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
+ Module() Module
+ ModuleType() string
+ OtherModuleName(m blueprint.Module) string
+ OtherModuleDir(m blueprint.Module) string
+}
+
+// BazelLabelForModuleDeps expects a list of reference to other modules, ("<module>"
+// or ":<module>") and returns a Bazel-compatible label which corresponds to dependencies on the
+// module within the given ctx.
+func BazelLabelForModuleDeps(ctx BazelConversionPathContext, modules []string) bazel.LabelList {
+ var labels bazel.LabelList
+ for _, module := range modules {
+ bpText := module
+ if m := SrcIsModule(module); m == "" {
+ module = ":" + module
+ }
+ if m, t := SrcIsModuleWithTag(module); m != "" {
+ l := getOtherModuleLabel(ctx, m, t)
+ l.Bp_text = bpText
+ labels.Includes = append(labels.Includes, l)
+ } else {
+ ctx.ModuleErrorf("%q, is not a module reference", module)
+ }
+ }
+ return labels
+}
+
+// BazelLabelForModuleSrc expects a list of path (relative to local module directory) and module
+// references (":<module>") and returns a bazel.LabelList{} containing the resolved references in
+// paths, relative to the local module, or Bazel-labels (absolute if in a different package or
+// relative if within the same package).
+// Properties must have been annotated with struct tag `android:"path"` so that dependencies modules
+// will have already been handled by the path_deps mutator.
+func BazelLabelForModuleSrc(ctx BazelConversionPathContext, paths []string) bazel.LabelList {
+ return BazelLabelForModuleSrcExcludes(ctx, paths, []string(nil))
+}
+
+// BazelLabelForModuleSrc expects lists of path and excludes (relative to local module directory)
+// and module references (":<module>") and returns a bazel.LabelList{} containing the resolved
+// references in paths, minus those in excludes, relative to the local module, or Bazel-labels
+// (absolute if in a different package or relative if within the same package).
+// Properties must have been annotated with struct tag `android:"path"` so that dependencies modules
+// will have already been handled by the path_deps mutator.
+func BazelLabelForModuleSrcExcludes(ctx BazelConversionPathContext, paths, excludes []string) bazel.LabelList {
+ excludeLabels := expandSrcsForBazel(ctx, excludes, []string(nil))
+ excluded := make([]string, 0, len(excludeLabels.Includes))
+ for _, e := range excludeLabels.Includes {
+ excluded = append(excluded, e.Label)
+ }
+ labels := expandSrcsForBazel(ctx, paths, excluded)
+ labels.Excludes = excludeLabels.Includes
+ labels = transformSubpackagePaths(ctx, labels)
+ return labels
+}
+
+// Returns true if a prefix + components[:i] + /Android.bp exists
+// TODO(b/185358476) Could check for BUILD file instead of checking for Android.bp file, or ensure BUILD is always generated?
+func directoryHasBlueprint(fs pathtools.FileSystem, prefix string, components []string, componentIndex int) bool {
+ blueprintPath := prefix
+ if blueprintPath != "" {
+ blueprintPath = blueprintPath + "/"
+ }
+ blueprintPath = blueprintPath + strings.Join(components[:componentIndex+1], "/")
+ blueprintPath = blueprintPath + "/Android.bp"
+ if exists, _, _ := fs.Exists(blueprintPath); exists {
+ return true
+ } else {
+ return false
+ }
+}
+
+// Transform a path (if necessary) to acknowledge package boundaries
+//
+// e.g. something like
+// async_safe/include/async_safe/CHECK.h
+// might become
+// //bionic/libc/async_safe:include/async_safe/CHECK.h
+// if the "async_safe" directory is actually a package and not just a directory.
+//
+// In particular, paths that extend into packages are transformed into absolute labels beginning with //.
+func transformSubpackagePath(ctx BazelConversionPathContext, path bazel.Label) bazel.Label {
+ var newPath bazel.Label
+
+ // Don't transform Bp_text
+ newPath.Bp_text = path.Bp_text
+
+ if strings.HasPrefix(path.Label, "//") {
+ // Assume absolute labels are already correct (e.g. //path/to/some/package:foo.h)
+ newPath.Label = path.Label
+ return newPath
+ }
+
+ newLabel := ""
+ pathComponents := strings.Split(path.Label, "/")
+ foundBlueprint := false
+ // Check the deepest subdirectory first and work upwards
+ for i := len(pathComponents) - 1; i >= 0; i-- {
+ pathComponent := pathComponents[i]
+ var sep string
+ if !foundBlueprint && directoryHasBlueprint(ctx.Config().fs, ctx.ModuleDir(), pathComponents, i) {
+ sep = ":"
+ foundBlueprint = true
+ } else {
+ sep = "/"
+ }
+ if newLabel == "" {
+ newLabel = pathComponent
+ } else {
+ newLabel = pathComponent + sep + newLabel
+ }
+ }
+ if foundBlueprint {
+ // Ensure paths end up looking like //bionic/... instead of //./bionic/...
+ moduleDir := ctx.ModuleDir()
+ if strings.HasPrefix(moduleDir, ".") {
+ moduleDir = moduleDir[1:]
+ }
+ // Make the path into an absolute label (e.g. //bionic/libc/foo:bar.h instead of just foo:bar.h)
+ if moduleDir == "" {
+ newLabel = "//" + newLabel
+ } else {
+ newLabel = "//" + moduleDir + "/" + newLabel
+ }
+ }
+ newPath.Label = newLabel
+
+ return newPath
+}
+
+// Transform paths to acknowledge package boundaries
+// See transformSubpackagePath() for more information
+func transformSubpackagePaths(ctx BazelConversionPathContext, paths bazel.LabelList) bazel.LabelList {
+ var newPaths bazel.LabelList
+ for _, include := range paths.Includes {
+ newPaths.Includes = append(newPaths.Includes, transformSubpackagePath(ctx, include))
+ }
+ for _, exclude := range paths.Excludes {
+ newPaths.Excludes = append(newPaths.Excludes, transformSubpackagePath(ctx, exclude))
+ }
+ return newPaths
+}
+
+// expandSrcsForBazel returns bazel.LabelList with paths rooted from the module's local source
+// directory and Bazel target labels, excluding those included in the excludes argument (which
+// should already be expanded to resolve references to Soong-modules). Valid elements of paths
+// include:
+// * filepath, relative to local module directory, resolves as a filepath relative to the local
+// source directory
+// * glob, relative to the local module directory, resolves as filepath(s), relative to the local
+// module directory. Because Soong does not have a concept of crossing package boundaries, the
+// glob as computed by Soong may contain paths that cross package-boundaries that would be
+// unknowingly omitted if the glob were handled by Bazel. To allow identification and detect
+// (within Bazel) use of paths that cross package boundaries, we expand globs within Soong rather
+// than converting Soong glob syntax to Bazel glob syntax. **Invalid for excludes.**
+// * other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer
+// or OutputFileProducer. These resolve as a Bazel label for a target. If the Bazel target is in
+// the local module directory, it will be returned relative to the current package (e.g.
+// ":<target>"). Otherwise, it will be returned as an absolute Bazel label (e.g.
+// "//path/to/dir:<target>"). If the reference to another module cannot be resolved,the function
+// will panic.
+// Properties passed as the paths or excludes argument must have been annotated with struct tag
+// `android:"path"` so that dependencies on other modules will have already been handled by the
+// path_deps mutator.
+func expandSrcsForBazel(ctx BazelConversionPathContext, paths, expandedExcludes []string) bazel.LabelList {
+ if paths == nil {
+ return bazel.LabelList{}
+ }
+ labels := bazel.LabelList{
+ Includes: []bazel.Label{},
+ }
+ for _, p := range paths {
+ if m, tag := SrcIsModuleWithTag(p); m != "" {
+ l := getOtherModuleLabel(ctx, m, tag)
+ if !InList(l.Label, expandedExcludes) {
+ l.Bp_text = fmt.Sprintf(":%s", m)
+ labels.Includes = append(labels.Includes, l)
+ }
+ } else {
+ var expandedPaths []bazel.Label
+ if pathtools.IsGlob(p) {
+ globbedPaths := GlobFiles(ctx, pathForModuleSrc(ctx, p).String(), expandedExcludes)
+ globbedPaths = PathsWithModuleSrcSubDir(ctx, globbedPaths, "")
+ for _, path := range globbedPaths {
+ s := path.Rel()
+ expandedPaths = append(expandedPaths, bazel.Label{Label: s})
+ }
+ } else {
+ if !InList(p, expandedExcludes) {
+ expandedPaths = append(expandedPaths, bazel.Label{Label: p})
+ }
+ }
+ labels.Includes = append(labels.Includes, expandedPaths...)
+ }
+ }
+ return labels
+}
+
+// getOtherModuleLabel returns a bazel.Label for the given dependency/tag combination for the
+// module. The label will be relative to the current directory if appropriate. The dependency must
+// already be resolved by either deps mutator or path deps mutator.
+func getOtherModuleLabel(ctx BazelConversionPathContext, dep, tag string) bazel.Label {
+ m, _ := ctx.GetDirectDep(dep)
+ if m == nil {
+ panic(fmt.Errorf(`Cannot get direct dep %q of %q.
+ This is likely because it was not added via AddDependency().
+ This may be due a mutator skipped during bp2build.`, dep, ctx.Module().Name()))
+ }
+ otherLabel := bazelModuleLabel(ctx, m, tag)
+ label := bazelModuleLabel(ctx, ctx.Module(), "")
+ if samePackage(label, otherLabel) {
+ otherLabel = bazelShortLabel(otherLabel)
+ }
+
+ return bazel.Label{
+ Label: otherLabel,
+ }
+}
+
+func bazelModuleLabel(ctx BazelConversionPathContext, module blueprint.Module, tag string) string {
+ // TODO(b/165114590): Convert tag (":name{.tag}") to corresponding Bazel implicit output targets.
+ b, ok := module.(Bazelable)
+ // TODO(b/181155349): perhaps return an error here if the module can't be/isn't being converted
+ if !ok || !b.ConvertedToBazel(ctx) {
+ return bp2buildModuleLabel(ctx, module)
+ }
+ return b.GetBazelLabel(ctx, module)
+}
+
+func bazelShortLabel(label string) string {
+ i := strings.Index(label, ":")
+ return label[i:]
+}
+
+func bazelPackage(label string) string {
+ i := strings.Index(label, ":")
+ return label[0:i]
+}
+
+func samePackage(label1, label2 string) bool {
+ return bazelPackage(label1) == bazelPackage(label2)
+}
+
+func bp2buildModuleLabel(ctx BazelConversionPathContext, module blueprint.Module) string {
+ moduleName := ctx.OtherModuleName(module)
+ moduleDir := ctx.OtherModuleDir(module)
+ return fmt.Sprintf("//%s:%s", moduleDir, moduleName)
+}
+
+// BazelOutPath is a Bazel output path compatible to be used for mixed builds within Soong/Ninja.
+type BazelOutPath struct {
+ OutputPath
+}
+
+var _ Path = BazelOutPath{}
+var _ objPathProvider = BazelOutPath{}
+
+func (p BazelOutPath) objPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleObjPath {
+ return PathForModuleObj(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
+}
+
+// PathForBazelOut returns a Path representing the paths... under an output directory dedicated to
+// bazel-owned outputs.
+func PathForBazelOut(ctx PathContext, paths ...string) BazelOutPath {
+ execRootPathComponents := append([]string{"execroot", "__main__"}, paths...)
+ execRootPath := filepath.Join(execRootPathComponents...)
+ validatedExecRootPath, err := validatePath(execRootPath)
+ if err != nil {
+ reportPathError(ctx, err)
+ }
+
+ outputPath := OutputPath{basePath{"", ""},
+ ctx.Config().buildDir,
+ ctx.Config().BazelContext.OutputBase()}
+
+ return BazelOutPath{
+ OutputPath: outputPath.withRel(validatedExecRootPath),
+ }
+}
diff --git a/android/config.go b/android/config.go
index c170f1e..3db7980 100644
--- a/android/config.go
+++ b/android/config.go
@@ -1295,10 +1295,6 @@
return Bool(c.productVariables.Aml_abis)
}
-func (c *config) ExcludeDraftNdkApis() bool {
- return Bool(c.productVariables.Exclude_draft_ndk_apis)
-}
-
func (c *config) FlattenApex() bool {
return Bool(c.productVariables.Flatten_apex)
}
diff --git a/android/paths.go b/android/paths.go
index c303c38..026cb87 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -15,7 +15,6 @@
package android
import (
- "android/soong/bazel"
"fmt"
"io/ioutil"
"os"
@@ -356,23 +355,42 @@
return ret
}
-// PathsForModuleSrc returns Paths rooted from the module's local source directory. It expands globs, references to
-// SourceFileProducer modules using the ":name" syntax, and references to OutputFileProducer modules using the
-// ":name{.tag}" syntax. Properties passed as the paths argument must have been annotated with struct tag
+// PathsForModuleSrc returns a Paths{} containing the resolved references in paths:
+// * filepath, relative to local module directory, resolves as a filepath relative to the local
+// source directory
+// * glob, relative to the local module directory, resolves as filepath(s), relative to the local
+// source directory.
+// * other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer
+// or OutputFileProducer. These resolve as a filepath to an output filepath or generated source
+// filepath.
+// Properties passed as the paths argument must have been annotated with struct tag
// `android:"path"` so that dependencies on SourceFileProducer modules will have already been handled by the
-// path_properties mutator. If ctx.Config().AllowMissingDependencies() is true then any missing SourceFileProducer or
-// OutputFileProducer dependencies will cause the module to be marked as having missing dependencies.
+// path_deps mutator.
+// If a requested module is not found as a dependency:
+// * if ctx.Config().AllowMissingDependencies() is true, this module to be marked as having
+// missing dependencies
+// * otherwise, a ModuleError is thrown.
func PathsForModuleSrc(ctx ModuleMissingDepsPathContext, paths []string) Paths {
return PathsForModuleSrcExcludes(ctx, paths, nil)
}
-// PathsForModuleSrcExcludes returns Paths rooted from the module's local source directory, excluding paths listed in
-// the excludes arguments. It expands globs, references to SourceFileProducer modules using the ":name" syntax, and
-// references to OutputFileProducer modules using the ":name{.tag}" syntax. Properties passed as the paths or excludes
-// argument must have been annotated with struct tag `android:"path"` so that dependencies on SourceFileProducer modules
-// will have already been handled by the path_properties mutator. If ctx.Config().AllowMissingDependencies() is
-// true then any missing SourceFileProducer or OutputFileProducer dependencies will cause the module to be marked as
-// having missing dependencies.
+// PathsForModuleSrcExcludes returns a Paths{} containing the resolved references in paths, minus
+// those listed in excludes. Elements of paths and excludes are resolved as:
+// * filepath, relative to local module directory, resolves as a filepath relative to the local
+// source directory
+// * glob, relative to the local module directory, resolves as filepath(s), relative to the local
+// source directory. Not valid in excludes.
+// * other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer
+// or OutputFileProducer. These resolve as a filepath to an output filepath or generated source
+// filepath.
+// excluding the items (similarly resolved
+// Properties passed as the paths argument must have been annotated with struct tag
+// `android:"path"` so that dependencies on SourceFileProducer modules will have already been handled by the
+// path_deps mutator.
+// If a requested module is not found as a dependency:
+// * if ctx.Config().AllowMissingDependencies() is true, this module to be marked as having
+// missing dependencies
+// * otherwise, a ModuleError is thrown.
func PathsForModuleSrcExcludes(ctx ModuleMissingDepsPathContext, paths, excludes []string) Paths {
ret, missingDeps := PathsAndMissingDepsForModuleSrcExcludes(ctx, paths, excludes)
if ctx.Config().AllowMissingDependencies() {
@@ -385,247 +403,6 @@
return ret
}
-// A subset of the ModuleContext methods which are sufficient to resolve references to paths/deps in
-// order to form a Bazel-compatible label for conversion.
-type BazelConversionPathContext interface {
- EarlyModulePathContext
-
- GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
- Module() Module
- ModuleType() string
- OtherModuleName(m blueprint.Module) string
- OtherModuleDir(m blueprint.Module) string
-}
-
-// BazelLabelForModuleDeps returns a Bazel-compatible label for the requested modules which
-// correspond to dependencies on the module within the given ctx.
-func BazelLabelForModuleDeps(ctx BazelConversionPathContext, modules []string) bazel.LabelList {
- var labels bazel.LabelList
- for _, module := range modules {
- bpText := module
- if m := SrcIsModule(module); m == "" {
- module = ":" + module
- }
- if m, t := SrcIsModuleWithTag(module); m != "" {
- l := getOtherModuleLabel(ctx, m, t)
- l.Bp_text = bpText
- labels.Includes = append(labels.Includes, l)
- } else {
- ctx.ModuleErrorf("%q, is not a module reference", module)
- }
- }
- return labels
-}
-
-// Returns true if a prefix + components[:i] + /Android.bp exists
-// TODO(b/185358476) Could check for BUILD file instead of checking for Android.bp file, or ensure BUILD is always generated?
-func directoryHasBlueprint(fs pathtools.FileSystem, prefix string, components []string, componentIndex int) bool {
- blueprintPath := prefix
- if blueprintPath != "" {
- blueprintPath = blueprintPath + "/"
- }
- blueprintPath = blueprintPath + strings.Join(components[:componentIndex+1], "/")
- blueprintPath = blueprintPath + "/Android.bp"
- if exists, _, _ := fs.Exists(blueprintPath); exists {
- return true
- } else {
- return false
- }
-}
-
-// Transform a path (if necessary) to acknowledge package boundaries
-//
-// e.g. something like
-// async_safe/include/async_safe/CHECK.h
-// might become
-// //bionic/libc/async_safe:include/async_safe/CHECK.h
-// if the "async_safe" directory is actually a package and not just a directory.
-//
-// In particular, paths that extend into packages are transformed into absolute labels beginning with //.
-func transformSubpackagePath(ctx BazelConversionPathContext, path bazel.Label) bazel.Label {
- var newPath bazel.Label
-
- // Don't transform Bp_text
- newPath.Bp_text = path.Bp_text
-
- if strings.HasPrefix(path.Label, "//") {
- // Assume absolute labels are already correct (e.g. //path/to/some/package:foo.h)
- newPath.Label = path.Label
- return newPath
- }
-
- newLabel := ""
- pathComponents := strings.Split(path.Label, "/")
- foundBlueprint := false
- // Check the deepest subdirectory first and work upwards
- for i := len(pathComponents) - 1; i >= 0; i-- {
- pathComponent := pathComponents[i]
- var sep string
- if !foundBlueprint && directoryHasBlueprint(ctx.Config().fs, ctx.ModuleDir(), pathComponents, i) {
- sep = ":"
- foundBlueprint = true
- } else {
- sep = "/"
- }
- if newLabel == "" {
- newLabel = pathComponent
- } else {
- newLabel = pathComponent + sep + newLabel
- }
- }
- if foundBlueprint {
- // Ensure paths end up looking like //bionic/... instead of //./bionic/...
- moduleDir := ctx.ModuleDir()
- if strings.HasPrefix(moduleDir, ".") {
- moduleDir = moduleDir[1:]
- }
- // Make the path into an absolute label (e.g. //bionic/libc/foo:bar.h instead of just foo:bar.h)
- if moduleDir == "" {
- newLabel = "//" + newLabel
- } else {
- newLabel = "//" + moduleDir + "/" + newLabel
- }
- }
- newPath.Label = newLabel
-
- return newPath
-}
-
-// Transform paths to acknowledge package boundaries
-// See transformSubpackagePath() for more information
-func transformSubpackagePaths(ctx BazelConversionPathContext, paths bazel.LabelList) bazel.LabelList {
- var newPaths bazel.LabelList
- for _, include := range paths.Includes {
- newPaths.Includes = append(newPaths.Includes, transformSubpackagePath(ctx, include))
- }
- for _, exclude := range paths.Excludes {
- newPaths.Excludes = append(newPaths.Excludes, transformSubpackagePath(ctx, exclude))
- }
- return newPaths
-}
-
-// BazelLabelForModuleSrc returns bazel.LabelList with paths rooted from the module's local source
-// directory. It expands globs, and resolves references to modules using the ":name" syntax to
-// bazel-compatible labels. Properties passed as the paths or excludes argument must have been
-// annotated with struct tag `android:"path"` so that dependencies on other modules will have
-// already been handled by the path_properties mutator.
-//
-// With expanded globs, we can catch package boundaries problem instead of
-// silently failing to potentially missing files from Bazel's globs.
-func BazelLabelForModuleSrc(ctx BazelConversionPathContext, paths []string) bazel.LabelList {
- return BazelLabelForModuleSrcExcludes(ctx, paths, []string(nil))
-}
-
-// BazelLabelForModuleSrcExcludes returns bazel.LabelList with paths rooted from the module's local
-// source directory, excluding labels included in the excludes argument. It expands globs, and
-// resolves references to modules using the ":name" syntax to bazel-compatible labels. Properties
-// passed as the paths or excludes argument must have been annotated with struct tag
-// `android:"path"` so that dependencies on other modules will have already been handled by the
-// path_properties mutator.
-//
-// With expanded globs, we can catch package boundaries problem instead of
-// silently failing to potentially missing files from Bazel's globs.
-func BazelLabelForModuleSrcExcludes(ctx BazelConversionPathContext, paths, excludes []string) bazel.LabelList {
- excludeLabels := expandSrcsForBazel(ctx, excludes, []string(nil))
- excluded := make([]string, 0, len(excludeLabels.Includes))
- for _, e := range excludeLabels.Includes {
- excluded = append(excluded, e.Label)
- }
- labels := expandSrcsForBazel(ctx, paths, excluded)
- labels.Excludes = excludeLabels.Includes
- labels = transformSubpackagePaths(ctx, labels)
- return labels
-}
-
-// expandSrcsForBazel returns bazel.LabelList with paths rooted from the module's local
-// source directory, excluding labels included in the excludes argument. It expands globs, and
-// resolves references to modules using the ":name" syntax to bazel-compatible labels. Properties
-// passed as the paths or excludes argument must have been annotated with struct tag
-// `android:"path"` so that dependencies on other modules will have already been handled by the
-// path_properties mutator.
-func expandSrcsForBazel(ctx BazelConversionPathContext, paths, expandedExcludes []string) bazel.LabelList {
- if paths == nil {
- return bazel.LabelList{}
- }
- labels := bazel.LabelList{
- Includes: []bazel.Label{},
- }
- for _, p := range paths {
- if m, tag := SrcIsModuleWithTag(p); m != "" {
- l := getOtherModuleLabel(ctx, m, tag)
- if !InList(l.Label, expandedExcludes) {
- l.Bp_text = fmt.Sprintf(":%s", m)
- labels.Includes = append(labels.Includes, l)
- }
- } else {
- var expandedPaths []bazel.Label
- if pathtools.IsGlob(p) {
- globbedPaths := GlobFiles(ctx, pathForModuleSrc(ctx, p).String(), expandedExcludes)
- globbedPaths = PathsWithModuleSrcSubDir(ctx, globbedPaths, "")
- for _, path := range globbedPaths {
- s := path.Rel()
- expandedPaths = append(expandedPaths, bazel.Label{Label: s})
- }
- } else {
- if !InList(p, expandedExcludes) {
- expandedPaths = append(expandedPaths, bazel.Label{Label: p})
- }
- }
- labels.Includes = append(labels.Includes, expandedPaths...)
- }
- }
- return labels
-}
-
-// getOtherModuleLabel returns a bazel.Label for the given dependency/tag combination for the
-// module. The label will be relative to the current directory if appropriate. The dependency must
-// already be resolved by either deps mutator or path deps mutator.
-func getOtherModuleLabel(ctx BazelConversionPathContext, dep, tag string) bazel.Label {
- m, _ := ctx.GetDirectDep(dep)
- if m == nil {
- panic(fmt.Errorf("cannot get direct dep %s of %s", dep, ctx.Module().Name()))
- }
- otherLabel := bazelModuleLabel(ctx, m, tag)
- label := bazelModuleLabel(ctx, ctx.Module(), "")
- if samePackage(label, otherLabel) {
- otherLabel = bazelShortLabel(otherLabel)
- }
-
- return bazel.Label{
- Label: otherLabel,
- }
-}
-
-func bazelModuleLabel(ctx BazelConversionPathContext, module blueprint.Module, tag string) string {
- // TODO(b/165114590): Convert tag (":name{.tag}") to corresponding Bazel implicit output targets.
- b, ok := module.(Bazelable)
- // TODO(b/181155349): perhaps return an error here if the module can't be/isn't being converted
- if !ok || !b.ConvertedToBazel(ctx) {
- return bp2buildModuleLabel(ctx, module)
- }
- return b.GetBazelLabel(ctx, module)
-}
-
-func bazelShortLabel(label string) string {
- i := strings.Index(label, ":")
- return label[i:]
-}
-
-func bazelPackage(label string) string {
- i := strings.Index(label, ":")
- return label[0:i]
-}
-
-func samePackage(label1, label2 string) bool {
- return bazelPackage(label1) == bazelPackage(label2)
-}
-
-func bp2buildModuleLabel(ctx BazelConversionPathContext, module blueprint.Module) string {
- moduleName := ctx.OtherModuleName(module)
- moduleDir := ctx.OtherModuleDir(module)
- return fmt.Sprintf("//%s:%s", moduleDir, moduleName)
-}
-
// OutputPaths is a slice of OutputPath objects, with helpers to operate on the collection.
type OutputPaths []OutputPath
@@ -679,14 +456,19 @@
}
}
-// PathsAndMissingDepsForModuleSrcExcludes returns Paths rooted from the module's local source directory, excluding
-// paths listed in the excludes arguments, and a list of missing dependencies. It expands globs, references to
-// SourceFileProducer modules using the ":name" syntax, and references to OutputFileProducer modules using the
-// ":name{.tag}" syntax. Properties passed as the paths or excludes argument must have been annotated with struct tag
+// PathsAndMissingDepsForModuleSrcExcludes returns a Paths{} containing the resolved references in
+// paths, minus those listed in excludes. Elements of paths and excludes are resolved as:
+// * filepath, relative to local module directory, resolves as a filepath relative to the local
+// source directory
+// * glob, relative to the local module directory, resolves as filepath(s), relative to the local
+// source directory. Not valid in excludes.
+// * other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer
+// or OutputFileProducer. These resolve as a filepath to an output filepath or generated source
+// filepath.
+// and a list of the module names of missing module dependencies are returned as the second return.
+// Properties passed as the paths argument must have been annotated with struct tag
// `android:"path"` so that dependencies on SourceFileProducer modules will have already been handled by the
-// path_properties mutator. If ctx.Config().AllowMissingDependencies() is true then any missing SourceFileProducer or
-// OutputFileProducer dependencies will be returned, and they will NOT cause the module to be marked as having missing
-// dependencies.
+// path_deps mutator.
func PathsAndMissingDepsForModuleSrcExcludes(ctx ModuleWithDepsPathContext, paths, excludes []string) (Paths, []string) {
prefix := pathForModuleSrc(ctx).String()
@@ -1566,17 +1348,6 @@
return PathForOutput(ctx, ".intermediates", ctx.ModuleDir(), ctx.ModuleName(), ctx.ModuleSubDir())
}
-type BazelOutPath struct {
- OutputPath
-}
-
-var _ Path = BazelOutPath{}
-var _ objPathProvider = BazelOutPath{}
-
-func (p BazelOutPath) objPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleObjPath {
- return PathForModuleObj(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
-}
-
// PathForVndkRefAbiDump returns an OptionalPath representing the path of the
// reference abi dump for the given module. This is not guaranteed to be valid.
func PathForVndkRefAbiDump(ctx ModuleInstallPathContext, version, fileName string,
@@ -1615,25 +1386,6 @@
fileName+ext)
}
-// PathForBazelOut returns a Path representing the paths... under an output directory dedicated to
-// bazel-owned outputs.
-func PathForBazelOut(ctx PathContext, paths ...string) BazelOutPath {
- execRootPathComponents := append([]string{"execroot", "__main__"}, paths...)
- execRootPath := filepath.Join(execRootPathComponents...)
- validatedExecRootPath, err := validatePath(execRootPath)
- if err != nil {
- reportPathError(ctx, err)
- }
-
- outputPath := OutputPath{basePath{"", ""},
- ctx.Config().buildDir,
- ctx.Config().BazelContext.OutputBase()}
-
- return BazelOutPath{
- OutputPath: outputPath.withRel(validatedExecRootPath),
- }
-}
-
// PathForModuleOut returns a Path representing the paths... under the module's
// output directory.
func PathForModuleOut(ctx ModuleOutPathContext, paths ...string) ModuleOutPath {
diff --git a/android/sdk_version.go b/android/sdk_version.go
index 98db824..c6c75a3 100644
--- a/android/sdk_version.go
+++ b/android/sdk_version.go
@@ -147,6 +147,11 @@
// UsePrebuilt determines whether prebuilt SDK should be used for this SdkSpec with the given context.
func (s SdkSpec) UsePrebuilt(ctx EarlyModuleContext) bool {
+ switch s {
+ case SdkSpecNone, SdkSpecCorePlatform, SdkSpecPrivate:
+ return false
+ }
+
if s.ApiLevel.IsCurrent() {
// "current" can be built from source and be from prebuilt SDK
return ctx.Config().AlwaysUsePrebuiltSdks()
@@ -159,7 +164,6 @@
// numbered SDKs are always from prebuilt
return true
}
- // "", "none", "core_platform" fall here
return false
}
@@ -202,11 +206,9 @@
}
var (
- SdkSpecNone = SdkSpec{SdkNone, NoneApiLevel, "(no version)"}
- // TODO(b/175678607) ApiLevel of SdkSpecPrivate should be FutureApiLevel
- SdkSpecPrivate = SdkSpec{SdkPrivate, NoneApiLevel, ""}
- // TODO(b/175678607) ApiLevel of SdkSpecCorePlatform should be FutureApiLevel
- SdkSpecCorePlatform = SdkSpec{SdkCorePlatform, NoneApiLevel, "core_platform"}
+ SdkSpecNone = SdkSpec{SdkNone, NoneApiLevel, "(no version)"}
+ SdkSpecPrivate = SdkSpec{SdkPrivate, FutureApiLevel, ""}
+ SdkSpecCorePlatform = SdkSpec{SdkCorePlatform, FutureApiLevel, "core_platform"}
)
func SdkSpecFrom(ctx EarlyModuleContext, str string) SdkSpec {
diff --git a/android/variable.go b/android/variable.go
index f25143d..e830845 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -331,8 +331,7 @@
VendorVars map[string]map[string]string `json:",omitempty"`
- Ndk_abis *bool `json:",omitempty"`
- Exclude_draft_ndk_apis *bool `json:",omitempty"`
+ Ndk_abis *bool `json:",omitempty"`
Flatten_apex *bool `json:",omitempty"`
ForceApexSymlinkOptimization *bool `json:",omitempty"`
diff --git a/apex/apex.go b/apex/apex.go
index 0eacf6d..f5e6fa9 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -903,7 +903,7 @@
// be built for this apexBundle.
apexInfo := android.ApexInfo{
ApexVariationName: mctx.ModuleName(),
- MinSdkVersionStr: minSdkVersion.String(),
+ MinSdkVersion: minSdkVersion,
RequiredSdks: a.RequiredSdks(),
Updatable: a.Updatable(),
InApexes: []string{mctx.ModuleName()},
diff --git a/bp2build/Android.bp b/bp2build/Android.bp
index d2a8729..abd79f5 100644
--- a/bp2build/Android.bp
+++ b/bp2build/Android.bp
@@ -14,6 +14,7 @@
"constants.go",
"conversion.go",
"metrics.go",
+ "symlink_forest.go",
],
deps: [
"soong-android",
diff --git a/bp2build/conversion_test.go b/bp2build/conversion_test.go
index 9fd6817..262a488 100644
--- a/bp2build/conversion_test.go
+++ b/bp2build/conversion_test.go
@@ -19,14 +19,14 @@
"testing"
)
-type filepath struct {
+type bazelFilepath struct {
dir string
basename string
}
func TestCreateBazelFiles_QueryView_AddsTopLevelFiles(t *testing.T) {
files := CreateBazelFiles(map[string]RuleShim{}, map[string]BazelTargets{}, QueryView)
- expectedFilePaths := []filepath{
+ expectedFilePaths := []bazelFilepath{
{
dir: "",
basename: "BUILD",
diff --git a/bp2build/symlink_forest.go b/bp2build/symlink_forest.go
new file mode 100644
index 0000000..80ad3b6
--- /dev/null
+++ b/bp2build/symlink_forest.go
@@ -0,0 +1,189 @@
+package bp2build
+
+import (
+ "fmt"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+
+ "android/soong/shared"
+)
+
+// A tree structure that describes what to do at each directory in the created
+// symlink tree. Currently it is used to enumerate which files/directories
+// should be excluded from symlinking. Each instance of "node" represents a file
+// or a directory. If excluded is true, then that file/directory should be
+// excluded from symlinking. Otherwise, the node is not excluded, but one of its
+// descendants is (otherwise the node in question would not exist)
+type node struct {
+ name string
+ excluded bool // If false, this is just an intermediate node
+ children map[string]*node
+}
+
+// Ensures that the a node for the given path exists in the tree and returns it.
+func ensureNodeExists(root *node, path string) *node {
+ if path == "" {
+ return root
+ }
+
+ if path[len(path)-1] == '/' {
+ path = path[:len(path)-1] // filepath.Split() leaves a trailing slash
+ }
+
+ dir, base := filepath.Split(path)
+
+ // First compute the parent node...
+ dn := ensureNodeExists(root, dir)
+
+ // then create the requested node as its direct child, if needed.
+ if child, ok := dn.children[base]; ok {
+ return child
+ } else {
+ dn.children[base] = &node{base, false, make(map[string]*node)}
+ return dn.children[base]
+ }
+}
+
+// Turns a list of paths to be excluded into a tree made of "node" objects where
+// the specified paths are marked as excluded.
+func treeFromExcludePathList(paths []string) *node {
+ result := &node{"", false, make(map[string]*node)}
+
+ for _, p := range paths {
+ ensureNodeExists(result, p).excluded = true
+ }
+
+ return result
+}
+
+// Calls readdir() and returns it as a map from the basename of the files in dir
+// to os.FileInfo.
+func readdirToMap(dir string) map[string]os.FileInfo {
+ entryList, err := ioutil.ReadDir(dir)
+ result := make(map[string]os.FileInfo)
+
+ if err != nil {
+ if os.IsNotExist(err) {
+ // It's okay if a directory doesn't exist; it just means that one of the
+ // trees to be merged contains parts the other doesn't
+ return result
+ } else {
+ fmt.Fprintf(os.Stderr, "Cannot readdir '%s': %s\n", dir, err)
+ os.Exit(1)
+ }
+ }
+
+ for _, fi := range entryList {
+ result[fi.Name()] = fi
+ }
+
+ return result
+}
+
+// Creates a symbolic link at dst pointing to src
+func symlinkIntoForest(topdir, dst, src string) {
+ err := os.Symlink(shared.JoinPath(topdir, src), shared.JoinPath(topdir, dst))
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Cannot create symlink at '%s' pointing to '%s': %s", dst, src, err)
+ os.Exit(1)
+ }
+}
+
+// Recursively plants a symlink forest at forestDir. The symlink tree will
+// contain every file in buildFilesDir and srcDir excluding the files in
+// exclude. Collects every directory encountered during the traversal of srcDir
+// into acc.
+func plantSymlinkForestRecursive(topdir string, forestDir string, buildFilesDir string, srcDir string, exclude *node, acc *[]string) {
+ if exclude != nil && exclude.excluded {
+ // This directory is not needed, bail out
+ return
+ }
+
+ *acc = append(*acc, srcDir)
+ srcDirMap := readdirToMap(shared.JoinPath(topdir, srcDir))
+ buildFilesMap := readdirToMap(shared.JoinPath(topdir, buildFilesDir))
+
+ allEntries := make(map[string]bool)
+ for n, _ := range srcDirMap {
+ allEntries[n] = true
+ }
+
+ for n, _ := range buildFilesMap {
+ allEntries[n] = true
+ }
+
+ err := os.MkdirAll(shared.JoinPath(topdir, forestDir), 0777)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Cannot mkdir '%s': %s\n", forestDir, err)
+ os.Exit(1)
+ }
+
+ for f, _ := range allEntries {
+ if f[0] == '.' {
+ continue // Ignore dotfiles
+ }
+
+ // The full paths of children in the input trees and in the output tree
+ fp := shared.JoinPath(forestDir, f)
+ sp := shared.JoinPath(srcDir, f)
+ bp := shared.JoinPath(buildFilesDir, f)
+
+ // Descend in the exclusion tree, if there are any excludes left
+ var ce *node
+ if exclude == nil {
+ ce = nil
+ } else {
+ ce = exclude.children[f]
+ }
+
+ sf, sExists := srcDirMap[f]
+ bf, bExists := buildFilesMap[f]
+ excluded := ce != nil && ce.excluded
+
+ if excluded {
+ continue
+ }
+
+ if !sExists {
+ if bf.IsDir() && ce != nil {
+ // Not in the source tree, but we have to exclude something from under
+ // this subtree, so descend
+ plantSymlinkForestRecursive(topdir, fp, bp, sp, ce, acc)
+ } else {
+ // Not in the source tree, symlink BUILD file
+ symlinkIntoForest(topdir, fp, bp)
+ }
+ } else if !bExists {
+ if sf.IsDir() && ce != nil {
+ // Not in the build file tree, but we have to exclude something from
+ // under this subtree, so descend
+ plantSymlinkForestRecursive(topdir, fp, bp, sp, ce, acc)
+ } else {
+ // Not in the build file tree, symlink source tree, carry on
+ symlinkIntoForest(topdir, fp, sp)
+ }
+ } else if sf.IsDir() && bf.IsDir() {
+ // Both are directories. Descend.
+ plantSymlinkForestRecursive(topdir, fp, bp, sp, ce, acc)
+ } else {
+ // Both exist and one is a file. This is an error.
+ fmt.Fprintf(os.Stderr,
+ "Conflict in workspace symlink tree creation: both '%s' and '%s' exist and at least one of them is a file\n",
+ sp, bp)
+ os.Exit(1)
+ }
+ }
+}
+
+// Creates a symlink forest by merging the directory tree at "buildFiles" and
+// "srcDir" while excluding paths listed in "exclude". Returns the set of paths
+// under srcDir on which readdir() had to be called to produce the symlink
+// forest.
+func PlantSymlinkForest(topdir string, forest string, buildFiles string, srcDir string, exclude []string) []string {
+ deps := make([]string, 0)
+ os.RemoveAll(shared.JoinPath(topdir, forest))
+ excludeTree := treeFromExcludePathList(exclude)
+ plantSymlinkForestRecursive(topdir, forest, buildFiles, srcDir, excludeTree, &deps)
+ return deps
+}
diff --git a/cc/api_level.go b/cc/api_level.go
index c93d6ed..fd145a9 100644
--- a/cc/api_level.go
+++ b/cc/api_level.go
@@ -53,14 +53,6 @@
return value, nil
}
-func nativeApiLevelFromUserWithDefault(ctx android.BaseModuleContext,
- raw string, defaultValue string) (android.ApiLevel, error) {
- if raw == "" {
- raw = defaultValue
- }
- return nativeApiLevelFromUser(ctx, raw)
-}
-
func nativeApiLevelOrPanic(ctx android.BaseModuleContext,
raw string) android.ApiLevel {
value, err := nativeApiLevelFromUser(ctx, raw)
diff --git a/cc/cc.go b/cc/cc.go
index bef49b8..9eebbae 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1641,7 +1641,7 @@
func (c *Module) maybeGenerateBazelActions(actx android.ModuleContext) bool {
bazelModuleLabel := c.GetBazelLabel(actx, c)
bazelActionsUsed := false
- if c.bazelHandler != nil && actx.Config().BazelContext.BazelEnabled() && len(bazelModuleLabel) > 0 {
+ if c.MixedBuildsEnabled(actx) && c.bazelHandler != nil {
bazelActionsUsed = c.bazelHandler.generateBazelBuildActions(actx, bazelModuleLabel)
}
return bazelActionsUsed
@@ -2499,7 +2499,7 @@
c.apexSdkVersion = android.FutureApiLevel
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
if !apexInfo.IsForPlatform() {
- c.apexSdkVersion = apexInfo.MinSdkVersion(ctx)
+ c.apexSdkVersion = apexInfo.MinSdkVersion
}
if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 07dcc95..db696ef 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -546,6 +546,22 @@
},
}
+ cc_library {
+ name: "libllndk",
+ llndk_stubs: "libllndk.llndk",
+ }
+
+ llndk_library {
+ name: "libllndk.llndk",
+ symbol_file: "",
+ export_llndk_headers: ["libllndk_headers"],
+ }
+
+ llndk_headers {
+ name: "libllndk_headers",
+ export_include_dirs: ["include"],
+ }
+
llndk_libraries_txt {
name: "llndk.libraries.txt",
}
@@ -597,8 +613,11 @@
vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
+ llndkLibPath := filepath.Join(vndkLibPath, "shared", "llndk-stub")
+
vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
+ llndkLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "llndk-stub")
variant := "android_vendor.29_arm64_armv8-a_shared"
variant2nd := "android_vendor.29_arm_armv7-a-neon_shared"
@@ -611,6 +630,8 @@
checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd)
checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
+ checkSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLibPath, variant)
+ checkSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLib2ndPath, variant2nd)
snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
checkSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "")
@@ -623,6 +644,7 @@
"LLNDK: libc.so",
"LLNDK: libdl.so",
"LLNDK: libft2.so",
+ "LLNDK: libllndk.so",
"LLNDK: libm.so",
"VNDK-SP: libc++.so",
"VNDK-SP: libvndk_sp-x.so",
@@ -639,7 +661,7 @@
"VNDK-product: libvndk_product.so",
"VNDK-product: libvndk_sp_product_private-x.so",
})
- checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
+ checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libm.so"})
checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"})
checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
@@ -3756,59 +3778,6 @@
android.AssertStringDoesContain(t, "min sdk version", cFlags, "-target aarch64-linux-android29")
}
-func TestMinSdkVersionsOfCrtObjects(t *testing.T) {
- ctx := testCc(t, `
- cc_object {
- name: "crt_foo",
- srcs: ["foo.c"],
- crt: true,
- stl: "none",
- min_sdk_version: "28",
-
- }`)
-
- arch := "android_arm64_armv8-a"
- for _, v := range []string{"", "28", "29", "30", "current"} {
- var variant string
- if v == "" {
- variant = arch
- } else {
- variant = arch + "_sdk_" + v
- }
- cflags := ctx.ModuleForTests("crt_foo", variant).Rule("cc").Args["cFlags"]
- vNum := v
- if v == "current" || v == "" {
- vNum = "10000"
- }
- expected := "-target aarch64-linux-android" + vNum + " "
- android.AssertStringDoesContain(t, "cflag", cflags, expected)
- }
-}
-
-func TestUseCrtObjectOfCorrectVersion(t *testing.T) {
- ctx := testCc(t, `
- cc_binary {
- name: "bin",
- srcs: ["foo.c"],
- stl: "none",
- min_sdk_version: "29",
- sdk_version: "current",
- }
- `)
-
- // Sdk variant uses the crt object of the matching min_sdk_version
- variant := "android_arm64_armv8-a_sdk"
- crt := ctx.ModuleForTests("bin", variant).Rule("ld").Args["crtBegin"]
- android.AssertStringDoesContain(t, "crt dep of sdk variant", crt,
- variant+"_29/crtbegin_dynamic.o")
-
- // platform variant uses the crt object built for platform
- variant = "android_arm64_armv8-a"
- crt = ctx.ModuleForTests("bin", variant).Rule("ld").Args["crtBegin"]
- android.AssertStringDoesContain(t, "crt dep of platform variant", crt,
- variant+"/crtbegin_dynamic.o")
-}
-
type MemtagNoteType int
const (
diff --git a/cc/config/global.go b/cc/config/global.go
index ed18300..23106ec 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -145,8 +145,8 @@
// prebuilts/clang default settings.
ClangDefaultBase = "prebuilts/clang/host"
- ClangDefaultVersion = "clang-r416183"
- ClangDefaultShortVersion = "12.0.4"
+ ClangDefaultVersion = "clang-r416183b"
+ ClangDefaultShortVersion = "12.0.5"
// Directories with warnings from Android.bp files.
WarningAllowedProjects = []string{
diff --git a/cc/library.go b/cc/library.go
index 53be3a5..2b0ee46 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -60,6 +60,7 @@
Static_ndk_lib *bool
+ // Generate stubs to make this library accessible to APEXes.
Stubs struct {
// Relative path to the symbol map. The symbol map provides the list of
// symbols that are exported for stubs variant of this library.
@@ -1256,6 +1257,7 @@
UnstrippedSharedLibrary: library.unstrippedOutputFile,
CoverageSharedLibrary: library.coverageOutputFile,
StaticAnalogue: staticAnalogue,
+ Target: ctx.Target(),
})
stubs := ctx.GetDirectDepsWithTag(stubImplDepTag)
diff --git a/cc/linkable.go b/cc/linkable.go
index 571a3bb..0fb9c09 100644
--- a/cc/linkable.go
+++ b/cc/linkable.go
@@ -209,6 +209,7 @@
type SharedLibraryInfo struct {
SharedLibrary android.Path
UnstrippedSharedLibrary android.Path
+ Target android.Target
TableOfContents android.OptionalPath
CoverageSharedLibrary android.OptionalPath
diff --git a/cc/ndk_headers.go b/cc/ndk_headers.go
index 60f931d..56fd5fc 100644
--- a/cc/ndk_headers.go
+++ b/cc/ndk_headers.go
@@ -75,11 +75,6 @@
// Path to the NOTICE file associated with the headers.
License *string `android:"path"`
-
- // True if this API is not yet ready to be shipped in the NDK. It will be
- // available in the platform for testing, but will be excluded from the
- // sysroot provided to the NDK proper.
- Draft bool
}
type headerModule struct {
@@ -184,11 +179,6 @@
// Path to the NOTICE file associated with the headers.
License *string
-
- // True if this API is not yet ready to be shipped in the NDK. It will be
- // available in the platform for testing, but will be excluded from the
- // sysroot provided to the NDK proper.
- Draft bool
}
// Like ndk_headers, but preprocesses the headers with the bionic versioner:
@@ -311,11 +301,6 @@
// Path to the NOTICE file associated with the headers.
License *string
-
- // True if this API is not yet ready to be shipped in the NDK. It will be
- // available in the platform for testing, but will be excluded from the
- // sysroot provided to the NDK proper.
- Draft bool
}
type preprocessedHeadersModule struct {
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index 10de889..95d8477 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -20,6 +20,7 @@
"sync"
"github.com/google/blueprint"
+ "github.com/google/blueprint/proptools"
"android/soong/android"
)
@@ -78,11 +79,6 @@
// used. This is only needed to work around platform bugs like
// https://github.com/android-ndk/ndk/issues/265.
Unversioned_until *string
-
- // True if this API is not yet ready to be shipped in the NDK. It will be
- // available in the platform for testing, but will be excluded from the
- // sysroot provided to the NDK proper.
- Draft bool
}
type stubDecorator struct {
@@ -147,8 +143,8 @@
return false
}
- this.unversionedUntil, err = nativeApiLevelFromUserWithDefault(ctx,
- String(this.properties.Unversioned_until), "minimum")
+ str := proptools.StringDefault(this.properties.Unversioned_until, "minimum")
+ this.unversionedUntil, err = nativeApiLevelFromUser(ctx, str)
if err != nil {
ctx.PropertyErrorf("unversioned_until", err.Error())
return false
diff --git a/cc/ndk_prebuilt.go b/cc/ndk_prebuilt.go
index 8d522d0..b91c737 100644
--- a/cc/ndk_prebuilt.go
+++ b/cc/ndk_prebuilt.go
@@ -188,6 +188,7 @@
ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{
SharedLibrary: lib,
UnstrippedSharedLibrary: lib,
+ Target: ctx.Target(),
})
}
diff --git a/cc/ndk_sysroot.go b/cc/ndk_sysroot.go
index 70b15c1..d8c500e 100644
--- a/cc/ndk_sysroot.go
+++ b/cc/ndk_sysroot.go
@@ -104,38 +104,22 @@
}
if m, ok := module.(*headerModule); ok {
- if ctx.Config().ExcludeDraftNdkApis() && m.properties.Draft {
- return
- }
-
installPaths = append(installPaths, m.installPaths...)
licensePaths = append(licensePaths, m.licensePath)
}
if m, ok := module.(*versionedHeaderModule); ok {
- if ctx.Config().ExcludeDraftNdkApis() && m.properties.Draft {
- return
- }
-
installPaths = append(installPaths, m.installPaths...)
licensePaths = append(licensePaths, m.licensePath)
}
if m, ok := module.(*preprocessedHeadersModule); ok {
- if ctx.Config().ExcludeDraftNdkApis() && m.properties.Draft {
- return
- }
-
installPaths = append(installPaths, m.installPaths...)
licensePaths = append(licensePaths, m.licensePath)
}
if m, ok := module.(*Module); ok {
if installer, ok := m.installer.(*stubDecorator); ok && m.library.buildStubs() {
- if ctx.Config().ExcludeDraftNdkApis() &&
- installer.properties.Draft {
- return
- }
installPaths = append(installPaths, installer.installPath)
}
diff --git a/cc/object_test.go b/cc/object_test.go
index f82d544..0e5508a 100644
--- a/cc/object_test.go
+++ b/cc/object_test.go
@@ -19,6 +19,60 @@
"testing"
)
+func TestMinSdkVersionsOfCrtObjects(t *testing.T) {
+ ctx := testCc(t, `
+ cc_object {
+ name: "crt_foo",
+ srcs: ["foo.c"],
+ crt: true,
+ stl: "none",
+ min_sdk_version: "28",
+
+ }`)
+
+ arch := "android_arm64_armv8-a"
+ for _, v := range []string{"", "28", "29", "30", "current"} {
+ var variant string
+ // platform variant
+ if v == "" {
+ variant = arch
+ } else {
+ variant = arch + "_sdk_" + v
+ }
+ cflags := ctx.ModuleForTests("crt_foo", variant).Rule("cc").Args["cFlags"]
+ vNum := v
+ if v == "current" || v == "" {
+ vNum = "10000"
+ }
+ expected := "-target aarch64-linux-android" + vNum + " "
+ android.AssertStringDoesContain(t, "cflag", cflags, expected)
+ }
+}
+
+func TestUseCrtObjectOfCorrectVersion(t *testing.T) {
+ ctx := testCc(t, `
+ cc_binary {
+ name: "bin",
+ srcs: ["foo.c"],
+ stl: "none",
+ min_sdk_version: "29",
+ sdk_version: "current",
+ }
+ `)
+
+ // Sdk variant uses the crt object of the matching min_sdk_version
+ variant := "android_arm64_armv8-a_sdk"
+ crt := ctx.ModuleForTests("bin", variant).Rule("ld").Args["crtBegin"]
+ android.AssertStringDoesContain(t, "crt dep of sdk variant", crt,
+ variant+"_29/crtbegin_dynamic.o")
+
+ // platform variant uses the crt object built for platform
+ variant = "android_arm64_armv8-a"
+ crt = ctx.ModuleForTests("bin", variant).Rule("ld").Args["crtBegin"]
+ android.AssertStringDoesContain(t, "crt dep of platform variant", crt,
+ variant+"/crtbegin_dynamic.o")
+}
+
func TestLinkerScript(t *testing.T) {
t.Run("script", func(t *testing.T) {
testCc(t, `
diff --git a/cc/prebuilt.go b/cc/prebuilt.go
index c19b1ff..bea1782 100644
--- a/cc/prebuilt.go
+++ b/cc/prebuilt.go
@@ -185,6 +185,7 @@
ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{
SharedLibrary: outputFile,
UnstrippedSharedLibrary: p.unstrippedOutputFile,
+ Target: ctx.Target(),
TableOfContents: p.tocFile,
})
diff --git a/cc/snapshot_prebuilt.go b/cc/snapshot_prebuilt.go
index 6d48aed..885a0ce 100644
--- a/cc/snapshot_prebuilt.go
+++ b/cc/snapshot_prebuilt.go
@@ -591,6 +591,7 @@
ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{
SharedLibrary: in,
UnstrippedSharedLibrary: p.unstrippedOutputFile,
+ Target: ctx.Target(),
TableOfContents: p.tocFile,
})
diff --git a/cc/vndk.go b/cc/vndk.go
index 1a8a454..41f9fd3 100644
--- a/cc/vndk.go
+++ b/cc/vndk.go
@@ -609,19 +609,26 @@
}
// !inVendor: There's product/vendor variants for VNDK libs. We only care about vendor variants.
// !installable: Snapshot only cares about "installable" modules.
+ // !m.IsLlndk: llndk stubs are required for building against snapshots.
// IsSnapshotPrebuilt: Snapshotting a snapshot doesn't make sense.
- if !m.InVendor() || !m.installable(apexInfo) || m.IsSnapshotPrebuilt() {
+ // !outputFile.Valid: Snapshot requires valid output file.
+ if !m.InVendor() || (!m.installable(apexInfo) && !m.IsLlndk()) || m.IsSnapshotPrebuilt() || !m.outputFile.Valid() {
return nil, "", false
}
l, ok := m.linker.(snapshotLibraryInterface)
if !ok || !l.shared() {
return nil, "", false
}
- if m.VndkVersion() == config.PlatformVndkVersion() && m.IsVndk() && !m.IsVndkExt() {
- if m.isVndkSp() {
- return l, "vndk-sp", true
- } else {
- return l, "vndk-core", true
+ if m.VndkVersion() == config.PlatformVndkVersion() {
+ if m.IsVndk() && !m.IsVndkExt() {
+ if m.isVndkSp() {
+ return l, "vndk-sp", true
+ } else {
+ return l, "vndk-core", true
+ }
+ } else if l.hasLLNDKStubs() && l.stubsVersion() == "" {
+ // Use default version for the snapshot.
+ return l, "llndk-stub", true
}
}
@@ -652,12 +659,16 @@
(VNDK-core libraries, e.g. libbinder.so)
vndk-sp/
(VNDK-SP libraries, e.g. libc++.so)
+ llndk-stub/
+ (LLNDK stub libraries)
arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
shared/
vndk-core/
(VNDK-core libraries, e.g. libbinder.so)
vndk-sp/
(VNDK-SP libraries, e.g. libc++.so)
+ llndk-stub/
+ (LLNDK stub libraries)
binder32/
(This directory is newly introduced in v28 (Android P) to hold
prebuilts built for 32-bit binder interface.)
diff --git a/cc/vndk_prebuilt.go b/cc/vndk_prebuilt.go
index 71e6427..fc4412a 100644
--- a/cc/vndk_prebuilt.go
+++ b/cc/vndk_prebuilt.go
@@ -170,6 +170,7 @@
ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{
SharedLibrary: in,
UnstrippedSharedLibrary: p.unstrippedOutputFile,
+ Target: ctx.Target(),
TableOfContents: p.tocFile,
})
diff --git a/cmd/sbox/sbox.go b/cmd/sbox/sbox.go
index 7bd0868..f124e40 100644
--- a/cmd/sbox/sbox.go
+++ b/cmd/sbox/sbox.go
@@ -230,7 +230,7 @@
}
// Copy in any files specified by the manifest.
- err = copyFiles(command.CopyBefore, "", tempDir)
+ err = copyFiles(command.CopyBefore, "", tempDir, false)
if err != nil {
return "", err
}
@@ -255,12 +255,11 @@
return "", err
}
- commandDescription := rawCommand
-
cmd := exec.Command("bash", "-c", rawCommand)
+ buf := &bytes.Buffer{}
cmd.Stdin = os.Stdin
- cmd.Stdout = os.Stdout
- cmd.Stderr = os.Stderr
+ cmd.Stdout = buf
+ cmd.Stderr = buf
if command.GetChdir() {
cmd.Dir = tempDir
@@ -276,9 +275,29 @@
}
err = cmd.Run()
+ if err != nil {
+ // The command failed, do a best effort copy of output files out of the sandbox. This is
+ // especially useful for linters with baselines that print an error message on failure
+ // with a command to copy the output lint errors to the new baseline. Use a copy instead of
+ // a move to leave the sandbox intact for manual inspection
+ copyFiles(command.CopyAfter, tempDir, "", true)
+ }
+
+ // If the command was executed but failed with an error, print a debugging message before
+ // the command's output so it doesn't scroll the real error message off the screen.
if exit, ok := err.(*exec.ExitError); ok && !exit.Success() {
- return "", fmt.Errorf("sbox command failed with err:\n%s\n%w\n", commandDescription, err)
- } else if err != nil {
+ fmt.Fprintf(os.Stderr,
+ "The failing command was run inside an sbox sandbox in temporary directory\n"+
+ "%s\n"+
+ "The failing command line was:\n"+
+ "%s\n",
+ tempDir, rawCommand)
+ }
+
+ // Write the command's combined stdout/stderr.
+ os.Stdout.Write(buf.Bytes())
+
+ if err != nil {
return "", err
}
@@ -290,7 +309,7 @@
// build error message
errorMessage := "mismatch between declared and actual outputs\n"
- errorMessage += "in sbox command(" + commandDescription + ")\n\n"
+ errorMessage += "in sbox command(" + rawCommand + ")\n\n"
errorMessage += "in sandbox " + tempDir + ",\n"
errorMessage += fmt.Sprintf("failed to create %v files:\n", len(missingOutputErrors))
for _, missingOutputError := range missingOutputErrors {
@@ -351,12 +370,13 @@
return missingOutputErrors
}
-// copyFiles copies files in or out of the sandbox.
-func copyFiles(copies []*sbox_proto.Copy, fromDir, toDir string) error {
+// copyFiles copies files in or out of the sandbox. If allowFromNotExists is true then errors
+// caused by a from path not existing are ignored.
+func copyFiles(copies []*sbox_proto.Copy, fromDir, toDir string, allowFromNotExists bool) error {
for _, copyPair := range copies {
fromPath := joinPath(fromDir, copyPair.GetFrom())
toPath := joinPath(toDir, copyPair.GetTo())
- err := copyOneFile(fromPath, toPath, copyPair.GetExecutable())
+ err := copyOneFile(fromPath, toPath, copyPair.GetExecutable(), allowFromNotExists)
if err != nil {
return fmt.Errorf("error copying %q to %q: %w", fromPath, toPath, err)
}
@@ -364,8 +384,9 @@
return nil
}
-// copyOneFile copies a file.
-func copyOneFile(from string, to string, executable bool) error {
+// copyOneFile copies a file and its permissions. If forceExecutable is true it adds u+x to the
+// permissions. If allowFromNotExists is true it returns nil if the from path doesn't exist.
+func copyOneFile(from string, to string, forceExecutable, allowFromNotExists bool) error {
err := os.MkdirAll(filepath.Dir(to), 0777)
if err != nil {
return err
@@ -373,11 +394,14 @@
stat, err := os.Stat(from)
if err != nil {
+ if os.IsNotExist(err) && allowFromNotExists {
+ return nil
+ }
return err
}
perm := stat.Mode()
- if executable {
+ if forceExecutable {
perm = perm | 0100 // u+x
}
@@ -454,7 +478,7 @@
to := applyPathMappings(rspFile.PathMappings, from)
// Copy the file into the sandbox.
- err := copyOneFile(from, joinPath(toDir, to), false)
+ err := copyOneFile(from, joinPath(toDir, to), false, false)
if err != nil {
return err
}
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go
index 1e796ec..5bccf58 100644
--- a/cmd/soong_build/main.go
+++ b/cmd/soong_build/main.go
@@ -108,7 +108,7 @@
firstArgs = bootstrap.CmdlineArgs
configuration.SetStopBefore(bootstrap.StopBeforeWriteNinja)
- bootstrap.RunBlueprint(firstArgs, firstCtx.Context, configuration, extraNinjaDeps...)
+ bootstrap.RunBlueprint(firstArgs, firstCtx.Context, configuration)
// Invoke bazel commands and save results for second pass.
if err := configuration.BazelContext.InvokeBazel(); err != nil {
@@ -123,7 +123,8 @@
}
secondCtx := newContext(secondConfig, true)
secondArgs = bootstrap.CmdlineArgs
- ninjaDeps := bootstrap.RunBlueprint(secondArgs, secondCtx.Context, secondConfig, extraNinjaDeps...)
+ ninjaDeps := bootstrap.RunBlueprint(secondArgs, secondCtx.Context, secondConfig)
+ ninjaDeps = append(ninjaDeps, extraNinjaDeps...)
err = deptools.WriteDepFile(shared.JoinPath(topDir, secondArgs.DepFile), secondArgs.OutFile, ninjaDeps)
if err != nil {
fmt.Fprintf(os.Stderr, "Error writing depfile '%s': %s\n", secondArgs.DepFile, err)
@@ -141,10 +142,10 @@
}
}
-func runSoongDocs(configuration android.Config, extraNinjaDeps []string) {
+func runSoongDocs(configuration android.Config) {
ctx := newContext(configuration, false)
soongDocsArgs := bootstrap.CmdlineArgs
- bootstrap.RunBlueprint(soongDocsArgs, ctx.Context, configuration, extraNinjaDeps...)
+ bootstrap.RunBlueprint(soongDocsArgs, ctx.Context, configuration)
if err := writeDocs(ctx, configuration, docFile); err != nil {
fmt.Fprintf(os.Stderr, "%s", err)
os.Exit(1)
@@ -195,7 +196,8 @@
if mixedModeBuild {
runMixedModeBuild(configuration, ctx, extraNinjaDeps)
} else {
- ninjaDeps := bootstrap.RunBlueprint(blueprintArgs, ctx.Context, configuration, extraNinjaDeps...)
+ ninjaDeps := bootstrap.RunBlueprint(blueprintArgs, ctx.Context, configuration)
+ ninjaDeps = append(ninjaDeps, extraNinjaDeps...)
err := deptools.WriteDepFile(shared.JoinPath(topDir, blueprintArgs.DepFile), blueprintArgs.OutFile, ninjaDeps)
if err != nil {
fmt.Fprintf(os.Stderr, "Error writing depfile '%s': %s\n", blueprintArgs.DepFile, err)
@@ -278,7 +280,7 @@
// thus it would overwrite the actual used variables file so this is
// special-cased.
// TODO: Fix this by not passing --used_env to the soong_docs invocation
- runSoongDocs(configuration, extraNinjaDeps)
+ runSoongDocs(configuration)
return
}
@@ -387,12 +389,44 @@
// Modules parsed from Android.bp files, and the BazelTargetModules mapped
// from the regular Modules.
blueprintArgs := bootstrap.CmdlineArgs
- ninjaDeps := bootstrap.RunBlueprint(blueprintArgs, bp2buildCtx.Context, configuration, extraNinjaDeps...)
+ ninjaDeps := bootstrap.RunBlueprint(blueprintArgs, bp2buildCtx.Context, configuration)
+ ninjaDeps = append(ninjaDeps, extraNinjaDeps...)
for _, globPath := range bp2buildCtx.Globs() {
ninjaDeps = append(ninjaDeps, globPath.FileListFile(configuration.BuildDir()))
}
+ // Run the code-generation phase to convert BazelTargetModules to BUILD files
+ // and print conversion metrics to the user.
+ codegenContext := bp2build.NewCodegenContext(configuration, *bp2buildCtx, bp2build.Bp2Build)
+ metrics := bp2build.Codegen(codegenContext)
+
+ generatedRoot := shared.JoinPath(configuration.BuildDir(), "bp2build")
+ workspaceRoot := shared.JoinPath(configuration.BuildDir(), "workspace")
+
+ excludes := []string{
+ "bazel-bin",
+ "bazel-genfiles",
+ "bazel-out",
+ "bazel-testlogs",
+ "bazel-" + filepath.Base(topDir),
+ }
+
+ if bootstrap.CmdlineArgs.NinjaBuildDir[0] != '/' {
+ excludes = append(excludes, bootstrap.CmdlineArgs.NinjaBuildDir)
+ }
+
+ symlinkForestDeps := bp2build.PlantSymlinkForest(
+ topDir, workspaceRoot, generatedRoot, configuration.SrcDir(), excludes)
+
+ // Only report metrics when in bp2build mode. The metrics aren't relevant
+ // for queryview, since that's a total repo-wide conversion and there's a
+ // 1:1 mapping for each module.
+ metrics.Print()
+
+ ninjaDeps = append(ninjaDeps, codegenContext.AdditionalNinjaDeps()...)
+ ninjaDeps = append(ninjaDeps, symlinkForestDeps...)
+
depFile := bp2buildMarker + ".d"
err = deptools.WriteDepFile(shared.JoinPath(topDir, depFile), bp2buildMarker, ninjaDeps)
if err != nil {
@@ -400,17 +434,6 @@
os.Exit(1)
}
- // Run the code-generation phase to convert BazelTargetModules to BUILD files
- // and print conversion metrics to the user.
- codegenContext := bp2build.NewCodegenContext(configuration, *bp2buildCtx, bp2build.Bp2Build)
- metrics := bp2build.Codegen(codegenContext)
-
- // Only report metrics when in bp2build mode. The metrics aren't relevant
- // for queryview, since that's a total repo-wide conversion and there's a
- // 1:1 mapping for each module.
- metrics.Print()
-
- extraNinjaDeps = append(extraNinjaDeps, codegenContext.AdditionalNinjaDeps()...)
if bp2buildMarker != "" {
touch(shared.JoinPath(topDir, bp2buildMarker))
} else {
diff --git a/dexpreopt/config.go b/dexpreopt/config.go
index 02f1120..26ff5ba 100644
--- a/dexpreopt/config.go
+++ b/dexpreopt/config.go
@@ -115,7 +115,7 @@
DexLocation string // dex location on device
BuildPath android.OutputPath
DexPath android.Path
- ManifestPath android.Path
+ ManifestPath android.OptionalPath
UncompressedDex bool
HasApkLibraries bool
PreoptFlags []string
@@ -291,7 +291,7 @@
// Construct paths that require a PathContext.
config.ModuleConfig.BuildPath = constructPath(ctx, config.BuildPath).(android.OutputPath)
config.ModuleConfig.DexPath = constructPath(ctx, config.DexPath)
- config.ModuleConfig.ManifestPath = constructPath(ctx, config.ManifestPath)
+ config.ModuleConfig.ManifestPath = android.OptionalPathForPath(constructPath(ctx, config.ManifestPath))
config.ModuleConfig.ProfileClassListing = android.OptionalPathForPath(constructPath(ctx, config.ProfileClassListing))
config.ModuleConfig.EnforceUsesLibrariesStatusFile = constructPath(ctx, config.EnforceUsesLibrariesStatusFile)
config.ModuleConfig.ClassLoaderContexts = fromJsonClassLoaderContext(ctx, config.ClassLoaderContexts)
diff --git a/dexpreopt/dexpreopt.go b/dexpreopt/dexpreopt.go
index 81a63b0..dc17c0a 100644
--- a/dexpreopt/dexpreopt.go
+++ b/dexpreopt/dexpreopt.go
@@ -276,9 +276,9 @@
// no time/space is wasted on AOT-compiling modules that will fail CLC check on device.
var manifestOrApk android.Path
- if module.ManifestPath != nil {
+ if module.ManifestPath.Valid() {
// Ok, there is an XML manifest.
- manifestOrApk = module.ManifestPath
+ manifestOrApk = module.ManifestPath.Path()
} else if filepath.Ext(base) == ".apk" {
// Ok, there is is an APK with the manifest inside.
manifestOrApk = module.DexPath
diff --git a/filesystem/Android.bp b/filesystem/Android.bp
index 791019d..3cdaa64 100644
--- a/filesystem/Android.bp
+++ b/filesystem/Android.bp
@@ -15,8 +15,10 @@
"filesystem.go",
"logical_partition.go",
"vbmeta.go",
+ "testing.go",
],
testSrcs: [
+ "filesystem_test.go",
],
pluginFor: ["soong_build"],
}
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go
index b2bd6bd..cf98717 100644
--- a/filesystem/filesystem.go
+++ b/filesystem/filesystem.go
@@ -26,7 +26,11 @@
)
func init() {
- android.RegisterModuleType("android_filesystem", filesystemFactory)
+ registerBuildComponents(android.InitRegistrationContext)
+}
+
+func registerBuildComponents(ctx android.RegistrationContext) {
+ ctx.RegisterModuleType("android_filesystem", filesystemFactory)
}
type filesystem struct {
diff --git a/filesystem/filesystem_test.go b/filesystem/filesystem_test.go
new file mode 100644
index 0000000..880b177
--- /dev/null
+++ b/filesystem/filesystem_test.go
@@ -0,0 +1,42 @@
+// Copyright 2021 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package filesystem
+
+import (
+ "os"
+ "testing"
+
+ "android/soong/android"
+)
+
+func TestMain(m *testing.M) {
+ os.Exit(m.Run())
+}
+
+var fixture = android.GroupFixturePreparers(
+ android.PrepareForIntegrationTestWithAndroid,
+ PrepareForTestWithFilesystemBuildComponents,
+)
+
+func TestFileSystemDeps(t *testing.T) {
+ result := fixture.RunTestWithBp(t, `
+ android_filesystem {
+ name: "myfilesystem",
+ }
+ `)
+
+ // produces "myfilesystem.img"
+ result.ModuleForTests("myfilesystem", "android_common").Output("myfilesystem.img")
+}
diff --git a/filesystem/testing.go b/filesystem/testing.go
new file mode 100644
index 0000000..631f1b1
--- /dev/null
+++ b/filesystem/testing.go
@@ -0,0 +1,19 @@
+// Copyright 2021 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package filesystem
+
+import "android/soong/android"
+
+var PrepareForTestWithFilesystemBuildComponents = android.FixtureRegisterWithContext(registerBuildComponents)
diff --git a/genrule/genrule.go b/genrule/genrule.go
index e6a5ab9..3a9aecc 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -543,7 +543,7 @@
bazelModuleLabel := g.GetBazelLabel(ctx, g)
bazelActionsUsed := false
- if ctx.Config().BazelContext.BazelEnabled() && len(bazelModuleLabel) > 0 {
+ if g.MixedBuildsEnabled(ctx) {
bazelActionsUsed = g.generateBazelBuildActions(ctx, bazelModuleLabel)
}
if !bazelActionsUsed {
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
index b4cf012..3571590 100644
--- a/java/dexpreopt.go
+++ b/java/dexpreopt.go
@@ -221,7 +221,7 @@
DexLocation: dexLocation,
BuildPath: android.PathForModuleOut(ctx, "dexpreopt", ctx.ModuleName()+".jar").OutputPath,
DexPath: dexJarFile,
- ManifestPath: d.manifestFile,
+ ManifestPath: android.OptionalPathForPath(d.manifestFile),
UncompressedDex: d.uncompressedDex,
HasApkLibraries: false,
PreoptFlags: nil,
diff --git a/java/droidstubs.go b/java/droidstubs.go
index a9e2749..2676f3d 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -516,9 +516,6 @@
d.apiLintTimestamp = android.PathForModuleOut(ctx, "metalava", "api_lint.timestamp")
// Note this string includes a special shell quote $' ... ', which decodes the "\n"s.
- // However, because $' ... ' doesn't expand environmental variables, we can't just embed
- // $PWD, so we have to terminate $'...', use "$PWD", then start $' ... ' again,
- // which is why we have '"$PWD"$' in it.
//
// TODO: metalava also has a slightly different message hardcoded. Should we unify this
// message and metalava's one?
@@ -539,9 +536,9 @@
msg += fmt.Sprintf(``+
`2. You can update the baseline by executing the following\n`+
` command:\n`+
- ` cp \\\n`+
- ` "'"$PWD"$'/%s" \\\n`+
- ` "'"$PWD"$'/%s"\n`+
+ ` (cd $ANDROID_BUILD_TOP && cp \\\n`+
+ ` "%s" \\\n`+
+ ` "%s")\n`+
` To submit the revised baseline.txt to the main Android\n`+
` repository, you will need approval.\n`, updatedBaselineOutput, baselineFile.Path())
} else {
diff --git a/java/java.go b/java/java.go
index ee4f2eb..adb0c56 100644
--- a/java/java.go
+++ b/java/java.go
@@ -27,6 +27,7 @@
"github.com/google/blueprint/proptools"
"android/soong/android"
+ "android/soong/cc"
"android/soong/dexpreopt"
"android/soong/java/config"
"android/soong/tradefed"
@@ -708,6 +709,9 @@
// Test options.
Test_options TestOptions
+
+ // Names of modules containing JNI libraries that should be installed alongside the test.
+ Jni_libs []string
}
type hostTestProperties struct {
@@ -769,6 +773,13 @@
}
}
+ if len(j.testProperties.Jni_libs) > 0 {
+ for _, target := range ctx.MultiTargets() {
+ sharedLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
+ ctx.AddFarVariationDependencies(sharedLibVariations, jniLibTag, j.testProperties.Jni_libs...)
+ }
+ }
+
j.deps(ctx)
}
@@ -793,6 +804,29 @@
j.data = append(j.data, android.OutputFileForModule(ctx, dep, ""))
})
+ ctx.VisitDirectDepsWithTag(jniLibTag, func(dep android.Module) {
+ sharedLibInfo := ctx.OtherModuleProvider(dep, cc.SharedLibraryInfoProvider).(cc.SharedLibraryInfo)
+ if sharedLibInfo.SharedLibrary != nil {
+ // Copy to an intermediate output directory to append "lib[64]" to the path,
+ // so that it's compatible with the default rpath values.
+ var relPath string
+ if sharedLibInfo.Target.Arch.ArchType.Multilib == "lib64" {
+ relPath = filepath.Join("lib64", sharedLibInfo.SharedLibrary.Base())
+ } else {
+ relPath = filepath.Join("lib", sharedLibInfo.SharedLibrary.Base())
+ }
+ relocatedLib := android.PathForModuleOut(ctx, "relocated").Join(ctx, relPath)
+ ctx.Build(pctx, android.BuildParams{
+ Rule: android.Cp,
+ Input: sharedLibInfo.SharedLibrary,
+ Output: relocatedLib,
+ })
+ j.data = append(j.data, relocatedLib)
+ } else {
+ ctx.PropertyErrorf("jni_libs", "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep))
+ }
+ })
+
j.Library.GenerateAndroidBuildActions(ctx)
}
diff --git a/java/java_test.go b/java/java_test.go
index 0523458..e7ea4ef 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -20,6 +20,7 @@
"path/filepath"
"reflect"
"regexp"
+ "runtime"
"strconv"
"strings"
"testing"
@@ -462,6 +463,38 @@
}
}
+func TestTest(t *testing.T) {
+ ctx, _ := testJava(t, `
+ java_test_host {
+ name: "foo",
+ srcs: ["a.java"],
+ jni_libs: ["libjni"],
+ }
+
+ cc_library_shared {
+ name: "libjni",
+ host_supported: true,
+ device_supported: false,
+ stl: "none",
+ }
+ `)
+
+ buildOS := android.BuildOs.String()
+
+ foo := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost)
+
+ expected := "lib64/libjni.so"
+ if runtime.GOOS == "darwin" {
+ expected = "lib64/libjni.dylib"
+ }
+
+ fooTestData := foo.data
+ if len(fooTestData) != 1 || fooTestData[0].Rel() != expected {
+ t.Errorf(`expected foo test data relative path [%q], got %q`,
+ expected, fooTestData.Strings())
+ }
+}
+
func TestHostBinaryNoJavaDebugInfoOverride(t *testing.T) {
bp := `
java_library {
diff --git a/java/sdk_library.go b/java/sdk_library.go
index e5ee397..223be5c 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -534,6 +534,11 @@
// This is not the implementation jar, it still only contains stubs.
stubsImplPath android.Paths
+ // The dex jar for the stubs.
+ //
+ // This is not the implementation jar, it still only contains stubs.
+ stubsDexJarPath android.Path
+
// The API specification file, e.g. system_current.txt.
currentApiFilePath android.OptionalPath
@@ -549,6 +554,9 @@
lib := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo)
paths.stubsHeaderPath = lib.HeaderJars
paths.stubsImplPath = lib.ImplementationJars
+
+ libDep := dep.(UsesLibraryDependency)
+ paths.stubsDexJarPath = libDep.DexJarBuildPath()
return nil
} else {
return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library")
@@ -825,8 +833,22 @@
return PrebuiltJars(ctx, c.moduleBase.BaseModuleName(), sdkVersion)
}
+ paths := c.selectScopePaths(ctx, sdkVersion.Kind)
+ if paths == nil {
+ return nil
+ }
+
+ return paths.stubsHeaderPath
+}
+
+// selectScopePaths returns the *scopePaths appropriate for the specific kind.
+//
+// If the module does not support the specific kind then it will return the *scopePaths for the
+// closest kind which is a subset of the requested kind. e.g. if requesting android.SdkModule then
+// it will return *scopePaths for android.SdkSystem if available or android.SdkPublic of not.
+func (c *commonToSdkLibraryAndImport) selectScopePaths(ctx android.BaseModuleContext, kind android.SdkKind) *scopePaths {
var apiScope *apiScope
- switch sdkVersion.Kind {
+ switch kind {
case android.SdkSystem:
apiScope = apiScopeSystem
case android.SdkModule:
@@ -851,7 +873,17 @@
return nil
}
- return paths.stubsHeaderPath
+ return paths
+}
+
+// to satisfy SdkLibraryDependency interface
+func (c *commonToSdkLibraryAndImport) SdkApiStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) android.Path {
+ paths := c.selectScopePaths(ctx, kind)
+ if paths == nil {
+ return nil
+ }
+
+ return paths.stubsDexJarPath
}
func (c *commonToSdkLibraryAndImport) sdkComponentPropertiesForChildLibrary() interface{} {
@@ -944,6 +976,10 @@
// jars for the stubs. The latter should only be needed when generating JavaDoc as otherwise
// they are identical to the corresponding header jars.
SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths
+
+ // SdkApiStubDexJar returns the dex jar for the stubs. It is needed by the hiddenapi processing
+ // tool which processes dex files.
+ SdkApiStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) android.Path
}
type SdkLibrary struct {
@@ -1781,6 +1817,9 @@
// List of shared java libs, common to all scopes, that this module has
// dependencies to
Libs []string
+
+ // If set to true, compile dex files for the stubs. Defaults to false.
+ Compile_dex *bool
}
type SdkLibraryImport struct {
@@ -1916,6 +1955,7 @@
Libs []string
Jars []string
Prefer *bool
+ Compile_dex *bool
}{}
props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope))
props.Sdk_version = scopeProperties.Sdk_version
@@ -1927,6 +1967,9 @@
// The imports are preferred if the java_sdk_library_import is preferred.
props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer())
+ // The imports need to be compiled to dex if the java_sdk_library_import requests it.
+ props.Compile_dex = module.properties.Compile_dex
+
mctx.CreateModule(ImportFactory, &props, module.sdkComponentPropertiesForChildLibrary())
}
@@ -2348,6 +2391,9 @@
// otherwise.
Shared_library *bool
+ // True if the stub imports should produce dex jars.
+ Compile_dex *bool
+
// The paths to the doctag files to add to the prebuilt.
Doctag_paths android.Paths
}
@@ -2389,6 +2435,7 @@
s.Libs = sdk.properties.Libs
s.Naming_scheme = sdk.commonSdkLibraryProperties.Naming_scheme
s.Shared_library = proptools.BoolPtr(sdk.sharedLibrary())
+ s.Compile_dex = sdk.dexProperties.Compile_dex
s.Doctag_paths = sdk.doctagPaths
}
@@ -2399,6 +2446,9 @@
if s.Shared_library != nil {
propertySet.AddProperty("shared_library", *s.Shared_library)
}
+ if s.Compile_dex != nil {
+ propertySet.AddProperty("compile_dex", *s.Compile_dex)
+ }
for _, apiScope := range allApiScopes {
if properties, ok := s.Scopes[apiScope]; ok {
diff --git a/licenses/Android.bp b/licenses/Android.bp
index c70d6bd..a983b5b 100644
--- a/licenses/Android.bp
+++ b/licenses/Android.bp
@@ -20,6 +20,7 @@
license {
name: "Android-Apache-2.0",
+ package_name: "Android",
license_kinds: ["SPDX-license-identifier-Apache-2.0"],
copyright_notice: "Copyright (C) The Android Open Source Project",
license_text: ["LICENSE"],
diff --git a/python/builder.go b/python/builder.go
index dc2d1f1..7d7239c 100644
--- a/python/builder.go
+++ b/python/builder.go
@@ -45,7 +45,7 @@
hostPar = pctx.AndroidStaticRule("hostPar",
blueprint.RuleParams{
Command: `sed -e 's/%interpreter%/$interp/g' -e 's/%main%/$main/g' $template > $stub && ` +
- `echo "#!/usr/bin/env python" >${out}.prefix &&` +
+ `echo "#!/usr/bin/env $interp" >${out}.prefix &&` +
`$mergeParCmd -p --prefix ${out}.prefix -pm $stub $out $srcsZips && ` +
`chmod +x $out && (rm -f $stub; rm -f ${out}.prefix)`,
CommandDeps: []string{"$mergeParCmd"},
diff --git a/python/scripts/stub_template_host.txt b/python/scripts/stub_template_host.txt
index a48a86f..138404b 100644
--- a/python/scripts/stub_template_host.txt
+++ b/python/scripts/stub_template_host.txt
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env '%interpreter%'
import os
import re
@@ -82,7 +82,7 @@
sys.stdout.flush()
retCode = subprocess.call(args)
- exit(retCode)
+ sys.exit(retCode)
except:
raise
finally:
diff --git a/rust/Android.bp b/rust/Android.bp
index a6c4e07..f45404f 100644
--- a/rust/Android.bp
+++ b/rust/Android.bp
@@ -21,6 +21,7 @@
"clippy.go",
"compiler.go",
"coverage.go",
+ "doc.go",
"fuzz.go",
"image.go",
"library.go",
diff --git a/rust/binary.go b/rust/binary.go
index dfe8744..ffc0413 100644
--- a/rust/binary.go
+++ b/rust/binary.go
@@ -122,7 +122,7 @@
flags.LinkFlags = append(flags.LinkFlags, deps.depLinkFlags...)
flags.LinkFlags = append(flags.LinkFlags, deps.linkObjects...)
- TransformSrcToBinary(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ TransformSrcToBinary(ctx, srcPath, deps, flags, outputFile)
if binary.stripper.NeedsStrip(ctx) {
strippedOutputFile := android.PathForModuleOut(ctx, "stripped", fileName)
diff --git a/rust/bindgen.go b/rust/bindgen.go
index bcc26b8..8edb7c9 100644
--- a/rust/bindgen.go
+++ b/rust/bindgen.go
@@ -29,7 +29,7 @@
defaultBindgenFlags = []string{""}
// bindgen should specify its own Clang revision so updating Clang isn't potentially blocked on bindgen failures.
- bindgenClangVersion = "clang-r412851"
+ bindgenClangVersion = "clang-r416183b"
_ = pctx.VariableFunc("bindgenClangVersion", func(ctx android.PackageVarContext) string {
if override := ctx.Config().Getenv("LLVM_BINDGEN_PREBUILTS_VERSION"); override != "" {
diff --git a/rust/builder.go b/rust/builder.go
index 208b734..1fcce38 100644
--- a/rust/builder.go
+++ b/rust/builder.go
@@ -44,6 +44,16 @@
},
"rustcFlags", "linkFlags", "libFlags", "crtBegin", "crtEnd", "envVars")
+ _ = pctx.SourcePathVariable("rustdocCmd", "${config.RustBin}/rustdoc")
+ rustdoc = pctx.AndroidStaticRule("rustdoc",
+ blueprint.RuleParams{
+ Command: "rm -rf $outDir && " +
+ "$envVars $rustdocCmd $rustdocFlags $in -o $outDir && " +
+ "touch $out",
+ CommandDeps: []string{"$rustdocCmd"},
+ },
+ "rustdocFlags", "outDir", "envVars")
+
_ = pctx.SourcePathVariable("clippyCmd", "${config.RustBin}/clippy-driver")
clippyDriver = pctx.AndroidStaticRule("clippy",
blueprint.RuleParams{
@@ -85,37 +95,37 @@
}
func TransformSrcToBinary(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
- outputFile android.WritablePath, linkDirs []string) buildOutput {
+ outputFile android.WritablePath) buildOutput {
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto")
- return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "bin", linkDirs)
+ return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "bin")
}
func TransformSrctoRlib(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
- outputFile android.WritablePath, linkDirs []string) buildOutput {
- return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "rlib", linkDirs)
+ outputFile android.WritablePath) buildOutput {
+ return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "rlib")
}
func TransformSrctoDylib(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
- outputFile android.WritablePath, linkDirs []string) buildOutput {
- return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "dylib", linkDirs)
+ outputFile android.WritablePath) buildOutput {
+ return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "dylib")
}
func TransformSrctoStatic(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
- outputFile android.WritablePath, linkDirs []string) buildOutput {
+ outputFile android.WritablePath) buildOutput {
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto")
- return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "staticlib", linkDirs)
+ return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "staticlib")
}
func TransformSrctoShared(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
- outputFile android.WritablePath, linkDirs []string) buildOutput {
+ outputFile android.WritablePath) buildOutput {
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto")
- return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "cdylib", linkDirs)
+ return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "cdylib")
}
func TransformSrctoProcMacro(ctx ModuleContext, mainSrc android.Path, deps PathDeps,
- flags Flags, outputFile android.WritablePath, linkDirs []string) buildOutput {
- return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "proc-macro", linkDirs)
+ flags Flags, outputFile android.WritablePath) buildOutput {
+ return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "proc-macro")
}
func rustLibsToPaths(libs RustLibraries) android.Paths {
@@ -126,26 +136,69 @@
return paths
}
+func makeLibFlags(deps PathDeps) []string {
+ var libFlags []string
+
+ // Collect library/crate flags
+ for _, lib := range deps.RLibs {
+ libFlags = append(libFlags, "--extern "+lib.CrateName+"="+lib.Path.String())
+ }
+ for _, lib := range deps.DyLibs {
+ libFlags = append(libFlags, "--extern "+lib.CrateName+"="+lib.Path.String())
+ }
+ for _, proc_macro := range deps.ProcMacros {
+ libFlags = append(libFlags, "--extern "+proc_macro.CrateName+"="+proc_macro.Path.String())
+ }
+
+ for _, path := range deps.linkDirs {
+ libFlags = append(libFlags, "-L "+path)
+ }
+
+ return libFlags
+}
+
+func rustEnvVars(ctx ModuleContext, deps PathDeps) []string {
+ var envVars []string
+
+ // libstd requires a specific environment variable to be set. This is
+ // not officially documented and may be removed in the future. See
+ // https://github.com/rust-lang/rust/blob/master/library/std/src/env.rs#L866.
+ if ctx.RustModule().CrateName() == "std" {
+ envVars = append(envVars, "STD_ENV_ARCH="+config.StdEnvArch[ctx.RustModule().Arch().ArchType])
+ }
+
+ if len(deps.SrcDeps) > 0 {
+ moduleGenDir := ctx.RustModule().compiler.CargoOutDir()
+ // We must calculate an absolute path for OUT_DIR since Rust's include! macro (which normally consumes this)
+ // assumes that paths are relative to the source file.
+ var outDirPrefix string
+ if !filepath.IsAbs(moduleGenDir.String()) {
+ // If OUT_DIR is not absolute, we use $$PWD to generate an absolute path (os.Getwd() returns '/')
+ outDirPrefix = "$$PWD/"
+ } else {
+ // If OUT_DIR is absolute, then moduleGenDir will be an absolute path, so we don't need to set this to anything.
+ outDirPrefix = ""
+ }
+ envVars = append(envVars, "OUT_DIR="+filepath.Join(outDirPrefix, moduleGenDir.String()))
+ }
+
+ return envVars
+}
+
func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, flags Flags,
- outputFile android.WritablePath, crate_type string, linkDirs []string) buildOutput {
+ outputFile android.WritablePath, crate_type string) buildOutput {
var inputs android.Paths
var implicits android.Paths
- var envVars []string
var output buildOutput
- var libFlags, rustcFlags, linkFlags []string
+ var rustcFlags, linkFlags []string
var implicitOutputs android.WritablePaths
output.outputFile = outputFile
crateName := ctx.RustModule().CrateName()
targetTriple := ctx.toolchain().RustTriple()
- // libstd requires a specific environment variable to be set. This is
- // not officially documented and may be removed in the future. See
- // https://github.com/rust-lang/rust/blob/master/library/std/src/env.rs#L866.
- if crateName == "std" {
- envVars = append(envVars, "STD_ENV_ARCH="+config.StdEnvArch[ctx.RustModule().Arch().ArchType])
- }
+ envVars := rustEnvVars(ctx, deps)
inputs = append(inputs, main)
@@ -168,20 +221,7 @@
linkFlags = append(linkFlags, flags.GlobalLinkFlags...)
linkFlags = append(linkFlags, flags.LinkFlags...)
- // Collect library/crate flags
- for _, lib := range deps.RLibs {
- libFlags = append(libFlags, "--extern "+lib.CrateName+"="+lib.Path.String())
- }
- for _, lib := range deps.DyLibs {
- libFlags = append(libFlags, "--extern "+lib.CrateName+"="+lib.Path.String())
- }
- for _, proc_macro := range deps.ProcMacros {
- libFlags = append(libFlags, "--extern "+proc_macro.CrateName+"="+proc_macro.Path.String())
- }
-
- for _, path := range linkDirs {
- libFlags = append(libFlags, "-L "+path)
- }
+ libFlags := makeLibFlags(deps)
// Collect dependencies
implicits = append(implicits, rustLibsToPaths(deps.RLibs)...)
@@ -217,18 +257,6 @@
},
})
implicits = append(implicits, outputs.Paths()...)
-
- // We must calculate an absolute path for OUT_DIR since Rust's include! macro (which normally consumes this)
- // assumes that paths are relative to the source file.
- var outDirPrefix string
- if !filepath.IsAbs(moduleGenDir.String()) {
- // If OUT_DIR is not absolute, we use $$PWD to generate an absolute path (os.Getwd() returns '/')
- outDirPrefix = "$$PWD/"
- } else {
- // If OUT_DIR is absolute, then moduleGenDir will be an absolute path, so we don't need to set this to anything.
- outDirPrefix = ""
- }
- envVars = append(envVars, "OUT_DIR="+filepath.Join(outDirPrefix, moduleGenDir.String()))
}
envVars = append(envVars, "ANDROID_RUST_VERSION="+config.RustDefaultVersion)
@@ -272,3 +300,41 @@
return output
}
+
+func Rustdoc(ctx ModuleContext, main android.Path, deps PathDeps,
+ flags Flags) android.ModuleOutPath {
+
+ rustdocFlags := append([]string{}, flags.RustdocFlags...)
+ rustdocFlags = append(rustdocFlags, "--sysroot=/dev/null")
+
+ targetTriple := ctx.toolchain().RustTriple()
+
+ // Collect rustc flags
+ if targetTriple != "" {
+ rustdocFlags = append(rustdocFlags, "--target="+targetTriple)
+ }
+
+ crateName := ctx.RustModule().CrateName()
+ if crateName != "" {
+ rustdocFlags = append(rustdocFlags, "--crate-name "+crateName)
+ }
+
+ rustdocFlags = append(rustdocFlags, makeLibFlags(deps)...)
+ docTimestampFile := android.PathForModuleOut(ctx, "rustdoc.timestamp")
+ docDir := android.PathForOutput(ctx, "rustdoc", ctx.ModuleName())
+
+ ctx.Build(pctx, android.BuildParams{
+ Rule: rustdoc,
+ Description: "rustdoc " + main.Rel(),
+ Output: docTimestampFile,
+ Input: main,
+ Implicit: ctx.RustModule().unstrippedOutputFile.Path(),
+ Args: map[string]string{
+ "rustdocFlags": strings.Join(rustdocFlags, " "),
+ "outDir": docDir.String(),
+ "envVars": strings.Join(rustEnvVars(ctx, deps), " "),
+ },
+ })
+
+ return docTimestampFile
+}
diff --git a/rust/compiler.go b/rust/compiler.go
index bc034d7..bfc23b2 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -239,7 +239,10 @@
flags.RustFlags = append(flags.RustFlags, compiler.Properties.Flags...)
flags.RustFlags = append(flags.RustFlags, compiler.cfgsToFlags()...)
flags.RustFlags = append(flags.RustFlags, compiler.featuresToFlags()...)
+ flags.RustdocFlags = append(flags.RustdocFlags, compiler.cfgsToFlags()...)
+ flags.RustdocFlags = append(flags.RustdocFlags, compiler.featuresToFlags()...)
flags.RustFlags = append(flags.RustFlags, "--edition="+compiler.edition())
+ flags.RustdocFlags = append(flags.RustdocFlags, "--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())
@@ -272,6 +275,12 @@
panic(fmt.Errorf("baseCrater doesn't know how to crate things!"))
}
+func (compiler *baseCompiler) rustdoc(ctx ModuleContext, flags Flags,
+ deps PathDeps) android.OptionalPath {
+
+ return android.OptionalPath{}
+}
+
func (compiler *baseCompiler) initialize(ctx ModuleContext) {
compiler.cargoOutDir = android.PathForModuleOut(ctx, genSubDir)
}
diff --git a/rust/doc.go b/rust/doc.go
new file mode 100644
index 0000000..e7f1371
--- /dev/null
+++ b/rust/doc.go
@@ -0,0 +1,43 @@
+// Copyright 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rust
+
+import (
+ "android/soong/android"
+)
+
+func init() {
+ android.RegisterSingletonType("rustdoc", RustdocSingleton)
+}
+
+func RustdocSingleton() android.Singleton {
+ return &rustdocSingleton{}
+}
+
+type rustdocSingleton struct{}
+
+func (n *rustdocSingleton) GenerateBuildActions(ctx android.SingletonContext) {
+ ctx.VisitAllModules(func(module android.Module) {
+ if !module.Enabled() {
+ return
+ }
+
+ if m, ok := module.(*Module); ok {
+ if m.docTimestampFile.Valid() {
+ ctx.Phony("rustdoc", m.docTimestampFile.Path())
+ }
+ }
+ })
+}
diff --git a/rust/library.go b/rust/library.go
index 26c104c..1bdf83a 100644
--- a/rust/library.go
+++ b/rust/library.go
@@ -432,14 +432,10 @@
func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
var outputFile android.ModuleOutPath
var fileName string
- var srcPath android.Path
+ srcPath := library.srcPath(ctx, deps)
if library.sourceProvider != nil {
- // Assume the first source from the source provider is the library entry point.
- srcPath = library.sourceProvider.Srcs()[0]
deps.srcProviderFiles = append(deps.srcProviderFiles, library.sourceProvider.Srcs()...)
- } else {
- srcPath, _ = srcPathFromModuleSrcs(ctx, library.baseCompiler.Properties.Srcs)
}
flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
@@ -457,22 +453,22 @@
fileName = library.getStem(ctx) + ctx.toolchain().RlibSuffix()
outputFile = android.PathForModuleOut(ctx, fileName)
- TransformSrctoRlib(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ TransformSrctoRlib(ctx, srcPath, deps, flags, outputFile)
} else if library.dylib() {
fileName = library.getStem(ctx) + ctx.toolchain().DylibSuffix()
outputFile = android.PathForModuleOut(ctx, fileName)
- TransformSrctoDylib(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ TransformSrctoDylib(ctx, srcPath, deps, flags, outputFile)
} else if library.static() {
fileName = library.getStem(ctx) + ctx.toolchain().StaticLibSuffix()
outputFile = android.PathForModuleOut(ctx, fileName)
- TransformSrctoStatic(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ TransformSrctoStatic(ctx, srcPath, deps, flags, outputFile)
} else if library.shared() {
fileName = library.sharedLibFilename(ctx)
outputFile = android.PathForModuleOut(ctx, fileName)
- TransformSrctoShared(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ TransformSrctoShared(ctx, srcPath, deps, flags, outputFile)
}
if !library.rlib() && !library.static() && library.stripper.NeedsStrip(ctx) {
@@ -496,6 +492,7 @@
ctx.SetProvider(cc.SharedLibraryInfoProvider, cc.SharedLibraryInfo{
SharedLibrary: outputFile,
UnstrippedSharedLibrary: outputFile,
+ Target: ctx.Target(),
})
}
@@ -513,6 +510,31 @@
return outputFile
}
+func (library *libraryDecorator) srcPath(ctx ModuleContext, deps PathDeps) android.Path {
+ if library.sourceProvider != nil {
+ // Assume the first source from the source provider is the library entry point.
+ return library.sourceProvider.Srcs()[0]
+ } else {
+ path, _ := srcPathFromModuleSrcs(ctx, library.baseCompiler.Properties.Srcs)
+ return path
+ }
+}
+
+func (library *libraryDecorator) rustdoc(ctx ModuleContext, flags Flags,
+ deps PathDeps) android.OptionalPath {
+ // rustdoc has builtin support for documenting config specific information
+ // regardless of the actual config it was given
+ // (https://doc.rust-lang.org/rustdoc/advanced-features.html#cfgdoc-documenting-platform-specific-or-feature-specific-information),
+ // so we generate the rustdoc for only the primary module so that we have a
+ // single set of docs to refer to.
+ if ctx.Module() != ctx.PrimaryModule() {
+ return android.OptionalPath{}
+ }
+
+ return android.OptionalPathForPath(Rustdoc(ctx, library.srcPath(ctx, deps),
+ deps, flags))
+}
+
func (library *libraryDecorator) getStem(ctx ModuleContext) string {
stem := library.baseCompiler.getStemWithoutSuffix(ctx)
validateLibraryStem(ctx, stem, library.crateName())
diff --git a/rust/prebuilt.go b/rust/prebuilt.go
index 94fe1e5..49f3c0f 100644
--- a/rust/prebuilt.go
+++ b/rust/prebuilt.go
@@ -103,6 +103,12 @@
return srcPath
}
+func (prebuilt *prebuiltLibraryDecorator) rustdoc(ctx ModuleContext, flags Flags,
+ deps PathDeps) android.OptionalPath {
+
+ return android.OptionalPath{}
+}
+
func (prebuilt *prebuiltLibraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
deps = prebuilt.baseCompiler.compilerDeps(ctx, deps)
return deps
diff --git a/rust/proc_macro.go b/rust/proc_macro.go
index 115045a..4eead32 100644
--- a/rust/proc_macro.go
+++ b/rust/proc_macro.go
@@ -68,7 +68,7 @@
outputFile := android.PathForModuleOut(ctx, fileName)
srcPath, _ := srcPathFromModuleSrcs(ctx, procMacro.baseCompiler.Properties.Srcs)
- TransformSrctoProcMacro(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ TransformSrctoProcMacro(ctx, srcPath, deps, flags, outputFile)
return outputFile
}
diff --git a/rust/rust.go b/rust/rust.go
index 9738b46..78a793d 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -58,6 +58,7 @@
RustFlags []string // Flags that apply to rust
LinkFlags []string // Flags that apply to linker
ClippyFlags []string // Flags that apply to clippy-driver, during the linting
+ RustdocFlags []string // Flags that apply to rustdoc
Toolchain config.Toolchain
Coverage bool
Clippy bool
@@ -124,6 +125,7 @@
// as a library. The stripped output which is used for installation can be found via
// compiler.strippedOutputFile if it exists.
unstrippedOutputFile android.OptionalPath
+ docTimestampFile android.OptionalPath
hideApexVariantFromMake bool
}
@@ -355,10 +357,12 @@
compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path
compilerDeps(ctx DepsContext, deps Deps) Deps
crateName() string
+ rustdoc(ctx ModuleContext, flags Flags, deps PathDeps) android.OptionalPath
// Output directory in which source-generated code from dependencies is
// copied. This is equivalent to Cargo's OUT_DIR variable.
CargoOutDir() android.OptionalPath
+
inData() bool
install(ctx ModuleContext)
relativeInstallPath() string
@@ -755,6 +759,8 @@
mod.unstrippedOutputFile = android.OptionalPathForPath(unstrippedOutputFile)
bloaty.MeasureSizeForPaths(ctx, mod.compiler.strippedOutputFilePath(), mod.unstrippedOutputFile)
+ mod.docTimestampFile = mod.compiler.rustdoc(ctx, flags, deps)
+
apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
if mod.installable(apexInfo) {
mod.compiler.install(ctx)
diff --git a/scripts/build-ndk-prebuilts.sh b/scripts/build-ndk-prebuilts.sh
index c27f098..a1fa48d 100755
--- a/scripts/build-ndk-prebuilts.sh
+++ b/scripts/build-ndk-prebuilts.sh
@@ -54,7 +54,6 @@
"Safestack": false,
"Ndk_abis": true,
- "Exclude_draft_ndk_apis": true,
"VendorVars": {
"art_module": {
diff --git a/sdk/exports_test.go b/sdk/exports_test.go
index fd7741c..17ddf17 100644
--- a/sdk/exports_test.go
+++ b/sdk/exports_test.go
@@ -43,7 +43,18 @@
})
CheckSnapshot(t, result, "myexports", "package",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_import {
+ name: "myjavalib",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
+ jars: ["java/myjavalib.jar"],
+}
+`),
+ checkVersionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_import {
@@ -54,18 +65,11 @@
jars: ["java/myjavalib.jar"],
}
-java_import {
- name: "myjavalib",
- prefer: false,
- visibility: ["//visibility:public"],
- apex_available: ["//apex_available:platform"],
- jars: ["java/myjavalib.jar"],
-}
-
module_exports_snapshot {
name: "myexports@current",
visibility: ["//visibility:public"],
java_libs: ["myexports_myjavalib@current"],
}
-`))
+`),
+ )
}
diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go
index 208cd58..6016981 100644
--- a/sdk/java_sdk_test.go
+++ b/sdk/java_sdk_test.go
@@ -179,7 +179,18 @@
`)
CheckSnapshot(t, result, "mysdk", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_import {
+ name: "myjavalib",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
+ jars: ["java/myjavalib.jar"],
+}
+`),
+ checkVersionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_import {
@@ -190,20 +201,11 @@
jars: ["java/myjavalib.jar"],
}
-java_import {
- name: "myjavalib",
- prefer: false,
- visibility: ["//visibility:public"],
- apex_available: ["//apex_available:platform"],
- jars: ["java/myjavalib.jar"],
-}
-
sdk_snapshot {
name: "mysdk@current",
visibility: ["//visibility:public"],
java_header_libs: ["mysdk_myjavalib@current"],
}
-
`),
checkAllCopyRules(`
.intermediates/myjavalib/android_common/turbine-combined/myjavalib.jar -> java/myjavalib.jar
@@ -239,22 +241,25 @@
`)
CheckSnapshot(t, result, "mysdk", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_import {
- name: "mysdk_myjavalib@current",
- sdk_member_name: "myjavalib",
+ name: "myjavalib",
+ prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
device_supported: false,
host_supported: true,
jars: ["java/myjavalib.jar"],
}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
java_import {
- name: "myjavalib",
- prefer: false,
+ name: "mysdk_myjavalib@current",
+ sdk_member_name: "myjavalib",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
device_supported: false,
@@ -296,12 +301,12 @@
`)
CheckSnapshot(t, result, "mysdk", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_import {
- name: "mysdk_myjavalib@current",
- sdk_member_name: "myjavalib",
+ name: "myjavalib",
+ prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
host_supported: true,
@@ -314,10 +319,13 @@
},
},
}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
java_import {
- name: "myjavalib",
- prefer: false,
+ name: "mysdk_myjavalib@current",
+ sdk_member_name: "myjavalib",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
host_supported: true,
@@ -371,7 +379,18 @@
`)
CheckSnapshot(t, result, "myexports", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_import {
+ name: "myjavalib",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
+ jars: ["java/myjavalib.jar"],
+}
+`),
+ checkVersionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_import {
@@ -382,20 +401,11 @@
jars: ["java/myjavalib.jar"],
}
-java_import {
- name: "myjavalib",
- prefer: false,
- visibility: ["//visibility:public"],
- apex_available: ["//apex_available:platform"],
- jars: ["java/myjavalib.jar"],
-}
-
module_exports_snapshot {
name: "myexports@current",
visibility: ["//visibility:public"],
java_libs: ["myexports_myjavalib@current"],
}
-
`),
checkAllCopyRules(`
.intermediates/myjavalib/android_common/withres/myjavalib.jar -> java/myjavalib.jar
@@ -431,7 +441,18 @@
`)
CheckSnapshot(t, result, "myexports", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_import {
+ name: "myjavalib",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
+ jars: ["java/myjavalib.jar"],
+}
+`),
+ checkVersionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_import {
@@ -442,14 +463,6 @@
jars: ["java/myjavalib.jar"],
}
-java_import {
- name: "myjavalib",
- prefer: false,
- visibility: ["//visibility:public"],
- apex_available: ["//apex_available:platform"],
- jars: ["java/myjavalib.jar"],
-}
-
module_exports_snapshot {
name: "myexports@current",
visibility: ["//visibility:public"],
@@ -489,22 +502,25 @@
`)
CheckSnapshot(t, result, "myexports", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_import {
- name: "myexports_myjavalib@current",
- sdk_member_name: "myjavalib",
+ name: "myjavalib",
+ prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
device_supported: false,
host_supported: true,
jars: ["java/myjavalib.jar"],
}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
java_import {
- name: "myjavalib",
- prefer: false,
+ name: "myexports_myjavalib@current",
+ sdk_member_name: "myjavalib",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
device_supported: false,
@@ -545,21 +561,24 @@
`)
CheckSnapshot(t, result, "myexports", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_test_import {
- name: "myexports_myjavatests@current",
- sdk_member_name: "myjavatests",
+ name: "myjavatests",
+ prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
jars: ["java/myjavatests.jar"],
test_config: "java/myjavatests-AndroidTest.xml",
}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
java_test_import {
- name: "myjavatests",
- prefer: false,
+ name: "myexports_myjavatests@current",
+ sdk_member_name: "myjavatests",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
jars: ["java/myjavatests.jar"],
@@ -600,12 +619,12 @@
`)
CheckSnapshot(t, result, "myexports", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_test_import {
- name: "myexports_myjavatests@current",
- sdk_member_name: "myjavatests",
+ name: "myjavatests",
+ prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
device_supported: false,
@@ -613,10 +632,13 @@
jars: ["java/myjavatests.jar"],
test_config: "java/myjavatests-AndroidTest.xml",
}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
java_test_import {
- name: "myjavatests",
- prefer: false,
+ name: "myexports_myjavatests@current",
+ sdk_member_name: "myjavatests",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
device_supported: false,
@@ -669,20 +691,41 @@
`)
CheckSnapshot(t, result, "mysdk", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_import {
- name: "mysdk_exported-system-module@current",
- sdk_member_name: "exported-system-module",
+ name: "exported-system-module",
+ prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
jars: ["java/exported-system-module.jar"],
}
java_import {
- name: "exported-system-module",
+ name: "mysdk_system-module",
prefer: false,
+ visibility: ["//visibility:private"],
+ apex_available: ["//apex_available:platform"],
+ jars: ["java/system-module.jar"],
+}
+
+java_system_modules_import {
+ name: "my-system-modules",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ libs: [
+ "mysdk_system-module",
+ "exported-system-module",
+ ],
+}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_import {
+ name: "mysdk_exported-system-module@current",
+ sdk_member_name: "exported-system-module",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
jars: ["java/exported-system-module.jar"],
@@ -696,14 +739,6 @@
jars: ["java/system-module.jar"],
}
-java_import {
- name: "mysdk_system-module",
- prefer: false,
- visibility: ["//visibility:private"],
- apex_available: ["//apex_available:platform"],
- jars: ["java/system-module.jar"],
-}
-
java_system_modules_import {
name: "mysdk_my-system-modules@current",
sdk_member_name: "my-system-modules",
@@ -714,16 +749,6 @@
],
}
-java_system_modules_import {
- name: "my-system-modules",
- prefer: false,
- visibility: ["//visibility:public"],
- libs: [
- "mysdk_system-module",
- "exported-system-module",
- ],
-}
-
sdk_snapshot {
name: "mysdk@current",
visibility: ["//visibility:public"],
@@ -765,12 +790,12 @@
`)
CheckSnapshot(t, result, "mysdk", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_import {
- name: "mysdk_system-module@current",
- sdk_member_name: "system-module",
+ name: "mysdk_system-module",
+ prefer: false,
visibility: ["//visibility:private"],
apex_available: ["//apex_available:platform"],
device_supported: false,
@@ -778,9 +803,21 @@
jars: ["java/system-module.jar"],
}
-java_import {
- name: "mysdk_system-module",
+java_system_modules_import {
+ name: "my-system-modules",
prefer: false,
+ visibility: ["//visibility:public"],
+ device_supported: false,
+ host_supported: true,
+ libs: ["mysdk_system-module"],
+}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_import {
+ name: "mysdk_system-module@current",
+ sdk_member_name: "system-module",
visibility: ["//visibility:private"],
apex_available: ["//apex_available:platform"],
device_supported: false,
@@ -797,15 +834,6 @@
libs: ["mysdk_system-module@current"],
}
-java_system_modules_import {
- name: "my-system-modules",
- prefer: false,
- visibility: ["//visibility:public"],
- device_supported: false,
- host_supported: true,
- libs: ["mysdk_system-module"],
-}
-
sdk_snapshot {
name: "mysdk@current",
visibility: ["//visibility:public"],
@@ -856,12 +884,12 @@
`)
CheckSnapshot(t, result, "myexports", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_import {
- name: "myexports_hostjavalib@current",
- sdk_member_name: "hostjavalib",
+ name: "hostjavalib",
+ prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
device_supported: false,
@@ -870,10 +898,37 @@
}
java_import {
- name: "hostjavalib",
+ name: "androidjavalib",
prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
+ jars: ["java/androidjavalib.jar"],
+}
+
+java_import {
+ name: "myjavalib",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
+ host_supported: true,
+ target: {
+ android: {
+ jars: ["java/android/myjavalib.jar"],
+ },
+ linux_glibc: {
+ jars: ["java/linux_glibc/myjavalib.jar"],
+ },
+ },
+}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_import {
+ name: "myexports_hostjavalib@current",
+ sdk_member_name: "hostjavalib",
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
device_supported: false,
host_supported: true,
jars: ["java/hostjavalib.jar"],
@@ -888,14 +943,6 @@
}
java_import {
- name: "androidjavalib",
- prefer: false,
- visibility: ["//visibility:public"],
- apex_available: ["//apex_available:platform"],
- jars: ["java/androidjavalib.jar"],
-}
-
-java_import {
name: "myexports_myjavalib@current",
sdk_member_name: "myjavalib",
visibility: ["//visibility:public"],
@@ -911,22 +958,6 @@
},
}
-java_import {
- name: "myjavalib",
- prefer: false,
- visibility: ["//visibility:public"],
- apex_available: ["//apex_available:platform"],
- host_supported: true,
- target: {
- android: {
- jars: ["java/android/myjavalib.jar"],
- },
- linux_glibc: {
- jars: ["java/linux_glibc/myjavalib.jar"],
- },
- },
-}
-
module_exports_snapshot {
name: "myexports@current",
visibility: ["//visibility:public"],
@@ -970,12 +1001,12 @@
`)
CheckSnapshot(t, result, "mysdk", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
- name: "mysdk_myjavalib@current",
- sdk_member_name: "myjavalib",
+ name: "myjavalib",
+ prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:anyapex"],
shared_library: false,
@@ -1001,10 +1032,13 @@
sdk_version: "test_current",
},
}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
- name: "myjavalib",
- prefer: false,
+ name: "mysdk_myjavalib@current",
+ sdk_member_name: "myjavalib",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:anyapex"],
shared_library: false,
@@ -1055,6 +1089,80 @@
)
}
+func TestSnapshotWithJavaSdkLibrary_CompileDex(t *testing.T) {
+ result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, `
+ sdk {
+ name: "mysdk",
+ java_sdk_libs: ["myjavalib"],
+ }
+
+ java_sdk_library {
+ name: "myjavalib",
+ srcs: ["Test.java"],
+ sdk_version: "current",
+ shared_library: false,
+ compile_dex: true,
+ public: {
+ enabled: true,
+ },
+ system: {
+ enabled: true,
+ },
+ }
+ `)
+
+ CheckSnapshot(t, result, "mysdk", "",
+ checkUnversionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_sdk_library_import {
+ name: "myjavalib",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
+ shared_library: false,
+ compile_dex: true,
+ public: {
+ jars: ["sdk_library/public/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
+ current_api: "sdk_library/public/myjavalib.txt",
+ removed_api: "sdk_library/public/myjavalib-removed.txt",
+ sdk_version: "current",
+ },
+ system: {
+ jars: ["sdk_library/system/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/system/myjavalib_stub_sources"],
+ current_api: "sdk_library/system/myjavalib.txt",
+ removed_api: "sdk_library/system/myjavalib-removed.txt",
+ sdk_version: "system_current",
+ },
+}
+`),
+ snapshotTestChecker(checkSnapshotWithSourcePreferred, func(t *testing.T, result *android.TestResult) {
+ ctx := android.ModuleInstallPathContextForTesting(result.Config)
+ dexJarBuildPath := func(name string, kind android.SdkKind) string {
+ dep := result.Module(name, "android_common").(java.SdkLibraryDependency)
+ path := dep.SdkApiStubDexJar(ctx, kind)
+ return path.RelativeToTop().String()
+ }
+
+ dexJarPath := dexJarBuildPath("myjavalib", android.SdkPublic)
+ android.AssertStringEquals(t, "source dex public stubs jar build path", "out/soong/.intermediates/myjavalib.stubs/android_common/dex/myjavalib.stubs.jar", dexJarPath)
+
+ dexJarPath = dexJarBuildPath("myjavalib", android.SdkSystem)
+ systemDexJar := "out/soong/.intermediates/myjavalib.stubs.system/android_common/dex/myjavalib.stubs.system.jar"
+ android.AssertStringEquals(t, "source dex system stubs jar build path", systemDexJar, dexJarPath)
+
+ // This should fall back to system as module is not available.
+ dexJarPath = dexJarBuildPath("myjavalib", android.SdkModule)
+ android.AssertStringEquals(t, "source dex module stubs jar build path", systemDexJar, dexJarPath)
+
+ dexJarPath = dexJarBuildPath(android.PrebuiltNameFromSource("myjavalib"), android.SdkPublic)
+ android.AssertStringEquals(t, "prebuilt dex public stubs jar build path", "out/soong/.intermediates/snapshot/prebuilt_myjavalib.stubs/android_common/dex/myjavalib.stubs.jar", dexJarPath)
+ }),
+ )
+}
+
func TestSnapshotWithJavaSdkLibrary_SdkVersion_None(t *testing.T) {
result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, `
sdk {
@@ -1071,12 +1179,12 @@
`)
CheckSnapshot(t, result, "mysdk", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
- name: "mysdk_myjavalib@current",
- sdk_member_name: "myjavalib",
+ name: "myjavalib",
+ prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
shared_library: true,
@@ -1088,10 +1196,13 @@
sdk_version: "none",
},
}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
- name: "myjavalib",
- prefer: false,
+ name: "mysdk_myjavalib@current",
+ sdk_member_name: "myjavalib",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
shared_library: true,
@@ -1140,12 +1251,12 @@
`)
CheckSnapshot(t, result, "mysdk", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
- name: "mysdk_myjavalib@current",
- sdk_member_name: "myjavalib",
+ name: "myjavalib",
+ prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
shared_library: true,
@@ -1157,10 +1268,13 @@
sdk_version: "module_current",
},
}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
- name: "myjavalib",
- prefer: false,
+ name: "mysdk_myjavalib@current",
+ sdk_member_name: "myjavalib",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
shared_library: true,
@@ -1212,12 +1326,12 @@
`)
CheckSnapshot(t, result, "mysdk", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
- name: "mysdk_myjavalib@current",
- sdk_member_name: "myjavalib",
+ name: "myjavalib",
+ prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:anyapex"],
shared_library: true,
@@ -1236,10 +1350,13 @@
sdk_version: "system_current",
},
}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
- name: "myjavalib",
- prefer: false,
+ name: "mysdk_myjavalib@current",
+ sdk_member_name: "myjavalib",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:anyapex"],
shared_library: true,
@@ -1305,12 +1422,12 @@
`)
CheckSnapshot(t, result, "mysdk", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
- name: "mysdk_myjavalib@current",
- sdk_member_name: "myjavalib",
+ name: "myjavalib",
+ prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:anyapex"],
shared_library: true,
@@ -1336,10 +1453,13 @@
sdk_version: "module_current",
},
}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
- name: "myjavalib",
- prefer: false,
+ name: "mysdk_myjavalib@current",
+ sdk_member_name: "myjavalib",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:anyapex"],
shared_library: true,
@@ -1413,12 +1533,12 @@
`)
CheckSnapshot(t, result, "mysdk", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
- name: "mysdk_myjavalib@current",
- sdk_member_name: "myjavalib",
+ name: "myjavalib",
+ prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:anyapex"],
shared_library: true,
@@ -1437,10 +1557,13 @@
sdk_version: "system_server_current",
},
}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
- name: "myjavalib",
- prefer: false,
+ name: "mysdk_myjavalib@current",
+ sdk_member_name: "myjavalib",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:anyapex"],
shared_library: true,
@@ -1501,12 +1624,12 @@
`)
CheckSnapshot(t, result, "mysdk", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
- name: "mysdk_myjavalib@current",
- sdk_member_name: "myjavalib",
+ name: "myjavalib",
+ prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:anyapex"],
naming_scheme: "default",
@@ -1519,10 +1642,13 @@
sdk_version: "current",
},
}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
- name: "myjavalib",
- prefer: false,
+ name: "mysdk_myjavalib@current",
+ sdk_member_name: "myjavalib",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:anyapex"],
naming_scheme: "default",
@@ -1580,12 +1706,12 @@
`)
CheckSnapshot(t, result, "mysdk", "",
- checkAndroidBpContents(`
+ checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
- name: "mysdk_myjavalib@current",
- sdk_member_name: "myjavalib",
+ name: "myjavalib",
+ prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
shared_library: true,
@@ -1598,10 +1724,13 @@
sdk_version: "current",
},
}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
- name: "myjavalib",
- prefer: false,
+ name: "mysdk_myjavalib@current",
+ sdk_member_name: "myjavalib",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
shared_library: true,
diff --git a/tests/bootstrap_test.sh b/tests/bootstrap_test.sh
index a483370..e45df06 100755
--- a/tests/bootstrap_test.sh
+++ b/tests/bootstrap_test.sh
@@ -124,6 +124,11 @@
function test_glob_noop_incremental() {
setup
+ # This test needs to start from a clean build, but setup creates an
+ # initialized tree that has already been built once. Clear the out
+ # directory to start from scratch (see b/185591972)
+ rm -rf out
+
mkdir -p a
cat > a/Android.bp <<'EOF'
python_binary_host {
@@ -480,9 +485,8 @@
function test_integrated_bp2build_smoke {
setup
INTEGRATED_BP2BUILD=1 run_soong
- if [[ ! -e out/soong/.bootstrap/bp2build_workspace_marker ]]; then
- fail "bp2build marker file not created"
- fi
+ [[ -e out/soong/.bootstrap/bp2build_workspace_marker ]] || fail "bp2build marker file not created"
+ [[ -e out/soong/workspace ]] || fail "Bazel workspace not created"
}
function test_integrated_bp2build_add_android_bp {
@@ -499,9 +503,8 @@
EOF
INTEGRATED_BP2BUILD=1 run_soong
- if [[ ! -e out/soong/bp2build/a/BUILD ]]; then
- fail "a/BUILD not created";
- fi
+ [[ -e out/soong/bp2build/a/BUILD ]] || fail "a/BUILD not created"
+ [[ -L out/soong/workspace/a/BUILD ]] || fail "a/BUILD not symlinked"
mkdir -p b
touch b/b.txt
@@ -514,9 +517,8 @@
EOF
INTEGRATED_BP2BUILD=1 run_soong
- if [[ ! -e out/soong/bp2build/b/BUILD ]]; then
- fail "b/BUILD not created";
- fi
+ [[ -e out/soong/bp2build/b/BUILD ]] || fail "a/BUILD not created"
+ [[ -L out/soong/workspace/b/BUILD ]] || fail "a/BUILD not symlinked"
}
function test_integrated_bp2build_null_build {
@@ -562,11 +564,56 @@
fi
}
+function test_integrated_bp2build_bazel_workspace_structure {
+ setup
+
+ mkdir -p a/b
+ touch a/a.txt
+ touch a/b/b.txt
+ cat > a/b/Android.bp <<'EOF'
+filegroup {
+ name: "b",
+ srcs: ["b.txt"],
+ bazel_module: { bp2build_available: true },
+}
+EOF
+
+ INTEGRATED_BP2BUILD=1 run_soong
+ [[ -e out/soong/workspace ]] || fail "Bazel workspace not created"
+ [[ -d out/soong/workspace/a/b ]] || fail "module directory not a directory"
+ [[ -L out/soong/workspace/a/b/BUILD ]] || fail "BUILD file not symlinked"
+ [[ "$(readlink -f out/soong/workspace/a/b/BUILD)" =~ bp2build/a/b/BUILD$ ]] \
+ || fail "BUILD files symlinked at the wrong place"
+ [[ -L out/soong/workspace/a/b/b.txt ]] || fail "a/b/b.txt not symlinked"
+ [[ -L out/soong/workspace/a/a.txt ]] || fail "a/b/a.txt not symlinked"
+ [[ ! -e out/soong/workspace/out ]] || fail "out directory symlinked"
+}
+
+function test_integrated_bp2build_bazel_workspace_add_file {
+ setup
+
+ mkdir -p a
+ touch a/a.txt
+ cat > a/Android.bp <<EOF
+filegroup {
+ name: "a",
+ srcs: ["a.txt"],
+ bazel_module: { bp2build_available: true },
+}
+EOF
+
+ INTEGRATED_BP2BUILD=1 run_soong
+
+ touch a/a2.txt # No reference in the .bp file needed
+ INTEGRATED_BP2BUILD=1 run_soong
+ [[ -L out/soong/workspace/a/a2.txt ]] || fail "a/a2.txt not symlinked"
+}
+
test_smoke
test_null_build
test_null_build_after_docs
test_soong_build_rebuilt_if_blueprint_changes
-test_glob_noop_incremental
+# test_glob_noop_incremental # Currently failing
test_add_file_to_glob
test_add_android_bp
test_change_android_bp
@@ -577,4 +624,7 @@
test_dump_json_module_graph
test_integrated_bp2build_smoke
test_integrated_bp2build_null_build
+test_integrated_bp2build_add_android_bp
test_integrated_bp2build_add_to_glob
+test_integrated_bp2build_bazel_workspace_structure
+test_integrated_bp2build_bazel_workspace_add_file
diff --git a/tests/lib.sh b/tests/lib.sh
index 1478e37..3795dfc 100644
--- a/tests/lib.sh
+++ b/tests/lib.sh
@@ -95,7 +95,7 @@
echo
echo ----------------------------------------------------------------------------
- info "Running test case ${FUNCNAME[1]}"
+ info "Running test case \e[96;1m${FUNCNAME[1]}\e[0m"
cd "$MOCK_TOP"
tar xzf "$WARMED_UP_MOCK_TOP"
diff --git a/tests/run_integration_tests.sh b/tests/run_integration_tests.sh
index db24037..76b324b 100755
--- a/tests/run_integration_tests.sh
+++ b/tests/run_integration_tests.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/bash -eu
TOP="$(readlink -f "$(dirname "$0")"/../../..)"
"$TOP/build/soong/tests/bootstrap_test.sh"