diff options
Diffstat (limited to 'android')
| -rw-r--r-- | android/bazel.go | 6 | ||||
| -rw-r--r-- | android/bazel_handler.go | 26 | ||||
| -rw-r--r-- | android/bazel_paths.go | 51 | ||||
| -rw-r--r-- | android/config.go | 10 | ||||
| -rw-r--r-- | android/image.go | 7 | ||||
| -rw-r--r-- | android/testing.go | 10 |
6 files changed, 82 insertions, 28 deletions
diff --git a/android/bazel.go b/android/bazel.go index b9d707090..992d8aa27 100644 --- a/android/bazel.go +++ b/android/bazel.go @@ -218,11 +218,7 @@ var ( // Per-module denylist to opt modules out of mixed builds. Such modules will // still be generated via bp2build. - mixedBuildsDisabledList = []string{ - "libc", // b/190211183, missing libbionic_Slibdl_Sliblibdl_Ubp2build_Ucc_Ulibrary_Ushared.so - "libdl", // b/190211183, missing libbionic_Slinker_Slibld-android_Ubp2build_Ucc_Ulibrary_Ushared.so - "libdl_android", // b/190211183, missing libbionic_Slinker_Slibld-android_Ubp2build_Ucc_Ulibrary_Ushared.so - } + mixedBuildsDisabledList = []string{} // Used for quicker lookups bp2buildModuleDoNotConvert = map[string]bool{} diff --git a/android/bazel_handler.go b/android/bazel_handler.go index f906c8add..b11b4743e 100644 --- a/android/bazel_handler.go +++ b/android/bazel_handler.go @@ -542,10 +542,13 @@ def get_arch(target): platform_name = build_options(target)["//command_line_option:platforms"][0].name if platform_name == "host": return "HOST" - elif not platform_name.startswith("android_"): - fail("expected platform name of the form 'android_<arch>', but was " + str(platforms)) + elif platform_name.startswith("android_"): + return platform_name[len("android_"):] + elif platform_name.startswith("linux_"): + return platform_name[len("linux_"):] + else: + fail("expected platform name of the form 'android_<arch>' or 'linux_<arch>', but was " + str(platforms)) return "UNKNOWN" - return platform_name[len("android_"):] def format(target): id_string = str(target.label) + "|" + get_arch(target) @@ -742,8 +745,17 @@ func (c *bazelSingleton) GenerateBuildActions(ctx SingletonContext) { } rule := NewRuleBuilder(pctx, ctx) cmd := rule.Command() - cmd.Text(fmt.Sprintf("cd %s/execroot/__main__ && %s", - ctx.Config().BazelContext.OutputBase(), buildStatement.Command)) + + // cd into Bazel's execution root, which is the action cwd. + cmd.Text(fmt.Sprintf("cd %s/execroot/__main__ && ", ctx.Config().BazelContext.OutputBase())) + + for _, pair := range buildStatement.Env { + // Set per-action env variables, if any. + cmd.Flag(pair.Key + "=" + pair.Value) + } + + // The actual Bazel action. + cmd.Text(" " + buildStatement.Command) for _, outputPath := range buildStatement.OutputPaths { cmd.ImplicitOutput(PathForBazelOut(ctx, outputPath)) @@ -756,6 +768,10 @@ func (c *bazelSingleton) GenerateBuildActions(ctx SingletonContext) { cmd.ImplicitDepFile(PathForBazelOut(ctx, *depfile)) } + for _, symlinkPath := range buildStatement.SymlinkPaths { + cmd.ImplicitSymlinkOutput(PathForBazelOut(ctx, symlinkPath)) + } + // This is required to silence warnings pertaining to unexpected timestamps. Particularly, // some Bazel builtins (such as files in the bazel_tools directory) have far-future // timestamps. Without restat, Ninja would emit warnings that the input files of a diff --git a/android/bazel_paths.go b/android/bazel_paths.go index f93fe2b5e..f74fed13f 100644 --- a/android/bazel_paths.go +++ b/android/bazel_paths.go @@ -83,6 +83,36 @@ type BazelConversionPathContext interface { // or ":<module>") and returns a Bazel-compatible label which corresponds to dependencies on the // module within the given ctx. func BazelLabelForModuleDeps(ctx BazelConversionPathContext, modules []string) bazel.LabelList { + return bazelLabelForModuleDeps(ctx, modules, false) +} + +// BazelLabelForModuleWholeDeps expects a list of references to other modules, ("<module>" +// or ":<module>") and returns a Bazel-compatible label which corresponds to dependencies on the +// module within the given ctx, where prebuilt dependencies will be appended with _alwayslink so +// they can be handled as whole static libraries. +func BazelLabelForModuleWholeDeps(ctx BazelConversionPathContext, modules []string) bazel.LabelList { + return bazelLabelForModuleDeps(ctx, modules, true) +} + +// BazelLabelForModuleDepsExcludes expects two lists: modules (containing modules to include in the +// list), and excludes (modules to exclude from the list). Both of these should contain references +// to other modules, ("<module>" or ":<module>"). It returns a Bazel-compatible label list which +// corresponds to dependencies on the module within the given ctx, and the excluded dependencies. +func BazelLabelForModuleDepsExcludes(ctx BazelConversionPathContext, modules, excludes []string) bazel.LabelList { + return bazelLabelForModuleDepsExcludes(ctx, modules, excludes, false) +} + +// BazelLabelForModuleWholeDepsExcludes expects two lists: modules (containing modules to include in +// the list), and excludes (modules to exclude from the list). Both of these should contain +// references to other modules, ("<module>" or ":<module>"). It returns a Bazel-compatible label +// list which corresponds to dependencies on the module within the given ctx, and the excluded +// dependencies. Prebuilt dependencies will be appended with _alwayslink so they can be handled as +// whole static libraries. +func BazelLabelForModuleWholeDepsExcludes(ctx BazelConversionPathContext, modules, excludes []string) bazel.LabelList { + return bazelLabelForModuleDepsExcludes(ctx, modules, excludes, true) +} + +func bazelLabelForModuleDeps(ctx BazelConversionPathContext, modules []string, isWholeLibs bool) bazel.LabelList { var labels bazel.LabelList for _, module := range modules { bpText := module @@ -90,7 +120,7 @@ func BazelLabelForModuleDeps(ctx BazelConversionPathContext, modules []string) b module = ":" + module } if m, t := SrcIsModuleWithTag(module); m != "" { - l := getOtherModuleLabel(ctx, m, t) + l := getOtherModuleLabel(ctx, m, t, isWholeLibs) l.OriginalModuleName = bpText labels.Includes = append(labels.Includes, l) } else { @@ -100,16 +130,12 @@ func BazelLabelForModuleDeps(ctx BazelConversionPathContext, modules []string) b return labels } -// BazelLabelForModuleDeps expects two lists: modules (containing modules to include in the list), -// and excludes (modules to exclude from the list). Both of these should contain references to other -// modules, ("<module>" or ":<module>"). It returns a Bazel-compatible label list which corresponds -// to dependencies on the module within the given ctx, and the excluded dependencies. -func BazelLabelForModuleDepsExcludes(ctx BazelConversionPathContext, modules, excludes []string) bazel.LabelList { - moduleLabels := BazelLabelForModuleDeps(ctx, RemoveListFromList(modules, excludes)) +func bazelLabelForModuleDepsExcludes(ctx BazelConversionPathContext, modules, excludes []string, isWholeLibs bool) bazel.LabelList { + moduleLabels := bazelLabelForModuleDeps(ctx, RemoveListFromList(modules, excludes), isWholeLibs) if len(excludes) == 0 { return moduleLabels } - excludeLabels := BazelLabelForModuleDeps(ctx, excludes) + excludeLabels := bazelLabelForModuleDeps(ctx, excludes, isWholeLibs) return bazel.LabelList{ Includes: moduleLabels.Includes, Excludes: excludeLabels.Includes, @@ -273,7 +299,7 @@ func expandSrcsForBazel(ctx BazelConversionPathContext, paths, expandedExcludes for _, p := range paths { if m, tag := SrcIsModuleWithTag(p); m != "" { - l := getOtherModuleLabel(ctx, m, tag) + l := getOtherModuleLabel(ctx, m, tag, false) if !InList(l.Label, expandedExcludes) { l.OriginalModuleName = fmt.Sprintf(":%s", m) labels.Includes = append(labels.Includes, l) @@ -304,7 +330,7 @@ func expandSrcsForBazel(ctx BazelConversionPathContext, paths, expandedExcludes // getOtherModuleLabel returns a bazel.Label for the given dependency/tag combination for the // module. The label will be relative to the current directory if appropriate. The dependency must // already be resolved by either deps mutator or path deps mutator. -func getOtherModuleLabel(ctx BazelConversionPathContext, dep, tag string) bazel.Label { +func getOtherModuleLabel(ctx BazelConversionPathContext, dep, tag string, isWholeLibs bool) bazel.Label { m, _ := ctx.GetDirectDep(dep) if m == nil { panic(fmt.Errorf(`Cannot get direct dep %q of %q. @@ -313,6 +339,11 @@ func getOtherModuleLabel(ctx BazelConversionPathContext, dep, tag string) bazel. } otherLabel := bazelModuleLabel(ctx, m, tag) label := bazelModuleLabel(ctx, ctx.Module(), "") + if isWholeLibs { + if m, ok := m.(Module); ok && IsModulePrebuilt(m) { + otherLabel += "_alwayslink" + } + } if samePackage(label, otherLabel) { otherLabel = bazelShortLabel(otherLabel) } diff --git a/android/config.go b/android/config.go index da78c7a12..ed90c3181 100644 --- a/android/config.go +++ b/android/config.go @@ -1690,6 +1690,16 @@ func (l *ConfiguredJarList) BuildPaths(ctx PathContext, dir OutputPath) Writable return paths } +// BuildPathsByModule returns a map from module name to build paths based on the given directory +// prefix. +func (l *ConfiguredJarList) BuildPathsByModule(ctx PathContext, dir OutputPath) map[string]WritablePath { + paths := map[string]WritablePath{} + for _, jar := range l.jars { + paths[jar] = dir.Join(ctx, ModuleStem(jar)+".jar") + } + return paths +} + // UnmarshalJSON converts JSON configuration from raw bytes into a // ConfiguredJarList structure. func (l *ConfiguredJarList) UnmarshalJSON(b []byte) error { diff --git a/android/image.go b/android/image.go index 66101be02..bc6b8cd86 100644 --- a/android/image.go +++ b/android/image.go @@ -43,10 +43,9 @@ type ImageInterface interface { // its variation. ExtraImageVariations(ctx BaseModuleContext) []string - // SetImageVariation will be passed a newly created recovery variant of the module. ModuleBase implements - // SetImageVariation, most module types will not need to override it, and those that do must call the - // overridden method. Implementors of SetImageVariation must be careful to modify the module argument - // and not the receiver. + // SetImageVariation is called for each newly created image variant. The receiver is the original + // module, "variation" is the name of the newly created variant and "module" is the newly created + // variant itself. SetImageVariation(ctx BaseModuleContext, variation string, module Module) } diff --git a/android/testing.go b/android/testing.go index 191cb8d02..b36f62cce 100644 --- a/android/testing.go +++ b/android/testing.go @@ -713,9 +713,11 @@ func (b baseTestingComponent) newTestingBuildParams(bparams BuildParams) Testing func (b baseTestingComponent) maybeBuildParamsFromRule(rule string) (TestingBuildParams, []string) { var searchedRules []string - for _, p := range b.provider.BuildParamsForTests() { - searchedRules = append(searchedRules, p.Rule.String()) - if strings.Contains(p.Rule.String(), rule) { + buildParams := b.provider.BuildParamsForTests() + for _, p := range buildParams { + ruleAsString := p.Rule.String() + searchedRules = append(searchedRules, ruleAsString) + if strings.Contains(ruleAsString, rule) { return b.newTestingBuildParams(p), searchedRules } } @@ -725,7 +727,7 @@ func (b baseTestingComponent) maybeBuildParamsFromRule(rule string) (TestingBuil func (b baseTestingComponent) buildParamsFromRule(rule string) TestingBuildParams { p, searchRules := b.maybeBuildParamsFromRule(rule) if p.Rule == nil { - panic(fmt.Errorf("couldn't find rule %q.\nall rules: %v", rule, searchRules)) + panic(fmt.Errorf("couldn't find rule %q.\nall rules:\n%s", rule, strings.Join(searchRules, "\n"))) } return p } |