Use `Path` instead of string for file paths
This centralizes verification and common operations, like converting the
path to a source file to the path for a built object.
It also embeds the configuration knowledge into the path, so that we can
remove "${SrcDir}/path" from the ninja file. When SrcDir is '.', that
leads to paths like './path' instead of just 'path' like make is doing,
causing differences in compiled binaries.
Change-Id: Ib4e8910a6e867ce1b7b420d927c04f1142a7589e
diff --git a/common/config.go b/common/config.go
index c67023e..7f6ee65 100644
--- a/common/config.go
+++ b/common/config.go
@@ -20,6 +20,7 @@
"os"
"path/filepath"
"runtime"
+ "strings"
"sync"
)
@@ -38,8 +39,6 @@
type Config struct {
*config
-
- dontCreateNinjaFile bool
}
// A config object represents the entire build configuration for Android.
@@ -142,8 +141,24 @@
},
}
+ // Sanity check the build and source directories. This won't catch strange
+ // configurations with symlinks, but at least checks the obvious cases.
+ absBuildDir, err := filepath.Abs(buildDir)
+ if err != nil {
+ return Config{}, err
+ }
+
+ absSrcDir, err := filepath.Abs(srcDir)
+ if err != nil {
+ return Config{}, err
+ }
+
+ if strings.HasPrefix(absSrcDir, absBuildDir) {
+ return Config{}, fmt.Errorf("Build dir must not contain source directory")
+ }
+
// Load any configurable options from the configuration file
- err := loadConfig(config.config)
+ err = loadConfig(config.config)
if err != nil {
return Config{}, err
}
@@ -159,18 +174,6 @@
return config, nil
}
-func (c *config) SrcDir() string {
- return c.srcDir
-}
-
-func (c *config) BuildDir() string {
- return c.buildDir
-}
-
-func (c *config) IntermediatesDir() string {
- return filepath.Join(c.BuildDir(), ".intermediates")
-}
-
func (c *config) RemoveAbandonedFiles() bool {
return false
}
@@ -238,37 +241,7 @@
return false
}
-// DeviceOut returns the path to out directory for device targets
-func (c *config) DeviceOut() string {
- return filepath.Join(c.BuildDir(), "target/product", c.DeviceName())
-}
-
-// HostOut returns the path to out directory for host targets
-func (c *config) HostOut() string {
- return filepath.Join(c.BuildDir(), "host", c.PrebuiltOS())
-}
-
-// HostBin returns the path to bin directory for host targets
-func (c *config) HostBin() string {
- return filepath.Join(c.HostOut(), "bin")
-}
-
-// HostBinTool returns the path to a host tool in the bin directory for host targets
-func (c *config) HostBinTool(tool string) (string, error) {
- return filepath.Join(c.HostBin(), tool), nil
-}
-
-// HostJavaDir returns the path to framework directory for host targets
-func (c *config) HostJavaDir() string {
- return filepath.Join(c.HostOut(), "framework")
-}
-
-// HostJavaTool returns the path to a host tool in the frameworks directory for host targets
-func (c *config) HostJavaTool(tool string) (string, error) {
- return filepath.Join(c.HostJavaDir(), tool), nil
-}
-
-func (c *config) ResourceOverlays() []string {
+func (c *config) ResourceOverlays() []SourcePath {
return nil
}
@@ -296,10 +269,10 @@
return "nosdcard"
}
-func (c *config) DefaultAppCertificateDir() string {
- return filepath.Join(c.SrcDir(), "build/target/product/security")
+func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
+ return PathForSource(ctx, "build/target/product/security")
}
-func (c *config) DefaultAppCertificate() string {
- return filepath.Join(c.DefaultAppCertificateDir(), "testkey")
+func (c *config) DefaultAppCertificate(ctx PathContext) SourcePath {
+ return c.DefaultAppCertificateDir(ctx).Join(ctx, "testkey")
}