diff options
Diffstat (limited to 'android/paths.go')
-rw-r--r-- | android/paths.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/android/paths.go b/android/paths.go index 0f20b844..edddce90 100644 --- a/android/paths.go +++ b/android/paths.go @@ -46,6 +46,7 @@ type ModuleInstallPathContext interface { androidBaseContext InstallInData() bool + InstallInTestcases() bool InstallInSanitizerDir() bool InstallInRecovery() bool } @@ -644,6 +645,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 +723,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. @@ -1117,6 +1168,8 @@ func modulePartition(ctx ModuleInstallPathContext) string { var partition string if ctx.InstallInData() { partition = "data" + } else if ctx.InstallInTestcases() { + partition = "testcases" } else if ctx.InstallInRecovery() { // the layout of recovery partion is the same as that of system partition partition = "recovery/root/system" |