Merge "export common bp2build testing functions"
diff --git a/android/Android.bp b/android/Android.bp
index cbd3459..f58a472 100644
--- a/android/Android.bp
+++ b/android/Android.bp
@@ -88,6 +88,7 @@
"test_asserts.go",
"test_suites.go",
"testing.go",
+ "updatable_modules.go",
"util.go",
"variable.go",
"visibility.go",
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index aa4363c..79d4910 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -132,6 +132,7 @@
"external/libevent": Bp2BuildDefaultTrueRecursively,
"external/libgav1": Bp2BuildDefaultTrueRecursively,
"external/libhevc": Bp2BuildDefaultTrueRecursively,
+ "external/libjpeg-turbo": Bp2BuildDefaultTrueRecursively,
"external/libmpeg2": Bp2BuildDefaultTrueRecursively,
"external/libpng": Bp2BuildDefaultTrueRecursively,
"external/lz4/lib": Bp2BuildDefaultTrue,
@@ -217,6 +218,7 @@
"system/unwinding/libunwindstack": Bp2BuildDefaultTrueRecursively,
"tools/apksig": Bp2BuildDefaultTrue,
"tools/platform-compat/java/android/compat": Bp2BuildDefaultTrueRecursively,
+ "tools/tradefederation/prebuilts/filegroups": Bp2BuildDefaultTrueRecursively,
}
Bp2buildKeepExistingBuildFile = map[string]bool{
@@ -262,6 +264,7 @@
"prebuilts/gcc":/* recursive = */ true,
"prebuilts/build-tools":/* recursive = */ true,
"prebuilts/jdk/jdk11":/* recursive = */ false,
+ "prebuilts/misc":/* recursive = */ false, // not recursive because we need bp2build converted build files in prebuilts/misc/common/asm
"prebuilts/sdk":/* recursive = */ false,
"prebuilts/sdk/current/extras/app-toolkit":/* recursive = */ false,
"prebuilts/sdk/current/support":/* recursive = */ false,
@@ -377,15 +380,16 @@
"gen-kotlin-build-file.py", // TODO(b/198619163) module has same name as source
"libgtest_ndk_c++", "libgtest_main_ndk_c++", // TODO(b/201816222): Requires sdk_version support.
"linkerconfig", "mdnsd", // TODO(b/202876379): has arch-variant static_executable
- "linker", // TODO(b/228316882): cc_binary uses link_crt
- "libdebuggerd", // TODO(b/228314770): support product variable-specific header_libs
- "versioner", // TODO(b/228313961): depends on prebuilt shared library libclang-cpp_host as a shared library, which does not supply expected providers for a shared library
- "libspeexresampler", // TODO(b/231995978): Filter out unknown cflags
- "libjpeg", "libvpx", // TODO(b/233948256): Convert .asm files
+ "linker", // TODO(b/228316882): cc_binary uses link_crt
+ "libdebuggerd", // TODO(b/228314770): support product variable-specific header_libs
+ "versioner", // TODO(b/228313961): depends on prebuilt shared library libclang-cpp_host as a shared library, which does not supply expected providers for a shared library
+ "libspeexresampler", // TODO(b/231995978): Filter out unknown cflags
+ "libvpx", // TODO(b/240756936): Arm neon variant not supported
"art_libartbase_headers", // TODO(b/236268577): Header libraries do not support export_shared_libs_headers
"apexer_test", // Requires aapt2
"apexer_test_host_tools",
"host_apex_verifier",
+ "tjbench", // TODO(b/240563612): Stem property
// java bugs
"libbase_ndk", // TODO(b/186826477): fails to link libctscamera2_jni for device (required for CtsCameraTestCases)
@@ -526,5 +530,20 @@
"simpleperf_ndk",
"toybox-static",
"zlib_bench",
+
+ // java_import[_host] issues
+ // tradefed prebuilts depend on libprotobuf
+ "prebuilt_tradefed",
+ "prebuilt_tradefed-test-framework",
+ // handcrafted BUILD.bazel files in //prebuilts/...
+ "prebuilt_r8lib-prebuilt",
+ "prebuilt_sdk-core-lambda-stubs",
+ "prebuilt_android-support-collections-nodeps",
+ "prebuilt_android-arch-core-common-nodeps",
+ "prebuilt_android-arch-lifecycle-common-java8-nodeps",
+ "prebuilt_android-arch-lifecycle-common-nodeps",
+ "prebuilt_android-support-annotations-nodeps",
+ "prebuilt_android-arch-paging-common-nodeps",
+ "prebuilt_android-arch-room-common-nodeps",
}
)
diff --git a/android/androidmk.go b/android/androidmk.go
index d6fe06d..006e43d 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -604,10 +604,6 @@
}
}
- if len(base.noticeFiles) > 0 {
- a.AddStrings("LOCAL_NOTICE_FILE", strings.Join(base.noticeFiles.Strings(), " "))
- }
-
if host {
makeOs := base.Os().String()
if base.Os() == Linux || base.Os() == LinuxBionic || base.Os() == LinuxMusl {
diff --git a/android/bazel.go b/android/bazel.go
index 40f2917..183a2f3 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -35,6 +35,20 @@
Bp2BuildTopLevel = "."
)
+type BazelConversionStatus struct {
+ // Information about _all_ bp2build targets generated by this module. Multiple targets are
+ // supported as Soong handles some things within a single target that we may choose to split into
+ // multiple targets, e.g. renderscript, protos, yacc within a cc module.
+ Bp2buildInfo []bp2buildInfo `blueprint:"mutated"`
+
+ // UnconvertedBp2buildDep stores the module names of direct dependency that were not converted to
+ // Bazel
+ UnconvertedDeps []string `blueprint:"mutated"`
+
+ // MissingBp2buildDep stores the module names of direct dependency that were not found
+ MissingDeps []string `blueprint:"mutated"`
+}
+
type bazelModuleProperties struct {
// The label of the Bazel target replacing this Soong module. When run in conversion mode, this
// will import the handcrafted build target into the autogenerated file. Note: this may result in
diff --git a/android/bazel_paths.go b/android/bazel_paths.go
index 1d0a6d5..c030aa8 100644
--- a/android/bazel_paths.go
+++ b/android/bazel_paths.go
@@ -32,14 +32,14 @@
// 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
+// 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
@@ -68,7 +68,7 @@
// cannot be resolved,the function will panic. This is often due to the dependency not being added
// via an AddDependency* method.
-// A minimal context interface to check if a module should be converted by bp2build,
+// BazelConversionContext is a minimal context interface to check if a module should be converted by bp2build,
// with functions containing information to match against allowlists and denylists.
// If a module is deemed to be convertible by bp2build, then it should rely on a
// BazelConversionPathContext for more functions for dep/path features.
diff --git a/android/config.go b/android/config.go
index 8c7d789..8c01bee 100644
--- a/android/config.go
+++ b/android/config.go
@@ -761,6 +761,10 @@
return uncheckedFinalApiLevel(*c.productVariables.Platform_sdk_version)
}
+func (c *config) PlatformSdkFinal() bool {
+ return Bool(c.productVariables.Platform_sdk_final)
+}
+
func (c *config) PlatformSdkCodename() string {
return String(c.productVariables.Platform_sdk_codename)
}
diff --git a/android/license_metadata.go b/android/license_metadata.go
index f2ab0a4..4ee5bf7 100644
--- a/android/license_metadata.go
+++ b/android/license_metadata.go
@@ -15,7 +15,6 @@
package android
import (
- "fmt"
"sort"
"strings"
@@ -67,6 +66,11 @@
return
}
+ // Defaults add properties and dependencies that get processed on their own.
+ if ctx.OtherModuleDependencyTag(dep) == DefaultsDepTag {
+ return
+ }
+
if ctx.OtherModuleHasProvider(dep, LicenseMetadataProvider) {
info := ctx.OtherModuleProvider(dep, LicenseMetadataProvider).(*LicenseMetadataInfo)
allDepMetadataFiles = append(allDepMetadataFiles, info.LicenseMetadataPath)
@@ -139,8 +143,6 @@
if len(outputFiles) > 0 {
args = append(args,
JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(outputFiles.Strings()), "-t "))
- } else {
- args = append(args, fmt.Sprintf("-t //%s:%s", ctx.ModuleDir(), ctx.ModuleName()))
}
// Installed files
diff --git a/android/module.go b/android/module.go
index 7173c0d..39f5ff9 100644
--- a/android/module.go
+++ b/android/module.go
@@ -515,7 +515,6 @@
ExportedToMake() bool
InitRc() Paths
VintfFragments() Paths
- NoticeFiles() Paths
EffectiveLicenseFiles() Paths
AddProperties(props ...interface{})
@@ -831,9 +830,6 @@
// names of other modules to install on target if this module is installed
Target_required []string `android:"arch_variant"`
- // relative path to a file to include in the list of notices for the device
- Notice *string `android:"path"`
-
// The OsType of artifacts that this module variant is responsible for creating.
//
// Set by osMutator
@@ -913,17 +909,8 @@
// constants in image.go, but can also be set to a custom value by individual module types.
ImageVariation string `blueprint:"mutated"`
- // Information about _all_ bp2build targets generated by this module. Multiple targets are
- // supported as Soong handles some things within a single target that we may choose to split into
- // multiple targets, e.g. renderscript, protos, yacc within a cc module.
- Bp2buildInfo []bp2buildInfo `blueprint:"mutated"`
-
- // UnconvertedBp2buildDep stores the module names of direct dependency that were not converted to
- // Bazel
- UnconvertedBp2buildDeps []string `blueprint:"mutated"`
-
- // MissingBp2buildDep stores the module names of direct dependency that were not found
- MissingBp2buildDeps []string `blueprint:"mutated"`
+ // Bazel conversion status
+ BazelConversionStatus BazelConversionStatus `blueprint:"mutated"`
}
// CommonAttributes represents the common Bazel attributes from which properties
@@ -1423,7 +1410,6 @@
checkbuildFiles Paths
packagingSpecs []PackagingSpec
packagingSpecsDepSet *packagingSpecsDepSet
- noticeFiles Paths
// katiInstalls tracks the install rules that were created by Soong but are being exported
// to Make to convert to ninja rules so that Make can add additional dependencies.
katiInstalls katiInstalls
@@ -1494,40 +1480,40 @@
}
func (m *ModuleBase) addBp2buildInfo(info bp2buildInfo) {
- m.commonProperties.Bp2buildInfo = append(m.commonProperties.Bp2buildInfo, info)
+ m.commonProperties.BazelConversionStatus.Bp2buildInfo = append(m.commonProperties.BazelConversionStatus.Bp2buildInfo, info)
}
// IsConvertedByBp2build returns whether this module was converted via bp2build.
func (m *ModuleBase) IsConvertedByBp2build() bool {
- return len(m.commonProperties.Bp2buildInfo) > 0
+ return len(m.commonProperties.BazelConversionStatus.Bp2buildInfo) > 0
}
// Bp2buildTargets returns the Bazel targets bp2build generated for this module.
func (m *ModuleBase) Bp2buildTargets() []bp2buildInfo {
- return m.commonProperties.Bp2buildInfo
+ return m.commonProperties.BazelConversionStatus.Bp2buildInfo
}
// AddUnconvertedBp2buildDep stores module name of a dependency that was not converted to Bazel.
func (b *baseModuleContext) AddUnconvertedBp2buildDep(dep string) {
- unconvertedDeps := &b.Module().base().commonProperties.UnconvertedBp2buildDeps
+ unconvertedDeps := &b.Module().base().commonProperties.BazelConversionStatus.UnconvertedDeps
*unconvertedDeps = append(*unconvertedDeps, dep)
}
// AddMissingBp2buildDep stores module name of a dependency that was not found in a Android.bp file.
func (b *baseModuleContext) AddMissingBp2buildDep(dep string) {
- missingDeps := &b.Module().base().commonProperties.MissingBp2buildDeps
+ missingDeps := &b.Module().base().commonProperties.BazelConversionStatus.MissingDeps
*missingDeps = append(*missingDeps, dep)
}
// GetUnconvertedBp2buildDeps returns the list of module names of this module's direct dependencies that
// were not converted to Bazel.
func (m *ModuleBase) GetUnconvertedBp2buildDeps() []string {
- return FirstUniqueStrings(m.commonProperties.UnconvertedBp2buildDeps)
+ return FirstUniqueStrings(m.commonProperties.BazelConversionStatus.UnconvertedDeps)
}
// GetMissingBp2buildDeps eturns the list of module names that were not found in Android.bp files.
func (m *ModuleBase) GetMissingBp2buildDeps() []string {
- return FirstUniqueStrings(m.commonProperties.MissingBp2buildDeps)
+ return FirstUniqueStrings(m.commonProperties.BazelConversionStatus.MissingDeps)
}
func (m *ModuleBase) AddJSONData(d *map[string]interface{}) {
@@ -2054,10 +2040,6 @@
return String(m.commonProperties.Owner)
}
-func (m *ModuleBase) NoticeFiles() Paths {
- return m.noticeFiles
-}
-
func (m *ModuleBase) setImageVariation(variant string) {
m.commonProperties.ImageVariation = variant
}
@@ -2317,19 +2299,6 @@
}
})
- m.noticeFiles = make([]Path, 0)
- optPath := OptionalPath{}
- notice := proptools.StringDefault(m.commonProperties.Notice, "")
- if module := SrcIsModule(notice); module != "" {
- optPath = ctx.ExpandOptionalSource(¬ice, "notice")
- } else if notice != "" {
- noticePath := filepath.Join(ctx.ModuleDir(), notice)
- optPath = ExistentPathForSource(ctx, noticePath)
- }
- if optPath.Valid() {
- m.noticeFiles = append(m.noticeFiles, optPath.Path())
- }
-
licensesPropertyFlattener(ctx)
if ctx.Failed() {
return
diff --git a/android/neverallow.go b/android/neverallow.go
index 357cae5..00078a0 100644
--- a/android/neverallow.go
+++ b/android/neverallow.go
@@ -58,7 +58,6 @@
AddNeverAllowRules(createMakefileGoalRules()...)
AddNeverAllowRules(createInitFirstStageRules()...)
AddNeverAllowRules(createProhibitFrameworkAccessRules()...)
- AddNeverAllowRules(createNoticeDeprecationRules()...)
}
// Add a NeverAllow rule to the set of rules to apply.
@@ -213,11 +212,16 @@
}
func createMakefileGoalRules() []Rule {
+ allowlist := []string{
+ // libwifi_hal uses makefile_goal for its dependencies
+ "frameworks/opt/net/wifi/libwifi_hal",
+ }
return []Rule{
NeverAllow().
ModuleType("makefile_goal").
WithoutMatcher("product_out_path", Regexp("^boot[0-9a-zA-Z.-]*[.]img$")).
- Because("Only boot images may be imported as a makefile goal."),
+ NotIn(allowlist...).
+ Because("Only boot images may be imported as a makefile goal if not in allowed projects"),
}
}
@@ -239,15 +243,6 @@
}
}
-func createNoticeDeprecationRules() []Rule {
- return []Rule{
- NeverAllow().
- WithMatcher("notice", isSetMatcherInstance).
- NotIn("vendor/linaro/linux-firmware/").
- Because("notice has been replaced by licenses/default_applicable_licenses"),
- }
-}
-
func neverallowMutator(ctx BottomUpMutatorContext) {
m, ok := ctx.Module().(Module)
if !ok {
diff --git a/android/neverallow_test.go b/android/neverallow_test.go
index 86f1a37..4772799 100644
--- a/android/neverallow_test.go
+++ b/android/neverallow_test.go
@@ -324,7 +324,32 @@
`),
},
expectedErrors: []string{
- "Only boot images may be imported as a makefile goal.",
+ "Only boot images.* may be imported as a makefile goal",
+ },
+ },
+ {
+ name: "disallowed makefile_goal outside external",
+ fs: map[string][]byte{
+ "project/Android.bp": []byte(`
+ makefile_goal {
+ name: "foo",
+ product_out_path: "obj/EXE/foo",
+ }
+ `),
+ },
+ expectedErrors: []string{
+ "not in allowed projects",
+ },
+ },
+ {
+ name: "allow makefile_goal within external",
+ fs: map[string][]byte{
+ "frameworks/opt/net/wifi/libwifi_hal/Android.bp": []byte(`
+ makefile_goal {
+ name: "foo",
+ product_out_path: "obj/EXE/foo",
+ }
+ `),
},
},
// Tests for the rule prohibiting the use of framework
diff --git a/apex/constants.go b/android/updatable_modules.go
similarity index 82%
rename from apex/constants.go
rename to android/updatable_modules.go
index c68edb7..71c76c5 100644
--- a/apex/constants.go
+++ b/android/updatable_modules.go
@@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package apex
+package android
-// This file contains branch specific constants. They are stored in a separate
-// file to minimise the potential of merge conflicts between branches when
-// the code from the package is changed.
+// This file contains branch specific constants for building updatable modules.
+// They are stored in a separate file to minimise the potential of merge
+// conflicts between branches when the code from the package is changed.
// The default manifest version for all the modules on this branch.
// This version code will be used only if there is no version field in the
@@ -33,4 +33,4 @@
// * AOSP - xx9990000
// * x-mainline-prod - xx9990000
// * master - 990090000
-const defaultManifestVersion = "339990000"
+const DefaultUpdatableModuleVersion = "339990000"
diff --git a/apex/Android.bp b/apex/Android.bp
index 6533c61..018d030 100644
--- a/apex/Android.bp
+++ b/apex/Android.bp
@@ -26,7 +26,7 @@
"apex_sdk_member.go",
"apex_singleton.go",
"builder.go",
- "constants.go",
+ "bp2build.go",
"deapexer.go",
"key.go",
"prebuilt.go",
diff --git a/apex/androidmk.go b/apex/androidmk.go
index 938c8ed..3373211 100644
--- a/apex/androidmk.go
+++ b/apex/androidmk.go
@@ -168,10 +168,6 @@
if len(newDataPaths) > 0 {
fmt.Fprintln(w, "LOCAL_TEST_DATA :=", strings.Join(android.AndroidMkDataPaths(newDataPaths), " "))
}
-
- if fi.module != nil && len(fi.module.NoticeFiles()) > 0 {
- fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", strings.Join(fi.module.NoticeFiles().Strings(), " "))
- }
} else {
modulePath = pathWhenActivated
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 69205f8..5282941 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -443,7 +443,6 @@
srcs: ["mylib.cpp"],
system_shared_libs: [],
stl: "none",
- notice: "custom_notice",
static_libs: ["libstatic"],
// TODO: remove //apex_available:platform
apex_available: [
@@ -467,7 +466,6 @@
srcs: ["mylib.cpp"],
system_shared_libs: [],
stl: "none",
- notice: "custom_notice_for_static_lib",
// TODO: remove //apex_available:platform
apex_available: [
"//apex_available:platform",
diff --git a/apex/bp2build.go b/apex/bp2build.go
new file mode 100644
index 0000000..221ab13
--- /dev/null
+++ b/apex/bp2build.go
@@ -0,0 +1,30 @@
+// Copyright (C) 2022 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 apex
+
+import (
+ "android/soong/android"
+ "strings"
+)
+
+// This file contains the bp2build integration for the apex package.
+
+// Export constants as Starlark using bp2build to Bazel.
+func BazelApexToolchainVars() string {
+ content := []string{
+ "# GENERATED BY SOONG. DO NOT EDIT.",
+ "default_manifest_version = " + android.DefaultUpdatableModuleVersion, // constants.go is different in every branch.
+ }
+ return strings.Join(content, "\n")
+}
diff --git a/apex/builder.go b/apex/builder.go
index 58acf71..f1b1448 100644
--- a/apex/builder.go
+++ b/apex/builder.go
@@ -214,7 +214,7 @@
Args: map[string]string{
"provideNativeLibs": strings.Join(provideNativeLibs, " "),
"requireNativeLibs": strings.Join(requireNativeLibs, " "),
- "default_version": defaultManifestVersion,
+ "default_version": android.DefaultUpdatableModuleVersion,
"opt": strings.Join(optCommands, " "),
},
})
diff --git a/apex/vndk_test.go b/apex/vndk_test.go
index d580e5a..21526c3 100644
--- a/apex/vndk_test.go
+++ b/apex/vndk_test.go
@@ -86,7 +86,6 @@
},
system_shared_libs: [],
stl: "none",
- notice: "custom_notice",
}
` + vndkLibrariesTxtFiles("current")
diff --git a/bazel/aquery_test.go b/bazel/aquery_test.go
index 3a2bf0f..53056c7 100644
--- a/bazel/aquery_test.go
+++ b/bazel/aquery_test.go
@@ -499,19 +499,11 @@
func TestBazelOutRemovalFromInputDepsets(t *testing.T) {
const inputString = `{
- "artifacts": [{
- "id": 1,
- "pathFragmentId": 10
- }, {
- "id": 2,
- "pathFragmentId": 20
- }, {
- "id": 3,
- "pathFragmentId": 30
- }, {
- "id": 4,
- "pathFragmentId": 40
- }],
+ "artifacts": [
+ { "id": 1, "pathFragmentId": 10 },
+ { "id": 2, "pathFragmentId": 20 },
+ { "id": 3, "pathFragmentId": 30 },
+ { "id": 4, "pathFragmentId": 40 }],
"depSetOfFiles": [{
"id": 1111,
"directArtifactIds": [3 , 4]
@@ -525,28 +517,14 @@
"outputIds": [2],
"primaryOutputId": 1
}],
- "pathFragments": [{
- "id": 10,
- "label": "input"
- }, {
- "id": 20,
- "label": "output"
- }, {
- "id": 30,
- "label": "dep1",
- "parentId": 50
- }, {
- "id": 40,
- "label": "dep2",
- "parentId": 60
- }, {
- "id": 50,
- "label": "bazel_tools",
- "parentId": 60
- }, {
- "id": 60,
- "label": ".."
- }]
+ "pathFragments": [
+ { "id": 10, "label": "input" },
+ { "id": 20, "label": "output" },
+ { "id": 30, "label": "dep1", "parentId": 50 },
+ { "id": 40, "label": "dep2", "parentId": 60 },
+ { "id": 50, "label": "bazel_tools", "parentId": 60 },
+ { "id": 60, "label": ".."}
+ ]
}`
actualBuildStatements, actualDepsets, _ := AqueryBuildStatements([]byte(inputString))
if len(actualDepsets) != 1 {
diff --git a/bp2build/bp2build.go b/bp2build/bp2build.go
index 5bff956..0e3d2a5 100644
--- a/bp2build/bp2build.go
+++ b/bp2build/bp2build.go
@@ -29,7 +29,9 @@
func Codegen(ctx *CodegenContext) CodegenMetrics {
// This directory stores BUILD files that could be eventually checked-in.
bp2buildDir := android.PathForOutput(ctx, "bp2build")
- android.RemoveAllOutputDir(bp2buildDir)
+ if err := android.RemoveAllOutputDir(bp2buildDir); err != nil {
+ fmt.Printf("ERROR: Encountered error while cleaning %s: %s", bp2buildDir, err.Error())
+ }
res, errs := GenerateBazelTargets(ctx, true)
if len(errs) > 0 {
@@ -52,7 +54,9 @@
// Get the output directory and create it if it doesn't exist.
func getOrCreateOutputDir(outputDir android.OutputPath, ctx android.PathContext, dir string) android.OutputPath {
dirPath := outputDir.Join(ctx, dir)
- android.CreateOutputDirIfNonexistent(dirPath, os.ModePerm)
+ if err := android.CreateOutputDirIfNonexistent(dirPath, os.ModePerm); err != nil {
+ fmt.Printf("ERROR: path %s: %s", dirPath, err.Error())
+ }
return dirPath
}
@@ -60,13 +64,13 @@
func writeFiles(ctx android.PathContext, outputDir android.OutputPath, files []BazelFile) {
for _, f := range files {
p := getOrCreateOutputDir(outputDir, ctx, f.Dir).Join(ctx, f.Basename)
- if err := writeFile(ctx, p, f.Contents); err != nil {
+ if err := writeFile(p, f.Contents); err != nil {
panic(fmt.Errorf("Failed to write %q (dir %q) due to %q", f.Basename, f.Dir, err))
}
}
}
-func writeFile(ctx android.PathContext, pathToFile android.OutputPath, content string) error {
+func writeFile(pathToFile android.OutputPath, content string) error {
// These files are made editable to allow users to modify and iterate on them
// in the source tree.
return android.WriteFileToOutputDir(pathToFile, []byte(content), 0644)
diff --git a/bp2build/build_conversion.go b/bp2build/build_conversion.go
index a96a3fc..415becb 100644
--- a/bp2build/build_conversion.go
+++ b/bp2build/build_conversion.go
@@ -161,22 +161,22 @@
unconvertedDepMode unconvertedDepsMode
}
-func (c *CodegenContext) Mode() CodegenMode {
- return c.mode
+func (ctx *CodegenContext) Mode() CodegenMode {
+ return ctx.mode
}
// CodegenMode is an enum to differentiate code-generation modes.
type CodegenMode int
const (
- // Bp2Build: generate BUILD files with targets buildable by Bazel directly.
+ // Bp2Build - generate BUILD files with targets buildable by Bazel directly.
//
// This mode is used for the Soong->Bazel build definition conversion.
Bp2Build CodegenMode = iota
- // QueryView: generate BUILD files with targets representing fully mutated
+ // QueryView - generate BUILD files with targets representing fully mutated
// Soong modules, representing the fully configured Soong module graph with
- // variants and dependency endges.
+ // variants and dependency edges.
//
// This mode is used for discovering and introspecting the existing Soong
// module graph.
@@ -470,13 +470,13 @@
})
}
- for p, _ := range ignoredPropNames {
+ for p := range ignoredPropNames {
delete(props.Attrs, p)
}
attributes := propsToAttributes(props.Attrs)
depLabelList := "[\n"
- for depLabel, _ := range depLabels {
+ for depLabel := range depLabels {
depLabelList += fmt.Sprintf(" %q,\n", depLabel)
}
depLabelList += " ]"
diff --git a/bp2build/cc_yasm_conversion_test.go b/bp2build/cc_yasm_conversion_test.go
new file mode 100644
index 0000000..6114a49
--- /dev/null
+++ b/bp2build/cc_yasm_conversion_test.go
@@ -0,0 +1,179 @@
+// Copyright 2022 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package bp2build
+
+import (
+ "testing"
+
+ "android/soong/android"
+ "android/soong/cc"
+)
+
+func runYasmTestCase(t *testing.T, tc bp2buildTestCase) {
+ t.Helper()
+ runBp2BuildTestCase(t, registerYasmModuleTypes, tc)
+}
+
+func registerYasmModuleTypes(ctx android.RegistrationContext) {
+ cc.RegisterCCBuildComponents(ctx)
+ ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
+ ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
+ ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory)
+ ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
+}
+
+func TestYasmSimple(t *testing.T) {
+ runYasmTestCase(t, bp2buildTestCase{
+ description: "Simple yasm test",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ filesystem: map[string]string{
+ "main.cpp": "",
+ "myfile.asm": "",
+ },
+ blueprint: `
+cc_library {
+ name: "foo",
+ srcs: ["main.cpp", "myfile.asm"],
+}`,
+ expectedBazelTargets: append([]string{
+ makeBazelTarget("yasm", "foo_yasm", map[string]string{
+ "include_dirs": `["."]`,
+ "srcs": `["myfile.asm"]`,
+ }),
+ }, makeCcLibraryTargets("foo", map[string]string{
+ "local_includes": `["."]`,
+ "srcs": `[
+ "main.cpp",
+ ":foo_yasm",
+ ]`,
+ })...),
+ })
+}
+
+func TestYasmWithIncludeDirs(t *testing.T) {
+ runYasmTestCase(t, bp2buildTestCase{
+ description: "Simple yasm test",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ filesystem: map[string]string{
+ "main.cpp": "",
+ "myfile.asm": "",
+ "include1/foo/myinclude.inc": "",
+ "include2/foo/myinclude2.inc": "",
+ },
+ blueprint: `
+cc_library {
+ name: "foo",
+ local_include_dirs: ["include1/foo"],
+ export_include_dirs: ["include2/foo"],
+ srcs: ["main.cpp", "myfile.asm"],
+}`,
+ expectedBazelTargets: append([]string{
+ makeBazelTarget("yasm", "foo_yasm", map[string]string{
+ "include_dirs": `[
+ "include1/foo",
+ ".",
+ "include2/foo",
+ ]`,
+ "srcs": `["myfile.asm"]`,
+ }),
+ }, makeCcLibraryTargets("foo", map[string]string{
+ "local_includes": `[
+ "include1/foo",
+ ".",
+ ]`,
+ "export_includes": `["include2/foo"]`,
+ "srcs": `[
+ "main.cpp",
+ ":foo_yasm",
+ ]`,
+ })...),
+ })
+}
+
+func TestYasmConditionalBasedOnArch(t *testing.T) {
+ runYasmTestCase(t, bp2buildTestCase{
+ description: "Simple yasm test",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ filesystem: map[string]string{
+ "main.cpp": "",
+ "myfile.asm": "",
+ },
+ blueprint: `
+cc_library {
+ name: "foo",
+ srcs: ["main.cpp"],
+ arch: {
+ x86: {
+ srcs: ["myfile.asm"],
+ },
+ },
+}`,
+ expectedBazelTargets: append([]string{
+ makeBazelTarget("yasm", "foo_yasm", map[string]string{
+ "include_dirs": `["."]`,
+ "srcs": `select({
+ "//build/bazel/platforms/arch:x86": ["myfile.asm"],
+ "//conditions:default": [],
+ })`,
+ }),
+ }, makeCcLibraryTargets("foo", map[string]string{
+ "local_includes": `["."]`,
+ "srcs": `["main.cpp"] + select({
+ "//build/bazel/platforms/arch:x86": [":foo_yasm"],
+ "//conditions:default": [],
+ })`,
+ })...),
+ })
+}
+
+func TestYasmPartiallyConditional(t *testing.T) {
+ runYasmTestCase(t, bp2buildTestCase{
+ description: "Simple yasm test",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ filesystem: map[string]string{
+ "main.cpp": "",
+ "myfile.asm": "",
+ "mysecondfile.asm": "",
+ },
+ blueprint: `
+cc_library {
+ name: "foo",
+ srcs: ["main.cpp", "myfile.asm"],
+ arch: {
+ x86: {
+ srcs: ["mysecondfile.asm"],
+ },
+ },
+}`,
+ expectedBazelTargets: append([]string{
+ makeBazelTarget("yasm", "foo_yasm", map[string]string{
+ "include_dirs": `["."]`,
+ "srcs": `["myfile.asm"] + select({
+ "//build/bazel/platforms/arch:x86": ["mysecondfile.asm"],
+ "//conditions:default": [],
+ })`,
+ }),
+ }, makeCcLibraryTargets("foo", map[string]string{
+ "local_includes": `["."]`,
+ "srcs": `[
+ "main.cpp",
+ ":foo_yasm",
+ ]`,
+ })...),
+ })
+}
diff --git a/bp2build/conversion.go b/bp2build/conversion.go
index 4246f7d..8cf9bea 100644
--- a/bp2build/conversion.go
+++ b/bp2build/conversion.go
@@ -10,6 +10,8 @@
cc_config "android/soong/cc/config"
java_config "android/soong/java/config"
+ "android/soong/apex"
+
"github.com/google/blueprint/proptools"
)
@@ -28,6 +30,9 @@
files = append(files, newFile("java_toolchain", GeneratedBuildFileName, "")) // Creates a //java_toolchain package.
files = append(files, newFile("java_toolchain", "constants.bzl", java_config.BazelJavaToolchainVars(cfg)))
+ files = append(files, newFile("apex_toolchain", GeneratedBuildFileName, "")) // Creates a //apex_toolchain package.
+ files = append(files, newFile("apex_toolchain", "constants.bzl", apex.BazelApexToolchainVars()))
+
files = append(files, newFile("metrics", "converted_modules.txt", strings.Join(metrics.convertedModules, "\n")))
files = append(files, newFile("product_config", "soong_config_variables.bzl", cfg.Bp2buildSoongConfigDefinitions.String()))
diff --git a/bp2build/conversion_test.go b/bp2build/conversion_test.go
index b0d0740..0cb711c 100644
--- a/bp2build/conversion_test.go
+++ b/bp2build/conversion_test.go
@@ -104,6 +104,14 @@
basename: "constants.bzl",
},
{
+ dir: "apex_toolchain",
+ basename: GeneratedBuildFileName,
+ },
+ {
+ dir: "apex_toolchain",
+ basename: "constants.bzl",
+ },
+ {
dir: "metrics",
basename: "converted_modules.txt",
},
diff --git a/bp2build/symlink_forest.go b/bp2build/symlink_forest.go
index c5075e5..78e7b0e 100644
--- a/bp2build/symlink_forest.go
+++ b/bp2build/symlink_forest.go
@@ -22,7 +22,7 @@
children map[string]*node
}
-// Ensures that the a node for the given path exists in the tree and returns it.
+// Ensures that the node for the given path exists in the tree and returns it.
func ensureNodeExists(root *node, path string) *node {
if path == "" {
return root
@@ -126,11 +126,11 @@
buildFilesMap := readdirToMap(shared.JoinPath(topdir, buildFilesDir))
allEntries := make(map[string]bool)
- for n, _ := range srcDirMap {
+ for n := range srcDirMap {
allEntries[n] = true
}
- for n, _ := range buildFilesMap {
+ for n := range buildFilesMap {
allEntries[n] = true
}
@@ -140,7 +140,7 @@
os.Exit(1)
}
- for f, _ := range allEntries {
+ for f := range allEntries {
if f[0] == '.' {
continue // Ignore dotfiles
}
diff --git a/build_kzip.bash b/build_kzip.bash
index 6219021..fa616b9 100755
--- a/build_kzip.bash
+++ b/build_kzip.bash
@@ -44,14 +44,18 @@
declare -r go_root=$(realpath prebuilts/go/linux-x86)
declare -r source_root=$PWD
-# TODO(asmundak): Until b/182183061 is fixed, default corpus has to be specified
-# in the rules file. Generate this file on the fly with corpus value set from the
-# environment variable.
-for dir in blueprint soong; do
- (cd "build/$dir";
+# For the Go code, we invoke the extractor directly. The two caveats are that
+# the extractor's rewrite rules are generated on the fly as they depend on the XREF_CORPUS
+# value, and that the name of the kzip file is derived from the directory name
+# by replacing '/' with '_'.
+declare -ar go_modules=(build/blueprint build/soong
+ build/make/tools/canoninja build/make/tools/compliance build/make/tools/rbcrun)
+for dir in "${go_modules[@]}"; do
+ (cd "$dir";
+ outfile=$(echo "$dir" | sed -r 's|/|_|g;s|(.*)|\1.go.kzip|');
KYTHE_ROOT_DIRECTORY="${source_root}" "$go_extractor" --goroot="$go_root" \
--rules=<(printf '[{"pattern": "(.*)","vname": {"path": "@1@", "corpus":"%s"}}]' "${XREF_CORPUS}") \
- --canonicalize_package_corpus --output "${abspath_out}/soong/build_${dir}.go.kzip" ./...
+ --canonicalize_package_corpus --output "${abspath_out}/soong/$outfile" ./...
)
done
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 6cd6733..61a55ee 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -4,7 +4,7 @@
// 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
+// 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,
@@ -30,6 +30,7 @@
const (
cSrcPartition = "c"
asSrcPartition = "as"
+ asmSrcPartition = "asm"
lSrcPartition = "l"
llSrcPartition = "ll"
cppSrcPartition = "cpp"
@@ -81,6 +82,7 @@
protoSrcPartition: android.ProtoSrcLabelPartition,
cSrcPartition: bazel.LabelPartition{Extensions: []string{".c"}, LabelMapper: addSuffixForFilegroup("_c_srcs")},
asSrcPartition: bazel.LabelPartition{Extensions: []string{".s", ".S"}, LabelMapper: addSuffixForFilegroup("_as_srcs")},
+ asmSrcPartition: bazel.LabelPartition{Extensions: []string{".asm"}},
// TODO(http://b/231968910): If there is ever a filegroup target that
// contains .l or .ll files we will need to find a way to add a
// LabelMapper for these that identifies these filegroups and
@@ -289,6 +291,7 @@
// Assembly options and sources
asFlags bazel.StringListAttribute
asSrcs bazel.LabelListAttribute
+ asmSrcs bazel.LabelListAttribute
// C options and sources
conlyFlags bazel.StringListAttribute
cSrcs bazel.LabelListAttribute
@@ -447,6 +450,7 @@
ca.srcs = partitionedSrcs[cppSrcPartition]
ca.cSrcs = partitionedSrcs[cSrcPartition]
ca.asSrcs = partitionedSrcs[asSrcPartition]
+ ca.asmSrcs = partitionedSrcs[asmSrcPartition]
ca.lSrcs = partitionedSrcs[lSrcPartition]
ca.llSrcs = partitionedSrcs[llSrcPartition]
@@ -527,6 +531,61 @@
return relative, absolute
}
+type YasmAttributes struct {
+ Srcs bazel.LabelListAttribute
+ Flags bazel.StringListAttribute
+ Include_dirs bazel.StringListAttribute
+}
+
+func bp2BuildYasm(ctx android.Bp2buildMutatorContext, m *Module, ca compilerAttributes) *bazel.LabelAttribute {
+ if ca.asmSrcs.IsEmpty() {
+ return nil
+ }
+
+ // Yasm needs the include directories from both local_includes and
+ // export_include_dirs. We don't care about actually exporting them from the
+ // yasm rule though, because they will also be present on the cc_ rule that
+ // wraps this yasm rule.
+ includes := ca.localIncludes.Clone()
+ bp2BuildPropParseHelper(ctx, m, &FlagExporterProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
+ if flagExporterProperties, ok := props.(*FlagExporterProperties); ok {
+ if len(flagExporterProperties.Export_include_dirs) > 0 {
+ x := bazel.StringListAttribute{}
+ x.SetSelectValue(axis, config, flagExporterProperties.Export_include_dirs)
+ includes.Append(x)
+ }
+ }
+ })
+
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "yasm",
+ Bzl_load_location: "//build/bazel/rules/cc:yasm.bzl",
+ },
+ android.CommonAttributes{Name: m.Name() + "_yasm"},
+ &YasmAttributes{
+ Srcs: ca.asmSrcs,
+ Flags: ca.asFlags,
+ Include_dirs: *includes,
+ })
+
+ // We only want to add a dependency on the _yasm target if there are asm
+ // sources in the current configuration. If there are unconfigured asm
+ // sources, always add the dependency. Otherwise, add the dependency only
+ // on the configuration axes and values that had asm sources.
+ if len(ca.asmSrcs.Value.Includes) > 0 {
+ return bazel.MakeLabelAttribute(":" + m.Name() + "_yasm")
+ }
+
+ ret := &bazel.LabelAttribute{}
+ for _, axis := range ca.asmSrcs.SortedConfigurationAxes() {
+ for config := range ca.asmSrcs.ConfigurableValues[axis] {
+ ret.SetSelectValue(axis, config, bazel.Label{Label: ":" + m.Name() + "_yasm"})
+ }
+ }
+ return ret
+}
+
// bp2BuildParseBaseProps returns all compiler, linker, library attributes of a cc module..
func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) baseAttributes {
archVariantCompilerProps := module.GetArchVariantProperties(ctx, &BaseCompilerProperties{})
@@ -612,6 +671,8 @@
(&compilerAttrs).finalize(ctx, implementationHdrs)
(&linkerAttrs).finalize(ctx)
+ (&compilerAttrs.srcs).Add(bp2BuildYasm(ctx, module, compilerAttrs))
+
protoDep := bp2buildProto(ctx, module, compilerAttrs.protoSrcs)
// bp2buildProto will only set wholeStaticLib or implementationWholeStaticLib, but we don't know
diff --git a/cc/library.go b/cc/library.go
index bd6ccb5..ff485cf 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -1616,14 +1616,18 @@
func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objects, fileName string, soFile android.Path) {
if library.sabi.shouldCreateSourceAbiDump() {
- var vndkVersion string
-
+ var version string
if ctx.useVndk() {
// For modules linking against vndk, follow its vndk version
- vndkVersion = ctx.Module().(*Module).VndkVersion()
+ version = ctx.Module().(*Module).VndkVersion()
} else {
- // Regard the other modules as PLATFORM_VNDK_VERSION
- vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
+ // After sdk finalizatoin, the ABI of the latest API level must be consistent with the source code
+ // so the chosen reference dump is the PLATFORM_SDK_VERSION.
+ if ctx.Config().PlatformSdkFinal() {
+ version = ctx.Config().PlatformSdkVersion().String()
+ } else {
+ version = "current"
+ }
}
exportIncludeDirs := library.flagExporter.exportedIncludes(ctx)
@@ -1642,7 +1646,7 @@
addLsdumpPath(classifySourceAbiDump(ctx) + ":" + library.sAbiOutputFile.String())
- refAbiDumpFile := getRefAbiDumpFile(ctx, vndkVersion, fileName)
+ refAbiDumpFile := getRefAbiDumpFile(ctx, version, fileName)
if refAbiDumpFile != nil {
library.sAbiDiff = sourceAbiDiff(ctx, library.sAbiOutputFile.Path(),
refAbiDumpFile, fileName, exportedHeaderFlags,
diff --git a/cc/testing.go b/cc/testing.go
index 6b858d5..d70ec9b 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -194,7 +194,6 @@
native_coverage: false,
system_shared_libs: [],
stl: "none",
- notice: "custom_notice",
}
cc_library {
name: "libprofile-clang-extras",
@@ -205,7 +204,6 @@
native_coverage: false,
system_shared_libs: [],
stl: "none",
- notice: "custom_notice",
}
cc_library {
name: "libprofile-extras_ndk",
@@ -214,7 +212,6 @@
native_coverage: false,
system_shared_libs: [],
stl: "none",
- notice: "custom_notice",
sdk_version: "current",
}
cc_library {
@@ -224,7 +221,6 @@
native_coverage: false,
system_shared_libs: [],
stl: "none",
- notice: "custom_notice",
sdk_version: "current",
}
diff --git a/cc/vndk.go b/cc/vndk.go
index bf6148b..4cd4d42 100644
--- a/cc/vndk.go
+++ b/cc/vndk.go
@@ -671,12 +671,8 @@
snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
configsDir := filepath.Join(snapshotArchDir, "configs")
- noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
includeDir := filepath.Join(snapshotArchDir, "include")
- // set of notice files copied.
- noticeBuilt := make(map[string]bool)
-
// paths of VNDK modules for GPL license checking
modulePaths := make(map[string]string)
@@ -762,16 +758,6 @@
moduleNames[stem] = ctx.ModuleName(m)
modulePaths[stem] = ctx.ModuleDir(m)
- if len(m.NoticeFiles()) > 0 {
- noticeName := stem + ".txt"
- // skip already copied notice file
- if _, ok := noticeBuilt[noticeName]; !ok {
- noticeBuilt[noticeName] = true
- snapshotOutputs = append(snapshotOutputs, combineNoticesRule(
- ctx, m.NoticeFiles(), filepath.Join(noticeDir, noticeName)))
- }
- }
-
if ctx.Config().VndkSnapshotBuildArtifacts() {
headers = append(headers, m.SnapshotHeaders()...)
}
diff --git a/fuzz/fuzz_common.go b/fuzz/fuzz_common.go
index 1a87b30..2474cbc 100644
--- a/fuzz/fuzz_common.go
+++ b/fuzz/fuzz_common.go
@@ -106,21 +106,21 @@
// A brief description of what the fuzzed code does.
Description string `json:"description,omitempty"`
// Can this code be triggered remotely or only locally.
- Remotely_accessible bool `json:"remotely_accessible,omitempty"`
+ Remotely_accessible *bool `json:"remotely_accessible,omitempty"`
// Is the fuzzed code host only, i.e. test frameworks or support utilities.
- Host_only bool `json:"host_only,omitempty"`
+ Host_only *bool `json:"host_only,omitempty"`
// Can third party/untrusted apps supply data to fuzzed code.
- Untrusted_data bool `json:"untrusted_data,omitempty"`
+ Untrusted_data *bool `json:"untrusted_data,omitempty"`
// Is the code being fuzzed in a privileged, constrained or any other
// context from:
// https://source.android.com/security/overview/updates-resources#context_types.
Privilege_level PrivilegedLevel `json:"privilege_level,omitempty"`
// Can the fuzzed code isolated or can be called by multiple users/processes.
- Isolated bool `json:"users_isolation,omitempty"`
+ Isolated *bool `json:"users_isolation,omitempty"`
// When code was relaeased or will be released.
Production_date string `json:"production_date,omitempty"`
// Prevents critical service functionality like phone calls, bluetooth, etc.
- Critical bool `json:"critical,omitempty"`
+ Critical *bool `json:"critical,omitempty"`
// Specify whether to enable continuous fuzzing on devices. Defaults to true.
Fuzz_on_haiku_device *bool `json:"fuzz_on_haiku_device,omitempty"`
// Specify whether to enable continuous fuzzing on host. Defaults to true.
diff --git a/java/Android.bp b/java/Android.bp
index e25accf..9df4ab4 100644
--- a/java/Android.bp
+++ b/java/Android.bp
@@ -76,6 +76,7 @@
"tradefed.go",
],
testSrcs: [
+ "aar_test.go",
"androidmk_test.go",
"app_import_test.go",
"app_set_test.go",
diff --git a/java/aar.go b/java/aar.go
index dadfc6a..a59ecb8 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -105,6 +105,7 @@
noticeFile android.OptionalPath
assetPackage android.OptionalPath
isLibrary bool
+ defaultManifestVersion string
useEmbeddedNativeLibs bool
useEmbeddedDex bool
usesNonSdkApis bool
@@ -281,14 +282,15 @@
manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
manifestPath := ManifestFixer(ctx, manifestSrcPath, ManifestFixerParams{
- SdkContext: sdkContext,
- ClassLoaderContexts: classLoaderContexts,
- IsLibrary: a.isLibrary,
- UseEmbeddedNativeLibs: a.useEmbeddedNativeLibs,
- UsesNonSdkApis: a.usesNonSdkApis,
- UseEmbeddedDex: a.useEmbeddedDex,
- HasNoCode: a.hasNoCode,
- LoggingParent: a.LoggingParent,
+ SdkContext: sdkContext,
+ ClassLoaderContexts: classLoaderContexts,
+ IsLibrary: a.isLibrary,
+ DefaultManifestVersion: a.defaultManifestVersion,
+ UseEmbeddedNativeLibs: a.useEmbeddedNativeLibs,
+ UsesNonSdkApis: a.usesNonSdkApis,
+ UseEmbeddedDex: a.useEmbeddedDex,
+ HasNoCode: a.hasNoCode,
+ LoggingParent: a.LoggingParent,
})
// Add additional manifest files to transitive manifests.
@@ -570,12 +572,24 @@
a.exportedProguardFlagFiles = android.FirstUniquePaths(a.exportedProguardFlagFiles)
a.exportedStaticPackages = android.FirstUniquePaths(a.exportedStaticPackages)
+
+ prebuiltJniPackages := android.Paths{}
+ ctx.VisitDirectDeps(func(module android.Module) {
+ if info, ok := ctx.OtherModuleProvider(module, JniPackageProvider).(JniPackageInfo); ok {
+ prebuiltJniPackages = append(prebuiltJniPackages, info.JniPackages...)
+ }
+ })
+ if len(prebuiltJniPackages) > 0 {
+ ctx.SetProvider(JniPackageProvider, JniPackageInfo{
+ JniPackages: prebuiltJniPackages,
+ })
+ }
}
// android_library builds and links sources into a `.jar` file for the device along with Android resources.
//
// An android_library has a single variant that produces a `.jar` file containing `.class` files that were
-// compiled against the device bootclasspath, along with a `package-res.apk` file containing Android resources compiled
+// compiled against the device bootclasspath, along with a `package-res.apk` file containing Android resources compiled
// with aapt2. This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of
// an android_app module.
func AndroidLibraryFactory() android.Module {
@@ -619,6 +633,10 @@
Libs []string
// If set to true, run Jetifier against .aar file. Defaults to false.
Jetifier *bool
+ // If true, extract JNI libs from AAR archive. These libs will be accessible to android_app modules and
+ // will be passed transitively through android_libraries to an android_app.
+ //TODO(b/241138093) evaluate whether we can have this flag default to true for Bazel conversion
+ Extract_jni *bool
}
type AARImport struct {
@@ -643,7 +661,8 @@
hideApexVariantFromMake bool
- aarPath android.Path
+ aarPath android.Path
+ jniPackages android.Paths
sdkVersion android.SdkSpec
minSdkVersion android.SdkSpec
@@ -751,6 +770,28 @@
ctx.AddVariationDependencies(nil, staticLibTag, a.properties.Static_libs...)
}
+type JniPackageInfo struct {
+ // List of zip files containing JNI libraries
+ // Zip files should have directory structure jni/<arch>/*.so
+ JniPackages android.Paths
+}
+
+var JniPackageProvider = blueprint.NewProvider(JniPackageInfo{})
+
+// Unzip an AAR and extract the JNI libs for $archString.
+var extractJNI = pctx.AndroidStaticRule("extractJNI",
+ blueprint.RuleParams{
+ Command: `rm -rf $out $outDir && touch $out && ` +
+ `unzip -qoDD -d $outDir $in "jni/${archString}/*" && ` +
+ `jni_files=$$(find $outDir/jni -type f) && ` +
+ // print error message if there are no JNI libs for this arch
+ `[ -n "$$jni_files" ] || (echo "ERROR: no JNI libs found for arch ${archString}" && exit 1) && ` +
+ `${config.SoongZipCmd} -o $out -P 'lib/${archString}' ` +
+ `-C $outDir/jni/${archString} $$(echo $$jni_files | xargs -n1 printf " -f %s")`,
+ CommandDeps: []string{"${config.SoongZipCmd}"},
+ },
+ "outDir", "archString")
+
// Unzip an AAR into its constituent files and directories. Any files in Outputs that don't exist in the AAR will be
// touched to create an empty file. The res directory is not extracted, as it will be extracted in its own rule.
var unzipAAR = pctx.AndroidStaticRule("unzipAAR",
@@ -858,6 +899,31 @@
ImplementationAndResourcesJars: android.PathsIfNonNil(a.classpathFile),
ImplementationJars: android.PathsIfNonNil(a.classpathFile),
})
+
+ if proptools.Bool(a.properties.Extract_jni) {
+ for _, t := range ctx.MultiTargets() {
+ arch := t.Arch.Abi[0]
+ path := android.PathForModuleOut(ctx, arch+"_jni.zip")
+ a.jniPackages = append(a.jniPackages, path)
+
+ outDir := android.PathForModuleOut(ctx, "aarForJni")
+ aarPath := android.PathForModuleSrc(ctx, a.properties.Aars[0])
+ ctx.Build(pctx, android.BuildParams{
+ Rule: extractJNI,
+ Input: aarPath,
+ Outputs: android.WritablePaths{path},
+ Description: "extract JNI from AAR",
+ Args: map[string]string{
+ "outDir": outDir.String(),
+ "archString": arch,
+ },
+ })
+ }
+
+ ctx.SetProvider(JniPackageProvider, JniPackageInfo{
+ JniPackages: a.jniPackages,
+ })
+ }
}
func (a *AARImport) HeaderJars() android.Paths {
@@ -906,6 +972,6 @@
android.InitPrebuiltModule(module, &module.properties.Aars)
android.InitApexModule(module)
- InitJavaModule(module, android.DeviceSupported)
+ InitJavaModuleMultiTargets(module, android.DeviceSupported)
return module
}
diff --git a/java/aar_test.go b/java/aar_test.go
new file mode 100644
index 0000000..8afa039
--- /dev/null
+++ b/java/aar_test.go
@@ -0,0 +1,83 @@
+// Copyright 2022 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package java
+
+import (
+ "android/soong/android"
+ "testing"
+)
+
+func TestAarImportProducesJniPackages(t *testing.T) {
+ ctx := android.GroupFixturePreparers(
+ PrepareForTestWithJavaDefaultModules,
+ ).RunTestWithBp(t, `
+ android_library_import {
+ name: "aar-no-jni",
+ aars: ["aary.aar"],
+ }
+ android_library_import {
+ name: "aar-jni",
+ aars: ["aary.aar"],
+ extract_jni: true,
+ }`)
+
+ testCases := []struct {
+ name string
+ hasPackage bool
+ }{
+ {
+ name: "aar-no-jni",
+ hasPackage: false,
+ },
+ {
+ name: "aar-jni",
+ hasPackage: true,
+ },
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ appMod := ctx.Module(tc.name, "android_common")
+ appTestMod := ctx.ModuleForTests(tc.name, "android_common")
+
+ info, ok := ctx.ModuleProvider(appMod, JniPackageProvider).(JniPackageInfo)
+ if !ok {
+ t.Errorf("expected android_library_import to have JniPackageProvider")
+ }
+
+ if !tc.hasPackage {
+ if len(info.JniPackages) != 0 {
+ t.Errorf("expected JniPackages to be empty, but got %v", info.JniPackages)
+ }
+ outputFile := "arm64-v8a_jni.zip"
+ jniOutputLibZip := appTestMod.MaybeOutput(outputFile)
+ if jniOutputLibZip.Rule != nil {
+ t.Errorf("did not expect an output file, but found %v", outputFile)
+ }
+ return
+ }
+
+ if len(info.JniPackages) != 1 {
+ t.Errorf("expected a single JniPackage, but got %v", info.JniPackages)
+ }
+
+ outputFile := info.JniPackages[0].String()
+ jniOutputLibZip := appTestMod.Output(outputFile)
+ if jniOutputLibZip.Rule == nil {
+ t.Errorf("did not find output file %v", outputFile)
+ }
+ })
+ }
+}
diff --git a/java/android_manifest.go b/java/android_manifest.go
index c61823d..83cb171 100644
--- a/java/android_manifest.go
+++ b/java/android_manifest.go
@@ -56,15 +56,16 @@
}
type ManifestFixerParams struct {
- SdkContext android.SdkContext
- ClassLoaderContexts dexpreopt.ClassLoaderContextMap
- IsLibrary bool
- UseEmbeddedNativeLibs bool
- UsesNonSdkApis bool
- UseEmbeddedDex bool
- HasNoCode bool
- TestOnly bool
- LoggingParent string
+ SdkContext android.SdkContext
+ ClassLoaderContexts dexpreopt.ClassLoaderContextMap
+ IsLibrary bool
+ DefaultManifestVersion string
+ UseEmbeddedNativeLibs bool
+ UsesNonSdkApis bool
+ UseEmbeddedDex bool
+ HasNoCode bool
+ TestOnly bool
+ LoggingParent string
}
// Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml
@@ -153,6 +154,9 @@
args = append(args, "--replaceMaxSdkVersionPlaceholder ", strconv.Itoa(replaceMaxSdkVersionPlaceholder.FinalOrFutureInt()))
args = append(args, "--raise-min-sdk-version")
}
+ if params.DefaultManifestVersion != "" {
+ args = append(args, "--override-placeholder-version", params.DefaultManifestVersion)
+ }
fixedManifest := android.PathForModuleOut(ctx, "manifest_fixer", "AndroidManifest.xml")
argsMapper["args"] = strings.Join(args, " ")
diff --git a/java/app.go b/java/app.go
index 23a9816..5185959 100755
--- a/java/app.go
+++ b/java/app.go
@@ -417,6 +417,9 @@
a.aapt.splitNames = a.appProperties.Package_splits
a.aapt.LoggingParent = String(a.overridableAppProperties.Logging_parent)
+ if a.Updatable() {
+ a.aapt.defaultManifestVersion = android.DefaultUpdatableModuleVersion
+ }
a.aapt.buildActions(ctx, android.SdkContext(a), a.classLoaderContexts,
a.usesLibraryProperties.Exclude_uses_libs, aaptLinkFlags...)
@@ -472,14 +475,14 @@
return a.dexJarFile.PathOrNil()
}
-func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, ctx android.ModuleContext) android.WritablePath {
+func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, prebuiltJniPackages android.Paths, ctx android.ModuleContext) android.WritablePath {
var jniJarFile android.WritablePath
- if len(jniLibs) > 0 {
+ if len(jniLibs) > 0 || len(prebuiltJniPackages) > 0 {
a.jniLibs = jniLibs
if a.shouldEmbedJnis(ctx) {
jniJarFile = android.PathForModuleOut(ctx, "jnilibs.zip")
a.installPathForJNISymbols = a.installPath(ctx)
- TransformJniLibsToJar(ctx, jniJarFile, jniLibs, a.useEmbeddedNativeLibs(ctx))
+ TransformJniLibsToJar(ctx, jniJarFile, jniLibs, prebuiltJniPackages, a.useEmbeddedNativeLibs(ctx))
for _, jni := range jniLibs {
if jni.coverageFile.Valid() {
// Only collect coverage for the first target arch if this is a multilib target.
@@ -623,8 +626,8 @@
dexJarFile := a.dexBuildActions(ctx)
- jniLibs, certificateDeps := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis))
- jniJarFile := a.jniBuildActions(jniLibs, ctx)
+ jniLibs, prebuiltJniPackages, certificateDeps := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis))
+ jniJarFile := a.jniBuildActions(jniLibs, prebuiltJniPackages, ctx)
if ctx.Failed() {
return
@@ -724,9 +727,10 @@
func collectAppDeps(ctx android.ModuleContext, app appDepsInterface,
shouldCollectRecursiveNativeDeps bool,
- checkNativeSdkVersion bool) ([]jniLib, []Certificate) {
+ checkNativeSdkVersion bool) ([]jniLib, android.Paths, []Certificate) {
var jniLibs []jniLib
+ var prebuiltJniPackages android.Paths
var certificates []Certificate
seenModulePaths := make(map[string]bool)
@@ -775,6 +779,10 @@
return shouldCollectRecursiveNativeDeps
}
+ if info, ok := ctx.OtherModuleProvider(module, JniPackageProvider).(JniPackageInfo); ok {
+ prebuiltJniPackages = append(prebuiltJniPackages, info.JniPackages...)
+ }
+
if tag == certificateTag {
if dep, ok := module.(*AndroidAppCertificate); ok {
certificates = append(certificates, dep.Certificate)
@@ -786,7 +794,7 @@
return false
})
- return jniLibs, certificates
+ return jniLibs, prebuiltJniPackages, certificates
}
func (a *AndroidApp) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
diff --git a/java/app_builder.go b/java/app_builder.go
index 4a18dca..4348644 100644
--- a/java/app_builder.go
+++ b/java/app_builder.go
@@ -218,8 +218,14 @@
})
}
-func TransformJniLibsToJar(ctx android.ModuleContext, outputFile android.WritablePath,
- jniLibs []jniLib, uncompressJNI bool) {
+const jniJarOutputPathString = "jniJarOutput.zip"
+
+func TransformJniLibsToJar(
+ ctx android.ModuleContext,
+ outputFile android.WritablePath,
+ jniLibs []jniLib,
+ prebuiltJniPackages android.Paths,
+ uncompressJNI bool) {
var deps android.Paths
jarArgs := []string{
@@ -245,13 +251,20 @@
rule = zipRE
args["implicits"] = strings.Join(deps.Strings(), ",")
}
+ jniJarPath := android.PathForModuleOut(ctx, jniJarOutputPathString)
ctx.Build(pctx, android.BuildParams{
Rule: rule,
Description: "zip jni libs",
- Output: outputFile,
+ Output: jniJarPath,
Implicits: deps,
Args: args,
})
+ ctx.Build(pctx, android.BuildParams{
+ Rule: mergeAssetsRule,
+ Description: "merge prebuilt JNI packages",
+ Inputs: append(prebuiltJniPackages, jniJarPath),
+ Output: outputFile,
+ })
}
func targetToJniDir(target android.Target) string {
diff --git a/java/app_import.go b/java/app_import.go
index b017eca..9d199d6 100644
--- a/java/app_import.go
+++ b/java/app_import.go
@@ -256,7 +256,7 @@
ctx.ModuleErrorf("One and only one of certficate, presigned, and default_dev_cert properties must be set")
}
- _, certificates := collectAppDeps(ctx, a, false, false)
+ _, _, certificates := collectAppDeps(ctx, a, false, false)
// TODO: LOCAL_EXTRACT_APK/LOCAL_EXTRACT_DPI_APK
// TODO: LOCAL_PACKAGE_SPLITS
diff --git a/java/app_test.go b/java/app_test.go
index c4ac4df..bb44803 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -1218,7 +1218,7 @@
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
app := ctx.ModuleForTests(test.name, "android_common")
- jniLibZip := app.Output("jnilibs.zip")
+ jniLibZip := app.Output(jniJarOutputPathString)
var abis []string
args := strings.Fields(jniLibZip.Args["jarArgs"])
for i := 0; i < len(args); i++ {
@@ -1351,7 +1351,7 @@
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
app := ctx.ModuleForTests(test.name, "android_common")
- jniLibZip := app.MaybeOutput("jnilibs.zip")
+ jniLibZip := app.MaybeOutput(jniJarOutputPathString)
if g, w := (jniLibZip.Rule != nil), test.packaged; g != w {
t.Errorf("expected jni packaged %v, got %v", w, g)
}
@@ -1442,7 +1442,7 @@
t.Run(test.name, func(t *testing.T) {
app := ctx.ModuleForTests(test.name, "android_common")
- jniLibZip := app.MaybeOutput("jnilibs.zip")
+ jniLibZip := app.MaybeOutput(jniJarOutputPathString)
if len(jniLibZip.Implicits) != 1 {
t.Fatalf("expected exactly one jni library, got %q", jniLibZip.Implicits.Strings())
}
@@ -2425,7 +2425,7 @@
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
app := ctx.ModuleForTests(test.name, "android_common")
- jniLibZip := app.Output("jnilibs.zip")
+ jniLibZip := app.Output(jniJarOutputPathString)
var jnis []string
args := strings.Fields(jniLibZip.Args["jarArgs"])
for i := 0; i < len(args); i++ {
@@ -3074,3 +3074,89 @@
}
android.AssertStringDoesContain(t, "expected error rule message", fooApk.Args["error"], "missing dependencies: missing_certificate\n")
}
+
+func TestAppIncludesJniPackages(t *testing.T) {
+ ctx := android.GroupFixturePreparers(
+ PrepareForTestWithJavaDefaultModules,
+ ).RunTestWithBp(t, `
+ android_library_import {
+ name: "aary-nodeps",
+ aars: ["aary.aar"],
+ extract_jni: true,
+ }
+
+ android_library {
+ name: "aary-lib",
+ sdk_version: "current",
+ min_sdk_version: "21",
+ static_libs: ["aary-nodeps"],
+ }
+
+ android_app {
+ name: "aary-lib-dep",
+ sdk_version: "current",
+ min_sdk_version: "21",
+ manifest: "AndroidManifest.xml",
+ static_libs: ["aary-lib"],
+ use_embedded_native_libs: true,
+ }
+
+ android_app {
+ name: "aary-import-dep",
+ sdk_version: "current",
+ min_sdk_version: "21",
+ manifest: "AndroidManifest.xml",
+ static_libs: ["aary-nodeps"],
+ use_embedded_native_libs: true,
+ }
+
+ android_app {
+ name: "aary-no-use-embedded",
+ sdk_version: "current",
+ min_sdk_version: "21",
+ manifest: "AndroidManifest.xml",
+ static_libs: ["aary-nodeps"],
+ }`)
+
+ testCases := []struct {
+ name string
+ hasPackage bool
+ }{
+ {
+ name: "aary-import-dep",
+ hasPackage: true,
+ },
+ {
+ name: "aary-lib-dep",
+ hasPackage: true,
+ },
+ {
+ name: "aary-no-use-embedded",
+ hasPackage: false,
+ },
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ app := ctx.ModuleForTests(tc.name, "android_common")
+
+ outputFile := "jnilibs.zip"
+ jniOutputLibZip := app.MaybeOutput(outputFile)
+ if jniOutputLibZip.Rule == nil && !tc.hasPackage {
+ return
+ }
+
+ jniPackage := "arm64-v8a_jni.zip"
+ inputs := jniOutputLibZip.Inputs
+ foundPackage := false
+ for i := 0; i < len(inputs); i++ {
+ if strings.Contains(inputs[i].String(), jniPackage) {
+ foundPackage = true
+ }
+ }
+ if foundPackage != tc.hasPackage {
+ t.Errorf("expected to find %v in %v inputs; inputs = %v", jniPackage, outputFile, inputs)
+ }
+ })
+ }
+}
diff --git a/java/java.go b/java/java.go
index dae69dc..f4ec04e 100644
--- a/java/java.go
+++ b/java/java.go
@@ -24,6 +24,7 @@
"strings"
"android/soong/bazel"
+ "android/soong/bazel/cquery"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -1610,7 +1611,8 @@
}
}
-func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+func (j *Import) commonBuildActions(ctx android.ModuleContext) {
+ //TODO(b/231322772) these should come from Bazel once available
j.sdkVersion = j.SdkVersion(ctx)
j.minSdkVersion = j.MinSdkVersion(ctx)
@@ -1621,6 +1623,10 @@
if ctx.Windows() {
j.HideFromMake()
}
+}
+
+func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ j.commonBuildActions(ctx)
jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
@@ -1662,19 +1668,7 @@
addCLCFromDep(ctx, module, j.classLoaderContexts)
})
- if Bool(j.properties.Installable) {
- var installDir android.InstallPath
- if ctx.InstallInTestcases() {
- var archDir string
- if !ctx.Host() {
- archDir = ctx.DeviceConfig().DeviceArch()
- }
- installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir)
- } else {
- installDir = android.PathForModuleInstall(ctx, "framework")
- }
- ctx.InstallFile(installDir, jarName, outputFile)
- }
+ j.maybeInstall(ctx, jarName, outputFile)
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs)
@@ -1748,6 +1742,24 @@
})
}
+func (j *Import) maybeInstall(ctx android.ModuleContext, jarName string, outputFile android.Path) {
+ if !Bool(j.properties.Installable) {
+ return
+ }
+
+ var installDir android.InstallPath
+ if ctx.InstallInTestcases() {
+ var archDir string
+ if !ctx.Host() {
+ archDir = ctx.DeviceConfig().DeviceArch()
+ }
+ installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir)
+ } else {
+ installDir = android.PathForModuleInstall(ctx, "framework")
+ }
+ ctx.InstallFile(installDir, jarName, outputFile)
+}
+
func (j *Import) OutputFiles(tag string) (android.Paths, error) {
switch tag {
case "", ".jar":
@@ -2046,9 +2058,7 @@
return module
}
-//
// Defaults
-//
type Defaults struct {
android.ModuleBase
android.DefaultsModuleBase
@@ -2063,29 +2073,29 @@
//
// Example:
//
-// java_defaults {
-// name: "example_defaults",
-// srcs: ["common/**/*.java"],
-// javacflags: ["-Xlint:all"],
-// aaptflags: ["--auto-add-overlay"],
-// }
+// java_defaults {
+// name: "example_defaults",
+// srcs: ["common/**/*.java"],
+// javacflags: ["-Xlint:all"],
+// aaptflags: ["--auto-add-overlay"],
+// }
//
-// java_library {
-// name: "example",
-// defaults: ["example_defaults"],
-// srcs: ["example/**/*.java"],
-// }
+// java_library {
+// name: "example",
+// defaults: ["example_defaults"],
+// srcs: ["example/**/*.java"],
+// }
//
// is functionally identical to:
//
-// java_library {
-// name: "example",
-// srcs: [
-// "common/**/*.java",
-// "example/**/*.java",
-// ],
-// javacflags: ["-Xlint:all"],
-// }
+// java_library {
+// name: "example",
+// srcs: [
+// "common/**/*.java",
+// "example/**/*.java",
+// ],
+// javacflags: ["-Xlint:all"],
+// }
func DefaultsFactory() android.Module {
module := &Defaults{}
@@ -2483,5 +2493,54 @@
props := bazel.BazelTargetModuleProperties{Rule_class: "java_import"}
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: android.RemoveOptionalPrebuiltPrefix(i.Name())}, attrs)
+}
+var _ android.MixedBuildBuildable = (*Import)(nil)
+
+func (i *Import) getBazelModuleLabel(ctx android.BaseModuleContext) string {
+ return android.RemoveOptionalPrebuiltPrefixFromBazelLabel(i.GetBazelLabel(ctx, i))
+}
+
+func (i *Import) ProcessBazelQueryResponse(ctx android.ModuleContext) {
+ i.commonBuildActions(ctx)
+
+ bazelCtx := ctx.Config().BazelContext
+ filePaths, err := bazelCtx.GetOutputFiles(i.getBazelModuleLabel(ctx), android.GetConfigKey(ctx))
+ if err != nil {
+ ctx.ModuleErrorf(err.Error())
+ return
+ }
+
+ bazelJars := android.Paths{}
+ for _, bazelOutputFile := range filePaths {
+ bazelJars = append(bazelJars, android.PathForBazelOut(ctx, bazelOutputFile))
+ }
+
+ jarName := android.RemoveOptionalPrebuiltPrefix(i.Name()) + ".jar"
+ outputFile := android.PathForModuleOut(ctx, "bazelCombined", jarName)
+ TransformJarsToJar(ctx, outputFile, "combine prebuilt jars", bazelJars,
+ android.OptionalPath{}, // manifest
+ false, // stripDirEntries
+ []string{}, // filesToStrip
+ []string{}, // dirsToStrip
+ )
+ i.combinedClasspathFile = outputFile
+
+ ctx.SetProvider(JavaInfoProvider, JavaInfo{
+ HeaderJars: android.PathsIfNonNil(i.combinedClasspathFile),
+ ImplementationAndResourcesJars: android.PathsIfNonNil(i.combinedClasspathFile),
+ ImplementationJars: android.PathsIfNonNil(i.combinedClasspathFile),
+ //TODO(b/240308299) include AIDL information from Bazel
+ })
+
+ i.maybeInstall(ctx, jarName, outputFile)
+}
+
+func (i *Import) QueueBazelCall(ctx android.BaseModuleContext) {
+ bazelCtx := ctx.Config().BazelContext
+ bazelCtx.QueueBazelRequest(i.getBazelModuleLabel(ctx), cquery.GetOutputFiles, android.GetConfigKey(ctx))
+}
+
+func (i *Import) IsMixedBuildSupported(ctx android.BaseModuleContext) bool {
+ return true
}
diff --git a/java/java_test.go b/java/java_test.go
index 32b0b0f..9e5cf0c 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -1667,3 +1667,48 @@
})
}
}
+
+func TestImportMixedBuild(t *testing.T) {
+ bp := `
+ java_import {
+ name: "baz",
+ jars: [
+ "test1.jar",
+ "test2.jar",
+ ],
+ bazel_module: { label: "//foo/bar:baz" },
+ }
+ `
+
+ ctx := android.GroupFixturePreparers(
+ prepareForJavaTest,
+ android.FixtureModifyConfig(func(config android.Config) {
+ config.BazelContext = android.MockBazelContext{
+ OutputBaseDir: "outputbase",
+ LabelToOutputFiles: map[string][]string{
+ "//foo/bar:baz": []string{"test1.jar", "test2.jar"},
+ },
+ }
+ }),
+ ).RunTestWithBp(t, bp)
+
+ bazMod := ctx.ModuleForTests("baz", "android_common").Module()
+ producer := bazMod.(android.OutputFileProducer)
+ expectedOutputFiles := []string{".intermediates/baz/android_common/bazelCombined/baz.jar"}
+
+ outputFiles, err := producer.OutputFiles("")
+ if err != nil {
+ t.Errorf("Unexpected error getting java_import outputfiles %s", err)
+ }
+ actualOutputFiles := android.NormalizePathsForTesting(outputFiles)
+ android.AssertDeepEquals(t, "Output files are produced", expectedOutputFiles, actualOutputFiles)
+
+ javaInfoProvider := ctx.ModuleProvider(bazMod, JavaInfoProvider)
+ javaInfo, ok := javaInfoProvider.(JavaInfo)
+ if !ok {
+ t.Error("could not get JavaInfo from java_import module")
+ }
+ android.AssertDeepEquals(t, "Header JARs are produced", expectedOutputFiles, android.NormalizePathsForTesting(javaInfo.HeaderJars))
+ android.AssertDeepEquals(t, "Implementation/Resources JARs are produced", expectedOutputFiles, android.NormalizePathsForTesting(javaInfo.ImplementationAndResourcesJars))
+ android.AssertDeepEquals(t, "Implementation JARs are produced", expectedOutputFiles, android.NormalizePathsForTesting(javaInfo.ImplementationJars))
+}
diff --git a/java/rro.go b/java/rro.go
index 7952c2c..9c8c53b 100644
--- a/java/rro.go
+++ b/java/rro.go
@@ -142,7 +142,7 @@
r.aapt.buildActions(ctx, r, nil, nil, aaptLinkFlags...)
// Sign the built package
- _, certificates := collectAppDeps(ctx, r, false, false)
+ _, _, certificates := collectAppDeps(ctx, r, false, false)
certificates = processMainCert(r.ModuleBase, String(r.properties.Certificate), certificates, ctx)
signed := android.PathForModuleOut(ctx, "signed", r.Name()+".apk")
var lineageFile android.Path
diff --git a/licenses/Android.bp b/licenses/Android.bp
index 8db001f..133f7f7 100644
--- a/licenses/Android.bp
+++ b/licenses/Android.bp
@@ -32,6 +32,15 @@
}
license_kind {
+ name: "BSD-Like-Binary-Only",
+ conditions: [
+ "notice",
+ "by_exception_only",
+ "proprietary",
+ ],
+}
+
+license_kind {
name: "SPDX-license-identifier-0BSD",
conditions: ["unencumbered"],
url: "https://spdx.org/licenses/0BSD",
diff --git a/scripts/manifest_fixer.py b/scripts/manifest_fixer.py
index 2da29ee..58079aa 100755
--- a/scripts/manifest_fixer.py
+++ b/scripts/manifest_fixer.py
@@ -70,6 +70,8 @@
parser.add_argument('--test-only', dest='test_only', action='store_true',
help=('adds testOnly="true" attribute to application. Assign true value if application elem '
'already has a testOnly attribute.'))
+ parser.add_argument('--override-placeholder-version', dest='new_version',
+ help='Overrides the versionCode if it\'s set to the placeholder value of 0')
parser.add_argument('input', help='input AndroidManifest.xml file')
parser.add_argument('output', help='output AndroidManifest.xml file')
return parser.parse_args()
@@ -362,6 +364,19 @@
if max_attr and max_attr.value == 'current':
max_attr.value = max_sdk_version
+def override_placeholder_version(doc, new_version):
+ """Replace the versionCode attribute value if it\'s currently
+ set to the placeholder version of 0.
+
+ Args:
+ doc: The XML document. May be modified by this function.
+ new_version: The new version to set if versionCode is equal to 0.
+ """
+ manifest = parse_manifest(doc)
+ version = manifest.getAttribute("android:versionCode")
+ if (version == '0'):
+ manifest.setAttribute("android:versionCode", new_version)
+
def main():
"""Program entry point."""
try:
@@ -401,6 +416,9 @@
if args.extract_native_libs is not None:
add_extract_native_libs(doc, args.extract_native_libs)
+ if args.new_version:
+ override_placeholder_version(doc, args.new_version)
+
with open(args.output, 'w') as f:
write_xml(f, doc)
diff --git a/scripts/manifest_fixer_test.py b/scripts/manifest_fixer_test.py
index dad104a..0a62b10 100755
--- a/scripts/manifest_fixer_test.py
+++ b/scripts/manifest_fixer_test.py
@@ -643,5 +643,39 @@
output = self.run_test(manifest_input, '9000')
self.assert_xml_equal(output, expected)
+class OverrideDefaultVersionTest(unittest.TestCase):
+ """Unit tests for override_default_version function."""
+
+ def assert_xml_equal(self, output, expected):
+ self.assertEqual(ET.canonicalize(output), ET.canonicalize(expected))
+
+ def run_test(self, input_manifest, version):
+ doc = minidom.parseString(input_manifest)
+ manifest_fixer.override_placeholder_version(doc, version)
+ output = io.StringIO()
+ manifest_fixer.write_xml(output, doc)
+ return output.getvalue()
+
+ manifest_tmpl = (
+ '<?xml version="1.0" encoding="utf-8"?>\n'
+ '<manifest xmlns:android="http://schemas.android.com/apk/res/android" '
+ 'android:versionCode="%s">\n'
+ '</manifest>\n')
+
+ def test_doesnt_override_existing_version(self):
+ """Tests that an existing version is not overridden"""
+ manifest_input = self.manifest_tmpl % '12345'
+ expected = manifest_input
+ output = self.run_test(manifest_input, '67890')
+ self.assert_xml_equal(output, expected)
+
+ def test_overrides_default_version(self):
+ """Tests that a default version is overridden"""
+ manifest_input = self.manifest_tmpl % '0'
+ expected = self.manifest_tmpl % '67890'
+ output = self.run_test(manifest_input, '67890')
+ self.assert_xml_equal(output, expected)
+
+
if __name__ == '__main__':
unittest.main(verbosity=2)
diff --git a/ui/build/build.go b/ui/build/build.go
index ec42b70..5b80b4d 100644
--- a/ui/build/build.go
+++ b/ui/build/build.go
@@ -183,8 +183,8 @@
}
}
-// Build the tree. The 'what' argument can be used to chose which components of
-// the build to run, via checking various bitmasks.
+// Build the tree. Various flags in `config` govern which components of
+// the build to run.
func Build(ctx Context, config Config) {
ctx.Verboseln("Starting build with args:", config.Arguments())
ctx.Verboseln("Environment:", config.Environment().Environ())
diff --git a/ui/build/soong.go b/ui/build/soong.go
index 8992b4f..cfcf990 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -544,7 +544,7 @@
buf, err := os.ReadFile(soongBuildMetricsFile)
if errors.Is(err, fs.ErrNotExist) {
// Soong may not have run during this invocation
- ctx.Verbosef("Failed to read metrics file, %s: %s", soongBuildMetricsFile, err)
+ ctx.Verbosef("Failed to read metrics file, %s: %s", soongBuildMetricsFile, err)
return nil
} else if err != nil {
ctx.Fatalf("Failed to load %s: %s", soongBuildMetricsFile, err)