Merge "Use __SBOX_OUT_DIR__ in sbox output file list"
This commit is contained in:
@@ -136,14 +136,11 @@ func run() error {
|
|||||||
|
|
||||||
tempDir, err := ioutil.TempDir(sandboxesRoot, "sbox")
|
tempDir, err := ioutil.TempDir(sandboxesRoot, "sbox")
|
||||||
|
|
||||||
// Rewrite output file paths to be relative to output root
|
|
||||||
// This facilitates matching them up against the corresponding paths in the temporary directory in case they're absolute
|
|
||||||
for i, filePath := range outputsVarEntries {
|
for i, filePath := range outputsVarEntries {
|
||||||
relativePath, err := filepath.Rel(outputRoot, filePath)
|
if !strings.HasPrefix(filePath, "__SBOX_OUT_DIR__/") {
|
||||||
if err != nil {
|
return fmt.Errorf("output files must start with `__SBOX_OUT_DIR__/`")
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
outputsVarEntries[i] = relativePath
|
outputsVarEntries[i] = strings.TrimPrefix(filePath, "__SBOX_OUT_DIR__/")
|
||||||
}
|
}
|
||||||
|
|
||||||
allOutputs = append([]string(nil), outputsVarEntries...)
|
allOutputs = append([]string(nil), outputsVarEntries...)
|
||||||
|
@@ -112,9 +112,10 @@ type Module struct {
|
|||||||
type taskFunc func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) generateTask
|
type taskFunc func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) generateTask
|
||||||
|
|
||||||
type generateTask struct {
|
type generateTask struct {
|
||||||
in android.Paths
|
in android.Paths
|
||||||
out android.WritablePaths
|
out android.WritablePaths
|
||||||
cmd string
|
sandboxOuts []string
|
||||||
|
cmd string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Module) GeneratedSourceFiles() android.Paths {
|
func (g *Module) GeneratedSourceFiles() android.Paths {
|
||||||
@@ -320,7 +321,7 @@ func (g *Module) generateSourceFile(ctx android.ModuleContext, task generateTask
|
|||||||
Inputs: task.in,
|
Inputs: task.in,
|
||||||
Implicits: g.deps,
|
Implicits: g.deps,
|
||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
"allouts": strings.Join(task.out.Strings(), " "),
|
"allouts": strings.Join(task.sandboxOuts, " "),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if Bool(g.properties.Depfile) {
|
if Bool(g.properties.Depfile) {
|
||||||
@@ -346,23 +347,31 @@ func generatorFactory(taskGenerator taskFunc, props ...interface{}) *Module {
|
|||||||
return module
|
return module
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// replace "out" with "__SBOX_OUT_DIR__/<the value of ${out}>"
|
||||||
|
func pathToSandboxOut(path android.Path, genDir android.Path) string {
|
||||||
|
relOut, err := filepath.Rel(genDir.String(), path.String())
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("Could not make ${out} relative: %v", err))
|
||||||
|
}
|
||||||
|
return filepath.Join("__SBOX_OUT_DIR__", relOut)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func NewGenSrcs() *Module {
|
func NewGenSrcs() *Module {
|
||||||
properties := &genSrcsProperties{}
|
properties := &genSrcsProperties{}
|
||||||
|
|
||||||
taskGenerator := func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) generateTask {
|
taskGenerator := func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) generateTask {
|
||||||
commands := []string{}
|
commands := []string{}
|
||||||
outFiles := android.WritablePaths{}
|
outFiles := android.WritablePaths{}
|
||||||
genPath := android.PathForModuleGen(ctx).String()
|
genDir := android.PathForModuleGen(ctx)
|
||||||
|
sandboxOuts := []string{}
|
||||||
for _, in := range srcFiles {
|
for _, in := range srcFiles {
|
||||||
outFile := android.GenPathWithExt(ctx, "", in, String(properties.Output_extension))
|
outFile := android.GenPathWithExt(ctx, "", in, String(properties.Output_extension))
|
||||||
outFiles = append(outFiles, outFile)
|
outFiles = append(outFiles, outFile)
|
||||||
|
|
||||||
// replace "out" with "__SBOX_OUT_DIR__/<the value of ${out}>"
|
sandboxOutfile := pathToSandboxOut(outFile, genDir)
|
||||||
relOut, err := filepath.Rel(genPath, outFile.String())
|
sandboxOuts = append(sandboxOuts, sandboxOutfile)
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Sprintf("Could not make ${out} relative: %v", err))
|
|
||||||
}
|
|
||||||
sandboxOutfile := filepath.Join("__SBOX_OUT_DIR__", relOut)
|
|
||||||
command, err := android.Expand(rawCommand, func(name string) (string, error) {
|
command, err := android.Expand(rawCommand, func(name string) (string, error) {
|
||||||
switch name {
|
switch name {
|
||||||
case "in":
|
case "in":
|
||||||
@@ -384,9 +393,10 @@ func NewGenSrcs() *Module {
|
|||||||
fullCommand := strings.Join(commands, " && ")
|
fullCommand := strings.Join(commands, " && ")
|
||||||
|
|
||||||
return generateTask{
|
return generateTask{
|
||||||
in: srcFiles,
|
in: srcFiles,
|
||||||
out: outFiles,
|
out: outFiles,
|
||||||
cmd: fullCommand,
|
sandboxOuts: sandboxOuts,
|
||||||
|
cmd: fullCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,13 +419,17 @@ func NewGenRule() *Module {
|
|||||||
|
|
||||||
taskGenerator := func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) generateTask {
|
taskGenerator := func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) generateTask {
|
||||||
outs := make(android.WritablePaths, len(properties.Out))
|
outs := make(android.WritablePaths, len(properties.Out))
|
||||||
|
sandboxOuts := make([]string, len(properties.Out))
|
||||||
|
genDir := android.PathForModuleGen(ctx)
|
||||||
for i, out := range properties.Out {
|
for i, out := range properties.Out {
|
||||||
outs[i] = android.PathForModuleGen(ctx, out)
|
outs[i] = android.PathForModuleGen(ctx, out)
|
||||||
|
sandboxOuts[i] = pathToSandboxOut(outs[i], genDir)
|
||||||
}
|
}
|
||||||
return generateTask{
|
return generateTask{
|
||||||
in: srcFiles,
|
in: srcFiles,
|
||||||
out: outs,
|
out: outs,
|
||||||
cmd: rawCommand,
|
sandboxOuts: sandboxOuts,
|
||||||
|
cmd: rawCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user