diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 98 | 
1 files changed, 82 insertions, 16 deletions
| diff --git a/java/java.go b/java/java.go index bb7c32be8..e55f04599 100644 --- a/java/java.go +++ b/java/java.go @@ -274,6 +274,9 @@ type dependencyTag struct {  	// True if the dependency is relinked at runtime.  	runtimeLinked bool + +	// True if the dependency is a toolchain, for example an annotation processor. +	toolchain bool  }  // installDependencyTag is a dependency tag that is annotated to cause the installed files of the @@ -287,6 +290,8 @@ type installDependencyTag struct {  func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation {  	if d.runtimeLinked {  		return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency} +	} else if d.toolchain { +		return []android.LicenseAnnotation{android.LicenseAnnotationToolchain}  	}  	return nil  } @@ -325,22 +330,23 @@ func IsJniDepTag(depTag blueprint.DependencyTag) bool {  var (  	dataNativeBinsTag       = dependencyTag{name: "dataNativeBins"} +	dataDeviceBinsTag       = dependencyTag{name: "dataDeviceBins"}  	staticLibTag            = dependencyTag{name: "staticlib"}  	libTag                  = dependencyTag{name: "javalib", runtimeLinked: true}  	java9LibTag             = dependencyTag{name: "java9lib", runtimeLinked: true} -	pluginTag               = dependencyTag{name: "plugin"} -	errorpronePluginTag     = dependencyTag{name: "errorprone-plugin"} -	exportedPluginTag       = dependencyTag{name: "exported-plugin"} +	pluginTag               = dependencyTag{name: "plugin", toolchain: true} +	errorpronePluginTag     = dependencyTag{name: "errorprone-plugin", toolchain: true} +	exportedPluginTag       = dependencyTag{name: "exported-plugin", toolchain: true}  	bootClasspathTag        = dependencyTag{name: "bootclasspath", runtimeLinked: true}  	systemModulesTag        = dependencyTag{name: "system modules", runtimeLinked: true}  	frameworkResTag         = dependencyTag{name: "framework-res"}  	kotlinStdlibTag         = dependencyTag{name: "kotlin-stdlib", runtimeLinked: true}  	kotlinAnnotationsTag    = dependencyTag{name: "kotlin-annotations", runtimeLinked: true} -	kotlinPluginTag         = dependencyTag{name: "kotlin-plugin"} +	kotlinPluginTag         = dependencyTag{name: "kotlin-plugin", toolchain: true}  	proguardRaiseTag        = dependencyTag{name: "proguard-raise"}  	certificateTag          = dependencyTag{name: "certificate"}  	instrumentationForTag   = dependencyTag{name: "instrumentation_for"} -	extraLintCheckTag       = dependencyTag{name: "extra-lint-check"} +	extraLintCheckTag       = dependencyTag{name: "extra-lint-check", toolchain: true}  	jniLibTag               = dependencyTag{name: "jnilib", runtimeLinked: true}  	syspropPublicStubDepTag = dependencyTag{name: "sysprop public stub"}  	jniInstallTag           = installDependencyTag{name: "jni install"} @@ -450,14 +456,8 @@ func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext an  		return normalizeJavaVersion(ctx, javaVersion)  	} else if ctx.Device() {  		return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion(ctx)) -	} else if ctx.Config().TargetsJava11() { -		// Temporary experimental flag to be able to try and build with -		// java version 11 options.  The flag, if used, just sets Java -		// 11 as the default version, leaving any components that -		// target an older version intact. -		return JAVA_VERSION_11  	} else { -		return JAVA_VERSION_9 +		return JAVA_VERSION_11  	}  } @@ -837,6 +837,9 @@ type testProperties struct {  type hostTestProperties struct {  	// list of native binary modules that should be installed alongside the test  	Data_native_bins []string `android:"arch_variant"` + +	// list of device binary modules that should be installed alongside the test +	Data_device_bins []string `android:"arch_variant"`  }  type testHelperLibraryProperties struct { @@ -910,6 +913,11 @@ func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) {  		}  	} +	if len(j.testHostProperties.Data_device_bins) > 0 { +		deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations() +		ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins...) +	} +  	if len(j.testProperties.Jni_libs) > 0 {  		for _, target := range ctx.MultiTargets() {  			sharedLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"}) @@ -924,14 +932,35 @@ func (j *TestHost) AddExtraResource(p android.Path) {  	j.extraResources = append(j.extraResources, p)  } +func (j *TestHost) GenerateAndroidBuildActions(ctx android.ModuleContext) { +	var configs []tradefed.Config +	if len(j.testHostProperties.Data_device_bins) > 0 { +		// add Tradefed configuration to push device bins to device for testing +		remoteDir := filepath.Join("/data/local/tests/unrestricted/", j.Name()) +		options := []tradefed.Option{{Name: "cleanup", Value: "true"}} +		for _, bin := range j.testHostProperties.Data_device_bins { +			fullPath := filepath.Join(remoteDir, bin) +			options = append(options, tradefed.Option{Name: "push-file", Key: bin, Value: fullPath}) +		} +		configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.PushFilePreparer", options}) +	} + +	j.Test.generateAndroidBuildActionsWithConfig(ctx, configs) +} +  func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) { +	j.generateAndroidBuildActionsWithConfig(ctx, nil) +} + +func (j *Test) generateAndroidBuildActionsWithConfig(ctx android.ModuleContext, configs []tradefed.Config) {  	if j.testProperties.Test_options.Unit_test == nil && ctx.Host() {  		// TODO(b/): Clean temporary heuristic to avoid unexpected onboarding.  		defaultUnitTest := !inList("tradefed", j.properties.Libs) && !inList("cts", j.testProperties.Test_suites)  		j.testProperties.Test_options.Unit_test = proptools.BoolPtr(defaultUnitTest)  	} +  	j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template, -		j.testProperties.Test_suites, j.testProperties.Auto_gen_config, j.testProperties.Test_options.Unit_test) +		j.testProperties.Test_suites, configs, j.testProperties.Auto_gen_config, j.testProperties.Test_options.Unit_test)  	j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data) @@ -941,6 +970,10 @@ func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {  		j.data = append(j.data, android.OutputFileForModule(ctx, dep, ""))  	}) +	ctx.VisitDirectDepsWithTag(dataDeviceBinsTag, func(dep android.Module) { +		j.data = append(j.data, android.OutputFileForModule(ctx, dep, "")) +	}) +  	ctx.VisitDirectDepsWithTag(jniLibTag, func(dep android.Module) {  		sharedLibInfo := ctx.OtherModuleProvider(dep, cc.SharedLibraryInfoProvider).(cc.SharedLibraryInfo)  		if sharedLibInfo.SharedLibrary != nil { @@ -973,7 +1006,7 @@ func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContex  func (j *JavaTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {  	j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.prebuiltTestProperties.Test_config, nil, -		j.prebuiltTestProperties.Test_suites, nil, nil) +		j.prebuiltTestProperties.Test_suites, nil, nil, nil)  	j.Import.GenerateAndroidBuildActions(ctx)  } @@ -1300,6 +1333,7 @@ type Import struct {  	android.ModuleBase  	android.DefaultableModuleBase  	android.ApexModuleBase +	android.BazelModuleBase  	prebuilt android.Prebuilt  	android.SdkBase @@ -1655,6 +1689,7 @@ func ImportFactory() android.Module {  	android.InitPrebuiltModule(module, &module.properties.Jars)  	android.InitApexModule(module)  	android.InitSdkAwareModule(module) +	android.InitBazelModule(module)  	InitJavaModule(module, android.HostAndDeviceSupported)  	return module  } @@ -1975,7 +2010,8 @@ type javaLibraryAttributes struct {  	Javacopts bazel.StringListAttribute  } -func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) { +func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) *javaLibraryAttributes { +	//TODO(b/209577426): Support multiple arch variants  	srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrcExcludes(ctx, m.properties.Srcs, m.properties.Exclude_srcs))  	attrs := &javaLibraryAttributes{  		Srcs: srcs, @@ -1985,9 +2021,21 @@ func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {  		attrs.Javacopts = bazel.MakeStringListAttribute(m.properties.Javacflags)  	} +	var deps bazel.LabelList  	if m.properties.Libs != nil { -		attrs.Deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, m.properties.Libs)) +		deps.Append(android.BazelLabelForModuleDeps(ctx, m.properties.Libs)) +	} +	if m.properties.Static_libs != nil { +		//TODO(b/217236083) handle static libs similarly to Soong +		deps.Append(android.BazelLabelForModuleDeps(ctx, m.properties.Static_libs))  	} +	attrs.Deps = bazel.MakeLabelListAttribute(deps) + +	return attrs +} + +func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) { +	attrs := m.convertLibraryAttrsBp2Build(ctx)  	props := bazel.BazelTargetModuleProperties{  		Rule_class:        "java_library", @@ -2073,3 +2121,21 @@ func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) {  	// Create the BazelTargetModule.  	ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)  } + +type bazelJavaImportAttributes struct { +	Jars bazel.LabelListAttribute +} + +// java_import bp2Build converter. +func (i *Import) ConvertWithBp2build(ctx android.TopDownMutatorContext) { +	//TODO(b/209577426): Support multiple arch variants +	jars := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrcExcludes(ctx, i.properties.Jars, []string(nil))) + +	attrs := &bazelJavaImportAttributes{ +		Jars: jars, +	} +	props := bazel.BazelTargetModuleProperties{Rule_class: "java_import"} + +	ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: android.RemoveOptionalPrebuiltPrefix(i.Name())}, attrs) + +} |