diff options
Diffstat (limited to 'android/paths.go')
-rw-r--r-- | android/paths.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/android/paths.go b/android/paths.go index 325a953c4..d4b1d6e29 100644 --- a/android/paths.go +++ b/android/paths.go @@ -171,6 +171,9 @@ type Path interface { // Base returns the last element of the path Base() string + // Dir returns a path pointing the directory containing the path + Dir() Path + // Rel returns the portion of the path relative to the directory it was created from. For // example, Rel on a PathsForModuleSrc would return the path relative to the module source // directory, and OutputPath.Join("foo").Rel() would return "foo". @@ -1012,6 +1015,12 @@ func (p basePath) Base() string { return filepath.Base(p.path) } +func (p basePath) Dir() Path { + p.path = filepath.Dir(p.path) + p.rel = filepath.Dir(p.rel) + return p +} + func (p basePath) Rel() string { if p.rel != "" { return p.rel @@ -1046,6 +1055,11 @@ func (p SourcePath) withRel(rel string) SourcePath { return p } +func (p SourcePath) Dir() Path { + p.basePath = p.basePath.Dir().(basePath) + return p +} + // safePathForSource is for paths that we expect are safe -- only for use by go // code that is embedding ninja variables in paths func safePathForSource(ctx PathContext, pathComponents ...string) (SourcePath, error) { @@ -1248,6 +1262,12 @@ func (p OutputPath) withRel(rel string) OutputPath { return p } +func (p OutputPath) Dir() Path { + p.basePath = p.basePath.Dir().(basePath) + p.fullPath = filepath.Dir(p.fullPath) + return p +} + func (p OutputPath) WithoutRel() OutputPath { p.basePath.rel = filepath.Base(p.basePath.path) return p @@ -1280,6 +1300,11 @@ type toolDepPath struct { basePath } +func (p toolDepPath) Dir() Path { + p.basePath = p.basePath.Dir().(basePath) + return p +} + func (t toolDepPath) RelativeToTop() Path { ensureTestOnly() return t @@ -1463,6 +1488,11 @@ type ModuleOutPath struct { OutputPath } +func (p ModuleOutPath) Dir() Path { + p.OutputPath = p.OutputPath.Dir().(OutputPath) + return p +} + func (p ModuleOutPath) RelativeToTop() Path { p.OutputPath = p.outputPathRelativeToTop() return p @@ -1507,6 +1537,11 @@ type ModuleGenPath struct { ModuleOutPath } +func (p ModuleGenPath) Dir() Path { + p.ModuleOutPath = p.ModuleOutPath.Dir().(ModuleOutPath) + return p +} + func (p ModuleGenPath) RelativeToTop() Path { p.OutputPath = p.outputPathRelativeToTop() return p @@ -1546,6 +1581,11 @@ type ModuleObjPath struct { ModuleOutPath } +func (p ModuleObjPath) Dir() Path { + p.ModuleOutPath = p.ModuleOutPath.Dir().(ModuleOutPath) + return p +} + func (p ModuleObjPath) RelativeToTop() Path { p.OutputPath = p.outputPathRelativeToTop() return p @@ -1570,6 +1610,11 @@ type ModuleResPath struct { ModuleOutPath } +func (p ModuleResPath) Dir() Path { + p.ModuleOutPath = p.ModuleOutPath.Dir().(ModuleOutPath) + return p +} + func (p ModuleResPath) RelativeToTop() Path { p.OutputPath = p.outputPathRelativeToTop() return p @@ -1606,6 +1651,11 @@ type InstallPath struct { makePath bool } +func (p InstallPath) Dir() Path { + p.basePath = p.basePath.Dir().(basePath) + return p +} + // Will panic if called from outside a test environment. func ensureTestOnly() { if PrefixInList(os.Args, "-test.") { @@ -1922,6 +1972,11 @@ type PhonyPath struct { basePath } +func (p PhonyPath) Dir() Path { + p.basePath = p.basePath.Dir().(basePath) + return p +} + func (p PhonyPath) writablePath() {} func (p PhonyPath) getSoongOutDir() string { @@ -1947,6 +2002,11 @@ type testPath struct { basePath } +func (p testPath) Dir() Path { + p.basePath = p.basePath.Dir().(basePath) + return p +} + func (p testPath) RelativeToTop() Path { ensureTestOnly() return p |