diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 82 | 
1 files changed, 68 insertions, 14 deletions
| diff --git a/java/java.go b/java/java.go index 874f93576..a00e26f83 100644 --- a/java/java.go +++ b/java/java.go @@ -795,6 +795,8 @@ type librarySdkMemberProperties struct {  	// The value of the min_sdk_version property, translated into a number where possible.  	MinSdkVersion *string `supported_build_releases:"Tiramisu+"` + +	DexPreoptProfileGuided *bool `supported_build_releases:"UpsideDownCake+"`  }  func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { @@ -812,6 +814,10 @@ func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberCo  		canonical := android.ReplaceFinalizedCodenames(ctx.SdkModuleContext().Config(), j.minSdkVersion.ApiLevel.String())  		p.MinSdkVersion = proptools.StringPtr(canonical)  	} + +	if j.dexpreopter.dexpreoptProperties.Dex_preopt_result.Profile_guided { +		p.DexPreoptProfileGuided = proptools.BoolPtr(true) +	}  }  func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { @@ -838,6 +844,11 @@ func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberConte  		propertySet.AddProperty("permitted_packages", p.PermittedPackages)  	} +	dexPreoptSet := propertySet.AddPropertySet("dex_preopt") +	if p.DexPreoptProfileGuided != nil { +		dexPreoptSet.AddProperty("profile_guided", proptools.Bool(p.DexPreoptProfileGuided)) +	} +  	// Do not copy anything else to the snapshot.  	if memberType.onlyCopyJarToSnapshot {  		return @@ -1627,6 +1638,10 @@ type JavaApiLibraryProperties struct {  	// List of shared java libs that this module has dependencies to and  	// should be passed as classpath in javac invocation  	Libs []string + +	// List of java libs that this module has static dependencies to and will be +	// passed in metalava invocation +	Static_libs []string  }  func ApiLibraryFactory() android.Module { @@ -1699,6 +1714,7 @@ func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {  		ctx.AddDependency(ctx.Module(), javaApiContributionTag, apiContributionName)  	}  	ctx.AddVariationDependencies(nil, libTag, al.properties.Libs...) +	ctx.AddVariationDependencies(nil, staticLibTag, al.properties.Static_libs...)  }  func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -1718,6 +1734,7 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {  	var srcFiles android.Paths  	var classPaths android.Paths +	var staticLibs android.Paths  	ctx.VisitDirectDeps(func(dep android.Module) {  		tag := ctx.OtherModuleDependencyTag(dep)  		switch tag { @@ -1731,6 +1748,9 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {  		case libTag:  			provider := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo)  			classPaths = append(classPaths, provider.HeaderJars...) +		case staticLibTag: +			provider := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo) +			staticLibs = append(staticLibs, provider.HeaderJars...)  		}  	}) @@ -1755,17 +1775,25 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {  		FlagWithArg("-D ", stubsDir.String())  	rule.Build("metalava", "metalava merged") - -	al.stubsJar = android.PathForModuleOut(ctx, ctx.ModuleName(), "android.jar") +	compiledStubs := android.PathForModuleOut(ctx, ctx.ModuleName(), "stubs.jar") +	al.stubsJar = android.PathForModuleOut(ctx, ctx.ModuleName(), fmt.Sprintf("%s.jar", ctx.ModuleName()))  	var flags javaBuilderFlags  	flags.javaVersion = getStubsJavaVersion()  	flags.javacFlags = strings.Join(al.properties.Javacflags, " ")  	flags.classpath = classpath(classPaths) -	TransformJavaToClasses(ctx, al.stubsJar, 0, android.Paths{}, +	TransformJavaToClasses(ctx, compiledStubs, 0, android.Paths{},  		android.Paths{al.stubsSrcJar}, flags, android.Paths{}) +	builder := android.NewRuleBuilder(pctx, ctx) +	builder.Command(). +		BuiltTool("merge_zips"). +		Output(al.stubsJar). +		Inputs(android.Paths{compiledStubs}). +		Inputs(staticLibs) +	builder.Build("merge_zips", "merge jar files") +  	ctx.Phony(ctx.ModuleName(), al.stubsJar)  	ctx.SetProvider(JavaInfoProvider, JavaInfo{ @@ -1991,7 +2019,8 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {  			if di == nil {  				return // An error has been reported by FindDeapexerProviderForModule.  			} -			if dexOutputPath := di.PrebuiltExportPath(apexRootRelativePathToJavaLib(j.BaseModuleName())); dexOutputPath != nil { +			dexJarFileApexRootRelative := apexRootRelativePathToJavaLib(j.BaseModuleName()) +			if dexOutputPath := di.PrebuiltExportPath(dexJarFileApexRootRelative); dexOutputPath != nil {  				dexJarFile := makeDexJarPathFromPath(dexOutputPath)  				j.dexJarFile = dexJarFile  				installPath := android.PathForModuleInPartitionInstall(ctx, "apex", ai.ApexVariationName, apexRootRelativePathToJavaLib(j.BaseModuleName())) @@ -2000,6 +2029,11 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {  				j.dexpreopter.installPath = j.dexpreopter.getInstallPath(ctx, installPath)  				setUncompressDex(ctx, &j.dexpreopter, &j.dexer)  				j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex + +				if profilePath := di.PrebuiltExportPath(dexJarFileApexRootRelative + ".prof"); profilePath != nil { +					j.dexpreopter.inputProfilePathOnHost = profilePath +				} +  				j.dexpreopt(ctx, dexOutputPath)  				// Initialize the hiddenapi structure. @@ -2027,7 +2061,15 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {  			j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex  			var dexOutputFile android.OutputPath -			dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(ctx), outputFile, jarName) +			dexParams := &compileDexParams{ +				flags:         flags, +				sdkVersion:    j.SdkVersion(ctx), +				minSdkVersion: j.MinSdkVersion(ctx), +				classesJar:    outputFile, +				jarName:       jarName, +			} + +			dexOutputFile = j.dexer.compileDex(ctx, dexParams)  			if ctx.Failed() {  				return  			} @@ -2118,15 +2160,18 @@ func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu  // Implements android.ApexModule  func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext,  	sdkVersion android.ApiLevel) error { -	sdkSpec := j.MinSdkVersion(ctx) -	if !sdkSpec.Specified() { +	sdkVersionSpec := j.SdkVersion(ctx) +	minSdkVersionSpec := j.MinSdkVersion(ctx) +	if !minSdkVersionSpec.Specified() {  		return fmt.Errorf("min_sdk_version is not specified")  	} -	if sdkSpec.Kind == android.SdkCore { +	// If the module is compiling against core (via sdk_version), skip comparison check. +	if sdkVersionSpec.Kind == android.SdkCore {  		return nil  	} -	if sdkSpec.ApiLevel.GreaterThan(sdkVersion) { -		return fmt.Errorf("newer SDK(%v)", sdkSpec.ApiLevel) +	minSdkVersion := minSdkVersionSpec.ApiLevel +	if minSdkVersion.GreaterThan(sdkVersion) { +		return fmt.Errorf("newer SDK(%v)", minSdkVersion)  	}  	return nil  } @@ -2134,11 +2179,16 @@ func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext,  // requiredFilesFromPrebuiltApexForImport returns information about the files that a java_import or  // java_sdk_library_import with the specified base module name requires to be exported from a  // prebuilt_apex/apex_set. -func requiredFilesFromPrebuiltApexForImport(name string) []string { +func requiredFilesFromPrebuiltApexForImport(name string, d *dexpreopter) []string { +	dexJarFileApexRootRelative := apexRootRelativePathToJavaLib(name)  	// Add the dex implementation jar to the set of exported files. -	return []string{ -		apexRootRelativePathToJavaLib(name), +	files := []string{ +		dexJarFileApexRootRelative, +	} +	if BoolDefault(d.importDexpreoptProperties.Dex_preopt.Profile_guided, false) { +		files = append(files, dexJarFileApexRootRelative+".prof")  	} +	return files  }  // apexRootRelativePathToJavaLib returns the path, relative to the root of the apex's contents, for @@ -2151,7 +2201,7 @@ var _ android.RequiredFilesFromPrebuiltApex = (*Import)(nil)  func (j *Import) RequiredFilesFromPrebuiltApex(_ android.BaseModuleContext) []string {  	name := j.BaseModuleName() -	return requiredFilesFromPrebuiltApexForImport(name) +	return requiredFilesFromPrebuiltApexForImport(name, &j.dexpreopter)  }  // Add compile time check for interface implementation @@ -2192,6 +2242,7 @@ func ImportFactory() android.Module {  	module.AddProperties(  		&module.properties,  		&module.dexer.dexProperties, +		&module.importDexpreoptProperties,  	)  	module.initModuleAndImport(module) @@ -2761,6 +2812,9 @@ func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {  		if sdkVersion.Kind == android.SdkPublic && sdkVersion.ApiLevel == android.FutureApiLevel {  			// TODO(b/220869005) remove forced dependency on current public android.jar  			deps.Add(bazel.MakeLabelAttribute("//prebuilts/sdk:public_current_android_sdk_java_import")) +		} else if sdkVersion.Kind == android.SdkSystem && sdkVersion.ApiLevel == android.FutureApiLevel { +			// TODO(b/215230098) remove forced dependency on current public android.jar +			deps.Add(bazel.MakeLabelAttribute("//prebuilts/sdk:system_current_android_sdk_java_import"))  		}  	} else if !deps.IsEmpty() {  		ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.") |