diff options
author | Colin Cross <ccross@android.com> | 2019-03-05 22:25:09 -0800 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2019-03-20 19:36:13 +0000 |
commit | 8a49795df1ed87a4889f267dbd8d28c5832bb897 (patch) | |
tree | e769fe1ab955ab4420d1edf68355c2ff9a4b470e | |
parent | 07e51619a2752d6a36bd149c8938b5d7cae5baa7 (diff) | |
download | android_build_soong-8a49795df1ed87a4889f267dbd8d28c5832bb897.tar.gz android_build_soong-8a49795df1ed87a4889f267dbd8d28c5832bb897.tar.bz2 android_build_soong-8a49795df1ed87a4889f267dbd8d28c5832bb897.zip |
Replace ctx.ExpandSources with android.PathsForModuleSrc
Move the logic from ctx.ExpandSources into android.PathsForModuleSrc
and ctx.ExpandSource into android.PathForModuleSrc, and deprecate
them. When combined with the pathDepsMutator this will let all
properties that take source paths also take filegroups or genrule
outputs, as long as they are tagged with `android:"path"`.
Test: All soong tests
Change-Id: I01625e76b5da19240e9649bf26a014eeeafcab8f
-rw-r--r-- | android/filegroup.go | 2 | ||||
-rw-r--r-- | android/module.go | 89 | ||||
-rw-r--r-- | android/paths.go | 132 | ||||
-rw-r--r-- | android/paths_test.go | 240 | ||||
-rw-r--r-- | android/prebuilt.go | 2 | ||||
-rw-r--r-- | android/prebuilt_etc.go | 4 | ||||
-rw-r--r-- | android/sh_binary.go | 4 | ||||
-rw-r--r-- | apex/apex.go | 6 | ||||
-rw-r--r-- | bpf/bpf.go | 2 | ||||
-rw-r--r-- | cc/compiler.go | 2 | ||||
-rw-r--r-- | cc/library.go | 4 | ||||
-rw-r--r-- | cc/ndk_headers.go | 4 | ||||
-rw-r--r-- | cc/test.go | 4 | ||||
-rw-r--r-- | cc/test_data_test.go | 2 | ||||
-rw-r--r-- | genrule/genrule.go | 4 | ||||
-rw-r--r-- | java/aar.go | 2 | ||||
-rw-r--r-- | java/app.go | 2 | ||||
-rw-r--r-- | java/droiddoc.go | 18 | ||||
-rw-r--r-- | java/java.go | 14 | ||||
-rw-r--r-- | java/java_resources.go | 4 | ||||
-rw-r--r-- | python/python.go | 4 | ||||
-rw-r--r-- | xml/xml.go | 2 |
22 files changed, 361 insertions, 186 deletions
diff --git a/android/filegroup.go b/android/filegroup.go index 0b716c64..ec522fc0 100644 --- a/android/filegroup.go +++ b/android/filegroup.go @@ -60,7 +60,7 @@ func FileGroupFactory() Module { } func (fg *fileGroup) GenerateAndroidBuildActions(ctx ModuleContext) { - fg.srcs = ctx.ExpandSources(fg.properties.Srcs, fg.properties.Exclude_srcs) + fg.srcs = PathsForModuleSrcExcludes(ctx, fg.properties.Srcs, fg.properties.Exclude_srcs) if fg.properties.Path != nil { fg.srcs = PathsWithModuleSrcSubDir(ctx, fg.srcs, String(fg.properties.Path)) diff --git a/android/module.go b/android/module.go index dfeb45d1..afd2b714 100644 --- a/android/module.go +++ b/android/module.go @@ -854,7 +854,7 @@ func (a *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) if a.commonProperties.Notice != nil { // For filegroup-based notice file references. - a.noticeFile = ctx.ExpandSource(*a.commonProperties.Notice, "notice") + a.noticeFile = PathForModuleSrc(ctx, *a.commonProperties.Notice) } } @@ -1419,91 +1419,18 @@ type SourceFileProducer interface { // Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must // be tagged with `android:"path" to support automatic source module dependency resolution. +// +// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead. func (ctx *androidModuleContext) ExpandSources(srcFiles, excludes []string) Paths { - prefix := PathForModuleSrc(ctx).String() - - var expandedExcludes []string - if excludes != nil { - expandedExcludes = make([]string, 0, len(excludes)) - } - - for _, e := range excludes { - if m := SrcIsModule(e); m != "" { - module := ctx.GetDirectDepWithTag(m, SourceDepTag) - if module == nil { - if ctx.Config().AllowMissingDependencies() { - ctx.AddMissingDependencies([]string{m}) - } else { - ctx.ModuleErrorf(`missing dependency on %q, is the property annotated with android:"path"?`, m) - } - continue - } - if srcProducer, ok := module.(SourceFileProducer); ok { - expandedExcludes = append(expandedExcludes, srcProducer.Srcs().Strings()...) - } else { - ctx.ModuleErrorf("srcs dependency %q is not a source file producing module", m) - } - } else { - expandedExcludes = append(expandedExcludes, filepath.Join(prefix, e)) - } - } - expandedSrcFiles := make(Paths, 0, len(srcFiles)) - for _, s := range srcFiles { - if m := SrcIsModule(s); m != "" { - module := ctx.GetDirectDepWithTag(m, SourceDepTag) - if module == nil { - if ctx.Config().AllowMissingDependencies() { - ctx.AddMissingDependencies([]string{m}) - } else { - ctx.ModuleErrorf(`missing dependency on %q, is the property annotated with android:"path"?`, m) - } - continue - } - if srcProducer, ok := module.(SourceFileProducer); ok { - moduleSrcs := srcProducer.Srcs() - for _, e := range expandedExcludes { - for j, ms := range moduleSrcs { - if ms.String() == e { - moduleSrcs = append(moduleSrcs[:j], moduleSrcs[j+1:]...) - } - } - } - expandedSrcFiles = append(expandedSrcFiles, moduleSrcs...) - } else { - ctx.ModuleErrorf("srcs dependency %q is not a source file producing module", m) - } - } else if pathtools.IsGlob(s) { - globbedSrcFiles := ctx.GlobFiles(filepath.Join(prefix, s), expandedExcludes) - globbedSrcFiles = PathsWithModuleSrcSubDir(ctx, globbedSrcFiles, "") - expandedSrcFiles = append(expandedSrcFiles, globbedSrcFiles...) - } else { - p := PathForModuleSrc(ctx, s) - j := findStringInSlice(p.String(), expandedExcludes) - if j == -1 { - expandedSrcFiles = append(expandedSrcFiles, p) - } - } - } - return expandedSrcFiles + return PathsForModuleSrcExcludes(ctx, srcFiles, excludes) } // Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must // be tagged with `android:"path" to support automatic source module dependency resolution. +// +// Deprecated: use PathForModuleSrc instead. func (ctx *androidModuleContext) ExpandSource(srcFile, prop string) Path { - srcFiles := ctx.ExpandSources([]string{srcFile}, nil) - if len(srcFiles) == 1 { - return srcFiles[0] - } else if len(srcFiles) == 0 { - if ctx.Config().AllowMissingDependencies() { - ctx.AddMissingDependencies([]string{srcFile}) - } else { - ctx.PropertyErrorf(prop, "%s path %s does not exist", prop, srcFile) - } - return nil - } else { - ctx.PropertyErrorf(prop, "module providing %s must produce exactly one file", prop) - return nil - } + return PathForModuleSrc(ctx, srcFile) } // Returns an optional single path expanded from globs and modules referenced using ":module" syntax if @@ -1511,7 +1438,7 @@ func (ctx *androidModuleContext) ExpandSource(srcFile, prop string) Path { // dependency resolution. func (ctx *androidModuleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath { if srcFile != nil { - return OptionalPathForPath(ctx.ExpandSource(*srcFile, prop)) + return OptionalPathForPath(PathForModuleSrc(ctx, *srcFile)) } return OptionalPath{} } diff --git a/android/paths.go b/android/paths.go index a2908e1d..cdcb7192 100644 --- a/android/paths.go +++ b/android/paths.go @@ -220,11 +220,104 @@ func ExistentPathsForSources(ctx PathContext, paths []string) Paths { // PathsForModuleSrc returns Paths rooted from the module's local source // directory func PathsForModuleSrc(ctx ModuleContext, paths []string) Paths { - ret := make(Paths, len(paths)) - for i, path := range paths { - ret[i] = PathForModuleSrc(ctx, path) + return PathsForModuleSrcExcludes(ctx, paths, nil) +} + +func PathsForModuleSrcExcludes(ctx ModuleContext, paths, excludes []string) Paths { + prefix := pathForModuleSrc(ctx).String() + + var expandedExcludes []string + if excludes != nil { + expandedExcludes = make([]string, 0, len(excludes)) + } + + for _, e := range excludes { + if m := SrcIsModule(e); m != "" { + module := ctx.GetDirectDepWithTag(m, SourceDepTag) + if module == nil { + if ctx.Config().AllowMissingDependencies() { + ctx.AddMissingDependencies([]string{m}) + } else { + ctx.ModuleErrorf(`missing dependency on %q, is the property annotated with android:"path"?`, m) + } + continue + } + if srcProducer, ok := module.(SourceFileProducer); ok { + expandedExcludes = append(expandedExcludes, srcProducer.Srcs().Strings()...) + } else { + ctx.ModuleErrorf("srcs dependency %q is not a source file producing module", m) + } + } else { + expandedExcludes = append(expandedExcludes, filepath.Join(prefix, e)) + } + } + + if paths == nil { + return nil + } + + expandedSrcFiles := make(Paths, 0, len(paths)) + for _, s := range paths { + srcFiles, err := expandOneSrcPath(ctx, s, expandedExcludes) + if depErr, ok := err.(missingDependencyError); ok { + if ctx.Config().AllowMissingDependencies() { + ctx.AddMissingDependencies(depErr.missingDeps) + } else { + ctx.ModuleErrorf(`%s, is the property annotated with android:"path"?`, depErr.Error()) + } + } else if err != nil { + reportPathError(ctx, err) + } + expandedSrcFiles = append(expandedSrcFiles, srcFiles...) + } + return expandedSrcFiles +} + +type missingDependencyError struct { + missingDeps []string +} + +func (e missingDependencyError) Error() string { + return "missing dependencies: " + strings.Join(e.missingDeps, ", ") +} + +func expandOneSrcPath(ctx ModuleContext, s string, expandedExcludes []string) (Paths, error) { + if m := SrcIsModule(s); m != "" { + module := ctx.GetDirectDepWithTag(m, SourceDepTag) + if module == nil { + return nil, missingDependencyError{[]string{m}} + } + if srcProducer, ok := module.(SourceFileProducer); ok { + moduleSrcs := srcProducer.Srcs() + for _, e := range expandedExcludes { + for j := 0; j < len(moduleSrcs); j++ { + if moduleSrcs[j].String() == e { + moduleSrcs = append(moduleSrcs[:j], moduleSrcs[j+1:]...) + j-- + } + } + } + return moduleSrcs, nil + } else { + return nil, fmt.Errorf("path dependency %q is not a source file producing module", m) + } + } else if pathtools.IsGlob(s) { + paths := ctx.GlobFiles(pathForModuleSrc(ctx, s).String(), expandedExcludes) + return PathsWithModuleSrcSubDir(ctx, paths, ""), nil + } else { + p := pathForModuleSrc(ctx, s) + if exists, _, err := ctx.Fs().Exists(p.String()); err != nil { + reportPathErrorf(ctx, "%s: %s", p, err.Error()) + } else if !exists { + reportPathErrorf(ctx, "module source path %q does not exist", p) + } + + j := findStringInSlice(p.String(), expandedExcludes) + if j >= 0 { + return nil, nil + } + return Paths{p}, nil } - return ret } // pathsForModuleSrcFromFullPath returns Paths rooted from the module's local @@ -750,15 +843,30 @@ var _ resPathProvider = SourcePath{} // PathForModuleSrc returns a Path representing the paths... under the // module's local source directory. -func PathForModuleSrc(ctx ModuleContext, paths ...string) Path { - path := pathForModuleSrc(ctx, paths...) - - if exists, _, err := ctx.Fs().Exists(path.String()); err != nil { - reportPathErrorf(ctx, "%s: %s", path, err.Error()) - } else if !exists { - reportPathErrorf(ctx, "module source path %q does not exist", path) +func PathForModuleSrc(ctx ModuleContext, pathComponents ...string) Path { + p, err := validatePath(pathComponents...) + if err != nil { + reportPathError(ctx, err) } - return path + paths, err := expandOneSrcPath(ctx, p, nil) + if err != nil { + if depErr, ok := err.(missingDependencyError); ok { + if ctx.Config().AllowMissingDependencies() { + ctx.AddMissingDependencies(depErr.missingDeps) + } else { + ctx.ModuleErrorf(`%s, is the property annotated with android:"path"?`, depErr.Error()) + } + } else { + reportPathError(ctx, err) + } + return nil + } else if len(paths) == 0 { + reportPathErrorf(ctx, "%q produced no files, expected exactly one", p) + return nil + } else if len(paths) > 1 { + reportPathErrorf(ctx, "%q produced %d files, expected exactly one", p, len(paths)) + } + return paths[0] } func pathForModuleSrc(ctx ModuleContext, paths ...string) SourcePath { diff --git a/android/paths_test.go b/android/paths_test.go index f5902b53..2e0e0e86 100644 --- a/android/paths_test.go +++ b/android/paths_test.go @@ -24,6 +24,7 @@ import ( "testing" "github.com/google/blueprint/pathtools" + "github.com/google/blueprint/proptools" ) type strsTestCase struct { @@ -706,39 +707,117 @@ func TestPathForSource(t *testing.T) { } } -type expandSourcesTestModule struct { +type pathForModuleSrcTestModule struct { ModuleBase props struct { Srcs []string `android:"path"` Exclude_srcs []string `android:"path"` + + Src *string `android:"path"` } - srcs Paths + src string + rel string + + srcs []string rels []string + + missingDeps []string } -func expandSourcesTestModuleFactory() Module { - module := &expandSourcesTestModule{} +func pathForModuleSrcTestModuleFactory() Module { + module := &pathForModuleSrcTestModule{} module.AddProperties(&module.props) InitAndroidModule(module) return module } -func (p *expandSourcesTestModule) GenerateAndroidBuildActions(ctx ModuleContext) { - p.srcs = ctx.ExpandSources(p.props.Srcs, p.props.Exclude_srcs) +func (p *pathForModuleSrcTestModule) GenerateAndroidBuildActions(ctx ModuleContext) { + srcs := PathsForModuleSrcExcludes(ctx, p.props.Srcs, p.props.Exclude_srcs) + p.srcs = srcs.Strings() - for _, src := range p.srcs { + for _, src := range srcs { p.rels = append(p.rels, src.Rel()) } + + if p.props.Src != nil { + src := PathForModuleSrc(ctx, *p.props.Src) + if src != nil { + p.src = src.String() + p.rel = src.Rel() + } + } + + p.missingDeps = ctx.GetMissingDependencies() } -func TestExpandSources(t *testing.T) { - tests := []struct { - name string - bp string - srcs []string - rels []string - }{ +type pathForModuleSrcTestCase struct { + name string + bp string + srcs []string + rels []string + src string + rel string +} + +func testPathForModuleSrc(t *testing.T, buildDir string, tests []pathForModuleSrcTestCase) { + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + config := TestConfig(buildDir, nil) + ctx := NewTestContext() + + ctx.RegisterModuleType("test", ModuleFactoryAdaptor(pathForModuleSrcTestModuleFactory)) + ctx.RegisterModuleType("filegroup", ModuleFactoryAdaptor(FileGroupFactory)) + + fgBp := ` + filegroup { + name: "a", + srcs: ["src/a"], + } + ` + + mockFS := map[string][]byte{ + "fg/Android.bp": []byte(fgBp), + "foo/Android.bp": []byte(test.bp), + "fg/src/a": nil, + "foo/src/b": nil, + "foo/src/c": nil, + "foo/src/d": nil, + "foo/src/e/e": nil, + "foo/src_special/$": nil, + } + + ctx.MockFileSystem(mockFS) + + ctx.Register() + _, errs := ctx.ParseFileList(".", []string{"fg/Android.bp", "foo/Android.bp"}) + FailIfErrored(t, errs) + _, errs = ctx.PrepareBuildActions(config) + FailIfErrored(t, errs) + + m := ctx.ModuleForTests("foo", "").Module().(*pathForModuleSrcTestModule) + + if g, w := m.srcs, test.srcs; !reflect.DeepEqual(g, w) { + t.Errorf("want srcs %q, got %q", w, g) + } + + if g, w := m.rels, test.rels; !reflect.DeepEqual(g, w) { + t.Errorf("want rels %q, got %q", w, g) + } + + if g, w := m.src, test.src; g != w { + t.Errorf("want src %q, got %q", w, g) + } + + if g, w := m.rel, test.rel; g != w { + t.Errorf("want rel %q, got %q", w, g) + } + }) + } +} + +func TestPathsForModuleSrc(t *testing.T) { + tests := []pathForModuleSrcTestCase{ { name: "path", bp: ` @@ -794,57 +873,118 @@ func TestExpandSources(t *testing.T) { }, } + buildDir, err := ioutil.TempDir("", "soong_paths_for_module_src_test") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(buildDir) + + testPathForModuleSrc(t, buildDir, tests) +} + +func TestPathForModuleSrc(t *testing.T) { + tests := []pathForModuleSrcTestCase{ + { + name: "path", + bp: ` + test { + name: "foo", + src: "src/b", + }`, + src: "foo/src/b", + rel: "src/b", + }, + { + name: "glob", + bp: ` + test { + name: "foo", + src: "src/e/*", + }`, + src: "foo/src/e/e", + rel: "src/e/e", + }, + { + name: "filegroup", + bp: ` + test { + name: "foo", + src: ":a", + }`, + src: "fg/src/a", + rel: "src/a", + }, + { + name: "special characters glob", + bp: ` + test { + name: "foo", + src: "src_special/*", + }`, + src: "foo/src_special/$", + rel: "src_special/$", + }, + } + buildDir, err := ioutil.TempDir("", "soong_path_for_module_src_test") if err != nil { t.Fatal(err) } defer os.RemoveAll(buildDir) - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - config := TestConfig(buildDir, nil) - ctx := NewTestContext() + testPathForModuleSrc(t, buildDir, tests) +} - ctx.RegisterModuleType("test", ModuleFactoryAdaptor(expandSourcesTestModuleFactory)) - ctx.RegisterModuleType("filegroup", ModuleFactoryAdaptor(FileGroupFactory)) +func TestPathsForModuleSrc_AllowMissingDependencies(t *testing.T) { + buildDir, err := ioutil.TempDir("", "soong_paths_for_module_src_allow_missing_dependencies_test") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(buildDir) - fgBp := ` - filegroup { - name: "a", - srcs: ["src/a"], - } - ` + config := TestConfig(buildDir, nil) + config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true) - mockFS := map[string][]byte{ - "fg/Android.bp": []byte(fgBp), - "foo/Android.bp": []byte(test.bp), - "fg/src/a": nil, - "foo/src/b": nil, - "foo/src/c": nil, - "foo/src/d": nil, - "foo/src/e/e": nil, - "foo/src_special/$": nil, - } + ctx := NewTestContext() + ctx.SetAllowMissingDependencies(true) - ctx.MockFileSystem(mockFS) + ctx.RegisterModuleType("test", ModuleFactoryAdaptor(pathForModuleSrcTestModuleFactory)) - ctx.Register() - _, errs := ctx.ParseFileList(".", []string{"fg/Android.bp", "foo/Android.bp"}) - FailIfErrored(t, errs) - _, errs = ctx.PrepareBuildActions(config) - FailIfErrored(t, errs) + bp := ` + test { + name: "foo", + srcs: [":a"], + exclude_srcs: [":b"], + src: ":c", + } + ` - m := ctx.ModuleForTests("foo", "").Module().(*expandSourcesTestModule) + mockFS := map[string][]byte{ + "Android.bp": []byte(bp), + } - if g, w := m.srcs.Strings(), test.srcs; !reflect.DeepEqual(g, w) { - t.Errorf("want srcs %q, got %q", w, g) - } + ctx.MockFileSystem(mockFS) - if g, w := m.rels, test.rels; !reflect.DeepEqual(g, w) { - t.Errorf("want rels %q, got %q", w, g) - } - }) + ctx.Register() + _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) + FailIfErrored(t, errs) + _, errs = ctx.PrepareBuildActions(config) + FailIfErrored(t, errs) + + foo := ctx.ModuleForTests("foo", "").Module().(*pathForModuleSrcTestModule) + + if g, w := foo.missingDeps, []string{"a", "b", "c"}; !reflect.DeepEqual(g, w) { + t.Errorf("want missing deps %q, got %q", w, g) } + + if g, w := foo.srcs, []string{}; !reflect.DeepEqual(g, w) { + t.Errorf("want srcs %q, got %q", w, g) + } + + if g, w := foo.src, ""; g != w { + t.Errorf("want src %q, got %q", w, g) + } + } func ExampleOutputPath_ReplaceExtension() { diff --git a/android/prebuilt.go b/android/prebuilt.go index ea4870dd..5bd0e2da 100644 --- a/android/prebuilt.go +++ b/android/prebuilt.go @@ -61,7 +61,7 @@ func (p *Prebuilt) SingleSourcePath(ctx ModuleContext) Path { // Return the singleton source after expanding any filegroup in the // sources. - return ctx.ExpandSource((*p.srcs)[0], "") + return PathForModuleSrc(ctx, (*p.srcs)[0]) } func InitPrebuiltModule(module PrebuiltInterface, srcs *[]string) { diff --git a/android/prebuilt_etc.go b/android/prebuilt_etc.go index 0c68b0cc..2a3e07e3 100644 --- a/android/prebuilt_etc.go +++ b/android/prebuilt_etc.go @@ -88,7 +88,7 @@ func (p *PrebuiltEtc) DepsMutator(ctx BottomUpMutatorContext) { } func (p *PrebuiltEtc) SourceFilePath(ctx ModuleContext) Path { - return ctx.ExpandSource(String(p.properties.Src), "src") + return PathForModuleSrc(ctx, String(p.properties.Src)) } // This allows other derivative modules (e.g. prebuilt_etc_xml) to perform @@ -110,7 +110,7 @@ func (p *PrebuiltEtc) Installable() bool { } func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx ModuleContext) { - p.sourceFilePath = ctx.ExpandSource(String(p.properties.Src), "src") + p.sourceFilePath = PathForModuleSrc(ctx, String(p.properties.Src)) filename := String(p.properties.Filename) filename_from_src := Bool(p.properties.Filename_from_src) if filename == "" { diff --git a/android/sh_binary.go b/android/sh_binary.go index 8bb35178..bee61ef4 100644 --- a/android/sh_binary.go +++ b/android/sh_binary.go @@ -82,7 +82,7 @@ func (s *ShBinary) DepsMutator(ctx BottomUpMutatorContext) { } func (s *ShBinary) SourceFilePath(ctx ModuleContext) Path { - return ctx.ExpandSource(String(s.properties.Src), "src") + return PathForModuleSrc(ctx, String(s.properties.Src)) } func (s *ShBinary) OutputFile() OutputPath { @@ -98,7 +98,7 @@ func (s *ShBinary) Installable() bool { } func (s *ShBinary) GenerateAndroidBuildActions(ctx ModuleContext) { - s.sourceFilePath = ctx.ExpandSource(String(s.properties.Src), "src") + s.sourceFilePath = PathForModuleSrc(ctx, String(s.properties.Src)) filename := String(s.properties.Filename) filename_from_src := Bool(s.properties.Filename_from_src) if filename == "" { diff --git a/apex/apex.go b/apex/apex.go index 04b70d44..ad1ef74f 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -839,7 +839,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType ap a.container_private_key_file = key } - manifest := ctx.ExpandSource(proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"), "manifest") + manifest := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json")) var abis []string for _, target := range ctx.MultiTargets() { @@ -936,7 +936,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType ap } if a.properties.AndroidManifest != nil { - androidManifestFile := ctx.ExpandSource(proptools.String(a.properties.AndroidManifest), "androidManifest") + androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest)) implicitInputs = append(implicitInputs, androidManifestFile) optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String()) } @@ -1015,7 +1015,7 @@ func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) { if a.installable() { // For flattened APEX, do nothing but make sure that apex_manifest.json file is also copied along // with other ordinary files. - manifest := ctx.ExpandSource(proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"), "manifest") + manifest := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json")) // rename to apex_manifest.json copiedManifest := android.PathForModuleOut(ctx, "apex_manifest.json") @@ -76,7 +76,7 @@ func (bpf *bpf) GenerateAndroidBuildActions(ctx android.ModuleContext) { cflags = append(cflags, bpf.properties.Cflags...) - srcs := ctx.ExpandSources(bpf.properties.Srcs, nil) + srcs := android.PathsForModuleSrc(ctx, bpf.properties.Srcs) for _, src := range srcs { obj := android.ObjPathWithExt(ctx, "", src, "o") diff --git a/cc/compiler.go b/cc/compiler.go index df396e81..0ab1f018 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -256,7 +256,7 @@ func addToModuleList(ctx ModuleContext, key android.OnceKey, module string) { func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags { tc := ctx.toolchain() - compiler.srcsBeforeGen = ctx.ExpandSources(compiler.Properties.Srcs, compiler.Properties.Exclude_srcs) + compiler.srcsBeforeGen = android.PathsForModuleSrcExcludes(ctx, compiler.Properties.Srcs, compiler.Properties.Exclude_srcs) compiler.srcsBeforeGen = append(compiler.srcsBeforeGen, deps.GeneratedSources...) CheckBadCompilerFlags(ctx, "cflags", compiler.Properties.Cflags) diff --git a/cc/library.go b/cc/library.go index 5df51129..8b666ed1 100644 --- a/cc/library.go +++ b/cc/library.go @@ -450,11 +450,11 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa buildFlags := flagsToBuilderFlags(flags) if library.static() { - srcs := ctx.ExpandSources(library.Properties.Static.Srcs, nil) + srcs := android.PathsForModuleSrc(ctx, library.Properties.Static.Srcs) objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceStaticLibrary, srcs, library.baseCompiler.pathDeps, library.baseCompiler.cFlagsDeps)) } else if library.shared() { - srcs := ctx.ExpandSources(library.Properties.Shared.Srcs, nil) + srcs := android.PathsForModuleSrc(ctx, library.Properties.Shared.Srcs) objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceSharedLibrary, srcs, library.baseCompiler.pathDeps, library.baseCompiler.cFlagsDeps)) } diff --git a/cc/ndk_headers.go b/cc/ndk_headers.go index 9653a17d..5e45c1ac 100644 --- a/cc/ndk_headers.go +++ b/cc/ndk_headers.go @@ -140,7 +140,7 @@ func (m *headerModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { return } - srcFiles := ctx.ExpandSources(m.properties.Srcs, m.properties.Exclude_srcs) + srcFiles := android.PathsForModuleSrcExcludes(ctx, m.properties.Srcs, m.properties.Exclude_srcs) for _, header := range srcFiles { installDir := getHeaderInstallDir(ctx, header, String(m.properties.From), String(m.properties.To)) @@ -338,7 +338,7 @@ func (m *preprocessedHeadersModule) GenerateAndroidBuildActions(ctx android.Modu preprocessor := android.PathForModuleSrc(ctx, String(m.properties.Preprocessor)) m.licensePath = android.PathForModuleSrc(ctx, String(m.properties.License)) - srcFiles := ctx.ExpandSources(m.properties.Srcs, m.properties.Exclude_srcs) + srcFiles := android.PathsForModuleSrcExcludes(ctx, m.properties.Srcs, m.properties.Exclude_srcs) installDir := getCurrentIncludePath(ctx).Join(ctx, String(m.properties.To)) for _, src := range srcFiles { installPath := installDir.Join(ctx, src.Base()) @@ -253,7 +253,7 @@ func (test *testBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags { } func (test *testBinary) install(ctx ModuleContext, file android.Path) { - test.data = ctx.ExpandSources(test.Properties.Data, nil) + test.data = android.PathsForModuleSrc(ctx, test.Properties.Data) optionsMap := map[string]string{} if Bool(test.testDecorator.Properties.Isolated) { optionsMap["not-shardable"] = "true" @@ -378,7 +378,7 @@ func (benchmark *benchmarkDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps } func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Path) { - benchmark.data = ctx.ExpandSources(benchmark.Properties.Data, nil) + benchmark.data = android.PathsForModuleSrc(ctx, benchmark.Properties.Data) benchmark.testConfig = tradefed.AutoGenNativeBenchmarkTestConfig(ctx, benchmark.Properties.Test_config, benchmark.Properties.Test_config_template, benchmark.Properties.Test_suites) diff --git a/cc/test_data_test.go b/cc/test_data_test.go index 7ba244ef..21ea765e 100644 --- a/cc/test_data_test.go +++ b/cc/test_data_test.go @@ -178,5 +178,5 @@ func newTest() android.Module { } func (test *testDataTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { - test.data = ctx.ExpandSources(test.Properties.Data, nil) + test.data = android.PathsForModuleSrc(ctx, test.Properties.Data) } diff --git a/genrule/genrule.go b/genrule/genrule.go index f265eb60..c8be61ac 100644 --- a/genrule/genrule.go +++ b/genrule/genrule.go @@ -225,14 +225,14 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) { } for _, toolFile := range g.properties.Tool_files { - paths := ctx.ExpandSources([]string{toolFile}, nil) + paths := android.PathsForModuleSrc(ctx, []string{toolFile}) g.deps = append(g.deps, paths...) addLocationLabel(toolFile, paths.Strings()) } var srcFiles android.Paths for _, in := range g.properties.Srcs { - paths := ctx.ExpandSources([]string{in}, g.properties.Exclude_srcs) + paths := android.PathsForModuleSrcExcludes(ctx, []string{in}, g.properties.Exclude_srcs) srcFiles = append(srcFiles, paths...) addLocationLabel(in, paths.Strings()) } diff --git a/java/aar.go b/java/aar.go index 29578e21..1a5ea4d2 100644 --- a/java/aar.go +++ b/java/aar.go @@ -130,7 +130,7 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext, mani // Find implicit or explicit asset and resource dirs assetDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Asset_dirs, "assets") resourceDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res") - resourceZips := ctx.ExpandSources(a.aaptProperties.Resource_zips, nil) + resourceZips := android.PathsForModuleSrc(ctx, a.aaptProperties.Resource_zips) var linkDeps android.Paths diff --git a/java/app.go b/java/app.go index 45e3a836..8f5d010c 100644 --- a/java/app.go +++ b/java/app.go @@ -470,7 +470,7 @@ func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.generateAndroidBuildActions(ctx) a.testConfig = tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config, a.testProperties.Test_config_template, a.manifestPath, a.testProperties.Test_suites) - a.data = ctx.ExpandSources(a.testProperties.Data, nil) + a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data) } func (a *AndroidTest) DepsMutator(ctx android.BottomUpMutatorContext) { diff --git a/java/droiddoc.go b/java/droiddoc.go index a85da0ef..e163617e 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -696,7 +696,7 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { }) // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs // may contain filegroup or genrule. - srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs) + srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs) flags := j.collectAidlFlags(ctx, deps) srcFiles = j.genSources(ctx, srcFiles, flags) @@ -715,12 +715,12 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { } j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths) - j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil) + j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files) argFilesMap := map[string]string{} argFileLabels := []string{} for _, label := range j.properties.Arg_files { - var paths = ctx.ExpandSources([]string{label}, nil) + var paths = android.PathsForModuleSrc(ctx, []string{label}) if _, exists := argFilesMap[label]; !exists { argFilesMap[label] = strings.Join(paths.Strings(), " ") argFileLabels = append(argFileLabels, label) @@ -936,13 +936,13 @@ func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits if len(d.properties.Html_dirs) > 0 { htmlDir := d.properties.Html_dirs[0] - *implicits = append(*implicits, ctx.ExpandSources([]string{filepath.Join(d.properties.Html_dirs[0], "**/*")}, nil)...) + *implicits = append(*implicits, android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")})...) args = args + " -htmldir " + htmlDir } if len(d.properties.Html_dirs) > 1 { htmlDir2 := d.properties.Html_dirs[1] - *implicits = append(*implicits, ctx.ExpandSources([]string{filepath.Join(htmlDir2, "**/*")}, nil)...) + *implicits = append(*implicits, android.PathsForModuleSrc(ctx, []string{filepath.Join(htmlDir2, "**/*")})...) args = args + " -htmldir2 " + htmlDir2 } @@ -950,7 +950,7 @@ func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs") } - knownTags := ctx.ExpandSources(d.properties.Knowntags, nil) + knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags) *implicits = append(*implicits, knownTags...) for _, kt := range knownTags { @@ -1415,12 +1415,12 @@ func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext, "has to be non-empty if annotations was enabled (unless validating nullability)") } if migratingNullability { - previousApi := ctx.ExpandSource(String(d.properties.Previous_api), "previous_api") + previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api)) *implicits = append(*implicits, previousApi) flags += " --migrate-nullness " + previousApi.String() } if s := String(d.properties.Validate_nullability_from_list); s != "" { - flags += " --validate-nullability-from-list " + ctx.ExpandSource(s, "validate_nullability_from_list").String() + flags += " --validate-nullability-from-list " + android.PathForModuleSrc(ctx, s).String() } if validatingNullability { d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt") @@ -1793,7 +1793,7 @@ func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {} func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) { path := String(d.properties.Path) d.dir = android.PathForModuleSrc(ctx, path) - d.deps = ctx.ExpandSources([]string{filepath.Join(path, "**/*")}, nil) + d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")}) } // diff --git a/java/java.go b/java/java.go index 986e4250..e0da0063 100644 --- a/java/java.go +++ b/java/java.go @@ -942,7 +942,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path if flags.javaVersion == "1.9" { j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...) } - srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs) + srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs) if hasSrcExt(srcFiles.Strings(), ".proto") { flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags) } @@ -958,7 +958,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.Strings()...) if j.properties.Jarjar_rules != nil { - j.expandJarjarRules = ctx.ExpandSource(*j.properties.Jarjar_rules, "jarjar_rules") + j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules) } jarName := ctx.ModuleName() + ".jar" @@ -1133,10 +1133,10 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path manifest := j.overrideManifest if !manifest.Valid() && j.properties.Manifest != nil { - manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest")) + manifest = android.OptionalPathForPath(android.PathForModuleSrc(ctx, *j.properties.Manifest)) } - services := ctx.ExpandSources(j.properties.Services, nil) + services := android.PathsForModuleSrc(ctx, j.properties.Services) if len(services) > 0 { servicesJar := android.PathForModuleOut(ctx, "services", jarName) var zipargs []string @@ -1547,7 +1547,7 @@ type Test struct { func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template, j.testProperties.Test_suites) - j.data = ctx.ExpandSources(j.testProperties.Data, nil) + j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data) j.Library.GenerateAndroidBuildActions(ctx) } @@ -1641,7 +1641,7 @@ func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.isWrapperVariant = true if j.binaryProperties.Wrapper != nil { - j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper") + j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper) } else { j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh") } @@ -1765,7 +1765,7 @@ func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { } func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { - jars := ctx.ExpandSources(j.properties.Jars, nil) + jars := android.PathsForModuleSrc(ctx, j.properties.Jars) jarName := ctx.ModuleName() + ".jar" outputFile := android.PathForModuleOut(ctx, "combined", jarName) diff --git a/java/java_resources.go b/java/java_resources.go index 46229630..71611689 100644 --- a/java/java_resources.go +++ b/java/java_resources.go @@ -46,7 +46,7 @@ func ResourceDirsToJarArgs(ctx android.ModuleContext, } } - excludeFiles = append(excludeFiles, ctx.ExpandSources(excludeResourceFiles, nil).Strings()...) + excludeFiles = append(excludeFiles, android.PathsForModuleSrc(ctx, excludeResourceFiles).Strings()...) excludeFiles = append(excludeFiles, resourceExcludes...) @@ -96,7 +96,7 @@ func SourceFilesToJarArgs(ctx android.ModuleContext, func resourceFilesToJarArgs(ctx android.ModuleContext, res, exclude []string) (args []string, deps android.Paths) { - files := ctx.ExpandSources(res, exclude) + files := android.PathsForModuleSrcExcludes(ctx, res, exclude) lastDir := "" for i, f := range files { diff --git a/python/python.go b/python/python.go index 6d160201..6eb9b6ef 100644 --- a/python/python.go +++ b/python/python.go @@ -414,7 +414,7 @@ func (p *Module) GeneratePythonBuildActions(ctx android.ModuleContext) { panic(fmt.Errorf("unknown Python Actual_version: %q for module: %q.", p.properties.Actual_version, ctx.ModuleName())) } - expandedSrcs := ctx.ExpandSources(srcs, exclude_srcs) + expandedSrcs := android.PathsForModuleSrcExcludes(ctx, srcs, exclude_srcs) requiresSrcs := true if p.bootstrapper != nil && !p.bootstrapper.autorun() { requiresSrcs = false @@ -424,7 +424,7 @@ func (p *Module) GeneratePythonBuildActions(ctx android.ModuleContext) { } // expand data files from "data" property. - expandedData := ctx.ExpandSources(p.properties.Data, nil) + expandedData := android.PathsForModuleSrc(ctx, p.properties.Data) // sanitize pkg_path. pkgPath := String(p.properties.Pkg_path) @@ -79,7 +79,7 @@ func (p *prebuiltEtcXml) GenerateAndroidBuildActions(ctx android.ModuleContext) p.PrebuiltEtc.GenerateAndroidBuildActions(ctx) if p.properties.Schema != nil { - schema := ctx.ExpandSource(proptools.String(p.properties.Schema), "schema") + schema := android.PathForModuleSrc(ctx, proptools.String(p.properties.Schema)) switch schema.Ext() { case ".dtd": |