diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 220 | 
1 files changed, 115 insertions, 105 deletions
| diff --git a/java/java.go b/java/java.go index 018850fef..5bb36368b 100644 --- a/java/java.go +++ b/java/java.go @@ -70,9 +70,9 @@ func registerJavaBuildComponents(ctx android.RegistrationContext) {  	// established, to not get the dependencies split into the wrong variants and  	// to support the checks in dexpreoptDisabled().  	ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) { -		ctx.BottomUp("dexpreopt_tool_deps", dexpreoptToolDepsMutator).Parallel() +		ctx.BottomUp("dexpreopt_tool_deps", dexpreoptToolDepsMutator)  		// needs access to ApexInfoProvider which is available after variant creation -		ctx.BottomUp("jacoco_deps", jacocoDepsMutator).Parallel() +		ctx.BottomUp("jacoco_deps", jacocoDepsMutator)  	})  	ctx.RegisterParallelSingletonType("kythe_java_extract", kytheExtractJavaFactory) @@ -450,7 +450,6 @@ var (  	javaApiContributionTag  = dependencyTag{name: "java-api-contribution"}  	aconfigDeclarationTag   = dependencyTag{name: "aconfig-declaration"}  	jniInstallTag           = dependencyTag{name: "jni install", runtimeLinked: true, installable: true} -	binaryInstallTag        = dependencyTag{name: "binary install", runtimeLinked: true, installable: true}  	usesLibReqTag           = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, false)  	usesLibOptTag           = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, true)  	usesLibCompat28OptTag   = makeUsesLibraryDependencyTag(28, true) @@ -1004,13 +1003,7 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {  	}  	j.compile(ctx, nil, nil, nil, nil) -	// If this module is an impl library created from java_sdk_library, -	// install the files under the java_sdk_library module outdir instead of this module outdir. -	if j.SdkLibraryName() != nil && strings.HasSuffix(j.Name(), ".impl") { -		j.setInstallRules(ctx, proptools.String(j.SdkLibraryName())) -	} else { -		j.setInstallRules(ctx, ctx.ModuleName()) -	} +	j.setInstallRules(ctx)  	android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{  		TestOnly:       Bool(j.sourceProperties.Test_only), @@ -1020,7 +1013,27 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {  	setOutputFiles(ctx, j.Module)  } -func (j *Library) setInstallRules(ctx android.ModuleContext, installModuleName string) { +func (j *Library) getJarInstallDir(ctx android.ModuleContext) android.InstallPath { +	var installDir android.InstallPath +	if ctx.InstallInTestcases() { +		var archDir string +		if !ctx.Host() { +			archDir = ctx.DeviceConfig().DeviceArch() +		} +		installModuleName := ctx.ModuleName() +		// If this module is an impl library created from java_sdk_library, +		// install the files under the java_sdk_library module outdir instead of this module outdir. +		if j.SdkLibraryName() != nil && strings.HasSuffix(j.Name(), ".impl") { +			installModuleName = proptools.String(j.SdkLibraryName()) +		} +		installDir = android.PathForModuleInstall(ctx, installModuleName, archDir) +	} else { +		installDir = android.PathForModuleInstall(ctx, "framework") +	} +	return installDir +} + +func (j *Library) setInstallRules(ctx android.ModuleContext) {  	apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)  	if (Bool(j.properties.Installable) || ctx.Host()) && apexInfo.IsForPlatform() { @@ -1034,17 +1047,7 @@ func (j *Library) setInstallRules(ctx android.ModuleContext, installModuleName s  				android.PathForHostDexInstall(ctx, "framework"),  				j.Stem()+"-hostdex.jar", j.outputFile)  		} -		var installDir android.InstallPath -		if ctx.InstallInTestcases() { -			var archDir string -			if !ctx.Host() { -				archDir = ctx.DeviceConfig().DeviceArch() -			} -			installDir = android.PathForModuleInstall(ctx, installModuleName, archDir) -		} else { -			installDir = android.PathForModuleInstall(ctx, "framework") -		} -		j.installFile = ctx.InstallFileWithoutCheckbuild(installDir, j.Stem()+".jar", j.outputFile, extraInstallDeps...) +		j.installFile = ctx.InstallFileWithoutCheckbuild(j.getJarInstallDir(ctx), j.Stem()+".jar", j.outputFile, extraInstallDeps...)  	}  } @@ -1288,6 +1291,16 @@ type testProperties struct {  	// the test  	Data []string `android:"path"` +	// Same as data, but will add dependencies on modules using the device's os variation and +	// the common arch variation. Useful for a host test that wants to embed a module built for +	// device. +	Device_common_data []string `android:"path_device_common"` + +	// same as data, but adds dependencies using the device's os variation and the device's first +	// architecture's variation. Can be used to add a module built for device to the data of a +	// host test. +	Device_first_data []string `android:"path_device_first"` +  	// Flag to indicate whether or not to create test config automatically. If AndroidTest.xml  	// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true  	// explicitly. @@ -1578,6 +1591,8 @@ func (j *Test) generateAndroidBuildActionsWithConfig(ctx android.ModuleContext,  	})  	j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data) +	j.data = append(j.data, android.PathsForModuleSrc(ctx, j.testProperties.Device_common_data)...) +	j.data = append(j.data, android.PathsForModuleSrc(ctx, j.testProperties.Device_first_data)...)  	j.extraTestConfigs = android.PathsForModuleSrc(ctx, j.testProperties.Test_options.Extra_test_configs) @@ -1804,8 +1819,6 @@ type Binary struct {  	binaryProperties binaryProperties -	isWrapperVariant bool -  	wrapperFile android.Path  	binaryFile  android.InstallPath @@ -1819,97 +1832,94 @@ func (j *Binary) HostToolPath() android.OptionalPath {  func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {  	j.stem = proptools.StringDefault(j.overridableProperties.Stem, ctx.ModuleName()) -	if ctx.Arch().ArchType == android.Common { -		// Compile the jar -		if j.binaryProperties.Main_class != nil { -			if j.properties.Manifest != nil { -				ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set") -			} -			manifestFile := android.PathForModuleOut(ctx, "manifest.txt") -			GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class)) -			j.overrideManifest = android.OptionalPathForPath(manifestFile) -		} - -		j.Library.GenerateAndroidBuildActions(ctx) +	// Handle the binary wrapper. This comes before compiling the jar so that the wrapper +	// is the first PackagingSpec +	if j.binaryProperties.Wrapper != nil { +		j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper)  	} else { -		// Handle the binary wrapper -		j.isWrapperVariant = true - -		if j.binaryProperties.Wrapper != nil { -			j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper) -		} else { -			if ctx.Windows() { -				ctx.PropertyErrorf("wrapper", "wrapper is required for Windows") -			} +		if ctx.Windows() { +			ctx.PropertyErrorf("wrapper", "wrapper is required for Windows") +		} -			if ctx.Device() { -				// device binary should have a main_class property if it does not -				// have a specific wrapper, so that a default wrapper can -				// be generated for it. -				if j.binaryProperties.Main_class == nil { -					ctx.PropertyErrorf("main_class", "main_class property "+ -						"is required for device binary if no default wrapper is assigned") -				} else { -					wrapper := android.PathForModuleOut(ctx, ctx.ModuleName()+".sh") -					jarName := j.Stem() + ".jar" -					partition := j.PartitionTag(ctx.DeviceConfig()) -					ctx.Build(pctx, android.BuildParams{ -						Rule:   deviceBinaryWrapper, -						Output: wrapper, -						Args: map[string]string{ -							"jar_name":   jarName, -							"partition":  partition, -							"main_class": String(j.binaryProperties.Main_class), -						}, -					}) -					j.wrapperFile = wrapper -				} +		if ctx.Device() { +			// device binary should have a main_class property if it does not +			// have a specific wrapper, so that a default wrapper can +			// be generated for it. +			if j.binaryProperties.Main_class == nil { +				ctx.PropertyErrorf("main_class", "main_class property "+ +					"is required for device binary if no default wrapper is assigned")  			} else { -				j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh") +				wrapper := android.PathForModuleOut(ctx, ctx.ModuleName()+".sh") +				jarName := j.Stem() + ".jar" +				partition := j.PartitionTag(ctx.DeviceConfig()) +				ctx.Build(pctx, android.BuildParams{ +					Rule:   deviceBinaryWrapper, +					Output: wrapper, +					Args: map[string]string{ +						"jar_name":   jarName, +						"partition":  partition, +						"main_class": String(j.binaryProperties.Main_class), +					}, +				}) +				j.wrapperFile = wrapper  			} +		} else { +			j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")  		} +	} -		ext := "" -		if ctx.Windows() { -			ext = ".bat" +	ext := "" +	if ctx.Windows() { +		ext = ".bat" +	} + +	// The host installation rules make the installed wrapper depend on all the dependencies +	// of the wrapper variant, which will include the common variant's jar file and any JNI +	// libraries.  This is verified by TestBinary. Also make it depend on the jar file so that +	// the binary file timestamp will update when the jar file timestamp does. The jar file is +	// built later on, in j.Library.GenerateAndroidBuildActions, so we have to create an identical +	// installpath representing it here. +	j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"), +		ctx.ModuleName()+ext, j.wrapperFile, j.getJarInstallDir(ctx).Join(ctx, j.Stem()+".jar")) + +	// Set the jniLibs of this binary. +	// These will be added to `LOCAL_REQUIRED_MODULES`, and the kati packaging system will +	// install these alongside the java binary. +	ctx.VisitDirectDepsWithTag(jniInstallTag, func(jni android.Module) { +		// Use the BaseModuleName of the dependency (without any prebuilt_ prefix) +		bmn, _ := jni.(interface{ BaseModuleName() string }) +		j.androidMkNamesOfJniLibs = append(j.androidMkNamesOfJniLibs, bmn.BaseModuleName()+":"+jni.Target().Arch.ArchType.Bitness()) +	}) +	// Check that native libraries are not listed in `required`. Prompt users to use `jni_libs` instead. +	ctx.VisitDirectDepsWithTag(android.RequiredDepTag, func(dep android.Module) { +		if _, hasSharedLibraryInfo := android.OtherModuleProvider(ctx, dep, cc.SharedLibraryInfoProvider); hasSharedLibraryInfo { +			ctx.ModuleErrorf("cc_library %s is no longer supported in `required` of java_binary modules. Please use jni_libs instead.", dep.Name())  		} +	}) -		// The host installation rules make the installed wrapper depend on all the dependencies -		// of the wrapper variant, which will include the common variant's jar file and any JNI -		// libraries.  This is verified by TestBinary. -		j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"), -			ctx.ModuleName()+ext, j.wrapperFile) - -		setOutputFiles(ctx, j.Library.Module) - -		// Set the jniLibs of this binary. -		// These will be added to `LOCAL_REQUIRED_MODULES`, and the kati packaging system will -		// install these alongside the java binary. -		ctx.VisitDirectDepsWithTag(jniInstallTag, func(jni android.Module) { -			// Use the BaseModuleName of the dependency (without any prebuilt_ prefix) -			bmn, _ := jni.(interface{ BaseModuleName() string }) -			j.androidMkNamesOfJniLibs = append(j.androidMkNamesOfJniLibs, bmn.BaseModuleName()+":"+jni.Target().Arch.ArchType.Bitness()) -		}) -		// Check that native libraries are not listed in `required`. Prompt users to use `jni_libs` instead. -		ctx.VisitDirectDepsWithTag(android.RequiredDepTag, func(dep android.Module) { -			if _, hasSharedLibraryInfo := android.OtherModuleProvider(ctx, dep, cc.SharedLibraryInfoProvider); hasSharedLibraryInfo { -				ctx.ModuleErrorf("cc_library %s is no longer supported in `required` of java_binary modules. Please use jni_libs instead.", dep.Name()) -			} -		}) +	// Compile the jar +	if j.binaryProperties.Main_class != nil { +		if j.properties.Manifest != nil { +			ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set") +		} +		manifestFile := android.PathForModuleOut(ctx, "manifest.txt") +		GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class)) +		j.overrideManifest = android.OptionalPathForPath(manifestFile)  	} + +	j.Library.GenerateAndroidBuildActions(ctx)  }  func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) { -	if ctx.Arch().ArchType == android.Common { -		j.deps(ctx) -	} +	j.deps(ctx)  	// These dependencies ensure the installation rules will install the jar file when the  	// wrapper is installed, and the jni libraries when the wrapper is installed. -	if ctx.Arch().ArchType != android.Common { -		ctx.AddVariationDependencies(nil, jniInstallTag, j.binaryProperties.Jni_libs...) -		ctx.AddVariationDependencies( -			[]blueprint.Variation{{Mutator: "arch", Variation: android.CommonArch.String()}}, -			binaryInstallTag, ctx.ModuleName()) +	if ctx.Os().Class == android.Host { +		ctx.AddVariationDependencies(ctx.Config().BuildOSTarget.Variations(), jniInstallTag, j.binaryProperties.Jni_libs...) +	} else if ctx.Os().Class == android.Device { +		ctx.AddVariationDependencies(ctx.Config().AndroidFirstDeviceTarget.Variations(), jniInstallTag, j.binaryProperties.Jni_libs...) +	} else { +		ctx.ModuleErrorf("Unknown os class")  	}  } @@ -1929,7 +1939,7 @@ func BinaryFactory() android.Module {  	module.Module.properties.Installable = proptools.BoolPtr(true) -	android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst) +	android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)  	android.InitDefaultableModule(module)  	return module @@ -1947,7 +1957,7 @@ func BinaryHostFactory() android.Module {  	module.Module.properties.Installable = proptools.BoolPtr(true) -	android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst) +	android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)  	android.InitDefaultableModule(module)  	return module  } @@ -2456,7 +2466,7 @@ func (al *ApiLibrary) ideDeps(ctx android.BaseModuleContext) []string {  	ret := []string{}  	ret = append(ret, al.properties.Libs.GetOrDefault(ctx, nil)...)  	ret = append(ret, al.properties.Static_libs.GetOrDefault(ctx, nil)...) -	if al.properties.System_modules != nil { +	if proptools.StringDefault(al.properties.System_modules, "none") != "none" {  		ret = append(ret, proptools.String(al.properties.System_modules))  	}  	// Other non java_library dependencies like java_api_contribution are ignored for now. @@ -3345,7 +3355,7 @@ func addCLCFromDep(ctx android.ModuleContext, depModule android.Module,  	if sdkLib != nil {  		optional := false  		if module, ok := ctx.Module().(ModuleWithUsesLibrary); ok { -			if android.InList(*sdkLib, module.UsesLibrary().usesLibraryProperties.Optional_uses_libs) { +			if android.InList(*sdkLib, module.UsesLibrary().usesLibraryProperties.Optional_uses_libs.GetOrDefault(ctx, nil)) {  				optional = true  			}  		} |