diff options
| author | Sam Mortimer <sam@mortimer.me.uk> | 2019-09-05 15:16:13 -0700 |
|---|---|---|
| committer | Rashed Abdel-Tawab <rashed@linux.com> | 2019-09-07 14:54:30 -0700 |
| commit | 1ffdf0fc74ee8aa9967288b74ecebf94332e9c60 (patch) | |
| tree | 4e2ebd58af46b5bf987cab5a60d29dad8d1ef4c9 | |
| parent | 0627d813700af4043d6f213d451f9d0fabdbed1c (diff) | |
| download | build_soong-1ffdf0fc74ee8aa9967288b74ecebf94332e9c60.tar.gz build_soong-1ffdf0fc74ee8aa9967288b74ecebf94332e9c60.tar.bz2 build_soong-1ffdf0fc74ee8aa9967288b74ecebf94332e9c60.zip | |
soong: Add PathForSourceRelaxed
Used by vendor/lineage generated kernel header module.
Partial pick from:
Author: Sam Mortimer <sam@mortimer.me.uk>
Date: Fri Aug 17 11:25:08 2018 -0700
soong: Add java sources overlay support
Change-Id: I94143febb0a8afa6a165364d36a40d5120a4e7bc
Change-Id: I415af71458f2a7be8e256cb3c548994f09c5bebf
| -rw-r--r-- | android/paths.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/android/paths.go b/android/paths.go index 8cc7057a..8d0573d5 100644 --- a/android/paths.go +++ b/android/paths.go @@ -644,6 +644,31 @@ func pathForSource(ctx PathContext, pathComponents ...string) (SourcePath, error return ret, nil } +// pathForSourceRelaxed creates a SourcePath from pathComponents, but does not check that it exists. +// It differs from pathForSource in that the path is allowed to exist outside of the PathContext. +func pathForSourceRelaxed(ctx PathContext, pathComponents ...string) (SourcePath, error) { + p := filepath.Join(pathComponents...) + ret := SourcePath{basePath{p, ctx.Config(), ""}} + + abs, err := filepath.Abs(ret.String()) + if err != nil { + return ret, err + } + buildroot, err := filepath.Abs(ctx.Config().buildDir) + if err != nil { + return ret, err + } + 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) { @@ -697,6 +722,31 @@ func PathForSource(ctx PathContext, pathComponents ...string) SourcePath { return path } +// PathForSourceRelaxed joins the provided path components. Unlike PathForSource, +// the result is allowed to exist outside of the source dir. +// On error, it will return a usable, but invalid SourcePath, and report a ModuleError. +func PathForSourceRelaxed(ctx PathContext, pathComponents ...string) SourcePath { + path, err := pathForSourceRelaxed(ctx, pathComponents...) + if err != nil { + reportPathError(ctx, err) + } + + 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()) + } else if !exists { + reportPathErrorf(ctx, "source path %s does not exist", path) + } + return path +} + // 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. |
