From ff52684882ffac48adcb1d9d8540fdf3fae97cfa Mon Sep 17 00:00:00 2001 From: Peter Ebden Date: Tue, 26 Sep 2017 09:44:49 +0100 Subject: [PATCH] Allow setting the 'manual' label for a particular architecture. --- ChangeLog | 6 ++++++ VERSION | 2 +- src/cache/http_cache.go | 19 ++++++++----------- src/cache/http_cache_test.go | 7 ++----- src/cache/rpc_cache_test.go | 6 ++---- src/core/build_target.go | 2 +- src/core/build_target_test.go | 14 ++++++++++++++ src/core/config.go | 18 +++++++++++------- 8 files changed, 45 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index cc10df4c4a..229369a683 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 ------------- diff --git a/VERSION b/VERSION index 77063fc9e3..47da986f86 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -9.0.4 +9.1.0 diff --git a/src/cache/http_cache.go b/src/cache/http_cache.go index 25f7dfb5d0..720226c557 100644 --- a/src/cache/http_cache.go +++ b/src/cache/http_cache.go @@ -11,7 +11,6 @@ import ( "os" "path" "path/filepath" - "runtime" "time" "core" @@ -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) { @@ -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), @@ -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), @@ -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, ) @@ -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), + } } diff --git a/src/cache/http_cache_test.go b/src/cache/http_cache_test.go index 3aac9e1530..71019e4af7 100644 --- a/src/cache/http_cache_test.go +++ b/src/cache/http_cache_test.go @@ -5,7 +5,6 @@ import ( "net/http/httptest" "path" "path/filepath" - "runtime" "testing" "time" @@ -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) @@ -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) } @@ -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) } diff --git a/src/cache/rpc_cache_test.go b/src/cache/rpc_cache_test.go index 40cd032a39..9bf5d257b5 100644 --- a/src/cache/rpc_cache_test.go +++ b/src/cache/rpc_cache_test.go @@ -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. @@ -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) } @@ -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) } diff --git a/src/core/build_target.go b/src/core/build_target.go index 280a38cc03..a2edee9eb8 100644 --- a/src/core/build_target.go +++ b/src/core/build_target.go @@ -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 } diff --git a/src/core/build_target_test.go b/src/core/build_target_test.go index 3ef4b42896..c70be23ec4 100644 --- a/src/core/build_target_test.go +++ b/src/core/build_target_test.go @@ -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" { diff --git a/src/core/config.go b/src/core/config.go index 94f83e78b0..f33760338c 100644 --- a/src/core/config.go +++ b/src/core/config.go @@ -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 (