diff options
117 files changed, 4075 insertions, 2828 deletions
diff --git a/android/Android.bp b/android/Android.bp index cbd345945..f58a47296 100644 --- a/android/Android.bp +++ b/android/Android.bp @@ -88,6 +88,7 @@ bootstrap_go_package { "test_asserts.go", "test_suites.go", "testing.go", + "updatable_modules.go", "util.go", "variable.go", "visibility.go", diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go index ab71d995c..b668042b9 100644 --- a/android/allowlists/allowlists.go +++ b/android/allowlists/allowlists.go @@ -132,6 +132,7 @@ var ( "external/libevent": Bp2BuildDefaultTrueRecursively, "external/libgav1": Bp2BuildDefaultTrueRecursively, "external/libhevc": Bp2BuildDefaultTrueRecursively, + "external/libjpeg-turbo": Bp2BuildDefaultTrueRecursively, "external/libmpeg2": Bp2BuildDefaultTrueRecursively, "external/libpng": Bp2BuildDefaultTrueRecursively, "external/lz4/lib": Bp2BuildDefaultTrue, @@ -145,6 +146,7 @@ var ( "external/scudo": Bp2BuildDefaultTrueRecursively, "external/selinux/libselinux": Bp2BuildDefaultTrueRecursively, "external/selinux/libsepol": Bp2BuildDefaultTrueRecursively, + "external/toybox": Bp2BuildDefaultTrueRecursively, "external/zlib": Bp2BuildDefaultTrueRecursively, "external/zopfli": Bp2BuildDefaultTrueRecursively, "external/zstd": Bp2BuildDefaultTrueRecursively, @@ -217,6 +219,7 @@ var ( "system/unwinding/libunwindstack": Bp2BuildDefaultTrueRecursively, "tools/apksig": Bp2BuildDefaultTrue, "tools/platform-compat/java/android/compat": Bp2BuildDefaultTrueRecursively, + "tools/tradefederation/prebuilts/filegroups": Bp2BuildDefaultTrueRecursively, } Bp2buildKeepExistingBuildFile = map[string]bool{ @@ -262,6 +265,7 @@ var ( "prebuilts/gcc":/* recursive = */ true, "prebuilts/build-tools":/* recursive = */ true, "prebuilts/jdk/jdk11":/* recursive = */ false, + "prebuilts/misc":/* recursive = */ false, // not recursive because we need bp2build converted build files in prebuilts/misc/common/asm "prebuilts/sdk":/* recursive = */ false, "prebuilts/sdk/current/extras/app-toolkit":/* recursive = */ false, "prebuilts/sdk/current/support":/* recursive = */ false, @@ -332,6 +336,13 @@ var ( "server_configurable_flags", "tensorflow_headers", + // fastboot + "bootimg_headers", + "fastboot", + "libfastboot", + "liblp", + "libstorage_literals_headers", + //external/avb "avbtool", "libavb", @@ -366,6 +377,7 @@ var ( } Bp2buildModuleTypeAlwaysConvertList = []string{ + "linker_config", "java_import", "java_import_host", } @@ -376,15 +388,16 @@ var ( "gen-kotlin-build-file.py", // TODO(b/198619163) module has same name as source "libgtest_ndk_c++", "libgtest_main_ndk_c++", // TODO(b/201816222): Requires sdk_version support. "linkerconfig", "mdnsd", // TODO(b/202876379): has arch-variant static_executable - "linker", // TODO(b/228316882): cc_binary uses link_crt - "libdebuggerd", // TODO(b/228314770): support product variable-specific header_libs - "versioner", // TODO(b/228313961): depends on prebuilt shared library libclang-cpp_host as a shared library, which does not supply expected providers for a shared library - "libspeexresampler", // TODO(b/231995978): Filter out unknown cflags - "libjpeg", "libvpx", // TODO(b/233948256): Convert .asm files + "linker", // TODO(b/228316882): cc_binary uses link_crt + "libdebuggerd", // TODO(b/228314770): support product variable-specific header_libs + "versioner", // TODO(b/228313961): depends on prebuilt shared library libclang-cpp_host as a shared library, which does not supply expected providers for a shared library + "libspeexresampler", // TODO(b/231995978): Filter out unknown cflags + "libvpx", // TODO(b/240756936): Arm neon variant not supported "art_libartbase_headers", // TODO(b/236268577): Header libraries do not support export_shared_libs_headers "apexer_test", // Requires aapt2 "apexer_test_host_tools", "host_apex_verifier", + "tjbench", // TODO(b/240563612): Stem property // java bugs "libbase_ndk", // TODO(b/186826477): fails to link libctscamera2_jni for device (required for CtsCameraTestCases) @@ -440,7 +453,6 @@ var ( "art-script", // depends on unconverted modules: dalvikvm, dex2oat "bin2c_fastdeployagent", // depends on unconverted modules: deployagent "com.android.runtime", // depends on unconverted modules: bionic-linker-config, linkerconfig - "conv_linker_config", // depends on unconverted modules: linker_config_proto "currysrc", // depends on unconverted modules: currysrc_org.eclipse, guavalib, jopt-simple-4.9 "dex2oat-script", // depends on unconverted modules: dex2oat "generated_android_icu4j_resources", // depends on unconverted modules: android_icu4j_srcgen_binary, soong_zip @@ -481,6 +493,9 @@ var ( // b/215723302; awaiting tz{data,_version} to then rename targets conflicting with srcs "tzdata", "tz_version", + + // '//bionic/libc:libc_bp2build_cc_library_static' is duplicated in the 'deps' attribute of rule + "toybox-static", } Bp2buildCcLibraryStaticOnlyList = []string{} @@ -526,5 +541,20 @@ var ( "simpleperf_ndk", "toybox-static", "zlib_bench", + + // java_import[_host] issues + // tradefed prebuilts depend on libprotobuf + "prebuilt_tradefed", + "prebuilt_tradefed-test-framework", + // handcrafted BUILD.bazel files in //prebuilts/... + "prebuilt_r8lib-prebuilt", + "prebuilt_sdk-core-lambda-stubs", + "prebuilt_android-support-collections-nodeps", + "prebuilt_android-arch-core-common-nodeps", + "prebuilt_android-arch-lifecycle-common-java8-nodeps", + "prebuilt_android-arch-lifecycle-common-nodeps", + "prebuilt_android-support-annotations-nodeps", + "prebuilt_android-arch-paging-common-nodeps", + "prebuilt_android-arch-room-common-nodeps", } ) diff --git a/android/androidmk.go b/android/androidmk.go index d6fe06d93..006e43def 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -604,10 +604,6 @@ func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint } } - if len(base.noticeFiles) > 0 { - a.AddStrings("LOCAL_NOTICE_FILE", strings.Join(base.noticeFiles.Strings(), " ")) - } - if host { makeOs := base.Os().String() if base.Os() == Linux || base.Os() == LinuxBionic || base.Os() == LinuxMusl { diff --git a/android/bazel.go b/android/bazel.go index 40f2917db..183a2f324 100644 --- a/android/bazel.go +++ b/android/bazel.go @@ -35,6 +35,20 @@ const ( Bp2BuildTopLevel = "." ) +type BazelConversionStatus struct { + // Information about _all_ bp2build targets generated by this module. Multiple targets are + // supported as Soong handles some things within a single target that we may choose to split into + // multiple targets, e.g. renderscript, protos, yacc within a cc module. + Bp2buildInfo []bp2buildInfo `blueprint:"mutated"` + + // UnconvertedBp2buildDep stores the module names of direct dependency that were not converted to + // Bazel + UnconvertedDeps []string `blueprint:"mutated"` + + // MissingBp2buildDep stores the module names of direct dependency that were not found + MissingDeps []string `blueprint:"mutated"` +} + type bazelModuleProperties struct { // The label of the Bazel target replacing this Soong module. When run in conversion mode, this // will import the handcrafted build target into the autogenerated file. Note: this may result in diff --git a/android/bazel_handler.go b/android/bazel_handler.go index 5e8a1839e..5804a46ed 100644 --- a/android/bazel_handler.go +++ b/android/bazel_handler.go @@ -91,6 +91,10 @@ type configKey struct { osType OsType } +func (c configKey) String() string { + return fmt.Sprintf("%s::%s", c.arch, c.osType) +} + // Map key to describe bazel cquery requests. type cqueryKey struct { label string @@ -98,6 +102,11 @@ type cqueryKey struct { configKey configKey } +func (c cqueryKey) String() string { + return fmt.Sprintf("cquery(%s,%s,%s)", c.label, c.requestType.Name(), c.configKey) + +} + // BazelContext is a context object useful for interacting with Bazel during // the course of a build. Use of Bazel to evaluate part of the build graph // is referred to as a "mixed build". (Some modules are managed by Soong, @@ -123,6 +132,9 @@ type BazelContext interface { // TODO(b/232976601): Remove. GetPythonBinary(label string, cfgKey configKey) (string, error) + // Returns the results of the GetApexInfo query (including output files) + GetApexInfo(label string, cfgkey configKey) (cquery.ApexCqueryInfo, error) + // ** end Cquery Results Retrieval Functions // Issues commands to Bazel to receive results for all cquery requests @@ -186,6 +198,7 @@ type MockBazelContext struct { LabelToOutputFiles map[string][]string LabelToCcInfo map[string]cquery.CcInfo LabelToPythonBinary map[string]string + LabelToApexInfo map[string]cquery.ApexCqueryInfo } func (m MockBazelContext) QueueBazelRequest(_ string, _ cqueryRequest, _ configKey) { @@ -207,6 +220,10 @@ func (m MockBazelContext) GetPythonBinary(label string, _ configKey) (string, er return result, nil } +func (n MockBazelContext) GetApexInfo(_ string, _ configKey) (cquery.ApexCqueryInfo, error) { + panic("unimplemented") +} + func (m MockBazelContext) InvokeBazel(_ Config) error { panic("unimplemented") } @@ -261,6 +278,14 @@ func (bazelCtx *bazelContext) GetPythonBinary(label string, cfgKey configKey) (s return "", fmt.Errorf("no bazel response found for %v", key) } +func (bazelCtx *bazelContext) GetApexInfo(label string, cfgKey configKey) (cquery.ApexCqueryInfo, error) { + key := cqueryKey{label, cquery.GetApexInfo, cfgKey} + if rawString, ok := bazelCtx.results[key]; ok { + return cquery.GetApexInfo.ParseResult(strings.TrimSpace(rawString)), nil + } + return cquery.ApexCqueryInfo{}, fmt.Errorf("no bazel response found for %v", key) +} + func (n noopBazelContext) QueueBazelRequest(_ string, _ cqueryRequest, _ configKey) { panic("unimplemented") } @@ -277,6 +302,10 @@ func (n noopBazelContext) GetPythonBinary(_ string, _ configKey) (string, error) panic("unimplemented") } +func (n noopBazelContext) GetApexInfo(_ string, _ configKey) (cquery.ApexCqueryInfo, error) { + panic("unimplemented") +} + func (n noopBazelContext) InvokeBazel(_ Config) error { panic("unimplemented") } @@ -401,11 +430,9 @@ func (r *builtinBazelRunner) issueBazelCommand(paths *bazelPaths, runName bazel. cmdFlags := []string{ "--output_base=" + absolutePath(paths.outputBase), command.command, - } - cmdFlags = append(cmdFlags, command.expression) - cmdFlags = append(cmdFlags, + command.expression, // TODO(asmundak): is it needed in every build? - "--profile="+shared.BazelMetricsFilename(paths, runName), + "--profile=" + shared.BazelMetricsFilename(paths, runName), // Set default platforms to canonicalized values for mixed builds requests. // If these are set in the bazelrc, they will have values that are @@ -426,21 +453,23 @@ func (r *builtinBazelRunner) issueBazelCommand(paths *bazelPaths, runName bazel. // Suppress noise "--ui_event_filters=-INFO", - "--noshow_progress") + "--noshow_progress"} cmdFlags = append(cmdFlags, extraFlags...) bazelCmd := exec.Command(paths.bazelPath, cmdFlags...) bazelCmd.Dir = absolutePath(paths.syntheticWorkspaceDir()) - bazelCmd.Env = append(os.Environ(), - "HOME="+paths.homeDir, + extraEnv := []string{ + "HOME=" + paths.homeDir, pwdPrefix(), - "BUILD_DIR="+absolutePath(paths.soongOutDir), + "BUILD_DIR=" + absolutePath(paths.soongOutDir), // Make OUT_DIR absolute here so tools/bazel.sh uses the correct // OUT_DIR at <root>/out, instead of <root>/out/soong/workspace/out. - "OUT_DIR="+absolutePath(paths.outDir()), + "OUT_DIR=" + absolutePath(paths.outDir()), // Disables local host detection of gcc; toolchain information is defined // explicitly in BUILD files. - "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1") + "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1", + } + bazelCmd.Env = append(os.Environ(), extraEnv...) stderr := &bytes.Buffer{} bazelCmd.Stderr = stderr @@ -651,6 +680,15 @@ def get_arch(target): fail("expected platform name of the form 'android_<arch>' or 'linux_<arch>', but was " + str(platforms)) return "UNKNOWN" +def json_for_file(key, file): + return '"' + key + '":"' + file.path + '"' + +def json_for_files(key, files): + return '"' + key + '":[' + ",".join(['"' + f.path + '"' for f in files]) + ']' + +def json_for_labels(key, ll): + return '"' + key + '":[' + ",".join(['"' + str(x) + '"' for x in ll]) + ']' + def format(target): id_string = str(target.label) + "|" + get_arch(target) @@ -728,7 +766,7 @@ func (context *bazelContext) InvokeBazel(config Config) error { cqueryOutput, cqueryErr, err := context.issueBazelCommand(context.paths, bazel.CqueryBuildRootRunName, cqueryCmd, "--output=starlark", "--starlark:file="+absolutePath(cqueryFileRelpath)) if err != nil { - err = ioutil.WriteFile(filepath.Join(soongInjectionPath, "cquery.out"), []byte(cqueryOutput), 0666) + _ = ioutil.WriteFile(filepath.Join(soongInjectionPath, "cquery.out"), []byte(cqueryOutput), 0666) } if err != nil { return err diff --git a/android/bazel_paths.go b/android/bazel_paths.go index 1d0a6d541..c030aa864 100644 --- a/android/bazel_paths.go +++ b/android/bazel_paths.go @@ -32,14 +32,14 @@ import ( // There is often a similar method for Bazel as there is for Soong path handling and should be used // in similar circumstances // -// Bazel Soong -// -// BazelLabelForModuleSrc PathForModuleSrc -// BazelLabelForModuleSrcExcludes PathForModuleSrcExcludes -// BazelLabelForModuleDeps n/a -// tbd PathForSource -// tbd ExistentPathsForSources -// PathForBazelOut PathForModuleOut +// Bazel Soong +// ============================================================== +// BazelLabelForModuleSrc PathForModuleSrc +// BazelLabelForModuleSrcExcludes PathForModuleSrcExcludes +// BazelLabelForModuleDeps n/a +// tbd PathForSource +// tbd ExistentPathsForSources +// PathForBazelOut PathForModuleOut // // Use cases: // * Module contains a property (often tagged `android:"path"`) that expects paths *relative to the @@ -68,7 +68,7 @@ import ( // cannot be resolved,the function will panic. This is often due to the dependency not being added // via an AddDependency* method. -// A minimal context interface to check if a module should be converted by bp2build, +// BazelConversionContext is a minimal context interface to check if a module should be converted by bp2build, // with functions containing information to match against allowlists and denylists. // If a module is deemed to be convertible by bp2build, then it should rely on a // BazelConversionPathContext for more functions for dep/path features. diff --git a/android/config.go b/android/config.go index a5337d07d..84c17dee3 100644 --- a/android/config.go +++ b/android/config.go @@ -18,6 +18,7 @@ package android // product variables necessary for soong_build's operation. import ( + "bytes" "encoding/json" "errors" "fmt" @@ -305,6 +306,9 @@ func saveToBazelConfigFile(config *productVariables, outDir string) error { if err != nil { return fmt.Errorf("cannot marshal config data: %s", err.Error()) } + // The backslashes need to be escaped because this text is going to be put + // inside a Starlark string literal. + configJson = bytes.ReplaceAll(configJson, []byte("\\"), []byte("\\\\")) bzl := []string{ bazel.GeneratedBazelFileWarning, @@ -317,11 +321,11 @@ product_var_constraints = _product_var_constraints arch_variant_product_var_constraints = _arch_variant_product_var_constraints `, } - err = ioutil.WriteFile(filepath.Join(dir, "product_variables.bzl"), []byte(strings.Join(bzl, "\n")), 0644) + err = os.WriteFile(filepath.Join(dir, "product_variables.bzl"), []byte(strings.Join(bzl, "\n")), 0644) if err != nil { return fmt.Errorf("Could not write .bzl config file %s", err) } - err = ioutil.WriteFile(filepath.Join(dir, "BUILD"), []byte(bazel.GeneratedBazelFileWarning), 0644) + err = os.WriteFile(filepath.Join(dir, "BUILD"), []byte(bazel.GeneratedBazelFileWarning), 0644) if err != nil { return fmt.Errorf("Could not write BUILD config file %s", err) } @@ -761,6 +765,10 @@ func (c *config) PlatformSdkVersion() ApiLevel { return uncheckedFinalApiLevel(*c.productVariables.Platform_sdk_version) } +func (c *config) PlatformSdkFinal() bool { + return Bool(c.productVariables.Platform_sdk_final) +} + func (c *config) PlatformSdkCodename() string { return String(c.productVariables.Platform_sdk_codename) } @@ -1446,8 +1454,8 @@ func (c *config) ForceApexSymlinkOptimization() bool { return Bool(c.productVariables.ForceApexSymlinkOptimization) } -func (c *config) CompressedApex() bool { - return Bool(c.productVariables.CompressedApex) +func (c *config) ApexCompressionEnabled() bool { + return Bool(c.productVariables.CompressedApex) && !c.UnbundledBuildApps() } func (c *config) EnforceSystemCertificate() bool { diff --git a/android/license_metadata.go b/android/license_metadata.go index f2ab0a44c..4ee5bf7ae 100644 --- a/android/license_metadata.go +++ b/android/license_metadata.go @@ -15,7 +15,6 @@ package android import ( - "fmt" "sort" "strings" @@ -67,6 +66,11 @@ func buildLicenseMetadata(ctx ModuleContext, licenseMetadataFile WritablePath) { return } + // Defaults add properties and dependencies that get processed on their own. + if ctx.OtherModuleDependencyTag(dep) == DefaultsDepTag { + return + } + if ctx.OtherModuleHasProvider(dep, LicenseMetadataProvider) { info := ctx.OtherModuleProvider(dep, LicenseMetadataProvider).(*LicenseMetadataInfo) allDepMetadataFiles = append(allDepMetadataFiles, info.LicenseMetadataPath) @@ -139,8 +143,6 @@ func buildLicenseMetadata(ctx ModuleContext, licenseMetadataFile WritablePath) { if len(outputFiles) > 0 { args = append(args, JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(outputFiles.Strings()), "-t ")) - } else { - args = append(args, fmt.Sprintf("-t //%s:%s", ctx.ModuleDir(), ctx.ModuleName())) } // Installed files diff --git a/android/metrics.go b/android/metrics.go index 1580f82b1..ecda0266d 100644 --- a/android/metrics.go +++ b/android/metrics.go @@ -32,8 +32,13 @@ type SoongMetrics struct { Variants int } -func ReadSoongMetrics(config Config) SoongMetrics { - return config.Get(soongMetricsOnceKey).(SoongMetrics) +func readSoongMetrics(config Config) (SoongMetrics, bool) { + soongMetrics, ok := config.Peek(soongMetricsOnceKey) + if ok { + return soongMetrics.(SoongMetrics), true + } else { + return SoongMetrics{}, false + } } func init() { @@ -60,9 +65,11 @@ func (soongMetricsSingleton) GenerateBuildActions(ctx SingletonContext) { func collectMetrics(config Config, eventHandler metrics.EventHandler) *soong_metrics_proto.SoongBuildMetrics { metrics := &soong_metrics_proto.SoongBuildMetrics{} - soongMetrics := ReadSoongMetrics(config) - metrics.Modules = proto.Uint32(uint32(soongMetrics.Modules)) - metrics.Variants = proto.Uint32(uint32(soongMetrics.Variants)) + soongMetrics, ok := readSoongMetrics(config) + if ok { + metrics.Modules = proto.Uint32(uint32(soongMetrics.Modules)) + metrics.Variants = proto.Uint32(uint32(soongMetrics.Variants)) + } memStats := runtime.MemStats{} runtime.ReadMemStats(&memStats) diff --git a/android/module.go b/android/module.go index 7173c0d3c..450dba997 100644 --- a/android/module.go +++ b/android/module.go @@ -35,10 +35,6 @@ import ( var ( DeviceSharedLibrary = "shared_library" DeviceStaticLibrary = "static_library" - DeviceExecutable = "executable" - HostSharedLibrary = "host_shared_library" - HostStaticLibrary = "host_static_library" - HostExecutable = "host_executable" ) type BuildParams struct { @@ -515,7 +511,6 @@ type Module interface { ExportedToMake() bool InitRc() Paths VintfFragments() Paths - NoticeFiles() Paths EffectiveLicenseFiles() Paths AddProperties(props ...interface{}) @@ -831,9 +826,6 @@ type commonProperties struct { // names of other modules to install on target if this module is installed Target_required []string `android:"arch_variant"` - // relative path to a file to include in the list of notices for the device - Notice *string `android:"path"` - // The OsType of artifacts that this module variant is responsible for creating. // // Set by osMutator @@ -913,17 +905,8 @@ type commonProperties struct { // constants in image.go, but can also be set to a custom value by individual module types. ImageVariation string `blueprint:"mutated"` - // Information about _all_ bp2build targets generated by this module. Multiple targets are - // supported as Soong handles some things within a single target that we may choose to split into - // multiple targets, e.g. renderscript, protos, yacc within a cc module. - Bp2buildInfo []bp2buildInfo `blueprint:"mutated"` - - // UnconvertedBp2buildDep stores the module names of direct dependency that were not converted to - // Bazel - UnconvertedBp2buildDeps []string `blueprint:"mutated"` - - // MissingBp2buildDep stores the module names of direct dependency that were not found - MissingBp2buildDeps []string `blueprint:"mutated"` + // Bazel conversion status + BazelConversionStatus BazelConversionStatus `blueprint:"mutated"` } // CommonAttributes represents the common Bazel attributes from which properties @@ -993,8 +976,8 @@ func (t TaggedDistFiles) merge(other TaggedDistFiles) TaggedDistFiles { } func MakeDefaultDistFiles(paths ...Path) TaggedDistFiles { - for _, path := range paths { - if path == nil { + for _, p := range paths { + if p == nil { panic("The path to a dist file cannot be nil.") } } @@ -1018,7 +1001,6 @@ const ( MultilibFirst Multilib = "first" MultilibCommon Multilib = "common" MultilibCommonFirst Multilib = "common_first" - MultilibDefault Multilib = "" ) type HostOrDeviceSupported int @@ -1162,23 +1144,17 @@ func InitCommonOSAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupport func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutatorContext, enabledPropertyOverrides bazel.BoolAttribute) constraintAttributes { + + mod := ctx.Module().base() // Assert passed-in attributes include Name - name := attrs.Name - if len(name) == 0 { + if len(attrs.Name) == 0 { ctx.ModuleErrorf("CommonAttributes in fillCommonBp2BuildModuleAttrs expects a `.Name`!") } - mod := ctx.Module().base() - props := &mod.commonProperties - depsToLabelList := func(deps []string) bazel.LabelListAttribute { return bazel.MakeLabelListAttribute(BazelLabelForModuleDeps(ctx, deps)) } - data := &attrs.Data - - archVariantProps := mod.GetArchVariantProperties(ctx, &commonProperties{}) - var enabledProperty bazel.BoolAttribute onlyAndroid := false @@ -1206,11 +1182,11 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator neitherHostNorDevice = true } - for _, os := range OsTypeList() { - if os.Class == Host { - osSupport[os.Name] = moduleSupportsHost - } else if os.Class == Device { - osSupport[os.Name] = moduleSupportsDevice + for _, osType := range OsTypeList() { + if osType.Class == Host { + osSupport[osType.Name] = moduleSupportsHost + } else if osType.Class == Device { + osSupport[osType.Name] = moduleSupportsDevice } } } @@ -1218,25 +1194,26 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator 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 { + } else if mod.commonProperties.Enabled != nil { + enabledProperty.SetValue(mod.commonProperties.Enabled) + if !*mod.commonProperties.Enabled { + for oss, enabled := range osSupport { + if val := enabledProperty.SelectValue(bazel.OsConfigurationAxis, oss); enabled && val != nil && *val { // if this should be disabled by default, clear out any enabling we've done - enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, os, nil) + enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, oss, nil) } } } } - required := depsToLabelList(props.Required) + required := depsToLabelList(mod.commonProperties.Required) + archVariantProps := mod.GetArchVariantProperties(ctx, &commonProperties{}) for axis, configToProps := range archVariantProps { for config, _props := range configToProps { if archProps, ok := _props.(*commonProperties); ok { // TODO(b/234748998) Remove this requiredFiltered workaround when aapt2 converts successfully requiredFiltered := archProps.Required - if name == "apexer" { + if attrs.Name == "apexer" { requiredFiltered = make([]string, 0, len(archProps.Required)) for _, req := range archProps.Required { if req != "aapt2" && req != "apexer" { @@ -1291,7 +1268,7 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator }) platformEnabledAttribute, err := enabledProperty.ToLabelListAttribute( - bazel.LabelList{[]bazel.Label{bazel.Label{Label: "@platforms//:incompatible"}}, nil}, + bazel.LabelList{[]bazel.Label{{Label: "@platforms//:incompatible"}}, nil}, bazel.LabelList{[]bazel.Label{}, nil}) if err != nil { ctx.ModuleErrorf("Error processing platform enabled attribute: %s", err) @@ -1304,15 +1281,13 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator platformEnabledAttribute.Add(&l) } - data.Append(required) + attrs.Data.Append(required) - constraints := constraintAttributes{} moduleEnableConstraints := bazel.LabelListAttribute{} moduleEnableConstraints.Append(platformEnabledAttribute) moduleEnableConstraints.Append(productConfigEnabledAttribute) - constraints.Target_compatible_with = moduleEnableConstraints - return constraints + return constraintAttributes{Target_compatible_with: moduleEnableConstraints} } // Check product variables for `enabled: true` flag override. @@ -1423,7 +1398,6 @@ type ModuleBase struct { checkbuildFiles Paths packagingSpecs []PackagingSpec packagingSpecsDepSet *packagingSpecsDepSet - noticeFiles Paths // katiInstalls tracks the install rules that were created by Soong but are being exported // to Make to convert to ninja rules so that Make can add additional dependencies. katiInstalls katiInstalls @@ -1494,40 +1468,40 @@ func (b bp2buildInfo) BazelAttributes() []interface{} { } func (m *ModuleBase) addBp2buildInfo(info bp2buildInfo) { - m.commonProperties.Bp2buildInfo = append(m.commonProperties.Bp2buildInfo, info) + m.commonProperties.BazelConversionStatus.Bp2buildInfo = append(m.commonProperties.BazelConversionStatus.Bp2buildInfo, info) } // IsConvertedByBp2build returns whether this module was converted via bp2build. func (m *ModuleBase) IsConvertedByBp2build() bool { - return len(m.commonProperties.Bp2buildInfo) > 0 + return len(m.commonProperties.BazelConversionStatus.Bp2buildInfo) > 0 } // Bp2buildTargets returns the Bazel targets bp2build generated for this module. func (m *ModuleBase) Bp2buildTargets() []bp2buildInfo { - return m.commonProperties.Bp2buildInfo + return m.commonProperties.BazelConversionStatus.Bp2buildInfo } // AddUnconvertedBp2buildDep stores module name of a dependency that was not converted to Bazel. func (b *baseModuleContext) AddUnconvertedBp2buildDep(dep string) { - unconvertedDeps := &b.Module().base().commonProperties.UnconvertedBp2buildDeps + unconvertedDeps := &b.Module().base().commonProperties.BazelConversionStatus.UnconvertedDeps *unconvertedDeps = append(*unconvertedDeps, dep) } // AddMissingBp2buildDep stores module name of a dependency that was not found in a Android.bp file. func (b *baseModuleContext) AddMissingBp2buildDep(dep string) { - missingDeps := &b.Module().base().commonProperties.MissingBp2buildDeps + missingDeps := &b.Module().base().commonProperties.BazelConversionStatus.MissingDeps *missingDeps = append(*missingDeps, dep) } // GetUnconvertedBp2buildDeps returns the list of module names of this module's direct dependencies that // were not converted to Bazel. func (m *ModuleBase) GetUnconvertedBp2buildDeps() []string { - return FirstUniqueStrings(m.commonProperties.UnconvertedBp2buildDeps) + return FirstUniqueStrings(m.commonProperties.BazelConversionStatus.UnconvertedDeps) } // GetMissingBp2buildDeps eturns the list of module names that were not found in Android.bp files. func (m *ModuleBase) GetMissingBp2buildDeps() []string { - return FirstUniqueStrings(m.commonProperties.MissingBp2buildDeps) + return FirstUniqueStrings(m.commonProperties.BazelConversionStatus.MissingDeps) } func (m *ModuleBase) AddJSONData(d *map[string]interface{}) { @@ -1656,7 +1630,7 @@ func (m *ModuleBase) BuildParamsForTests() []BuildParams { // transformSourceToObj, and should only affects unit tests. vars := m.VariablesForTests() buildParams := append([]BuildParams(nil), m.buildParams...) - for i, _ := range buildParams { + for i := range buildParams { newArgs := make(map[string]string) for k, v := range buildParams[i].Args { newArgs[k] = v @@ -2054,10 +2028,6 @@ func (m *ModuleBase) Owner() string { return String(m.commonProperties.Owner) } -func (m *ModuleBase) NoticeFiles() Paths { - return m.noticeFiles -} - func (m *ModuleBase) setImageVariation(variant string) { m.commonProperties.ImageVariation = variant } @@ -2305,7 +2275,7 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) // Some common property checks for properties that will be used later in androidmk.go checkDistProperties(ctx, "dist", &m.distProperties.Dist) - for i, _ := range m.distProperties.Dists { + for i := range m.distProperties.Dists { checkDistProperties(ctx, fmt.Sprintf("dists[%d]", i), &m.distProperties.Dists[i]) } @@ -2317,19 +2287,6 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) } }) - m.noticeFiles = make([]Path, 0) - optPath := OptionalPath{} - notice := proptools.StringDefault(m.commonProperties.Notice, "") - if module := SrcIsModule(notice); module != "" { - optPath = ctx.ExpandOptionalSource(¬ice, "notice") - } else if notice != "" { - noticePath := filepath.Join(ctx.ModuleDir(), notice) - optPath = ExistentPathForSource(ctx, noticePath) - } - if optPath.Valid() { - m.noticeFiles = append(m.noticeFiles, optPath.Path()) - } - licensesPropertyFlattener(ctx) if ctx.Failed() { return @@ -3496,14 +3453,6 @@ func sourceOrOutputDepTag(moduleName, tag string) blueprint.DependencyTag { return sourceOrOutputDependencyTag{moduleName: moduleName, tag: tag} } -// IsSourceDepTag returns true if the supplied blueprint.DependencyTag is one that was used to add -// dependencies by either ExtractSourceDeps, ExtractSourcesDeps or automatically for properties -// tagged with `android:"path"`. -func IsSourceDepTag(depTag blueprint.DependencyTag) bool { - _, ok := depTag.(sourceOrOutputDependencyTag) - return ok -} - // IsSourceDepTagWithOutputTag returns true if the supplied blueprint.DependencyTag is one that was // used to add dependencies by either ExtractSourceDeps, ExtractSourcesDeps or automatically for // properties tagged with `android:"path"` AND it was added using a module reference of @@ -3630,14 +3579,14 @@ func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths { // be tagged with `android:"path" to support automatic source module dependency resolution. // // Deprecated: use PathForModuleSrc instead. -func (m *moduleContext) ExpandSource(srcFile, prop string) Path { +func (m *moduleContext) ExpandSource(srcFile, _ string) Path { return PathForModuleSrc(m, srcFile) } // Returns an optional single path expanded from globs and modules referenced using ":module" syntax if // the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module // dependency resolution. -func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath { +func (m *moduleContext) ExpandOptionalSource(srcFile *string, _ string) OptionalPath { if srcFile != nil { return OptionalPathForPath(PathForModuleSrc(m, *srcFile)) } diff --git a/android/neverallow.go b/android/neverallow.go index aa47bcaeb..00078a025 100644 --- a/android/neverallow.go +++ b/android/neverallow.go @@ -212,11 +212,16 @@ func createUncompressDexRules() []Rule { } func createMakefileGoalRules() []Rule { + allowlist := []string{ + // libwifi_hal uses makefile_goal for its dependencies + "frameworks/opt/net/wifi/libwifi_hal", + } return []Rule{ NeverAllow(). ModuleType("makefile_goal"). WithoutMatcher("product_out_path", Regexp("^boot[0-9a-zA-Z.-]*[.]img$")). - Because("Only boot images may be imported as a makefile goal."), + NotIn(allowlist...). + Because("Only boot images may be imported as a makefile goal if not in allowed projects"), } } diff --git a/android/neverallow_test.go b/android/neverallow_test.go index 86f1a378f..477279979 100644 --- a/android/neverallow_test.go +++ b/android/neverallow_test.go @@ -324,7 +324,32 @@ var neverallowTests = []struct { `), }, expectedErrors: []string{ - "Only boot images may be imported as a makefile goal.", + "Only boot images.* may be imported as a makefile goal", + }, + }, + { + name: "disallowed makefile_goal outside external", + fs: map[string][]byte{ + "project/Android.bp": []byte(` + makefile_goal { + name: "foo", + product_out_path: "obj/EXE/foo", + } + `), + }, + expectedErrors: []string{ + "not in allowed projects", + }, + }, + { + name: "allow makefile_goal within external", + fs: map[string][]byte{ + "frameworks/opt/net/wifi/libwifi_hal/Android.bp": []byte(` + makefile_goal { + name: "foo", + product_out_path: "obj/EXE/foo", + } + `), }, }, // Tests for the rule prohibiting the use of framework diff --git a/android/onceper.go b/android/onceper.go index 481cdea05..fa415d183 100644 --- a/android/onceper.go +++ b/android/onceper.go @@ -79,6 +79,17 @@ func (once *OncePer) Get(key OnceKey) interface{} { return once.maybeWaitFor(key, v) } +// Peek returns the value previously computed with Once for a given key. If Once has not +// been called for the given key Peek will return ok == false. +func (once *OncePer) Peek(key OnceKey) (interface{}, bool) { + v, ok := once.values.Load(key) + if !ok { + return nil, false + } + + return once.maybeWaitFor(key, v), true +} + // OnceStringSlice is the same as Once, but returns the value cast to a []string func (once *OncePer) OnceStringSlice(key OnceKey, value func() []string) []string { return once.Once(key, func() interface{} { return value() }).([]string) diff --git a/android/paths.go b/android/paths.go index d5cec9af7..f8e701822 100644 --- a/android/paths.go +++ b/android/paths.go @@ -1474,7 +1474,7 @@ func pathForModuleOut(ctx ModuleOutPathContext) OutputPath { // PathForVndkRefAbiDump returns an OptionalPath representing the path of the // reference abi dump for the given module. This is not guaranteed to be valid. func PathForVndkRefAbiDump(ctx ModuleInstallPathContext, version, fileName string, - isNdk, isLlndkOrVndk, isGzip bool) OptionalPath { + isNdk, isVndk, isGzip bool) OptionalPath { currentArchType := ctx.Arch().ArchType primaryArchType := ctx.Config().DevicePrimaryArchType() @@ -1486,7 +1486,7 @@ func PathForVndkRefAbiDump(ctx ModuleInstallPathContext, version, fileName strin var dirName string if isNdk { dirName = "ndk" - } else if isLlndkOrVndk { + } else if isVndk { dirName = "vndk" } else { dirName = "platform" // opt-in libs diff --git a/apex/constants.go b/android/updatable_modules.go index c68edb724..71c76c56a 100644 --- a/apex/constants.go +++ b/android/updatable_modules.go @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -package apex +package android -// This file contains branch specific constants. They are stored in a separate -// file to minimise the potential of merge conflicts between branches when -// the code from the package is changed. +// This file contains branch specific constants for building updatable modules. +// They are stored in a separate file to minimise the potential of merge +// conflicts between branches when the code from the package is changed. // The default manifest version for all the modules on this branch. // This version code will be used only if there is no version field in the @@ -33,4 +33,4 @@ package apex // * AOSP - xx9990000 // * x-mainline-prod - xx9990000 // * master - 990090000 -const defaultManifestVersion = "339990000" +const DefaultUpdatableModuleVersion = "339990000" diff --git a/apex/Android.bp b/apex/Android.bp index 6533c6103..018d0306d 100644 --- a/apex/Android.bp +++ b/apex/Android.bp @@ -26,7 +26,7 @@ bootstrap_go_package { "apex_sdk_member.go", "apex_singleton.go", "builder.go", - "constants.go", + "bp2build.go", "deapexer.go", "key.go", "prebuilt.go", diff --git a/apex/androidmk.go b/apex/androidmk.go index 938c8edd3..3373211a0 100644 --- a/apex/androidmk.go +++ b/apex/androidmk.go @@ -168,10 +168,6 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, mo if len(newDataPaths) > 0 { fmt.Fprintln(w, "LOCAL_TEST_DATA :=", strings.Join(android.AndroidMkDataPaths(newDataPaths), " ")) } - - if fi.module != nil && len(fi.module.NoticeFiles()) > 0 { - fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", strings.Join(fi.module.NoticeFiles().Strings(), " ")) - } } else { modulePath = pathWhenActivated fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated) diff --git a/apex/apex.go b/apex/apex.go index 7b6707ce6..e9b08150f 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -17,6 +17,7 @@ package apex import ( + "android/soong/bazel/cquery" "fmt" "path/filepath" "regexp" @@ -639,7 +640,7 @@ var ( fsTag = &dependencyTag{name: "filesystem", payload: true} bcpfTag = &dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true, memberType: java.BootclasspathFragmentSdkMemberType} sscpfTag = &dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true, memberType: java.SystemServerClasspathFragmentSdkMemberType} - compatConfigTag = &dependencyTag{name: "compatConfig", payload: true, sourceOnly: true} + compatConfigTag = &dependencyTag{name: "compatConfig", payload: true, sourceOnly: true, memberType: java.CompatConfigSdkMemberType} javaLibTag = &dependencyTag{name: "javaLib", payload: true} jniLibTag = &dependencyTag{name: "jniLib", payload: true} keyTag = &dependencyTag{name: "key"} @@ -1803,6 +1804,184 @@ func (f fsType) string() string { } } +var _ android.MixedBuildBuildable = (*apexBundle)(nil) + +func (a *apexBundle) IsMixedBuildSupported(ctx android.BaseModuleContext) bool { + return ctx.ModuleType() == "apex" && a.properties.ApexType == imageApex +} + +func (a *apexBundle) QueueBazelCall(ctx android.BaseModuleContext) { + bazelCtx := ctx.Config().BazelContext + bazelCtx.QueueBazelRequest(a.GetBazelLabel(ctx, a), cquery.GetApexInfo, android.GetConfigKey(ctx)) +} + +func (a *apexBundle) ProcessBazelQueryResponse(ctx android.ModuleContext) { + if !a.commonBuildActions(ctx) { + return + } + + a.setApexTypeAndSuffix(ctx) + a.setPayloadFsType(ctx) + a.setSystemLibLink(ctx) + + if a.properties.ApexType != zipApex { + a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx, a.primaryApexType) + } + + bazelCtx := ctx.Config().BazelContext + outputs, err := bazelCtx.GetApexInfo(a.GetBazelLabel(ctx, a), android.GetConfigKey(ctx)) + if err != nil { + ctx.ModuleErrorf(err.Error()) + return + } + a.installDir = android.PathForModuleInstall(ctx, "apex") + a.outputApexFile = android.PathForBazelOut(ctx, outputs.SignedOutput) + a.outputFile = a.outputApexFile + a.setCompression(ctx) + + a.publicKeyFile = android.PathForBazelOut(ctx, outputs.BundleKeyPair[0]) + a.privateKeyFile = android.PathForBazelOut(ctx, outputs.BundleKeyPair[1]) + a.containerCertificateFile = android.PathForBazelOut(ctx, outputs.ContainerKeyPair[0]) + a.containerPrivateKeyFile = android.PathForBazelOut(ctx, outputs.ContainerKeyPair[1]) + apexType := a.properties.ApexType + switch apexType { + case imageApex: + // TODO(asmundak): Bazel does not create these files yet. + // b/190817312 + a.htmlGzNotice = android.PathForBazelOut(ctx, "NOTICE.html.gz") + // b/239081457 + a.bundleModuleFile = android.PathForBazelOut(ctx, a.Name()+apexType.suffix()+"-base.zip") + // b/239081455 + a.nativeApisUsedByModuleFile = android.ModuleOutPath(android.PathForBazelOut(ctx, a.Name()+"_using.txt")) + // b/239081456 + a.nativeApisBackedByModuleFile = android.ModuleOutPath(android.PathForBazelOut(ctx, a.Name()+"_backing.txt")) + // b/239084755 + a.javaApisUsedByModuleFile = android.ModuleOutPath(android.PathForBazelOut(ctx, a.Name()+"_using.xml")) + installSuffix := imageApexSuffix + if a.isCompressed { + installSuffix = imageCapexSuffix + } + a.installedFile = ctx.InstallFile(a.installDir, a.Name()+installSuffix, a.outputFile, + a.compatSymlinks.Paths()...) + default: + panic(fmt.Errorf("unexpected apex_type for the ProcessBazelQuery: %v", a.properties.ApexType)) + } + + /* + TODO(asmundak): compared to building an APEX with Soong, building it with Bazel does not + return filesInfo and requiredDeps fields (in the Soong build the latter is updated). + Fix this, as these fields are subsequently used in apex/androidmk.go and in apex/builder/go + To find out what Soong build puts there, run: + vctx := visitorContext{handleSpecialLibs: !android.Bool(a.properties.Ignore_system_library_special_case)} + ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool { + return a.depVisitor(&vctx, ctx, child, parent) + }) + vctx.normalizeFileInfo() + */ + +} + +func (a *apexBundle) setCompression(ctx android.ModuleContext) { + if a.properties.ApexType != imageApex { + a.isCompressed = false + } else if a.testOnlyShouldForceCompression() { + a.isCompressed = true + } else { + a.isCompressed = ctx.Config().ApexCompressionEnabled() && a.isCompressable() + } +} + +func (a *apexBundle) setSystemLibLink(ctx android.ModuleContext) { + // Optimization. If we are building bundled APEX, for the files that are gathered due to the + // transitive dependencies, don't place them inside the APEX, but place a symlink pointing + // the same library in the system partition, thus effectively sharing the same libraries + // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed + // in the APEX. + a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable() + + // APEXes targeting other than system/system_ext partitions use vendor/product variants. + // So we can't link them to /system/lib libs which are core variants. + if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) { + a.linkToSystemLib = false + } + + forced := ctx.Config().ForceApexSymlinkOptimization() + updatable := a.Updatable() || a.FutureUpdatable() + + // We don't need the optimization for updatable APEXes, as it might give false signal + // to the system health when the APEXes are still bundled (b/149805758). + if !forced && updatable && a.properties.ApexType == imageApex { + a.linkToSystemLib = false + } + + // We also don't want the optimization for host APEXes, because it doesn't make sense. + if ctx.Host() { + a.linkToSystemLib = false + } +} + +func (a *apexBundle) setPayloadFsType(ctx android.ModuleContext) { + switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) { + case ext4FsType: + a.payloadFsType = ext4 + case f2fsFsType: + a.payloadFsType = f2fs + case erofsFsType: + a.payloadFsType = erofs + default: + ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs, erofs]", *a.properties.Payload_fs_type) + } +} + +func (a *apexBundle) setApexTypeAndSuffix(ctx android.ModuleContext) { + // Set suffix and primaryApexType depending on the ApexType + buildFlattenedAsDefault := ctx.Config().FlattenApex() + switch a.properties.ApexType { + case imageApex: + if buildFlattenedAsDefault { + a.suffix = imageApexSuffix + } else { + a.suffix = "" + a.primaryApexType = true + + if ctx.Config().InstallExtraFlattenedApexes() { + a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix) + } + } + case zipApex: + if proptools.String(a.properties.Payload_type) == "zip" { + a.suffix = "" + a.primaryApexType = true + } else { + a.suffix = zipApexSuffix + } + case flattenedApex: + if buildFlattenedAsDefault { + a.suffix = "" + a.primaryApexType = true + } else { + a.suffix = flattenedSuffix + } + } +} + +func (a apexBundle) isCompressable() bool { + return proptools.BoolDefault(a.overridableProperties.Compressible, false) && !a.testApex +} + +func (a *apexBundle) commonBuildActions(ctx android.ModuleContext) bool { + a.checkApexAvailability(ctx) + a.checkUpdatable(ctx) + a.CheckMinSdkVersion(ctx) + a.checkStaticLinkingToStubLibraries(ctx) + a.checkStaticExecutables(ctx) + if len(a.properties.Tests) > 0 && !a.testApex { + ctx.PropertyErrorf("tests", "property allowed only in apex_test module type") + return false + } + return true +} + type visitorContext struct { // all the files that will be included in this APEX filesInfo []apexFile @@ -2188,16 +2367,9 @@ func (a *apexBundle) depVisitor(vctx *visitorContext, ctx android.ModuleContext, func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { //////////////////////////////////////////////////////////////////////////////////////////// // 1) do some validity checks such as apex_available, min_sdk_version, etc. - a.checkApexAvailability(ctx) - a.checkUpdatable(ctx) - a.CheckMinSdkVersion(ctx) - a.checkStaticLinkingToStubLibraries(ctx) - a.checkStaticExecutables(ctx) - if len(a.properties.Tests) > 0 && !a.testApex { - ctx.PropertyErrorf("tests", "property allowed only in apex_test module type") + if !a.commonBuildActions(ctx) { return } - //////////////////////////////////////////////////////////////////////////////////////////// // 2) traverse the dependency tree to collect apexFile structs from them. @@ -2219,74 +2391,9 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.installDir = android.PathForModuleInstall(ctx, "apex") a.filesInfo = vctx.filesInfo - // Set suffix and primaryApexType depending on the ApexType - buildFlattenedAsDefault := ctx.Config().FlattenApex() - switch a.properties.ApexType { - case imageApex: - if buildFlattenedAsDefault { - a.suffix = imageApexSuffix - } else { - a.suffix = "" - a.primaryApexType = true - - if ctx.Config().InstallExtraFlattenedApexes() { - a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix) - } - } - case zipApex: - if proptools.String(a.properties.Payload_type) == "zip" { - a.suffix = "" - a.primaryApexType = true - } else { - a.suffix = zipApexSuffix - } - case flattenedApex: - if buildFlattenedAsDefault { - a.suffix = "" - a.primaryApexType = true - } else { - a.suffix = flattenedSuffix - } - } - - switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) { - case ext4FsType: - a.payloadFsType = ext4 - case f2fsFsType: - a.payloadFsType = f2fs - case erofsFsType: - a.payloadFsType = erofs - default: - ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs, erofs]", *a.properties.Payload_fs_type) - } - - // Optimization. If we are building bundled APEX, for the files that are gathered due to the - // transitive dependencies, don't place them inside the APEX, but place a symlink pointing - // the same library in the system partition, thus effectively sharing the same libraries - // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed - // in the APEX. - a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable() - - // APEXes targeting other than system/system_ext partitions use vendor/product variants. - // So we can't link them to /system/lib libs which are core variants. - if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) { - a.linkToSystemLib = false - } - - forced := ctx.Config().ForceApexSymlinkOptimization() - updatable := a.Updatable() || a.FutureUpdatable() - - // We don't need the optimization for updatable APEXes, as it might give false signal - // to the system health when the APEXes are still bundled (b/149805758). - if !forced && updatable && a.properties.ApexType == imageApex { - a.linkToSystemLib = false - } - - // We also don't want the optimization for host APEXes, because it doesn't make sense. - if ctx.Host() { - a.linkToSystemLib = false - } - + a.setApexTypeAndSuffix(ctx) + a.setPayloadFsType(ctx) + a.setSystemLibLink(ctx) if a.properties.ApexType != zipApex { a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx, a.primaryApexType) } @@ -2594,7 +2701,7 @@ func (o *OverrideApex) ConvertWithBp2build(ctx android.TopDownMutatorContext) { var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil) -// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version +// Ensures that min_sdk_version of the included modules are equal or less than the min_sdk_version // of this apexBundle. func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) { if a.testApex || a.vndkApex { diff --git a/apex/apex_test.go b/apex/apex_test.go index dbe918010..52829417d 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -443,7 +443,6 @@ func TestBasicApex(t *testing.T) { srcs: ["mylib.cpp"], system_shared_libs: [], stl: "none", - notice: "custom_notice", static_libs: ["libstatic"], // TODO: remove //apex_available:platform apex_available: [ @@ -467,7 +466,6 @@ func TestBasicApex(t *testing.T) { srcs: ["mylib.cpp"], system_shared_libs: [], stl: "none", - notice: "custom_notice_for_static_lib", // TODO: remove //apex_available:platform apex_available: [ "//apex_available:platform", @@ -619,7 +617,7 @@ func TestDefaults(t *testing.T) { java_libs: ["myjar"], apps: ["AppFoo"], rros: ["rro"], - bpfs: ["bpf", "netd_test"], + bpfs: ["bpf", "netdTest"], updatable: false, } @@ -673,8 +671,8 @@ func TestDefaults(t *testing.T) { } bpf { - name: "netd_test", - srcs: ["netd_test.c"], + name: "netdTest", + srcs: ["netdTest.c"], sub_dir: "netd", } @@ -687,7 +685,7 @@ func TestDefaults(t *testing.T) { "overlay/blue/rro.apk", "etc/bpf/bpf.o", "etc/bpf/bpf2.o", - "etc/bpf/netd/netd_test.o", + "etc/bpf/netd/netdTest.o", }) } @@ -949,8 +947,10 @@ func TestApexWithStubs(t *testing.T) { // mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] // ensureNotContains(t, mylib2Cflags, "-include ") - // Ensure that genstub is invoked with --apex - ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_3").Rule("genStubSrc").Args["flags"]) + // Ensure that genstub for platform-provided lib is invoked with --systemapi + ensureContains(t, ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_3").Rule("genStubSrc").Args["flags"], "--systemapi") + // Ensure that genstub for apex-provided lib is invoked with --apex + ensureContains(t, ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_shared_12").Rule("genStubSrc").Args["flags"], "--apex") ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ "lib64/mylib.so", @@ -1134,8 +1134,8 @@ func TestApexWithStubsWithMinSdkVersion(t *testing.T) { mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_29").Rule("cc").Args["cFlags"] ensureNotContains(t, mylib2Cflags, "-include ") - // Ensure that genstub is invoked with --apex - ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_29").Rule("genStubSrc").Args["flags"]) + // Ensure that genstub is invoked with --systemapi + ensureContains(t, ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_29").Rule("genStubSrc").Args["flags"], "--systemapi") ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ "lib64/mylib.so", @@ -6151,7 +6151,7 @@ func TestOverrideApex(t *testing.T) { name: "override_myapex", base: "myapex", apps: ["override_app"], - bpfs: ["override_bpf"], + bpfs: ["overrideBpf"], prebuilts: ["override_myetc"], bootclasspath_fragments: ["override_bootclasspath_fragment"], systemserverclasspath_fragments: ["override_systemserverclasspath_fragment"], @@ -6201,8 +6201,8 @@ func TestOverrideApex(t *testing.T) { } bpf { - name: "override_bpf", - srcs: ["override_bpf.c"], + name: "overrideBpf", + srcs: ["overrideBpf.c"], } prebuilt_etc { @@ -6305,7 +6305,7 @@ func TestOverrideApex(t *testing.T) { ensureContains(t, copyCmds, "image.apex/app/override_app@TEST.BUILD_ID/override_app.apk") ensureNotContains(t, copyCmds, "image.apex/etc/bpf/bpf.o") - ensureContains(t, copyCmds, "image.apex/etc/bpf/override_bpf.o") + ensureContains(t, copyCmds, "image.apex/etc/bpf/overrideBpf.o") ensureNotContains(t, copyCmds, "image.apex/etc/myetc") ensureContains(t, copyCmds, "image.apex/etc/override_myetc") @@ -6339,7 +6339,7 @@ func TestOverrideApex(t *testing.T) { data.Custom(&builder, name, "TARGET_", "", data) androidMk := builder.String() ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") - ensureContains(t, androidMk, "LOCAL_MODULE := override_bpf.o.override_myapex") + ensureContains(t, androidMk, "LOCAL_MODULE := overrideBpf.o.override_myapex") ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") ensureContains(t, androidMk, "LOCAL_MODULE := override_bcplib.override_myapex") ensureContains(t, androidMk, "LOCAL_MODULE := override_systemserverlib.override_myapex") diff --git a/apex/bp2build.go b/apex/bp2build.go new file mode 100644 index 000000000..221ab132f --- /dev/null +++ b/apex/bp2build.go @@ -0,0 +1,30 @@ +// Copyright (C) 2022 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package apex + +import ( + "android/soong/android" + "strings" +) + +// This file contains the bp2build integration for the apex package. + +// Export constants as Starlark using bp2build to Bazel. +func BazelApexToolchainVars() string { + content := []string{ + "# GENERATED BY SOONG. DO NOT EDIT.", + "default_manifest_version = " + android.DefaultUpdatableModuleVersion, // constants.go is different in every branch. + } + return strings.Join(content, "\n") +} diff --git a/apex/builder.go b/apex/builder.go index 1956b4447..f1b14484e 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -214,7 +214,7 @@ func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, Args: map[string]string{ "provideNativeLibs": strings.Join(provideNativeLibs, " "), "requireNativeLibs": strings.Join(requireNativeLibs, " "), - "default_version": defaultManifestVersion, + "default_version": android.DefaultUpdatableModuleVersion, "opt": strings.Join(optCommands, " "), }, }) @@ -549,8 +549,6 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { outHostBinDir := ctx.Config().HostToolPath(ctx, "").String() prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin") - // Figure out if we need to compress the apex. - compressionEnabled := ctx.Config().CompressedApex() && proptools.BoolDefault(a.overridableProperties.Compressible, false) && !a.testApex && !ctx.Config().UnbundledBuildApps() if apexType == imageApex { //////////////////////////////////////////////////////////////////////////////////// @@ -635,10 +633,15 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { implicitInputs = append(implicitInputs, noticeAssetPath) optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeAssetPath.String())) - if (moduleMinSdkVersion.GreaterThan(android.SdkVersion_Android10) && !a.shouldGenerateHashtree()) && !compressionEnabled { - // Apexes which are supposed to be installed in builtin dirs(/system, etc) - // don't need hashtree for activation. Therefore, by removing hashtree from - // apex bundle (filesystem image in it, to be specific), we can save storage. + // Apexes which are supposed to be installed in builtin dirs(/system, etc) + // don't need hashtree for activation. Therefore, by removing hashtree from + // apex bundle (filesystem image in it, to be specific), we can save storage. + needHashTree := moduleMinSdkVersion.LessThanOrEqualTo(android.SdkVersion_Android10) || + a.shouldGenerateHashtree() + if ctx.Config().ApexCompressionEnabled() && a.isCompressable() { + needHashTree = true + } + if !needHashTree { optFlags = append(optFlags, "--no_hashtree") } @@ -806,8 +809,9 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { return } - if apexType == imageApex && (compressionEnabled || a.testOnlyShouldForceCompression()) { - a.isCompressed = true + installSuffix := suffix + a.setCompression(ctx) + if a.isCompressed { unsignedCompressedOutputFile := android.PathForModuleOut(ctx, a.Name()+imageCapexSuffix+".unsigned") compressRule := android.NewRuleBuilder(pctx, ctx) @@ -835,10 +839,6 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { Args: args, }) a.outputFile = signedCompressedOutputFile - } - - installSuffix := suffix - if a.isCompressed { installSuffix = imageCapexSuffix } diff --git a/apex/vndk_test.go b/apex/vndk_test.go index d580e5aa6..21526c3eb 100644 --- a/apex/vndk_test.go +++ b/apex/vndk_test.go @@ -86,7 +86,6 @@ func TestVndkApexUsesVendorVariant(t *testing.T) { }, system_shared_libs: [], stl: "none", - notice: "custom_notice", } ` + vndkLibrariesTxtFiles("current") diff --git a/bazel/aquery.go b/bazel/aquery.go index ae2b107e1..418b14321 100644 --- a/bazel/aquery.go +++ b/bazel/aquery.go @@ -574,7 +574,7 @@ func (a *aqueryArtifactHandler) getOutputPaths(actionEntry action) (outputPaths // expandTemplateContent substitutes the tokens in a template. func expandTemplateContent(actionEntry action) string { - replacerString := []string{} + var replacerString []string for _, pair := range actionEntry.Substitutions { value := pair.Value if val, ok := templateActionOverriddenTokens[pair.Key]; ok { @@ -647,7 +647,7 @@ func expandPathFragment(id pathFragmentId, pathFragmentsMap map[pathFragmentId]p } labels = append([]string{currFragment.Label}, labels...) if currId == currFragment.ParentId { - return "", fmt.Errorf("Fragment cannot refer to itself as parent %#v", currFragment) + return "", fmt.Errorf("fragment cannot refer to itself as parent %#v", currFragment) } currId = currFragment.ParentId } diff --git a/bazel/aquery_test.go b/bazel/aquery_test.go index 3a2bf0f38..53056c742 100644 --- a/bazel/aquery_test.go +++ b/bazel/aquery_test.go @@ -499,19 +499,11 @@ func TestSymlinkTree(t *testing.T) { func TestBazelOutRemovalFromInputDepsets(t *testing.T) { const inputString = `{ - "artifacts": [{ - "id": 1, - "pathFragmentId": 10 - }, { - "id": 2, - "pathFragmentId": 20 - }, { - "id": 3, - "pathFragmentId": 30 - }, { - "id": 4, - "pathFragmentId": 40 - }], + "artifacts": [ + { "id": 1, "pathFragmentId": 10 }, + { "id": 2, "pathFragmentId": 20 }, + { "id": 3, "pathFragmentId": 30 }, + { "id": 4, "pathFragmentId": 40 }], "depSetOfFiles": [{ "id": 1111, "directArtifactIds": [3 , 4] @@ -525,28 +517,14 @@ func TestBazelOutRemovalFromInputDepsets(t *testing.T) { "outputIds": [2], "primaryOutputId": 1 }], - "pathFragments": [{ - "id": 10, - "label": "input" - }, { - "id": 20, - "label": "output" - }, { - "id": 30, - "label": "dep1", - "parentId": 50 - }, { - "id": 40, - "label": "dep2", - "parentId": 60 - }, { - "id": 50, - "label": "bazel_tools", - "parentId": 60 - }, { - "id": 60, - "label": ".." - }] + "pathFragments": [ + { "id": 10, "label": "input" }, + { "id": 20, "label": "output" }, + { "id": 30, "label": "dep1", "parentId": 50 }, + { "id": 40, "label": "dep2", "parentId": 60 }, + { "id": 50, "label": "bazel_tools", "parentId": 60 }, + { "id": 60, "label": ".."} + ] }` actualBuildStatements, actualDepsets, _ := AqueryBuildStatements([]byte(inputString)) if len(actualDepsets) != 1 { diff --git a/bazel/cquery/request_type.go b/bazel/cquery/request_type.go index f5435f25f..d32e61969 100644 --- a/bazel/cquery/request_type.go +++ b/bazel/cquery/request_type.go @@ -1,6 +1,7 @@ package cquery import ( + "encoding/json" "fmt" "strings" ) @@ -9,6 +10,7 @@ var ( GetOutputFiles = &getOutputFilesRequestType{} GetPythonBinary = &getPythonBinaryRequestType{} GetCcInfo = &getCcInfoType{} + GetApexInfo = &getApexInfoType{} ) type CcInfo struct { @@ -179,7 +181,7 @@ func (g getCcInfoType) ParseResult(rawString string) (CcInfo, error) { const expectedLen = 10 splitString := strings.Split(rawString, "|") if len(splitString) != expectedLen { - return CcInfo{}, fmt.Errorf("Expected %d items, got %q", expectedLen, splitString) + return CcInfo{}, fmt.Errorf("expected %d items, got %q", expectedLen, splitString) } outputFilesString := splitString[0] ccObjectsString := splitString[1] @@ -215,6 +217,54 @@ func (g getCcInfoType) ParseResult(rawString string) (CcInfo, error) { }, nil } +// Query Bazel for the artifacts generated by the apex modules. +type getApexInfoType struct{} + +// Name returns a string name for this request type. Such request type names must be unique, +// and must only consist of alphanumeric characters. +func (g getApexInfoType) Name() string { + return "getApexInfo" +} + +// StarlarkFunctionBody returns a starlark function body to process this request type. +// The returned string is the body of a Starlark function which obtains +// all request-relevant information about a target and returns a string containing +// this information. The function should have the following properties: +// - `target` is the only parameter to this function (a configured target). +// - The return value must be a string. +// - The function body should not be indented outside of its own scope. +func (g getApexInfoType) StarlarkFunctionBody() string { + return `info = providers(target)["//build/bazel/rules/apex:apex.bzl%ApexInfo"] +return "{%s}" % ",".join([ + json_for_file("signed_output", info.signed_output), + json_for_file("unsigned_output", info.unsigned_output), + json_for_labels("provides_native_libs", info.provides_native_libs), + json_for_labels("requires_native_libs", info.requires_native_libs), + json_for_files("bundle_key_pair", info.bundle_key_pair), + json_for_files("container_key_pair", info.container_key_pair) + ])` +} + +type ApexCqueryInfo struct { + SignedOutput string `json:"signed_output"` + UnsignedOutput string `json:"unsigned_output"` + ProvidesLibs []string `json:"provides_native_libs"` + RequiresLibs []string `json:"requires_native_libs"` + BundleKeyPair []string `json:"bundle_key_pair"` + ContainerKeyPair []string `json:"container_key_pair"` +} + +// ParseResult returns a value obtained by parsing the result of the request's Starlark function. +// The given rawString must correspond to the string output which was created by evaluating the +// Starlark given in StarlarkFunctionBody. +func (g getApexInfoType) ParseResult(rawString string) ApexCqueryInfo { + var info ApexCqueryInfo + if err := json.Unmarshal([]byte(rawString), &info); err != nil { + panic(fmt.Errorf("cannot parse cquery result '%s': %s", rawString, err)) + } + return info +} + // splitOrEmpty is a modification of strings.Split() that returns an empty list // if the given string is empty. func splitOrEmpty(s string, sep string) []string { diff --git a/bazel/cquery/request_type_test.go b/bazel/cquery/request_type_test.go index 606e285bb..34248ce81 100644 --- a/bazel/cquery/request_type_test.go +++ b/bazel/cquery/request_type_test.go @@ -148,13 +148,13 @@ func TestGetCcInfoParseResults(t *testing.T) { description: "too few result splits", input: "|", expectedOutput: CcInfo{}, - expectedErrorMessage: fmt.Sprintf("Expected %d items, got %q", expectedSplits, []string{"", ""}), + expectedErrorMessage: fmt.Sprintf("expected %d items, got %q", expectedSplits, []string{"", ""}), }, { description: "too many result splits", input: strings.Repeat("|", expectedSplits+1), // 2 too many expectedOutput: CcInfo{}, - expectedErrorMessage: fmt.Sprintf("Expected %d items, got %q", expectedSplits, make([]string, expectedSplits+2)), + expectedErrorMessage: fmt.Sprintf("expected %d items, got %q", expectedSplits, make([]string, expectedSplits+2)), }, } for _, tc := range testCases { @@ -167,3 +167,40 @@ func TestGetCcInfoParseResults(t *testing.T) { } } } + +func TestGetApexInfoParseResults(t *testing.T) { + testCases := []struct { + description string + input string + expectedOutput ApexCqueryInfo + }{ + { + description: "no result", + input: "{}", + expectedOutput: ApexCqueryInfo{}, + }, + { + description: "one result", + input: `{"signed_output":"my.apex",` + + `"unsigned_output":"my.apex.unsigned",` + + `"requires_native_libs":["//bionic/libc:libc","//bionic/libdl:libdl"],` + + `"bundle_key_pair":["foo.pem","foo.privkey"],` + + `"container_key_pair":["foo.x509.pem", "foo.pk8"],` + + `"provides_native_libs":[]}`, + expectedOutput: ApexCqueryInfo{ + SignedOutput: "my.apex", + UnsignedOutput: "my.apex.unsigned", + RequiresLibs: []string{"//bionic/libc:libc", "//bionic/libdl:libdl"}, + ProvidesLibs: []string{}, + BundleKeyPair: []string{"foo.pem", "foo.privkey"}, + ContainerKeyPair: []string{"foo.x509.pem", "foo.pk8"}, + }, + }, + } + for _, tc := range testCases { + actualOutput := GetApexInfo.ParseResult(tc.input) + if !reflect.DeepEqual(tc.expectedOutput, actualOutput) { + t.Errorf("%q: expected %#v != actual %#v", tc.description, tc.expectedOutput, actualOutput) + } + } +} diff --git a/bazel/properties.go b/bazel/properties.go index e29b9e137..aba97c647 100644 --- a/bazel/properties.go +++ b/bazel/properties.go @@ -94,6 +94,10 @@ func (ll *LabelList) IsNil() bool { return ll.Includes == nil && ll.Excludes == nil } +func (ll *LabelList) IsEmpty() bool { + return len(ll.Includes) == 0 && len(ll.Excludes) == 0 +} + func (ll *LabelList) deepCopy() LabelList { return LabelList{ Includes: ll.Includes[:], diff --git a/bp2build/Android.bp b/bp2build/Android.bp index 34548ed95..07557d604 100644 --- a/bp2build/Android.bp +++ b/bp2build/Android.bp @@ -20,15 +20,16 @@ bootstrap_go_package { "soong-android", "soong-android-allowlists", "soong-android-soongconfig", - "soong-shared", "soong-apex", "soong-bazel", "soong-cc", "soong-cc-config", "soong-etc", "soong-genrule", + "soong-linkerconfig", "soong-python", "soong-sh", + "soong-shared", "soong-starlark-format", "soong-ui-metrics", ], @@ -58,6 +59,7 @@ bootstrap_go_package { "java_library_host_conversion_test.go", "java_plugin_conversion_test.go", "java_proto_conversion_test.go", + "linker_config_conversion_test.go", "performance_test.go", "prebuilt_etc_conversion_test.go", "python_binary_conversion_test.go", diff --git a/bp2build/android_app_certificate_conversion_test.go b/bp2build/android_app_certificate_conversion_test.go index 173b4e485..01045134c 100644 --- a/bp2build/android_app_certificate_conversion_test.go +++ b/bp2build/android_app_certificate_conversion_test.go @@ -21,28 +21,28 @@ import ( "testing" ) -func runAndroidAppCertificateTestCase(t *testing.T, tc bp2buildTestCase) { +func runAndroidAppCertificateTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - runBp2BuildTestCase(t, registerAndroidAppCertificateModuleTypes, tc) + RunBp2BuildTestCase(t, registerAndroidAppCertificateModuleTypes, tc) } func registerAndroidAppCertificateModuleTypes(ctx android.RegistrationContext) { } func TestAndroidAppCertificateSimple(t *testing.T) { - runAndroidAppCertificateTestCase(t, bp2buildTestCase{ - description: "Android app certificate - simple example", - moduleTypeUnderTest: "android_app_certificate", - moduleTypeUnderTestFactory: java.AndroidAppCertificateFactory, - filesystem: map[string]string{}, - blueprint: ` + runAndroidAppCertificateTestCase(t, Bp2buildTestCase{ + Description: "Android app certificate - simple example", + ModuleTypeUnderTest: "android_app_certificate", + ModuleTypeUnderTestFactory: java.AndroidAppCertificateFactory, + Filesystem: map[string]string{}, + Blueprint: ` android_app_certificate { name: "com.android.apogee.cert", certificate: "chamber_of_secrets_dir", } `, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("android_app_certificate", "com.android.apogee.cert", attrNameToString{ + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("android_app_certificate", "com.android.apogee.cert", AttrNameToString{ "certificate": `"chamber_of_secrets_dir"`, }), }}) diff --git a/bp2build/android_app_conversion_test.go b/bp2build/android_app_conversion_test.go index a216c9d11..a37af12bd 100644 --- a/bp2build/android_app_conversion_test.go +++ b/bp2build/android_app_conversion_test.go @@ -21,33 +21,33 @@ import ( "testing" ) -func runAndroidAppTestCase(t *testing.T, tc bp2buildTestCase) { +func runAndroidAppTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - runBp2BuildTestCase(t, registerAndroidAppModuleTypes, tc) + RunBp2BuildTestCase(t, registerAndroidAppModuleTypes, tc) } func registerAndroidAppModuleTypes(ctx android.RegistrationContext) { } func TestMinimalAndroidApp(t *testing.T) { - runAndroidAppTestCase(t, bp2buildTestCase{ - description: "Android app - simple example", - moduleTypeUnderTest: "android_app", - moduleTypeUnderTestFactory: java.AndroidAppFactory, - filesystem: map[string]string{ + runAndroidAppTestCase(t, Bp2buildTestCase{ + Description: "Android app - simple example", + ModuleTypeUnderTest: "android_app", + ModuleTypeUnderTestFactory: java.AndroidAppFactory, + Filesystem: map[string]string{ "app.java": "", "res/res.png": "", "AndroidManifest.xml": "", }, - blueprint: ` + Blueprint: ` android_app { name: "TestApp", srcs: ["app.java"], sdk_version: "current", } `, - expectedBazelTargets: []string{ - makeBazelTarget("android_binary", "TestApp", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("android_binary", "TestApp", AttrNameToString{ "srcs": `["app.java"]`, "manifest": `"AndroidManifest.xml"`, "resource_files": `["res/res.png"]`, @@ -56,17 +56,17 @@ android_app { } func TestAndroidAppAllSupportedFields(t *testing.T) { - runAndroidAppTestCase(t, bp2buildTestCase{ - description: "Android app - all supported fields", - moduleTypeUnderTest: "android_app", - moduleTypeUnderTestFactory: java.AndroidAppFactory, - filesystem: map[string]string{ + runAndroidAppTestCase(t, Bp2buildTestCase{ + Description: "Android app - all supported fields", + ModuleTypeUnderTest: "android_app", + ModuleTypeUnderTestFactory: java.AndroidAppFactory, + Filesystem: map[string]string{ "app.java": "", "resa/res.png": "", "resb/res.png": "", "manifest/AndroidManifest.xml": "", }, - blueprint: simpleModuleDoNotConvertBp2build("android_app", "static_lib_dep") + ` + Blueprint: simpleModuleDoNotConvertBp2build("android_app", "static_lib_dep") + ` android_app { name: "TestApp", srcs: ["app.java"], @@ -78,8 +78,8 @@ android_app { java_version: "7", } `, - expectedBazelTargets: []string{ - makeBazelTarget("android_binary", "TestApp", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("android_binary", "TestApp", AttrNameToString{ "srcs": `["app.java"]`, "manifest": `"manifest/AndroidManifest.xml"`, "resource_files": `[ @@ -94,17 +94,17 @@ android_app { } func TestAndroidAppArchVariantSrcs(t *testing.T) { - runAndroidAppTestCase(t, bp2buildTestCase{ - description: "Android app - arch variant srcs", - moduleTypeUnderTest: "android_app", - moduleTypeUnderTestFactory: java.AndroidAppFactory, - filesystem: map[string]string{ + runAndroidAppTestCase(t, Bp2buildTestCase{ + Description: "Android app - arch variant srcs", + ModuleTypeUnderTest: "android_app", + ModuleTypeUnderTestFactory: java.AndroidAppFactory, + Filesystem: map[string]string{ "arm.java": "", "x86.java": "", "res/res.png": "", "AndroidManifest.xml": "", }, - blueprint: ` + Blueprint: ` android_app { name: "TestApp", sdk_version: "current", @@ -118,8 +118,8 @@ android_app { } } `, - expectedBazelTargets: []string{ - makeBazelTarget("android_binary", "TestApp", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("android_binary", "TestApp", AttrNameToString{ "srcs": `select({ "//build/bazel/platforms/arch:arm": ["arm.java"], "//build/bazel/platforms/arch:x86": ["x86.java"], diff --git a/bp2build/apex_conversion_test.go b/bp2build/apex_conversion_test.go index 7bc379fac..415e69558 100644 --- a/bp2build/apex_conversion_test.go +++ b/bp2build/apex_conversion_test.go @@ -25,9 +25,9 @@ import ( "testing" ) -func runApexTestCase(t *testing.T, tc bp2buildTestCase) { +func runApexTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - runBp2BuildTestCase(t, registerApexModuleTypes, tc) + RunBp2BuildTestCase(t, registerApexModuleTypes, tc) } func registerApexModuleTypes(ctx android.RegistrationContext) { @@ -43,9 +43,9 @@ func registerApexModuleTypes(ctx android.RegistrationContext) { ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory) } -func runOverrideApexTestCase(t *testing.T, tc bp2buildTestCase) { +func runOverrideApexTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - runBp2BuildTestCase(t, registerOverrideApexModuleTypes, tc) + RunBp2BuildTestCase(t, registerOverrideApexModuleTypes, tc) } func registerOverrideApexModuleTypes(ctx android.RegistrationContext) { @@ -63,12 +63,12 @@ func registerOverrideApexModuleTypes(ctx android.RegistrationContext) { } func TestApexBundleSimple(t *testing.T) { - runApexTestCase(t, bp2buildTestCase{ - description: "apex - example with all props, file_context is a module in same Android.bp", - moduleTypeUnderTest: "apex", - moduleTypeUnderTestFactory: apex.BundleFactory, - filesystem: map[string]string{}, - blueprint: ` + runApexTestCase(t, Bp2buildTestCase{ + Description: "apex - example with all props, file_context is a module in same Android.bp", + ModuleTypeUnderTest: "apex", + ModuleTypeUnderTestFactory: apex.BundleFactory, + Filesystem: map[string]string{}, + Blueprint: ` apex_key { name: "com.android.apogee.key", public_key: "com.android.apogee.avbpubkey", @@ -140,8 +140,8 @@ apex { logging_parent: "logging.parent", } `, - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.android.apogee", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("apex", "com.android.apogee", AttrNameToString{ "android_manifest": `"ApogeeAndroidManifest.xml"`, "binaries": `[ ":cc_binary_1", @@ -181,11 +181,11 @@ apex { } func TestApexBundleSimple_fileContextsInAnotherAndroidBp(t *testing.T) { - runApexTestCase(t, bp2buildTestCase{ - description: "apex - file contexts is a module in another Android.bp", - moduleTypeUnderTest: "apex", - moduleTypeUnderTestFactory: apex.BundleFactory, - filesystem: map[string]string{ + runApexTestCase(t, Bp2buildTestCase{ + Description: "apex - file contexts is a module in another Android.bp", + ModuleTypeUnderTest: "apex", + ModuleTypeUnderTestFactory: apex.BundleFactory, + Filesystem: map[string]string{ "a/b/Android.bp": ` filegroup { name: "com.android.apogee-file_contexts", @@ -196,14 +196,14 @@ filegroup { } `, }, - blueprint: ` + Blueprint: ` apex { name: "com.android.apogee", file_contexts: ":com.android.apogee-file_contexts", } `, - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.android.apogee", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("apex", "com.android.apogee", AttrNameToString{ "file_contexts": `"//a/b:com.android.apogee-file_contexts"`, "manifest": `"apex_manifest.json"`, }), @@ -211,19 +211,19 @@ apex { } func TestApexBundleSimple_fileContextsIsFile(t *testing.T) { - runApexTestCase(t, bp2buildTestCase{ - description: "apex - file contexts is a file", - moduleTypeUnderTest: "apex", - moduleTypeUnderTestFactory: apex.BundleFactory, - filesystem: map[string]string{}, - blueprint: ` + runApexTestCase(t, Bp2buildTestCase{ + Description: "apex - file contexts is a file", + ModuleTypeUnderTest: "apex", + ModuleTypeUnderTestFactory: apex.BundleFactory, + Filesystem: map[string]string{}, + Blueprint: ` apex { name: "com.android.apogee", file_contexts: "file_contexts_file", } `, - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.android.apogee", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("apex", "com.android.apogee", AttrNameToString{ "file_contexts": `"file_contexts_file"`, "manifest": `"apex_manifest.json"`, }), @@ -231,11 +231,11 @@ apex { } func TestApexBundleSimple_fileContextsIsNotSpecified(t *testing.T) { - runApexTestCase(t, bp2buildTestCase{ - description: "apex - file contexts is not specified", - moduleTypeUnderTest: "apex", - moduleTypeUnderTestFactory: apex.BundleFactory, - filesystem: map[string]string{ + runApexTestCase(t, Bp2buildTestCase{ + Description: "apex - file contexts is not specified", + ModuleTypeUnderTest: "apex", + ModuleTypeUnderTestFactory: apex.BundleFactory, + Filesystem: map[string]string{ "system/sepolicy/apex/Android.bp": ` filegroup { name: "com.android.apogee-file_contexts", @@ -246,13 +246,13 @@ filegroup { } `, }, - blueprint: ` + Blueprint: ` apex { name: "com.android.apogee", } `, - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.android.apogee", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("apex", "com.android.apogee", AttrNameToString{ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, "manifest": `"apex_manifest.json"`, }), @@ -260,11 +260,11 @@ apex { } func TestApexBundleCompileMultilibBoth(t *testing.T) { - runApexTestCase(t, bp2buildTestCase{ - description: "apex - example with compile_multilib=both", - moduleTypeUnderTest: "apex", - moduleTypeUnderTestFactory: apex.BundleFactory, - filesystem: map[string]string{ + runApexTestCase(t, Bp2buildTestCase{ + Description: "apex - example with compile_multilib=both", + ModuleTypeUnderTest: "apex", + ModuleTypeUnderTestFactory: apex.BundleFactory, + Filesystem: map[string]string{ "system/sepolicy/apex/Android.bp": ` filegroup { name: "com.android.apogee-file_contexts", @@ -273,9 +273,9 @@ filegroup { } `, }, - blueprint: createMultilibBlueprint("both"), - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.android.apogee", attrNameToString{ + Blueprint: createMultilibBlueprint("both"), + ExpectedBazelTargets: []string{ + makeBazelTarget("apex", "com.android.apogee", AttrNameToString{ "native_shared_libs_32": `[ ":native_shared_lib_1", ":native_shared_lib_3", @@ -304,11 +304,11 @@ filegroup { } func TestApexBundleCompileMultilibFirst(t *testing.T) { - runApexTestCase(t, bp2buildTestCase{ - description: "apex - example with compile_multilib=first", - moduleTypeUnderTest: "apex", - moduleTypeUnderTestFactory: apex.BundleFactory, - filesystem: map[string]string{ + runApexTestCase(t, Bp2buildTestCase{ + Description: "apex - example with compile_multilib=first", + ModuleTypeUnderTest: "apex", + ModuleTypeUnderTestFactory: apex.BundleFactory, + Filesystem: map[string]string{ "system/sepolicy/apex/Android.bp": ` filegroup { name: "com.android.apogee-file_contexts", @@ -317,9 +317,9 @@ filegroup { } `, }, - blueprint: createMultilibBlueprint("first"), - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.android.apogee", attrNameToString{ + Blueprint: createMultilibBlueprint("first"), + ExpectedBazelTargets: []string{ + makeBazelTarget("apex", "com.android.apogee", AttrNameToString{ "native_shared_libs_32": `select({ "//build/bazel/platforms/arch:arm": [ ":native_shared_lib_1", @@ -353,11 +353,11 @@ filegroup { } func TestApexBundleCompileMultilib32(t *testing.T) { - runApexTestCase(t, bp2buildTestCase{ - description: "apex - example with compile_multilib=32", - moduleTypeUnderTest: "apex", - moduleTypeUnderTestFactory: apex.BundleFactory, - filesystem: map[string]string{ + runApexTestCase(t, Bp2buildTestCase{ + Description: "apex - example with compile_multilib=32", + ModuleTypeUnderTest: "apex", + ModuleTypeUnderTestFactory: apex.BundleFactory, + Filesystem: map[string]string{ "system/sepolicy/apex/Android.bp": ` filegroup { name: "com.android.apogee-file_contexts", @@ -366,9 +366,9 @@ filegroup { } `, }, - blueprint: createMultilibBlueprint("32"), - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.android.apogee", attrNameToString{ + Blueprint: createMultilibBlueprint("32"), + ExpectedBazelTargets: []string{ + makeBazelTarget("apex", "com.android.apogee", AttrNameToString{ "native_shared_libs_32": `[ ":native_shared_lib_1", ":native_shared_lib_3", @@ -384,11 +384,11 @@ filegroup { } func TestApexBundleCompileMultilib64(t *testing.T) { - runApexTestCase(t, bp2buildTestCase{ - description: "apex - example with compile_multilib=64", - moduleTypeUnderTest: "apex", - moduleTypeUnderTestFactory: apex.BundleFactory, - filesystem: map[string]string{ + runApexTestCase(t, Bp2buildTestCase{ + Description: "apex - example with compile_multilib=64", + ModuleTypeUnderTest: "apex", + ModuleTypeUnderTestFactory: apex.BundleFactory, + Filesystem: map[string]string{ "system/sepolicy/apex/Android.bp": ` filegroup { name: "com.android.apogee-file_contexts", @@ -397,9 +397,9 @@ filegroup { } `, }, - blueprint: createMultilibBlueprint("64"), - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.android.apogee", attrNameToString{ + Blueprint: createMultilibBlueprint("64"), + ExpectedBazelTargets: []string{ + makeBazelTarget("apex", "com.android.apogee", AttrNameToString{ "native_shared_libs_64": `select({ "//build/bazel/platforms/arch:arm64": [ ":native_shared_lib_1", @@ -420,11 +420,11 @@ filegroup { } func TestApexBundleDefaultPropertyValues(t *testing.T) { - runApexTestCase(t, bp2buildTestCase{ - description: "apex - default property values", - moduleTypeUnderTest: "apex", - moduleTypeUnderTestFactory: apex.BundleFactory, - filesystem: map[string]string{ + runApexTestCase(t, Bp2buildTestCase{ + Description: "apex - default property values", + ModuleTypeUnderTest: "apex", + ModuleTypeUnderTestFactory: apex.BundleFactory, + Filesystem: map[string]string{ "system/sepolicy/apex/Android.bp": ` filegroup { name: "com.android.apogee-file_contexts", @@ -433,13 +433,13 @@ filegroup { } `, }, - blueprint: ` + Blueprint: ` apex { name: "com.android.apogee", manifest: "apogee_manifest.json", } `, - expectedBazelTargets: []string{makeBazelTarget("apex", "com.android.apogee", attrNameToString{ + ExpectedBazelTargets: []string{makeBazelTarget("apex", "com.android.apogee", AttrNameToString{ "manifest": `"apogee_manifest.json"`, "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, }), @@ -447,11 +447,11 @@ apex { } func TestApexBundleHasBazelModuleProps(t *testing.T) { - runApexTestCase(t, bp2buildTestCase{ - description: "apex - has bazel module props", - moduleTypeUnderTest: "apex", - moduleTypeUnderTestFactory: apex.BundleFactory, - filesystem: map[string]string{ + runApexTestCase(t, Bp2buildTestCase{ + Description: "apex - has bazel module props", + ModuleTypeUnderTest: "apex", + ModuleTypeUnderTestFactory: apex.BundleFactory, + Filesystem: map[string]string{ "system/sepolicy/apex/Android.bp": ` filegroup { name: "apogee-file_contexts", @@ -460,14 +460,14 @@ filegroup { } `, }, - blueprint: ` + Blueprint: ` apex { name: "apogee", manifest: "manifest.json", bazel_module: { bp2build_available: true }, } `, - expectedBazelTargets: []string{makeBazelTarget("apex", "apogee", attrNameToString{ + ExpectedBazelTargets: []string{makeBazelTarget("apex", "apogee", AttrNameToString{ "manifest": `"manifest.json"`, "file_contexts": `"//system/sepolicy/apex:apogee-file_contexts"`, }), @@ -525,12 +525,12 @@ apex { } func TestBp2BuildOverrideApex(t *testing.T) { - runOverrideApexTestCase(t, bp2buildTestCase{ - description: "override_apex", - moduleTypeUnderTest: "override_apex", - moduleTypeUnderTestFactory: apex.OverrideApexFactory, - filesystem: map[string]string{}, - blueprint: ` + runOverrideApexTestCase(t, Bp2buildTestCase{ + Description: "override_apex", + ModuleTypeUnderTest: "override_apex", + ModuleTypeUnderTestFactory: apex.OverrideApexFactory, + Filesystem: map[string]string{}, + Blueprint: ` apex_key { name: "com.android.apogee.key", public_key: "com.android.apogee.avbpubkey", @@ -623,8 +623,8 @@ override_apex { compressible: true, } `, - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ "android_manifest": `"ApogeeAndroidManifest.xml"`, "binaries": `[ ":cc_binary_1", @@ -659,11 +659,11 @@ override_apex { } func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) { - runOverrideApexTestCase(t, bp2buildTestCase{ - description: "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp", - moduleTypeUnderTest: "override_apex", - moduleTypeUnderTestFactory: apex.OverrideApexFactory, - filesystem: map[string]string{ + runOverrideApexTestCase(t, Bp2buildTestCase{ + Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp", + ModuleTypeUnderTest: "override_apex", + ModuleTypeUnderTestFactory: apex.OverrideApexFactory, + Filesystem: map[string]string{ "system/sepolicy/apex/Android.bp": ` filegroup { name: "com.android.apogee-file_contexts", @@ -677,14 +677,14 @@ apex { } `, }, - blueprint: ` + Blueprint: ` override_apex { name: "com.google.android.apogee", base: ":com.android.apogee", } `, - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, "manifest": `"//a/b:apex_manifest.json"`, }), @@ -692,11 +692,11 @@ override_apex { } func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) { - runOverrideApexTestCase(t, bp2buildTestCase{ - description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp", - moduleTypeUnderTest: "override_apex", - moduleTypeUnderTestFactory: apex.OverrideApexFactory, - filesystem: map[string]string{ + runOverrideApexTestCase(t, Bp2buildTestCase{ + Description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp", + ModuleTypeUnderTest: "override_apex", + ModuleTypeUnderTestFactory: apex.OverrideApexFactory, + Filesystem: map[string]string{ "system/sepolicy/apex/Android.bp": ` filegroup { name: "com.android.apogee-file_contexts", @@ -711,14 +711,14 @@ apex { } `, }, - blueprint: ` + Blueprint: ` override_apex { name: "com.google.android.apogee", base: ":com.android.apogee", } `, - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, "manifest": `"//a/b:apogee_manifest.json"`, }), @@ -726,11 +726,11 @@ override_apex { } func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) { - runOverrideApexTestCase(t, bp2buildTestCase{ - description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp", - moduleTypeUnderTest: "override_apex", - moduleTypeUnderTestFactory: apex.OverrideApexFactory, - filesystem: map[string]string{ + runOverrideApexTestCase(t, Bp2buildTestCase{ + Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp", + ModuleTypeUnderTest: "override_apex", + ModuleTypeUnderTestFactory: apex.OverrideApexFactory, + Filesystem: map[string]string{ "system/sepolicy/apex/Android.bp": ` filegroup { name: "com.android.apogee-file_contexts", @@ -738,7 +738,7 @@ filegroup { bazel_module: { bp2build_available: false }, }`, }, - blueprint: ` + Blueprint: ` apex { name: "com.android.apogee", bazel_module: { bp2build_available: false }, @@ -749,8 +749,8 @@ override_apex { base: ":com.android.apogee", } `, - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, "manifest": `"apex_manifest.json"`, }), @@ -758,11 +758,11 @@ override_apex { } func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) { - runOverrideApexTestCase(t, bp2buildTestCase{ - description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp", - moduleTypeUnderTest: "override_apex", - moduleTypeUnderTestFactory: apex.OverrideApexFactory, - filesystem: map[string]string{ + runOverrideApexTestCase(t, Bp2buildTestCase{ + Description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp", + ModuleTypeUnderTest: "override_apex", + ModuleTypeUnderTestFactory: apex.OverrideApexFactory, + Filesystem: map[string]string{ "system/sepolicy/apex/Android.bp": ` filegroup { name: "com.android.apogee-file_contexts", @@ -770,7 +770,7 @@ filegroup { bazel_module: { bp2build_available: false }, }`, }, - blueprint: ` + Blueprint: ` apex { name: "com.android.apogee", manifest: "apogee_manifest.json", @@ -782,8 +782,8 @@ override_apex { base: ":com.android.apogee", } `, - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, "manifest": `"apogee_manifest.json"`, }), @@ -791,11 +791,11 @@ override_apex { } 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{ + 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", @@ -803,7 +803,7 @@ filegroup { bazel_module: { bp2build_available: false }, }`, }, - blueprint: ` + Blueprint: ` apex { name: "com.android.apogee", bazel_module: { bp2build_available: false }, @@ -815,8 +815,8 @@ override_apex { package_name: "com.google.android.apogee", } `, - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ + 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"`, @@ -825,11 +825,11 @@ override_apex { } func TestApexBundleSimple_NoPrebuiltsOverride(t *testing.T) { - runOverrideApexTestCase(t, bp2buildTestCase{ - description: "override_apex - no override", - moduleTypeUnderTest: "override_apex", - moduleTypeUnderTestFactory: apex.OverrideApexFactory, - filesystem: map[string]string{ + 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", @@ -837,7 +837,7 @@ filegroup { bazel_module: { bp2build_available: false }, }`, }, - blueprint: ` + Blueprint: ` prebuilt_etc { name: "prebuilt_file", bazel_module: { bp2build_available: false }, @@ -854,8 +854,8 @@ override_apex { base: ":com.android.apogee", } `, - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ + 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"]`, @@ -864,11 +864,11 @@ override_apex { } func TestApexBundleSimple_PrebuiltsOverride(t *testing.T) { - runOverrideApexTestCase(t, bp2buildTestCase{ - description: "override_apex - ooverride", - moduleTypeUnderTest: "override_apex", - moduleTypeUnderTestFactory: apex.OverrideApexFactory, - filesystem: map[string]string{ + 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", @@ -876,7 +876,7 @@ filegroup { bazel_module: { bp2build_available: false }, }`, }, - blueprint: ` + Blueprint: ` prebuilt_etc { name: "prebuilt_file", bazel_module: { bp2build_available: false }, @@ -899,8 +899,8 @@ override_apex { prebuilts: ["prebuilt_file2"] } `, - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ + 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"]`, @@ -909,11 +909,11 @@ override_apex { } 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{ + 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", @@ -921,7 +921,7 @@ filegroup { bazel_module: { bp2build_available: false }, }`, }, - blueprint: ` + Blueprint: ` prebuilt_etc { name: "prebuilt_file", bazel_module: { bp2build_available: false }, @@ -939,8 +939,8 @@ override_apex { prebuilts: [], } `, - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, "manifest": `"apex_manifest.json"`, "prebuilts": `[]`, @@ -949,11 +949,11 @@ override_apex { } 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{ + 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", @@ -961,7 +961,7 @@ filegroup { bazel_module: { bp2build_available: false }, }`, }, - blueprint: ` + Blueprint: ` apex { name: "com.android.apogee", bazel_module: { bp2build_available: false }, @@ -973,8 +973,8 @@ override_apex { base: ":com.android.apogee", } `, - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ + 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"`, @@ -983,11 +983,11 @@ override_apex { } 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{ + 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", @@ -995,7 +995,7 @@ filegroup { bazel_module: { bp2build_available: false }, }`, }, - blueprint: ` + Blueprint: ` apex { name: "com.android.apogee", bazel_module: { bp2build_available: false }, @@ -1008,8 +1008,8 @@ override_apex { logging_parent: "foo.bar.baz.override", } `, - expectedBazelTargets: []string{ - makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ + 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 dfa96a290..15bccf742 100644 --- a/bp2build/apex_key_conversion_test.go +++ b/bp2build/apex_key_conversion_test.go @@ -21,28 +21,28 @@ import ( "testing" ) -func runApexKeyTestCase(t *testing.T, tc bp2buildTestCase) { +func runApexKeyTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - runBp2BuildTestCase(t, registerApexKeyModuleTypes, tc) + RunBp2BuildTestCase(t, registerApexKeyModuleTypes, tc) } func registerApexKeyModuleTypes(ctx android.RegistrationContext) { } func TestApexKeySimple(t *testing.T) { - runApexKeyTestCase(t, bp2buildTestCase{ - description: "apex key - simple example", - moduleTypeUnderTest: "apex_key", - moduleTypeUnderTestFactory: apex.ApexKeyFactory, - filesystem: map[string]string{}, - blueprint: ` + runApexKeyTestCase(t, Bp2buildTestCase{ + Description: "apex key - simple example", + ModuleTypeUnderTest: "apex_key", + ModuleTypeUnderTestFactory: apex.ApexKeyFactory, + Filesystem: map[string]string{}, + Blueprint: ` apex_key { name: "com.android.apogee.key", public_key: "com.android.apogee.avbpubkey", private_key: "com.android.apogee.pem", } `, - expectedBazelTargets: []string{makeBazelTargetNoRestrictions("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/bp2build.go b/bp2build/bp2build.go index b0c3899ba..0e3d2a5f9 100644 --- a/bp2build/bp2build.go +++ b/bp2build/bp2build.go @@ -29,7 +29,9 @@ import ( func Codegen(ctx *CodegenContext) CodegenMetrics { // This directory stores BUILD files that could be eventually checked-in. bp2buildDir := android.PathForOutput(ctx, "bp2build") - android.RemoveAllOutputDir(bp2buildDir) + if err := android.RemoveAllOutputDir(bp2buildDir); err != nil { + fmt.Printf("ERROR: Encountered error while cleaning %s: %s", bp2buildDir, err.Error()) + } res, errs := GenerateBazelTargets(ctx, true) if len(errs) > 0 { @@ -40,7 +42,7 @@ func Codegen(ctx *CodegenContext) CodegenMetrics { fmt.Printf("ERROR: Encountered %d error(s): \nERROR: %s", len(errs), strings.Join(errMsgs, "\n")) os.Exit(1) } - bp2buildFiles := CreateBazelFiles(nil, res.buildFileToTargets, ctx.mode) + bp2buildFiles := CreateBazelFiles(ctx.Config(), nil, res.buildFileToTargets, ctx.mode) writeFiles(ctx, bp2buildDir, bp2buildFiles) soongInjectionDir := android.PathForOutput(ctx, bazel.SoongInjectionDirName) @@ -52,7 +54,9 @@ func Codegen(ctx *CodegenContext) CodegenMetrics { // Get the output directory and create it if it doesn't exist. func getOrCreateOutputDir(outputDir android.OutputPath, ctx android.PathContext, dir string) android.OutputPath { dirPath := outputDir.Join(ctx, dir) - android.CreateOutputDirIfNonexistent(dirPath, os.ModePerm) + if err := android.CreateOutputDirIfNonexistent(dirPath, os.ModePerm); err != nil { + fmt.Printf("ERROR: path %s: %s", dirPath, err.Error()) + } return dirPath } @@ -60,13 +64,13 @@ func getOrCreateOutputDir(outputDir android.OutputPath, ctx android.PathContext, func writeFiles(ctx android.PathContext, outputDir android.OutputPath, files []BazelFile) { for _, f := range files { p := getOrCreateOutputDir(outputDir, ctx, f.Dir).Join(ctx, f.Basename) - if err := writeFile(ctx, p, f.Contents); err != nil { + if err := writeFile(p, f.Contents); err != nil { panic(fmt.Errorf("Failed to write %q (dir %q) due to %q", f.Basename, f.Dir, err)) } } } -func writeFile(ctx android.PathContext, pathToFile android.OutputPath, content string) error { +func writeFile(pathToFile android.OutputPath, content string) error { // These files are made editable to allow users to modify and iterate on them // in the source tree. return android.WriteFileToOutputDir(pathToFile, []byte(content), 0644) diff --git a/bp2build/build_conversion.go b/bp2build/build_conversion.go index a96a3fc7b..242ea1e69 100644 --- a/bp2build/build_conversion.go +++ b/bp2build/build_conversion.go @@ -161,22 +161,22 @@ type CodegenContext struct { unconvertedDepMode unconvertedDepsMode } -func (c *CodegenContext) Mode() CodegenMode { - return c.mode +func (ctx *CodegenContext) Mode() CodegenMode { + return ctx.mode } // CodegenMode is an enum to differentiate code-generation modes. type CodegenMode int const ( - // Bp2Build: generate BUILD files with targets buildable by Bazel directly. + // Bp2Build - generate BUILD files with targets buildable by Bazel directly. // // This mode is used for the Soong->Bazel build definition conversion. Bp2Build CodegenMode = iota - // QueryView: generate BUILD files with targets representing fully mutated + // QueryView - generate BUILD files with targets representing fully mutated // Soong modules, representing the fully configured Soong module graph with - // variants and dependency endges. + // variants and dependency edges. // // This mode is used for discovering and introspecting the existing Soong // module graph. @@ -320,7 +320,8 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (convers // Handle modules with unconverted deps. By default, emit a warning. if unconvertedDeps := aModule.GetUnconvertedBp2buildDeps(); len(unconvertedDeps) > 0 { - msg := fmt.Sprintf("%q depends on unconverted modules: %s", m.Name(), strings.Join(unconvertedDeps, ", ")) + msg := fmt.Sprintf("%s %s:%s depends on unconverted modules: %s", + moduleType, bpCtx.ModuleDir(m), m.Name(), strings.Join(unconvertedDeps, ", ")) if ctx.unconvertedDepMode == warnUnconvertedDeps { metrics.moduleWithUnconvertedDepsMsgs = append(metrics.moduleWithUnconvertedDepsMsgs, msg) } else if ctx.unconvertedDepMode == errorModulesUnconvertedDeps { @@ -329,7 +330,8 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (convers } } if unconvertedDeps := aModule.GetMissingBp2buildDeps(); len(unconvertedDeps) > 0 { - msg := fmt.Sprintf("%q depends on missing modules: %s", m.Name(), strings.Join(unconvertedDeps, ", ")) + msg := fmt.Sprintf("%s %s:%s depends on missing modules: %s", + moduleType, bpCtx.ModuleDir(m), m.Name(), strings.Join(unconvertedDeps, ", ")) if ctx.unconvertedDepMode == warnUnconvertedDeps { metrics.moduleWithMissingDepsMsgs = append(metrics.moduleWithMissingDepsMsgs, msg) } else if ctx.unconvertedDepMode == errorModulesUnconvertedDeps { @@ -470,13 +472,13 @@ func generateSoongModuleTarget(ctx bpToBuildContext, m blueprint.Module) BazelTa }) } - for p, _ := range ignoredPropNames { + for p := range ignoredPropNames { delete(props.Attrs, p) } attributes := propsToAttributes(props.Attrs) depLabelList := "[\n" - for depLabel, _ := range depLabels { + for depLabel := range depLabels { depLabelList += fmt.Sprintf(" %q,\n", depLabel) } depLabelList += " ]" diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go index 19209f634..c5644ed2d 100644 --- a/bp2build/build_conversion_test.go +++ b/bp2build/build_conversion_test.go @@ -229,30 +229,30 @@ func TestGenerateSoongModuleTargets(t *testing.T) { } func TestGenerateBazelTargetModules(t *testing.T) { - testCases := []bp2buildTestCase{ + testCases := []Bp2buildTestCase{ { - description: "string ptr props", - blueprint: `custom { + Description: "string ptr props", + Blueprint: `custom { name: "foo", string_ptr_prop: "", bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("custom", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("custom", "foo", AttrNameToString{ "string_ptr_prop": `""`, }), }, }, { - description: "string props", - blueprint: `custom { + Description: "string props", + Blueprint: `custom { name: "foo", string_list_prop: ["a", "b"], string_ptr_prop: "a", bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("custom", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("custom", "foo", AttrNameToString{ "string_list_prop": `[ "a", "b", @@ -262,15 +262,15 @@ func TestGenerateBazelTargetModules(t *testing.T) { }, }, { - description: "control characters", - blueprint: `custom { + Description: "control characters", + Blueprint: `custom { name: "foo", string_list_prop: ["\t", "\n"], string_ptr_prop: "a\t\n\r", bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("custom", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("custom", "foo", AttrNameToString{ "string_list_prop": `[ "\t", "\n", @@ -280,8 +280,8 @@ func TestGenerateBazelTargetModules(t *testing.T) { }, }, { - description: "handles dep", - blueprint: `custom { + Description: "handles dep", + Blueprint: `custom { name: "has_dep", arch_paths: [":dep"], bazel_module: { bp2build_available: true }, @@ -292,31 +292,31 @@ custom { arch_paths: ["abc"], bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("custom", "dep", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("custom", "dep", AttrNameToString{ "arch_paths": `["abc"]`, }), - makeBazelTarget("custom", "has_dep", attrNameToString{ + makeBazelTarget("custom", "has_dep", AttrNameToString{ "arch_paths": `[":dep"]`, }), }, }, { - description: "non-existent dep", - blueprint: `custom { + Description: "non-existent dep", + Blueprint: `custom { name: "has_dep", arch_paths: [":dep"], bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("custom", "has_dep", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("custom", "has_dep", AttrNameToString{ "arch_paths": `[":dep__BP2BUILD__MISSING__DEP"]`, }), }, }, { - description: "arch-variant srcs", - blueprint: `custom { + Description: "arch-variant srcs", + Blueprint: `custom { name: "arch_paths", arch: { x86: { arch_paths: ["x86.txt"] }, @@ -344,8 +344,8 @@ custom { }, bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("custom", "arch_paths", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("custom", "arch_paths", AttrNameToString{ "arch_paths": `select({ "//build/bazel/platforms/arch:arm": [ "arm.txt", @@ -406,8 +406,8 @@ custom { }, }, { - description: "arch-variant deps", - blueprint: `custom { + Description: "arch-variant deps", + Blueprint: `custom { name: "has_dep", arch: { x86: { @@ -422,11 +422,11 @@ custom { arch_paths: ["abc"], bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("custom", "dep", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("custom", "dep", AttrNameToString{ "arch_paths": `["abc"]`, }), - makeBazelTarget("custom", "has_dep", attrNameToString{ + makeBazelTarget("custom", "has_dep", AttrNameToString{ "arch_paths": `select({ "//build/bazel/platforms/arch:x86": [":dep"], "//conditions:default": [], @@ -435,27 +435,27 @@ custom { }, }, { - description: "embedded props", - blueprint: `custom { + Description: "embedded props", + Blueprint: `custom { name: "embedded_props", embedded_prop: "abc", bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("custom", "embedded_props", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("custom", "embedded_props", AttrNameToString{ "embedded_attr": `"abc"`, }), }, }, { - description: "ptr to embedded props", - blueprint: `custom { + Description: "ptr to embedded props", + Blueprint: `custom { name: "ptr_to_embedded_props", other_embedded_prop: "abc", bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("custom", "ptr_to_embedded_props", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("custom", "ptr_to_embedded_props", AttrNameToString{ "other_embedded_attr": `"abc"`, }), }, @@ -464,8 +464,8 @@ custom { dir := "." for _, testCase := range testCases { - t.Run(testCase.description, func(t *testing.T) { - config := android.TestConfig(buildDir, nil, testCase.blueprint, nil) + t.Run(testCase.Description, func(t *testing.T) { + config := android.TestConfig(buildDir, nil, testCase.Blueprint, nil) ctx := android.NewTestContext(config) registerCustomModuleForBp2buildConversion(ctx) @@ -483,10 +483,10 @@ custom { bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir) android.FailIfErrored(t, err) - if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount { - t.Errorf("Expected %d bazel target (%s),\ngot %d (%s)", expectedCount, testCase.expectedBazelTargets, actualCount, bazelTargets) + if actualCount, expectedCount := len(bazelTargets), len(testCase.ExpectedBazelTargets); actualCount != expectedCount { + t.Errorf("Expected %d bazel target (%s),\ngot %d (%s)", expectedCount, testCase.ExpectedBazelTargets, actualCount, bazelTargets) } else { - for i, expectedBazelTarget := range testCase.expectedBazelTargets { + for i, expectedBazelTarget := range testCase.ExpectedBazelTargets { actualBazelTarget := bazelTargets[i] if actualBazelTarget.content != expectedBazelTarget { t.Errorf( @@ -502,83 +502,83 @@ custom { } func TestBp2buildHostAndDevice(t *testing.T) { - testCases := []bp2buildTestCase{ + testCases := []Bp2buildTestCase{ { - description: "host and device, device only", - moduleTypeUnderTest: "custom", - moduleTypeUnderTestFactory: customModuleFactoryHostAndDevice, - blueprint: `custom { + 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), + ExpectedBazelTargets: []string{ + makeBazelTargetHostOrDevice("custom", "foo", AttrNameToString{}, android.DeviceSupported), }, }, { - description: "host and device, both", - moduleTypeUnderTest: "custom", - moduleTypeUnderTestFactory: customModuleFactoryHostAndDevice, - blueprint: `custom { + 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{}), + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("custom", "foo", AttrNameToString{}), }, }, { - description: "host and device, host explicitly disabled", - moduleTypeUnderTest: "custom", - moduleTypeUnderTestFactory: customModuleFactoryHostAndDevice, - blueprint: `custom { + 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), + ExpectedBazelTargets: []string{ + makeBazelTargetHostOrDevice("custom", "foo", AttrNameToString{}, android.DeviceSupported), }, }, { - description: "host and device, neither", - moduleTypeUnderTest: "custom", - moduleTypeUnderTestFactory: customModuleFactoryHostAndDevice, - blueprint: `custom { + 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{ + 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 { + 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{ + 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 { + Description: "host and device, both, disabled overrided with product_var", + ModuleTypeUnderTest: "custom", + ModuleTypeUnderTestFactory: customModuleFactoryHostAndDevice, + Blueprint: `custom { name: "foo", host_supported: true, device_supported: true, @@ -586,117 +586,117 @@ func TestBp2buildHostAndDevice(t *testing.T) { product_variables: { unbundled_build: { enabled: true } }, bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("custom", "foo", attrNameToString{ + 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 { + 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{ + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("custom", "foo", AttrNameToString{ "target_compatible_with": `["@platforms//:incompatible"]`, }), }, }, { - description: "host and device, host only", - moduleTypeUnderTest: "custom", - moduleTypeUnderTestFactory: customModuleFactoryHostAndDevice, - blueprint: `custom { + 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), + ExpectedBazelTargets: []string{ + makeBazelTargetHostOrDevice("custom", "foo", AttrNameToString{}, android.HostSupported), }, }, { - description: "host only", - moduleTypeUnderTest: "custom", - moduleTypeUnderTestFactory: customModuleFactoryHostSupported, - blueprint: `custom { + Description: "host only", + ModuleTypeUnderTest: "custom", + ModuleTypeUnderTestFactory: customModuleFactoryHostSupported, + Blueprint: `custom { name: "foo", bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTargetHostOrDevice("custom", "foo", attrNameToString{}, android.HostSupported), + ExpectedBazelTargets: []string{ + makeBazelTargetHostOrDevice("custom", "foo", AttrNameToString{}, android.HostSupported), }, }, { - description: "device only", - moduleTypeUnderTest: "custom", - moduleTypeUnderTestFactory: customModuleFactoryDeviceSupported, - blueprint: `custom { + Description: "device only", + ModuleTypeUnderTest: "custom", + ModuleTypeUnderTestFactory: customModuleFactoryDeviceSupported, + Blueprint: `custom { name: "foo", bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTargetHostOrDevice("custom", "foo", attrNameToString{}, android.DeviceSupported), + ExpectedBazelTargets: []string{ + makeBazelTargetHostOrDevice("custom", "foo", AttrNameToString{}, android.DeviceSupported), }, }, { - description: "host and device default, default", - moduleTypeUnderTest: "custom", - moduleTypeUnderTestFactory: customModuleFactoryHostAndDeviceDefault, - blueprint: `custom { + 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{}), + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("custom", "foo", AttrNameToString{}), }, }, { - description: "host and device default, device only", - moduleTypeUnderTest: "custom", - moduleTypeUnderTestFactory: customModuleFactoryHostAndDeviceDefault, - blueprint: `custom { + 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), + ExpectedBazelTargets: []string{ + makeBazelTargetHostOrDevice("custom", "foo", AttrNameToString{}, android.DeviceSupported), }, }, { - description: "host and device default, host only", - moduleTypeUnderTest: "custom", - moduleTypeUnderTestFactory: customModuleFactoryHostAndDeviceDefault, - blueprint: `custom { + 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), + ExpectedBazelTargets: []string{ + makeBazelTargetHostOrDevice("custom", "foo", AttrNameToString{}, android.HostSupported), }, }, { - description: "host and device default, neither", - moduleTypeUnderTest: "custom", - moduleTypeUnderTestFactory: customModuleFactoryHostAndDeviceDefault, - blueprint: `custom { + 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{ + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("custom", "foo", AttrNameToString{ "target_compatible_with": `["@platforms//:incompatible"]`, }), }, @@ -704,7 +704,7 @@ func TestBp2buildHostAndDevice(t *testing.T) { } for _, tc := range testCases { - t.Run(tc.description, func(t *testing.T) { + t.Run(tc.Description, func(t *testing.T) { runBp2BuildTestCaseSimple(t, tc) }) } @@ -880,43 +880,43 @@ load("//build/bazel/rules:rules.bzl", "my_library")`, } func TestModuleTypeBp2Build(t *testing.T) { - testCases := []bp2buildTestCase{ + testCases := []Bp2buildTestCase{ { - description: "filegroup with does not specify srcs", - moduleTypeUnderTest: "filegroup", - moduleTypeUnderTestFactory: android.FileGroupFactory, - blueprint: `filegroup { + Description: "filegroup with does not specify srcs", + ModuleTypeUnderTest: "filegroup", + ModuleTypeUnderTestFactory: android.FileGroupFactory, + Blueprint: `filegroup { name: "fg_foo", bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{}), + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{}), }, }, { - description: "filegroup with no srcs", - moduleTypeUnderTest: "filegroup", - moduleTypeUnderTestFactory: android.FileGroupFactory, - blueprint: `filegroup { + Description: "filegroup with no srcs", + ModuleTypeUnderTest: "filegroup", + ModuleTypeUnderTestFactory: android.FileGroupFactory, + Blueprint: `filegroup { name: "fg_foo", srcs: [], bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{}), + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{}), }, }, { - description: "filegroup with srcs", - moduleTypeUnderTest: "filegroup", - moduleTypeUnderTestFactory: android.FileGroupFactory, - blueprint: `filegroup { + Description: "filegroup with srcs", + ModuleTypeUnderTest: "filegroup", + ModuleTypeUnderTestFactory: android.FileGroupFactory, + Blueprint: `filegroup { name: "fg_foo", srcs: ["a", "b"], bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ "srcs": `[ "a", "b", @@ -925,32 +925,32 @@ func TestModuleTypeBp2Build(t *testing.T) { }, }, { - description: "filegroup with excludes srcs", - moduleTypeUnderTest: "filegroup", - moduleTypeUnderTestFactory: android.FileGroupFactory, - blueprint: `filegroup { + Description: "filegroup with excludes srcs", + ModuleTypeUnderTest: "filegroup", + ModuleTypeUnderTestFactory: android.FileGroupFactory, + Blueprint: `filegroup { name: "fg_foo", srcs: ["a", "b"], exclude_srcs: ["a"], bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ "srcs": `["b"]`, }), }, }, { - description: "filegroup with glob", - moduleTypeUnderTest: "filegroup", - moduleTypeUnderTestFactory: android.FileGroupFactory, - blueprint: `filegroup { + Description: "filegroup with glob", + ModuleTypeUnderTest: "filegroup", + ModuleTypeUnderTestFactory: android.FileGroupFactory, + Blueprint: `filegroup { name: "fg_foo", srcs: ["**/*.txt"], bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ "srcs": `[ "other/a.txt", "other/b.txt", @@ -958,7 +958,7 @@ func TestModuleTypeBp2Build(t *testing.T) { ]`, }), }, - filesystem: map[string]string{ + Filesystem: map[string]string{ "other/a.txt": "", "other/b.txt": "", "other/subdir/a.txt": "", @@ -966,11 +966,11 @@ func TestModuleTypeBp2Build(t *testing.T) { }, }, { - description: "filegroup with glob in subdir", - moduleTypeUnderTest: "filegroup", - moduleTypeUnderTestFactory: android.FileGroupFactory, - dir: "other", - filesystem: map[string]string{ + Description: "filegroup with glob in subdir", + ModuleTypeUnderTest: "filegroup", + ModuleTypeUnderTestFactory: android.FileGroupFactory, + Dir: "other", + Filesystem: map[string]string{ "other/Android.bp": `filegroup { name: "fg_foo", srcs: ["**/*.txt"], @@ -981,8 +981,8 @@ func TestModuleTypeBp2Build(t *testing.T) { "other/subdir/a.txt": "", "other/file": "", }, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ "srcs": `[ "a.txt", "b.txt", @@ -992,10 +992,10 @@ func TestModuleTypeBp2Build(t *testing.T) { }, }, { - description: "depends_on_other_dir_module", - moduleTypeUnderTest: "filegroup", - moduleTypeUnderTestFactory: android.FileGroupFactory, - blueprint: `filegroup { + Description: "depends_on_other_dir_module", + ModuleTypeUnderTest: "filegroup", + ModuleTypeUnderTestFactory: android.FileGroupFactory, + Blueprint: `filegroup { name: "fg_foo", srcs: [ ":foo", @@ -1003,15 +1003,15 @@ func TestModuleTypeBp2Build(t *testing.T) { ], bazel_module: { bp2build_available: true }, }`, - filesystem: map[string]string{ + Filesystem: map[string]string{ "other/Android.bp": `filegroup { name: "foo", srcs: ["a", "b"], bazel_module: { bp2build_available: true }, }`, }, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ "srcs": `[ "//other:foo", "c", @@ -1020,11 +1020,11 @@ func TestModuleTypeBp2Build(t *testing.T) { }, }, { - description: "depends_on_other_unconverted_module_error", - moduleTypeUnderTest: "filegroup", - moduleTypeUnderTestFactory: android.FileGroupFactory, - unconvertedDepsMode: errorModulesUnconvertedDeps, - blueprint: `filegroup { + Description: "depends_on_other_unconverted_module_error", + ModuleTypeUnderTest: "filegroup", + ModuleTypeUnderTestFactory: android.FileGroupFactory, + UnconvertedDepsMode: errorModulesUnconvertedDeps, + Blueprint: `filegroup { name: "foobar", srcs: [ ":foo", @@ -1032,8 +1032,8 @@ func TestModuleTypeBp2Build(t *testing.T) { ], bazel_module: { bp2build_available: true }, }`, - expectedErr: fmt.Errorf(`"foobar" depends on unconverted modules: foo`), - filesystem: map[string]string{ + ExpectedErr: fmt.Errorf(`filegroup .:foobar depends on unconverted modules: foo`), + Filesystem: map[string]string{ "other/Android.bp": `filegroup { name: "foo", srcs: ["a", "b"], @@ -1043,8 +1043,8 @@ func TestModuleTypeBp2Build(t *testing.T) { } for _, testCase := range testCases { - t.Run(testCase.description, func(t *testing.T) { - runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, testCase) + t.Run(testCase.Description, func(t *testing.T) { + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, testCase) }) } } @@ -1244,27 +1244,27 @@ filegroup { name: "opt-out-h", bazel_module: { bp2build_available: false } } } func TestCombineBuildFilesBp2buildTargets(t *testing.T) { - testCases := []bp2buildTestCase{ + testCases := []Bp2buildTestCase{ { - description: "filegroup bazel_module.label", - moduleTypeUnderTest: "filegroup", - moduleTypeUnderTestFactory: android.FileGroupFactory, - blueprint: `filegroup { + Description: "filegroup bazel_module.label", + ModuleTypeUnderTest: "filegroup", + ModuleTypeUnderTestFactory: android.FileGroupFactory, + Blueprint: `filegroup { name: "fg_foo", bazel_module: { label: "//other:fg_foo" }, }`, - expectedBazelTargets: []string{ + ExpectedBazelTargets: []string{ `// BUILD file`, }, - filesystem: map[string]string{ + Filesystem: map[string]string{ "other/BUILD.bazel": `// BUILD file`, }, }, { - description: "multiple bazel_module.label same BUILD", - moduleTypeUnderTest: "filegroup", - moduleTypeUnderTestFactory: android.FileGroupFactory, - blueprint: `filegroup { + Description: "multiple bazel_module.label same BUILD", + ModuleTypeUnderTest: "filegroup", + ModuleTypeUnderTestFactory: android.FileGroupFactory, + Blueprint: `filegroup { name: "fg_foo", bazel_module: { label: "//other:fg_foo" }, } @@ -1273,20 +1273,20 @@ func TestCombineBuildFilesBp2buildTargets(t *testing.T) { name: "foo", bazel_module: { label: "//other:foo" }, }`, - expectedBazelTargets: []string{ + ExpectedBazelTargets: []string{ `// BUILD file`, }, - filesystem: map[string]string{ + Filesystem: map[string]string{ "other/BUILD.bazel": `// BUILD file`, }, }, { - description: "filegroup bazel_module.label and bp2build in subdir", - moduleTypeUnderTest: "filegroup", - moduleTypeUnderTestFactory: android.FileGroupFactory, - dir: "other", - blueprint: ``, - filesystem: map[string]string{ + Description: "filegroup bazel_module.label and bp2build in subdir", + ModuleTypeUnderTest: "filegroup", + ModuleTypeUnderTestFactory: android.FileGroupFactory, + Dir: "other", + Blueprint: ``, + Filesystem: map[string]string{ "other/Android.bp": `filegroup { name: "fg_foo", bazel_module: { @@ -1301,20 +1301,20 @@ func TestCombineBuildFilesBp2buildTargets(t *testing.T) { }`, "other/BUILD.bazel": `// definition for fg_bar`, }, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{}), + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{}), `// definition for fg_bar`, }, }, { - description: "filegroup bazel_module.label and filegroup bp2build", - moduleTypeUnderTest: "filegroup", - moduleTypeUnderTestFactory: android.FileGroupFactory, + Description: "filegroup bazel_module.label and filegroup bp2build", + ModuleTypeUnderTest: "filegroup", + ModuleTypeUnderTestFactory: android.FileGroupFactory, - filesystem: map[string]string{ + Filesystem: map[string]string{ "other/BUILD.bazel": `// BUILD file`, }, - blueprint: `filegroup { + Blueprint: `filegroup { name: "fg_foo", bazel_module: { label: "//other:fg_foo", @@ -1327,8 +1327,8 @@ func TestCombineBuildFilesBp2buildTargets(t *testing.T) { bp2build_available: true, }, }`, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("filegroup", "fg_bar", map[string]string{}), + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("filegroup", "fg_bar", map[string]string{}), `// BUILD file`, }, }, @@ -1336,20 +1336,20 @@ func TestCombineBuildFilesBp2buildTargets(t *testing.T) { dir := "." for _, testCase := range testCases { - t.Run(testCase.description, func(t *testing.T) { + t.Run(testCase.Description, func(t *testing.T) { fs := make(map[string][]byte) toParse := []string{ "Android.bp", } - for f, content := range testCase.filesystem { + for f, content := range testCase.Filesystem { if strings.HasSuffix(f, "Android.bp") { toParse = append(toParse, f) } fs[f] = []byte(content) } - config := android.TestConfig(buildDir, nil, testCase.blueprint, fs) + config := android.TestConfig(buildDir, nil, testCase.Blueprint, fs) ctx := android.NewTestContext(config) - ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory) + ctx.RegisterModuleType(testCase.ModuleTypeUnderTest, testCase.ModuleTypeUnderTestFactory) ctx.RegisterForBazelConversion() _, errs := ctx.ParseFileList(dir, toParse) @@ -1362,15 +1362,15 @@ func TestCombineBuildFilesBp2buildTargets(t *testing.T) { } checkDir := dir - if testCase.dir != "" { - checkDir = testCase.dir + if testCase.Dir != "" { + checkDir = testCase.Dir } codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) bazelTargets, err := generateBazelTargetsForDir(codegenCtx, checkDir) android.FailIfErrored(t, err) bazelTargets.sort() actualCount := len(bazelTargets) - expectedCount := len(testCase.expectedBazelTargets) + expectedCount := len(testCase.ExpectedBazelTargets) if actualCount != expectedCount { t.Errorf("Expected %d bazel target, got %d\n%s", expectedCount, actualCount, bazelTargets) } @@ -1379,7 +1379,7 @@ func TestCombineBuildFilesBp2buildTargets(t *testing.T) { } for i, target := range bazelTargets { actualContent := target.content - expectedContent := testCase.expectedBazelTargets[i] + expectedContent := testCase.ExpectedBazelTargets[i] if expectedContent != actualContent { t.Errorf( "Expected generated Bazel target to be '%s', got '%s'", @@ -1393,18 +1393,18 @@ func TestCombineBuildFilesBp2buildTargets(t *testing.T) { } func TestGlobExcludeSrcs(t *testing.T) { - testCases := []bp2buildTestCase{ + testCases := []Bp2buildTestCase{ { - description: "filegroup top level exclude_srcs", - moduleTypeUnderTest: "filegroup", - moduleTypeUnderTestFactory: android.FileGroupFactory, - blueprint: `filegroup { + Description: "filegroup top level exclude_srcs", + ModuleTypeUnderTest: "filegroup", + ModuleTypeUnderTestFactory: android.FileGroupFactory, + Blueprint: `filegroup { name: "fg_foo", srcs: ["**/*.txt"], exclude_srcs: ["c.txt"], bazel_module: { bp2build_available: true }, }`, - filesystem: map[string]string{ + Filesystem: map[string]string{ "a.txt": "", "b.txt": "", "c.txt": "", @@ -1412,8 +1412,8 @@ func TestGlobExcludeSrcs(t *testing.T) { "dir/e.txt": "", "dir/f.txt": "", }, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ "srcs": `[ "a.txt", "b.txt", @@ -1424,12 +1424,12 @@ func TestGlobExcludeSrcs(t *testing.T) { }, }, { - description: "filegroup in subdir exclude_srcs", - moduleTypeUnderTest: "filegroup", - moduleTypeUnderTestFactory: android.FileGroupFactory, - blueprint: "", - dir: "dir", - filesystem: map[string]string{ + Description: "filegroup in subdir exclude_srcs", + ModuleTypeUnderTest: "filegroup", + ModuleTypeUnderTestFactory: android.FileGroupFactory, + Blueprint: "", + Dir: "dir", + Filesystem: map[string]string{ "dir/Android.bp": `filegroup { name: "fg_foo", srcs: ["**/*.txt"], @@ -1443,8 +1443,8 @@ func TestGlobExcludeSrcs(t *testing.T) { "dir/subdir/e.txt": "", "dir/subdir/f.txt": "", }, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ "srcs": `[ "a.txt", "//dir/subdir:e.txt", @@ -1456,35 +1456,35 @@ func TestGlobExcludeSrcs(t *testing.T) { } for _, testCase := range testCases { - t.Run(testCase.description, func(t *testing.T) { + t.Run(testCase.Description, func(t *testing.T) { runBp2BuildTestCaseSimple(t, testCase) }) } } func TestCommonBp2BuildModuleAttrs(t *testing.T) { - testCases := []bp2buildTestCase{ + testCases := []Bp2buildTestCase{ { - description: "Required into data test", - moduleTypeUnderTest: "filegroup", - moduleTypeUnderTestFactory: android.FileGroupFactory, - blueprint: simpleModuleDoNotConvertBp2build("filegroup", "reqd") + ` + Description: "Required into data test", + ModuleTypeUnderTest: "filegroup", + ModuleTypeUnderTestFactory: android.FileGroupFactory, + Blueprint: simpleModuleDoNotConvertBp2build("filegroup", "reqd") + ` filegroup { name: "fg_foo", required: ["reqd"], bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ "data": `[":reqd"]`, }), }, }, { - description: "Required via arch into data test", - moduleTypeUnderTest: "python_library", - moduleTypeUnderTestFactory: python.PythonLibraryFactory, - blueprint: simpleModuleDoNotConvertBp2build("python_library", "reqdx86") + + Description: "Required via arch into data test", + ModuleTypeUnderTest: "python_library", + ModuleTypeUnderTestFactory: python.PythonLibraryFactory, + Blueprint: simpleModuleDoNotConvertBp2build("python_library", "reqdx86") + simpleModuleDoNotConvertBp2build("python_library", "reqdarm") + ` python_library { name: "fg_foo", @@ -1498,7 +1498,7 @@ python_library { }, bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ + ExpectedBazelTargets: []string{ makeBazelTarget("py_library", "fg_foo", map[string]string{ "data": `select({ "//build/bazel/platforms/arch:arm": [":reqdarm"], @@ -1511,21 +1511,21 @@ python_library { }, }, { - description: "Required appended to data test", - moduleTypeUnderTest: "python_library", - moduleTypeUnderTestFactory: python.PythonLibraryFactory, - filesystem: map[string]string{ + Description: "Required appended to data test", + ModuleTypeUnderTest: "python_library", + ModuleTypeUnderTestFactory: python.PythonLibraryFactory, + Filesystem: map[string]string{ "data.bin": "", "src.py": "", }, - blueprint: simpleModuleDoNotConvertBp2build("python_library", "reqd") + ` + Blueprint: simpleModuleDoNotConvertBp2build("python_library", "reqd") + ` python_library { name: "fg_foo", data: ["data.bin"], required: ["reqd"], bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ + ExpectedBazelTargets: []string{ makeBazelTarget("py_library", "fg_foo", map[string]string{ "data": `[ "data.bin", @@ -1537,17 +1537,17 @@ python_library { }, }, { - description: "All props-to-attrs at once together test", - moduleTypeUnderTest: "filegroup", - moduleTypeUnderTestFactory: android.FileGroupFactory, - blueprint: simpleModuleDoNotConvertBp2build("filegroup", "reqd") + ` + Description: "All props-to-attrs at once together test", + ModuleTypeUnderTest: "filegroup", + ModuleTypeUnderTestFactory: android.FileGroupFactory, + Blueprint: simpleModuleDoNotConvertBp2build("filegroup", "reqd") + ` filegroup { name: "fg_foo", required: ["reqd"], bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ "data": `[":reqd"]`, }), }, @@ -1555,7 +1555,7 @@ filegroup { } for _, tc := range testCases { - t.Run(tc.description, func(t *testing.T) { + t.Run(tc.Description, func(t *testing.T) { runBp2BuildTestCaseSimple(t, tc) }) } diff --git a/bp2build/bzl_conversion_test.go b/bp2build/bzl_conversion_test.go index f3345a6ae..6cb9509ed 100644 --- a/bp2build/bzl_conversion_test.go +++ b/bp2build/bzl_conversion_test.go @@ -189,7 +189,7 @@ func TestGenerateSoongModuleBzl(t *testing.T) { content: "irrelevant", }, } - files := CreateBazelFiles(ruleShims, make(map[string]BazelTargets), QueryView) + files := CreateBazelFiles(android.NullConfig("out", "out/soong"), ruleShims, make(map[string]BazelTargets), QueryView) var actualSoongModuleBzl BazelFile for _, f := range files { diff --git a/bp2build/cc_binary_conversion_test.go b/bp2build/cc_binary_conversion_test.go index 4794269e4..95869dd87 100644 --- a/bp2build/cc_binary_conversion_test.go +++ b/bp2build/cc_binary_conversion_test.go @@ -31,7 +31,7 @@ const ( type testBazelTarget struct { typ string name string - attrs attrNameToString + attrs AttrNameToString } func generateBazelTargetsForTest(targets []testBazelTarget, hod android.HostOrDeviceSupported) []string { @@ -73,12 +73,12 @@ func runCcBinaryTestCase(t *testing.T, testCase ccBinaryBp2buildTestCase) { description := fmt.Sprintf("%s %s", moduleTypeUnderTest, testCase.description) t.Run(description, func(t *testing.T) { t.Helper() - runBp2BuildTestCase(t, registerCcBinaryModuleTypes, bp2buildTestCase{ - expectedBazelTargets: generateBazelTargetsForTest(testCase.targets, android.DeviceSupported), - moduleTypeUnderTest: moduleTypeUnderTest, - moduleTypeUnderTestFactory: cc.BinaryFactory, - description: description, - blueprint: binaryReplacer.Replace(testCase.blueprint), + RunBp2BuildTestCase(t, registerCcBinaryModuleTypes, Bp2buildTestCase{ + ExpectedBazelTargets: generateBazelTargetsForTest(testCase.targets, android.DeviceSupported), + ModuleTypeUnderTest: moduleTypeUnderTest, + ModuleTypeUnderTestFactory: cc.BinaryFactory, + Description: description, + Blueprint: binaryReplacer.Replace(testCase.blueprint), }) }) } @@ -88,12 +88,12 @@ func runCcHostBinaryTestCase(t *testing.T, testCase ccBinaryBp2buildTestCase) { moduleTypeUnderTest := "cc_binary_host" description := fmt.Sprintf("%s %s", moduleTypeUnderTest, testCase.description) t.Run(description, func(t *testing.T) { - runBp2BuildTestCase(t, registerCcBinaryModuleTypes, bp2buildTestCase{ - expectedBazelTargets: generateBazelTargetsForTest(testCase.targets, android.HostSupported), - moduleTypeUnderTest: moduleTypeUnderTest, - moduleTypeUnderTestFactory: cc.BinaryHostFactory, - description: description, - blueprint: hostBinaryReplacer.Replace(testCase.blueprint), + RunBp2BuildTestCase(t, registerCcBinaryModuleTypes, Bp2buildTestCase{ + ExpectedBazelTargets: generateBazelTargetsForTest(testCase.targets, android.HostSupported), + ModuleTypeUnderTest: moduleTypeUnderTest, + ModuleTypeUnderTestFactory: cc.BinaryHostFactory, + Description: description, + Blueprint: hostBinaryReplacer.Replace(testCase.blueprint), }) }) } @@ -126,7 +126,7 @@ func TestBasicCcBinary(t *testing.T) { } `, targets: []testBazelTarget{ - {"cc_binary", "foo", attrNameToString{ + {"cc_binary", "foo", AttrNameToString{ "absolute_includes": `["absolute_dir"]`, "asflags": `["-Dasflag"]`, "conlyflags": `["-Dconlyflag"]`, @@ -166,7 +166,7 @@ func TestCcBinaryWithSharedLdflagDisableFeature(t *testing.T) { } `, targets: []testBazelTarget{ - {"cc_binary", "foo", attrNameToString{ + {"cc_binary", "foo", AttrNameToString{ "features": `["-static_flag"]`, "linkopts": `["-shared"]`, }, @@ -186,7 +186,7 @@ func TestCcBinaryWithLinkStatic(t *testing.T) { } `, targets: []testBazelTarget{ - {"cc_binary", "foo", attrNameToString{ + {"cc_binary", "foo", AttrNameToString{ "linkshared": `False`, }, }, @@ -205,7 +205,7 @@ func TestCcBinaryVersionScript(t *testing.T) { } `, targets: []testBazelTarget{ - {"cc_binary", "foo", attrNameToString{ + {"cc_binary", "foo", AttrNameToString{ "additional_linker_inputs": `["vs"]`, "linkopts": `["-Wl,--version-script,$(location vs)"]`, }, @@ -230,7 +230,7 @@ func TestCcBinarySplitSrcsByLang(t *testing.T) { } ` + simpleModuleDoNotConvertBp2build("filegroup", "fg_foo"), targets: []testBazelTarget{ - {"cc_binary", "foo", attrNameToString{ + {"cc_binary", "foo", AttrNameToString{ "srcs": `[ "cpponly.cpp", ":fg_foo_cpp_srcs", @@ -285,7 +285,7 @@ genrule { simpleModuleDoNotConvertBp2build("cc_library", "shared_dep") + simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep"), targets: []testBazelTarget{ - {"cc_binary", "foo", attrNameToString{ + {"cc_binary", "foo", AttrNameToString{ "deps": `[ ":implementation_static_dep", ":static_dep", @@ -314,21 +314,21 @@ func TestCcBinaryNocrtTests(t *testing.T) { baseTestCases := []struct { description string soongProperty string - bazelAttr attrNameToString + bazelAttr AttrNameToString }{ { description: "nocrt: true", soongProperty: `nocrt: true,`, - bazelAttr: attrNameToString{"link_crt": `False`}, + bazelAttr: AttrNameToString{"link_crt": `False`}, }, { description: "nocrt: false", soongProperty: `nocrt: false,`, - bazelAttr: attrNameToString{}, + bazelAttr: AttrNameToString{}, }, { description: "nocrt: not set", - bazelAttr: attrNameToString{}, + bazelAttr: AttrNameToString{}, }, } @@ -357,21 +357,21 @@ func TestCcBinaryNo_libcrtTests(t *testing.T) { baseTestCases := []struct { description string soongProperty string - bazelAttr attrNameToString + bazelAttr AttrNameToString }{ { description: "no_libcrt: true", soongProperty: `no_libcrt: true,`, - bazelAttr: attrNameToString{"use_libcrt": `False`}, + bazelAttr: AttrNameToString{"use_libcrt": `False`}, }, { description: "no_libcrt: false", soongProperty: `no_libcrt: false,`, - bazelAttr: attrNameToString{"use_libcrt": `True`}, + bazelAttr: AttrNameToString{"use_libcrt": `True`}, }, { description: "no_libcrt: not set", - bazelAttr: attrNameToString{}, + bazelAttr: AttrNameToString{}, }, } @@ -400,35 +400,35 @@ func TestCcBinaryPropertiesToFeatures(t *testing.T) { baseTestCases := []struct { description string soongProperty string - bazelAttr attrNameToString + bazelAttr AttrNameToString }{ { description: "pack_relocation: true", soongProperty: `pack_relocations: true,`, - bazelAttr: attrNameToString{}, + bazelAttr: AttrNameToString{}, }, { description: "pack_relocations: false", soongProperty: `pack_relocations: false,`, - bazelAttr: attrNameToString{"features": `["disable_pack_relocations"]`}, + bazelAttr: AttrNameToString{"features": `["disable_pack_relocations"]`}, }, { description: "pack_relocations: not set", - bazelAttr: attrNameToString{}, + bazelAttr: AttrNameToString{}, }, { description: "pack_relocation: true", soongProperty: `allow_undefined_symbols: true,`, - bazelAttr: attrNameToString{"features": `["-no_undefined_symbols"]`}, + bazelAttr: AttrNameToString{"features": `["-no_undefined_symbols"]`}, }, { description: "allow_undefined_symbols: false", soongProperty: `allow_undefined_symbols: false,`, - bazelAttr: attrNameToString{}, + bazelAttr: AttrNameToString{}, }, { description: "allow_undefined_symbols: not set", - bazelAttr: attrNameToString{}, + bazelAttr: AttrNameToString{}, }, } @@ -462,11 +462,11 @@ func TestCcBinarySharedProto(t *testing.T) { include_build_directory: false, }`, targets: []testBazelTarget{ - {"proto_library", "foo_proto", attrNameToString{ + {"proto_library", "foo_proto", AttrNameToString{ "srcs": `["foo.proto"]`, - }}, {"cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + }}, {"cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ "deps": `[":foo_proto"]`, - }}, {"cc_binary", "foo", attrNameToString{ + }}, {"cc_binary", "foo", AttrNameToString{ "dynamic_deps": `[":libprotobuf-cpp-lite"]`, "whole_archive_deps": `[":foo_cc_proto_lite"]`, }}, @@ -485,11 +485,11 @@ func TestCcBinaryStaticProto(t *testing.T) { include_build_directory: false, }`, targets: []testBazelTarget{ - {"proto_library", "foo_proto", attrNameToString{ + {"proto_library", "foo_proto", AttrNameToString{ "srcs": `["foo.proto"]`, - }}, {"cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + }}, {"cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ "deps": `[":foo_proto"]`, - }}, {"cc_binary", "foo", attrNameToString{ + }}, {"cc_binary", "foo", AttrNameToString{ "deps": `[":libprotobuf-cpp-lite"]`, "whole_archive_deps": `[":foo_cc_proto_lite"]`, "linkshared": `False`, @@ -510,7 +510,7 @@ func TestCcBinaryConvertLex(t *testing.T) { } `, targets: []testBazelTarget{ - {"genlex", "foo_genlex_l", attrNameToString{ + {"genlex", "foo_genlex_l", AttrNameToString{ "srcs": `[ "foo1.l", "foo2.l", @@ -520,7 +520,7 @@ func TestCcBinaryConvertLex(t *testing.T) { "--bar_opt", ]`, }}, - {"genlex", "foo_genlex_ll", attrNameToString{ + {"genlex", "foo_genlex_ll", AttrNameToString{ "srcs": `[ "bar1.ll", "bar2.ll", @@ -530,7 +530,7 @@ func TestCcBinaryConvertLex(t *testing.T) { "--bar_opt", ]`, }}, - {"cc_binary", "foo", attrNameToString{ + {"cc_binary", "foo", AttrNameToString{ "srcs": `[ "bar.cc", ":foo_genlex_ll", diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index 2cc2207df..6c56d4188 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -43,9 +43,9 @@ cc_library { soongCcProtoPreamble = soongCcLibraryPreamble + soongCcProtoLibraries ) -func runCcLibraryTestCase(t *testing.T, tc bp2buildTestCase) { +func runCcLibraryTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - runBp2BuildTestCase(t, registerCcLibraryModuleTypes, tc) + RunBp2BuildTestCase(t, registerCcLibraryModuleTypes, tc) } func registerCcLibraryModuleTypes(ctx android.RegistrationContext) { @@ -57,11 +57,11 @@ func registerCcLibraryModuleTypes(ctx android.RegistrationContext) { } func TestCcLibrarySimple(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library - simple example", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library - simple example", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Filesystem: map[string]string{ "android.cpp": "", "bionic.cpp": "", "darwin.cpp": "", @@ -81,7 +81,7 @@ func TestCcLibrarySimple(t *testing.T) { "x86_64.cpp": "", "foo-dir/a.h": "", }, - blueprint: soongCcLibraryPreamble + + Blueprint: soongCcLibraryPreamble + simpleModuleDoNotConvertBp2build("cc_library_headers", "some-headers") + ` cc_library { name: "foo-lib", @@ -120,7 +120,7 @@ cc_library { use_version_lib: true, } `, - expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ "copts": `["-Wall"]`, "export_includes": `["foo-dir"]`, "implementation_deps": `[":some-headers"]`, @@ -151,18 +151,18 @@ cc_library { } func TestCcLibraryTrimmedLdAndroid(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library - trimmed example of //bionic/linker:ld-android", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library - trimmed example of //bionic/linker:ld-android", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Filesystem: map[string]string{ "ld-android.cpp": "", "linked_list.h": "", "linker.h": "", "linker_block_allocator.h": "", "linker_cfi.h": "", }, - blueprint: soongCcLibraryPreamble + + Blueprint: soongCcLibraryPreamble + simpleModuleDoNotConvertBp2build("cc_library_headers", "libc_headers") + ` cc_library { name: "fake-ld-android", @@ -193,7 +193,7 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: makeCcLibraryTargets("fake-ld-android", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("fake-ld-android", AttrNameToString{ "srcs": `["ld_android.cpp"]`, "copts": `[ "-Wall", @@ -219,12 +219,12 @@ cc_library { } func TestCcLibraryExcludeSrcs(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library exclude_srcs - trimmed example of //external/arm-optimized-routines:libarm-optimized-routines-math", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - dir: "external", - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library exclude_srcs - trimmed example of //external/arm-optimized-routines:libarm-optimized-routines-math", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Dir: "external", + Filesystem: map[string]string{ "external/math/cosf.c": "", "external/math/erf.c": "", "external/math/erf_data.c": "", @@ -257,8 +257,8 @@ cc_library { } `, }, - blueprint: soongCcLibraryPreamble, - expectedBazelTargets: makeCcLibraryTargets("fake-libarm-optimized-routines-math", attrNameToString{ + Blueprint: soongCcLibraryPreamble, + ExpectedBazelTargets: makeCcLibraryTargets("fake-libarm-optimized-routines-math", AttrNameToString{ "copts": `select({ "//build/bazel/platforms/arch:arm64": ["-DHAVE_FAST_FMA=1"], "//conditions:default": [], @@ -270,16 +270,16 @@ cc_library { } func TestCcLibrarySharedStaticProps(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library shared/static props", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library shared/static props", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Filesystem: map[string]string{ "both.cpp": "", "sharedonly.cpp": "", "staticonly.cpp": "", }, - blueprint: soongCcLibraryPreamble + ` + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "a", srcs: ["both.cpp"], @@ -354,8 +354,8 @@ cc_library { bazel_module: { bp2build_available: false }, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ "copts": `[ "bothflag", "staticflag", @@ -377,7 +377,7 @@ cc_library { ":whole_and_static_lib_for_both", ":whole_static_lib_for_static", ]`}), - makeBazelTarget("cc_library_shared", "a", attrNameToString{ + makeBazelTarget("cc_library_shared", "a", AttrNameToString{ "copts": `[ "bothflag", "sharedflag", @@ -405,16 +405,16 @@ cc_library { } func TestCcLibraryDeps(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library shared/static props", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library shared/static props", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Filesystem: map[string]string{ "both.cpp": "", "sharedonly.cpp": "", "staticonly.cpp": "", }, - blueprint: soongCcLibraryPreamble + ` + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "a", srcs: ["both.cpp"], @@ -462,8 +462,8 @@ cc_library { simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_static") + simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_both") + simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_both"), - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ "copts": `[ "bothflag", "staticflag", @@ -495,7 +495,7 @@ cc_library { ":whole_static_dep_for_static", ]`, }), - makeBazelTarget("cc_library_shared", "a", attrNameToString{ + makeBazelTarget("cc_library_shared", "a", AttrNameToString{ "copts": `[ "bothflag", "sharedflag", @@ -532,11 +532,11 @@ cc_library { } func TestCcLibraryWholeStaticLibsAlwaysLink(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - dir: "foo/bar", - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Dir: "foo/bar", + Filesystem: map[string]string{ "foo/bar/Android.bp": ` cc_library { name: "a", @@ -558,15 +558,15 @@ cc_prebuilt_library_static { name: "whole_static_lib_for_static" } cc_prebuilt_library_static { name: "whole_static_lib_for_both" } `, }, - blueprint: soongCcLibraryPreamble, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", attrNameToString{ + Blueprint: soongCcLibraryPreamble, + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ "whole_archive_deps": `[ ":whole_static_lib_for_both_alwayslink", ":whole_static_lib_for_static_alwayslink", ]`, }), - makeBazelTarget("cc_library_shared", "a", attrNameToString{ + makeBazelTarget("cc_library_shared", "a", AttrNameToString{ "whole_archive_deps": `[ ":whole_static_lib_for_both_alwayslink", ":whole_static_lib_for_shared_alwayslink", @@ -578,12 +578,12 @@ cc_prebuilt_library_static { name: "whole_static_lib_for_both" } } func TestCcLibrarySharedStaticPropsInArch(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library shared/static props in arch", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - dir: "foo/bar", - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library shared/static props in arch", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Dir: "foo/bar", + Filesystem: map[string]string{ "foo/bar/arm.cpp": "", "foo/bar/x86.cpp": "", "foo/bar/sharedonly.cpp": "", @@ -652,9 +652,9 @@ cc_library_static { name: "x86_dep_for_static" } cc_library_static { name: "android_dep_for_shared" } `, }, - blueprint: soongCcLibraryPreamble, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", attrNameToString{ + Blueprint: soongCcLibraryPreamble, + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ "copts": `[ "bothflag", "staticflag", @@ -678,7 +678,7 @@ cc_library_static { name: "android_dep_for_shared" } "//conditions:default": [], })`, }), - makeBazelTarget("cc_library_shared", "a", attrNameToString{ + makeBazelTarget("cc_library_shared", "a", AttrNameToString{ "copts": `[ "bothflag", "sharedflag", @@ -728,12 +728,12 @@ cc_library_static { name: "android_dep_for_shared" } } func TestCcLibrarySharedStaticPropsWithMixedSources(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library shared/static props with c/cpp/s mixed sources", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - dir: "foo/bar", - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library shared/static props with c/cpp/s mixed sources", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Dir: "foo/bar", + Filesystem: map[string]string{ "foo/bar/both_source.cpp": "", "foo/bar/both_source.cc": "", "foo/bar/both_source.c": "", @@ -805,9 +805,9 @@ filegroup { } `, }, - blueprint: soongCcLibraryPreamble, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", attrNameToString{ + Blueprint: soongCcLibraryPreamble, + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ "local_includes": `["."]`, "srcs": `[ "both_source.cpp", @@ -832,7 +832,7 @@ filegroup { ":static_filegroup_c_srcs", ]`, }), - makeBazelTarget("cc_library_shared", "a", attrNameToString{ + makeBazelTarget("cc_library_shared", "a", AttrNameToString{ "local_includes": `["."]`, "srcs": `[ "both_source.cpp", @@ -860,12 +860,12 @@ filegroup { } func TestCcLibraryNonConfiguredVersionScript(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library non-configured version script", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - dir: "foo/bar", - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library non-configured version script", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Dir: "foo/bar", + Filesystem: map[string]string{ "foo/bar/Android.bp": ` cc_library { name: "a", @@ -876,8 +876,8 @@ cc_library { } `, }, - blueprint: soongCcLibraryPreamble, - expectedBazelTargets: makeCcLibraryTargets("a", attrNameToString{ + Blueprint: soongCcLibraryPreamble, + ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ "additional_linker_inputs": `["v.map"]`, "linkopts": `["-Wl,--version-script,$(location v.map)"]`, "srcs": `["a.cpp"]`, @@ -887,12 +887,12 @@ cc_library { } func TestCcLibraryConfiguredVersionScript(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library configured version script", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - dir: "foo/bar", - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library configured version script", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Dir: "foo/bar", + Filesystem: map[string]string{ "foo/bar/Android.bp": ` cc_library { name: "a", @@ -911,8 +911,8 @@ cc_library { } `, }, - blueprint: soongCcLibraryPreamble, - expectedBazelTargets: makeCcLibraryTargets("a", attrNameToString{ + Blueprint: soongCcLibraryPreamble, + ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ "additional_linker_inputs": `select({ "//build/bazel/platforms/arch:arm": ["arm.map"], "//build/bazel/platforms/arch:arm64": ["arm64.map"], @@ -930,11 +930,11 @@ cc_library { } func TestCcLibrarySharedLibs(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library shared_libs", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcLibraryPreamble + ` + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library shared_libs", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "mylib", bazel_module: { bp2build_available: false }, @@ -946,7 +946,7 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: makeCcLibraryTargets("a", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ "implementation_dynamic_deps": `[":mylib"]`, }), }, @@ -955,7 +955,7 @@ cc_library { func TestCcLibraryFeatures(t *testing.T) { expected_targets := []string{} - expected_targets = append(expected_targets, makeCcLibraryTargets("a", attrNameToString{ + expected_targets = append(expected_targets, makeCcLibraryTargets("a", AttrNameToString{ "features": `[ "disable_pack_relocations", "-no_undefined_symbols", @@ -963,7 +963,7 @@ func TestCcLibraryFeatures(t *testing.T) { ]`, "srcs": `["a.cpp"]`, })...) - expected_targets = append(expected_targets, makeCcLibraryTargets("b", attrNameToString{ + expected_targets = append(expected_targets, makeCcLibraryTargets("b", AttrNameToString{ "features": `["-coverage"] + select({ "//build/bazel/platforms/arch:x86_64": [ "disable_pack_relocations", @@ -973,7 +973,7 @@ func TestCcLibraryFeatures(t *testing.T) { })`, "srcs": `["b.cpp"]`, })...) - expected_targets = append(expected_targets, makeCcLibraryTargets("c", attrNameToString{ + expected_targets = append(expected_targets, makeCcLibraryTargets("c", AttrNameToString{ "features": `select({ "//build/bazel/platforms/os:darwin": [ "disable_pack_relocations", @@ -984,11 +984,11 @@ func TestCcLibraryFeatures(t *testing.T) { "srcs": `["c.cpp"]`, })...) - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library pack_relocations test", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcLibraryPreamble + ` + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library pack_relocations test", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "a", srcs: ["a.cpp"], @@ -1022,23 +1022,23 @@ cc_library { }, include_build_directory: false, }`, - expectedBazelTargets: expected_targets, + ExpectedBazelTargets: expected_targets, }) } func TestCcLibrarySpacesInCopts(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library spaces in copts", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcLibraryPreamble + ` + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library spaces in copts", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "a", cflags: ["-include header.h",], include_build_directory: false, } `, - expectedBazelTargets: makeCcLibraryTargets("a", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ "copts": `[ "-include", "header.h", @@ -1049,11 +1049,11 @@ cc_library { } func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library cppflags usage", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcLibraryPreamble + `cc_library { + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library cppflags usage", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcLibraryPreamble + `cc_library { name: "a", srcs: ["a.cpp"], cflags: ["-Wall"], @@ -1074,7 +1074,7 @@ func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) { include_build_directory: false, } `, - expectedBazelTargets: makeCcLibraryTargets("a", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ "copts": `["-Wall"]`, "cppflags": `[ "-fsigned-char", @@ -1093,11 +1093,11 @@ func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) { } func TestCcLibraryExcludeLibs(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - filesystem: map[string]string{}, - blueprint: soongCcLibraryStaticPreamble + ` + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Filesystem: map[string]string{}, + Blueprint: soongCcLibraryStaticPreamble + ` cc_library { name: "foo_static", srcs: ["common.c"], @@ -1171,7 +1171,7 @@ cc_library { bazel_module: { bp2build_available: false }, } `, - expectedBazelTargets: makeCcLibraryTargets("foo_static", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("foo_static", AttrNameToString{ "implementation_deps": `select({ "//build/bazel/platforms/arch:arm": [], "//conditions:default": [":arm_static_lib_excludes_bp2build_cc_library_static"], @@ -1200,14 +1200,14 @@ cc_library { } func TestCCLibraryNoCrtTrue(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library - nocrt: true emits attribute", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library - nocrt: true emits attribute", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Filesystem: map[string]string{ "impl.cpp": "", }, - blueprint: soongCcLibraryPreamble + ` + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "foo-lib", srcs: ["impl.cpp"], @@ -1215,7 +1215,7 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ "link_crt": `False`, "srcs": `["impl.cpp"]`, }), @@ -1224,14 +1224,14 @@ cc_library { } func TestCCLibraryNoCrtFalse(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library - nocrt: false - does not emit attribute", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library - nocrt: false - does not emit attribute", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Filesystem: map[string]string{ "impl.cpp": "", }, - blueprint: soongCcLibraryPreamble + ` + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "foo-lib", srcs: ["impl.cpp"], @@ -1239,21 +1239,21 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ "srcs": `["impl.cpp"]`, }), }) } func TestCCLibraryNoCrtArchVariant(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library - nocrt in select", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library - nocrt in select", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Filesystem: map[string]string{ "impl.cpp": "", }, - blueprint: soongCcLibraryPreamble + ` + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "foo-lib", srcs: ["impl.cpp"], @@ -1268,18 +1268,18 @@ cc_library { include_build_directory: false, } `, - expectedErr: fmt.Errorf("module \"foo-lib\": nocrt is not supported for arch variants"), + ExpectedErr: fmt.Errorf("module \"foo-lib\": nocrt is not supported for arch variants"), }) } func TestCCLibraryNoLibCrtTrue(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Filesystem: map[string]string{ "impl.cpp": "", }, - blueprint: soongCcLibraryPreamble + ` + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "foo-lib", srcs: ["impl.cpp"], @@ -1287,14 +1287,14 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ "srcs": `["impl.cpp"]`, "use_libcrt": `False`, }), }) } -func makeCcLibraryTargets(name string, attrs attrNameToString) []string { +func makeCcLibraryTargets(name string, attrs AttrNameToString) []string { STATIC_ONLY_ATTRS := map[string]bool{} SHARED_ONLY_ATTRS := map[string]bool{ "link_crt": true, @@ -1305,8 +1305,8 @@ func makeCcLibraryTargets(name string, attrs attrNameToString) []string { "stubs_versions": true, "inject_bssl_hash": true, } - sharedAttrs := attrNameToString{} - staticAttrs := attrNameToString{} + sharedAttrs := AttrNameToString{} + staticAttrs := AttrNameToString{} for key, val := range attrs { if _, staticOnly := STATIC_ONLY_ATTRS[key]; !staticOnly { sharedAttrs[key] = val @@ -1322,13 +1322,13 @@ func makeCcLibraryTargets(name string, attrs attrNameToString) []string { } func TestCCLibraryNoLibCrtFalse(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Filesystem: map[string]string{ "impl.cpp": "", }, - blueprint: soongCcLibraryPreamble + ` + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "foo-lib", srcs: ["impl.cpp"], @@ -1336,7 +1336,7 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ "srcs": `["impl.cpp"]`, "use_libcrt": `True`, }), @@ -1344,13 +1344,13 @@ cc_library { } func TestCCLibraryNoLibCrtArchVariant(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Filesystem: map[string]string{ "impl.cpp": "", }, - blueprint: soongCcLibraryPreamble + ` + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "foo-lib", srcs: ["impl.cpp"], @@ -1365,7 +1365,7 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ "srcs": `["impl.cpp"]`, "use_libcrt": `select({ "//build/bazel/platforms/arch:arm": False, @@ -1377,13 +1377,13 @@ cc_library { } func TestCCLibraryNoLibCrtArchAndTargetVariant(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Filesystem: map[string]string{ "impl.cpp": "", }, - blueprint: soongCcLibraryPreamble + ` + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "foo-lib", srcs: ["impl.cpp"], @@ -1403,7 +1403,7 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ "srcs": `["impl.cpp"]`, "use_libcrt": `select({ "//build/bazel/platforms/os_arch:android_arm": False, @@ -1420,13 +1420,13 @@ cc_library { } func TestCCLibraryNoLibCrtArchAndTargetVariantConflict(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Filesystem: map[string]string{ "impl.cpp": "", }, - blueprint: soongCcLibraryPreamble + ` + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "foo-lib", srcs: ["impl.cpp"], @@ -1447,7 +1447,7 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ "srcs": `["impl.cpp"]`, "use_libcrt": `select({ "//build/bazel/platforms/os_arch:android_arm": False, @@ -1466,38 +1466,38 @@ cc_library { func TestCcLibraryStrip(t *testing.T) { expectedTargets := []string{} - expectedTargets = append(expectedTargets, makeCcLibraryTargets("all", attrNameToString{ + expectedTargets = append(expectedTargets, makeCcLibraryTargets("all", AttrNameToString{ "strip": `{ "all": True, }`, })...) - expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols", attrNameToString{ + expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols", AttrNameToString{ "strip": `{ "keep_symbols": True, }`, })...) - expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols_and_debug_frame", attrNameToString{ + expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols_and_debug_frame", AttrNameToString{ "strip": `{ "keep_symbols_and_debug_frame": True, }`, })...) - expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols_list", attrNameToString{ + expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols_list", AttrNameToString{ "strip": `{ "keep_symbols_list": ["symbol"], }`, })...) - expectedTargets = append(expectedTargets, makeCcLibraryTargets("none", attrNameToString{ + expectedTargets = append(expectedTargets, makeCcLibraryTargets("none", AttrNameToString{ "strip": `{ "none": True, }`, })...) - expectedTargets = append(expectedTargets, makeCcLibraryTargets("nothing", attrNameToString{})...) + expectedTargets = append(expectedTargets, makeCcLibraryTargets("nothing", AttrNameToString{})...) - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library strip args", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcLibraryPreamble + ` + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library strip args", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "nothing", include_build_directory: false, @@ -1538,16 +1538,16 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: expectedTargets, + ExpectedBazelTargets: expectedTargets, }) } func TestCcLibraryStripWithArch(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library strip args", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcLibraryPreamble + ` + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library strip args", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "multi-arch", target: { @@ -1572,7 +1572,7 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: makeCcLibraryTargets("multi-arch", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("multi-arch", AttrNameToString{ "strip": `{ "keep_symbols": select({ "//build/bazel/platforms/arch:arm64": True, @@ -1596,18 +1596,18 @@ cc_library { } func TestCcLibrary_SystemSharedLibsRootEmpty(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library system_shared_libs empty at root", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcLibraryPreamble + ` + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library system_shared_libs empty at root", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "root_empty", system_shared_libs: [], include_build_directory: false, } `, - expectedBazelTargets: makeCcLibraryTargets("root_empty", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("root_empty", AttrNameToString{ "system_dynamic_deps": `[]`, }), }, @@ -1615,11 +1615,11 @@ cc_library { } func TestCcLibrary_SystemSharedLibsStaticEmpty(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library system_shared_libs empty for static variant", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcLibraryPreamble + ` + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library system_shared_libs empty for static variant", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "static_empty", static: { @@ -1628,21 +1628,21 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "static_empty_bp2build_cc_library_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "static_empty_bp2build_cc_library_static", AttrNameToString{ "system_dynamic_deps": "[]", }), - makeBazelTarget("cc_library_shared", "static_empty", attrNameToString{}), + makeBazelTarget("cc_library_shared", "static_empty", AttrNameToString{}), }, }) } func TestCcLibrary_SystemSharedLibsSharedEmpty(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library system_shared_libs empty for shared variant", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcLibraryPreamble + ` + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library system_shared_libs empty for shared variant", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "shared_empty", shared: { @@ -1651,9 +1651,9 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "shared_empty_bp2build_cc_library_static", attrNameToString{}), - makeBazelTarget("cc_library_shared", "shared_empty", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "shared_empty_bp2build_cc_library_static", AttrNameToString{}), + makeBazelTarget("cc_library_shared", "shared_empty", AttrNameToString{ "system_dynamic_deps": "[]", }), }, @@ -1661,11 +1661,11 @@ cc_library { } func TestCcLibrary_SystemSharedLibsSharedBionicEmpty(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library system_shared_libs empty for shared, bionic variant", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcLibraryPreamble + ` + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library system_shared_libs empty for shared, bionic variant", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "shared_empty", target: { @@ -1678,9 +1678,9 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "shared_empty_bp2build_cc_library_static", attrNameToString{}), - makeBazelTarget("cc_library_shared", "shared_empty", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "shared_empty_bp2build_cc_library_static", AttrNameToString{}), + makeBazelTarget("cc_library_shared", "shared_empty", AttrNameToString{ "system_dynamic_deps": "[]", }), }, @@ -1692,11 +1692,11 @@ func TestCcLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) { // The correct behavior would be if bp2build wrote `system_dynamic_deps = []` // only for linux_bionic, but `android` had `["libc", "libdl", "libm"]. // b/195791252 tracks the fix. - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library system_shared_libs empty for linux_bionic variant", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcLibraryPreamble + ` + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library system_shared_libs empty for linux_bionic variant", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "target_linux_bionic_empty", target: { @@ -1707,7 +1707,7 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: makeCcLibraryTargets("target_linux_bionic_empty", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("target_linux_bionic_empty", AttrNameToString{ "system_dynamic_deps": `[]`, }), }, @@ -1715,11 +1715,11 @@ cc_library { } func TestCcLibrary_SystemSharedLibsBionicEmpty(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library system_shared_libs empty for bionic variant", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcLibraryPreamble + ` + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library system_shared_libs empty for bionic variant", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "target_bionic_empty", target: { @@ -1730,7 +1730,7 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: makeCcLibraryTargets("target_bionic_empty", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("target_bionic_empty", AttrNameToString{ "system_dynamic_deps": `[]`, }), }, @@ -1738,11 +1738,11 @@ cc_library { } func TestCcLibrary_SystemSharedLibsSharedAndRoot(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library system_shared_libs set for shared and root", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcLibraryPreamble + ` + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library system_shared_libs set for shared and root", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "libc", bazel_module: { bp2build_available: false }, @@ -1761,11 +1761,11 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "system_dynamic_deps": `[":libc"]`, }), - makeBazelTarget("cc_library_shared", "foo", attrNameToString{ + makeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "system_dynamic_deps": `[ ":libc", ":libm", @@ -1776,12 +1776,12 @@ cc_library { } func TestCcLibraryOsSelects(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library - selects for all os targets", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - filesystem: map[string]string{}, - blueprint: soongCcLibraryPreamble + ` + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library - selects for all os targets", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Filesystem: map[string]string{}, + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "foo-lib", srcs: ["base.cpp"], @@ -1811,7 +1811,7 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ "srcs": `["base.cpp"] + select({ "//build/bazel/platforms/os:android": [ "linux.cpp", @@ -1840,12 +1840,12 @@ cc_library { } func TestLibcryptoHashInjection(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library - libcrypto hash injection", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - filesystem: map[string]string{}, - blueprint: soongCcLibraryPreamble + ` + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library - libcrypto hash injection", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Filesystem: map[string]string{}, + Blueprint: soongCcLibraryPreamble + ` cc_library { name: "libcrypto", target: { @@ -1856,7 +1856,7 @@ cc_library { include_build_directory: false, } `, - expectedBazelTargets: makeCcLibraryTargets("libcrypto", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("libcrypto", AttrNameToString{ "inject_bssl_hash": `select({ "//build/bazel/platforms/os:android": True, "//conditions:default": None, @@ -1940,7 +1940,7 @@ func TestCcLibraryCppStdWithGnuExtensions_ConvertsToFeatureAttr(t *testing.T) { if tc.gnu_extensions != "" { gnuExtensionsProp = fmt.Sprintf(" gnu_extensions: %s,", tc.gnu_extensions) } - attrs := attrNameToString{} + attrs := AttrNameToString{} if tc.bazel_cpp_std != "" { attrs["cpp_std"] = fmt.Sprintf(`"%s"`, tc.bazel_cpp_std) } @@ -1948,12 +1948,12 @@ func TestCcLibraryCppStdWithGnuExtensions_ConvertsToFeatureAttr(t *testing.T) { attrs["c_std"] = fmt.Sprintf(`"%s"`, tc.bazel_c_std) } - runCcLibraryTestCase(t, bp2buildTestCase{ - description: 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(` + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcLibraryPreamble + fmt.Sprintf(` cc_library { name: "%s_full", %s // cpp_std: *string @@ -1962,15 +1962,15 @@ cc_library { 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( + 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(` + ModuleTypeUnderTest: "cc_library_static", + ModuleTypeUnderTestFactory: cc.LibraryStaticFactory, + Blueprint: soongCcLibraryPreamble + fmt.Sprintf(` cc_library_static { name: "%s_static", %s // cpp_std: *string @@ -1979,17 +1979,17 @@ cc_library_static { include_build_directory: false, } `, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp), - expectedBazelTargets: []string{ + ExpectedBazelTargets: []string{ makeBazelTarget("cc_library_static", name_prefix+"_static", attrs), }, }) - runCcLibrarySharedTestCase(t, bp2buildTestCase{ - description: 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(` + ModuleTypeUnderTest: "cc_library_shared", + ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, + Blueprint: soongCcLibraryPreamble + fmt.Sprintf(` cc_library_shared { name: "%s_shared", %s // cpp_std: *string @@ -1998,7 +1998,7 @@ cc_library_shared { include_build_directory: false, } `, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp), - expectedBazelTargets: []string{ + ExpectedBazelTargets: []string{ makeBazelTarget("cc_library_shared", name_prefix+"_shared", attrs), }, }) @@ -2007,23 +2007,23 @@ cc_library_shared { } func TestCcLibraryProtoSimple(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcProtoPreamble + `cc_library { + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcProtoPreamble + `cc_library { name: "foo", srcs: ["foo.proto"], include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("proto_library", "foo_proto", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("proto_library", "foo_proto", AttrNameToString{ "srcs": `["foo.proto"]`, - }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ "deps": `[":foo_proto"]`, - }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ + }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, "deps": `[":libprotobuf-cpp-lite"]`, - }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ + }), makeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "dynamic_deps": `[":libprotobuf-cpp-lite"]`, }), }, @@ -2031,25 +2031,25 @@ func TestCcLibraryProtoSimple(t *testing.T) { } func TestCcLibraryProtoNoCanonicalPathFromRoot(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcProtoPreamble + `cc_library { + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcProtoPreamble + `cc_library { name: "foo", srcs: ["foo.proto"], proto: { canonical_path_from_root: false}, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("proto_library", "foo_proto", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("proto_library", "foo_proto", AttrNameToString{ "srcs": `["foo.proto"]`, "strip_import_prefix": `""`, - }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ "deps": `[":foo_proto"]`, - }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ + }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, "deps": `[":libprotobuf-cpp-lite"]`, - }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ + }), makeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "dynamic_deps": `[":libprotobuf-cpp-lite"]`, }), }, @@ -2057,24 +2057,24 @@ func TestCcLibraryProtoNoCanonicalPathFromRoot(t *testing.T) { } func TestCcLibraryProtoExplicitCanonicalPathFromRoot(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcProtoPreamble + `cc_library { + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcProtoPreamble + `cc_library { name: "foo", srcs: ["foo.proto"], proto: { canonical_path_from_root: true}, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("proto_library", "foo_proto", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("proto_library", "foo_proto", AttrNameToString{ "srcs": `["foo.proto"]`, - }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ "deps": `[":foo_proto"]`, - }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ + }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, "deps": `[":libprotobuf-cpp-lite"]`, - }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ + }), makeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "dynamic_deps": `[":libprotobuf-cpp-lite"]`, }), }, @@ -2082,10 +2082,10 @@ func TestCcLibraryProtoExplicitCanonicalPathFromRoot(t *testing.T) { } func TestCcLibraryProtoFull(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcProtoPreamble + `cc_library { + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcProtoPreamble + `cc_library { name: "foo", srcs: ["foo.proto"], proto: { @@ -2093,15 +2093,15 @@ func TestCcLibraryProtoFull(t *testing.T) { }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("proto_library", "foo_proto", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("proto_library", "foo_proto", AttrNameToString{ "srcs": `["foo.proto"]`, - }), makeBazelTarget("cc_proto_library", "foo_cc_proto", attrNameToString{ + }), makeBazelTarget("cc_proto_library", "foo_cc_proto", AttrNameToString{ "deps": `[":foo_proto"]`, - }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ + }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "implementation_whole_archive_deps": `[":foo_cc_proto"]`, "deps": `[":libprotobuf-cpp-full"]`, - }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ + }), makeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "dynamic_deps": `[":libprotobuf-cpp-full"]`, }), }, @@ -2109,10 +2109,10 @@ func TestCcLibraryProtoFull(t *testing.T) { } func TestCcLibraryProtoLite(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcProtoPreamble + `cc_library { + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcProtoPreamble + `cc_library { name: "foo", srcs: ["foo.proto"], proto: { @@ -2120,15 +2120,15 @@ func TestCcLibraryProtoLite(t *testing.T) { }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("proto_library", "foo_proto", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("proto_library", "foo_proto", AttrNameToString{ "srcs": `["foo.proto"]`, - }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ "deps": `[":foo_proto"]`, - }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ + }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, "deps": `[":libprotobuf-cpp-lite"]`, - }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ + }), makeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "dynamic_deps": `[":libprotobuf-cpp-lite"]`, }), }, @@ -2136,10 +2136,10 @@ func TestCcLibraryProtoLite(t *testing.T) { } func TestCcLibraryProtoExportHeaders(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcProtoPreamble + `cc_library { + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcProtoPreamble + `cc_library { name: "foo", srcs: ["foo.proto"], proto: { @@ -2147,15 +2147,15 @@ func TestCcLibraryProtoExportHeaders(t *testing.T) { }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("proto_library", "foo_proto", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("proto_library", "foo_proto", AttrNameToString{ "srcs": `["foo.proto"]`, - }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ "deps": `[":foo_proto"]`, - }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ + }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "deps": `[":libprotobuf-cpp-lite"]`, "whole_archive_deps": `[":foo_cc_proto_lite"]`, - }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ + }), makeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "dynamic_deps": `[":libprotobuf-cpp-lite"]`, "whole_archive_deps": `[":foo_cc_proto_lite"]`, }), @@ -2164,10 +2164,10 @@ func TestCcLibraryProtoExportHeaders(t *testing.T) { } func TestCcLibraryProtoFilegroups(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcProtoPreamble + + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcProtoPreamble + simpleModuleDoNotConvertBp2build("filegroup", "a_fg_proto") + simpleModuleDoNotConvertBp2build("filegroup", "b_protos") + simpleModuleDoNotConvertBp2build("filegroup", "c-proto-srcs") + @@ -2207,66 +2207,66 @@ cc_library { }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("proto_library", "a_proto", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("proto_library", "a_proto", AttrNameToString{ "srcs": `[":a_fg_proto"]`, - }), makeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", attrNameToString{ + }), makeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", AttrNameToString{ "deps": `[":a_proto"]`, - }), makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", attrNameToString{ + }), makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ "deps": `[":libprotobuf-cpp-lite"]`, "whole_archive_deps": `[":a_cc_proto_lite"]`, "srcs": `[":a_fg_proto_cpp_srcs"]`, "srcs_as": `[":a_fg_proto_as_srcs"]`, "srcs_c": `[":a_fg_proto_c_srcs"]`, - }), makeBazelTarget("cc_library_shared", "a", attrNameToString{ + }), makeBazelTarget("cc_library_shared", "a", AttrNameToString{ "dynamic_deps": `[":libprotobuf-cpp-lite"]`, "whole_archive_deps": `[":a_cc_proto_lite"]`, "srcs": `[":a_fg_proto_cpp_srcs"]`, "srcs_as": `[":a_fg_proto_as_srcs"]`, "srcs_c": `[":a_fg_proto_c_srcs"]`, - }), makeBazelTarget("proto_library", "b_proto", attrNameToString{ + }), makeBazelTarget("proto_library", "b_proto", AttrNameToString{ "srcs": `[":b_protos"]`, - }), makeBazelTarget("cc_lite_proto_library", "b_cc_proto_lite", attrNameToString{ + }), makeBazelTarget("cc_lite_proto_library", "b_cc_proto_lite", AttrNameToString{ "deps": `[":b_proto"]`, - }), makeBazelTarget("cc_library_static", "b_bp2build_cc_library_static", attrNameToString{ + }), makeBazelTarget("cc_library_static", "b_bp2build_cc_library_static", AttrNameToString{ "deps": `[":libprotobuf-cpp-lite"]`, "whole_archive_deps": `[":b_cc_proto_lite"]`, "srcs": `[":b_protos_cpp_srcs"]`, "srcs_as": `[":b_protos_as_srcs"]`, "srcs_c": `[":b_protos_c_srcs"]`, - }), makeBazelTarget("cc_library_shared", "b", attrNameToString{ + }), makeBazelTarget("cc_library_shared", "b", AttrNameToString{ "dynamic_deps": `[":libprotobuf-cpp-lite"]`, "whole_archive_deps": `[":b_cc_proto_lite"]`, "srcs": `[":b_protos_cpp_srcs"]`, "srcs_as": `[":b_protos_as_srcs"]`, "srcs_c": `[":b_protos_c_srcs"]`, - }), makeBazelTarget("proto_library", "c_proto", attrNameToString{ + }), makeBazelTarget("proto_library", "c_proto", AttrNameToString{ "srcs": `[":c-proto-srcs"]`, - }), makeBazelTarget("cc_lite_proto_library", "c_cc_proto_lite", attrNameToString{ + }), makeBazelTarget("cc_lite_proto_library", "c_cc_proto_lite", AttrNameToString{ "deps": `[":c_proto"]`, - }), makeBazelTarget("cc_library_static", "c_bp2build_cc_library_static", attrNameToString{ + }), makeBazelTarget("cc_library_static", "c_bp2build_cc_library_static", AttrNameToString{ "deps": `[":libprotobuf-cpp-lite"]`, "whole_archive_deps": `[":c_cc_proto_lite"]`, "srcs": `[":c-proto-srcs_cpp_srcs"]`, "srcs_as": `[":c-proto-srcs_as_srcs"]`, "srcs_c": `[":c-proto-srcs_c_srcs"]`, - }), makeBazelTarget("cc_library_shared", "c", attrNameToString{ + }), makeBazelTarget("cc_library_shared", "c", AttrNameToString{ "dynamic_deps": `[":libprotobuf-cpp-lite"]`, "whole_archive_deps": `[":c_cc_proto_lite"]`, "srcs": `[":c-proto-srcs_cpp_srcs"]`, "srcs_as": `[":c-proto-srcs_as_srcs"]`, "srcs_c": `[":c-proto-srcs_c_srcs"]`, - }), makeBazelTarget("proto_library", "d_proto", attrNameToString{ + }), makeBazelTarget("proto_library", "d_proto", AttrNameToString{ "srcs": `[":proto-srcs-d"]`, - }), makeBazelTarget("cc_lite_proto_library", "d_cc_proto_lite", attrNameToString{ + }), makeBazelTarget("cc_lite_proto_library", "d_cc_proto_lite", AttrNameToString{ "deps": `[":d_proto"]`, - }), makeBazelTarget("cc_library_static", "d_bp2build_cc_library_static", attrNameToString{ + }), makeBazelTarget("cc_library_static", "d_bp2build_cc_library_static", AttrNameToString{ "deps": `[":libprotobuf-cpp-lite"]`, "whole_archive_deps": `[":d_cc_proto_lite"]`, "srcs": `[":proto-srcs-d_cpp_srcs"]`, "srcs_as": `[":proto-srcs-d_as_srcs"]`, "srcs_c": `[":proto-srcs-d_c_srcs"]`, - }), makeBazelTarget("cc_library_shared", "d", attrNameToString{ + }), makeBazelTarget("cc_library_shared", "d", AttrNameToString{ "dynamic_deps": `[":libprotobuf-cpp-lite"]`, "whole_archive_deps": `[":d_cc_proto_lite"]`, "srcs": `[":proto-srcs-d_cpp_srcs"]`, @@ -2278,10 +2278,10 @@ cc_library { } func TestCcLibraryDisabledArchAndTarget(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcProtoPreamble + `cc_library { + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcProtoPreamble + `cc_library { name: "foo", srcs: ["foo.cpp"], host_supported: true, @@ -2298,7 +2298,7 @@ func TestCcLibraryDisabledArchAndTarget(t *testing.T) { }, include_build_directory: false, }`, - expectedBazelTargets: makeCcLibraryTargets("foo", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{ "srcs": `["foo.cpp"]`, "target_compatible_with": `select({ "//build/bazel/platforms/os_arch:darwin_arm64": ["@platforms//:incompatible"], @@ -2313,10 +2313,10 @@ func TestCcLibraryDisabledArchAndTarget(t *testing.T) { } func TestCcLibraryDisabledArchAndTargetWithDefault(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcProtoPreamble + `cc_library { + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcProtoPreamble + `cc_library { name: "foo", srcs: ["foo.cpp"], enabled: false, @@ -2334,7 +2334,7 @@ func TestCcLibraryDisabledArchAndTargetWithDefault(t *testing.T) { }, include_build_directory: false, }`, - expectedBazelTargets: makeCcLibraryTargets("foo", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{ "srcs": `["foo.cpp"]`, "target_compatible_with": `select({ "//build/bazel/platforms/os_arch:darwin_arm64": [], @@ -2346,10 +2346,10 @@ func TestCcLibraryDisabledArchAndTargetWithDefault(t *testing.T) { } func TestCcLibrarySharedDisabled(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcProtoPreamble + `cc_library { + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcProtoPreamble + `cc_library { name: "foo", srcs: ["foo.cpp"], enabled: false, @@ -2365,10 +2365,10 @@ func TestCcLibrarySharedDisabled(t *testing.T) { }, include_build_directory: false, }`, - expectedBazelTargets: []string{makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ + ExpectedBazelTargets: []string{makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "srcs": `["foo.cpp"]`, "target_compatible_with": `["@platforms//:incompatible"]`, - }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ + }), makeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "srcs": `["foo.cpp"]`, "target_compatible_with": `select({ "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], @@ -2380,10 +2380,10 @@ func TestCcLibrarySharedDisabled(t *testing.T) { } func TestCcLibraryStaticDisabledForSomeArch(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcProtoPreamble + `cc_library { + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcProtoPreamble + `cc_library { name: "foo", host_supported: true, srcs: ["foo.cpp"], @@ -2405,13 +2405,13 @@ func TestCcLibraryStaticDisabledForSomeArch(t *testing.T) { }, include_build_directory: false, }`, - expectedBazelTargets: []string{makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ + ExpectedBazelTargets: []string{makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "srcs": `["foo.cpp"]`, "target_compatible_with": `select({ "//build/bazel/platforms/os:windows": ["@platforms//:incompatible"], "//conditions:default": [], })`, - }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ + }), makeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "srcs": `["foo.cpp"]`, "target_compatible_with": `select({ "//build/bazel/platforms/os_arch:darwin_arm64": [], @@ -2424,12 +2424,12 @@ func TestCcLibraryStaticDisabledForSomeArch(t *testing.T) { } func TestCcLibraryStubs(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - description: "cc_library stubs", - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - dir: "foo/bar", - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library stubs", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Dir: "foo/bar", + Filesystem: map[string]string{ "foo/bar/Android.bp": ` cc_library { name: "a", @@ -2439,8 +2439,8 @@ cc_library { } `, }, - blueprint: soongCcLibraryPreamble, - expectedBazelTargets: makeCcLibraryTargets("a", attrNameToString{ + Blueprint: soongCcLibraryPreamble, + ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ "stubs_symbol_file": `"a.map.txt"`, "stubs_versions": `[ "28", @@ -2453,25 +2453,25 @@ cc_library { } func TestCcLibraryEscapeLdflags(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - blueprint: soongCcProtoPreamble + `cc_library { + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcProtoPreamble + `cc_library { name: "foo", ldflags: ["-Wl,--rpath,${ORIGIN}"], include_build_directory: false, }`, - expectedBazelTargets: makeCcLibraryTargets("foo", attrNameToString{ + ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{ "linkopts": `["-Wl,--rpath,$${ORIGIN}"]`, }), }) } func TestCcLibraryConvertLex(t *testing.T) { - runCcLibraryTestCase(t, bp2buildTestCase{ - moduleTypeUnderTest: "cc_library", - moduleTypeUnderTestFactory: cc.LibraryFactory, - filesystem: map[string]string{ + runCcLibraryTestCase(t, Bp2buildTestCase{ + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Filesystem: map[string]string{ "foo.c": "", "bar.cc": "", "foo1.l": "", @@ -2479,22 +2479,22 @@ func TestCcLibraryConvertLex(t *testing.T) { "foo2.l": "", "bar2.ll": "", }, - blueprint: `cc_library { + Blueprint: `cc_library { name: "foo_lib", srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"], lex: { flags: ["--foo_flags"] }, include_build_directory: false, bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: append([]string{ - makeBazelTarget("genlex", "foo_lib_genlex_l", attrNameToString{ + ExpectedBazelTargets: append([]string{ + makeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{ "srcs": `[ "foo1.l", "foo2.l", ]`, "lexopts": `["--foo_flags"]`, }), - makeBazelTarget("genlex", "foo_lib_genlex_ll", attrNameToString{ + makeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{ "srcs": `[ "bar1.ll", "bar2.ll", @@ -2502,7 +2502,7 @@ func TestCcLibraryConvertLex(t *testing.T) { "lexopts": `["--foo_flags"]`, }), }, - makeCcLibraryTargets("foo_lib", attrNameToString{ + makeCcLibraryTargets("foo_lib", AttrNameToString{ "srcs": `[ "bar.cc", ":foo_lib_genlex_ll", diff --git a/bp2build/cc_library_headers_conversion_test.go b/bp2build/cc_library_headers_conversion_test.go index 641984b52..bb59c63e8 100644 --- a/bp2build/cc_library_headers_conversion_test.go +++ b/bp2build/cc_library_headers_conversion_test.go @@ -59,17 +59,17 @@ func registerCcLibraryHeadersModuleTypes(ctx android.RegistrationContext) { cc.RegisterCCBuildComponents(ctx) } -func runCcLibraryHeadersTestCase(t *testing.T, tc bp2buildTestCase) { +func runCcLibraryHeadersTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - runBp2BuildTestCase(t, registerCcLibraryHeadersModuleTypes, tc) + RunBp2BuildTestCase(t, registerCcLibraryHeadersModuleTypes, tc) } func TestCcLibraryHeadersSimple(t *testing.T) { - runCcLibraryHeadersTestCase(t, bp2buildTestCase{ - description: "cc_library_headers test", - moduleTypeUnderTest: "cc_library_headers", - moduleTypeUnderTestFactory: cc.LibraryHeaderFactory, - filesystem: map[string]string{ + runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ + Description: "cc_library_headers test", + ModuleTypeUnderTest: "cc_library_headers", + ModuleTypeUnderTestFactory: cc.LibraryHeaderFactory, + Filesystem: map[string]string{ "lib-1/lib1a.h": "", "lib-1/lib1b.h": "", "lib-2/lib2a.h": "", @@ -82,7 +82,7 @@ func TestCcLibraryHeadersSimple(t *testing.T) { "arch_x86_exported_include_dir/b.h": "", "arch_x86_64_exported_include_dir/c.h": "", }, - blueprint: soongCcLibraryHeadersPreamble + ` + Blueprint: soongCcLibraryHeadersPreamble + ` cc_library_headers { name: "foo_headers", export_include_dirs: ["dir-1", "dir-2"], @@ -105,8 +105,8 @@ cc_library_headers { // TODO: Also support export_header_lib_headers }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_headers", "foo_headers", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{ "export_includes": `[ "dir-1", "dir-2", @@ -124,12 +124,12 @@ cc_library_headers { } func TestCcLibraryHeadersOsSpecificHeader(t *testing.T) { - runCcLibraryHeadersTestCase(t, bp2buildTestCase{ - description: "cc_library_headers test with os-specific header_libs props", - moduleTypeUnderTest: "cc_library_headers", - moduleTypeUnderTestFactory: cc.LibraryHeaderFactory, - filesystem: map[string]string{}, - blueprint: soongCcLibraryPreamble + ` + runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ + Description: "cc_library_headers test with os-specific header_libs props", + ModuleTypeUnderTest: "cc_library_headers", + ModuleTypeUnderTestFactory: cc.LibraryHeaderFactory, + Filesystem: map[string]string{}, + Blueprint: soongCcLibraryPreamble + ` cc_library_headers { name: "android-lib", bazel_module: { bp2build_available: false }, @@ -182,8 +182,8 @@ cc_library_headers { }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_headers", "foo_headers", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{ "deps": `[":base-lib"] + select({ "//build/bazel/platforms/os:android": [":android-lib"], "//build/bazel/platforms/os:darwin": [":darwin-lib"], @@ -198,12 +198,12 @@ cc_library_headers { } func TestCcLibraryHeadersOsSpecficHeaderLibsExportHeaderLibHeaders(t *testing.T) { - runCcLibraryHeadersTestCase(t, bp2buildTestCase{ - description: "cc_library_headers test with os-specific header_libs and export_header_lib_headers props", - moduleTypeUnderTest: "cc_library_headers", - moduleTypeUnderTestFactory: cc.LibraryHeaderFactory, - filesystem: map[string]string{}, - blueprint: soongCcLibraryPreamble + ` + runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ + Description: "cc_library_headers test with os-specific header_libs and export_header_lib_headers props", + ModuleTypeUnderTest: "cc_library_headers", + ModuleTypeUnderTestFactory: cc.LibraryHeaderFactory, + Filesystem: map[string]string{}, + Blueprint: soongCcLibraryPreamble + ` cc_library_headers { name: "android-lib", bazel_module: { bp2build_available: false }, @@ -222,8 +222,8 @@ cc_library_headers { }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_headers", "foo_headers", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{ "deps": `select({ "//build/bazel/platforms/os:android": [":exported-lib"], "//conditions:default": [], @@ -234,12 +234,12 @@ cc_library_headers { } func TestCcLibraryHeadersArchAndTargetExportSystemIncludes(t *testing.T) { - runCcLibraryHeadersTestCase(t, bp2buildTestCase{ - description: "cc_library_headers test with arch-specific and target-specific export_system_include_dirs props", - moduleTypeUnderTest: "cc_library_headers", - moduleTypeUnderTestFactory: cc.LibraryHeaderFactory, - filesystem: map[string]string{}, - blueprint: soongCcLibraryPreamble + `cc_library_headers { + runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ + Description: "cc_library_headers test with arch-specific and target-specific export_system_include_dirs props", + ModuleTypeUnderTest: "cc_library_headers", + ModuleTypeUnderTestFactory: cc.LibraryHeaderFactory, + Filesystem: map[string]string{}, + Blueprint: soongCcLibraryPreamble + `cc_library_headers { name: "foo_headers", export_system_include_dirs: [ "shared_include_dir", @@ -275,8 +275,8 @@ func TestCcLibraryHeadersArchAndTargetExportSystemIncludes(t *testing.T) { }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_headers", "foo_headers", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{ "export_system_includes": `["shared_include_dir"] + select({ "//build/bazel/platforms/arch:arm": ["arm_include_dir"], "//build/bazel/platforms/arch:x86_64": ["x86_64_include_dir"], @@ -293,11 +293,11 @@ func TestCcLibraryHeadersArchAndTargetExportSystemIncludes(t *testing.T) { } func TestCcLibraryHeadersNoCrtIgnored(t *testing.T) { - runCcLibraryHeadersTestCase(t, bp2buildTestCase{ - description: "cc_library_headers test", - moduleTypeUnderTest: "cc_library_headers", - moduleTypeUnderTestFactory: cc.LibraryHeaderFactory, - filesystem: map[string]string{ + runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ + Description: "cc_library_headers test", + ModuleTypeUnderTest: "cc_library_headers", + ModuleTypeUnderTestFactory: cc.LibraryHeaderFactory, + Filesystem: map[string]string{ "lib-1/lib1a.h": "", "lib-1/lib1b.h": "", "lib-2/lib2a.h": "", @@ -310,15 +310,15 @@ func TestCcLibraryHeadersNoCrtIgnored(t *testing.T) { "arch_x86_exported_include_dir/b.h": "", "arch_x86_64_exported_include_dir/c.h": "", }, - blueprint: soongCcLibraryHeadersPreamble + ` + Blueprint: soongCcLibraryHeadersPreamble + ` cc_library_headers { name: "lib-1", export_include_dirs: ["lib-1"], no_libcrt: true, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_headers", "lib-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_headers", "lib-1", AttrNameToString{ "export_includes": `["lib-1"]`, }), }, @@ -326,12 +326,12 @@ cc_library_headers { } func TestCcLibraryHeadersExportedStaticLibHeadersReexported(t *testing.T) { - runCcLibraryHeadersTestCase(t, bp2buildTestCase{ - description: "cc_library_headers exported_static_lib_headers is reexported", - moduleTypeUnderTest: "cc_library_headers", - moduleTypeUnderTestFactory: cc.LibraryHeaderFactory, - filesystem: map[string]string{}, - blueprint: soongCcLibraryHeadersPreamble + ` + runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ + Description: "cc_library_headers exported_static_lib_headers is reexported", + ModuleTypeUnderTest: "cc_library_headers", + ModuleTypeUnderTestFactory: cc.LibraryHeaderFactory, + Filesystem: map[string]string{}, + Blueprint: soongCcLibraryHeadersPreamble + ` cc_library_headers { name: "foo_headers", export_static_lib_headers: ["foo_export"], @@ -339,8 +339,8 @@ cc_library_headers { bazel_module: { bp2build_available: true }, } ` + simpleModuleDoNotConvertBp2build("cc_library_headers", "foo_export"), - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_headers", "foo_headers", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{ "deps": `[":foo_export"]`, }), }, @@ -348,12 +348,12 @@ cc_library_headers { } func TestCcLibraryHeadersExportedSharedLibHeadersReexported(t *testing.T) { - runCcLibraryHeadersTestCase(t, bp2buildTestCase{ - description: "cc_library_headers exported_shared_lib_headers is reexported", - moduleTypeUnderTest: "cc_library_headers", - moduleTypeUnderTestFactory: cc.LibraryHeaderFactory, - filesystem: map[string]string{}, - blueprint: soongCcLibraryHeadersPreamble + ` + runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ + Description: "cc_library_headers exported_shared_lib_headers is reexported", + ModuleTypeUnderTest: "cc_library_headers", + ModuleTypeUnderTestFactory: cc.LibraryHeaderFactory, + Filesystem: map[string]string{}, + Blueprint: soongCcLibraryHeadersPreamble + ` cc_library_headers { name: "foo_headers", export_shared_lib_headers: ["foo_export"], @@ -361,8 +361,8 @@ cc_library_headers { bazel_module: { bp2build_available: true }, } ` + simpleModuleDoNotConvertBp2build("cc_library_headers", "foo_export"), - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_headers", "foo_headers", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{ "deps": `[":foo_export"]`, }), }, @@ -370,12 +370,12 @@ cc_library_headers { } func TestCcLibraryHeadersExportedHeaderLibHeadersReexported(t *testing.T) { - runCcLibraryHeadersTestCase(t, bp2buildTestCase{ - description: "cc_library_headers exported_header_lib_headers is reexported", - moduleTypeUnderTest: "cc_library_headers", - moduleTypeUnderTestFactory: cc.LibraryHeaderFactory, - filesystem: map[string]string{}, - blueprint: soongCcLibraryHeadersPreamble + ` + runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ + Description: "cc_library_headers exported_header_lib_headers is reexported", + ModuleTypeUnderTest: "cc_library_headers", + ModuleTypeUnderTestFactory: cc.LibraryHeaderFactory, + Filesystem: map[string]string{}, + Blueprint: soongCcLibraryHeadersPreamble + ` cc_library_headers { name: "foo_headers", export_header_lib_headers: ["foo_export"], @@ -383,8 +383,8 @@ cc_library_headers { bazel_module: { bp2build_available: true }, } ` + simpleModuleDoNotConvertBp2build("cc_library_headers", "foo_export"), - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_headers", "foo_headers", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{ "deps": `[":foo_export"]`, }), }, diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go index be096168c..6a4786254 100644 --- a/bp2build/cc_library_shared_conversion_test.go +++ b/bp2build/cc_library_shared_conversion_test.go @@ -35,17 +35,17 @@ func registerCcLibrarySharedModuleTypes(ctx android.RegistrationContext) { ctx.RegisterModuleType("cc_library", cc.LibraryFactory) } -func runCcLibrarySharedTestCase(t *testing.T, tc bp2buildTestCase) { +func runCcLibrarySharedTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - (&tc).moduleTypeUnderTest = "cc_library_shared" - (&tc).moduleTypeUnderTestFactory = cc.LibrarySharedFactory - runBp2BuildTestCase(t, registerCcLibrarySharedModuleTypes, tc) + (&tc).ModuleTypeUnderTest = "cc_library_shared" + (&tc).ModuleTypeUnderTestFactory = cc.LibrarySharedFactory + RunBp2BuildTestCase(t, registerCcLibrarySharedModuleTypes, tc) } func TestCcLibrarySharedSimple(t *testing.T) { - runCcLibrarySharedTestCase(t, bp2buildTestCase{ - description: "cc_library_shared simple overall test", - filesystem: map[string]string{ + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_shared simple overall test", + Filesystem: map[string]string{ // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?) "include_dir_1/include_dir_1_a.h": "", "include_dir_1/include_dir_1_b.h": "", @@ -65,7 +65,7 @@ func TestCcLibrarySharedSimple(t *testing.T) { "implicit_include_1.h": "", "implicit_include_2.h": "", }, - blueprint: soongCcLibrarySharedPreamble + ` + Blueprint: soongCcLibrarySharedPreamble + ` cc_library_headers { name: "header_lib_1", export_include_dirs: ["header_lib_1"], @@ -141,8 +141,8 @@ cc_library_shared { // TODO: Also support export_header_lib_headers }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ "absolute_includes": `[ "include_dir_1", "include_dir_2", @@ -184,10 +184,10 @@ cc_library_shared { } func TestCcLibrarySharedArchSpecificSharedLib(t *testing.T) { - runCcLibrarySharedTestCase(t, bp2buildTestCase{ - description: "cc_library_shared arch-specific shared_libs with whole_static_libs", - filesystem: map[string]string{}, - blueprint: soongCcLibrarySharedPreamble + ` + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_shared arch-specific shared_libs with whole_static_libs", + Filesystem: map[string]string{}, + Blueprint: soongCcLibrarySharedPreamble + ` cc_library_static { name: "static_dep", bazel_module: { bp2build_available: false }, @@ -201,8 +201,8 @@ cc_library_shared { arch: { arm64: { shared_libs: ["shared_dep"], whole_static_libs: ["static_dep"] } }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ "implementation_dynamic_deps": `select({ "//build/bazel/platforms/arch:arm64": [":shared_dep"], "//conditions:default": [], @@ -217,10 +217,10 @@ cc_library_shared { } func TestCcLibrarySharedOsSpecificSharedLib(t *testing.T) { - runCcLibrarySharedTestCase(t, bp2buildTestCase{ - description: "cc_library_shared os-specific shared_libs", - filesystem: map[string]string{}, - blueprint: soongCcLibrarySharedPreamble + ` + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_shared os-specific shared_libs", + Filesystem: map[string]string{}, + Blueprint: soongCcLibrarySharedPreamble + ` cc_library_shared { name: "shared_dep", bazel_module: { bp2build_available: false }, @@ -230,8 +230,8 @@ cc_library_shared { target: { android: { shared_libs: ["shared_dep"], } }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ "implementation_dynamic_deps": `select({ "//build/bazel/platforms/os:android": [":shared_dep"], "//conditions:default": [], @@ -242,10 +242,10 @@ cc_library_shared { } func TestCcLibrarySharedBaseArchOsSpecificSharedLib(t *testing.T) { - runCcLibrarySharedTestCase(t, bp2buildTestCase{ - description: "cc_library_shared base, arch, and os-specific shared_libs", - filesystem: map[string]string{}, - blueprint: soongCcLibrarySharedPreamble + ` + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_shared base, arch, and os-specific shared_libs", + Filesystem: map[string]string{}, + Blueprint: soongCcLibrarySharedPreamble + ` cc_library_shared { name: "shared_dep", bazel_module: { bp2build_available: false }, @@ -265,8 +265,8 @@ cc_library_shared { arch: { arm64: { shared_libs: ["shared_dep3"] } }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ "implementation_dynamic_deps": `[":shared_dep"] + select({ "//build/bazel/platforms/arch:arm64": [":shared_dep3"], "//conditions:default": [], @@ -280,22 +280,22 @@ cc_library_shared { } func TestCcLibrarySharedSimpleExcludeSrcs(t *testing.T) { - runCcLibrarySharedTestCase(t, bp2buildTestCase{ - description: "cc_library_shared simple exclude_srcs", - filesystem: map[string]string{ + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_shared simple exclude_srcs", + Filesystem: map[string]string{ "common.c": "", "foo-a.c": "", "foo-excluded.c": "", }, - blueprint: soongCcLibrarySharedPreamble + ` + Blueprint: soongCcLibrarySharedPreamble + ` cc_library_shared { name: "foo_shared", srcs: ["common.c", "foo-*.c"], exclude_srcs: ["foo-excluded.c"], include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ "srcs_c": `[ "common.c", "foo-a.c", @@ -306,10 +306,10 @@ cc_library_shared { } func TestCcLibrarySharedStrip(t *testing.T) { - runCcLibrarySharedTestCase(t, bp2buildTestCase{ - description: "cc_library_shared stripping", - filesystem: map[string]string{}, - blueprint: soongCcLibrarySharedPreamble + ` + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_shared stripping", + Filesystem: map[string]string{}, + Blueprint: soongCcLibrarySharedPreamble + ` cc_library_shared { name: "foo_shared", strip: { @@ -321,8 +321,8 @@ cc_library_shared { }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ "strip": `{ "all": True, "keep_symbols": False, @@ -339,19 +339,19 @@ cc_library_shared { } func TestCcLibrarySharedVersionScript(t *testing.T) { - runCcLibrarySharedTestCase(t, bp2buildTestCase{ - description: "cc_library_shared version script", - filesystem: map[string]string{ + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_shared version script", + Filesystem: map[string]string{ "version_script": "", }, - blueprint: soongCcLibrarySharedPreamble + ` + Blueprint: soongCcLibrarySharedPreamble + ` cc_library_shared { name: "foo_shared", version_script: "version_script", include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ "additional_linker_inputs": `["version_script"]`, "linkopts": `["-Wl,--version-script,$(location version_script)"]`, }), @@ -360,12 +360,12 @@ cc_library_shared { } func TestCcLibrarySharedNoCrtTrue(t *testing.T) { - runCcLibrarySharedTestCase(t, bp2buildTestCase{ - description: "cc_library_shared - nocrt: true emits attribute", - filesystem: map[string]string{ + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_shared - nocrt: true emits attribute", + Filesystem: map[string]string{ "impl.cpp": "", }, - blueprint: soongCcLibraryPreamble + ` + Blueprint: soongCcLibraryPreamble + ` cc_library_shared { name: "foo_shared", srcs: ["impl.cpp"], @@ -373,8 +373,8 @@ cc_library_shared { include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ "link_crt": `False`, "srcs": `["impl.cpp"]`, }), @@ -383,12 +383,12 @@ cc_library_shared { } func TestCcLibrarySharedNoCrtFalse(t *testing.T) { - runCcLibrarySharedTestCase(t, bp2buildTestCase{ - description: "cc_library_shared - nocrt: false doesn't emit attribute", - filesystem: map[string]string{ + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_shared - nocrt: false doesn't emit attribute", + Filesystem: map[string]string{ "impl.cpp": "", }, - blueprint: soongCcLibraryPreamble + ` + Blueprint: soongCcLibraryPreamble + ` cc_library_shared { name: "foo_shared", srcs: ["impl.cpp"], @@ -396,8 +396,8 @@ cc_library_shared { include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ "srcs": `["impl.cpp"]`, }), }, @@ -405,12 +405,12 @@ cc_library_shared { } func TestCcLibrarySharedNoCrtArchVariant(t *testing.T) { - runCcLibrarySharedTestCase(t, bp2buildTestCase{ - description: "cc_library_shared - nocrt in select", - filesystem: map[string]string{ + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_shared - nocrt in select", + Filesystem: map[string]string{ "impl.cpp": "", }, - blueprint: soongCcLibraryPreamble + ` + Blueprint: soongCcLibraryPreamble + ` cc_library_shared { name: "foo_shared", srcs: ["impl.cpp"], @@ -425,13 +425,13 @@ cc_library_shared { include_build_directory: false, } `, - expectedErr: fmt.Errorf("module \"foo_shared\": nocrt is not supported for arch variants"), + ExpectedErr: fmt.Errorf("module \"foo_shared\": nocrt is not supported for arch variants"), }) } func TestCcLibrarySharedProto(t *testing.T) { - runCcLibrarySharedTestCase(t, bp2buildTestCase{ - blueprint: soongCcProtoPreamble + `cc_library_shared { + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Blueprint: soongCcProtoPreamble + `cc_library_shared { name: "foo", srcs: ["foo.proto"], proto: { @@ -439,12 +439,12 @@ func TestCcLibrarySharedProto(t *testing.T) { }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("proto_library", "foo_proto", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("proto_library", "foo_proto", AttrNameToString{ "srcs": `["foo.proto"]`, - }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ "deps": `[":foo_proto"]`, - }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ + }), makeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "dynamic_deps": `[":libprotobuf-cpp-lite"]`, "whole_archive_deps": `[":foo_cc_proto_lite"]`, }), @@ -453,14 +453,14 @@ func TestCcLibrarySharedProto(t *testing.T) { } func TestCcLibrarySharedUseVersionLib(t *testing.T) { - runCcLibrarySharedTestCase(t, bp2buildTestCase{ - blueprint: soongCcProtoPreamble + `cc_library_shared { + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Blueprint: soongCcProtoPreamble + `cc_library_shared { name: "foo", use_version_lib: true, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_shared", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "use_version_lib": "True", }), }, @@ -468,12 +468,12 @@ func TestCcLibrarySharedUseVersionLib(t *testing.T) { } func TestCcLibrarySharedStubs(t *testing.T) { - runCcLibrarySharedTestCase(t, bp2buildTestCase{ - description: "cc_library_shared stubs", - moduleTypeUnderTest: "cc_library_shared", - moduleTypeUnderTestFactory: cc.LibrarySharedFactory, - dir: "foo/bar", - filesystem: map[string]string{ + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_shared stubs", + ModuleTypeUnderTest: "cc_library_shared", + ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, + Dir: "foo/bar", + Filesystem: map[string]string{ "foo/bar/Android.bp": ` cc_library_shared { name: "a", @@ -483,8 +483,8 @@ cc_library_shared { } `, }, - blueprint: soongCcLibraryPreamble, - expectedBazelTargets: []string{makeBazelTarget("cc_library_shared", "a", attrNameToString{ + Blueprint: soongCcLibraryPreamble, + ExpectedBazelTargets: []string{makeBazelTarget("cc_library_shared", "a", AttrNameToString{ "stubs_symbol_file": `"a.map.txt"`, "stubs_versions": `[ "28", @@ -498,11 +498,11 @@ cc_library_shared { } func TestCcLibrarySharedSystemSharedLibsSharedEmpty(t *testing.T) { - runCcLibrarySharedTestCase(t, bp2buildTestCase{ - description: "cc_library_shared system_shared_libs empty shared default", - moduleTypeUnderTest: "cc_library_shared", - moduleTypeUnderTestFactory: cc.LibrarySharedFactory, - blueprint: soongCcLibrarySharedPreamble + ` + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_shared system_shared_libs empty shared default", + ModuleTypeUnderTest: "cc_library_shared", + ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, + Blueprint: soongCcLibrarySharedPreamble + ` cc_defaults { name: "empty_defaults", shared: { @@ -515,18 +515,18 @@ cc_library_shared { defaults: ["empty_defaults"], } `, - expectedBazelTargets: []string{makeBazelTarget("cc_library_shared", "empty", attrNameToString{ + ExpectedBazelTargets: []string{makeBazelTarget("cc_library_shared", "empty", AttrNameToString{ "system_dynamic_deps": "[]", })}, }) } func TestCcLibrarySharedConvertLex(t *testing.T) { - runCcLibrarySharedTestCase(t, bp2buildTestCase{ - description: "cc_library_shared with lex files", - moduleTypeUnderTest: "cc_library_shared", - moduleTypeUnderTestFactory: cc.LibrarySharedFactory, - filesystem: map[string]string{ + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_shared with lex files", + ModuleTypeUnderTest: "cc_library_shared", + ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, + Filesystem: map[string]string{ "foo.c": "", "bar.cc": "", "foo1.l": "", @@ -534,29 +534,29 @@ func TestCcLibrarySharedConvertLex(t *testing.T) { "foo2.l": "", "bar2.ll": "", }, - blueprint: `cc_library_shared { + Blueprint: `cc_library_shared { name: "foo_lib", srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"], lex: { flags: ["--foo_flags"] }, include_build_directory: false, bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("genlex", "foo_lib_genlex_l", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{ "srcs": `[ "foo1.l", "foo2.l", ]`, "lexopts": `["--foo_flags"]`, }), - makeBazelTarget("genlex", "foo_lib_genlex_ll", attrNameToString{ + makeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{ "srcs": `[ "bar1.ll", "bar2.ll", ]`, "lexopts": `["--foo_flags"]`, }), - makeBazelTarget("cc_library_shared", "foo_lib", attrNameToString{ + makeBazelTarget("cc_library_shared", "foo_lib", AttrNameToString{ "srcs": `[ "bar.cc", ":foo_lib_genlex_ll", @@ -569,3 +569,58 @@ func TestCcLibrarySharedConvertLex(t *testing.T) { }, }) } + +func TestCcLibrarySharedClangUnknownFlags(t *testing.T) { + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Blueprint: soongCcProtoPreamble + `cc_library_shared { + name: "foo", + conlyflags: ["-a", "-finline-functions"], + cflags: ["-b","-finline-functions"], + cppflags: ["-c", "-finline-functions"], + ldflags: ["-d","-finline-functions", "-e"], + include_build_directory: false, +}`, + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_shared", "foo", AttrNameToString{ + "conlyflags": `["-a"]`, + "copts": `["-b"]`, + "cppflags": `["-c"]`, + "linkopts": `[ + "-d", + "-e", + ]`, + }), + }, + }) +} + +func TestCCLibraryFlagSpaceSplitting(t *testing.T) { + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Blueprint: soongCcProtoPreamble + `cc_library_shared { + name: "foo", + conlyflags: [ "-include header.h"], + cflags: ["-include header.h"], + cppflags: ["-include header.h"], + version_script: "version_script", + include_build_directory: false, +}`, + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_shared", "foo", AttrNameToString{ + "additional_linker_inputs": `["version_script"]`, + "conlyflags": `[ + "-include", + "header.h", + ]`, + "copts": `[ + "-include", + "header.h", + ]`, + "cppflags": `[ + "-include", + "header.h", + ]`, + "linkopts": `["-Wl,--version-script,$(location version_script)"]`, + }), + }, + }) +} diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go index 36c46a427..ddb7bf94b 100644 --- a/bp2build/cc_library_static_conversion_test.go +++ b/bp2build/cc_library_static_conversion_test.go @@ -65,18 +65,18 @@ func registerCcLibraryStaticModuleTypes(ctx android.RegistrationContext) { ctx.RegisterModuleType("cc_library", cc.LibraryFactory) } -func runCcLibraryStaticTestCase(t *testing.T, tc bp2buildTestCase) { +func runCcLibraryStaticTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - (&tc).moduleTypeUnderTest = "cc_library_static" - (&tc).moduleTypeUnderTestFactory = cc.LibraryStaticFactory - runBp2BuildTestCase(t, registerCcLibraryStaticModuleTypes, tc) + (&tc).ModuleTypeUnderTest = "cc_library_static" + (&tc).ModuleTypeUnderTestFactory = cc.LibraryStaticFactory + RunBp2BuildTestCase(t, registerCcLibraryStaticModuleTypes, tc) } func TestCcLibraryStaticSimple(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static test", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static test", + Filesystem: map[string]string{ // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?) "include_dir_1/include_dir_1_a.h": "", "include_dir_1/include_dir_1_b.h": "", @@ -96,7 +96,7 @@ func TestCcLibraryStaticSimple(t *testing.T) { "implicit_include_1.h": "", "implicit_include_2.h": "", }, - blueprint: soongCcLibraryStaticPreamble + ` + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_headers { name: "header_lib_1", export_include_dirs: ["header_lib_1"], @@ -172,8 +172,8 @@ cc_library_static { // TODO: Also support export_header_lib_headers }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "absolute_includes": `[ "include_dir_1", "include_dir_2", @@ -213,9 +213,9 @@ cc_library_static { } func TestCcLibraryStaticSubpackage(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static subpackage test", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static subpackage test", + Filesystem: map[string]string{ // subpackage with subdirectory "subpackage/Android.bp": "", "subpackage/subpackage_header.h": "", @@ -229,7 +229,7 @@ func TestCcLibraryStaticSubpackage(t *testing.T) { "subpackage/subsubpackage/subsubsubpackage/subsubsubpackage_header.h": "", "subpackage/subsubpackage/subsubsubpackage/subdirectory/subdirectory_header.h": "", }, - blueprint: soongCcLibraryStaticPreamble + ` + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", srcs: [], @@ -237,8 +237,8 @@ cc_library_static { "subpackage", ], }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "absolute_includes": `["subpackage"]`, "local_includes": `["."]`, }), @@ -247,22 +247,22 @@ cc_library_static { } func TestCcLibraryStaticExportIncludeDir(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static export include dir", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static export include dir", + Filesystem: map[string]string{ // subpackage with subdirectory "subpackage/Android.bp": "", "subpackage/subpackage_header.h": "", "subpackage/subdirectory/subdirectory_header.h": "", }, - blueprint: soongCcLibraryStaticPreamble + ` + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", export_include_dirs: ["subpackage"], include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "export_includes": `["subpackage"]`, }), }, @@ -270,22 +270,22 @@ cc_library_static { } func TestCcLibraryStaticExportSystemIncludeDir(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static export system include dir", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static export system include dir", + Filesystem: map[string]string{ // subpackage with subdirectory "subpackage/Android.bp": "", "subpackage/subpackage_header.h": "", "subpackage/subdirectory/subdirectory_header.h": "", }, - blueprint: soongCcLibraryStaticPreamble + ` + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", export_system_include_dirs: ["subpackage"], include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "export_system_includes": `["subpackage"]`, }), }, @@ -293,10 +293,10 @@ cc_library_static { } func TestCcLibraryStaticManyIncludeDirs(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static include_dirs, local_include_dirs, export_include_dirs (b/183742505)", - dir: "subpackage", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static include_dirs, local_include_dirs, export_include_dirs (b/183742505)", + Dir: "subpackage", + Filesystem: map[string]string{ // subpackage with subdirectory "subpackage/Android.bp": ` cc_library_static { @@ -318,9 +318,9 @@ cc_library_static { "subpackage2/header.h": "", "subpackage3/subsubpackage/header.h": "", }, - blueprint: soongCcLibraryStaticPreamble, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + Blueprint: soongCcLibraryStaticPreamble, + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "absolute_includes": `[ "subpackage/subsubpackage", "subpackage2", @@ -336,23 +336,23 @@ cc_library_static { } func TestCcLibraryStaticIncludeBuildDirectoryDisabled(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static include_build_directory disabled", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static include_build_directory disabled", + Filesystem: map[string]string{ // subpackage with subdirectory "subpackage/Android.bp": "", "subpackage/subpackage_header.h": "", "subpackage/subdirectory/subdirectory_header.h": "", }, - blueprint: soongCcLibraryStaticPreamble + ` + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended local_include_dirs: ["subpackage2"], include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "absolute_includes": `["subpackage"]`, "local_includes": `["subpackage2"]`, }), @@ -361,9 +361,9 @@ cc_library_static { } func TestCcLibraryStaticIncludeBuildDirectoryEnabled(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static include_build_directory enabled", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static include_build_directory enabled", + Filesystem: map[string]string{ // subpackage with subdirectory "subpackage/Android.bp": "", "subpackage/subpackage_header.h": "", @@ -371,15 +371,15 @@ func TestCcLibraryStaticIncludeBuildDirectoryEnabled(t *testing.T) { "subpackage2/subpackage2_header.h": "", "subpackage/subdirectory/subdirectory_header.h": "", }, - blueprint: soongCcLibraryStaticPreamble + ` + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended local_include_dirs: ["subpackage2"], include_build_directory: true, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "absolute_includes": `["subpackage"]`, "local_includes": `[ "subpackage2", @@ -391,10 +391,10 @@ cc_library_static { } func TestCcLibraryStaticArchSpecificStaticLib(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static arch-specific static_libs", - filesystem: map[string]string{}, - blueprint: soongCcLibraryStaticPreamble + ` + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static arch-specific static_libs", + Filesystem: map[string]string{}, + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "static_dep", bazel_module: { bp2build_available: false }, @@ -408,8 +408,8 @@ cc_library_static { arch: { arm64: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "implementation_deps": `select({ "//build/bazel/platforms/arch:arm64": [":static_dep"], "//conditions:default": [], @@ -424,10 +424,10 @@ cc_library_static { } func TestCcLibraryStaticOsSpecificStaticLib(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static os-specific static_libs", - filesystem: map[string]string{}, - blueprint: soongCcLibraryStaticPreamble + ` + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static os-specific static_libs", + Filesystem: map[string]string{}, + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "static_dep", bazel_module: { bp2build_available: false }, @@ -441,8 +441,8 @@ cc_library_static { target: { android: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "implementation_deps": `select({ "//build/bazel/platforms/os:android": [":static_dep"], "//conditions:default": [], @@ -457,10 +457,10 @@ cc_library_static { } func TestCcLibraryStaticBaseArchOsSpecificStaticLib(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static base, arch and os-specific static_libs", - filesystem: map[string]string{}, - blueprint: soongCcLibraryStaticPreamble + ` + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static base, arch and os-specific static_libs", + Filesystem: map[string]string{}, + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "static_dep", bazel_module: { bp2build_available: false }, @@ -485,8 +485,8 @@ cc_library_static { arch: { arm64: { static_libs: ["static_dep4"] } }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "implementation_deps": `[":static_dep"] + select({ "//build/bazel/platforms/arch:arm64": [":static_dep4"], "//conditions:default": [], @@ -501,22 +501,22 @@ cc_library_static { } func TestCcLibraryStaticSimpleExcludeSrcs(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static simple exclude_srcs", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static simple exclude_srcs", + Filesystem: map[string]string{ "common.c": "", "foo-a.c": "", "foo-excluded.c": "", }, - blueprint: soongCcLibraryStaticPreamble + ` + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", srcs: ["common.c", "foo-*.c"], exclude_srcs: ["foo-excluded.c"], include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "srcs_c": `[ "common.c", "foo-a.c", @@ -527,21 +527,21 @@ cc_library_static { } func TestCcLibraryStaticOneArchSrcs(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static one arch specific srcs", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static one arch specific srcs", + Filesystem: map[string]string{ "common.c": "", "foo-arm.c": "", }, - blueprint: soongCcLibraryStaticPreamble + ` + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", srcs: ["common.c"], arch: { arm: { srcs: ["foo-arm.c"] } }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "srcs_c": `["common.c"] + select({ "//build/bazel/platforms/arch:arm": ["foo-arm.c"], "//conditions:default": [], @@ -552,15 +552,15 @@ cc_library_static { } func TestCcLibraryStaticOneArchSrcsExcludeSrcs(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static one arch specific srcs and exclude_srcs", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static one arch specific srcs and exclude_srcs", + Filesystem: map[string]string{ "common.c": "", "for-arm.c": "", "not-for-arm.c": "", "not-for-anything.c": "", }, - blueprint: soongCcLibraryStaticPreamble + ` + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", srcs: ["common.c", "not-for-*.c"], @@ -570,8 +570,8 @@ cc_library_static { }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "srcs_c": `["common.c"] + select({ "//build/bazel/platforms/arch:arm": ["for-arm.c"], "//conditions:default": ["not-for-arm.c"], @@ -582,16 +582,16 @@ cc_library_static { } func TestCcLibraryStaticTwoArchExcludeSrcs(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static arch specific exclude_srcs for 2 architectures", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static arch specific exclude_srcs for 2 architectures", + Filesystem: map[string]string{ "common.c": "", "for-arm.c": "", "for-x86.c": "", "not-for-arm.c": "", "not-for-x86.c": "", }, - blueprint: soongCcLibraryStaticPreamble + ` + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", srcs: ["common.c", "not-for-*.c"], @@ -602,8 +602,8 @@ cc_library_static { }, include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "srcs_c": `["common.c"] + select({ "//build/bazel/platforms/arch:arm": [ "not-for-x86.c", @@ -624,9 +624,9 @@ cc_library_static { } func TestCcLibraryStaticFourArchExcludeSrcs(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static arch specific exclude_srcs for 4 architectures", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static arch specific exclude_srcs for 4 architectures", + Filesystem: map[string]string{ "common.c": "", "for-arm.c": "", "for-arm64.c": "", @@ -638,7 +638,7 @@ func TestCcLibraryStaticFourArchExcludeSrcs(t *testing.T) { "not-for-x86_64.c": "", "not-for-everything.c": "", }, - blueprint: soongCcLibraryStaticPreamble + ` + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", srcs: ["common.c", "not-for-*.c"], @@ -651,8 +651,8 @@ cc_library_static { }, include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "srcs_c": `["common.c"] + select({ "//build/bazel/platforms/arch:arm": [ "not-for-arm64.c", @@ -691,14 +691,14 @@ cc_library_static { } func TestCcLibraryStaticOneArchEmpty(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static one arch empty", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static one arch empty", + Filesystem: map[string]string{ "common.cc": "", "foo-no-arm.cc": "", "foo-excluded.cc": "", }, - blueprint: soongCcLibraryStaticPreamble + ` + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", srcs: ["common.cc", "foo-*.cc"], @@ -708,8 +708,8 @@ cc_library_static { }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "srcs": `["common.cc"] + select({ "//build/bazel/platforms/arch:arm": [], "//conditions:default": ["foo-no-arm.cc"], @@ -720,15 +720,15 @@ cc_library_static { } func TestCcLibraryStaticOneArchEmptyOtherSet(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static one arch empty other set", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static one arch empty other set", + Filesystem: map[string]string{ "common.cc": "", "foo-no-arm.cc": "", "x86-only.cc": "", "foo-excluded.cc": "", }, - blueprint: soongCcLibraryStaticPreamble + ` + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", srcs: ["common.cc", "foo-*.cc"], @@ -739,8 +739,8 @@ cc_library_static { }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "srcs": `["common.cc"] + select({ "//build/bazel/platforms/arch:arm": [], "//build/bazel/platforms/arch:x86": [ @@ -755,10 +755,10 @@ cc_library_static { } func TestCcLibraryStaticMultipleDepSameName(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static multiple dep same name panic", - filesystem: map[string]string{}, - blueprint: soongCcLibraryStaticPreamble + ` + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static multiple dep same name panic", + Filesystem: map[string]string{}, + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "static_dep", bazel_module: { bp2build_available: false }, @@ -768,8 +768,8 @@ cc_library_static { static_libs: ["static_dep", "static_dep"], include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "implementation_deps": `[":static_dep"]`, }), }, @@ -777,14 +777,14 @@ cc_library_static { } func TestCcLibraryStaticOneMultilibSrcsExcludeSrcs(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static 1 multilib srcs and exclude_srcs", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static 1 multilib srcs and exclude_srcs", + Filesystem: map[string]string{ "common.c": "", "for-lib32.c": "", "not-for-lib32.c": "", }, - blueprint: soongCcLibraryStaticPreamble + ` + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", srcs: ["common.c", "not-for-*.c"], @@ -793,8 +793,8 @@ cc_library_static { }, include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "srcs_c": `["common.c"] + select({ "//build/bazel/platforms/arch:arm": ["for-lib32.c"], "//build/bazel/platforms/arch:x86": ["for-lib32.c"], @@ -806,16 +806,16 @@ cc_library_static { } func TestCcLibraryStaticTwoMultilibSrcsExcludeSrcs(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static 2 multilib srcs and exclude_srcs", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static 2 multilib srcs and exclude_srcs", + Filesystem: map[string]string{ "common.c": "", "for-lib32.c": "", "for-lib64.c": "", "not-for-lib32.c": "", "not-for-lib64.c": "", }, - blueprint: soongCcLibraryStaticPreamble + ` + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", srcs: ["common.c", "not-for-*.c"], @@ -825,8 +825,8 @@ cc_library_static { }, include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "srcs_c": `["common.c"] + select({ "//build/bazel/platforms/arch:arm": [ "not-for-lib64.c", @@ -855,9 +855,9 @@ cc_library_static { } func TestCcLibrarySTaticArchMultilibSrcsExcludeSrcs(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static arch and multilib srcs and exclude_srcs", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static arch and multilib srcs and exclude_srcs", + Filesystem: map[string]string{ "common.c": "", "for-arm.c": "", "for-arm64.c": "", @@ -873,7 +873,7 @@ func TestCcLibrarySTaticArchMultilibSrcsExcludeSrcs(t *testing.T) { "not-for-lib64.c": "", "not-for-everything.c": "", }, - blueprint: soongCcLibraryStaticPreamble + ` + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", srcs: ["common.c", "not-for-*.c"], @@ -890,8 +890,8 @@ cc_library_static { }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "srcs_c": `["common.c"] + select({ "//build/bazel/platforms/arch:arm": [ "not-for-arm64.c", @@ -940,8 +940,8 @@ cc_library_static { } func TestCcLibraryStaticGeneratedHeadersAllPartitions(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - blueprint: soongCcLibraryStaticPreamble + ` + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Blueprint: soongCcLibraryStaticPreamble + ` genrule { name: "generated_hdr", cmd: "nothing to see here", @@ -961,8 +961,8 @@ cc_library_static { export_generated_headers: ["export_generated_hdr"], include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "export_includes": `["."]`, "local_includes": `["."]`, "hdrs": `[":export_generated_hdr"]`, @@ -984,9 +984,9 @@ cc_library_static { } func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static arch srcs/exclude_srcs with generated files", - filesystem: map[string]string{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static arch srcs/exclude_srcs with generated files", + Filesystem: map[string]string{ "common.cpp": "", "for-x86.cpp": "", "not-for-x86.cpp": "", @@ -997,7 +997,7 @@ func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) { simpleModuleDoNotConvertBp2build("genrule", "generated_hdr_other_pkg_x86") + simpleModuleDoNotConvertBp2build("genrule", "generated_hdr_other_pkg_android"), }, - blueprint: soongCcLibraryStaticPreamble + + Blueprint: soongCcLibraryStaticPreamble + simpleModuleDoNotConvertBp2build("genrule", "generated_src") + simpleModuleDoNotConvertBp2build("genrule", "generated_src_not_x86") + simpleModuleDoNotConvertBp2build("genrule", "generated_src_android") + @@ -1029,8 +1029,8 @@ cc_library_static { include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "srcs": `[ "common.cpp", ":generated_src", @@ -1061,10 +1061,10 @@ cc_library_static { } func TestCcLibraryStaticGetTargetProperties(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ - description: "cc_library_static complex GetTargetProperties", - blueprint: soongCcLibraryStaticPreamble + ` + Description: "cc_library_static complex GetTargetProperties", + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", target: { @@ -1092,8 +1092,8 @@ cc_library_static { }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "srcs_c": `select({ "//build/bazel/platforms/os:android": ["android_src.c"], "//conditions:default": [], @@ -1112,9 +1112,9 @@ cc_library_static { } func TestCcLibraryStaticProductVariableSelects(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static product variable selects", - blueprint: soongCcLibraryStaticPreamble + ` + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static product variable selects", + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", srcs: ["common.c"], @@ -1131,8 +1131,8 @@ cc_library_static { }, include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "copts": `select({ "//build/bazel/product_variables:binder32bit": ["-Wbinder32bit"], "//conditions:default": [], @@ -1150,10 +1150,10 @@ cc_library_static { } func TestCcLibraryStaticProductVariableArchSpecificSelects(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static arch-specific product variable selects", - filesystem: map[string]string{}, - blueprint: soongCcLibraryStaticPreamble + ` + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static arch-specific product variable selects", + Filesystem: map[string]string{}, + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", srcs: ["common.c"], @@ -1191,8 +1191,8 @@ cc_library_static { }, include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "copts": `select({ "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"], "//conditions:default": [], @@ -1216,10 +1216,10 @@ cc_library_static { } func TestCcLibraryStaticProductVariableStringReplacement(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static product variable string replacement", - filesystem: map[string]string{}, - blueprint: soongCcLibraryStaticPreamble + ` + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static product variable string replacement", + Filesystem: map[string]string{}, + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", srcs: ["common.S"], @@ -1230,8 +1230,8 @@ cc_library_static { }, include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo_static", AttrNameToString{ "asflags": `select({ "//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"], "//conditions:default": [], @@ -1243,17 +1243,17 @@ cc_library_static { } func TestStaticLibrary_SystemSharedLibsRootEmpty(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static system_shared_lib empty root", - blueprint: soongCcLibraryStaticPreamble + ` + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static system_shared_lib empty root", + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "root_empty", system_shared_libs: [], include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "root_empty", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "root_empty", AttrNameToString{ "system_dynamic_deps": `[]`, }), }, @@ -1261,9 +1261,9 @@ cc_library_static { } func TestStaticLibrary_SystemSharedLibsStaticEmpty(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static system_shared_lib empty static default", - blueprint: soongCcLibraryStaticPreamble + ` + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static system_shared_lib empty static default", + Blueprint: soongCcLibraryStaticPreamble + ` cc_defaults { name: "static_empty_defaults", static: { @@ -1276,8 +1276,8 @@ cc_library_static { defaults: ["static_empty_defaults"], } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "static_empty", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "static_empty", AttrNameToString{ "system_dynamic_deps": `[]`, }), }, @@ -1285,9 +1285,9 @@ cc_library_static { } func TestStaticLibrary_SystemSharedLibsBionicEmpty(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static system_shared_lib empty for bionic variant", - blueprint: soongCcLibraryStaticPreamble + ` + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static system_shared_lib empty for bionic variant", + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "target_bionic_empty", target: { @@ -1298,8 +1298,8 @@ cc_library_static { include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "target_bionic_empty", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "target_bionic_empty", AttrNameToString{ "system_dynamic_deps": `[]`, }), }, @@ -1311,9 +1311,9 @@ func TestStaticLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) { // The correct behavior would be if bp2build wrote `system_dynamic_deps = []` // only for linux_bionic, but `android` had `["libc", "libdl", "libm"]. // b/195791252 tracks the fix. - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static system_shared_lib empty for linux_bionic variant", - blueprint: soongCcLibraryStaticPreamble + ` + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static system_shared_lib empty for linux_bionic variant", + Blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "target_linux_bionic_empty", target: { @@ -1324,8 +1324,8 @@ cc_library_static { include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "target_linux_bionic_empty", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "target_linux_bionic_empty", AttrNameToString{ "system_dynamic_deps": `[]`, }), }, @@ -1333,9 +1333,9 @@ cc_library_static { } func TestStaticLibrary_SystemSharedLibsBionic(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static system_shared_libs set for bionic variant", - blueprint: soongCcLibraryStaticPreamble + + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static system_shared_libs set for bionic variant", + Blueprint: soongCcLibraryStaticPreamble + simpleModuleDoNotConvertBp2build("cc_library", "libc") + ` cc_library_static { name: "target_bionic", @@ -1347,8 +1347,8 @@ cc_library_static { include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "target_bionic", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "target_bionic", AttrNameToString{ "system_dynamic_deps": `select({ "//build/bazel/platforms/os:android": [":libc"], "//build/bazel/platforms/os:linux_bionic": [":libc"], @@ -1360,9 +1360,9 @@ cc_library_static { } func TestStaticLibrary_SystemSharedLibsLinuxRootAndLinuxBionic(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static system_shared_libs set for root and linux_bionic variant", - blueprint: soongCcLibraryStaticPreamble + + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static system_shared_libs set for root and linux_bionic variant", + Blueprint: soongCcLibraryStaticPreamble + simpleModuleDoNotConvertBp2build("cc_library", "libc") + simpleModuleDoNotConvertBp2build("cc_library", "libm") + ` cc_library_static { @@ -1376,8 +1376,8 @@ cc_library_static { include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "target_linux_bionic", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "target_linux_bionic", AttrNameToString{ "system_dynamic_deps": `[":libc"] + select({ "//build/bazel/platforms/os:linux_bionic": [":libm"], "//conditions:default": [], @@ -1388,9 +1388,9 @@ cc_library_static { } func TestCcLibrarystatic_SystemSharedLibUsedAsDep(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static system_shared_lib empty for linux_bionic variant", - blueprint: soongCcLibraryStaticPreamble + + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static system_shared_lib empty for linux_bionic variant", + Blueprint: soongCcLibraryStaticPreamble + simpleModuleDoNotConvertBp2build("cc_library", "libc") + ` cc_library_static { name: "used_in_bionic_oses", @@ -1418,26 +1418,26 @@ cc_library_static { include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "all", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "all", AttrNameToString{ "implementation_dynamic_deps": `select({ "//build/bazel/platforms/os:android": [], "//build/bazel/platforms/os:linux_bionic": [], "//conditions:default": [":libc"], })`, }), - makeBazelTarget("cc_library_static", "keep_for_empty_system_shared_libs", attrNameToString{ + makeBazelTarget("cc_library_static", "keep_for_empty_system_shared_libs", AttrNameToString{ "implementation_dynamic_deps": `[":libc"]`, "system_dynamic_deps": `[]`, }), - makeBazelTarget("cc_library_static", "used_in_bionic_oses", attrNameToString{}), + makeBazelTarget("cc_library_static", "used_in_bionic_oses", AttrNameToString{}), }, }) } func TestCcLibraryStaticProto(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - blueprint: soongCcProtoPreamble + `cc_library_static { + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Blueprint: soongCcProtoPreamble + `cc_library_static { name: "foo", srcs: ["foo.proto"], proto: { @@ -1445,12 +1445,12 @@ func TestCcLibraryStaticProto(t *testing.T) { }, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("proto_library", "foo_proto", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("proto_library", "foo_proto", AttrNameToString{ "srcs": `["foo.proto"]`, - }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ "deps": `[":foo_proto"]`, - }), makeBazelTarget("cc_library_static", "foo", attrNameToString{ + }), makeBazelTarget("cc_library_static", "foo", AttrNameToString{ "deps": `[":libprotobuf-cpp-lite"]`, "whole_archive_deps": `[":foo_cc_proto_lite"]`, }), @@ -1459,14 +1459,14 @@ func TestCcLibraryStaticProto(t *testing.T) { } func TestCcLibraryStaticUseVersionLib(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - blueprint: soongCcProtoPreamble + `cc_library_static { + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Blueprint: soongCcProtoPreamble + `cc_library_static { name: "foo", use_version_lib: true, include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo", AttrNameToString{ "use_version_lib": "True", }), }, @@ -1474,16 +1474,16 @@ func TestCcLibraryStaticUseVersionLib(t *testing.T) { } func TestCcLibraryStaticStdInFlags(t *testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - blueprint: soongCcProtoPreamble + `cc_library_static { + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Blueprint: soongCcProtoPreamble + `cc_library_static { name: "foo", cflags: ["-std=candcpp"], conlyflags: ["-std=conly"], cppflags: ["-std=cpp"], include_build_directory: false, }`, - expectedBazelTargets: []string{ - makeBazelTarget("cc_library_static", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo", AttrNameToString{ "conlyflags": `["-std=conly"]`, "cppflags": `["-std=cpp"]`, }), @@ -1495,64 +1495,64 @@ func TestCcLibraryStaticStl(t *testing.T) { testCases := []struct { desc string prop string - attr attrNameToString + attr AttrNameToString }{ { desc: "c++_shared deduped to libc++", prop: `stl: "c++_shared",`, - attr: attrNameToString{ + attr: AttrNameToString{ "stl": `"libc++"`, }, }, { desc: "libc++ to libc++", prop: `stl: "libc++",`, - attr: attrNameToString{ + attr: AttrNameToString{ "stl": `"libc++"`, }, }, { desc: "c++_static to libc++_static", prop: `stl: "c++_static",`, - attr: attrNameToString{ + attr: AttrNameToString{ "stl": `"libc++_static"`, }, }, { desc: "libc++_static to libc++_static", prop: `stl: "libc++_static",`, - attr: attrNameToString{ + attr: AttrNameToString{ "stl": `"libc++_static"`, }, }, { desc: "system to system", prop: `stl: "system",`, - attr: attrNameToString{ + attr: AttrNameToString{ "stl": `"system"`, }, }, { desc: "none to none", prop: `stl: "none",`, - attr: attrNameToString{ + attr: AttrNameToString{ "stl": `"none"`, }, }, { desc: "empty to empty", - attr: attrNameToString{}, + attr: AttrNameToString{}, }, } for _, tc := range testCases { t.Run(tc.desc, func(*testing.T) { - runCcLibraryStaticTestCase(t, bp2buildTestCase{ - blueprint: fmt.Sprintf(`cc_library_static { + runCcLibraryStaticTestCase(t, Bp2buildTestCase{ + Blueprint: fmt.Sprintf(`cc_library_static { name: "foo", include_build_directory: false, %s }`, tc.prop), - expectedBazelTargets: []string{ + ExpectedBazelTargets: []string{ makeBazelTarget("cc_library_static", "foo", tc.attr), }, }) diff --git a/bp2build/cc_object_conversion_test.go b/bp2build/cc_object_conversion_test.go index 52688d9e9..37d55809a 100644 --- a/bp2build/cc_object_conversion_test.go +++ b/bp2build/cc_object_conversion_test.go @@ -26,23 +26,23 @@ func registerCcObjectModuleTypes(ctx android.RegistrationContext) { ctx.RegisterModuleType("cc_defaults", func() android.Module { return cc.DefaultsFactory() }) } -func runCcObjectTestCase(t *testing.T, tc bp2buildTestCase) { +func runCcObjectTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - (&tc).moduleTypeUnderTest = "cc_object" - (&tc).moduleTypeUnderTestFactory = cc.ObjectFactory - runBp2BuildTestCase(t, registerCcObjectModuleTypes, tc) + (&tc).ModuleTypeUnderTest = "cc_object" + (&tc).ModuleTypeUnderTestFactory = cc.ObjectFactory + RunBp2BuildTestCase(t, registerCcObjectModuleTypes, tc) } func TestCcObjectSimple(t *testing.T) { - runCcObjectTestCase(t, bp2buildTestCase{ - description: "simple cc_object generates cc_object with include header dep", - filesystem: map[string]string{ + runCcObjectTestCase(t, Bp2buildTestCase{ + Description: "simple cc_object generates cc_object with include header dep", + Filesystem: map[string]string{ "a/b/foo.h": "", "a/b/bar.h": "", "a/b/exclude.c": "", "a/b/c.c": "", }, - blueprint: `cc_object { + Blueprint: `cc_object { name: "foo", local_include_dirs: ["include"], system_shared_libs: [], @@ -59,8 +59,8 @@ func TestCcObjectSimple(t *testing.T) { min_sdk_version: "29", } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_object", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_object", "foo", AttrNameToString{ "copts": `[ "-fno-addrsig", "-Wno-gcc-compat", @@ -73,16 +73,16 @@ func TestCcObjectSimple(t *testing.T) { ]`, "srcs": `["a/b/c.c"]`, "system_dynamic_deps": `[]`, - "sdk_version": `"current"`, - "min_sdk_version": `"29"`, + "sdk_version": `"current"`, + "min_sdk_version": `"29"`, }), }, }) } func TestCcObjectDefaults(t *testing.T) { - runCcObjectTestCase(t, bp2buildTestCase{ - blueprint: `cc_object { + runCcObjectTestCase(t, Bp2buildTestCase{ + Blueprint: `cc_object { name: "foo", system_shared_libs: [], srcs: [ @@ -105,8 +105,8 @@ cc_defaults { ], } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_object", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_object", "foo", AttrNameToString{ "copts": `[ "-Werror", "-fno-addrsig", @@ -119,13 +119,13 @@ cc_defaults { } func TestCcObjectCcObjetDepsInObjs(t *testing.T) { - runCcObjectTestCase(t, bp2buildTestCase{ - description: "cc_object with cc_object deps in objs props", - filesystem: map[string]string{ + runCcObjectTestCase(t, Bp2buildTestCase{ + Description: "cc_object with cc_object deps in objs props", + Filesystem: map[string]string{ "a/b/c.c": "", "x/y/z.c": "", }, - blueprint: `cc_object { + Blueprint: `cc_object { name: "foo", system_shared_libs: [], srcs: ["a/b/c.c"], @@ -140,12 +140,12 @@ cc_object { include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_object", "bar", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_object", "bar", AttrNameToString{ "copts": `["-fno-addrsig"]`, "srcs": `["x/y/z.c"]`, "system_dynamic_deps": `[]`, - }), makeBazelTarget("cc_object", "foo", attrNameToString{ + }), makeBazelTarget("cc_object", "foo", AttrNameToString{ "copts": `["-fno-addrsig"]`, "deps": `[":bar"]`, "srcs": `["a/b/c.c"]`, @@ -156,21 +156,21 @@ cc_object { } func TestCcObjectIncludeBuildDirFalse(t *testing.T) { - runCcObjectTestCase(t, bp2buildTestCase{ - description: "cc_object with include_build_dir: false", - filesystem: map[string]string{ + runCcObjectTestCase(t, Bp2buildTestCase{ + Description: "cc_object with include_build_dir: false", + Filesystem: map[string]string{ "a/b/c.c": "", "x/y/z.c": "", }, - blueprint: `cc_object { + Blueprint: `cc_object { name: "foo", system_shared_libs: [], srcs: ["a/b/c.c"], include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_object", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_object", "foo", AttrNameToString{ "copts": `["-fno-addrsig"]`, "srcs": `["a/b/c.c"]`, "system_dynamic_deps": `[]`, @@ -180,9 +180,9 @@ func TestCcObjectIncludeBuildDirFalse(t *testing.T) { } func TestCcObjectProductVariable(t *testing.T) { - runCcObjectTestCase(t, bp2buildTestCase{ - description: "cc_object with product variable", - blueprint: `cc_object { + runCcObjectTestCase(t, Bp2buildTestCase{ + Description: "cc_object with product variable", + Blueprint: `cc_object { name: "foo", system_shared_libs: [], include_build_directory: false, @@ -194,8 +194,8 @@ func TestCcObjectProductVariable(t *testing.T) { srcs: ["src.S"], } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_object", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_object", "foo", AttrNameToString{ "asflags": `select({ "//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"], "//conditions:default": [], @@ -209,9 +209,9 @@ func TestCcObjectProductVariable(t *testing.T) { } func TestCcObjectCflagsOneArch(t *testing.T) { - runCcObjectTestCase(t, bp2buildTestCase{ - description: "cc_object setting cflags for one arch", - blueprint: `cc_object { + runCcObjectTestCase(t, Bp2buildTestCase{ + Description: "cc_object setting cflags for one arch", + Blueprint: `cc_object { name: "foo", system_shared_libs: [], srcs: ["a.cpp"], @@ -226,8 +226,8 @@ func TestCcObjectCflagsOneArch(t *testing.T) { include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_object", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_object", "foo", AttrNameToString{ "copts": `["-fno-addrsig"] + select({ "//build/bazel/platforms/arch:x86": ["-fPIC"], "//conditions:default": [], @@ -243,9 +243,9 @@ func TestCcObjectCflagsOneArch(t *testing.T) { } func TestCcObjectCflagsFourArch(t *testing.T) { - runCcObjectTestCase(t, bp2buildTestCase{ - description: "cc_object setting cflags for 4 architectures", - blueprint: `cc_object { + runCcObjectTestCase(t, Bp2buildTestCase{ + Description: "cc_object setting cflags for 4 architectures", + Blueprint: `cc_object { name: "foo", system_shared_libs: [], srcs: ["base.cpp"], @@ -270,8 +270,8 @@ func TestCcObjectCflagsFourArch(t *testing.T) { include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_object", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_object", "foo", AttrNameToString{ "copts": `["-fno-addrsig"] + select({ "//build/bazel/platforms/arch:arm": ["-Wall"], "//build/bazel/platforms/arch:arm64": ["-Wall"], @@ -293,17 +293,17 @@ func TestCcObjectCflagsFourArch(t *testing.T) { } func TestCcObjectLinkerScript(t *testing.T) { - runCcObjectTestCase(t, bp2buildTestCase{ - description: "cc_object setting linker_script", - blueprint: `cc_object { + runCcObjectTestCase(t, Bp2buildTestCase{ + Description: "cc_object setting linker_script", + Blueprint: `cc_object { name: "foo", srcs: ["base.cpp"], linker_script: "bunny.lds", include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_object", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_object", "foo", AttrNameToString{ "copts": `["-fno-addrsig"]`, "linker_script": `"bunny.lds"`, "srcs": `["base.cpp"]`, @@ -313,9 +313,9 @@ func TestCcObjectLinkerScript(t *testing.T) { } func TestCcObjectDepsAndLinkerScriptSelects(t *testing.T) { - runCcObjectTestCase(t, bp2buildTestCase{ - description: "cc_object setting deps and linker_script across archs", - blueprint: `cc_object { + runCcObjectTestCase(t, Bp2buildTestCase{ + Description: "cc_object setting deps and linker_script across archs", + Blueprint: `cc_object { name: "foo", srcs: ["base.cpp"], arch: { @@ -359,8 +359,8 @@ cc_object { bazel_module: { bp2build_available: false }, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_object", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_object", "foo", AttrNameToString{ "copts": `["-fno-addrsig"]`, "deps": `select({ "//build/bazel/platforms/arch:arm": [":arm_obj"], @@ -381,9 +381,9 @@ cc_object { } func TestCcObjectSelectOnLinuxAndBionicArchs(t *testing.T) { - runCcObjectTestCase(t, bp2buildTestCase{ - description: "cc_object setting srcs based on linux and bionic archs", - blueprint: `cc_object { + runCcObjectTestCase(t, Bp2buildTestCase{ + Description: "cc_object setting srcs based on linux and bionic archs", + Blueprint: `cc_object { name: "foo", srcs: ["base.cpp"], target: { @@ -400,8 +400,8 @@ func TestCcObjectSelectOnLinuxAndBionicArchs(t *testing.T) { include_build_directory: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("cc_object", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("cc_object", "foo", AttrNameToString{ "copts": `["-fno-addrsig"]`, "srcs": `["base.cpp"] + select({ "//build/bazel/platforms/os_arch:android_arm64": [ diff --git a/bp2build/cc_prebuilt_library_conversion_test.go b/bp2build/cc_prebuilt_library_conversion_test.go index 3cf896903..74ad0053a 100644 --- a/bp2build/cc_prebuilt_library_conversion_test.go +++ b/bp2build/cc_prebuilt_library_conversion_test.go @@ -22,24 +22,24 @@ import ( func TestPrebuiltLibraryStaticAndSharedSimple(t *testing.T) { runBp2BuildTestCaseSimple(t, - bp2buildTestCase{ - description: "prebuilt library static and shared simple", - moduleTypeUnderTest: "cc_prebuilt_library", - moduleTypeUnderTestFactory: cc.PrebuiltLibraryFactory, - filesystem: map[string]string{ + Bp2buildTestCase{ + Description: "prebuilt library static and shared simple", + ModuleTypeUnderTest: "cc_prebuilt_library", + ModuleTypeUnderTestFactory: cc.PrebuiltLibraryFactory, + Filesystem: map[string]string{ "libf.so": "", }, - blueprint: ` + Blueprint: ` cc_prebuilt_library { name: "libtest", srcs: ["libf.so"], bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("prebuilt_library_static", "libtest_bp2build_cc_library_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{ "static_library": `"libf.so"`, }), - makeBazelTarget("prebuilt_library_shared", "libtest", attrNameToString{ + makeBazelTarget("prebuilt_library_shared", "libtest", AttrNameToString{ "shared_library": `"libf.so"`, }), }, @@ -48,15 +48,15 @@ cc_prebuilt_library { func TestPrebuiltLibraryWithArchVariance(t *testing.T) { runBp2BuildTestCaseSimple(t, - bp2buildTestCase{ - description: "prebuilt library with arch variance", - moduleTypeUnderTest: "cc_prebuilt_library", - moduleTypeUnderTestFactory: cc.PrebuiltLibraryFactory, - filesystem: map[string]string{ + Bp2buildTestCase{ + Description: "prebuilt library with arch variance", + ModuleTypeUnderTest: "cc_prebuilt_library", + ModuleTypeUnderTestFactory: cc.PrebuiltLibraryFactory, + Filesystem: map[string]string{ "libf.so": "", "libg.so": "", }, - blueprint: ` + Blueprint: ` cc_prebuilt_library { name: "libtest", arch: { @@ -65,15 +65,15 @@ cc_prebuilt_library { }, bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("prebuilt_library_static", "libtest_bp2build_cc_library_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{ "static_library": `select({ "//build/bazel/platforms/arch:arm": "libg.so", "//build/bazel/platforms/arch:arm64": "libf.so", "//conditions:default": None, })`, }), - makeBazelTarget("prebuilt_library_shared", "libtest", attrNameToString{ + makeBazelTarget("prebuilt_library_shared", "libtest", AttrNameToString{ "shared_library": `select({ "//build/bazel/platforms/arch:arm": "libg.so", "//build/bazel/platforms/arch:arm64": "libf.so", @@ -86,16 +86,16 @@ cc_prebuilt_library { func TestPrebuiltLibraryAdditionalAttrs(t *testing.T) { runBp2BuildTestCaseSimple(t, - bp2buildTestCase{ - description: "prebuilt library additional attributes", - moduleTypeUnderTest: "cc_prebuilt_library", - moduleTypeUnderTestFactory: cc.PrebuiltLibraryFactory, - filesystem: map[string]string{ + Bp2buildTestCase{ + Description: "prebuilt library additional attributes", + ModuleTypeUnderTest: "cc_prebuilt_library", + ModuleTypeUnderTestFactory: cc.PrebuiltLibraryFactory, + Filesystem: map[string]string{ "libf.so": "", "testdir/1/": "", "testdir/2/": "", }, - blueprint: ` + Blueprint: ` cc_prebuilt_library { name: "libtest", srcs: ["libf.so"], @@ -103,14 +103,14 @@ cc_prebuilt_library { export_system_include_dirs: ["testdir/2/"], bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("prebuilt_library_static", "libtest_bp2build_cc_library_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{ "static_library": `"libf.so"`, "export_includes": `["testdir/1/"]`, "export_system_includes": `["testdir/2/"]`, }), // TODO(b/229374533): When fixed, update this test - makeBazelTarget("prebuilt_library_shared", "libtest", attrNameToString{ + makeBazelTarget("prebuilt_library_shared", "libtest", AttrNameToString{ "shared_library": `"libf.so"`, }), }, @@ -119,15 +119,15 @@ cc_prebuilt_library { func TestPrebuiltLibrarySharedStanzaFails(t *testing.T) { runBp2BuildTestCaseSimple(t, - bp2buildTestCase{ - description: "prebuilt library with shared stanza fails because multiple sources", - moduleTypeUnderTest: "cc_prebuilt_library", - moduleTypeUnderTestFactory: cc.PrebuiltLibraryFactory, - filesystem: map[string]string{ + Bp2buildTestCase{ + Description: "prebuilt library with shared stanza fails because multiple sources", + ModuleTypeUnderTest: "cc_prebuilt_library", + ModuleTypeUnderTestFactory: cc.PrebuiltLibraryFactory, + Filesystem: map[string]string{ "libf.so": "", "libg.so": "", }, - blueprint: ` + Blueprint: ` cc_prebuilt_library { name: "libtest", srcs: ["libf.so"], @@ -136,21 +136,21 @@ cc_prebuilt_library { }, bazel_module: { bp2build_available: true }, }`, - expectedErr: fmt.Errorf("Expected at most one source file"), + ExpectedErr: fmt.Errorf("Expected at most one source file"), }) } func TestPrebuiltLibraryStaticStanzaFails(t *testing.T) { runBp2BuildTestCaseSimple(t, - bp2buildTestCase{ - description: "prebuilt library with static stanza fails because multiple sources", - moduleTypeUnderTest: "cc_prebuilt_library", - moduleTypeUnderTestFactory: cc.PrebuiltLibraryFactory, - filesystem: map[string]string{ + Bp2buildTestCase{ + Description: "prebuilt library with static stanza fails because multiple sources", + ModuleTypeUnderTest: "cc_prebuilt_library", + ModuleTypeUnderTestFactory: cc.PrebuiltLibraryFactory, + Filesystem: map[string]string{ "libf.so": "", "libg.so": "", }, - blueprint: ` + Blueprint: ` cc_prebuilt_library { name: "libtest", srcs: ["libf.so"], @@ -159,21 +159,21 @@ cc_prebuilt_library { }, bazel_module: { bp2build_available: true }, }`, - expectedErr: fmt.Errorf("Expected at most one source file"), + ExpectedErr: fmt.Errorf("Expected at most one source file"), }) } func TestPrebuiltLibrarySharedAndStaticStanzas(t *testing.T) { runBp2BuildTestCaseSimple(t, - bp2buildTestCase{ - description: "prebuilt library with both shared and static stanzas", - moduleTypeUnderTest: "cc_prebuilt_library", - moduleTypeUnderTestFactory: cc.PrebuiltLibraryFactory, - filesystem: map[string]string{ + Bp2buildTestCase{ + Description: "prebuilt library with both shared and static stanzas", + ModuleTypeUnderTest: "cc_prebuilt_library", + ModuleTypeUnderTestFactory: cc.PrebuiltLibraryFactory, + Filesystem: map[string]string{ "libf.so": "", "libg.so": "", }, - blueprint: ` + Blueprint: ` cc_prebuilt_library { name: "libtest", static: { @@ -184,11 +184,11 @@ cc_prebuilt_library { }, bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("prebuilt_library_static", "libtest_bp2build_cc_library_static", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{ "static_library": `"libf.so"`, }), - makeBazelTarget("prebuilt_library_shared", "libtest", attrNameToString{ + makeBazelTarget("prebuilt_library_shared", "libtest", AttrNameToString{ "shared_library": `"libg.so"`, }), }, diff --git a/bp2build/cc_prebuilt_library_shared_test.go b/bp2build/cc_prebuilt_library_shared_test.go index 57905e559..bcf0ce20a 100644 --- a/bp2build/cc_prebuilt_library_shared_test.go +++ b/bp2build/cc_prebuilt_library_shared_test.go @@ -9,21 +9,21 @@ import ( func TestSharedPrebuiltLibrary(t *testing.T) { runBp2BuildTestCaseSimple(t, - bp2buildTestCase{ - description: "prebuilt library shared simple", - moduleTypeUnderTest: "cc_prebuilt_library_shared", - moduleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory, - filesystem: map[string]string{ + Bp2buildTestCase{ + Description: "prebuilt library shared simple", + ModuleTypeUnderTest: "cc_prebuilt_library_shared", + ModuleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory, + Filesystem: map[string]string{ "libf.so": "", }, - blueprint: ` + Blueprint: ` cc_prebuilt_library_shared { name: "libtest", srcs: ["libf.so"], bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("prebuilt_library_shared", "libtest", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("prebuilt_library_shared", "libtest", AttrNameToString{ "shared_library": `"libf.so"`, }), }, @@ -32,15 +32,15 @@ cc_prebuilt_library_shared { func TestSharedPrebuiltLibraryWithArchVariance(t *testing.T) { runBp2BuildTestCaseSimple(t, - bp2buildTestCase{ - description: "prebuilt library shared with arch variance", - moduleTypeUnderTest: "cc_prebuilt_library_shared", - moduleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory, - filesystem: map[string]string{ + Bp2buildTestCase{ + Description: "prebuilt library shared with arch variance", + ModuleTypeUnderTest: "cc_prebuilt_library_shared", + ModuleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory, + Filesystem: map[string]string{ "libf.so": "", "libg.so": "", }, - blueprint: ` + Blueprint: ` cc_prebuilt_library_shared { name: "libtest", arch: { @@ -49,8 +49,8 @@ cc_prebuilt_library_shared { }, bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("prebuilt_library_shared", "libtest", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("prebuilt_library_shared", "libtest", AttrNameToString{ "shared_library": `select({ "//build/bazel/platforms/arch:arm": "libg.so", "//build/bazel/platforms/arch:arm64": "libf.so", @@ -63,15 +63,15 @@ cc_prebuilt_library_shared { func TestSharedPrebuiltLibrarySharedStanzaFails(t *testing.T) { runBp2BuildTestCaseSimple(t, - bp2buildTestCase{ - description: "prebuilt library shared with shared stanza fails because multiple sources", - moduleTypeUnderTest: "cc_prebuilt_library_shared", - moduleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory, - filesystem: map[string]string{ + Bp2buildTestCase{ + Description: "prebuilt library shared with shared stanza fails because multiple sources", + ModuleTypeUnderTest: "cc_prebuilt_library_shared", + ModuleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory, + Filesystem: map[string]string{ "libf.so": "", "libg.so": "", }, - blueprint: ` + Blueprint: ` cc_prebuilt_library_shared { name: "libtest", srcs: ["libf.so"], @@ -80,6 +80,6 @@ cc_prebuilt_library_shared { }, bazel_module: { bp2build_available: true}, }`, - expectedErr: fmt.Errorf("Expected at most one source file"), + ExpectedErr: fmt.Errorf("Expected at most one source file"), }) } diff --git a/bp2build/cc_prebuilt_library_static_test.go b/bp2build/cc_prebuilt_library_static_test.go index 59839c884..7498e504c 100644 --- a/bp2build/cc_prebuilt_library_static_test.go +++ b/bp2build/cc_prebuilt_library_static_test.go @@ -22,21 +22,21 @@ import ( func TestStaticPrebuiltLibrary(t *testing.T) { runBp2BuildTestCaseSimple(t, - bp2buildTestCase{ - description: "prebuilt library static simple", - moduleTypeUnderTest: "cc_prebuilt_library_static", - moduleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory, - filesystem: map[string]string{ + Bp2buildTestCase{ + Description: "prebuilt library static simple", + ModuleTypeUnderTest: "cc_prebuilt_library_static", + ModuleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory, + Filesystem: map[string]string{ "libf.so": "", }, - blueprint: ` + Blueprint: ` cc_prebuilt_library_static { name: "libtest", srcs: ["libf.so"], bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("prebuilt_library_static", "libtest", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("prebuilt_library_static", "libtest", AttrNameToString{ "static_library": `"libf.so"`, }), }, @@ -45,15 +45,15 @@ cc_prebuilt_library_static { func TestStaticPrebuiltLibraryWithArchVariance(t *testing.T) { runBp2BuildTestCaseSimple(t, - bp2buildTestCase{ - description: "prebuilt library static with arch variance", - moduleTypeUnderTest: "cc_prebuilt_library_static", - moduleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory, - filesystem: map[string]string{ + Bp2buildTestCase{ + Description: "prebuilt library static with arch variance", + ModuleTypeUnderTest: "cc_prebuilt_library_static", + ModuleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory, + Filesystem: map[string]string{ "libf.so": "", "libg.so": "", }, - blueprint: ` + Blueprint: ` cc_prebuilt_library_static { name: "libtest", arch: { @@ -62,8 +62,8 @@ cc_prebuilt_library_static { }, bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("prebuilt_library_static", "libtest", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("prebuilt_library_static", "libtest", AttrNameToString{ "static_library": `select({ "//build/bazel/platforms/arch:arm": "libg.so", "//build/bazel/platforms/arch:arm64": "libf.so", @@ -76,15 +76,15 @@ cc_prebuilt_library_static { func TestStaticPrebuiltLibraryStaticStanzaFails(t *testing.T) { runBp2BuildTestCaseSimple(t, - bp2buildTestCase{ - description: "prebuilt library with static stanza fails because multiple sources", - moduleTypeUnderTest: "cc_prebuilt_library_static", - moduleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory, - filesystem: map[string]string{ + Bp2buildTestCase{ + Description: "prebuilt library with static stanza fails because multiple sources", + ModuleTypeUnderTest: "cc_prebuilt_library_static", + ModuleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory, + Filesystem: map[string]string{ "libf.so": "", "libg.so": "", }, - blueprint: ` + Blueprint: ` cc_prebuilt_library_static { name: "libtest", srcs: ["libf.so"], @@ -93,16 +93,16 @@ cc_prebuilt_library_static { }, bazel_module: { bp2build_available: true }, }`, - expectedErr: fmt.Errorf("Expected at most one source file"), + ExpectedErr: fmt.Errorf("Expected at most one source file"), }) } func TestCcLibraryStaticConvertLex(t *testing.T) { - runCcLibrarySharedTestCase(t, bp2buildTestCase{ - description: "cc_library_static with lex files", - moduleTypeUnderTest: "cc_library_static", - moduleTypeUnderTestFactory: cc.LibraryStaticFactory, - filesystem: map[string]string{ + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_static with lex files", + ModuleTypeUnderTest: "cc_library_static", + ModuleTypeUnderTestFactory: cc.LibraryStaticFactory, + Filesystem: map[string]string{ "foo.c": "", "bar.cc": "", "foo1.l": "", @@ -110,29 +110,29 @@ func TestCcLibraryStaticConvertLex(t *testing.T) { "foo2.l": "", "bar2.ll": "", }, - blueprint: `cc_library_static { + Blueprint: `cc_library_static { name: "foo_lib", srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"], lex: { flags: ["--foo_flags"] }, include_build_directory: false, bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("genlex", "foo_lib_genlex_l", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{ "srcs": `[ "foo1.l", "foo2.l", ]`, "lexopts": `["--foo_flags"]`, }), - makeBazelTarget("genlex", "foo_lib_genlex_ll", attrNameToString{ + makeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{ "srcs": `[ "bar1.ll", "bar2.ll", ]`, "lexopts": `["--foo_flags"]`, }), - makeBazelTarget("cc_library_static", "foo_lib", attrNameToString{ + makeBazelTarget("cc_library_static", "foo_lib", AttrNameToString{ "srcs": `[ "bar.cc", ":foo_lib_genlex_ll", diff --git a/bp2build/cc_yasm_conversion_test.go b/bp2build/cc_yasm_conversion_test.go new file mode 100644 index 000000000..6114a4933 --- /dev/null +++ b/bp2build/cc_yasm_conversion_test.go @@ -0,0 +1,179 @@ +// Copyright 2022 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package bp2build + +import ( + "testing" + + "android/soong/android" + "android/soong/cc" +) + +func runYasmTestCase(t *testing.T, tc bp2buildTestCase) { + t.Helper() + runBp2BuildTestCase(t, registerYasmModuleTypes, tc) +} + +func registerYasmModuleTypes(ctx android.RegistrationContext) { + cc.RegisterCCBuildComponents(ctx) + ctx.RegisterModuleType("filegroup", android.FileGroupFactory) + ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) + ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory) + ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) +} + +func TestYasmSimple(t *testing.T) { + runYasmTestCase(t, bp2buildTestCase{ + description: "Simple yasm test", + moduleTypeUnderTest: "cc_library", + moduleTypeUnderTestFactory: cc.LibraryFactory, + filesystem: map[string]string{ + "main.cpp": "", + "myfile.asm": "", + }, + blueprint: ` +cc_library { + name: "foo", + srcs: ["main.cpp", "myfile.asm"], +}`, + expectedBazelTargets: append([]string{ + makeBazelTarget("yasm", "foo_yasm", map[string]string{ + "include_dirs": `["."]`, + "srcs": `["myfile.asm"]`, + }), + }, makeCcLibraryTargets("foo", map[string]string{ + "local_includes": `["."]`, + "srcs": `[ + "main.cpp", + ":foo_yasm", + ]`, + })...), + }) +} + +func TestYasmWithIncludeDirs(t *testing.T) { + runYasmTestCase(t, bp2buildTestCase{ + description: "Simple yasm test", + moduleTypeUnderTest: "cc_library", + moduleTypeUnderTestFactory: cc.LibraryFactory, + filesystem: map[string]string{ + "main.cpp": "", + "myfile.asm": "", + "include1/foo/myinclude.inc": "", + "include2/foo/myinclude2.inc": "", + }, + blueprint: ` +cc_library { + name: "foo", + local_include_dirs: ["include1/foo"], + export_include_dirs: ["include2/foo"], + srcs: ["main.cpp", "myfile.asm"], +}`, + expectedBazelTargets: append([]string{ + makeBazelTarget("yasm", "foo_yasm", map[string]string{ + "include_dirs": `[ + "include1/foo", + ".", + "include2/foo", + ]`, + "srcs": `["myfile.asm"]`, + }), + }, makeCcLibraryTargets("foo", map[string]string{ + "local_includes": `[ + "include1/foo", + ".", + ]`, + "export_includes": `["include2/foo"]`, + "srcs": `[ + "main.cpp", + ":foo_yasm", + ]`, + })...), + }) +} + +func TestYasmConditionalBasedOnArch(t *testing.T) { + runYasmTestCase(t, bp2buildTestCase{ + description: "Simple yasm test", + moduleTypeUnderTest: "cc_library", + moduleTypeUnderTestFactory: cc.LibraryFactory, + filesystem: map[string]string{ + "main.cpp": "", + "myfile.asm": "", + }, + blueprint: ` +cc_library { + name: "foo", + srcs: ["main.cpp"], + arch: { + x86: { + srcs: ["myfile.asm"], + }, + }, +}`, + expectedBazelTargets: append([]string{ + makeBazelTarget("yasm", "foo_yasm", map[string]string{ + "include_dirs": `["."]`, + "srcs": `select({ + "//build/bazel/platforms/arch:x86": ["myfile.asm"], + "//conditions:default": [], + })`, + }), + }, makeCcLibraryTargets("foo", map[string]string{ + "local_includes": `["."]`, + "srcs": `["main.cpp"] + select({ + "//build/bazel/platforms/arch:x86": [":foo_yasm"], + "//conditions:default": [], + })`, + })...), + }) +} + +func TestYasmPartiallyConditional(t *testing.T) { + runYasmTestCase(t, bp2buildTestCase{ + description: "Simple yasm test", + moduleTypeUnderTest: "cc_library", + moduleTypeUnderTestFactory: cc.LibraryFactory, + filesystem: map[string]string{ + "main.cpp": "", + "myfile.asm": "", + "mysecondfile.asm": "", + }, + blueprint: ` +cc_library { + name: "foo", + srcs: ["main.cpp", "myfile.asm"], + arch: { + x86: { + srcs: ["mysecondfile.asm"], + }, + }, +}`, + expectedBazelTargets: append([]string{ + makeBazelTarget("yasm", "foo_yasm", map[string]string{ + "include_dirs": `["."]`, + "srcs": `["myfile.asm"] + select({ + "//build/bazel/platforms/arch:x86": ["mysecondfile.asm"], + "//conditions:default": [], + })`, + }), + }, makeCcLibraryTargets("foo", map[string]string{ + "local_includes": `["."]`, + "srcs": `[ + "main.cpp", + ":foo_yasm", + ]`, + })...), + }) +} diff --git a/bp2build/conversion.go b/bp2build/conversion.go index 4b013d913..8cf9beaf4 100644 --- a/bp2build/conversion.go +++ b/bp2build/conversion.go @@ -10,6 +10,8 @@ import ( cc_config "android/soong/cc/config" java_config "android/soong/java/config" + "android/soong/apex" + "github.com/google/blueprint/proptools" ) @@ -28,6 +30,9 @@ func CreateSoongInjectionFiles(cfg android.Config, metrics CodegenMetrics) []Baz files = append(files, newFile("java_toolchain", GeneratedBuildFileName, "")) // Creates a //java_toolchain package. files = append(files, newFile("java_toolchain", "constants.bzl", java_config.BazelJavaToolchainVars(cfg))) + files = append(files, newFile("apex_toolchain", GeneratedBuildFileName, "")) // Creates a //apex_toolchain package. + files = append(files, newFile("apex_toolchain", "constants.bzl", apex.BazelApexToolchainVars())) + files = append(files, newFile("metrics", "converted_modules.txt", strings.Join(metrics.convertedModules, "\n"))) files = append(files, newFile("product_config", "soong_config_variables.bzl", cfg.Bp2buildSoongConfigDefinitions.String())) @@ -50,6 +55,7 @@ func convertedModules(convertedModules []string) string { } func CreateBazelFiles( + cfg android.Config, ruleShims map[string]RuleShim, buildToTargets map[string]BazelTargets, mode CodegenMode) []BazelFile { @@ -74,16 +80,19 @@ func CreateBazelFiles( files = append(files, newFile(bazelRulesSubDir, "soong_module.bzl", generateSoongModuleBzl(ruleShims))) } - files = append(files, createBuildFiles(buildToTargets, mode)...) + files = append(files, createBuildFiles(cfg, buildToTargets, mode)...) return files } -func createBuildFiles(buildToTargets map[string]BazelTargets, mode CodegenMode) []BazelFile { +func createBuildFiles(cfg android.Config, buildToTargets map[string]BazelTargets, mode CodegenMode) []BazelFile { files := make([]BazelFile, 0, len(buildToTargets)) + warnNotWriting := cfg.IsEnvTrue("BP2BUILD_VERBOSE") for _, dir := range android.SortedStringKeys(buildToTargets) { if mode == Bp2Build && android.ShouldKeepExistingBuildFileForDir(dir) { - fmt.Printf("[bp2build] Not writing generated BUILD file for dir: '%s'\n", dir) + if warnNotWriting { + fmt.Printf("[bp2build] Not writing generated BUILD file for dir: '%s'\n", dir) + } continue } targets := buildToTargets[dir] diff --git a/bp2build/conversion_test.go b/bp2build/conversion_test.go index e49d8553b..0cb711ca5 100644 --- a/bp2build/conversion_test.go +++ b/bp2build/conversion_test.go @@ -27,7 +27,8 @@ type bazelFilepath struct { } func TestCreateBazelFiles_QueryView_AddsTopLevelFiles(t *testing.T) { - files := CreateBazelFiles(map[string]RuleShim{}, map[string]BazelTargets{}, QueryView) + files := CreateBazelFiles(android.NullConfig("out", "out/soong"), + map[string]RuleShim{}, map[string]BazelTargets{}, QueryView) expectedFilePaths := []bazelFilepath{ { dir: "", @@ -103,6 +104,14 @@ func TestCreateBazelFiles_Bp2Build_CreatesDefaultFiles(t *testing.T) { basename: "constants.bzl", }, { + dir: "apex_toolchain", + basename: GeneratedBuildFileName, + }, + { + dir: "apex_toolchain", + basename: "constants.bzl", + }, + { dir: "metrics", basename: "converted_modules.txt", }, diff --git a/bp2build/filegroup_conversion_test.go b/bp2build/filegroup_conversion_test.go index b43cf5374..b598b855e 100644 --- a/bp2build/filegroup_conversion_test.go +++ b/bp2build/filegroup_conversion_test.go @@ -21,38 +21,38 @@ import ( "testing" ) -func runFilegroupTestCase(t *testing.T, tc bp2buildTestCase) { +func runFilegroupTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - (&tc).moduleTypeUnderTest = "filegroup" - (&tc).moduleTypeUnderTestFactory = android.FileGroupFactory - runBp2BuildTestCase(t, registerFilegroupModuleTypes, tc) + (&tc).ModuleTypeUnderTest = "filegroup" + (&tc).ModuleTypeUnderTestFactory = android.FileGroupFactory + RunBp2BuildTestCase(t, registerFilegroupModuleTypes, tc) } func registerFilegroupModuleTypes(ctx android.RegistrationContext) {} func TestFilegroupSameNameAsFile_OneFile(t *testing.T) { - runFilegroupTestCase(t, bp2buildTestCase{ - description: "filegroup - same name as file, with one file", - filesystem: map[string]string{}, - blueprint: ` + runFilegroupTestCase(t, Bp2buildTestCase{ + Description: "filegroup - same name as file, with one file", + Filesystem: map[string]string{}, + Blueprint: ` filegroup { name: "foo", srcs: ["foo"], } `, - expectedBazelTargets: []string{}}) + ExpectedBazelTargets: []string{}}) } func TestFilegroupSameNameAsFile_MultipleFiles(t *testing.T) { - runFilegroupTestCase(t, bp2buildTestCase{ - description: "filegroup - same name as file, with multiple files", - filesystem: map[string]string{}, - blueprint: ` + runFilegroupTestCase(t, Bp2buildTestCase{ + Description: "filegroup - same name as file, with multiple files", + Filesystem: map[string]string{}, + Blueprint: ` filegroup { name: "foo", srcs: ["foo", "bar"], } `, - expectedErr: fmt.Errorf("filegroup 'foo' cannot contain a file with the same name"), + ExpectedErr: fmt.Errorf("filegroup 'foo' cannot contain a file with the same name"), }) } diff --git a/bp2build/genrule_conversion_test.go b/bp2build/genrule_conversion_test.go index 45048924e..a8bfecda0 100644 --- a/bp2build/genrule_conversion_test.go +++ b/bp2build/genrule_conversion_test.go @@ -27,11 +27,11 @@ func registerGenruleModuleTypes(ctx android.RegistrationContext) { ctx.RegisterModuleType("genrule_defaults", func() android.Module { return genrule.DefaultsFactory() }) } -func runGenruleTestCase(t *testing.T, tc bp2buildTestCase) { +func runGenruleTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - (&tc).moduleTypeUnderTest = "genrule" - (&tc).moduleTypeUnderTestFactory = genrule.GenRuleFactory - runBp2BuildTestCase(t, registerGenruleModuleTypes, tc) + (&tc).ModuleTypeUnderTest = "genrule" + (&tc).ModuleTypeUnderTestFactory = genrule.GenRuleFactory + RunBp2BuildTestCase(t, registerGenruleModuleTypes, tc) } func otherGenruleBp(genruleTarget string) map[string]string { @@ -101,7 +101,7 @@ func TestGenruleCliVariableReplacement(t *testing.T) { }` for _, tc := range testCases { - moduleAttrs := attrNameToString{ + moduleAttrs := AttrNameToString{ "cmd": fmt.Sprintf(`"$(location :foo.tool) --genDir=%s arg $(SRCS) $(OUTS)"`, tc.genDir), "outs": `["foo.out"]`, "srcs": `["foo.in"]`, @@ -113,12 +113,12 @@ func TestGenruleCliVariableReplacement(t *testing.T) { } t.Run(tc.moduleType, func(t *testing.T) { - runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, - bp2buildTestCase{ - moduleTypeUnderTest: tc.moduleType, - moduleTypeUnderTestFactory: tc.factory, - blueprint: fmt.Sprintf(bp, tc.moduleType, tc.moduleType), - expectedBazelTargets: expectedBazelTargets, + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, + Bp2buildTestCase{ + ModuleTypeUnderTest: tc.moduleType, + ModuleTypeUnderTestFactory: tc.factory, + Blueprint: fmt.Sprintf(bp, tc.moduleType, tc.moduleType), + ExpectedBazelTargets: expectedBazelTargets, }) }) } @@ -169,13 +169,13 @@ func TestGenruleLocationsLabel(t *testing.T) { }` for _, tc := range testCases { - fooAttrs := attrNameToString{ + fooAttrs := AttrNameToString{ "cmd": `"$(locations :foo.tools) -s $(OUTS) $(SRCS)"`, "outs": `["foo.out"]`, "srcs": `["foo.in"]`, "tools": `[":foo.tools"]`, } - fooToolsAttrs := attrNameToString{ + fooToolsAttrs := AttrNameToString{ "cmd": `"cp $(SRCS) $(OUTS)"`, "outs": `[ "foo_tool.out", @@ -190,12 +190,12 @@ func TestGenruleLocationsLabel(t *testing.T) { } t.Run(tc.moduleType, func(t *testing.T) { - runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, - bp2buildTestCase{ - moduleTypeUnderTest: tc.moduleType, - moduleTypeUnderTestFactory: tc.factory, - blueprint: fmt.Sprintf(bp, tc.moduleType, tc.moduleType), - expectedBazelTargets: expectedBazelTargets, + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, + Bp2buildTestCase{ + ModuleTypeUnderTest: tc.moduleType, + ModuleTypeUnderTestFactory: tc.factory, + Blueprint: fmt.Sprintf(bp, tc.moduleType, tc.moduleType), + ExpectedBazelTargets: expectedBazelTargets, }) }) } @@ -238,7 +238,7 @@ func TestGenruleLocationsAbsoluteLabel(t *testing.T) { }` for _, tc := range testCases { - moduleAttrs := attrNameToString{ + moduleAttrs := AttrNameToString{ "cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`, "outs": `["foo.out"]`, "srcs": `["foo.in"]`, @@ -250,13 +250,13 @@ func TestGenruleLocationsAbsoluteLabel(t *testing.T) { } t.Run(tc.moduleType, func(t *testing.T) { - runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, - bp2buildTestCase{ - moduleTypeUnderTest: tc.moduleType, - moduleTypeUnderTestFactory: tc.factory, - blueprint: fmt.Sprintf(bp, tc.moduleType), - expectedBazelTargets: expectedBazelTargets, - filesystem: otherGenruleBp(tc.moduleType), + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, + Bp2buildTestCase{ + ModuleTypeUnderTest: tc.moduleType, + ModuleTypeUnderTestFactory: tc.factory, + Blueprint: fmt.Sprintf(bp, tc.moduleType), + ExpectedBazelTargets: expectedBazelTargets, + Filesystem: otherGenruleBp(tc.moduleType), }) }) } @@ -299,7 +299,7 @@ func TestGenruleSrcsLocationsAbsoluteLabel(t *testing.T) { }` for _, tc := range testCases { - moduleAttrs := attrNameToString{ + moduleAttrs := AttrNameToString{ "cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(location //other:other.tool)"`, "outs": `["foo.out"]`, "srcs": `["//other:other.tool"]`, @@ -311,13 +311,13 @@ func TestGenruleSrcsLocationsAbsoluteLabel(t *testing.T) { } t.Run(tc.moduleType, func(t *testing.T) { - runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, - bp2buildTestCase{ - moduleTypeUnderTest: tc.moduleType, - moduleTypeUnderTestFactory: tc.factory, - blueprint: fmt.Sprintf(bp, tc.moduleType), - expectedBazelTargets: expectedBazelTargets, - filesystem: otherGenruleBp(tc.moduleType), + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, + Bp2buildTestCase{ + ModuleTypeUnderTest: tc.moduleType, + ModuleTypeUnderTestFactory: tc.factory, + Blueprint: fmt.Sprintf(bp, tc.moduleType), + ExpectedBazelTargets: expectedBazelTargets, + Filesystem: otherGenruleBp(tc.moduleType), }) }) } @@ -360,7 +360,7 @@ func TestGenruleLocationLabelShouldSubstituteFirstToolLabel(t *testing.T) { }` for _, tc := range testCases { - moduleAttrs := attrNameToString{ + moduleAttrs := AttrNameToString{ "cmd": `"$(location //other:foo.tool) -s $(OUTS) $(SRCS)"`, "outs": `["foo.out"]`, "srcs": `["foo.in"]`, @@ -375,13 +375,13 @@ func TestGenruleLocationLabelShouldSubstituteFirstToolLabel(t *testing.T) { } t.Run(tc.moduleType, func(t *testing.T) { - runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, - bp2buildTestCase{ - moduleTypeUnderTest: tc.moduleType, - moduleTypeUnderTestFactory: tc.factory, - blueprint: fmt.Sprintf(bp, tc.moduleType), - expectedBazelTargets: expectedBazelTargets, - filesystem: otherGenruleBp(tc.moduleType), + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, + Bp2buildTestCase{ + ModuleTypeUnderTest: tc.moduleType, + ModuleTypeUnderTestFactory: tc.factory, + Blueprint: fmt.Sprintf(bp, tc.moduleType), + ExpectedBazelTargets: expectedBazelTargets, + Filesystem: otherGenruleBp(tc.moduleType), }) }) } @@ -424,7 +424,7 @@ func TestGenruleLocationsLabelShouldSubstituteFirstToolLabel(t *testing.T) { }` for _, tc := range testCases { - moduleAttrs := attrNameToString{ + moduleAttrs := AttrNameToString{ "cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`, "outs": `["foo.out"]`, "srcs": `["foo.in"]`, @@ -439,13 +439,13 @@ func TestGenruleLocationsLabelShouldSubstituteFirstToolLabel(t *testing.T) { } t.Run(tc.moduleType, func(t *testing.T) { - runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, - bp2buildTestCase{ - moduleTypeUnderTest: tc.moduleType, - moduleTypeUnderTestFactory: tc.factory, - blueprint: fmt.Sprintf(bp, tc.moduleType), - expectedBazelTargets: expectedBazelTargets, - filesystem: otherGenruleBp(tc.moduleType), + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, + Bp2buildTestCase{ + ModuleTypeUnderTest: tc.moduleType, + ModuleTypeUnderTestFactory: tc.factory, + Blueprint: fmt.Sprintf(bp, tc.moduleType), + ExpectedBazelTargets: expectedBazelTargets, + Filesystem: otherGenruleBp(tc.moduleType), }) }) } @@ -487,7 +487,7 @@ func TestGenruleWithoutToolsOrToolFiles(t *testing.T) { }` for _, tc := range testCases { - moduleAttrs := attrNameToString{ + moduleAttrs := AttrNameToString{ "cmd": `"cp $(SRCS) $(OUTS)"`, "outs": `["foo.out"]`, "srcs": `["foo.in"]`, @@ -498,22 +498,22 @@ func TestGenruleWithoutToolsOrToolFiles(t *testing.T) { } t.Run(tc.moduleType, func(t *testing.T) { - runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, - bp2buildTestCase{ - moduleTypeUnderTest: tc.moduleType, - moduleTypeUnderTestFactory: tc.factory, - blueprint: fmt.Sprintf(bp, tc.moduleType), - expectedBazelTargets: expectedBazelTargets, + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, + Bp2buildTestCase{ + ModuleTypeUnderTest: tc.moduleType, + ModuleTypeUnderTestFactory: tc.factory, + Blueprint: fmt.Sprintf(bp, tc.moduleType), + ExpectedBazelTargets: expectedBazelTargets, }) }) } } func TestGenruleBp2BuildInlinesDefaults(t *testing.T) { - testCases := []bp2buildTestCase{ + testCases := []Bp2buildTestCase{ { - description: "genrule applies properties from a genrule_defaults dependency if not specified", - blueprint: `genrule_defaults { + Description: "genrule applies properties from a genrule_defaults dependency if not specified", + Blueprint: `genrule_defaults { name: "gen_defaults", cmd: "do-something $(in) $(out)", } @@ -525,8 +525,8 @@ genrule { bazel_module: { bp2build_available: true }, } `, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("genrule", "gen", attrNameToString{ + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{ "cmd": `"do-something $(SRCS) $(OUTS)"`, "outs": `["out"]`, "srcs": `["in1"]`, @@ -534,8 +534,8 @@ genrule { }, }, { - description: "genrule does merges properties from a genrule_defaults dependency, latest-first", - blueprint: `genrule_defaults { + Description: "genrule does merges properties from a genrule_defaults dependency, latest-first", + Blueprint: `genrule_defaults { name: "gen_defaults", out: ["out-from-defaults"], srcs: ["in-from-defaults"], @@ -550,8 +550,8 @@ genrule { bazel_module: { bp2build_available: true }, } `, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("genrule", "gen", attrNameToString{ + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{ "cmd": `"do-something $(SRCS) $(OUTS)"`, "outs": `[ "out-from-defaults", @@ -565,8 +565,8 @@ genrule { }, }, { - description: "genrule applies properties from list of genrule_defaults", - blueprint: `genrule_defaults { + Description: "genrule applies properties from list of genrule_defaults", + Blueprint: `genrule_defaults { name: "gen_defaults1", cmd: "cp $(in) $(out)", } @@ -583,8 +583,8 @@ genrule { bazel_module: { bp2build_available: true }, } `, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("genrule", "gen", attrNameToString{ + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{ "cmd": `"cp $(SRCS) $(OUTS)"`, "outs": `["out"]`, "srcs": `["in1"]`, @@ -592,8 +592,8 @@ genrule { }, }, { - description: "genrule applies properties from genrule_defaults transitively", - blueprint: `genrule_defaults { + Description: "genrule applies properties from genrule_defaults transitively", + Blueprint: `genrule_defaults { name: "gen_defaults1", defaults: ["gen_defaults2"], cmd: "cmd1 $(in) $(out)", // overrides gen_defaults2's cmd property value. @@ -620,8 +620,8 @@ genrule { bazel_module: { bp2build_available: true }, } `, - expectedBazelTargets: []string{ - makeBazelTargetNoRestrictions("genrule", "gen", attrNameToString{ + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{ "cmd": `"cmd1 $(SRCS) $(OUTS)"`, "outs": `[ "out-from-3", @@ -638,7 +638,7 @@ genrule { } for _, testCase := range testCases { - t.Run(testCase.description, func(t *testing.T) { + t.Run(testCase.Description, func(t *testing.T) { runGenruleTestCase(t, testCase) }) } diff --git a/bp2build/gensrcs_conversion_test.go b/bp2build/gensrcs_conversion_test.go index 76826631a..4845973d8 100644 --- a/bp2build/gensrcs_conversion_test.go +++ b/bp2build/gensrcs_conversion_test.go @@ -24,7 +24,7 @@ func TestGensrcs(t *testing.T) { testcases := []struct { name string bp string - expectedBazelAttrs attrNameToString + expectedBazelAttrs AttrNameToString }{ { name: "gensrcs with common usage of properties", @@ -37,7 +37,7 @@ func TestGensrcs(t *testing.T) { output_extension: "out", bazel_module: { bp2build_available: true }, }`, - expectedBazelAttrs: attrNameToString{ + expectedBazelAttrs: AttrNameToString{ "srcs": `[ "test/input.txt", ":external_files__BP2BUILD__MISSING__DEP", @@ -56,7 +56,7 @@ func TestGensrcs(t *testing.T) { cmd: "cat $(in) > $(out)", bazel_module: { bp2build_available: true }, }`, - expectedBazelAttrs: attrNameToString{ + expectedBazelAttrs: AttrNameToString{ "srcs": `["input.txt"]`, "cmd": `"cat $(SRC) > $(OUT)"`, }, @@ -65,15 +65,15 @@ func TestGensrcs(t *testing.T) { for _, test := range testcases { expectedBazelTargets := []string{ - makeBazelTargetNoRestrictions("gensrcs", "foo", test.expectedBazelAttrs), + 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, + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, + Bp2buildTestCase{ + ModuleTypeUnderTest: "gensrcs", + ModuleTypeUnderTestFactory: genrule.GenSrcsFactory, + Blueprint: test.bp, + ExpectedBazelTargets: expectedBazelTargets, }) }) } diff --git a/bp2build/java_binary_host_conversion_test.go b/bp2build/java_binary_host_conversion_test.go index d7a76a89f..50ea542b7 100644 --- a/bp2build/java_binary_host_conversion_test.go +++ b/bp2build/java_binary_host_conversion_test.go @@ -22,11 +22,11 @@ import ( "android/soong/java" ) -func runJavaBinaryHostTestCase(t *testing.T, tc bp2buildTestCase) { +func runJavaBinaryHostTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - (&tc).moduleTypeUnderTest = "java_binary_host" - (&tc).moduleTypeUnderTestFactory = java.BinaryHostFactory - runBp2BuildTestCase(t, func(ctx android.RegistrationContext) { + (&tc).ModuleTypeUnderTest = "java_binary_host" + (&tc).ModuleTypeUnderTestFactory = java.BinaryHostFactory + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { ctx.RegisterModuleType("cc_library_host_shared", cc.LibraryHostSharedFactory) ctx.RegisterModuleType("java_library", java.LibraryFactory) }, tc) @@ -41,10 +41,10 @@ var fs = map[string]string{ } func TestJavaBinaryHost(t *testing.T) { - runJavaBinaryHostTestCase(t, bp2buildTestCase{ - description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.", - filesystem: fs, - blueprint: `java_binary_host { + runJavaBinaryHostTestCase(t, Bp2buildTestCase{ + Description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.", + Filesystem: fs, + Blueprint: `java_binary_host { name: "java-binary-host-1", srcs: ["a.java", "b.java"], exclude_srcs: ["b.java"], @@ -54,8 +54,8 @@ func TestJavaBinaryHost(t *testing.T) { bazel_module: { bp2build_available: true }, java_version: "8", }`, - expectedBazelTargets: []string{ - makeBazelTarget("java_binary", "java-binary-host-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_binary", "java-binary-host-1", AttrNameToString{ "srcs": `["a.java"]`, "main_class": `"com.android.test.MainClass"`, "deps": `["//other:jni-lib-1"]`, @@ -74,10 +74,10 @@ func TestJavaBinaryHost(t *testing.T) { } func TestJavaBinaryHostRuntimeDeps(t *testing.T) { - runJavaBinaryHostTestCase(t, bp2buildTestCase{ - description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.", - filesystem: fs, - blueprint: `java_binary_host { + runJavaBinaryHostTestCase(t, Bp2buildTestCase{ + Description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.", + Filesystem: fs, + Blueprint: `java_binary_host { name: "java-binary-host-1", static_libs: ["java-dep-1"], manifest: "test.mf", @@ -90,8 +90,8 @@ java_library { bazel_module: { bp2build_available: false }, } `, - expectedBazelTargets: []string{ - makeBazelTarget("java_binary", "java-binary-host-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_binary", "java-binary-host-1", AttrNameToString{ "main_class": `"com.android.test.MainClass"`, "runtime_deps": `[":java-dep-1"]`, "target_compatible_with": `select({ diff --git a/bp2build/java_import_conversion_test.go b/bp2build/java_import_conversion_test.go index 0b3191c32..707ecce91 100644 --- a/bp2build/java_import_conversion_test.go +++ b/bp2build/java_import_conversion_test.go @@ -21,45 +21,45 @@ import ( "testing" ) -func runJavaImportTestCase(t *testing.T, tc bp2buildTestCase) { +func runJavaImportTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - runBp2BuildTestCase(t, registerJavaImportModuleTypes, tc) + RunBp2BuildTestCase(t, registerJavaImportModuleTypes, tc) } func registerJavaImportModuleTypes(ctx android.RegistrationContext) { } func TestJavaImportMinimal(t *testing.T) { - runJavaImportTestCase(t, bp2buildTestCase{ - description: "Java import - simple example", - moduleTypeUnderTest: "java_import", - moduleTypeUnderTestFactory: java.ImportFactory, - filesystem: map[string]string{ + runJavaImportTestCase(t, Bp2buildTestCase{ + Description: "Java import - simple example", + ModuleTypeUnderTest: "java_import", + ModuleTypeUnderTestFactory: java.ImportFactory, + Filesystem: map[string]string{ "import.jar": "", }, - blueprint: ` + Blueprint: ` java_import { name: "example_import", jars: ["import.jar"], bazel_module: { bp2build_available: true }, } `, - expectedBazelTargets: []string{ - makeBazelTarget("java_import", "example_import", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_import", "example_import", AttrNameToString{ "jars": `["import.jar"]`, }), }}) } func TestJavaImportArchVariant(t *testing.T) { - runJavaImportTestCase(t, bp2buildTestCase{ - description: "Java import - simple example", - moduleTypeUnderTest: "java_import", - moduleTypeUnderTestFactory: java.ImportFactory, - filesystem: map[string]string{ + runJavaImportTestCase(t, Bp2buildTestCase{ + Description: "Java import - simple example", + ModuleTypeUnderTest: "java_import", + ModuleTypeUnderTestFactory: java.ImportFactory, + Filesystem: map[string]string{ "import.jar": "", }, - blueprint: ` + Blueprint: ` java_import { name: "example_import", target: { @@ -73,8 +73,8 @@ java_import { bazel_module: { bp2build_available: true }, } `, - expectedBazelTargets: []string{ - makeBazelTarget("java_import", "example_import", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_import", "example_import", AttrNameToString{ "jars": `select({ "//build/bazel/platforms/os:android": ["android.jar"], "//build/bazel/platforms/os:linux": ["linux.jar"], diff --git a/bp2build/java_library_conversion_test.go b/bp2build/java_library_conversion_test.go index e4d9cbcac..7fa19d950 100644 --- a/bp2build/java_library_conversion_test.go +++ b/bp2build/java_library_conversion_test.go @@ -22,22 +22,22 @@ import ( "android/soong/java" ) -func runJavaLibraryTestCaseWithRegistrationCtxFunc(t *testing.T, tc bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) { +func runJavaLibraryTestCaseWithRegistrationCtxFunc(t *testing.T, tc Bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) { t.Helper() - (&tc).moduleTypeUnderTest = "java_library" - (&tc).moduleTypeUnderTestFactory = java.LibraryFactory - runBp2BuildTestCase(t, registrationCtxFunc, tc) + (&tc).ModuleTypeUnderTest = "java_library" + (&tc).ModuleTypeUnderTestFactory = java.LibraryFactory + RunBp2BuildTestCase(t, registrationCtxFunc, tc) } -func runJavaLibraryTestCase(t *testing.T, tc bp2buildTestCase) { +func runJavaLibraryTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() runJavaLibraryTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) {}) } func TestJavaLibrary(t *testing.T) { - runJavaLibraryTestCase(t, bp2buildTestCase{ - description: "java_library with srcs, exclude_srcs and libs", - blueprint: `java_library { + runJavaLibraryTestCase(t, Bp2buildTestCase{ + Description: "java_library with srcs, exclude_srcs and libs", + Blueprint: `java_library { name: "java-lib-1", srcs: ["a.java", "b.java"], exclude_srcs: ["b.java"], @@ -50,12 +50,12 @@ java_library { srcs: ["b.java"], bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("java_library", "java-lib-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_library", "java-lib-1", AttrNameToString{ "srcs": `["a.java"]`, "deps": `[":java-lib-2"]`, }), - makeBazelTarget("java_library", "java-lib-2", attrNameToString{ + makeBazelTarget("java_library", "java-lib-2", AttrNameToString{ "srcs": `["b.java"]`, }), }, @@ -63,8 +63,8 @@ java_library { } func TestJavaLibraryConvertsStaticLibsToDepsAndExports(t *testing.T) { - runJavaLibraryTestCase(t, bp2buildTestCase{ - blueprint: `java_library { + runJavaLibraryTestCase(t, Bp2buildTestCase{ + Blueprint: `java_library { name: "java-lib-1", srcs: ["a.java"], libs: ["java-lib-2"], @@ -83,8 +83,8 @@ java_library { srcs: ["c.java"], bazel_module: { bp2build_available: false }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("java_library", "java-lib-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_library", "java-lib-1", AttrNameToString{ "srcs": `["a.java"]`, "deps": `[ ":java-lib-2", @@ -97,8 +97,8 @@ java_library { } func TestJavaLibraryConvertsStaticLibsToExportsIfNoSrcs(t *testing.T) { - runJavaLibraryTestCase(t, bp2buildTestCase{ - blueprint: `java_library { + runJavaLibraryTestCase(t, Bp2buildTestCase{ + Blueprint: `java_library { name: "java-lib-1", static_libs: ["java-lib-2"], bazel_module: { bp2build_available: true }, @@ -109,8 +109,8 @@ java_library { srcs: ["a.java"], bazel_module: { bp2build_available: false }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("java_library", "java-lib-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_library", "java-lib-1", AttrNameToString{ "exports": `[":java-lib-2"]`, }), }, @@ -118,9 +118,9 @@ java_library { } func TestJavaLibraryFailsToConvertLibsWithNoSrcs(t *testing.T) { - runJavaLibraryTestCase(t, bp2buildTestCase{ - expectedErr: fmt.Errorf("Module has direct dependencies but no sources. Bazel will not allow this."), - blueprint: `java_library { + runJavaLibraryTestCase(t, Bp2buildTestCase{ + ExpectedErr: fmt.Errorf("Module has direct dependencies but no sources. Bazel will not allow this."), + Blueprint: `java_library { name: "java-lib-1", libs: ["java-lib-2"], bazel_module: { bp2build_available: true }, @@ -131,13 +131,13 @@ java_library { srcs: ["a.java"], bazel_module: { bp2build_available: false }, }`, - expectedBazelTargets: []string{}, + ExpectedBazelTargets: []string{}, }) } func TestJavaLibraryPlugins(t *testing.T) { - runJavaLibraryTestCaseWithRegistrationCtxFunc(t, bp2buildTestCase{ - blueprint: `java_library { + runJavaLibraryTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{ + Blueprint: `java_library { name: "java-lib-1", plugins: ["java-plugin-1"], bazel_module: { bp2build_available: true }, @@ -148,8 +148,8 @@ java_plugin { srcs: ["a.java"], bazel_module: { bp2build_available: false }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("java_library", "java-lib-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_library", "java-lib-1", AttrNameToString{ "plugins": `[":java-plugin-1"]`, }), }, @@ -159,14 +159,14 @@ java_plugin { } func TestJavaLibraryJavaVersion(t *testing.T) { - runJavaLibraryTestCase(t, bp2buildTestCase{ - blueprint: `java_library { + runJavaLibraryTestCase(t, Bp2buildTestCase{ + Blueprint: `java_library { name: "java-lib-1", srcs: ["a.java"], java_version: "11", }`, - expectedBazelTargets: []string{ - makeBazelTarget("java_library", "java-lib-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_library", "java-lib-1", AttrNameToString{ "srcs": `["a.java"]`, "javacopts": `["-source 11 -target 11"]`, }), @@ -175,8 +175,8 @@ func TestJavaLibraryJavaVersion(t *testing.T) { } func TestJavaLibraryErrorproneJavacflagsEnabledManually(t *testing.T) { - runJavaLibraryTestCase(t, bp2buildTestCase{ - blueprint: `java_library { + runJavaLibraryTestCase(t, Bp2buildTestCase{ + Blueprint: `java_library { name: "java-lib-1", srcs: ["a.java"], javacflags: ["-Xsuper-fast"], @@ -185,8 +185,8 @@ func TestJavaLibraryErrorproneJavacflagsEnabledManually(t *testing.T) { javacflags: ["-Xep:SpeedLimit:OFF"], }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("java_library", "java-lib-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_library", "java-lib-1", AttrNameToString{ "javacopts": `[ "-Xsuper-fast", "-Xep:SpeedLimit:OFF", @@ -198,8 +198,8 @@ func TestJavaLibraryErrorproneJavacflagsEnabledManually(t *testing.T) { } func TestJavaLibraryErrorproneJavacflagsErrorproneDisabledByDefault(t *testing.T) { - runJavaLibraryTestCase(t, bp2buildTestCase{ - blueprint: `java_library { + runJavaLibraryTestCase(t, Bp2buildTestCase{ + Blueprint: `java_library { name: "java-lib-1", srcs: ["a.java"], javacflags: ["-Xsuper-fast"], @@ -207,8 +207,8 @@ func TestJavaLibraryErrorproneJavacflagsErrorproneDisabledByDefault(t *testing.T javacflags: ["-Xep:SpeedLimit:OFF"], }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("java_library", "java-lib-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_library", "java-lib-1", AttrNameToString{ "javacopts": `["-Xsuper-fast"]`, "srcs": `["a.java"]`, }), @@ -217,8 +217,8 @@ func TestJavaLibraryErrorproneJavacflagsErrorproneDisabledByDefault(t *testing.T } func TestJavaLibraryErrorproneJavacflagsErrorproneDisabledManually(t *testing.T) { - runJavaLibraryTestCase(t, bp2buildTestCase{ - blueprint: `java_library { + runJavaLibraryTestCase(t, Bp2buildTestCase{ + Blueprint: `java_library { name: "java-lib-1", srcs: ["a.java"], javacflags: ["-Xsuper-fast"], @@ -227,8 +227,8 @@ func TestJavaLibraryErrorproneJavacflagsErrorproneDisabledManually(t *testing.T) javacflags: ["-Xep:SpeedLimit:OFF"], }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("java_library", "java-lib-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_library", "java-lib-1", AttrNameToString{ "javacopts": `["-Xsuper-fast"]`, "srcs": `["a.java"]`, }), @@ -237,11 +237,11 @@ func TestJavaLibraryErrorproneJavacflagsErrorproneDisabledManually(t *testing.T) } func TestJavaLibraryLogTags(t *testing.T) { - runJavaLibraryTestCase(t, bp2buildTestCase{ - description: "Java library - logtags creates separate dependency", - moduleTypeUnderTest: "java_library", - moduleTypeUnderTestFactory: java.LibraryFactory, - blueprint: `java_library { + runJavaLibraryTestCase(t, Bp2buildTestCase{ + Description: "Java library - logtags creates separate dependency", + ModuleTypeUnderTest: "java_library", + ModuleTypeUnderTestFactory: java.LibraryFactory, + Blueprint: `java_library { name: "example_lib", srcs: [ "a.java", @@ -251,14 +251,14 @@ func TestJavaLibraryLogTags(t *testing.T) { ], bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("event_log_tags", "example_lib_logtags", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("event_log_tags", "example_lib_logtags", AttrNameToString{ "srcs": `[ "a.logtag", "b.logtag", ]`, }), - makeBazelTarget("java_library", "example_lib", attrNameToString{ + makeBazelTarget("java_library", "example_lib", AttrNameToString{ "srcs": `[ "a.java", "b.java", @@ -269,18 +269,18 @@ func TestJavaLibraryLogTags(t *testing.T) { } func TestJavaLibraryResources(t *testing.T) { - runJavaLibraryTestCase(t, bp2buildTestCase{ - filesystem: map[string]string{ + runJavaLibraryTestCase(t, Bp2buildTestCase{ + Filesystem: map[string]string{ "res/a.res": "", "res/b.res": "", "res/dir1/b.res": "", }, - blueprint: `java_library { + Blueprint: `java_library { name: "java-lib-1", java_resources: ["res/a.res", "res/b.res"], }`, - expectedBazelTargets: []string{ - makeBazelTarget("java_library", "java-lib-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_library", "java-lib-1", AttrNameToString{ "resources": `[ "res/a.res", "res/b.res", @@ -291,18 +291,18 @@ func TestJavaLibraryResources(t *testing.T) { } func TestJavaLibraryResourceDirs(t *testing.T) { - runJavaLibraryTestCase(t, bp2buildTestCase{ - filesystem: map[string]string{ + runJavaLibraryTestCase(t, Bp2buildTestCase{ + Filesystem: map[string]string{ "res/a.res": "", "res/b.res": "", "res/dir1/b.res": "", }, - blueprint: `java_library { + Blueprint: `java_library { name: "java-lib-1", java_resource_dirs: ["res"], }`, - expectedBazelTargets: []string{ - makeBazelTarget("java_library", "java-lib-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_library", "java-lib-1", AttrNameToString{ "resource_strip_prefix": `"res"`, "resources": `[ "res/a.res", @@ -315,18 +315,18 @@ func TestJavaLibraryResourceDirs(t *testing.T) { } func TestJavaLibraryResourcesExcludeDir(t *testing.T) { - runJavaLibraryTestCase(t, bp2buildTestCase{ - filesystem: map[string]string{ + runJavaLibraryTestCase(t, Bp2buildTestCase{ + Filesystem: map[string]string{ "res/a.res": "", "res/exclude/b.res": "", }, - blueprint: `java_library { + Blueprint: `java_library { name: "java-lib-1", java_resource_dirs: ["res"], exclude_java_resource_dirs: ["res/exclude"], }`, - expectedBazelTargets: []string{ - makeBazelTarget("java_library", "java-lib-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_library", "java-lib-1", AttrNameToString{ "resource_strip_prefix": `"res"`, "resources": `["res/a.res"]`, }), @@ -335,19 +335,19 @@ func TestJavaLibraryResourcesExcludeDir(t *testing.T) { } func TestJavaLibraryResourcesExcludeFile(t *testing.T) { - runJavaLibraryTestCase(t, bp2buildTestCase{ - filesystem: map[string]string{ + runJavaLibraryTestCase(t, Bp2buildTestCase{ + Filesystem: map[string]string{ "res/a.res": "", "res/dir1/b.res": "", "res/dir1/exclude.res": "", }, - blueprint: `java_library { + Blueprint: `java_library { name: "java-lib-1", java_resource_dirs: ["res"], exclude_java_resources: ["res/dir1/exclude.res"], }`, - expectedBazelTargets: []string{ - makeBazelTarget("java_library", "java-lib-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_library", "java-lib-1", AttrNameToString{ "resource_strip_prefix": `"res"`, "resources": `[ "res/a.res", @@ -359,16 +359,16 @@ func TestJavaLibraryResourcesExcludeFile(t *testing.T) { } func TestJavaLibraryResourcesFailsWithMultipleDirs(t *testing.T) { - runJavaLibraryTestCase(t, bp2buildTestCase{ - filesystem: map[string]string{ + runJavaLibraryTestCase(t, Bp2buildTestCase{ + Filesystem: map[string]string{ "res/a.res": "", "res1/a.res": "", }, - blueprint: `java_library { + Blueprint: `java_library { name: "java-lib-1", java_resource_dirs: ["res", "res1"], }`, - expectedErr: fmt.Errorf("bp2build does not support more than one directory in java_resource_dirs (b/226423379)"), - expectedBazelTargets: []string{}, + ExpectedErr: fmt.Errorf("bp2build does not support more than one directory in java_resource_dirs (b/226423379)"), + ExpectedBazelTargets: []string{}, }) } diff --git a/bp2build/java_library_host_conversion_test.go b/bp2build/java_library_host_conversion_test.go index 83cc5519a..1dcf16337 100644 --- a/bp2build/java_library_host_conversion_test.go +++ b/bp2build/java_library_host_conversion_test.go @@ -21,17 +21,17 @@ import ( "android/soong/java" ) -func runJavaLibraryHostTestCase(t *testing.T, tc bp2buildTestCase) { +func runJavaLibraryHostTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - (&tc).moduleTypeUnderTest = "java_library_host" - (&tc).moduleTypeUnderTestFactory = java.LibraryHostFactory - runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc) + (&tc).ModuleTypeUnderTest = "java_library_host" + (&tc).ModuleTypeUnderTestFactory = java.LibraryHostFactory + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc) } func TestJavaLibraryHost(t *testing.T) { - runJavaLibraryHostTestCase(t, bp2buildTestCase{ - description: "java_library_host with srcs, exclude_srcs and libs", - blueprint: `java_library_host { + runJavaLibraryHostTestCase(t, Bp2buildTestCase{ + Description: "java_library_host with srcs, exclude_srcs and libs", + Blueprint: `java_library_host { name: "java-lib-host-1", srcs: ["a.java", "b.java"], exclude_srcs: ["b.java"], @@ -45,8 +45,8 @@ java_library_host { bazel_module: { bp2build_available: true }, java_version: "9", }`, - expectedBazelTargets: []string{ - makeBazelTarget("java_library", "java-lib-host-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_library", "java-lib-host-1", AttrNameToString{ "srcs": `["a.java"]`, "deps": `[":java-lib-host-2"]`, "target_compatible_with": `select({ @@ -54,7 +54,7 @@ java_library_host { "//conditions:default": [], })`, }), - makeBazelTarget("java_library", "java-lib-host-2", attrNameToString{ + makeBazelTarget("java_library", "java-lib-host-2", AttrNameToString{ "javacopts": `["-source 1.9 -target 1.9"]`, "srcs": `["c.java"]`, "target_compatible_with": `select({ diff --git a/bp2build/java_plugin_conversion_test.go b/bp2build/java_plugin_conversion_test.go index dc763e763..2d2e5ff5d 100644 --- a/bp2build/java_plugin_conversion_test.go +++ b/bp2build/java_plugin_conversion_test.go @@ -21,19 +21,19 @@ import ( "android/soong/java" ) -func runJavaPluginTestCase(t *testing.T, tc bp2buildTestCase) { +func runJavaPluginTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - (&tc).moduleTypeUnderTest = "java_plugin" - (&tc).moduleTypeUnderTestFactory = java.PluginFactory - runBp2BuildTestCase(t, func(ctx android.RegistrationContext) { + (&tc).ModuleTypeUnderTest = "java_plugin" + (&tc).ModuleTypeUnderTestFactory = java.PluginFactory + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { ctx.RegisterModuleType("java_library", java.LibraryFactory) }, tc) } func TestJavaPlugin(t *testing.T) { - runJavaPluginTestCase(t, bp2buildTestCase{ - description: "java_plugin with srcs, libs, static_libs", - blueprint: `java_plugin { + runJavaPluginTestCase(t, Bp2buildTestCase{ + Description: "java_plugin with srcs, libs, static_libs", + Blueprint: `java_plugin { name: "java-plug-1", srcs: ["a.java", "b.java"], libs: ["java-lib-1"], @@ -53,8 +53,8 @@ java_library { srcs: ["c.java"], bazel_module: { bp2build_available: false }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("java_plugin", "java-plug-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_plugin", "java-plug-1", AttrNameToString{ "target_compatible_with": `select({ "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], "//conditions:default": [], @@ -74,9 +74,9 @@ java_library { } func TestJavaPluginNoSrcs(t *testing.T) { - runJavaPluginTestCase(t, bp2buildTestCase{ - description: "java_plugin without srcs converts (static) libs to deps", - blueprint: `java_plugin { + runJavaPluginTestCase(t, Bp2buildTestCase{ + Description: "java_plugin without srcs converts (static) libs to deps", + Blueprint: `java_plugin { name: "java-plug-1", libs: ["java-lib-1"], static_libs: ["java-lib-2"], @@ -94,8 +94,8 @@ java_library { srcs: ["c.java"], bazel_module: { bp2build_available: false }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("java_plugin", "java-plug-1", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("java_plugin", "java-plug-1", AttrNameToString{ "target_compatible_with": `select({ "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], "//conditions:default": [], diff --git a/bp2build/java_proto_conversion_test.go b/bp2build/java_proto_conversion_test.go index c6feeb8dc..6465641f0 100644 --- a/bp2build/java_proto_conversion_test.go +++ b/bp2build/java_proto_conversion_test.go @@ -22,11 +22,11 @@ import ( "android/soong/java" ) -func runJavaProtoTestCase(t *testing.T, tc bp2buildTestCase) { +func runJavaProtoTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - (&tc).moduleTypeUnderTest = "java_library_static" - (&tc).moduleTypeUnderTestFactory = java.LibraryFactory - runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc) + (&tc).ModuleTypeUnderTest = "java_library_static" + (&tc).ModuleTypeUnderTestFactory = java.LibraryFactory + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc) } func TestJavaProto(t *testing.T) { @@ -70,25 +70,25 @@ func TestJavaProto(t *testing.T) { srcs: ["a.proto"], }` - protoLibrary := makeBazelTarget("proto_library", "java-protos_proto", attrNameToString{ + protoLibrary := makeBazelTarget("proto_library", "java-protos_proto", AttrNameToString{ "srcs": `["a.proto"]`, }) for _, tc := range testCases { javaLibraryName := fmt.Sprintf("java-protos_%s", tc.javaLibraryNameExtension) - runJavaProtoTestCase(t, bp2buildTestCase{ - description: fmt.Sprintf("java_proto %s", tc.protoType), - blueprint: fmt.Sprintf(bp, tc.protoType), - expectedBazelTargets: []string{ + runJavaProtoTestCase(t, Bp2buildTestCase{ + Description: fmt.Sprintf("java_proto %s", tc.protoType), + Blueprint: fmt.Sprintf(bp, tc.protoType), + ExpectedBazelTargets: []string{ protoLibrary, makeBazelTarget( tc.javaLibraryType, javaLibraryName, - attrNameToString{ + AttrNameToString{ "deps": `[":java-protos_proto"]`, }), - makeBazelTarget("java_library", "java-protos", attrNameToString{ + makeBazelTarget("java_library", "java-protos", AttrNameToString{ "exports": fmt.Sprintf(`[":%s"]`, javaLibraryName), }), }, @@ -97,25 +97,25 @@ func TestJavaProto(t *testing.T) { } func TestJavaProtoDefault(t *testing.T) { - runJavaProtoTestCase(t, bp2buildTestCase{ - description: "java_library proto default", - blueprint: `java_library_static { + runJavaProtoTestCase(t, Bp2buildTestCase{ + Description: "java_library proto default", + Blueprint: `java_library_static { name: "java-protos", srcs: ["a.proto"], java_version: "7", } `, - expectedBazelTargets: []string{ - makeBazelTarget("proto_library", "java-protos_proto", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("proto_library", "java-protos_proto", AttrNameToString{ "srcs": `["a.proto"]`, }), makeBazelTarget( "java_lite_proto_library", "java-protos_java_proto_lite", - attrNameToString{ + AttrNameToString{ "deps": `[":java-protos_proto"]`, }), - makeBazelTarget("java_library", "java-protos", attrNameToString{ + makeBazelTarget("java_library", "java-protos", AttrNameToString{ "exports": `[":java-protos_java_proto_lite"]`, "javacopts": `["-source 1.7 -target 1.7"]`, }), diff --git a/bp2build/linker_config_conversion_test.go b/bp2build/linker_config_conversion_test.go new file mode 100644 index 000000000..3b8a36355 --- /dev/null +++ b/bp2build/linker_config_conversion_test.go @@ -0,0 +1,59 @@ +// Copyright 2022 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package bp2build + +import ( + "fmt" + "testing" + + "android/soong/linkerconfig" +) + +func runLinkerConfigTestCase(t *testing.T, tc Bp2buildTestCase) { + t.Helper() + (&tc).ModuleTypeUnderTest = "linker_config" + (&tc).ModuleTypeUnderTestFactory = linkerconfig.LinkerConfigFactory + runBp2BuildTestCaseSimple(t, tc) +} + +func TestLinkerConfigConvertsSrc(t *testing.T) { + runLinkerConfigTestCase(t, + Bp2buildTestCase{ + Blueprint: ` +linker_config { + name: "foo", + src: "a.json", +} +`, + ExpectedBazelTargets: []string{makeBazelTarget("linker_config", "foo", AttrNameToString{ + "src": `"a.json"`, + })}, + }) + +} + +func TestLinkerConfigNoSrc(t *testing.T) { + runLinkerConfigTestCase(t, + Bp2buildTestCase{ + Blueprint: ` +linker_config { + name: "foo", +} +`, + ExpectedBazelTargets: []string{}, + ExpectedErr: fmt.Errorf("Android.bp:2:1: module \"foo\": src: empty src is not supported"), + }) + +} diff --git a/bp2build/metrics.go b/bp2build/metrics.go index 04fac441e..3a21c3454 100644 --- a/bp2build/metrics.go +++ b/bp2build/metrics.go @@ -116,8 +116,6 @@ func (metrics *CodegenMetrics) Write(dir string) { } if _, err := os.Stat(metricsFile); err != nil { fail(err, "MISSING BP2BUILD METRICS OUTPUT: Failed to `stat` %s", metricsFile) - } else { - fmt.Printf("\nWrote bp2build metrics to: %s\n", metricsFile) } } diff --git a/bp2build/prebuilt_etc_conversion_test.go b/bp2build/prebuilt_etc_conversion_test.go index 2e4b22119..fce4c745b 100644 --- a/bp2build/prebuilt_etc_conversion_test.go +++ b/bp2build/prebuilt_etc_conversion_test.go @@ -21,21 +21,21 @@ import ( "testing" ) -func runPrebuiltEtcTestCase(t *testing.T, tc bp2buildTestCase) { +func runPrebuiltEtcTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - (&tc).moduleTypeUnderTest = "prebuilt_etc" - (&tc).moduleTypeUnderTestFactory = etc.PrebuiltEtcFactory - runBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc) + (&tc).ModuleTypeUnderTest = "prebuilt_etc" + (&tc).ModuleTypeUnderTestFactory = etc.PrebuiltEtcFactory + RunBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc) } func registerPrebuiltEtcModuleTypes(ctx android.RegistrationContext) { } func TestPrebuiltEtcSimple(t *testing.T) { - runPrebuiltEtcTestCase(t, bp2buildTestCase{ - description: "prebuilt_etc - simple example", - filesystem: map[string]string{}, - blueprint: ` + runPrebuiltEtcTestCase(t, Bp2buildTestCase{ + Description: "prebuilt_etc - simple example", + Filesystem: map[string]string{}, + Blueprint: ` prebuilt_etc { name: "apex_tz_version", src: "version/tz_version", @@ -44,8 +44,8 @@ prebuilt_etc { installable: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("prebuilt_file", "apex_tz_version", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{ "filename": `"tz_version"`, "installable": `False`, "src": `"version/tz_version"`, @@ -54,10 +54,10 @@ prebuilt_etc { } func TestPrebuiltEtcArchVariant(t *testing.T) { - runPrebuiltEtcTestCase(t, bp2buildTestCase{ - description: "prebuilt_etc - arch variant", - filesystem: map[string]string{}, - blueprint: ` + runPrebuiltEtcTestCase(t, Bp2buildTestCase{ + Description: "prebuilt_etc - arch variant", + Filesystem: map[string]string{}, + Blueprint: ` prebuilt_etc { name: "apex_tz_version", src: "version/tz_version", @@ -74,8 +74,8 @@ prebuilt_etc { } } `, - expectedBazelTargets: []string{ - makeBazelTarget("prebuilt_file", "apex_tz_version", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{ "filename": `"tz_version"`, "installable": `False`, "src": `select({ @@ -88,10 +88,10 @@ prebuilt_etc { } func TestPrebuiltEtcArchAndTargetVariant(t *testing.T) { - runPrebuiltEtcTestCase(t, bp2buildTestCase{ - description: "prebuilt_etc - arch variant", - filesystem: map[string]string{}, - blueprint: ` + runPrebuiltEtcTestCase(t, Bp2buildTestCase{ + Description: "prebuilt_etc - arch variant", + Filesystem: map[string]string{}, + Blueprint: ` prebuilt_etc { name: "apex_tz_version", src: "version/tz_version", @@ -113,8 +113,8 @@ prebuilt_etc { }, } `, - expectedBazelTargets: []string{ - makeBazelTarget("prebuilt_file", "apex_tz_version", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{ "filename": `"tz_version"`, "installable": `False`, "src": `select({ @@ -129,21 +129,21 @@ prebuilt_etc { })}}) } -func runPrebuiltUsrShareTestCase(t *testing.T, tc bp2buildTestCase) { +func runPrebuiltUsrShareTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - (&tc).moduleTypeUnderTest = "prebuilt_usr_share" - (&tc).moduleTypeUnderTestFactory = etc.PrebuiltUserShareFactory - runBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc) + (&tc).ModuleTypeUnderTest = "prebuilt_usr_share" + (&tc).ModuleTypeUnderTestFactory = etc.PrebuiltUserShareFactory + RunBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc) } func registerPrebuiltUsrShareModuleTypes(ctx android.RegistrationContext) { } func TestPrebuiltUsrShareSimple(t *testing.T) { - runPrebuiltUsrShareTestCase(t, bp2buildTestCase{ - description: "prebuilt_usr_share - simple example", - filesystem: map[string]string{}, - blueprint: ` + runPrebuiltUsrShareTestCase(t, Bp2buildTestCase{ + Description: "prebuilt_usr_share - simple example", + Filesystem: map[string]string{}, + Blueprint: ` prebuilt_usr_share { name: "apex_tz_version", src: "version/tz_version", @@ -152,8 +152,8 @@ prebuilt_usr_share { installable: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("prebuilt_file", "apex_tz_version", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{ "filename": `"tz_version"`, "installable": `False`, "src": `"version/tz_version"`, @@ -162,10 +162,10 @@ prebuilt_usr_share { } func TestPrebuiltEtcNoSubdir(t *testing.T) { - runPrebuiltEtcTestCase(t, bp2buildTestCase{ - description: "prebuilt_etc - no subdir", - filesystem: map[string]string{}, - blueprint: ` + runPrebuiltEtcTestCase(t, Bp2buildTestCase{ + Description: "prebuilt_etc - no subdir", + Filesystem: map[string]string{}, + Blueprint: ` prebuilt_etc { name: "apex_tz_version", src: "version/tz_version", @@ -173,8 +173,8 @@ prebuilt_etc { installable: false, } `, - expectedBazelTargets: []string{ - makeBazelTarget("prebuilt_file", "apex_tz_version", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{ "filename": `"tz_version"`, "installable": `False`, "src": `"version/tz_version"`, diff --git a/bp2build/python_binary_conversion_test.go b/bp2build/python_binary_conversion_test.go index 22bd028e7..79da5d597 100644 --- a/bp2build/python_binary_conversion_test.go +++ b/bp2build/python_binary_conversion_test.go @@ -7,27 +7,27 @@ import ( "android/soong/python" ) -func runBp2BuildTestCaseWithPythonLibraries(t *testing.T, tc bp2buildTestCase) { +func runBp2BuildTestCaseWithPythonLibraries(t *testing.T, tc Bp2buildTestCase) { t.Helper() - runBp2BuildTestCase(t, func(ctx android.RegistrationContext) { + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { ctx.RegisterModuleType("python_library", python.PythonLibraryFactory) ctx.RegisterModuleType("python_library_host", python.PythonLibraryHostFactory) }, tc) } func TestPythonBinaryHostSimple(t *testing.T) { - runBp2BuildTestCaseWithPythonLibraries(t, bp2buildTestCase{ - description: "simple python_binary_host converts to a native py_binary", - moduleTypeUnderTest: "python_binary_host", - moduleTypeUnderTestFactory: python.PythonBinaryHostFactory, - filesystem: map[string]string{ + runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{ + Description: "simple python_binary_host converts to a native py_binary", + ModuleTypeUnderTest: "python_binary_host", + ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory, + Filesystem: map[string]string{ "a.py": "", "b/c.py": "", "b/d.py": "", "b/e.py": "", "files/data.txt": "", }, - blueprint: `python_binary_host { + Blueprint: `python_binary_host { name: "foo", main: "a.py", srcs: ["**/*.py"], @@ -41,8 +41,8 @@ func TestPythonBinaryHostSimple(t *testing.T) { srcs: ["b/e.py"], bazel_module: { bp2build_available: false }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("py_binary", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("py_binary", "foo", AttrNameToString{ "data": `["files/data.txt"]`, "deps": `[":bar"]`, "main": `"a.py"`, @@ -62,11 +62,11 @@ func TestPythonBinaryHostSimple(t *testing.T) { } func TestPythonBinaryHostPy2(t *testing.T) { - runBp2BuildTestCaseSimple(t, bp2buildTestCase{ - description: "py2 python_binary_host", - moduleTypeUnderTest: "python_binary_host", - moduleTypeUnderTestFactory: python.PythonBinaryHostFactory, - blueprint: `python_binary_host { + runBp2BuildTestCaseSimple(t, Bp2buildTestCase{ + Description: "py2 python_binary_host", + ModuleTypeUnderTest: "python_binary_host", + ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory, + Blueprint: `python_binary_host { name: "foo", srcs: ["a.py"], version: { @@ -81,8 +81,8 @@ func TestPythonBinaryHostPy2(t *testing.T) { bazel_module: { bp2build_available: true }, } `, - expectedBazelTargets: []string{ - makeBazelTarget("py_binary", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("py_binary", "foo", AttrNameToString{ "python_version": `"PY2"`, "imports": `["."]`, "srcs": `["a.py"]`, @@ -96,11 +96,11 @@ func TestPythonBinaryHostPy2(t *testing.T) { } func TestPythonBinaryHostPy3(t *testing.T) { - runBp2BuildTestCaseSimple(t, bp2buildTestCase{ - description: "py3 python_binary_host", - moduleTypeUnderTest: "python_binary_host", - moduleTypeUnderTestFactory: python.PythonBinaryHostFactory, - blueprint: `python_binary_host { + runBp2BuildTestCaseSimple(t, Bp2buildTestCase{ + Description: "py3 python_binary_host", + ModuleTypeUnderTest: "python_binary_host", + ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory, + Blueprint: `python_binary_host { name: "foo", srcs: ["a.py"], version: { @@ -115,9 +115,9 @@ func TestPythonBinaryHostPy3(t *testing.T) { bazel_module: { bp2build_available: true }, } `, - expectedBazelTargets: []string{ + ExpectedBazelTargets: []string{ // python_version is PY3 by default. - makeBazelTarget("py_binary", "foo", attrNameToString{ + makeBazelTarget("py_binary", "foo", AttrNameToString{ "imports": `["."]`, "srcs": `["a.py"]`, "target_compatible_with": `select({ @@ -130,15 +130,15 @@ func TestPythonBinaryHostPy3(t *testing.T) { } func TestPythonBinaryHostArchVariance(t *testing.T) { - runBp2BuildTestCaseSimple(t, bp2buildTestCase{ - description: "test arch variants", - moduleTypeUnderTest: "python_binary_host", - moduleTypeUnderTestFactory: python.PythonBinaryHostFactory, - filesystem: map[string]string{ + runBp2BuildTestCaseSimple(t, Bp2buildTestCase{ + Description: "test arch variants", + ModuleTypeUnderTest: "python_binary_host", + ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory, + Filesystem: map[string]string{ "dir/arm.py": "", "dir/x86.py": "", }, - blueprint: `python_binary_host { + Blueprint: `python_binary_host { name: "foo-arm", arch: { arm: { @@ -149,8 +149,8 @@ func TestPythonBinaryHostArchVariance(t *testing.T) { }, }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("py_binary", "foo-arm", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("py_binary", "foo-arm", AttrNameToString{ "imports": `["."]`, "srcs": `select({ "//build/bazel/platforms/arch:arm": ["arm.py"], diff --git a/bp2build/python_library_conversion_test.go b/bp2build/python_library_conversion_test.go index f51f1068b..1d6061bf1 100644 --- a/bp2build/python_library_conversion_test.go +++ b/bp2build/python_library_conversion_test.go @@ -21,7 +21,7 @@ type pythonLibBp2BuildTestCase struct { expectedError error } -func convertPythonLibTestCaseToBp2build_Host(tc pythonLibBp2BuildTestCase) bp2buildTestCase { +func convertPythonLibTestCaseToBp2build_Host(tc pythonLibBp2BuildTestCase) Bp2buildTestCase { for i := range tc.expectedBazelTargets { tc.expectedBazelTargets[i].attrs["target_compatible_with"] = `select({ "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], @@ -32,7 +32,7 @@ func convertPythonLibTestCaseToBp2build_Host(tc pythonLibBp2BuildTestCase) bp2bu return convertPythonLibTestCaseToBp2build(tc) } -func convertPythonLibTestCaseToBp2build(tc pythonLibBp2BuildTestCase) bp2buildTestCase { +func convertPythonLibTestCaseToBp2build(tc pythonLibBp2BuildTestCase) Bp2buildTestCase { var bp2BuildTargets []string for _, t := range tc.expectedBazelTargets { bp2BuildTargets = append(bp2BuildTargets, makeBazelTarget(t.typ, t.name, t.attrs)) @@ -43,28 +43,28 @@ func convertPythonLibTestCaseToBp2build(tc pythonLibBp2BuildTestCase) bp2buildTe for k, v := range tc.filesystem { filesystemCopy[k] = v } - return bp2buildTestCase{ - description: tc.description, - filesystem: filesystemCopy, - blueprint: tc.blueprint, - expectedBazelTargets: bp2BuildTargets, - dir: tc.dir, - expectedErr: tc.expectedError, + return Bp2buildTestCase{ + Description: tc.description, + Filesystem: filesystemCopy, + Blueprint: tc.blueprint, + ExpectedBazelTargets: bp2BuildTargets, + Dir: tc.dir, + ExpectedErr: tc.expectedError, } } func runPythonLibraryTestCase(t *testing.T, tc pythonLibBp2BuildTestCase) { t.Helper() testCase := convertPythonLibTestCaseToBp2build(tc) - testCase.description = fmt.Sprintf(testCase.description, "python_library") - testCase.blueprint = fmt.Sprintf(testCase.blueprint, "python_library") - for name, contents := range testCase.filesystem { + testCase.Description = fmt.Sprintf(testCase.Description, "python_library") + testCase.Blueprint = fmt.Sprintf(testCase.Blueprint, "python_library") + for name, contents := range testCase.Filesystem { if strings.HasSuffix(name, "Android.bp") { - testCase.filesystem[name] = fmt.Sprintf(contents, "python_library") + testCase.Filesystem[name] = fmt.Sprintf(contents, "python_library") } } - testCase.moduleTypeUnderTest = "python_library" - testCase.moduleTypeUnderTestFactory = python.PythonLibraryFactory + testCase.ModuleTypeUnderTest = "python_library" + testCase.ModuleTypeUnderTestFactory = python.PythonLibraryFactory runBp2BuildTestCaseSimple(t, testCase) } @@ -72,16 +72,16 @@ func runPythonLibraryTestCase(t *testing.T, tc pythonLibBp2BuildTestCase) { func runPythonLibraryHostTestCase(t *testing.T, tc pythonLibBp2BuildTestCase) { t.Helper() testCase := convertPythonLibTestCaseToBp2build_Host(tc) - testCase.description = fmt.Sprintf(testCase.description, "python_library_host") - testCase.blueprint = fmt.Sprintf(testCase.blueprint, "python_library_host") - for name, contents := range testCase.filesystem { + testCase.Description = fmt.Sprintf(testCase.Description, "python_library_host") + testCase.Blueprint = fmt.Sprintf(testCase.Blueprint, "python_library_host") + for name, contents := range testCase.Filesystem { if strings.HasSuffix(name, "Android.bp") { - testCase.filesystem[name] = fmt.Sprintf(contents, "python_library_host") + testCase.Filesystem[name] = fmt.Sprintf(contents, "python_library_host") } } - testCase.moduleTypeUnderTest = "python_library_host" - testCase.moduleTypeUnderTestFactory = python.PythonLibraryHostFactory - runBp2BuildTestCase(t, func(ctx android.RegistrationContext) { + testCase.ModuleTypeUnderTest = "python_library_host" + testCase.ModuleTypeUnderTestFactory = python.PythonLibraryHostFactory + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { ctx.RegisterModuleType("python_library", python.PythonLibraryFactory) }, testCase) @@ -121,7 +121,7 @@ func TestSimplePythonLib(t *testing.T) { { typ: "py_library", name: "foo", - attrs: attrNameToString{ + attrs: AttrNameToString{ "data": `["files/data.txt"]`, "deps": `[":bar"]`, "srcs": `[ @@ -155,7 +155,7 @@ func TestSimplePythonLib(t *testing.T) { { typ: "py_library", name: "foo", - attrs: attrNameToString{ + attrs: AttrNameToString{ "srcs": `["a.py"]`, "srcs_version": `"PY2"`, "imports": `["."]`, @@ -183,7 +183,7 @@ func TestSimplePythonLib(t *testing.T) { { typ: "py_library", name: "foo", - attrs: attrNameToString{ + attrs: AttrNameToString{ "srcs": `["a.py"]`, "srcs_version": `"PY3"`, "imports": `["."]`, @@ -212,7 +212,7 @@ func TestSimplePythonLib(t *testing.T) { // srcs_version is PY2ANDPY3 by default. typ: "py_library", name: "foo", - attrs: attrNameToString{ + attrs: AttrNameToString{ "srcs": `["a.py"]`, "imports": `["."]`, }, @@ -238,7 +238,7 @@ func TestSimplePythonLib(t *testing.T) { // srcs_version is PY2ANDPY3 by default. typ: "py_library", name: "foo", - attrs: attrNameToString{ + attrs: AttrNameToString{ "srcs": `["a.py"]`, "imports": `["../.."]`, "srcs_version": `"PY3"`, @@ -292,7 +292,7 @@ func TestPythonArchVariance(t *testing.T) { { typ: "py_library", name: "foo", - attrs: attrNameToString{ + attrs: AttrNameToString{ "srcs": `select({ "//build/bazel/platforms/arch:arm": ["arm.py"], "//build/bazel/platforms/arch:x86": ["x86.py"], @@ -324,21 +324,21 @@ func TestPythonLibraryWithProtobufs(t *testing.T) { { typ: "proto_library", name: "foo_proto", - attrs: attrNameToString{ + attrs: AttrNameToString{ "srcs": `["dir/myproto.proto"]`, }, }, { typ: "py_proto_library", name: "foo_py_proto", - attrs: attrNameToString{ + attrs: AttrNameToString{ "deps": `[":foo_proto"]`, }, }, { typ: "py_library", name: "foo", - attrs: attrNameToString{ + attrs: AttrNameToString{ "srcs": `["dir/mylib.py"]`, "srcs_version": `"PY3"`, "imports": `["."]`, diff --git a/bp2build/sh_conversion_test.go b/bp2build/sh_conversion_test.go index ac890878b..d8f701d94 100644 --- a/bp2build/sh_conversion_test.go +++ b/bp2build/sh_conversion_test.go @@ -48,25 +48,25 @@ func TestShBinaryLoadStatement(t *testing.T) { } } -func runShBinaryTestCase(t *testing.T, tc bp2buildTestCase) { +func runShBinaryTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() - runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc) + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc) } func TestShBinarySimple(t *testing.T) { - runShBinaryTestCase(t, bp2buildTestCase{ - description: "sh_binary test", - moduleTypeUnderTest: "sh_binary", - moduleTypeUnderTestFactory: sh.ShBinaryFactory, - blueprint: `sh_binary { + runShBinaryTestCase(t, Bp2buildTestCase{ + Description: "sh_binary test", + ModuleTypeUnderTest: "sh_binary", + ModuleTypeUnderTestFactory: sh.ShBinaryFactory, + Blueprint: `sh_binary { name: "foo", src: "foo.sh", filename: "foo.exe", sub_dir: "sub", bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("sh_binary", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("sh_binary", "foo", AttrNameToString{ "srcs": `["foo.sh"]`, "filename": `"foo.exe"`, "sub_dir": `"sub"`, @@ -75,17 +75,17 @@ func TestShBinarySimple(t *testing.T) { } func TestShBinaryDefaults(t *testing.T) { - runShBinaryTestCase(t, bp2buildTestCase{ - description: "sh_binary test", - moduleTypeUnderTest: "sh_binary", - moduleTypeUnderTestFactory: sh.ShBinaryFactory, - blueprint: `sh_binary { + runShBinaryTestCase(t, Bp2buildTestCase{ + Description: "sh_binary test", + ModuleTypeUnderTest: "sh_binary", + ModuleTypeUnderTestFactory: sh.ShBinaryFactory, + Blueprint: `sh_binary { name: "foo", src: "foo.sh", bazel_module: { bp2build_available: true }, }`, - expectedBazelTargets: []string{ - makeBazelTarget("sh_binary", "foo", attrNameToString{ + ExpectedBazelTargets: []string{ + makeBazelTarget("sh_binary", "foo", AttrNameToString{ "srcs": `["foo.sh"]`, })}, }) diff --git a/bp2build/soong_config_module_type_conversion_test.go b/bp2build/soong_config_module_type_conversion_test.go index 8460caeb3..a94b2b9f1 100644 --- a/bp2build/soong_config_module_type_conversion_test.go +++ b/bp2build/soong_config_module_type_conversion_test.go @@ -20,9 +20,9 @@ import ( "testing" ) -func runSoongConfigModuleTypeTest(t *testing.T, tc bp2buildTestCase) { +func runSoongConfigModuleTypeTest(t *testing.T, tc Bp2buildTestCase) { t.Helper() - runBp2BuildTestCase(t, registerSoongConfigModuleTypes, tc) + RunBp2BuildTestCase(t, registerSoongConfigModuleTypes, tc) } func registerSoongConfigModuleTypes(ctx android.RegistrationContext) { @@ -61,12 +61,12 @@ custom_cc_library_static { } ` - runSoongConfigModuleTypeTest(t, bp2buildTestCase{ - description: "soong config variables - soong_config_module_type is supported in bp2build", - moduleTypeUnderTest: "cc_library_static", - moduleTypeUnderTestFactory: cc.LibraryStaticFactory, - blueprint: bp, - expectedBazelTargets: []string{`cc_library_static( + runSoongConfigModuleTypeTest(t, Bp2buildTestCase{ + Description: "soong config variables - soong_config_module_type is supported in bp2build", + ModuleTypeUnderTest: "cc_library_static", + ModuleTypeUnderTestFactory: cc.LibraryStaticFactory, + Blueprint: bp, + ExpectedBazelTargets: []string{`cc_library_static( name = "foo", copts = select({ "//build/bazel/product_variables:acme__feature1": ["-DFEATURE1"], @@ -107,15 +107,15 @@ custom_cc_library_static { } ` - runSoongConfigModuleTypeTest(t, bp2buildTestCase{ - description: "soong config variables - soong_config_module_type_import is supported in bp2build", - moduleTypeUnderTest: "cc_library_static", - moduleTypeUnderTestFactory: cc.LibraryStaticFactory, - filesystem: map[string]string{ + runSoongConfigModuleTypeTest(t, Bp2buildTestCase{ + Description: "soong config variables - soong_config_module_type_import is supported in bp2build", + ModuleTypeUnderTest: "cc_library_static", + ModuleTypeUnderTestFactory: cc.LibraryStaticFactory, + Filesystem: map[string]string{ "foo/bar/SoongConfig.bp": configBp, }, - blueprint: bp, - expectedBazelTargets: []string{`cc_library_static( + Blueprint: bp, + ExpectedBazelTargets: []string{`cc_library_static( name = "foo", copts = select({ "//build/bazel/product_variables:acme__feature1": ["-DFEATURE1"], @@ -161,12 +161,12 @@ custom_cc_library_static { } ` - runSoongConfigModuleTypeTest(t, bp2buildTestCase{ - description: "soong config variables - generates selects for string vars", - moduleTypeUnderTest: "cc_library_static", - moduleTypeUnderTestFactory: cc.LibraryStaticFactory, - blueprint: bp, - expectedBazelTargets: []string{`cc_library_static( + runSoongConfigModuleTypeTest(t, Bp2buildTestCase{ + Description: "soong config variables - generates selects for string vars", + ModuleTypeUnderTest: "cc_library_static", + ModuleTypeUnderTestFactory: cc.LibraryStaticFactory, + Blueprint: bp, + ExpectedBazelTargets: []string{`cc_library_static( name = "foo", copts = select({ "//build/bazel/product_variables:acme__board__soc_a": ["-DSOC_A"], @@ -232,12 +232,12 @@ custom_cc_library_static { }, }` - runSoongConfigModuleTypeTest(t, bp2buildTestCase{ - description: "soong config variables - generates selects for multiple variable types", - moduleTypeUnderTest: "cc_library_static", - moduleTypeUnderTestFactory: cc.LibraryStaticFactory, - blueprint: bp, - expectedBazelTargets: []string{`cc_library_static( + runSoongConfigModuleTypeTest(t, Bp2buildTestCase{ + Description: "soong config variables - generates selects for multiple variable types", + ModuleTypeUnderTest: "cc_library_static", + ModuleTypeUnderTestFactory: cc.LibraryStaticFactory, + Blueprint: bp, + ExpectedBazelTargets: []string{`cc_library_static( name = "foo", copts = select({ "//build/bazel/product_variables:acme__board__soc_a": ["-DSOC_A"], @@ -298,15 +298,15 @@ cc_library_static { name: "soc_b_dep", bazel_module: { bp2build_available: false cc_library_static { name: "soc_default_static_dep", bazel_module: { bp2build_available: false } } ` - runSoongConfigModuleTypeTest(t, bp2buildTestCase{ - description: "soong config variables - generates selects for label list attributes", - moduleTypeUnderTest: "cc_library_static", - moduleTypeUnderTestFactory: cc.LibraryStaticFactory, - blueprint: bp, - filesystem: map[string]string{ + runSoongConfigModuleTypeTest(t, Bp2buildTestCase{ + Description: "soong config variables - generates selects for label list attributes", + ModuleTypeUnderTest: "cc_library_static", + ModuleTypeUnderTestFactory: cc.LibraryStaticFactory, + Blueprint: bp, + Filesystem: map[string]string{ "foo/bar/Android.bp": otherDeps, }, - expectedBazelTargets: []string{`cc_library_static( + ExpectedBazelTargets: []string{`cc_library_static( name = "foo", copts = select({ "//build/bazel/product_variables:acme__board__soc_a": ["-DSOC_A"], @@ -365,12 +365,12 @@ cc_library_static { } ` - runSoongConfigModuleTypeTest(t, bp2buildTestCase{ - description: "soong config variables - defaults with a single namespace", - moduleTypeUnderTest: "cc_library_static", - moduleTypeUnderTestFactory: cc.LibraryStaticFactory, - blueprint: bp, - expectedBazelTargets: []string{`cc_library_static( + runSoongConfigModuleTypeTest(t, Bp2buildTestCase{ + Description: "soong config variables - defaults with a single namespace", + ModuleTypeUnderTest: "cc_library_static", + ModuleTypeUnderTestFactory: cc.LibraryStaticFactory, + Blueprint: bp, + ExpectedBazelTargets: []string{`cc_library_static( name = "lib", copts = select({ "//build/bazel/product_variables:vendor_foo__feature": [ @@ -446,12 +446,12 @@ cc_library_static { } ` - runSoongConfigModuleTypeTest(t, bp2buildTestCase{ - description: "soong config variables - multiple defaults with a single namespace", - moduleTypeUnderTest: "cc_library_static", - moduleTypeUnderTestFactory: cc.LibraryStaticFactory, - blueprint: bp, - expectedBazelTargets: []string{`cc_library_static( + runSoongConfigModuleTypeTest(t, Bp2buildTestCase{ + Description: "soong config variables - multiple defaults with a single namespace", + ModuleTypeUnderTest: "cc_library_static", + ModuleTypeUnderTestFactory: cc.LibraryStaticFactory, + Blueprint: bp, + ExpectedBazelTargets: []string{`cc_library_static( name = "lib", asflags = select({ "//build/bazel/product_variables:acme__feature": ["-asflag_bar"], @@ -562,12 +562,12 @@ cc_library_static { } ` - runSoongConfigModuleTypeTest(t, bp2buildTestCase{ - description: "soong config variables - defaults with multiple namespaces", - moduleTypeUnderTest: "cc_library_static", - moduleTypeUnderTestFactory: cc.LibraryStaticFactory, - blueprint: bp, - expectedBazelTargets: []string{`cc_library_static( + runSoongConfigModuleTypeTest(t, Bp2buildTestCase{ + Description: "soong config variables - defaults with multiple namespaces", + ModuleTypeUnderTest: "cc_library_static", + ModuleTypeUnderTestFactory: cc.LibraryStaticFactory, + Blueprint: bp, + ExpectedBazelTargets: []string{`cc_library_static( name = "lib", copts = select({ "//build/bazel/product_variables:vendor_bar__feature": ["-DVENDOR_BAR_FEATURE"], @@ -653,15 +653,15 @@ cc_library { name: "lib_b", bazel_module: { bp2build_available: false } } cc_library { name: "lib_default", bazel_module: { bp2build_available: false } } ` - runSoongConfigModuleTypeTest(t, bp2buildTestCase{ - description: "soong config variables - generates selects for library_linking_strategy", - moduleTypeUnderTest: "cc_binary", - moduleTypeUnderTestFactory: cc.BinaryFactory, - blueprint: bp, - filesystem: map[string]string{ + runSoongConfigModuleTypeTest(t, Bp2buildTestCase{ + Description: "soong config variables - generates selects for library_linking_strategy", + ModuleTypeUnderTest: "cc_binary", + ModuleTypeUnderTestFactory: cc.BinaryFactory, + Blueprint: bp, + Filesystem: map[string]string{ "foo/bar/Android.bp": otherDeps, }, - expectedBazelTargets: []string{`cc_binary( + ExpectedBazelTargets: []string{`cc_binary( name = "library_linking_strategy_sample_binary", deps = select({ "//build/bazel/product_variables:android__library_linking_strategy__prefer_static": [ @@ -734,15 +734,15 @@ cc_library { name: "lib_a", bazel_module: { bp2build_available: false } } cc_library { name: "lib_b", bazel_module: { bp2build_available: false } } ` - runSoongConfigModuleTypeTest(t, bp2buildTestCase{ - description: "soong config variables - generates selects for library_linking_strategy", - moduleTypeUnderTest: "cc_binary", - moduleTypeUnderTestFactory: cc.BinaryFactory, - blueprint: bp, - filesystem: map[string]string{ + runSoongConfigModuleTypeTest(t, Bp2buildTestCase{ + Description: "soong config variables - generates selects for library_linking_strategy", + ModuleTypeUnderTest: "cc_binary", + ModuleTypeUnderTestFactory: cc.BinaryFactory, + Blueprint: bp, + Filesystem: map[string]string{ "foo/bar/Android.bp": otherDeps, }, - expectedBazelTargets: []string{`cc_binary( + ExpectedBazelTargets: []string{`cc_binary( name = "library_linking_strategy_sample_binary", deps = select({ "//build/bazel/product_variables:android__library_linking_strategy__prefer_static": [ @@ -822,15 +822,15 @@ cc_library { name: "lib_b", bazel_module: { bp2build_available: false } } cc_library { name: "lib_default", bazel_module: { bp2build_available: false } } ` - runSoongConfigModuleTypeTest(t, bp2buildTestCase{ - description: "soong config variables - generates selects for library_linking_strategy", - moduleTypeUnderTest: "cc_binary", - moduleTypeUnderTestFactory: cc.BinaryFactory, - blueprint: bp, - filesystem: map[string]string{ + runSoongConfigModuleTypeTest(t, Bp2buildTestCase{ + Description: "soong config variables - generates selects for library_linking_strategy", + ModuleTypeUnderTest: "cc_binary", + ModuleTypeUnderTestFactory: cc.BinaryFactory, + Blueprint: bp, + Filesystem: map[string]string{ "foo/bar/Android.bp": otherDeps, }, - expectedBazelTargets: []string{`cc_binary( + ExpectedBazelTargets: []string{`cc_binary( name = "alphabet_binary", deps = select({ "//build/bazel/product_variables:android__alphabet__a": [], @@ -888,13 +888,13 @@ cc_binary { }, }` - runSoongConfigModuleTypeTest(t, bp2buildTestCase{ - description: "soong config variables - generates selects for library_linking_strategy", - moduleTypeUnderTest: "cc_binary", - moduleTypeUnderTestFactory: cc.BinaryFactory, - blueprint: bp, - filesystem: map[string]string{}, - expectedBazelTargets: []string{`cc_binary( + runSoongConfigModuleTypeTest(t, Bp2buildTestCase{ + Description: "soong config variables - generates selects for library_linking_strategy", + ModuleTypeUnderTest: "cc_binary", + ModuleTypeUnderTestFactory: cc.BinaryFactory, + Blueprint: bp, + Filesystem: map[string]string{}, + ExpectedBazelTargets: []string{`cc_binary( name = "alphabet_binary", local_includes = ["."], srcs = ["main.cc"], @@ -941,13 +941,13 @@ cc_binary { enabled: false, }` - runSoongConfigModuleTypeTest(t, bp2buildTestCase{ - description: "soong config variables - generates selects for library_linking_strategy", - moduleTypeUnderTest: "cc_binary", - moduleTypeUnderTestFactory: cc.BinaryFactory, - blueprint: bp, - filesystem: map[string]string{}, - expectedBazelTargets: []string{`cc_binary( + runSoongConfigModuleTypeTest(t, Bp2buildTestCase{ + Description: "soong config variables - generates selects for library_linking_strategy", + ModuleTypeUnderTest: "cc_binary", + ModuleTypeUnderTestFactory: cc.BinaryFactory, + Blueprint: bp, + Filesystem: map[string]string{}, + ExpectedBazelTargets: []string{`cc_binary( name = "alphabet_binary", local_includes = ["."], srcs = ["main.cc"], @@ -985,13 +985,13 @@ cc_binary { defaults: ["alphabet_sample_cc_defaults"], }` - runSoongConfigModuleTypeTest(t, bp2buildTestCase{ - description: "soong config variables - generates selects for library_linking_strategy", - moduleTypeUnderTest: "cc_binary", - moduleTypeUnderTestFactory: cc.BinaryFactory, - blueprint: bp, - filesystem: map[string]string{}, - expectedBazelTargets: []string{`cc_binary( + runSoongConfigModuleTypeTest(t, Bp2buildTestCase{ + Description: "soong config variables - generates selects for library_linking_strategy", + ModuleTypeUnderTest: "cc_binary", + ModuleTypeUnderTestFactory: cc.BinaryFactory, + Blueprint: bp, + Filesystem: map[string]string{}, + ExpectedBazelTargets: []string{`cc_binary( name = "alphabet_binary", local_includes = ["."], srcs = ["main.cc"], diff --git a/bp2build/symlink_forest.go b/bp2build/symlink_forest.go index 818d7aece..78e7b0e75 100644 --- a/bp2build/symlink_forest.go +++ b/bp2build/symlink_forest.go @@ -1,6 +1,7 @@ package bp2build import ( + "android/soong/android" "fmt" "io/ioutil" "os" @@ -21,7 +22,7 @@ type node struct { children map[string]*node } -// Ensures that the a node for the given path exists in the tree and returns it. +// Ensures that the node for the given path exists in the tree and returns it. func ensureNodeExists(root *node, path string) *node { if path == "" { return root @@ -114,7 +115,7 @@ func isDir(path string, fi os.FileInfo) bool { // contain every file in buildFilesDir and srcDir excluding the files in // exclude. Collects every directory encountered during the traversal of srcDir // into acc. -func plantSymlinkForestRecursive(topdir string, forestDir string, buildFilesDir string, srcDir string, exclude *node, acc *[]string, okay *bool) { +func plantSymlinkForestRecursive(cfg android.Config, topdir string, forestDir string, buildFilesDir string, srcDir string, exclude *node, acc *[]string, okay *bool) { if exclude != nil && exclude.excluded { // This directory is not needed, bail out return @@ -125,11 +126,11 @@ func plantSymlinkForestRecursive(topdir string, forestDir string, buildFilesDir buildFilesMap := readdirToMap(shared.JoinPath(topdir, buildFilesDir)) allEntries := make(map[string]bool) - for n, _ := range srcDirMap { + for n := range srcDirMap { allEntries[n] = true } - for n, _ := range buildFilesMap { + for n := range buildFilesMap { allEntries[n] = true } @@ -139,7 +140,7 @@ func plantSymlinkForestRecursive(topdir string, forestDir string, buildFilesDir os.Exit(1) } - for f, _ := range allEntries { + for f := range allEntries { if f[0] == '.' { continue // Ignore dotfiles } @@ -179,7 +180,7 @@ func plantSymlinkForestRecursive(topdir string, forestDir string, buildFilesDir if bDir && excludeChild != nil { // Not in the source tree, but we have to exclude something from under // this subtree, so descend - plantSymlinkForestRecursive(topdir, forestChild, buildFilesChild, srcChild, excludeChild, acc, okay) + plantSymlinkForestRecursive(cfg, topdir, forestChild, buildFilesChild, srcChild, excludeChild, acc, okay) } else { // Not in the source tree, symlink BUILD file symlinkIntoForest(topdir, forestChild, buildFilesChild) @@ -188,19 +189,21 @@ func plantSymlinkForestRecursive(topdir string, forestDir string, buildFilesDir if sDir && excludeChild != nil { // Not in the build file tree, but we have to exclude something from // under this subtree, so descend - plantSymlinkForestRecursive(topdir, forestChild, buildFilesChild, srcChild, excludeChild, acc, okay) + plantSymlinkForestRecursive(cfg, topdir, forestChild, buildFilesChild, srcChild, excludeChild, acc, okay) } else { // Not in the build file tree, symlink source tree, carry on symlinkIntoForest(topdir, forestChild, srcChild) } } else if sDir && bDir { // Both are directories. Descend. - plantSymlinkForestRecursive(topdir, forestChild, buildFilesChild, srcChild, excludeChild, acc, okay) + plantSymlinkForestRecursive(cfg, topdir, forestChild, buildFilesChild, srcChild, excludeChild, acc, okay) } else if !sDir && !bDir { // Neither is a directory. Prioritize BUILD files generated by bp2build // over any BUILD file imported into external/. - fmt.Fprintf(os.Stderr, "Both '%s' and '%s' exist, symlinking the former to '%s'\n", - buildFilesChild, srcChild, forestChild) + if cfg.IsEnvTrue("BP2BUILD_VERBOSE") { + fmt.Fprintf(os.Stderr, "Both '%s' and '%s' exist, symlinking the former to '%s'\n", + buildFilesChild, srcChild, forestChild) + } symlinkIntoForest(topdir, forestChild, buildFilesChild) } else { // Both exist and one is a file. This is an error. @@ -216,12 +219,12 @@ func plantSymlinkForestRecursive(topdir string, forestDir string, buildFilesDir // "srcDir" while excluding paths listed in "exclude". Returns the set of paths // under srcDir on which readdir() had to be called to produce the symlink // forest. -func PlantSymlinkForest(topdir string, forest string, buildFiles string, srcDir string, exclude []string) []string { +func PlantSymlinkForest(cfg android.Config, topdir string, forest string, buildFiles string, srcDir string, exclude []string) []string { deps := make([]string, 0) os.RemoveAll(shared.JoinPath(topdir, forest)) excludeTree := treeFromExcludePathList(exclude) okay := true - plantSymlinkForestRecursive(topdir, forest, buildFiles, srcDir, excludeTree, &deps, &okay) + plantSymlinkForestRecursive(cfg, topdir, forest, buildFiles, srcDir, excludeTree, &deps, &okay) if !okay { os.Exit(1) } diff --git a/bp2build/testing.go b/bp2build/testing.go index 580bac4a5..3ee5096da 100644 --- a/bp2build/testing.go +++ b/bp2build/testing.go @@ -53,16 +53,16 @@ func checkError(t *testing.T, errs []error, expectedErr error) bool { return false } -func errored(t *testing.T, tc bp2buildTestCase, errs []error) bool { +func errored(t *testing.T, tc Bp2buildTestCase, errs []error) bool { t.Helper() - if tc.expectedErr != nil { + if tc.ExpectedErr != nil { // Rely on checkErrors, as this test case is expected to have an error. return false } if len(errs) > 0 { for _, err := range errs { - t.Errorf("%s: %s", tc.description, err) + t.Errorf("%s: %s", tc.Description, err) } return true } @@ -71,42 +71,42 @@ func errored(t *testing.T, tc bp2buildTestCase, errs []error) bool { return false } -func runBp2BuildTestCaseSimple(t *testing.T, tc bp2buildTestCase) { +func runBp2BuildTestCaseSimple(t *testing.T, tc Bp2buildTestCase) { t.Helper() - runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc) + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc) } -type bp2buildTestCase struct { - description string - moduleTypeUnderTest string - moduleTypeUnderTestFactory android.ModuleFactory - blueprint string - expectedBazelTargets []string - filesystem map[string]string - dir string +type Bp2buildTestCase struct { + Description string + ModuleTypeUnderTest string + ModuleTypeUnderTestFactory android.ModuleFactory + Blueprint string + ExpectedBazelTargets []string + Filesystem map[string]string + Dir string // An error with a string contained within the string of the expected error - expectedErr error - unconvertedDepsMode unconvertedDepsMode + ExpectedErr error + UnconvertedDepsMode unconvertedDepsMode } -func runBp2BuildTestCase(t *testing.T, registerModuleTypes func(ctx android.RegistrationContext), tc bp2buildTestCase) { +func RunBp2BuildTestCase(t *testing.T, registerModuleTypes func(ctx android.RegistrationContext), tc Bp2buildTestCase) { t.Helper() dir := "." filesystem := make(map[string][]byte) toParse := []string{ "Android.bp", } - for f, content := range tc.filesystem { + for f, content := range tc.Filesystem { if strings.HasSuffix(f, "Android.bp") { toParse = append(toParse, f) } filesystem[f] = []byte(content) } - config := android.TestConfig(buildDir, nil, tc.blueprint, filesystem) + config := android.TestConfig(buildDir, nil, tc.Blueprint, filesystem) ctx := android.NewTestContext(config) registerModuleTypes(ctx) - ctx.RegisterModuleType(tc.moduleTypeUnderTest, tc.moduleTypeUnderTestFactory) + ctx.RegisterModuleType(tc.ModuleTypeUnderTest, tc.ModuleTypeUnderTestFactory) ctx.RegisterBp2BuildConfig(bp2buildConfig) ctx.RegisterForBazelConversion() @@ -120,35 +120,35 @@ func runBp2BuildTestCase(t *testing.T, registerModuleTypes func(ctx android.Regi } parseAndResolveErrs := append(parseErrs, resolveDepsErrs...) - if tc.expectedErr != nil && checkError(t, parseAndResolveErrs, tc.expectedErr) { + if tc.ExpectedErr != nil && checkError(t, parseAndResolveErrs, tc.ExpectedErr) { return } checkDir := dir - if tc.dir != "" { - checkDir = tc.dir + if tc.Dir != "" { + checkDir = tc.Dir } codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) - codegenCtx.unconvertedDepMode = tc.unconvertedDepsMode + codegenCtx.unconvertedDepMode = tc.UnconvertedDepsMode bazelTargets, errs := generateBazelTargetsForDir(codegenCtx, checkDir) - if tc.expectedErr != nil { - if checkError(t, errs, tc.expectedErr) { + if tc.ExpectedErr != nil { + if checkError(t, errs, tc.ExpectedErr) { return } else { - t.Errorf("Expected error: %q, got: %q and %q", tc.expectedErr, errs, parseAndResolveErrs) + t.Errorf("Expected error: %q, got: %q and %q", tc.ExpectedErr, errs, parseAndResolveErrs) } } else { android.FailIfErrored(t, errs) } - if actualCount, expectedCount := len(bazelTargets), len(tc.expectedBazelTargets); actualCount != expectedCount { + if actualCount, expectedCount := len(bazelTargets), len(tc.ExpectedBazelTargets); actualCount != expectedCount { t.Errorf("%s: Expected %d bazel target (%s), got `%d`` (%s)", - tc.description, expectedCount, tc.expectedBazelTargets, actualCount, bazelTargets) + tc.Description, expectedCount, tc.ExpectedBazelTargets, actualCount, bazelTargets) } else { for i, target := range bazelTargets { - if w, g := tc.expectedBazelTargets[i], target.content; w != g { + if w, g := tc.ExpectedBazelTargets[i], target.content; w != g { t.Errorf( "%s: Expected generated Bazel target to be `%s`, got `%s`", - tc.description, w, g) + tc.Description, w, g) } } } @@ -391,10 +391,10 @@ func simpleModuleDoNotConvertBp2build(typ, name string) string { }`, typ, name) } -type attrNameToString map[string]string +type AttrNameToString map[string]string -func (a attrNameToString) clone() attrNameToString { - newAttrs := make(attrNameToString, len(a)) +func (a AttrNameToString) clone() AttrNameToString { + newAttrs := make(AttrNameToString, len(a)) for k, v := range a { newAttrs[k] = v } @@ -403,7 +403,7 @@ func (a attrNameToString) clone() attrNameToString { // 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 { +func makeBazelTargetHostOrDevice(typ, name string, attrs AttrNameToString, hod android.HostOrDeviceSupported) string { if _, ok := attrs["target_compatible_with"]; !ok { switch hod { case android.HostSupported: @@ -426,15 +426,15 @@ func makeBazelTargetHostOrDevice(typ, name string, attrs attrNameToString, hod a )`, typ, strings.Join(attrStrings, "\n")) } -// makeBazelTargetNoRestrictions returns bazel target build file definition that does not add a +// 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 { +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 { +func makeBazelTarget(typ, name string, attrs AttrNameToString) string { return makeBazelTargetHostOrDevice(typ, name, attrs, android.DeviceSupported) } diff --git a/bpf/bpf.go b/bpf/bpf.go index 14b2d84c5..5d2533fc2 100644 --- a/bpf/bpf.go +++ b/bpf/bpf.go @@ -17,6 +17,7 @@ package bpf import ( "fmt" "io" + "path/filepath" "strings" "android/soong/android" @@ -154,6 +155,9 @@ func (bpf *bpf) GenerateAndroidBuildActions(ctx android.ModuleContext) { srcs := android.PathsForModuleSrc(ctx, bpf.properties.Srcs) for _, src := range srcs { + if strings.ContainsRune(filepath.Base(src.String()), '_') { + ctx.ModuleErrorf("invalid character '_' in source name") + } obj := android.ObjPathWithExt(ctx, "unstripped", src, "o") ctx.Build(pctx, android.BuildParams{ diff --git a/bpf/bpf_test.go b/bpf/bpf_test.go index 51fbc15e1..6e3909680 100644 --- a/bpf/bpf_test.go +++ b/bpf/bpf_test.go @@ -30,8 +30,9 @@ var prepareForBpfTest = android.GroupFixturePreparers( cc.PrepareForTestWithCcDefaultModules, android.FixtureMergeMockFs( map[string][]byte{ - "bpf.c": nil, - "BpfTest.cpp": nil, + "bpf.c": nil, + "bpf_invalid_name.c": nil, + "BpfTest.cpp": nil, }, ), PrepareForTestWithBpf, @@ -58,3 +59,15 @@ func TestBpfDataDependency(t *testing.T) { // value is not available for testing from this package. // TODO(jungjw): Add a check for data or move this test to the cc package. } + +func TestBpfSourceName(t *testing.T) { + bp := ` + bpf { + name: "bpf_invalid_name.o", + srcs: ["bpf_invalid_name.c"], + } + ` + prepareForBpfTest.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern( + `\QAndroid.bp:2:3: module "bpf_invalid_name.o" variant "android_common": invalid character '_' in source name\E`)). + RunTestWithBp(t, bp) +} diff --git a/build_kzip.bash b/build_kzip.bash index 6219021cf..fa616b94d 100755 --- a/build_kzip.bash +++ b/build_kzip.bash @@ -44,14 +44,18 @@ declare -r go_extractor=$(realpath prebuilts/build-tools/linux-x86/bin/go_extrac declare -r go_root=$(realpath prebuilts/go/linux-x86) declare -r source_root=$PWD -# TODO(asmundak): Until b/182183061 is fixed, default corpus has to be specified -# in the rules file. Generate this file on the fly with corpus value set from the -# environment variable. -for dir in blueprint soong; do - (cd "build/$dir"; +# For the Go code, we invoke the extractor directly. The two caveats are that +# the extractor's rewrite rules are generated on the fly as they depend on the XREF_CORPUS +# value, and that the name of the kzip file is derived from the directory name +# by replacing '/' with '_'. +declare -ar go_modules=(build/blueprint build/soong + build/make/tools/canoninja build/make/tools/compliance build/make/tools/rbcrun) +for dir in "${go_modules[@]}"; do + (cd "$dir"; + outfile=$(echo "$dir" | sed -r 's|/|_|g;s|(.*)|\1.go.kzip|'); KYTHE_ROOT_DIRECTORY="${source_root}" "$go_extractor" --goroot="$go_root" \ --rules=<(printf '[{"pattern": "(.*)","vname": {"path": "@1@", "corpus":"%s"}}]' "${XREF_CORPUS}") \ - --canonicalize_package_corpus --output "${abspath_out}/soong/build_${dir}.go.kzip" ./... + --canonicalize_package_corpus --output "${abspath_out}/soong/$outfile" ./... ) done diff --git a/cc/bp2build.go b/cc/bp2build.go index fa30d096b..61a55ee69 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -20,6 +20,7 @@ import ( "android/soong/android" "android/soong/bazel" + "android/soong/cc/config" "github.com/google/blueprint" @@ -29,6 +30,7 @@ import ( const ( cSrcPartition = "c" asSrcPartition = "as" + asmSrcPartition = "asm" lSrcPartition = "l" llSrcPartition = "ll" cppSrcPartition = "cpp" @@ -80,6 +82,7 @@ func groupSrcsByExtension(ctx android.BazelConversionPathContext, srcs bazel.Lab protoSrcPartition: android.ProtoSrcLabelPartition, cSrcPartition: bazel.LabelPartition{Extensions: []string{".c"}, LabelMapper: addSuffixForFilegroup("_c_srcs")}, asSrcPartition: bazel.LabelPartition{Extensions: []string{".s", ".S"}, LabelMapper: addSuffixForFilegroup("_as_srcs")}, + asmSrcPartition: bazel.LabelPartition{Extensions: []string{".asm"}}, // TODO(http://b/231968910): If there is ever a filegroup target that // contains .l or .ll files we will need to find a way to add a // LabelMapper for these that identifies these filegroups and @@ -156,7 +159,7 @@ func bp2buildParseStaticOrSharedProps(ctx android.BazelConversionPathContext, mo attrs := staticOrSharedAttributes{} setAttrs := func(axis bazel.ConfigurationAxis, config string, props StaticOrSharedProperties) { - attrs.Copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags, filterOutStdFlag)) + attrs.Copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags, true, filterOutStdFlag)) attrs.Srcs.SetSelectValue(axis, config, android.BazelLabelForModuleSrc(ctx, props.Srcs)) attrs.System_dynamic_deps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, props.System_shared_libs)) @@ -288,6 +291,7 @@ type compilerAttributes struct { // Assembly options and sources asFlags bazel.StringListAttribute asSrcs bazel.LabelListAttribute + asmSrcs bazel.LabelListAttribute // C options and sources conlyFlags bazel.StringListAttribute cSrcs bazel.LabelListAttribute @@ -326,16 +330,39 @@ func filterOutStdFlag(flag string) bool { return strings.HasPrefix(flag, "-std=") } -func parseCommandLineFlags(soongFlags []string, filterOut filterOutFn) []string { +func filterOutClangUnknownCflags(flag string) bool { + for _, f := range config.ClangUnknownCflags { + if f == flag { + return true + } + } + return false +} + +func parseCommandLineFlags(soongFlags []string, noCoptsTokenization bool, filterOut ...filterOutFn) []string { var result []string for _, flag := range soongFlags { - if filterOut != nil && filterOut(flag) { + skipFlag := false + for _, filter := range filterOut { + if filter != nil && filter(flag) { + skipFlag = true + } + } + if skipFlag { continue } // Soong's cflags can contain spaces, like `-include header.h`. For // Bazel's copts, split them up to be compatible with the // no_copts_tokenization feature. - result = append(result, strings.Split(flag, " ")...) + if noCoptsTokenization { + result = append(result, strings.Split(flag, " ")...) + } else { + // Soong's Version Script and Dynamic List Properties are added as flags + // to Bazel's linkopts using "($location label)" syntax. + // Splitting on spaces would separate this into two different flags + // "($ location" and "label)" + result = append(result, flag) + } } return result } @@ -362,10 +389,10 @@ func (ca *compilerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversi // overridden. In Bazel we always allow overriding, via flags; however, this can cause // incompatibilities, so we remove "-std=" flags from Cflag properties while leaving it in other // cases. - ca.copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags, filterOutStdFlag)) - ca.asFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Asflags, nil)) - ca.conlyFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Conlyflags, nil)) - ca.cppFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Cppflags, nil)) + ca.copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags, true, filterOutStdFlag, filterOutClangUnknownCflags)) + ca.asFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Asflags, true, nil)) + ca.conlyFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Conlyflags, true, filterOutClangUnknownCflags)) + ca.cppFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Cppflags, true, filterOutClangUnknownCflags)) ca.rtti.SetSelectValue(axis, config, props.Rtti) } @@ -423,6 +450,7 @@ func (ca *compilerAttributes) finalize(ctx android.BazelConversionPathContext, i ca.srcs = partitionedSrcs[cppSrcPartition] ca.cSrcs = partitionedSrcs[cSrcPartition] ca.asSrcs = partitionedSrcs[asSrcPartition] + ca.asmSrcs = partitionedSrcs[asmSrcPartition] ca.lSrcs = partitionedSrcs[lSrcPartition] ca.llSrcs = partitionedSrcs[llSrcPartition] @@ -503,6 +531,61 @@ func includesFromLabelList(labelList bazel.LabelList) (relative, absolute []stri return relative, absolute } +type YasmAttributes struct { + Srcs bazel.LabelListAttribute + Flags bazel.StringListAttribute + Include_dirs bazel.StringListAttribute +} + +func bp2BuildYasm(ctx android.Bp2buildMutatorContext, m *Module, ca compilerAttributes) *bazel.LabelAttribute { + if ca.asmSrcs.IsEmpty() { + return nil + } + + // Yasm needs the include directories from both local_includes and + // export_include_dirs. We don't care about actually exporting them from the + // yasm rule though, because they will also be present on the cc_ rule that + // wraps this yasm rule. + includes := ca.localIncludes.Clone() + bp2BuildPropParseHelper(ctx, m, &FlagExporterProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) { + if flagExporterProperties, ok := props.(*FlagExporterProperties); ok { + if len(flagExporterProperties.Export_include_dirs) > 0 { + x := bazel.StringListAttribute{} + x.SetSelectValue(axis, config, flagExporterProperties.Export_include_dirs) + includes.Append(x) + } + } + }) + + ctx.CreateBazelTargetModule( + bazel.BazelTargetModuleProperties{ + Rule_class: "yasm", + Bzl_load_location: "//build/bazel/rules/cc:yasm.bzl", + }, + android.CommonAttributes{Name: m.Name() + "_yasm"}, + &YasmAttributes{ + Srcs: ca.asmSrcs, + Flags: ca.asFlags, + Include_dirs: *includes, + }) + + // We only want to add a dependency on the _yasm target if there are asm + // sources in the current configuration. If there are unconfigured asm + // sources, always add the dependency. Otherwise, add the dependency only + // on the configuration axes and values that had asm sources. + if len(ca.asmSrcs.Value.Includes) > 0 { + return bazel.MakeLabelAttribute(":" + m.Name() + "_yasm") + } + + ret := &bazel.LabelAttribute{} + for _, axis := range ca.asmSrcs.SortedConfigurationAxes() { + for config := range ca.asmSrcs.ConfigurableValues[axis] { + ret.SetSelectValue(axis, config, bazel.Label{Label: ":" + m.Name() + "_yasm"}) + } + } + return ret +} + // bp2BuildParseBaseProps returns all compiler, linker, library attributes of a cc module.. func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) baseAttributes { archVariantCompilerProps := module.GetArchVariantProperties(ctx, &BaseCompilerProperties{}) @@ -588,6 +671,8 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) (&compilerAttrs).finalize(ctx, implementationHdrs) (&linkerAttrs).finalize(ctx) + (&compilerAttrs.srcs).Add(bp2BuildYasm(ctx, module, compilerAttrs)) + protoDep := bp2buildProto(ctx, module, compilerAttrs.protoSrcs) // bp2buildProto will only set wholeStaticLib or implementationWholeStaticLib, but we don't know @@ -721,7 +806,7 @@ func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversion linkerFlags = append(linkerFlags, fmt.Sprintf("-Wl,--dynamic-list,$(location %s)", label.Label)) } - la.linkopts.SetSelectValue(axis, config, linkerFlags) + la.linkopts.SetSelectValue(axis, config, parseCommandLineFlags(linkerFlags, false, filterOutClangUnknownCflags)) la.useLibcrt.SetSelectValue(axis, config, props.libCrt()) if axis == bazel.NoConfigAxis { diff --git a/cc/config/global.go b/cc/config/global.go index 69990896b..26d93abb3 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -228,7 +228,6 @@ var ( // New warnings to be fixed after clang-r383902. "-Wno-deprecated-copy", // http://b/153746672 "-Wno-range-loop-construct", // http://b/153747076 - "-Wno-misleading-indentation", // http://b/153746954 "-Wno-zero-as-null-pointer-constant", // http://b/68236239 "-Wno-deprecated-anon-enum-enum-conversion", // http://b/153746485 "-Wno-pessimizing-move", // http://b/154270751 @@ -239,6 +238,8 @@ var ( // New warnings to be fixed after clang-r433403 "-Wno-error=unused-but-set-variable", // http://b/197240255 "-Wno-error=unused-but-set-parameter", // http://b/197240255 + // New warnings to be fixed after clang-r458507 + "-Wno-error=unqualified-std-cast-call", // http://b/239662094 } noOverrideExternalGlobalCflags = []string{ @@ -247,6 +248,8 @@ var ( "-Wno-unused-but-set-parameter", // http://b/215753485 "-Wno-bitwise-instead-of-logical", + // http://b/232926688 + "-Wno-misleading-indentation", } // Extra cflags for external third-party projects to disable warnings that @@ -278,11 +281,12 @@ var ( // http://b/175068488 "-Wno-string-concatenation", + + // http://b/239661264 + "-Wno-deprecated-non-prototype", } llvmNextExtraCommonGlobalCflags = []string{ - "-Wno-unqualified-std-cast-call", - "-Wno-deprecated-non-prototype", } IllegalFlags = []string{ @@ -296,8 +300,8 @@ var ( // prebuilts/clang default settings. ClangDefaultBase = "prebuilts/clang/host" - ClangDefaultVersion = "clang-r450784e" - ClangDefaultShortVersion = "14.0.7" + ClangDefaultVersion = "clang-r458507" + ClangDefaultShortVersion = "15.0.1" // Directories with warnings from Android.bp files. WarningAllowedProjects = []string{ @@ -371,6 +375,10 @@ func init() { flags = append(flags, llvmNextExtraCommonGlobalCflags...) } + if ctx.Config().IsEnvTrue("ALLOW_UNKNOWN_WARNING_OPTION") { + flags = append(flags, "-Wno-error=unknown-warning-option") + } + return strings.Join(flags, " ") }) diff --git a/cc/image.go b/cc/image.go index 3a0857b21..921b2bb13 100644 --- a/cc/image.go +++ b/cc/image.go @@ -533,7 +533,7 @@ func MutateImage(mctx android.BaseModuleContext, m ImageMutatableModule) { } } else { // This is either in /system (or similar: /data), or is a - // modules built with the NDK. Modules built with the NDK + // module built with the NDK. Modules built with the NDK // will be restricted using the existing link type checks. coreVariantNeeded = true } diff --git a/cc/library.go b/cc/library.go index c445a42ca..ff485cfde 100644 --- a/cc/library.go +++ b/cc/library.go @@ -1032,9 +1032,19 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa ctx.PropertyErrorf("symbol_file", "%q doesn't have .map.txt suffix", symbolFile) return Objects{} } + // b/239274367 --apex and --systemapi filters symbols tagged with # apex and # + // systemapi, respectively. The former is for symbols defined in platform libraries + // and the latter is for symbols defined in APEXes. + var flag string + if ctx.Module().(android.ApexModule).NotInPlatform() { + flag = "--apex" + } else { + // TODO(b/239274367) drop --apex when #apex is replaced with #systemapi + // in the map.txt files of platform libraries + flag = "--systemapi --apex" + } nativeAbiResult := parseNativeAbiDefinition(ctx, symbolFile, - android.ApiLevelOrPanic(ctx, library.MutatedProperties.StubsVersion), - "--apex") + android.ApiLevelOrPanic(ctx, library.MutatedProperties.StubsVersion), flag) objs := compileStubLibrary(ctx, flags, nativeAbiResult.stubSrc) library.versionScriptPath = android.OptionalPathForPath( nativeAbiResult.versionScript) @@ -1584,10 +1594,10 @@ func (library *libraryDecorator) coverageOutputFilePath() android.OptionalPath { func getRefAbiDumpFile(ctx ModuleContext, vndkVersion, fileName string) android.Path { // The logic must be consistent with classifySourceAbiDump. isNdk := ctx.isNdk(ctx.Config()) - isLlndkOrVndk := ctx.IsLlndkPublic() || (ctx.useVndk() && ctx.isVndk()) + isVndk := ctx.useVndk() && ctx.isVndk() - refAbiDumpTextFile := android.PathForVndkRefAbiDump(ctx, vndkVersion, fileName, isNdk, isLlndkOrVndk, false) - refAbiDumpGzipFile := android.PathForVndkRefAbiDump(ctx, vndkVersion, fileName, isNdk, isLlndkOrVndk, true) + refAbiDumpTextFile := android.PathForVndkRefAbiDump(ctx, vndkVersion, fileName, isNdk, isVndk, false) + refAbiDumpGzipFile := android.PathForVndkRefAbiDump(ctx, vndkVersion, fileName, isNdk, isVndk, true) if refAbiDumpTextFile.Valid() { if refAbiDumpGzipFile.Valid() { @@ -1606,14 +1616,18 @@ func getRefAbiDumpFile(ctx ModuleContext, vndkVersion, fileName string) android. func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objects, fileName string, soFile android.Path) { if library.sabi.shouldCreateSourceAbiDump() { - var vndkVersion string - + var version string if ctx.useVndk() { // For modules linking against vndk, follow its vndk version - vndkVersion = ctx.Module().(*Module).VndkVersion() + version = ctx.Module().(*Module).VndkVersion() } else { - // Regard the other modules as PLATFORM_VNDK_VERSION - vndkVersion = ctx.DeviceConfig().PlatformVndkVersion() + // After sdk finalizatoin, the ABI of the latest API level must be consistent with the source code + // so the chosen reference dump is the PLATFORM_SDK_VERSION. + if ctx.Config().PlatformSdkFinal() { + version = ctx.Config().PlatformSdkVersion().String() + } else { + version = "current" + } } exportIncludeDirs := library.flagExporter.exportedIncludes(ctx) @@ -1632,7 +1646,7 @@ func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objec addLsdumpPath(classifySourceAbiDump(ctx) + ":" + library.sAbiOutputFile.String()) - refAbiDumpFile := getRefAbiDumpFile(ctx, vndkVersion, fileName) + refAbiDumpFile := getRefAbiDumpFile(ctx, version, fileName) if refAbiDumpFile != nil { library.sAbiDiff = sourceAbiDiff(ctx, library.sAbiOutputFile.Path(), refAbiDumpFile, fileName, exportedHeaderFlags, diff --git a/cc/ndk_api_coverage_parser/__init__.py b/cc/ndk_api_coverage_parser/__init__.py index 8b9cd66fa..752f7d488 100755 --- a/cc/ndk_api_coverage_parser/__init__.py +++ b/cc/ndk_api_coverage_parser/__init__.py @@ -23,6 +23,7 @@ import sys from xml.etree.ElementTree import Element, SubElement, tostring from symbolfile import ( ALL_ARCHITECTURES, + Filter, FUTURE_API_LEVEL, MultiplyDefinedSymbolError, SymbolFileParser, @@ -139,9 +140,8 @@ def main(): with open(args.symbol_file) as symbol_file: try: - versions = SymbolFileParser( - symbol_file, api_map, "", FUTURE_API_LEVEL, True, True - ).parse() + filt = Filter("", FUTURE_API_LEVEL, True, True, True) + versions = SymbolFileParser(symbol_file, api_map, filt).parse() except MultiplyDefinedSymbolError as ex: sys.exit('{}: error: {}'.format(args.symbol_file, ex)) diff --git a/cc/ndk_api_coverage_parser/test_ndk_api_coverage_parser.py b/cc/ndk_api_coverage_parser/test_ndk_api_coverage_parser.py index 141059c7d..7c6ef682b 100644 --- a/cc/ndk_api_coverage_parser/test_ndk_api_coverage_parser.py +++ b/cc/ndk_api_coverage_parser/test_ndk_api_coverage_parser.py @@ -20,7 +20,7 @@ import textwrap import unittest from xml.etree.ElementTree import fromstring -from symbolfile import FUTURE_API_LEVEL, SymbolFileParser +from symbolfile import Filter, FUTURE_API_LEVEL, SymbolFileParser import ndk_api_coverage_parser as nparser @@ -78,9 +78,8 @@ class ApiCoverageSymbolFileParserTest(unittest.TestCase): """ ) ) - parser = SymbolFileParser( - input_file, {}, "", FUTURE_API_LEVEL, True, True - ) + filt = Filter("", FUTURE_API_LEVEL, True, True, True) + parser = SymbolFileParser(input_file, {}, filt) generator = nparser.XmlGenerator(io.StringIO()) result = generator.convertToXml(parser.parse()) expected = fromstring( diff --git a/cc/ndkstubgen/__init__.py b/cc/ndkstubgen/__init__.py index 5e6b8f509..f893d41e2 100755 --- a/cc/ndkstubgen/__init__.py +++ b/cc/ndkstubgen/__init__.py @@ -29,15 +29,12 @@ from symbolfile import Arch, Version class Generator: """Output generator that writes stub source files and version scripts.""" def __init__(self, src_file: TextIO, version_script: TextIO, - symbol_list: TextIO, arch: Arch, api: int, llndk: bool, - apex: bool) -> None: + symbol_list: TextIO, filt: symbolfile.Filter) -> None: self.src_file = src_file self.version_script = version_script self.symbol_list = symbol_list - self.arch = arch - self.api = api - self.llndk = llndk - self.apex = apex + self.filter = filt + self.api = filt.api def write(self, versions: Iterable[Version]) -> None: """Writes all symbol data to the output files.""" @@ -47,8 +44,7 @@ class Generator: def write_version(self, version: Version) -> None: """Writes a single version block's data to the output files.""" - if symbolfile.should_omit_version(version, self.arch, self.api, - self.llndk, self.apex): + if self.filter.should_omit_version(version): return section_versioned = symbolfile.symbol_versioned_in_api( @@ -56,8 +52,7 @@ class Generator: version_empty = True pruned_symbols = [] for symbol in version.symbols: - if symbolfile.should_omit_symbol(symbol, self.arch, self.api, - self.llndk, self.apex): + if self.filter.should_omit_symbol(symbol): continue if symbolfile.symbol_versioned_in_api(symbol.tags, self.api): @@ -110,12 +105,12 @@ def parse_args() -> argparse.Namespace: parser.add_argument( '--apex', action='store_true', - help='Use the APEX variant. Note: equivalent to --system-api.') + help='Use the APEX variant.') parser.add_argument( - '--system-api', + '--systemapi', action='store_true', - dest='apex', - help='Use the SystemAPI variant. Note: equivalent to --apex.') + dest='systemapi', + help='Use the SystemAPI variant.') parser.add_argument('--api-map', type=resolved_path, @@ -152,11 +147,10 @@ def main() -> None: verbosity = 2 logging.basicConfig(level=verbose_map[verbosity]) + filt = symbolfile.Filter(args.arch, api, args.llndk, args.apex, args.systemapi) with args.symbol_file.open() as symbol_file: try: - versions = symbolfile.SymbolFileParser(symbol_file, api_map, - args.arch, api, args.llndk, - args.apex).parse() + versions = symbolfile.SymbolFileParser(symbol_file, api_map, filt).parse() except symbolfile.MultiplyDefinedSymbolError as ex: sys.exit(f'{args.symbol_file}: error: {ex}') @@ -164,7 +158,7 @@ def main() -> None: with args.version_script.open('w') as version_script: with args.symbol_list.open('w') as symbol_list: generator = Generator(src_file, version_script, symbol_list, - args.arch, api, args.llndk, args.apex) + filt) generator.write(versions) diff --git a/cc/ndkstubgen/test_ndkstubgen.py b/cc/ndkstubgen/test_ndkstubgen.py index c8cd056a4..450719bfc 100755 --- a/cc/ndkstubgen/test_ndkstubgen.py +++ b/cc/ndkstubgen/test_ndkstubgen.py @@ -18,6 +18,7 @@ import io import textwrap import unittest +from copy import copy import symbolfile from symbolfile import Arch, Tags @@ -29,6 +30,9 @@ import ndkstubgen class GeneratorTest(unittest.TestCase): + def setUp(self) -> None: + self.filter = symbolfile.Filter(Arch('arm'), 9, False, False) + def test_omit_version(self) -> None: # Thorough testing of the cases involved here is handled by # OmitVersionTest, PrivateVersionTest, and SymbolPresenceTest. @@ -37,7 +41,7 @@ class GeneratorTest(unittest.TestCase): symbol_list_file = io.StringIO() generator = ndkstubgen.Generator(src_file, version_file, symbol_list_file, - Arch('arm'), 9, False, False) + self.filter) version = symbolfile.Version('VERSION_PRIVATE', None, Tags(), [ symbolfile.Symbol('foo', Tags()), @@ -70,7 +74,7 @@ class GeneratorTest(unittest.TestCase): symbol_list_file = io.StringIO() generator = ndkstubgen.Generator(src_file, version_file, symbol_list_file, - Arch('arm'), 9, False, False) + self.filter) version = symbolfile.Version('VERSION_1', None, Tags(), [ symbolfile.Symbol('foo', Tags.from_strs(['x86'])), @@ -106,7 +110,7 @@ class GeneratorTest(unittest.TestCase): symbol_list_file = io.StringIO() generator = ndkstubgen.Generator(src_file, version_file, symbol_list_file, - Arch('arm'), 9, False, False) + self.filter) versions = [ symbolfile.Version('VERSION_1', None, Tags(), [ @@ -162,6 +166,9 @@ class GeneratorTest(unittest.TestCase): class IntegrationTest(unittest.TestCase): + def setUp(self) -> None: + self.filter = symbolfile.Filter(Arch('arm'), 9, False, False) + def test_integration(self) -> None: api_map = { 'O': 9000, @@ -199,8 +206,7 @@ class IntegrationTest(unittest.TestCase): wobble; } VERSION_4; """)) - parser = symbolfile.SymbolFileParser(input_file, api_map, Arch('arm'), - 9, False, False) + parser = symbolfile.SymbolFileParser(input_file, api_map, self.filter) versions = parser.parse() src_file = io.StringIO() @@ -208,7 +214,7 @@ class IntegrationTest(unittest.TestCase): symbol_list_file = io.StringIO() generator = ndkstubgen.Generator(src_file, version_file, symbol_list_file, - Arch('arm'), 9, False, False) + self.filter) generator.write(versions) expected_src = textwrap.dedent("""\ @@ -263,16 +269,18 @@ class IntegrationTest(unittest.TestCase): *; }; """)) - parser = symbolfile.SymbolFileParser(input_file, api_map, Arch('arm'), - 9001, False, False) + f = copy(self.filter) + f.api = 9001 + parser = symbolfile.SymbolFileParser(input_file, api_map, f) versions = parser.parse() src_file = io.StringIO() version_file = io.StringIO() symbol_list_file = io.StringIO() + f = copy(self.filter) + f.api = 9001 generator = ndkstubgen.Generator(src_file, - version_file, symbol_list_file, - Arch('arm'), 9001, False, False) + version_file, symbol_list_file, f) generator.write(versions) expected_src = textwrap.dedent("""\ @@ -322,8 +330,9 @@ class IntegrationTest(unittest.TestCase): } VERSION_2; """)) - parser = symbolfile.SymbolFileParser(input_file, {}, Arch('arm'), 16, - False, False) + f = copy(self.filter) + f.api = 16 + parser = symbolfile.SymbolFileParser(input_file, {}, f) with self.assertRaises( symbolfile.MultiplyDefinedSymbolError) as ex_context: @@ -370,16 +379,18 @@ class IntegrationTest(unittest.TestCase): wobble; } VERSION_4; """)) - parser = symbolfile.SymbolFileParser(input_file, api_map, Arch('arm'), - 9, False, True) + f = copy(self.filter) + f.apex = True + parser = symbolfile.SymbolFileParser(input_file, api_map, f) versions = parser.parse() src_file = io.StringIO() version_file = io.StringIO() symbol_list_file = io.StringIO() + f = copy(self.filter) + f.apex = True generator = ndkstubgen.Generator(src_file, - version_file, symbol_list_file, - Arch('arm'), 9, False, True) + version_file, symbol_list_file, f) generator.write(versions) expected_src = textwrap.dedent("""\ @@ -428,20 +439,19 @@ class IntegrationTest(unittest.TestCase): *; }; """)) - parser = symbolfile.SymbolFileParser(input_file, {}, Arch('arm'), - 9, llndk=False, apex=True) + f = copy(self.filter) + f.apex = True + parser = symbolfile.SymbolFileParser(input_file, {}, f) versions = parser.parse() src_file = io.StringIO() version_file = io.StringIO() symbol_list_file = io.StringIO() + f = copy(self.filter) + f.apex = True generator = ndkstubgen.Generator(src_file, version_file, - symbol_list_file, - Arch('arm'), - 9, - llndk=False, - apex=True) + symbol_list_file, f) generator.write(versions) self.assertEqual('', src_file.getvalue()) diff --git a/cc/symbolfile/__init__.py b/cc/symbolfile/__init__.py index f8d18414c..471a12f50 100644 --- a/cc/symbolfile/__init__.py +++ b/cc/symbolfile/__init__.py @@ -78,12 +78,17 @@ class Tags: @property def has_mode_tags(self) -> bool: """Returns True if any mode tags (apex, llndk, etc) are set.""" - return self.has_apex_tags or self.has_llndk_tags + return self.has_apex_tags or self.has_llndk_tags or self.has_systemapi_tags @property def has_apex_tags(self) -> bool: """Returns True if any APEX tags are set.""" - return 'apex' in self.tags or 'systemapi' in self.tags + return 'apex' in self.tags + + @property + def has_systemapi_tags(self) -> bool: + """Returns True if any APEX tags are set.""" + return 'systemapi' in self.tags @property def has_llndk_tags(self) -> bool: @@ -198,50 +203,57 @@ def get_tag_value(tag: Tag) -> str: """ return split_tag(tag)[1] +class Filter: + """A filter encapsulates a condition that tells whether a version or a + symbol should be omitted or not + """ -def _should_omit_tags(tags: Tags, arch: Arch, api: int, llndk: bool, - apex: bool) -> bool: - """Returns True if the tagged object should be omitted. + def __init__(self, arch: Arch, api: int, llndk: bool = False, apex: bool = False, systemapi: bool = False): + self.arch = arch + self.api = api + self.llndk = llndk + self.apex = apex + self.systemapi = systemapi - This defines the rules shared between version tagging and symbol tagging. - """ - # The apex and llndk tags will only exclude APIs from other modes. If in - # APEX or LLNDK mode and neither tag is provided, we fall back to the - # default behavior because all NDK symbols are implicitly available to APEX - # and LLNDK. - if tags.has_mode_tags: - if not apex and not llndk: + def _should_omit_tags(self, tags: Tags) -> bool: + """Returns True if the tagged object should be omitted. + + This defines the rules shared between version tagging and symbol tagging. + """ + # The apex and llndk tags will only exclude APIs from other modes. If in + # APEX or LLNDK mode and neither tag is provided, we fall back to the + # default behavior because all NDK symbols are implicitly available to + # APEX and LLNDK. + if tags.has_mode_tags: + if self.apex and tags.has_apex_tags: + return False + if self.llndk and tags.has_llndk_tags: + return False + if self.systemapi and tags.has_systemapi_tags: + return False return True - if apex and not tags.has_apex_tags: + if not symbol_in_arch(tags, self.arch): return True - if llndk and not tags.has_llndk_tags: + if not symbol_in_api(tags, self.arch, self.api): return True - if not symbol_in_arch(tags, arch): - return True - if not symbol_in_api(tags, arch, api): - return True - return False - + return False -def should_omit_version(version: Version, arch: Arch, api: int, llndk: bool, - apex: bool) -> bool: - """Returns True if the version section should be omitted. - - We want to omit any sections that do not have any symbols we'll have in the - stub library. Sections that contain entirely future symbols or only symbols - for certain architectures. - """ - if version.is_private: - return True - if version.tags.has_platform_only_tags: - return True - return _should_omit_tags(version.tags, arch, api, llndk, apex) + def should_omit_version(self, version: Version) -> bool: + """Returns True if the version section should be omitted. + We want to omit any sections that do not have any symbols we'll have in + the stub library. Sections that contain entirely future symbols or only + symbols for certain architectures. + """ + if version.is_private: + return True + if version.tags.has_platform_only_tags: + return True + return self._should_omit_tags(version.tags) -def should_omit_symbol(symbol: Symbol, arch: Arch, api: int, llndk: bool, - apex: bool) -> bool: - """Returns True if the symbol should be omitted.""" - return _should_omit_tags(symbol.tags, arch, api, llndk, apex) + def should_omit_symbol(self, symbol: Symbol) -> bool: + """Returns True if the symbol should be omitted.""" + return self._should_omit_tags(symbol.tags) def symbol_in_arch(tags: Tags, arch: Arch) -> bool: @@ -316,14 +328,10 @@ class MultiplyDefinedSymbolError(RuntimeError): class SymbolFileParser: """Parses NDK symbol files.""" - def __init__(self, input_file: TextIO, api_map: ApiMap, arch: Arch, - api: int, llndk: bool, apex: bool) -> None: + def __init__(self, input_file: TextIO, api_map: ApiMap, filt: Filter) -> None: self.input_file = input_file self.api_map = api_map - self.arch = arch - self.api = api - self.llndk = llndk - self.apex = apex + self.filter = filt self.current_line: Optional[str] = None def parse(self) -> List[Version]: @@ -352,13 +360,11 @@ class SymbolFileParser: symbol_names = set() multiply_defined_symbols = set() for version in versions: - if should_omit_version(version, self.arch, self.api, self.llndk, - self.apex): + if self.filter.should_omit_version(version): continue for symbol in version.symbols: - if should_omit_symbol(symbol, self.arch, self.api, self.llndk, - self.apex): + if self.filter.should_omit_symbol(symbol): continue if symbol.name in symbol_names: diff --git a/cc/symbolfile/test_symbolfile.py b/cc/symbolfile/test_symbolfile.py index c1e821904..e17a8d01d 100644 --- a/cc/symbolfile/test_symbolfile.py +++ b/cc/symbolfile/test_symbolfile.py @@ -19,7 +19,8 @@ import textwrap import unittest import symbolfile -from symbolfile import Arch, Tag, Tags, Version +from symbolfile import Arch, Tag, Tags, Version, Symbol, Filter +from copy import copy # pylint: disable=missing-docstring @@ -202,178 +203,188 @@ class SymbolPresenceTest(unittest.TestCase): class OmitVersionTest(unittest.TestCase): + def setUp(self) -> None: + self.filter = Filter(arch = Arch('arm'), api = 9) + self.version = Version('foo', None, Tags(), []) + + def assertOmit(self, f: Filter, v: Version) -> None: + self.assertTrue(f.should_omit_version(v)) + + def assertInclude(self, f: Filter, v: Version) -> None: + self.assertFalse(f.should_omit_version(v)) + def test_omit_private(self) -> None: - self.assertFalse( - symbolfile.should_omit_version( - symbolfile.Version('foo', None, Tags(), []), Arch('arm'), 9, - False, False)) + f = self.filter + v = self.version - self.assertTrue( - symbolfile.should_omit_version( - symbolfile.Version('foo_PRIVATE', None, Tags(), []), - Arch('arm'), 9, False, False)) - self.assertTrue( - symbolfile.should_omit_version( - symbolfile.Version('foo_PLATFORM', None, Tags(), []), - Arch('arm'), 9, False, False)) + self.assertInclude(f, v) - self.assertTrue( - symbolfile.should_omit_version( - symbolfile.Version('foo', None, - Tags.from_strs(['platform-only']), []), - Arch('arm'), 9, False, False)) + v.name = 'foo_PRIVATE' + self.assertOmit(f, v) + + v.name = 'foo_PLATFORM' + self.assertOmit(f, v) + + v.name = 'foo' + v.tags = Tags.from_strs(['platform-only']) + self.assertOmit(f, v) def test_omit_llndk(self) -> None: - self.assertTrue( - symbolfile.should_omit_version( - symbolfile.Version('foo', None, Tags.from_strs(['llndk']), []), - Arch('arm'), 9, False, False)) + f = self.filter + v = self.version + v_llndk = copy(v) + v_llndk.tags = Tags.from_strs(['llndk']) - self.assertFalse( - symbolfile.should_omit_version( - symbolfile.Version('foo', None, Tags(), []), Arch('arm'), 9, - True, False)) - self.assertFalse( - symbolfile.should_omit_version( - symbolfile.Version('foo', None, Tags.from_strs(['llndk']), []), - Arch('arm'), 9, True, False)) + self.assertOmit(f, v_llndk) + + f.llndk = True + self.assertInclude(f, v) + self.assertInclude(f, v_llndk) def test_omit_apex(self) -> None: - self.assertTrue( - symbolfile.should_omit_version( - symbolfile.Version('foo', None, Tags.from_strs(['apex']), []), - Arch('arm'), 9, False, False)) + f = self.filter + v = self.version + v_apex = copy(v) + v_apex.tags = Tags.from_strs(['apex']) + v_systemapi = copy(v) + v_systemapi.tags = Tags.from_strs(['systemapi']) - self.assertFalse( - symbolfile.should_omit_version( - symbolfile.Version('foo', None, Tags(), []), Arch('arm'), 9, - False, True)) - self.assertFalse( - symbolfile.should_omit_version( - symbolfile.Version('foo', None, Tags.from_strs(['apex']), []), - Arch('arm'), 9, False, True)) + self.assertOmit(f, v_apex) + + f.apex = True + self.assertInclude(f, v) + self.assertInclude(f, v_apex) + self.assertOmit(f, v_systemapi) def test_omit_systemapi(self) -> None: - self.assertTrue( - symbolfile.should_omit_version( - symbolfile.Version('foo', None, Tags.from_strs(['systemapi']), - []), Arch('arm'), 9, False, False)) + f = self.filter + v = self.version + v_apex = copy(v) + v_apex.tags = Tags.from_strs(['apex']) + v_systemapi = copy(v) + v_systemapi.tags = Tags.from_strs(['systemapi']) - self.assertFalse( - symbolfile.should_omit_version( - symbolfile.Version('foo', None, Tags(), []), Arch('arm'), 9, - False, True)) - self.assertFalse( - symbolfile.should_omit_version( - symbolfile.Version('foo', None, Tags.from_strs(['systemapi']), - []), Arch('arm'), 9, False, True)) + self.assertOmit(f, v_systemapi) + + f.systemapi = True + self.assertInclude(f, v) + self.assertInclude(f, v_systemapi) + self.assertOmit(f, v_apex) def test_omit_arch(self) -> None: - self.assertFalse( - symbolfile.should_omit_version( - symbolfile.Version('foo', None, Tags(), []), Arch('arm'), 9, - False, False)) - self.assertFalse( - symbolfile.should_omit_version( - symbolfile.Version('foo', None, Tags.from_strs(['arm']), []), - Arch('arm'), 9, False, False)) + f_arm = self.filter + v_none = self.version + self.assertInclude(f_arm, v_none) - self.assertTrue( - symbolfile.should_omit_version( - symbolfile.Version('foo', None, Tags.from_strs(['x86']), []), - Arch('arm'), 9, False, False)) + v_arm = copy(v_none) + v_arm.tags = Tags.from_strs(['arm']) + self.assertInclude(f_arm, v_arm) + + v_x86 = copy(v_none) + v_x86.tags = Tags.from_strs(['x86']) + self.assertOmit(f_arm, v_x86) def test_omit_api(self) -> None: - self.assertFalse( - symbolfile.should_omit_version( - symbolfile.Version('foo', None, Tags(), []), Arch('arm'), 9, - False, False)) - self.assertFalse( - symbolfile.should_omit_version( - symbolfile.Version('foo', None, - Tags.from_strs(['introduced=9']), []), - Arch('arm'), 9, False, False)) + f_api9 = self.filter + v_none = self.version + self.assertInclude(f_api9, v_none) - self.assertTrue( - symbolfile.should_omit_version( - symbolfile.Version('foo', None, - Tags.from_strs(['introduced=14']), []), - Arch('arm'), 9, False, False)) + v_api9 = copy(v_none) + v_api9.tags = Tags.from_strs(['introduced=9']) + self.assertInclude(f_api9, v_api9) + + v_api14 = copy(v_none) + v_api14.tags = Tags.from_strs(['introduced=14']) + self.assertOmit(f_api9, v_api14) class OmitSymbolTest(unittest.TestCase): + def setUp(self) -> None: + self.filter = Filter(arch = Arch('arm'), api = 9) + + def assertOmit(self, f: Filter, s: Symbol) -> None: + self.assertTrue(f.should_omit_symbol(s)) + + def assertInclude(self, f: Filter, s: Symbol) -> None: + self.assertFalse(f.should_omit_symbol(s)) + def test_omit_llndk(self) -> None: - self.assertTrue( - symbolfile.should_omit_symbol( - symbolfile.Symbol('foo', Tags.from_strs(['llndk'])), - Arch('arm'), 9, False, False)) + f_none = self.filter + f_llndk = copy(f_none) + f_llndk.llndk = True - self.assertFalse( - symbolfile.should_omit_symbol(symbolfile.Symbol('foo', Tags()), - Arch('arm'), 9, True, False)) - self.assertFalse( - symbolfile.should_omit_symbol( - symbolfile.Symbol('foo', Tags.from_strs(['llndk'])), - Arch('arm'), 9, True, False)) + s_none = Symbol('foo', Tags()) + s_llndk = Symbol('foo', Tags.from_strs(['llndk'])) + + self.assertOmit(f_none, s_llndk) + self.assertInclude(f_llndk, s_none) + self.assertInclude(f_llndk, s_llndk) def test_omit_apex(self) -> None: - self.assertTrue( - symbolfile.should_omit_symbol( - symbolfile.Symbol('foo', Tags.from_strs(['apex'])), - Arch('arm'), 9, False, False)) + f_none = self.filter + f_apex = copy(f_none) + f_apex.apex = True - self.assertFalse( - symbolfile.should_omit_symbol(symbolfile.Symbol('foo', Tags()), - Arch('arm'), 9, False, True)) - self.assertFalse( - symbolfile.should_omit_symbol( - symbolfile.Symbol('foo', Tags.from_strs(['apex'])), - Arch('arm'), 9, False, True)) + s_none = Symbol('foo', Tags()) + s_apex = Symbol('foo', Tags.from_strs(['apex'])) + s_systemapi = Symbol('foo', Tags.from_strs(['systemapi'])) - def test_omit_systemapi(self) -> None: - self.assertTrue( - symbolfile.should_omit_symbol( - symbolfile.Symbol('foo', Tags.from_strs(['systemapi'])), - Arch('arm'), 9, False, False)) + self.assertOmit(f_none, s_apex) + self.assertInclude(f_apex, s_none) + self.assertInclude(f_apex, s_apex) + self.assertOmit(f_apex, s_systemapi) - self.assertFalse( - symbolfile.should_omit_symbol(symbolfile.Symbol('foo', Tags()), - Arch('arm'), 9, False, True)) - self.assertFalse( - symbolfile.should_omit_symbol( - symbolfile.Symbol('foo', Tags.from_strs(['systemapi'])), - Arch('arm'), 9, False, True)) + def test_omit_systemapi(self) -> None: + f_none = self.filter + f_systemapi = copy(f_none) + f_systemapi.systemapi = True + + s_none = Symbol('foo', Tags()) + s_apex = Symbol('foo', Tags.from_strs(['apex'])) + s_systemapi = Symbol('foo', Tags.from_strs(['systemapi'])) + + self.assertOmit(f_none, s_systemapi) + self.assertInclude(f_systemapi, s_none) + self.assertInclude(f_systemapi, s_systemapi) + self.assertOmit(f_systemapi, s_apex) + + def test_omit_apex_and_systemapi(self) -> None: + f = self.filter + f.systemapi = True + f.apex = True + + s_none = Symbol('foo', Tags()) + s_apex = Symbol('foo', Tags.from_strs(['apex'])) + s_systemapi = Symbol('foo', Tags.from_strs(['systemapi'])) + self.assertInclude(f, s_none) + self.assertInclude(f, s_apex) + self.assertInclude(f, s_systemapi) def test_omit_arch(self) -> None: - self.assertFalse( - symbolfile.should_omit_symbol(symbolfile.Symbol('foo', Tags()), - Arch('arm'), 9, False, False)) - self.assertFalse( - symbolfile.should_omit_symbol( - symbolfile.Symbol('foo', Tags.from_strs(['arm'])), Arch('arm'), - 9, False, False)) + f_arm = self.filter + s_none = Symbol('foo', Tags()) + s_arm = Symbol('foo', Tags.from_strs(['arm'])) + s_x86 = Symbol('foo', Tags.from_strs(['x86'])) - self.assertTrue( - symbolfile.should_omit_symbol( - symbolfile.Symbol('foo', Tags.from_strs(['x86'])), Arch('arm'), - 9, False, False)) + self.assertInclude(f_arm, s_none) + self.assertInclude(f_arm, s_arm) + self.assertOmit(f_arm, s_x86) def test_omit_api(self) -> None: - self.assertFalse( - symbolfile.should_omit_symbol(symbolfile.Symbol('foo', Tags()), - Arch('arm'), 9, False, False)) - self.assertFalse( - symbolfile.should_omit_symbol( - symbolfile.Symbol('foo', Tags.from_strs(['introduced=9'])), - Arch('arm'), 9, False, False)) + f_api9 = self.filter + s_none = Symbol('foo', Tags()) + s_api9 = Symbol('foo', Tags.from_strs(['introduced=9'])) + s_api14 = Symbol('foo', Tags.from_strs(['introduced=14'])) - self.assertTrue( - symbolfile.should_omit_symbol( - symbolfile.Symbol('foo', Tags.from_strs(['introduced=14'])), - Arch('arm'), 9, False, False)) + self.assertInclude(f_api9, s_none) + self.assertInclude(f_api9, s_api9) + self.assertOmit(f_api9, s_api14) class SymbolFileParseTest(unittest.TestCase): + def setUp(self) -> None: + self.filter = Filter(arch = Arch('arm'), api = 16) + def test_next_line(self) -> None: input_file = io.StringIO(textwrap.dedent("""\ foo @@ -382,8 +393,7 @@ class SymbolFileParseTest(unittest.TestCase): # baz qux """)) - parser = symbolfile.SymbolFileParser(input_file, {}, Arch('arm'), 16, - False, False) + parser = symbolfile.SymbolFileParser(input_file, {}, self.filter) self.assertIsNone(parser.current_line) self.assertEqual('foo', parser.next_line().strip()) @@ -409,8 +419,7 @@ class SymbolFileParseTest(unittest.TestCase): VERSION_2 { } VERSION_1; # asdf """)) - parser = symbolfile.SymbolFileParser(input_file, {}, Arch('arm'), 16, - False, False) + parser = symbolfile.SymbolFileParser(input_file, {}, self.filter) parser.next_line() version = parser.parse_version() @@ -419,8 +428,8 @@ class SymbolFileParseTest(unittest.TestCase): self.assertEqual(Tags.from_strs(['foo', 'bar']), version.tags) expected_symbols = [ - symbolfile.Symbol('baz', Tags()), - symbolfile.Symbol('qux', Tags.from_strs(['woodly', 'doodly'])), + Symbol('baz', Tags()), + Symbol('qux', Tags.from_strs(['woodly', 'doodly'])), ] self.assertEqual(expected_symbols, version.symbols) @@ -434,8 +443,7 @@ class SymbolFileParseTest(unittest.TestCase): input_file = io.StringIO(textwrap.dedent("""\ VERSION_1 { """)) - parser = symbolfile.SymbolFileParser(input_file, {}, Arch('arm'), 16, - False, False) + parser = symbolfile.SymbolFileParser(input_file, {}, self.filter) parser.next_line() with self.assertRaises(symbolfile.ParseError): parser.parse_version() @@ -446,8 +454,7 @@ class SymbolFileParseTest(unittest.TestCase): foo: } """)) - parser = symbolfile.SymbolFileParser(input_file, {}, Arch('arm'), 16, - False, False) + parser = symbolfile.SymbolFileParser(input_file, {}, self.filter) parser.next_line() with self.assertRaises(symbolfile.ParseError): parser.parse_version() @@ -457,8 +464,7 @@ class SymbolFileParseTest(unittest.TestCase): foo; bar; # baz qux """)) - parser = symbolfile.SymbolFileParser(input_file, {}, Arch('arm'), 16, - False, False) + parser = symbolfile.SymbolFileParser(input_file, {}, self.filter) parser.next_line() symbol = parser.parse_symbol() @@ -476,8 +482,7 @@ class SymbolFileParseTest(unittest.TestCase): *; }; """)) - parser = symbolfile.SymbolFileParser(input_file, {}, Arch('arm'), 16, - False, False) + parser = symbolfile.SymbolFileParser(input_file, {}, self.filter) parser.next_line() with self.assertRaises(symbolfile.ParseError): parser.parse_version() @@ -489,8 +494,7 @@ class SymbolFileParseTest(unittest.TestCase): *; }; """)) - parser = symbolfile.SymbolFileParser(input_file, {}, Arch('arm'), 16, - False, False) + parser = symbolfile.SymbolFileParser(input_file, {}, self.filter) parser.next_line() version = parser.parse_version() self.assertEqual([], version.symbols) @@ -501,8 +505,7 @@ class SymbolFileParseTest(unittest.TestCase): foo }; """)) - parser = symbolfile.SymbolFileParser(input_file, {}, Arch('arm'), 16, - False, False) + parser = symbolfile.SymbolFileParser(input_file, {}, self.filter) parser.next_line() with self.assertRaises(symbolfile.ParseError): parser.parse_version() @@ -510,8 +513,7 @@ class SymbolFileParseTest(unittest.TestCase): def test_parse_fails_invalid_input(self) -> None: with self.assertRaises(symbolfile.ParseError): input_file = io.StringIO('foo') - parser = symbolfile.SymbolFileParser(input_file, {}, Arch('arm'), - 16, False, False) + parser = symbolfile.SymbolFileParser(input_file, {}, self.filter) parser.parse() def test_parse(self) -> None: @@ -532,19 +534,18 @@ class SymbolFileParseTest(unittest.TestCase): qwerty; } VERSION_1; """)) - parser = symbolfile.SymbolFileParser(input_file, {}, Arch('arm'), 16, - False, False) + parser = symbolfile.SymbolFileParser(input_file, {}, self.filter) versions = parser.parse() expected = [ symbolfile.Version('VERSION_1', None, Tags(), [ - symbolfile.Symbol('foo', Tags()), - symbolfile.Symbol('bar', Tags.from_strs(['baz'])), + Symbol('foo', Tags()), + Symbol('bar', Tags.from_strs(['baz'])), ]), symbolfile.Version( 'VERSION_2', 'VERSION_1', Tags.from_strs(['wasd']), [ - symbolfile.Symbol('woodly', Tags()), - symbolfile.Symbol('doodly', Tags.from_strs(['asdf'])), + Symbol('woodly', Tags()), + Symbol('doodly', Tags.from_strs(['asdf'])), ]), ] @@ -559,8 +560,9 @@ class SymbolFileParseTest(unittest.TestCase): qux; # apex }; """)) - parser = symbolfile.SymbolFileParser(input_file, {}, Arch('arm'), 16, - False, True) + f = copy(self.filter) + f.llndk = True + parser = symbolfile.SymbolFileParser(input_file, {}, f) parser.next_line() version = parser.parse_version() @@ -568,10 +570,10 @@ class SymbolFileParseTest(unittest.TestCase): self.assertIsNone(version.base) expected_symbols = [ - symbolfile.Symbol('foo', Tags()), - symbolfile.Symbol('bar', Tags.from_strs(['llndk'])), - symbolfile.Symbol('baz', Tags.from_strs(['llndk', 'apex'])), - symbolfile.Symbol('qux', Tags.from_strs(['apex'])), + Symbol('foo', Tags()), + Symbol('bar', Tags.from_strs(['llndk'])), + Symbol('baz', Tags.from_strs(['llndk', 'apex'])), + Symbol('qux', Tags.from_strs(['apex'])), ] self.assertEqual(expected_symbols, version.symbols) diff --git a/cc/testing.go b/cc/testing.go index 42c9c3a89..79ae3c3ae 100644 --- a/cc/testing.go +++ b/cc/testing.go @@ -194,7 +194,6 @@ func commonDefaultModules() string { native_coverage: false, system_shared_libs: [], stl: "none", - notice: "custom_notice", } cc_library { name: "libprofile-clang-extras", @@ -205,7 +204,6 @@ func commonDefaultModules() string { native_coverage: false, system_shared_libs: [], stl: "none", - notice: "custom_notice", } cc_library { name: "libprofile-extras_ndk", @@ -214,7 +212,6 @@ func commonDefaultModules() string { native_coverage: false, system_shared_libs: [], stl: "none", - notice: "custom_notice", sdk_version: "current", } cc_library { @@ -224,7 +221,6 @@ func commonDefaultModules() string { native_coverage: false, system_shared_libs: [], stl: "none", - notice: "custom_notice", sdk_version: "current", } diff --git a/cc/vndk.go b/cc/vndk.go index bf6148b1c..4cd4d4273 100644 --- a/cc/vndk.go +++ b/cc/vndk.go @@ -671,12 +671,8 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch()) configsDir := filepath.Join(snapshotArchDir, "configs") - noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES") includeDir := filepath.Join(snapshotArchDir, "include") - // set of notice files copied. - noticeBuilt := make(map[string]bool) - // paths of VNDK modules for GPL license checking modulePaths := make(map[string]string) @@ -762,16 +758,6 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex moduleNames[stem] = ctx.ModuleName(m) modulePaths[stem] = ctx.ModuleDir(m) - if len(m.NoticeFiles()) > 0 { - noticeName := stem + ".txt" - // skip already copied notice file - if _, ok := noticeBuilt[noticeName]; !ok { - noticeBuilt[noticeName] = true - snapshotOutputs = append(snapshotOutputs, combineNoticesRule( - ctx, m.NoticeFiles(), filepath.Join(noticeDir, noticeName))) - } - } - if ctx.Config().VndkSnapshotBuildArtifacts() { headers = append(headers, m.SnapshotHeaders()...) } diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go index 8a3d6e037..53422cd6c 100644 --- a/cmd/soong_build/main.go +++ b/cmd/soong_build/main.go @@ -220,7 +220,7 @@ func writeDepFile(outputFile string, eventHandler metrics.EventHandler, ninjaDep // 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, logDir string) string { +func doChosenActivity(ctx *android.Context, configuration android.Config, extraNinjaDeps []string, logDir string) string { mixedModeBuild := configuration.BazelContext.BazelEnabled() generateBazelWorkspace := bp2buildMarker != "" generateQueryView := bazelQueryViewDir != "" @@ -236,7 +236,6 @@ func doChosenActivity(configuration android.Config, extraNinjaDeps []string, log blueprintArgs := cmdlineArgs - ctx := newContext(configuration) if mixedModeBuild { runMixedModeBuild(configuration, ctx, extraNinjaDeps) } else { @@ -284,7 +283,6 @@ func doChosenActivity(configuration android.Config, extraNinjaDeps []string, log } } - writeMetrics(configuration, *ctx.EventHandler, logDir) return cmdlineArgs.OutFile } @@ -344,7 +342,13 @@ func main() { // 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) + ctx := newContext(configuration) + ctx.EventHandler.Begin("soong_build") + + finalOutputFile := doChosenActivity(ctx, configuration, extraNinjaDeps, logDir) + + ctx.EventHandler.End("soong_build") + writeMetrics(configuration, *ctx.EventHandler, logDir) writeUsedEnvironmentFile(configuration, finalOutputFile) } @@ -552,7 +556,7 @@ func runBp2Build(configuration android.Config, extraNinjaDeps []string) { excludes = append(excludes, getTemporaryExcludes()...) symlinkForestDeps := bp2build.PlantSymlinkForest( - topDir, workspaceRoot, generatedRoot, ".", excludes) + configuration, topDir, workspaceRoot, generatedRoot, ".", excludes) ninjaDeps = append(ninjaDeps, codegenContext.AdditionalNinjaDeps()...) ninjaDeps = append(ninjaDeps, symlinkForestDeps...) @@ -566,7 +570,9 @@ func runBp2Build(configuration android.Config, extraNinjaDeps []string) { // Only report metrics when in bp2build mode. The metrics aren't relevant // for queryview, since that's a total repo-wide conversion and there's a // 1:1 mapping for each module. - metrics.Print() + if configuration.IsEnvTrue("BP2BUILD_VERBOSE") { + metrics.Print() + } writeBp2BuildMetrics(&metrics, configuration, eventHandler) } diff --git a/cmd/soong_build/queryview.go b/cmd/soong_build/queryview.go index d63ded56c..983dbf0fc 100644 --- a/cmd/soong_build/queryview.go +++ b/cmd/soong_build/queryview.go @@ -32,7 +32,8 @@ func createBazelQueryView(ctx *bp2build.CodegenContext, bazelQueryViewDir string panic(err) } - filesToWrite := bp2build.CreateBazelFiles(ruleShims, res.BuildDirToTargets(), bp2build.QueryView) + filesToWrite := bp2build.CreateBazelFiles(ctx.Config(), ruleShims, res.BuildDirToTargets(), + bp2build.QueryView) for _, f := range filesToWrite { if err := writeReadOnlyFile(bazelQueryViewDir, f); err != nil { return err diff --git a/fuzz/fuzz_common.go b/fuzz/fuzz_common.go index 7f7c60129..c8cd21b7e 100644 --- a/fuzz/fuzz_common.go +++ b/fuzz/fuzz_common.go @@ -113,21 +113,21 @@ type FuzzConfig struct { // A brief description of what the fuzzed code does. Description string `json:"description,omitempty"` // Can this code be triggered remotely or only locally. - Remotely_accessible bool `json:"remotely_accessible,omitempty"` + Remotely_accessible *bool `json:"remotely_accessible,omitempty"` // Is the fuzzed code host only, i.e. test frameworks or support utilities. - Host_only bool `json:"host_only,omitempty"` + Host_only *bool `json:"host_only,omitempty"` // Can third party/untrusted apps supply data to fuzzed code. - Untrusted_data bool `json:"untrusted_data,omitempty"` + Untrusted_data *bool `json:"untrusted_data,omitempty"` // Is the code being fuzzed in a privileged, constrained or any other // context from: // https://source.android.com/security/overview/updates-resources#context_types. Privilege_level PrivilegedLevel `json:"privilege_level,omitempty"` // Can the fuzzed code isolated or can be called by multiple users/processes. - Isolated bool `json:"users_isolation,omitempty"` + Isolated *bool `json:"users_isolation,omitempty"` // When code was relaeased or will be released. Production_date string `json:"production_date,omitempty"` // Prevents critical service functionality like phone calls, bluetooth, etc. - Critical bool `json:"critical,omitempty"` + Critical *bool `json:"critical,omitempty"` // Specify whether to enable continuous fuzzing on devices. Defaults to true. Fuzz_on_haiku_device *bool `json:"fuzz_on_haiku_device,omitempty"` // Specify whether to enable continuous fuzzing on host. Defaults to true. diff --git a/java/Android.bp b/java/Android.bp index e25accf2a..9df4ab4de 100644 --- a/java/Android.bp +++ b/java/Android.bp @@ -76,6 +76,7 @@ bootstrap_go_package { "tradefed.go", ], testSrcs: [ + "aar_test.go", "androidmk_test.go", "app_import_test.go", "app_set_test.go", diff --git a/java/aar.go b/java/aar.go index cf84309f4..a59ecb8ca 100644 --- a/java/aar.go +++ b/java/aar.go @@ -105,6 +105,7 @@ type aapt struct { noticeFile android.OptionalPath assetPackage android.OptionalPath isLibrary bool + defaultManifestVersion string useEmbeddedNativeLibs bool useEmbeddedDex bool usesNonSdkApis bool @@ -281,14 +282,15 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile) manifestPath := ManifestFixer(ctx, manifestSrcPath, ManifestFixerParams{ - SdkContext: sdkContext, - ClassLoaderContexts: classLoaderContexts, - IsLibrary: a.isLibrary, - UseEmbeddedNativeLibs: a.useEmbeddedNativeLibs, - UsesNonSdkApis: a.usesNonSdkApis, - UseEmbeddedDex: a.useEmbeddedDex, - HasNoCode: a.hasNoCode, - LoggingParent: a.LoggingParent, + SdkContext: sdkContext, + ClassLoaderContexts: classLoaderContexts, + IsLibrary: a.isLibrary, + DefaultManifestVersion: a.defaultManifestVersion, + UseEmbeddedNativeLibs: a.useEmbeddedNativeLibs, + UsesNonSdkApis: a.usesNonSdkApis, + UseEmbeddedDex: a.useEmbeddedDex, + HasNoCode: a.hasNoCode, + LoggingParent: a.LoggingParent, }) // Add additional manifest files to transitive manifests. @@ -570,12 +572,24 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) a.exportedProguardFlagFiles = android.FirstUniquePaths(a.exportedProguardFlagFiles) a.exportedStaticPackages = android.FirstUniquePaths(a.exportedStaticPackages) + + prebuiltJniPackages := android.Paths{} + ctx.VisitDirectDeps(func(module android.Module) { + if info, ok := ctx.OtherModuleProvider(module, JniPackageProvider).(JniPackageInfo); ok { + prebuiltJniPackages = append(prebuiltJniPackages, info.JniPackages...) + } + }) + if len(prebuiltJniPackages) > 0 { + ctx.SetProvider(JniPackageProvider, JniPackageInfo{ + JniPackages: prebuiltJniPackages, + }) + } } // android_library builds and links sources into a `.jar` file for the device along with Android resources. // // An android_library has a single variant that produces a `.jar` file containing `.class` files that were -// compiled against the device bootclasspath, along with a `package-res.apk` file containing Android resources compiled +// compiled against the device bootclasspath, along with a `package-res.apk` file containing Android resources compiled // with aapt2. This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of // an android_app module. func AndroidLibraryFactory() android.Module { @@ -619,6 +633,10 @@ type AARImportProperties struct { Libs []string // If set to true, run Jetifier against .aar file. Defaults to false. Jetifier *bool + // If true, extract JNI libs from AAR archive. These libs will be accessible to android_app modules and + // will be passed transitively through android_libraries to an android_app. + //TODO(b/241138093) evaluate whether we can have this flag default to true for Bazel conversion + Extract_jni *bool } type AARImport struct { @@ -643,7 +661,8 @@ type AARImport struct { hideApexVariantFromMake bool - aarPath android.Path + aarPath android.Path + jniPackages android.Paths sdkVersion android.SdkSpec minSdkVersion android.SdkSpec @@ -751,6 +770,28 @@ func (a *AARImport) DepsMutator(ctx android.BottomUpMutatorContext) { ctx.AddVariationDependencies(nil, staticLibTag, a.properties.Static_libs...) } +type JniPackageInfo struct { + // List of zip files containing JNI libraries + // Zip files should have directory structure jni/<arch>/*.so + JniPackages android.Paths +} + +var JniPackageProvider = blueprint.NewProvider(JniPackageInfo{}) + +// Unzip an AAR and extract the JNI libs for $archString. +var extractJNI = pctx.AndroidStaticRule("extractJNI", + blueprint.RuleParams{ + Command: `rm -rf $out $outDir && touch $out && ` + + `unzip -qoDD -d $outDir $in "jni/${archString}/*" && ` + + `jni_files=$$(find $outDir/jni -type f) && ` + + // print error message if there are no JNI libs for this arch + `[ -n "$$jni_files" ] || (echo "ERROR: no JNI libs found for arch ${archString}" && exit 1) && ` + + `${config.SoongZipCmd} -o $out -P 'lib/${archString}' ` + + `-C $outDir/jni/${archString} $$(echo $$jni_files | xargs -n1 printf " -f %s")`, + CommandDeps: []string{"${config.SoongZipCmd}"}, + }, + "outDir", "archString") + // Unzip an AAR into its constituent files and directories. Any files in Outputs that don't exist in the AAR will be // touched to create an empty file. The res directory is not extracted, as it will be extracted in its own rule. var unzipAAR = pctx.AndroidStaticRule("unzipAAR", @@ -858,6 +899,31 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { ImplementationAndResourcesJars: android.PathsIfNonNil(a.classpathFile), ImplementationJars: android.PathsIfNonNil(a.classpathFile), }) + + if proptools.Bool(a.properties.Extract_jni) { + for _, t := range ctx.MultiTargets() { + arch := t.Arch.Abi[0] + path := android.PathForModuleOut(ctx, arch+"_jni.zip") + a.jniPackages = append(a.jniPackages, path) + + outDir := android.PathForModuleOut(ctx, "aarForJni") + aarPath := android.PathForModuleSrc(ctx, a.properties.Aars[0]) + ctx.Build(pctx, android.BuildParams{ + Rule: extractJNI, + Input: aarPath, + Outputs: android.WritablePaths{path}, + Description: "extract JNI from AAR", + Args: map[string]string{ + "outDir": outDir.String(), + "archString": arch, + }, + }) + } + + ctx.SetProvider(JniPackageProvider, JniPackageInfo{ + JniPackages: a.jniPackages, + }) + } } func (a *AARImport) HeaderJars() android.Paths { @@ -893,7 +959,7 @@ func (g *AARImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, return nil } -var _ android.PrebuiltInterface = (*Import)(nil) +var _ android.PrebuiltInterface = (*AARImport)(nil) // android_library_import imports an `.aar` file into the build graph as if it was built with android_library. // @@ -906,6 +972,6 @@ func AARImportFactory() android.Module { android.InitPrebuiltModule(module, &module.properties.Aars) android.InitApexModule(module) - InitJavaModule(module, android.DeviceSupported) + InitJavaModuleMultiTargets(module, android.DeviceSupported) return module } diff --git a/java/aar_test.go b/java/aar_test.go new file mode 100644 index 000000000..8afa039c4 --- /dev/null +++ b/java/aar_test.go @@ -0,0 +1,83 @@ +// Copyright 2022 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package java + +import ( + "android/soong/android" + "testing" +) + +func TestAarImportProducesJniPackages(t *testing.T) { + ctx := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + ).RunTestWithBp(t, ` + android_library_import { + name: "aar-no-jni", + aars: ["aary.aar"], + } + android_library_import { + name: "aar-jni", + aars: ["aary.aar"], + extract_jni: true, + }`) + + testCases := []struct { + name string + hasPackage bool + }{ + { + name: "aar-no-jni", + hasPackage: false, + }, + { + name: "aar-jni", + hasPackage: true, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + appMod := ctx.Module(tc.name, "android_common") + appTestMod := ctx.ModuleForTests(tc.name, "android_common") + + info, ok := ctx.ModuleProvider(appMod, JniPackageProvider).(JniPackageInfo) + if !ok { + t.Errorf("expected android_library_import to have JniPackageProvider") + } + + if !tc.hasPackage { + if len(info.JniPackages) != 0 { + t.Errorf("expected JniPackages to be empty, but got %v", info.JniPackages) + } + outputFile := "arm64-v8a_jni.zip" + jniOutputLibZip := appTestMod.MaybeOutput(outputFile) + if jniOutputLibZip.Rule != nil { + t.Errorf("did not expect an output file, but found %v", outputFile) + } + return + } + + if len(info.JniPackages) != 1 { + t.Errorf("expected a single JniPackage, but got %v", info.JniPackages) + } + + outputFile := info.JniPackages[0].String() + jniOutputLibZip := appTestMod.Output(outputFile) + if jniOutputLibZip.Rule == nil { + t.Errorf("did not find output file %v", outputFile) + } + }) + } +} diff --git a/java/android_manifest.go b/java/android_manifest.go index c61823d06..522b6647a 100644 --- a/java/android_manifest.go +++ b/java/android_manifest.go @@ -45,7 +45,11 @@ var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger", // This enables release builds (that run with TARGET_BUILD_APPS=[val...]) to target APIs that have not yet been finalized as part of an SDK func targetSdkVersionForManifestFixer(ctx android.ModuleContext, sdkContext android.SdkContext) string { targetSdkVersionSpec := sdkContext.TargetSdkVersion(ctx) - if ctx.Config().UnbundledBuildApps() && targetSdkVersionSpec.ApiLevel.IsPreview() { + // Return 10000 for modules targeting "current" if either + // 1. The module is built in unbundled mode (TARGET_BUILD_APPS not empty) + // 2. The module is run as part of MTS, and should be testable on stable branches + // TODO(b/240294501): Determine the rules for handling test apexes + if targetSdkVersionSpec.ApiLevel.IsPreview() && (ctx.Config().UnbundledBuildApps() || includedInMts(ctx.Module())) { return strconv.Itoa(android.FutureApiLevel.FinalOrFutureInt()) } targetSdkVersion, err := targetSdkVersionSpec.EffectiveVersionString(ctx) @@ -55,16 +59,26 @@ func targetSdkVersionForManifestFixer(ctx android.ModuleContext, sdkContext andr return targetSdkVersion } +// Helper function that casts android.Module to java.androidTestApp +// If this type conversion is possible, it queries whether the test app is included in an MTS suite +func includedInMts(module android.Module) bool { + if test, ok := module.(androidTestApp); ok { + return test.includedInTestSuite("mts") + } + return false +} + type ManifestFixerParams struct { - SdkContext android.SdkContext - ClassLoaderContexts dexpreopt.ClassLoaderContextMap - IsLibrary bool - UseEmbeddedNativeLibs bool - UsesNonSdkApis bool - UseEmbeddedDex bool - HasNoCode bool - TestOnly bool - LoggingParent string + SdkContext android.SdkContext + ClassLoaderContexts dexpreopt.ClassLoaderContextMap + IsLibrary bool + DefaultManifestVersion string + UseEmbeddedNativeLibs bool + UsesNonSdkApis bool + UseEmbeddedDex bool + HasNoCode bool + TestOnly bool + LoggingParent string } // Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml @@ -153,6 +167,9 @@ func ManifestFixer(ctx android.ModuleContext, manifest android.Path, args = append(args, "--replaceMaxSdkVersionPlaceholder ", strconv.Itoa(replaceMaxSdkVersionPlaceholder.FinalOrFutureInt())) args = append(args, "--raise-min-sdk-version") } + if params.DefaultManifestVersion != "" { + args = append(args, "--override-placeholder-version", params.DefaultManifestVersion) + } fixedManifest := android.PathForModuleOut(ctx, "manifest_fixer", "AndroidManifest.xml") argsMapper["args"] = strings.Join(args, " ") diff --git a/java/app.go b/java/app.go index 23a9816b4..c3699784c 100755 --- a/java/app.go +++ b/java/app.go @@ -417,6 +417,9 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { a.aapt.splitNames = a.appProperties.Package_splits a.aapt.LoggingParent = String(a.overridableAppProperties.Logging_parent) + if a.Updatable() { + a.aapt.defaultManifestVersion = android.DefaultUpdatableModuleVersion + } a.aapt.buildActions(ctx, android.SdkContext(a), a.classLoaderContexts, a.usesLibraryProperties.Exclude_uses_libs, aaptLinkFlags...) @@ -472,14 +475,14 @@ func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path { return a.dexJarFile.PathOrNil() } -func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, ctx android.ModuleContext) android.WritablePath { +func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, prebuiltJniPackages android.Paths, ctx android.ModuleContext) android.WritablePath { var jniJarFile android.WritablePath - if len(jniLibs) > 0 { + if len(jniLibs) > 0 || len(prebuiltJniPackages) > 0 { a.jniLibs = jniLibs if a.shouldEmbedJnis(ctx) { jniJarFile = android.PathForModuleOut(ctx, "jnilibs.zip") a.installPathForJNISymbols = a.installPath(ctx) - TransformJniLibsToJar(ctx, jniJarFile, jniLibs, a.useEmbeddedNativeLibs(ctx)) + TransformJniLibsToJar(ctx, jniJarFile, jniLibs, prebuiltJniPackages, a.useEmbeddedNativeLibs(ctx)) for _, jni := range jniLibs { if jni.coverageFile.Valid() { // Only collect coverage for the first target arch if this is a multilib target. @@ -623,8 +626,8 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { dexJarFile := a.dexBuildActions(ctx) - jniLibs, certificateDeps := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis)) - jniJarFile := a.jniBuildActions(jniLibs, ctx) + jniLibs, prebuiltJniPackages, certificateDeps := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis)) + jniJarFile := a.jniBuildActions(jniLibs, prebuiltJniPackages, ctx) if ctx.Failed() { return @@ -724,9 +727,10 @@ type appDepsInterface interface { func collectAppDeps(ctx android.ModuleContext, app appDepsInterface, shouldCollectRecursiveNativeDeps bool, - checkNativeSdkVersion bool) ([]jniLib, []Certificate) { + checkNativeSdkVersion bool) ([]jniLib, android.Paths, []Certificate) { var jniLibs []jniLib + var prebuiltJniPackages android.Paths var certificates []Certificate seenModulePaths := make(map[string]bool) @@ -775,6 +779,10 @@ func collectAppDeps(ctx android.ModuleContext, app appDepsInterface, return shouldCollectRecursiveNativeDeps } + if info, ok := ctx.OtherModuleProvider(module, JniPackageProvider).(JniPackageInfo); ok { + prebuiltJniPackages = append(prebuiltJniPackages, info.JniPackages...) + } + if tag == certificateTag { if dep, ok := module.(*AndroidAppCertificate); ok { certificates = append(certificates, dep.Certificate) @@ -786,7 +794,7 @@ func collectAppDeps(ctx android.ModuleContext, app appDepsInterface, return false }) - return jniLibs, certificates + return jniLibs, prebuiltJniPackages, certificates } func (a *AndroidApp) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) { @@ -954,6 +962,18 @@ func (a *AndroidTest) InstallInTestcases() bool { return true } +type androidTestApp interface { + includedInTestSuite(searchPrefix string) bool +} + +func (a *AndroidTest) includedInTestSuite(searchPrefix string) bool { + return android.PrefixInList(a.testProperties.Test_suites, searchPrefix) +} + +func (a *AndroidTestHelperApp) includedInTestSuite(searchPrefix string) bool { + return android.PrefixInList(a.appTestHelperAppProperties.Test_suites, searchPrefix) +} + func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { var configs []tradefed.Config if a.appTestProperties.Instrumentation_target_package != nil { diff --git a/java/app_builder.go b/java/app_builder.go index 4a18dcada..434864484 100644 --- a/java/app_builder.go +++ b/java/app_builder.go @@ -218,8 +218,14 @@ func BuildBundleModule(ctx android.ModuleContext, outputFile android.WritablePat }) } -func TransformJniLibsToJar(ctx android.ModuleContext, outputFile android.WritablePath, - jniLibs []jniLib, uncompressJNI bool) { +const jniJarOutputPathString = "jniJarOutput.zip" + +func TransformJniLibsToJar( + ctx android.ModuleContext, + outputFile android.WritablePath, + jniLibs []jniLib, + prebuiltJniPackages android.Paths, + uncompressJNI bool) { var deps android.Paths jarArgs := []string{ @@ -245,13 +251,20 @@ func TransformJniLibsToJar(ctx android.ModuleContext, outputFile android.Writabl rule = zipRE args["implicits"] = strings.Join(deps.Strings(), ",") } + jniJarPath := android.PathForModuleOut(ctx, jniJarOutputPathString) ctx.Build(pctx, android.BuildParams{ Rule: rule, Description: "zip jni libs", - Output: outputFile, + Output: jniJarPath, Implicits: deps, Args: args, }) + ctx.Build(pctx, android.BuildParams{ + Rule: mergeAssetsRule, + Description: "merge prebuilt JNI packages", + Inputs: append(prebuiltJniPackages, jniJarPath), + Output: outputFile, + }) } func targetToJniDir(target android.Target) string { diff --git a/java/app_import.go b/java/app_import.go index b017eca60..9d199d60b 100644 --- a/java/app_import.go +++ b/java/app_import.go @@ -256,7 +256,7 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext ctx.ModuleErrorf("One and only one of certficate, presigned, and default_dev_cert properties must be set") } - _, certificates := collectAppDeps(ctx, a, false, false) + _, _, certificates := collectAppDeps(ctx, a, false, false) // TODO: LOCAL_EXTRACT_APK/LOCAL_EXTRACT_DPI_APK // TODO: LOCAL_PACKAGE_SPLITS diff --git a/java/app_test.go b/java/app_test.go index c4ac4dfdb..0f973ba16 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -1218,7 +1218,7 @@ func TestJNIABI(t *testing.T) { for _, test := range testCases { t.Run(test.name, func(t *testing.T) { app := ctx.ModuleForTests(test.name, "android_common") - jniLibZip := app.Output("jnilibs.zip") + jniLibZip := app.Output(jniJarOutputPathString) var abis []string args := strings.Fields(jniLibZip.Args["jarArgs"]) for i := 0; i < len(args); i++ { @@ -1351,7 +1351,7 @@ func TestJNIPackaging(t *testing.T) { for _, test := range testCases { t.Run(test.name, func(t *testing.T) { app := ctx.ModuleForTests(test.name, "android_common") - jniLibZip := app.MaybeOutput("jnilibs.zip") + jniLibZip := app.MaybeOutput(jniJarOutputPathString) if g, w := (jniLibZip.Rule != nil), test.packaged; g != w { t.Errorf("expected jni packaged %v, got %v", w, g) } @@ -1442,7 +1442,7 @@ func TestJNISDK(t *testing.T) { t.Run(test.name, func(t *testing.T) { app := ctx.ModuleForTests(test.name, "android_common") - jniLibZip := app.MaybeOutput("jnilibs.zip") + jniLibZip := app.MaybeOutput(jniJarOutputPathString) if len(jniLibZip.Implicits) != 1 { t.Fatalf("expected exactly one jni library, got %q", jniLibZip.Implicits.Strings()) } @@ -2425,7 +2425,7 @@ func TestStl(t *testing.T) { for _, test := range testCases { t.Run(test.name, func(t *testing.T) { app := ctx.ModuleForTests(test.name, "android_common") - jniLibZip := app.Output("jnilibs.zip") + jniLibZip := app.Output(jniJarOutputPathString) var jnis []string args := strings.Fields(jniLibZip.Args["jarArgs"]) for i := 0; i < len(args); i++ { @@ -3074,3 +3074,151 @@ func TestAppMissingCertificateAllowMissingDependencies(t *testing.T) { } android.AssertStringDoesContain(t, "expected error rule message", fooApk.Args["error"], "missing dependencies: missing_certificate\n") } + +func TestAppIncludesJniPackages(t *testing.T) { + ctx := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + ).RunTestWithBp(t, ` + android_library_import { + name: "aary-nodeps", + aars: ["aary.aar"], + extract_jni: true, + } + + android_library { + name: "aary-lib", + sdk_version: "current", + min_sdk_version: "21", + static_libs: ["aary-nodeps"], + } + + android_app { + name: "aary-lib-dep", + sdk_version: "current", + min_sdk_version: "21", + manifest: "AndroidManifest.xml", + static_libs: ["aary-lib"], + use_embedded_native_libs: true, + } + + android_app { + name: "aary-import-dep", + sdk_version: "current", + min_sdk_version: "21", + manifest: "AndroidManifest.xml", + static_libs: ["aary-nodeps"], + use_embedded_native_libs: true, + } + + android_app { + name: "aary-no-use-embedded", + sdk_version: "current", + min_sdk_version: "21", + manifest: "AndroidManifest.xml", + static_libs: ["aary-nodeps"], + }`) + + testCases := []struct { + name string + hasPackage bool + }{ + { + name: "aary-import-dep", + hasPackage: true, + }, + { + name: "aary-lib-dep", + hasPackage: true, + }, + { + name: "aary-no-use-embedded", + hasPackage: false, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + app := ctx.ModuleForTests(tc.name, "android_common") + + outputFile := "jnilibs.zip" + jniOutputLibZip := app.MaybeOutput(outputFile) + if jniOutputLibZip.Rule == nil && !tc.hasPackage { + return + } + + jniPackage := "arm64-v8a_jni.zip" + inputs := jniOutputLibZip.Inputs + foundPackage := false + for i := 0; i < len(inputs); i++ { + if strings.Contains(inputs[i].String(), jniPackage) { + foundPackage = true + } + } + if foundPackage != tc.hasPackage { + t.Errorf("expected to find %v in %v inputs; inputs = %v", jniPackage, outputFile, inputs) + } + }) + } +} + +func TestTargetSdkVersionMtsTests(t *testing.T) { + platformSdkCodename := "Tiramisu" + android_test := "android_test" + android_test_helper_app := "android_test_helper_app" + bpTemplate := ` + %v { + name: "mytest", + target_sdk_version: "%v", + test_suites: ["othersuite", "%v"], + } + ` + testCases := []struct { + desc string + moduleType string + targetSdkVersionInBp string + targetSdkVersionExpected string + testSuites string + }{ + { + desc: "Non-MTS android_test_apps targeting current should not be upgraded to 10000", + moduleType: android_test, + targetSdkVersionInBp: "current", + targetSdkVersionExpected: platformSdkCodename, + testSuites: "non-mts-suite", + }, + { + desc: "MTS android_test_apps targeting released sdks should not be upgraded to 10000", + moduleType: android_test, + targetSdkVersionInBp: "29", + targetSdkVersionExpected: "29", + testSuites: "mts-suite", + }, + { + desc: "MTS android_test_apps targeting current should be upgraded to 10000", + moduleType: android_test, + targetSdkVersionInBp: "current", + targetSdkVersionExpected: "10000", + testSuites: "mts-suite", + }, + { + desc: "MTS android_test_helper_apps targeting current should be upgraded to 10000", + moduleType: android_test_helper_app, + targetSdkVersionInBp: "current", + targetSdkVersionExpected: "10000", + testSuites: "mts-suite", + }, + } + fixture := android.GroupFixturePreparers( + prepareForJavaTest, + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.Platform_sdk_codename = &platformSdkCodename + variables.Platform_version_active_codenames = []string{platformSdkCodename} + }), + ) + for _, testCase := range testCases { + result := fixture.RunTestWithBp(t, fmt.Sprintf(bpTemplate, testCase.moduleType, testCase.targetSdkVersionInBp, testCase.testSuites)) + mytest := result.ModuleForTests("mytest", "android_common") + manifestFixerArgs := mytest.Output("manifest_fixer/AndroidManifest.xml").Args["args"] + android.AssertStringDoesContain(t, testCase.desc, manifestFixerArgs, "--targetSdkVersion "+testCase.targetSdkVersionExpected) + } +} diff --git a/java/dex.go b/java/dex.go index c943938e2..a44d7921f 100644 --- a/java/dex.go +++ b/java/dex.go @@ -42,6 +42,9 @@ type DexProperties struct { // True if the module containing this has it set by default. EnabledByDefault bool `blueprint:"mutated"` + // Whether to continue building even if warnings are emitted. Defaults to true. + Ignore_warnings *bool + // If true, runs R8 in Proguard compatibility mode (default). // Otherwise, runs R8 in full mode. Proguard_compatibility *bool @@ -293,7 +296,10 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Fl } // TODO(b/180878971): missing classes should be added to the relevant builds. - r8Flags = append(r8Flags, "-ignorewarnings") + // TODO(b/229727645): do not use true as default for Android platform builds. + if proptools.BoolDefault(opt.Ignore_warnings, true) { + r8Flags = append(r8Flags, "-ignorewarnings") + } return r8Flags, r8Deps } diff --git a/java/dex_test.go b/java/dex_test.go index fbdccb65d..a3e2deda4 100644 --- a/java/dex_test.go +++ b/java/dex_test.go @@ -59,6 +59,36 @@ func TestR8(t *testing.T) { appR8.Args["r8Flags"], libHeader.String()) android.AssertStringDoesNotContain(t, "expected no static_lib header jar in app javac classpath", appR8.Args["r8Flags"], staticLibHeader.String()) + android.AssertStringDoesContain(t, "expected -ignorewarnings in app r8 flags", + appR8.Args["r8Flags"], "-ignorewarnings") +} + +func TestR8Flags(t *testing.T) { + result := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd.RunTestWithBp(t, ` + android_app { + name: "app", + srcs: ["foo.java"], + platform_apis: true, + optimize: { + shrink: false, + optimize: false, + obfuscate: false, + ignore_warnings: false, + }, + } + `) + + app := result.ModuleForTests("app", "android_common") + appR8 := app.Rule("r8") + android.AssertStringDoesContain(t, "expected -dontshrink in app r8 flags", + appR8.Args["r8Flags"], "-dontshrink") + android.AssertStringDoesContain(t, "expected -dontoptimize in app r8 flags", + appR8.Args["r8Flags"], "-dontoptimize") + android.AssertStringDoesContain(t, "expected -dontobfuscate in app r8 flags", + appR8.Args["r8Flags"], "-dontobfuscate") + android.AssertStringDoesNotContain(t, "expected no -ignorewarnings in app r8 flags", + appR8.Args["r8Flags"], "-ignorewarnings") + } func TestD8(t *testing.T) { diff --git a/java/java.go b/java/java.go index dae69dcdc..f4ec04ef4 100644 --- a/java/java.go +++ b/java/java.go @@ -24,6 +24,7 @@ import ( "strings" "android/soong/bazel" + "android/soong/bazel/cquery" "github.com/google/blueprint" "github.com/google/blueprint/proptools" @@ -1610,7 +1611,8 @@ func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { } } -func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { +func (j *Import) commonBuildActions(ctx android.ModuleContext) { + //TODO(b/231322772) these should come from Bazel once available j.sdkVersion = j.SdkVersion(ctx) j.minSdkVersion = j.MinSdkVersion(ctx) @@ -1621,6 +1623,10 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { if ctx.Windows() { j.HideFromMake() } +} + +func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { + j.commonBuildActions(ctx) jars := android.PathsForModuleSrc(ctx, j.properties.Jars) @@ -1662,19 +1668,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { addCLCFromDep(ctx, module, j.classLoaderContexts) }) - if Bool(j.properties.Installable) { - var installDir android.InstallPath - if ctx.InstallInTestcases() { - var archDir string - if !ctx.Host() { - archDir = ctx.DeviceConfig().DeviceArch() - } - installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir) - } else { - installDir = android.PathForModuleInstall(ctx, "framework") - } - ctx.InstallFile(installDir, jarName, outputFile) - } + j.maybeInstall(ctx, jarName, outputFile) j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs) @@ -1748,6 +1742,24 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { }) } +func (j *Import) maybeInstall(ctx android.ModuleContext, jarName string, outputFile android.Path) { + if !Bool(j.properties.Installable) { + return + } + + var installDir android.InstallPath + if ctx.InstallInTestcases() { + var archDir string + if !ctx.Host() { + archDir = ctx.DeviceConfig().DeviceArch() + } + installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir) + } else { + installDir = android.PathForModuleInstall(ctx, "framework") + } + ctx.InstallFile(installDir, jarName, outputFile) +} + func (j *Import) OutputFiles(tag string) (android.Paths, error) { switch tag { case "", ".jar": @@ -2046,9 +2058,7 @@ func DexImportFactory() android.Module { return module } -// // Defaults -// type Defaults struct { android.ModuleBase android.DefaultsModuleBase @@ -2063,29 +2073,29 @@ type Defaults struct { // // Example: // -// java_defaults { -// name: "example_defaults", -// srcs: ["common/**/*.java"], -// javacflags: ["-Xlint:all"], -// aaptflags: ["--auto-add-overlay"], -// } +// java_defaults { +// name: "example_defaults", +// srcs: ["common/**/*.java"], +// javacflags: ["-Xlint:all"], +// aaptflags: ["--auto-add-overlay"], +// } // -// java_library { -// name: "example", -// defaults: ["example_defaults"], -// srcs: ["example/**/*.java"], -// } +// java_library { +// name: "example", +// defaults: ["example_defaults"], +// srcs: ["example/**/*.java"], +// } // // is functionally identical to: // -// java_library { -// name: "example", -// srcs: [ -// "common/**/*.java", -// "example/**/*.java", -// ], -// javacflags: ["-Xlint:all"], -// } +// java_library { +// name: "example", +// srcs: [ +// "common/**/*.java", +// "example/**/*.java", +// ], +// javacflags: ["-Xlint:all"], +// } func DefaultsFactory() android.Module { module := &Defaults{} @@ -2483,5 +2493,54 @@ func (i *Import) ConvertWithBp2build(ctx android.TopDownMutatorContext) { props := bazel.BazelTargetModuleProperties{Rule_class: "java_import"} ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: android.RemoveOptionalPrebuiltPrefix(i.Name())}, attrs) +} + +var _ android.MixedBuildBuildable = (*Import)(nil) + +func (i *Import) getBazelModuleLabel(ctx android.BaseModuleContext) string { + return android.RemoveOptionalPrebuiltPrefixFromBazelLabel(i.GetBazelLabel(ctx, i)) +} + +func (i *Import) ProcessBazelQueryResponse(ctx android.ModuleContext) { + i.commonBuildActions(ctx) + + bazelCtx := ctx.Config().BazelContext + filePaths, err := bazelCtx.GetOutputFiles(i.getBazelModuleLabel(ctx), android.GetConfigKey(ctx)) + if err != nil { + ctx.ModuleErrorf(err.Error()) + return + } + + bazelJars := android.Paths{} + for _, bazelOutputFile := range filePaths { + bazelJars = append(bazelJars, android.PathForBazelOut(ctx, bazelOutputFile)) + } + + jarName := android.RemoveOptionalPrebuiltPrefix(i.Name()) + ".jar" + outputFile := android.PathForModuleOut(ctx, "bazelCombined", jarName) + TransformJarsToJar(ctx, outputFile, "combine prebuilt jars", bazelJars, + android.OptionalPath{}, // manifest + false, // stripDirEntries + []string{}, // filesToStrip + []string{}, // dirsToStrip + ) + i.combinedClasspathFile = outputFile + + ctx.SetProvider(JavaInfoProvider, JavaInfo{ + HeaderJars: android.PathsIfNonNil(i.combinedClasspathFile), + ImplementationAndResourcesJars: android.PathsIfNonNil(i.combinedClasspathFile), + ImplementationJars: android.PathsIfNonNil(i.combinedClasspathFile), + //TODO(b/240308299) include AIDL information from Bazel + }) + i.maybeInstall(ctx, jarName, outputFile) +} + +func (i *Import) QueueBazelCall(ctx android.BaseModuleContext) { + bazelCtx := ctx.Config().BazelContext + bazelCtx.QueueBazelRequest(i.getBazelModuleLabel(ctx), cquery.GetOutputFiles, android.GetConfigKey(ctx)) +} + +func (i *Import) IsMixedBuildSupported(ctx android.BaseModuleContext) bool { + return true } diff --git a/java/java_test.go b/java/java_test.go index 32b0b0f68..9e5cf0cf2 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1667,3 +1667,48 @@ func TestDataDeviceBinsBuildsDeviceBinary(t *testing.T) { }) } } + +func TestImportMixedBuild(t *testing.T) { + bp := ` + java_import { + name: "baz", + jars: [ + "test1.jar", + "test2.jar", + ], + bazel_module: { label: "//foo/bar:baz" }, + } + ` + + ctx := android.GroupFixturePreparers( + prepareForJavaTest, + android.FixtureModifyConfig(func(config android.Config) { + config.BazelContext = android.MockBazelContext{ + OutputBaseDir: "outputbase", + LabelToOutputFiles: map[string][]string{ + "//foo/bar:baz": []string{"test1.jar", "test2.jar"}, + }, + } + }), + ).RunTestWithBp(t, bp) + + bazMod := ctx.ModuleForTests("baz", "android_common").Module() + producer := bazMod.(android.OutputFileProducer) + expectedOutputFiles := []string{".intermediates/baz/android_common/bazelCombined/baz.jar"} + + outputFiles, err := producer.OutputFiles("") + if err != nil { + t.Errorf("Unexpected error getting java_import outputfiles %s", err) + } + actualOutputFiles := android.NormalizePathsForTesting(outputFiles) + android.AssertDeepEquals(t, "Output files are produced", expectedOutputFiles, actualOutputFiles) + + javaInfoProvider := ctx.ModuleProvider(bazMod, JavaInfoProvider) + javaInfo, ok := javaInfoProvider.(JavaInfo) + if !ok { + t.Error("could not get JavaInfo from java_import module") + } + android.AssertDeepEquals(t, "Header JARs are produced", expectedOutputFiles, android.NormalizePathsForTesting(javaInfo.HeaderJars)) + android.AssertDeepEquals(t, "Implementation/Resources JARs are produced", expectedOutputFiles, android.NormalizePathsForTesting(javaInfo.ImplementationAndResourcesJars)) + android.AssertDeepEquals(t, "Implementation JARs are produced", expectedOutputFiles, android.NormalizePathsForTesting(javaInfo.ImplementationJars)) +} diff --git a/java/lint.go b/java/lint.go index e276345eb..c27ca9821 100644 --- a/java/lint.go +++ b/java/lint.go @@ -338,6 +338,14 @@ func (l *linter) lint(ctx android.ModuleContext) { ctx.PropertyErrorf("lint.disabled_checks", "Can't disable %v checks if min_sdk_version is different from sdk_version.", filtered) } + + // TODO(b/238784089): Remove this workaround when the NewApi issues have been addressed in PermissionController + if ctx.ModuleName() == "PermissionController" { + l.extraMainlineLintErrors = android.FilterListPred(l.extraMainlineLintErrors, func(s string) bool { + return s != "NewApi" + }) + l.properties.Lint.Warning_checks = append(l.properties.Lint.Warning_checks, "NewApi") + } } extraLintCheckModules := ctx.GetDirectDepsWithTag(extraLintCheckTag) diff --git a/java/lint_defaults.txt b/java/lint_defaults.txt index 1eee354cd..e99cb05c5 100644 --- a/java/lint_defaults.txt +++ b/java/lint_defaults.txt @@ -6,6 +6,7 @@ --disable_check AnimatorKeep --disable_check AppBundleLocaleChanges +--disable_check AppCompatCustomView --disable_check BlockedPrivateApi --disable_check CustomSplashScreen --disable_check CustomX509TrustManager @@ -22,6 +23,7 @@ --disable_check PrivateApi --disable_check ProtectedPermissions --disable_check QueryPermissionsNeeded +--disable_check ReservedSystemPermission --disable_check ScopedStorage --disable_check ServiceCast --disable_check SoonBlockedPrivateApi @@ -99,7 +101,10 @@ --warning_check WrongViewCast # 1 occurences in 1 modules --warning_check CoarseFineLocation +--warning_check ExtraText --warning_check IntentFilterExportedReceiver +--warning_check MissingInflatedId +--warning_check NotificationPermission --warning_check QueryAllPackagesPermission --warning_check RemoteViewLayout --warning_check SupportAnnotationUsage diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go index f442ddfd4..1c4249507 100644 --- a/java/platform_compat_config.go +++ b/java/platform_compat_config.go @@ -26,12 +26,14 @@ import ( func init() { registerPlatformCompatConfigBuildComponents(android.InitRegistrationContext) - android.RegisterSdkMemberType(&compatConfigMemberType{ - SdkMemberTypeBase: android.SdkMemberTypeBase{ - PropertyName: "compat_configs", - SupportsSdk: true, - }, - }) + android.RegisterSdkMemberType(CompatConfigSdkMemberType) +} + +var CompatConfigSdkMemberType = &compatConfigMemberType{ + SdkMemberTypeBase: android.SdkMemberTypeBase{ + PropertyName: "compat_configs", + SupportsSdk: true, + }, } func registerPlatformCompatConfigBuildComponents(ctx android.RegistrationContext) { diff --git a/java/rro.go b/java/rro.go index 7952c2cc4..9c8c53b15 100644 --- a/java/rro.go +++ b/java/rro.go @@ -142,7 +142,7 @@ func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleC r.aapt.buildActions(ctx, r, nil, nil, aaptLinkFlags...) // Sign the built package - _, certificates := collectAppDeps(ctx, r, false, false) + _, _, certificates := collectAppDeps(ctx, r, false, false) certificates = processMainCert(r.ModuleBase, String(r.properties.Certificate), certificates, ctx) signed := android.PathForModuleOut(ctx, "signed", r.Name()+".apk") var lineageFile android.Path diff --git a/licenses/Android.bp b/licenses/Android.bp index 8db001f44..133f7f783 100644 --- a/licenses/Android.bp +++ b/licenses/Android.bp @@ -32,6 +32,15 @@ license { } license_kind { + name: "BSD-Like-Binary-Only", + conditions: [ + "notice", + "by_exception_only", + "proprietary", + ], +} + +license_kind { name: "SPDX-license-identifier-0BSD", conditions: ["unencumbered"], url: "https://spdx.org/licenses/0BSD", diff --git a/linkerconfig/linkerconfig.go b/linkerconfig/linkerconfig.go index 003b27507..412a23b26 100644 --- a/linkerconfig/linkerconfig.go +++ b/linkerconfig/linkerconfig.go @@ -22,6 +22,7 @@ import ( "github.com/google/blueprint/proptools" "android/soong/android" + "android/soong/bazel" "android/soong/cc" "android/soong/etc" ) @@ -36,7 +37,7 @@ func init() { } func registerLinkerConfigBuildComponent(ctx android.RegistrationContext) { - ctx.RegisterModuleType("linker_config", linkerConfigFactory) + ctx.RegisterModuleType("linker_config", LinkerConfigFactory) } type linkerConfigProperties struct { @@ -52,6 +53,7 @@ type linkerConfigProperties struct { type linkerConfig struct { android.ModuleBase + android.BazelModuleBase properties linkerConfigProperties outputFilePath android.OutputPath @@ -100,6 +102,28 @@ func (l *linkerConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) { ctx.InstallFile(l.installDirPath, l.outputFilePath.Base(), l.outputFilePath) } +type linkerConfigAttributes struct { + Src bazel.LabelAttribute +} + +func (l *linkerConfig) ConvertWithBp2build(ctx android.TopDownMutatorContext) { + if l.properties.Src == nil { + ctx.PropertyErrorf("src", "empty src is not supported") + return + } + src := android.BazelLabelForModuleSrcSingle(ctx, *l.properties.Src) + targetModuleProperties := bazel.BazelTargetModuleProperties{ + Rule_class: "linker_config", + Bzl_load_location: "//build/bazel/rules:linker_config.bzl", + } + ctx.CreateBazelTargetModule( + targetModuleProperties, + android.CommonAttributes{Name: l.Name()}, + &linkerConfigAttributes{ + Src: bazel.LabelAttribute{Value: &src}, + }) +} + func BuildLinkerConfig(ctx android.ModuleContext, builder *android.RuleBuilder, input android.Path, otherModules []android.Module, output android.OutputPath) { @@ -141,10 +165,11 @@ func BuildLinkerConfig(ctx android.ModuleContext, builder *android.RuleBuilder, // linker_config generates protobuf file from json file. This protobuf file will be used from // linkerconfig while generating ld.config.txt. Format of this file can be found from // https://android.googlesource.com/platform/system/linkerconfig/+/master/README.md -func linkerConfigFactory() android.Module { +func LinkerConfigFactory() android.Module { m := &linkerConfig{} m.AddProperties(&m.properties) android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibFirst) + android.InitBazelModule(m) return m } diff --git a/rust/OWNERS b/rust/OWNERS index ddaebc522..b59551160 100644 --- a/rust/OWNERS +++ b/rust/OWNERS @@ -1,5 +1,2 @@ # Additional owner/reviewers for rust rules, including parent directory owners. per-file * = chiw@google.com, chriswailes@google.com, ivanlozano@google.com, jeffv@google.com, mmaurer@google.com, srhines@google.com - -# Limited owners/reviewers of the allowed list. -per-file allowed_list.go = chiw@google.com, chriswailes@google.com, ivanlozano@google.com, jeffv@google.com, mmaurer@google.com, srhines@google.com diff --git a/rust/config/Android.bp b/rust/config/Android.bp index ba40cb0a6..be73d69eb 100644 --- a/rust/config/Android.bp +++ b/rust/config/Android.bp @@ -16,7 +16,6 @@ bootstrap_go_package { "global.go", "lints.go", "toolchain.go", - "allowed_list.go", "darwin_host.go", "x86_linux_bionic_host.go", "x86_linux_host.go", diff --git a/rust/config/allowed_list.go b/rust/config/allowed_list.go deleted file mode 100644 index 9129b0e10..000000000 --- a/rust/config/allowed_list.go +++ /dev/null @@ -1,79 +0,0 @@ -package config - -var ( - // When adding a new path below, add a rustfmt.toml file at the root of - // the repository and enable the rustfmt repo hook. See aosp/1458238 - // for an example. - // TODO(b/160223496): enable rustfmt globally. - RustAllowedPaths = []string{ - "device/google/cuttlefish", - "external/adhd", - "external/boringssl", - "external/crosvm", - "external/libchromeos-rs", - "external/minijail", - "external/open-dice", - "external/rust", - "external/selinux/libselinux", - "external/uwb", - "external/vm_tools/p9", - "frameworks/native/libs/binder/rust", - "frameworks/proto_logging/stats", - "hardware/interfaces/security", - "hardware/interfaces/uwb", - "packages/modules/Bluetooth", - "packages/modules/DnsResolver", - "packages/modules/Uwb", - "packages/modules/Virtualization", - "platform_testing/tests/codecoverage/native/rust", - "prebuilts/rust", - "system/core/debuggerd/rust", - "system/core/libstats/pull_rust", - "system/core/trusty/libtrusty-rs", - "system/core/trusty/keymint", - "system/extras/profcollectd", - "system/extras/simpleperf", - "system/hardware/interfaces/keystore2", - "system/keymint", - "system/librustutils", - "system/logging/liblog", - "system/logging/rust", - "system/nfc", - "system/security", - "system/tools/aidl", - "tools/security/fuzzing/example_rust_fuzzer", - "tools/security/fuzzing/orphans", - "tools/security/remote_provisioning/cert_validator", - "tools/vendor", - "vendor/", - } - - DownstreamRustAllowedPaths = []string{ - // Add downstream allowed Rust paths here. - } - - RustModuleTypes = []string{ - // Don't add rust_bindgen or rust_protobuf as these are code generation modules - // and can be expected to be in paths without Rust code. - "rust_benchmark", - "rust_benchmark_host", - "rust_binary", - "rust_binary_host", - "rust_library", - "rust_library_dylib", - "rust_library_rlib", - "rust_ffi", - "rust_ffi_shared", - "rust_ffi_static", - "rust_fuzz", - "rust_library_host", - "rust_library_host_dylib", - "rust_library_host_rlib", - "rust_ffi_host", - "rust_ffi_host_shared", - "rust_ffi_host_static", - "rust_proc_macro", - "rust_test", - "rust_test_host", - } -) diff --git a/rust/config/global.go b/rust/config/global.go index 9e48344b8..9acbfb355 100644 --- a/rust/config/global.go +++ b/rust/config/global.go @@ -24,7 +24,7 @@ import ( var pctx = android.NewPackageContext("android/soong/rust/config") var ( - RustDefaultVersion = "1.62.0" + RustDefaultVersion = "1.62.0.p1" RustDefaultBase = "prebuilts/rust/" DefaultEdition = "2021" Stdlibs = []string{ diff --git a/rust/rust.go b/rust/rust.go index d5d492971..4d9fe4c03 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -33,13 +33,6 @@ import ( var pctx = android.NewPackageContext("android/soong/rust") func init() { - // Only allow rust modules to be defined for certain projects - - android.AddNeverAllowRules( - android.NeverAllow(). - NotIn(append(config.RustAllowedPaths, config.DownstreamRustAllowedPaths...)...). - ModuleType(config.RustModuleTypes...)) - android.RegisterModuleType("rust_defaults", defaultsFactory) android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { ctx.BottomUp("rust_libraries", LibraryMutator).Parallel() diff --git a/scripts/manifest_fixer.py b/scripts/manifest_fixer.py index 2da29ee91..58079aa5d 100755 --- a/scripts/manifest_fixer.py +++ b/scripts/manifest_fixer.py @@ -70,6 +70,8 @@ def parse_args(): parser.add_argument('--test-only', dest='test_only', action='store_true', help=('adds testOnly="true" attribute to application. Assign true value if application elem ' 'already has a testOnly attribute.')) + parser.add_argument('--override-placeholder-version', dest='new_version', + help='Overrides the versionCode if it\'s set to the placeholder value of 0') parser.add_argument('input', help='input AndroidManifest.xml file') parser.add_argument('output', help='output AndroidManifest.xml file') return parser.parse_args() @@ -362,6 +364,19 @@ def set_max_sdk_version(doc, max_sdk_version): if max_attr and max_attr.value == 'current': max_attr.value = max_sdk_version +def override_placeholder_version(doc, new_version): + """Replace the versionCode attribute value if it\'s currently + set to the placeholder version of 0. + + Args: + doc: The XML document. May be modified by this function. + new_version: The new version to set if versionCode is equal to 0. + """ + manifest = parse_manifest(doc) + version = manifest.getAttribute("android:versionCode") + if (version == '0'): + manifest.setAttribute("android:versionCode", new_version) + def main(): """Program entry point.""" try: @@ -401,6 +416,9 @@ def main(): if args.extract_native_libs is not None: add_extract_native_libs(doc, args.extract_native_libs) + if args.new_version: + override_placeholder_version(doc, args.new_version) + with open(args.output, 'w') as f: write_xml(f, doc) diff --git a/scripts/manifest_fixer_test.py b/scripts/manifest_fixer_test.py index dad104a54..0a62b10a4 100755 --- a/scripts/manifest_fixer_test.py +++ b/scripts/manifest_fixer_test.py @@ -643,5 +643,39 @@ class SetMaxSdkVersionTest(unittest.TestCase): output = self.run_test(manifest_input, '9000') self.assert_xml_equal(output, expected) +class OverrideDefaultVersionTest(unittest.TestCase): + """Unit tests for override_default_version function.""" + + def assert_xml_equal(self, output, expected): + self.assertEqual(ET.canonicalize(output), ET.canonicalize(expected)) + + def run_test(self, input_manifest, version): + doc = minidom.parseString(input_manifest) + manifest_fixer.override_placeholder_version(doc, version) + output = io.StringIO() + manifest_fixer.write_xml(output, doc) + return output.getvalue() + + manifest_tmpl = ( + '<?xml version="1.0" encoding="utf-8"?>\n' + '<manifest xmlns:android="http://schemas.android.com/apk/res/android" ' + 'android:versionCode="%s">\n' + '</manifest>\n') + + def test_doesnt_override_existing_version(self): + """Tests that an existing version is not overridden""" + manifest_input = self.manifest_tmpl % '12345' + expected = manifest_input + output = self.run_test(manifest_input, '67890') + self.assert_xml_equal(output, expected) + + def test_overrides_default_version(self): + """Tests that a default version is overridden""" + manifest_input = self.manifest_tmpl % '0' + expected = self.manifest_tmpl % '67890' + output = self.run_test(manifest_input, '67890') + self.assert_xml_equal(output, expected) + + if __name__ == '__main__': unittest.main(verbosity=2) diff --git a/sdk/compat_config_sdk_test.go b/sdk/compat_config_sdk_test.go index d166add00..45e8e0ed6 100644 --- a/sdk/compat_config_sdk_test.go +++ b/sdk/compat_config_sdk_test.go @@ -21,16 +21,12 @@ import ( "android/soong/java" ) -func TestSnapshotWithCompatConfig(t *testing.T) { +func testSnapshotWithCompatConfig(t *testing.T, sdk string) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, java.PrepareForTestWithPlatformCompatConfig, - ).RunTestWithBp(t, ` - sdk { - name: "mysdk", - compat_configs: ["myconfig"], - } - + prepareForSdkTestWithApex, + ).RunTestWithBp(t, sdk+` platform_compat_config { name: "myconfig", } @@ -73,3 +69,28 @@ prebuilt_platform_compat_config { }), ) } + +func TestSnapshotWithCompatConfig(t *testing.T) { + testSnapshotWithCompatConfig(t, ` + sdk { + name: "mysdk", + compat_configs: ["myconfig"], + } +`) +} + +func TestSnapshotWithCompatConfig_Apex(t *testing.T) { + testSnapshotWithCompatConfig(t, ` + apex { + name: "myapex", + key: "myapex.key", + min_sdk_version: "2", + compat_configs: ["myconfig"], + } + + sdk { + name: "mysdk", + apexes: ["myapex"], + } +`) +} diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index 57c171fed..7ab5285c6 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -1339,9 +1339,9 @@ java_sdk_library_import { .intermediates/myjavalib.stubs.source.module_lib/android_common/metalava/myjavalib.stubs.source.module_lib_removed.txt -> sdk_library/module-lib/myjavalib-removed.txt `), checkMergeZips( + ".intermediates/mysdk/common_os/tmp/sdk_library/module-lib/myjavalib_stub_sources.zip", ".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip", ".intermediates/mysdk/common_os/tmp/sdk_library/system/myjavalib_stub_sources.zip", - ".intermediates/mysdk/common_os/tmp/sdk_library/module-lib/myjavalib_stub_sources.zip", ), ) } diff --git a/sdk/update.go b/sdk/update.go index 995da741c..c555ddc7a 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -108,7 +108,7 @@ var ( mergeZips = pctx.AndroidStaticRule("SnapshotMergeZips", blueprint.RuleParams{ - Command: `${config.MergeZipsCmd} $out $in`, + Command: `${config.MergeZipsCmd} -s $out $in`, CommandDeps: []string{ "${config.MergeZipsCmd}", }, @@ -481,7 +481,7 @@ be unnecessary as every module in the sdk already has its own licenses property. // Copy the build number file into the snapshot. builder.CopyToSnapshot(ctx.Config().BuildNumberFile(ctx), BUILD_NUMBER_FILE) - filesToZip := builder.filesToZip + filesToZip := android.SortedUniquePaths(builder.filesToZip) // zip them all zipPath := fmt.Sprintf("%s%s.zip", ctx.ModuleName(), snapshotFileSuffix) @@ -517,7 +517,7 @@ be unnecessary as every module in the sdk already has its own licenses property. Description: outputDesc, Rule: mergeZips, Input: zipFile, - Inputs: builder.zipsToMerge, + Inputs: android.SortedUniquePaths(builder.zipsToMerge), Output: outputZipFile, }) } diff --git a/ui/build/build.go b/ui/build/build.go index ec42b7004..5b80b4df8 100644 --- a/ui/build/build.go +++ b/ui/build/build.go @@ -183,8 +183,8 @@ func checkRAM(ctx Context, config Config) { } } -// Build the tree. The 'what' argument can be used to chose which components of -// the build to run, via checking various bitmasks. +// Build the tree. Various flags in `config` govern which components of +// the build to run. func Build(ctx Context, config Config) { ctx.Verboseln("Starting build with args:", config.Arguments()) ctx.Verboseln("Environment:", config.Environment().Environ()) diff --git a/ui/build/cleanbuild.go b/ui/build/cleanbuild.go index 1c80cff31..fd601772c 100644 --- a/ui/build/cleanbuild.go +++ b/ui/build/cleanbuild.go @@ -167,6 +167,7 @@ func installClean(ctx Context, config Config) { productOut("debug_ramdisk"), productOut("vendor_ramdisk"), productOut("vendor_debug_ramdisk"), + productOut("vendor_kernel_ramdisk"), productOut("test_harness_ramdisk"), productOut("recovery"), productOut("root"), diff --git a/ui/build/soong.go b/ui/build/soong.go index 8992b4f07..cfcf99028 100644 --- a/ui/build/soong.go +++ b/ui/build/soong.go @@ -544,7 +544,7 @@ func loadSoongBuildMetrics(ctx Context, config Config) *soong_metrics_proto.Soon buf, err := os.ReadFile(soongBuildMetricsFile) if errors.Is(err, fs.ErrNotExist) { // Soong may not have run during this invocation - ctx.Verbosef("Failed to read metrics file, %s: %s", soongBuildMetricsFile, err) + ctx.Verbosef("Failed to read metrics file, %s: %s", soongBuildMetricsFile, err) return nil } else if err != nil { ctx.Fatalf("Failed to load %s: %s", soongBuildMetricsFile, err) diff --git a/ui/terminal/simple_status.go b/ui/terminal/simple_status.go index cef3b5d5c..9e9ffc003 100644 --- a/ui/terminal/simple_status.go +++ b/ui/terminal/simple_status.go @@ -22,30 +22,24 @@ import ( ) type simpleStatusOutput struct { - writer io.Writer - formatter formatter - keepANSI bool - outputLevel status.MsgLevel + writer io.Writer + formatter formatter + keepANSI bool } // NewSimpleStatusOutput returns a StatusOutput that represents the // current build status similarly to Ninja's built-in terminal // output. -func NewSimpleStatusOutput(w io.Writer, formatter formatter, keepANSI bool, quietBuild bool) status.StatusOutput { - level := status.StatusLvl - if quietBuild { - level = status.PrintLvl - } +func NewSimpleStatusOutput(w io.Writer, formatter formatter, keepANSI bool) status.StatusOutput { return &simpleStatusOutput{ - writer: w, - formatter: formatter, - keepANSI: keepANSI, - outputLevel: level, + writer: w, + formatter: formatter, + keepANSI: keepANSI, } } func (s *simpleStatusOutput) Message(level status.MsgLevel, message string) { - if level >= s.outputLevel { + if level >= status.StatusLvl { output := s.formatter.message(level, message) if !s.keepANSI { output = string(stripAnsiEscapes([]byte(output))) @@ -54,13 +48,10 @@ func (s *simpleStatusOutput) Message(level status.MsgLevel, message string) { } } -func (s *simpleStatusOutput) StartAction(_ *status.Action, _ status.Counts) { +func (s *simpleStatusOutput) StartAction(action *status.Action, counts status.Counts) { } func (s *simpleStatusOutput) FinishAction(result status.ActionResult, counts status.Counts) { - if s.outputLevel > status.StatusLvl { - return - } str := result.Description if str == "" { str = result.Command diff --git a/ui/terminal/status.go b/ui/terminal/status.go index ff0af4737..2ad174fee 100644 --- a/ui/terminal/status.go +++ b/ui/terminal/status.go @@ -29,9 +29,9 @@ import ( func NewStatusOutput(w io.Writer, statusFormat string, forceSimpleOutput, quietBuild, forceKeepANSI bool) status.StatusOutput { formatter := newFormatter(statusFormat, quietBuild) - if forceSimpleOutput || quietBuild || !isSmartTerminal(w) { - return NewSimpleStatusOutput(w, formatter, forceKeepANSI, quietBuild) - } else { + if !forceSimpleOutput && isSmartTerminal(w) { return NewSmartStatusOutput(w, formatter) + } else { + return NewSimpleStatusOutput(w, formatter, forceKeepANSI) } } |