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
This commit is contained in:
parent
277672eab4
commit
34e34e8c1d
1 changed files with 50 additions and 0 deletions
|
@ -1145,6 +1145,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, ""}}
|
||||
|
||||
abs, err := filepath.Abs(ret.String())
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
buildroot, err := filepath.Abs(ctx.Config().soongOutDir)
|
||||
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 PathGlobContext, path SourcePath) (exists bool, err error) {
|
||||
|
@ -1190,6 +1215,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(modCtx, path)
|
||||
if err != nil {
|
||||
reportPathError(ctx, err)
|
||||
}
|
||||
if !exists {
|
||||
modCtx.AddMissingDependencies([]string{path.String()})
|
||||
}
|
||||
} else if exists, _, err := ctx.Config().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
|
||||
}
|
||||
|
||||
// PathForArbitraryOutput creates a path for the given components. Unlike PathForOutput,
|
||||
// the path is relative to the root of the output folder, not the out/soong folder.
|
||||
func PathForArbitraryOutput(ctx PathContext, pathComponents ...string) Path {
|
||||
|
|
Loading…
Reference in a new issue