From 86758ac94c6807c473dd895622de6efe84c1f87c Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Wed, 3 Nov 2021 14:44:12 +0000 Subject: [PATCH] Make PrebuiltStubsSources support srcjar properly Initially prebuilt stub sources only supported directories as input, but support has been added for packaging them up in srcjar as well. However the build action was not updated accordingly. Add support to determine if our input is a srcjar, and if so just use it directly. Bug: 204978699 Test: m sdk (with prebuilts) Change-Id: I302cd34ebd55414d35c4f936cd563a4af89b22c6 --- java/droidstubs.go | 51 +++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/java/droidstubs.go b/java/droidstubs.go index 0c66ccf40..7ad316fcf 100644 --- a/java/droidstubs.go +++ b/java/droidstubs.go @@ -16,6 +16,7 @@ package java import ( "fmt" + "path/filepath" "strings" "github.com/google/blueprint/proptools" @@ -805,7 +806,7 @@ type PrebuiltStubsSources struct { properties PrebuiltStubsSourcesProperties - stubsSrcJar android.ModuleOutPath + stubsSrcJar android.Path } func (p *PrebuiltStubsSources) OutputFiles(tag string) (android.Paths, error) { @@ -822,35 +823,39 @@ func (d *PrebuiltStubsSources) StubsSrcJar() android.Path { } func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) { - p.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar") - if len(p.properties.Srcs) != 1 { - ctx.PropertyErrorf("srcs", "must only specify one directory path, contains %d paths", len(p.properties.Srcs)) + ctx.PropertyErrorf("srcs", "must only specify one directory path or srcjar, contains %d paths", len(p.properties.Srcs)) return } - localSrcDir := p.properties.Srcs[0] - // Although PathForModuleSrc can return nil if either the path doesn't exist or - // the path components are invalid it won't in this case because no components - // are specified and the module directory must exist in order to get this far. - srcDir := android.PathForModuleSrc(ctx).(android.SourcePath).Join(ctx, localSrcDir) + src := p.properties.Srcs[0] + if filepath.Ext(src) == ".srcjar" { + // This is a srcjar. We can use it directly. + p.stubsSrcJar = android.PathForModuleSrc(ctx, src) + } else { + outPath := android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar") - // Glob the contents of the directory just in case the directory does not exist. - srcGlob := localSrcDir + "/**/*" - srcPaths := android.PathsForModuleSrc(ctx, []string{srcGlob}) + // This is a directory. Glob the contents just in case the directory does not exist. + srcGlob := src + "/**/*" + srcPaths := android.PathsForModuleSrc(ctx, []string{srcGlob}) - rule := android.NewRuleBuilder(pctx, ctx) - rule.Command(). - BuiltTool("soong_zip"). - Flag("-write_if_changed"). - Flag("-jar"). - FlagWithOutput("-o ", p.stubsSrcJar). - FlagWithArg("-C ", srcDir.String()). - FlagWithRspFileInputList("-r ", p.stubsSrcJar.ReplaceExtension(ctx, "rsp"), srcPaths) + // Although PathForModuleSrc can return nil if either the path doesn't exist or + // the path components are invalid it won't in this case because no components + // are specified and the module directory must exist in order to get this far. + srcDir := android.PathForModuleSrc(ctx).(android.SourcePath).Join(ctx, src) - rule.Restat() - - rule.Build("zip src", "Create srcjar from prebuilt source") + rule := android.NewRuleBuilder(pctx, ctx) + rule.Command(). + BuiltTool("soong_zip"). + Flag("-write_if_changed"). + Flag("-jar"). + FlagWithOutput("-o ", outPath). + FlagWithArg("-C ", srcDir.String()). + FlagWithRspFileInputList("-r ", outPath.ReplaceExtension(ctx, "rsp"), srcPaths) + rule.Restat() + rule.Build("zip src", "Create srcjar from prebuilt source") + p.stubsSrcJar = outPath + } } func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {