Filter target build-tags if user specified an overriding option (#3357)
compileopts: Filter target build-tags if user specified an overriding option
Этот коммит содержится в:
родитель
cecb80b8bf
коммит
e0a5fc2555
2 изменённых файлов: 158 добавлений и 1 удалений
|
@ -75,7 +75,8 @@ func (c *Config) GOARM() string {
|
|||
|
||||
// BuildTags returns the complete list of build tags used during this build.
|
||||
func (c *Config) BuildTags() []string {
|
||||
tags := append(c.Target.BuildTags, []string{"tinygo", "math_big_pure_go", "gc." + c.GC(), "scheduler." + c.Scheduler(), "serial." + c.Serial()}...)
|
||||
targetTags := filterTags(c.Target.BuildTags, c.Options.Tags)
|
||||
tags := append(targetTags, []string{"tinygo", "math_big_pure_go", "gc." + c.GC(), "scheduler." + c.Scheduler(), "serial." + c.Serial()}...)
|
||||
for i := 1; i <= c.GoMinorVersion; i++ {
|
||||
tags = append(tags, fmt.Sprintf("go1.%d", i))
|
||||
}
|
||||
|
@ -550,3 +551,27 @@ type TestConfig struct {
|
|||
CompileTestBinary bool
|
||||
// TODO: Filter the test functions to run, include verbose flag, etc
|
||||
}
|
||||
|
||||
// filterTags removes predefined build tags for a target if a conflicting option
|
||||
// is provided by the user.
|
||||
func filterTags(targetTags []string, userTags []string) []string {
|
||||
var filtered []string
|
||||
for _, t := range targetTags {
|
||||
switch {
|
||||
case strings.HasPrefix(t, "runtime_memhash_"):
|
||||
overridden := false
|
||||
for _, ut := range userTags {
|
||||
if strings.HasPrefix(ut, "runtime_memhash_") {
|
||||
overridden = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !overridden {
|
||||
filtered = append(filtered, t)
|
||||
}
|
||||
default:
|
||||
filtered = append(filtered, t)
|
||||
}
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
|
132
compileopts/config_test.go
Обычный файл
132
compileopts/config_test.go
Обычный файл
|
@ -0,0 +1,132 @@
|
|||
package compileopts
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBuildTags(t *testing.T) {
|
||||
tests := []struct {
|
||||
targetTags []string
|
||||
userTags []string
|
||||
result []string
|
||||
}{
|
||||
{
|
||||
targetTags: []string{},
|
||||
userTags: []string{},
|
||||
result: []string{
|
||||
"tinygo",
|
||||
"math_big_pure_go",
|
||||
"gc.conservative",
|
||||
"scheduler.none",
|
||||
"serial.none",
|
||||
},
|
||||
},
|
||||
{
|
||||
targetTags: []string{"bear"},
|
||||
userTags: []string{},
|
||||
result: []string{
|
||||
"bear",
|
||||
"tinygo",
|
||||
"math_big_pure_go",
|
||||
"gc.conservative",
|
||||
"scheduler.none",
|
||||
"serial.none",
|
||||
},
|
||||
},
|
||||
{
|
||||
targetTags: []string{},
|
||||
userTags: []string{"cat"},
|
||||
result: []string{
|
||||
"tinygo",
|
||||
"math_big_pure_go",
|
||||
"gc.conservative",
|
||||
"scheduler.none",
|
||||
"serial.none",
|
||||
"cat",
|
||||
},
|
||||
},
|
||||
{
|
||||
targetTags: []string{"bear"},
|
||||
userTags: []string{"cat"},
|
||||
result: []string{
|
||||
"bear",
|
||||
"tinygo",
|
||||
"math_big_pure_go",
|
||||
"gc.conservative",
|
||||
"scheduler.none",
|
||||
"serial.none",
|
||||
"cat",
|
||||
},
|
||||
},
|
||||
{
|
||||
targetTags: []string{"bear", "runtime_memhash_leveldb"},
|
||||
userTags: []string{"cat"},
|
||||
result: []string{
|
||||
"bear",
|
||||
"runtime_memhash_leveldb",
|
||||
"tinygo",
|
||||
"math_big_pure_go",
|
||||
"gc.conservative",
|
||||
"scheduler.none",
|
||||
"serial.none",
|
||||
"cat",
|
||||
},
|
||||
},
|
||||
{
|
||||
targetTags: []string{"bear", "runtime_memhash_leveldb"},
|
||||
userTags: []string{"cat", "runtime_memhash_leveldb"},
|
||||
result: []string{
|
||||
"bear",
|
||||
"tinygo",
|
||||
"math_big_pure_go",
|
||||
"gc.conservative",
|
||||
"scheduler.none",
|
||||
"serial.none",
|
||||
"cat",
|
||||
"runtime_memhash_leveldb",
|
||||
},
|
||||
},
|
||||
{
|
||||
targetTags: []string{"bear", "runtime_memhash_leveldb"},
|
||||
userTags: []string{"cat", "runtime_memhash_sip"},
|
||||
result: []string{
|
||||
"bear",
|
||||
"tinygo",
|
||||
"math_big_pure_go",
|
||||
"gc.conservative",
|
||||
"scheduler.none",
|
||||
"serial.none",
|
||||
"cat",
|
||||
"runtime_memhash_sip",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
tt := tc
|
||||
t.Run(fmt.Sprintf("%s+%s", strings.Join(tt.targetTags, ","), strings.Join(tt.userTags, ",")), func(t *testing.T) {
|
||||
c := &Config{
|
||||
Target: &TargetSpec{
|
||||
BuildTags: tt.targetTags,
|
||||
},
|
||||
Options: &Options{
|
||||
Tags: tt.userTags,
|
||||
},
|
||||
}
|
||||
|
||||
res := c.BuildTags()
|
||||
|
||||
if len(res) != len(tt.result) {
|
||||
t.Errorf("expected %d tags, got %d", len(tt.result), len(res))
|
||||
}
|
||||
|
||||
for i, tag := range tt.result {
|
||||
if tag != res[i] {
|
||||
t.Errorf("tag %d: expected %s, got %s", i, tt.result[i], tag)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Загрузка…
Создание таблицы
Сослаться в новой задаче