Skip to content

Commit

Permalink
Allow setting the 'manual' label for a particular architecture.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterebden committed Sep 26, 2017
1 parent 5f74221 commit ff52684
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 29 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Version 9.1.0
-------------

* The 'manual' label can now be applied per-architecture, e.g. manual:linux_amd64.


Version 9.0.4
-------------

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.0.4
9.1.0
19 changes: 8 additions & 11 deletions src/cache/http_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"time"

"core"
Expand All @@ -21,7 +20,6 @@ type httpCache struct {
Url string
Writeable bool
Timeout time.Duration
OSName string
}

func (cache *httpCache) Store(target *core.BuildTarget, key []byte, files ...string) {
Expand All @@ -48,7 +46,7 @@ func (cache *httpCache) Store(target *core.BuildTarget, key []byte, files ...str
func (cache *httpCache) StoreExtra(target *core.BuildTarget, key []byte, file string) {
if cache.Writeable {
artifact := path.Join(
cache.OSName,
core.OsArch,
target.Label.PackageName,
target.Label.Name,
base64.RawURLEncoding.EncodeToString(key),
Expand Down Expand Up @@ -90,7 +88,7 @@ func (cache *httpCache) RetrieveExtra(target *core.BuildTarget, key []byte, file
log.Debug("Retrieving %s:%s from http cache...", target.Label, file)

artifact := path.Join(
cache.OSName,
core.OsArch,
target.Label.PackageName,
target.Label.Name,
base64.RawURLEncoding.EncodeToString(key),
Expand Down Expand Up @@ -152,7 +150,7 @@ func (cache *httpCache) writeFile(target *core.BuildTarget, file string, r io.Re
func (cache *httpCache) Clean(target *core.BuildTarget) {
var reader io.Reader
artifact := path.Join(
cache.OSName,
core.OsArch,
target.Label.PackageName,
target.Label.Name,
)
Expand All @@ -174,10 +172,9 @@ func (cache *httpCache) CleanAll() {
func (cache *httpCache) Shutdown() {}

func newHttpCache(config *core.Configuration) *httpCache {
cache := new(httpCache)
cache.OSName = runtime.GOOS + "_" + runtime.GOARCH
cache.Url = config.Cache.HttpUrl.String()
cache.Writeable = config.Cache.HttpWriteable
cache.Timeout = time.Duration(config.Cache.HttpTimeout)
return cache
return &httpCache{
Url: config.Cache.HttpUrl.String(),
Writeable: config.Cache.HttpWriteable,
Timeout: time.Duration(config.Cache.HttpTimeout),
}
}
7 changes: 2 additions & 5 deletions src/cache/http_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net/http/httptest"
"path"
"path/filepath"
"runtime"
"testing"
"time"

Expand All @@ -18,11 +17,9 @@ var (
target *core.BuildTarget
httpcache *httpCache
key []byte
osName string
)

func init() {
osName = runtime.GOOS + "_" + runtime.GOARCH
label = core.NewBuildLabel("pkg/name", "label_name")
target = core.NewBuildTarget(label)

Expand All @@ -40,7 +37,7 @@ func init() {
func TestStore(t *testing.T) {
target.AddOutput("testfile")
httpcache.Store(target, []byte("test_key"))
abs, _ := filepath.Abs(path.Join("src/cache/test_data", osName, "pkg/name", "label_name"))
abs, _ := filepath.Abs(path.Join("src/cache/test_data", core.OsArch, "pkg/name", "label_name"))
if !core.PathExists(abs) {
t.Errorf("Test file %s was not stored in cache.", abs)
}
Expand All @@ -54,7 +51,7 @@ func TestRetrieve(t *testing.T) {

func TestClean(t *testing.T) {
httpcache.Clean(target)
filename := path.Join("src/cache/test_data", osName, "pkg/name/label_name")
filename := path.Join("src/cache/test_data", core.OsArch, "pkg/name/label_name")
if core.PathExists(filename) {
t.Errorf("File %s was not removed from cache.", filename)
}
Expand Down
6 changes: 2 additions & 4 deletions src/cache/rpc_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ import (
var (
label core.BuildLabel
rpccache *rpcCache
osName string
)

func init() {
runtime.GOMAXPROCS(1) // Don't allow tests to run in parallel, they should work but makes debugging tricky
osName = runtime.GOOS + "_" + runtime.GOARCH
label = core.NewBuildLabel("pkg/name", "label_name")

// Move this directory from test_data to somewhere local.
Expand Down Expand Up @@ -68,7 +66,7 @@ func TestStore(t *testing.T) {
target := core.NewBuildTarget(label)
target.AddOutput("testfile2")
rpccache.Store(target, []byte("test_key"))
expectedPath := path.Join("src/cache/test_data", osName, "pkg/name", "label_name", "dGVzdF9rZXk", target.Outputs()[0])
expectedPath := path.Join("src/cache/test_data", core.OsArch, "pkg/name", "label_name", "dGVzdF9rZXk", target.Outputs()[0])
if !core.PathExists(expectedPath) {
t.Errorf("Test file %s was not stored in cache.", expectedPath)
}
Expand Down Expand Up @@ -101,7 +99,7 @@ func TestStoreAndRetrieve(t *testing.T) {
func TestClean(t *testing.T) {
target := core.NewBuildTarget(label)
rpccache.Clean(target)
filename := path.Join("src/cache/test_data", osName, "pkg/name/label_name")
filename := path.Join("src/cache/test_data", core.OsArch, "pkg/name/label_name")
if core.PathExists(filename) {
t.Errorf("File %s was not removed from cache.", filename)
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/build_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ func (target *BuildTarget) HasAllLabels(labels []string) bool {
// Each include/exclude can have multiple comma-separated labels; in this case, all of the labels
// in a given group must match.
func (target *BuildTarget) ShouldInclude(includes, excludes []string) bool {
if target.HasLabel("manual") {
if target.HasLabel("manual") || target.HasLabel("manual:"+OsArch) {
return false
}

Expand Down
14 changes: 14 additions & 0 deletions src/core/build_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,20 @@ func TestShouldIncludeWithCompoundIncludeAndExclude(t *testing.T) {
assert.False(t, target.ShouldInclude(includes, excludes))
}

func TestShouldIncludeManual(t *testing.T) {
target := makeTargetWithLabels("//src/core:target1", "a", "manual")
// Doesn't include because "manual" overrides it
assert.False(t, target.ShouldInclude([]string{"a"}, nil))

target = makeTargetWithLabels("//src/core:target1", "a", "manual:test_armhf")
// Does include because it's a different architecture
assert.True(t, target.ShouldInclude([]string{"a"}, nil))

target = makeTargetWithLabels("//src/core:target1", "a", "manual:"+OsArch)
// Doesn't include because it's manual for this architecture.
assert.False(t, target.ShouldInclude([]string{"a"}, nil))
}

func makeTarget(label, visibility string, deps ...*BuildTarget) *BuildTarget {
target := NewBuildTarget(ParseBuildLabel(label, ""))
if visibility == "PUBLIC" {
Expand Down
18 changes: 11 additions & 7 deletions src/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@ import (
"cli"
)

// File name for the typical repo config - this is normally checked in
// OsArch is the os/arch pair, like linux_amd64 etc.
const OsArch = runtime.GOOS + "_" + runtime.GOARCH

// ConfigFileName is the file name for the typical repo config - this is normally checked in
const ConfigFileName string = ".plzconfig"

// Architecture-specific config file which overrides the repo one. Also normally checked in if needed.
const ArchConfigFileName string = ".plzconfig_" + runtime.GOOS + "_" + runtime.GOARCH
// ArchConfigFileName is the architecture-specific config file which overrides the repo one.
// Also normally checked in if needed.
const ArchConfigFileName string = ".plzconfig_" + OsArch

// File name for the local repo config - this is not normally checked in and used to
// override settings on the local machine.
// LocalConfigFileName is the file name for the local repo config - this is not normally checked
// in and used to override settings on the local machine.
const LocalConfigFileName string = ".plzconfig.local"

// File name for the machine-level config - can use this to override things
// for a particular machine (eg. build machine with different caching behaviour).
// MachineConfigFileName is the file name for the machine-level config - can use this to override
// things for a particular machine (eg. build machine with different caching behaviour).
const MachineConfigFileName = "/etc/plzconfig"

const (
Expand Down

0 comments on commit ff52684

Please sign in to comment.