diff options
Diffstat (limited to 'java')
| -rw-r--r-- | java/Android.bp | 1 | ||||
| -rw-r--r-- | java/aar.go | 190 | ||||
| -rwxr-xr-x | java/app.go | 264 | ||||
| -rw-r--r-- | java/base.go | 53 | ||||
| -rw-r--r-- | java/config/config.go | 4 | ||||
| -rw-r--r-- | java/device_host_converter.go | 34 | ||||
| -rw-r--r-- | java/droiddoc.go | 25 | ||||
| -rw-r--r-- | java/droidstubs.go | 23 | ||||
| -rw-r--r-- | java/droidstubs_test.go | 42 | ||||
| -rw-r--r-- | java/gen.go | 14 | ||||
| -rw-r--r-- | java/generated_java_library.go | 7 | ||||
| -rw-r--r-- | java/generated_java_library_test.go | 3 | ||||
| -rw-r--r-- | java/genrule.go | 2 | ||||
| -rw-r--r-- | java/java.go | 703 | ||||
| -rw-r--r-- | java/java_test.go | 118 | ||||
| -rw-r--r-- | java/platform_compat_config.go | 23 | ||||
| -rw-r--r-- | java/plugin.go | 38 | ||||
| -rw-r--r-- | java/prebuilt_apis.go | 42 | ||||
| -rw-r--r-- | java/proto.go | 79 | ||||
| -rw-r--r-- | java/sdk_library.go | 72 |
20 files changed, 7 insertions, 1730 deletions
diff --git a/java/Android.bp b/java/Android.bp index d39a1954b..79cd3f923 100644 --- a/java/Android.bp +++ b/java/Android.bp @@ -11,7 +11,6 @@ bootstrap_go_package { "soong", "soong-aconfig", "soong-android", - "soong-bazel", "soong-cc", "soong-dexpreopt", "soong-genrule", diff --git a/java/aar.go b/java/aar.go index 1ab452965..af99cd0eb 100644 --- a/java/aar.go +++ b/java/aar.go @@ -22,10 +22,7 @@ import ( "strings" "android/soong/android" - "android/soong/bazel" "android/soong/dexpreopt" - "android/soong/ui/metrics/bp2build_metrics_proto" - "github.com/google/blueprint" "github.com/google/blueprint/proptools" ) @@ -768,7 +765,6 @@ func aaptLibs(ctx android.ModuleContext, sdkContext android.SdkContext, classLoa type AndroidLibrary struct { Library aapt - android.BazelModuleBase androidLibraryProperties androidLibraryProperties @@ -905,7 +901,6 @@ func AndroidLibraryFactory() android.Module { android.InitApexModule(module) InitJavaModule(module, android.DeviceSupported) - android.InitBazelModule(module) return module } @@ -944,7 +939,6 @@ type AARImport struct { android.ModuleBase android.DefaultableModuleBase android.ApexModuleBase - android.BazelModuleBase prebuilt android.Prebuilt // Functionality common to Module and Import. @@ -1316,189 +1310,5 @@ func AARImportFactory() android.Module { android.InitPrebuiltModule(module, &module.properties.Aars) android.InitApexModule(module) InitJavaModuleMultiTargets(module, android.DeviceSupported) - android.InitBazelModule(module) return module } - -type bazelAapt struct { - Manifest bazel.Label - Resource_files bazel.LabelListAttribute - Resource_zips bazel.LabelListAttribute - Assets_dir bazel.StringAttribute - Assets bazel.LabelListAttribute -} - -type bazelAndroidLibrary struct { - *javaLibraryAttributes - *bazelAapt -} - -type bazelAndroidLibraryImport struct { - Aar bazel.Label - Deps bazel.LabelListAttribute - Exports bazel.LabelListAttribute - Sdk_version bazel.StringAttribute -} - -func (a *aapt) convertAaptAttrsWithBp2Build(ctx android.Bp2buildMutatorContext) (*bazelAapt, bool) { - manifest := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml") - - resourceFiles := bazel.LabelList{ - Includes: []bazel.Label{}, - } - for _, dir := range android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res") { - files := android.RootToModuleRelativePaths(ctx, androidResourceGlob(ctx, dir)) - resourceFiles.Includes = append(resourceFiles.Includes, files...) - } - - assetsDir := bazel.StringAttribute{} - var assets bazel.LabelList - for i, dir := range android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Asset_dirs, "assets") { - if i > 0 { - ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_PROPERTY_UNSUPPORTED, "multiple asset_dirs") - return &bazelAapt{}, false - } - // Assets_dirs are relative to the module dir when specified, but if the default in used in - // PathsWithOptionalDefaultForModuleSrc, then dir is relative to the top. - assetsRelDir, error := filepath.Rel(ctx.ModuleDir(), dir.Rel()) - if error != nil { - assetsRelDir = dir.Rel() - } - assetsDir.Value = proptools.StringPtr(assetsRelDir) - assets = bazel.MakeLabelList(android.RootToModuleRelativePaths(ctx, androidResourceGlob(ctx, dir))) - - } - var resourceZips bazel.LabelList - if len(a.aaptProperties.Resource_zips) > 0 { - if ctx.ModuleName() == "framework-res" { - resourceZips = android.BazelLabelForModuleSrc(ctx, a.aaptProperties.Resource_zips) - } else { - //TODO: b/301593550 - Implement support for this - ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_PROPERTY_UNSUPPORTED, "resource_zips") - return &bazelAapt{}, false - } - } - return &bazelAapt{ - android.BazelLabelForModuleSrcSingle(ctx, manifest), - bazel.MakeLabelListAttribute(resourceFiles), - bazel.MakeLabelListAttribute(resourceZips), - assetsDir, - bazel.MakeLabelListAttribute(assets), - }, true -} - -func (a *AARImport) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - if len(a.properties.Aars) == 0 { - ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_PROPERTY_UNSUPPORTED, "aars can't be empty") - return - } - aars := android.BazelLabelForModuleSrcExcludes(ctx, a.properties.Aars, []string{}) - exportableStaticLibs := []string{} - // TODO(b/240716882): investigate and handle static_libs deps that are not imports. They are not supported for export by Bazel. - for _, depName := range a.properties.Static_libs { - if dep, ok := ctx.ModuleFromName(depName); ok { - switch dep.(type) { - case *AARImport, *Import: - exportableStaticLibs = append(exportableStaticLibs, depName) - } - } - } - name := android.RemoveOptionalPrebuiltPrefix(a.Name()) - deps := android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(android.CopyOf(append(a.properties.Static_libs, a.properties.Libs...)))) - exports := android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(exportableStaticLibs)) - - ctx.CreateBazelTargetModule( - bazel.BazelTargetModuleProperties{ - Rule_class: "aar_import", - Bzl_load_location: "//build/bazel/rules/android:aar_import.bzl", - }, - android.CommonAttributes{Name: name}, - &bazelAndroidLibraryImport{ - Aar: aars.Includes[0], - Deps: bazel.MakeLabelListAttribute(deps), - Exports: bazel.MakeLabelListAttribute(exports), - Sdk_version: bazel.StringAttribute{Value: a.properties.Sdk_version}, - }, - ) - - neverlink := true - ctx.CreateBazelTargetModule( - AndroidLibraryBazelTargetModuleProperties(), - android.CommonAttributes{Name: name + "-neverlink"}, - &bazelAndroidLibrary{ - javaLibraryAttributes: &javaLibraryAttributes{ - Neverlink: bazel.BoolAttribute{Value: &neverlink}, - Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}), - javaCommonAttributes: &javaCommonAttributes{ - Sdk_version: bazel.StringAttribute{Value: a.properties.Sdk_version}, - }, - }, - }, - ) - -} -func AndroidLibraryBazelTargetModuleProperties() bazel.BazelTargetModuleProperties { - return bazel.BazelTargetModuleProperties{ - Rule_class: "android_library", - Bzl_load_location: "//build/bazel/rules/android:android_library.bzl", - } -} - -func (a *AndroidLibrary) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - commonAttrs, bp2buildInfo, supported := a.convertLibraryAttrsBp2Build(ctx) - if !supported { - return - } - - depLabels := bp2buildInfo.DepLabels - - deps := depLabels.Deps - if !commonAttrs.Srcs.IsEmpty() { - deps.Append(depLabels.StaticDeps) // we should only append these if there are sources to use them - } else if !depLabels.Deps.IsEmpty() { - // android_library does not accept deps when there are no srcs because - // there is no compilation happening, but it accepts exports. - // The non-empty deps here are unnecessary as deps on the android_library - // since they aren't being propagated to any dependencies. - // So we can drop deps here. - deps = bazel.LabelListAttribute{} - } - name := a.Name() - props := AndroidLibraryBazelTargetModuleProperties() - - aaptAttrs, supported := a.convertAaptAttrsWithBp2Build(ctx) - if !supported { - return - } - if hasJavaResources := aaptAttrs.ConvertJavaResources(ctx, commonAttrs); hasJavaResources { - return - } - ctx.CreateBazelTargetModule( - props, - android.CommonAttributes{Name: name}, - &bazelAndroidLibrary{ - &javaLibraryAttributes{ - javaCommonAttributes: commonAttrs, - Deps: deps, - Exports: depLabels.StaticDeps, - }, - aaptAttrs, - }, - ) - - neverlink := true - ctx.CreateBazelTargetModule( - props, - android.CommonAttributes{Name: name + "-neverlink"}, - &bazelAndroidLibrary{ - javaLibraryAttributes: &javaLibraryAttributes{ - Neverlink: bazel.BoolAttribute{Value: &neverlink}, - Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}), - javaCommonAttributes: &javaCommonAttributes{ - Sdk_version: bazel.StringAttribute{Value: a.deviceProperties.Sdk_version}, - Java_version: bazel.StringAttribute{Value: a.properties.Java_version}, - }, - }, - }, - ) -} diff --git a/java/app.go b/java/app.go index b2b6ed32c..d5c4ebaaf 100755 --- a/java/app.go +++ b/java/app.go @@ -29,12 +29,10 @@ import ( "github.com/google/blueprint/proptools" "android/soong/android" - "android/soong/bazel" "android/soong/cc" "android/soong/dexpreopt" "android/soong/genrule" "android/soong/tradefed" - "android/soong/ui/metrics/bp2build_metrics_proto" ) func init() { @@ -184,7 +182,6 @@ type overridableAppProperties struct { } type AndroidApp struct { - android.BazelModuleBase Library aapt android.OverridableModuleBase @@ -1173,7 +1170,6 @@ func AndroidAppFactory() android.Module { android.InitDefaultableModule(module) android.InitOverridableModule(module, &module.overridableAppProperties.Overrides) android.InitApexModule(module) - android.InitBazelModule(module) android.AddLoadHook(module, func(ctx android.LoadHookContext) { a := ctx.Module().(*AndroidApp) @@ -1258,8 +1254,6 @@ type AndroidTest struct { testConfig android.Path extraTestConfigs android.Paths data android.Paths - - android.BazelModuleBase } func (a *AndroidTest) InstallInTestcases() bool { @@ -1386,7 +1380,6 @@ func AndroidTestFactory() android.Module { android.InitDefaultableModule(module) android.InitOverridableModule(module, &module.overridableAppProperties.Overrides) - android.InitBazelModule(module) return module } @@ -1410,8 +1403,6 @@ type AndroidTestHelperApp struct { AndroidApp appTestHelperAppProperties appTestHelperAppProperties - - android.BazelModuleBase } func (a *AndroidTestHelperApp) InstallInTestcases() bool { @@ -1443,13 +1434,11 @@ func AndroidTestHelperAppFactory() android.Module { android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) android.InitApexModule(module) - android.InitBazelModule(module) return module } type AndroidAppCertificate struct { android.ModuleBase - android.BazelModuleBase properties AndroidAppCertificateProperties Certificate Certificate @@ -1466,7 +1455,6 @@ func AndroidAppCertificateFactory() android.Module { module := &AndroidAppCertificate{} module.AddProperties(&module.properties) android.InitAndroidModule(module) - android.InitBazelModule(module) return module } @@ -1743,255 +1731,3 @@ func (u *usesLibrary) verifyUsesLibrariesManifest(ctx android.ModuleContext, man func (u *usesLibrary) verifyUsesLibrariesAPK(ctx android.ModuleContext, apk android.Path) { u.verifyUsesLibraries(ctx, apk, nil) // for APKs manifest_check does not write output file } - -// For Bazel / bp2build - -type bazelAndroidAppCertificateAttributes struct { - Certificate string -} - -func (m *AndroidAppCertificate) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - androidAppCertificateBp2Build(ctx, m) -} - -func androidAppCertificateBp2Build(ctx android.Bp2buildMutatorContext, module *AndroidAppCertificate) { - var certificate string - if module.properties.Certificate != nil { - certificate = *module.properties.Certificate - } - - attrs := &bazelAndroidAppCertificateAttributes{ - Certificate: certificate, - } - - props := bazel.BazelTargetModuleProperties{ - Rule_class: "android_app_certificate", - Bzl_load_location: "//build/bazel/rules/android:android_app_certificate.bzl", - } - - ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs) -} - -type manifestValueAttribute struct { - MinSdkVersion *string - TargetSdkVersion *string -} - -type bazelAndroidAppAttributes struct { - *javaCommonAttributes - *bazelAapt - Deps bazel.LabelListAttribute - Custom_package *string - Certificate bazel.LabelAttribute - Certificate_name bazel.StringAttribute - Manifest_values *manifestValueAttribute - Optimize *bool - Proguard_specs bazel.LabelListAttribute - Updatable *bool -} - -func (b bazelAapt) ConvertJavaResources(ctx android.Bp2buildMutatorContext, javaAttrs *javaCommonAttributes) bool { - // TODO (b/300470246) bp2build support for java_resources & java_resource_dirs in android rules - hasJavaResources := !javaAttrs.javaResourcesAttributes.Resources.IsEmpty() - if hasJavaResources { - ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_UNSUPPORTED, "(b/300470246) java resources in android_* module") - } - return hasJavaResources -} - -func convertWithBp2build(ctx android.Bp2buildMutatorContext, a *AndroidApp) (bool, android.CommonAttributes, *bazelAndroidAppAttributes) { - aapt, supported := a.convertAaptAttrsWithBp2Build(ctx) - if !supported { - return false, android.CommonAttributes{}, &bazelAndroidAppAttributes{} - } - if a.appProperties.Jni_uses_platform_apis != nil { - ctx.MarkBp2buildUnconvertible( - bp2build_metrics_proto.UnconvertedReasonType_UNSUPPORTED, - "TODO - b/299360988: Add bp2build support for jni_uses_platform_apis", - ) - return false, android.CommonAttributes{}, &bazelAndroidAppAttributes{} - } - if a.appProperties.Jni_uses_sdk_apis != nil { - ctx.MarkBp2buildUnconvertible( - bp2build_metrics_proto.UnconvertedReasonType_UNSUPPORTED, - "TODO - b/299360988: Add bp2build support for jni_uses_sdk_apis", - ) - return false, android.CommonAttributes{}, &bazelAndroidAppAttributes{} - } - - certificate, certificateName := android.BazelStringOrLabelFromProp(ctx, a.overridableAppProperties.Certificate) - - manifestValues := &manifestValueAttribute{ - MinSdkVersion: a.deviceProperties.Min_sdk_version, - TargetSdkVersion: a.deviceProperties.Target_sdk_version, - } - - appAttrs := &bazelAndroidAppAttributes{ - // TODO(b/209576404): handle package name override by product variable PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES - Custom_package: a.overridableAppProperties.Package_name, - Certificate: certificate, - Certificate_name: certificateName, - Manifest_values: manifestValues, - Updatable: a.appProperties.Updatable, - } - - // As framework-res has no sources, no deps in the Bazel sense, and java compilation, dexing and optimization is skipped by - // Soong specifically for it, return early here before any of the conversion work for the above is attempted. - if ctx.ModuleName() == "framework-res" { - appAttrs.bazelAapt = aapt - return true, android.CommonAttributes{Name: a.Name(), SkipData: proptools.BoolPtr(true)}, appAttrs - } - - // Optimization is.. - // - enabled by default for android_app, android_test_helper_app - // - disabled by default for android_test - // - // TODO(b/192032291): Disable android_test_helper_app optimization by - // default after auditing downstream usage. - if a.dexProperties.Optimize.EnabledByDefault != a.dexer.effectiveOptimizeEnabled() { - // Property is explicitly defined by default from default, so emit the Bazel attribute. - appAttrs.Optimize = proptools.BoolPtr(a.dexer.effectiveOptimizeEnabled()) - } - - if a.dexer.effectiveOptimizeEnabled() { - handCraftedFlags := "" - if Bool(a.dexProperties.Optimize.Ignore_warnings) { - handCraftedFlags += "-ignorewarning " - } - if !Bool(a.dexProperties.Optimize.Shrink) { - handCraftedFlags += "-dontshrink " - } - if !Bool(a.dexProperties.Optimize.Optimize) { - handCraftedFlags += "-dontoptimize " - } - if !Bool(a.dexProperties.Optimize.Obfuscate) { - handCraftedFlags += "-dontobfuscate " - } - appAttrs.Proguard_specs = bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, a.dexProperties.Optimize.Proguard_flags_files)) - if handCraftedFlags != "" { - generatedFlagFileRuleName := a.Name() + "_proguard_flags" - ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{ - Rule_class: "genrule", - }, android.CommonAttributes{ - Name: generatedFlagFileRuleName, - SkipData: proptools.BoolPtr(true), - }, &genrule.BazelGenruleAttributes{ - Outs: []string{a.Name() + "_proguard.flags"}, - Cmd: bazel.StringAttribute{ - Value: proptools.StringPtr("echo " + handCraftedFlags + "> $(OUTS)"), - }, - }) - appAttrs.Proguard_specs.Add(bazel.MakeLabelAttribute(":" + generatedFlagFileRuleName)) - } - } - - commonAttrs, bp2BuildInfo, supported := a.convertLibraryAttrsBp2Build(ctx) - if !supported { - return false, android.CommonAttributes{}, &bazelAndroidAppAttributes{} - } - if hasJavaResources := aapt.ConvertJavaResources(ctx, commonAttrs); hasJavaResources { - return false, android.CommonAttributes{}, &bazelAndroidAppAttributes{} - } - - depLabels := bp2BuildInfo.DepLabels - - deps := depLabels.Deps - deps.Append(depLabels.StaticDeps) - - var jniDeps bazel.LabelListAttribute - archVariantProps := a.GetArchVariantProperties(ctx, &appProperties{}) - for axis, configToProps := range archVariantProps { - for config, _props := range configToProps { - if archProps, ok := _props.(*appProperties); ok { - archJniLibs := android.BazelLabelForModuleDeps( - ctx, - android.LastUniqueStrings(android.CopyOf(archProps.Jni_libs))) - jniDeps.SetSelectValue(axis, config, archJniLibs) - } - } - } - deps.Append(jniDeps) - - if !bp2BuildInfo.hasKotlin { - appAttrs.javaCommonAttributes = commonAttrs - appAttrs.bazelAapt = aapt - appAttrs.Deps = deps - } else { - ktName := a.Name() + "_kt" - ctx.CreateBazelTargetModule( - AndroidLibraryBazelTargetModuleProperties(), - android.CommonAttributes{Name: ktName}, - &bazelAndroidLibrary{ - javaLibraryAttributes: &javaLibraryAttributes{ - javaCommonAttributes: commonAttrs, - Deps: deps, - }, - bazelAapt: aapt, - }, - ) - - appAttrs.bazelAapt = &bazelAapt{Manifest: aapt.Manifest} - appAttrs.Deps = bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + ktName}) - appAttrs.javaCommonAttributes = &javaCommonAttributes{ - Sdk_version: commonAttrs.Sdk_version, - } - } - - return true, android.CommonAttributes{Name: a.Name(), SkipData: proptools.BoolPtr(true)}, appAttrs -} - -// ConvertWithBp2build is used to convert android_app to Bazel. -func (a *AndroidApp) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - if ok, commonAttrs, appAttrs := convertWithBp2build(ctx, a); ok { - var props bazel.BazelTargetModuleProperties - if ctx.ModuleName() == "framework-res" { - props = bazel.BazelTargetModuleProperties{ - Rule_class: "framework_resources", - Bzl_load_location: "//build/bazel/rules/android:framework_resources.bzl", - } - } else { - props = bazel.BazelTargetModuleProperties{ - Rule_class: "android_binary", - Bzl_load_location: "//build/bazel/rules/android:android_binary.bzl", - } - } - ctx.CreateBazelTargetModule(props, commonAttrs, appAttrs) - } - -} - -// ConvertWithBp2build is used to convert android_test to Bazel. -func (at *AndroidTest) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - if ok, commonAttrs, appAttrs := convertWithBp2build(ctx, &at.AndroidApp); ok { - props := bazel.BazelTargetModuleProperties{ - Rule_class: "android_test", - Bzl_load_location: "//build/bazel/rules/android:android_test.bzl", - } - - ctx.CreateBazelTargetModule(props, commonAttrs, appAttrs) - } - -} - -func (atha *AndroidTestHelperApp) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - if ok, commonAttrs, appAttrs := convertWithBp2build(ctx, &atha.AndroidApp); ok { - // an android_test_helper_app is an android_binary with testonly = True - commonAttrs.Testonly = proptools.BoolPtr(true) - - // android_test_helper_app sets default values differently to android_app, - // https://cs.android.com/android/platform/superproject/main/+/main:build/soong/java/app.go;l=1273-1279;drc=e12c083198403ec694af6c625aed11327eb2bf7f - // - // installable: true (settable prop) - // use_embedded_native_libs: true (settable prop) - // lint.test: true (settable prop) - // AlwaysPackageNativeLibs: true (blueprint mutated prop) - // dexpreopt isTest: true (not prop) - - props := bazel.BazelTargetModuleProperties{ - Rule_class: "android_binary", - Bzl_load_location: "//build/bazel/rules/android:android_binary.bzl", - } - - ctx.CreateBazelTargetModule(props, commonAttrs, appAttrs) - } -} diff --git a/java/base.go b/java/base.go index c4b402620..cdb58a2f9 100644 --- a/java/base.go +++ b/java/base.go @@ -20,8 +20,6 @@ import ( "strconv" "strings" - "android/soong/ui/metrics/bp2build_metrics_proto" - "github.com/google/blueprint" "github.com/google/blueprint/pathtools" "github.com/google/blueprint/proptools" @@ -408,7 +406,6 @@ type Module struct { android.ModuleBase android.DefaultableModuleBase android.ApexModuleBase - android.BazelModuleBase // Functionality common to Module and Import. embeddableInModuleAndImport @@ -1038,37 +1035,6 @@ func (j *Module) collectJavacFlags( // just adding a symlink under the root doesn't help.) patchPaths := []string{".", ctx.Config().SoongOutDir()} - // b/150878007 - // - // Workaround to support *Bazel-executed* JDK9 javac in Bazel's - // execution root for --patch-module. If this javac command line is - // invoked within Bazel's execution root working directory, the top - // level directories (e.g. libcore/, tools/, frameworks/) are all - // symlinks. JDK9 javac does not traverse into symlinks, which causes - // --patch-module to fail source file lookups when invoked in the - // execution root. - // - // Short of patching javac or enumerating *all* directories as possible - // input dirs, manually add the top level dir of the source files to be - // compiled. - topLevelDirs := map[string]bool{} - for _, srcFilePath := range srcFiles { - srcFileParts := strings.Split(srcFilePath.String(), "/") - // Ignore source files that are already in the top level directory - // as well as generated files in the out directory. The out - // directory may be an absolute path, which means srcFileParts[0] is the - // empty string, so check that as well. Note that "out" in Bazel's execution - // root is *not* a symlink, which doesn't cause problems for --patch-modules - // anyway, so it's fine to not apply this workaround for generated - // source files. - if len(srcFileParts) > 1 && - srcFileParts[0] != "" && - srcFileParts[0] != "out" { - topLevelDirs[srcFileParts[0]] = true - } - } - patchPaths = append(patchPaths, android.SortedKeys(topLevelDirs)...) - classPath := flags.classpath.FormJavaClassPath("") if classPath != "" { patchPaths = append(patchPaths, classPath) @@ -2379,22 +2345,3 @@ type ModuleWithStem interface { } var _ ModuleWithStem = (*Module)(nil) - -func (j *Module) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - switch ctx.ModuleType() { - case "java_library", "java_library_host", "java_library_static", "tradefed_java_library_host": - if lib, ok := ctx.Module().(*Library); ok { - javaLibraryBp2Build(ctx, lib) - } - case "java_binary_host": - if binary, ok := ctx.Module().(*Binary); ok { - javaBinaryHostBp2Build(ctx, binary) - } - case "java_test_host": - if testHost, ok := ctx.Module().(*TestHost); ok { - javaTestHostBp2Build(ctx, testHost) - } - default: - ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "") - } -} diff --git a/java/config/config.go b/java/config/config.go index 009813078..d80ed4142 100644 --- a/java/config/config.go +++ b/java/config/config.go @@ -221,10 +221,6 @@ func init() { hostJNIToolVariableWithSdkToolsPrebuilt("SignapkJniLibrary", "libconscrypt_openjdk_jni") } -func BazelJavaToolchainVars(config android.Config) string { - return android.BazelToolchainVars(config, exportedVars) -} - func hostBinToolVariableWithSdkToolsPrebuilt(name, tool string) { pctx.VariableFunc(name, func(ctx android.PackageVarContext) string { if ctx.Config().AlwaysUsePrebuiltSdks() { diff --git a/java/device_host_converter.go b/java/device_host_converter.go index c5ba245ea..ee8a15a03 100644 --- a/java/device_host_converter.go +++ b/java/device_host_converter.go @@ -19,16 +19,12 @@ import ( "io" "android/soong/android" - "android/soong/bazel" "android/soong/dexpreopt" - - "github.com/google/blueprint/proptools" ) type DeviceHostConverter struct { android.ModuleBase android.DefaultableModuleBase - android.BazelModuleBase properties DeviceHostConverterProperties @@ -80,7 +76,6 @@ func HostForDeviceFactory() android.Module { module.AddProperties(&module.properties) InitJavaModule(module, android.DeviceSupported) - android.InitBazelModule(module) return module } @@ -193,32 +188,3 @@ func (d *DeviceHostConverter) AndroidMk() android.AndroidMkData { }, } } - -type bazelDeviceHostConverterAttributes struct { - Exports bazel.LabelListAttribute -} - -func (d *DeviceHostConverter) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - ctx.CreateBazelTargetModule( - bazel.BazelTargetModuleProperties{ - Rule_class: "java_host_for_device", - Bzl_load_location: "//build/bazel/rules/java:host_for_device.bzl", - }, - android.CommonAttributes{Name: d.Name()}, - &bazelDeviceHostConverterAttributes{ - Exports: bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, d.properties.Libs)), - }, - ) - neverLinkAttrs := &javaLibraryAttributes{ - Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + d.Name()}), - Neverlink: bazel.BoolAttribute{Value: proptools.BoolPtr(true)}, - javaCommonAttributes: &javaCommonAttributes{ - Sdk_version: bazel.StringAttribute{Value: proptools.StringPtr("none")}, - }, - } - ctx.CreateBazelTargetModule( - javaLibraryBazelTargetModuleProperties(), - android.CommonAttributes{Name: d.Name() + "-neverlink"}, - neverLinkAttrs) - -} diff --git a/java/droiddoc.go b/java/droiddoc.go index f7d7de6ae..b0d537617 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -22,7 +22,6 @@ import ( "github.com/google/blueprint/proptools" "android/soong/android" - "android/soong/bazel" "android/soong/java/config" ) @@ -852,7 +851,6 @@ type ExportedDroiddocDirProperties struct { type ExportedDroiddocDir struct { android.ModuleBase - android.BazelModuleBase properties ExportedDroiddocDirProperties @@ -865,7 +863,6 @@ func ExportedDroiddocDirFactory() android.Module { module := &ExportedDroiddocDir{} module.AddProperties(&module.properties) android.InitAndroidModule(module) - android.InitBazelModule(module) return module } @@ -877,28 +874,6 @@ func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleCont d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")}) } -// ConvertWithBp2build implements android.BazelModule. -func (d *ExportedDroiddocDir) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - props := bazel.BazelTargetModuleProperties{ - // Use the native py_library rule. - Rule_class: "droiddoc_exported_dir", - Bzl_load_location: "//build/bazel/rules/droiddoc:droiddoc_exported_dir.bzl", - } - - type BazelAttrs struct { - Dir *string - Srcs bazel.LabelListAttribute - } - - attrs := &BazelAttrs{ - Dir: proptools.StringPtr(*d.properties.Path), - Srcs: bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, []string{filepath.Join(*d.properties.Path, "**/*")})), - } - - ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: d.Name()}, attrs) - -} - // Defaults type DocDefaults struct { android.ModuleBase diff --git a/java/droidstubs.go b/java/droidstubs.go index 6b8d21f8c..e7ccc1ba4 100644 --- a/java/droidstubs.go +++ b/java/droidstubs.go @@ -18,7 +18,6 @@ import ( "fmt" "path/filepath" "regexp" - "sort" "strings" "github.com/google/blueprint/proptools" @@ -894,28 +893,6 @@ var ( } ) -// A helper function that returns the api surface of the corresponding java_api_contribution Bazel target -// The api_surface is populated using the naming convention of the droidstubs module. -func bazelApiSurfaceName(name string) string { - // Sort the keys so that longer strings appear first - // Otherwise substrings like system will match both system and system_server - sortedKeys := make([]string, 0) - for key := range droidstubsModuleNamingToSdkKind { - sortedKeys = append(sortedKeys, key) - } - sort.Slice(sortedKeys, func(i, j int) bool { - return len(sortedKeys[i]) > len(sortedKeys[j]) - }) - for _, sortedKey := range sortedKeys { - if strings.Contains(name, sortedKey) { - sdkKind := droidstubsModuleNamingToSdkKind[sortedKey] - return sdkKind.String() + "api" - } - } - // Default is publicapi - return android.SdkPublic.String() + "api" -} - func StubsDefaultsFactory() android.Module { module := &DocDefaults{} diff --git a/java/droidstubs_test.go b/java/droidstubs_test.go index 7b89dded4..b97ae29d2 100644 --- a/java/droidstubs_test.go +++ b/java/droidstubs_test.go @@ -307,48 +307,6 @@ func TestDroidstubsWithSdkExtensions(t *testing.T) { android.AssertStringDoesContain(t, "sdk-extensions-info present", cmdline, "--sdk-extensions-info sdk/extensions/info.txt") } -func TestApiSurfaceFromDroidStubsName(t *testing.T) { - testCases := []struct { - desc string - name string - expectedApiSurface string - }{ - { - desc: "Default is publicapi", - name: "mydroidstubs", - expectedApiSurface: "publicapi", - }, - { - desc: "name contains system substring", - name: "mydroidstubs.system.suffix", - expectedApiSurface: "systemapi", - }, - { - desc: "name contains system_server substring", - name: "mydroidstubs.system_server.suffix", - expectedApiSurface: "system-serverapi", - }, - { - desc: "name contains module_lib substring", - name: "mydroidstubs.module_lib.suffix", - expectedApiSurface: "module-libapi", - }, - { - desc: "name contains test substring", - name: "mydroidstubs.test.suffix", - expectedApiSurface: "testapi", - }, - { - desc: "name contains intra.core substring", - name: "mydroidstubs.intra.core.suffix", - expectedApiSurface: "intracoreapi", - }, - } - for _, tc := range testCases { - android.AssertStringEquals(t, tc.desc, tc.expectedApiSurface, bazelApiSurfaceName(tc.name)) - } -} - func TestDroidStubsApiContributionGeneration(t *testing.T) { ctx, _ := testJavaWithFS(t, ` droidstubs { diff --git a/java/gen.go b/java/gen.go index 638da255a..68a9b53fe 100644 --- a/java/gen.go +++ b/java/gen.go @@ -129,19 +129,7 @@ func genAidlIncludeFlags(ctx android.PathContext, srcFiles android.Paths, exclud baseDir = filepath.Clean(baseDir) baseDirSeen := android.InList(baseDir, baseDirs) || android.InList(baseDir, excludeDirsStrings) - // For go/bp2build mixed builds, a file may be listed under a - // directory in the Bazel output tree that is symlinked to a - // directory under the android source tree. We should only - // include one copy of this directory so that the AIDL tool - // doesn't find multiple definitions of the same AIDL class. - // This code comes into effect when filegroups are used in mixed builds. - bazelPathPrefix := android.PathForBazelOut(ctx, "").String() - bazelBaseDir, err := filepath.Rel(bazelPathPrefix, baseDir) - bazelBaseDirSeen := err == nil && - android.InList(bazelBaseDir, baseDirs) || - android.InList(bazelBaseDir, excludeDirsStrings) - - if baseDir != "" && !baseDirSeen && !bazelBaseDirSeen { + if baseDir != "" && !baseDirSeen { baseDirs = append(baseDirs, baseDir) } } diff --git a/java/generated_java_library.go b/java/generated_java_library.go index 930bfd267..40f780c59 100644 --- a/java/generated_java_library.go +++ b/java/generated_java_library.go @@ -35,8 +35,6 @@ type GeneratedJavaLibraryCallbacks interface { // Called from inside GenerateAndroidBuildActions. Add the build rules to // make the srcjar, and return the path to it. GenerateSourceJarBuildActions(module *GeneratedJavaLibraryModule, ctx android.ModuleContext) android.Path - - Bp2build(ctx android.Bp2buildMutatorContext, module *GeneratedJavaLibraryModule) } // GeneratedJavaLibraryModuleFactory provides a utility for modules that are generated @@ -57,7 +55,6 @@ func GeneratedJavaLibraryModuleFactory(moduleName string, callbacks GeneratedJav module.addHostAndDeviceProperties() module.initModuleAndImport(module) android.InitApexModule(module) - android.InitBazelModule(module) InitJavaModule(module, android.HostAndDeviceSupported) if properties != nil { module.AddProperties(properties) @@ -110,7 +107,3 @@ func (module *GeneratedJavaLibraryModule) GenerateAndroidBuildActions(ctx androi module.Library.properties.Generated_srcjars = append(module.Library.properties.Generated_srcjars, srcJarPath) module.Library.GenerateAndroidBuildActions(ctx) } - -func (module *GeneratedJavaLibraryModule) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - module.callbacks.Bp2build(ctx, module) -} diff --git a/java/generated_java_library_test.go b/java/generated_java_library_test.go index ac9524e07..be816cda9 100644 --- a/java/generated_java_library_test.go +++ b/java/generated_java_library_test.go @@ -40,9 +40,6 @@ func (callbacks *JavaGenLibTestCallbacks) GenerateSourceJarBuildActions(module * return android.PathForOutput(ctx, "blah.srcjar") } -func (callbacks *JavaGenLibTestCallbacks) Bp2build(ctx android.Bp2buildMutatorContext, module *GeneratedJavaLibraryModule) { -} - func testGenLib(t *testing.T, errorHandler android.FixtureErrorHandler, bp string) *android.TestResult { return android.GroupFixturePreparers( PrepareForIntegrationTestWithJava, diff --git a/java/genrule.go b/java/genrule.go index 208e1f43b..b84225fa5 100644 --- a/java/genrule.go +++ b/java/genrule.go @@ -65,7 +65,6 @@ func GenRuleFactory() android.Module { android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) - android.InitBazelModule(module) return module } @@ -79,7 +78,6 @@ func GenRuleFactoryHost() android.Module { android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon) android.InitDefaultableModule(module) - android.InitBazelModule(module) return module } diff --git a/java/java.go b/java/java.go index d5d22b2aa..9be8bfd28 100644 --- a/java/java.go +++ b/java/java.go @@ -24,12 +24,8 @@ import ( "sort" "strings" - "android/soong/bazel" - "android/soong/bazel/cquery" "android/soong/remoteexec" "android/soong/testing" - "android/soong/ui/metrics/bp2build_metrics_proto" - "github.com/google/blueprint" "github.com/google/blueprint/proptools" @@ -909,7 +905,6 @@ func LibraryFactory() android.Module { module.initModuleAndImport(module) android.InitApexModule(module) - android.InitBazelModule(module) InitJavaModule(module, android.HostAndDeviceSupported) return module } @@ -931,7 +926,6 @@ func LibraryHostFactory() android.Module { module.Module.properties.Installable = proptools.BoolPtr(true) android.InitApexModule(module) - android.InitBazelModule(module) InitJavaModule(module, android.HostSupported) return module } @@ -1441,8 +1435,6 @@ func TestHostFactory() android.Module { nil, nil) - android.InitBazelModule(module) - InitJavaModuleMultiTargets(module, android.HostSupported) return module @@ -1583,7 +1575,6 @@ func BinaryFactory() android.Module { android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst) android.InitDefaultableModule(module) - android.InitBazelModule(module) return module } @@ -1602,7 +1593,6 @@ func BinaryHostFactory() android.Module { android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst) android.InitDefaultableModule(module) - android.InitBazelModule(module) return module } @@ -2097,7 +2087,6 @@ type Import struct { android.ModuleBase android.DefaultableModuleBase android.ApexModuleBase - android.BazelModuleBase prebuilt android.Prebuilt // Functionality common to Module and Import. @@ -2196,7 +2185,6 @@ func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { } 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) @@ -2498,7 +2486,6 @@ func ImportFactory() android.Module { android.InitPrebuiltModule(module, &module.properties.Jars) android.InitApexModule(module) - android.InitBazelModule(module) InitJavaModule(module, android.HostAndDeviceSupported) return module } @@ -2515,7 +2502,6 @@ func ImportFactoryHost() android.Module { android.InitPrebuiltModule(module, &module.properties.Jars) android.InitApexModule(module) - android.InitBazelModule(module) InitJavaModule(module, android.HostSupported) return module } @@ -2812,695 +2798,6 @@ func addCLCFromDep(ctx android.ModuleContext, depModule android.Module, } } -type javaResourcesAttributes struct { - Resources bazel.LabelListAttribute - Resource_strip_prefix *string - Additional_resources bazel.LabelListAttribute `blueprint:"mutated"` -} - -func (m *Library) getResourceFilegroupStripPrefix(ctx android.Bp2buildMutatorContext, resourceFilegroup string) (*string, bool) { - if otherM, ok := ctx.ModuleFromName(resourceFilegroup); ok { - if fg, isFilegroup := otherM.(android.FileGroupPath); isFilegroup { - return proptools.StringPtr(filepath.Join(ctx.OtherModuleDir(otherM), fg.GetPath(ctx))), true - } - } - return proptools.StringPtr(""), false -} - -func (m *Library) convertJavaResourcesAttributes(ctx android.Bp2buildMutatorContext) *javaResourcesAttributes { - var resources bazel.LabelList - var resourceStripPrefix *string - - additionalJavaResourcesMap := make(map[string]*javaResourcesAttributes) - - if m.properties.Java_resources != nil { - for _, res := range m.properties.Java_resources { - if prefix, isFilegroup := m.getResourceFilegroupStripPrefix(ctx, res); isFilegroup { - otherM, _ := ctx.ModuleFromName(res) - resourcesTargetName := ctx.ModuleName() + "_filegroup_resources_" + otherM.Name() - additionalJavaResourcesMap[resourcesTargetName] = &javaResourcesAttributes{ - Resources: bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, []string{res})), - Resource_strip_prefix: prefix, - } - } else { - resources.Append(android.BazelLabelForModuleSrc(ctx, []string{res})) - } - } - - if !resources.IsEmpty() { - resourceStripPrefix = proptools.StringPtr(ctx.ModuleDir()) - } - } - - //TODO(b/179889880) handle case where glob includes files outside package - resDeps := ResourceDirsToFiles( - ctx, - m.properties.Java_resource_dirs, - m.properties.Exclude_java_resource_dirs, - m.properties.Exclude_java_resources, - ) - - for _, resDep := range resDeps { - dir, files := resDep.dir, resDep.files - - // Bazel includes the relative path from the WORKSPACE root when placing the resource - // inside the JAR file, so we need to remove that prefix - prefix := proptools.StringPtr(dir.String()) - resourcesTargetName := ctx.ModuleName() + "_resource_dir_" + dir.String() - additionalJavaResourcesMap[resourcesTargetName] = &javaResourcesAttributes{ - Resources: bazel.MakeLabelListAttribute(bazel.MakeLabelList(android.RootToModuleRelativePaths(ctx, files))), - Resource_strip_prefix: prefix, - } - } - - var additionalResourceLabels bazel.LabelList - if len(additionalJavaResourcesMap) > 0 { - var additionalResources []string - for resName, _ := range additionalJavaResourcesMap { - additionalResources = append(additionalResources, resName) - } - sort.Strings(additionalResources) - - for i, resName := range additionalResources { - resAttr := additionalJavaResourcesMap[resName] - if resourceStripPrefix == nil && i == 0 { - resourceStripPrefix = resAttr.Resource_strip_prefix - resources = resAttr.Resources.Value - } else if !resAttr.Resources.IsEmpty() { - ctx.CreateBazelTargetModule( - bazel.BazelTargetModuleProperties{ - Rule_class: "java_resources", - Bzl_load_location: "//build/bazel/rules/java:java_resources.bzl", - }, - android.CommonAttributes{Name: resName}, - resAttr, - ) - additionalResourceLabels.Append(android.BazelLabelForModuleSrc(ctx, []string{resName})) - } - } - - } - - return &javaResourcesAttributes{ - Resources: bazel.MakeLabelListAttribute(resources), - Resource_strip_prefix: resourceStripPrefix, - Additional_resources: bazel.MakeLabelListAttribute(additionalResourceLabels), - } -} - -type javaCommonAttributes struct { - *javaResourcesAttributes - *kotlinAttributes - Srcs bazel.LabelListAttribute - Plugins bazel.LabelListAttribute - Javacopts bazel.StringListAttribute - Sdk_version bazel.StringAttribute - Java_version bazel.StringAttribute - Errorprone_force_enable bazel.BoolAttribute - Javac_shard_size *int64 -} - -type javaDependencyLabels struct { - // Dependencies which DO NOT contribute to the API visible to upstream dependencies. - Deps bazel.LabelListAttribute - // Dependencies which DO contribute to the API visible to upstream dependencies. - StaticDeps bazel.LabelListAttribute -} - -type eventLogTagsAttributes struct { - Srcs bazel.LabelListAttribute -} - -type aidlLibraryAttributes struct { - Srcs bazel.LabelListAttribute - Tags bazel.StringListAttribute -} - -type javaAidlLibraryAttributes struct { - Deps bazel.LabelListAttribute - Tags bazel.StringListAttribute -} - -// bp2BuildJavaInfo has information needed for the conversion of java*_modules -// that is needed bor Bp2Build conversion but that requires different handling -// depending on the module type. -type bp2BuildJavaInfo struct { - // separates dependencies into dynamic dependencies and static dependencies. - DepLabels *javaDependencyLabels - hasKotlin bool -} - -func javaXsdTargetName(xsd android.XsdConfigBp2buildTargets) string { - return xsd.JavaBp2buildTargetName() -} - -// convertLibraryAttrsBp2Build returns a javaCommonAttributes struct with -// converted attributes shared across java_* modules and a bp2BuildJavaInfo struct -// which has other non-attribute information needed for bp2build conversion -// that needs different handling depending on the module types, and thus needs -// to be returned to the calling function. -func (m *Library) convertLibraryAttrsBp2Build(ctx android.Bp2buildMutatorContext) (*javaCommonAttributes, *bp2BuildJavaInfo, bool) { - var srcs bazel.LabelListAttribute - var deps bazel.LabelListAttribute - var staticDeps bazel.LabelListAttribute - - if proptools.String(m.deviceProperties.Sdk_version) == "" && m.DeviceSupported() { - // TODO(b/297356704): handle platform apis in bp2build - ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_PROPERTY_UNSUPPORTED, "sdk_version unset") - return &javaCommonAttributes{}, &bp2BuildJavaInfo{}, false - } else if proptools.String(m.deviceProperties.Sdk_version) == "core_platform" { - // TODO(b/297356582): handle core_platform in bp2build - ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_PROPERTY_UNSUPPORTED, "sdk_version core_platform") - return &javaCommonAttributes{}, &bp2BuildJavaInfo{}, false - } - - archVariantProps := m.GetArchVariantProperties(ctx, &CommonProperties{}) - for axis, configToProps := range archVariantProps { - for config, p := range configToProps { - if archProps, ok := p.(*CommonProperties); ok { - archSrcs := android.BazelLabelForModuleSrcExcludes(ctx, archProps.Srcs, archProps.Exclude_srcs) - srcs.SetSelectValue(axis, config, archSrcs) - if archProps.Jarjar_rules != nil { - ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_PROPERTY_UNSUPPORTED, "jarjar_rules") - return &javaCommonAttributes{}, &bp2BuildJavaInfo{}, false - } - } - } - } - srcs.Append( - bazel.MakeLabelListAttribute( - android.BazelLabelForModuleSrcExcludes(ctx, - m.properties.Openjdk9.Srcs, - m.properties.Exclude_srcs))) - srcs.ResolveExcludes() - - javaSrcPartition := "java" - protoSrcPartition := "proto" - xsdSrcPartition := "xsd" - logtagSrcPartition := "logtag" - aidlSrcPartition := "aidl" - kotlinPartition := "kotlin" - srcPartitions := bazel.PartitionLabelListAttribute(ctx, &srcs, bazel.LabelPartitions{ - javaSrcPartition: bazel.LabelPartition{Extensions: []string{".java"}, Keep_remainder: true}, - logtagSrcPartition: bazel.LabelPartition{Extensions: []string{".logtags", ".logtag"}}, - protoSrcPartition: android.ProtoSrcLabelPartition, - aidlSrcPartition: android.AidlSrcLabelPartition, - xsdSrcPartition: bazel.LabelPartition{LabelMapper: android.XsdLabelMapper(javaXsdTargetName)}, - kotlinPartition: bazel.LabelPartition{Extensions: []string{".kt"}}, - }) - - javaSrcs := srcPartitions[javaSrcPartition] - kotlinSrcs := srcPartitions[kotlinPartition] - javaSrcs.Append(kotlinSrcs) - - staticDeps.Append(srcPartitions[xsdSrcPartition]) - - if !srcPartitions[logtagSrcPartition].IsEmpty() { - logtagsLibName := m.Name() + "_logtags" - ctx.CreateBazelTargetModule( - bazel.BazelTargetModuleProperties{ - Rule_class: "event_log_tags", - Bzl_load_location: "//build/bazel/rules/java:event_log_tags.bzl", - }, - android.CommonAttributes{Name: logtagsLibName}, - &eventLogTagsAttributes{ - Srcs: srcPartitions[logtagSrcPartition], - }, - ) - - logtagsSrcs := bazel.MakeLabelList([]bazel.Label{{Label: ":" + logtagsLibName}}) - javaSrcs.Append(bazel.MakeLabelListAttribute(logtagsSrcs)) - } - - if !srcPartitions[aidlSrcPartition].IsEmpty() { - aidlLibs, aidlSrcs := srcPartitions[aidlSrcPartition].Partition(func(src bazel.Label) bool { - return android.IsConvertedToAidlLibrary(ctx, src.OriginalModuleName) - }) - - apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx, ctx.Module()) - - if !aidlSrcs.IsEmpty() { - aidlLibName := m.Name() + "_aidl_library" - ctx.CreateBazelTargetModule( - bazel.BazelTargetModuleProperties{ - Rule_class: "aidl_library", - Bzl_load_location: "//build/bazel/rules/aidl:aidl_library.bzl", - }, - android.CommonAttributes{Name: aidlLibName}, - &aidlLibraryAttributes{ - Srcs: aidlSrcs, - Tags: apexAvailableTags, - }, - ) - aidlLibs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}}) - } - - javaAidlLibName := m.Name() + "_java_aidl_library" - ctx.CreateBazelTargetModule( - bazel.BazelTargetModuleProperties{ - Rule_class: "java_aidl_library", - Bzl_load_location: "//build/bazel/rules/java:java_aidl_library.bzl", - }, - android.CommonAttributes{Name: javaAidlLibName}, - &javaAidlLibraryAttributes{ - Deps: aidlLibs, - Tags: apexAvailableTags, - }, - ) - - staticDeps.Append(bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + javaAidlLibName})) - } - - var javacopts bazel.StringListAttribute //[]string - plugins := bazel.MakeLabelListAttribute( - android.BazelLabelForModuleDeps(ctx, m.properties.Plugins), - ) - if m.properties.Javacflags != nil || m.properties.Openjdk9.Javacflags != nil { - javacopts = bazel.MakeStringListAttribute( - append(append([]string{}, m.properties.Javacflags...), m.properties.Openjdk9.Javacflags...)) - } - - epEnabled := m.properties.Errorprone.Enabled - epJavacflags := m.properties.Errorprone.Javacflags - var errorproneForceEnable bazel.BoolAttribute - if epEnabled == nil { - //TODO(b/227504307) add configuration that depends on RUN_ERROR_PRONE environment variable - } else if *epEnabled { - plugins.Append(bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, m.properties.Errorprone.Extra_check_modules))) - javacopts.Append(bazel.MakeStringListAttribute(epJavacflags)) - errorproneForceEnable.Value = epEnabled - } else { - javacopts.Append(bazel.MakeStringListAttribute([]string{"-XepDisableAllChecks"})) - } - - resourcesAttrs := m.convertJavaResourcesAttributes(ctx) - - commonAttrs := &javaCommonAttributes{ - Srcs: javaSrcs, - javaResourcesAttributes: resourcesAttrs, - Plugins: plugins, - Javacopts: javacopts, - Java_version: bazel.StringAttribute{Value: m.properties.Java_version}, - Sdk_version: bazel.StringAttribute{Value: m.deviceProperties.Sdk_version}, - Errorprone_force_enable: errorproneForceEnable, - Javac_shard_size: m.properties.Javac_shard_size, - } - - for axis, configToProps := range archVariantProps { - for config, _props := range configToProps { - if archProps, ok := _props.(*CommonProperties); ok { - var libLabels []bazel.Label - for _, d := range archProps.Libs { - neverlinkLabel := android.BazelLabelForModuleDepSingle(ctx, d) - neverlinkLabel.Label = neverlinkLabel.Label + "-neverlink" - libLabels = append(libLabels, neverlinkLabel) - } - deps.SetSelectValue(axis, config, bazel.MakeLabelList(libLabels)) - } - } - } - - depLabels := &javaDependencyLabels{} - deps.Append(resourcesAttrs.Additional_resources) - depLabels.Deps = deps - - for axis, configToProps := range archVariantProps { - for config, _props := range configToProps { - if archProps, ok := _props.(*CommonProperties); ok { - archStaticLibs := android.BazelLabelForModuleDeps( - ctx, - android.LastUniqueStrings(android.CopyOf(archProps.Static_libs))) - depLabels.StaticDeps.SetSelectValue(axis, config, archStaticLibs) - } - } - } - depLabels.StaticDeps.Append(staticDeps) - - var additionalProtoDeps bazel.LabelListAttribute - additionalProtoDeps.Append(depLabels.Deps) - additionalProtoDeps.Append(depLabels.StaticDeps) - protoDepLabel := bp2buildProto(ctx, &m.Module, srcPartitions[protoSrcPartition], additionalProtoDeps) - // Soong does not differentiate between a java_library and the Bazel equivalent of - // a java_proto_library + proto_library pair. Instead, in Soong proto sources are - // listed directly in the srcs of a java_library, and the classes produced - // by protoc are included directly in the resulting JAR. Thus upstream dependencies - // that depend on a java_library with proto sources can link directly to the protobuf API, - // and so this should be a static dependency. - if protoDepLabel != nil { - depLabels.StaticDeps.Append(bazel.MakeSingleLabelListAttribute(*protoDepLabel)) - } - - hasKotlin := !kotlinSrcs.IsEmpty() - commonAttrs.kotlinAttributes = &kotlinAttributes{ - Kotlincflags: &m.properties.Kotlincflags, - } - if len(m.properties.Common_srcs) != 0 { - hasKotlin = true - commonAttrs.kotlinAttributes.Common_srcs = bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Common_srcs)) - } - - bp2BuildInfo := &bp2BuildJavaInfo{ - DepLabels: depLabels, - hasKotlin: hasKotlin, - } - - return commonAttrs, bp2BuildInfo, true -} - -type javaLibraryAttributes struct { - *javaCommonAttributes - Deps bazel.LabelListAttribute - Exports bazel.LabelListAttribute - Neverlink bazel.BoolAttribute -} - -type kotlinAttributes struct { - Common_srcs bazel.LabelListAttribute - Kotlincflags *[]string -} - -func ktJvmLibraryBazelTargetModuleProperties() bazel.BazelTargetModuleProperties { - return bazel.BazelTargetModuleProperties{ - Rule_class: "kt_jvm_library", - Bzl_load_location: "//build/bazel/rules/kotlin:kt_jvm_library.bzl", - } -} - -func javaLibraryBazelTargetModuleProperties() bazel.BazelTargetModuleProperties { - return bazel.BazelTargetModuleProperties{ - Rule_class: "java_library", - Bzl_load_location: "//build/bazel/rules/java:library.bzl", - } -} - -func javaLibraryBp2Build(ctx android.Bp2buildMutatorContext, m *Library) { - commonAttrs, bp2BuildInfo, supported := m.convertLibraryAttrsBp2Build(ctx) - if !supported { - return - } - depLabels := bp2BuildInfo.DepLabels - - deps := depLabels.Deps - exports := depLabels.StaticDeps - if !commonAttrs.Srcs.IsEmpty() { - deps.Append(exports) // we should only append these if there are sources to use them - } else if !deps.IsEmpty() { - // java_library does not accept deps when there are no srcs because - // there is no compilation happening, but it accepts exports. - // The non-empty deps here are unnecessary as deps on the java_library - // since they aren't being propagated to any dependencies. - // So we can drop deps here. - deps = bazel.LabelListAttribute{} - } - var props bazel.BazelTargetModuleProperties - attrs := &javaLibraryAttributes{ - javaCommonAttributes: commonAttrs, - Deps: deps, - Exports: exports, - } - name := m.Name() - - if !bp2BuildInfo.hasKotlin { - props = javaLibraryBazelTargetModuleProperties() - } else { - props = ktJvmLibraryBazelTargetModuleProperties() - } - - ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs) - neverlinkProp := true - neverLinkAttrs := &javaLibraryAttributes{ - Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}), - Neverlink: bazel.BoolAttribute{Value: &neverlinkProp}, - javaCommonAttributes: &javaCommonAttributes{ - Sdk_version: bazel.StringAttribute{Value: m.deviceProperties.Sdk_version}, - Java_version: bazel.StringAttribute{Value: m.properties.Java_version}, - }, - } - ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name + "-neverlink"}, neverLinkAttrs) - -} - -type javaBinaryHostAttributes struct { - *javaCommonAttributes - Deps bazel.LabelListAttribute - Runtime_deps bazel.LabelListAttribute - Main_class string - Jvm_flags bazel.StringListAttribute -} - -// JavaBinaryHostBp2Build is for java_binary_host bp2build. -func javaBinaryHostBp2Build(ctx android.Bp2buildMutatorContext, m *Binary) { - commonAttrs, bp2BuildInfo, supported := m.convertLibraryAttrsBp2Build(ctx) - if !supported { - return - } - depLabels := bp2BuildInfo.DepLabels - - deps := depLabels.Deps - deps.Append(depLabels.StaticDeps) - if m.binaryProperties.Jni_libs != nil { - deps.Append(bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, m.binaryProperties.Jni_libs))) - } - - var runtimeDeps bazel.LabelListAttribute - if commonAttrs.Srcs.IsEmpty() { - // if there are no sources, then the dependencies can only be used at runtime - runtimeDeps = deps - deps = bazel.LabelListAttribute{} - } - - mainClass := "" - if m.binaryProperties.Main_class != nil { - mainClass = *m.binaryProperties.Main_class - } - if m.properties.Manifest != nil { - mainClassInManifest, err := android.GetMainClassInManifest(ctx.Config(), android.PathForModuleSrc(ctx, *m.properties.Manifest).String()) - if err != nil { - return - } - mainClass = mainClassInManifest - } - - // Attribute jvm_flags - var jvmFlags bazel.StringListAttribute - if m.binaryProperties.Jni_libs != nil { - jniLibPackages := []string{} - for _, jniLib := range m.binaryProperties.Jni_libs { - if jniLibModule, exists := ctx.ModuleFromName(jniLib); exists { - otherDir := ctx.OtherModuleDir(jniLibModule) - jniLibPackages = append(jniLibPackages, filepath.Join(otherDir, jniLib)) - } - } - jniLibPaths := []string{} - for _, jniLibPackage := range jniLibPackages { - // See cs/f:.*/third_party/bazel/.*java_stub_template.txt for the use of RUNPATH - jniLibPaths = append(jniLibPaths, "$${RUNPATH}"+jniLibPackage) - } - jvmFlags = bazel.MakeStringListAttribute([]string{"-Djava.library.path=" + strings.Join(jniLibPaths, ":")}) - } - - props := bazel.BazelTargetModuleProperties{ - Rule_class: "java_binary", - Bzl_load_location: "@rules_java//java:defs.bzl", - } - binAttrs := &javaBinaryHostAttributes{ - Runtime_deps: runtimeDeps, - Main_class: mainClass, - Jvm_flags: jvmFlags, - } - - if commonAttrs.Srcs.IsEmpty() { - binAttrs.javaCommonAttributes = commonAttrs - ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, binAttrs) - return - } - - libInfo := libraryCreationInfo{ - deps: deps, - attrs: commonAttrs, - baseName: m.Name(), - hasKotlin: bp2BuildInfo.hasKotlin, - } - libName := createLibraryTarget(ctx, libInfo) - binAttrs.Runtime_deps.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + libName}}) - - // Create the BazelTargetModule. - ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, binAttrs) -} - -type javaTestHostAttributes struct { - *javaCommonAttributes - Srcs bazel.LabelListAttribute - Deps bazel.LabelListAttribute - Runtime_deps bazel.LabelListAttribute -} - -// javaTestHostBp2Build is for java_test_host bp2build. -func javaTestHostBp2Build(ctx android.Bp2buildMutatorContext, m *TestHost) { - commonAttrs, bp2BuildInfo, supported := m.convertLibraryAttrsBp2Build(ctx) - if !supported { - return - } - depLabels := bp2BuildInfo.DepLabels - - deps := depLabels.Deps - deps.Append(depLabels.StaticDeps) - - var runtimeDeps bazel.LabelListAttribute - attrs := &javaTestHostAttributes{ - Runtime_deps: runtimeDeps, - } - props := bazel.BazelTargetModuleProperties{ - Rule_class: "java_test", - Bzl_load_location: "//build/bazel/rules/java:test.bzl", - } - - if commonAttrs.Srcs.IsEmpty() { - // if there are no sources, then the dependencies can only be used at runtime - attrs.Runtime_deps = deps - attrs.javaCommonAttributes = commonAttrs - ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs) - return - } - - libInfo := libraryCreationInfo{ - deps: deps, - attrs: commonAttrs, - baseName: m.Name(), - hasKotlin: bp2BuildInfo.hasKotlin, - } - libName := createLibraryTarget(ctx, libInfo) - - attrs.Srcs = commonAttrs.Srcs - attrs.Deps = deps - attrs.Runtime_deps.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + libName}}) - // Create the BazelTargetModule. - ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs) -} - -// libraryCreationInfo encapsulates the info needed to create java_library target from -// java_binary_host or java_test_host. -type libraryCreationInfo struct { - deps bazel.LabelListAttribute - attrs *javaCommonAttributes - baseName string - hasKotlin bool -} - -// helper function that creates java_library target from java_binary_host or java_test_host, -// and returns the library target name, -func createLibraryTarget(ctx android.Bp2buildMutatorContext, libInfo libraryCreationInfo) string { - libName := libInfo.baseName + "_lib" - var libProps bazel.BazelTargetModuleProperties - if libInfo.hasKotlin { - libProps = ktJvmLibraryBazelTargetModuleProperties() - } else { - libProps = javaLibraryBazelTargetModuleProperties() - } - libAttrs := &javaLibraryAttributes{ - Deps: libInfo.deps, - javaCommonAttributes: libInfo.attrs, - } - - ctx.CreateBazelTargetModule(libProps, android.CommonAttributes{Name: libName}, libAttrs) - return libName -} - -type bazelJavaImportAttributes struct { - Jars bazel.LabelListAttribute - Exports bazel.LabelListAttribute -} - -// java_import bp2Build converter. -func (i *Import) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - var jars bazel.LabelListAttribute - archVariantProps := i.GetArchVariantProperties(ctx, &ImportProperties{}) - for axis, configToProps := range archVariantProps { - for config, _props := range configToProps { - if archProps, ok := _props.(*ImportProperties); ok { - archJars := android.BazelLabelForModuleSrcExcludes(ctx, archProps.Jars, []string(nil)) - jars.SetSelectValue(axis, config, archJars) - } - } - } - - attrs := &bazelJavaImportAttributes{ - Jars: jars, - } - props := bazel.BazelTargetModuleProperties{ - Rule_class: "java_import", - Bzl_load_location: "//build/bazel/rules/java:import.bzl", - } - - name := android.RemoveOptionalPrebuiltPrefix(i.Name()) - - ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs) - - neverlink := true - neverlinkAttrs := &javaLibraryAttributes{ - Neverlink: bazel.BoolAttribute{Value: &neverlink}, - Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}), - javaCommonAttributes: &javaCommonAttributes{ - Sdk_version: bazel.StringAttribute{Value: proptools.StringPtr("none")}, - }, - } - ctx.CreateBazelTargetModule( - javaLibraryBazelTargetModuleProperties(), - android.CommonAttributes{Name: name + "-neverlink"}, - neverlinkAttrs) -} - -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 - // TODO: aconfig files? - }) - - 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 -} - type JavaApiContributionImport struct { JavaApiContribution diff --git a/java/java_test.go b/java/java_test.go index d4b056bc9..8e83fc412 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1205,7 +1205,7 @@ func TestPatchModule(t *testing.T) { expected := "java.base=.:out/soong" checkPatchModuleFlag(t, ctx, "bar", expected) expected = "java.base=" + strings.Join([]string{ - ".", "out/soong", "dir", "dir2", "nested", defaultModuleToPath("ext"), defaultModuleToPath("framework")}, ":") + ".", "out/soong", defaultModuleToPath("ext"), defaultModuleToPath("framework")}, ":") checkPatchModuleFlag(t, ctx, "baz", expected) }) } @@ -1290,43 +1290,6 @@ func TestAidlExportIncludeDirsFromImports(t *testing.T) { } } -func TestAidlIncludeDirFromConvertedFileGroupWithPathPropInMixedBuilds(t *testing.T) { - // TODO(b/247782695), TODO(b/242847534) Fix mixed builds for filegroups - t.Skip("Re-enable once filegroups are corrected for mixed builds") - bp := ` - filegroup { - name: "foo_aidl", - srcs: ["aidl/foo/IFoo.aidl"], - path: "aidl/foo", - bazel_module: { label: "//:foo_aidl" }, - } - java_library { - name: "foo", - srcs: [":foo_aidl"], - } -` - - outBaseDir := "out/bazel/output" - result := android.GroupFixturePreparers( - prepareForJavaTest, - android.PrepareForTestWithFilegroup, - android.FixtureModifyConfig(func(config android.Config) { - config.BazelContext = android.MockBazelContext{ - OutputBaseDir: outBaseDir, - LabelToOutputFiles: map[string][]string{ - "//:foo_aidl": []string{"aidl/foo/IFoo.aidl"}, - }, - } - }), - ).RunTestWithBp(t, bp) - - aidlCommand := result.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command - expectedAidlFlag := "-I" + outBaseDir + "/execroot/__main__/aidl/foo" - if !strings.Contains(aidlCommand, expectedAidlFlag) { - t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) - } -} - func TestAidlFlagsArePassedToTheAidlCompiler(t *testing.T) { ctx, _ := testJava(t, ` java_library { @@ -1743,85 +1706,6 @@ 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)) -} - -func TestGenAidlIncludeFlagsForMixedBuilds(t *testing.T) { - bazelOutputBaseDir := filepath.Join("out", "bazel") - result := android.GroupFixturePreparers( - PrepareForIntegrationTestWithJava, - android.FixtureModifyConfig(func(config android.Config) { - config.BazelContext = android.MockBazelContext{ - OutputBaseDir: bazelOutputBaseDir, - } - }), - ).RunTest(t) - - ctx := &android.TestPathContext{TestResult: result} - - srcDirectory := filepath.Join("frameworks", "base") - srcDirectoryAlreadyIncluded := filepath.Join("frameworks", "base", "core", "java") - bazelSrcDirectory := android.PathForBazelOut(ctx, srcDirectory) - bazelSrcDirectoryAlreadyIncluded := android.PathForBazelOut(ctx, srcDirectoryAlreadyIncluded) - srcs := android.Paths{ - android.PathForTestingWithRel(bazelSrcDirectory.String(), "bazelAidl.aidl"), - android.PathForTestingWithRel(bazelSrcDirectory.String(), "bazelAidl2.aidl"), - android.PathForTestingWithRel(bazelSrcDirectoryAlreadyIncluded.String(), "bazelAidlExclude.aidl"), - android.PathForTestingWithRel(bazelSrcDirectoryAlreadyIncluded.String(), "bazelAidl2Exclude.aidl"), - } - dirsAlreadyIncluded := android.Paths{ - android.PathForTesting(srcDirectoryAlreadyIncluded), - } - - expectedFlags := " -Iout/bazel/execroot/__main__/frameworks/base" - flags := genAidlIncludeFlags(ctx, srcs, dirsAlreadyIncluded) - if flags != expectedFlags { - t.Errorf("expected flags to be %q; was %q", expectedFlags, flags) - } -} - func TestDeviceBinaryWrapperGeneration(t *testing.T) { // Scenario 1: java_binary has main_class property in its bp ctx, _ := testJava(t, ` diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go index 662a2d768..2197304a5 100644 --- a/java/platform_compat_config.go +++ b/java/platform_compat_config.go @@ -19,10 +19,7 @@ import ( "path/filepath" "android/soong/android" - "android/soong/bazel" - "github.com/google/blueprint" - "github.com/google/blueprint/proptools" ) func init() { @@ -57,7 +54,6 @@ type platformCompatConfigProperties struct { type platformCompatConfig struct { android.ModuleBase - android.BazelModuleBase properties platformCompatConfigProperties installDirPath android.InstallPath @@ -126,29 +122,10 @@ func (p *platformCompatConfig) AndroidMkEntries() []android.AndroidMkEntries { }} } -type bazelPlatformCompatConfigAttributes struct { - Src bazel.LabelAttribute -} - -func (p *platformCompatConfig) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - props := bazel.BazelTargetModuleProperties{ - Rule_class: "platform_compat_config", - Bzl_load_location: "//build/bazel/rules/java:platform_compat_config.bzl", - } - attr := &bazelPlatformCompatConfigAttributes{ - Src: *bazel.MakeLabelAttribute( - android.BazelLabelForModuleSrcSingle(ctx, proptools.String(p.properties.Src)).Label), - } - ctx.CreateBazelTargetModule(props, android.CommonAttributes{ - Name: p.Name(), - }, attr) -} - func PlatformCompatConfigFactory() android.Module { module := &platformCompatConfig{} module.AddProperties(&module.properties) android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) - android.InitBazelModule(module) return module } diff --git a/java/plugin.go b/java/plugin.go index 4d4c199f7..9c4774a10 100644 --- a/java/plugin.go +++ b/java/plugin.go @@ -16,7 +16,6 @@ package java import ( "android/soong/android" - "android/soong/bazel" ) func init() { @@ -35,8 +34,6 @@ func PluginFactory() android.Module { InitJavaModule(module, android.HostSupported) - android.InitBazelModule(module) - return module } @@ -56,38 +53,3 @@ type PluginProperties struct { // parallelism and cause more recompilation for modules that depend on modules that use this plugin. Generates_api *bool } - -type pluginAttributes struct { - *javaCommonAttributes - Deps bazel.LabelListAttribute - Processor_class *string -} - -// ConvertWithBp2build is used to convert android_app to Bazel. -func (p *Plugin) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - pluginName := p.Name() - commonAttrs, bp2BuildInfo, supported := p.convertLibraryAttrsBp2Build(ctx) - if !supported { - return - } - depLabels := bp2BuildInfo.DepLabels - - deps := depLabels.Deps - deps.Append(depLabels.StaticDeps) - - var processorClass *string - if p.pluginProperties.Processor_class != nil { - processorClass = p.pluginProperties.Processor_class - } - - attrs := &pluginAttributes{ - javaCommonAttributes: commonAttrs, - Deps: deps, - Processor_class: processorClass, - } - - props := bazel.BazelTargetModuleProperties{ - Rule_class: "java_plugin", - } - ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: pluginName}, attrs) -} diff --git a/java/prebuilt_apis.go b/java/prebuilt_apis.go index 99cb99ba2..94e9c6c57 100644 --- a/java/prebuilt_apis.go +++ b/java/prebuilt_apis.go @@ -127,41 +127,13 @@ func parseFinalizedPrebuiltPath(ctx android.LoadHookContext, p string, allowIncr func prebuiltApiModuleName(mctx android.LoadHookContext, module, scope, version string) string { return fmt.Sprintf("%s_%s_%s_%s", mctx.ModuleName(), scope, version, module) } - -func hasBazelPrebuilt(module string) bool { - return module == "android" || module == "core-for-system-modules" -} - -func bazelPrebuiltApiModuleName(module, scope, version string) string { - bazelModule := module - switch module { - case "android": - bazelModule = "android_jar" - case "core-for-system-modules": - bazelModule = "core_jar" - } - bazelVersion := version - if version == "current" { - bazelVersion = strconv.Itoa(android.FutureApiLevelInt) - } - bazelScope := scope - switch scope { - case "module-lib": - bazelScope = "module" - case "system-server": - bazelScope = "system_server" - } - return fmt.Sprintf("//prebuilts/sdk:%s_%s_%s", bazelScope, bazelVersion, bazelModule) -} - func createImport(mctx android.LoadHookContext, module, scope, version, path, sdkVersion string, compileDex bool) { props := struct { - Name *string - Jars []string - Sdk_version *string - Installable *bool - Compile_dex *bool - Bazel_module android.BazelModuleProperties + Name *string + Jars []string + Sdk_version *string + Installable *bool + Compile_dex *bool }{ Name: proptools.StringPtr(prebuiltApiModuleName(mctx, module, scope, version)), Jars: []string{path}, @@ -169,10 +141,6 @@ func createImport(mctx android.LoadHookContext, module, scope, version, path, sd Installable: proptools.BoolPtr(false), Compile_dex: proptools.BoolPtr(compileDex), } - if hasBazelPrebuilt(module) { - props.Bazel_module = android.BazelModuleProperties{ - Label: proptools.StringPtr(bazelPrebuiltApiModuleName(module, scope, version))} - } mctx.CreateModule(ImportFactory, &props) } diff --git a/java/proto.go b/java/proto.go index c88d3d7fc..e27ef2c41 100644 --- a/java/proto.go +++ b/java/proto.go @@ -19,9 +19,6 @@ import ( "strconv" "android/soong/android" - "android/soong/bazel" - - "github.com/google/blueprint/proptools" ) const ( @@ -141,79 +138,3 @@ func protoFlags(ctx android.ModuleContext, j *CommonProperties, p *android.Proto return flags } - -type protoAttributes struct { - Deps bazel.LabelListAttribute - - // A list of proto_library targets that the proto_library in `deps` depends on - // This list is overestimation. - // Overestimation is necessary since Soong includes other protos via proto.include_dirs and not - // a specific .proto file module explicitly. - Transitive_deps bazel.LabelListAttribute - - // This is the libs and the static_libs of the original java_library module. - // On the bazel side, after proto sources are generated in java_*_proto_library, a java_library - // will compile them. The libs and static_libs from the original java_library module need - // to be linked because they are necessary in compile-time classpath. - Additional_proto_deps bazel.LabelListAttribute - - Sdk_version bazel.StringAttribute - Java_version bazel.StringAttribute - - Plugin bazel.LabelAttribute -} - -func bp2buildProto(ctx android.Bp2buildMutatorContext, m *Module, protoSrcs bazel.LabelListAttribute, AdditionalProtoDeps bazel.LabelListAttribute) *bazel.Label { - protoInfo, ok := android.Bp2buildProtoProperties(ctx, &m.ModuleBase, protoSrcs) - if !ok { - return nil - } - - typ := proptools.StringDefault(protoInfo.Type, protoTypeDefault) - var rule_class string - suffix := "_java_proto" - switch typ { - case "nano": - suffix += "_nano" - rule_class = "java_nano_proto_library" - case "micro": - suffix += "_micro" - rule_class = "java_micro_proto_library" - case "lite": - suffix += "_lite" - rule_class = "java_lite_proto_library" - case "stream": - suffix += "_stream" - rule_class = "java_stream_proto_library" - case "full": - rule_class = "java_proto_library" - default: - ctx.PropertyErrorf("proto.type", "cannot handle conversion at this time: %q", typ) - } - - plugin := bazel.LabelAttribute{} - if m.protoProperties.Proto.Plugin != nil { - plugin.SetValue(android.BazelLabelForModuleDepSingle(ctx, "protoc-gen-"+*m.protoProperties.Proto.Plugin)) - } - - protoAttrs := &protoAttributes{ - Deps: bazel.MakeLabelListAttribute(protoInfo.Proto_libs), - Transitive_deps: bazel.MakeLabelListAttribute(protoInfo.Transitive_proto_libs), - Additional_proto_deps: AdditionalProtoDeps, - Java_version: bazel.StringAttribute{Value: m.properties.Java_version}, - Sdk_version: bazel.StringAttribute{Value: m.deviceProperties.Sdk_version}, - Plugin: plugin, - } - - name := m.Name() + suffix - - ctx.CreateBazelTargetModule( - bazel.BazelTargetModuleProperties{ - Rule_class: rule_class, - Bzl_load_location: "//build/bazel/rules/java:proto.bzl", - }, - android.CommonAttributes{Name: name}, - protoAttrs) - - return &bazel.Label{Label: ":" + name} -} diff --git a/java/sdk_library.go b/java/sdk_library.go index fbfe509b8..176bda0ce 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -24,13 +24,10 @@ import ( "strings" "sync" - "android/soong/ui/metrics/bp2build_metrics_proto" - "github.com/google/blueprint" "github.com/google/blueprint/proptools" "android/soong/android" - "android/soong/bazel" "android/soong/dexpreopt" ) @@ -1238,8 +1235,6 @@ type SdkLibraryDependency interface { type SdkLibrary struct { Library - android.BazelModuleBase - sdkLibraryProperties sdkLibraryProperties // Map from api scope to the scope specific property structure. @@ -2318,47 +2313,9 @@ func SdkLibraryFactory() android.Module { module.CreateInternalModules(ctx) } }) - android.InitBazelModule(module) return module } -type bazelSdkLibraryAttributes struct { - Public *bazel.Label - System *bazel.Label - Test *bazel.Label - Module_lib *bazel.Label - System_server *bazel.Label -} - -// java_sdk_library bp2build converter -func (module *SdkLibrary) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - if ctx.ModuleType() != "java_sdk_library" { - ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "") - return - } - - nameToAttr := make(map[string]*bazel.Label) - - for _, scope := range module.getGeneratedApiScopes(ctx) { - apiSurfaceFile := android.BazelLabelForModuleSrcSingle(ctx, path.Join(module.getApiDir(), scope.apiFilePrefix+"current.txt")) - nameToAttr[scope.name] = &apiSurfaceFile - } - - attrs := bazelSdkLibraryAttributes{ - Public: nameToAttr["public"], - System: nameToAttr["system"], - Test: nameToAttr["test"], - Module_lib: nameToAttr["module-lib"], - System_server: nameToAttr["system-server"], - } - props := bazel.BazelTargetModuleProperties{ - Rule_class: "java_sdk_library", - Bzl_load_location: "//build/bazel/rules/java:sdk_library.bzl", - } - - ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, &attrs) -} - // // SDK library prebuilts // @@ -2400,7 +2357,6 @@ type sdkLibraryImportProperties struct { type SdkLibraryImport struct { android.ModuleBase android.DefaultableModuleBase - android.BazelModuleBase prebuilt android.Prebuilt android.ApexModuleBase @@ -2484,7 +2440,6 @@ func sdkLibraryImportFactory() android.Module { android.InitPrebuiltModule(module, &[]string{""}) android.InitApexModule(module) - android.InitBazelModule(module) InitJavaModule(module, android.HostAndDeviceSupported) module.SetDefaultableHook(func(mctx android.DefaultableHookContext) { @@ -2495,33 +2450,6 @@ func sdkLibraryImportFactory() android.Module { return module } -// java_sdk_library bp2build converter -func (i *SdkLibraryImport) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - nameToAttr := make(map[string]*bazel.Label) - - for scope, props := range i.scopeProperties { - if api := proptools.String(props.Current_api); api != "" { - apiSurfaceFile := android.BazelLabelForModuleSrcSingle(ctx, api) - nameToAttr[scope.name] = &apiSurfaceFile - } - } - - attrs := bazelSdkLibraryAttributes{ - Public: nameToAttr["public"], - System: nameToAttr["system"], - Test: nameToAttr["test"], - Module_lib: nameToAttr["module-lib"], - System_server: nameToAttr["system-server"], - } - props := bazel.BazelTargetModuleProperties{ - Rule_class: "java_sdk_library", - Bzl_load_location: "//build/bazel/rules/java:sdk_library.bzl", - } - - name := android.RemoveOptionalPrebuiltPrefix(i.Name()) - ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, &attrs) -} - var _ PermittedPackagesForUpdatableBootJars = (*SdkLibraryImport)(nil) func (module *SdkLibraryImport) PermittedPackagesForUpdatableBootJars() []string { |