Merge changes from topic "fix-stubs-source-snapshot"
* changes: Fix prebuilt_stubs_sources to work with no stubs sources Revert "Use glob for java_sdk_library_import stub_srcs"
This commit is contained in:
@@ -1748,8 +1748,6 @@ type PrebuiltStubsSources struct {
|
||||
|
||||
properties PrebuiltStubsSourcesProperties
|
||||
|
||||
// The source directories containing stubs source files.
|
||||
srcDirs android.Paths
|
||||
stubsSrcJar android.ModuleOutPath
|
||||
}
|
||||
|
||||
@@ -1769,21 +1767,29 @@ func (d *PrebuiltStubsSources) StubsSrcJar() android.Path {
|
||||
func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
p.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
|
||||
|
||||
p.srcDirs = android.PathsForModuleSrc(ctx, p.properties.Srcs)
|
||||
if len(p.properties.Srcs) != 1 {
|
||||
ctx.PropertyErrorf("srcs", "must only specify one directory path, 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)
|
||||
|
||||
// Glob the contents of the directory just in case the directory does not exist.
|
||||
srcGlob := localSrcDir + "/**/*"
|
||||
srcPaths := android.PathsForModuleSrc(ctx, []string{srcGlob})
|
||||
|
||||
rule := android.NewRuleBuilder()
|
||||
command := rule.Command().
|
||||
rule.Command().
|
||||
BuiltTool(ctx, "soong_zip").
|
||||
Flag("-write_if_changed").
|
||||
Flag("-jar").
|
||||
FlagWithOutput("-o ", p.stubsSrcJar)
|
||||
|
||||
for _, d := range p.srcDirs {
|
||||
dir := d.String()
|
||||
command.
|
||||
FlagWithArg("-C ", dir).
|
||||
FlagWithInput("-D ", d)
|
||||
}
|
||||
FlagWithOutput("-o ", p.stubsSrcJar).
|
||||
FlagWithArg("-C ", srcDir.String()).
|
||||
FlagWithRspFileInputList("-r ", srcPaths)
|
||||
|
||||
rule.Restat()
|
||||
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package java
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -622,6 +623,35 @@ func assertDeepEquals(t *testing.T, message string, expected interface{}, actual
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrebuiltStubsSources(t *testing.T) {
|
||||
test := func(t *testing.T, sourcesPath string, expectedInputs []string) {
|
||||
ctx, _ := testJavaWithFS(t, fmt.Sprintf(`
|
||||
prebuilt_stubs_sources {
|
||||
name: "stubs-source",
|
||||
srcs: ["%s"],
|
||||
}`, sourcesPath), map[string][]byte{
|
||||
"stubs/sources/pkg/A.java": nil,
|
||||
"stubs/sources/pkg/B.java": nil,
|
||||
})
|
||||
|
||||
zipSrc := ctx.ModuleForTests("stubs-source", "android_common").Rule("zip_src")
|
||||
if expected, actual := expectedInputs, zipSrc.Inputs.Strings(); !reflect.DeepEqual(expected, actual) {
|
||||
t.Errorf("mismatch of inputs to soong_zip: expected %q, actual %q", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
t.Run("empty/missing directory", func(t *testing.T) {
|
||||
test(t, "empty-directory", []string{})
|
||||
})
|
||||
|
||||
t.Run("non-empty set of sources", func(t *testing.T) {
|
||||
test(t, "stubs/sources", []string{
|
||||
"stubs/sources/pkg/A.java",
|
||||
"stubs/sources/pkg/B.java",
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaSdkLibraryImport(t *testing.T) {
|
||||
ctx, _ := testJava(t, `
|
||||
java_library {
|
||||
|
@@ -2300,11 +2300,10 @@ func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberCo
|
||||
scopeSet.AddProperty("jars", jars)
|
||||
|
||||
// Merge the stubs source jar into the snapshot zip so that when it is unpacked
|
||||
// the source files are also unpacked. Use a glob so that if the directory is missing
|
||||
// (because there are no stubs sources for this scope) it will not fail.
|
||||
// the source files are also unpacked.
|
||||
snapshotRelativeDir := filepath.Join(scopeDir, ctx.Name()+"_stub_sources")
|
||||
ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir)
|
||||
scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir + "/**/*.java"})
|
||||
scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir})
|
||||
|
||||
if properties.CurrentApiFile != nil {
|
||||
currentApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+".txt")
|
||||
|
Reference in New Issue
Block a user