func makeCaches() (mockCache, core.Cache) {
	mCache := mockCache{
		inFlight:  make(map[*core.BuildTarget]bool),
		completed: make(map[*core.BuildTarget]bool),
		stored:    make(map[*core.BuildTarget][]string),
	}
	return mCache, newAsyncCache(&mCache, core.DefaultConfiguration())
}
示例#2
0
func makeConfig(dir string) *core.Configuration {
	c := core.DefaultConfiguration()
	wd, _ := os.Getwd()
	c.Please.Location = path.Join(wd, dir)
	c.Please.DownloadLocation = server.URL
	c.Please.Version = *semver.New("42.0.0")
	return c
}
示例#3
0
func TestExportedFunctions(t *testing.T) {
	// For various reasons it's important that this is the only test that uses the global singleton.
	config := core.DefaultConfiguration()
	config.Metrics.PushGatewayURL = url
	config.Metrics.PushFrequency = verySlow
	InitFromConfig(config)
	Record(core.NewBuildTarget(label), time.Millisecond)
	Stop()
	assert.Equal(t, 1, m.errors)
}
示例#4
0
func init() {
	osName = runtime.GOOS + "_" + runtime.GOARCH
	label = core.NewBuildLabel("pkg/name", "label_name")
	target = core.NewBuildTarget(label)

	// Arbitrary large numbers so the cleaner never needs to run.
	cache := server.NewCache("src/cache/test_data", 20*time.Hour, 100000, 100000000, 1000000000)
	key, _ = ioutil.ReadFile("src/cache/test_data/testfile")
	testServer := httptest.NewServer(server.BuildRouter(cache))

	config := core.DefaultConfiguration()
	config.Cache.HttpUrl = testServer.URL
	config.Cache.HttpWriteable = true
	httpcache = newHttpCache(config)
}
func TestBazelCompatReplacements(t *testing.T) {
	// Check that we don't do any of these things normally.
	target := makeTarget("//path/to:target", "cp $< $@", nil)
	assert.Equal(t, "cp $< $@", replaceSequences(target))
	// In Bazel compat mode we do though.
	state := core.NewBuildState(1, nil, 1, core.DefaultConfiguration())
	state.Config.Bazel.Compatibility = true
	assert.Equal(t, "cp $SRCS $OUTS", replaceSequences(target))
	// @D is the output dir, for us it's the tmp dir.
	target.Command = "cp $SRCS $@D"
	assert.Equal(t, "cp $SRCS $TMP_DIR", replaceSequences(target))
	// This parenthesised syntax seems to be allowed too.
	target.Command = "cp $(<) $(@)"
	assert.Equal(t, "cp $SRCS $OUTS", replaceSequences(target))
}
示例#6
0
func buildClient(port int, ca string) *rpcCache {
	config := core.DefaultConfiguration()
	config.Cache.RpcUrl = fmt.Sprintf("localhost:%d", port)
	config.Cache.RpcWriteable = true
	config.Cache.RpcCACert = ca

	cache, err := newRpcCache(config)
	if err != nil {
		log.Fatalf("Failed to create RPC cache: %s", err)
	}

	// Busy-wait sucks but this isn't supposed to be visible from outside.
	for i := 0; i < 10 && !cache.Connected && cache.Connecting; i++ {
		time.Sleep(100 * time.Millisecond)
	}
	return cache
}
func TestGetSubincludeFile(t *testing.T) {
	assertError := func(t *testing.T, ret, msg string) { assert.True(t, strings.HasPrefix(ret, "__"), msg) }

	state := core.NewBuildState(10, nil, 2, core.DefaultConfiguration())
	pkg := core.NewPackage("src/parse")
	pkg2 := core.NewPackage("src/core")
	assert.Equal(t, pyDeferParse, getSubincludeFile(pkg, "//src/core:target"), "Package not loaded yet, should defer")
	assertError(t, getSubincludeFile(pkg, "//src/parse:target"), "Should produce an error on attempts for local subincludes.")
	assertError(t, getSubincludeFile(pkg, ":target"), "Should produce an error on attempts for local subincludes.")
	state.Graph.AddPackage(pkg)
	state.Graph.AddPackage(pkg2)
	assertError(t, getSubincludeFile(pkg, "//src/core:target"), "Produces an error, target does not exist in package.")
	target := core.NewBuildTarget(core.ParseBuildLabel("//src/core:target", ""))
	state.Graph.AddTarget(target)
	assertError(t, getSubincludeFile(pkg, "//src/core:target"), "Errors, target is not visible to subincluding package.")
	target.Visibility = []core.BuildLabel{core.ParseBuildLabel("//src/parse:all", "")}
	assertError(t, getSubincludeFile(pkg, "//src/core:target"), "Errors, target doesn't have any outputs to include.")
	target.AddOutput("test.py")
	assert.Equal(t, pyDeferParse, getSubincludeFile(pkg, "//src/core:target"), "Target isn't built yet, so still deferred")
	target.SetState(core.Built)
	assert.Equal(t, "plz-out/gen/src/core/test.py", getSubincludeFile(pkg, "//src/core:target"), "Success at last")
}
func TestGetLabels(t *testing.T) {
	state := core.NewBuildState(10, nil, 2, core.DefaultConfiguration())
	target1 := core.NewBuildTarget(core.ParseBuildLabel("//src/parse:target1", ""))
	target2 := core.NewBuildTarget(core.ParseBuildLabel("//src/parse:target2", ""))
	target3 := core.NewBuildTarget(core.ParseBuildLabel("//src/parse:target3", ""))
	target1.AddLabel("go")
	target2.AddLabel("py")
	target3.AddLabel("cc")
	target1.AddDependency(target2.Label)
	target1.AddDependency(target3.Label)
	target2.AddDependency(target3.Label)
	state.Graph.AddTarget(target1)
	state.Graph.AddTarget(target2)
	state.Graph.AddTarget(target3)
	state.Graph.AddDependency(target1.Label, target2.Label)
	state.Graph.AddDependency(target1.Label, target3.Label)
	state.Graph.AddDependency(target2.Label, target3.Label)
	// Note labels always come out in sorted order.
	assert.Equal(t, []string{"cc", "go", "py"}, getLabels(target1, "", core.Inactive))
	assert.Equal(t, []string{"cc", "py"}, getLabels(target2, "", core.Inactive))
	assert.Equal(t, []string{"cc"}, getLabels(target3, "", core.Inactive))
	assert.Equal(t, []string{"y"}, getLabels(target1, "p", core.Inactive))
}
示例#9
0
// makeState creates a new build state with optionally one or two packages in it.
// Used in various tests above.
func makeState(withPackage1, withPackage2 bool) *core.BuildState {
	state := core.NewBuildState(5, nil, 4, core.DefaultConfiguration())
	if withPackage1 {
		pkg := core.NewPackage("package1")
		state.Graph.AddPackage(pkg)
		pkg.Targets["target1"] = makeTarget("//package1:target1", "//package1:target2", "//package2:target1")
		pkg.Targets["target2"] = makeTarget("//package1:target2", "//package2:target1")
		pkg.Targets["target3"] = makeTarget("//package1:target3", "//package2:target2")
		state.Graph.AddTarget(pkg.Targets["target1"])
		state.Graph.AddTarget(pkg.Targets["target2"])
		state.Graph.AddTarget(pkg.Targets["target3"])
		addDeps(state.Graph, pkg)
	}
	if withPackage2 {
		pkg := core.NewPackage("package2")
		state.Graph.AddPackage(pkg)
		pkg.Targets["target1"] = makeTarget("//package2:target1", "//package2:target2", "//package1:target3")
		pkg.Targets["target2"] = makeTarget("//package2:target2")
		state.Graph.AddTarget(pkg.Targets["target1"])
		state.Graph.AddTarget(pkg.Targets["target2"])
		addDeps(state.Graph, pkg)
	}
	return state
}
func init() {
	core.NewBuildState(1, nil, 1, core.DefaultConfiguration())
}
示例#11
0
func TestMain(m *testing.M) {
	core.NewBuildState(10, nil, 2, core.DefaultConfiguration())
	// Need to set this before calling parseSource.
	core.State.Config.Please.BuildFileName = []string{"TEST_BUILD"}
	os.Exit(m.Run())
}
示例#12
0
func TestMain(m *testing.M) {
	// Need to set this before calling parseSource. It's a bit of a hack but whatevs.
	buildFileNames = []string{"TEST_BUILD"}
	core.NewBuildState(10, nil, 2, core.DefaultConfiguration())
	os.Exit(m.Run())
}
示例#13
0
func init() {
	cache = newCache(cachePath)
	core.NewBuildState(1, nil, 4, core.DefaultConfiguration())
}