Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 91b38477 authored by Jaewoong Jung's avatar Jaewoong Jung Committed by Gerrit Code Review
Browse files

Merge "Add defaults support to genrule."

parents a45e15e2 98716bdf
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import (
)

func init() {
	android.RegisterModuleType("genrule_defaults", defaultsFactory)

	android.RegisterModuleType("gensrcs", GenSrcsFactory)
	android.RegisterModuleType("genrule", GenRuleFactory)
}
@@ -95,6 +97,7 @@ type generatorProperties struct {

type Module struct {
	android.ModuleBase
	android.DefaultableModuleBase

	// For other packages to make their own genrules with extra
	// properties
@@ -502,6 +505,7 @@ func NewGenRule() *Module {
func GenRuleFactory() android.Module {
	m := NewGenRule()
	android.InitAndroidModule(m)
	android.InitDefaultableModule(m)
	return m
}

@@ -512,3 +516,35 @@ type genRuleProperties struct {

var Bool = proptools.Bool
var String = proptools.String

//
// Defaults
//
type Defaults struct {
	android.ModuleBase
	android.DefaultsModuleBase
}

func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}

func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
}

func defaultsFactory() android.Module {
	return DefaultsFactory()
}

func DefaultsFactory(props ...interface{}) android.Module {
	module := &Defaults{}

	module.AddProperties(props...)
	module.AddProperties(
		&generatorProperties{},
		&genRuleProperties{},
	)

	android.InitDefaultsModule(module)

	return module
}
+43 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import (
	"testing"

	"android/soong/android"
	"reflect"
)

var buildDir string
@@ -54,7 +55,9 @@ func testContext(config android.Config, bp string,
	ctx := android.NewTestArchContext()
	ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
	ctx.RegisterModuleType("genrule", android.ModuleFactoryAdaptor(GenRuleFactory))
	ctx.RegisterModuleType("genrule_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
	ctx.RegisterModuleType("tool", android.ModuleFactoryAdaptor(toolFactory))
	ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
	ctx.Register()

	bp += `
@@ -465,6 +468,46 @@ func TestGenruleCmd(t *testing.T) {

}

func TestGenruleDefaults(t *testing.T) {
	config := android.TestArchConfig(buildDir, nil)
	bp := `
				genrule_defaults {
					name: "gen_defaults1",
					cmd: "cp $(in) $(out)",
				}

				genrule_defaults {
					name: "gen_defaults2",
					srcs: ["in1"],
				}

				genrule {
					name: "gen",
					out: ["out"],
					defaults: ["gen_defaults1", "gen_defaults2"],
				}
			`
	ctx := testContext(config, bp, nil)
	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
	if errs == nil {
		_, errs = ctx.PrepareBuildActions(config)
	}
	if errs != nil {
		t.Fatal(errs)
	}
	gen := ctx.ModuleForTests("gen", "").Module().(*Module)

	expectedCmd := "'cp ${in} __SBOX_OUT_FILES__'"
	if gen.rawCommand != expectedCmd {
		t.Errorf("Expected cmd: %q, actual: %q", expectedCmd, gen.rawCommand)
	}

	expectedSrcs := []string{"in1"}
	if !reflect.DeepEqual(expectedSrcs, gen.properties.Srcs) {
		t.Errorf("Expected srcs: %q, actual: %q", expectedSrcs, gen.properties.Srcs)
	}
}

type testTool struct {
	android.ModuleBase
	outputFile android.Path