Merge "Use hardlinks for Bazel's symlink actions"
diff --git a/Android.bp b/Android.bp
index d6260b4..b5ddaa4 100644
--- a/Android.bp
+++ b/Android.bp
@@ -62,6 +62,7 @@
},
},
notice: ":mingw-libwinpthread-notice",
+ licenses: ["winpthreads_license"],
}
kernel_headers {
diff --git a/android/androidmk.go b/android/androidmk.go
index 967c550..feaef1f 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -836,6 +836,7 @@
case "*aidl.aidlApi": // writes non-custom before adding .phony
case "*aidl.aidlMapping": // writes non-custom before adding .phony
case "*android.customModule": // appears in tests only
+ case "*android_sdk.sdkRepoHost": // doesn't go through base_rules
case "*apex.apexBundle": // license properties written
case "*bpf.bpf": // license properties written (both for module and objs)
case "*genrule.Module": // writes non-custom before adding .phony
diff --git a/android/bazel.go b/android/bazel.go
index e4eaa37..91ca969 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -243,6 +243,11 @@
"brotli-fuzzer-corpus", // b/202015218: outputs are in location incompatible with bazel genrule handling.
+ // b/203369847: multiple genrules in the same package creating the same file
+ // //development/sdk/...
+ "platform_tools_properties",
+ "build_tools_source_properties",
+
// //external/libcap/...
"libcap", // http://b/198595332, depends on _makenames, a cc_binary
"cap_names.h", // http://b/198596102, depends on _makenames, a cc_binary
diff --git a/android/module.go b/android/module.go
index 327e6ae..02706ec 100644
--- a/android/module.go
+++ b/android/module.go
@@ -2818,11 +2818,13 @@
}
func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, executable bool) PackagingSpec {
+ licenseFiles := m.Module().EffectiveLicenseFiles()
spec := PackagingSpec{
- relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
- srcPath: srcPath,
- symlinkTarget: "",
- executable: executable,
+ relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
+ srcPath: srcPath,
+ symlinkTarget: "",
+ executable: executable,
+ effectiveLicenseFiles: &licenseFiles,
}
m.packagingSpecs = append(m.packagingSpecs, spec)
return spec
diff --git a/android/neverallow.go b/android/neverallow.go
index b8517a9..9098a71 100644
--- a/android/neverallow.go
+++ b/android/neverallow.go
@@ -150,6 +150,7 @@
func createJavaDeviceForHostRules() []Rule {
javaDeviceForHostProjectsAllowedList := []string{
+ "development/build",
"external/guava",
"external/robolectric-shadows",
"frameworks/layoutlib",
diff --git a/android/notices.go b/android/notices.go
index 07cf3e4..d8cfaf2 100644
--- a/android/notices.go
+++ b/android/notices.go
@@ -100,3 +100,56 @@
HtmlGzOutput: OptionalPathForPath(htmlGzOutput),
}
}
+
+// BuildNotices merges the supplied NOTICE files into a single file that lists notices
+// for every key in noticeMap (which would normally be installed files).
+func BuildNotices(ctx ModuleContext, noticeMap map[string]Paths) NoticeOutputs {
+ // TODO(jungjw): We should just produce a well-formatted NOTICE.html file in a single pass.
+ //
+ // generate-notice-files.py, which processes the merged NOTICE file, has somewhat strict rules
+ // about input NOTICE file paths.
+ // 1. Their relative paths to the src root become their NOTICE index titles. We want to use
+ // on-device paths as titles, and so output the merged NOTICE file the corresponding location.
+ // 2. They must end with .txt extension. Otherwise, they're ignored.
+
+ mergeTool := PathForSource(ctx, "build/soong/scripts/mergenotice.py")
+ generateNoticeTool := PathForSource(ctx, "build/soong/scripts/generate-notice-files.py")
+
+ outputDir := PathForModuleOut(ctx, "notices")
+ builder := NewRuleBuilder(pctx, ctx).
+ Sbox(outputDir, PathForModuleOut(ctx, "notices.sbox.textproto"))
+ for _, installPath := range SortedStringKeys(noticeMap) {
+ noticePath := outputDir.Join(ctx, installPath+".txt")
+ // It would be nice if sbox created directories for temporaries, but until then
+ // this is simple enough.
+ builder.Command().
+ Text("(cd").OutputDir().Text("&&").
+ Text("mkdir -p").Text(filepath.Dir(installPath)).Text(")")
+ builder.Temporary(noticePath)
+ builder.Command().
+ Tool(mergeTool).
+ Flag("--output").Output(noticePath).
+ Inputs(noticeMap[installPath])
+ }
+
+ // Transform the merged NOTICE file into a gzipped HTML file.
+ txtOutput := outputDir.Join(ctx, "NOTICE.txt")
+ htmlOutput := outputDir.Join(ctx, "NOTICE.html")
+ htmlGzOutput := outputDir.Join(ctx, "NOTICE.html.gz")
+ title := "\"Notices for " + ctx.ModuleName() + "\""
+ builder.Command().Tool(generateNoticeTool).
+ FlagWithOutput("--text-output ", txtOutput).
+ FlagWithOutput("--html-output ", htmlOutput).
+ FlagWithArg("-t ", title).
+ Flag("-s").OutputDir()
+ builder.Command().BuiltTool("minigzip").
+ FlagWithInput("-c ", htmlOutput).
+ FlagWithOutput("> ", htmlGzOutput)
+ builder.Build("build_notices", "generate notice output")
+
+ return NoticeOutputs{
+ TxtOutput: OptionalPathForPath(txtOutput),
+ HtmlOutput: OptionalPathForPath(htmlOutput),
+ HtmlGzOutput: OptionalPathForPath(htmlGzOutput),
+ }
+}
diff --git a/android/packaging.go b/android/packaging.go
index 9065826..e3a0b54 100644
--- a/android/packaging.go
+++ b/android/packaging.go
@@ -38,6 +38,8 @@
// Whether relPathInPackage should be marked as executable or not
executable bool
+
+ effectiveLicenseFiles *Paths
}
// Get file name of installed package
@@ -54,6 +56,17 @@
return p.relPathInPackage
}
+func (p *PackagingSpec) SetRelPathInPackage(relPathInPackage string) {
+ p.relPathInPackage = relPathInPackage
+}
+
+func (p *PackagingSpec) EffectiveLicenseFiles() Paths {
+ if p.effectiveLicenseFiles == nil {
+ return Paths{}
+ }
+ return *p.effectiveLicenseFiles
+}
+
type PackageModule interface {
Module
packagingBase() *PackagingBase
@@ -214,15 +227,9 @@
return m
}
-// See PackageModule.CopyDepsToZip
-func (p *PackagingBase) CopyDepsToZip(ctx ModuleContext, zipOut WritablePath) (entries []string) {
- m := p.GatherPackagingSpecs(ctx)
- builder := NewRuleBuilder(pctx, ctx)
-
- dir := PathForModuleOut(ctx, ".zip")
- builder.Command().Text("rm").Flag("-rf").Text(dir.String())
- builder.Command().Text("mkdir").Flag("-p").Text(dir.String())
-
+// CopySpecsToDir is a helper that will add commands to the rule builder to copy the PackagingSpec
+// entries into the specified directory.
+func (p *PackagingBase) CopySpecsToDir(ctx ModuleContext, builder *RuleBuilder, m map[string]PackagingSpec, dir ModuleOutPath) (entries []string) {
seenDir := make(map[string]bool)
for _, k := range SortedStringKeys(m) {
ps := m[k]
@@ -243,6 +250,19 @@
}
}
+ return entries
+}
+
+// See PackageModule.CopyDepsToZip
+func (p *PackagingBase) CopyDepsToZip(ctx ModuleContext, zipOut WritablePath) (entries []string) {
+ m := p.GatherPackagingSpecs(ctx)
+ builder := NewRuleBuilder(pctx, ctx)
+
+ dir := PathForModuleOut(ctx, ".zip")
+ builder.Command().Text("rm").Flag("-rf").Text(dir.String())
+ builder.Command().Text("mkdir").Flag("-p").Text(dir.String())
+ entries = p.CopySpecsToDir(ctx, builder, m, dir)
+
builder.Command().
BuiltTool("soong_zip").
FlagWithOutput("-o ", zipOut).
diff --git a/android/variable.go b/android/variable.go
index 4a82f23..5c54e94 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -40,6 +40,7 @@
Platform_sdk_version struct {
Asflags []string
Cflags []string
+ Cmd *string
}
Platform_sdk_version_or_codename struct {
@@ -50,6 +51,10 @@
Cmd *string
}
+ Platform_version_name struct {
+ Base_dir *string
+ }
+
// unbundled_build is a catch-all property to annotate modules that don't build in one or
// more unbundled branches, usually due to dependencies missing from the manifest.
Unbundled_build struct {
diff --git a/android_sdk/Android.bp b/android_sdk/Android.bp
new file mode 100644
index 0000000..e686d59
--- /dev/null
+++ b/android_sdk/Android.bp
@@ -0,0 +1,22 @@
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+bootstrap_go_package {
+ name: "soong-android-sdk",
+ pkgPath: "android/soong/android_sdk",
+ deps: [
+ "blueprint",
+ "soong",
+ "soong-android",
+ "soong-cc",
+ "soong-cc-config",
+ ],
+ srcs: [
+ "sdk_repo_host.go",
+ ],
+ testSrcs: [
+ "sdk_repo_host_test.go",
+ ],
+ pluginFor: ["soong_build"],
+}
diff --git a/android_sdk/sdk_repo_host.go b/android_sdk/sdk_repo_host.go
new file mode 100644
index 0000000..d64eb7a
--- /dev/null
+++ b/android_sdk/sdk_repo_host.go
@@ -0,0 +1,294 @@
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package android_sdk
+
+import (
+ "fmt"
+ "io"
+ "path/filepath"
+ "strings"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/pathtools"
+ "github.com/google/blueprint/proptools"
+
+ "android/soong/android"
+ "android/soong/cc/config"
+)
+
+var pctx = android.NewPackageContext("android/soong/android_sdk")
+
+func init() {
+ registerBuildComponents(android.InitRegistrationContext)
+}
+
+func registerBuildComponents(ctx android.RegistrationContext) {
+ ctx.RegisterModuleType("android_sdk_repo_host", SdkRepoHostFactory)
+}
+
+type sdkRepoHost struct {
+ android.ModuleBase
+ android.PackagingBase
+
+ properties sdkRepoHostProperties
+
+ outputBaseName string
+ outputFile android.OptionalPath
+}
+
+type remapProperties struct {
+ From string
+ To string
+}
+
+type sdkRepoHostProperties struct {
+ // The top level directory to use for the SDK repo.
+ Base_dir *string
+
+ // List of src:dst mappings to rename files from `deps`.
+ Deps_remap []remapProperties `android:"arch_variant"`
+
+ // List of zip files to merge into the SDK repo.
+ Merge_zips []string `android:"arch_variant,path"`
+
+ // List of sources to include into the SDK repo. These are usually raw files, filegroups,
+ // or genrules, as most built modules should be referenced via `deps`.
+ Srcs []string `android:"arch_variant,path"`
+
+ // List of files to strip. This should be a list of files, not modules. This happens after
+ // `deps_remap` and `merge_zips` are applied, but before the `base_dir` is added.
+ Strip_files []string `android:"arch_variant"`
+}
+
+// android_sdk_repo_host defines an Android SDK repo containing host tools.
+//
+// This implementation is trying to be a faithful reproduction of how these sdk-repos were produced
+// in the Make system, which may explain some of the oddities (like `strip_files` not being
+// automatic)
+func SdkRepoHostFactory() android.Module {
+ return newSdkRepoHostModule()
+}
+
+func newSdkRepoHostModule() *sdkRepoHost {
+ s := &sdkRepoHost{}
+ s.AddProperties(&s.properties)
+ android.InitPackageModule(s)
+ android.InitAndroidMultiTargetsArchModule(s, android.HostSupported, android.MultilibCommon)
+ return s
+}
+
+type dependencyTag struct {
+ blueprint.BaseDependencyTag
+ android.PackagingItemAlwaysDepTag
+}
+
+// TODO(b/201696252): Evaluate whether licenses should be propagated through this dependency.
+func (d dependencyTag) PropagateLicenses() bool {
+ return false
+}
+
+var depTag = dependencyTag{}
+
+func (s *sdkRepoHost) DepsMutator(ctx android.BottomUpMutatorContext) {
+ s.AddDeps(ctx, depTag)
+}
+
+func (s *sdkRepoHost) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ dir := android.PathForModuleOut(ctx, "zip")
+ builder := android.NewRuleBuilder(pctx, ctx).
+ Sbox(dir, android.PathForModuleOut(ctx, "out.sbox.textproto")).
+ SandboxInputs()
+
+ // Get files from modules listed in `deps`
+ packageSpecs := s.GatherPackagingSpecs(ctx)
+
+ // Handle `deps_remap` renames
+ err := remapPackageSpecs(packageSpecs, s.properties.Deps_remap)
+ if err != nil {
+ ctx.PropertyErrorf("deps_remap", "%s", err.Error())
+ }
+
+ s.CopySpecsToDir(ctx, builder, packageSpecs, dir)
+
+ // Collect licenses to write into NOTICE.txt
+ noticeMap := map[string]android.Paths{}
+ for path, pkgSpec := range packageSpecs {
+ licenseFiles := pkgSpec.EffectiveLicenseFiles()
+ if len(licenseFiles) > 0 {
+ noticeMap[path] = pkgSpec.EffectiveLicenseFiles()
+ }
+ }
+ notices := android.BuildNotices(ctx, noticeMap)
+ builder.Command().Text("cp").
+ Input(notices.TxtOutput.Path()).
+ Text(filepath.Join(dir.String(), "NOTICE.txt"))
+
+ // Handle `merge_zips` by extracting their contents into our tmpdir
+ for _, zip := range android.PathsForModuleSrc(ctx, s.properties.Merge_zips) {
+ builder.Command().
+ Text("unzip").
+ Flag("-DD").
+ Flag("-q").
+ FlagWithArg("-d ", dir.String()).
+ Input(zip)
+ }
+
+ // Copy files from `srcs` into our tmpdir
+ for _, src := range android.PathsForModuleSrc(ctx, s.properties.Srcs) {
+ builder.Command().
+ Text("cp").Input(src).Flag(dir.Join(ctx, src.Rel()).String())
+ }
+
+ // Handle `strip_files` by calling the necessary strip commands
+ //
+ // Note: this stripping logic was copied over from the old Make implementation
+ // It's not using the same flags as the regular stripping support, nor does it
+ // support the array of per-module stripping options. It would be nice if we
+ // pulled the stripped versions from the CC modules, but that doesn't exist
+ // for host tools today. (And not all the things we strip are CC modules today)
+ if ctx.Darwin() {
+ macStrip := config.MacStripPath(ctx)
+ for _, strip := range s.properties.Strip_files {
+ builder.Command().
+ Text(macStrip).Flag("-x").
+ Flag(dir.Join(ctx, strip).String())
+ }
+ } else {
+ llvmStrip := config.ClangPath(ctx, "bin/llvm-strip")
+ llvmLib := config.ClangPath(ctx, "lib64/libc++.so.1")
+ for _, strip := range s.properties.Strip_files {
+ cmd := builder.Command().Tool(llvmStrip).ImplicitTool(llvmLib)
+ if !ctx.Windows() {
+ cmd.Flag("-x")
+ }
+ cmd.Flag(dir.Join(ctx, strip).String())
+ }
+ }
+
+ // Fix up the line endings of all text files. This also removes executable permissions.
+ builder.Command().
+ Text("find").
+ Flag(dir.String()).
+ Flag("-name '*.aidl' -o -name '*.css' -o -name '*.html' -o -name '*.java'").
+ Flag("-o -name '*.js' -o -name '*.prop' -o -name '*.template'").
+ Flag("-o -name '*.txt' -o -name '*.windows' -o -name '*.xml' -print0").
+ // Using -n 500 for xargs to limit the max number of arguments per call to line_endings
+ // to 500. This avoids line_endings failing with "arguments too long".
+ Text("| xargs -0 -n 500 ").
+ BuiltTool("line_endings").
+ Flag("unix")
+
+ // Exclude some file types (roughly matching sdk.exclude.atree)
+ builder.Command().
+ Text("find").
+ Flag(dir.String()).
+ Flag("'('").
+ Flag("-name '.*' -o -name '*~' -o -name 'Makefile' -o -name 'Android.mk' -o").
+ Flag("-name '.*.swp' -o -name '.DS_Store' -o -name '*.pyc' -o -name 'OWNERS' -o").
+ Flag("-name 'MODULE_LICENSE_*' -o -name '*.ezt' -o -name 'Android.bp'").
+ Flag("')' -print0").
+ Text("| xargs -0 -r rm -rf")
+ builder.Command().
+ Text("find").
+ Flag(dir.String()).
+ Flag("-name '_*' ! -name '__*' -print0").
+ Text("| xargs -0 -r rm -rf")
+
+ if ctx.Windows() {
+ // Fix EOL chars to make window users happy
+ builder.Command().
+ Text("find").
+ Flag(dir.String()).
+ Flag("-maxdepth 2 -name '*.bat' -type f -print0").
+ Text("| xargs -0 -r unix2dos")
+ }
+
+ // Zip up our temporary directory as the sdk-repo
+ outputZipFile := dir.Join(ctx, "output.zip")
+ builder.Command().
+ BuiltTool("soong_zip").
+ FlagWithOutput("-o ", outputZipFile).
+ FlagWithArg("-P ", proptools.StringDefault(s.properties.Base_dir, ".")).
+ FlagWithArg("-C ", dir.String()).
+ FlagWithArg("-D ", dir.String())
+ builder.Command().Text("rm").Flag("-rf").Text(dir.String())
+
+ builder.Build("build_sdk_repo", "Creating sdk-repo-"+s.BaseModuleName())
+
+ osName := ctx.Os().String()
+ if osName == "linux_glibc" {
+ osName = "linux"
+ }
+ name := fmt.Sprintf("sdk-repo-%s-%s", osName, s.BaseModuleName())
+
+ s.outputBaseName = name
+ s.outputFile = android.OptionalPathForPath(outputZipFile)
+ ctx.InstallFile(android.PathForModuleInstall(ctx, "sdk-repo"), name+".zip", outputZipFile)
+}
+
+func (s *sdkRepoHost) AndroidMk() android.AndroidMkData {
+ return android.AndroidMkData{
+ Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
+ fmt.Fprintln(w, ".PHONY:", name, "sdk_repo", "sdk-repo-"+name)
+ fmt.Fprintln(w, "sdk_repo", "sdk-repo-"+name+":", strings.Join(s.FilesToInstall().Strings(), " "))
+
+ fmt.Fprintf(w, "$(call dist-for-goals,sdk_repo sdk-repo-%s,%s:%s-$(FILE_NAME_TAG).zip)\n\n", s.BaseModuleName(), s.outputFile.String(), s.outputBaseName)
+ },
+ }
+}
+
+func remapPackageSpecs(specs map[string]android.PackagingSpec, remaps []remapProperties) error {
+ for _, remap := range remaps {
+ for path, spec := range specs {
+ if match, err := pathtools.Match(remap.From, path); err != nil {
+ return fmt.Errorf("Error parsing %q: %v", remap.From, err)
+ } else if match {
+ newPath := remap.To
+ if pathtools.IsGlob(remap.From) {
+ rel, err := filepath.Rel(constantPartOfPattern(remap.From), path)
+ if err != nil {
+ return fmt.Errorf("Error handling %q", path)
+ }
+ newPath = filepath.Join(remap.To, rel)
+ }
+ delete(specs, path)
+ spec.SetRelPathInPackage(newPath)
+ specs[newPath] = spec
+ }
+ }
+ }
+ return nil
+}
+
+func constantPartOfPattern(pattern string) string {
+ ret := ""
+ for pattern != "" {
+ var first string
+ first, pattern = splitFirst(pattern)
+ if pathtools.IsGlob(first) {
+ return ret
+ }
+ ret = filepath.Join(ret, first)
+ }
+ return ret
+}
+
+func splitFirst(path string) (string, string) {
+ i := strings.IndexRune(path, filepath.Separator)
+ if i < 0 {
+ return path, ""
+ }
+ return path[:i], path[i+1:]
+}
diff --git a/android_sdk/sdk_repo_host_test.go b/android_sdk/sdk_repo_host_test.go
new file mode 100644
index 0000000..0688921
--- /dev/null
+++ b/android_sdk/sdk_repo_host_test.go
@@ -0,0 +1,124 @@
+// Copyright 2021 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package android_sdk
+
+import (
+ "fmt"
+ "runtime"
+ "sort"
+ "testing"
+
+ "android/soong/android"
+ "android/soong/cc"
+
+ "github.com/google/blueprint/pathtools"
+)
+
+var fixture = android.GroupFixturePreparers(
+ android.PrepareForIntegrationTestWithAndroid,
+ cc.PrepareForIntegrationTestWithCc,
+ android.FixtureRegisterWithContext(registerBuildComponents),
+)
+
+func TestSdkRepoHostDeps(t *testing.T) {
+ if runtime.GOOS != "linux" {
+ t.Skipf("Skipping sdk_repo_host testing that is only supported on linux not %s", runtime.GOOS)
+ }
+
+ result := fixture.RunTestWithBp(t, `
+ android_sdk_repo_host {
+ name: "platform-tools",
+ }
+ `)
+
+ // produces "sdk-repo-{OS}-platform-tools.zip"
+ result.ModuleForTests("platform-tools", "linux_glibc_common").Output("sdk-repo-linux-platform-tools.zip")
+}
+
+func TestRemapPackageSpecs(t *testing.T) {
+ testcases := []struct {
+ name string
+ input []string
+ remaps []remapProperties
+ output []string
+ err string
+ }{
+ {
+ name: "basic remap",
+ input: []string{"a", "c"},
+ remaps: []remapProperties{
+ {From: "a", To: "b"},
+ },
+ output: []string{"b", "c"},
+ },
+ {
+ name: "non-matching remap",
+ input: []string{"a"},
+ remaps: []remapProperties{
+ {From: "b", To: "c"},
+ },
+ output: []string{"a"},
+ },
+ {
+ name: "glob",
+ input: []string{"bin/d", "liba.so", "libb.so", "lib/c.so"},
+ remaps: []remapProperties{
+ {From: "lib*.so", To: "lib/"},
+ },
+ output: []string{"bin/d", "lib/c.so", "lib/liba.so", "lib/libb.so"},
+ },
+ {
+ name: "bad glob",
+ input: []string{"a"},
+ remaps: []remapProperties{
+ {From: "**", To: "./"},
+ },
+ err: fmt.Sprintf("Error parsing \"**\": %v", pathtools.GlobLastRecursiveErr.Error()),
+ },
+ {
+ name: "globbed dirs",
+ input: []string{"a/b/c"},
+ remaps: []remapProperties{
+ {From: "a/*/c", To: "./"},
+ },
+ output: []string{"b/c"},
+ },
+ }
+
+ for _, test := range testcases {
+ t.Run(test.name, func(t *testing.T) {
+ specs := map[string]android.PackagingSpec{}
+ for _, input := range test.input {
+ spec := android.PackagingSpec{}
+ spec.SetRelPathInPackage(input)
+ specs[input] = spec
+ }
+
+ err := remapPackageSpecs(specs, test.remaps)
+
+ if test.err != "" {
+ android.AssertErrorMessageEquals(t, "", test.err, err)
+ } else {
+ outputs := []string{}
+ for path, spec := range specs {
+ android.AssertStringEquals(t, "path does not match rel path", path, spec.RelPathInPackage())
+ outputs = append(outputs, path)
+ }
+ sort.Strings(outputs)
+ android.AssertArrayString(t, "outputs mismatch", test.output, outputs)
+ }
+ })
+ }
+}
diff --git a/apex/apex.go b/apex/apex.go
index 7ac3bc8..0bca093 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -158,8 +158,8 @@
// is 'image'.
Payload_type *string
- // The type of filesystem to use when the payload_type is 'image'. Either 'ext4' or 'f2fs'.
- // Default 'ext4'.
+ // The type of filesystem to use when the payload_type is 'image'. Either 'ext4', 'f2fs'
+ // or 'erofs'. Default 'ext4'.
Payload_fs_type *string
// For telling the APEX to ignore special handling for system libraries such as bionic.
@@ -1151,8 +1151,9 @@
zipApexType = "zip"
flattenedApexType = "flattened"
- ext4FsType = "ext4"
- f2fsFsType = "f2fs"
+ ext4FsType = "ext4"
+ f2fsFsType = "f2fs"
+ erofsFsType = "erofs"
)
// The suffix for the output "file", not the module
@@ -1625,6 +1626,7 @@
const (
ext4 fsType = iota
f2fs
+ erofs
)
func (f fsType) string() string {
@@ -1633,6 +1635,8 @@
return ext4FsType
case f2fs:
return f2fsFsType
+ case erofs:
+ return erofsFsType
default:
panic(fmt.Errorf("unknown APEX payload type %d", f))
}
@@ -1679,6 +1683,9 @@
if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
return false
}
+ if mod, ok := child.(android.Module); ok && !mod.Enabled() {
+ return false
+ }
depName := ctx.OtherModuleName(child)
if _, isDirectDep := parent.(*apexBundle); isDirectDep {
switch depTag {
@@ -2056,8 +2063,10 @@
a.payloadFsType = ext4
case f2fsFsType:
a.payloadFsType = f2fs
+ case erofsFsType:
+ a.payloadFsType = erofs
default:
- ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs]", *a.properties.Payload_fs_type)
+ ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs, erofs]", *a.properties.Payload_fs_type)
}
// Optimization. If we are building bundled APEX, for the files that are gathered due to the
diff --git a/apex/builder.go b/apex/builder.go
index c05c20c..702b6fc 100644
--- a/apex/builder.go
+++ b/apex/builder.go
@@ -65,6 +65,7 @@
pctx.HostBinToolVariable("extract_apks", "extract_apks")
pctx.HostBinToolVariable("make_f2fs", "make_f2fs")
pctx.HostBinToolVariable("sload_f2fs", "sload_f2fs")
+ pctx.HostBinToolVariable("make_erofs", "make_erofs")
pctx.HostBinToolVariable("apex_compression_tool", "apex_compression_tool")
pctx.SourcePathVariable("genNdkUsedbyApexPath", "build/soong/scripts/gen_ndk_usedby_apex.sh")
}
@@ -120,7 +121,7 @@
`--payload_type image ` +
`--key ${key} ${opt_flags} ${image_dir} ${out} `,
CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}",
- "${mke2fs}", "${resize2fs}", "${sefcontext_compile}", "${make_f2fs}", "${sload_f2fs}",
+ "${mke2fs}", "${resize2fs}", "${sefcontext_compile}", "${make_f2fs}", "${sload_f2fs}", "${make_erofs}",
"${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"},
Rspfile: "${out}.copy_commands",
RspfileContent: "${copy_commands}",
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 653e8c7..cbdc167 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -803,8 +803,9 @@
blueprint: soongCcLibraryPreamble,
expectedBazelTargets: []string{`cc_library(
name = "a",
+ additional_linker_inputs = ["v.map"],
+ linkopts = ["-Wl,--version-script,$(location v.map)"],
srcs = ["a.cpp"],
- version_script = "v.map",
)`},
})
}
@@ -838,12 +839,17 @@
blueprint: soongCcLibraryPreamble,
expectedBazelTargets: []string{`cc_library(
name = "a",
- srcs = ["a.cpp"],
- version_script = select({
- "//build/bazel/platforms/arch:arm": "arm.map",
- "//build/bazel/platforms/arch:arm64": "arm64.map",
- "//conditions:default": None,
+ additional_linker_inputs = select({
+ "//build/bazel/platforms/arch:arm": ["arm.map"],
+ "//build/bazel/platforms/arch:arm64": ["arm64.map"],
+ "//conditions:default": [],
}),
+ linkopts = select({
+ "//build/bazel/platforms/arch:arm": ["-Wl,--version-script,$(location arm.map)"],
+ "//build/bazel/platforms/arch:arm64": ["-Wl,--version-script,$(location arm64.map)"],
+ "//conditions:default": [],
+ }),
+ srcs = ["a.cpp"],
)`},
})
}
@@ -1010,39 +1016,6 @@
})
}
-func TestCcLibraryLabelAttributeGetTargetProperties(t *testing.T) {
- runCcLibraryTestCase(t, bp2buildTestCase{
- description: "cc_library GetTargetProperties on a LabelAttribute",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
- blueprint: soongCcLibraryPreamble + `
-cc_library {
- name: "a",
- srcs: ["a.cpp"],
- target: {
- android_arm: {
- version_script: "android_arm.map",
- },
- linux_bionic_arm64: {
- version_script: "linux_bionic_arm64.map",
- },
- },
- include_build_directory: false,
-}
- `,
- expectedBazelTargets: []string{`cc_library(
- name = "a",
- srcs = ["a.cpp"],
- version_script = select({
- "//build/bazel/platforms/os_arch:android_arm": "android_arm.map",
- "//build/bazel/platforms/os_arch:linux_bionic_arm64": "linux_bionic_arm64.map",
- "//conditions:default": None,
- }),
-)`},
- })
-}
-
func TestCcLibraryExcludeLibs(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
moduleTypeUnderTest: "cc_library",
diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go
index b272067..bb15776 100644
--- a/bp2build/cc_library_shared_conversion_test.go
+++ b/bp2build/cc_library_shared_conversion_test.go
@@ -361,7 +361,8 @@
}`,
expectedBazelTargets: []string{`cc_library_shared(
name = "foo_shared",
- version_script = "version_script",
+ additional_linker_inputs = ["version_script"],
+ linkopts = ["-Wl,--version-script,$(location version_script)"],
)`},
})
}
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 543394d..c078096 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -14,6 +14,7 @@
package cc
import (
+ "fmt"
"path/filepath"
"strings"
@@ -397,7 +398,7 @@
linkCrt bazel.BoolAttribute
useLibcrt bazel.BoolAttribute
linkopts bazel.StringListAttribute
- versionScript bazel.LabelAttribute
+ additionalLinkerInputs bazel.LabelListAttribute
stripKeepSymbols bazel.BoolAttribute
stripKeepSymbolsAndDebugFrame bazel.BoolAttribute
stripKeepSymbolsList bazel.StringListAttribute
@@ -420,8 +421,8 @@
systemSharedDeps := bazel.LabelListAttribute{ForceSpecifyEmptyList: true}
var linkopts bazel.StringListAttribute
- var versionScript bazel.LabelAttribute
var linkCrt bazel.BoolAttribute
+ var additionalLinkerInputs bazel.LabelListAttribute
var useLibcrt bazel.BoolAttribute
var stripKeepSymbols bazel.BoolAttribute
@@ -482,7 +483,6 @@
headerDeps.SetSelectValue(axis, config, hDeps.export)
implementationHeaderDeps.SetSelectValue(axis, config, hDeps.implementation)
- linkopts.SetSelectValue(axis, config, baseLinkerProps.Ldflags)
if !BoolDefault(baseLinkerProps.Pack_relocations, packRelocationsDefault) {
axisFeatures = append(axisFeatures, "disable_pack_relocations")
}
@@ -491,9 +491,16 @@
axisFeatures = append(axisFeatures, "-no_undefined_symbols")
}
- if baseLinkerProps.Version_script != nil {
- versionScript.SetSelectValue(axis, config, android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script))
+ var linkerFlags []string
+ if len(baseLinkerProps.Ldflags) > 0 {
+ linkerFlags = append(linkerFlags, baseLinkerProps.Ldflags...)
}
+ if baseLinkerProps.Version_script != nil {
+ label := android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script)
+ additionalLinkerInputs.SetSelectValue(axis, config, bazel.LabelList{Includes: []bazel.Label{label}})
+ linkerFlags = append(linkerFlags, fmt.Sprintf("-Wl,--version-script,$(location %s)", label.Label))
+ }
+ linkopts.SetSelectValue(axis, config, linkerFlags)
useLibcrt.SetSelectValue(axis, config, baseLinkerProps.libCrt())
// it's very unlikely for nocrt to be arch variant, so bp2build doesn't support it.
@@ -585,10 +592,10 @@
wholeArchiveDeps: wholeArchiveDeps,
systemDynamicDeps: systemSharedDeps,
- linkCrt: linkCrt,
- linkopts: linkopts,
- useLibcrt: useLibcrt,
- versionScript: versionScript,
+ linkCrt: linkCrt,
+ linkopts: linkopts,
+ useLibcrt: useLibcrt,
+ additionalLinkerInputs: additionalLinkerInputs,
// Strip properties
stripKeepSymbols: stripKeepSymbols,
diff --git a/cc/config/global.go b/cc/config/global.go
index ba10491..6108d3d 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -270,8 +270,8 @@
// prebuilts/clang default settings.
ClangDefaultBase = "prebuilts/clang/host"
- ClangDefaultVersion = "clang-r433403"
- ClangDefaultShortVersion = "13.0.2"
+ ClangDefaultVersion = "clang-r433403b"
+ ClangDefaultShortVersion = "13.0.3"
// Directories with warnings from Android.bp files.
WarningAllowedProjects = []string{
@@ -366,28 +366,12 @@
exportStringStaticVariable("CLANG_DEFAULT_VERSION", ClangDefaultVersion)
exportStringStaticVariable("CLANG_DEFAULT_SHORT_VERSION", ClangDefaultShortVersion)
- pctx.SourcePathVariable("ClangDefaultBase", ClangDefaultBase)
- pctx.VariableFunc("ClangBase", func(ctx android.PackageVarContext) string {
- if override := ctx.Config().Getenv("LLVM_PREBUILTS_BASE"); override != "" {
- return override
- }
- return "${ClangDefaultBase}"
- })
- pctx.VariableFunc("ClangVersion", func(ctx android.PackageVarContext) string {
- if override := ctx.Config().Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
- return override
- }
- return ClangDefaultVersion
- })
+ pctx.StaticVariableWithEnvOverride("ClangBase", "LLVM_PREBUILTS_BASE", ClangDefaultBase)
+ pctx.StaticVariableWithEnvOverride("ClangVersion", "LLVM_PREBUILTS_VERSION", ClangDefaultVersion)
pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
- pctx.VariableFunc("ClangShortVersion", func(ctx android.PackageVarContext) string {
- if override := ctx.Config().Getenv("LLVM_RELEASE_VERSION"); override != "" {
- return override
- }
- return ClangDefaultShortVersion
- })
+ pctx.StaticVariableWithEnvOverride("ClangShortVersion", "LLVM_RELEASE_VERSION", ClangDefaultShortVersion)
pctx.StaticVariable("ClangAsanLibDir", "${ClangBase}/linux-x86/${ClangVersion}/lib64/clang/${ClangShortVersion}/lib/linux")
// These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
@@ -421,3 +405,29 @@
}
var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
+
+func ClangPath(ctx android.PathContext, file string) android.SourcePath {
+ type clangToolKey string
+
+ key := android.NewCustomOnceKey(clangToolKey(file))
+
+ return ctx.Config().OnceSourcePath(key, func() android.SourcePath {
+ return clangPath(ctx).Join(ctx, file)
+ })
+}
+
+var clangPathKey = android.NewOnceKey("clangPath")
+
+func clangPath(ctx android.PathContext) android.SourcePath {
+ return ctx.Config().OnceSourcePath(clangPathKey, func() android.SourcePath {
+ clangBase := ClangDefaultBase
+ if override := ctx.Config().Getenv("LLVM_PREBUILTS_BASE"); override != "" {
+ clangBase = override
+ }
+ clangVersion := ClangDefaultVersion
+ if override := ctx.Config().Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
+ clangVersion = override
+ }
+ return android.PathForSource(ctx, clangBase, ctx.Config().PrebuiltOS(), clangVersion)
+ })
+}
diff --git a/cc/config/x86_darwin_host.go b/cc/config/x86_darwin_host.go
index 0bb1a81..ecdcbde 100644
--- a/cc/config/x86_darwin_host.go
+++ b/cc/config/x86_darwin_host.go
@@ -113,6 +113,10 @@
pctx.StaticVariable("DarwinYasmFlags", "-f macho -m amd64")
}
+func MacStripPath(ctx android.PathContext) string {
+ return getMacTools(ctx).stripPath
+}
+
type macPlatformTools struct {
once sync.Once
err error
@@ -125,7 +129,7 @@
var macTools = &macPlatformTools{}
-func getMacTools(ctx android.PackageVarContext) *macPlatformTools {
+func getMacTools(ctx android.PathContext) *macPlatformTools {
macTools.once.Do(func() {
xcrunTool := "/usr/bin/xcrun"
@@ -170,7 +174,7 @@
macTools.toolPath = filepath.Dir(xcrun("--find", "ld"))
})
if macTools.err != nil {
- ctx.Errorf("%q", macTools.err)
+ android.ReportPathErrorf(ctx, "%q", macTools.err)
}
return macTools
}
diff --git a/cc/fuzz.go b/cc/fuzz.go
index 83f0037..40f16f3 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -79,54 +79,21 @@
return flags
}
-// This function performs a breadth-first search over the provided module's
-// dependencies using `visitDirectDeps` to enumerate all shared library
-// dependencies. We require breadth-first expansion, as otherwise we may
-// incorrectly use the core libraries (sanitizer runtimes, libc, libdl, etc.)
-// from a dependency. This may cause issues when dependencies have explicit
-// sanitizer tags, as we may get a dependency on an unsanitized libc, etc.
-func collectAllSharedDependencies(ctx android.SingletonContext, module android.Module) android.Paths {
- var fringe []android.Module
-
- seen := make(map[string]bool)
-
- // Enumerate the first level of dependencies, as we discard all non-library
- // modules in the BFS loop below.
- ctx.VisitDirectDeps(module, func(dep android.Module) {
- if isValidSharedDependency(dep) {
- fringe = append(fringe, dep)
- }
- })
-
- var sharedLibraries android.Paths
-
- for i := 0; i < len(fringe); i++ {
- module := fringe[i]
- if seen[module.Name()] {
- continue
- }
- seen[module.Name()] = true
-
- ccModule := module.(*Module)
- sharedLibraries = append(sharedLibraries, ccModule.UnstrippedOutputFile())
- ctx.VisitDirectDeps(module, func(dep android.Module) {
- if isValidSharedDependency(dep) && !seen[dep.Name()] {
- fringe = append(fringe, dep)
- }
- })
+func UnstrippedOutputFile(module android.Module) android.Path {
+ if mod, ok := module.(LinkableInterface); ok {
+ return mod.UnstrippedOutputFile()
}
-
- return sharedLibraries
+ panic("UnstrippedOutputFile called on non-LinkableInterface module: " + module.Name())
}
-// This function takes a module and determines if it is a unique shared library
+// IsValidSharedDependency takes a module and determines if it is a unique shared library
// that should be installed in the fuzz target output directories. This function
// returns true, unless:
// - The module is not an installable shared library, or
// - The module is a header or stub, or
// - The module is a prebuilt and its source is available, or
// - The module is a versioned member of an SDK snapshot.
-func isValidSharedDependency(dependency android.Module) bool {
+func IsValidSharedDependency(dependency android.Module) bool {
// TODO(b/144090547): We should be parsing these modules using
// ModuleDependencyTag instead of the current brute-force checking.
@@ -246,7 +213,7 @@
}
seen[child.Name()] = true
- if isValidSharedDependency(child) {
+ if IsValidSharedDependency(child) {
sharedLibraries = append(sharedLibraries, child.(*Module).UnstrippedOutputFile())
return true
}
@@ -304,7 +271,6 @@
// their architecture & target/host specific zip file.
type ccFuzzPackager struct {
fuzz.FuzzPackager
- sharedLibInstallStrings []string
}
func fuzzPackagingFactory() android.Singleton {
@@ -317,14 +283,14 @@
// archive}).
archDirs := make(map[fuzz.ArchOs][]fuzz.FileToZip)
- // Map tracking whether each shared library has an install rule to avoid duplicate install rules from
- // multiple fuzzers that depend on the same shared library.
- sharedLibraryInstalled := make(map[string]bool)
-
// List of individual fuzz targets, so that 'make fuzz' also installs the targets
// to the correct output directories as well.
s.FuzzTargets = make(map[string]bool)
+ // Map tracking whether each shared library has an install rule to avoid duplicate install rules from
+ // multiple fuzzers that depend on the same shared library.
+ sharedLibraryInstalled := make(map[string]bool)
+
ctx.VisitAllModules(func(module android.Module) {
ccModule, ok := module.(*Module)
if !ok || ccModule.Properties.PreventInstall {
@@ -351,7 +317,7 @@
archOs := fuzz.ArchOs{HostOrTarget: hostOrTargetString, Arch: archString, Dir: archDir.String()}
// Grab the list of required shared libraries.
- sharedLibraries := collectAllSharedDependencies(ctx, module)
+ sharedLibraries := fuzz.CollectAllSharedDependencies(ctx, module, UnstrippedOutputFile, IsValidSharedDependency)
var files []fuzz.FileToZip
builder := android.NewRuleBuilder(pctx, ctx)
@@ -359,39 +325,8 @@
// Package the corpus, data, dict and config into a zipfile.
files = s.PackageArtifacts(ctx, module, fuzzModule.fuzzPackagedModule, archDir, builder)
- // Find and mark all the transiently-dependent shared libraries for
- // packaging.
- for _, library := range sharedLibraries {
- files = append(files, fuzz.FileToZip{library, "lib"})
-
- // For each architecture-specific shared library dependency, we need to
- // install it to the output directory. Setup the install destination here,
- // which will be used by $(copy-many-files) in the Make backend.
- installDestination := sharedLibraryInstallLocation(
- library, ccModule.Host(), archString)
- if sharedLibraryInstalled[installDestination] {
- continue
- }
- sharedLibraryInstalled[installDestination] = true
-
- // Escape all the variables, as the install destination here will be called
- // via. $(eval) in Make.
- installDestination = strings.ReplaceAll(
- installDestination, "$", "$$")
- s.sharedLibInstallStrings = append(s.sharedLibInstallStrings,
- library.String()+":"+installDestination)
-
- // Ensure that on device, the library is also reinstalled to the /symbols/
- // dir. Symbolized DSO's are always installed to the device when fuzzing, but
- // we want symbolization tools (like `stack`) to be able to find the symbols
- // in $ANDROID_PRODUCT_OUT/symbols automagically.
- if !ccModule.Host() {
- symbolsInstallDestination := sharedLibrarySymbolsInstallLocation(library, archString)
- symbolsInstallDestination = strings.ReplaceAll(symbolsInstallDestination, "$", "$$")
- s.sharedLibInstallStrings = append(s.sharedLibInstallStrings,
- library.String()+":"+symbolsInstallDestination)
- }
- }
+ // Package shared libraries
+ files = append(files, GetSharedLibsToZip(sharedLibraries, ccModule, &s.FuzzPackager, archString, &sharedLibraryInstalled)...)
// The executable.
files = append(files, fuzz.FileToZip{ccModule.UnstrippedOutputFile(), ""})
@@ -409,15 +344,54 @@
func (s *ccFuzzPackager) MakeVars(ctx android.MakeVarsContext) {
packages := s.Packages.Strings()
sort.Strings(packages)
- sort.Strings(s.sharedLibInstallStrings)
+ sort.Strings(s.FuzzPackager.SharedLibInstallStrings)
// TODO(mitchp): Migrate this to use MakeVarsContext::DistForGoal() when it's
// ready to handle phony targets created in Soong. In the meantime, this
// exports the phony 'fuzz' target and dependencies on packages to
// core/main.mk so that we can use dist-for-goals.
ctx.Strict("SOONG_FUZZ_PACKAGING_ARCH_MODULES", strings.Join(packages, " "))
ctx.Strict("FUZZ_TARGET_SHARED_DEPS_INSTALL_PAIRS",
- strings.Join(s.sharedLibInstallStrings, " "))
+ strings.Join(s.FuzzPackager.SharedLibInstallStrings, " "))
// Preallocate the slice of fuzz targets to minimise memory allocations.
s.PreallocateSlice(ctx, "ALL_FUZZ_TARGETS")
}
+
+// GetSharedLibsToZip finds and marks all the transiently-dependent shared libraries for
+// packaging.
+func GetSharedLibsToZip(sharedLibraries android.Paths, module LinkableInterface, s *fuzz.FuzzPackager, archString string, sharedLibraryInstalled *map[string]bool) []fuzz.FileToZip {
+ var files []fuzz.FileToZip
+
+ for _, library := range sharedLibraries {
+ files = append(files, fuzz.FileToZip{library, "lib"})
+
+ // For each architecture-specific shared library dependency, we need to
+ // install it to the output directory. Setup the install destination here,
+ // which will be used by $(copy-many-files) in the Make backend.
+ installDestination := sharedLibraryInstallLocation(
+ library, module.Host(), archString)
+ if (*sharedLibraryInstalled)[installDestination] {
+ continue
+ }
+ (*sharedLibraryInstalled)[installDestination] = true
+
+ // Escape all the variables, as the install destination here will be called
+ // via. $(eval) in Make.
+ installDestination = strings.ReplaceAll(
+ installDestination, "$", "$$")
+ s.SharedLibInstallStrings = append(s.SharedLibInstallStrings,
+ library.String()+":"+installDestination)
+
+ // Ensure that on device, the library is also reinstalled to the /symbols/
+ // dir. Symbolized DSO's are always installed to the device when fuzzing, but
+ // we want symbolization tools (like `stack`) to be able to find the symbols
+ // in $ANDROID_PRODUCT_OUT/symbols automagically.
+ if !module.Host() {
+ symbolsInstallDestination := sharedLibrarySymbolsInstallLocation(library, archString)
+ symbolsInstallDestination = strings.ReplaceAll(symbolsInstallDestination, "$", "$$")
+ s.SharedLibInstallStrings = append(s.SharedLibInstallStrings,
+ library.String()+":"+symbolsInstallDestination)
+ }
+ }
+ return files
+}
diff --git a/cc/library.go b/cc/library.go
index 00e215b..ed4d3d2 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -253,8 +253,8 @@
Cpp_std *string
// This is shared only.
- Version_script bazel.LabelAttribute
- Link_crt bazel.BoolAttribute
+ Link_crt bazel.BoolAttribute
+ Additional_linker_inputs bazel.LabelListAttribute
// Common properties shared between both shared and static variants.
Shared staticOrSharedAttributes
@@ -332,7 +332,7 @@
Stl: compilerAttrs.stl,
Cpp_std: compilerAttrs.cppStd,
- Version_script: linkerAttrs.versionScript,
+ Additional_linker_inputs: linkerAttrs.additionalLinkerInputs,
Strip: stripAttributes{
Keep_symbols: linkerAttrs.stripKeepSymbols,
@@ -2402,7 +2402,6 @@
attrs = &bazelCcLibraryStaticAttributes{
staticOrSharedAttributes: commonAttrs,
- Linkopts: linkerAttrs.linkopts,
Use_libcrt: linkerAttrs.useLibcrt,
Rtti: compilerAttrs.rtti,
Stl: compilerAttrs.stl,
@@ -2433,11 +2432,11 @@
Stl: compilerAttrs.stl,
Cpp_std: compilerAttrs.cppStd,
- Export_includes: exportedIncludes.Includes,
- Export_system_includes: exportedIncludes.SystemIncludes,
- Local_includes: compilerAttrs.localIncludes,
- Absolute_includes: compilerAttrs.absoluteIncludes,
- Version_script: linkerAttrs.versionScript,
+ Export_includes: exportedIncludes.Includes,
+ Export_system_includes: exportedIncludes.SystemIncludes,
+ Local_includes: compilerAttrs.localIncludes,
+ Absolute_includes: compilerAttrs.absoluteIncludes,
+ Additional_linker_inputs: linkerAttrs.additionalLinkerInputs,
Strip: stripAttributes{
Keep_symbols: linkerAttrs.stripKeepSymbols,
@@ -2463,7 +2462,6 @@
type bazelCcLibraryStaticAttributes struct {
staticOrSharedAttributes
- Linkopts bazel.StringListAttribute
Use_libcrt bazel.BoolAttribute
Rtti bazel.BoolAttribute
Stl *string
@@ -2503,8 +2501,8 @@
Absolute_includes bazel.StringListAttribute
Hdrs bazel.LabelListAttribute
- Strip stripAttributes
- Version_script bazel.LabelAttribute
+ Strip stripAttributes
+ Additional_linker_inputs bazel.LabelListAttribute
Cppflags bazel.StringListAttribute
Conlyflags bazel.StringListAttribute
diff --git a/cc/linkable.go b/cc/linkable.go
index b510508..560c9de 100644
--- a/cc/linkable.go
+++ b/cc/linkable.go
@@ -110,6 +110,7 @@
BaseModuleName() string
OutputFile() android.OptionalPath
+ UnstrippedOutputFile() android.Path
CoverageFiles() android.Paths
NonCcVariants() bool
diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go
index a1ce8dc..2865ffa 100644
--- a/etc/prebuilt_etc.go
+++ b/etc/prebuilt_etc.go
@@ -439,6 +439,7 @@
InitPrebuiltEtcModule(module, "etc")
// This module is host-only
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
+ android.InitDefaultableModule(module)
return module
}
@@ -449,6 +450,7 @@
InitPrebuiltRootModule(module)
// This module is device-only
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
+ android.InitDefaultableModule(module)
return module
}
@@ -459,6 +461,7 @@
InitPrebuiltEtcModule(module, "usr/share")
// This module is device-only
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
+ android.InitDefaultableModule(module)
return module
}
@@ -469,6 +472,7 @@
InitPrebuiltEtcModule(module, "usr/share")
// This module is host-only
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
+ android.InitDefaultableModule(module)
return module
}
@@ -478,6 +482,7 @@
InitPrebuiltEtcModule(module, "fonts")
// This module is device-only
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
+ android.InitDefaultableModule(module)
return module
}
@@ -491,6 +496,7 @@
InitPrebuiltEtcModule(module, "etc/firmware")
// This module is device-only
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
+ android.InitDefaultableModule(module)
return module
}
@@ -503,6 +509,7 @@
InitPrebuiltEtcModule(module, "etc/dsp")
// This module is device-only
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
+ android.InitDefaultableModule(module)
return module
}
@@ -516,6 +523,7 @@
InitPrebuiltEtcModule(module, "lib/rfsa")
// This module is device-only
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
+ android.InitDefaultableModule(module)
return module
}
diff --git a/fuzz/fuzz_common.go b/fuzz/fuzz_common.go
index ccadc0f..8861d1b 100644
--- a/fuzz/fuzz_common.go
+++ b/fuzz/fuzz_common.go
@@ -42,8 +42,9 @@
}
type FuzzPackager struct {
- Packages android.Paths
- FuzzTargets map[string]bool
+ Packages android.Paths
+ FuzzTargets map[string]bool
+ SharedLibInstallStrings []string
}
type FileToZip struct {
@@ -251,3 +252,42 @@
sort.Strings(fuzzTargets)
ctx.Strict(targets, strings.Join(fuzzTargets, " "))
}
+
+// CollectAllSharedDependencies performs a breadth-first search over the provided module's
+// dependencies using `visitDirectDeps` to enumerate all shared library
+// dependencies. We require breadth-first expansion, as otherwise we may
+// incorrectly use the core libraries (sanitizer runtimes, libc, libdl, etc.)
+// from a dependency. This may cause issues when dependencies have explicit
+// sanitizer tags, as we may get a dependency on an unsanitized libc, etc.
+func CollectAllSharedDependencies(ctx android.SingletonContext, module android.Module, unstrippedOutputFile func(module android.Module) android.Path, isValidSharedDependency func(dependency android.Module) bool) android.Paths {
+ var fringe []android.Module
+
+ seen := make(map[string]bool)
+
+ // Enumerate the first level of dependencies, as we discard all non-library
+ // modules in the BFS loop below.
+ ctx.VisitDirectDeps(module, func(dep android.Module) {
+ if isValidSharedDependency(dep) {
+ fringe = append(fringe, dep)
+ }
+ })
+
+ var sharedLibraries android.Paths
+
+ for i := 0; i < len(fringe); i++ {
+ module := fringe[i]
+ if seen[module.Name()] {
+ continue
+ }
+ seen[module.Name()] = true
+
+ sharedLibraries = append(sharedLibraries, unstrippedOutputFile(module))
+ ctx.VisitDirectDeps(module, func(dep android.Module) {
+ if isValidSharedDependency(dep) && !seen[dep.Name()] {
+ fringe = append(fringe, dep)
+ }
+ })
+ }
+
+ return sharedLibraries
+}
diff --git a/java/androidmk.go b/java/androidmk.go
index 537159e..eca5caa 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -60,6 +60,11 @@
func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
var entriesList []android.AndroidMkEntries
+ if library.Os() == android.Windows {
+ // Make does not support Windows Java modules
+ return nil
+ }
+
if library.hideApexVariantFromMake {
// For a java library built for an APEX, we don't need a Make module for itself. Otherwise, it
// will conflict with the platform variant because they have the same module name in the
@@ -250,6 +255,10 @@
}
func (binary *Binary) AndroidMkEntries() []android.AndroidMkEntries {
+ if binary.Os() == android.Windows {
+ // Make does not support Windows Java modules
+ return nil
+ }
if !binary.isWrapperVariant {
return []android.AndroidMkEntries{android.AndroidMkEntries{
diff --git a/java/device_host_converter.go b/java/device_host_converter.go
index 39fb04a..4abdcc6 100644
--- a/java/device_host_converter.go
+++ b/java/device_host_converter.go
@@ -118,7 +118,7 @@
TransformJarsToJar(ctx, outputFile, "combine", d.implementationAndResourceJars,
android.OptionalPath{}, false, nil, nil)
d.combinedImplementationJar = outputFile
- } else {
+ } else if len(d.implementationAndResourceJars) == 1 {
d.combinedImplementationJar = d.implementationAndResourceJars[0]
}
@@ -127,7 +127,7 @@
TransformJarsToJar(ctx, outputFile, "turbine combine", d.headerJars,
android.OptionalPath{}, false, nil, []string{"META-INF/TRANSITIVE"})
d.combinedHeaderJar = outputFile
- } else {
+ } else if len(d.headerJars) == 1 {
d.combinedHeaderJar = d.headerJars[0]
}
@@ -174,7 +174,9 @@
return android.AndroidMkData{
Class: "JAVA_LIBRARIES",
OutputFile: android.OptionalPathForPath(d.combinedImplementationJar),
- Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
+ // Make does not support Windows Java modules
+ Disabled: d.Os() == android.Windows,
+ Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Extra: []android.AndroidMkExtraFunc{
func(w io.Writer, outputFile android.Path) {
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
diff --git a/java/java.go b/java/java.go
index 287bcfa..29f31e5 100644
--- a/java/java.go
+++ b/java/java.go
@@ -532,6 +532,14 @@
return false
}
+// Sets `dexer.dexProperties.Uncompress_dex` to the proper value.
+func setUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter, dexer *dexer) {
+ if dexer.dexProperties.Uncompress_dex == nil {
+ // If the value was not force-set by the user, use reasonable default based on the module.
+ dexer.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, dexpreopter))
+ }
+}
+
func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.sdkVersion = j.SdkVersion(ctx)
j.minSdkVersion = j.MinSdkVersion(ctx)
@@ -545,10 +553,7 @@
j.dexpreopter.installPath = j.dexpreopter.getInstallPath(
ctx, android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar"))
j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
- if j.dexProperties.Uncompress_dex == nil {
- // If the value was not force-set by the user, use reasonable default based on the module.
- j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter))
- }
+ setUncompressDex(ctx, &j.dexpreopter, &j.dexer)
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
j.classLoaderContexts = j.usesLibrary.classLoaderContextForUsesLibDeps(ctx)
j.compile(ctx, nil)
@@ -565,10 +570,6 @@
j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
j.Stem()+".jar", j.outputFile, extraInstallDeps...)
}
-
- if ctx.Windows() {
- j.HideFromMake()
- }
}
func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
@@ -1135,10 +1136,6 @@
j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
ctx.ModuleName()+ext, j.wrapperFile)
}
-
- if ctx.Windows() {
- j.HideFromMake()
- }
}
func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
@@ -1401,16 +1398,13 @@
installPath := android.PathForModuleInPartitionInstall(ctx, "apex", ai.ApexVariationName, apexRootRelativePathToJavaLib(j.BaseModuleName()))
j.dexJarInstallFile = installPath
- // Initialize the hiddenapi structure.
- j.initHiddenAPI(ctx, dexJarFile, outputFile, nil)
-
j.dexpreopter.installPath = j.dexpreopter.getInstallPath(ctx, installPath)
- if j.dexProperties.Uncompress_dex == nil {
- // If the value was not force-set by the user, use reasonable default based on the module.
- j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter))
- }
+ setUncompressDex(ctx, &j.dexpreopter, &j.dexer)
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
j.dexpreopt(ctx, dexOutputPath)
+
+ // Initialize the hiddenapi structure.
+ j.initHiddenAPI(ctx, dexJarFile, outputFile, j.dexProperties.Uncompress_dex)
} else {
// This should never happen as a variant for a prebuilt_apex is only created if the
// prebuilt_apex has been configured to export the java library dex file.
@@ -1430,10 +1424,7 @@
j.dexpreopter.installPath = j.dexpreopter.getInstallPath(
ctx, android.PathForModuleInstall(ctx, "framework", jarName))
- if j.dexProperties.Uncompress_dex == nil {
- // If the value was not force-set by the user, use reasonable default based on the module.
- j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter))
- }
+ setUncompressDex(ctx, &j.dexpreopter, &j.dexer)
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
var dexOutputFile android.OutputPath
diff --git a/rust/fuzz.go b/rust/fuzz.go
index 5fb56ff..a628b61 100644
--- a/rust/fuzz.go
+++ b/rust/fuzz.go
@@ -111,6 +111,10 @@
// List of individual fuzz targets.
s.FuzzTargets = make(map[string]bool)
+ // Map tracking whether each shared library has an install rule to avoid duplicate install rules from
+ // multiple fuzzers that depend on the same shared library.
+ sharedLibraryInstalled := make(map[string]bool)
+
ctx.VisitAllModules(func(module android.Module) {
// Discard non-fuzz targets.
rustModule, ok := module.(*Module)
@@ -145,6 +149,12 @@
// The executable.
files = append(files, fuzz.FileToZip{rustModule.unstrippedOutputFile.Path(), ""})
+ // Grab the list of required shared libraries.
+ sharedLibraries := fuzz.CollectAllSharedDependencies(ctx, module, cc.UnstrippedOutputFile, cc.IsValidSharedDependency)
+
+ // Package shared libraries
+ files = append(files, cc.GetSharedLibsToZip(sharedLibraries, rustModule, &s.FuzzPackager, archString, &sharedLibraryInstalled)...)
+
archDirs[archOs], ok = s.BuildZipFile(ctx, module, fuzzModule.fuzzPackagedModule, files, builder, archDir, archString, hostOrTargetString, archOs, archDirs)
if !ok {
return
diff --git a/rust/rust.go b/rust/rust.go
index 93dbd00..13169f1 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -594,6 +594,13 @@
return false
}
+func (mod *Module) UnstrippedOutputFile() android.Path {
+ if mod.unstrippedOutputFile.Valid() {
+ return mod.unstrippedOutputFile.Path()
+ }
+ return nil
+}
+
func (mod *Module) IncludeDirs() android.Paths {
if mod.compiler != nil {
if library, ok := mod.compiler.(*libraryDecorator); ok {