diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 81 | 
1 files changed, 30 insertions, 51 deletions
| diff --git a/java/java.go b/java/java.go index d5aeb7cb2..bf692be24 100644 --- a/java/java.go +++ b/java/java.go @@ -1667,11 +1667,6 @@ type JavaApiLibraryProperties struct {  	// This is a list of Soong modules  	Api_contributions []string -	// list of api.txt files relative to this directory that contribute to the -	// API surface. -	// This is a list of relative paths -	Api_files []string `android:"path"` -  	// List of flags to be passed to the javac compiler to generate jar file  	Javacflags []string @@ -1819,37 +1814,22 @@ func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {  	}  } -// API signature file names sorted from -// the narrowest api scope to the widest api scope -var scopeOrderedSourceFileNames = allApiScopes.Strings( -	func(s *apiScope) string { return s.apiFilePrefix + "current.txt" }) - -func (al *ApiLibrary) sortApiFilesByApiScope(ctx android.ModuleContext, srcFilesInfo []JavaApiImportInfo, apiFiles android.Paths) android.Paths { -	var sortedSrcFiles android.Paths - -	for i, apiScope := range allApiScopes { -		for _, srcFileInfo := range srcFilesInfo { -			if srcFileInfo.ApiFile.Base() == scopeOrderedSourceFileNames[i] || srcFileInfo.ApiSurface == apiScope.name { -				sortedSrcFiles = append(sortedSrcFiles, android.PathForSource(ctx, srcFileInfo.ApiFile.String())) -			} -		} -		// TODO: b/300964421 - Remove when api_files property is removed -		for _, apiFileName := range apiFiles { -			if apiFileName.Base() == scopeOrderedSourceFileNames[i] { -				sortedSrcFiles = append(sortedSrcFiles, apiFileName) -			} -		} -	} +// Map where key is the api scope name and value is the int value +// representing the order of the api scope, narrowest to the widest +var scopeOrderMap = allApiScopes.MapToIndex( +	func(s *apiScope) string { return s.name }) -	if len(srcFilesInfo)+len(apiFiles) != len(sortedSrcFiles) { -		var srcFiles android.Paths -		for _, srcFileInfo := range srcFilesInfo { -			srcFiles = append(srcFiles, srcFileInfo.ApiFile) +func (al *ApiLibrary) sortApiFilesByApiScope(ctx android.ModuleContext, srcFilesInfo []JavaApiImportInfo) []JavaApiImportInfo { +	for _, srcFileInfo := range srcFilesInfo { +		if srcFileInfo.ApiSurface == "" { +			ctx.ModuleErrorf("Api surface not defined for the associated api file %s", srcFileInfo.ApiFile)  		} -		ctx.ModuleErrorf("Unrecognizable source file found within %s", append(srcFiles, apiFiles...))  	} +	sort.Slice(srcFilesInfo, func(i, j int) bool { +		return scopeOrderMap[srcFilesInfo[i].ApiSurface] < scopeOrderMap[srcFilesInfo[j].ApiSurface] +	}) -	return sortedSrcFiles +	return srcFilesInfo  }  func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -1892,16 +1872,12 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {  		}  	}) -	// Add the api_files inputs -	// These are api files in the module subdirectory, which are not provided by -	// java_api_contribution but provided directly as module property. -	var apiFiles android.Paths -	for _, api := range al.properties.Api_files { -		apiFiles = append(apiFiles, android.PathForModuleSrc(ctx, api)) +	srcFilesInfo = al.sortApiFilesByApiScope(ctx, srcFilesInfo) +	var srcFiles android.Paths +	for _, srcFileInfo := range srcFilesInfo { +		srcFiles = append(srcFiles, android.PathForSource(ctx, srcFileInfo.ApiFile.String()))  	} -	srcFiles := al.sortApiFilesByApiScope(ctx, srcFilesInfo, apiFiles) -  	if srcFiles == nil && !ctx.Config().AllowMissingDependencies() {  		ctx.ModuleErrorf("Error: %s has an empty api file.", ctx.ModuleName())  	} @@ -3067,17 +3043,6 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.Bp2buildMutatorContext  		}  	} -	protoDepLabel := bp2buildProto(ctx, &m.Module, srcPartitions[protoSrcPartition]) -	// 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 { -		staticDeps.Append(bazel.MakeSingleLabelListAttribute(*protoDepLabel)) -	} -  	depLabels := &javaDependencyLabels{}  	depLabels.Deps = deps @@ -3093,6 +3058,20 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.Bp2buildMutatorContext  	}  	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, |