func TestCreateMakefile(t *testing.T) { oldChooseTool := toolchain.ChooseTool defer func() { toolchain.ChooseTool = oldChooseTool }() toolchain.ChooseTool = func(op, unitType string) (*srclib.ToolRef, error) { return &srclib.ToolRef{ Toolchain: "tc", Subcmd: "t", }, nil } buildDataDir := "testdata" c := &config.Tree{ SourceUnits: []*unit.SourceUnit{ { Key: unit.Key{ Name: "n", Type: "t", }, Info: unit.Info{ Files: []string{"f"}, Ops: map[string][]byte{ "graph": nil, "depresolve": nil, }, }, }, }, } mf, err := plan.CreateMakefile(buildDataDir, nil, "", c) if err != nil { t.Fatal(err) } want := ` .PHONY: all all: testdata/n/t.depresolve.json testdata/n/t.graph.json testdata/n/t.depresolve.json: testdata/n/t.unit.json srclib tool "tc" "t" < $^ 1> $@ testdata/n/t.graph.json: testdata/n/t.unit.json srclib tool "tc" "t" < $< | srclib internal normalize-graph-data --unit-type "t" --dir . 1> $@ .DELETE_ON_ERROR: ` gotBytes, err := makex.Marshal(mf) if err != nil { t.Fatal(err) } want = strings.TrimSpace(want) got := string(bytes.TrimSpace(gotBytes)) if got != want { t.Errorf("got makefile:\n==========\n%s\n==========\n\nwant makefile:\n==========\n%s\n==========", got, want) } }
func (c *MakefileCmd) Execute(args []string) error { mf, err := CreateMakefile(c.ToolchainExecOpt, c.BuildCacheOpt) if err != nil { return err } mfData, err := makex.Marshal(mf) if err != nil { return err } _, err = os.Stdout.Write(mfData) return err }
func (c *MakefileCmd) Execute(args []string) error { mf, err := CreateMakefile() if err != nil { return err } mfData, err := makex.Marshal(mf) if err != nil { return err } _, err = os.Stdout.Write(mfData) return err }
func TestCreateMakefile(t *testing.T) { buildDataDir := "testdata" c := &config.Tree{ SourceUnits: []*unit.SourceUnit{ { Name: "n", Type: "t", Files: []string{"f"}, Ops: map[string]*srclib.ToolRef{ "graph": {Toolchain: "tc", Subcmd: "t"}, "depresolve": {Toolchain: "tc", Subcmd: "t"}, }, }, }, } mf, err := plan.CreateMakefile(buildDataDir, nil, "", c, plan.Options{NoCache: true}) if err != nil { t.Fatal(err) } sep := string(filepath.Separator) want := ` all: testdata` + sep + `n` + sep + `t.graph.json testdata` + sep + `n` + sep + `t.depresolve.json testdata` + sep + `n` + sep + `t.graph.json: testdata` + sep + `n` + sep + `t.unit.json f src tool "tc" "t" < $< | src internal normalize-graph-data --unit-type "t" --dir . 1> $@ testdata` + sep + `n` + sep + `t.depresolve.json: testdata` + sep + `n` + sep + `t.unit.json src tool "tc" "t" < $^ 1> $@ .DELETE_ON_ERROR: ` gotBytes, err := makex.Marshal(mf) if err != nil { t.Fatal(err) } want = strings.TrimSpace(want) got := string(bytes.TrimSpace(gotBytes)) if got != want { t.Errorf("got makefile:\n==========\n%s\n==========\n\nwant makefile:\n==========\n%s\n==========", got, want) } }