-
Notifications
You must be signed in to change notification settings - Fork 49
build: prepare bounded parallel compilation #2174
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
Closed
zhouguangyuan0718
wants to merge
1
commit into
xgo-dev:main
from
zhouguangyuan0718:agent/parallel-build-pr0
Closed
Changes from all commits
Commits
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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,52 @@ | ||
| /* | ||
| * Copyright (c) 2026 The XGo Authors (xgo.dev). All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package build | ||
|
|
||
| import ( | ||
| "sort" | ||
|
|
||
| "github.com/goplus/llgo/internal/packages" | ||
| ) | ||
|
|
||
| // effectiveDependencies returns the package graph that contributes code to an | ||
| // aPackage. An alternate package can add imports beyond the original package, | ||
| // so using only Package.Imports would allow stale cache entries after an alt | ||
| // dependency changes. | ||
| func effectiveDependencies(pkg *aPackage) []*packages.Package { | ||
| if pkg == nil || pkg.Package == nil { | ||
| return nil | ||
| } | ||
| deps := make(map[string]*packages.Package) | ||
| add := func(imports map[string]*packages.Package) { | ||
| for _, dep := range imports { | ||
| if dep == nil || dep.ID == pkg.ID || (pkg.AltPkg != nil && dep.ID == pkg.AltPkg.ID) { | ||
| continue | ||
| } | ||
| deps[dep.ID] = dep | ||
| } | ||
| } | ||
| add(pkg.Imports) | ||
| if pkg.AltPkg != nil { | ||
| add(pkg.AltPkg.Imports) | ||
| } | ||
| ret := make([]*packages.Package, 0, len(deps)) | ||
| for _, dep := range deps { | ||
| ret = append(ret, dep) | ||
| } | ||
| sort.Slice(ret, func(i, j int) bool { return ret[i].ID < ret[j].ID }) | ||
| return ret | ||
| } |
This file contains hidden or 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,46 @@ | ||
| /* | ||
| * Copyright (c) 2026 The XGo Authors (xgo.dev). All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package build | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "testing" | ||
|
|
||
| "github.com/goplus/llgo/internal/packages" | ||
| ) | ||
|
|
||
| func TestEffectiveDependenciesIncludesAlternateImports(t *testing.T) { | ||
| base := &packages.Package{ID: "base"} | ||
| shared := &packages.Package{ID: "shared"} | ||
| altOnly := &packages.Package{ID: "alt-only"} | ||
| alt := &packages.Package{ | ||
| ID: "alt", | ||
| Imports: map[string]*packages.Package{"shared": shared, "alt-only": altOnly}, | ||
| } | ||
| pkg := &aPackage{ | ||
| Package: &packages.Package{ID: "pkg", Imports: map[string]*packages.Package{"base": base, "shared": shared}}, | ||
| AltPkg: &packages.Cached{Package: alt}, | ||
| } | ||
| deps := effectiveDependencies(pkg) | ||
| got := make([]string, len(deps)) | ||
| for i, dep := range deps { | ||
| got[i] = dep.ID | ||
| } | ||
| if want := []string{"alt-only", "base", "shared"}; !reflect.DeepEqual(got, want) { | ||
| t.Fatalf("effectiveDependencies = %v, want %v", got, want) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Adding
"p"toargumentListFlagNameshas an asymmetric side effect in flag files.This list is used both by
normalizeBuildFlags(so-p 3→-p=3, whichparseBuildParallelneeds) and bywholeLineValueFlagin this file, which treats the entire remainder of a flags-file line as a single value. That greedy behavior is correct for genuine argument-list flags like-ldflags, but-ptakes a single integer.Consequence: a flags-file line combining
-pwith other flags, e.g.is collapsed into the single token
-p=4 -trimpath.strconv.Atoi("4 -trimpath")then fails with-p must be a positive integer, got "4 -trimpath", and-trimpathis silently swallowed. The equivalent command-line form works becausenormalizeBuildFlagsprocesses each arg independently.Suggestion: allow
-pto be normalized without adding it to the whole-lineargumentListFlagNamesset — e.g. a separate list forwholeLineValueFlag, or special-case-pso it only claims the single following integer. A test covering-pcombined with other flags on one flags-file line would guard this.