aboutsummaryrefslogtreecommitdiffstats
path: root/common/paths.go
diff options
context:
space:
mode:
Diffstat (limited to 'common/paths.go')
-rw-r--r--common/paths.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/common/paths.go b/common/paths.go
index c4bdfc72..d92dcf91 100644
--- a/common/paths.go
+++ b/common/paths.go
@@ -15,6 +15,7 @@
package common
import (
+ "fmt"
"os"
"path/filepath"
)
@@ -105,3 +106,15 @@ func CheckSrcDirsExist(ctx AndroidModuleContext, dirs []string, prop string) {
}
}
}
+
+// Returns a path relative to the top level source directory. Panics if path is not inside the
+// top level source directory.
+func SrcDirRelPath(ctx AndroidModuleContext, path string) string {
+ srcDir := ctx.AConfig().SrcDir()
+ relPath, err := filepath.Rel(srcDir, path)
+ if err != nil {
+ panic(fmt.Errorf("%q is not inside %q: %s", path, srcDir, err.Error()))
+ }
+
+ return relPath
+}