Skip to content

Commit

Permalink
Rework rule building in lineage_generator
Browse files Browse the repository at this point in the history
Signed-off-by: SagarMakhar <[email protected]>
Co-authored-by: Arian <[email protected]>
Change-Id: I05c36b8660e51a18ac70a6712b2d03edfc561156
  • Loading branch information
SagarMakhar and ArianK16a committed Oct 15, 2021
1 parent 8c26f9b commit 5a4a0c7
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions build/soong/generator/generator.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2015 Google Inc. All rights reserved.
// Copyright (C) 2018 The LineageOS Project
// Copyright (C) 2018,2021 The LineageOS Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -24,14 +24,11 @@ import (
"github.com/google/blueprint/proptools"

"android/soong/android"
"android/soong/shared"
"path/filepath"
)

func init() {
android.RegisterModuleType("lineage_generator", GeneratorFactory)

pctx.HostBinToolVariable("sboxCmd", "sbox")
}

var String = proptools.String
Expand Down Expand Up @@ -245,7 +242,7 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
return tools[toolFiles[0].Rel()].String(), nil
}
case "genDir":
return "__SBOX_OUT_DIR__", nil
return android.PathForModuleGen(ctx).String(), nil
default:
if strings.HasPrefix(name, "location ") {
label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Expand All @@ -267,33 +264,23 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// Dummy output dep
dummyDep := android.PathForModuleGen(ctx, ".dummy_dep")

// tell the sbox command which directory to use as its sandbox root
buildDir := android.PathForOutput(ctx).String()
sandboxPath := shared.TempDirForOutDir(buildDir)

genDir := android.PathForModuleGen(ctx)
// Escape the command for the shell
rawCommand = "'" + strings.Replace(rawCommand, "'", `'\''`, -1) + "'"
sandboxCommand := fmt.Sprintf("$sboxCmd --sandbox-path %s --output-root %s --copy-all-output -c %s && touch %s",
sandboxPath, genDir, rawCommand, dummyDep.String())

ruleParams := blueprint.RuleParams{
Command: sandboxCommand,
CommandDeps: []string{"$sboxCmd"},
}
g.rule = ctx.Rule(pctx, "generator", ruleParams)

params := android.BuildParams{
Rule: g.rule,
Description: "generate",
Output: dummyDep,
Inputs: g.inputDeps,
Implicits: g.implicitDeps,
}
manifestPath := android.PathForModuleOut(ctx, "generator.sbox.textproto")

// Use a RuleBuilder to create a rule that runs the command inside an sbox sandbox.
rule := android.NewRuleBuilder(pctx, ctx).Sbox(genDir, manifestPath).SandboxTools()

rule.Command().
Text(rawCommand).
ImplicitOutput(dummyDep).
Implicits(g.inputDeps).
Implicits(g.implicitDeps)

rule.Command().Text("touch").Output(dummyDep)

g.outputDeps = append(g.outputDeps, dummyDep)

ctx.Build(pctx, params)
rule.Build("generator", "generate")
}

func NewGenerator() *Module {
Expand Down

0 comments on commit 5a4a0c7

Please sign in to comment.