-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade original targets #2942
Merged
peterebden
merged 10 commits into
thought-machine:master
from
peterebden:upgrade-original-targets
Nov 3, 2023
Merged
Upgrade original targets #2942
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
878a312
Add targetset
peterebden 4a96e39
start using it
peterebden 8bcf6f2
Add AllTargets
peterebden 0ee7324
Update a couple of tests
peterebden 56ed27a
Add tests
peterebden 809836b
Preserve original ordering
peterebden 27fcfe9
Exclude gocritic for test files, my tests don't need any more criticism
peterebden 5a544e4
Version bump
peterebden ce90345
Fix IsOriginalTarget logic
peterebden 2f19586
goddamn tabses, we hates them
peterebden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
17.4.0-beta.3 | ||
17.4.0-beta.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,8 @@ func TestExpandVisibleOriginalTargets(t *testing.T) { | |
|
||
func TestExpandOriginalSubLabels(t *testing.T) { | ||
state := NewDefaultBuildState() | ||
state.AddOriginalTarget(BuildLabel{PackageName: "src/core", Name: "..."}, true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we ever actually needed to support this. The new implementation just panics but things like |
||
state.AddOriginalTarget(BuildLabel{PackageName: "src/core", Name: "all"}, true) | ||
state.AddOriginalTarget(BuildLabel{PackageName: "src/core/tests", Name: "all"}, true) | ||
state.Include = []string{"go"} | ||
state.Exclude = []string{"py"} | ||
addTarget(state, "//src/core:target1", "go") | ||
|
@@ -76,7 +77,8 @@ func TestExpandOriginalSubLabels(t *testing.T) { | |
func TestExpandOriginalLabelsOrdering(t *testing.T) { | ||
state := NewDefaultBuildState() | ||
state.AddOriginalTarget(BuildLabel{PackageName: "src/parse", Name: "parse"}, true) | ||
state.AddOriginalTarget(BuildLabel{PackageName: "src/core", Name: "..."}, true) | ||
state.AddOriginalTarget(BuildLabel{PackageName: "src/core", Name: "all"}, true) | ||
state.AddOriginalTarget(BuildLabel{PackageName: "src/core/tests", Name: "all"}, true) | ||
state.AddOriginalTarget(BuildLabel{PackageName: "src/build", Name: "build"}, true) | ||
addTarget(state, "//src/core:target1", "go") | ||
addTarget(state, "//src/core:target2", "py") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package core | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
// A TargetSet contains a series of targets and supports efficiently checking for membership | ||
// The zero value is not safe for use. | ||
type TargetSet struct { | ||
targets map[BuildLabel]struct{} | ||
packages map[packageKey]struct{} | ||
everything []BuildLabel | ||
mutex sync.RWMutex | ||
} | ||
|
||
// NewTargetSet returns a new TargetSet. | ||
func NewTargetSet() *TargetSet { | ||
return &TargetSet{ | ||
targets: map[BuildLabel]struct{}{}, | ||
packages: map[packageKey]struct{}{}, | ||
} | ||
} | ||
|
||
// Add adds a new target to this set. | ||
func (ts *TargetSet) Add(label BuildLabel) { | ||
ts.mutex.Lock() | ||
defer ts.mutex.Unlock() | ||
if label.IsAllSubpackages() { | ||
panic("TargetSet doesn't support ... labels") | ||
} else if label.IsAllTargets() { | ||
ts.packages[label.packageKey()] = struct{}{} | ||
} else { | ||
ts.targets[label] = struct{}{} | ||
} | ||
ts.everything = append(ts.everything, label) | ||
} | ||
|
||
// Match checks if this label is covered by the set (either explicitly or via :all) | ||
// The first return checks if it's matched, the second if the match was exact or not. | ||
func (ts *TargetSet) Match(label BuildLabel) (bool, bool) { | ||
ts.mutex.RLock() | ||
defer ts.mutex.RUnlock() | ||
if _, present := ts.targets[label]; present { | ||
return true, true | ||
} | ||
_, present := ts.packages[label.packageKey()] | ||
return present, false | ||
} | ||
|
||
// MatchExact checks if this label was explicitly added to the set (i.e. :all doesn't count) | ||
func (ts *TargetSet) MatchExact(label BuildLabel) bool { | ||
ts.mutex.RLock() | ||
defer ts.mutex.RUnlock() | ||
_, present := ts.targets[label] | ||
return present | ||
} | ||
|
||
// AllTargets returns a copy of the set of targets | ||
func (ts *TargetSet) AllTargets() []BuildLabel { | ||
ts.mutex.RLock() | ||
defer ts.mutex.RUnlock() | ||
return ts.everything[:] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package core | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTargetSetMatch(t *testing.T) { | ||
ts := NewTargetSet() | ||
ts.Add(ParseBuildLabel("//src/core:core", "")) | ||
ts.Add(ParseBuildLabel("//src/parse:all", "")) | ||
matched, exact := ts.Match(ParseBuildLabel("//src/core:core", "")) | ||
assert.True(t, matched) | ||
assert.True(t, exact) | ||
matched, exact = ts.Match(ParseBuildLabel("//src/core:core_test", "")) | ||
assert.False(t, matched) | ||
assert.False(t, exact) | ||
matched, exact = ts.Match(ParseBuildLabel("//src/parse:parse", "")) | ||
assert.True(t, matched) | ||
assert.False(t, exact) | ||
matched, exact = ts.Match(ParseBuildLabel("//src/parse:parse_test", "")) | ||
assert.True(t, matched) | ||
assert.False(t, exact) | ||
matched, exact = ts.Match(ParseBuildLabel("//src/build", "")) | ||
assert.False(t, matched) | ||
assert.False(t, exact) | ||
} | ||
|
||
func TestTargetSetMatchExact(t *testing.T) { | ||
ts := NewTargetSet() | ||
ts.Add(ParseBuildLabel("//src/core:core", "")) | ||
ts.Add(ParseBuildLabel("//src/parse:all", "")) | ||
assert.True(t, ts.MatchExact(ParseBuildLabel("//src/core:core", ""))) | ||
assert.False(t, ts.MatchExact(ParseBuildLabel("//src/core:core_test", ""))) | ||
assert.False(t, ts.MatchExact(ParseBuildLabel("//src/parse:parse", ""))) | ||
assert.False(t, ts.MatchExact(ParseBuildLabel("//src/parse:parse_test", ""))) | ||
assert.False(t, ts.MatchExact(ParseBuildLabel("//src/build", ""))) | ||
} | ||
|
||
func TestAllTargets(t *testing.T) { | ||
ts := NewTargetSet() | ||
labels := []BuildLabel{ | ||
ParseBuildLabel("//src/core:core", ""), | ||
ParseBuildLabel("//src/core:core_test", ""), | ||
ParseBuildLabel("//src/parse:all", ""), | ||
ParseBuildLabel("//src/parse:parse_test", ""), | ||
} | ||
for _, label := range labels { | ||
ts.Add(label) | ||
} | ||
assert.Equal(t, labels, ts.AllTargets()) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm restructuring this a bit but also it was wrong for ages because it didn't look at subrepos.