Refactor install paths

Explicitly allow installation into the data partition instead of using
"../data" for tests. At the same time, pipe through the information
required for vendor modules.

Change-Id: I6baf9d828c285e1080e43074beef8aebdbb38875
diff --git a/common/module.go b/common/module.go
index a2b2efa..0f6ecb5 100644
--- a/common/module.go
+++ b/common/module.go
@@ -56,6 +56,8 @@
 	Darwin() bool
 	Debug() bool
 	AConfig() Config
+	Proprietary() bool
+	InstallInData() bool
 }
 
 type AndroidBaseContext interface {
@@ -74,8 +76,8 @@
 	ExpandSources(srcFiles, excludes []string) Paths
 	Glob(outDir, globPattern string, excludes []string) Paths
 
-	InstallFile(installPath string, srcPath Path, deps ...Path) Path
-	InstallFileName(installPath, name string, srcPath Path, deps ...Path) Path
+	InstallFile(installPath OutputPath, srcPath Path, deps ...Path) Path
+	InstallFileName(installPath OutputPath, name string, srcPath Path, deps ...Path) Path
 	CheckbuildFile(srcPath Path)
 }
 
@@ -87,6 +89,7 @@
 	base() *AndroidModuleBase
 	Enabled() bool
 	HostOrDevice() HostOrDevice
+	InstallInData() bool
 }
 
 type commonProperties struct {
@@ -103,6 +106,9 @@
 	// platform
 	Compile_multilib string
 
+	// whether this is a proprietary vendor module, and should be installed into /vendor
+	Proprietary bool
+
 	// Set by HostOrDeviceMutator
 	CompileHostOrDevice HostOrDevice `blueprint:"mutated"`
 
@@ -294,6 +300,10 @@
 	return p.noAddressSanitizer
 }
 
+func (p *AndroidModuleBase) InstallInData() bool {
+	return false
+}
+
 func (a *AndroidModuleBase) generateModuleTarget(ctx blueprint.ModuleContext) {
 	if a != ctx.FinalModule().(AndroidModule).base() {
 		return
@@ -352,10 +362,12 @@
 
 func (a *AndroidModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl {
 	return androidBaseContextImpl{
-		arch:   a.commonProperties.CompileArch,
-		hod:    a.commonProperties.CompileHostOrDevice,
-		ht:     a.commonProperties.CompileHostType,
-		config: ctx.Config().(Config),
+		arch:          a.commonProperties.CompileArch,
+		hod:           a.commonProperties.CompileHostOrDevice,
+		ht:            a.commonProperties.CompileHostType,
+		proprietary:   a.commonProperties.Proprietary,
+		config:        ctx.Config().(Config),
+		installInData: a.module.InstallInData(),
 	}
 }
 
@@ -387,11 +399,13 @@
 }
 
 type androidBaseContextImpl struct {
-	arch   Arch
-	hod    HostOrDevice
-	ht     HostType
-	debug  bool
-	config Config
+	arch          Arch
+	hod           HostOrDevice
+	ht            HostType
+	debug         bool
+	config        Config
+	proprietary   bool
+	installInData bool
 }
 
 type androidModuleContext struct {
@@ -492,10 +506,18 @@
 	return a.config
 }
 
-func (a *androidModuleContext) InstallFileName(installPath, name string, srcPath Path,
+func (a *androidBaseContextImpl) Proprietary() bool {
+	return a.proprietary
+}
+
+func (a *androidBaseContextImpl) InstallInData() bool {
+	return a.installInData
+}
+
+func (a *androidModuleContext) InstallFileName(installPath OutputPath, name string, srcPath Path,
 	deps ...Path) Path {
 
-	fullInstallPath := PathForModuleInstall(a, installPath, name)
+	fullInstallPath := installPath.Join(a, name)
 
 	deps = append(deps, a.installDeps...)
 
@@ -512,7 +534,7 @@
 	return fullInstallPath
 }
 
-func (a *androidModuleContext) InstallFile(installPath string, srcPath Path, deps ...Path) Path {
+func (a *androidModuleContext) InstallFile(installPath OutputPath, srcPath Path, deps ...Path) Path {
 	return a.InstallFileName(installPath, filepath.Base(srcPath.String()), srcPath, deps...)
 }