Merge "Clarify paths.go somewhat" am: bdb02bd334
am: 0669b93b74
Change-Id: I2a8e8dcd12fcfd109029bb55b680ec94b7b4f706
This commit is contained in:
@@ -120,16 +120,16 @@ func (p AndroidPackageContext) IntermediatesPathVariable(name, path string) blue
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrefixedPathsForOptionalSourceVariable returns a Variable whose value is the
|
// PrefixedExistentPathsForSourcesVariable returns a Variable whose value is the
|
||||||
// list of present source paths prefixed with the supplied prefix. It may only
|
// list of present source paths prefixed with the supplied prefix. It may only
|
||||||
// be called during a Go package's initialization - either from the init()
|
// be called during a Go package's initialization - either from the init()
|
||||||
// function or as part of a package-scoped variable's initialization.
|
// function or as part of a package-scoped variable's initialization.
|
||||||
func (p AndroidPackageContext) PrefixedPathsForOptionalSourceVariable(
|
func (p AndroidPackageContext) PrefixedExistentPathsForSourcesVariable(
|
||||||
name, prefix string, paths []string) blueprint.Variable {
|
name, prefix string, paths []string) blueprint.Variable {
|
||||||
|
|
||||||
return p.VariableFunc(name, func(config interface{}) (string, error) {
|
return p.VariableFunc(name, func(config interface{}) (string, error) {
|
||||||
ctx := &configErrorWrapper{p, config.(Config), []error{}}
|
ctx := &configErrorWrapper{p, config.(Config), []error{}}
|
||||||
paths := PathsForOptionalSource(ctx, "", paths)
|
paths := ExistentPathsForSources(ctx, "", paths)
|
||||||
if len(ctx.errors) > 0 {
|
if len(ctx.errors) > 0 {
|
||||||
return "", ctx.errors[0]
|
return "", ctx.errors[0]
|
||||||
}
|
}
|
||||||
|
@@ -97,6 +97,8 @@ type Path interface {
|
|||||||
type WritablePath interface {
|
type WritablePath interface {
|
||||||
Path
|
Path
|
||||||
|
|
||||||
|
// the writablePath method doesn't directly do anything,
|
||||||
|
// but it allows a struct to distinguish between whether or not it implements the WritablePath interface
|
||||||
writablePath()
|
writablePath()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +139,7 @@ func ResPathWithName(ctx ModuleContext, p Path, name string) ModuleResPath {
|
|||||||
if path, ok := p.(resPathProvider); ok {
|
if path, ok := p.(resPathProvider); ok {
|
||||||
return path.resPathWithName(ctx, name)
|
return path.resPathWithName(ctx, name)
|
||||||
}
|
}
|
||||||
reportPathError(ctx, "Tried to create object file from unsupported path: %s (%s)", reflect.TypeOf(p).Name(), p)
|
reportPathError(ctx, "Tried to create res file from unsupported path: %s (%s)", reflect.TypeOf(p).Name(), p)
|
||||||
return PathForModuleRes(ctx)
|
return PathForModuleRes(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +190,7 @@ func PathsForSource(ctx PathContext, paths []string) Paths {
|
|||||||
ret := make(Paths, 0, len(paths))
|
ret := make(Paths, 0, len(paths))
|
||||||
intermediates := filepath.Join(modCtx.ModuleDir(), modCtx.ModuleName(), modCtx.ModuleSubDir(), "missing")
|
intermediates := filepath.Join(modCtx.ModuleDir(), modCtx.ModuleName(), modCtx.ModuleSubDir(), "missing")
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
p := OptionalPathForSource(ctx, intermediates, path)
|
p := ExistentPathForSource(ctx, intermediates, path)
|
||||||
if p.Valid() {
|
if p.Valid() {
|
||||||
ret = append(ret, p.Path())
|
ret = append(ret, p.Path())
|
||||||
} else {
|
} else {
|
||||||
@@ -205,13 +207,13 @@ func PathsForSource(ctx PathContext, paths []string) Paths {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// PathsForOptionalSource returns a list of Paths rooted from SrcDir that are
|
// ExistentPathsForSources returns a list of Paths rooted from SrcDir that are
|
||||||
// found in the tree. If any are not found, they are omitted from the list,
|
// found in the tree. If any are not found, they are omitted from the list,
|
||||||
// and dependencies are added so that we're re-run when they are added.
|
// and dependencies are added so that we're re-run when they are added.
|
||||||
func PathsForOptionalSource(ctx PathContext, intermediates string, paths []string) Paths {
|
func ExistentPathsForSources(ctx PathContext, intermediates string, paths []string) Paths {
|
||||||
ret := make(Paths, 0, len(paths))
|
ret := make(Paths, 0, len(paths))
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
p := OptionalPathForSource(ctx, intermediates, path)
|
p := ExistentPathForSource(ctx, intermediates, path)
|
||||||
if p.Valid() {
|
if p.Valid() {
|
||||||
ret = append(ret, p.Path())
|
ret = append(ret, p.Path())
|
||||||
}
|
}
|
||||||
@@ -337,12 +339,11 @@ func safePathForSource(ctx PathContext, path string) SourcePath {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// PathForSource returns a SourcePath for the provided paths... (which are
|
// PathForSource joins the provided path components and validates that the result
|
||||||
// joined together with filepath.Join). This also validates that the path
|
// neither escapes the source dir nor is in the out dir.
|
||||||
// doesn't escape the source dir, or is contained in the build dir. On error, it
|
// On error, it will return a usable, but invalid SourcePath, and report a ModuleError.
|
||||||
// will return a usable, but invalid SourcePath, and report a ModuleError.
|
func PathForSource(ctx PathContext, pathComponents ...string) SourcePath {
|
||||||
func PathForSource(ctx PathContext, paths ...string) SourcePath {
|
p := validatePath(ctx, pathComponents...)
|
||||||
p := validatePath(ctx, paths...)
|
|
||||||
ret := SourcePath{basePath{p, pathConfig(ctx), ""}}
|
ret := SourcePath{basePath{p, pathConfig(ctx), ""}}
|
||||||
|
|
||||||
abs, err := filepath.Abs(ret.String())
|
abs, err := filepath.Abs(ret.String())
|
||||||
@@ -368,16 +369,16 @@ func PathForSource(ctx PathContext, paths ...string) SourcePath {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// OptionalPathForSource returns an OptionalPath with the SourcePath if the
|
// ExistentPathForSource returns an OptionalPath with the SourcePath if the
|
||||||
// path exists, or an empty OptionalPath if it doesn't exist. Dependencies are added
|
// 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.
|
// so that the ninja file will be regenerated if the state of the path changes.
|
||||||
func OptionalPathForSource(ctx PathContext, intermediates string, paths ...string) OptionalPath {
|
func ExistentPathForSource(ctx PathContext, intermediates string, pathComponents ...string) OptionalPath {
|
||||||
if len(paths) == 0 {
|
if len(pathComponents) == 0 {
|
||||||
// For when someone forgets the 'intermediates' argument
|
// For when someone forgets the 'intermediates' argument
|
||||||
panic("Missing path(s)")
|
panic("Missing path(s)")
|
||||||
}
|
}
|
||||||
|
|
||||||
p := validatePath(ctx, paths...)
|
p := validatePath(ctx, pathComponents...)
|
||||||
path := SourcePath{basePath{p, pathConfig(ctx), ""}}
|
path := SourcePath{basePath{p, pathConfig(ctx), ""}}
|
||||||
|
|
||||||
abs, err := filepath.Abs(path.String())
|
abs, err := filepath.Abs(path.String())
|
||||||
@@ -483,12 +484,11 @@ type OutputPath struct {
|
|||||||
|
|
||||||
var _ Path = OutputPath{}
|
var _ Path = OutputPath{}
|
||||||
|
|
||||||
// PathForOutput returns an OutputPath for the provided paths... (which are
|
// PathForOutput joins the provided paths and returns an OutputPath that is
|
||||||
// joined together with filepath.Join). This also validates that the path
|
// validated to not escape the build dir.
|
||||||
// does not escape the build dir. On error, it will return a usable, but invalid
|
// On error, it will return a usable, but invalid OutputPath, and report a ModuleError.
|
||||||
// OutputPath, and report a ModuleError.
|
func PathForOutput(ctx PathContext, pathComponents ...string) OutputPath {
|
||||||
func PathForOutput(ctx PathContext, paths ...string) OutputPath {
|
path := validatePath(ctx, pathComponents...)
|
||||||
path := validatePath(ctx, paths...)
|
|
||||||
return OutputPath{basePath{path, pathConfig(ctx), ""}}
|
return OutputPath{basePath{path, pathConfig(ctx), ""}}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -597,7 +597,7 @@ func PathForVndkRefAbiDump(ctx ModuleContext, version, fileName string, vndkOrNd
|
|||||||
}
|
}
|
||||||
refDumpFileStr := "prebuilts/abi-dumps/" + vndkOrNdkDir + "/" + version + "/" +
|
refDumpFileStr := "prebuilts/abi-dumps/" + vndkOrNdkDir + "/" + version + "/" +
|
||||||
archName + "/" + sourceOrBinaryDir + "/" + fileName + ext
|
archName + "/" + sourceOrBinaryDir + "/" + fileName + ext
|
||||||
return OptionalPathForSource(ctx, "", refDumpFileStr)
|
return ExistentPathForSource(ctx, "", refDumpFileStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PathForModuleOut returns a Path representing the paths... under the module's
|
// PathForModuleOut returns a Path representing the paths... under the module's
|
||||||
@@ -647,8 +647,8 @@ var _ Path = ModuleObjPath{}
|
|||||||
|
|
||||||
// PathForModuleObj returns a Path representing the paths... under the module's
|
// PathForModuleObj returns a Path representing the paths... under the module's
|
||||||
// 'obj' directory.
|
// 'obj' directory.
|
||||||
func PathForModuleObj(ctx ModuleContext, paths ...string) ModuleObjPath {
|
func PathForModuleObj(ctx ModuleContext, pathComponents ...string) ModuleObjPath {
|
||||||
p := validatePath(ctx, paths...)
|
p := validatePath(ctx, pathComponents...)
|
||||||
return ModuleObjPath{PathForModuleOut(ctx, "obj", p)}
|
return ModuleObjPath{PathForModuleOut(ctx, "obj", p)}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -662,14 +662,14 @@ var _ Path = ModuleResPath{}
|
|||||||
|
|
||||||
// PathForModuleRes returns a Path representing the paths... under the module's
|
// PathForModuleRes returns a Path representing the paths... under the module's
|
||||||
// 'res' directory.
|
// 'res' directory.
|
||||||
func PathForModuleRes(ctx ModuleContext, paths ...string) ModuleResPath {
|
func PathForModuleRes(ctx ModuleContext, pathComponents ...string) ModuleResPath {
|
||||||
p := validatePath(ctx, paths...)
|
p := validatePath(ctx, pathComponents...)
|
||||||
return ModuleResPath{PathForModuleOut(ctx, "res", p)}
|
return ModuleResPath{PathForModuleOut(ctx, "res", p)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PathForModuleInstall returns a Path representing the install path for the
|
// PathForModuleInstall returns a Path representing the install path for the
|
||||||
// module appended with paths...
|
// module appended with paths...
|
||||||
func PathForModuleInstall(ctx ModuleContext, paths ...string) OutputPath {
|
func PathForModuleInstall(ctx ModuleContext, pathComponents ...string) OutputPath {
|
||||||
var outPaths []string
|
var outPaths []string
|
||||||
if ctx.Device() {
|
if ctx.Device() {
|
||||||
partition := "system"
|
partition := "system"
|
||||||
@@ -689,14 +689,14 @@ func PathForModuleInstall(ctx ModuleContext, paths ...string) OutputPath {
|
|||||||
if ctx.Debug() {
|
if ctx.Debug() {
|
||||||
outPaths = append([]string{"debug"}, outPaths...)
|
outPaths = append([]string{"debug"}, outPaths...)
|
||||||
}
|
}
|
||||||
outPaths = append(outPaths, paths...)
|
outPaths = append(outPaths, pathComponents...)
|
||||||
return PathForOutput(ctx, outPaths...)
|
return PathForOutput(ctx, outPaths...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateSafePath validates a path that we trust (may contain ninja variables).
|
// validateSafePath validates a path that we trust (may contain ninja variables).
|
||||||
// Ensures that each path component does not attempt to leave its component.
|
// Ensures that each path component does not attempt to leave its component.
|
||||||
func validateSafePath(ctx PathContext, paths ...string) string {
|
func validateSafePath(ctx PathContext, pathComponents ...string) string {
|
||||||
for _, path := range paths {
|
for _, path := range pathComponents {
|
||||||
path := filepath.Clean(path)
|
path := filepath.Clean(path)
|
||||||
if path == ".." || strings.HasPrefix(path, "../") || strings.HasPrefix(path, "/") {
|
if path == ".." || strings.HasPrefix(path, "../") || strings.HasPrefix(path, "/") {
|
||||||
reportPathError(ctx, "Path is outside directory: %s", path)
|
reportPathError(ctx, "Path is outside directory: %s", path)
|
||||||
@@ -706,20 +706,20 @@ func validateSafePath(ctx PathContext, paths ...string) string {
|
|||||||
// TODO: filepath.Join isn't necessarily correct with embedded ninja
|
// TODO: filepath.Join isn't necessarily correct with embedded ninja
|
||||||
// variables. '..' may remove the entire ninja variable, even if it
|
// variables. '..' may remove the entire ninja variable, even if it
|
||||||
// will be expanded to multiple nested directories.
|
// will be expanded to multiple nested directories.
|
||||||
return filepath.Join(paths...)
|
return filepath.Join(pathComponents...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// validatePath validates that a path does not include ninja variables, and that
|
// validatePath validates that a path does not include ninja variables, and that
|
||||||
// each path component does not attempt to leave its component. Returns a joined
|
// each path component does not attempt to leave its component. Returns a joined
|
||||||
// version of each path component.
|
// version of each path component.
|
||||||
func validatePath(ctx PathContext, paths ...string) string {
|
func validatePath(ctx PathContext, pathComponents ...string) string {
|
||||||
for _, path := range paths {
|
for _, path := range pathComponents {
|
||||||
if strings.Contains(path, "$") {
|
if strings.Contains(path, "$") {
|
||||||
reportPathError(ctx, "Path contains invalid character($): %s", path)
|
reportPathError(ctx, "Path contains invalid character($): %s", path)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return validateSafePath(ctx, paths...)
|
return validateSafePath(ctx, pathComponents...)
|
||||||
}
|
}
|
||||||
|
|
||||||
type testPath struct {
|
type testPath struct {
|
||||||
|
@@ -104,7 +104,7 @@ func init() {
|
|||||||
|
|
||||||
// Everything in these lists is a crime against abstraction and dependency tracking.
|
// Everything in these lists is a crime against abstraction and dependency tracking.
|
||||||
// Do not add anything to this list.
|
// Do not add anything to this list.
|
||||||
pctx.PrefixedPathsForOptionalSourceVariable("CommonGlobalIncludes", "-I",
|
pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I",
|
||||||
[]string{
|
[]string{
|
||||||
"system/core/include",
|
"system/core/include",
|
||||||
"system/media/audio/include",
|
"system/media/audio/include",
|
||||||
@@ -118,7 +118,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
// This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
|
// This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
|
||||||
// with this, since there is no associated library.
|
// with this, since there is no associated library.
|
||||||
pctx.PrefixedPathsForOptionalSourceVariable("CommonNativehelperInclude", "-I",
|
pctx.PrefixedExistentPathsForSourcesVariable("CommonNativehelperInclude", "-I",
|
||||||
[]string{"libnativehelper/include/nativehelper"})
|
[]string{"libnativehelper/include/nativehelper"})
|
||||||
|
|
||||||
pctx.SourcePathVariable("ClangDefaultBase", "prebuilts/clang/host")
|
pctx.SourcePathVariable("ClangDefaultBase", "prebuilts/clang/host")
|
||||||
@@ -153,7 +153,7 @@ func init() {
|
|||||||
pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
|
pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
|
||||||
pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
|
pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
|
||||||
|
|
||||||
pctx.PrefixedPathsForOptionalSourceVariable("RsGlobalIncludes", "-I",
|
pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I",
|
||||||
[]string{
|
[]string{
|
||||||
"external/clang/lib/Headers",
|
"external/clang/lib/Headers",
|
||||||
"frameworks/rs/script_api/include",
|
"frameworks/rs/script_api/include",
|
||||||
|
Reference in New Issue
Block a user