Skip to content

Commit 0233891

Browse files
authored
Merge pull request #1437 from goplus/xgopilot/claude/issue-1436-1764823116
Add -a flag to llgo build to force package rebuilds
2 parents e7dd77d + 3bb2657 commit 0233891

5 files changed

Lines changed: 86 additions & 1 deletion

File tree

cmd/internal/base/pass.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func NewPassArgs(flag *flag.FlagSet) *PassArgs {
7272
func PassBuildFlags(cmd *Command) *PassArgs {
7373
p := NewPassArgs(&cmd.Flag)
7474
p.Bool("n", "x")
75-
p.Bool("a")
75+
// Note: "a" flag removed - now handled by flags.AddBuildFlags()
7676
p.Bool("linkshared", "race", "msan", "asan",
7777
"trimpath", "work")
7878
p.Var("p", "asmflags", "compiler",

cmd/internal/flags/flags.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ var ForceEspClang bool
3939
var SizeReport bool
4040
var SizeFormat string
4141
var SizeLevel string
42+
var ForceRebuild bool
4243

4344
func AddCommonFlags(fs *flag.FlagSet) {
4445
fs.BoolVar(&Verbose, "v", false, "Verbose output")
4546
}
4647

4748
func AddBuildFlags(fs *flag.FlagSet) {
49+
fs.BoolVar(&ForceRebuild, "a", false, "Force rebuilding of packages that are already up-to-date")
4850
fs.StringVar(&Tags, "tags", "", "Build tags")
4951
fs.StringVar(&BuildEnv, "buildenv", "", "Build environment")
5052
if buildenv.Dev {
@@ -86,6 +88,7 @@ func UpdateConfig(conf *build.Config) error {
8688
conf.Target = Target
8789
conf.Port = Port
8890
conf.BaudRate = BaudRate
91+
conf.ForceRebuild = ForceRebuild
8992
if SizeReport || SizeFormat != "" || SizeLevel != "" {
9093
conf.SizeReport = true
9194
if SizeFormat != "" {

internal/build/build.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ type Config struct {
132132
CheckLLFiles bool // check .ll files valid
133133
CheckLinkArgs bool // check linkargs valid
134134
ForceEspClang bool // force to use esp-clang
135+
ForceRebuild bool // force rebuilding of packages that are already up-to-date
135136
Tags string
136137
SizeReport bool // print size report after successful build
137138
SizeFormat string // size report format: text,json (default text)

internal/build/collect.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ func (c *context) tryLoadFromCache(pkg *aPackage) bool {
309309
return false
310310
}
311311

312+
// Skip cache when force rebuild is enabled
313+
if c.buildConf.ForceRebuild {
314+
return false
315+
}
316+
312317
if pkg.Fingerprint == "" {
313318
return false
314319
}

internal/build/collect_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,82 @@ func TestTryLoadFromCache_NoFingerprint(t *testing.T) {
378378
}
379379
}
380380

381+
func TestTryLoadFromCache_ForceRebuild(t *testing.T) {
382+
td := t.TempDir()
383+
oldFunc := cacheRootFunc
384+
cacheRootFunc = func() string { return td }
385+
defer func() { cacheRootFunc = oldFunc }()
386+
387+
ctx := &context{
388+
conf: &packages.Config{},
389+
buildConf: &Config{
390+
Goos: "darwin",
391+
Goarch: "arm64",
392+
ForceRebuild: true, // Force rebuild enabled
393+
},
394+
crossCompile: crosscompile.Export{
395+
LLVMTarget: "arm64-apple-darwin",
396+
},
397+
}
398+
399+
// Create a fake cache entry
400+
pkg := &aPackage{
401+
Package: &packages.Package{
402+
PkgPath: "example.com/cached",
403+
Name: "cached",
404+
},
405+
Fingerprint: "test123",
406+
Manifest: func() string {
407+
m := newManifestBuilder()
408+
m.env.Goos = "darwin"
409+
m.pkg.PkgPath = "example.com/cached"
410+
return m.Build()
411+
}(),
412+
}
413+
414+
// Create a temporary .o file
415+
objFile, err := os.CreateTemp(td, "test-*.o")
416+
if err != nil {
417+
t.Fatalf("CreateTemp: %v", err)
418+
}
419+
objFile.WriteString("fake object file")
420+
objFile.Close()
421+
422+
pkg.LLFiles = []string{objFile.Name()}
423+
424+
// First save to cache
425+
ctx.buildConf.ForceRebuild = false
426+
if err := ctx.saveToCache(pkg); err != nil {
427+
t.Fatalf("saveToCache: %v", err)
428+
}
429+
430+
// Verify cache exists
431+
cm := ctx.ensureCacheManager()
432+
paths := cm.PackagePaths("arm64-apple-darwin", "example.com/cached", "test123")
433+
if _, err := os.Stat(paths.Archive); err != nil {
434+
t.Fatalf("cache should exist: %v", err)
435+
}
436+
437+
// Now enable ForceRebuild and try to load
438+
ctx.buildConf.ForceRebuild = true
439+
440+
// Clear LLFiles to verify it's not loaded from cache
441+
pkg.LLFiles = nil
442+
pkg.CacheHit = false
443+
444+
if ctx.tryLoadFromCache(pkg) {
445+
t.Error("should return false when ForceRebuild is enabled, even with valid cache")
446+
}
447+
448+
if pkg.CacheHit {
449+
t.Error("CacheHit should remain false when ForceRebuild is enabled")
450+
}
451+
452+
if len(pkg.LLFiles) > 0 {
453+
t.Error("LLFiles should not be populated when ForceRebuild is enabled")
454+
}
455+
}
456+
381457
func TestSaveToCache_MainPackage(t *testing.T) {
382458
td := t.TempDir()
383459
oldFunc := cacheRootFunc

0 commit comments

Comments
 (0)