Revert "Make RuleBuilder methods take Paths"

This reverts commit acdd6940719125104dfd2f692990c99682f95f05.

Reason for revert: broke ndk build

Change-Id: I5655e48c15eb8f5f0267afdd853fbc25765b8623
diff --git a/dexpreopt/config.go b/dexpreopt/config.go
index 6f8ea3a..ee3cc8d 100644
--- a/dexpreopt/config.go
+++ b/dexpreopt/config.go
@@ -17,7 +17,6 @@
 import (
 	"encoding/json"
 	"io/ioutil"
-	"strings"
 
 	"android/soong/android"
 )
@@ -75,13 +74,12 @@
 	InstructionSetFeatures map[android.ArchType]string // instruction set for each architecture
 
 	// Only used for boot image
-	DirtyImageObjects      android.OptionalPath // path to a dirty-image-objects file
-	PreloadedClasses       android.OptionalPath // path to a preloaded-classes file
-	BootImageProfiles      android.Paths        // path to a boot-image-profile.txt file
-	UseProfileForBootImage bool                 // whether a profile should be used to compile the boot image
-	BootFlags              string               // extra flags to pass to dex2oat for the boot image
-	Dex2oatImageXmx        string               // max heap size for dex2oat for the boot image
-	Dex2oatImageXms        string               // initial heap size for dex2oat for the boot image
+	DirtyImageObjects string   // path to a dirty-image-objects file
+	PreloadedClasses  string   // path to a preloaded-classes file
+	BootImageProfiles []string // path to a boot-image-profile.txt file
+	BootFlags         string   // extra flags to pass to dex2oat for the boot image
+	Dex2oatImageXmx   string   // max heap size for dex2oat for the boot image
+	Dex2oatImageXms   string   // initial heap size for dex2oat for the boot image
 
 	Tools Tools // paths to tools possibly used by the generated commands
 }
@@ -89,38 +87,38 @@
 // Tools contains paths to tools possibly used by the generated commands.  If you add a new tool here you MUST add it
 // to the order-only dependency list in DEXPREOPT_GEN_DEPS.
 type Tools struct {
-	Profman  android.Path
-	Dex2oat  android.Path
-	Aapt     android.Path
-	SoongZip android.Path
-	Zip2zip  android.Path
+	Profman  string
+	Dex2oat  string
+	Aapt     string
+	SoongZip string
+	Zip2zip  string
 
-	VerifyUsesLibraries android.Path
-	ConstructContext    android.Path
+	VerifyUsesLibraries string
+	ConstructContext    string
 }
 
 type ModuleConfig struct {
 	Name            string
 	DexLocation     string // dex location on device
-	BuildPath       android.OutputPath
-	DexPath         android.Path
+	BuildPath       string
+	DexPath         string
 	UncompressedDex bool
 	HasApkLibraries bool
 	PreoptFlags     []string
 
-	ProfileClassListing  android.OptionalPath
+	ProfileClassListing  string
 	ProfileIsTextListing bool
 
 	EnforceUsesLibraries  bool
 	OptionalUsesLibraries []string
 	UsesLibraries         []string
-	LibraryPaths          map[string]android.Path
+	LibraryPaths          map[string]string
 
 	Archs           []android.ArchType
-	DexPreoptImages []android.Path
+	DexPreoptImages []string
 
-	PreoptBootClassPathDexFiles     android.Paths // file paths of boot class path files
-	PreoptBootClassPathDexLocations []string      // virtual locations of boot class path files
+	PreoptBootClassPathDexFiles     []string // file paths of boot class path files
+	PreoptBootClassPathDexLocations []string // virtual locations of boot class path files
 
 	PreoptExtractedApk bool // Overrides OnlyPreoptModules
 
@@ -130,137 +128,24 @@
 	PresignedPrebuilt bool
 
 	NoStripping     bool
-	StripInputPath  android.Path
-	StripOutputPath android.WritablePath
+	StripInputPath  string
+	StripOutputPath string
 }
 
