aboutsummaryrefslogtreecommitdiffstats
path: root/android
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2018-02-23 07:28:49 +0000
committerandroid-build-merger <android-build-merger@google.com>2018-02-23 07:28:49 +0000
commit0071b0d8bd0dc96a0e8181b4ab20d0aa9f0402a8 (patch)
tree3babd97fa730753d02ea03825386e480092d2b9f /android
parent10c7d51f6d9db1092342f6958b36ebec6ed4cc47 (diff)
parentd543f3759888a07d19ea3c091acda5cf5328a842 (diff)
downloadbuild_soong-0071b0d8bd0dc96a0e8181b4ab20d0aa9f0402a8.tar.gz
build_soong-0071b0d8bd0dc96a0e8181b4ab20d0aa9f0402a8.tar.bz2
build_soong-0071b0d8bd0dc96a0e8181b4ab20d0aa9f0402a8.zip
Revert "Move AllowMissingDependencies check from PathsForSource to PathForSource" am: c48c14369c am: 6fe8d17dd2
am: d543f37598 Change-Id: Id00030c0a6253237777b6ccf69bcb6ee63550668
Diffstat (limited to 'android')
-rw-r--r--android/paths.go136
1 files changed, 75 insertions, 61 deletions
diff --git a/android/paths.go b/android/paths.go
index 3bb5d1b7..3d4d3f30 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -195,6 +195,20 @@ type Paths []Path
// PathsForSource returns Paths rooted from SrcDir
func PathsForSource(ctx PathContext, paths []string) Paths {
+ if ctx.Config().AllowMissingDependencies() {
+ if modCtx, ok := ctx.(ModuleContext); ok {
+ ret := make(Paths, 0, len(paths))
+ for _, path := range paths {
+ p := ExistentPathForSource(ctx, path)
+ if p.Valid() {
+ ret = append(ret, p.Path())
+ } else {
+ modCtx.AddMissingDependencies([]string{path})
+ }
+ }
+ return ret
+ }
+ }
ret := make(Paths, len(paths))
for i, path := range paths {
ret[i] = PathForSource(ctx, path)
@@ -493,100 +507,100 @@ func safePathForSource(ctx PathContext, path string) SourcePath {
return ret
}
-// pathForSource creates a SourcePath from pathComponents, but does not check that it exists.
-func pathForSource(ctx PathContext, pathComponents ...string) (SourcePath, error) {
+// PathForSource joins the provided path components and validates that the result
+// neither escapes the source dir nor is in the out dir.
+// On error, it will return a usable, but invalid SourcePath, and report a ModuleError.
+func PathForSource(ctx PathContext, pathComponents ...string) SourcePath {
p, err := validatePath(pathComponents...)
ret := SourcePath{basePath{p, ctx.Config(), ""}}
if err != nil {
- return ret, err
+ reportPathError(ctx, err)
+ return ret
}
abs, err := filepath.Abs(ret.String())
if err != nil {
- return ret, err
+ reportPathError(ctx, err)
+ return ret
}
buildroot, err := filepath.Abs(ctx.Config().buildDir)
if err != nil {
- return ret, err
+ reportPathError(ctx, err)
+ return ret
}
if strings.HasPrefix(abs, buildroot) {
- return ret, fmt.Errorf("source path %s is in output", abs)
- }
-
- if pathtools.IsGlob(ret.String()) {
- return ret, fmt.Errorf("path may not contain a glob: %s", ret.String())
- }
-
- return ret, nil
-}
-
-// existsWithDependencies returns true if the path exists, and adds appropriate dependencies to rerun if the
-// path does not exist.
-func existsWithDependencies(ctx PathContext, path SourcePath) (exists bool, err error) {
- var files []string
-
- if gctx, ok := ctx.(PathGlobContext); ok {
- // Use glob to produce proper dependencies, even though we only want
- // a single file.
- files, err = gctx.GlobWithDeps(path.String(), nil)
- } else {
- var deps []string
- // We cannot add build statements in this context, so we fall back to
- // AddNinjaFileDeps
- files, deps, err = pathtools.Glob(path.String(), nil)
- ctx.AddNinjaFileDeps(deps...)
- }
-
- if err != nil {
- return false, fmt.Errorf("glob: %s", err.Error())
- }
-
- return len(files) > 0, nil
-}
-
-// PathForSource joins the provided path components and validates that the result
-// neither escapes the source dir nor is in the out dir.
-// On error, it will return a usable, but invalid SourcePath, and report a ModuleError.
-func PathForSource(ctx PathContext, pathComponents ...string) SourcePath {
- path, err := pathForSource(ctx, pathComponents...)
- if err != nil {
- reportPathError(ctx, err)
+ reportPathErrorf(ctx, "source path %s is in output", abs)
+ return ret
}
- if modCtx, ok := ctx.(ModuleContext); ok && ctx.Config().AllowMissingDependencies() {
- exists, err := existsWithDependencies(ctx, path)
- if err != nil {
- reportPathError(ctx, err)
- }
- if !exists {
- modCtx.AddMissingDependencies([]string{path.String()})
- }
- } else if exists, _, err := ctx.Fs().Exists(path.String()); err != nil {
- reportPathErrorf(ctx, "%s: %s", path, err.Error())
+ if exists, _, err := ctx.Fs().Exists(ret.String()); err != nil {
+ reportPathErrorf(ctx, "%s: %s", ret, err.Error())
} else if !exists {
- reportPathErrorf(ctx, "source path %s does not exist", path)
+ reportPathErrorf(ctx, "source path %s does not exist", ret)
}
- return path
+ return ret
}
// ExistentPathForSource returns an OptionalPath with the SourcePath if the
// path exists, or an empty OptionalPath if it doesn't exist. Dependencies are added
// so that the ninja file will be regenerated if the state of the path changes.
func ExistentPathForSource(ctx PathContext, pathComponents ...string) OptionalPath {
- path, err := pathForSource(ctx, pathComponents...)
+ p, err := validatePath(pathComponents...)
if err != nil {
reportPathError(ctx, err)
return OptionalPath{}
}
+ path := SourcePath{basePath{p, ctx.Config(), ""}}
- exists, err := existsWithDependencies(ctx, path)
+ abs, err := filepath.Abs(path.String())
if err != nil {
reportPathError(ctx, err)
return OptionalPath{}
}
- if !exists {
+ buildroot, err := filepath.Abs(ctx.Config().buildDir)
+ if err != nil {
+ reportPathError(ctx, err)
+ return OptionalPath{}
+ }
+ if strings.HasPrefix(abs, buildroot) {
+ reportPathErrorf(ctx, "source path %s is in output", abs)
+ return OptionalPath{}
+ }
+
+ if pathtools.IsGlob(path.String()) {
+ reportPathErrorf(ctx, "path may not contain a glob: %s", path.String())
return OptionalPath{}
}
+
+ if gctx, ok := ctx.(PathGlobContext); ok {
+ // Use glob to produce proper dependencies, even though we only want
+ // a single file.
+ files, err := gctx.GlobWithDeps(path.String(), nil)
+ if err != nil {
+ reportPathErrorf(ctx, "glob: %s", err.Error())
+ return OptionalPath{}
+ }
+
+ if len(files) == 0 {
+ return OptionalPath{}
+ }
+ } else {
+ // We cannot add build statements in this context, so we fall back to
+ // AddNinjaFileDeps
+ files, dirs, err := pathtools.Glob(path.String(), nil)
+ if err != nil {
+ reportPathErrorf(ctx, "glob: %s", err.Error())
+ return OptionalPath{}
+ }
+
+ ctx.AddNinjaFileDeps(dirs...)
+
+ if len(files) == 0 {
+ return OptionalPath{}
+ }
+
+ ctx.AddNinjaFileDeps(path.String())
+ }
return OptionalPathForPath(path)
}