Merge "Revert "Keep minimal abort when enabling integer overflow check""
diff --git a/android/Android.bp b/android/Android.bp
index 65332b2..cbd3459 100644
--- a/android/Android.bp
+++ b/android/Android.bp
@@ -98,6 +98,7 @@
"apex_test.go",
"arch_test.go",
"bazel_handler_test.go",
+ "bazel_paths_test.go",
"bazel_test.go",
"config_test.go",
"config_bp2build_test.go",
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index ee200a1..672d7f6 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -37,16 +37,18 @@
var (
Bp2buildDefaultConfig = Bp2BuildConfig{
- "art/libartpalette": Bp2BuildDefaultTrueRecursively,
- "art/libdexfile": Bp2BuildDefaultTrueRecursively,
- "art/libnativebridge": Bp2BuildDefaultTrueRecursively,
- "art/runtime": Bp2BuildDefaultTrueRecursively,
- "art/tools": Bp2BuildDefaultTrue,
- "bionic": Bp2BuildDefaultTrueRecursively,
- "bootable/recovery/tools/recovery_l10n": Bp2BuildDefaultTrue,
- "build/bazel/examples/apex/minimal": Bp2BuildDefaultTrueRecursively,
+ "prebuilts/runtime/mainline/platform/sdk": Bp2BuildDefaultTrueRecursively,
+ "art/libartpalette": Bp2BuildDefaultTrueRecursively,
+ "art/libdexfile": Bp2BuildDefaultTrueRecursively,
+ "art/libnativebridge": Bp2BuildDefaultTrueRecursively,
+ "art/runtime": Bp2BuildDefaultTrueRecursively,
+ "art/tools": Bp2BuildDefaultTrue,
+ "bionic": Bp2BuildDefaultTrueRecursively,
+ "bootable/recovery/tools/recovery_l10n": Bp2BuildDefaultTrue,
+ "build/bazel/examples/apex/minimal": Bp2BuildDefaultTrueRecursively,
"build/bazel/examples/soong_config_variables": Bp2BuildDefaultTrueRecursively,
"build/bazel/examples/python": Bp2BuildDefaultTrueRecursively,
+ "build/bazel/examples/gensrcs": Bp2BuildDefaultTrueRecursively,
"build/make/target/product/security": Bp2BuildDefaultTrue,
"build/make/tools/signapk": Bp2BuildDefaultTrue,
"build/make/tools/zipalign": Bp2BuildDefaultTrueRecursively,
@@ -203,6 +205,7 @@
"system/libziparchive": Bp2BuildDefaultTrueRecursively,
"system/logging/liblog": Bp2BuildDefaultTrueRecursively,
"system/media/audio": Bp2BuildDefaultTrueRecursively,
+ "system/memory/libion": Bp2BuildDefaultTrueRecursively,
"system/memory/libmemunreachable": Bp2BuildDefaultTrueRecursively,
"system/sepolicy/apex": Bp2BuildDefaultTrueRecursively,
"system/timezone/apex": Bp2BuildDefaultTrueRecursively,
@@ -262,21 +265,56 @@
Bp2buildModuleAlwaysConvertList = []string{
// cc mainline modules
- "libnativeloader-headers",
- "libgui_bufferqueue_sources",
"code_coverage.policy",
"code_coverage.policy.other",
"codec2_soft_exports",
+ "com.android.media.swcodec-androidManifest",
"com.android.media.swcodec-ld.config.txt",
- "libcodec2_headers",
- "libcodec2_internal",
"com.android.media.swcodec-mediaswcodec.rc",
+ "com.android.media.swcodec.certificate",
+ "com.android.media.swcodec.key",
+ "com.android.neuralnetworks-androidManifest",
+ "com.android.neuralnetworks.certificate",
+ "com.android.neuralnetworks.key",
"flatbuffer_headers",
"gemmlowp_headers",
"gl_headers",
- "libbluetooth-types-header",
+ "libandroid_runtime_vm_headers",
"libaudioclient_aidl_conversion_util",
"libaudioutils_fixedfft",
+ "libbinder_headers_platform_shared",
+ "libbluetooth-types-header",
+ "libcodec2_headers",
+ "libcodec2_internal",
+ "libdmabufheap",
+ "libgsm",
+ "libgui_bufferqueue_sources",
+ "libhardware_headers",
+ "libnativeloader-headers",
+ "libnativewindow_headers",
+ "libneuralnetworks_headers",
+ "libopus",
+ "libprocpartition",
+ "libserviceutils",
+ "libstagefright_amrnb_common",
+ "libstagefright_amrwbdec",
+ "libstagefright_enc_common",
+ "libstagefright_foundation_headers",
+ "libstagefright_headers",
+ "libstagefright_m4vh263dec",
+ "libstagefright_m4vh263enc",
+ "libstagefright_mp3dec_headers",
+ "libsync",
+ "libtextclassifier_hash_headers",
+ "libtextclassifier_hash_static",
+ "libui-types",
+ "libvorbisidec",
+ "media_ndk_headers",
+ "mediaswcodec.policy",
+ "mediaswcodec.xml",
+ "philox_random_headers",
+ "server_configurable_flags",
+ "tensorflow_headers",
//external/avb
"avbtool",
@@ -324,8 +362,6 @@
"linker", // TODO(b/228316882): cc_binary uses link_crt
"libdebuggerd", // TODO(b/228314770): support product variable-specific header_libs
"versioner", // TODO(b/228313961): depends on prebuilt shared library libclang-cpp_host as a shared library, which does not supply expected providers for a shared library
- "f2fs.fibmap", // ld.lld: error: undefined symbol: _IO
- "f2fscrypt", // TODO(b/234340806): error: incompatible integer to pointer conversion initializing 'FILE *' (aka 'struct _IO_FILE *') with an expression of type 'int', and error: incomplete definition of type 'struct mntent'
"apexer", "apexer_test", // Requires aapt2
"apexer_test_host_tools",
"host_apex_verifier",
diff --git a/android/androidmk.go b/android/androidmk.go
index 5c715b4..6b675a6 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -288,6 +288,8 @@
// The contributions to the dist.
type distContributions struct {
+ // Path to license metadata file.
+ licenseMetadataFile Path
// List of goals and the dist copy instructions.
copiesForGoals []*copiesForGoals
}
@@ -364,6 +366,8 @@
// Collate the contributions this module makes to the dist.
distContributions := &distContributions{}
+ distContributions.licenseMetadataFile = amod.licenseMetadataFile
+
// Iterate over this module's dist structs, merged from the dist and dists properties.
for _, dist := range amod.Dists() {
// Get the list of goals this dist should be enabled for. e.g. sdk, droidcore
@@ -456,6 +460,10 @@
for _, c := range d.copies {
ret = append(
ret,
+ fmt.Sprintf("$(if $(strip $(ALL_TARGETS.%s.META_LIC)),,$(eval ALL_TARGETS.%s.META_LIC := %s))\n",
+ c.from.String(), c.from.String(), distContributions.licenseMetadataFile.String()))
+ ret = append(
+ ret,
fmt.Sprintf("$(call dist-for-goals,%s,%s:%s)\n", d.goals, c.from.String(), c.dest))
}
}
diff --git a/android/androidmk_test.go b/android/androidmk_test.go
index caf11f1..ae2187f 100644
--- a/android/androidmk_test.go
+++ b/android/androidmk_test.go
@@ -50,6 +50,8 @@
func (m *customModule) GenerateAndroidBuildActions(ctx ModuleContext) {
+ m.base().licenseMetadataFile = PathForOutput(ctx, "meta_lic")
+
// If the dist_output_file: true then create an output file that is stored in
// the OutputFile property of the AndroidMkEntry.
if proptools.BoolDefault(m.properties.Dist_output_file, true) {
@@ -198,10 +200,13 @@
},
}
+ dc.licenseMetadataFile = PathForTesting("meta_lic")
makeOutput := generateDistContributionsForMake(dc)
assertStringEquals(t, `.PHONY: my_goal
+$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))
$(call dist-for-goals,my_goal,one.out:one.out)
+$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))
$(call dist-for-goals,my_goal,two.out:other.out)
`, strings.Join(makeOutput, ""))
}
@@ -243,18 +248,26 @@
expectedAndroidMkLines := []string{
".PHONY: my_second_goal\n",
+ "$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))\n",
"$(call dist-for-goals,my_second_goal,two.out:two.out)\n",
+ "$(if $(strip $(ALL_TARGETS.three/four.out.META_LIC)),,$(eval ALL_TARGETS.three/four.out.META_LIC := meta_lic))\n",
"$(call dist-for-goals,my_second_goal,three/four.out:four.out)\n",
".PHONY: my_third_goal\n",
+ "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n",
"$(call dist-for-goals,my_third_goal,one.out:test/dir/one.out)\n",
".PHONY: my_fourth_goal\n",
+ "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n",
"$(call dist-for-goals,my_fourth_goal,one.out:one.suffix.out)\n",
".PHONY: my_fifth_goal\n",
+ "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n",
"$(call dist-for-goals,my_fifth_goal,one.out:new-name)\n",
".PHONY: my_sixth_goal\n",
+ "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n",
"$(call dist-for-goals,my_sixth_goal,one.out:some/dir/new-name.suffix)\n",
".PHONY: my_goal my_other_goal\n",
+ "$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))\n",
"$(call dist-for-goals,my_goal my_other_goal,two.out:two.out)\n",
+ "$(if $(strip $(ALL_TARGETS.three/four.out.META_LIC)),,$(eval ALL_TARGETS.three/four.out.META_LIC := meta_lic))\n",
"$(call dist-for-goals,my_goal my_other_goal,three/four.out:four.out)\n",
}
@@ -274,7 +287,7 @@
)
}
for idx, line := range androidMkLines {
- expectedLine := expectedAndroidMkLines[idx]
+ expectedLine := strings.ReplaceAll(expectedAndroidMkLines[idx], "meta_lic", module.base().licenseMetadataFile.String())
if line != expectedLine {
t.Errorf(
"Expected AndroidMk line to be '%s', got '%s'",
diff --git a/android/arch.go b/android/arch.go
index f732a7d..cbf77c7 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -1832,10 +1832,10 @@
return ret
}
-// firstTarget takes a list of Targets and a list of multilib values and returns a list of Targets
+// FirstTarget takes a list of Targets and a list of multilib values and returns a list of Targets
// that contains zero or one Target for each OsType, selecting the one that matches the earliest
// filter.
-func firstTarget(targets []Target, filters ...string) []Target {
+func FirstTarget(targets []Target, filters ...string) []Target {
// find the first target from each OS
var ret []Target
hasHost := false
@@ -1865,9 +1865,9 @@
case "common_first":
buildTargets = getCommonTargets(targets)
if prefer32 {
- buildTargets = append(buildTargets, firstTarget(targets, "lib32", "lib64")...)
+ buildTargets = append(buildTargets, FirstTarget(targets, "lib32", "lib64")...)
} else {
- buildTargets = append(buildTargets, firstTarget(targets, "lib64", "lib32")...)
+ buildTargets = append(buildTargets, FirstTarget(targets, "lib64", "lib32")...)
}
case "both":
if prefer32 {
@@ -1883,12 +1883,12 @@
buildTargets = filterMultilibTargets(targets, "lib64")
case "first":
if prefer32 {
- buildTargets = firstTarget(targets, "lib32", "lib64")
+ buildTargets = FirstTarget(targets, "lib32", "lib64")
} else {
- buildTargets = firstTarget(targets, "lib64", "lib32")
+ buildTargets = FirstTarget(targets, "lib64", "lib32")
}
case "first_prefer32":
- buildTargets = firstTarget(targets, "lib32", "lib64")
+ buildTargets = FirstTarget(targets, "lib32", "lib64")
case "prefer32":
buildTargets = filterMultilibTargets(targets, "lib32")
if len(buildTargets) == 0 {
diff --git a/android/bazel_handler.go b/android/bazel_handler.go
index 4d9423a..8ab003c 100644
--- a/android/bazel_handler.go
+++ b/android/bazel_handler.go
@@ -878,7 +878,7 @@
}
// The actual Bazel action.
- cmd.Text(" " + buildStatement.Command)
+ cmd.Text(buildStatement.Command)
for _, outputPath := range buildStatement.OutputPaths {
cmd.ImplicitOutput(PathForBazelOut(ctx, outputPath))
diff --git a/android/bazel_paths.go b/android/bazel_paths.go
index fa10f62..1d0a6d5 100644
--- a/android/bazel_paths.go
+++ b/android/bazel_paths.go
@@ -449,25 +449,51 @@
return PathForModuleObj(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
}
-// PathForBazelOut returns a Path representing the paths... under an output directory dedicated to
-// bazel-owned outputs.
-func PathForBazelOut(ctx PathContext, paths ...string) BazelOutPath {
- execRootPathComponents := append([]string{"execroot", "__main__"}, paths...)
- execRootPath := filepath.Join(execRootPathComponents...)
- validatedExecRootPath, err := validatePath(execRootPath)
+// PathForBazelOutRelative returns a BazelOutPath representing the path under an output directory dedicated to
+// bazel-owned outputs. Calling .Rel() on the result will give the input path as relative to the given
+// relativeRoot.
+func PathForBazelOutRelative(ctx PathContext, relativeRoot string, path string) BazelOutPath {
+ validatedPath, err := validatePath(filepath.Join("execroot", "__main__", path))
if err != nil {
reportPathError(ctx, err)
}
+ relativeRootPath := filepath.Join("execroot", "__main__", relativeRoot)
+ if pathComponents := strings.Split(path, "/"); len(pathComponents) >= 3 &&
+ pathComponents[0] == "bazel-out" && pathComponents[2] == "bin" {
+ // If the path starts with something like: bazel-out/linux_x86_64-fastbuild-ST-b4ef1c4402f9/bin/
+ // make it relative to that folder. bazel-out/volatile-status.txt is an example
+ // of something that starts with bazel-out but is not relative to the bin folder
+ relativeRootPath = filepath.Join("execroot", "__main__", pathComponents[0], pathComponents[1], pathComponents[2], relativeRoot)
+ }
- outputPath := OutputPath{basePath{"", ""},
+ var relPath string
+ if relPath, err = filepath.Rel(relativeRootPath, validatedPath); err != nil || strings.HasPrefix(relPath, "../") {
+ // We failed to make this path relative to execroot/__main__, fall back to a non-relative path
+ // One case where this happens is when path is ../bazel_tools/something
+ relativeRootPath = ""
+ relPath = validatedPath
+ }
+
+ outputPath := OutputPath{
+ basePath{"", ""},
ctx.Config().soongOutDir,
- ctx.Config().BazelContext.OutputBase()}
+ ctx.Config().BazelContext.OutputBase(),
+ }
return BazelOutPath{
- OutputPath: outputPath.withRel(validatedExecRootPath),
+ // .withRel() appends its argument onto the current path, and only the most
+ // recently appended part is returned by outputPath.rel().
+ // So outputPath.rel() will return relPath.
+ OutputPath: outputPath.withRel(relativeRootPath).withRel(relPath),
}
}
+// PathForBazelOut returns a BazelOutPath representing the path under an output directory dedicated to
+// bazel-owned outputs.
+func PathForBazelOut(ctx PathContext, path string) BazelOutPath {
+ return PathForBazelOutRelative(ctx, "", path)
+}
+
// PathsForBazelOut returns a list of paths representing the paths under an output directory
// dedicated to Bazel-owned outputs.
func PathsForBazelOut(ctx PathContext, paths []string) Paths {
diff --git a/android/bazel_paths_test.go b/android/bazel_paths_test.go
new file mode 100644
index 0000000..b047511
--- /dev/null
+++ b/android/bazel_paths_test.go
@@ -0,0 +1,108 @@
+// Copyright 2022 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package android
+
+import (
+ "path/filepath"
+ "testing"
+)
+
+type TestBazelPathContext struct{}
+
+func (*TestBazelPathContext) Config() Config {
+ cfg := NullConfig("out", "out/soong")
+ cfg.BazelContext = MockBazelContext{
+ OutputBaseDir: "out/bazel",
+ }
+ return cfg
+}
+
+func (*TestBazelPathContext) AddNinjaFileDeps(deps ...string) {
+ panic("Unimplemented")
+}
+
+func TestPathForBazelOut(t *testing.T) {
+ ctx := &TestBazelPathContext{}
+ out := PathForBazelOut(ctx, "foo/bar/baz/boq.txt")
+ expectedPath := filepath.Join(ctx.Config().BazelContext.OutputBase(), "execroot/__main__/foo/bar/baz/boq.txt")
+ if out.String() != expectedPath {
+ t.Errorf("incorrect OutputPath: expected %q, got %q", expectedPath, out.String())
+ }
+
+ expectedRelPath := "foo/bar/baz/boq.txt"
+ if out.Rel() != expectedRelPath {
+ t.Errorf("incorrect OutputPath.Rel(): expected %q, got %q", expectedRelPath, out.Rel())
+ }
+}
+
+func TestPathForBazelOutRelative(t *testing.T) {
+ ctx := &TestBazelPathContext{}
+ out := PathForBazelOutRelative(ctx, "foo/bar", "foo/bar/baz/boq.txt")
+
+ expectedPath := filepath.Join(ctx.Config().BazelContext.OutputBase(), "execroot/__main__/foo/bar/baz/boq.txt")
+ if out.String() != expectedPath {
+ t.Errorf("incorrect OutputPath: expected %q, got %q", expectedPath, out.String())
+ }
+
+ expectedRelPath := "baz/boq.txt"
+ if out.Rel() != expectedRelPath {
+ t.Errorf("incorrect OutputPath.Rel(): expected %q, got %q", expectedRelPath, out.Rel())
+ }
+}
+
+func TestPathForBazelOutRelativeUnderBinFolder(t *testing.T) {
+ ctx := &TestBazelPathContext{}
+ out := PathForBazelOutRelative(ctx, "foo/bar", "bazel-out/linux_x86_64-fastbuild-ST-b4ef1c4402f9/bin/foo/bar/baz/boq.txt")
+
+ expectedPath := filepath.Join(ctx.Config().BazelContext.OutputBase(), "execroot/__main__/bazel-out/linux_x86_64-fastbuild-ST-b4ef1c4402f9/bin/foo/bar/baz/boq.txt")
+ if out.String() != expectedPath {
+ t.Errorf("incorrect OutputPath: expected %q, got %q", expectedPath, out.String())
+ }
+
+ expectedRelPath := "baz/boq.txt"
+ if out.Rel() != expectedRelPath {
+ t.Errorf("incorrect OutputPath.Rel(): expected %q, got %q", expectedRelPath, out.Rel())
+ }
+}
+
+func TestPathForBazelOutOutsideOfExecroot(t *testing.T) {
+ ctx := &TestBazelPathContext{}
+ out := PathForBazelOut(ctx, "../bazel_tools/linux_x86_64-fastbuild/bin/tools/android/java_base_extras.jar")
+
+ expectedPath := filepath.Join(ctx.Config().BazelContext.OutputBase(), "execroot/bazel_tools/linux_x86_64-fastbuild/bin/tools/android/java_base_extras.jar")
+ if out.String() != expectedPath {
+ t.Errorf("incorrect OutputPath: expected %q, got %q", expectedPath, out.String())
+ }
+
+ expectedRelPath := "execroot/bazel_tools/linux_x86_64-fastbuild/bin/tools/android/java_base_extras.jar"
+ if out.Rel() != expectedRelPath {
+ t.Errorf("incorrect OutputPath.Rel(): expected %q, got %q", expectedRelPath, out.Rel())
+ }
+}
+
+func TestPathForBazelOutRelativeWithParentDirectoryRoot(t *testing.T) {
+ ctx := &TestBazelPathContext{}
+ out := PathForBazelOutRelative(ctx, "../bazel_tools", "../bazel_tools/foo/bar/baz.sh")
+
+ expectedPath := filepath.Join(ctx.Config().BazelContext.OutputBase(), "execroot/bazel_tools/foo/bar/baz.sh")
+ if out.String() != expectedPath {
+ t.Errorf("incorrect OutputPath: expected %q, got %q", expectedPath, out.String())
+ }
+
+ expectedRelPath := "foo/bar/baz.sh"
+ if out.Rel() != expectedRelPath {
+ t.Errorf("incorrect OutputPath.Rel(): expected %q, got %q", expectedRelPath, out.Rel())
+ }
+}
diff --git a/android/config.go b/android/config.go
index eb01baa..ef71292 100644
--- a/android/config.go
+++ b/android/config.go
@@ -416,7 +416,7 @@
config.BuildOSTarget = config.Targets[config.BuildOS][0]
config.BuildOSCommonTarget = getCommonTargets(config.Targets[config.BuildOS])[0]
config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
- config.AndroidFirstDeviceTarget = firstTarget(config.Targets[Android], "lib64", "lib32")[0]
+ config.AndroidFirstDeviceTarget = FirstTarget(config.Targets[Android], "lib64", "lib32")[0]
config.TestProductVariables.DeviceArch = proptools.StringPtr("arm64")
config.TestProductVariables.DeviceArchVariant = proptools.StringPtr("armv8-a")
config.TestProductVariables.DeviceSecondaryArch = proptools.StringPtr("arm")
@@ -554,7 +554,7 @@
// Compilation targets for Android.
if len(config.Targets[Android]) > 0 {
config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
- config.AndroidFirstDeviceTarget = firstTarget(config.Targets[Android], "lib64", "lib32")[0]
+ config.AndroidFirstDeviceTarget = FirstTarget(config.Targets[Android], "lib64", "lib32")[0]
}
config.BazelContext, err = NewBazelContext(config)
diff --git a/android/filegroup.go b/android/filegroup.go
index 14ed783..9e5769a 100644
--- a/android/filegroup.go
+++ b/android/filegroup.go
@@ -178,8 +178,7 @@
bazelOuts := make(Paths, 0, len(filePaths))
for _, p := range filePaths {
- src := PathForBazelOut(ctx, p)
- bazelOuts = append(bazelOuts, src)
+ bazelOuts = append(bazelOuts, PathForBazelOutRelative(ctx, ctx.ModuleDir(), p))
}
fg.srcs = bazelOuts
diff --git a/android/gen_notice.go b/android/gen_notice.go
index fda91ac..e2b839f 100644
--- a/android/gen_notice.go
+++ b/android/gen_notice.go
@@ -67,7 +67,12 @@
if ctx.Failed() {
return
}
- out(ctx, gm.output, ctx.ModuleName(gm), proptools.StringDefault(gm.properties.ArtifactName, defaultName), "", modules...)
+ out(ctx, gm.output, ctx.ModuleName(gm),
+ proptools.StringDefault(gm.properties.ArtifactName, defaultName),
+ []string{
+ ctx.Config().OutDir() + "/",
+ ctx.Config().SoongOutDir() + "/",
+ }, modules...)
})
}
diff --git a/android/license_metadata.go b/android/license_metadata.go
index 6a5b0da..48c1383 100644
--- a/android/license_metadata.go
+++ b/android/license_metadata.go
@@ -105,7 +105,7 @@
if p := base.commonProperties.Effective_package_name; p != nil {
args = append(args,
- "-p "+proptools.NinjaAndShellEscape(*p))
+ `-p "`+proptools.NinjaAndShellEscape(*p)+`"`)
}
args = append(args,
diff --git a/android/licenses.go b/android/licenses.go
index 81c557e..c47b3e6 100644
--- a/android/licenses.go
+++ b/android/licenses.go
@@ -331,6 +331,8 @@
func licensesMakeVarsProvider(ctx MakeVarsContext) {
ctx.Strict("BUILD_LICENSE_METADATA",
ctx.Config().HostToolPath(ctx, "build_license_metadata").String())
+ ctx.Strict("COPY_LICENSE_METADATA",
+ ctx.Config().HostToolPath(ctx, "copy_license_metadata").String())
ctx.Strict("HTMLNOTICE", ctx.Config().HostToolPath(ctx, "htmlnotice").String())
ctx.Strict("XMLNOTICE", ctx.Config().HostToolPath(ctx, "xmlnotice").String())
ctx.Strict("TEXTNOTICE", ctx.Config().HostToolPath(ctx, "textnotice").String())
diff --git a/android/makevars.go b/android/makevars.go
index ece7091..a74185a 100644
--- a/android/makevars.go
+++ b/android/makevars.go
@@ -472,7 +472,8 @@
fmt.Fprintf(buf, "\tchmod +x $@\n")
}
if extraFiles := install.extraFiles; extraFiles != nil {
- fmt.Fprintf(buf, "\tunzip -qDD -d '%s' '%s'\n", extraFiles.dir.String(), extraFiles.zip.String())
+ fmt.Fprintf(buf, "\t( unzip -qDD -d '%s' '%s' 2>&1 | grep -v \"zipfile is empty\"; exit $${PIPESTATUS[0]} ) || \\\n", extraFiles.dir.String(), extraFiles.zip.String())
+ fmt.Fprintf(buf, "\t ( code=$$?; if [ $$code -ne 0 -a $$code -ne 1 ]; then exit $$code; fi )\n")
}
fmt.Fprintln(buf)
}
diff --git a/android/module.go b/android/module.go
index 21d5a3d..ad01e9e 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1181,33 +1181,89 @@
archVariantProps := mod.GetArchVariantProperties(ctx, &commonProperties{})
var enabledProperty bazel.BoolAttribute
- if props.Enabled != nil {
- enabledProperty.Value = props.Enabled
+
+ onlyAndroid := false
+ neitherHostNorDevice := false
+
+ osSupport := map[string]bool{}
+
+ // if the target is enabled and supports arch variance, determine the defaults based on the module
+ // type's host or device property and host_supported/device_supported properties
+ if mod.commonProperties.ArchSpecific {
+ moduleSupportsDevice := mod.DeviceSupported()
+ moduleSupportsHost := mod.HostSupported()
+ if moduleSupportsHost && !moduleSupportsDevice {
+ // for host only, we specify as unsupported on android rather than listing all host osSupport
+ // TODO(b/220874839): consider replacing this with a constraint that covers all host osSupport
+ // instead
+ enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, Android.Name, proptools.BoolPtr(false))
+ } else if moduleSupportsDevice && !moduleSupportsHost {
+ enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, Android.Name, proptools.BoolPtr(true))
+ // specify as a positive to ensure any target-specific enabled can be resolved
+ // also save that a target is only android, as if there is only the positive restriction on
+ // android, it'll be dropped, so we may need to add it back later
+ onlyAndroid = true
+ } else if !moduleSupportsHost && !moduleSupportsDevice {
+ neitherHostNorDevice = true
+ }
+
+ for _, os := range OsTypeList() {
+ if os.Class == Host {
+ osSupport[os.Name] = moduleSupportsHost
+ } else if os.Class == Device {
+ osSupport[os.Name] = moduleSupportsDevice
+ }
+ }
+ }
+
+ if neitherHostNorDevice {
+ // we can't build this, disable
+ enabledProperty.Value = proptools.BoolPtr(false)
+ } else if props.Enabled != nil {
+ enabledProperty.SetValue(props.Enabled)
+ if !*props.Enabled {
+ for os, enabled := range osSupport {
+ if val := enabledProperty.SelectValue(bazel.OsConfigurationAxis, os); enabled && val != nil && *val {
+ // if this should be disabled by default, clear out any enabling we've done
+ enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, os, nil)
+ }
+ }
+ }
}
for axis, configToProps := range archVariantProps {
for config, _props := range configToProps {
if archProps, ok := _props.(*commonProperties); ok {
required.SetSelectValue(axis, config, depsToLabelList(archProps.Required).Value)
- if archProps.Enabled != nil {
- enabledProperty.SetSelectValue(axis, config, archProps.Enabled)
+ if !neitherHostNorDevice {
+ if archProps.Enabled != nil {
+ if axis != bazel.OsConfigurationAxis || osSupport[config] {
+ enabledProperty.SetSelectValue(axis, config, archProps.Enabled)
+ }
+ }
}
}
}
}
- if enabledPropertyOverrides.Value != nil {
- enabledProperty.Value = enabledPropertyOverrides.Value
- }
- for _, axis := range enabledPropertyOverrides.SortedConfigurationAxes() {
- configToBools := enabledPropertyOverrides.ConfigurableValues[axis]
- for cfg, val := range configToBools {
- enabledProperty.SetSelectValue(axis, cfg, &val)
+ if !neitherHostNorDevice {
+ if enabledPropertyOverrides.Value != nil {
+ enabledProperty.Value = enabledPropertyOverrides.Value
+ }
+ for _, axis := range enabledPropertyOverrides.SortedConfigurationAxes() {
+ configToBools := enabledPropertyOverrides.ConfigurableValues[axis]
+ for cfg, val := range configToBools {
+ if axis != bazel.OsConfigurationAxis || osSupport[cfg] {
+ enabledProperty.SetSelectValue(axis, cfg, &val)
+ }
+ }
}
}
productConfigEnabledLabels := []bazel.Label{}
- if !proptools.BoolDefault(enabledProperty.Value, true) {
+ // TODO(b/234497586): Soong config variables and product variables have different overriding behavior, we
+ // should handle it correctly
+ if !proptools.BoolDefault(enabledProperty.Value, true) && !neitherHostNorDevice {
// If the module is not enabled by default, then we can check if a
// product variable enables it
productConfigEnabledLabels = productVariableConfigEnableLabels(ctx)
@@ -1224,11 +1280,6 @@
productConfigEnabledLabels, nil,
})
- moduleSupportsDevice := mod.commonProperties.HostOrDeviceSupported&deviceSupported == deviceSupported
- if mod.commonProperties.HostOrDeviceSupported != NeitherHostNorDeviceSupported && !moduleSupportsDevice {
- enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, Android.Name, proptools.BoolPtr(false))
- }
-
platformEnabledAttribute, err := enabledProperty.ToLabelListAttribute(
bazel.LabelList{[]bazel.Label{bazel.Label{Label: "@platforms//:incompatible"}}, nil},
bazel.LabelList{[]bazel.Label{}, nil})
@@ -1236,6 +1287,13 @@
ctx.ModuleErrorf("Error processing platform enabled attribute: %s", err)
}
+ // if android is the only arch/os enabled, then add a restriction to only be compatible with android
+ if platformEnabledAttribute.IsNil() && onlyAndroid {
+ l := bazel.LabelAttribute{}
+ l.SetValue(bazel.Label{Label: bazel.OsConfigurationAxis.SelectKey(Android.Name)})
+ platformEnabledAttribute.Add(&l)
+ }
+
data.Append(required)
constraints := constraintAttributes{}
@@ -3224,8 +3282,9 @@
extraCmds := ""
if extraZip != nil {
- extraCmds += fmt.Sprintf(" && unzip -qDD -d '%s' '%s'",
+ extraCmds += fmt.Sprintf(" && ( unzip -qDD -d '%s' '%s' 2>&1 | grep -v \"zipfile is empty\"; exit $${PIPESTATUS[0]} )",
extraZip.dir.String(), extraZip.zip.String())
+ extraCmds += " || ( code=$$?; if [ $$code -ne 0 -a $$code -ne 1 ]; then exit $$code; fi )"
implicitDeps = append(implicitDeps, extraZip.zip)
}
diff --git a/android/notices.go b/android/notices.go
index 562a156..b9c1682 100644
--- a/android/notices.go
+++ b/android/notices.go
@@ -47,7 +47,9 @@
}
// buildNoticeOutputFromLicenseMetadata writes out a notice file.
-func buildNoticeOutputFromLicenseMetadata(ctx BuilderContext, tool, ruleName string, outputFile WritablePath, libraryName, stripPrefix string, modules ...Module) {
+func buildNoticeOutputFromLicenseMetadata(
+ ctx BuilderContext, tool, ruleName string, outputFile WritablePath,
+ libraryName string, stripPrefix []string, modules ...Module) {
depsFile := outputFile.ReplaceExtension(ctx, strings.TrimPrefix(outputFile.Ext()+".d", "."))
rule := NewRuleBuilder(pctx, ctx)
if len(modules) == 0 {
@@ -64,8 +66,8 @@
BuiltTool(tool).
FlagWithOutput("-o ", outputFile).
FlagWithDepFile("-d ", depsFile)
- if stripPrefix != "" {
- cmd = cmd.FlagWithArg("--strip_prefix ", stripPrefix)
+ if len(stripPrefix) > 0 {
+ cmd = cmd.FlagForEachArg("--strip_prefix ", stripPrefix)
}
outputs := modulesOutputDirs(ctx, modules...)
if len(outputs) > 0 {
@@ -81,20 +83,29 @@
// BuildNoticeTextOutputFromLicenseMetadata writes out a notice text file based
// on the license metadata files for the input `modules` defaulting to the
// current context module if none given.
-func BuildNoticeTextOutputFromLicenseMetadata(ctx BuilderContext, outputFile WritablePath, ruleName, libraryName, stripPrefix string, modules ...Module) {
- buildNoticeOutputFromLicenseMetadata(ctx, "textnotice", "text_notice_"+ruleName, outputFile, libraryName, stripPrefix, modules...)
+func BuildNoticeTextOutputFromLicenseMetadata(
+ ctx BuilderContext, outputFile WritablePath, ruleName, libraryName string,
+ stripPrefix []string, modules ...Module) {
+ buildNoticeOutputFromLicenseMetadata(ctx, "textnotice", "text_notice_"+ruleName,
+ outputFile, libraryName, stripPrefix, modules...)
}
// BuildNoticeHtmlOutputFromLicenseMetadata writes out a notice text file based
// on the license metadata files for the input `modules` defaulting to the
// current context module if none given.
-func BuildNoticeHtmlOutputFromLicenseMetadata(ctx BuilderContext, outputFile WritablePath, ruleName, libraryName, stripPrefix string, modules ...Module) {
- buildNoticeOutputFromLicenseMetadata(ctx, "htmlnotice", "html_notice_"+ruleName, outputFile, libraryName, stripPrefix, modules...)
+func BuildNoticeHtmlOutputFromLicenseMetadata(
+ ctx BuilderContext, outputFile WritablePath, ruleName, libraryName string,
+ stripPrefix []string, modules ...Module) {
+ buildNoticeOutputFromLicenseMetadata(ctx, "htmlnotice", "html_notice_"+ruleName,
+ outputFile, libraryName, stripPrefix, modules...)
}
// BuildNoticeXmlOutputFromLicenseMetadata writes out a notice text file based
// on the license metadata files for the input `modules` defaulting to the
// current context module if none given.
-func BuildNoticeXmlOutputFromLicenseMetadata(ctx BuilderContext, outputFile WritablePath, ruleName, libraryName, stripPrefix string, modules ...Module) {
- buildNoticeOutputFromLicenseMetadata(ctx, "xmlnotice", "xml_notice_"+ruleName, outputFile, libraryName, stripPrefix, modules...)
+func BuildNoticeXmlOutputFromLicenseMetadata(
+ ctx BuilderContext, outputFile WritablePath, ruleName, libraryName string,
+ stripPrefix []string, modules ...Module) {
+ buildNoticeOutputFromLicenseMetadata(ctx, "xmlnotice", "xml_notice_"+ruleName,
+ outputFile, libraryName, stripPrefix, modules...)
}
diff --git a/android/prebuilt.go b/android/prebuilt.go
index 5843487..4e4fa42 100644
--- a/android/prebuilt.go
+++ b/android/prebuilt.go
@@ -110,6 +110,18 @@
return strings.TrimPrefix(name, "prebuilt_")
}
+// RemoveOptionalPrebuiltPrefixFromBazelLabel removes the "prebuilt_" prefix from the *target name* of a Bazel label.
+// This differs from RemoveOptionalPrebuiltPrefix in that it does not remove it from the start of the string, but
+// instead removes it from the target name itself.
+func RemoveOptionalPrebuiltPrefixFromBazelLabel(label string) string {
+ splitLabel := strings.Split(label, ":")
+ bazelModuleNameNoPrebuilt := RemoveOptionalPrebuiltPrefix(splitLabel[1])
+ return strings.Join([]string{
+ splitLabel[0],
+ bazelModuleNameNoPrebuilt,
+ }, ":")
+}
+
func (p *Prebuilt) Name(name string) string {
return PrebuiltNameFromSource(name)
}
diff --git a/android_sdk/sdk_repo_host.go b/android_sdk/sdk_repo_host.go
index 9519be0..280dae8 100644
--- a/android_sdk/sdk_repo_host.go
+++ b/android_sdk/sdk_repo_host.go
@@ -124,7 +124,12 @@
s.CopySpecsToDir(ctx, builder, packageSpecs, dir)
noticeFile := android.PathForModuleOut(ctx, "NOTICES.txt")
- android.BuildNoticeTextOutputFromLicenseMetadata(ctx, noticeFile, "", "", outputZipFile.String())
+ android.BuildNoticeTextOutputFromLicenseMetadata(
+ ctx, noticeFile, "", "",
+ []string{
+ android.PathForModuleInstall(ctx, "sdk-repo").String() + "/",
+ outputZipFile.String(),
+ })
builder.Command().Text("cp").
Input(noticeFile).
Text(filepath.Join(dir.String(), "NOTICE.txt"))
diff --git a/apex/Android.bp b/apex/Android.bp
index d3417c2..fcdf8e6 100644
--- a/apex/Android.bp
+++ b/apex/Android.bp
@@ -25,6 +25,7 @@
"apex.go",
"apex_singleton.go",
"builder.go",
+ "constants.go",
"deapexer.go",
"key.go",
"prebuilt.go",
diff --git a/apex/androidmk.go b/apex/androidmk.go
index e094a12..938c8ed 100644
--- a/apex/androidmk.go
+++ b/apex/androidmk.go
@@ -412,6 +412,7 @@
fmt.Fprintln(w, ".PHONY:", goal)
fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n",
goal, a.installedFilesFile.String(), distFile)
+ fmt.Fprintf(w, "$(call declare-0p-target,%s)\n", a.installedFilesFile.String())
}
for _, dist := range data.Entries.GetDistForGoals(a) {
fmt.Fprintf(w, dist)
diff --git a/apex/apex.go b/apex/apex.go
index 21725ff..beabbc9 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -2523,13 +2523,36 @@
}
// Prebuilts
- prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, overridableProperties.Prebuilts)
- attrs.Prebuilts = bazel.MakeLabelListAttribute(prebuiltsLabelList)
+ if overridableProperties.Prebuilts != nil {
+ prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, overridableProperties.Prebuilts)
+ attrs.Prebuilts = bazel.MakeLabelListAttribute(prebuiltsLabelList)
+ }
// Compressible
if overridableProperties.Compressible != nil {
attrs.Compressible = bazel.BoolAttribute{Value: overridableProperties.Compressible}
}
+
+ // Package name
+ //
+ // e.g. com.android.adbd's package name is com.android.adbd, but
+ // com.google.android.adbd overrides the package name to com.google.android.adbd
+ //
+ // TODO: this can be overridden from the product configuration, see
+ // getOverrideManifestPackageName and
+ // PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES.
+ //
+ // Instead of generating the BUILD files differently based on the product config
+ // at the point of conversion, this should be handled by the BUILD file loading
+ // from the soong_injection's product_vars, so product config is decoupled from bp2build.
+ if overridableProperties.Package_name != "" {
+ attrs.Package_name = &overridableProperties.Package_name
+ }
+
+ // Logging parent
+ if overridableProperties.Logging_parent != "" {
+ attrs.Logging_parent = &overridableProperties.Logging_parent
+ }
}
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: o.Name()}, &attrs)
@@ -3471,6 +3494,8 @@
Native_shared_libs_32 bazel.LabelListAttribute
Native_shared_libs_64 bazel.LabelListAttribute
Compressible bazel.BoolAttribute
+ Package_name *string
+ Logging_parent *string
}
type convertedNativeSharedLibs struct {
@@ -3565,6 +3590,16 @@
compressibleAttribute.Value = a.overridableProperties.Compressible
}
+ var packageName *string
+ if a.overridableProperties.Package_name != "" {
+ packageName = &a.overridableProperties.Package_name
+ }
+
+ var loggingParent *string
+ if a.overridableProperties.Logging_parent != "" {
+ loggingParent = &a.overridableProperties.Logging_parent
+ }
+
attrs := bazelApexBundleAttributes{
Manifest: manifestLabelAttribute,
Android_manifest: androidManifestLabelAttribute,
@@ -3579,6 +3614,8 @@
Binaries: binariesLabelListAttribute,
Prebuilts: prebuiltsLabelListAttribute,
Compressible: compressibleAttribute,
+ Package_name: packageName,
+ Logging_parent: loggingParent,
}
props := bazel.BazelTargetModuleProperties{
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 07372a3..7905710 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -6227,6 +6227,9 @@
name: "mybootclasspath_fragment",
contents: ["bcplib"],
apex_available: ["myapex"],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_library {
@@ -6241,6 +6244,9 @@
name: "override_bootclasspath_fragment",
contents: ["override_bcplib"],
apex_available: ["myapex"],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_library {
@@ -7294,6 +7300,9 @@
apex_available: [
"some-non-updatable-apex",
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_library {
@@ -7352,6 +7361,9 @@
apex_available: [
"com.android.art.debug",
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
apex_key {
@@ -8695,6 +8707,9 @@
name: "mybootclasspathfragment",
contents: ["mybootclasspathlib"],
apex_available: ["myapex"],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_library {
@@ -9015,6 +9030,9 @@
name: "mybootclasspathfragment",
contents: ["mybootclasspathlib"],
apex_available: ["myapex"],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_sdk_library {
@@ -9115,6 +9133,9 @@
name: "mybootclasspathfragment",
contents: ["mybootclasspathlib"],
apex_available: ["myapex"],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_sdk_library {
@@ -9334,6 +9355,9 @@
name: "mybootclasspathfragment",
contents: ["myjavalib"],
apex_available: ["myapex"],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_library {
name: "myjavalib",
diff --git a/apex/bootclasspath_fragment_test.go b/apex/bootclasspath_fragment_test.go
index ce6b7f7..b298dac 100644
--- a/apex/bootclasspath_fragment_test.go
+++ b/apex/bootclasspath_fragment_test.go
@@ -110,6 +110,9 @@
apex_available: [
"com.android.art",
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
`,
)
@@ -209,6 +212,9 @@
apex_available: [
"com.android.art",
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
bootclasspath_fragment {
@@ -220,6 +226,9 @@
module: "art-bootclasspath-fragment",
},
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
`,
)
@@ -361,6 +370,9 @@
apex_available: [
"com.android.art",
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
`, contentsInsert(contents))
@@ -853,6 +865,9 @@
apex_available: [
"myapex",
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
`)
@@ -959,6 +974,9 @@
apex_available: [
"com.android.art",
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
apex {
@@ -1010,6 +1028,9 @@
module: "art-bootclasspath-fragment",
},
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
`)
@@ -1123,6 +1144,9 @@
apex_available: [
"com.android.art",
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
apex {
@@ -1175,6 +1199,9 @@
module: "art-bootclasspath-fragment",
},
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
`)
@@ -1282,6 +1309,9 @@
apex_available: [
"com.android.art",
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
apex {
@@ -1334,6 +1364,9 @@
module: "art-bootclasspath-fragment",
},
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
`)
diff --git a/apex/builder.go b/apex/builder.go
index 9119363..fc9bb3b 100644
--- a/apex/builder.go
+++ b/apex/builder.go
@@ -618,7 +618,12 @@
// Create a NOTICE file, and embed it as an asset file in the APEX.
a.htmlGzNotice = android.PathForModuleOut(ctx, "NOTICE.html.gz")
- android.BuildNoticeHtmlOutputFromLicenseMetadata(ctx, a.htmlGzNotice, "", "", unsignedOutputFile.String())
+ android.BuildNoticeHtmlOutputFromLicenseMetadata(
+ ctx, a.htmlGzNotice, "", "",
+ []string{
+ android.PathForModuleInstall(ctx).String() + "/",
+ android.PathForModuleInPartitionInstall(ctx, "apex").String() + "/",
+ })
noticeAssetPath := android.PathForModuleOut(ctx, "NOTICE", "NOTICE.html.gz")
builder := android.NewRuleBuilder(pctx, ctx)
builder.Command().Text("cp").
@@ -650,6 +655,8 @@
optFlags = append(optFlags, "--manifest_json "+a.manifestJsonOut.String())
}
+ optFlags = append(optFlags, "--apex_version "+defaultManifestVersion)
+
optFlags = append(optFlags, "--payload_fs_type "+a.payloadFsType.string())
ctx.Build(pctx, android.BuildParams{
diff --git a/apex/classpath_element_test.go b/apex/classpath_element_test.go
index 60f18bd..9142eed 100644
--- a/apex/classpath_element_test.go
+++ b/apex/classpath_element_test.go
@@ -88,6 +88,9 @@
"baz",
"quuz",
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_library {
@@ -134,6 +137,9 @@
contents: [
"bar",
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_library {
diff --git a/apex/constants.go b/apex/constants.go
new file mode 100644
index 0000000..c68edb7
--- /dev/null
+++ b/apex/constants.go
@@ -0,0 +1,36 @@
+// Copyright (C) 2022 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package apex
+
+// This file contains branch specific constants. They are stored in a separate
+// file to minimise the potential of merge conflicts between branches when
+// the code from the package is changed.
+
+// The default manifest version for all the modules on this branch.
+// This version code will be used only if there is no version field in the
+// module's apex_manifest.json. Release branches have their version injected
+// into apex_manifest.json by the tooling and will not use the version set
+// here. Developers can also set the version field locally in the
+// apex_manifest.json to build a module with a specific version.
+//
+// The value follows the schema from go/mainline-version-codes, and is chosen
+// based on the branch such that the builds from testing and development
+// branches will have a version higher than the prebuilts.
+// Versions per branch:
+// * x-dev - xx0090000 (where xx is the branch SDK level)
+// * AOSP - xx9990000
+// * x-mainline-prod - xx9990000
+// * master - 990090000
+const defaultManifestVersion = "339990000"
diff --git a/apex/platform_bootclasspath_test.go b/apex/platform_bootclasspath_test.go
index 06c39ee..4b48da8 100644
--- a/apex/platform_bootclasspath_test.go
+++ b/apex/platform_bootclasspath_test.go
@@ -125,6 +125,7 @@
unsupported_packages: [
"bar-unsupported-packages.txt",
],
+ split_packages: ["*"],
},
}
@@ -274,6 +275,9 @@
"baz",
"quuz",
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_library {
@@ -317,6 +321,9 @@
name: "my-bootclasspath-fragment",
contents: ["bar"],
apex_available: ["myapex"],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
apex_key {
@@ -482,6 +489,9 @@
contents: [
"foo", "bar",
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
prebuilt_bootclasspath_fragment {
@@ -599,6 +609,9 @@
generate_classpaths_proto: false,
contents: ["foo"],
apex_available: ["myapex"],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_library {
@@ -656,6 +669,9 @@
contents: [
"foo",
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
platform_bootclasspath {
@@ -696,6 +712,9 @@
bootclasspath_fragment {
name: "not-in-apex-fragment",
contents: ["foo"],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
platform_bootclasspath {
@@ -746,6 +765,9 @@
name: "apex-fragment",
contents: ["foo", "bar"],
apex_available:[ "myapex" ],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
platform_bootclasspath {
diff --git a/bazel/aquery.go b/bazel/aquery.go
index ab31581..433d502 100644
--- a/bazel/aquery.go
+++ b/bazel/aquery.go
@@ -16,6 +16,7 @@
import (
"crypto/sha256"
+ "encoding/base64"
"encoding/json"
"fmt"
"path/filepath"
@@ -295,7 +296,7 @@
a.depsetHashToArtifactPathsCache[depsetHash] = result
return result, nil
} else {
- return nil, fmt.Errorf("undefined input depset hash %d", depsetHash)
+ return nil, fmt.Errorf("undefined input depset hash %s", depsetHash)
}
}
@@ -390,8 +391,8 @@
h := sha256.New()
// Use newline as delimiter, as paths cannot contain newline.
h.Write([]byte(strings.Join(directPaths, "\n")))
- h.Write([]byte(strings.Join(transitiveDepsetHashes, "\n")))
- fullHash := fmt.Sprintf("%016x", h.Sum(nil))
+ h.Write([]byte(strings.Join(transitiveDepsetHashes, "")))
+ fullHash := base64.RawURLEncoding.EncodeToString(h.Sum(nil))
return fullHash
}
diff --git a/bazel/aquery_test.go b/bazel/aquery_test.go
index 740a1f1..c9c8909 100644
--- a/bazel/aquery_test.go
+++ b/bazel/aquery_test.go
@@ -847,8 +847,8 @@
}
expectedDepsetFiles := [][]string{
- []string{"middleinput_one", "middleinput_two"},
- []string{"middleinput_one", "middleinput_two", "maininput_one", "maininput_two"},
+ {"middleinput_one", "middleinput_two", "maininput_one", "maininput_two"},
+ {"middleinput_one", "middleinput_two"},
}
assertFlattenedDepsets(t, actualDepsets, expectedDepsetFiles)
@@ -897,7 +897,7 @@
func assertFlattenedDepsets(t *testing.T, actualDepsets []AqueryDepset, expectedDepsetFiles [][]string) {
t.Helper()
if len(actualDepsets) != len(expectedDepsetFiles) {
- t.Errorf("Expected %d depsets, but got %d depsets", expectedDepsetFiles, actualDepsets)
+ t.Errorf("Expected %s depsets, but got %s depsets", expectedDepsetFiles, actualDepsets)
}
for i, actualDepset := range actualDepsets {
actualFlattenedInputs := flattenDepsets([]string{actualDepset.ContentHash}, actualDepsets)
diff --git a/bazel/properties.go b/bazel/properties.go
index 41bcaca..e29b9e1 100644
--- a/bazel/properties.go
+++ b/bazel/properties.go
@@ -409,6 +409,11 @@
return false
}
+// SetValue sets value for the no config axis
+func (ba *BoolAttribute) SetValue(value *bool) {
+ ba.SetSelectValue(NoConfigAxis, "", value)
+}
+
// SetSelectValue sets value for the given axis/config.
func (ba *BoolAttribute) SetSelectValue(axis ConfigurationAxis, config string, value *bool) {
axis.validateConfig(config)
diff --git a/bp2build/Android.bp b/bp2build/Android.bp
index e0ce194..34548ed 100644
--- a/bp2build/Android.bp
+++ b/bp2build/Android.bp
@@ -51,6 +51,7 @@
"conversion_test.go",
"filegroup_conversion_test.go",
"genrule_conversion_test.go",
+ "gensrcs_conversion_test.go",
"java_binary_host_conversion_test.go",
"java_import_conversion_test.go",
"java_library_conversion_test.go",
diff --git a/bp2build/android_app_certificate_conversion_test.go b/bp2build/android_app_certificate_conversion_test.go
index 035a352..173b4e4 100644
--- a/bp2build/android_app_certificate_conversion_test.go
+++ b/bp2build/android_app_certificate_conversion_test.go
@@ -42,7 +42,7 @@
}
`,
expectedBazelTargets: []string{
- makeBazelTarget("android_app_certificate", "com.android.apogee.cert", attrNameToString{
+ makeBazelTargetNoRestrictions("android_app_certificate", "com.android.apogee.cert", attrNameToString{
"certificate": `"chamber_of_secrets_dir"`,
}),
}})
diff --git a/bp2build/apex_conversion_test.go b/bp2build/apex_conversion_test.go
index d15dc0c..7bc379f 100644
--- a/bp2build/apex_conversion_test.go
+++ b/bp2build/apex_conversion_test.go
@@ -18,6 +18,7 @@
"android/soong/android"
"android/soong/apex"
"android/soong/cc"
+ "android/soong/etc"
"android/soong/java"
"android/soong/sh"
@@ -39,6 +40,7 @@
ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
+ ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory)
}
func runOverrideApexTestCase(t *testing.T, tc bp2buildTestCase) {
@@ -57,6 +59,7 @@
ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
ctx.RegisterModuleType("apex", apex.BundleFactory)
+ ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory)
}
func TestApexBundleSimple(t *testing.T) {
@@ -89,13 +92,13 @@
bazel_module: { bp2build_available: false },
}
-cc_library {
- name: "pretend_prebuilt_1",
+prebuilt_etc {
+ name: "prebuilt_1",
bazel_module: { bp2build_available: false },
}
-cc_library {
- name: "pretend_prebuilt_2",
+prebuilt_etc {
+ name: "prebuilt_2",
bazel_module: { bp2build_available: false },
}
@@ -130,9 +133,11 @@
"sh_binary_2",
],
prebuilts: [
- "pretend_prebuilt_1",
- "pretend_prebuilt_2",
+ "prebuilt_1",
+ "prebuilt_2",
],
+ package_name: "com.android.apogee.test.package",
+ logging_parent: "logging.parent",
}
`,
expectedBazelTargets: []string{
@@ -164,11 +169,13 @@
"//conditions:default": [],
})`,
"prebuilts": `[
- ":pretend_prebuilt_1",
- ":pretend_prebuilt_2",
+ ":prebuilt_1",
+ ":prebuilt_2",
]`,
- "updatable": "False",
- "compressible": "False",
+ "updatable": "False",
+ "compressible": "False",
+ "package_name": `"com.android.apogee.test.package"`,
+ "logging_parent": `"logging.parent"`,
}),
}})
}
@@ -547,13 +554,13 @@
bazel_module: { bp2build_available: false },
}
-cc_library {
- name: "pretend_prebuilt_1",
+prebuilt_etc {
+ name: "prebuilt_1",
bazel_module: { bp2build_available: false },
}
-cc_library {
- name: "pretend_prebuilt_2",
+prebuilt_etc {
+ name: "prebuilt_2",
bazel_module: { bp2build_available: false },
}
@@ -588,8 +595,8 @@
"sh_binary_2",
],
prebuilts: [
- "pretend_prebuilt_1",
- "pretend_prebuilt_2",
+ "prebuilt_1",
+ "prebuilt_2",
],
bazel_module: { bp2build_available: false },
}
@@ -782,3 +789,230 @@
}),
}})
}
+
+func TestApexBundleSimple_packageNameOverride(t *testing.T) {
+ runOverrideApexTestCase(t, bp2buildTestCase{
+ description: "override_apex - override package name",
+ moduleTypeUnderTest: "override_apex",
+ moduleTypeUnderTestFactory: apex.OverrideApexFactory,
+ filesystem: map[string]string{
+ "system/sepolicy/apex/Android.bp": `
+filegroup {
+ name: "com.android.apogee-file_contexts",
+ srcs: [ "apogee-file_contexts", ],
+ bazel_module: { bp2build_available: false },
+}`,
+ },
+ blueprint: `
+apex {
+ name: "com.android.apogee",
+ bazel_module: { bp2build_available: false },
+}
+
+override_apex {
+ name: "com.google.android.apogee",
+ base: ":com.android.apogee",
+ package_name: "com.google.android.apogee",
+}
+`,
+ expectedBazelTargets: []string{
+ makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
+ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
+ "manifest": `"apex_manifest.json"`,
+ "package_name": `"com.google.android.apogee"`,
+ }),
+ }})
+}
+
+func TestApexBundleSimple_NoPrebuiltsOverride(t *testing.T) {
+ runOverrideApexTestCase(t, bp2buildTestCase{
+ description: "override_apex - no override",
+ moduleTypeUnderTest: "override_apex",
+ moduleTypeUnderTestFactory: apex.OverrideApexFactory,
+ filesystem: map[string]string{
+ "system/sepolicy/apex/Android.bp": `
+filegroup {
+ name: "com.android.apogee-file_contexts",
+ srcs: [ "apogee-file_contexts", ],
+ bazel_module: { bp2build_available: false },
+}`,
+ },
+ blueprint: `
+prebuilt_etc {
+ name: "prebuilt_file",
+ bazel_module: { bp2build_available: false },
+}
+
+apex {
+ name: "com.android.apogee",
+ bazel_module: { bp2build_available: false },
+ prebuilts: ["prebuilt_file"]
+}
+
+override_apex {
+ name: "com.google.android.apogee",
+ base: ":com.android.apogee",
+}
+`,
+ expectedBazelTargets: []string{
+ makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
+ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
+ "manifest": `"apex_manifest.json"`,
+ "prebuilts": `[":prebuilt_file"]`,
+ }),
+ }})
+}
+
+func TestApexBundleSimple_PrebuiltsOverride(t *testing.T) {
+ runOverrideApexTestCase(t, bp2buildTestCase{
+ description: "override_apex - ooverride",
+ moduleTypeUnderTest: "override_apex",
+ moduleTypeUnderTestFactory: apex.OverrideApexFactory,
+ filesystem: map[string]string{
+ "system/sepolicy/apex/Android.bp": `
+filegroup {
+ name: "com.android.apogee-file_contexts",
+ srcs: [ "apogee-file_contexts", ],
+ bazel_module: { bp2build_available: false },
+}`,
+ },
+ blueprint: `
+prebuilt_etc {
+ name: "prebuilt_file",
+ bazel_module: { bp2build_available: false },
+}
+
+prebuilt_etc {
+ name: "prebuilt_file2",
+ bazel_module: { bp2build_available: false },
+}
+
+apex {
+ name: "com.android.apogee",
+ bazel_module: { bp2build_available: false },
+ prebuilts: ["prebuilt_file"]
+}
+
+override_apex {
+ name: "com.google.android.apogee",
+ base: ":com.android.apogee",
+ prebuilts: ["prebuilt_file2"]
+}
+`,
+ expectedBazelTargets: []string{
+ makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
+ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
+ "manifest": `"apex_manifest.json"`,
+ "prebuilts": `[":prebuilt_file2"]`,
+ }),
+ }})
+}
+
+func TestApexBundleSimple_PrebuiltsOverrideEmptyList(t *testing.T) {
+ runOverrideApexTestCase(t, bp2buildTestCase{
+ description: "override_apex - override with empty list",
+ moduleTypeUnderTest: "override_apex",
+ moduleTypeUnderTestFactory: apex.OverrideApexFactory,
+ filesystem: map[string]string{
+ "system/sepolicy/apex/Android.bp": `
+filegroup {
+ name: "com.android.apogee-file_contexts",
+ srcs: [ "apogee-file_contexts", ],
+ bazel_module: { bp2build_available: false },
+}`,
+ },
+ blueprint: `
+prebuilt_etc {
+ name: "prebuilt_file",
+ bazel_module: { bp2build_available: false },
+}
+
+apex {
+ name: "com.android.apogee",
+ bazel_module: { bp2build_available: false },
+ prebuilts: ["prebuilt_file"]
+}
+
+override_apex {
+ name: "com.google.android.apogee",
+ base: ":com.android.apogee",
+ prebuilts: [],
+}
+`,
+ expectedBazelTargets: []string{
+ makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
+ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
+ "manifest": `"apex_manifest.json"`,
+ "prebuilts": `[]`,
+ }),
+ }})
+}
+
+func TestApexBundleSimple_NoLoggingParentOverride(t *testing.T) {
+ runOverrideApexTestCase(t, bp2buildTestCase{
+ description: "override_apex - logging_parent - no override",
+ moduleTypeUnderTest: "override_apex",
+ moduleTypeUnderTestFactory: apex.OverrideApexFactory,
+ filesystem: map[string]string{
+ "system/sepolicy/apex/Android.bp": `
+filegroup {
+ name: "com.android.apogee-file_contexts",
+ srcs: [ "apogee-file_contexts", ],
+ bazel_module: { bp2build_available: false },
+}`,
+ },
+ blueprint: `
+apex {
+ name: "com.android.apogee",
+ bazel_module: { bp2build_available: false },
+ logging_parent: "foo.bar.baz",
+}
+
+override_apex {
+ name: "com.google.android.apogee",
+ base: ":com.android.apogee",
+}
+`,
+ expectedBazelTargets: []string{
+ makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
+ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
+ "manifest": `"apex_manifest.json"`,
+ "logging_parent": `"foo.bar.baz"`,
+ }),
+ }})
+}
+
+func TestApexBundleSimple_LoggingParentOverride(t *testing.T) {
+ runOverrideApexTestCase(t, bp2buildTestCase{
+ description: "override_apex - logging_parent - override",
+ moduleTypeUnderTest: "override_apex",
+ moduleTypeUnderTestFactory: apex.OverrideApexFactory,
+ filesystem: map[string]string{
+ "system/sepolicy/apex/Android.bp": `
+filegroup {
+ name: "com.android.apogee-file_contexts",
+ srcs: [ "apogee-file_contexts", ],
+ bazel_module: { bp2build_available: false },
+}`,
+ },
+ blueprint: `
+apex {
+ name: "com.android.apogee",
+ bazel_module: { bp2build_available: false },
+ logging_parent: "foo.bar.baz",
+}
+
+override_apex {
+ name: "com.google.android.apogee",
+ base: ":com.android.apogee",
+ logging_parent: "foo.bar.baz.override",
+}
+`,
+ expectedBazelTargets: []string{
+ makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
+ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
+ "manifest": `"apex_manifest.json"`,
+ "logging_parent": `"foo.bar.baz.override"`,
+ }),
+ }})
+}
diff --git a/bp2build/apex_key_conversion_test.go b/bp2build/apex_key_conversion_test.go
index 1d949901..dfa96a2 100644
--- a/bp2build/apex_key_conversion_test.go
+++ b/bp2build/apex_key_conversion_test.go
@@ -42,7 +42,7 @@
private_key: "com.android.apogee.pem",
}
`,
- expectedBazelTargets: []string{makeBazelTarget("apex_key", "com.android.apogee.key", attrNameToString{
+ expectedBazelTargets: []string{makeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", attrNameToString{
"private_key": `"com.android.apogee.pem"`,
"public_key": `"com.android.apogee.avbpubkey"`,
}),
diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go
index 0f6e139..19209f6 100644
--- a/bp2build/build_conversion_test.go
+++ b/bp2build/build_conversion_test.go
@@ -201,7 +201,7 @@
config := android.TestConfig(buildDir, nil, testCase.bp, nil)
ctx := android.NewTestContext(config)
- ctx.RegisterModuleType("custom", customModuleFactory)
+ ctx.RegisterModuleType("custom", customModuleFactoryHostAndDevice)
ctx.Register()
_, errs := ctx.ParseFileList(dir, []string{"Android.bp"})
@@ -501,6 +501,215 @@
}
}
+func TestBp2buildHostAndDevice(t *testing.T) {
+ testCases := []bp2buildTestCase{
+ {
+ description: "host and device, device only",
+ moduleTypeUnderTest: "custom",
+ moduleTypeUnderTestFactory: customModuleFactoryHostAndDevice,
+ blueprint: `custom {
+ name: "foo",
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTargetHostOrDevice("custom", "foo", attrNameToString{}, android.DeviceSupported),
+ },
+ },
+ {
+ description: "host and device, both",
+ moduleTypeUnderTest: "custom",
+ moduleTypeUnderTestFactory: customModuleFactoryHostAndDevice,
+ blueprint: `custom {
+ name: "foo",
+ host_supported: true,
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTargetNoRestrictions("custom", "foo", attrNameToString{}),
+ },
+ },
+ {
+ description: "host and device, host explicitly disabled",
+ moduleTypeUnderTest: "custom",
+ moduleTypeUnderTestFactory: customModuleFactoryHostAndDevice,
+ blueprint: `custom {
+ name: "foo",
+ host_supported: false,
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTargetHostOrDevice("custom", "foo", attrNameToString{}, android.DeviceSupported),
+ },
+ },
+ {
+ description: "host and device, neither",
+ moduleTypeUnderTest: "custom",
+ moduleTypeUnderTestFactory: customModuleFactoryHostAndDevice,
+ blueprint: `custom {
+ name: "foo",
+ host_supported: false,
+ device_supported: false,
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTargetNoRestrictions("custom", "foo", attrNameToString{
+ "target_compatible_with": `["@platforms//:incompatible"]`,
+ }),
+ },
+ },
+ {
+ description: "host and device, neither, cannot override with product_var",
+ moduleTypeUnderTest: "custom",
+ moduleTypeUnderTestFactory: customModuleFactoryHostAndDevice,
+ blueprint: `custom {
+ name: "foo",
+ host_supported: false,
+ device_supported: false,
+ product_variables: { unbundled_build: { enabled: true } },
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTargetNoRestrictions("custom", "foo", attrNameToString{
+ "target_compatible_with": `["@platforms//:incompatible"]`,
+ }),
+ },
+ },
+ {
+ description: "host and device, both, disabled overrided with product_var",
+ moduleTypeUnderTest: "custom",
+ moduleTypeUnderTestFactory: customModuleFactoryHostAndDevice,
+ blueprint: `custom {
+ name: "foo",
+ host_supported: true,
+ device_supported: true,
+ enabled: false,
+ product_variables: { unbundled_build: { enabled: true } },
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTargetNoRestrictions("custom", "foo", attrNameToString{
+ "target_compatible_with": `["//build/bazel/product_variables:unbundled_build"]`,
+ }),
+ },
+ },
+ {
+ description: "host and device, neither, cannot override with arch enabled",
+ moduleTypeUnderTest: "custom",
+ moduleTypeUnderTestFactory: customModuleFactoryHostAndDevice,
+ blueprint: `custom {
+ name: "foo",
+ host_supported: false,
+ device_supported: false,
+ arch: { x86: { enabled: true } },
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTargetNoRestrictions("custom", "foo", attrNameToString{
+ "target_compatible_with": `["@platforms//:incompatible"]`,
+ }),
+ },
+ },
+ {
+ description: "host and device, host only",
+ moduleTypeUnderTest: "custom",
+ moduleTypeUnderTestFactory: customModuleFactoryHostAndDevice,
+ blueprint: `custom {
+ name: "foo",
+ host_supported: true,
+ device_supported: false,
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTargetHostOrDevice("custom", "foo", attrNameToString{}, android.HostSupported),
+ },
+ },
+ {
+ description: "host only",
+ moduleTypeUnderTest: "custom",
+ moduleTypeUnderTestFactory: customModuleFactoryHostSupported,
+ blueprint: `custom {
+ name: "foo",
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTargetHostOrDevice("custom", "foo", attrNameToString{}, android.HostSupported),
+ },
+ },
+ {
+ description: "device only",
+ moduleTypeUnderTest: "custom",
+ moduleTypeUnderTestFactory: customModuleFactoryDeviceSupported,
+ blueprint: `custom {
+ name: "foo",
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTargetHostOrDevice("custom", "foo", attrNameToString{}, android.DeviceSupported),
+ },
+ },
+ {
+ description: "host and device default, default",
+ moduleTypeUnderTest: "custom",
+ moduleTypeUnderTestFactory: customModuleFactoryHostAndDeviceDefault,
+ blueprint: `custom {
+ name: "foo",
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTargetNoRestrictions("custom", "foo", attrNameToString{}),
+ },
+ },
+ {
+ description: "host and device default, device only",
+ moduleTypeUnderTest: "custom",
+ moduleTypeUnderTestFactory: customModuleFactoryHostAndDeviceDefault,
+ blueprint: `custom {
+ name: "foo",
+ host_supported: false,
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTargetHostOrDevice("custom", "foo", attrNameToString{}, android.DeviceSupported),
+ },
+ },
+ {
+ description: "host and device default, host only",
+ moduleTypeUnderTest: "custom",
+ moduleTypeUnderTestFactory: customModuleFactoryHostAndDeviceDefault,
+ blueprint: `custom {
+ name: "foo",
+ device_supported: false,
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTargetHostOrDevice("custom", "foo", attrNameToString{}, android.HostSupported),
+ },
+ },
+ {
+ description: "host and device default, neither",
+ moduleTypeUnderTest: "custom",
+ moduleTypeUnderTestFactory: customModuleFactoryHostAndDeviceDefault,
+ blueprint: `custom {
+ name: "foo",
+ host_supported: false,
+ device_supported: false,
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTargetNoRestrictions("custom", "foo", attrNameToString{
+ "target_compatible_with": `["@platforms//:incompatible"]`,
+ }),
+ },
+ },
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.description, func(t *testing.T) {
+ runBp2BuildTestCaseSimple(t, tc)
+ })
+ }
+}
+
func TestLoadStatements(t *testing.T) {
testCases := []struct {
bazelTargets BazelTargets
@@ -610,6 +819,7 @@
{
bp: `custom {
name: "bar",
+ host_supported: true,
one_to_many_prop: true,
bazel_module: { bp2build_available: true },
}`,
@@ -634,7 +844,7 @@
for _, testCase := range testCases {
config := android.TestConfig(buildDir, nil, testCase.bp, nil)
ctx := android.NewTestContext(config)
- ctx.RegisterModuleType("custom", customModuleFactory)
+ ctx.RegisterModuleType("custom", customModuleFactoryHostAndDevice)
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, []string{"Android.bp"})
@@ -680,7 +890,7 @@
bazel_module: { bp2build_available: true },
}`,
expectedBazelTargets: []string{
- makeBazelTarget("filegroup", "fg_foo", map[string]string{}),
+ makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{}),
},
},
{
@@ -693,7 +903,7 @@
bazel_module: { bp2build_available: true },
}`,
expectedBazelTargets: []string{
- makeBazelTarget("filegroup", "fg_foo", map[string]string{}),
+ makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{}),
},
},
{
@@ -706,7 +916,7 @@
bazel_module: { bp2build_available: true },
}`,
expectedBazelTargets: []string{
- makeBazelTarget("filegroup", "fg_foo", map[string]string{
+ makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{
"srcs": `[
"a",
"b",
@@ -725,7 +935,7 @@
bazel_module: { bp2build_available: true },
}`,
expectedBazelTargets: []string{
- makeBazelTarget("filegroup", "fg_foo", map[string]string{
+ makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{
"srcs": `["b"]`,
}),
},
@@ -740,7 +950,7 @@
bazel_module: { bp2build_available: true },
}`,
expectedBazelTargets: []string{
- makeBazelTarget("filegroup", "fg_foo", map[string]string{
+ makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{
"srcs": `[
"other/a.txt",
"other/b.txt",
@@ -772,7 +982,7 @@
"other/file": "",
},
expectedBazelTargets: []string{
- makeBazelTarget("filegroup", "fg_foo", map[string]string{
+ makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{
"srcs": `[
"a.txt",
"b.txt",
@@ -801,7 +1011,7 @@
}`,
},
expectedBazelTargets: []string{
- makeBazelTarget("filegroup", "fg_foo", map[string]string{
+ makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{
"srcs": `[
"//other:foo",
"c",
@@ -884,7 +1094,7 @@
{
description: "generates more than 1 target if needed",
moduleTypeUnderTest: "custom",
- moduleTypeUnderTestFactory: customModuleFactory,
+ moduleTypeUnderTestFactory: customModuleFactoryHostAndDevice,
bp: `custom {
name: "foo",
one_to_many_prop: true,
@@ -1092,7 +1302,7 @@
"other/BUILD.bazel": `// definition for fg_bar`,
},
expectedBazelTargets: []string{
- makeBazelTarget("filegroup", "fg_foo", map[string]string{}),
+ makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{}),
`// definition for fg_bar`,
},
},
@@ -1118,7 +1328,7 @@
},
}`,
expectedBazelTargets: []string{
- makeBazelTarget("filegroup", "fg_bar", map[string]string{}),
+ makeBazelTargetNoRestrictions("filegroup", "fg_bar", map[string]string{}),
`// BUILD file`,
},
},
@@ -1203,7 +1413,7 @@
"dir/f.txt": "",
},
expectedBazelTargets: []string{
- makeBazelTarget("filegroup", "fg_foo", map[string]string{
+ makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{
"srcs": `[
"a.txt",
"b.txt",
@@ -1234,7 +1444,7 @@
"dir/subdir/f.txt": "",
},
expectedBazelTargets: []string{
- makeBazelTarget("filegroup", "fg_foo", map[string]string{
+ makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{
"srcs": `[
"a.txt",
"//dir/subdir:e.txt",
@@ -1265,7 +1475,7 @@
bazel_module: { bp2build_available: true },
}`,
expectedBazelTargets: []string{
- makeBazelTarget("filegroup", "fg_foo", map[string]string{
+ makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{
"data": `[":reqd"]`,
}),
},
@@ -1337,7 +1547,7 @@
bazel_module: { bp2build_available: true },
}`,
expectedBazelTargets: []string{
- makeBazelTarget("filegroup", "fg_foo", map[string]string{
+ makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{
"data": `[":reqd"]`,
}),
},
diff --git a/bp2build/cc_binary_conversion_test.go b/bp2build/cc_binary_conversion_test.go
index 30be997..4794269 100644
--- a/bp2build/cc_binary_conversion_test.go
+++ b/bp2build/cc_binary_conversion_test.go
@@ -34,10 +34,11 @@
attrs attrNameToString
}
-func generateBazelTargetsForTest(targets []testBazelTarget) []string {
+func generateBazelTargetsForTest(targets []testBazelTarget, hod android.HostOrDeviceSupported) []string {
ret := make([]string, 0, len(targets))
for _, t := range targets {
- ret = append(ret, makeBazelTarget(t.typ, t.name, t.attrs))
+ attrs := t.attrs.clone()
+ ret = append(ret, makeBazelTargetHostOrDevice(t.typ, t.name, attrs, hod))
}
return ret
}
@@ -65,42 +66,33 @@
runCcHostBinaryTestCase(t, tc)
}
-func runCcBinaryTestCase(t *testing.T, tc ccBinaryBp2buildTestCase) {
+func runCcBinaryTestCase(t *testing.T, testCase ccBinaryBp2buildTestCase) {
t.Helper()
moduleTypeUnderTest := "cc_binary"
- testCase := bp2buildTestCase{
- expectedBazelTargets: generateBazelTargetsForTest(tc.targets),
- moduleTypeUnderTest: moduleTypeUnderTest,
- moduleTypeUnderTestFactory: cc.BinaryFactory,
- description: fmt.Sprintf("%s %s", moduleTypeUnderTest, tc.description),
- blueprint: binaryReplacer.Replace(tc.blueprint),
- }
- t.Run(testCase.description, func(t *testing.T) {
+
+ description := fmt.Sprintf("%s %s", moduleTypeUnderTest, testCase.description)
+ t.Run(description, func(t *testing.T) {
t.Helper()
- runBp2BuildTestCase(t, registerCcBinaryModuleTypes, testCase)
+ runBp2BuildTestCase(t, registerCcBinaryModuleTypes, bp2buildTestCase{
+ expectedBazelTargets: generateBazelTargetsForTest(testCase.targets, android.DeviceSupported),
+ moduleTypeUnderTest: moduleTypeUnderTest,
+ moduleTypeUnderTestFactory: cc.BinaryFactory,
+ description: description,
+ blueprint: binaryReplacer.Replace(testCase.blueprint),
+ })
})
}
-func runCcHostBinaryTestCase(t *testing.T, tc ccBinaryBp2buildTestCase) {
+func runCcHostBinaryTestCase(t *testing.T, testCase ccBinaryBp2buildTestCase) {
t.Helper()
- testCase := tc
- for i, tar := range testCase.targets {
- switch tar.typ {
- case "cc_binary", "proto_library", "cc_lite_proto_library", "genlex":
- tar.attrs["target_compatible_with"] = `select({
- "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
- "//conditions:default": [],
- })`
- }
- testCase.targets[i] = tar
- }
moduleTypeUnderTest := "cc_binary_host"
- t.Run(testCase.description, func(t *testing.T) {
+ description := fmt.Sprintf("%s %s", moduleTypeUnderTest, testCase.description)
+ t.Run(description, func(t *testing.T) {
runBp2BuildTestCase(t, registerCcBinaryModuleTypes, bp2buildTestCase{
- expectedBazelTargets: generateBazelTargetsForTest(testCase.targets),
+ expectedBazelTargets: generateBazelTargetsForTest(testCase.targets, android.HostSupported),
moduleTypeUnderTest: moduleTypeUnderTest,
moduleTypeUnderTestFactory: cc.BinaryHostFactory,
- description: fmt.Sprintf("%s %s", moduleTypeUnderTest, tc.description),
+ description: description,
blueprint: hostBinaryReplacer.Replace(testCase.blueprint),
})
})
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index a0bc9e7..555f5a7 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -1879,76 +1879,78 @@
// not set, only emit if gnu_extensions is disabled. the default (gnu+17
// is set in the toolchain.)
{cpp_std: "", gnu_extensions: "", bazel_cpp_std: ""},
- {cpp_std: "", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c99"},
+ {cpp_std: "", gnu_extensions: "false", bazel_cpp_std: "cpp_std_default_no_gnu", bazel_c_std: "c_std_default_no_gnu"},
{cpp_std: "", gnu_extensions: "true", bazel_cpp_std: ""},
// experimental defaults to gnu++2a
- {cpp_std: "experimental", gnu_extensions: "", bazel_cpp_std: "gnu++2a"},
- {cpp_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "c++2a", bazel_c_std: "c99"},
- {cpp_std: "experimental", gnu_extensions: "true", bazel_cpp_std: "gnu++2a"},
+ {cpp_std: "experimental", gnu_extensions: "", bazel_cpp_std: "cpp_std_experimental"},
+ {cpp_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "cpp_std_experimental_no_gnu", bazel_c_std: "c_std_default_no_gnu"},
+ {cpp_std: "experimental", gnu_extensions: "true", bazel_cpp_std: "cpp_std_experimental"},
// Explicitly setting a c++ std does not use replace gnu++ std even if
// gnu_extensions is true.
// "c++11",
{cpp_std: "c++11", gnu_extensions: "", bazel_cpp_std: "c++11"},
- {cpp_std: "c++11", gnu_extensions: "false", bazel_cpp_std: "c++11", bazel_c_std: "c99"},
+ {cpp_std: "c++11", gnu_extensions: "false", bazel_cpp_std: "c++11", bazel_c_std: "c_std_default_no_gnu"},
{cpp_std: "c++11", gnu_extensions: "true", bazel_cpp_std: "c++11"},
// "c++17",
{cpp_std: "c++17", gnu_extensions: "", bazel_cpp_std: "c++17"},
- {cpp_std: "c++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c99"},
+ {cpp_std: "c++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c_std_default_no_gnu"},
{cpp_std: "c++17", gnu_extensions: "true", bazel_cpp_std: "c++17"},
// "c++2a",
{cpp_std: "c++2a", gnu_extensions: "", bazel_cpp_std: "c++2a"},
- {cpp_std: "c++2a", gnu_extensions: "false", bazel_cpp_std: "c++2a", bazel_c_std: "c99"},
+ {cpp_std: "c++2a", gnu_extensions: "false", bazel_cpp_std: "c++2a", bazel_c_std: "c_std_default_no_gnu"},
{cpp_std: "c++2a", gnu_extensions: "true", bazel_cpp_std: "c++2a"},
// "c++98",
{cpp_std: "c++98", gnu_extensions: "", bazel_cpp_std: "c++98"},
- {cpp_std: "c++98", gnu_extensions: "false", bazel_cpp_std: "c++98", bazel_c_std: "c99"},
+ {cpp_std: "c++98", gnu_extensions: "false", bazel_cpp_std: "c++98", bazel_c_std: "c_std_default_no_gnu"},
{cpp_std: "c++98", gnu_extensions: "true", bazel_cpp_std: "c++98"},
// gnu++ is replaced with c++ if gnu_extensions is explicitly false.
// "gnu++11",
{cpp_std: "gnu++11", gnu_extensions: "", bazel_cpp_std: "gnu++11"},
- {cpp_std: "gnu++11", gnu_extensions: "false", bazel_cpp_std: "c++11", bazel_c_std: "c99"},
+ {cpp_std: "gnu++11", gnu_extensions: "false", bazel_cpp_std: "c++11", bazel_c_std: "c_std_default_no_gnu"},
{cpp_std: "gnu++11", gnu_extensions: "true", bazel_cpp_std: "gnu++11"},
// "gnu++17",
{cpp_std: "gnu++17", gnu_extensions: "", bazel_cpp_std: "gnu++17"},
- {cpp_std: "gnu++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c99"},
+ {cpp_std: "gnu++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c_std_default_no_gnu"},
{cpp_std: "gnu++17", gnu_extensions: "true", bazel_cpp_std: "gnu++17"},
// some c_std test cases
- {c_std: "experimental", gnu_extensions: "", bazel_c_std: "gnu17"},
- {c_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c17"},
- {c_std: "experimental", gnu_extensions: "true", bazel_c_std: "gnu17"},
+ {c_std: "experimental", gnu_extensions: "", bazel_c_std: "c_std_experimental"},
+ {c_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "cpp_std_default_no_gnu", bazel_c_std: "c_std_experimental_no_gnu"},
+ {c_std: "experimental", gnu_extensions: "true", bazel_c_std: "c_std_experimental"},
{c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "", bazel_cpp_std: "gnu++17", bazel_c_std: "gnu11"},
{c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c11"},
{c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "true", bazel_cpp_std: "gnu++17", bazel_c_std: "gnu11"},
}
for i, tc := range testCases {
- name_prefix := fmt.Sprintf("a_%v", i)
- cppStdProp := ""
- if tc.cpp_std != "" {
- cppStdProp = fmt.Sprintf(" cpp_std: \"%s\",", tc.cpp_std)
- }
- cStdProp := ""
- if tc.c_std != "" {
- cStdProp = fmt.Sprintf(" c_std: \"%s\",", tc.c_std)
- }
- gnuExtensionsProp := ""
- if tc.gnu_extensions != "" {
- gnuExtensionsProp = fmt.Sprintf(" gnu_extensions: %s,", tc.gnu_extensions)
- }
- attrs := attrNameToString{}
- if tc.bazel_cpp_std != "" {
- attrs["cpp_std"] = fmt.Sprintf(`"%s"`, tc.bazel_cpp_std)
- }
- if tc.bazel_c_std != "" {
- attrs["c_std"] = fmt.Sprintf(`"%s"`, tc.bazel_c_std)
- }
+ name := fmt.Sprintf("cpp std: %q, c std: %q, gnu_extensions: %q", tc.cpp_std, tc.c_std, tc.gnu_extensions)
+ t.Run(name, func(t *testing.T) {
+ name_prefix := fmt.Sprintf("a_%v", i)
+ cppStdProp := ""
+ if tc.cpp_std != "" {
+ cppStdProp = fmt.Sprintf(" cpp_std: \"%s\",", tc.cpp_std)
+ }
+ cStdProp := ""
+ if tc.c_std != "" {
+ cStdProp = fmt.Sprintf(" c_std: \"%s\",", tc.c_std)
+ }
+ gnuExtensionsProp := ""
+ if tc.gnu_extensions != "" {
+ gnuExtensionsProp = fmt.Sprintf(" gnu_extensions: %s,", tc.gnu_extensions)
+ }
+ attrs := attrNameToString{}
+ if tc.bazel_cpp_std != "" {
+ attrs["cpp_std"] = fmt.Sprintf(`"%s"`, tc.bazel_cpp_std)
+ }
+ if tc.bazel_c_std != "" {
+ attrs["c_std"] = fmt.Sprintf(`"%s"`, tc.bazel_c_std)
+ }
- runCcLibraryTestCase(t, bp2buildTestCase{
- description: fmt.Sprintf(
- "cc_library with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions),
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- blueprint: soongCcLibraryPreamble + fmt.Sprintf(`
+ runCcLibraryTestCase(t, bp2buildTestCase{
+ description: fmt.Sprintf(
+ "cc_library with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions),
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ blueprint: soongCcLibraryPreamble + fmt.Sprintf(`
cc_library {
name: "%s_full",
%s // cpp_std: *string
@@ -1957,15 +1959,15 @@
include_build_directory: false,
}
`, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp),
- expectedBazelTargets: makeCcLibraryTargets(name_prefix+"_full", attrs),
- })
+ expectedBazelTargets: makeCcLibraryTargets(name_prefix+"_full", attrs),
+ })
- runCcLibraryStaticTestCase(t, bp2buildTestCase{
- description: fmt.Sprintf(
- "cc_library_static with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions),
- moduleTypeUnderTest: "cc_library_static",
- moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
- blueprint: soongCcLibraryPreamble + fmt.Sprintf(`
+ runCcLibraryStaticTestCase(t, bp2buildTestCase{
+ description: fmt.Sprintf(
+ "cc_library_static with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions),
+ moduleTypeUnderTest: "cc_library_static",
+ moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
+ blueprint: soongCcLibraryPreamble + fmt.Sprintf(`
cc_library_static {
name: "%s_static",
%s // cpp_std: *string
@@ -1974,17 +1976,17 @@
include_build_directory: false,
}
`, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp),
- expectedBazelTargets: []string{
- makeBazelTarget("cc_library_static", name_prefix+"_static", attrs),
- },
- })
+ expectedBazelTargets: []string{
+ makeBazelTarget("cc_library_static", name_prefix+"_static", attrs),
+ },
+ })
- runCcLibrarySharedTestCase(t, bp2buildTestCase{
- description: fmt.Sprintf(
- "cc_library_shared with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions),
- moduleTypeUnderTest: "cc_library_shared",
- moduleTypeUnderTestFactory: cc.LibrarySharedFactory,
- blueprint: soongCcLibraryPreamble + fmt.Sprintf(`
+ runCcLibrarySharedTestCase(t, bp2buildTestCase{
+ description: fmt.Sprintf(
+ "cc_library_shared with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions),
+ moduleTypeUnderTest: "cc_library_shared",
+ moduleTypeUnderTestFactory: cc.LibrarySharedFactory,
+ blueprint: soongCcLibraryPreamble + fmt.Sprintf(`
cc_library_shared {
name: "%s_shared",
%s // cpp_std: *string
@@ -1993,9 +1995,10 @@
include_build_directory: false,
}
`, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp),
- expectedBazelTargets: []string{
- makeBazelTarget("cc_library_shared", name_prefix+"_shared", attrs),
- },
+ expectedBazelTargets: []string{
+ makeBazelTarget("cc_library_shared", name_prefix+"_shared", attrs),
+ },
+ })
})
}
}
@@ -2278,6 +2281,7 @@
blueprint: soongCcProtoPreamble + `cc_library {
name: "foo",
srcs: ["foo.cpp"],
+ host_supported: true,
target: {
darwin: {
enabled: false,
@@ -2313,6 +2317,7 @@
name: "foo",
srcs: ["foo.cpp"],
enabled: false,
+ host_supported: true,
target: {
darwin: {
enabled: true,
@@ -2377,6 +2382,7 @@
moduleTypeUnderTestFactory: cc.LibraryFactory,
blueprint: soongCcProtoPreamble + `cc_library {
name: "foo",
+ host_supported: true,
srcs: ["foo.cpp"],
shared: {
enabled: false
diff --git a/bp2build/genrule_conversion_test.go b/bp2build/genrule_conversion_test.go
index 9244b99..4504892 100644
--- a/bp2build/genrule_conversion_test.go
+++ b/bp2build/genrule_conversion_test.go
@@ -56,6 +56,7 @@
moduleType string
factory android.ModuleFactory
genDir string
+ hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
@@ -66,16 +67,19 @@
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
genDir: "$(RULEDIR)",
+ hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
genDir: "$(RULEDIR)",
+ hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
genDir: "$(RULEDIR)",
+ hod: android.HostSupported,
},
}
@@ -104,15 +108,8 @@
"tools": `[":foo.tool"]`,
}
- if tc.moduleType == "java_genrule_host" {
- moduleAttrs["target_compatible_with"] = `select({
- "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
- "//conditions:default": [],
- })`
- }
-
expectedBazelTargets := []string{
- makeBazelTarget("genrule", "foo", moduleAttrs),
+ makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
@@ -131,6 +128,7 @@
testCases := []struct {
moduleType string
factory android.ModuleFactory
+ hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
@@ -139,14 +137,17 @@
{
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
+ hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
+ hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
+ hod: android.HostSupported,
},
}
@@ -183,18 +184,9 @@
"srcs": `["foo_tool.in"]`,
}
- if tc.moduleType == "java_genrule_host" {
- compatibilityAttrs := `select({
- "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
- "//conditions:default": [],
- })`
- fooAttrs["target_compatible_with"] = compatibilityAttrs
- fooToolsAttrs["target_compatible_with"] = compatibilityAttrs
- }
-
expectedBazelTargets := []string{
- makeBazelTarget("genrule", "foo", fooAttrs),
- makeBazelTarget("genrule", "foo.tools", fooToolsAttrs),
+ makeBazelTargetHostOrDevice("genrule", "foo", fooAttrs, tc.hod),
+ makeBazelTargetHostOrDevice("genrule", "foo.tools", fooToolsAttrs, tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
@@ -213,6 +205,7 @@
testCases := []struct {
moduleType string
factory android.ModuleFactory
+ hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
@@ -221,14 +214,17 @@
{
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
+ hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
+ hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
+ hod: android.HostSupported,
},
}
@@ -249,15 +245,8 @@
"tools": `["//other:foo.tool"]`,
}
- if tc.moduleType == "java_genrule_host" {
- moduleAttrs["target_compatible_with"] = `select({
- "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
- "//conditions:default": [],
- })`
- }
-
expectedBazelTargets := []string{
- makeBazelTarget("genrule", "foo", moduleAttrs),
+ makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
@@ -277,6 +266,7 @@
testCases := []struct {
moduleType string
factory android.ModuleFactory
+ hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
@@ -285,14 +275,17 @@
{
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
+ hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
+ hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
+ hod: android.HostSupported,
},
}
@@ -313,15 +306,8 @@
"tools": `["//other:foo.tool"]`,
}
- if tc.moduleType == "java_genrule_host" {
- moduleAttrs["target_compatible_with"] = `select({
- "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
- "//conditions:default": [],
- })`
- }
-
expectedBazelTargets := []string{
- makeBazelTarget("genrule", "foo", moduleAttrs),
+ makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
@@ -341,6 +327,7 @@
testCases := []struct {
moduleType string
factory android.ModuleFactory
+ hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
@@ -349,14 +336,17 @@
{
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
+ hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
+ hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
+ hod: android.HostSupported,
},
}
@@ -380,15 +370,8 @@
]`,
}
- if tc.moduleType == "java_genrule_host" {
- moduleAttrs["target_compatible_with"] = `select({
- "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
- "//conditions:default": [],
- })`
- }
-
expectedBazelTargets := []string{
- makeBazelTarget("genrule", "foo", moduleAttrs),
+ makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
@@ -408,6 +391,7 @@
testCases := []struct {
moduleType string
factory android.ModuleFactory
+ hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
@@ -416,14 +400,17 @@
{
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
+ hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
+ hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
+ hod: android.HostSupported,
},
}
@@ -447,15 +434,8 @@
]`,
}
- if tc.moduleType == "java_genrule_host" {
- moduleAttrs["target_compatible_with"] = `select({
- "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
- "//conditions:default": [],
- })`
- }
-
expectedBazelTargets := []string{
- makeBazelTarget("genrule", "foo", moduleAttrs),
+ makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
@@ -475,6 +455,7 @@
testCases := []struct {
moduleType string
factory android.ModuleFactory
+ hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
@@ -483,14 +464,17 @@
{
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
+ hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
+ hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
+ hod: android.HostSupported,
},
}
@@ -509,15 +493,8 @@
"srcs": `["foo.in"]`,
}
- if tc.moduleType == "java_genrule_host" {
- moduleAttrs["target_compatible_with"] = `select({
- "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
- "//conditions:default": [],
- })`
- }
-
expectedBazelTargets := []string{
- makeBazelTarget("genrule", "foo", moduleAttrs),
+ makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
@@ -549,7 +526,7 @@
}
`,
expectedBazelTargets: []string{
- makeBazelTarget("genrule", "gen", attrNameToString{
+ makeBazelTargetNoRestrictions("genrule", "gen", attrNameToString{
"cmd": `"do-something $(SRCS) $(OUTS)"`,
"outs": `["out"]`,
"srcs": `["in1"]`,
@@ -574,7 +551,7 @@
}
`,
expectedBazelTargets: []string{
- makeBazelTarget("genrule", "gen", attrNameToString{
+ makeBazelTargetNoRestrictions("genrule", "gen", attrNameToString{
"cmd": `"do-something $(SRCS) $(OUTS)"`,
"outs": `[
"out-from-defaults",
@@ -607,7 +584,7 @@
}
`,
expectedBazelTargets: []string{
- makeBazelTarget("genrule", "gen", attrNameToString{
+ makeBazelTargetNoRestrictions("genrule", "gen", attrNameToString{
"cmd": `"cp $(SRCS) $(OUTS)"`,
"outs": `["out"]`,
"srcs": `["in1"]`,
@@ -644,7 +621,7 @@
}
`,
expectedBazelTargets: []string{
- makeBazelTarget("genrule", "gen", attrNameToString{
+ makeBazelTargetNoRestrictions("genrule", "gen", attrNameToString{
"cmd": `"cmd1 $(SRCS) $(OUTS)"`,
"outs": `[
"out-from-3",
diff --git a/bp2build/gensrcs_conversion_test.go b/bp2build/gensrcs_conversion_test.go
new file mode 100644
index 0000000..7682663
--- /dev/null
+++ b/bp2build/gensrcs_conversion_test.go
@@ -0,0 +1,80 @@
+// Copyright 2020 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package bp2build
+
+import (
+ "android/soong/android"
+ "android/soong/genrule"
+ "testing"
+)
+
+func TestGensrcs(t *testing.T) {
+ testcases := []struct {
+ name string
+ bp string
+ expectedBazelAttrs attrNameToString
+ }{
+ {
+ name: "gensrcs with common usage of properties",
+ bp: `
+ gensrcs {
+ name: "foo",
+ srcs: ["test/input.txt", ":external_files"],
+ tool_files: ["program.py"],
+ cmd: "$(location program.py) $(in) $(out)",
+ output_extension: "out",
+ bazel_module: { bp2build_available: true },
+ }`,
+ expectedBazelAttrs: attrNameToString{
+ "srcs": `[
+ "test/input.txt",
+ ":external_files__BP2BUILD__MISSING__DEP",
+ ]`,
+ "tools": `["program.py"]`,
+ "output_extension": `"out"`,
+ "cmd": `"$(location program.py) $(SRC) $(OUT)"`,
+ },
+ },
+ {
+ name: "gensrcs with out_extension unset",
+ bp: `
+ gensrcs {
+ name: "foo",
+ srcs: ["input.txt"],
+ cmd: "cat $(in) > $(out)",
+ bazel_module: { bp2build_available: true },
+ }`,
+ expectedBazelAttrs: attrNameToString{
+ "srcs": `["input.txt"]`,
+ "cmd": `"cat $(SRC) > $(OUT)"`,
+ },
+ },
+ }
+
+ for _, test := range testcases {
+ expectedBazelTargets := []string{
+ makeBazelTargetNoRestrictions("gensrcs", "foo", test.expectedBazelAttrs),
+ }
+ t.Run(test.name, func(t *testing.T) {
+ runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
+ bp2buildTestCase{
+ moduleTypeUnderTest: "gensrcs",
+ moduleTypeUnderTestFactory: genrule.GenSrcsFactory,
+ blueprint: test.bp,
+ expectedBazelTargets: expectedBazelTargets,
+ })
+ })
+ }
+}
diff --git a/bp2build/soong_config_module_type_conversion_test.go b/bp2build/soong_config_module_type_conversion_test.go
index b1e1fb2..8460cae 100644
--- a/bp2build/soong_config_module_type_conversion_test.go
+++ b/bp2build/soong_config_module_type_conversion_test.go
@@ -49,6 +49,7 @@
custom_cc_library_static {
name: "foo",
bazel_module: { bp2build_available: true },
+ host_supported: true,
soong_config_variables: {
feature1: {
conditions_default: {
@@ -94,6 +95,7 @@
custom_cc_library_static {
name: "foo",
bazel_module: { bp2build_available: true },
+ host_supported: true,
soong_config_variables: {
feature1: {
conditions_default: {
@@ -141,6 +143,7 @@
custom_cc_library_static {
name: "foo",
bazel_module: { bp2build_available: true },
+ host_supported: true,
soong_config_variables: {
board: {
soc_a: {
@@ -200,6 +203,7 @@
custom_cc_library_static {
name: "foo",
bazel_module: { bp2build_available: true },
+ host_supported: true,
soong_config_variables: {
feature1: {
conditions_default: {
@@ -268,6 +272,7 @@
custom_cc_library_static {
name: "foo",
bazel_module: { bp2build_available: true },
+ host_supported: true,
soong_config_variables: {
board: {
soc_a: {
@@ -356,6 +361,7 @@
name: "lib",
defaults: ["foo_defaults_2"],
bazel_module: { bp2build_available: true },
+ host_supported: true,
}
`
@@ -429,12 +435,14 @@
name: "lib",
defaults: ["foo_defaults", "bar_defaults"],
bazel_module: { bp2build_available: true },
+ host_supported: true,
}
cc_library_static {
name: "lib2",
defaults: ["bar_defaults", "foo_defaults"],
bazel_module: { bp2build_available: true },
+ host_supported: true,
}
`
@@ -550,6 +558,7 @@
name: "lib",
defaults: ["foo_defaults", "qux_defaults"],
bazel_module: { bp2build_available: true },
+ host_supported: true,
}
`
@@ -615,6 +624,7 @@
library_linking_strategy_cc_defaults {
name: "library_linking_strategy_merged_defaults",
defaults: ["library_linking_strategy_lib_a_defaults"],
+ host_supported: true,
soong_config_variables: {
library_linking_strategy: {
prefer_static: {
@@ -714,6 +724,7 @@
cc_binary {
name: "library_linking_strategy_sample_binary",
+ host_supported: true,
srcs: ["library_linking_strategy.cc"],
defaults: ["library_linking_strategy_sample_defaults"],
}`
@@ -800,6 +811,7 @@
cc_binary {
name: "alphabet_binary",
+ host_supported: true,
srcs: ["main.cc"],
defaults: ["alphabet_sample_cc_defaults"],
}`
@@ -861,6 +873,7 @@
cc_binary {
name: "alphabet_binary",
srcs: ["main.cc"],
+ host_supported: true,
defaults: ["alphabet_sample_cc_defaults"],
enabled: false,
arch: {
@@ -958,6 +971,7 @@
alphabet_cc_defaults {
name: "alphabet_sample_cc_defaults",
+ host_supported: true,
soong_config_variables: {
special_build: {
enabled: true,
diff --git a/bp2build/testing.go b/bp2build/testing.go
index 9341495..580bac4 100644
--- a/bp2build/testing.go
+++ b/bp2build/testing.go
@@ -213,12 +213,36 @@
return module
}
-func customModuleFactory() android.Module {
+func customModuleFactoryHostAndDevice() android.Module {
m := customModuleFactoryBase()
android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibBoth)
return m
}
+func customModuleFactoryDeviceSupported() android.Module {
+ m := customModuleFactoryBase()
+ android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibBoth)
+ return m
+}
+
+func customModuleFactoryHostSupported() android.Module {
+ m := customModuleFactoryBase()
+ android.InitAndroidArchModule(m, android.HostSupported, android.MultilibBoth)
+ return m
+}
+
+func customModuleFactoryHostAndDeviceDefault() android.Module {
+ m := customModuleFactoryBase()
+ android.InitAndroidArchModule(m, android.HostAndDeviceDefault, android.MultilibBoth)
+ return m
+}
+
+func customModuleFactoryNeitherHostNorDeviceSupported() android.Module {
+ m := customModuleFactoryBase()
+ android.InitAndroidArchModule(m, android.NeitherHostNorDeviceSupported, android.MultilibBoth)
+ return m
+}
+
type testProps struct {
Test_prop struct {
Test_string_prop string
@@ -355,7 +379,7 @@
}
func registerCustomModuleForBp2buildConversion(ctx *android.TestContext) {
- ctx.RegisterModuleType("custom", customModuleFactory)
+ ctx.RegisterModuleType("custom", customModuleFactoryHostAndDevice)
ctx.RegisterForBazelConversion()
}
@@ -369,7 +393,29 @@
type attrNameToString map[string]string
-func makeBazelTarget(typ, name string, attrs attrNameToString) string {
+func (a attrNameToString) clone() attrNameToString {
+ newAttrs := make(attrNameToString, len(a))
+ for k, v := range a {
+ newAttrs[k] = v
+ }
+ return newAttrs
+}
+
+// makeBazelTargetNoRestrictions returns bazel target build file definition that can be host or
+// device specific, or independent of host/device.
+func makeBazelTargetHostOrDevice(typ, name string, attrs attrNameToString, hod android.HostOrDeviceSupported) string {
+ if _, ok := attrs["target_compatible_with"]; !ok {
+ switch hod {
+ case android.HostSupported:
+ attrs["target_compatible_with"] = `select({
+ "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
+ "//conditions:default": [],
+ })`
+ case android.DeviceSupported:
+ attrs["target_compatible_with"] = `["//build/bazel/platforms/os:android"]`
+ }
+ }
+
attrStrings := make([]string, 0, len(attrs)+1)
attrStrings = append(attrStrings, fmt.Sprintf(` name = "%s",`, name))
for _, k := range android.SortedStringKeys(attrs) {
@@ -379,3 +425,16 @@
%s
)`, typ, strings.Join(attrStrings, "\n"))
}
+
+// makeBazelTargetNoRestrictions returns bazel target build file definition that does not add a
+// target_compatible_with. This is useful for module types like filegroup and genrule that arch not
+// arch variant
+func makeBazelTargetNoRestrictions(typ, name string, attrs attrNameToString) string {
+ return makeBazelTargetHostOrDevice(typ, name, attrs, android.HostAndDeviceDefault)
+}
+
+// makeBazelTargetNoRestrictions returns bazel target build file definition that is device specific
+// as this is the most common default in Soong.
+func makeBazelTarget(typ, name string, attrs attrNameToString) string {
+ return makeBazelTargetHostOrDevice(typ, name, attrs, android.DeviceSupported)
+}
diff --git a/cc/bp2build.go b/cc/bp2build.go
index ba02b7e..70dcf40 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -444,32 +444,33 @@
return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedSrcsLabelList), anySrcs
}
-func bp2buildResolveCppStdValue(c_std *string, cpp_std *string, gnu_extensions *bool) (*string, *string) {
- var cStdVal, cppStdVal string
+func bp2buildStdVal(std *string, prefix string, useGnu bool) *string {
+ defaultVal := prefix + "_std_default"
// If c{,pp}std properties are not specified, don't generate them in the BUILD file.
// Defaults are handled by the toolchain definition.
// However, if gnu_extensions is false, then the default gnu-to-c version must be specified.
- if cpp_std != nil {
- cppStdVal = parseCppStd(cpp_std)
- } else if gnu_extensions != nil && !*gnu_extensions {
- cppStdVal = "c++17"
- }
- if c_std != nil {
- cStdVal = parseCStd(c_std)
- } else if gnu_extensions != nil && !*gnu_extensions {
- cStdVal = "c99"
+ stdVal := proptools.StringDefault(std, defaultVal)
+ if stdVal == "experimental" || stdVal == defaultVal {
+ if stdVal == "experimental" {
+ stdVal = prefix + "_std_experimental"
+ }
+ if !useGnu {
+ stdVal += "_no_gnu"
+ }
+ } else if !useGnu {
+ stdVal = gnuToCReplacer.Replace(stdVal)
}
- cStdVal, cppStdVal = maybeReplaceGnuToC(gnu_extensions, cStdVal, cppStdVal)
- var c_std_prop, cpp_std_prop *string
- if cStdVal != "" {
- c_std_prop = &cStdVal
+ if stdVal == defaultVal {
+ return nil
}
- if cppStdVal != "" {
- cpp_std_prop = &cppStdVal
- }
+ return &stdVal
+}
- return c_std_prop, cpp_std_prop
+func bp2buildResolveCppStdValue(c_std *string, cpp_std *string, gnu_extensions *bool) (*string, *string) {
+ useGnu := useGnuExtensions(gnu_extensions)
+
+ return bp2buildStdVal(c_std, "c", useGnu), bp2buildStdVal(cpp_std, "cpp", useGnu)
}
// packageFromLabel extracts package from a fully-qualified or relative Label and whether the label
diff --git a/cc/builder.go b/cc/builder.go
index 468452d..70bbd6a 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -202,36 +202,22 @@
},
"clangBin", "format")
- // Rule for invoking clang-tidy (a clang-based linter).
- clangTidyDep, clangTidyDepRE = pctx.RemoteStaticRules("clangTidyDep",
- blueprint.RuleParams{
- Depfile: "$out",
- Deps: blueprint.DepsGCC,
- Command: "${config.CcWrapper}$ccCmd $cFlags -E -o /dev/null $in " +
- "-MQ $tidyFile -MD -MF $out",
- CommandDeps: []string{"$ccCmd"},
- },
- &remoteexec.REParams{
- Labels: map[string]string{"type": "lint", "tool": "clang-tidy", "lang": "cpp"},
- ExecStrategy: "${config.REClangTidyExecStrategy}",
- Inputs: []string{"$in"},
- Platform: map[string]string{remoteexec.PoolKey: "${config.REClangTidyPool}"},
- }, []string{"ccCmd", "cFlags", "tidyFile"}, []string{})
-
+ // Rules for invoking clang-tidy (a clang-based linter).
clangTidy, clangTidyRE = pctx.RemoteStaticRules("clangTidy",
blueprint.RuleParams{
Depfile: "${out}.d",
Deps: blueprint.DepsGCC,
- Command: "cp ${out}.dep ${out}.d && " +
- "$tidyVars$reTemplate${config.ClangBin}/clang-tidy $tidyFlags $in -- $cFlags && " +
- "touch $out",
- CommandDeps: []string{"${config.ClangBin}/clang-tidy"},
+ Command: "CLANG_CMD=$clangCmd TIDY_FILE=$out " +
+ "$tidyVars$reTemplate${config.ClangBin}/clang-tidy.sh $in $tidyFlags -- $cFlags",
+ CommandDeps: []string{"${config.ClangBin}/clang-tidy.sh", "$ccCmd", "$tidyCmd"},
},
&remoteexec.REParams{
Labels: map[string]string{"type": "lint", "tool": "clang-tidy", "lang": "cpp"},
ExecStrategy: "${config.REClangTidyExecStrategy}",
- Inputs: []string{"$in", "${out}.dep"},
- EnvironmentVariables: []string{"TIDY_TIMEOUT"},
+ Inputs: []string{"$in"},
+ OutputFiles: []string{"${out}", "${out}.d"},
+ ToolchainInputs: []string{"$ccCmd", "$tidyCmd"},
+ EnvironmentVariables: []string{"CLANG_CMD", "TIDY_FILE", "TIDY_TIMEOUT"},
// Although clang-tidy has an option to "fix" source files, that feature is hardly useable
// under parallel compilation and RBE. So we assume no OutputFiles here.
// The clang-tidy fix option is best run locally in single thread.
@@ -239,7 +225,7 @@
// (1) New timestamps trigger clang and clang-tidy compilations again.
// (2) Changing source files caused concurrent clang or clang-tidy jobs to crash.
Platform: map[string]string{remoteexec.PoolKey: "${config.REClangTidyPool}"},
- }, []string{"cFlags", "tidyFlags", "tidyVars"}, []string{})
+ }, []string{"cFlags", "ccCmd", "clangCmd", "tidyCmd", "tidyFlags", "tidyVars"}, []string{})
_ = pctx.SourcePathVariable("yasmCmd", "prebuilts/misc/${config.HostPrebuiltTag}/yasm/yasm")
@@ -636,6 +622,7 @@
continue
}
+ // ccCmd is "clang" or "clang++"
ccDesc := ccCmd
ccCmd = "${config.ClangBin}/" + ccCmd
@@ -681,43 +668,30 @@
// Even with tidy, some src file could be skipped by noTidySrcsMap.
if tidy && !noTidySrcsMap[srcFile.String()] {
tidyFile := android.ObjPathWithExt(ctx, subdir, srcFile, "tidy")
- tidyDepFile := android.ObjPathWithExt(ctx, subdir, srcFile, "tidy.dep")
tidyFiles = append(tidyFiles, tidyFile)
+ tidyCmd := "${config.ClangBin}/clang-tidy"
- ruleDep := clangTidyDep
rule := clangTidy
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_CLANG_TIDY") {
- ruleDep = clangTidyDepRE
rule = clangTidyRE
}
sharedCFlags := shareFlags("cFlags", moduleFlags)
srcRelPath := srcFile.Rel()
- // Add the .tidy.d rule
- ctx.Build(pctx, android.BuildParams{
- Rule: ruleDep,
- Description: "clang-tidy-dep " + srcRelPath,
- Output: tidyDepFile,
- Input: srcFile,
- Implicits: cFlagsDeps,
- OrderOnly: pathDeps,
- Args: map[string]string{
- "ccCmd": ccCmd,
- "cFlags": sharedCFlags,
- "tidyFile": tidyFile.String(),
- },
- })
- // Add the .tidy rule with order only dependency on the .tidy.d file
+ // Add the .tidy rule
ctx.Build(pctx, android.BuildParams{
Rule: rule,
Description: "clang-tidy " + srcRelPath,
Output: tidyFile,
Input: srcFile,
Implicits: cFlagsDeps,
- OrderOnly: append(android.Paths{}, tidyDepFile),
+ OrderOnly: pathDeps,
Args: map[string]string{
"cFlags": sharedCFlags,
+ "ccCmd": ccCmd,
+ "clangCmd": ccDesc,
+ "tidyCmd": tidyCmd,
"tidyFlags": shareFlags("tidyFlags", config.TidyFlagsForSrcFile(srcFile, flags.tidyFlags)),
"tidyVars": tidyVars, // short and not shared
},
@@ -855,24 +829,13 @@
deps = append(deps, crtBegin...)
deps = append(deps, crtEnd...)
- var depFile android.WritablePath
- var depFileLdFlags string
- depsType := blueprint.DepsNone
- if !ctx.Windows() && !ctx.Darwin() {
- // lld only supports --dependency-file for elf files
- depFile = outputFile.ReplaceExtension(ctx, "d")
- depFileLdFlags = " -Wl,--dependency-file=" + depFile.String()
- depsType = blueprint.DepsGCC
- implicitOutputs = append(implicitOutputs, depFile)
- }
-
rule := ld
args := map[string]string{
"ldCmd": ldCmd,
"crtBegin": strings.Join(crtBegin.Strings(), " "),
"libFlags": strings.Join(libFlagsList, " "),
"extraLibFlags": flags.extraLibFlags,
- "ldFlags": flags.globalLdFlags + " " + flags.localLdFlags + depFileLdFlags,
+ "ldFlags": flags.globalLdFlags + " " + flags.localLdFlags,
"crtEnd": strings.Join(crtEnd.Strings(), " "),
}
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_CXX_LINKS") {
@@ -883,8 +846,6 @@
ctx.Build(pctx, android.BuildParams{
Rule: rule,
- Deps: depsType,
- Depfile: depFile,
Description: "link " + outputFile.Base(),
Output: outputFile,
ImplicitOutputs: implicitOutputs,
@@ -964,7 +925,6 @@
outputFile := android.PathForModuleOut(ctx, baseName+".abidiff")
libName := strings.TrimSuffix(baseName, filepath.Ext(baseName))
- createReferenceDumpFlags := ""
var extraFlags []string
if checkAllApis {
@@ -975,18 +935,8 @@
"-allow-unreferenced-elf-symbol-changes")
}
- if exportedHeaderFlags == "" {
- extraFlags = append(extraFlags, "-advice-only")
- }
-
if isLlndk || isNdk {
- createReferenceDumpFlags = "--llndk"
- if isLlndk {
- // TODO(b/130324828): "-consider-opaque-types-different" should apply to
- // both LLNDK and NDK shared libs. However, a known issue in header-abi-diff
- // breaks libaaudio. Remove the if-guard after the issue is fixed.
- extraFlags = append(extraFlags, "-consider-opaque-types-different")
- }
+ extraFlags = append(extraFlags, "-consider-opaque-types-different")
}
if isVndkExt {
extraFlags = append(extraFlags, "-allow-extensions")
@@ -1005,7 +955,7 @@
"libName": libName,
"arch": ctx.Arch().ArchType.Name,
"extraFlags": strings.Join(extraFlags, " "),
- "createReferenceDumpFlags": createReferenceDumpFlags,
+ "createReferenceDumpFlags": "",
},
})
return android.OptionalPathForPath(outputFile)
@@ -1041,33 +991,18 @@
ldCmd := "${config.ClangBin}/clang++"
- var implicitOutputs android.WritablePaths
- var depFile android.WritablePath
- var depFileLdFlags string
- depsType := blueprint.DepsNone
- if !ctx.Windows() && !ctx.Darwin() {
- // lld only supports --dependency-file for elf files
- depFile = outputFile.ReplaceExtension(ctx, "d")
- depFileLdFlags = " -Wl,--dependency-file=" + depFile.String()
- depsType = blueprint.DepsGCC
- implicitOutputs = append(implicitOutputs, depFile)
- }
-
rule := partialLd
args := map[string]string{
"ldCmd": ldCmd,
- "ldFlags": flags.globalLdFlags + " " + flags.localLdFlags + depFileLdFlags,
+ "ldFlags": flags.globalLdFlags + " " + flags.localLdFlags,
}
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_CXX_LINKS") {
rule = partialLdRE
args["inCommaList"] = strings.Join(objFiles.Strings(), ",")
args["implicitInputs"] = strings.Join(deps.Strings(), ",")
- args["implicitOutputs"] = strings.Join(implicitOutputs.Strings(), ",")
}
ctx.Build(pctx, android.BuildParams{
Rule: rule,
- Deps: depsType,
- Depfile: depFile,
Description: "link " + outputFile.Base(),
Output: outputFile,
Inputs: objFiles,
diff --git a/cc/cc.go b/cc/cc.go
index da8a807..55c0e48 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1789,13 +1789,20 @@
var _ android.MixedBuildBuildable = (*Module)(nil)
func (c *Module) getBazelModuleLabel(ctx android.BaseModuleContext) string {
+ var bazelModuleLabel string
if c.typ() == fullLibrary && c.static() {
// cc_library is a special case in bp2build; two targets are generated -- one for each
// of the shared and static variants. The shared variant keeps the module name, but the
// static variant uses a different suffixed name.
- return bazelLabelForStaticModule(ctx, c)
+ bazelModuleLabel = bazelLabelForStaticModule(ctx, c)
+ } else {
+ bazelModuleLabel = c.GetBazelLabel(ctx, c)
}
- return c.GetBazelLabel(ctx, c)
+ labelNoPrebuilt := bazelModuleLabel
+ if c.IsPrebuilt() {
+ labelNoPrebuilt = android.RemoveOptionalPrebuiltPrefixFromBazelLabel(bazelModuleLabel)
+ }
+ return labelNoPrebuilt
}
func (c *Module) QueueBazelCall(ctx android.BaseModuleContext) {
diff --git a/cc/cc_test.go b/cc/cc_test.go
index fb24624..38f6383 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -4076,7 +4076,7 @@
{
name: "assemble",
src: "foo.s",
- expected: combineSlices(baseExpectedFlags, []string{"-D__ASSEMBLY__"}, expectedIncludes, lastIncludes),
+ expected: combineSlices(baseExpectedFlags, []string{"-D__ASSEMBLY__", "-fdebug-default-version=4"}, expectedIncludes, lastIncludes),
},
}
diff --git a/cc/compiler.go b/cc/compiler.go
index 773a642..cd1d92c 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -295,8 +295,12 @@
getNamedMapForConfig(ctx.Config(), key).Store(module, true)
}
+func useGnuExtensions(gnuExtensions *bool) bool {
+ return proptools.BoolDefault(gnuExtensions, true)
+}
+
func maybeReplaceGnuToC(gnuExtensions *bool, cStd string, cppStd string) (string, string) {
- if gnuExtensions != nil && *gnuExtensions == false {
+ if !useGnuExtensions(gnuExtensions) {
cStd = gnuToCReplacer.Replace(cStd)
cppStd = gnuToCReplacer.Replace(cppStd)
}
@@ -491,6 +495,10 @@
flags.Global.AsFlags = append(flags.Global.AsFlags, "-D__ASSEMBLY__")
+ // TODO(b/235105792): override global -fdebug-default-version=5, it is causing $TMPDIR to
+ // end up in the dwarf data for crtend_so.S.
+ flags.Global.AsFlags = append(flags.Global.AsFlags, "-fdebug-default-version=4")
+
flags.Global.CppFlags = append(flags.Global.CppFlags, tc.Cppflags())
flags.Global.YasmFlags = append(flags.Global.YasmFlags, tc.YasmFlags())
diff --git a/cc/config/arm64_device.go b/cc/config/arm64_device.go
index dfe143f..66087e6 100644
--- a/cc/config/arm64_device.go
+++ b/cc/config/arm64_device.go
@@ -33,9 +33,7 @@
},
"armv8-a-branchprot": []string{
"-march=armv8-a",
- // Disable BTI until drm vendors stop using OS libraries as sources
- // of gadgets (https://issuetracker.google.com/216395195).
- "-mbranch-protection=pac-ret",
+ "-mbranch-protection=standard",
},
"armv8-2a": []string{
"-march=armv8.2-a",
diff --git a/cc/config/global.go b/cc/config/global.go
index 178e80b..b09598a 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -370,6 +370,11 @@
exportedVars.ExportStringListStaticVariable("CommonGlobalCppflags", commonGlobalCppflags)
exportedVars.ExportStringListStaticVariable("ExternalCflags", extraExternalCflags)
+ exportedVars.ExportString("CStdVersion", CStdVersion)
+ exportedVars.ExportString("CppStdVersion", CppStdVersion)
+ exportedVars.ExportString("ExperimentalCStdVersion", ExperimentalCStdVersion)
+ exportedVars.ExportString("ExperimentalCppStdVersion", ExperimentalCppStdVersion)
+
// Everything in these lists is a crime against abstraction and dependency tracking.
// Do not add anything to this list.
commonGlobalIncludes := []string{
diff --git a/cc/config/tidy.go b/cc/config/tidy.go
index 826197a..f96f3ed 100644
--- a/cc/config/tidy.go
+++ b/cc/config/tidy.go
@@ -94,6 +94,31 @@
}, ",")
})
+ // Some clang-tidy checks have bugs or not work for Android.
+ // They are disabled here, overriding any locally selected checks.
+ pctx.VariableFunc("TidyGlobalNoChecks", func(ctx android.PackageVarContext) string {
+ return strings.Join([]string{
+ // https://b.corp.google.com/issues/153464409
+ // many local projects enable cert-* checks, which
+ // trigger bugprone-reserved-identifier.
+ "-bugprone-reserved-identifier*,-cert-dcl51-cpp,-cert-dcl37-c",
+ // http://b/153757728
+ "-readability-qualified-auto",
+ // http://b/155034563
+ "-bugprone-signed-char-misuse",
+ // http://b/155034972
+ "-bugprone-branch-clone",
+ // http://b/193716442
+ "-bugprone-implicit-widening-of-multiplication-result",
+ // Too many existing functions trigger this rule, and fixing it requires large code
+ // refactoring. The cost of maintaining this tidy rule outweighs the benefit it brings.
+ "-bugprone-easily-swappable-parameters",
+ // http://b/216364337 - TODO: Follow-up after compiler update to
+ // disable or fix individual instances.
+ "-cert-err33-c",
+ }, ",")
+ })
+
// To reduce duplicate warnings from the same header files,
// header-filter will contain only the module directory and
// those specified by DEFAULT_TIDY_HEADER_DIRS.
@@ -115,6 +140,7 @@
const tidyDefault = "${config.TidyDefaultGlobalChecks}"
const tidyExternalVendor = "${config.TidyExternalVendorChecks}"
const tidyDefaultNoAnalyzer = "${config.TidyDefaultGlobalChecks},-clang-analyzer-*"
+const tidyGlobalNoChecks = "${config.TidyGlobalNoChecks}"
// This is a map of local path prefixes to the set of default clang-tidy checks
// to be used.
@@ -152,6 +178,11 @@
return tidyDefault
}
+// Returns a globally disabled tidy checks, overriding locally selected checks.
+func TidyGlobalNoChecks() string {
+ return tidyGlobalNoChecks
+}
+
func TidyFlagsForSrcFile(srcFile android.Path, flags string) string {
// Disable clang-analyzer-* checks globally for generated source files
// because some of them are too huge. Local .bp files can add wanted
diff --git a/cc/config/vndk.go b/cc/config/vndk.go
index 492cd98..dd612ce 100644
--- a/cc/config/vndk.go
+++ b/cc/config/vndk.go
@@ -17,100 +17,9 @@
// List of VNDK libraries that have different core variant and vendor variant.
// For these libraries, the vendor variants must be installed even if the device
// has VndkUseCoreVariant set.
-// TODO(b/150578172): clean up unstable and non-versioned aidl module
+// Note that AIDL-generated modules must use vendor variants by default.
var VndkMustUseVendorVariantList = []string{
- "android.hardware.authsecret-V1-ndk",
- "android.hardware.authsecret-V1-ndk_platform",
- "android.hardware.authsecret-ndk_platform",
- "android.hardware.authsecret-unstable-ndk_platform",
- "android.hardware.automotive.occupant_awareness-V1-ndk",
- "android.hardware.automotive.occupant_awareness-V1-ndk_platform",
- "android.hardware.automotive.occupant_awareness-ndk_platform",
- "android.hardware.gnss-V1-ndk",
- "android.hardware.gnss-V1-ndk_platform",
- "android.hardware.gnss-ndk_platform",
- "android.hardware.gnss-unstable-ndk_platform",
- "android.hardware.health-V1-ndk",
- "android.hardware.health-ndk",
- "android.hardware.health.storage-V1-ndk",
- "android.hardware.health.storage-V1-ndk_platform",
- "android.hardware.health.storage-ndk_platform",
- "android.hardware.health.storage-unstable-ndk_platform",
- "android.hardware.identity-V2-ndk_platform",
- "android.hardware.identity-V3-ndk",
- "android.hardware.identity-V3-ndk_platform",
- "android.hardware.identity-ndk_platform",
- "android.hardware.light-V1-ndk",
- "android.hardware.light-V1-ndk_platform",
- "android.hardware.light-ndk_platform",
- "android.hardware.memtrack-V1-ndk",
- "android.hardware.memtrack-V1-ndk_platform",
- "android.hardware.memtrack-ndk_platform",
- "android.hardware.memtrack-unstable-ndk_platform",
"android.hardware.nfc@1.2",
- "android.hardware.oemlock-V1-ndk",
- "android.hardware.oemlock-V1-ndk_platform",
- "android.hardware.oemlock-ndk_platform",
- "android.hardware.oemlock-unstable-ndk_platform",
- "android.hardware.power-V1-ndk_platform",
- "android.hardware.power-V2-ndk",
- "android.hardware.power-V2-ndk_platform",
- "android.hardware.power-ndk_platform",
- "android.hardware.power.stats-V1-ndk",
- "android.hardware.power.stats-V1-ndk_platform",
- "android.hardware.power.stats-ndk_platform",
- "android.hardware.power.stats-unstable-ndk_platform",
- "android.hardware.rebootescrow-V1-ndk",
- "android.hardware.rebootescrow-V1-ndk_platform",
- "android.hardware.rebootescrow-ndk_platform",
- "android.hardware.radio-V1-ndk",
- "android.hardware.radio-V1-ndk_platform",
- "android.hardware.radio.config-V1-ndk",
- "android.hardware.radio.config-V1-ndk_platform",
- "android.hardware.radio.data-V1-ndk",
- "android.hardware.radio.data-V1-ndk_platform",
- "android.hardware.radio.messaging-V1-ndk",
- "android.hardware.radio.messaging-V1-ndk_platform",
- "android.hardware.radio.modem-V1-ndk",
- "android.hardware.radio.modem-V1-ndk_platform",
- "android.hardware.radio.network-V1-ndk",
- "android.hardware.radio.network-V1-ndk_platform",
- "android.hardware.radio.sim-V1-ndk",
- "android.hardware.radio.sim-V1-ndk_platform",
- "android.hardware.radio.voice-V1-ndk",
- "android.hardware.radio.voice-V1-ndk_platform",
- "android.hardware.security.keymint-V1-ndk",
- "android.hardware.security.keymint-V1-ndk_platform",
- "android.hardware.security.keymint-ndk_platform",
- "android.hardware.security.keymint-unstable-ndk_platform",
- "android.hardware.security.secureclock-V1-ndk",
- "android.hardware.security.secureclock-V1-ndk_platform",
- "android.hardware.security.secureclock-ndk_platform",
- "android.hardware.security.secureclock-unstable-ndk_platform",
- "android.hardware.security.sharedsecret-V1-ndk",
- "android.hardware.security.sharedsecret-V1-ndk_platform",
- "android.hardware.security.sharedsecret-ndk_platform",
- "android.hardware.security.sharedsecret-unstable-ndk_platform",
- "android.hardware.vibrator-V1-ndk_platform",
- "android.hardware.vibrator-V2-ndk",
- "android.hardware.vibrator-V2-ndk_platform",
- "android.hardware.vibrator-ndk_platform",
- "android.hardware.weaver-V1-ndk",
- "android.hardware.weaver-V1-ndk_platform",
- "android.hardware.weaver-ndk_platform",
- "android.hardware.weaver-unstable-ndk_platform",
- "android.system.suspend-V1-ndk",
- "android.system.keystore2-V1-ndk",
- "android.se.omapi-V1-ndk_platform",
- "android.se.omapi-ndk_platform",
- "android.se.omapi-unstable-ndk_platform",
- "android.hardware.wifi.hostapd-V1-ndk",
- "android.hardware.wifi.hostapd-V1-ndk_platform",
- "android.hardware.wifi.supplicant-V1-ndk",
- "android.system.keystore2-V1-ndk_platform",
- "android.system.keystore2-ndk_platform",
- "android.system.keystore2-unstable-ndk_platform",
- "android.system.suspend-V1-ndk_platform",
"libbinder",
"libcrypto",
"libexpat",
diff --git a/cc/pgo.go b/cc/pgo.go
index 0632c15..463e2e6 100644
--- a/cc/pgo.go
+++ b/cc/pgo.go
@@ -41,7 +41,6 @@
const profileInstrumentFlag = "-fprofile-generate=/data/local/tmp"
const profileUseInstrumentFormat = "-fprofile-use=%s"
-const profileUseSamplingFormat = "-fprofile-sample-accurate -fprofile-sample-use=%s"
func getPgoProfileProjects(config android.DeviceConfig) []string {
return config.OnceStringSlice(pgoProfileProjectsConfigKey, func() []string {
@@ -56,12 +55,11 @@
type PgoProperties struct {
Pgo struct {
Instrumentation *bool
- Sampling *bool `android:"arch_variant"`
Profile_file *string `android:"arch_variant"`
Benchmarks []string
Enable_profile_use *bool `android:"arch_variant"`
// Additional compiler flags to use when building this module
- // for profiling (either instrumentation or sampling).
+ // for profiling.
Cflags []string `android:"arch_variant"`
} `android:"arch_variant"`
@@ -79,10 +77,6 @@
return props.Pgo.Instrumentation != nil && *props.Pgo.Instrumentation == true
}
-func (props *PgoProperties) isSampling() bool {
- return props.Pgo.Sampling != nil && *props.Pgo.Sampling == true
-}
-
func (pgo *pgo) props() []interface{} {
return []interface{}{&pgo.Properties}
}
@@ -135,18 +129,8 @@
return android.OptionalPathForPath(nil)
}
-func (props *PgoProperties) profileUseFlag(ctx ModuleContext, file string) string {
- if props.isInstrumentation() {
- return fmt.Sprintf(profileUseInstrumentFormat, file)
- }
- if props.isSampling() {
- return fmt.Sprintf(profileUseSamplingFormat, file)
- }
- return ""
-}
-
func (props *PgoProperties) profileUseFlags(ctx ModuleContext, file string) []string {
- flags := []string{props.profileUseFlag(ctx, file)}
+ flags := []string{fmt.Sprintf(profileUseInstrumentFormat, file)}
flags = append(flags, profileUseOtherFlags...)
return flags
}
@@ -169,19 +153,14 @@
// if profileFile gets updated
flags.CFlagsDeps = append(flags.CFlagsDeps, profileFilePath)
flags.LdFlagsDeps = append(flags.LdFlagsDeps, profileFilePath)
-
- if props.isSampling() {
- flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-mllvm,-no-warn-sample-unused=true")
- }
}
return flags
}
func (props *PgoProperties) isPGO(ctx BaseModuleContext) bool {
isInstrumentation := props.isInstrumentation()
- isSampling := props.isSampling()
- profileKindPresent := isInstrumentation || isSampling
+ profileKindPresent := isInstrumentation
filePresent := props.Pgo.Profile_file != nil
benchmarksPresent := len(props.Pgo.Benchmarks) > 0
@@ -194,7 +173,7 @@
if !profileKindPresent || !filePresent {
var missing []string
if !profileKindPresent {
- missing = append(missing, "profile kind (either \"instrumentation\" or \"sampling\" property)")
+ missing = append(missing, "profile kind")
}
if !filePresent {
missing = append(missing, "profile_file property")
@@ -208,14 +187,6 @@
ctx.ModuleErrorf("Instrumentation PGO specification is missing benchmark property")
}
- if isSampling {
- ctx.ModuleErrorf("Sampling PGO is deprecated, use AFDO instead")
- }
-
- if isSampling && isInstrumentation {
- ctx.PropertyErrorf("pgo", "Exactly one of \"instrumentation\" and \"sampling\" properties must be set")
- }
-
return true
}
diff --git a/cc/prebuilt.go b/cc/prebuilt.go
index a29e618..8c404d3 100644
--- a/cc/prebuilt.go
+++ b/cc/prebuilt.go
@@ -55,6 +55,13 @@
// This is needed only if this library is linked by other modules in build time.
// Only makes sense for the Windows target.
Windows_import_lib *string `android:"path,arch_variant"`
+
+ // MixedBuildsDisabled is true if and only if building this prebuilt is explicitly disabled in mixed builds for either
+ // its static or shared version on the current build variant. This is to prevent Bazel targets for build variants with
+ // which either the static or shared version is incompatible from participating in mixed buiods. Please note that this
+ // is an override and does not fully determine whether Bazel or Soong will be used. For the full determination, see
+ // cc.ProcessBazelQueryResponse, cc.QueueBazelCall, and cc.MixedBuildsDisabled.
+ MixedBuildsDisabled bool `blueprint:"mutated"`
}
type prebuiltLinker struct {
@@ -244,6 +251,7 @@
func (p *prebuiltLibraryLinker) disablePrebuilt() {
p.properties.Srcs = nil
+ p.properties.MixedBuildsDisabled = true
}
// Implements versionedInterface
@@ -255,6 +263,7 @@
module, library := NewLibrary(hod)
module.compiler = nil
module.bazelable = true
+ module.bazelHandler = &prebuiltLibraryBazelHandler{module: module, library: library}
prebuilt := &prebuiltLibraryLinker{
libraryDecorator: library,
@@ -310,8 +319,6 @@
func NewPrebuiltSharedLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
module, library := NewPrebuiltLibrary(hod, "srcs")
library.BuildOnlyShared()
- module.bazelable = true
- module.bazelHandler = &prebuiltSharedLibraryBazelHandler{module: module, library: library}
// Prebuilt shared libraries can be included in APEXes
android.InitApexModule(module)
@@ -329,8 +336,7 @@
func NewPrebuiltStaticLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
module, library := NewPrebuiltLibrary(hod, "srcs")
library.BuildOnlyStatic()
- module.bazelable = true
- module.bazelHandler = &prebuiltStaticLibraryBazelHandler{module: module, library: library}
+
return module, library
}
@@ -406,29 +412,52 @@
properties prebuiltObjectProperties
}
-type prebuiltStaticLibraryBazelHandler struct {
+type prebuiltLibraryBazelHandler struct {
module *Module
library *libraryDecorator
}
-var _ BazelHandler = (*prebuiltStaticLibraryBazelHandler)(nil)
+var _ BazelHandler = (*prebuiltLibraryBazelHandler)(nil)
-func (h *prebuiltStaticLibraryBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) {
+func (h *prebuiltLibraryBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) {
+ if h.module.linker.(*prebuiltLibraryLinker).properties.MixedBuildsDisabled {
+ return
+ }
bazelCtx := ctx.Config().BazelContext
bazelCtx.QueueBazelRequest(label, cquery.GetCcInfo, android.GetConfigKey(ctx))
}
-func (h *prebuiltStaticLibraryBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
+func (h *prebuiltLibraryBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
+ if h.module.linker.(*prebuiltLibraryLinker).properties.MixedBuildsDisabled {
+ return
+ }
bazelCtx := ctx.Config().BazelContext
ccInfo, err := bazelCtx.GetCcInfo(label, android.GetConfigKey(ctx))
if err != nil {
ctx.ModuleErrorf(err.Error())
return
}
+
+ if h.module.static() {
+ if ok := h.processStaticBazelQueryResponse(ctx, label, ccInfo); !ok {
+ return
+ }
+ } else if h.module.Shared() {
+ if ok := h.processSharedBazelQueryResponse(ctx, label, ccInfo); !ok {
+ return
+ }
+ } else {
+ return
+ }
+
+ h.module.maybeUnhideFromMake()
+}
+
+func (h *prebuiltLibraryBazelHandler) processStaticBazelQueryResponse(ctx android.ModuleContext, label string, ccInfo cquery.CcInfo) bool {
staticLibs := ccInfo.CcStaticLibraryFiles
if len(staticLibs) > 1 {
ctx.ModuleErrorf("expected 1 static library from bazel target %q, got %s", label, staticLibs)
- return
+ return false
}
// TODO(b/184543518): cc_prebuilt_library_static may have properties for re-exporting flags
@@ -443,7 +472,7 @@
if len(staticLibs) == 0 {
h.module.outputFile = android.OptionalPath{}
- return
+ return true
}
out := android.PathForBazelOut(ctx, staticLibs[0])
@@ -455,31 +484,15 @@
TransitiveStaticLibrariesForOrdering: depSet,
})
+
+ return true
}
-type prebuiltSharedLibraryBazelHandler struct {
- module *Module
- library *libraryDecorator
-}
-
-var _ BazelHandler = (*prebuiltSharedLibraryBazelHandler)(nil)
-
-func (h *prebuiltSharedLibraryBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) {
- bazelCtx := ctx.Config().BazelContext
- bazelCtx.QueueBazelRequest(label, cquery.GetCcInfo, android.GetConfigKey(ctx))
-}
-
-func (h *prebuiltSharedLibraryBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
- bazelCtx := ctx.Config().BazelContext
- ccInfo, err := bazelCtx.GetCcInfo(label, android.GetConfigKey(ctx))
- if err != nil {
- ctx.ModuleErrorf(err.Error())
- return
- }
+func (h *prebuiltLibraryBazelHandler) processSharedBazelQueryResponse(ctx android.ModuleContext, label string, ccInfo cquery.CcInfo) bool {
sharedLibs := ccInfo.CcSharedLibraryFiles
- if len(sharedLibs) != 1 {
+ if len(sharedLibs) > 1 {
ctx.ModuleErrorf("expected 1 shared library from bazel target %s, got %q", label, sharedLibs)
- return
+ return false
}
// TODO(b/184543518): cc_prebuilt_library_shared may have properties for re-exporting flags
@@ -487,14 +500,9 @@
// TODO(eakammer):Add stub-related flags if this library is a stub library.
// h.library.exportVersioningMacroIfNeeded(ctx)
- // Dependencies on this library will expect collectedSnapshotHeaders to be set, otherwise
- // validation will fail. For now, set this to an empty list.
- // TODO(cparsons): More closely mirror the collectHeadersForSnapshot implementation.
- h.library.collectedSnapshotHeaders = android.Paths{}
-
if len(sharedLibs) == 0 {
h.module.outputFile = android.OptionalPath{}
- return
+ return true
}
out := android.PathForBazelOut(ctx, sharedLibs[0])
@@ -519,6 +527,7 @@
h.library.setFlagExporterInfoFromCcInfo(ctx, ccInfo)
h.module.maybeUnhideFromMake()
+ return true
}
func (p *prebuiltObjectLinker) prebuilt() *android.Prebuilt {
diff --git a/cc/prebuilt_test.go b/cc/prebuilt_test.go
index 901f458..e959157 100644
--- a/cc/prebuilt_test.go
+++ b/cc/prebuilt_test.go
@@ -381,6 +381,149 @@
assertString(t, static2.OutputFile().Path().Base(), "libf.hwasan.a")
}
+func TestPrebuiltLibraryWithBazel(t *testing.T) {
+ const bp = `
+cc_prebuilt_library {
+ name: "foo",
+ shared: {
+ srcs: ["foo.so"],
+ },
+ static: {
+ srcs: ["foo.a"],
+ },
+ bazel_module: { label: "//foo/bar:bar" },
+}`
+ outBaseDir := "outputbase"
+ result := android.GroupFixturePreparers(
+ prepareForPrebuiltTest,
+ android.FixtureModifyConfig(func(config android.Config) {
+ config.BazelContext = android.MockBazelContext{
+ OutputBaseDir: outBaseDir,
+ LabelToCcInfo: map[string]cquery.CcInfo{
+ "//foo/bar:bar": cquery.CcInfo{
+ CcSharedLibraryFiles: []string{"foo.so"},
+ },
+ "//foo/bar:bar_bp2build_cc_library_static": cquery.CcInfo{
+ CcStaticLibraryFiles: []string{"foo.a"},
+ },
+ },
+ }
+ }),
+ ).RunTestWithBp(t, bp)
+ sharedFoo := result.ModuleForTests("foo", "android_arm_armv7-a-neon_shared").Module()
+ pathPrefix := outBaseDir + "/execroot/__main__/"
+
+ sharedInfo := result.ModuleProvider(sharedFoo, SharedLibraryInfoProvider).(SharedLibraryInfo)
+ android.AssertPathRelativeToTopEquals(t,
+ "prebuilt library shared target path did not exist or did not match expected. If the base path is what does not match, it is likely that Soong built this module instead of Bazel.",
+ pathPrefix+"foo.so", sharedInfo.SharedLibrary)
+
+ outputFiles, err := sharedFoo.(android.OutputFileProducer).OutputFiles("")
+ if err != nil {
+ t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
+ }
+ expectedOutputFiles := []string{pathPrefix + "foo.so"}
+ android.AssertDeepEquals(t,
+ "prebuilt library shared target output files did not match expected.",
+ expectedOutputFiles, outputFiles.Strings())
+
+ staticFoo := result.ModuleForTests("foo", "android_arm_armv7-a-neon_static").Module()
+ staticInfo := result.ModuleProvider(staticFoo, StaticLibraryInfoProvider).(StaticLibraryInfo)
+ android.AssertPathRelativeToTopEquals(t,
+ "prebuilt library static target path did not exist or did not match expected. If the base path is what does not match, it is likely that Soong built this module instead of Bazel.",
+ pathPrefix+"foo.a", staticInfo.StaticLibrary)
+
+ staticOutputFiles, err := staticFoo.(android.OutputFileProducer).OutputFiles("")
+ if err != nil {
+ t.Errorf("Unexpected error getting cc_object staticOutputFiles %s", err)
+ }
+ expectedStaticOutputFiles := []string{pathPrefix + "foo.a"}
+ android.AssertDeepEquals(t,
+ "prebuilt library static target output files did not match expected.",
+ expectedStaticOutputFiles, staticOutputFiles.Strings())
+}
+
+func TestPrebuiltLibraryWithBazelStaticDisabled(t *testing.T) {
+ const bp = `
+cc_prebuilt_library {
+ name: "foo",
+ shared: {
+ srcs: ["foo.so"],
+ },
+ static: {
+ enabled: false
+ },
+ bazel_module: { label: "//foo/bar:bar" },
+}`
+ outBaseDir := "outputbase"
+ result := android.GroupFixturePreparers(
+ prepareForPrebuiltTest,
+ android.FixtureModifyConfig(func(config android.Config) {
+ config.BazelContext = android.MockBazelContext{
+ OutputBaseDir: outBaseDir,
+ LabelToCcInfo: map[string]cquery.CcInfo{
+ "//foo/bar:bar": cquery.CcInfo{
+ CcSharedLibraryFiles: []string{"foo.so"},
+ },
+ },
+ }
+ }),
+ ).RunTestWithBp(t, bp)
+ sharedFoo := result.ModuleForTests("foo", "android_arm_armv7-a-neon_shared").Module()
+ pathPrefix := outBaseDir + "/execroot/__main__/"
+
+ sharedInfo := result.ModuleProvider(sharedFoo, SharedLibraryInfoProvider).(SharedLibraryInfo)
+ android.AssertPathRelativeToTopEquals(t,
+ "prebuilt library shared target path did not exist or did not match expected. If the base path is what does not match, it is likely that Soong built this module instead of Bazel.",
+ pathPrefix+"foo.so", sharedInfo.SharedLibrary)
+
+ outputFiles, err := sharedFoo.(android.OutputFileProducer).OutputFiles("")
+ if err != nil {
+ t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
+ }
+ expectedOutputFiles := []string{pathPrefix + "foo.so"}
+ android.AssertDeepEquals(t,
+ "prebuilt library shared target output files did not match expected.",
+ expectedOutputFiles, outputFiles.Strings())
+}
+
+func TestPrebuiltLibraryStaticWithBazel(t *testing.T) {
+ const bp = `
+cc_prebuilt_library_static {
+ name: "foo",
+ srcs: ["foo.so"],
+ bazel_module: { label: "//foo/bar:bar" },
+}`
+ outBaseDir := "outputbase"
+ result := android.GroupFixturePreparers(
+ prepareForPrebuiltTest,
+ android.FixtureModifyConfig(func(config android.Config) {
+ config.BazelContext = android.MockBazelContext{
+ OutputBaseDir: outBaseDir,
+ LabelToCcInfo: map[string]cquery.CcInfo{
+ "//foo/bar:bar": cquery.CcInfo{
+ CcStaticLibraryFiles: []string{"foo.so"},
+ },
+ },
+ }
+ }),
+ ).RunTestWithBp(t, bp)
+ staticFoo := result.ModuleForTests("foo", "android_arm_armv7-a-neon_static").Module()
+ pathPrefix := outBaseDir + "/execroot/__main__/"
+
+ info := result.ModuleProvider(staticFoo, StaticLibraryInfoProvider).(StaticLibraryInfo)
+ android.AssertPathRelativeToTopEquals(t,
+ "prebuilt library static path did not match expected. If the base path is what does not match, it is likely that Soong built this module instead of Bazel.",
+ pathPrefix+"foo.so", info.StaticLibrary)
+
+ outputFiles, err := staticFoo.(android.OutputFileProducer).OutputFiles("")
+ if err != nil {
+ t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
+ }
+ expectedOutputFiles := []string{pathPrefix + "foo.so"}
+ android.AssertDeepEquals(t, "prebuilt library static output files did not match expected.", expectedOutputFiles, outputFiles.Strings())
+}
+
func TestPrebuiltLibrarySharedWithBazelWithoutToc(t *testing.T) {
const bp = `
cc_prebuilt_library_shared {
diff --git a/cc/tidy.go b/cc/tidy.go
index ac1521b..75c038d 100644
--- a/cc/tidy.go
+++ b/cc/tidy.go
@@ -144,33 +144,31 @@
tidyChecks += config.TidyChecksForDir(ctx.ModuleDir())
}
if len(tidy.Properties.Tidy_checks) > 0 {
- tidyChecks = tidyChecks + "," + strings.Join(esc(ctx, "tidy_checks",
- config.ClangRewriteTidyChecks(tidy.Properties.Tidy_checks)), ",")
+ // If Tidy_checks contains "-*", ignore all checks before "-*".
+ localChecks := tidy.Properties.Tidy_checks
+ ignoreGlobalChecks := false
+ for n, check := range tidy.Properties.Tidy_checks {
+ if check == "-*" {
+ ignoreGlobalChecks = true
+ localChecks = tidy.Properties.Tidy_checks[n:]
+ }
+ }
+ if ignoreGlobalChecks {
+ tidyChecks = "-checks=" + strings.Join(esc(ctx, "tidy_checks",
+ config.ClangRewriteTidyChecks(localChecks)), ",")
+ } else {
+ tidyChecks = tidyChecks + "," + strings.Join(esc(ctx, "tidy_checks",
+ config.ClangRewriteTidyChecks(localChecks)), ",")
+ }
}
+ tidyChecks = tidyChecks + "," + config.TidyGlobalNoChecks()
if ctx.Windows() {
// https://b.corp.google.com/issues/120614316
// mingw32 has cert-dcl16-c warning in NO_ERROR,
// which is used in many Android files.
tidyChecks = tidyChecks + ",-cert-dcl16-c"
}
- // https://b.corp.google.com/issues/153464409
- // many local projects enable cert-* checks, which
- // trigger bugprone-reserved-identifier.
- tidyChecks = tidyChecks + ",-bugprone-reserved-identifier*,-cert-dcl51-cpp,-cert-dcl37-c"
- // http://b/153757728
- tidyChecks = tidyChecks + ",-readability-qualified-auto"
- // http://b/155034563
- tidyChecks = tidyChecks + ",-bugprone-signed-char-misuse"
- // http://b/155034972
- tidyChecks = tidyChecks + ",-bugprone-branch-clone"
- // http://b/193716442
- tidyChecks = tidyChecks + ",-bugprone-implicit-widening-of-multiplication-result"
- // Too many existing functions trigger this rule, and fixing it requires large code
- // refactoring. The cost of maintaining this tidy rule outweighs the benefit it brings.
- tidyChecks = tidyChecks + ",-bugprone-easily-swappable-parameters"
- // http://b/216364337 - TODO: Follow-up after compiler update to
- // disable or fix individual instances.
- tidyChecks = tidyChecks + ",-cert-err33-c"
+
flags.TidyFlags = append(flags.TidyFlags, tidyChecks)
if ctx.Config().IsEnvTrue("WITH_TIDY") {
diff --git a/cc/tidy_test.go b/cc/tidy_test.go
index 339b302..5c15fac 100644
--- a/cc/tidy_test.go
+++ b/cc/tidy_test.go
@@ -16,11 +16,83 @@
import (
"fmt"
+ "strings"
"testing"
"android/soong/android"
)
+func TestTidyChecks(t *testing.T) {
+ // The "tidy_checks" property defines additional checks appended
+ // to global default. But there are some checks disabled after
+ // the local tidy_checks.
+ bp := `
+ cc_library_shared { // has global checks + extraGlobalChecks
+ name: "libfoo_1",
+ srcs: ["foo.c"],
+ }
+ cc_library_shared { // has only local checks + extraGlobalChecks
+ name: "libfoo_2",
+ srcs: ["foo.c"],
+ tidy_checks: ["-*", "xyz-*"],
+ }
+ cc_library_shared { // has global checks + local checks + extraGlobalChecks
+ name: "libfoo_3",
+ srcs: ["foo.c"],
+ tidy_checks: ["-abc*", "xyz-*", "mycheck"],
+ }
+ cc_library_shared { // has only local checks after "-*" + extraGlobalChecks
+ name: "libfoo_4",
+ srcs: ["foo.c"],
+ tidy_checks: ["-abc*", "xyz-*", "mycheck", "-*", "xyz-*"],
+ }`
+ ctx := testCc(t, bp)
+
+ globalChecks := "-checks=${config.TidyDefaultGlobalChecks},"
+ firstXyzChecks := "-checks='-*','xyz-*',"
+ localXyzChecks := "'-*','xyz-*'"
+ localAbcChecks := "'-abc*','xyz-*',mycheck"
+ extraGlobalChecks := ",${config.TidyGlobalNoChecks}"
+ testCases := []struct {
+ libNumber int // 1,2,3,...
+ checks []string // must have substrings in -checks
+ noChecks []string // must not have substrings in -checks
+ }{
+ {1, []string{globalChecks, extraGlobalChecks}, []string{localXyzChecks, localAbcChecks}},
+ {2, []string{firstXyzChecks, extraGlobalChecks}, []string{globalChecks, localAbcChecks}},
+ {3, []string{globalChecks, localAbcChecks, extraGlobalChecks}, []string{localXyzChecks}},
+ {4, []string{firstXyzChecks, extraGlobalChecks}, []string{globalChecks, localAbcChecks}},
+ }
+ t.Run("caseTidyChecks", func(t *testing.T) {
+ variant := "android_arm64_armv8-a_shared"
+ for _, test := range testCases {
+ libName := fmt.Sprintf("libfoo_%d", test.libNumber)
+ flags := ctx.ModuleForTests(libName, variant).Rule("clangTidy").Args["tidyFlags"]
+ splitFlags := strings.Split(flags, " ")
+ foundCheckFlag := false
+ for _, flag := range splitFlags {
+ if strings.HasPrefix(flag, "-checks=") {
+ foundCheckFlag = true
+ for _, check := range test.checks {
+ if !strings.Contains(flag, check) {
+ t.Errorf("tidyFlags for %s does not contain %s.", libName, check)
+ }
+ }
+ for _, check := range test.noChecks {
+ if strings.Contains(flag, check) {
+ t.Errorf("tidyFlags for %s should not contain %s.", libName, check)
+ }
+ }
+ break
+ }
+ }
+ if !foundCheckFlag {
+ t.Errorf("tidyFlags for %s does not contain -checks=.", libName)
+ }
+ }
+ })
+}
+
func TestWithTidy(t *testing.T) {
// When WITH_TIDY=1 or (ALLOW_LOCAL_TIDY_TRUE=1 and local tidy:true)
// a C++ library should depend on .tidy files.
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go
index b1e119f..c548ef8 100644
--- a/cmd/soong_build/main.go
+++ b/cmd/soong_build/main.go
@@ -166,8 +166,7 @@
touch(shared.JoinPath(topDir, queryviewMarker))
}
-func writeMetrics(configuration android.Config, eventHandler metrics.EventHandler) {
- metricsDir := configuration.Getenv("LOG_DIR")
+func writeMetrics(configuration android.Config, eventHandler metrics.EventHandler, metricsDir string) {
if len(metricsDir) < 1 {
fmt.Fprintf(os.Stderr, "\nMissing required env var for generating soong metrics: LOG_DIR\n")
os.Exit(1)
@@ -221,7 +220,7 @@
// doChosenActivity runs Soong for a specific activity, like bp2build, queryview
// or the actual Soong build for the build.ninja file. Returns the top level
// output file of the specific activity.
-func doChosenActivity(configuration android.Config, extraNinjaDeps []string) string {
+func doChosenActivity(configuration android.Config, extraNinjaDeps []string, logDir string) string {
mixedModeBuild := configuration.BazelContext.BazelEnabled()
generateBazelWorkspace := bp2buildMarker != ""
generateQueryView := bazelQueryViewDir != ""
@@ -285,7 +284,7 @@
}
}
- writeMetrics(configuration, *ctx.EventHandler)
+ writeMetrics(configuration, *ctx.EventHandler, logDir)
return cmdlineArgs.OutFile
}
@@ -341,7 +340,11 @@
extraNinjaDeps = append(extraNinjaDeps, filepath.Join(configuration.SoongOutDir(), "always_rerun_for_delve"))
}
- finalOutputFile := doChosenActivity(configuration, extraNinjaDeps)
+ // Bypass configuration.Getenv, as LOG_DIR does not need to be dependency tracked. By definition, it will
+ // change between every CI build, so tracking it would require re-running Soong for every build.
+ logDir := availableEnv["LOG_DIR"]
+
+ finalOutputFile := doChosenActivity(configuration, extraNinjaDeps, logDir)
writeUsedEnvironmentFile(configuration, finalOutputFile)
}
@@ -443,6 +446,8 @@
// FIXME: 'autotest_lib' is a symlink back to external/autotest, and this causes an infinite symlink expansion error for Bazel
excludes = append(excludes, "external/autotest/venv/autotest_lib")
+ excludes = append(excludes, "external/autotest/autotest_lib")
+ excludes = append(excludes, "external/autotest/client/autotest_lib/client")
// FIXME: The external/google-fruit/extras/bazel_root/third_party/fruit dir is poison
// It contains several symlinks back to real source dirs, and those source dirs contain BUILD files we want to ignore
diff --git a/compliance/copy_license_metadata/Android.bp b/compliance/copy_license_metadata/Android.bp
new file mode 100644
index 0000000..83019eb
--- /dev/null
+++ b/compliance/copy_license_metadata/Android.bp
@@ -0,0 +1,30 @@
+// Copyright 2022 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+blueprint_go_binary {
+ name: "copy_license_metadata",
+ srcs: [
+ "copy_license_metadata.go",
+ ],
+ deps: [
+ "license_metadata_proto",
+ "golang-protobuf-proto",
+ "golang-protobuf-encoding-prototext",
+ "soong-response",
+ ],
+}
diff --git a/compliance/copy_license_metadata/copy_license_metadata.go b/compliance/copy_license_metadata/copy_license_metadata.go
new file mode 100644
index 0000000..36b9489
--- /dev/null
+++ b/compliance/copy_license_metadata/copy_license_metadata.go
@@ -0,0 +1,144 @@
+// Copyright 2022 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import (
+ "flag"
+ "fmt"
+ "io/ioutil"
+ "os"
+ "strings"
+
+ "google.golang.org/protobuf/encoding/prototext"
+ "google.golang.org/protobuf/proto"
+
+ "android/soong/compliance/license_metadata_proto"
+ "android/soong/response"
+)
+
+func newMultiString(flags *flag.FlagSet, name, usage string) *multiString {
+ var f multiString
+ flags.Var(&f, name, usage)
+ return &f
+}
+
+type multiString []string
+
+func (ms *multiString) String() string { return strings.Join(*ms, ", ") }
+func (ms *multiString) Set(s string) error { *ms = append(*ms, s); return nil }
+
+func main() {
+ var expandedArgs []string
+ for _, arg := range os.Args[1:] {
+ if strings.HasPrefix(arg, "@") {
+ f, err := os.Open(strings.TrimPrefix(arg, "@"))
+ if err != nil {
+ fmt.Fprintln(os.Stderr, err.Error())
+ os.Exit(1)
+ }
+
+ respArgs, err := response.ReadRspFile(f)
+ f.Close()
+ if err != nil {
+ fmt.Fprintln(os.Stderr, err.Error())
+ os.Exit(1)
+ }
+ expandedArgs = append(expandedArgs, respArgs...)
+ } else {
+ expandedArgs = append(expandedArgs, arg)
+ }
+ }
+
+ flags := flag.NewFlagSet("flags", flag.ExitOnError)
+
+ installed := flags.String("i", "", "installed target")
+ sources := newMultiString(flags, "s", "source (input) file")
+ dep := flags.String("d", "", "license metadata file dependency")
+ outFile := flags.String("o", "", "output file")
+
+ flags.Parse(expandedArgs)
+
+ if len(*dep) == 0 || len(*installed) == 0 || len(*sources) == 0 {
+ flags.Usage()
+ if len(*dep) == 0 {
+ fmt.Fprintf(os.Stderr, "source license metadata (-d flag) required\n")
+ }
+ if len(*sources) == 0 {
+ fmt.Fprintf(os.Stderr, "source copy (-s flag required\n")
+ }
+ if len(*installed) == 0 {
+ fmt.Fprintf(os.Stderr, "installed copy (-i flag) required\n")
+ }
+ os.Exit(1)
+ }
+
+ src_metadata := license_metadata_proto.LicenseMetadata{}
+ err := readMetadata(*dep, &src_metadata)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "error: %s\n", err.Error())
+ os.Exit(2)
+ }
+
+ metadata := src_metadata
+ metadata.Built = nil
+ metadata.InstallMap = nil
+ metadata.Installed = []string{*installed}
+ metadata.Sources = *sources
+ metadata.Deps = []*license_metadata_proto.AnnotatedDependency{&license_metadata_proto.AnnotatedDependency{
+ File: proto.String(*dep),
+ Annotations: []string{"static"},
+ }}
+
+ err = writeMetadata(*outFile, &metadata)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "error: %s\n", err.Error())
+ os.Exit(2)
+ }
+}
+
+func readMetadata(file string, metadata *license_metadata_proto.LicenseMetadata) error {
+ if file == "" {
+ return fmt.Errorf("source metadata file (-d) required")
+ }
+ buf, err := ioutil.ReadFile(file)
+ if err != nil {
+ return fmt.Errorf("error reading textproto %q: %w", file, err)
+ }
+
+ err = prototext.Unmarshal(buf, metadata)
+ if err != nil {
+ return fmt.Errorf("error unmarshalling textproto: %w", err)
+ }
+
+ return nil
+}
+
+func writeMetadata(file string, metadata *license_metadata_proto.LicenseMetadata) error {
+ buf, err := prototext.MarshalOptions{Multiline: true}.Marshal(metadata)
+ if err != nil {
+ return fmt.Errorf("error marshalling textproto: %w", err)
+ }
+
+ if file != "" {
+ err = ioutil.WriteFile(file, buf, 0666)
+ if err != nil {
+ return fmt.Errorf("error writing textproto %q: %w", file, err)
+ }
+ } else {
+ _, _ = os.Stdout.Write(buf)
+ }
+
+ return nil
+}
diff --git a/dexpreopt/config.go b/dexpreopt/config.go
index ab9e418..64cd46a 100644
--- a/dexpreopt/config.go
+++ b/dexpreopt/config.go
@@ -250,8 +250,9 @@
}
type globalConfigAndRaw struct {
- global *GlobalConfig
- data []byte
+ global *GlobalConfig
+ data []byte
+ pathErrors []error
}
// GetGlobalConfig returns the global dexpreopt.config that's created in the
@@ -272,16 +273,26 @@
var globalConfigOnceKey = android.NewOnceKey("DexpreoptGlobalConfig")
var testGlobalConfigOnceKey = android.NewOnceKey("TestDexpreoptGlobalConfig")
+type pathContextErrorCollector struct {
+ android.PathContext
+ errors []error
+}
+
+func (p *pathContextErrorCollector) Errorf(format string, args ...interface{}) {
+ p.errors = append(p.errors, fmt.Errorf(format, args...))
+}
+
func getGlobalConfigRaw(ctx android.PathContext) globalConfigAndRaw {
- return ctx.Config().Once(globalConfigOnceKey, func() interface{} {
+ config := ctx.Config().Once(globalConfigOnceKey, func() interface{} {
if data, err := ctx.Config().DexpreoptGlobalConfig(ctx); err != nil {
panic(err)
} else if data != nil {
- globalConfig, err := ParseGlobalConfig(ctx, data)
+ pathErrorCollectorCtx := &pathContextErrorCollector{PathContext: ctx}
+ globalConfig, err := ParseGlobalConfig(pathErrorCollectorCtx, data)
if err != nil {
panic(err)
}
- return globalConfigAndRaw{globalConfig, data}
+ return globalConfigAndRaw{globalConfig, data, pathErrorCollectorCtx.errors}
}
// No global config filename set, see if there is a test config set
@@ -291,16 +302,35 @@
DisablePreopt: true,
DisablePreoptBootImages: true,
DisableGenerateProfile: true,
- }, nil}
+ }, nil, nil}
})
}).(globalConfigAndRaw)
+
+ // Avoid non-deterministic errors by reporting cached path errors on all callers.
+ for _, err := range config.pathErrors {
+ if ctx.Config().AllowMissingDependencies() {
+ // When AllowMissingDependencies it set, report errors through AddMissingDependencies.
+ // If AddMissingDependencies doesn't exist on the current context (for example when
+ // called with a SingletonContext), just swallow the errors since there is no way to
+ // report them.
+ if missingDepsCtx, ok := ctx.(interface {
+ AddMissingDependencies(missingDeps []string)
+ }); ok {
+ missingDepsCtx.AddMissingDependencies([]string{err.Error()})
+ }
+ } else {
+ android.ReportPathErrorf(ctx, "%w", err)
+ }
+ }
+
+ return config
}
// SetTestGlobalConfig sets a GlobalConfig that future calls to GetGlobalConfig
// will return. It must be called before the first call to GetGlobalConfig for
// the config.
func SetTestGlobalConfig(config android.Config, globalConfig *GlobalConfig) {
- config.Once(testGlobalConfigOnceKey, func() interface{} { return globalConfigAndRaw{globalConfig, nil} })
+ config.Once(testGlobalConfigOnceKey, func() interface{} { return globalConfigAndRaw{globalConfig, nil, nil} })
}
// This struct is required to convert ModuleConfig from/to JSON.
diff --git a/genrule/genrule.go b/genrule/genrule.go
index 8649b15..818e1bc 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -805,6 +805,7 @@
func GenSrcsFactory() android.Module {
m := NewGenSrcs()
android.InitAndroidModule(m)
+ android.InitBazelModule(m)
return m
}
@@ -816,6 +817,13 @@
Shard_size *int64
}
+type bazelGensrcsAttributes struct {
+ Srcs bazel.LabelListAttribute
+ Output_extension *string
+ Tools bazel.LabelListAttribute
+ Cmd string
+}
+
const defaultShardSize = 50
func NewGenRule() *Module {
@@ -880,8 +888,14 @@
// Replace in and out variables with $< and $@
var cmd string
if m.properties.Cmd != nil {
- cmd = strings.Replace(*m.properties.Cmd, "$(in)", "$(SRCS)", -1)
- cmd = strings.Replace(cmd, "$(out)", "$(OUTS)", -1)
+ if ctx.ModuleType() == "gensrcs" {
+ cmd = strings.ReplaceAll(*m.properties.Cmd, "$(in)", "$(SRC)")
+ cmd = strings.ReplaceAll(cmd, "$(out)", "$(OUT)")
+ } else {
+ cmd = strings.Replace(*m.properties.Cmd, "$(in)", "$(SRCS)", -1)
+ cmd = strings.Replace(cmd, "$(out)", "$(OUTS)", -1)
+ }
+
genDir := "$(GENDIR)"
if t := ctx.ModuleType(); t == "cc_genrule" || t == "java_genrule" || t == "java_genrule_host" {
genDir = "$(RULEDIR)"
@@ -901,30 +915,50 @@
}
}
- // The Out prop is not in an immediately accessible field
- // in the Module struct, so use GetProperties and cast it
- // to the known struct prop.
- var outs []string
- for _, propIntf := range m.GetProperties() {
- if props, ok := propIntf.(*genRuleProperties); ok {
- outs = props.Out
- break
+ if ctx.ModuleType() == "gensrcs" {
+ // The Output_extension prop is not in an immediately accessible field
+ // in the Module struct, so use GetProperties and cast it
+ // to the known struct prop.
+ var outputExtension *string
+ for _, propIntf := range m.GetProperties() {
+ if props, ok := propIntf.(*genSrcsProperties); ok {
+ outputExtension = props.Output_extension
+ break
+ }
}
+ props := bazel.BazelTargetModuleProperties{
+ Rule_class: "gensrcs",
+ Bzl_load_location: "//build/bazel/rules:gensrcs.bzl",
+ }
+ attrs := &bazelGensrcsAttributes{
+ Srcs: srcs,
+ Output_extension: outputExtension,
+ Cmd: cmd,
+ Tools: tools,
+ }
+ ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
+ } else {
+ // The Out prop is not in an immediately accessible field
+ // in the Module struct, so use GetProperties and cast it
+ // to the known struct prop.
+ var outs []string
+ for _, propIntf := range m.GetProperties() {
+ if props, ok := propIntf.(*genRuleProperties); ok {
+ outs = props.Out
+ break
+ }
+ }
+ attrs := &bazelGenruleAttributes{
+ Srcs: srcs,
+ Outs: outs,
+ Cmd: cmd,
+ Tools: tools,
+ }
+ props := bazel.BazelTargetModuleProperties{
+ Rule_class: "genrule",
+ }
+ ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
}
-
- attrs := &bazelGenruleAttributes{
- Srcs: srcs,
- Outs: outs,
- Cmd: cmd,
- Tools: tools,
- }
-
- props := bazel.BazelTargetModuleProperties{
- Rule_class: "genrule",
- }
-
- // Create the BazelTargetModule.
- ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
}
var Bool = proptools.Bool
diff --git a/java/androidmk.go b/java/androidmk.go
index 330e594..82ef413 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -623,6 +623,7 @@
if dstubs.apiLintReport != nil {
fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", dstubs.Name()+"-api-lint",
dstubs.apiLintReport.String(), "apilint/"+dstubs.Name()+"-lint-report.txt")
+ fmt.Fprintf(w, "$(call declare-0p-target,%s)\n", dstubs.apiLintReport.String())
}
}
if dstubs.checkNullabilityWarningsTimestamp != nil {
diff --git a/java/app.go b/java/app.go
index 86238d5..c5d88e9 100755
--- a/java/app.go
+++ b/java/app.go
@@ -656,7 +656,13 @@
if Bool(a.appProperties.Embed_notices) || ctx.Config().IsEnvTrue("ALWAYS_EMBED_NOTICES") {
noticeFile := android.PathForModuleOut(ctx, "NOTICE.html.gz")
- android.BuildNoticeHtmlOutputFromLicenseMetadata(ctx, noticeFile, "", "", a.outputFile.String())
+ android.BuildNoticeHtmlOutputFromLicenseMetadata(
+ ctx, noticeFile, "", "",
+ []string{
+ a.installDir.String() + "/",
+ android.PathForModuleInstall(ctx).String() + "/",
+ a.outputFile.String(),
+ })
noticeAssetPath := android.PathForModuleOut(ctx, "NOTICE", "NOTICE.html.gz")
builder := android.NewRuleBuilder(pctx, ctx)
builder.Command().Text("cp").
@@ -1012,7 +1018,7 @@
func AndroidTestFactory() android.Module {
module := &AndroidTest{}
- module.Module.dexProperties.Optimize.EnabledByDefault = true
+ module.Module.dexProperties.Optimize.EnabledByDefault = false
module.Module.properties.Instrument = true
module.Module.properties.Supports_static_instrumentation = true
@@ -1066,6 +1072,7 @@
func AndroidTestHelperAppFactory() android.Module {
module := &AndroidTestHelperApp{}
+ // TODO(b/192032291): Disable by default after auditing downstream usage.
module.Module.dexProperties.Optimize.EnabledByDefault = true
module.Module.properties.Installable = proptools.BoolPtr(true)
diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go
index b28d70c..0591012 100644
--- a/java/bootclasspath_fragment.go
+++ b/java/bootclasspath_fragment.go
@@ -858,11 +858,18 @@
packagePrefixes := b.sourceOnlyProperties.Hidden_api.Package_prefixes
singlePackages := b.sourceOnlyProperties.Hidden_api.Single_packages
if splitPackages != nil || packagePrefixes != nil || singlePackages != nil {
- if splitPackages == nil {
- splitPackages = []string{"*"}
- }
output.SignaturePatternsPath = buildRuleSignaturePatternsFile(
ctx, output.AllFlagsPath, splitPackages, packagePrefixes, singlePackages)
+ } else if !b.isTestFragment() {
+ ctx.ModuleErrorf(`Must specify at least one of the split_packages, package_prefixes and single_packages properties
+ If this is a new bootclasspath_fragment or you are unsure what to do add the
+ the following to the bootclasspath_fragment:
+ hidden_api: {split_packages: ["*"]},
+ and then run the following:
+ m analyze_bcpf && analyze_bcpf --bcpf %q
+ it will analyze the bootclasspath_fragment and provide hints as to what you
+ should specify here. If you are happy with its suggestions then you can add
+ the --fix option and it will fix them for you.`, b.BaseModuleName())
}
return output
diff --git a/java/bootclasspath_fragment_test.go b/java/bootclasspath_fragment_test.go
index 8ffe99a..83beb6d 100644
--- a/java/bootclasspath_fragment_test.go
+++ b/java/bootclasspath_fragment_test.go
@@ -121,6 +121,9 @@
],
},
},
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_library {
@@ -201,6 +204,9 @@
core_platform_api: {
stub_libs: ["mycoreplatform.stubs"],
},
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_library {
diff --git a/java/dex.go b/java/dex.go
index 13d6e4a..c943938 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -36,8 +36,8 @@
Main_dex_rules []string `android:"path"`
Optimize struct {
- // If false, disable all optimization. Defaults to true for android_app and android_test
- // modules, false for java_library and java_test modules.
+ // If false, disable all optimization. Defaults to true for android_app and
+ // android_test_helper_app modules, false for android_test, java_library, and java_test modules.
Enabled *bool
// True if the module containing this has it set by default.
EnabledByDefault bool `blueprint:"mutated"`
diff --git a/java/java.go b/java/java.go
index 0dfb968..feb49ad 100644
--- a/java/java.go
+++ b/java/java.go
@@ -864,7 +864,25 @@
Data_native_bins []string `android:"arch_variant"`
// list of device binary modules that should be installed alongside the test
- Data_device_bins []string `android:"arch_variant"`
+ // This property only adds the first variant of the dependency
+ Data_device_bins_first []string `android:"arch_variant"`
+
+ // list of device binary modules that should be installed alongside the test
+ // This property adds 64bit AND 32bit variants of the dependency
+ Data_device_bins_both []string `android:"arch_variant"`
+
+ // list of device binary modules that should be installed alongside the test
+ // This property only adds 64bit variants of the dependency
+ Data_device_bins_64 []string `android:"arch_variant"`
+
+ // list of device binary modules that should be installed alongside the test
+ // This property adds 32bit variants of the dependency if available, or else
+ // defaults to the 64bit variant
+ Data_device_bins_prefer32 []string `android:"arch_variant"`
+
+ // list of device binary modules that should be installed alongside the test
+ // This property only adds 32bit variants of the dependency
+ Data_device_bins_32 []string `android:"arch_variant"`
}
type testHelperLibraryProperties struct {
@@ -931,6 +949,83 @@
return true
}
+func (j *TestHost) addDataDeviceBinsDeps(ctx android.BottomUpMutatorContext) {
+ if len(j.testHostProperties.Data_device_bins_first) > 0 {
+ deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations()
+ ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_first...)
+ }
+
+ var maybeAndroid32Target *android.Target
+ var maybeAndroid64Target *android.Target
+ android32TargetList := android.FirstTarget(ctx.Config().Targets[android.Android], "lib32")
+ android64TargetList := android.FirstTarget(ctx.Config().Targets[android.Android], "lib64")
+ if len(android32TargetList) > 0 {
+ maybeAndroid32Target = &android32TargetList[0]
+ }
+ if len(android64TargetList) > 0 {
+ maybeAndroid64Target = &android64TargetList[0]
+ }
+
+ if len(j.testHostProperties.Data_device_bins_both) > 0 {
+ if maybeAndroid32Target == nil && maybeAndroid64Target == nil {
+ ctx.PropertyErrorf("data_device_bins_both", "no device targets available. Targets: %q", ctx.Config().Targets)
+ return
+ }
+ if maybeAndroid32Target != nil {
+ ctx.AddFarVariationDependencies(
+ maybeAndroid32Target.Variations(),
+ dataDeviceBinsTag,
+ j.testHostProperties.Data_device_bins_both...,
+ )
+ }
+ if maybeAndroid64Target != nil {
+ ctx.AddFarVariationDependencies(
+ maybeAndroid64Target.Variations(),
+ dataDeviceBinsTag,
+ j.testHostProperties.Data_device_bins_both...,
+ )
+ }
+ }
+
+ if len(j.testHostProperties.Data_device_bins_prefer32) > 0 {
+ if maybeAndroid32Target != nil {
+ ctx.AddFarVariationDependencies(
+ maybeAndroid32Target.Variations(),
+ dataDeviceBinsTag,
+ j.testHostProperties.Data_device_bins_prefer32...,
+ )
+ } else {
+ if maybeAndroid64Target == nil {
+ ctx.PropertyErrorf("data_device_bins_prefer32", "no device targets available. Targets: %q", ctx.Config().Targets)
+ return
+ }
+ ctx.AddFarVariationDependencies(
+ maybeAndroid64Target.Variations(),
+ dataDeviceBinsTag,
+ j.testHostProperties.Data_device_bins_prefer32...,
+ )
+ }
+ }
+
+ if len(j.testHostProperties.Data_device_bins_32) > 0 {
+ if maybeAndroid32Target == nil {
+ ctx.PropertyErrorf("data_device_bins_32", "cannot find 32bit device target. Targets: %q", ctx.Config().Targets)
+ return
+ }
+ deviceVariations := maybeAndroid32Target.Variations()
+ ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_32...)
+ }
+
+ if len(j.testHostProperties.Data_device_bins_64) > 0 {
+ if maybeAndroid64Target == nil {
+ ctx.PropertyErrorf("data_device_bins_64", "cannot find 64bit device target. Targets: %q", ctx.Config().Targets)
+ return
+ }
+ deviceVariations := maybeAndroid64Target.Variations()
+ ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_64...)
+ }
+}
+
func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) {
if len(j.testHostProperties.Data_native_bins) > 0 {
for _, target := range ctx.MultiTargets() {
@@ -938,11 +1033,6 @@
}
}
- if len(j.testHostProperties.Data_device_bins) > 0 {
- deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations()
- ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins...)
- }
-
if len(j.testProperties.Jni_libs) > 0 {
for _, target := range ctx.MultiTargets() {
sharedLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
@@ -950,6 +1040,8 @@
}
}
+ j.addDataDeviceBinsDeps(ctx)
+
j.deps(ctx)
}
@@ -957,17 +1049,40 @@
j.extraResources = append(j.extraResources, p)
}
+func (j *TestHost) dataDeviceBins() []string {
+ ret := make([]string, 0,
+ len(j.testHostProperties.Data_device_bins_first)+
+ len(j.testHostProperties.Data_device_bins_both)+
+ len(j.testHostProperties.Data_device_bins_prefer32)+
+ len(j.testHostProperties.Data_device_bins_32)+
+ len(j.testHostProperties.Data_device_bins_64),
+ )
+
+ ret = append(ret, j.testHostProperties.Data_device_bins_first...)
+ ret = append(ret, j.testHostProperties.Data_device_bins_both...)
+ ret = append(ret, j.testHostProperties.Data_device_bins_prefer32...)
+ ret = append(ret, j.testHostProperties.Data_device_bins_32...)
+ ret = append(ret, j.testHostProperties.Data_device_bins_64...)
+
+ return ret
+}
+
func (j *TestHost) GenerateAndroidBuildActions(ctx android.ModuleContext) {
var configs []tradefed.Config
- if len(j.testHostProperties.Data_device_bins) > 0 {
+ dataDeviceBins := j.dataDeviceBins()
+ if len(dataDeviceBins) > 0 {
// add Tradefed configuration to push device bins to device for testing
remoteDir := filepath.Join("/data/local/tests/unrestricted/", j.Name())
options := []tradefed.Option{{Name: "cleanup", Value: "true"}}
- for _, bin := range j.testHostProperties.Data_device_bins {
+ for _, bin := range dataDeviceBins {
fullPath := filepath.Join(remoteDir, bin)
options = append(options, tradefed.Option{Name: "push-file", Key: bin, Value: fullPath})
}
- configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.PushFilePreparer", options})
+ configs = append(configs, tradefed.Object{
+ Type: "target_preparer",
+ Class: "com.android.tradefed.targetprep.PushFilePreparer",
+ Options: options,
+ })
}
j.Test.generateAndroidBuildActionsWithConfig(ctx, configs)
diff --git a/java/java_test.go b/java/java_test.go
index 4c93824..32b0b0f 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -723,9 +723,9 @@
t.Errorf("atestNoOptimize should not optimize APK")
}
- atestDefault := ctx.ModuleForTests("atestDefault", "android_common").MaybeRule("r8")
+ atestDefault := ctx.ModuleForTests("atestDefault", "android_common").MaybeRule("d8")
if atestDefault.Output == nil {
- t.Errorf("atestDefault should optimize APK")
+ t.Errorf("atestDefault should not optimize APK")
}
}
@@ -1498,62 +1498,172 @@
}
func TestDataDeviceBinsBuildsDeviceBinary(t *testing.T) {
- bp := `
- java_test_host {
- name: "foo",
- srcs: ["test.java"],
- data_device_bins: ["bar"],
- }
-
- cc_binary {
- name: "bar",
- }
- `
-
- ctx := android.GroupFixturePreparers(
- PrepareForIntegrationTestWithJava,
- ).RunTestWithBp(t, bp)
-
- buildOS := ctx.Config.BuildOS.String()
- fooVariant := ctx.ModuleForTests("foo", buildOS+"_common")
- barVariant := ctx.ModuleForTests("bar", "android_arm64_armv8-a")
- fooMod := fooVariant.Module().(*TestHost)
-
- relocated := barVariant.Output("bar")
- expectedInput := "out/soong/.intermediates/bar/android_arm64_armv8-a/unstripped/bar"
- android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input)
-
- entries := android.AndroidMkEntriesForTest(t, ctx.TestContext, fooMod)[0]
- expectedData := []string{
- "out/soong/.intermediates/bar/android_arm64_armv8-a/bar:bar",
+ testCases := []struct {
+ dataDeviceBinType string
+ depCompileMultilib string
+ variants []string
+ expectedError string
+ }{
+ {
+ dataDeviceBinType: "first",
+ depCompileMultilib: "first",
+ variants: []string{"android_arm64_armv8-a"},
+ },
+ {
+ dataDeviceBinType: "first",
+ depCompileMultilib: "both",
+ variants: []string{"android_arm64_armv8-a"},
+ },
+ {
+ // this is true because our testing framework is set up with
+ // Targets ~ [<64bit target>, <32bit target>], where 64bit is "first"
+ dataDeviceBinType: "first",
+ depCompileMultilib: "32",
+ expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
+ },
+ {
+ dataDeviceBinType: "first",
+ depCompileMultilib: "64",
+ variants: []string{"android_arm64_armv8-a"},
+ },
+ {
+ dataDeviceBinType: "both",
+ depCompileMultilib: "both",
+ variants: []string{
+ "android_arm_armv7-a-neon",
+ "android_arm64_armv8-a",
+ },
+ },
+ {
+ dataDeviceBinType: "both",
+ depCompileMultilib: "32",
+ expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
+ },
+ {
+ dataDeviceBinType: "both",
+ depCompileMultilib: "64",
+ expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
+ },
+ {
+ dataDeviceBinType: "both",
+ depCompileMultilib: "first",
+ expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
+ },
+ {
+ dataDeviceBinType: "32",
+ depCompileMultilib: "32",
+ variants: []string{"android_arm_armv7-a-neon"},
+ },
+ {
+ dataDeviceBinType: "32",
+ depCompileMultilib: "first",
+ expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
+ },
+ {
+ dataDeviceBinType: "32",
+ depCompileMultilib: "both",
+ variants: []string{"android_arm_armv7-a-neon"},
+ },
+ {
+ dataDeviceBinType: "32",
+ depCompileMultilib: "64",
+ expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
+ },
+ {
+ dataDeviceBinType: "64",
+ depCompileMultilib: "64",
+ variants: []string{"android_arm64_armv8-a"},
+ },
+ {
+ dataDeviceBinType: "64",
+ depCompileMultilib: "both",
+ variants: []string{"android_arm64_armv8-a"},
+ },
+ {
+ dataDeviceBinType: "64",
+ depCompileMultilib: "first",
+ variants: []string{"android_arm64_armv8-a"},
+ },
+ {
+ dataDeviceBinType: "64",
+ depCompileMultilib: "32",
+ expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
+ },
+ {
+ dataDeviceBinType: "prefer32",
+ depCompileMultilib: "32",
+ variants: []string{"android_arm_armv7-a-neon"},
+ },
+ {
+ dataDeviceBinType: "prefer32",
+ depCompileMultilib: "both",
+ variants: []string{"android_arm_armv7-a-neon"},
+ },
+ {
+ dataDeviceBinType: "prefer32",
+ depCompileMultilib: "first",
+ expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
+ },
+ {
+ dataDeviceBinType: "prefer32",
+ depCompileMultilib: "64",
+ expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
+ },
}
- actualData := entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"]
- android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", ctx.Config, expectedData, actualData)
-}
-func TestDataDeviceBinsAutogenTradefedConfig(t *testing.T) {
- bp := `
+ bpTemplate := `
java_test_host {
name: "foo",
srcs: ["test.java"],
- data_device_bins: ["bar"],
+ data_device_bins_%s: ["bar"],
}
cc_binary {
name: "bar",
+ compile_multilib: "%s",
}
`
- ctx := android.GroupFixturePreparers(
- PrepareForIntegrationTestWithJava,
- ).RunTestWithBp(t, bp)
+ for _, tc := range testCases {
+ bp := fmt.Sprintf(bpTemplate, tc.dataDeviceBinType, tc.depCompileMultilib)
- buildOS := ctx.Config.BuildOS.String()
- fooModule := ctx.ModuleForTests("foo", buildOS+"_common")
- expectedAutogenConfig := `<option name="push-file" key="bar" value="/data/local/tests/unrestricted/foo/bar" />`
+ errorHandler := android.FixtureExpectsNoErrors
+ if tc.expectedError != "" {
+ errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(tc.expectedError)
+ }
- autogen := fooModule.Rule("autogen")
- if !strings.Contains(autogen.Args["extraConfigs"], expectedAutogenConfig) {
- t.Errorf("foo extraConfigs %v does not contain %q", autogen.Args["extraConfigs"], expectedAutogenConfig)
+ testName := fmt.Sprintf(`data_device_bins_%s with compile_multilib:"%s"`, tc.dataDeviceBinType, tc.depCompileMultilib)
+ t.Run(testName, func(t *testing.T) {
+ ctx := android.GroupFixturePreparers(PrepareForIntegrationTestWithJava).
+ ExtendWithErrorHandler(errorHandler).
+ RunTestWithBp(t, bp)
+ if tc.expectedError != "" {
+ return
+ }
+
+ buildOS := ctx.Config.BuildOS.String()
+ fooVariant := ctx.ModuleForTests("foo", buildOS+"_common")
+ fooMod := fooVariant.Module().(*TestHost)
+ entries := android.AndroidMkEntriesForTest(t, ctx.TestContext, fooMod)[0]
+
+ expectedAutogenConfig := `<option name="push-file" key="bar" value="/data/local/tests/unrestricted/foo/bar" />`
+ autogen := fooVariant.Rule("autogen")
+ if !strings.Contains(autogen.Args["extraConfigs"], expectedAutogenConfig) {
+ t.Errorf("foo extraConfigs %v does not contain %q", autogen.Args["extraConfigs"], expectedAutogenConfig)
+ }
+
+ expectedData := []string{}
+ for _, variant := range tc.variants {
+ barVariant := ctx.ModuleForTests("bar", variant)
+ relocated := barVariant.Output("bar")
+ expectedInput := fmt.Sprintf("out/soong/.intermediates/bar/%s/unstripped/bar", variant)
+ android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input)
+
+ expectedData = append(expectedData, fmt.Sprintf("out/soong/.intermediates/bar/%s/bar:bar", variant))
+ }
+
+ actualData := entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"]
+ android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", ctx.Config, expectedData, actualData)
+ })
}
}
diff --git a/java/platform_bootclasspath_test.go b/java/platform_bootclasspath_test.go
index 6257e49..10c9187 100644
--- a/java/platform_bootclasspath_test.go
+++ b/java/platform_bootclasspath_test.go
@@ -272,7 +272,9 @@
entries := android.AndroidMkEntriesForTest(t, result.TestContext, platformBootclasspath)
goals := entries[0].GetDistForGoals(platformBootclasspath)
android.AssertStringEquals(t, "platform dist goals phony", ".PHONY: droidcore\n", goals[0])
- android.AssertStringEquals(t, "platform dist goals call", "$(call dist-for-goals,droidcore,out/soong/hiddenapi/hiddenapi-flags.csv:hiddenapi-flags.csv)\n", android.StringRelativeToTop(result.Config, goals[1]))
+ android.AssertStringDoesContain(t, "platform dist goals meta check", goals[1], "$(if $(strip $(ALL_TARGETS.")
+ android.AssertStringDoesContain(t, "platform dist goals meta assign", goals[1], "),,$(eval ALL_TARGETS.")
+ android.AssertStringEquals(t, "platform dist goals call", "$(call dist-for-goals,droidcore,out/soong/hiddenapi/hiddenapi-flags.csv:hiddenapi-flags.csv)\n", android.StringRelativeToTop(result.Config, goals[2]))
}
func TestPlatformBootclasspath_HiddenAPIMonolithicFiles(t *testing.T) {
diff --git a/rust/config/global.go b/rust/config/global.go
index d11665c..647a7cf 100644
--- a/rust/config/global.go
+++ b/rust/config/global.go
@@ -24,7 +24,7 @@
var pctx = android.NewPackageContext("android/soong/rust/config")
var (
- RustDefaultVersion = "1.60.0"
+ RustDefaultVersion = "1.61.0.p1"
RustDefaultBase = "prebuilts/rust/"
DefaultEdition = "2021"
Stdlibs = []string{
diff --git a/rust/coverage.go b/rust/coverage.go
index 651ce6e..5ea481f 100644
--- a/rust/coverage.go
+++ b/rust/coverage.go
@@ -56,7 +56,7 @@
flags.Coverage = true
coverage := ctx.GetDirectDepWithTag(CovLibraryName, cc.CoverageDepTag).(cc.LinkableInterface)
flags.RustFlags = append(flags.RustFlags,
- "-Z instrument-coverage", "-g")
+ "-C instrument-coverage", "-g")
flags.LinkFlags = append(flags.LinkFlags,
profileInstrFlag, "-g", coverage.OutputFile().Path().String(), "-Wl,--wrap,open")
deps.StaticLibs = append(deps.StaticLibs, coverage.OutputFile().Path())
diff --git a/rust/coverage_test.go b/rust/coverage_test.go
index f3cd375..0f599d7 100644
--- a/rust/coverage_test.go
+++ b/rust/coverage_test.go
@@ -56,7 +56,7 @@
fizzCov := ctx.ModuleForTests("fizz_cov", "android_arm64_armv8-a_cov").Rule("rustc")
buzzNoCov := ctx.ModuleForTests("buzzNoCov", "android_arm64_armv8-a").Rule("rustc")
- rustcCoverageFlags := []string{"-Z instrument-coverage", " -g "}
+ rustcCoverageFlags := []string{"-C instrument-coverage", " -g "}
for _, flag := range rustcCoverageFlags {
missingErrorStr := "missing rustc flag '%s' for '%s' module with coverage enabled; rustcFlags: %#v"
containsErrorStr := "contains rustc flag '%s' for '%s' module with coverage disabled; rustcFlags: %#v"
diff --git a/scripts/manifest_check.py b/scripts/manifest_check.py
index c8d4f76..0216fc0 100755
--- a/scripts/manifest_check.py
+++ b/scripts/manifest_check.py
@@ -20,9 +20,11 @@
import argparse
import json
+import os
import re
import subprocess
import sys
+from collections import OrderedDict
from xml.dom import minidom
from manifest import android_ns
@@ -43,11 +45,13 @@
'--uses-library',
dest='uses_libraries',
action='append',
+ default=[],
help='specify uses-library entries known to the build system')
parser.add_argument(
'--optional-uses-library',
dest='optional_uses_libraries',
action='append',
+ default=[],
help='specify uses-library entries known to the build system with '
'required:false'
)
@@ -74,9 +78,14 @@
help='print the targetSdkVersion from the manifest')
parser.add_argument(
'--dexpreopt-config',
- dest='dexpreopt_configs',
+ dest='dexpreopt_config',
+ help='a path to dexpreopt.config file for this library/app')
+ parser.add_argument(
+ '--dexpreopt-dep-config',
+ dest='dexpreopt_dep_configs',
action='append',
- help='a paths to a dexpreopt.config of some library')
+ default=[],
+ help='a path to dexpreopt.config file for a dependency library')
parser.add_argument('--aapt', dest='aapt', help='path to aapt executable')
parser.add_argument(
'--output', '-o', dest='output', help='output AndroidManifest.xml file')
@@ -295,25 +304,53 @@
return target_attr.value
-def load_dexpreopt_configs(configs):
+def remove_duplicates(l):
+ return list(OrderedDict.fromkeys(l))
+
+
+def load_dexpreopt_configs(args):
"""Load dexpreopt.config files and map module names to library names."""
module_to_libname = {}
- if configs is None:
- configs = []
+ # Go over dexpreopt.config files for uses-library dependencies and create
+ # a mapping from module name to real library name (they may differ).
+ for config in args.dexpreopt_dep_configs:
+ # Empty dexpreopt.config files are expected for some dependencies.
+ if os.stat(config).st_size != 0:
+ with open(config, 'r') as f:
+ contents = json.load(f)
+ module_to_libname[contents['Name']] = contents['ProvidesUsesLibrary']
- for config in configs:
- with open(config, 'r') as f:
+ required = translate_libnames(args.uses_libraries, module_to_libname)
+ optional = translate_libnames(args.optional_uses_libraries, module_to_libname)
+
+ # Add extra uses-libraries from the library/app's own dexpreopt.config.
+ # Extra libraries may be propagated via dependencies' dexpreopt.config files
+ # (not only uses-library ones, but also transitively via static libraries).
+ if args.dexpreopt_config:
+ with open(args.dexpreopt_config, 'r') as f:
contents = json.load(f)
- module_to_libname[contents['Name']] = contents['ProvidesUsesLibrary']
+ for clc in contents['ClassLoaderContexts']['any']:
+ ulib = clc['Name']
+ if clc['Optional']:
+ optional.append(ulib)
+ else:
+ required.append(ulib)
- return module_to_libname
+ required = remove_duplicates(required)
+ optional = remove_duplicates(optional)
+
+ # If the same library is both in optional and required, prefer required.
+ # This may happen for compatibility libraries, e.g. org.apache.http.legacy.
+ for lib in required:
+ if lib in optional:
+ optional.remove(lib)
+
+ return required, optional
def translate_libnames(modules, module_to_libname):
"""Translate module names into library names using the mapping."""
- if modules is None:
- modules = []
libnames = []
for name in modules:
@@ -346,10 +383,7 @@
# `optional_uses_libs`, `LOCAL_USES_LIBRARIES`,
# `LOCAL_OPTIONAL_LIBRARY_NAMES` all contain module names), while
# the manifest addresses libraries by their name.
- mod_to_lib = load_dexpreopt_configs(args.dexpreopt_configs)
- required = translate_libnames(args.uses_libraries, mod_to_lib)
- optional = translate_libnames(args.optional_uses_libraries,
- mod_to_lib)
+ required, optional = load_dexpreopt_configs(args)
# Check if the <uses-library> lists in the build system agree with
# those in the manifest. Raise an exception on mismatch, unless the
diff --git a/sdk/bootclasspath_fragment_sdk_test.go b/sdk/bootclasspath_fragment_sdk_test.go
index a60039a..93ad172 100644
--- a/sdk/bootclasspath_fragment_sdk_test.go
+++ b/sdk/bootclasspath_fragment_sdk_test.go
@@ -101,6 +101,9 @@
image_name: "art",
contents: ["mybootlib"],
apex_available: ["com.android.art"],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
apex_key {
@@ -235,6 +238,9 @@
// This should be automatically added to the sdk_snapshot as a java_sdk_libs module.
stub_libs: ["mycoreplatform"],
},
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_library {
@@ -453,6 +459,9 @@
contents: [
"myotherlib",
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_library {
@@ -482,6 +491,9 @@
module: "myotherbootclasspathfragment"
},
],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_sdk_library {
@@ -561,6 +573,9 @@
image_name: "art",
contents: ["mybootlib"],
apex_available: ["myapex"],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_library {
@@ -668,6 +683,7 @@
unsupported_packages: [
"my-unsupported-packages.txt",
],
+ split_packages: ["*"],
},
}
diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go
index e230d5c..1ec12c3 100644
--- a/sdk/sdk_test.go
+++ b/sdk/sdk_test.go
@@ -473,6 +473,9 @@
name: "mybootclasspathfragment",
apex_available: ["myapex"],
contents: ["mysdklibrary"],
+ hidden_api: {
+ split_packages: ["*"],
+ },
}
java_sdk_library {
diff --git a/ui/build/build.go b/ui/build/build.go
index aadf4af..ec42b70 100644
--- a/ui/build/build.go
+++ b/ui/build/build.go
@@ -266,6 +266,7 @@
}
if config.StartRBE() {
+ cleanupRBELogsDir(ctx, config)
startRBE(ctx, config)
defer DumpRBEMetrics(ctx, config, filepath.Join(config.LogsDir(), "rbe_metrics.pb"))
}
diff --git a/ui/build/config.go b/ui/build/config.go
index 0092ff1..5765f21 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -19,12 +19,14 @@
"encoding/json"
"fmt"
"io/ioutil"
+ "math/rand"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
+ "syscall"
"time"
"android/soong/shared"
@@ -42,6 +44,15 @@
envConfigFetchTimeout = 10 * time.Second
)
+var (
+ rbeRandPrefix int
+)
+
+func init() {
+ rand.Seed(time.Now().UnixNano())
+ rbeRandPrefix = rand.Intn(1000)
+}
+
type Config struct{ *configImpl }
type configImpl struct {
@@ -1144,34 +1155,25 @@
return true
}
-func (c *configImpl) rbeLogDir() string {
- for _, f := range []string{"RBE_log_dir", "FLAG_log_dir"} {
+func (c *configImpl) rbeProxyLogsDir() string {
+ for _, f := range []string{"RBE_proxy_log_dir", "FLAG_output_dir"} {
if v, ok := c.environ.Get(f); ok {
return v
}
}
- if c.Dist() {
- return c.LogsDir()
- }
- return c.OutDir()
+ buildTmpDir := shared.TempDirForOutDir(c.SoongOutDir())
+ return filepath.Join(buildTmpDir, "rbe")
}
-func (c *configImpl) rbeStatsOutputDir() string {
- for _, f := range []string{"RBE_output_dir", "FLAG_output_dir"} {
- if v, ok := c.environ.Get(f); ok {
- return v
+func (c *configImpl) shouldCleanupRBELogsDir() bool {
+ // Perform a log directory cleanup only when the log directory
+ // is auto created by the build rather than user-specified.
+ for _, f := range []string{"RBE_proxy_log_dir", "FLAG_output_dir"} {
+ if _, ok := c.environ.Get(f); ok {
+ return false
}
}
- return c.rbeLogDir()
-}
-
-func (c *configImpl) rbeLogPath() string {
- for _, f := range []string{"RBE_log_path", "FLAG_log_path"} {
- if v, ok := c.environ.Get(f); ok {
- return v
- }
- }
- return fmt.Sprintf("text://%v/reproxy_log.txt", c.rbeLogDir())
+ return true
}
func (c *configImpl) rbeExecRoot() string {
@@ -1223,19 +1225,21 @@
return "RBE_use_application_default_credentials", "true"
}
-func (c *configImpl) IsGooglerEnvironment() bool {
- cf := "ANDROID_BUILD_ENVIRONMENT_CONFIG"
- if v, ok := c.environ.Get(cf); ok {
- return v == "googler"
- }
- return false
-}
+func (c *configImpl) rbeSockAddr(dir string) (string, error) {
+ maxNameLen := len(syscall.RawSockaddrUnix{}.Path)
+ base := fmt.Sprintf("reproxy_%v.sock", rbeRandPrefix)
-func (c *configImpl) GoogleProdCredsExist() bool {
- if _, err := exec.Command("/usr/bin/prodcertstatus", "--simple_output", "--nocheck_loas").Output(); err != nil {
- return false
+ name := filepath.Join(dir, base)
+ if len(name) < maxNameLen {
+ return name, nil
}
- return true
+
+ name = filepath.Join("/tmp", base)
+ if len(name) < maxNameLen {
+ return name, nil
+ }
+
+ return "", fmt.Errorf("cannot generate a proxy socket address shorter than the limit of %v", maxNameLen)
}
func (c *configImpl) UseRemoteBuild() bool {
diff --git a/ui/build/rbe.go b/ui/build/rbe.go
index 78d37b4..3e558f7 100644
--- a/ui/build/rbe.go
+++ b/ui/build/rbe.go
@@ -16,12 +16,9 @@
import (
"fmt"
- "math/rand"
"os"
"path/filepath"
"runtime"
- "syscall"
- "time"
"android/soong/ui/metrics"
)
@@ -54,34 +51,16 @@
return cmdPath
}
-func sockAddr(dir string) (string, error) {
- maxNameLen := len(syscall.RawSockaddrUnix{}.Path)
- rand.Seed(time.Now().UnixNano())
- base := fmt.Sprintf("reproxy_%v.sock", rand.Intn(1000))
-
- name := filepath.Join(dir, base)
- if len(name) < maxNameLen {
- return name, nil
- }
-
- name = filepath.Join("/tmp", base)
- if len(name) < maxNameLen {
- return name, nil
- }
-
- return "", fmt.Errorf("cannot generate a proxy socket address shorter than the limit of %v", maxNameLen)
-}
-
func getRBEVars(ctx Context, config Config) map[string]string {
vars := map[string]string{
- "RBE_log_path": config.rbeLogPath(),
- "RBE_log_dir": config.rbeLogDir(),
+ "RBE_log_dir": config.rbeProxyLogsDir(),
"RBE_re_proxy": config.rbeReproxy(),
"RBE_exec_root": config.rbeExecRoot(),
- "RBE_output_dir": config.rbeStatsOutputDir(),
+ "RBE_output_dir": config.rbeProxyLogsDir(),
+ "RBE_proxy_log_dir": config.rbeProxyLogsDir(),
}
if config.StartRBE() {
- name, err := sockAddr(absPath(ctx, config.TempDir()))
+ name, err := config.rbeSockAddr(absPath(ctx, config.TempDir()))
if err != nil {
ctx.Fatalf("Error retrieving socket address: %v", err)
return nil
@@ -100,6 +79,17 @@
return vars
}
+func cleanupRBELogsDir(ctx Context, config Config) {
+ if !config.shouldCleanupRBELogsDir() {
+ return
+ }
+
+ rbeTmpDir := config.rbeProxyLogsDir()
+ if err := os.RemoveAll(rbeTmpDir); err != nil {
+ fmt.Fprintln(ctx.Writer, "\033[33mUnable to remove RBE log directory: ", err, "\033[0m")
+ }
+}
+
func startRBE(ctx Context, config Config) {
ctx.BeginTrace(metrics.RunSetupTool, "rbe_bootstrap")
defer ctx.EndTrace()
@@ -110,6 +100,11 @@
if n := ulimitOrFatal(ctx, config, "-n"); n < rbeLeastNFiles {
ctx.Fatalf("max open files is insufficient: %d; want >= %d.\n", n, rbeLeastNFiles)
}
+ if _, err := os.Stat(config.rbeProxyLogsDir()); os.IsNotExist(err) {
+ if err := os.MkdirAll(config.rbeProxyLogsDir(), 0744); err != nil {
+ ctx.Fatalf("Unable to create logs dir (%v) for RBE: %v", config.rbeProxyLogsDir, err)
+ }
+ }
cmd := Command(ctx, config, "startRBE bootstrap", rbeCommand(ctx, config, bootstrapCmd))
@@ -119,7 +114,6 @@
}
func stopRBE(ctx Context, config Config) {
- defer checkProdCreds(ctx, config)
cmd := Command(ctx, config, "stopRBE bootstrap", rbeCommand(ctx, config, bootstrapCmd), "-shutdown")
output, err := cmd.CombinedOutput()
if err != nil {
@@ -132,15 +126,6 @@
}
}
-func checkProdCreds(ctx Context, config Config) {
- if !config.IsGooglerEnvironment() || config.GoogleProdCredsExist() {
- return
- }
- fmt.Fprintln(ctx.Writer, "")
- fmt.Fprintln(ctx.Writer, "\033[33mWARNING: Missing LOAS credentials, please run `gcert`. This will result in failing RBE builds in the future, see go/build-fast#authentication.\033[0m")
- fmt.Fprintln(ctx.Writer, "")
-}
-
// DumpRBEMetrics creates a metrics protobuf file containing RBE related metrics.
// The protobuf file is created if RBE is enabled and the proxy service has
// started. The proxy service is shutdown in order to dump the RBE metrics to the
@@ -161,7 +146,7 @@
return
}
- outputDir := config.rbeStatsOutputDir()
+ outputDir := config.rbeProxyLogsDir()
if outputDir == "" {
ctx.Fatal("RBE output dir variable not defined. Aborting metrics dumping.")
}
diff --git a/ui/build/rbe_test.go b/ui/build/rbe_test.go
index 8ff96bc..266f76b 100644
--- a/ui/build/rbe_test.go
+++ b/ui/build/rbe_test.go
@@ -56,7 +56,8 @@
env := Environment(tt.env)
env.Set("OUT_DIR", tmpDir)
env.Set("RBE_DIR", tmpDir)
- env.Set("RBE_output_dir", t.TempDir())
+ env.Set("RBE_output_dir", tmpDir)
+ env.Set("RBE_proxy_log_dir", tmpDir)
config := Config{&configImpl{
environ: &env,
}}
diff --git a/ui/terminal/simple_status.go b/ui/terminal/simple_status.go
index 3157813..cef3b5d 100644
--- a/ui/terminal/simple_status.go
+++ b/ui/terminal/simple_status.go
@@ -46,7 +46,11 @@
func (s *simpleStatusOutput) Message(level status.MsgLevel, message string) {
if level >= s.outputLevel {
- fmt.Fprintln(s.writer, s.formatter.message(level, message))
+ output := s.formatter.message(level, message)
+ if !s.keepANSI {
+ output = string(stripAnsiEscapes([]byte(output)))
+ }
+ fmt.Fprintln(s.writer, output)
}
}
diff --git a/ui/terminal/status_test.go b/ui/terminal/status_test.go
index 810e31d..b9057d2 100644
--- a/ui/terminal/status_test.go
+++ b/ui/terminal/status_test.go
@@ -81,9 +81,9 @@
},
{
name: "action with output with ansi codes",
- calls: actionWithOuptutWithAnsiCodes,
- smart: "\r\x1b[1m[ 0% 0/1] action1\x1b[0m\x1b[K\r\x1b[1m[100% 1/1] action1\x1b[0m\x1b[K\n\x1b[31mcolor\x1b[0m\n",
- simple: "[100% 1/1] action1\ncolor\n",
+ calls: actionWithOutputWithAnsiCodes,
+ smart: "\r\x1b[1m[ 0% 0/1] action1\x1b[0m\x1b[K\r\x1b[1m[100% 1/1] action1\x1b[0m\x1b[K\n\x1b[31mcolor\x1b[0m\n\x1b[31mcolor message\x1b[0m\n",
+ simple: "[100% 1/1] action1\ncolor\ncolor message\n",
},
}
@@ -257,12 +257,14 @@
runner.finishAction(result1)
}
-func actionWithOuptutWithAnsiCodes(stat status.StatusOutput) {
+func actionWithOutputWithAnsiCodes(stat status.StatusOutput) {
result1WithOutputWithAnsiCodes := status.ActionResult{Action: action1, Output: "\x1b[31mcolor\x1b[0m"}
runner := newRunner(stat, 1)
runner.startAction(action1)
runner.finishAction(result1WithOutputWithAnsiCodes)
+
+ stat.Message(status.PrintLvl, "\x1b[31mcolor message\x1b[0m")
}
func TestSmartStatusOutputWidthChange(t *testing.T) {