-func constructPath(ctx android.PathContext, path string) android.Path {
-	buildDirPrefix := ctx.Config().BuildDir() + "/"
-	if path == "" {
-		return nil
-	} else if strings.HasPrefix(path, buildDirPrefix) {
-		return android.PathForOutput(ctx, strings.TrimPrefix(path, buildDirPrefix))
-	} else {
-		return android.PathForSource(ctx, path)
-	}
+func LoadGlobalConfig(path string) (GlobalConfig, error) {
+	config := GlobalConfig{}
+	err := loadConfig(path, &config)
+	return config, err
 }
 
-func constructPaths(ctx android.PathContext, paths []string) android.Paths {
-	var ret android.Paths
-	for _, path := range paths {
-		ret = append(ret, constructPath(ctx, path))
-	}
-	return ret
+func LoadModuleConfig(path string) (ModuleConfig, error) {
+	config := ModuleConfig{}
+	err := loadConfig(path, &config)
+	return config, err
 }
 
-func constructPathMap(ctx android.PathContext, paths map[string]string) map[string]android.Path {
-	ret := map[string]android.Path{}
-	for key, path := range paths {
-		ret[key] = constructPath(ctx, path)
-	}
-	return ret
-}
-
-func constructWritablePath(ctx android.PathContext, path string) android.WritablePath {
-	if path == "" {
-		return nil
-	}
-	return constructPath(ctx, path).(android.WritablePath)
-}
-
-// LoadGlobalConfig reads the global dexpreopt.config file into a GlobalConfig struct.  It is used directly in Soong
-// and in dexpreopt_gen called from Make to read the $OUT/dexpreopt.config written by Make.
-func LoadGlobalConfig(ctx android.PathContext, path string) (GlobalConfig, error) {
-	type GlobalJSONConfig struct {
-		GlobalConfig
-
-		// Copies of entries in GlobalConfig that are not constructable without extra parameters.  They will be
-		// used to construct the real value manually below.
-		DirtyImageObjects string
-		PreloadedClasses  string
-		BootImageProfiles []string
-
-		Tools struct {
-			Profman  string
-			Dex2oat  string
-			Aapt     string
-			SoongZip string
-			Zip2zip  string
-
-			VerifyUsesLibraries string
-			ConstructContext    string
-		}
-	}
-
-	config := GlobalJSONConfig{}
-	err := loadConfig(ctx, path, &config)
-	if err != nil {
-		return config.GlobalConfig, err
-	}
-
-	// Construct paths that require a PathContext.
-	config.GlobalConfig.DirtyImageObjects = android.OptionalPathForPath(constructPath(ctx, config.DirtyImageObjects))
-	config.GlobalConfig.PreloadedClasses = android.OptionalPathForPath(constructPath(ctx, config.PreloadedClasses))
-	config.GlobalConfig.BootImageProfiles = constructPaths(ctx, config.BootImageProfiles)
-
-	config.GlobalConfig.Tools.Profman = constructPath(ctx, config.Tools.Profman)
-	config.GlobalConfig.Tools.Dex2oat = constructPath(ctx, config.Tools.Dex2oat)
-	config.GlobalConfig.Tools.Aapt = constructPath(ctx, config.Tools.Aapt)
-	config.GlobalConfig.Tools.SoongZip = constructPath(ctx, config.Tools.SoongZip)
-	config.GlobalConfig.Tools.Zip2zip = constructPath(ctx, config.Tools.Zip2zip)
-	config.GlobalConfig.Tools.VerifyUsesLibraries = constructPath(ctx, config.Tools.VerifyUsesLibraries)
-	config.GlobalConfig.Tools.ConstructContext = constructPath(ctx, config.Tools.ConstructContext)
-
-	return config.GlobalConfig, nil
-}
-
-// LoadModuleConfig reads a per-module dexpreopt.config file into a ModuleConfig struct.  It is not used in Soong, which
-// receives a ModuleConfig struct directly from java/dexpreopt.go.  It is used in dexpreopt_gen called from oMake to
-// read the module dexpreopt.config written by Make.
-func LoadModuleConfig(ctx android.PathContext, path string) (ModuleConfig, error) {
-	type ModuleJSONConfig struct {
-		ModuleConfig
-
-		// Copies of entries in ModuleConfig that are not constructable without extra parameters.  They will be
-		// used to construct the real value manually below.
-		BuildPath                   string
-		DexPath                     string
-		ProfileClassListing         string
-		LibraryPaths                map[string]string
-		DexPreoptImages             []string
-		PreoptBootClassPathDexFiles []string
-		StripInputPath              string
-		StripOutputPath             string
-	}
-
-	config := ModuleJSONConfig{}
-
-	err := loadConfig(ctx, path, &config)
-	if err != nil {
-		return config.ModuleConfig, err
-	}
-
-	// Construct paths that require a PathContext.
-	config.ModuleConfig.BuildPath = constructPath(ctx, config.BuildPath).(android.OutputPath)
-	config.ModuleConfig.DexPath = constructPath(ctx, config.DexPath)
-	config.ModuleConfig.ProfileClassListing = android.OptionalPathForPath(constructPath(ctx, config.ProfileClassListing))
-	config.ModuleConfig.LibraryPaths = constructPathMap(ctx, config.LibraryPaths)
-	config.ModuleConfig.DexPreoptImages = constructPaths(ctx, config.DexPreoptImages)
-	config.ModuleConfig.PreoptBootClassPathDexFiles = constructPaths(ctx, config.PreoptBootClassPathDexFiles)
-	config.ModuleConfig.StripInputPath = constructPath(ctx, config.StripInputPath)
-	config.ModuleConfig.StripOutputPath = constructWritablePath(ctx, config.StripOutputPath)
-
-	return config.ModuleConfig, nil
-}
-
-func loadConfig(ctx android.PathContext, path string, config interface{}) error {
-	r, err := ctx.Fs().Open(path)
-	if err != nil {
-		return err
-	}
-	defer r.Close()
-
-	data, err := ioutil.ReadAll(r)
+func loadConfig(path string, config interface{}) error {
+	data, err := ioutil.ReadFile(path)
 	if err != nil {
 		return err
 	}
@@ -272,56 +157,3 @@
 
 	return nil
 }
-
-func GlobalConfigForTests(ctx android.PathContext) GlobalConfig {
-	return GlobalConfig{
-		DefaultNoStripping:                 false,
-		DisablePreoptModules:               nil,
-		OnlyPreoptBootImageAndSystemServer: false,
-		HasSystemOther:                     false,
-		PatternsOnSystemOther:              nil,
-		DisableGenerateProfile:             false,
-		BootJars:                           nil,
-		RuntimeApexJars:                    nil,
-		ProductUpdatableBootModules:        nil,
-		ProductUpdatableBootLocations:      nil,
-		SystemServerJars:                   nil,
-		SystemServerApps:                   nil,
-		SpeedApps:                          nil,
-		PreoptFlags:                        nil,
-		DefaultCompilerFilter:              "",
-		SystemServerCompilerFilter:         "",
-		GenerateDMFiles:                    false,
-		NeverAllowStripping:                false,
-		NoDebugInfo:                        false,
-		AlwaysSystemServerDebugInfo:        false,
-		NeverSystemServerDebugInfo:         false,
-		AlwaysOtherDebugInfo:               false,
-		NeverOtherDebugInfo:                false,
-		MissingUsesLibraries:               nil,
-		IsEng:                              false,
-		SanitizeLite:                       false,
-		DefaultAppImages:                   false,
-		Dex2oatXmx:                         "",
-		Dex2oatXms:                         "",
-		EmptyDirectory:                     "empty_dir",
-		CpuVariant:                         nil,
-		InstructionSetFeatures:             nil,
-		DirtyImageObjects:                  android.OptionalPath{},
-		PreloadedClasses:                   android.OptionalPath{},
-		BootImageProfiles:                  nil,
-		UseProfileForBootImage:             false,
-		BootFlags:                          "",
-		Dex2oatImageXmx:                    "",
-		Dex2oatImageXms:                    "",
-		Tools: Tools{
-			Profman:             android.PathForTesting("profman"),
-			Dex2oat:             android.PathForTesting("dex2oat"),
-			Aapt:                android.PathForTesting("aapt"),
-			SoongZip:            android.PathForTesting("soong_zip"),
-			Zip2zip:             android.PathForTesting("zip2zip"),
-			VerifyUsesLibraries: android.PathForTesting("verify_uses_libraries.sh"),
-			ConstructContext:    android.PathForTesting("construct_context.sh"),
-		},
-	}
-}