From 6648609116e33c5a1b6a7ff09b020622578a75e2 Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Fri, 8 May 2026 17:47:00 -0700 Subject: [PATCH] refactor: upgrade aspect-gazelle, support incremental-build-protocol v3 --- bazel/include/go.MODULE.bazel | 30 +++++++++++++++--------------- cmd/aspect/configure/configure.go | 10 ++++++++-- go.mod | 10 +++++----- go.sum | 20 ++++++++++---------- pkg/aspect/run/ibazel.go | 6 ++++++ pkg/aspect/run/run.go | 28 +++++++++++++++++++--------- 6 files changed, 63 insertions(+), 41 deletions(-) diff --git a/bazel/include/go.MODULE.bazel b/bazel/include/go.MODULE.bazel index 9ca0f60a..cf4c63d9 100644 --- a/bazel/include/go.MODULE.bazel +++ b/bazel/include/go.MODULE.bazel @@ -24,42 +24,42 @@ single_version_override( bazel_dep(name = "aspect_gazelle", version = "0.0.0") archive_override( module_name = "aspect_gazelle", - integrity = "sha256-XZUwwAH0/gyoW90PDDiZUxZaSuQcBQuvEe7PBaL0Eoc=", - strip_prefix = "aspect-gazelle-9c84884007d508c04a4b327cbf9c586a0c9d966c", - urls = ["https://github.com/aspect-build/aspect-gazelle/archive/9c84884007d508c04a4b327cbf9c586a0c9d966c.tar.gz"], + integrity = "sha256-Vi6jAIMt/3AxZsdLl0cTv9sNyYMK+iBK6b0lzDUJhdY=", + strip_prefix = "aspect-gazelle-75d3c1f7ae519e5a0a82e2b57a51280d029ac843", + urls = ["https://github.com/aspect-build/aspect-gazelle/archive/75d3c1f7ae519e5a0a82e2b57a51280d029ac843.tar.gz"], ) bazel_dep(name = "aspect_gazelle_js", version = "0.0.0") archive_override( module_name = "aspect_gazelle_js", - integrity = "sha256-XZUwwAH0/gyoW90PDDiZUxZaSuQcBQuvEe7PBaL0Eoc=", - strip_prefix = "aspect-gazelle-9c84884007d508c04a4b327cbf9c586a0c9d966c/language/js", - urls = ["https://github.com/aspect-build/aspect-gazelle/archive/9c84884007d508c04a4b327cbf9c586a0c9d966c.tar.gz"], + integrity = "sha256-Vi6jAIMt/3AxZsdLl0cTv9sNyYMK+iBK6b0lzDUJhdY=", + strip_prefix = "aspect-gazelle-75d3c1f7ae519e5a0a82e2b57a51280d029ac843/language/js", + urls = ["https://github.com/aspect-build/aspect-gazelle/archive/75d3c1f7ae519e5a0a82e2b57a51280d029ac843.tar.gz"], ) bazel_dep(name = "aspect_gazelle_orion", version = "0.0.0") archive_override( module_name = "aspect_gazelle_orion", - integrity = "sha256-XZUwwAH0/gyoW90PDDiZUxZaSuQcBQuvEe7PBaL0Eoc=", - strip_prefix = "aspect-gazelle-9c84884007d508c04a4b327cbf9c586a0c9d966c/language/orion", - urls = ["https://github.com/aspect-build/aspect-gazelle/archive/9c84884007d508c04a4b327cbf9c586a0c9d966c.tar.gz"], + integrity = "sha256-Vi6jAIMt/3AxZsdLl0cTv9sNyYMK+iBK6b0lzDUJhdY=", + strip_prefix = "aspect-gazelle-75d3c1f7ae519e5a0a82e2b57a51280d029ac843/language/orion", + urls = ["https://github.com/aspect-build/aspect-gazelle/archive/75d3c1f7ae519e5a0a82e2b57a51280d029ac843.tar.gz"], ) bazel_dep(name = "aspect_gazelle_runner", version = "0.0.0") archive_override( module_name = "aspect_gazelle_runner", - integrity = "sha256-XZUwwAH0/gyoW90PDDiZUxZaSuQcBQuvEe7PBaL0Eoc=", - strip_prefix = "aspect-gazelle-9c84884007d508c04a4b327cbf9c586a0c9d966c/runner", - urls = ["https://github.com/aspect-build/aspect-gazelle/archive/9c84884007d508c04a4b327cbf9c586a0c9d966c.tar.gz"], + integrity = "sha256-Vi6jAIMt/3AxZsdLl0cTv9sNyYMK+iBK6b0lzDUJhdY=", + strip_prefix = "aspect-gazelle-75d3c1f7ae519e5a0a82e2b57a51280d029ac843/runner", + urls = ["https://github.com/aspect-build/aspect-gazelle/archive/75d3c1f7ae519e5a0a82e2b57a51280d029ac843.tar.gz"], ) # Not direclty used but must be declared+overriden until aspect_gazelle_runner points to one published to BCR. bazel_dep(name = "aspect_gazelle_kotlin", version = "0.0.0") archive_override( module_name = "aspect_gazelle_kotlin", - integrity = "sha256-XZUwwAH0/gyoW90PDDiZUxZaSuQcBQuvEe7PBaL0Eoc=", - strip_prefix = "aspect-gazelle-9c84884007d508c04a4b327cbf9c586a0c9d966c/language/kotlin", - urls = ["https://github.com/aspect-build/aspect-gazelle/archive/9c84884007d508c04a4b327cbf9c586a0c9d966c.tar.gz"], + integrity = "sha256-Vi6jAIMt/3AxZsdLl0cTv9sNyYMK+iBK6b0lzDUJhdY=", + strip_prefix = "aspect-gazelle-75d3c1f7ae519e5a0a82e2b57a51280d029ac843/language/kotlin", + urls = ["https://github.com/aspect-build/aspect-gazelle/archive/75d3c1f7ae519e5a0a82e2b57a51280d029ac843.tar.gz"], ) # Go modules diff --git a/cmd/aspect/configure/configure.go b/cmd/aspect/configure/configure.go index f06005bd..25cbdebf 100644 --- a/cmd/aspect/configure/configure.go +++ b/cmd/aspect/configure/configure.go @@ -313,8 +313,14 @@ func runConfigureWatch(ctx context.Context, v *runner.GazelleRunner, mode string return fmt.Errorf("failed to enter build state: %w", err) } - if err := abazel.Cycle(ctx, ibp.WatchScope_Sources, changesetToCycle(cs)); err != nil { - return fmt.Errorf("failed to send cycle to incremental protocol: %w", err) + if cs.IsFreshInstance { + if err := abazel.CycleReset(ctx); err != nil { + return fmt.Errorf("failed to send cycle reset to incremental protocol: %w", err) + } + } else { + if err := abazel.Cycle(ctx, ibp.WatchScope_Sources, changesetToCycle(cs)); err != nil { + return fmt.Errorf("failed to send cycle to incremental protocol: %w", err) + } } // Leave the build state and fast forward the subscription clock. diff --git a/go.mod b/go.mod index 399f3098..55abf765 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,9 @@ go 1.26.1 require ( github.com/alphadose/haxmap v1.4.1 - github.com/aspect-build/aspect-gazelle/common v0.0.0-20260504072208-9c84884007d5 - github.com/aspect-build/aspect-gazelle/language/orion v0.0.0-20260504072208-9c84884007d5 - github.com/aspect-build/aspect-gazelle/runner v0.0.0-20260504072208-9c84884007d5 + github.com/aspect-build/aspect-gazelle/common v0.0.0-20260508230703-75d3c1f7ae51 + github.com/aspect-build/aspect-gazelle/language/orion v0.0.0-20260508230703-75d3c1f7ae51 + github.com/aspect-build/aspect-gazelle/runner v0.0.0-20260508230703-75d3c1f7ae51 github.com/bazelbuild/bazel-gazelle v0.50.0 github.com/bazelbuild/bazelisk v1.27.0 // NOTE: keep vendored code in sync github.com/bazelbuild/buildtools v0.0.0-20260319080235-05d2ebe49b0f @@ -62,8 +62,8 @@ require ( github.com/alecthomas/chroma/v2 v2.23.1 // indirect github.com/alecthomas/participle/v2 v2.1.4 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect - github.com/aspect-build/aspect-gazelle/language/js v0.0.0-20260504072208-9c84884007d5 // indirect - github.com/aspect-build/aspect-gazelle/language/kotlin v0.0.0-20260504072208-9c84884007d5 // indirect + github.com/aspect-build/aspect-gazelle/language/js v0.0.0-20260508230703-75d3c1f7ae51 // indirect + github.com/aspect-build/aspect-gazelle/language/kotlin v0.0.0-20260508230703-75d3c1f7ae51 // indirect github.com/atotto/clipboard v0.1.4 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymerick/douceur v0.2.0 // indirect diff --git a/go.sum b/go.sum index f7ff60a9..68f0ba71 100644 --- a/go.sum +++ b/go.sum @@ -31,16 +31,16 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/aspect-build/aspect-gazelle/common v0.0.0-20260504072208-9c84884007d5 h1:njHRmzoTLbaMhuMP46B2hZxGGWypwdnKp/1B76tVBks= -github.com/aspect-build/aspect-gazelle/common v0.0.0-20260504072208-9c84884007d5/go.mod h1:YYCHODCLeqDOEgXNvFKhKRwwprkXiaiCLceotY/ohHE= -github.com/aspect-build/aspect-gazelle/language/js v0.0.0-20260504072208-9c84884007d5 h1:kbwv97gOLoPN3nbYlkp/gHplKttrHBABtERTR3ya4nw= -github.com/aspect-build/aspect-gazelle/language/js v0.0.0-20260504072208-9c84884007d5/go.mod h1:mfeY2D7N0R0Od12id9hDnjPrR0Z2RXZN0JwTo7wNp/I= -github.com/aspect-build/aspect-gazelle/language/kotlin v0.0.0-20260504072208-9c84884007d5 h1:1v5EsA5OdV5eSrkObKCXtsbrQfJzpfObkHm4NgE3U5M= -github.com/aspect-build/aspect-gazelle/language/kotlin v0.0.0-20260504072208-9c84884007d5/go.mod h1:6YdjU23ZHWJEki9K3X+7agym4rf6BQ6Kes4a5MzfcgM= -github.com/aspect-build/aspect-gazelle/language/orion v0.0.0-20260504072208-9c84884007d5 h1:o00OB32hiquD2DfBjKGt21SmkL+gVxCpWllHF+g1XQk= -github.com/aspect-build/aspect-gazelle/language/orion v0.0.0-20260504072208-9c84884007d5/go.mod h1:2BMCnAh1+8C/LlOFsO/hR32xZtBLey3QDQ9a6DP5D7c= -github.com/aspect-build/aspect-gazelle/runner v0.0.0-20260504072208-9c84884007d5 h1:lbxAF24IfmqKvIOt6BPVFvc52EdTQ7T4MCe5bsG4paQ= -github.com/aspect-build/aspect-gazelle/runner v0.0.0-20260504072208-9c84884007d5/go.mod h1:s+yb0ysyhmYsEX02/Ao+ENhaDXEkzCfOg9iENGMWFfY= +github.com/aspect-build/aspect-gazelle/common v0.0.0-20260508230703-75d3c1f7ae51 h1:M5Ha1P7eYomjRxFDtxCF+La0M358JhHkHCSrVUvgs48= +github.com/aspect-build/aspect-gazelle/common v0.0.0-20260508230703-75d3c1f7ae51/go.mod h1:YYCHODCLeqDOEgXNvFKhKRwwprkXiaiCLceotY/ohHE= +github.com/aspect-build/aspect-gazelle/language/js v0.0.0-20260508230703-75d3c1f7ae51 h1:sv4tWtKyHoIPD2su7jwFO2RoTdPQlMn/UHzrmkH/vWo= +github.com/aspect-build/aspect-gazelle/language/js v0.0.0-20260508230703-75d3c1f7ae51/go.mod h1:mfeY2D7N0R0Od12id9hDnjPrR0Z2RXZN0JwTo7wNp/I= +github.com/aspect-build/aspect-gazelle/language/kotlin v0.0.0-20260508230703-75d3c1f7ae51 h1:gI5z4krmNi+Qp6YEZvIccD4fG9FJGxGBFJN1U6k7ACQ= +github.com/aspect-build/aspect-gazelle/language/kotlin v0.0.0-20260508230703-75d3c1f7ae51/go.mod h1:6YdjU23ZHWJEki9K3X+7agym4rf6BQ6Kes4a5MzfcgM= +github.com/aspect-build/aspect-gazelle/language/orion v0.0.0-20260508230703-75d3c1f7ae51 h1:QzCyALq8ESD8ifCAvXzZxXv6nmQn9zyXkyivEaua+PQ= +github.com/aspect-build/aspect-gazelle/language/orion v0.0.0-20260508230703-75d3c1f7ae51/go.mod h1:2BMCnAh1+8C/LlOFsO/hR32xZtBLey3QDQ9a6DP5D7c= +github.com/aspect-build/aspect-gazelle/runner v0.0.0-20260508230703-75d3c1f7ae51 h1:QpRpwJw3YtgcmH/i0WY3jC0YlV3UPrXctoEK81Ydu8E= +github.com/aspect-build/aspect-gazelle/runner v0.0.0-20260508230703-75d3c1f7ae51/go.mod h1:s+yb0ysyhmYsEX02/Ao+ENhaDXEkzCfOg9iENGMWFfY= github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= diff --git a/pkg/aspect/run/ibazel.go b/pkg/aspect/run/ibazel.go index b9c8b1cc..3e184225 100644 --- a/pkg/aspect/run/ibazel.go +++ b/pkg/aspect/run/ibazel.go @@ -59,6 +59,9 @@ func (ib *IBazelProtocol) Cycle(ctx context.Context, scope ibp.WatchScope, chang return res } +func (ib *IBazelProtocol) CycleReset(ctx context.Context) error { + return ib.Cycle(ctx, ibp.WatchScope_Runfiles, nil) +} func (ib *IBazelProtocol) Close() error { return nil } @@ -174,6 +177,9 @@ func (rb *RestartBazelProtocol) Cycle(ctx context.Context, scope ibp.WatchScope, return nil } +func (rb *RestartBazelProtocol) CycleReset(ctx context.Context) error { + return rb.Cycle(ctx, ibp.WatchScope_Runfiles, nil) +} func (rb *RestartBazelProtocol) Close() error { return nil } diff --git a/pkg/aspect/run/run.go b/pkg/aspect/run/run.go index 6a96d0a5..1bc9acd8 100644 --- a/pkg/aspect/run/run.go +++ b/pkg/aspect/run/run.go @@ -515,6 +515,7 @@ func (runner *Run) runWatch(ctx context.Context, bazelCmd []string, bzlCommandSt var ( cycleScope ibp.WatchScope cycleChanges ibp.SourceInfoMap + cycleIsReset bool ) if incBuildErr != nil { @@ -525,19 +526,15 @@ func (runner *Run) runWatch(ctx context.Context, bazelCmd []string, bzlCommandSt } else { // Drain accumulated changes every cycle to keep the // detector's internal map bounded; the result may be - // ignored (fresh-instance, source mode) when constructing + // ignored (source mode + fresh-instance) when constructing // the IBP message. changes := changedetect.cycleChanges() switch { - case cs.IsFreshInstance: - // IBP peer gets a reset (nil sources) instead of `changes`. - if watchRunfilesChanges { - cycleScope = ibp.WatchScope_Runfiles - } else if watchSourceChanges { - cycleScope = ibp.WatchScope_Sources - } case watchRunfilesChanges && len(changes) > 0: + // Runfiles deltas are reconciled from the runfiles manifest and + // execlog, so they're trustworthy even after a watchman fresh-instance + // where cs.Paths is empty. logger.Infof("Cycle changes: %v", changes) // For now just rerun the target, beware that RunCommand does not yield until @@ -547,6 +544,11 @@ func (runner *Run) runWatch(ctx context.Context, bazelCmd []string, bzlCommandSt cycleScope = ibp.WatchScope_Runfiles cycleChanges = changes // TODO: if we want to support ibazel livereload then we need to report changes. + case watchSourceChanges && cs.IsFreshInstance: + // Source-mode cycles are keyed by cs.Paths, which is unreliable on a + // fresh-instance and has no manifest-based reconciliation; signal a + // full peer reset. + cycleIsReset = true case watchSourceChanges: logger.Infof("Cycle source changes: %v", cs.Paths) @@ -562,7 +564,15 @@ func (runner *Run) runWatch(ctx context.Context, bazelCmd []string, bzlCommandSt } } - if cycleScope != "" { + if cycleIsReset { + ctctx, cycleTrace := runner.tracer.Start(tctx, "Run.Cycle") + defer cycleTrace.End() + + if err := incrementalProtocol.CycleReset(ctctx); err != nil { + cycleTrace.SetStatus(codes.Error, err.Error()) + return fmt.Errorf("failed to report cycle reset: %w", err) + } + } else if cycleScope != "" { ctctx, cycleTrace := runner.tracer.Start(tctx, "Run.Cycle") defer cycleTrace.End()