Merge "java_test macro needs srcs and deps to create .jar for tradefed_test_suite" into main
diff --git a/aconfig/Android.bp b/aconfig/Android.bp
index ae8276f..6927765 100644
--- a/aconfig/Android.bp
+++ b/aconfig/Android.bp
@@ -20,6 +20,7 @@
"aconfig_values.go",
"aconfig_value_set.go",
"all_aconfig_declarations.go",
+ "cc_aconfig_library.go",
"init.go",
"java_aconfig_library.go",
"testing.go",
@@ -28,6 +29,7 @@
"aconfig_declarations_test.go",
"aconfig_values_test.go",
"aconfig_value_set_test.go",
+ "java_aconfig_library_test.go",
],
pluginFor: ["soong_build"],
}
diff --git a/aconfig/aconfig_declarations.go b/aconfig/aconfig_declarations.go
index 007d529..565d185 100644
--- a/aconfig/aconfig_declarations.go
+++ b/aconfig/aconfig_declarations.go
@@ -125,12 +125,12 @@
intermediatePath := android.PathForModuleOut(ctx, "intermediate.pb")
ctx.Build(pctx, android.BuildParams{
Rule: aconfigRule,
- Inputs: inputFiles,
Output: intermediatePath,
Description: "aconfig_declarations",
Args: map[string]string{
"release_version": ctx.Config().ReleaseVersion(),
"package": module.properties.Package,
+ "declarations": android.JoinPathsWithPrefix(inputFiles, "--declarations "),
"values": joinAndPrefix(" --values ", module.properties.Values),
},
})
diff --git a/aconfig/aconfig_declarations_test.go b/aconfig/aconfig_declarations_test.go
index e14ca38..e0d8f7d 100644
--- a/aconfig/aconfig_declarations_test.go
+++ b/aconfig/aconfig_declarations_test.go
@@ -26,7 +26,10 @@
aconfig_declarations {
name: "module_name",
package: "com.example.package",
- srcs: ["foo.aconfig"],
+ srcs: [
+ "foo.aconfig",
+ "bar.aconfig",
+ ],
}
`
result := runTest(t, android.FixtureExpectsNoErrors, bp)
diff --git a/aconfig/cc_aconfig_library.go b/aconfig/cc_aconfig_library.go
new file mode 100644
index 0000000..14090bc
--- /dev/null
+++ b/aconfig/cc_aconfig_library.go
@@ -0,0 +1,128 @@
+// Copyright 2023 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 aconfig
+
+import (
+ "android/soong/android"
+ "android/soong/cc"
+ "github.com/google/blueprint"
+
+ "fmt"
+ "strings"
+)
+
+type ccDeclarationsTagType struct {
+ blueprint.BaseDependencyTag
+}
+
+var ccDeclarationsTag = ccDeclarationsTagType{}
+
+type CcAconfigLibraryProperties struct {
+ // name of the aconfig_declarations module to generate a library for
+ Aconfig_declarations string
+}
+
+type CcAconfigLibraryCallbacks struct {
+ properties *CcAconfigLibraryProperties
+
+ generatedDir android.WritablePath
+ headerDir android.WritablePath
+ generatedCpp android.WritablePath
+ generatedH android.WritablePath
+}
+
+func CcAconfigLibraryFactory() android.Module {
+ callbacks := &CcAconfigLibraryCallbacks{
+ properties: &CcAconfigLibraryProperties{},
+ }
+ return cc.GeneratedCcLibraryModuleFactory("cc_aconfig_library", callbacks)
+}
+
+func (this *CcAconfigLibraryCallbacks) GeneratorInit(ctx cc.BaseModuleContext) {
+}
+
+func (this *CcAconfigLibraryCallbacks) GeneratorProps() []interface{} {
+ return []interface{}{this.properties}
+}
+
+func (this *CcAconfigLibraryCallbacks) GeneratorDeps(ctx cc.DepsContext, deps cc.Deps) cc.Deps {
+ // Add a dependency for the declarations module
+ declarations := this.properties.Aconfig_declarations
+ if len(declarations) == 0 {
+ ctx.PropertyErrorf("aconfig_declarations", "aconfig_declarations property required")
+ } else {
+ ctx.AddDependency(ctx.Module(), ccDeclarationsTag, declarations)
+ }
+
+ // Add a dependency for the aconfig flags base library
+ deps.SharedLibs = append(deps.SharedLibs, "server_configurable_flags")
+ // TODO: It'd be really nice if we could reexport this library and not make everyone do it.
+
+ return deps
+}
+
+func (this *CcAconfigLibraryCallbacks) GeneratorSources(ctx cc.ModuleContext) cc.GeneratedSource {
+ result := cc.GeneratedSource{}
+
+ // Get the values that came from the global RELEASE_ACONFIG_VALUE_SETS flag
+ declarationsModules := ctx.GetDirectDepsWithTag(ccDeclarationsTag)
+ if len(declarationsModules) != 1 {
+ panic(fmt.Errorf("Exactly one aconfig_declarations property required"))
+ }
+ declarations := ctx.OtherModuleProvider(declarationsModules[0], declarationsProviderKey).(declarationsProviderData)
+
+ // Figure out the generated file paths. This has to match aconfig's codegen_cpp.rs.
+ this.generatedDir = android.PathForModuleGen(ctx)
+
+ this.headerDir = android.PathForModuleGen(ctx, "include")
+ result.IncludeDirs = []android.Path{this.headerDir}
+ result.ReexportedDirs = []android.Path{this.headerDir}
+
+ basename := strings.ReplaceAll(declarations.Package, ".", "_")
+
+ this.generatedCpp = android.PathForModuleGen(ctx, basename+".cc")
+ result.Sources = []android.Path{this.generatedCpp}
+
+ this.generatedH = android.PathForModuleGen(ctx, "include", basename+".h")
+ result.Headers = []android.Path{this.generatedH}
+
+ return result
+}
+
+func (this *CcAconfigLibraryCallbacks) GeneratorFlags(ctx cc.ModuleContext, flags cc.Flags, deps cc.PathDeps) cc.Flags {
+ return flags
+}
+
+func (this *CcAconfigLibraryCallbacks) GeneratorBuildActions(ctx cc.ModuleContext, flags cc.Flags, deps cc.PathDeps) {
+ // Get the values that came from the global RELEASE_ACONFIG_VALUE_SETS flag
+ declarationsModules := ctx.GetDirectDepsWithTag(ccDeclarationsTag)
+ if len(declarationsModules) != 1 {
+ panic(fmt.Errorf("Exactly one aconfig_declarations property required"))
+ }
+ declarations := ctx.OtherModuleProvider(declarationsModules[0], declarationsProviderKey).(declarationsProviderData)
+
+ ctx.Build(pctx, android.BuildParams{
+ Rule: cppRule,
+ Input: declarations.IntermediatePath,
+ Outputs: []android.WritablePath{
+ this.generatedCpp,
+ this.generatedH,
+ },
+ Description: "cc_aconfig_library",
+ Args: map[string]string{
+ "gendir": this.generatedDir.String(),
+ },
+ })
+}
diff --git a/aconfig/init.go b/aconfig/init.go
index 161fd42..3ed5faf 100644
--- a/aconfig/init.go
+++ b/aconfig/init.go
@@ -27,7 +27,7 @@
blueprint.RuleParams{
Command: `${aconfig} create-cache` +
` --package ${package}` +
- ` --declarations ${in}` +
+ ` ${declarations}` +
` ${values}` +
` --cache ${out}.tmp` +
` && ( if cmp -s ${out}.tmp ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
@@ -36,10 +36,10 @@
"${aconfig}",
},
Restat: true,
- }, "release_version", "package", "values")
+ }, "release_version", "package", "declarations", "values")
// For java_aconfig_library: Generate java file
- srcJarRule = pctx.AndroidStaticRule("aconfig_srcjar",
+ javaRule = pctx.AndroidStaticRule("java_aconfig_library",
blueprint.RuleParams{
Command: `rm -rf ${out}.tmp` +
` && mkdir -p ${out}.tmp` +
@@ -55,6 +55,20 @@
Restat: true,
})
+ // For java_aconfig_library: Generate java file
+ cppRule = pctx.AndroidStaticRule("cc_aconfig_library",
+ blueprint.RuleParams{
+ Command: `rm -rf ${gendir}` +
+ ` && mkdir -p ${gendir}` +
+ ` && ${aconfig} create-cpp-lib` +
+ ` --cache ${in}` +
+ ` --out ${gendir}`,
+ CommandDeps: []string{
+ "$aconfig",
+ "$soong_zip",
+ },
+ }, "gendir")
+
// For all_aconfig_declarations
allDeclarationsRule = pctx.AndroidStaticRule("all_aconfig_declarations_dump",
blueprint.RuleParams{
@@ -75,6 +89,7 @@
ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory)
ctx.RegisterModuleType("aconfig_values", ValuesFactory)
ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
+ ctx.RegisterModuleType("cc_aconfig_library", CcAconfigLibraryFactory)
ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory)
ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory)
}
diff --git a/aconfig/java_aconfig_library.go b/aconfig/java_aconfig_library.go
index 0eeb14f..53b2b10 100644
--- a/aconfig/java_aconfig_library.go
+++ b/aconfig/java_aconfig_library.go
@@ -51,7 +51,7 @@
}
}
-func (callbacks *JavaAconfigDeclarationsLibraryCallbacks) GenerateSourceJarBuildActions(ctx android.ModuleContext) android.Path {
+func (callbacks *JavaAconfigDeclarationsLibraryCallbacks) GenerateSourceJarBuildActions(module *java.GeneratedJavaLibraryModule, ctx android.ModuleContext) android.Path {
// Get the values that came from the global RELEASE_ACONFIG_VALUE_SETS flag
declarationsModules := ctx.GetDirectDepsWithTag(declarationsTag)
if len(declarationsModules) != 1 {
@@ -59,13 +59,18 @@
}
declarations := ctx.OtherModuleProvider(declarationsModules[0], declarationsProviderKey).(declarationsProviderData)
+ // Generate the action to build the srcjar
srcJarPath := android.PathForModuleGen(ctx, ctx.ModuleName()+".srcjar")
ctx.Build(pctx, android.BuildParams{
- Rule: srcJarRule,
+ Rule: javaRule,
Input: declarations.IntermediatePath,
Output: srcJarPath,
Description: "aconfig.srcjar",
})
+ // Tell the java module about the .aconfig files, so they can be propagated up the dependency chain.
+ // TODO: It would be nice to have that propagation code here instead of on java.Module and java.JavaInfo.
+ module.AddAconfigIntermediate(declarations.IntermediatePath)
+
return srcJarPath
}
diff --git a/aconfig/java_aconfig_library_test.go b/aconfig/java_aconfig_library_test.go
new file mode 100644
index 0000000..1808290
--- /dev/null
+++ b/aconfig/java_aconfig_library_test.go
@@ -0,0 +1,154 @@
+// Copyright 2023 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 aconfig
+
+import (
+ "strings"
+ "testing"
+
+ "android/soong/android"
+ "android/soong/java"
+)
+
+// Note: These tests cover the code in the java package. It'd be ideal of that code could
+// be in the aconfig package.
+
+// With the bp parameter that defines a my_module, make sure it has the LOCAL_ACONFIG_FILES entries
+func runJavaAndroidMkTest(t *testing.T, bp string) {
+ result := android.GroupFixturePreparers(
+ PrepareForTestWithAconfigBuildComponents,
+ java.PrepareForTestWithJavaDefaultModules).
+ ExtendWithErrorHandler(android.FixtureExpectsNoErrors).
+ RunTestWithBp(t, bp+`
+ aconfig_declarations {
+ name: "my_aconfig_declarations",
+ package: "com.example.package",
+ srcs: ["foo.aconfig"],
+ }
+
+ java_aconfig_library {
+ name: "my_java_aconfig_library",
+ aconfig_declarations: "my_aconfig_declarations",
+ }
+ `)
+
+ module := result.ModuleForTests("my_module", "android_common").Module()
+
+ entry := android.AndroidMkEntriesForTest(t, result.TestContext, module)[0]
+
+ makeVar := entry.EntryMap["LOCAL_ACONFIG_FILES"]
+ android.AssertIntEquals(t, "len(LOCAL_ACONFIG_FILES)", 1, len(makeVar))
+ if !strings.HasSuffix(makeVar[0], "intermediate.pb") {
+ t.Errorf("LOCAL_ACONFIG_FILES should end with /intermediates.pb, instead it is: %s", makeVar[0])
+ }
+}
+
+func TestAndroidMkJavaLibrary(t *testing.T) {
+ bp := `
+ java_library {
+ name: "my_module",
+ srcs: [
+ "src/foo.java",
+ ],
+ static_libs: [
+ "my_java_aconfig_library",
+ ],
+ platform_apis: true,
+ }
+ `
+
+ runJavaAndroidMkTest(t, bp)
+}
+
+func TestAndroidMkAndroidApp(t *testing.T) {
+ bp := `
+ android_app {
+ name: "my_module",
+ srcs: [
+ "src/foo.java",
+ ],
+ static_libs: [
+ "my_java_aconfig_library",
+ ],
+ platform_apis: true,
+ }
+ `
+
+ runJavaAndroidMkTest(t, bp)
+}
+
+func TestAndroidMkBinary(t *testing.T) {
+ bp := `
+ java_binary {
+ name: "my_module",
+ srcs: [
+ "src/foo.java",
+ ],
+ static_libs: [
+ "my_java_aconfig_library",
+ ],
+ platform_apis: true,
+ main_class: "foo",
+ }
+ `
+
+ runJavaAndroidMkTest(t, bp)
+}
+
+func TestAndroidMkAndroidLibrary(t *testing.T) {
+ bp := `
+ android_library {
+ name: "my_module",
+ srcs: [
+ "src/foo.java",
+ ],
+ static_libs: [
+ "my_java_aconfig_library",
+ ],
+ platform_apis: true,
+ }
+ `
+
+ runJavaAndroidMkTest(t, bp)
+}
+
+func TestAndroidMkBinaryThatLinksAgainstAar(t *testing.T) {
+ // Tests AndroidLibrary's propagation of flags through JavaInfo
+ bp := `
+ android_library {
+ name: "some_library",
+ srcs: [
+ "src/foo.java",
+ ],
+ static_libs: [
+ "my_java_aconfig_library",
+ ],
+ platform_apis: true,
+ }
+ java_binary {
+ name: "my_module",
+ srcs: [
+ "src/bar.java",
+ ],
+ static_libs: [
+ "some_library",
+ ],
+ platform_apis: true,
+ main_class: "foo",
+ }
+ `
+
+ runJavaAndroidMkTest(t, bp)
+}
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index fff41fc..316f89a 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -429,6 +429,7 @@
// external/bazelbuild-rules_android/... is needed by mixed builds, otherwise mixed builds analysis fails
// e.g. ERROR: Analysis of target '@soong_injection//mixed_builds:buildroot' failed
"external/bazelbuild-rules_android":/* recursive = */ true,
+ "external/bazelbuild-rules_java":/* recursive = */ true,
"external/bazelbuild-rules_license":/* recursive = */ true,
"external/bazelbuild-rules_go":/* recursive = */ true,
"external/bazelbuild-kotlin-rules":/* recursive = */ true,
@@ -931,9 +932,6 @@
"test_fips", // depends on unconverted modules: adb
"timezone-host", // depends on unconverted modules: art.module.api.annotations
- // '//bionic/libc:libc_bp2build_cc_library_static' is duplicated in the 'deps' attribute of rule
- "toybox-static",
-
// aidl files not created
"overlayable_policy_aidl_interface",
@@ -1016,6 +1014,7 @@
"bionic-unit-tests-static",
"boringssl_crypto_test",
"boringssl_ssl_test",
+ "boringssl_test_support", //b/244431896
"cfi_test_helper",
"cfi_test_helper2",
"cintltst32",
diff --git a/android/bazel_handler.go b/android/bazel_handler.go
index 5d93f06..4d91cc8 100644
--- a/android/bazel_handler.go
+++ b/android/bazel_handler.go
@@ -16,6 +16,8 @@
import (
"bytes"
+ "crypto/sha1"
+ "encoding/hex"
"fmt"
"os"
"path"
@@ -1222,7 +1224,11 @@
ctx.AddNinjaFileDeps(file)
}
+ depsetHashToDepset := map[string]bazel.AqueryDepset{}
+
for _, depset := range ctx.Config().BazelContext.AqueryDepsets() {
+ depsetHashToDepset[depset.ContentHash] = depset
+
var outputs []Path
var orderOnlies []Path
for _, depsetDepHash := range depset.TransitiveDepSetHashes {
@@ -1257,7 +1263,30 @@
}
if len(buildStatement.Command) > 0 {
rule := NewRuleBuilder(pctx, ctx)
- createCommand(rule.Command(), buildStatement, executionRoot, bazelOutDir, ctx)
+ intermediateDir, intermediateDirHash := intermediatePathForSboxMixedBuildAction(ctx, buildStatement)
+ if buildStatement.ShouldRunInSbox {
+ // Create a rule to build the output inside a sandbox
+ // This will create two changes of working directory
+ // 1. From ANDROID_BUILD_TOP to sbox top
+ // 2. From sbox top to a a synthetic mixed build execution root relative to it
+ // Finally, the outputs will be copied to intermediateDir
+ rule.Sbox(intermediateDir,
+ PathForOutput(ctx, "mixed_build_sbox_intermediates", intermediateDirHash+".textproto")).
+ SandboxInputs().
+ // Since we will cd to mixed build execution root, set sbox's out subdir to empty
+ // Without this, we will try to copy from $SBOX_SANDBOX_DIR/out/out/bazel/output/execroot/__main__/...
+ SetSboxOutDirDirAsEmpty()
+
+ // Create another set of rules to copy files from the intermediate dir to mixed build execution root
+ for _, outputPath := range buildStatement.OutputPaths {
+ ctx.Build(pctx, BuildParams{
+ Rule: CpIfChanged,
+ Input: intermediateDir.Join(ctx, executionRoot, outputPath),
+ Output: PathForBazelOut(ctx, outputPath),
+ })
+ }
+ }
+ createCommand(rule.Command(), buildStatement, executionRoot, bazelOutDir, ctx, depsetHashToDepset)
desc := fmt.Sprintf("%s: %s", buildStatement.Mnemonic, buildStatement.OutputPaths)
rule.Build(fmt.Sprintf("bazel %d", index), desc)
continue
@@ -1304,10 +1333,25 @@
}
}
+// Returns a out dir path for a sandboxed mixed build action
+func intermediatePathForSboxMixedBuildAction(ctx PathContext, statement *bazel.BuildStatement) (OutputPath, string) {
+ // An artifact can be generated by a single buildstatement.
+ // Use the hash of the first artifact to create a unique path
+ uniqueDir := sha1.New()
+ uniqueDir.Write([]byte(statement.OutputPaths[0]))
+ uniqueDirHashString := hex.EncodeToString(uniqueDir.Sum(nil))
+ return PathForOutput(ctx, "mixed_build_sbox_intermediates", uniqueDirHashString), uniqueDirHashString
+}
+
// Register bazel-owned build statements (obtained from the aquery invocation).
-func createCommand(cmd *RuleBuilderCommand, buildStatement *bazel.BuildStatement, executionRoot string, bazelOutDir string, ctx BuilderContext) {
+func createCommand(cmd *RuleBuilderCommand, buildStatement *bazel.BuildStatement, executionRoot string, bazelOutDir string, ctx BuilderContext, depsetHashToDepset map[string]bazel.AqueryDepset) {
// executionRoot is the action cwd.
- cmd.Text(fmt.Sprintf("cd '%s' &&", executionRoot))
+ if buildStatement.ShouldRunInSbox {
+ // mkdir -p ensures that the directory exists when run via sbox
+ cmd.Text(fmt.Sprintf("mkdir -p '%s' && cd '%s' &&", executionRoot, executionRoot))
+ } else {
+ cmd.Text(fmt.Sprintf("cd '%s' &&", executionRoot))
+ }
// Remove old outputs, as some actions might not rerun if the outputs are detected.
if len(buildStatement.OutputPaths) > 0 {
@@ -1334,14 +1378,33 @@
}
for _, outputPath := range buildStatement.OutputPaths {
- cmd.ImplicitOutput(PathForBazelOut(ctx, outputPath))
+ if buildStatement.ShouldRunInSbox {
+ // The full path has three components that get joined together
+ // 1. intermediate output dir that `sbox` will place the artifacts at
+ // 2. mixed build execution root
+ // 3. artifact path returned by aquery
+ intermediateDir, _ := intermediatePathForSboxMixedBuildAction(ctx, buildStatement)
+ cmd.ImplicitOutput(intermediateDir.Join(ctx, executionRoot, outputPath))
+ } else {
+ cmd.ImplicitOutput(PathForBazelOut(ctx, outputPath))
+ }
+ }
+ for _, inputPath := range buildStatement.OrderOnlyInputs {
+ cmd.OrderOnly(PathForBazelOut(ctx, inputPath))
}
for _, inputPath := range buildStatement.InputPaths {
cmd.Implicit(PathForBazelOut(ctx, inputPath))
}
for _, inputDepsetHash := range buildStatement.InputDepsetHashes {
- otherDepsetName := bazelDepsetName(inputDepsetHash)
- cmd.Implicit(PathForPhony(ctx, otherDepsetName))
+ if buildStatement.ShouldRunInSbox {
+ // Bazel depsets are phony targets that are used to group files.
+ // We need to copy the grouped files into the sandbox
+ ds, _ := depsetHashToDepset[inputDepsetHash]
+ cmd.Implicits(PathsForBazelOut(ctx, ds.DirectArtifacts))
+ } else {
+ otherDepsetName := bazelDepsetName(inputDepsetHash)
+ cmd.Implicit(PathForPhony(ctx, otherDepsetName))
+ }
}
if depfile := buildStatement.Depfile; depfile != nil {
diff --git a/android/bazel_handler_test.go b/android/bazel_handler_test.go
index 65cd5a8..e08a471 100644
--- a/android/bazel_handler_test.go
+++ b/android/bazel_handler_test.go
@@ -181,13 +181,62 @@
cmd := RuleBuilderCommand{}
ctx := builderContextForTests{PathContextForTesting(TestConfig("out", nil, "", nil))}
- createCommand(&cmd, got[0], "test/exec_root", "test/bazel_out", ctx)
+ createCommand(&cmd, got[0], "test/exec_root", "test/bazel_out", ctx, map[string]bazel.AqueryDepset{})
if actual, expected := cmd.buf.String(), testCase.command; expected != actual {
t.Errorf("expected: [%s], actual: [%s]", expected, actual)
}
}
}
+func TestMixedBuildSandboxedAction(t *testing.T) {
+ input := `{
+ "artifacts": [
+ { "id": 1, "path_fragment_id": 1 },
+ { "id": 2, "path_fragment_id": 2 }],
+ "actions": [{
+ "target_Id": 1,
+ "action_Key": "x",
+ "mnemonic": "x",
+ "arguments": ["touch", "foo"],
+ "input_dep_set_ids": [1],
+ "output_Ids": [1],
+ "primary_output_id": 1
+ }],
+ "dep_set_of_files": [
+ { "id": 1, "direct_artifact_ids": [1, 2] }],
+ "path_fragments": [
+ { "id": 1, "label": "one" },
+ { "id": 2, "label": "two" }]
+}`
+ data, err := JsonToActionGraphContainer(input)
+ if err != nil {
+ t.Error(err)
+ }
+ bazelContext, _ := testBazelContext(t, map[bazelCommand]string{aqueryCmd: string(data)})
+
+ err = bazelContext.InvokeBazel(testConfig, &testInvokeBazelContext{})
+ if err != nil {
+ t.Fatalf("TestMixedBuildSandboxedAction did not expect error invoking Bazel, but got %s", err)
+ }
+
+ statement := bazelContext.BuildStatementsToRegister()[0]
+ statement.ShouldRunInSbox = true
+
+ cmd := RuleBuilderCommand{}
+ ctx := builderContextForTests{PathContextForTesting(TestConfig("out", nil, "", nil))}
+ createCommand(&cmd, statement, "test/exec_root", "test/bazel_out", ctx, map[string]bazel.AqueryDepset{})
+ // Assert that the output is generated in an intermediate directory
+ // fe05bcdcdc4928012781a5f1a2a77cbb5398e106 is the sha1 checksum of "one"
+ if actual, expected := cmd.outputs[0].String(), "out/soong/mixed_build_sbox_intermediates/fe05bcdcdc4928012781a5f1a2a77cbb5398e106/test/exec_root/one"; expected != actual {
+ t.Errorf("expected: [%s], actual: [%s]", expected, actual)
+ }
+
+ // Assert the actual command remains unchanged inside the sandbox
+ if actual, expected := cmd.buf.String(), "mkdir -p 'test/exec_root' && cd 'test/exec_root' && rm -rf 'one' && touch foo"; expected != actual {
+ t.Errorf("expected: [%s], actual: [%s]", expected, actual)
+ }
+}
+
func TestCoverageFlagsAfterInvokeBazel(t *testing.T) {
testConfig.productVariables.ClangCoverage = boolPtr(true)
diff --git a/android/bazel_paths.go b/android/bazel_paths.go
index 2f5ff64..8956a18 100644
--- a/android/bazel_paths.go
+++ b/android/bazel_paths.go
@@ -179,7 +179,7 @@
// 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.
+// will have already been handled by the pathdeps mutator.
func BazelLabelForModuleSrc(ctx BazelConversionPathContext, paths []string) bazel.LabelList {
return BazelLabelForModuleSrcExcludes(ctx, paths, []string(nil))
}
@@ -189,7 +189,7 @@
// 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.
+// will have already been handled by the pathdeps mutator.
func BazelLabelForModuleSrcExcludes(ctx BazelConversionPathContext, paths, excludes []string) bazel.LabelList {
excludeLabels := expandSrcsForBazel(ctx, excludes, []string(nil))
excluded := make([]string, 0, len(excludeLabels.Includes))
@@ -355,7 +355,7 @@
//
// 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.
+// pathdeps mutator.
func expandSrcsForBazel(ctx BazelConversionPathContext, paths, expandedExcludes []string) bazel.LabelList {
if paths == nil {
return bazel.LabelList{}
diff --git a/android/config.go b/android/config.go
index fa43962..2a243ee 100644
--- a/android/config.go
+++ b/android/config.go
@@ -18,7 +18,6 @@
// product variables necessary for soong_build's operation.
import (
- "bytes"
"encoding/json"
"fmt"
"os"
@@ -202,10 +201,10 @@
// product configuration values are read from Kati-generated soong.variables.
type config struct {
// Options configurable with soong.variables
- productVariables productVariables
+ productVariables ProductVariables
// Only available on configs created by TestConfig
- TestProductVariables *productVariables
+ TestProductVariables *ProductVariables
// A specialized context object for Bazel/Soong mixed builds and migration
// purposes.
@@ -321,7 +320,7 @@
// loadFromConfigFile loads and decodes configuration options from a JSON file
// in the current working directory.
-func loadFromConfigFile(configurable *productVariables, filename string) error {
+func loadFromConfigFile(configurable *ProductVariables, filename string) error {
// Try to open the file
configFileReader, err := os.Open(filename)
defer configFileReader.Close()
@@ -373,7 +372,7 @@
// atomically writes the config file in case two copies of soong_build are running simultaneously
// (for example, docs generation and ninja manifest generation)
-func saveToConfigFile(config *productVariables, filename string) error {
+func saveToConfigFile(config *ProductVariables, filename string) error {
data, err := json.MarshalIndent(&config, "", " ")
if err != nil {
return fmt.Errorf("cannot marshal config data: %s", err.Error())
@@ -402,7 +401,7 @@
return nil
}
-func saveToBazelConfigFile(config *productVariables, outDir string) error {
+func saveToBazelConfigFile(config *ProductVariables, outDir string) error {
dir := filepath.Join(outDir, bazel.SoongInjectionDirName, "product_config")
err := createDirIfNonexistent(dir, os.ModePerm)
if err != nil {
@@ -431,32 +430,6 @@
return fmt.Errorf("cannot marshal arch variant product variable data: %s", err.Error())
}
- configJson, err := json.MarshalIndent(&config, "", " ")
- if err != nil {
- return fmt.Errorf("cannot marshal config data: %s", err.Error())
- }
- // The backslashes need to be escaped because this text is going to be put
- // inside a Starlark string literal.
- configJson = bytes.ReplaceAll(configJson, []byte("\\"), []byte("\\\\"))
-
- bzl := []string{
- bazel.GeneratedBazelFileWarning,
- fmt.Sprintf(`_product_vars = json.decode("""%s""")`, configJson),
- fmt.Sprintf(`_product_var_constraints = %s`, nonArchVariantProductVariablesJson),
- fmt.Sprintf(`_arch_variant_product_var_constraints = %s`, archVariantProductVariablesJson),
- "\n", `
-product_vars = _product_vars
-
-# TODO(b/269577299) Remove these when everything switches over to loading them from product_variable_constants.bzl
-product_var_constraints = _product_var_constraints
-arch_variant_product_var_constraints = _arch_variant_product_var_constraints
-`,
- }
- err = pathtools.WriteFileIfChanged(filepath.Join(dir, "product_variables.bzl"),
- []byte(strings.Join(bzl, "\n")), 0644)
- if err != nil {
- return fmt.Errorf("Could not write .bzl config file %s", err)
- }
err = pathtools.WriteFileIfChanged(filepath.Join(dir, "product_variable_constants.bzl"), []byte(fmt.Sprintf(`
product_var_constraints = %s
arch_variant_product_var_constraints = %s
@@ -1355,6 +1328,10 @@
return c.bazelForceEnabledModules
}
+func (c *config) IsVndkDeprecated() bool {
+ return !Bool(c.productVariables.KeepVndk)
+}
+
func (c *deviceConfig) Arches() []Arch {
var arches []Arch
for _, target := range c.config.Targets[Android] {
diff --git a/android/config_test.go b/android/config_test.go
index 9df5288..7d327a2 100644
--- a/android/config_test.go
+++ b/android/config_test.go
@@ -75,7 +75,7 @@
// run validateConfigAnnotations against each type that might have json annotations
func TestProductConfigAnnotations(t *testing.T) {
- err := validateConfigAnnotations(&productVariables{})
+ err := validateConfigAnnotations(&ProductVariables{})
if err != nil {
t.Errorf(err.Error())
}
@@ -88,7 +88,7 @@
}
}
-func verifyProductVariableMarshaling(t *testing.T, v productVariables) {
+func verifyProductVariableMarshaling(t *testing.T, v ProductVariables) {
dir := t.TempDir()
path := filepath.Join(dir, "test.variables")
err := saveToConfigFile(&v, path)
@@ -96,20 +96,20 @@
t.Errorf("Couldn't save default product config: %q", err)
}
- var v2 productVariables
+ var v2 ProductVariables
err = loadFromConfigFile(&v2, path)
if err != nil {
t.Errorf("Couldn't load default product config: %q", err)
}
}
func TestDefaultProductVariableMarshaling(t *testing.T) {
- v := productVariables{}
+ v := ProductVariables{}
v.SetDefaultConfig()
verifyProductVariableMarshaling(t, v)
}
func TestBootJarsMarshaling(t *testing.T) {
- v := productVariables{}
+ v := ProductVariables{}
v.SetDefaultConfig()
v.BootJars = ConfiguredJarList{
apexes: []string{"apex"},
diff --git a/android/configured_jars_test.go b/android/configured_jars_test.go
index 32c3613..4b586e4 100644
--- a/android/configured_jars_test.go
+++ b/android/configured_jars_test.go
@@ -21,7 +21,7 @@
func TestOverrideConfiguredJarLocationFor(t *testing.T) {
cfg := NullConfig("", "")
- cfg.productVariables = productVariables{
+ cfg.productVariables = ProductVariables{
ConfiguredJarLocationOverrides: []string{
"platform:libfoo-old:com.android.foo:libfoo-new",
"com.android.bar:libbar-old:platform:libbar-new",
diff --git a/android/fixture.go b/android/fixture.go
index dbc3bc5..6660afd 100644
--- a/android/fixture.go
+++ b/android/fixture.go
@@ -369,7 +369,7 @@
// Allow access to the product variables when preparing the fixture.
type FixtureProductVariables struct {
- *productVariables
+ *ProductVariables
}
// Modify product variables.
diff --git a/android/paths.go b/android/paths.go
index fda4d2f..e16cb37 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -396,7 +396,7 @@
//
// 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.
+// pathdeps 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
@@ -425,7 +425,7 @@
// 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.
+// pathdeps 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
@@ -560,7 +560,7 @@
// 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_deps mutator.
+// pathdeps mutator.
func PathsAndMissingDepsForModuleSrcExcludes(ctx ModuleMissingDepsPathContext, paths, excludes []string) (Paths, []string) {
return PathsAndMissingDepsRelativeToModuleSourceDir(SourceInput{
Context: ctx,
diff --git a/android/rule_builder.go b/android/rule_builder.go
index 0438eb8..777c1cf 100644
--- a/android/rule_builder.go
+++ b/android/rule_builder.go
@@ -53,6 +53,7 @@
remoteable RemoteRuleSupports
rbeParams *remoteexec.REParams
outDir WritablePath
+ sboxOutSubDir string
sboxTools bool
sboxInputs bool
sboxManifestPath WritablePath
@@ -65,9 +66,18 @@
pctx: pctx,
ctx: ctx,
temporariesSet: make(map[WritablePath]bool),
+ sboxOutSubDir: sboxOutSubDir,
}
}
+// SetSboxOutDirDirAsEmpty sets the out subdirectory to an empty string
+// This is useful for sandboxing actions that change the execution root to a path in out/ (e.g mixed builds)
+// For such actions, SetSboxOutDirDirAsEmpty ensures that the path does not become $SBOX_SANDBOX_DIR/out/out/bazel/output/execroot/__main__/...
+func (rb *RuleBuilder) SetSboxOutDirDirAsEmpty() *RuleBuilder {
+ rb.sboxOutSubDir = ""
+ return rb
+}
+
// RuleBuilderInstall is a tuple of install from and to locations.
type RuleBuilderInstall struct {
From Path
@@ -585,7 +595,7 @@
for _, output := range outputs {
rel := Rel(r.ctx, r.outDir.String(), output.String())
command.CopyAfter = append(command.CopyAfter, &sbox_proto.Copy{
- From: proto.String(filepath.Join(sboxOutSubDir, rel)),
+ From: proto.String(filepath.Join(r.sboxOutSubDir, rel)),
To: proto.String(output.String()),
})
}
diff --git a/android/sdk_version_test.go b/android/sdk_version_test.go
index ea99c4d..30bd002 100644
--- a/android/sdk_version_test.go
+++ b/android/sdk_version_test.go
@@ -75,7 +75,7 @@
config := NullConfig("", "")
- config.productVariables = productVariables{
+ config.productVariables = ProductVariables{
Platform_sdk_version: intPtr(31),
Platform_sdk_codename: stringPtr("Tiramisu"),
Platform_version_active_codenames: []string{"Tiramisu"},
diff --git a/android/test_config.go b/android/test_config.go
index 28d9ec4..2a59d92 100644
--- a/android/test_config.go
+++ b/android/test_config.go
@@ -35,7 +35,7 @@
envCopy["PATH"] = os.Getenv("PATH")
config := &config{
- productVariables: productVariables{
+ productVariables: ProductVariables{
DeviceName: stringPtr("test_device"),
DeviceProduct: stringPtr("test_product"),
Platform_sdk_version: intPtr(30),
diff --git a/android/util.go b/android/util.go
index e17d7b2..5375373 100644
--- a/android/util.go
+++ b/android/util.go
@@ -137,19 +137,17 @@
}
// IndexList returns the index of the first occurrence of the given string in the list or -1
-func IndexList(s string, list []string) int {
+func IndexList[T comparable](t T, list []T) int {
for i, l := range list {
- if l == s {
+ if l == t {
return i
}
}
-
return -1
}
-// InList checks if the string belongs to the list
-func InList(s string, list []string) bool {
- return IndexList(s, list) != -1
+func InList[T comparable](t T, list []T) bool {
+ return IndexList(t, list) != -1
}
func setFromList[T comparable](l []T) map[T]bool {
diff --git a/android/variable.go b/android/variable.go
index 4442a09..1c81f3c 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -185,7 +185,7 @@
var defaultProductVariables interface{} = variableProperties{}
-type productVariables struct {
+type ProductVariables struct {
// Suffix to add to generated Makefiles
Make_suffix *string `json:",omitempty"`
@@ -475,6 +475,8 @@
ReleaseVersion string `json:",omitempty"`
ReleaseAconfigValueSets []string `json:",omitempty"`
+
+ KeepVndk *bool `json:",omitempty"`
}
func boolPtr(v bool) *bool {
@@ -489,8 +491,8 @@
return &v
}
-func (v *productVariables) SetDefaultConfig() {
- *v = productVariables{
+func (v *ProductVariables) SetDefaultConfig() {
+ *v = ProductVariables{
BuildNumberFile: stringPtr("build_number.txt"),
Platform_version_name: stringPtr("S"),
diff --git a/apex/apex_test.go b/apex/apex_test.go
index f7a4dea..df138e0 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -10553,6 +10553,7 @@
src: "libc.so",
min_sdk_version: "29",
recovery_available: true,
+ vendor_available: true,
}
api_imports {
name: "api_imports",
diff --git a/bazel/aquery.go b/bazel/aquery.go
index 480158c..186a494 100644
--- a/bazel/aquery.go
+++ b/bazel/aquery.go
@@ -115,7 +115,11 @@
// input path string, but not both.
InputDepsetHashes []string
InputPaths []string
+ OrderOnlyInputs []string
FileContents string
+ // If ShouldRunInSbox is true, Soong will use sbox to created an isolated environment
+ // and run the mixed build action there
+ ShouldRunInSbox bool
}
// A helper type for aquery processing which facilitates retrieval of path IDs from their
@@ -134,6 +138,8 @@
depsetHashToArtifactPathsCache sync.Map
// Maps artifact ids to fully expanded paths.
artifactIdToPath map[artifactId]string
+
+ extraBuildStatements []*BuildStatement
}
// The tokens should be substituted with the value specified here, instead of the
@@ -163,13 +169,29 @@
return pathFragmentId(pf.Id)
})
+ var extraBuildStatements []*BuildStatement
artifactIdToPath := make(map[artifactId]string, len(aqueryResult.Artifacts))
for _, artifact := range aqueryResult.Artifacts {
artifactPath, err := expandPathFragment(pathFragmentId(artifact.PathFragmentId), pathFragments)
if err != nil {
return nil, err
}
- artifactIdToPath[artifactId(artifact.Id)] = artifactPath
+ if strings.HasSuffix(artifactPath, "DumpPlatformClassPath.java") {
+ // TODO(b/291828210): This is a workaround for the fact that DumpPlatformClassPath.java
+ // has a timestamp in 2033. We'll copy it to a new file using a order-only dep, so that
+ // the file is not recopied every build. Technically the order-only dep would produce
+ // incremental build issues if this was a regular file produced as part of the build,
+ // but this file is actually created by bazel during analysis, so it's not an issue.
+ outputPath := "hack_for_b291828210/DumpPlatformClassPath.java"
+ extraBuildStatements = append(extraBuildStatements, &BuildStatement{
+ Command: fmt.Sprintf("cp %s %s", artifactPath, outputPath),
+ OutputPaths: []string{outputPath},
+ OrderOnlyInputs: []string{artifactPath},
+ })
+ artifactIdToPath[artifactId(artifact.Id)] = outputPath
+ } else {
+ artifactIdToPath[artifactId(artifact.Id)] = artifactPath
+ }
}
// Map middleman artifact ContentHash to input artifact depset ID.
@@ -196,6 +218,7 @@
depsetHashToArtifactPathsCache: sync.Map{},
emptyDepsetIds: make(map[depsetId]struct{}, 0),
artifactIdToPath: artifactIdToPath,
+ extraBuildStatements: extraBuildStatements,
}
// Validate and adjust aqueryResult.DepSetOfFiles values.
@@ -369,6 +392,7 @@
if err != nil {
return nil, nil, err
}
+ buildStatements = append(buildStatements, aqueryHandler.extraBuildStatements...)
depsetsByHash := map[string]AqueryDepset{}
depsets := make([]AqueryDepset, 0, len(aqueryHandler.depsetIdToAqueryDepset))
@@ -496,6 +520,12 @@
Env: actionEntry.EnvironmentVariables,
Mnemonic: actionEntry.Mnemonic,
}
+ if buildStatement.Mnemonic == "GoToolchainBinaryBuild" {
+ // Unlike b's execution root, mixed build execution root contains a symlink to prebuilts/go
+ // This causes issues for `GOCACHE=$(mktemp -d) go build ...`
+ // To prevent this, sandbox this action in mixed builds as well
+ buildStatement.ShouldRunInSbox = true
+ }
return buildStatement, nil
}
diff --git a/bp2build/bp2build.go b/bp2build/bp2build.go
index b22cb28..cfe52db 100644
--- a/bp2build/bp2build.go
+++ b/bp2build/bp2build.go
@@ -80,6 +80,12 @@
os.Exit(1)
}
bp2buildFiles := CreateBazelFiles(ctx.Config(), nil, res.buildFileToTargets, ctx.mode)
+ injectionFiles, additionalBp2buildFiles, err := CreateSoongInjectionDirFiles(ctx, res.metrics)
+ if err != nil {
+ fmt.Printf("%s\n", err.Error())
+ os.Exit(1)
+ }
+ bp2buildFiles = append(bp2buildFiles, additionalBp2buildFiles...)
writeFiles(ctx, bp2buildDir, bp2buildFiles)
// Delete files under the bp2build root which weren't just written. An
// alternative would have been to delete the whole directory and write these
@@ -88,11 +94,6 @@
// performance implications.
deleteFilesExcept(ctx, bp2buildDir, bp2buildFiles)
- injectionFiles, err := CreateSoongInjectionDirFiles(ctx, res.metrics)
- if err != nil {
- fmt.Printf("%s\n", err.Error())
- os.Exit(1)
- }
writeFiles(ctx, android.PathForOutput(ctx, bazel.SoongInjectionDirName), injectionFiles)
starlarkDeps, err := starlark_import.GetNinjaDeps()
if err != nil {
@@ -107,20 +108,20 @@
// This includes
// 1. config value(s) that are hardcoded in Soong
// 2. product_config variables
-func CreateSoongInjectionDirFiles(ctx *CodegenContext, metrics CodegenMetrics) ([]BazelFile, error) {
+func CreateSoongInjectionDirFiles(ctx *CodegenContext, metrics CodegenMetrics) ([]BazelFile, []BazelFile, error) {
var ret []BazelFile
- productConfigFiles, err := CreateProductConfigFiles(ctx)
+ productConfigInjectionFiles, productConfigBp2BuildDirFiles, err := CreateProductConfigFiles(ctx)
if err != nil {
- return nil, err
+ return nil, nil, err
}
- ret = append(ret, productConfigFiles...)
+ ret = append(ret, productConfigInjectionFiles...)
injectionFiles, err := soongInjectionFiles(ctx.Config(), metrics)
if err != nil {
- return nil, err
+ return nil, nil, err
}
- ret = append(ret, injectionFiles...)
- return ret, nil
+ ret = append(injectionFiles, ret...)
+ return ret, productConfigBp2BuildDirFiles, nil
}
// Get the output directory and create it if it doesn't exist.
diff --git a/bp2build/bp2build_product_config.go b/bp2build/bp2build_product_config.go
index 7224496..c8067af 100644
--- a/bp2build/bp2build_product_config.go
+++ b/bp2build/bp2build_product_config.go
@@ -1,14 +1,20 @@
package bp2build
import (
+ "android/soong/android"
+ "android/soong/starlark_import"
+ "encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
+
+ "github.com/google/blueprint/proptools"
+ "go.starlark.net/starlark"
)
func CreateProductConfigFiles(
- ctx *CodegenContext) ([]BazelFile, error) {
+ ctx *CodegenContext) ([]BazelFile, []BazelFile, error) {
cfg := &ctx.config
targetProduct := "unknown"
if cfg.HasDeviceProduct() {
@@ -25,9 +31,14 @@
if !strings.HasPrefix(productVariablesFileName, "/") {
productVariablesFileName = filepath.Join(ctx.topDir, productVariablesFileName)
}
- bytes, err := os.ReadFile(productVariablesFileName)
+ productVariablesBytes, err := os.ReadFile(productVariablesFileName)
if err != nil {
- return nil, err
+ return nil, nil, err
+ }
+ productVariables := android.ProductVariables{}
+ err = json.Unmarshal(productVariablesBytes, &productVariables)
+ if err != nil {
+ return nil, nil, err
}
// TODO(b/249685973): the name is product_config_platforms because product_config
@@ -39,11 +50,16 @@
"{VARIANT}", targetBuildVariant,
"{PRODUCT_FOLDER}", currentProductFolder)
- result := []BazelFile{
+ platformMappingContent, err := platformMappingContent(productReplacer.Replace("@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}"), &productVariables)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ injectionDirFiles := []BazelFile{
newFile(
currentProductFolder,
"soong.variables.bzl",
- `variables = json.decode("""`+strings.ReplaceAll(string(bytes), "\\", "\\\\")+`""")`),
+ `variables = json.decode("""`+strings.ReplaceAll(string(productVariablesBytes), "\\", "\\\\")+`""")`),
newFile(
currentProductFolder,
"BUILD",
@@ -99,6 +115,7 @@
"product_config_platforms",
"common.bazelrc",
productReplacer.Replace(`
+build --platform_mappings=platform_mappings
build --platforms @soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_x86_64
build:android --platforms=@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}
@@ -120,6 +137,82 @@
build --host_platform @soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_darwin_x86_64
`)),
}
+ bp2buildDirFiles := []BazelFile{
+ newFile(
+ "",
+ "platform_mappings",
+ platformMappingContent),
+ }
+ return injectionDirFiles, bp2buildDirFiles, nil
+}
+func platformMappingContent(mainProductLabel string, mainProductVariables *android.ProductVariables) (string, error) {
+ productsForTesting, err := starlark_import.GetStarlarkValue[map[string]map[string]starlark.Value]("products_for_testing")
+ if err != nil {
+ return "", err
+ }
+ result := "platforms:\n"
+ result += platformMappingSingleProduct(mainProductLabel, mainProductVariables)
+ for product, productVariablesStarlark := range productsForTesting {
+ productVariables, err := starlarkMapToProductVariables(productVariablesStarlark)
+ if err != nil {
+ return "", err
+ }
+ result += platformMappingSingleProduct("@//build/bazel/tests/products:"+product, &productVariables)
+ }
+ return result, nil
+}
+
+var bazelPlatformSuffixes = []string{
+ "",
+ "_darwin_arm64",
+ "_darwin_x86_64",
+ "_linux_bionic_arm64",
+ "_linux_bionic_x86_64",
+ "_linux_musl_x86",
+ "_linux_musl_x86_64",
+ "_linux_x86",
+ "_linux_x86_64",
+ "_windows_x86",
+ "_windows_x86_64",
+}
+
+func platformMappingSingleProduct(label string, productVariables *android.ProductVariables) string {
+ buildSettings := ""
+ buildSettings += fmt.Sprintf(" --//build/bazel/product_config:apex_global_min_sdk_version_override=%s\n", proptools.String(productVariables.ApexGlobalMinSdkVersionOverride))
+ buildSettings += fmt.Sprintf(" --//build/bazel/product_config:cfi_include_paths=%s\n", strings.Join(productVariables.CFIIncludePaths, ","))
+ buildSettings += fmt.Sprintf(" --//build/bazel/product_config:cfi_exclude_paths=%s\n", strings.Join(productVariables.CFIExcludePaths, ","))
+ buildSettings += fmt.Sprintf(" --//build/bazel/product_config:enable_cfi=%t\n", proptools.BoolDefault(productVariables.EnableCFI, true))
+ buildSettings += fmt.Sprintf(" --//build/bazel/product_config:device_abi=%s\n", strings.Join(productVariables.DeviceAbi, ","))
+ result := ""
+ for _, suffix := range bazelPlatformSuffixes {
+ result += " " + label + suffix + "\n" + buildSettings
+ }
+ return result
+}
+
+func starlarkMapToProductVariables(in map[string]starlark.Value) (android.ProductVariables, error) {
+ var err error
+ result := android.ProductVariables{}
+ result.ApexGlobalMinSdkVersionOverride, err = starlark_import.UnmarshalNoneable[string](in["ApexGlobalMinSdkVersionOverride"])
+ if err != nil {
+ return result, err
+ }
+ result.CFIIncludePaths, err = starlark_import.Unmarshal[[]string](in["CFIIncludePaths"])
+ if err != nil {
+ return result, err
+ }
+ result.CFIExcludePaths, err = starlark_import.Unmarshal[[]string](in["CFIExcludePaths"])
+ if err != nil {
+ return result, err
+ }
+ result.EnableCFI, err = starlark_import.UnmarshalNoneable[bool](in["EnableCFI"])
+ if err != nil {
+ return result, err
+ }
+ result.DeviceAbi, err = starlark_import.Unmarshal[[]string](in["DeviceAbi"])
+ if err != nil {
+ return result, err
+ }
return result, nil
}
diff --git a/bp2build/build_conversion.go b/bp2build/build_conversion.go
index a817386..0e6596b 100644
--- a/bp2build/build_conversion.go
+++ b/bp2build/build_conversion.go
@@ -471,17 +471,6 @@
return []BazelTarget{binTarget}, nil
}
-var (
- // TODO - b/284483729: Remove this denyilst
- // Temporary denylist of go binaries that are currently used in mixed builds
- // This denylist allows us to rollout bp2build converters for go targets without affecting mixed builds
- goBinaryDenylist = []string{
- "soong_zip",
- "zip2zip",
- "bazel_notice_gen",
- }
-)
-
func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (conversionResults, []error) {
buildFileToTargets := make(map[string]BazelTargets)
@@ -574,7 +563,7 @@
targets, targetErrs = generateBazelTargetsGoPackage(bpCtx, glib, nameToGoLibMap)
errs = append(errs, targetErrs...)
metrics.IncrementRuleClassCount("go_library")
- } else if gbin, ok := m.(*bootstrap.GoBinary); ok && !android.InList(m.Name(), goBinaryDenylist) {
+ } else if gbin, ok := m.(*bootstrap.GoBinary); ok {
targets, targetErrs = generateBazelTargetsGoBinary(bpCtx, gbin, nameToGoLibMap)
errs = append(errs, targetErrs...)
metrics.IncrementRuleClassCount("go_binary")
diff --git a/bp2build/cc_binary_conversion_test.go b/bp2build/cc_binary_conversion_test.go
index 4b36cc7..d9a7860 100644
--- a/bp2build/cc_binary_conversion_test.go
+++ b/bp2build/cc_binary_conversion_test.go
@@ -1214,3 +1214,82 @@
},
})
}
+
+func TestCcBinaryStatic_SystemSharedLibUsedAsDep(t *testing.T) {
+ runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
+ description: "cc_library_static system_shared_lib empty for linux_bionic variant",
+ blueprint: soongCcLibraryStaticPreamble +
+ simpleModuleDoNotConvertBp2build("cc_library", "libc") + `
+
+cc_library {
+ name: "libm",
+ bazel_module: { bp2build_available: false },
+}
+
+cc_binary {
+ name: "used_in_bionic_oses",
+ target: {
+ android: {
+ static_libs: ["libc"],
+ },
+ linux_bionic: {
+ static_libs: ["libc"],
+ },
+ },
+ include_build_directory: false,
+ static_executable: true,
+}
+
+cc_binary {
+ name: "all",
+ static_libs: ["libc"],
+ include_build_directory: false,
+ static_executable: true,
+}
+
+cc_binary {
+ name: "keep_for_empty_system_shared_libs",
+ static_libs: ["libc"],
+ system_shared_libs: [],
+ include_build_directory: false,
+ static_executable: true,
+}
+
+cc_binary {
+ name: "used_with_stubs",
+ static_libs: ["libm"],
+ include_build_directory: false,
+ static_executable: true,
+}
+
+cc_binary {
+ name: "keep_with_stubs",
+ static_libs: ["libm"],
+ system_shared_libs: [],
+ include_build_directory: false,
+ static_executable: true,
+}
+`,
+ targets: []testBazelTarget{
+ {"cc_binary", "all", AttrNameToString{
+ "linkshared": "False",
+ }},
+ {"cc_binary", "keep_for_empty_system_shared_libs", AttrNameToString{
+ "deps": `[":libc_bp2build_cc_library_static"]`,
+ "system_deps": `[]`,
+ "linkshared": "False",
+ }},
+ {"cc_binary", "keep_with_stubs", AttrNameToString{
+ "linkshared": "False",
+ "deps": `[":libm_bp2build_cc_library_static"]`,
+ "system_deps": `[]`,
+ }},
+ {"cc_binary", "used_in_bionic_oses", AttrNameToString{
+ "linkshared": "False",
+ }},
+ {"cc_binary", "used_with_stubs", AttrNameToString{
+ "linkshared": "False",
+ }},
+ },
+ })
+}
diff --git a/cc/Android.bp b/cc/Android.bp
index f49dc1a..e88ea03 100644
--- a/cc/Android.bp
+++ b/cc/Android.bp
@@ -32,6 +32,7 @@
"check.go",
"coverage.go",
"gen.go",
+ "generated_cc_library.go",
"image.go",
"linkable.go",
"lto.go",
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 85a2284..6e00aa8 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -1139,6 +1139,7 @@
wholeArchiveDeps bazel.LabelListAttribute
implementationWholeArchiveDeps bazel.LabelListAttribute
systemDynamicDeps bazel.LabelListAttribute
+ usedSystemDynamicDepAsStaticDep map[string]bool
usedSystemDynamicDepAsDynamicDep map[string]bool
useVersionLib bazel.BoolAttribute
@@ -1201,6 +1202,18 @@
// https://cs.android.com/android/platform/superproject/+/master:build/soong/cc/linker.go;l=247-249;drc=088b53577dde6e40085ffd737a1ae96ad82fc4b0
la.wholeArchiveDeps.SetSelectValue(axis, config, bazelLabelForWholeDepsExcludes(ctx, wholeStaticLibs, props.Exclude_static_libs))
+ if isBinary && module.StaticExecutable() {
+ usedSystemStatic := android.FilterListPred(staticLibs, func(s string) bool {
+ return android.InList(s, soongSystemSharedLibs) && !android.InList(s, props.Exclude_static_libs)
+ })
+
+ for _, el := range usedSystemStatic {
+ if la.usedSystemDynamicDepAsStaticDep == nil {
+ la.usedSystemDynamicDepAsStaticDep = map[string]bool{}
+ }
+ la.usedSystemDynamicDepAsStaticDep[el] = true
+ }
+ }
staticDeps := maybePartitionExportedAndImplementationsDepsExcludes(
ctx,
!isBinary,
@@ -1233,6 +1246,7 @@
usedSystem := android.FilterListPred(sharedLibs, func(s string) bool {
return android.InList(s, soongSystemSharedLibs) && !android.InList(s, excludeSharedLibs)
})
+
for _, el := range usedSystem {
if la.usedSystemDynamicDepAsDynamicDep == nil {
la.usedSystemDynamicDepAsDynamicDep = map[string]bool{}
@@ -1625,6 +1639,15 @@
}
la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.AndroidPlatform, bazel.MakeLabelList(stubsToRemove))
}
+ if la.systemDynamicDeps.IsNil() && len(la.usedSystemDynamicDepAsStaticDep) > 0 {
+ toRemove := bazelLabelForStaticDeps(ctx, android.SortedKeys(la.usedSystemDynamicDepAsStaticDep))
+ la.deps.Exclude(bazel.NoConfigAxis, "", toRemove)
+ la.deps.Exclude(bazel.OsConfigurationAxis, "android", toRemove)
+ la.deps.Exclude(bazel.OsConfigurationAxis, "linux_bionic", toRemove)
+ la.implementationDeps.Exclude(bazel.NoConfigAxis, "", toRemove)
+ la.implementationDeps.Exclude(bazel.OsConfigurationAxis, "android", toRemove)
+ la.implementationDeps.Exclude(bazel.OsConfigurationAxis, "linux_bionic", toRemove)
+ }
la.deps.ResolveExcludes()
la.implementationDeps.ResolveExcludes()
diff --git a/cc/cc.go b/cc/cc.go
index 6087970..be67286 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -42,6 +42,7 @@
func init() {
RegisterCCBuildComponents(android.InitRegistrationContext)
+ pctx.Import("android/soong/android")
pctx.Import("android/soong/cc/config")
}
@@ -568,6 +569,24 @@
props() []interface{}
}
+// Information returned from Generator about the source code it's generating
+type GeneratedSource struct {
+ IncludeDirs android.Paths
+ Sources android.Paths
+ Headers android.Paths
+ ReexportedDirs android.Paths
+}
+
+// generator allows injection of generated code
+type Generator interface {
+ GeneratorProps() []interface{}
+ GeneratorInit(ctx BaseModuleContext)
+ GeneratorDeps(ctx DepsContext, deps Deps) Deps
+ GeneratorFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
+ GeneratorSources(ctx ModuleContext) GeneratedSource
+ GeneratorBuildActions(ctx ModuleContext, flags Flags, deps PathDeps)
+}
+
// compiler is the interface for a compiler helper object. Different module decorators may implement
// this helper differently.
type compiler interface {
@@ -850,6 +869,7 @@
// type-specific logic. These members may reference different objects or the same object.
// Functions of these decorators will be invoked to initialize and register type-specific
// build statements.
+ generators []Generator
compiler compiler
linker linker
installer installer
@@ -1079,6 +1099,10 @@
return false
}
+func (c *Module) RlibStd() bool {
+ panic(fmt.Errorf("RlibStd called on non-Rust module: %q", c.BaseModuleName()))
+}
+
func (c *Module) RustLibraryInterface() bool {
return false
}
@@ -1196,6 +1220,9 @@
func (c *Module) Init() android.Module {
c.AddProperties(&c.Properties, &c.VendorProperties)
+ for _, generator := range c.generators {
+ c.AddProperties(generator.GeneratorProps()...)
+ }
if c.compiler != nil {
c.AddProperties(c.compiler.compilerProps()...)
}
@@ -1367,7 +1394,7 @@
func (c *Module) isCfi() bool {
if sanitize := c.sanitize; sanitize != nil {
- return Bool(sanitize.Properties.Sanitize.Cfi)
+ return Bool(sanitize.Properties.SanitizeMutated.Cfi)
}
return false
}
@@ -2144,6 +2171,25 @@
return
}
+ for _, generator := range c.generators {
+ gen := generator.GeneratorSources(ctx)
+ deps.IncludeDirs = append(deps.IncludeDirs, gen.IncludeDirs...)
+ deps.ReexportedDirs = append(deps.ReexportedDirs, gen.ReexportedDirs...)
+ deps.GeneratedDeps = append(deps.GeneratedDeps, gen.Headers...)
+ deps.ReexportedGeneratedHeaders = append(deps.ReexportedGeneratedHeaders, gen.Headers...)
+ deps.ReexportedDeps = append(deps.ReexportedDeps, gen.Headers...)
+ if len(deps.Objs.objFiles) == 0 {
+ // If we are reusuing object files (which happens when we're a shared library and we're
+ // reusing our static variant's object files), then skip adding the actual source files,
+ // because we already have the object for it.
+ deps.GeneratedSources = append(deps.GeneratedSources, gen.Sources...)
+ }
+ }
+
+ if ctx.Failed() {
+ return
+ }
+
if c.stubLibraryMultipleApexViolation(actx) {
actx.PropertyErrorf("apex_available",
"Stub libraries should have a single apex_available (test apexes excluded). Got %v", c.ApexAvailable())
@@ -2158,6 +2204,9 @@
Toolchain: c.toolchain(ctx),
EmitXrefs: ctx.Config().EmitXrefRules(),
}
+ for _, generator := range c.generators {
+ flags = generator.GeneratorFlags(ctx, flags, deps)
+ }
if c.compiler != nil {
flags = c.compiler.compilerFlags(ctx, flags, deps)
}
@@ -2215,6 +2264,10 @@
flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
+ for _, generator := range c.generators {
+ generator.GeneratorBuildActions(ctx, flags, deps)
+ }
+
var objs Objects
if c.compiler != nil {
objs = c.compiler.compile(ctx, flags, deps)
@@ -2302,6 +2355,9 @@
}
func (c *Module) begin(ctx BaseModuleContext) {
+ for _, generator := range c.generators {
+ generator.GeneratorInit(ctx)
+ }
if c.compiler != nil {
c.compiler.compilerInit(ctx)
}
@@ -2337,6 +2393,9 @@
func (c *Module) deps(ctx DepsContext) Deps {
deps := Deps{}
+ for _, generator := range c.generators {
+ deps = generator.GeneratorDeps(ctx, deps)
+ }
if c.compiler != nil {
deps = c.compiler.compilerDeps(ctx, deps)
}
@@ -2945,20 +3004,20 @@
ctx.ModuleErrorf("links %q built against newer API version %q",
ctx.OtherModuleName(to.Module()), "current")
} else {
- fromApi, err := strconv.Atoi(from.SdkVersion())
+ fromApi, err := android.ApiLevelFromUserWithConfig(ctx.Config(), from.SdkVersion())
if err != nil {
ctx.PropertyErrorf("sdk_version",
- "Invalid sdk_version value (must be int or current): %q",
+ "Invalid sdk_version value (must be int, preview or current): %q",
from.SdkVersion())
}
- toApi, err := strconv.Atoi(to.SdkVersion())
+ toApi, err := android.ApiLevelFromUserWithConfig(ctx.Config(), to.SdkVersion())
if err != nil {
ctx.PropertyErrorf("sdk_version",
- "Invalid sdk_version value (must be int or current): %q",
+ "Invalid sdk_version value (must be int, preview or current): %q",
to.SdkVersion())
}
- if toApi > fromApi {
+ if toApi.GreaterThan(fromApi) {
ctx.ModuleErrorf("links %q built against newer API version %q",
ctx.OtherModuleName(to.Module()), to.SdkVersion())
}
diff --git a/cc/config/toolchain.go b/cc/config/toolchain.go
index a0ef575..62f75d1 100644
--- a/cc/config/toolchain.go
+++ b/cc/config/toolchain.go
@@ -261,5 +261,3 @@
func LibFuzzerRuntimeInterceptors(t Toolchain) string {
return LibclangRuntimeLibrary(t, "fuzzer_interceptors")
}
-
-var inList = android.InList
diff --git a/cc/fuzz.go b/cc/fuzz.go
index 636ad85..227fe8b 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -29,6 +29,7 @@
func init() {
android.RegisterModuleType("cc_fuzz", LibFuzzFactory)
android.RegisterParallelSingletonType("cc_fuzz_packaging", fuzzPackagingFactory)
+ android.RegisterParallelSingletonType("cc_fuzz_presubmit_packaging", fuzzPackagingFactoryPresubmit)
}
type FuzzProperties struct {
@@ -258,25 +259,29 @@
func PackageFuzzModule(ctx android.ModuleContext, fuzzPackagedModule fuzz.FuzzPackagedModule, pctx android.PackageContext) fuzz.FuzzPackagedModule {
fuzzPackagedModule.Corpus = android.PathsForModuleSrc(ctx, fuzzPackagedModule.FuzzProperties.Corpus)
- builder := android.NewRuleBuilder(pctx, ctx)
intermediateDir := android.PathForModuleOut(ctx, "corpus")
+
+ // Create one rule per file to avoid MAX_ARG_STRLEN hardlimit.
for _, entry := range fuzzPackagedModule.Corpus {
- builder.Command().Text("cp").
- Input(entry).
- Output(intermediateDir.Join(ctx, entry.Base()))
+ ctx.Build(pctx, android.BuildParams{
+ Rule: android.Cp,
+ Output: intermediateDir.Join(ctx, entry.Base()),
+ Input: entry,
+ })
}
- builder.Build("copy_corpus", "copy corpus")
fuzzPackagedModule.CorpusIntermediateDir = intermediateDir
fuzzPackagedModule.Data = android.PathsForModuleSrc(ctx, fuzzPackagedModule.FuzzProperties.Data)
- builder = android.NewRuleBuilder(pctx, ctx)
intermediateDir = android.PathForModuleOut(ctx, "data")
+
+ // Create one rule per file to avoid MAX_ARG_STRLEN hardlimit.
for _, entry := range fuzzPackagedModule.Data {
- builder.Command().Text("cp").
- Input(entry).
- Output(intermediateDir.Join(ctx, entry.Rel()))
+ ctx.Build(pctx, android.BuildParams{
+ Rule: android.Cp,
+ Output: intermediateDir.Join(ctx, entry.Rel()),
+ Input: entry,
+ })
}
- builder.Build("copy_data", "copy data")
fuzzPackagedModule.DataIntermediateDir = intermediateDir
if fuzzPackagedModule.FuzzProperties.Dictionary != nil {
@@ -352,9 +357,10 @@
// their architecture & target/host specific zip file.
type ccRustFuzzPackager struct {
fuzz.FuzzPackager
- fuzzPackagingArchModules string
- fuzzTargetSharedDepsInstallPairs string
- allFuzzTargetsName string
+ fuzzPackagingArchModules string
+ fuzzTargetSharedDepsInstallPairs string
+ allFuzzTargetsName string
+ onlyIncludePresubmits bool
}
func fuzzPackagingFactory() android.Singleton {
@@ -363,6 +369,18 @@
fuzzPackagingArchModules: "SOONG_FUZZ_PACKAGING_ARCH_MODULES",
fuzzTargetSharedDepsInstallPairs: "FUZZ_TARGET_SHARED_DEPS_INSTALL_PAIRS",
allFuzzTargetsName: "ALL_FUZZ_TARGETS",
+ onlyIncludePresubmits: false,
+ }
+ return fuzzPackager
+}
+
+func fuzzPackagingFactoryPresubmit() android.Singleton {
+
+ fuzzPackager := &ccRustFuzzPackager{
+ fuzzPackagingArchModules: "SOONG_PRESUBMIT_FUZZ_PACKAGING_ARCH_MODULES",
+ fuzzTargetSharedDepsInstallPairs: "PRESUBMIT_FUZZ_TARGET_SHARED_DEPS_INSTALL_PAIRS",
+ allFuzzTargetsName: "ALL_PRESUBMIT_FUZZ_TARGETS",
+ onlyIncludePresubmits: true,
}
return fuzzPackager
}
@@ -386,7 +404,6 @@
if !ok || ccModule.PreventInstall() {
return
}
-
// Discard non-fuzz targets.
if ok := fuzz.IsValid(ccModule.FuzzModuleStruct()); !ok {
return
@@ -403,6 +420,9 @@
} else if ccModule.Host() {
hostOrTargetString = "host"
}
+ if s.onlyIncludePresubmits == true {
+ hostOrTargetString = "presubmit-" + hostOrTargetString
+ }
fpm := fuzz.FuzzPackagedModule{}
if ok {
@@ -427,6 +447,14 @@
// The executable.
files = append(files, fuzz.FileToZip{SourceFilePath: android.OutputFileForModule(ctx, ccModule, "unstripped")})
+ if s.onlyIncludePresubmits == true {
+ if fpm.FuzzProperties.Fuzz_config == nil {
+ return
+ }
+ if !BoolDefault(fpm.FuzzProperties.Fuzz_config.Use_for_presubmit, false){
+ return
+ }
+ }
archDirs[archOs], ok = s.BuildZipFile(ctx, module, fpm, files, builder, archDir, archString, hostOrTargetString, archOs, archDirs)
if !ok {
return
diff --git a/cc/generated_cc_library.go b/cc/generated_cc_library.go
new file mode 100644
index 0000000..55e19f9
--- /dev/null
+++ b/cc/generated_cc_library.go
@@ -0,0 +1,38 @@
+// Copyright 2023 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 cc
+
+import (
+ "android/soong/android"
+)
+
+func GeneratedCcLibraryModuleFactory(moduleName string, callbacks Generator) android.Module {
+ module, _ := NewLibrary(android.HostAndDeviceSupported)
+
+ // Can be used as both a static and a shared library.
+ module.sdkMemberTypes = []android.SdkMemberType{
+ sharedLibrarySdkMemberType,
+ staticLibrarySdkMemberType,
+ staticAndSharedLibrarySdkMemberType,
+ }
+
+ // TODO: Need to be bazelable
+ // module.bazelable = true
+ // module.bazelHandler = &ccLibraryBazelHandler{module: module}
+
+ module.generators = append(module.generators, callbacks)
+
+ return module.Init()
+}
diff --git a/cc/library.go b/cc/library.go
index aec6433..266fa75 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -1963,6 +1963,10 @@
libName := strings.TrimSuffix(baseName, filepath.Ext(baseName))
errorMessage := "error: Please update ABI references with: $$ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py -l " + libName + " -ref-dump-dir $$ANDROID_BUILD_TOP/" + refDumpDir
+ // Most opt-in libraries do not have dumps for all default architectures.
+ if ctx.Config().HasDeviceProduct() {
+ errorMessage += " -products " + ctx.Config().DeviceProduct()
+ }
library.sourceAbiDiff(ctx, referenceDump, baseName, nameExt,
isLlndkOrNdk, false /* allowExtensions */, "current", errorMessage)
@@ -2271,7 +2275,7 @@
// do not install vndk libs
// vndk libs are packaged into VNDK APEX
- if ctx.isVndk() && !ctx.IsVndkExt() {
+ if ctx.isVndk() && !ctx.IsVndkExt() && !ctx.Config().IsVndkDeprecated() {
return
}
} else if library.hasStubsVariants() && !ctx.Host() && ctx.directlyInAnyApex() {
diff --git a/cc/linkable.go b/cc/linkable.go
index 19e6501..2099399 100644
--- a/cc/linkable.go
+++ b/cc/linkable.go
@@ -87,6 +87,12 @@
// SnapshotStaticLibs returns the list of static library dependencies for this module.
SnapshotStaticLibs() []string
+ // SnapshotDylibs returns the list of dylib library dependencies for this module.
+ SnapshotDylibs() []string
+
+ // SnapshotRlibs returns the list of rlib library dependencies for this module.
+ SnapshotRlibs() []string
+
// IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt.
IsSnapshotPrebuilt() bool
}
@@ -239,6 +245,9 @@
// Dylib returns true if this is an dylib module.
Dylib() bool
+ // RlibStd returns true if this is an rlib which links against an rlib libstd.
+ RlibStd() bool
+
// Static returns true if this is a static library module.
Static() bool
diff --git a/cc/ndk_sysroot.go b/cc/ndk_sysroot.go
index 0cf21b6..feb3880 100644
--- a/cc/ndk_sysroot.go
+++ b/cc/ndk_sysroot.go
@@ -58,7 +58,6 @@
func init() {
RegisterNdkModuleTypes(android.InitRegistrationContext)
- pctx.Import("android/soong/android")
}
func RegisterNdkModuleTypes(ctx android.RegistrationContext) {
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 62e31d1..626005b 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -646,10 +646,6 @@
if (ctx.Arch().ArchType != android.Arm64 && ctx.Arch().ArchType != android.Riscv64) || !ctx.toolchain().Bionic() {
s.Scs = nil
}
- // ...but temporarily globally disabled on riscv64 (http://b/277909695).
- if ctx.Arch().ArchType == android.Riscv64 {
- s.Scs = nil
- }
// Memtag_heap is only implemented on AArch64.
// Memtag ABI is Android specific for now, so disable for host.
diff --git a/cc/snapshot_prebuilt.go b/cc/snapshot_prebuilt.go
index a5729df..bb13310 100644
--- a/cc/snapshot_prebuilt.go
+++ b/cc/snapshot_prebuilt.go
@@ -100,6 +100,7 @@
snapshotBinarySuffix = "_binary."
snapshotObjectSuffix = "_object."
SnapshotRlibSuffix = "_rlib."
+ SnapshotDylibSuffix = "_dylib."
)
type SnapshotProperties struct {
@@ -107,6 +108,7 @@
Static_libs []string `android:"arch_variant"`
Shared_libs []string `android:"arch_variant"`
Rlibs []string `android:"arch_variant"`
+ Dylibs []string `android:"arch_variant"`
Vndk_libs []string `android:"arch_variant"`
Binaries []string `android:"arch_variant"`
Objects []string `android:"arch_variant"`
@@ -186,6 +188,7 @@
staticLibs := collectSnapshotMap(s.properties.Static_libs, snapshotSuffix, SnapshotStaticSuffix)
sharedLibs := collectSnapshotMap(s.properties.Shared_libs, snapshotSuffix, SnapshotSharedSuffix)
rlibs := collectSnapshotMap(s.properties.Rlibs, snapshotSuffix, SnapshotRlibSuffix)
+ dylibs := collectSnapshotMap(s.properties.Dylibs, snapshotSuffix, SnapshotDylibSuffix)
vndkLibs := collectSnapshotMap(s.properties.Vndk_libs, "", vndkSuffix)
for k, v := range vndkLibs {
sharedLibs[k] = v
@@ -198,11 +201,12 @@
StaticLibs: staticLibs,
SharedLibs: sharedLibs,
Rlibs: rlibs,
+ Dylibs: dylibs,
})
}
type SnapshotInfo struct {
- HeaderLibs, Binaries, Objects, StaticLibs, SharedLibs, Rlibs map[string]string
+ HeaderLibs, Binaries, Objects, StaticLibs, SharedLibs, Rlibs, Dylibs map[string]string
}
var SnapshotInfoProvider = blueprint.NewMutatorProvider(SnapshotInfo{}, "deps")
diff --git a/cc/snapshot_utils.go b/cc/snapshot_utils.go
index cf4617d..1ee120e 100644
--- a/cc/snapshot_utils.go
+++ b/cc/snapshot_utils.go
@@ -57,6 +57,14 @@
return m.Properties.SnapshotStaticLibs
}
+func (m *Module) SnapshotRlibs() []string {
+ return []string{}
+}
+
+func (m *Module) SnapshotDylibs() []string {
+ return []string{}
+}
+
// snapshotLibraryInterface is an interface for libraries captured to VNDK / vendor snapshots.
type snapshotLibraryInterface interface {
libraryInterface
diff --git a/cc/util.go b/cc/util.go
index 6d8ac43..c93646b 100644
--- a/cc/util.go
+++ b/cc/util.go
@@ -28,8 +28,8 @@
return android.JoinWithPrefix(dirs.Strings(), "-I")
}
-var indexList = android.IndexList
-var inList = android.InList
+var indexList = android.IndexList[string]
+var inList = android.InList[string]
var filterList = android.FilterList
var removeListFromList = android.RemoveListFromList
var removeFromList = android.RemoveFromList
diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go
index d2531c0..9ea337b 100644
--- a/cc/vendor_snapshot.go
+++ b/cc/vendor_snapshot.go
@@ -108,10 +108,10 @@
return false
}
}
- if sanitizable.Static() {
+ if sanitizable.Static() || sanitizable.Rlib() {
return sanitizable.OutputFile().Valid() && !isPrivate(image, m)
}
- if sanitizable.Shared() || sanitizable.Rlib() {
+ if sanitizable.Shared() || sanitizable.Dylib() {
if !sanitizable.OutputFile().Valid() {
return false
}
@@ -153,6 +153,8 @@
SharedLibs []string `json:",omitempty"`
StaticLibs []string `json:",omitempty"`
RuntimeLibs []string `json:",omitempty"`
+ Dylibs []string `json:",omitempty"`
+ Rlibs []string `json:",omitempty"`
// extra config files
InitRc []string `json:",omitempty"`
@@ -283,8 +285,17 @@
if m.Shared() {
prop.SharedLibs = m.SnapshotSharedLibs()
}
- // static libs dependencies are required to collect the NOTICE files.
+
+ // dylibs collect both shared and dylib dependencies.
+ if m.Dylib() {
+ prop.SharedLibs = m.SnapshotSharedLibs()
+ prop.Dylibs = m.SnapshotDylibs()
+ }
+
+ // static and rlib libs dependencies are required to collect the NOTICE files.
prop.StaticLibs = m.SnapshotStaticLibs()
+ prop.Rlibs = m.SnapshotRlibs()
+
if sanitizable, ok := m.(PlatformSanitizeable); ok {
if sanitizable.Static() && sanitizable.SanitizePropDefined() {
prop.SanitizeMinimalDep = sanitizable.MinimalRuntimeDep() || sanitizable.MinimalRuntimeNeeded()
@@ -299,13 +310,15 @@
libType = "shared"
} else if m.Rlib() {
libType = "rlib"
+ } else if m.Dylib() {
+ libType = "dylib"
} else {
libType = "header"
}
var stem string
- // install .a or .so
+ // install .a, .rlib, .dylib.so, or .so
if libType != "header" {
libPath := m.OutputFile().Path()
stem = libPath.Base()
@@ -328,6 +341,12 @@
}
}
}
+ if m.Rlib() && m.RlibStd() {
+ // rlibs produce both rlib-std and dylib-std variants
+ ext := filepath.Ext(stem)
+ stem = strings.TrimSuffix(stem, ext) + ".rlib-std" + ext
+ prop.ModuleName += ".rlib-std"
+ }
snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, m.RelativeInstallPath(), stem)
ret = append(ret, copyFile(ctx, libPath, snapshotLibOut, fake))
} else {
@@ -341,8 +360,12 @@
prop.StaticExecutable = m.StaticExecutable()
prop.InstallInRoot = m.InstallInRoot()
prop.SharedLibs = m.SnapshotSharedLibs()
- // static libs dependencies are required to collect the NOTICE files.
+ prop.Dylibs = m.SnapshotDylibs()
+
+ // static and rlib dependencies are required to collect the NOTICE files.
prop.StaticLibs = m.SnapshotStaticLibs()
+ prop.Rlibs = m.SnapshotRlibs()
+
// install bin
binPath := m.OutputFile().Path()
snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base())
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go
index 22d64a2..5ea84bc 100644
--- a/cmd/soong_build/main.go
+++ b/cmd/soong_build/main.go
@@ -225,7 +225,7 @@
ninjaDeps = append(ninjaDeps, codegenContext.AdditionalNinjaDeps()...)
// Create soong_injection repository
- soongInjectionFiles, err := bp2build.CreateSoongInjectionDirFiles(codegenContext, bp2build.CreateCodegenMetrics())
+ soongInjectionFiles, workspaceFiles, err := bp2build.CreateSoongInjectionDirFiles(codegenContext, bp2build.CreateCodegenMetrics())
maybeQuit(err, "")
absoluteSoongInjectionDir := shared.JoinPath(topDir, ctx.Config().SoongOutDir(), bazel.SoongInjectionDirName)
for _, file := range soongInjectionFiles {
@@ -236,6 +236,9 @@
// to allow users to edit/experiment in the synthetic workspace.
writeReadWriteFile(absoluteSoongInjectionDir, file)
}
+ for _, file := range workspaceFiles {
+ writeReadWriteFile(absoluteApiBp2buildDir, file)
+ }
workspace := shared.JoinPath(ctx.Config().SoongOutDir(), "api_bp2build")
// Create the symlink forest
diff --git a/cmd/zip2zip/BUILD.bazel b/cmd/zip2zip/BUILD.bazel
deleted file mode 100644
index 1915a2d..0000000
--- a/cmd/zip2zip/BUILD.bazel
+++ /dev/null
@@ -1,18 +0,0 @@
-# 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.
-
-alias(
- name = "zip2zip",
- actual = "//prebuilts/build-tools:linux-x86/bin/zip2zip",
-)
diff --git a/fuzz/fuzz_common.go b/fuzz/fuzz_common.go
index ada4712..94b795f 100644
--- a/fuzz/fuzz_common.go
+++ b/fuzz/fuzz_common.go
@@ -371,6 +371,8 @@
// Specifies whether fuzz target should check presubmitted code changes for crashes.
// Defaults to false.
Use_for_presubmit *bool `json:"use_for_presubmit,omitempty"`
+ // Specify which paths to exclude from fuzzing coverage reports
+ Exclude_paths_from_reports []string `json:"exclude_paths_from_reports,omitempty"`
}
type FuzzFrameworks struct {
diff --git a/genrule/allowlists.go b/genrule/allowlists.go
index c6fa030..afa52cc 100644
--- a/genrule/allowlists.go
+++ b/genrule/allowlists.go
@@ -116,6 +116,25 @@
"aidl_camera_build_version",
"cronet_aml_base_android_runtime_unchecked_jni_headers",
"cronet_aml_base_android_runtime_jni_headers",
+ "aidl-golden-test-build-hook-gen",
+ "PacketStreamerStub_h",
+ "FrontendStub_cc",
+ "FrontendStub_h",
+ "PacketStreamerStub_cc",
+ "pixelstatsatoms.h",
+ "pixelatoms_defs.h",
+ "pixelstatsatoms.cpp",
+ "hidl_java_impl_test_gen",
+ "cronet_aml_base_android_runtime_jni_headers__testing",
+ "cronet_aml_base_android_runtime_unchecked_jni_headers__testing",
+ "hidl_cpp_impl_test_gen-sources",
+ "fdt_test_tree_multiple_memory_ranges_dtb",
+ "fdt_test_tree_one_memory_range_dtb",
+ "fdt_test_tree_empty_memory_range_dtb",
+ "ltp_config_arm_64_lowmem",
+ "ltp_config_arm_64_lowmem_hwasan",
+ "ltp_config_x86",
+ "libbssl_sys_src_nostd",
}
SandboxingDenyPathList = []string{
diff --git a/genrule/genrule.go b/genrule/genrule.go
index 99c9166..6306c27 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -151,6 +151,9 @@
// input files to exclude
Exclude_srcs []string `android:"path,arch_variant"`
+
+ // Enable restat to update the output only if the output is changed
+ Write_if_changed *bool
}
type Module struct {
@@ -293,6 +296,9 @@
for _, dir := range g.properties.Export_include_dirs {
g.exportedIncludeDirs = append(g.exportedIncludeDirs,
android.PathForModuleGen(ctx, g.subDir, ctx.ModuleDir(), dir))
+ // Also export without ModuleDir for consistency with Export_include_dirs not being set
+ g.exportedIncludeDirs = append(g.exportedIncludeDirs,
+ android.PathForModuleGen(ctx, g.subDir, dir))
}
} else {
g.exportedIncludeDirs = append(g.exportedIncludeDirs, android.PathForModuleGen(ctx, g.subDir))
@@ -467,6 +473,9 @@
// Use a RuleBuilder to create a rule that runs the command inside an sbox sandbox.
rule := getSandboxedRuleBuilder(ctx, android.NewRuleBuilder(pctx, ctx).Sbox(task.genDir, manifestPath))
+ if Bool(g.properties.Write_if_changed) {
+ rule.Restat()
+ }
cmd := rule.Command()
for _, out := range task.out {
diff --git a/genrule/genrule_test.go b/genrule/genrule_test.go
index 6301bbf..7c14531 100644
--- a/genrule/genrule_test.go
+++ b/genrule/genrule_test.go
@@ -845,6 +845,49 @@
result.ModuleForTests("gen_all", "").Module().(*useSource).srcs)
}
+func TestGenruleInterface(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ prepareForGenRuleTest,
+ android.FixtureMergeMockFs(android.MockFS{
+ "package-dir/Android.bp": []byte(`
+ genrule {
+ name: "module-name",
+ cmd: "mkdir -p $(genDir) && cat $(in) >> $(genDir)/$(out)",
+ srcs: [
+ "src/foo.proto",
+ ],
+ out: ["proto.h", "bar/proto.h"],
+ export_include_dirs: [".", "bar"],
+ }
+ `),
+ }),
+ ).RunTest(t)
+
+ exportedIncludeDirs := []string{
+ "out/soong/.intermediates/package-dir/module-name/gen/package-dir",
+ "out/soong/.intermediates/package-dir/module-name/gen",
+ "out/soong/.intermediates/package-dir/module-name/gen/package-dir/bar",
+ "out/soong/.intermediates/package-dir/module-name/gen/bar",
+ }
+ gen := result.Module("module-name", "").(*Module)
+
+ android.AssertPathsRelativeToTopEquals(
+ t,
+ "include path",
+ exportedIncludeDirs,
+ gen.GeneratedHeaderDirs(),
+ )
+ android.AssertPathsRelativeToTopEquals(
+ t,
+ "files",
+ []string{
+ "out/soong/.intermediates/package-dir/module-name/gen/proto.h",
+ "out/soong/.intermediates/package-dir/module-name/gen/bar/proto.h",
+ },
+ gen.GeneratedSourceFiles(),
+ )
+}
+
func TestGenSrcsWithNonRootAndroidBpOutputFiles(t *testing.T) {
result := android.GroupFixturePreparers(
prepareForGenRuleTest,
diff --git a/java/aar.go b/java/aar.go
index 01bd103..a682e3a 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -611,6 +611,8 @@
a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
+ a.stem = proptools.StringDefault(a.overridableDeviceProperties.Stem, ctx.ModuleName())
+
ctx.CheckbuildFile(a.proguardOptionsFile)
ctx.CheckbuildFile(a.exportPackage)
ctx.CheckbuildFile(a.aaptSrcJar)
@@ -986,6 +988,7 @@
TransitiveStaticLibsHeaderJars: a.transitiveStaticLibsHeaderJars,
ImplementationAndResourcesJars: android.PathsIfNonNil(a.classpathFile),
ImplementationJars: android.PathsIfNonNil(a.classpathFile),
+ // TransitiveAconfigFiles: // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
})
if proptools.Bool(a.properties.Extract_jni) {
diff --git a/java/androidmk.go b/java/androidmk.go
index 13cc96a..4fca08d 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -123,6 +123,8 @@
if library.dexpreopter.configPath != nil {
entries.SetPath("LOCAL_SOONG_DEXPREOPT_CONFIG", library.dexpreopter.configPath)
}
+
+ entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", library.getTransitiveAconfigFiles().ToList())
},
},
})
@@ -220,6 +222,7 @@
entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.combinedClasspathFile)
entries.SetString("LOCAL_SDK_VERSION", prebuilt.sdkVersion.String())
entries.SetString("LOCAL_MODULE_STEM", prebuilt.Stem())
+ // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
},
},
}}
@@ -244,6 +247,7 @@
entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", prebuilt.dexpreopter.builtInstalled)
}
entries.SetString("LOCAL_MODULE_STEM", prebuilt.Stem())
+ // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
},
},
}}
@@ -269,6 +273,7 @@
entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", prebuilt.extraAaptPackagesFile)
entries.SetPath("LOCAL_FULL_MANIFEST_FILE", prebuilt.manifest)
entries.SetString("LOCAL_SDK_VERSION", prebuilt.sdkVersion.String())
+ // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
},
},
}}
@@ -295,6 +300,7 @@
if len(binary.dexpreopter.builtInstalled) > 0 {
entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", binary.dexpreopter.builtInstalled)
}
+ entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", binary.getTransitiveAconfigFiles().ToList())
},
},
ExtraFooters: []android.AndroidMkExtraFootersFunc{
@@ -437,6 +443,10 @@
}
entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", app.linter.reports)
+
+ if app.Name() != "framework-res" {
+ entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", app.getTransitiveAconfigFiles().ToList())
+ }
},
},
ExtraFooters: []android.AndroidMkExtraFootersFunc{
@@ -455,11 +465,6 @@
if len(a.overridableAppProperties.Overrides) > 0 {
overridden = append(overridden, a.overridableAppProperties.Overrides...)
}
- // When APK name is overridden via PRODUCT_PACKAGE_NAME_OVERRIDES
- // ensure that the original name is overridden.
- if a.Stem() != a.installApkName {
- overridden = append(overridden, a.Stem())
- }
return overridden
}
@@ -517,6 +522,7 @@
entries.SetPath("LOCAL_FULL_MANIFEST_FILE", a.mergedManifestFile)
entries.AddStrings("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", a.exportedProguardFlagFiles.Strings()...)
entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true)
+ entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", a.getTransitiveAconfigFiles().ToList())
})
return entriesList
@@ -689,6 +695,7 @@
if Bool(a.properties.Export_package_resources) {
entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", a.outputFile)
}
+ // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
},
},
}}
@@ -722,6 +729,7 @@
entries.SetString("LOCAL_CERTIFICATE", r.certificate.AndroidMkString())
entries.SetPath("LOCAL_MODULE_PATH", r.installDir)
entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", r.properties.Overrides...)
+ // TODO: LOCAL_ACONFIG_FILES -- Might eventually need aconfig flags?
},
},
}}
@@ -739,6 +747,7 @@
entries.SetPath("LOCAL_APK_SET_INSTALL_FILE", apkSet.PackedAdditionalOutputs())
entries.SetPath("LOCAL_APKCERTS_FILE", apkSet.apkcertsFile)
entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", apkSet.properties.Overrides...)
+ // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts -- Both declarations and values
},
},
},
diff --git a/java/app.go b/java/app.go
index 25909ec..8e4efd2 100755
--- a/java/app.go
+++ b/java/app.go
@@ -666,8 +666,17 @@
a.aapt.useEmbeddedNativeLibs = a.useEmbeddedNativeLibs(ctx)
a.aapt.useEmbeddedDex = Bool(a.appProperties.Use_embedded_dex)
+ // Unlike installApkName, a.stem should respect base module name for override_android_app.
+ // Therefore, use ctx.ModuleName() instead of a.Name().
+ a.stem = proptools.StringDefault(a.overridableDeviceProperties.Stem, ctx.ModuleName())
+
// Check if the install APK name needs to be overridden.
- a.installApkName = ctx.DeviceConfig().OverridePackageNameFor(a.Stem())
+ // Both android_app and override_android_app module are expected to possess
+ // its module bound apk path. However, override_android_app inherits ctx.ModuleName()
+ // from the base module. Therefore, use a.Name() which represents
+ // the module name for both android_app and override_android_app.
+ a.installApkName = ctx.DeviceConfig().OverridePackageNameFor(
+ proptools.StringDefault(a.overridableDeviceProperties.Stem, a.Name()))
if ctx.ModuleName() == "framework-res" {
// framework-res.apk is installed as system/framework/framework-res.apk
diff --git a/java/app_import.go b/java/app_import.go
index e25bcd1..ad1765e 100644
--- a/java/app_import.go
+++ b/java/app_import.go
@@ -51,9 +51,9 @@
Description: "Uncompress dex files",
})
- checkJniAndDexLibsAreUncompressedRule = pctx.AndroidStaticRule("check-jni-and-dex-libs-are-uncompressed", blueprint.RuleParams{
+ checkDexLibsAreUncompressedRule = pctx.AndroidStaticRule("check-dex-libs-are-uncompressed", blueprint.RuleParams{
// grep -v ' stor ' will search for lines that don't have ' stor '. stor means the file is stored uncompressed
- Command: "if (zipinfo $in 'lib/*.so' '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then " +
+ Command: "if (zipinfo $in '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then " +
"echo $in: Contains compressed JNI libraries and/or dex files >&2;" +
"exit 1; " +
"else " +
@@ -61,6 +61,17 @@
"fi",
Description: "Check for compressed JNI libs or dex files",
})
+
+ checkJniLibsAreUncompressedRule = pctx.AndroidStaticRule("check-jni-libs-are-uncompressed", blueprint.RuleParams{
+ // grep -v ' stor ' will search for lines that don't have ' stor '. stor means the file is stored uncompressed
+ Command: "if (zipinfo $in 'lib/*.so' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then " +
+ "echo $in: Contains compressed JNI libraries >&2;" +
+ "exit 1; " +
+ "else " +
+ "touch $out; " +
+ "fi",
+ Description: "Check for compressed JNI libs or dex files",
+ })
)
func RegisterAppImportBuildComponents(ctx android.RegistrationContext) {
@@ -384,26 +395,40 @@
}
func (a *AndroidAppImport) validatePreprocessedApk(ctx android.ModuleContext, srcApk android.Path, dstApk android.WritablePath) {
+ var validations android.Paths
+
alignmentStamp := android.PathForModuleOut(ctx, "validated-prebuilt", "alignment.stamp")
ctx.Build(pctx, android.BuildParams{
Rule: checkZipAlignment,
Input: srcApk,
Output: alignmentStamp,
})
- compressionStamp := android.PathForModuleOut(ctx, "validated-prebuilt", "compression.stamp")
+
+ validations = append(validations, alignmentStamp)
+ jniCompressionStamp := android.PathForModuleOut(ctx, "validated-prebuilt", "jni_compression.stamp")
ctx.Build(pctx, android.BuildParams{
- Rule: checkJniAndDexLibsAreUncompressedRule,
+ Rule: checkJniLibsAreUncompressedRule,
Input: srcApk,
- Output: compressionStamp,
+ Output: jniCompressionStamp,
})
+ validations = append(validations, jniCompressionStamp)
+
+ if a.Privileged() {
+ // It's ok for non-privileged apps to have compressed dex files, see go/gms-uncompressed-jni-slides
+ dexCompressionStamp := android.PathForModuleOut(ctx, "validated-prebuilt", "dex_compression.stamp")
+ ctx.Build(pctx, android.BuildParams{
+ Rule: checkDexLibsAreUncompressedRule,
+ Input: srcApk,
+ Output: dexCompressionStamp,
+ })
+ validations = append(validations, dexCompressionStamp)
+ }
+
ctx.Build(pctx, android.BuildParams{
- Rule: android.Cp,
- Input: srcApk,
- Output: dstApk,
- Validations: []android.Path{
- alignmentStamp,
- compressionStamp,
- },
+ Rule: android.Cp,
+ Input: srcApk,
+ Output: dstApk,
+ Validations: validations,
})
}
diff --git a/java/base.go b/java/base.go
index cb08ef3..6a532da 100644
--- a/java/base.go
+++ b/java/base.go
@@ -21,6 +21,7 @@
"strings"
"android/soong/ui/metrics/bp2build_metrics_proto"
+
"github.com/google/blueprint/pathtools"
"github.com/google/blueprint/proptools"
@@ -502,6 +503,19 @@
sourceExtensions []string
annoSrcJars android.Paths
+
+ // output file name based on Stem property.
+ // This should be set in every ModuleWithStem's GenerateAndroidBuildActions
+ // or the module should override Stem().
+ stem string
+
+ // Aconfig "cache files" that went directly into this module. Transitive ones are
+ // tracked via JavaInfo.TransitiveAconfigFiles
+ // TODO: Extract to something standalone to propagate tags via GeneratedJavaLibraryModule
+ aconfigIntermediates android.Paths
+
+ // Aconfig files for all transitive deps. Also exposed via JavaInfo
+ transitiveAconfigFiles *android.DepSet[android.Path]
}
func (j *Module) CheckStableSdkVersion(ctx android.BaseModuleContext) error {
@@ -1099,7 +1113,7 @@
j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
}
- jarName := ctx.ModuleName() + ".jar"
+ jarName := j.Stem() + ".jar"
var uniqueJavaFiles android.Paths
set := make(map[string]bool)
@@ -1617,6 +1631,8 @@
ctx.CheckbuildFile(outputFile)
+ j.collectTransitiveAconfigFiles(ctx)
+
ctx.SetProvider(JavaInfoProvider, JavaInfo{
HeaderJars: android.PathsIfNonNil(j.headerJarFile),
TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars,
@@ -1631,6 +1647,7 @@
ExportedPluginClasses: j.exportedPluginClasses,
ExportedPluginDisableTurbine: j.exportedDisableTurbine,
JacocoReportClassesFile: j.jacocoReportClassesFile,
+ TransitiveAconfigFiles: j.transitiveAconfigFiles,
})
// Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
@@ -1897,7 +1914,10 @@
}
func (j *Module) Stem() string {
- return proptools.StringDefault(j.overridableDeviceProperties.Stem, j.Name())
+ if j.stem == "" {
+ panic("Stem() called before stem property was set")
+ }
+ return j.stem
}
func (j *Module) JacocoReportClassesFile() android.Path {
@@ -1908,6 +1928,34 @@
return Bool(j.properties.Installable)
}
+func (j *Module) collectTransitiveAconfigFiles(ctx android.ModuleContext) {
+ // Aconfig files from this module
+ mine := j.aconfigIntermediates
+
+ // Aconfig files from transitive dependencies
+ fromDeps := []*android.DepSet[android.Path]{}
+ ctx.VisitDirectDeps(func(module android.Module) {
+ dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
+ if dep.TransitiveAconfigFiles != nil {
+ fromDeps = append(fromDeps, dep.TransitiveAconfigFiles)
+ }
+ })
+
+ // DepSet containing aconfig files myself and from dependencies
+ j.transitiveAconfigFiles = android.NewDepSet(android.POSTORDER, mine, fromDeps)
+}
+
+func (j *Module) AddAconfigIntermediate(path android.Path) {
+ j.aconfigIntermediates = append(j.aconfigIntermediates, path)
+}
+
+func (j *Module) getTransitiveAconfigFiles() *android.DepSet[android.Path] {
+ if j.transitiveAconfigFiles == nil {
+ panic(fmt.Errorf("java.Moduile: getTransitiveAconfigFiles called before collectTransitiveAconfigFiles module=%s", j.Name()))
+ }
+ return j.transitiveAconfigFiles
+}
+
type sdkLinkType int
const (
diff --git a/java/builder.go b/java/builder.go
index be4af55..94a6b84 100644
--- a/java/builder.go
+++ b/java/builder.go
@@ -42,7 +42,7 @@
// TODO(b/143658984): goma can't handle the --system argument to javac.
javac, javacRE = pctx.MultiCommandRemoteStaticRules("javac",
blueprint.RuleParams{
- Command: `rm -rf "$outDir" "$annoDir" "$annoSrcJar" "$srcJarDir" "$out" && ` +
+ Command: `rm -rf "$outDir" "$annoDir" "$annoSrcJar.tmp" "$srcJarDir" "$out.tmp" && ` +
`mkdir -p "$outDir" "$annoDir" "$srcJarDir" && ` +
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
`(if [ -s $srcJarDir/list ] || [ -s $out.rsp ] ; then ` +
@@ -51,8 +51,10 @@
`$processorpath $processor $javacFlags $bootClasspath $classpath ` +
`-source $javaVersion -target $javaVersion ` +
`-d $outDir -s $annoDir @$out.rsp @$srcJarDir/list ; fi ) && ` +
- `$annoSrcJarTemplate${config.SoongZipCmd} -jar -o $annoSrcJar -C $annoDir -D $annoDir && ` +
- `$zipTemplate${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir && ` +
+ `$annoSrcJarTemplate${config.SoongZipCmd} -jar -o $annoSrcJar.tmp -C $annoDir -D $annoDir && ` +
+ `$zipTemplate${config.SoongZipCmd} -jar -o $out.tmp -C $outDir -D $outDir && ` +
+ `if ! cmp -s "$out.tmp" "$out"; then mv "$out.tmp" "$out"; fi && ` +
+ `if ! cmp -s "$annoSrcJar.tmp" "$annoSrcJar"; then mv "$annoSrcJar.tmp" "$annoSrcJar"; fi && ` +
`rm -rf "$srcJarDir"`,
CommandDeps: []string{
"${config.JavacCmd}",
@@ -60,6 +62,7 @@
"${config.ZipSyncCmd}",
},
CommandOrderOnly: []string{"${config.SoongJavacWrapper}"},
+ Restat: true,
Rspfile: "$out.rsp",
RspfileContent: "$in",
}, map[string]*remoteexec.REParams{
@@ -71,14 +74,14 @@
"$zipTemplate": &remoteexec.REParams{
Labels: map[string]string{"type": "tool", "name": "soong_zip"},
Inputs: []string{"${config.SoongZipCmd}", "$outDir"},
- OutputFiles: []string{"$out"},
+ OutputFiles: []string{"$out.tmp"},
ExecStrategy: "${config.REJavacExecStrategy}",
Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
},
"$annoSrcJarTemplate": &remoteexec.REParams{
Labels: map[string]string{"type": "tool", "name": "soong_zip"},
Inputs: []string{"${config.SoongZipCmd}", "$annoDir"},
- OutputFiles: []string{"$annoSrcJar"},
+ OutputFiles: []string{"$annoSrcJar.tmp"},
ExecStrategy: "${config.REJavacExecStrategy}",
Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
},
diff --git a/java/device_host_converter.go b/java/device_host_converter.go
index 3581040..5460dc9 100644
--- a/java/device_host_converter.go
+++ b/java/device_host_converter.go
@@ -143,6 +143,8 @@
ResourceJars: d.resourceJars,
SrcJarArgs: d.srcJarArgs,
SrcJarDeps: d.srcJarDeps,
+ // TODO: Not sure if aconfig flags that have been moved between device and host variants
+ // make sense.
})
}
diff --git a/java/generated_java_library.go b/java/generated_java_library.go
index 1b3de9f..f9baa85 100644
--- a/java/generated_java_library.go
+++ b/java/generated_java_library.go
@@ -30,7 +30,7 @@
// Called from inside GenerateAndroidBuildActions. Add the build rules to
// make the srcjar, and return the path to it.
- GenerateSourceJarBuildActions(ctx android.ModuleContext) android.Path
+ GenerateSourceJarBuildActions(module *GeneratedJavaLibraryModule, ctx android.ModuleContext) android.Path
}
// GeneratedJavaLibraryModuleFactory provides a utility for modules that are generated
@@ -88,7 +88,7 @@
checkPropertyEmpty(ctx, module, "plugins", module.Library.properties.Plugins)
checkPropertyEmpty(ctx, module, "exported_plugins", module.Library.properties.Exported_plugins)
- srcJarPath := module.callbacks.GenerateSourceJarBuildActions(ctx)
+ srcJarPath := module.callbacks.GenerateSourceJarBuildActions(module, ctx)
module.Library.properties.Generated_srcjars = append(module.Library.properties.Generated_srcjars, srcJarPath)
module.Library.GenerateAndroidBuildActions(ctx)
}
diff --git a/java/generated_java_library_test.go b/java/generated_java_library_test.go
index 68f1f7e..7f52fd1 100644
--- a/java/generated_java_library_test.go
+++ b/java/generated_java_library_test.go
@@ -36,7 +36,8 @@
func (callbacks *JavaGenLibTestCallbacks) DepsMutator(module *GeneratedJavaLibraryModule, ctx android.BottomUpMutatorContext) {
}
-func (callbacks *JavaGenLibTestCallbacks) GenerateSourceJarBuildActions(ctx android.ModuleContext) android.Path {
+func (callbacks *JavaGenLibTestCallbacks) GenerateSourceJarBuildActions(module *GeneratedJavaLibraryModule, ctx android.ModuleContext) android.Path {
+ module.AddAconfigIntermediate(android.PathForOutput(ctx, "aconfig_cache_file"))
return android.PathForOutput(ctx, "blah.srcjar")
}
diff --git a/java/java.go b/java/java.go
index 2ed1130..20d9afc 100644
--- a/java/java.go
+++ b/java/java.go
@@ -274,7 +274,14 @@
// instrumented by jacoco.
JacocoReportClassesFile android.Path
- // TODO: Add device config declarations here?
+ // set of aconfig flags for all transitive libs deps
+ // TODO(joeo): It would be nice if this were over in the aconfig package instead of here.
+ // In order to do that, generated_java_library would need a way doing
+ // collectTransitiveAconfigFiles with one of the callbacks, and having that automatically
+ // propagated. If we were to clean up more of the stuff on JavaInfo that's not part of
+ // core java rules (e.g. AidlIncludeDirs), then maybe adding more framework to do that would be
+ // worth it.
+ TransitiveAconfigFiles *android.DepSet[android.Path]
}
var JavaInfoProvider = blueprint.NewProvider(JavaInfo{})
@@ -676,6 +683,8 @@
j.minSdkVersion = j.MinSdkVersion(ctx)
j.maxSdkVersion = j.MaxSdkVersion(ctx)
+ j.stem = proptools.StringDefault(j.overridableDeviceProperties.Stem, ctx.ModuleName())
+
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
if !apexInfo.IsForPlatform() {
j.hideApexVariantFromMake = true
@@ -728,6 +737,7 @@
}
})
j.exportedProguardFlagFiles = android.FirstUniquePaths(j.exportedProguardFlagFiles)
+
}
func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
@@ -1468,6 +1478,8 @@
}
func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ j.stem = proptools.StringDefault(j.overridableDeviceProperties.Stem, ctx.ModuleName())
+
if ctx.Arch().ArchType == android.Common {
// Compile the jar
if j.binaryProperties.Main_class != nil {
@@ -1912,6 +1924,7 @@
ImplementationAndResourcesJars: android.PathsIfNonNil(al.stubsJar),
ImplementationJars: android.PathsIfNonNil(al.stubsJar),
AidlIncludeDirs: android.Paths{},
+ // No aconfig libraries on api libraries
})
}
@@ -2233,6 +2246,7 @@
ImplementationAndResourcesJars: android.PathsIfNonNil(j.combinedClasspathFile),
ImplementationJars: android.PathsIfNonNil(j.combinedClasspathFile),
AidlIncludeDirs: j.exportAidlIncludeDirs,
+ // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
})
}
@@ -2653,7 +2667,7 @@
var Bool = proptools.Bool
var BoolDefault = proptools.BoolDefault
var String = proptools.String
-var inList = android.InList
+var inList = android.InList[string]
// Add class loader context (CLC) of a given dependency to the current CLC.
func addCLCFromDep(ctx android.ModuleContext, depModule android.Module,
@@ -3304,7 +3318,8 @@
HeaderJars: android.PathsIfNonNil(i.combinedClasspathFile),
ImplementationAndResourcesJars: android.PathsIfNonNil(i.combinedClasspathFile),
ImplementationJars: android.PathsIfNonNil(i.combinedClasspathFile),
- //TODO(b/240308299) include AIDL information from Bazel
+ // TODO(b/240308299) include AIDL information from Bazel
+ // TODO: aconfig files?
})
i.maybeInstall(ctx, jarName, outputFile)
diff --git a/java/java_test.go b/java/java_test.go
index 4738304..dd98677 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -2351,3 +2351,22 @@
`stable.core.platform.api.stubs`,
})
}
+
+func TestJavaLibraryWithResourcesStem(t *testing.T) {
+ ctx, _ := testJavaWithFS(t, `
+ java_library {
+ name: "foo",
+ java_resource_dirs: ["test-jar"],
+ stem: "test",
+ }
+ `,
+ map[string][]byte{
+ "test-jar/test/resource.txt": nil,
+ })
+
+ m := ctx.ModuleForTests("foo", "android_common")
+ outputs := fmt.Sprint(m.AllOutputs())
+ if !strings.Contains(outputs, "test.jar") {
+ t.Errorf("Module output does not contain expected jar %s", "test.jar")
+ }
+}
diff --git a/rust/binary.go b/rust/binary.go
index 2de92c1..e6f1539 100644
--- a/rust/binary.go
+++ b/rust/binary.go
@@ -158,9 +158,6 @@
// Binaries default to dylib dependencies for device, rlib for host.
if binary.preferRlib() {
return rlibAutoDep
- } else if mod, ok := ctx.Module().(*Module); ok && mod.InVendor() {
- // Vendor Rust binaries should prefer rlibs.
- return rlibAutoDep
} else if ctx.Device() {
return dylibAutoDep
} else {
@@ -171,8 +168,6 @@
func (binary *binaryDecorator) stdLinkage(ctx *depsContext) RustLinkage {
if binary.preferRlib() {
return RlibLinkage
- } else if ctx.RustModule().InVendor() {
- return RlibLinkage
}
return binary.baseCompiler.stdLinkage(ctx)
}
diff --git a/rust/bindgen.go b/rust/bindgen.go
index 7dc1b4b..59585aa 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-r487747c"
+ bindgenClangVersion = "clang-r498229"
_ = pctx.VariableFunc("bindgenClangVersion", func(ctx android.PackageVarContext) string {
if override := ctx.Config().Getenv("LLVM_BINDGEN_PREBUILTS_VERSION"); override != "" {
diff --git a/rust/image.go b/rust/image.go
index 50bf02a..53fb5c0 100644
--- a/rust/image.go
+++ b/rust/image.go
@@ -220,9 +220,6 @@
}
func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
- // Rust does not support installing to the product image yet.
- vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
-
if Bool(mod.VendorProperties.Double_loadable) {
mctx.PropertyErrorf("double_loadable",
"Rust modules do not yet support double loading")
@@ -232,11 +229,6 @@
mctx.PropertyErrorf("vendor_ramdisk_available", "cannot be set for rust_ffi or rust_ffi_shared modules.")
}
}
- if vendorSpecific {
- if lib, ok := mod.compiler.(libraryInterface); ok && lib.buildDylib() {
- mctx.PropertyErrorf("vendor", "Vendor-only dylibs are not yet supported, use rust_library_rlib.")
- }
- }
if mctx.ProductSpecific() {
if lib, ok := mod.compiler.(libraryInterface); ok && lib.buildDylib() {
mctx.PropertyErrorf("product", "Product-only dylibs are not yet supported, use rust_library_rlib.")
diff --git a/rust/library.go b/rust/library.go
index 331763a..3f480a2 100644
--- a/rust/library.go
+++ b/rust/library.go
@@ -21,7 +21,6 @@
"android/soong/android"
"android/soong/cc"
- "android/soong/snapshot"
)
var (
@@ -236,10 +235,7 @@
}
func (library *libraryDecorator) autoDep(ctx android.BottomUpMutatorContext) autoDep {
- if ctx.Module().(*Module).InVendor() {
- // Vendor modules should statically link libstd.
- return rlibAutoDep
- } else if library.preferRlib() {
+ if library.preferRlib() {
return rlibAutoDep
} else if library.rlib() || library.static() {
return rlibAutoDep
@@ -251,10 +247,7 @@
}
func (library *libraryDecorator) stdLinkage(ctx *depsContext) RustLinkage {
- if ctx.RustModule().InVendor() {
- // Vendor modules should statically link libstd.
- return RlibLinkage
- } else if library.static() || library.MutatedProperties.VariantIsStaticStd {
+ if library.static() || library.MutatedProperties.VariantIsStaticStd {
return RlibLinkage
} else if library.baseCompiler.preferRlib() {
return RlibLinkage
@@ -693,24 +686,6 @@
v.(*Module).Disable()
}
- variation := v.(*Module).ModuleBase.ImageVariation().Variation
- if strings.HasPrefix(variation, cc.VendorVariationPrefix) {
- // TODO(b/204303985)
- // Disable vendor dylibs until they are supported
- v.(*Module).Disable()
- }
-
- if strings.HasPrefix(variation, cc.VendorVariationPrefix) &&
- m.HasVendorVariant() &&
- !snapshot.IsVendorProprietaryModule(mctx) &&
- strings.TrimPrefix(variation, cc.VendorVariationPrefix) == mctx.DeviceConfig().VndkVersion() {
-
- // cc.MutateImage runs before LibraryMutator, so vendor variations which are meant for rlibs only are
- // produced for Dylibs; however, dylibs should not be enabled for boardVndkVersion for
- // non-vendor proprietary modules.
- v.(*Module).Disable()
- }
-
case "source":
v.(*Module).compiler.(libraryInterface).setSource()
// The source variant does not produce any library.
@@ -747,10 +722,9 @@
dylib := modules[1].(*Module)
rlib.compiler.(libraryInterface).setRlibStd()
dylib.compiler.(libraryInterface).setDylibStd()
- if dylib.ModuleBase.ImageVariation().Variation == android.VendorRamdiskVariation ||
- strings.HasPrefix(dylib.ModuleBase.ImageVariation().Variation, cc.VendorVariationPrefix) {
+ if dylib.ModuleBase.ImageVariation().Variation == android.VendorRamdiskVariation {
// TODO(b/165791368)
- // Disable rlibs that link against dylib-std on vendor and vendor ramdisk variations until those dylib
+ // Disable rlibs that link against dylib-std on vendor ramdisk variations until those dylib
// variants are properly supported.
dylib.Disable()
}
diff --git a/rust/rust.go b/rust/rust.go
index e524c9f..05fceee 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -43,6 +43,7 @@
android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel()
})
+ pctx.Import("android/soong/android")
pctx.Import("android/soong/rust/config")
pctx.ImportAs("cc_config", "android/soong/cc/config")
android.InitRegistrationContext.RegisterParallelSingletonType("kythe_rust_extract", kytheExtractRustFactory)
@@ -91,6 +92,8 @@
// Used by vendor snapshot to record dependencies from snapshot modules.
SnapshotSharedLibs []string `blueprint:"mutated"`
SnapshotStaticLibs []string `blueprint:"mutated"`
+ SnapshotRlibs []string `blueprint:"mutated"`
+ SnapshotDylibs []string `blueprint:"mutated"`
// Make this module available when building for ramdisk.
// On device without a dedicated recovery partition, the module is only
@@ -258,6 +261,15 @@
return false
}
+func (mod *Module) RlibStd() bool {
+ if mod.compiler != nil {
+ if library, ok := mod.compiler.(libraryInterface); ok && library.rlib() {
+ return library.rlibStd()
+ }
+ }
+ panic(fmt.Errorf("RlibStd() called on non-rlib module: %q", mod.BaseModuleName()))
+}
+
func (mod *Module) Rlib() bool {
if mod.compiler != nil {
if library, ok := mod.compiler.(libraryInterface); ok {
@@ -1225,6 +1237,8 @@
}
directDylibDeps = append(directDylibDeps, rustDep)
mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName)
+ mod.Properties.SnapshotDylibs = append(mod.Properties.SnapshotDylibs, cc.BaseLibName(depName))
+
case rlibDepTag:
rlib, ok := rustDep.compiler.(libraryInterface)
@@ -1234,6 +1248,8 @@
}
directRlibDeps = append(directRlibDeps, rustDep)
mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, makeLibName)
+ mod.Properties.SnapshotRlibs = append(mod.Properties.SnapshotRlibs, cc.BaseLibName(depName))
+
case procMacroDepTag:
directProcMacroDeps = append(directProcMacroDeps, rustDep)
mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName)
@@ -1518,10 +1534,10 @@
}
// dylibs
- actx.AddVariationDependencies(
- append(commonDepVariations, []blueprint.Variation{
- {Mutator: "rust_libraries", Variation: dylibVariation}}...),
- dylibDepTag, deps.Dylibs...)
+ dylibDepVariations := append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: dylibVariation})
+ for _, lib := range deps.Dylibs {
+ addDylibDependency(actx, lib, mod, &snapshotInfo, dylibDepVariations, dylibDepTag)
+ }
// rustlibs
if deps.Rustlibs != nil && !mod.compiler.Disabled() {
@@ -1536,8 +1552,11 @@
// otherwise select the rlib variant.
autoDepVariations := append(commonDepVariations,
blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation})
- if actx.OtherModuleDependencyVariantExists(autoDepVariations, lib) {
- actx.AddVariationDependencies(autoDepVariations, autoDep.depTag, lib)
+
+ replacementLib := cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Dylibs)
+
+ if actx.OtherModuleDependencyVariantExists(autoDepVariations, replacementLib) {
+ addDylibDependency(actx, lib, mod, &snapshotInfo, autoDepVariations, autoDep.depTag)
} else {
// If there's no dylib dependency available, try to add the rlib dependency instead.
addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations)
@@ -1549,16 +1568,14 @@
if deps.Stdlibs != nil {
if mod.compiler.stdLinkage(ctx) == RlibLinkage {
for _, lib := range deps.Stdlibs {
- depTag := rlibDepTag
lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs)
-
actx.AddVariationDependencies(append(commonDepVariations, []blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}...),
- depTag, lib)
+ rlibDepTag, lib)
}
} else {
- actx.AddVariationDependencies(
- append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"}),
- dylibDepTag, deps.Stdlibs...)
+ for _, lib := range deps.Stdlibs {
+ addDylibDependency(actx, lib, mod, &snapshotInfo, dylibDepVariations, dylibDepTag)
+ }
}
}
@@ -1636,6 +1653,11 @@
actx.AddVariationDependencies(variations, rlibDepTag, lib)
}
+func addDylibDependency(actx android.BottomUpMutatorContext, lib string, mod *Module, snapshotInfo **cc.SnapshotInfo, variations []blueprint.Variation, depTag dependencyTag) {
+ lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, snapshotInfo, actx).Dylibs)
+ actx.AddVariationDependencies(variations, depTag, lib)
+}
+
func BeginMutator(ctx android.BottomUpMutatorContext) {
if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() {
mod.beginMutator(ctx)
diff --git a/rust/rust_test.go b/rust/rust_test.go
index 64f90b6..3f4e296 100644
--- a/rust/rust_test.go
+++ b/rust/rust_test.go
@@ -79,14 +79,18 @@
}
const (
- sharedVendorVariant = "android_vendor.29_arm64_armv8-a_shared"
- rlibVendorVariant = "android_vendor.29_arm64_armv8-a_rlib_rlib-std"
- sharedRecoveryVariant = "android_recovery_arm64_armv8-a_shared"
- rlibRecoveryVariant = "android_recovery_arm64_armv8-a_rlib_rlib-std"
- binaryCoreVariant = "android_arm64_armv8-a"
- binaryVendorVariant = "android_vendor.29_arm64_armv8-a"
- binaryProductVariant = "android_product.29_arm64_armv8-a"
- binaryRecoveryVariant = "android_recovery_arm64_armv8-a"
+ sharedVendorVariant = "android_vendor.29_arm64_armv8-a_shared"
+ rlibVendorVariant = "android_vendor.29_arm64_armv8-a_rlib_rlib-std"
+ rlibDylibStdVendorVariant = "android_vendor.29_arm64_armv8-a_rlib_rlib-std"
+ dylibVendorVariant = "android_vendor.29_arm64_armv8-a_dylib"
+ sharedRecoveryVariant = "android_recovery_arm64_armv8-a_shared"
+ rlibRecoveryVariant = "android_recovery_arm64_armv8-a_rlib_dylib-std"
+ rlibRlibStdRecoveryVariant = "android_recovery_arm64_armv8-a_rlib_rlib-std"
+ dylibRecoveryVariant = "android_recovery_arm64_armv8-a_dylib"
+ binaryCoreVariant = "android_arm64_armv8-a"
+ binaryVendorVariant = "android_vendor.29_arm64_armv8-a"
+ binaryProductVariant = "android_product.29_arm64_armv8-a"
+ binaryRecoveryVariant = "android_recovery_arm64_armv8-a"
)
func testRustVndkFs(t *testing.T, bp string, fs android.MockFS) *android.TestContext {
diff --git a/rust/snapshot_prebuilt.go b/rust/snapshot_prebuilt.go
index 2f79cc5..32d3916 100644
--- a/rust/snapshot_prebuilt.go
+++ b/rust/snapshot_prebuilt.go
@@ -21,10 +21,6 @@
"github.com/google/blueprint/proptools"
)
-const (
- snapshotRlibSuffix = "_rlib."
-)
-
type snapshotLibraryDecorator struct {
cc.BaseSnapshotDecorator
*libraryDecorator
@@ -44,6 +40,8 @@
func registerRustSnapshotModules(ctx android.RegistrationContext) {
cc.VendorSnapshotImageSingleton.RegisterAdditionalModule(ctx,
"vendor_snapshot_rlib", VendorSnapshotRlibFactory)
+ cc.VendorSnapshotImageSingleton.RegisterAdditionalModule(ctx,
+ "vendor_snapshot_dylib", VendorSnapshotDylibFactory)
cc.RecoverySnapshotImageSingleton.RegisterAdditionalModule(ctx,
"recovery_snapshot_rlib", RecoverySnapshotRlibFactory)
}
@@ -77,12 +75,11 @@
variant = cc.SnapshotSharedSuffix
} else if library.rlib() {
variant = cc.SnapshotRlibSuffix
+ } else if library.dylib() {
+ variant = cc.SnapshotDylibSuffix
}
- if !library.dylib() {
- // TODO(184042776): Remove this check when dylibs are supported in snapshots.
- library.SetSnapshotAndroidMkSuffix(ctx, variant)
- }
+ library.SetSnapshotAndroidMkSuffix(ctx, variant)
if !library.MatchesWithDevice(ctx.DeviceConfig()) {
return buildOutput{}
@@ -107,6 +104,17 @@
return module.Init()
}
+// vendor_snapshot_dylib is a special prebuilt dylib library which is auto-generated by
+// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_dylib
+// overrides the vendor variant of the rust dylib library with the same name, if BOARD_VNDK_VERSION
+// is set.
+func VendorSnapshotDylibFactory() android.Module {
+ module, prebuilt := snapshotLibraryFactory(cc.VendorSnapshotImageSingleton, cc.SnapshotDylibSuffix)
+ prebuilt.libraryDecorator.BuildOnlyDylib()
+ prebuilt.libraryDecorator.setNoStdlibs()
+ return module.Init()
+}
+
func RecoverySnapshotRlibFactory() android.Module {
module, prebuilt := snapshotLibraryFactory(cc.RecoverySnapshotImageSingleton, cc.SnapshotRlibSuffix)
prebuilt.libraryDecorator.BuildOnlyRlib()
diff --git a/rust/snapshot_utils.go b/rust/snapshot_utils.go
index 8dabd9b..55c85e6 100644
--- a/rust/snapshot_utils.go
+++ b/rust/snapshot_utils.go
@@ -42,8 +42,7 @@
func (mod *Module) IsSnapshotLibrary() bool {
if lib, ok := mod.compiler.(libraryInterface); ok {
- // Rust-native dylibs are not snapshot supported yet. Only snapshot the rlib-std variants of rlibs.
- return lib.shared() || lib.static() || (lib.rlib() && lib.rlibStd())
+ return lib.shared() || lib.static() || lib.rlib() || lib.dylib()
}
return false
}
@@ -61,6 +60,14 @@
return mod.Properties.SnapshotStaticLibs
}
+func (mod *Module) SnapshotRlibs() []string {
+ return mod.Properties.SnapshotRlibs
+}
+
+func (mod *Module) SnapshotDylibs() []string {
+ return mod.Properties.SnapshotDylibs
+}
+
func (mod *Module) Symlinks() []string {
// TODO update this to return the list of symlinks when Rust supports defining symlinks
return nil
diff --git a/rust/vendor_snapshot_test.go b/rust/vendor_snapshot_test.go
index 2e7a330..387d170 100644
--- a/rust/vendor_snapshot_test.go
+++ b/rust/vendor_snapshot_test.go
@@ -48,15 +48,13 @@
crate_name: "rustvendor_available",
srcs: ["lib.rs"],
vendor_available: true,
- include_dirs: ["rust_headers/"],
}
- rust_library_rlib {
+ rust_library {
name: "librustvendor",
crate_name: "rustvendor",
srcs: ["lib.rs"],
vendor: true,
- include_dirs: ["rust_headers/"],
}
rust_binary {
@@ -116,7 +114,7 @@
filepath.Join(staticDir, "libffivendor.a.json"))
// For rlib libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
- rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
+ rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_dylib-std", archType, archVariant)
rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib", rlibDir, rlibVariant)
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor", "librustvendor.rlib", rlibDir, rlibVariant)
@@ -125,6 +123,25 @@
jsonFiles = append(jsonFiles,
filepath.Join(rlibDir, "librustvendor.rlib.json"))
+ // For rlib libraries, all rlib-std variants vendor:true and vendor_available modules (including VNDK) are captured.
+ rlibStdVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib-std.rlib", rlibDir, rlibStdVariant)
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor", "librustvendor.rlib-std.rlib", rlibDir, rlibStdVariant)
+ jsonFiles = append(jsonFiles,
+ filepath.Join(rlibDir, "librustvendor_available.rlib.json"))
+ jsonFiles = append(jsonFiles,
+ filepath.Join(rlibDir, "librustvendor.rlib.json"))
+
+ // For dylib libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
+ dylibVariant := fmt.Sprintf("android_vendor.29_%s_%s_dylib", archType, archVariant)
+ dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.dylib.so", dylibDir, dylibVariant)
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor", "librustvendor.dylib.so", dylibDir, dylibVariant)
+ jsonFiles = append(jsonFiles,
+ filepath.Join(dylibDir, "librustvendor_available.dylib.so.json"))
+ jsonFiles = append(jsonFiles,
+ filepath.Join(dylibDir, "librustvendor.dylib.so.json"))
+
// For binary executables, all vendor:true and vendor_available modules are captured.
if archType == "arm64" {
binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
@@ -209,21 +226,32 @@
archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
- rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
+ rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_dylib-std", archType, archVariant)
+ rlibRlibStdVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
+ dylibVariant := fmt.Sprintf("android_vendor.29_%s_%s_dylib", archType, archVariant)
+ dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
// Included modules
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib", rlibDir, rlibVariant)
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.dylib.so", dylibDir, dylibVariant)
cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor_available", "libffivendor_available.so", sharedDir, sharedVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_available.rlib.json"))
+ includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_available.rlib-std.rlib.json"))
+ includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librustvendor_available.dylib.so.json"))
includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libffivendor_available.so.json"))
// Excluded modules. Modules not included in the directed vendor snapshot
// are still include as fake modules.
cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librustvendor_exclude", "librustvendor_exclude.rlib", rlibDir, rlibVariant)
+ cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librustvendor_exclude", "librustvendor_exclude.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
+ cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librustvendor_exclude", "librustvendor_exclude.dylib.so", dylibDir, dylibVariant)
cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "libffivendor_exclude", "libffivendor_exclude.so", sharedDir, sharedVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_exclude.rlib.json"))
+ includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_exclude.rlib-std.rlib.json"))
+ includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librustvendor_exclude.dylib.so.json"))
includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libffivendor_exclude.so.json"))
}
@@ -274,7 +302,7 @@
vendor_available: true,
}
- rust_library_rlib {
+ rust_library {
name: "librust_exclude",
crate_name: "rust_exclude",
srcs: ["exclude.rs"],
@@ -308,6 +336,14 @@
cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_exclude", true, rlibVendorVariant)
cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_available_exclude", true, rlibVendorVariant)
+ cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_include", false, rlibDylibStdVendorVariant)
+ cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_exclude", true, rlibDylibStdVendorVariant)
+ cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_available_exclude", true, rlibDylibStdVendorVariant)
+
+ cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_include", false, dylibVendorVariant)
+ cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_exclude", true, dylibVendorVariant)
+ cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_available_exclude", true, dylibVendorVariant)
+
// Verify the content of the vendor snapshot.
snapshotDir := "vendor-snapshot"
@@ -327,14 +363,22 @@
sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
- rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
+
+ rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_dylib-std", archType, archVariant)
+ rlibRlibStdVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
+ dylibVariant := fmt.Sprintf("android_vendor.29_%s_%s_dylib", archType, archVariant)
+ dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
// Included modules
cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librust_include", "librust_include.rlib", rlibDir, rlibVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librust_include.rlib.json"))
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "librust_include", "librust_include.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
+ includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librust_include.rlib-std.rlib.json"))
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "librust_include", "librust_include.dylib.so", dylibDir, dylibVariant)
+ includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librust_include.dylib.so.json"))
// Excluded modules
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
@@ -345,6 +389,12 @@
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_exclude.rlib.json"))
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_available_exclude", "librust_available_exclude.rlib", rlibDir, rlibVariant)
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_available_exclude.rlib.json"))
+ cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_available_exclude", "librust_available_exclude.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
+ excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_available_exclude.rlib.rlib-std.json"))
+ cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_exclude", "librust_exclude.dylib.so", dylibDir, dylibVariant)
+ excludeJsonFiles = append(excludeJsonFiles, filepath.Join(dylibDir, "librust_exclude.dylib.so.json"))
+ cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_available_exclude", "librust_available_exclude.dylib.so", dylibDir, dylibVariant)
+ excludeJsonFiles = append(excludeJsonFiles, filepath.Join(dylibDir, "librust_available_exclude.dylib.so.json"))
}
// Verify that each json file for an included module has a rule.
@@ -525,7 +575,7 @@
srcs: ["client.rs"],
}
- rust_library_rlib {
+ rust_library {
name: "libclient_rust",
crate_name: "client_rust",
vendor: true,
@@ -572,6 +622,11 @@
rlibs: [
"libstd",
"librust_vendor_available",
+ "librust_vendor_available.rlib-std"
+ ],
+ dylibs: [
+ "libstd",
+ "librust_vendor_available",
],
binaries: [
"bin",
@@ -600,6 +655,10 @@
"libstd",
"librust_vendor_available",
],
+ dylibs: [
+ "libstd",
+ "librust_vendor_available",
+ ],
binaries: [
"bin32",
],
@@ -679,6 +738,52 @@
},
}
+ vendor_snapshot_rlib {
+ name: "librust_vendor_available.rlib-std",
+ version: "30",
+ target_arch: "arm64",
+ vendor: true,
+ arch: {
+ arm64: {
+ src: "librust_vendor_available.rlib-std.rlib",
+ },
+ arm: {
+ src: "librust_vendor_available.rlib-std.rlib",
+ },
+ },
+ }
+
+ vendor_snapshot_dylib {
+ name: "libstd",
+ version: "30",
+ target_arch: "arm64",
+ vendor: true,
+ sysroot: true,
+ arch: {
+ arm64: {
+ src: "libstd.dylib.so",
+ },
+ arm: {
+ src: "libstd.dylib.so",
+ },
+ },
+ }
+
+ vendor_snapshot_dylib {
+ name: "librust_vendor_available",
+ version: "30",
+ target_arch: "arm64",
+ vendor: true,
+ arch: {
+ arm64: {
+ src: "librust_vendor_available.dylib.so",
+ },
+ arm: {
+ src: "librust_vendor_available.dylib.so",
+ },
+ },
+ }
+
vendor_snapshot_object {
name: "crtend_android",
version: "30",
@@ -921,6 +1026,9 @@
"vendor/liblog.so": nil,
"vendor/libstd.rlib": nil,
"vendor/librust_vendor_available.rlib": nil,
+ "vendor/librust_vendor_available.rlib-std.rlib": nil,
+ "vendor/libstd.dylib.so": nil,
+ "vendor/librust_vendor_available.dylib.so": nil,
"vendor/crtbegin_so.o": nil,
"vendor/crtend_so.o": nil,
"vendor/libclang_rt.builtins-aarch64-android.a": nil,
@@ -931,7 +1039,9 @@
}
sharedVariant := "android_vendor.30_arm64_armv8-a_shared"
- rlibVariant := "android_vendor.30_arm64_armv8-a_rlib_rlib-std"
+ rlibVariant := "android_vendor.30_arm64_armv8-a_rlib_dylib-std"
+ rlibRlibStdVariant := "android_vendor.30_arm64_armv8-a_rlib_rlib-std"
+ dylibVariant := "android_vendor.30_arm64_armv8-a_dylib"
staticVariant := "android_vendor.30_arm64_armv8-a_static"
binaryVariant := "android_vendor.30_arm64_armv8-a"
@@ -963,14 +1073,9 @@
t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
}
- libclientAndroidMkRlibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkRlibs
- if g, w := libclientAndroidMkRlibs, []string{"librust_vendor_available.vendor.rlib-std", "libstd.vendor"}; !reflect.DeepEqual(g, w) {
- t.Errorf("wanted libclient libclientAndroidMkRlibs %q, got %q", w, g)
- }
-
libclientAndroidMkDylibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkDylibs
- if len(libclientAndroidMkDylibs) > 0 {
- t.Errorf("wanted libclient libclientAndroidMkDylibs [], got %q", libclientAndroidMkDylibs)
+ if g, w := libclientAndroidMkDylibs, []string{"librust_vendor_available.vendor", "libstd.vendor"}; !reflect.DeepEqual(g, w) {
+ t.Errorf("wanted libclient libclientAndroidMkDylibs %q, got %q", w, libclientAndroidMkDylibs)
}
libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).Properties.AndroidMkSharedLibs
@@ -979,22 +1084,39 @@
}
libclientRustAndroidMkRlibs := ctx.ModuleForTests("libclient_rust", rlibVariant).Module().(*Module).Properties.AndroidMkRlibs
- if g, w := libclientRustAndroidMkRlibs, []string{"librust_vendor_available.vendor.rlib-std", "libstd.vendor"}; !reflect.DeepEqual(g, w) {
- t.Errorf("wanted libclient libclientAndroidMkRlibs %q, got %q", w, g)
+ if g, w := libclientRustAndroidMkRlibs, []string{"librust_vendor_available.vendor"}; !reflect.DeepEqual(g, w) {
+ t.Errorf("wanted rlib libclient libclientAndroidMkRlibs %q, got %q", w, g)
+ }
+
+ libclientRlibStdRustAndroidMkRlibs := ctx.ModuleForTests("libclient_rust", rlibRlibStdVariant).Module().(*Module).Properties.AndroidMkRlibs
+ if g, w := libclientRlibStdRustAndroidMkRlibs, []string{"librust_vendor_available.vendor.rlib-std", "libstd.vendor"}; !reflect.DeepEqual(g, w) {
+ t.Errorf("wanted rlib libclient libclientAndroidMkRlibs %q, got %q", w, g)
+ }
+
+ libclientRustDylibAndroidMkDylibs := ctx.ModuleForTests("libclient_rust", dylibVariant).Module().(*Module).Properties.AndroidMkDylibs
+ if g, w := libclientRustDylibAndroidMkDylibs, []string{"librust_vendor_available.vendor", "libstd.vendor"}; !reflect.DeepEqual(g, w) {
+ t.Errorf("wanted dylib libclient libclientRustDylibAndroidMkDylibs %q, got %q", w, g)
}
// rust vendor snapshot must have ".vendor" suffix in AndroidMk
librustVendorAvailableSnapshotModule := ctx.ModuleForTests("librust_vendor_available.vendor_rlib.30.arm64", rlibVariant).Module()
librustVendorSnapshotMkName := android.AndroidMkEntriesForTest(t, ctx, librustVendorAvailableSnapshotModule)[0].EntryMap["LOCAL_MODULE"][0]
- expectedRustVendorSnapshotName := "librust_vendor_available.vendor.rlib-std"
+ expectedRustVendorSnapshotName := "librust_vendor_available.vendor"
if librustVendorSnapshotMkName != expectedRustVendorSnapshotName {
t.Errorf("Unexpected rust vendor snapshot name in AndroidMk: %q, expected: %q\n", librustVendorSnapshotMkName, expectedRustVendorSnapshotName)
}
+ librustVendorAvailableDylibSnapshotModule := ctx.ModuleForTests("librust_vendor_available.vendor_dylib.30.arm64", dylibVariant).Module()
+ librustVendorSnapshotDylibMkName := android.AndroidMkEntriesForTest(t, ctx, librustVendorAvailableDylibSnapshotModule)[0].EntryMap["LOCAL_MODULE"][0]
+ expectedRustVendorDylibSnapshotName := "librust_vendor_available.vendor"
+ if librustVendorSnapshotDylibMkName != expectedRustVendorDylibSnapshotName {
+ t.Errorf("Unexpected rust vendor snapshot name in AndroidMk: %q, expected: %q\n", librustVendorSnapshotDylibMkName, expectedRustVendorDylibSnapshotName)
+ }
+
rustVendorBinModule := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Module()
- rustVendorBinMkRlibName := android.AndroidMkEntriesForTest(t, ctx, rustVendorBinModule)[0].EntryMap["LOCAL_RLIB_LIBRARIES"][0]
- if rustVendorBinMkRlibName != expectedRustVendorSnapshotName {
- t.Errorf("Unexpected rust rlib name in AndroidMk: %q, expected: %q\n", rustVendorBinMkRlibName, expectedRustVendorSnapshotName)
+ rustVendorBinMkDylibName := android.AndroidMkEntriesForTest(t, ctx, rustVendorBinModule)[0].EntryMap["LOCAL_DYLIB_LIBRARIES"][0]
+ if rustVendorBinMkDylibName != expectedRustVendorSnapshotName {
+ t.Errorf("Unexpected rust rlib name in AndroidMk: %q, expected: %q\n", rustVendorBinMkDylibName, expectedRustVendorSnapshotName)
}
binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("rustLink").Args["linkFlags"]
@@ -1051,18 +1173,18 @@
crate_name: "recovery_available",
}
- rust_library_rlib {
- name: "librecovery_rlib",
+ rust_library {
+ name: "librecovery_rustlib",
recovery: true,
srcs: ["foo.rs"],
- crate_name: "recovery_rlib",
+ crate_name: "recovery_rustlib",
}
- rust_library_rlib {
- name: "librecovery_available_rlib",
+ rust_library {
+ name: "librecovery_available_rustlib",
recovery_available: true,
srcs: ["foo.rs"],
- crate_name: "recovery_available_rlib",
+ crate_name: "recovery_available_rustlib",
}
rust_binary {
@@ -1113,13 +1235,29 @@
filepath.Join(staticDir, "librecovery_available.a.json"))
// For rlib libraries, all recovery:true and recovery_available modules are captured.
- rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
+ rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_dylib-std", archType, archVariant)
rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rlib", "librecovery_rlib.rlib", rlibDir, rlibVariant)
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rlib", "librecovery_available_rlib.rlib", rlibDir, rlibVariant)
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib", rlibDir, rlibVariant)
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib", rlibDir, rlibVariant)
jsonFiles = append(jsonFiles,
- filepath.Join(rlibDir, "librecovery_rlib.rlib.json"),
- filepath.Join(rlibDir, "librecovery_available_rlib.rlib.json"))
+ filepath.Join(rlibDir, "librecovery_rustlib.rlib.json"),
+ filepath.Join(rlibDir, "librecovery_available_rustlib.rlib.json"))
+
+ rlibRlibStdVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
+ jsonFiles = append(jsonFiles,
+ filepath.Join(rlibDir, "librecovery_rustlib.rlib-std.rlib.json"),
+ filepath.Join(rlibDir, "librecovery_available_rustlib.rlib-std.rlib.json"))
+
+ // For dylib libraries, all recovery:true and recovery_available modules are captured.
+ dylibVariant := fmt.Sprintf("android_recovery_%s_%s_dylib", archType, archVariant)
+ dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.dylib.so", dylibDir, dylibVariant)
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.dylib.so", dylibDir, dylibVariant)
+ jsonFiles = append(jsonFiles,
+ filepath.Join(dylibDir, "librecovery_rustlib.dylib.so.json"),
+ filepath.Join(dylibDir, "librecovery_available_rustlib.dylib.so.json"))
// For binary executables, all recovery:true and recovery_available modules are captured.
if archType == "arm64" {
@@ -1169,25 +1307,25 @@
exclude_from_recovery_snapshot: true,
crate_name: "available_exclude",
}
- rust_library_rlib {
- name: "libinclude_rlib",
+ rust_library {
+ name: "libinclude_rustlib",
srcs: ["src/include.rs"],
recovery_available: true,
- crate_name: "include_rlib",
+ crate_name: "include_rustlib",
}
- rust_library_rlib {
- name: "libexclude_rlib",
+ rust_library {
+ name: "libexclude_rustlib",
srcs: ["src/exclude.rs"],
recovery: true,
exclude_from_recovery_snapshot: true,
- crate_name: "exclude_rlib",
+ crate_name: "exclude_rustlib",
}
- rust_library_rlib {
- name: "libavailable_exclude_rlib",
+ rust_library {
+ name: "libavailable_exclude_rustlib",
srcs: ["src/exclude.rs"],
recovery_available: true,
exclude_from_recovery_snapshot: true,
- crate_name: "available_exclude_rlib",
+ crate_name: "available_exclude_rustlib",
}
`
@@ -1198,11 +1336,11 @@
recovery: true,
crate_name: "recovery",
}
- rust_library_rlib {
- name: "librecovery_rlib",
+ rust_library {
+ name: "librecovery_rustlib",
srcs: ["recovery.rs"],
recovery: true,
- crate_name: "recovery_rlib",
+ crate_name: "recovery_rustlib",
}
`
@@ -1220,14 +1358,25 @@
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false, sharedRecoveryVariant)
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true, sharedRecoveryVariant)
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true, sharedRecoveryVariant)
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rlib", false, rlibRecoveryVariant)
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rlib", true, rlibRecoveryVariant)
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rlib", true, rlibRecoveryVariant)
+
+ cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rustlib", false, rlibRecoveryVariant)
+ cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rustlib", true, rlibRecoveryVariant)
+ cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rustlib", true, rlibRlibStdRecoveryVariant)
+
+ cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rustlib", false, rlibRlibStdRecoveryVariant)
+ cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rustlib", true, rlibRlibStdRecoveryVariant)
+ cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rustlib", true, rlibRlibStdRecoveryVariant)
+
+ cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rustlib", false, dylibRecoveryVariant)
+ cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rustlib", true, dylibRecoveryVariant)
+ cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rustlib", true, dylibRecoveryVariant)
// A recovery module is excluded, but by its path not the exclude_from_recovery_snapshot property
// ('device/' and 'vendor/' are default excluded). See snapshot/recovery_snapshot.go for more detail.
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false, sharedRecoveryVariant)
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rlib", false, rlibRecoveryVariant)
+ cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rustlib", false, rlibRecoveryVariant)
+ cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rustlib", false, rlibRlibStdRecoveryVariant)
+ cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rustlib", false, dylibRecoveryVariant)
// Verify the content of the recovery snapshot.
@@ -1246,15 +1395,21 @@
archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
- rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
+ rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_dylib-std", archType, archVariant)
+ rlibRlibStdVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
+ dylibVariant := fmt.Sprintf("android_recovery_%s_%s_dylib", archType, archVariant)
sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
+ dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
// Included modules
+
cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude_rlib", "libinclude_rlib.rlib", rlibDir, rlibVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "libinclude_rlib.rlib.json"))
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude_rustlib", "libinclude_rustlib.rlib", rlibDir, rlibVariant)
+ includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "libinclude_rustlib.rlib.json"))
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude_rustlib", "libinclude_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
+ includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "libinclude_rustlib.rlib-std.rlib.json"))
// Excluded modules
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
@@ -1263,12 +1418,27 @@
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rlib", "libexclude_rlib.rlib", rlibDir, rlibVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rlib.rlib.json"))
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rlib", "librecovery_rlib.rlib", rlibDir, rlibVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rlib.rlib.json"))
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rlib", "libavailable_exclude_rlib.rlib", rlibDir, rlibVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rlib.rlib.json"))
+
+ cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rustlib", "libexclude_rustlib.rlib", rlibDir, rlibVariant)
+ excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rustlib.rlib.json"))
+ cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib", rlibDir, rlibVariant)
+ excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib.json"))
+ cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rustlib", "libavailable_exclude_rustlib.rlib", rlibDir, rlibVariant)
+ excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rustlib.rlib.json"))
+
+ cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rustlib", "libexclude_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
+ excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rustlib.rlib-std.rlib.json"))
+ cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
+ excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib-std.rlib.json"))
+ cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rustlib", "libavailable_exclude_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
+ excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rustlib.rlib-std.rlib.json"))
+
+ cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rustlib", "libexclude_rustlib.dylib.so", dylibDir, dylibVariant)
+ excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rustlib.dylib.so.json"))
+ cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.dylib.so", dylibDir, dylibVariant)
+ excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.dylib.so.json"))
+ cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rustlib", "libavailable_exclude_rustlib.dylib.so", dylibDir, dylibVariant)
+ excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rustlib.dylib.so.json"))
}
// Verify that each json file for an included module has a rule.
@@ -1302,15 +1472,15 @@
srcs: ["foo.rs"],
}
- rust_library_rlib {
- name: "librecovery_rlib",
+ rust_library {
+ name: "librecovery_rustlib",
recovery: true,
crate_name: "recovery",
srcs: ["foo.rs"],
}
- rust_library_rlib {
- name: "librecovery_available_rlib",
+ rust_library {
+ name: "librecovery_available_rustlib",
recovery_available: true,
crate_name: "recovery_available",
srcs: ["foo.rs"],
@@ -1335,7 +1505,7 @@
ctx := testRustRecoveryFsVersions(t, bp, rustMockedFiles, "current", "29", "current")
ctx.Config().TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
ctx.Config().TestProductVariables.RecoverySnapshotModules["librecovery"] = true
- ctx.Config().TestProductVariables.RecoverySnapshotModules["librecovery_rlib"] = true
+ ctx.Config().TestProductVariables.RecoverySnapshotModules["librecovery_rustlib"] = true
ctx.Config().TestProductVariables.DirectedRecoverySnapshot = true
// Check recovery snapshot output.
@@ -1353,15 +1523,22 @@
archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
- rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
+ rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_dylib-std", archType, archVariant)
+ rlibRlibStdVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
+ dylibVariant := fmt.Sprintf("android_recovery_%s_%s_dylib", archType, archVariant)
sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
+ dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
// Included modules
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rlib", "librecovery_rlib.rlib", rlibDir, rlibVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_rlib.rlib.json"))
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib", rlibDir, rlibVariant)
+ includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib.json"))
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
+ includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib-std.rlib.json"))
+ cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.dylib.so", dylibDir, dylibVariant)
+ includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librecovery_rustlib.dylib.so.json"))
// TODO: When Rust supports the "prefer" property for prebuilts, perform this check.
/*
@@ -1374,8 +1551,12 @@
// are still included as fake modules.
cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
- cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rlib", "librecovery_available_rlib.rlib", rlibDir, rlibVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_available_rlib.rlib.json"))
+ cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib", rlibDir, rlibVariant)
+ includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_available_rustlib.rlib.json"))
+ cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
+ includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_available_rustlib.rlib-std.rlib.json"))
+ cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.dylib.so", dylibDir, dylibVariant)
+ includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librecovery_available_rustlib.dylib.so.json"))
}
// Verify that each json file for an included module has a rule.
diff --git a/starlark_import/unmarshal.go b/starlark_import/unmarshal.go
index 1b54437..33c0cd9 100644
--- a/starlark_import/unmarshal.go
+++ b/starlark_import/unmarshal.go
@@ -25,12 +25,14 @@
)
func Unmarshal[T any](value starlark.Value) (T, error) {
- var zero T
- x, err := UnmarshalReflect(value, reflect.TypeOf(zero))
+ x, err := UnmarshalReflect(value, reflect.TypeOf((*T)(nil)).Elem())
return x.Interface().(T), err
}
func UnmarshalReflect(value starlark.Value, ty reflect.Type) (reflect.Value, error) {
+ if ty == reflect.TypeOf((*starlark.Value)(nil)).Elem() {
+ return reflect.ValueOf(value), nil
+ }
zero := reflect.Zero(ty)
var result reflect.Value
if ty.Kind() == reflect.Interface {
@@ -286,3 +288,14 @@
return nil, fmt.Errorf("unimplemented starlark type: %s", value.Type())
}
}
+
+// UnmarshalNoneable is like Unmarshal, but it will accept None as the top level (but not nested)
+// starlark value. If the value is None, a nil pointer will be returned, otherwise a pointer
+// to the result of Unmarshal will be returned.
+func UnmarshalNoneable[T any](value starlark.Value) (*T, error) {
+ if _, ok := value.(starlark.NoneType); ok {
+ return nil, nil
+ }
+ ret, err := Unmarshal[T](value)
+ return &ret, err
+}
diff --git a/starlark_import/unmarshal_test.go b/starlark_import/unmarshal_test.go
index ee7a9e3..bc0ea4c 100644
--- a/starlark_import/unmarshal_test.go
+++ b/starlark_import/unmarshal_test.go
@@ -30,7 +30,7 @@
return result["x"]
}
-func TestUnmarshallConcreteType(t *testing.T) {
+func TestUnmarshalConcreteType(t *testing.T) {
x, err := Unmarshal[string](createStarlarkValue(t, `"foo"`))
if err != nil {
t.Error(err)
@@ -41,7 +41,7 @@
}
}
-func TestUnmarshallConcreteTypeWithInterfaces(t *testing.T) {
+func TestUnmarshalConcreteTypeWithInterfaces(t *testing.T) {
x, err := Unmarshal[map[string]map[string]interface{}](createStarlarkValue(t,
`{"foo": {"foo2": "foo3"}, "bar": {"bar2": ["bar3"]}}`))
if err != nil {
@@ -57,7 +57,22 @@
}
}
-func TestUnmarshall(t *testing.T) {
+func TestUnmarshalToStarlarkValue(t *testing.T) {
+ x, err := Unmarshal[map[string]starlark.Value](createStarlarkValue(t,
+ `{"foo": "Hi", "bar": None}`))
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ if x["foo"].(starlark.String).GoString() != "Hi" {
+ t.Errorf("Expected \"Hi\", got: %q", x["foo"].(starlark.String).GoString())
+ }
+ if x["bar"].Type() != "NoneType" {
+ t.Errorf("Expected \"NoneType\", got: %q", x["bar"].Type())
+ }
+}
+
+func TestUnmarshal(t *testing.T) {
testCases := []struct {
input string
expected interface{}
diff --git a/tests/lib.sh b/tests/lib.sh
index 4aaf272..40b317b 100644
--- a/tests/lib.sh
+++ b/tests/lib.sh
@@ -147,6 +147,7 @@
symlink_directory external/bazelbuild-rules_go
symlink_directory external/bazelbuild-rules_license
symlink_directory external/bazelbuild-kotlin-rules
+ symlink_directory external/bazelbuild-rules_java
symlink_file WORKSPACE
symlink_file BUILD
diff --git a/tests/run_integration_tests.sh b/tests/run_integration_tests.sh
index 43a9f0f..48f654e 100755
--- a/tests/run_integration_tests.sh
+++ b/tests/run_integration_tests.sh
@@ -10,7 +10,7 @@
"$TOP/build/soong/tests/persistent_bazel_test.sh"
"$TOP/build/soong/tests/soong_test.sh"
"$TOP/build/soong/tests/stale_metrics_files_test.sh"
-"$TOP/build/bazel/ci/rbc_regression_test.sh" aosp_arm64-userdebug
+"$TOP/prebuilts/build-tools/linux-x86/bin/py3-cmd" "$TOP/build/bazel/ci/rbc_dashboard.py" aosp_arm64-userdebug
# The following tests build against the full source tree and don't rely on the
# mock client.
diff --git a/tests/sbom_test.sh b/tests/sbom_test.sh
index 1241e89..afec6b1 100755
--- a/tests/sbom_test.sh
+++ b/tests/sbom_test.sh
@@ -85,7 +85,13 @@
lz4=$out_dir/host/linux-x86/bin/lz4
declare -A diff_excludes
- diff_excludes[vendor]="-I /vendor/lib64/libkeystore2_crypto.so"
+ diff_excludes[product]="\
+ -I /product/etc/aconfig_flags.textproto \
+ -I /product/etc/build_flags.json"
+ diff_excludes[vendor]="\
+ -I /vendor/lib64/libkeystore2_crypto.so \
+ -I /vendor/etc/aconfig_flags.textproto \
+ -I /vendor/etc/build_flags.json"
diff_excludes[system]="\
-I /bin \
-I /bugreports \
@@ -105,6 +111,8 @@
-I /odm/priv-app \
-I /odm/usr \
-I /sdcard \
+ -I /system/etc/aconfig_flags.textproto \
+ -I /system/etc/build_flags.json \
-I /system/lib64/android.hardware.confirmationui@1.0.so \
-I /system/lib64/android.hardware.confirmationui-V1-ndk.so \
-I /system/lib64/android.hardware.keymaster@4.1.so \
@@ -134,6 +142,9 @@
-I /system/lib/vndk-sp-29 \
-I /system/usr/icu \
-I /vendor_dlkm/etc"
+ diff_excludes[system_ext]="\
+ -I /system_ext/etc/aconfig_flags.textproto \
+ -I /system_ext/etc/build_flags.json"
# Example output of dump.erofs is as below, and the data used in the test start
# at line 11. Column 1 is inode id, column 2 is inode type and column 3 is name.
diff --git a/zip/cmd/BUILD.bazel b/zip/cmd/BUILD.bazel
deleted file mode 100644
index e04a1e1..0000000
--- a/zip/cmd/BUILD.bazel
+++ /dev/null
@@ -1,20 +0,0 @@
-# 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.
-
-# TODO(b/194644518): Switch to the source version when Bazel can build go
-# binaries.
-alias(
- name = "soong_zip",
- actual = "//prebuilts/build-tools:linux-x86/bin/soong_zip",
-)