Skip to content

Commit

Permalink
package_managers: gomod: Add support for vendored workspaces
Browse files Browse the repository at this point in the history
Introduced by Go 1.22 and controlled via 'go mod vendor'. We already
can work with plain module vendoring, so this is just a minor change
for us where based on detecting whether workspaces are in use along with
vendoring we just switch the command from 'go mod vendor' to 'go work
vendor'.

Signed-off-by: Erik Skultety <[email protected]>
  • Loading branch information
eskultety committed Jun 7, 2024
1 parent b8d222e commit b361dd9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cachi2/core/package_managers/gomod.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,9 @@ def _resolve_gomod(
flags, app_dir, config.gomod_strict_vendor
)
if should_vendor:
downloaded_modules = _vendor_deps(go, app_dir, can_make_changes, run_params)
downloaded_modules = _vendor_deps(
go, app_dir, bool(go_work_path), can_make_changes, run_params
)
else:
log.info("Downloading the gomod dependencies")
downloaded_modules = (
Expand Down Expand Up @@ -1506,6 +1508,7 @@ def parse_module_line(line: str) -> ParsedModule:
def _vendor_deps(
go: Go,
app_dir: RootedPath,
has_workspaces: bool,
can_make_changes: bool,
run_params: dict[str, Any],
) -> Iterable[ParsedModule]:
Expand All @@ -1523,7 +1526,9 @@ def _vendor_deps(
:raise UnexpectedFormat: if Cachi2 fails to parse vendor/modules.txt
"""
log.info("Vendoring the gomod dependencies")
go(["mod", "vendor"], run_params)

cmdscope = "mod" if not has_workspaces else "work"
go([cmdscope, "vendor"], run_params)
if not can_make_changes and _vendor_changed(app_dir):
raise PackageRejected(
reason=(
Expand Down

0 comments on commit b361dd9

Please sign in to comment.