-
Notifications
You must be signed in to change notification settings - Fork 6
Do not duplicate packages when running gazelle-update-repos #47
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
4729a48
124ad22
966b082
362e862
7388c7e
fed76e2
999e16a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ import ( | |||||||||||||||||||||||||||||||||||
| "errors" | ||||||||||||||||||||||||||||||||||||
| "flag" | ||||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||||
| "strconv" | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| "github.com/bazelbuild/bazel-gazelle/config" | ||||||||||||||||||||||||||||||||||||
| "github.com/bazelbuild/bazel-gazelle/label" | ||||||||||||||||||||||||||||||||||||
|
|
@@ -155,7 +156,7 @@ func rel(lbl label.Label, from label.Label) label.Label { | |||||||||||||||||||||||||||||||||||
| // haskell_library are assumed to be local. There rest of the | ||||||||||||||||||||||||||||||||||||
| // dependencies are assumed to come from packageRepo. | ||||||||||||||||||||||||||||||||||||
| func setDepsAndPluginsAttributes( | ||||||||||||||||||||||||||||||||||||
| extraLibraries []label.Label, | ||||||||||||||||||||||||||||||||||||
| extraLibraries []label.Label, | ||||||||||||||||||||||||||||||||||||
| packageRepo string, | ||||||||||||||||||||||||||||||||||||
| ix *resolve.RuleIndex, | ||||||||||||||||||||||||||||||||||||
| r *rule.Rule, | ||||||||||||||||||||||||||||||||||||
|
|
@@ -253,7 +254,7 @@ func getRuleIndexKeys(depName string, from label.Label, cabalPkgName string) []s | |||||||||||||||||||||||||||||||||||
| // colon prefix detected | ||||||||||||||||||||||||||||||||||||
| packagePrefix := splitted[0] | ||||||||||||||||||||||||||||||||||||
| libraryName := splitted[1] | ||||||||||||||||||||||||||||||||||||
| if (packagePrefix == cabalPkgName) { | ||||||||||||||||||||||||||||||||||||
| if packagePrefix == cabalPkgName { | ||||||||||||||||||||||||||||||||||||
| // the package prefix leads to a sub-library of the same package | ||||||||||||||||||||||||||||||||||||
| return []string{ | ||||||||||||||||||||||||||||||||||||
| fmt.Sprintf(format, privatePrefix, packagePrefix, libraryName), | ||||||||||||||||||||||||||||||||||||
|
|
@@ -408,7 +409,51 @@ func mapSortedStringKeys(m map[string]bool) []string { | |||||||||||||||||||||||||||||||||||
| i++ | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| sort.Strings(ss) | ||||||||||||||||||||||||||||||||||||
| return ss | ||||||||||||||||||||||||||||||||||||
| s_result := removeEquivalent(samePackage, ss) | ||||||||||||||||||||||||||||||||||||
| return s_result | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // This function assumes that equivalent elements are bundled and only keeps the last element of each equivalence class. | ||||||||||||||||||||||||||||||||||||
| func removeEquivalent(equiv func(string, string) bool, s []string) []string { | ||||||||||||||||||||||||||||||||||||
| if len(s) < 1 { | ||||||||||||||||||||||||||||||||||||
| return s | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| first_free_position := 1 | ||||||||||||||||||||||||||||||||||||
| for curr := 1; curr < len(s); curr++ { | ||||||||||||||||||||||||||||||||||||
| if equiv(s[first_free_position-1], s[curr]) { | ||||||||||||||||||||||||||||||||||||
| // If the last added element is equivalent is considered one, | ||||||||||||||||||||||||||||||||||||
| // then we move the cursor back so that the currently considered element | ||||||||||||||||||||||||||||||||||||
| // replace the previously added one. | ||||||||||||||||||||||||||||||||||||
| // This function is only keeping the last representative of the equivalence class | ||||||||||||||||||||||||||||||||||||
| // because it is used to deal with packages having or not a version number, | ||||||||||||||||||||||||||||||||||||
| // and in case both option are available, the version number should be kept. | ||||||||||||||||||||||||||||||||||||
| first_free_position-- | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| s[first_free_position] = s[curr] | ||||||||||||||||||||||||||||||||||||
| first_free_position++ | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
| if equiv(s[first_free_position-1], s[curr]) { | |
| // If the last added element is equivalent is considered one, | |
| // then we move the cursor back so that the currently considered element | |
| // replace the previously added one. | |
| // This function is only keeping the last representative of the equivalence class | |
| // because it is used to deal with packages having or not a version number, | |
| // and in case both option are available, the version number should be kept. | |
| first_free_position-- | |
| } | |
| s[first_free_position] = s[curr] | |
| first_free_position++ | |
| if equiv(s[first_free_position-1], s[curr]) { | |
| s[first_free_position-1] = s[curr] | |
| } else { | |
| s[first_free_position] = s[curr] | |
| first_free_position++ | |
| } |
facundominguez marked this conversation as resolved.
Show resolved
Hide resolved
facundominguez marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
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.
There is a low risk of overflow here. Would it be straighter to check that all characters are either digits or dots instead?
Uh oh!
There was an error while loading. Please reload this page.