diff options
| author | Dan Willemsen <dwillemsen@google.com> | 2015-09-23 15:26:20 -0700 |
|---|---|---|
| committer | Dan Willemsen <dwillemsen@google.com> | 2015-12-09 14:29:12 -0800 |
| commit | 34cc69e4bf36cb65bb181b42ccb0f8c792a32cfb (patch) | |
| tree | ecaff919037e29033fa9b3bbfb33baa8e93196cf /common/config.go | |
| parent | fafa3dc7e267675610a34b0c335be350eb30936d (diff) | |
| download | build_soong-34cc69e4bf36cb65bb181b42ccb0f8c792a32cfb.tar.gz build_soong-34cc69e4bf36cb65bb181b42ccb0f8c792a32cfb.tar.bz2 build_soong-34cc69e4bf36cb65bb181b42ccb0f8c792a32cfb.zip | |
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
Diffstat (limited to 'common/config.go')
| -rw-r--r-- | common/config.go | 73 |
1 files changed, 23 insertions, 50 deletions
diff --git a/common/config.go b/common/config.go index c67023e3..7f6ee65d 100644 --- a/common/config.go +++ b/common/config.go @@ -20,6 +20,7 @@ import ( "os" "path/filepath" "runtime" + "strings" "sync" ) @@ -38,8 +39,6 @@ func (f *FileConfigurableOptions) SetDefaultConfig() { type Config struct { *config - - dontCreateNinjaFile bool } // A config object represents the entire build configuration for Android. @@ -142,8 +141,24 @@ func NewConfig(srcDir, buildDir string) (Config, error) { }, } + // 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 @@ func NewConfig(srcDir, buildDir string) (Config, error) { 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 @@ func (c *config) DeviceUsesClang() bool { 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 @@ func (c *config) ProductAaptCharacteristics() string { 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") } |
