From 944f2d4ebe16eba885827ea0060a33dee72bc2dd Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Tue, 30 Jan 2024 17:25:32 -0700 Subject: [PATCH] fix: resolve local package paths relative to the repository root (#881) - Update `resources_example` moving the `Package.swift` under a sub-directory. - Resolve local Swift packages using the repository root directory. Closes #869. --- examples/resources_example/BUILD.bazel | 1 + examples/resources_example/MODULE.bazel.lock | 377 +++++++++++------- .../{ => swift}/Package.resolved | 0 .../{ => swift}/Package.swift | 6 +- gazelle/internal/swift/bzlmod.go | 5 +- gazelle/internal/swift/bzlmod_test.go | 4 +- gazelle/internal/swift/package.go | 3 +- gazelle/internal/swift/package_test.go | 7 +- gazelle/update_repos.go | 8 +- 9 files changed, 261 insertions(+), 150 deletions(-) rename examples/resources_example/{ => swift}/Package.resolved (100%) rename examples/resources_example/{ => swift}/Package.swift (61%) diff --git a/examples/resources_example/BUILD.bazel b/examples/resources_example/BUILD.bazel index 408299d43..4f4258a0f 100644 --- a/examples/resources_example/BUILD.bazel +++ b/examples/resources_example/BUILD.bazel @@ -32,5 +32,6 @@ swift_update_packages( name = "swift_update_pkgs", gazelle = ":gazelle_bin", generate_swift_deps_for_workspace = False, + package_manifest = "swift/Package.swift", update_bzlmod_stanzas = True, ) diff --git a/examples/resources_example/MODULE.bazel.lock b/examples/resources_example/MODULE.bazel.lock index fedab9502..396270afe 100644 --- a/examples/resources_example/MODULE.bazel.lock +++ b/examples/resources_example/MODULE.bazel.lock @@ -1,6 +1,6 @@ { "lockFileVersion": 3, - "moduleFileHash": "1b489574fdfd2dbbb67bebe9dc76c1ee002e1b0d2cc0723b39b03c943d261f63", + "moduleFileHash": "8eac54fb1e06f43d170844678240d92b9083ba2c7e90d5fc2032acc549992d4b", "flags": { "cmdRegistries": [ "https://bcr.bazel.build/" @@ -82,8 +82,8 @@ "cgrindel_bazel_starlib": "cgrindel_bazel_starlib@0.19.0", "bazel_skylib": "bazel_skylib@1.5.0", "apple_support": "apple_support@1.11.1", - "build_bazel_rules_swift": "rules_swift@1.13.0", - "build_bazel_rules_apple": "rules_apple@3.1.1", + "build_bazel_rules_swift": "rules_swift@1.15.1", + "build_bazel_rules_apple": "rules_apple@3.2.1", "bazel_skylib_gazelle_plugin": "bazel_skylib_gazelle_plugin@1.5.0", "bazel_gazelle": "gazelle@0.35.0", "bazel_tools": "bazel_tools@_", @@ -159,8 +159,8 @@ "apple_support": "apple_support@1.11.1", "rules_cc": "rules_cc@0.0.9", "platforms": "platforms@0.0.7", - "build_bazel_rules_swift": "rules_swift@1.13.0", - "build_bazel_rules_apple": "rules_apple@3.1.1", + "build_bazel_rules_swift": "rules_swift@1.15.1", + "build_bazel_rules_apple": "rules_apple@3.2.1", "bazel_gazelle": "gazelle@0.35.0", "bazel_tools": "bazel_tools@_", "local_config_platform": "local_config_platform@_" @@ -318,10 +318,10 @@ } } }, - "rules_swift@1.13.0": { + "rules_swift@1.15.1": { "name": "rules_swift", - "version": "1.13.0", - "key": "rules_swift@1.13.0", + "version": "1.15.1", + "key": "rules_swift@1.15.1", "repoName": "build_bazel_rules_swift", "executionPlatformsToRegister": [], "toolchainsToRegister": [], @@ -329,10 +329,10 @@ { "extensionBzlFile": "@build_bazel_rules_swift//swift:extensions.bzl", "extensionName": "non_module_deps", - "usingModule": "rules_swift@1.13.0", + "usingModule": "rules_swift@1.15.1", "location": { - "file": "https://bcr.bazel.build/modules/rules_swift/1.13.0/MODULE.bazel", - "line": 17, + "file": "https://bcr.bazel.build/modules/rules_swift/1.15.1/MODULE.bazel", + "line": 18, "column": 32 }, "imports": { @@ -354,10 +354,10 @@ { "extensionBzlFile": "@build_bazel_apple_support//crosstool:setup.bzl", "extensionName": "apple_cc_configure_extension", - "usingModule": "rules_swift@1.13.0", + "usingModule": "rules_swift@1.15.1", "location": { - "file": "https://bcr.bazel.build/modules/rules_swift/1.13.0/MODULE.bazel", - "line": 31, + "file": "https://bcr.bazel.build/modules/rules_swift/1.15.1/MODULE.bazel", + "line": 32, "column": 35 }, "imports": { @@ -370,6 +370,7 @@ } ], "deps": { + "bazel_features": "bazel_features@1.3.0", "bazel_skylib": "bazel_skylib@1.5.0", "build_bazel_apple_support": "apple_support@1.11.1", "rules_cc": "rules_cc@0.0.9", @@ -384,23 +385,23 @@ "bzlFile": "@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "rules_swift~1.13.0", + "name": "rules_swift~1.15.1", "urls": [ - "https://github.com/bazelbuild/rules_swift/releases/download/1.13.0/rules_swift.1.13.0.tar.gz" + "https://github.com/bazelbuild/rules_swift/releases/download/1.15.1/rules_swift.1.15.1.tar.gz" ], - "integrity": "sha256-KKZv9dl1APAwT06JRdk2/gWE4NW3pvgyWCmAB6kxkLo=", + "integrity": "sha256-4u7kY4OUg9/hsFzkBqTy+z/XSN3KoxHMh2j6fwQa8P8=", "strip_prefix": "", "remote_patches": { - "https://bcr.bazel.build/modules/rules_swift/1.13.0/patches/module_dot_bazel_version.patch": "sha256-B7W790qbiTQ3xI7qGr8iEjm56OTd2VPlZ9XVrgrhr4U=" + "https://bcr.bazel.build/modules/rules_swift/1.15.1/patches/module_dot_bazel_version.patch": "sha256-rMxzgZs1JKbQr3jJYCgiTGhj7zN0SOZurnW50gFgONA=" }, "remote_patch_strip": 1 } } }, - "rules_apple@3.1.1": { + "rules_apple@3.2.1": { "name": "rules_apple", - "version": "3.1.1", - "key": "rules_apple@3.1.1", + "version": "3.2.1", + "key": "rules_apple@3.2.1", "repoName": "build_bazel_rules_apple", "executionPlatformsToRegister": [], "toolchainsToRegister": [], @@ -408,9 +409,9 @@ { "extensionBzlFile": "@build_bazel_rules_apple//apple:extensions.bzl", "extensionName": "non_module_deps", - "usingModule": "rules_apple@3.1.1", + "usingModule": "rules_apple@3.2.1", "location": { - "file": "https://bcr.bazel.build/modules/rules_apple/3.1.1/MODULE.bazel", + "file": "https://bcr.bazel.build/modules/rules_apple/3.2.1/MODULE.bazel", "line": 21, "column": 32 }, @@ -425,9 +426,9 @@ { "extensionBzlFile": "@build_bazel_rules_apple//apple:apple.bzl", "extensionName": "provisioning_profile_repository_extension", - "usingModule": "rules_apple@3.1.1", + "usingModule": "rules_apple@3.2.1", "location": { - "file": "https://bcr.bazel.build/modules/rules_apple/3.1.1/MODULE.bazel", + "file": "https://bcr.bazel.build/modules/rules_apple/3.2.1/MODULE.bazel", "line": 27, "column": 48 }, @@ -442,9 +443,9 @@ { "extensionBzlFile": "@build_bazel_apple_support//crosstool:setup.bzl", "extensionName": "apple_cc_configure_extension", - "usingModule": "rules_apple@3.1.1", + "usingModule": "rules_apple@3.2.1", "location": { - "file": "https://bcr.bazel.build/modules/rules_apple/3.1.1/MODULE.bazel", + "file": "https://bcr.bazel.build/modules/rules_apple/3.2.1/MODULE.bazel", "line": 30, "column": 35 }, @@ -461,7 +462,7 @@ "build_bazel_apple_support": "apple_support@1.11.1", "bazel_skylib": "bazel_skylib@1.5.0", "platforms": "platforms@0.0.7", - "build_bazel_rules_swift": "rules_swift@1.13.0", + "build_bazel_rules_swift": "rules_swift@1.15.1", "bazel_tools": "bazel_tools@_", "local_config_platform": "local_config_platform@_" }, @@ -469,14 +470,14 @@ "bzlFile": "@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "rules_apple~3.1.1", + "name": "rules_apple~3.2.1", "urls": [ - "https://github.com/bazelbuild/rules_apple/releases/download/3.1.1/rules_apple.3.1.1.tar.gz" + "https://github.com/bazelbuild/rules_apple/releases/download/3.2.1/rules_apple.3.2.1.tar.gz" ], - "integrity": "sha256-NMQb+1nNrqKawt9aL6eeWt1gnHG7MDsuuxCYX5P6IOc=", + "integrity": "sha256-nE8eHsT9/qxb3bB/oOhyw5jj2OsKxZavnEY/kSOs4pI=", "strip_prefix": "", "remote_patches": { - "https://bcr.bazel.build/modules/rules_apple/3.1.1/patches/module_dot_bazel_version.patch": "sha256-KVsXlg8A0DKwRqg2JhtnBnv2NS2imHagLkDBQruoIGg=" + "https://bcr.bazel.build/modules/rules_apple/3.2.1/patches/module_dot_bazel_version.patch": "sha256-E83S37YdLiwd8kt/f1lbRRPyy6vbbxGogIqLulx9Lh0=" }, "remote_patch_strip": 1 } @@ -897,7 +898,7 @@ } ], "deps": { - "bazel_features": "bazel_features@1.1.1", + "bazel_features": "bazel_features@1.3.0", "bazel_skylib": "bazel_skylib@1.5.0", "platforms": "platforms@0.0.7", "rules_proto": "rules_proto@5.3.0-21.7", @@ -1078,6 +1079,54 @@ } } }, + "bazel_features@1.3.0": { + "name": "bazel_features", + "version": "1.3.0", + "key": "bazel_features@1.3.0", + "repoName": "bazel_features", + "executionPlatformsToRegister": [], + "toolchainsToRegister": [], + "extensionUsages": [ + { + "extensionBzlFile": "@bazel_features//private:extensions.bzl", + "extensionName": "version_extension", + "usingModule": "bazel_features@1.3.0", + "location": { + "file": "https://bcr.bazel.build/modules/bazel_features/1.3.0/MODULE.bazel", + "line": 6, + "column": 24 + }, + "imports": { + "bazel_features_globals": "bazel_features_globals", + "bazel_features_version": "bazel_features_version" + }, + "devImports": [], + "tags": [], + "hasDevUseExtension": false, + "hasNonDevUseExtension": true + } + ], + "deps": { + "bazel_tools": "bazel_tools@_", + "local_config_platform": "local_config_platform@_" + }, + "repoSpec": { + "bzlFile": "@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "name": "bazel_features~1.3.0", + "urls": [ + "https://github.com/bazel-contrib/bazel_features/releases/download/v1.3.0/bazel_features-v1.3.0.tar.gz" + ], + "integrity": "sha256-UxgqaPFyoq9K03BR+CIB4iK8GfekCCW4d9o/9MkiueA=", + "strip_prefix": "bazel_features-1.3.0", + "remote_patches": { + "https://bcr.bazel.build/modules/bazel_features/1.3.0/patches/module_dot_bazel_version.patch": "sha256-X7l0sL8EiVC1HcPyMCLA+y1hPqEIRRRP8S/Eh6YuRI4=" + }, + "remote_patch_strip": 1 + } + } + }, "protobuf@21.7": { "name": "protobuf", "version": "21.7", @@ -1440,54 +1489,6 @@ } } }, - "bazel_features@1.1.1": { - "name": "bazel_features", - "version": "1.1.1", - "key": "bazel_features@1.1.1", - "repoName": "bazel_features", - "executionPlatformsToRegister": [], - "toolchainsToRegister": [], - "extensionUsages": [ - { - "extensionBzlFile": "@bazel_features//private:extensions.bzl", - "extensionName": "version_extension", - "usingModule": "bazel_features@1.1.1", - "location": { - "file": "https://bcr.bazel.build/modules/bazel_features/1.1.1/MODULE.bazel", - "line": 6, - "column": 24 - }, - "imports": { - "bazel_features_globals": "bazel_features_globals", - "bazel_features_version": "bazel_features_version" - }, - "devImports": [], - "tags": [], - "hasDevUseExtension": false, - "hasNonDevUseExtension": true - } - ], - "deps": { - "bazel_tools": "bazel_tools@_", - "local_config_platform": "local_config_platform@_" - }, - "repoSpec": { - "bzlFile": "@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_archive", - "attributes": { - "name": "bazel_features~1.1.1", - "urls": [ - "https://github.com/bazel-contrib/bazel_features/releases/download/v1.1.1/bazel_features-v1.1.1.tar.gz" - ], - "integrity": "sha256-YsJuQn5cvHUQJERpJ2IuOYqdzfMsZDJSOIFXCdEcEag=", - "strip_prefix": "bazel_features-1.1.1", - "remote_patches": { - "https://bcr.bazel.build/modules/bazel_features/1.1.1/patches/module_dot_bazel_version.patch": "sha256-+56MAEsc7bYN/Pzhn252ZQUxiRzZg9bynXj1qpsmCYs=" - }, - "remote_patch_strip": 1 - } - } - }, "rules_pkg@0.7.0": { "name": "rules_pkg", "version": "0.7.0", @@ -1724,27 +1725,34 @@ "name": "apple_support~1.11.1~apple_cc_configure_extension~local_config_apple_cc_toolchains" } } - } + }, + "recordedRepoMappingEntries": [ + [ + "apple_support~1.11.1", + "bazel_tools", + "bazel_tools" + ] + ] } }, - "@@bazel_features~1.1.1//private:extensions.bzl%version_extension": { + "@@bazel_features~1.3.0//private:extensions.bzl%version_extension": { "general": { "bzlTransitiveDigest": "xm7Skm1Las5saxzFWt2hbS+e68BWi+MXyt6+lKIhjPA=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { "bazel_features_version": { - "bzlFile": "@@bazel_features~1.1.1//private:version_repo.bzl", + "bzlFile": "@@bazel_features~1.3.0//private:version_repo.bzl", "ruleClassName": "version_repo", "attributes": { - "name": "bazel_features~1.1.1~version_extension~bazel_features_version" + "name": "bazel_features~1.3.0~version_extension~bazel_features_version" } }, "bazel_features_globals": { - "bzlFile": "@@bazel_features~1.1.1//private:globals_repo.bzl", + "bzlFile": "@@bazel_features~1.3.0//private:globals_repo.bzl", "ruleClassName": "globals_repo", "attributes": { - "name": "bazel_features~1.1.1~version_extension~bazel_features_globals", + "name": "bazel_features~1.3.0~version_extension~bazel_features_globals", "globals": { "RunEnvironmentInfo": "5.3.0", "DefaultInfo": "0.0.1", @@ -1752,12 +1760,13 @@ } } } - } + }, + "recordedRepoMappingEntries": [] } }, "@@bazel_tools//tools/cpp:cc_configure.bzl%cc_configure_extension": { "general": { - "bzlTransitiveDigest": "O9sf6ilKWU9Veed02jG9o2HM/xgV/UAyciuFBuxrFRY=", + "bzlTransitiveDigest": "mcsWHq3xORJexV5/4eCvNOLxFOQKV6eli3fkr+tEaqE=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -1775,7 +1784,14 @@ "name": "bazel_tools~cc_configure_extension~local_config_cc_toolchains" } } - } + }, + "recordedRepoMappingEntries": [ + [ + "bazel_tools", + "bazel_tools", + "bazel_tools" + ] + ] } }, "@@bazel_tools//tools/osx:xcode_configure.bzl%xcode_configure_extension": { @@ -1793,7 +1809,8 @@ "remote_xcode": "" } } - } + }, + "recordedRepoMappingEntries": [] } }, "@@bazel_tools//tools/sh:sh_configure.bzl%sh_configure_extension": { @@ -1809,12 +1826,13 @@ "name": "bazel_tools~sh_configure_extension~local_config_sh" } } - } + }, + "recordedRepoMappingEntries": [] } }, "@@buildifier_prebuilt~6.0.0.1//:defs.bzl%buildifier_prebuilt_deps_extension": { "general": { - "bzlTransitiveDigest": "rw0w83IFOd+utieoxefELpxmQT7CxmI9Bd1pKxwbgZE=", + "bzlTransitiveDigest": "e/ywZz1v92DyiMnlC9hasz8Co0tsLhzEkfjuKBqw0WY=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -1930,7 +1948,19 @@ "sha256": "9ffa62ea1f55f420c36eeef1427f71a34a5d24332cb861753b2b59c66d6343e2" } } - } + }, + "recordedRepoMappingEntries": [ + [ + "buildifier_prebuilt~6.0.0.1", + "bazel_skylib", + "bazel_skylib~1.5.0" + ], + [ + "buildifier_prebuilt~6.0.0.1", + "bazel_tools", + "bazel_tools" + ] + ] } }, "@@gazelle~0.35.0//:extensions.bzl%go_deps": { @@ -2436,7 +2466,8 @@ "explicitRootModuleDirectDeps": [], "explicitRootModuleDirectDevDeps": [], "useAllRepos": "NO" - } + }, + "recordedRepoMappingEntries": [] } }, "@@gazelle~0.35.0//internal/bzlmod:non_module_deps.bzl%non_module_deps": { @@ -2470,12 +2501,13 @@ "go_env": {} } } - } + }, + "recordedRepoMappingEntries": [] } }, - "@@rules_apple~3.1.1//apple:extensions.bzl%non_module_deps": { + "@@rules_apple~3.2.1//apple:extensions.bzl%non_module_deps": { "general": { - "bzlTransitiveDigest": "qtprNaNQs1t4snJ9OPZii/Sk3Rw9CZ96CeXalzhUxZE=", + "bzlTransitiveDigest": "N8kVRd5FAdvXx7eSi2BgbUpsnUMZewaoOmBsW+UsKmw=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -2483,7 +2515,7 @@ "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "rules_apple~3.1.1~non_module_deps~xctestrunner", + "name": "rules_apple~3.2.1~non_module_deps~xctestrunner", "urls": [ "https://github.com/google/xctestrunner/archive/b7698df3d435b6491b4b4c0f9fc7a63fbed5e3a6.tar.gz" ], @@ -2491,12 +2523,19 @@ "sha256": "ae3a063c985a8633cb7eb566db21656f8db8eb9a0edb8c182312c7f0db53730d" } } - } + }, + "recordedRepoMappingEntries": [ + [ + "rules_apple~3.2.1", + "bazel_tools", + "bazel_tools" + ] + ] } }, "@@rules_go~0.44.0//go:extensions.bzl%go_sdk": { "os:osx,arch:x86_64": { - "bzlTransitiveDigest": "HOJ7KCV+gzdiDP50kTBrioqp+Vdoj42MzmZF65s69fg=", + "bzlTransitiveDigest": "GI6yMOM2hDU7hVAHmfnV90TgIqJguaDlemn2az5C07E=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -2663,12 +2702,39 @@ "version": "1.21.1" } } - } + }, + "recordedRepoMappingEntries": [ + [ + "bazel_features~1.3.0", + "bazel_features_globals", + "bazel_features~1.3.0~version_extension~bazel_features_globals" + ], + [ + "bazel_features~1.3.0", + "bazel_features_version", + "bazel_features~1.3.0~version_extension~bazel_features_version" + ], + [ + "rules_go~0.44.0", + "bazel_features", + "bazel_features~1.3.0" + ], + [ + "rules_go~0.44.0", + "bazel_tools", + "bazel_tools" + ], + [ + "rules_go~0.44.0", + "io_bazel_rules_go", + "rules_go~0.44.0" + ] + ] } }, "@@rules_java~7.1.0//java:extensions.bzl%toolchains": { "general": { - "bzlTransitiveDigest": "iUIRqCK7tkhvcDJCAfPPqSd06IHG0a8HQD0xeQyVAqw=", + "bzlTransitiveDigest": "D02GmifxnV/IhYgspsJMDZ/aE8HxAjXgek5gi6FSto4=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -3203,14 +3269,26 @@ "build_file": "\nconfig_setting(\n name = \"prefix_version_setting\",\n values = {\"java_runtime_version\": \"remotejdk_21\"},\n visibility = [\"//visibility:private\"],\n)\nconfig_setting(\n name = \"version_setting\",\n values = {\"java_runtime_version\": \"21\"},\n visibility = [\"//visibility:private\"],\n)\nalias(\n name = \"version_or_prefix_version_setting\",\n actual = select({\n \":version_setting\": \":version_setting\",\n \"//conditions:default\": \":prefix_version_setting\",\n }),\n visibility = [\"//visibility:private\"],\n)\ntoolchain(\n name = \"toolchain\",\n target_compatible_with = [\"@platforms//os:windows\", \"@platforms//cpu:x86_64\"],\n target_settings = [\":version_or_prefix_version_setting\"],\n toolchain_type = \"@bazel_tools//tools/jdk:runtime_toolchain_type\",\n toolchain = \"@remotejdk21_win//:jdk\",\n)\ntoolchain(\n name = \"bootstrap_runtime_toolchain\",\n # These constraints are not required for correctness, but prevent fetches of remote JDK for\n # different architectures. As every Java compilation toolchain depends on a bootstrap runtime in\n # the same configuration, this constraint will not result in toolchain resolution failures.\n exec_compatible_with = [\"@platforms//os:windows\", \"@platforms//cpu:x86_64\"],\n target_settings = [\":version_or_prefix_version_setting\"],\n toolchain_type = \"@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type\",\n toolchain = \"@remotejdk21_win//:jdk\",\n)\n" } } - } + }, + "recordedRepoMappingEntries": [ + [ + "rules_java~7.1.0", + "bazel_tools", + "bazel_tools" + ], + [ + "rules_java~7.1.0", + "remote_java_tools", + "rules_java~7.1.0~toolchains~remote_java_tools" + ] + ] } }, "@@rules_swift_package_manager~override//:extensions.bzl%swift_deps": { "general": { - "bzlTransitiveDigest": "Vm4X7iDGbtDxE8+1O6z+gzJQOsRyKvrfkO2LFiU6K30=", + "bzlTransitiveDigest": "RAXmIOdYeEgAIU2uKKJFxO3Uqo7xvnGxHmOD276y14c=", "accumulatedFileDigests": { - "@@//:swift_deps_index.json": "80db817f01480a09af48e2fed9a70284ebdff86384494d5390bb07538d42e680" + "@@//:swift_deps_index.json": "3be7742c44abf40672933dc1220e8ada77e4cf88cd3117e01fa449d128cec021" }, "envVariables": {}, "generatedRepoSpecs": { @@ -3230,7 +3308,7 @@ "attributes": { "name": "rules_swift_package_manager~override~swift_deps~swiftpkg_sdwebimageswiftui", "bazel_package_name": "swiftpkg_sdwebimageswiftui", - "commit": "aee64ef39b570c44ccf0f884c440fc6494a23c76", + "commit": "261b6cec35686d2dc192b809ab50742b4502a73b", "remote": "https://github.com/SDWebImage/SDWebImageSwiftUI.git", "dependencies_index": "@@//:swift_deps_index.json", "init_submodules": false, @@ -3364,12 +3442,29 @@ "dependencies_index": "@@//:swift_deps_index.json" } } - } + }, + "recordedRepoMappingEntries": [ + [ + "rules_swift_package_manager~override", + "bazel_skylib", + "bazel_skylib~1.5.0" + ], + [ + "rules_swift_package_manager~override", + "bazel_tools", + "bazel_tools" + ], + [ + "rules_swift_package_manager~override", + "cgrindel_bazel_starlib", + "cgrindel_bazel_starlib~0.19.0" + ] + ] } }, - "@@rules_swift~1.13.0//swift:extensions.bzl%non_module_deps": { + "@@rules_swift~1.15.1//swift:extensions.bzl%non_module_deps": { "general": { - "bzlTransitiveDigest": "3sh3cKY22C10PM2p2txmWVMqDfTn01dNChD4902k5jA=", + "bzlTransitiveDigest": "JXT9csgB0VHkXU94H+OROIY4q5dpOW0Di+C2YoFqVTM=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -3377,99 +3472,99 @@ "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "rules_swift~1.13.0~non_module_deps~com_github_grpc_grpc_swift", + "name": "rules_swift~1.15.1~non_module_deps~com_github_grpc_grpc_swift", "urls": [ "https://github.com/grpc/grpc-swift/archive/1.16.0.tar.gz" ], "sha256": "58b60431d0064969f9679411264b82e40a217ae6bd34e17096d92cc4e47556a5", "strip_prefix": "grpc-swift-1.16.0/", - "build_file": "@@rules_swift~1.13.0//third_party:com_github_grpc_grpc_swift/BUILD.overlay" + "build_file": "@@rules_swift~1.15.1//third_party:com_github_grpc_grpc_swift/BUILD.overlay" } }, "com_github_apple_swift_nio_extras": { "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "rules_swift~1.13.0~non_module_deps~com_github_apple_swift_nio_extras", + "name": "rules_swift~1.15.1~non_module_deps~com_github_apple_swift_nio_extras", "urls": [ "https://github.com/apple/swift-nio-extras/archive/1.4.0.tar.gz" ], "sha256": "4684b52951d9d9937bb3e8ccd6b5daedd777021ef2519ea2f18c4c922843b52b", "strip_prefix": "swift-nio-extras-1.4.0/", - "build_file": "@@rules_swift~1.13.0//third_party:com_github_apple_swift_nio_extras/BUILD.overlay" + "build_file": "@@rules_swift~1.15.1//third_party:com_github_apple_swift_nio_extras/BUILD.overlay" } }, "com_github_apple_swift_protobuf": { "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "rules_swift~1.13.0~non_module_deps~com_github_apple_swift_protobuf", + "name": "rules_swift~1.15.1~non_module_deps~com_github_apple_swift_protobuf", "urls": [ "https://github.com/apple/swift-protobuf/archive/1.20.2.tar.gz" ], "sha256": "3fb50bd4d293337f202d917b6ada22f9548a0a0aed9d9a4d791e6fbd8a246ebb", "strip_prefix": "swift-protobuf-1.20.2/", - "build_file": "@@rules_swift~1.13.0//third_party:com_github_apple_swift_protobuf/BUILD.overlay" + "build_file": "@@rules_swift~1.15.1//third_party:com_github_apple_swift_protobuf/BUILD.overlay" } }, "com_github_apple_swift_nio_ssl": { "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "rules_swift~1.13.0~non_module_deps~com_github_apple_swift_nio_ssl", + "name": "rules_swift~1.15.1~non_module_deps~com_github_apple_swift_nio_ssl", "urls": [ "https://github.com/apple/swift-nio-ssl/archive/2.23.0.tar.gz" ], "sha256": "4787c63f61dd04d99e498adc3d1a628193387e41efddf8de19b8db04544d016d", "strip_prefix": "swift-nio-ssl-2.23.0/", - "build_file": "@@rules_swift~1.13.0//third_party:com_github_apple_swift_nio_ssl/BUILD.overlay" + "build_file": "@@rules_swift~1.15.1//third_party:com_github_apple_swift_nio_ssl/BUILD.overlay" } }, "com_github_apple_swift_atomics": { "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "rules_swift~1.13.0~non_module_deps~com_github_apple_swift_atomics", + "name": "rules_swift~1.15.1~non_module_deps~com_github_apple_swift_atomics", "urls": [ "https://github.com/apple/swift-atomics/archive/1.1.0.tar.gz" ], "sha256": "1bee7f469f7e8dc49f11cfa4da07182fbc79eab000ec2c17bfdce468c5d276fb", "strip_prefix": "swift-atomics-1.1.0/", - "build_file": "@@rules_swift~1.13.0//third_party:com_github_apple_swift_atomics/BUILD.overlay" + "build_file": "@@rules_swift~1.15.1//third_party:com_github_apple_swift_atomics/BUILD.overlay" } }, "com_github_apple_swift_nio_http2": { "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "rules_swift~1.13.0~non_module_deps~com_github_apple_swift_nio_http2", + "name": "rules_swift~1.15.1~non_module_deps~com_github_apple_swift_nio_http2", "urls": [ "https://github.com/apple/swift-nio-http2/archive/1.26.0.tar.gz" ], "sha256": "f0edfc9d6a7be1d587e5b403f2d04264bdfae59aac1d74f7d974a9022c6d2b25", "strip_prefix": "swift-nio-http2-1.26.0/", - "build_file": "@@rules_swift~1.13.0//third_party:com_github_apple_swift_nio_http2/BUILD.overlay" + "build_file": "@@rules_swift~1.15.1//third_party:com_github_apple_swift_nio_http2/BUILD.overlay" } }, "com_github_apple_swift_nio_transport_services": { "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "rules_swift~1.13.0~non_module_deps~com_github_apple_swift_nio_transport_services", + "name": "rules_swift~1.15.1~non_module_deps~com_github_apple_swift_nio_transport_services", "urls": [ "https://github.com/apple/swift-nio-transport-services/archive/1.15.0.tar.gz" ], "sha256": "f3498dafa633751a52b9b7f741f7ac30c42bcbeb3b9edca6d447e0da8e693262", "strip_prefix": "swift-nio-transport-services-1.15.0/", - "build_file": "@@rules_swift~1.13.0//third_party:com_github_apple_swift_nio_transport_services/BUILD.overlay" + "build_file": "@@rules_swift~1.15.1//third_party:com_github_apple_swift_nio_transport_services/BUILD.overlay" } }, "build_bazel_rules_swift_index_import": { "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "rules_swift~1.13.0~non_module_deps~build_bazel_rules_swift_index_import", - "build_file": "@@rules_swift~1.13.0//third_party:build_bazel_rules_swift_index_import/BUILD.overlay", + "name": "rules_swift~1.15.1~non_module_deps~build_bazel_rules_swift_index_import", + "build_file": "@@rules_swift~1.15.1//third_party:build_bazel_rules_swift_index_import/BUILD.overlay", "canonical_id": "index-import-5.8", "urls": [ "https://github.com/MobileNativeFoundation/index-import/releases/download/5.8.0.1/index-import.tar.gz" @@ -3481,49 +3576,61 @@ "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "rules_swift~1.13.0~non_module_deps~com_github_apple_swift_nio", + "name": "rules_swift~1.15.1~non_module_deps~com_github_apple_swift_nio", "urls": [ "https://github.com/apple/swift-nio/archive/2.42.0.tar.gz" ], "sha256": "e3304bc3fb53aea74a3e54bd005ede11f6dc357117d9b1db642d03aea87194a0", "strip_prefix": "swift-nio-2.42.0/", - "build_file": "@@rules_swift~1.13.0//third_party:com_github_apple_swift_nio/BUILD.overlay" + "build_file": "@@rules_swift~1.15.1//third_party:com_github_apple_swift_nio/BUILD.overlay" } }, "com_github_apple_swift_log": { "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "rules_swift~1.13.0~non_module_deps~com_github_apple_swift_log", + "name": "rules_swift~1.15.1~non_module_deps~com_github_apple_swift_log", "urls": [ "https://github.com/apple/swift-log/archive/1.4.4.tar.gz" ], "sha256": "48fe66426c784c0c20031f15dc17faf9f4c9037c192bfac2f643f65cb2321ba0", "strip_prefix": "swift-log-1.4.4/", - "build_file": "@@rules_swift~1.13.0//third_party:com_github_apple_swift_log/BUILD.overlay" + "build_file": "@@rules_swift~1.15.1//third_party:com_github_apple_swift_log/BUILD.overlay" } }, "com_github_apple_swift_collections": { "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "rules_swift~1.13.0~non_module_deps~com_github_apple_swift_collections", + "name": "rules_swift~1.15.1~non_module_deps~com_github_apple_swift_collections", "urls": [ "https://github.com/apple/swift-collections/archive/1.0.4.tar.gz" ], "sha256": "d9e4c8a91c60fb9c92a04caccbb10ded42f4cb47b26a212bc6b39cc390a4b096", "strip_prefix": "swift-collections-1.0.4/", - "build_file": "@@rules_swift~1.13.0//third_party:com_github_apple_swift_collections/BUILD.overlay" + "build_file": "@@rules_swift~1.15.1//third_party:com_github_apple_swift_collections/BUILD.overlay" } }, "build_bazel_rules_swift_local_config": { - "bzlFile": "@@rules_swift~1.13.0//swift/internal:swift_autoconfiguration.bzl", + "bzlFile": "@@rules_swift~1.15.1//swift/internal:swift_autoconfiguration.bzl", "ruleClassName": "swift_autoconfiguration", "attributes": { - "name": "rules_swift~1.13.0~non_module_deps~build_bazel_rules_swift_local_config" + "name": "rules_swift~1.15.1~non_module_deps~build_bazel_rules_swift_local_config" } } - } + }, + "recordedRepoMappingEntries": [ + [ + "rules_swift~1.15.1", + "bazel_tools", + "bazel_tools" + ], + [ + "rules_swift~1.15.1", + "build_bazel_rules_swift", + "rules_swift~1.15.1" + ] + ] } } } diff --git a/examples/resources_example/Package.resolved b/examples/resources_example/swift/Package.resolved similarity index 100% rename from examples/resources_example/Package.resolved rename to examples/resources_example/swift/Package.resolved diff --git a/examples/resources_example/Package.swift b/examples/resources_example/swift/Package.swift similarity index 61% rename from examples/resources_example/Package.swift rename to examples/resources_example/swift/Package.swift index 2023f3983..5b14d6633 100644 --- a/examples/resources_example/Package.swift +++ b/examples/resources_example/swift/Package.swift @@ -5,9 +5,9 @@ import PackageDescription let package = Package( name: "resources_example", dependencies: [ - .package(path: "third_party/another_package_with_resources"), - .package(path: "third_party/app_lovin_sdk"), - .package(path: "third_party/package_with_resources"), + .package(path: "../third_party/another_package_with_resources"), + .package(path: "../third_party/app_lovin_sdk"), + .package(path: "../third_party/package_with_resources"), .package(url: "https://github.com/SDWebImage/SDWebImageSwiftUI.git", from: "2.2.6"), .package(url: "https://github.com/google/GoogleSignIn-iOS", from: "7.0.0"), ] diff --git a/gazelle/internal/swift/bzlmod.go b/gazelle/internal/swift/bzlmod.go index 5ca6bed6b..bb0602f26 100644 --- a/gazelle/internal/swift/bzlmod.go +++ b/gazelle/internal/swift/bzlmod.go @@ -25,9 +25,10 @@ func UseRepoNames(di *DependencyIndex) (string, error) { return b.String(), nil } -func BzlmodStanzas(di *DependencyIndex, moduleDir string, pkgPath string, diPath string) (string, error) { +func BzlmodStanzas(di *DependencyIndex, moduleDir string, diPath string) (string, error) { // get the relative path to the package containing the dependency index file - relPkgPath, err := filepath.Rel(moduleDir, pkgPath) + diDir := filepath.Dir(diPath) + relPkgPath, err := filepath.Rel(moduleDir, diDir) if err != nil { return "", err } diff --git a/gazelle/internal/swift/bzlmod_test.go b/gazelle/internal/swift/bzlmod_test.go index b8841746b..c5b412db6 100644 --- a/gazelle/internal/swift/bzlmod_test.go +++ b/gazelle/internal/swift/bzlmod_test.go @@ -30,7 +30,7 @@ func TestBzlmodStanzas(t *testing.T) { di.AddPackage(awesomePkg, anotherPkg) di.AddDirectDependency(awesomeRepoId, anotherRepoID) - actual, err := swift.BzlmodStanzas(di, "path/to/root", "path/to/root", "path/to/root/swift_deps_index.json") + actual, err := swift.BzlmodStanzas(di, "path/to/root", "path/to/root/swift_deps_index.json") assert.NoError(t, err) expected := `swift_deps = use_extension( "@rules_swift_package_manager//:extensions.bzl", @@ -71,7 +71,7 @@ func TestBzlmodStanzasWithCustomDepsIndex(t *testing.T) { di.AddPackage(awesomePkg, anotherPkg) di.AddDirectDependency(awesomeRepoId, anotherRepoID) - actual, err := swift.BzlmodStanzas(di, "path/to/root", "path/to/root/swift", "path/to/root/swift/deps_index.json") + actual, err := swift.BzlmodStanzas(di, "path/to/root", "path/to/root/swift/deps_index.json") assert.NoError(t, err) expected := `swift_deps = use_extension( "@rules_swift_package_manager//:extensions.bzl", diff --git a/gazelle/internal/swift/package.go b/gazelle/internal/swift/package.go index 3ad36aaf2..ddd995839 100644 --- a/gazelle/internal/swift/package.go +++ b/gazelle/internal/swift/package.go @@ -32,6 +32,7 @@ func NewPackageFromBazelRepo( bzlRepo *BazelRepo, diRel string, pkgDir string, + repoRoot string, patch *Patch, ) (*Package, error) { var err error @@ -54,7 +55,7 @@ func NewPackageFromBazelRepo( } p.Remote.Patch = patch } else { - relPath, err := filepath.Rel(pkgDir, bzlRepo.PkgInfo.Path) + relPath, err := filepath.Rel(repoRoot, bzlRepo.PkgInfo.Path) if err != nil { return nil, err } diff --git a/gazelle/internal/swift/package_test.go b/gazelle/internal/swift/package_test.go index f6374327f..950a6320b 100644 --- a/gazelle/internal/swift/package_test.go +++ b/gazelle/internal/swift/package_test.go @@ -11,6 +11,7 @@ import ( ) func TestNewPackageFromBazelRepo(t *testing.T) { + repoRoot := "/path/to/package" pkgDir := "/path/to/package" diBasename := "swift_deps_index.json" @@ -35,7 +36,7 @@ func TestNewPackageFromBazelRepo(t *testing.T) { Identity: identity, Pin: p, } - actual, err := swift.NewPackageFromBazelRepo(br, diBasename, pkgDir, nil) + actual, err := swift.NewPackageFromBazelRepo(br, diBasename, pkgDir, repoRoot, nil) assert.NoError(t, err) expected := &swift.Package{ Name: repoName, @@ -73,7 +74,7 @@ func TestNewPackageFromBazelRepo(t *testing.T) { Args: []string{"-p1"}, Files: []string{"@@//third-party/foo:0001-fix.patch"}, } - actual, err := swift.NewPackageFromBazelRepo(br, diBasename, pkgDir, patch) + actual, err := swift.NewPackageFromBazelRepo(br, diBasename, pkgDir, repoRoot, patch) assert.NoError(t, err) expected := &swift.Package{ Name: repoName, @@ -102,7 +103,7 @@ func TestNewPackageFromBazelRepo(t *testing.T) { Path: localPkgDir, }, } - actual, err := swift.NewPackageFromBazelRepo(br, diBasename, pkgDir, nil) + actual, err := swift.NewPackageFromBazelRepo(br, diBasename, pkgDir, repoRoot, nil) assert.NoError(t, err) expected := &swift.Package{ Name: repoName, diff --git a/gazelle/update_repos.go b/gazelle/update_repos.go index 35992f78c..f3957d233 100644 --- a/gazelle/update_repos.go +++ b/gazelle/update_repos.go @@ -144,7 +144,7 @@ func importReposFromPackageManifest(args language.ImportReposArgs) language.Impo return result } pkg, err := swift.NewPackageFromBazelRepo( - bzlRepo, sc.DependencyIndexRel, pkgDir, patches[bzlRepo.Identity]) + bzlRepo, sc.DependencyIndexRel, pkgDir, c.RepoRoot, patches[bzlRepo.Identity]) if err != nil { result.Error = err return result @@ -162,7 +162,7 @@ func importReposFromPackageManifest(args language.ImportReposArgs) language.Impo } // Output a bzlmod stanzas for bzlmod. - if err := writeBzlmodStanzas(pkgDir, di, sc); err != nil { + if err := writeBzlmodStanzas(di, sc); err != nil { result.Error = err return result } @@ -306,13 +306,13 @@ func writeBzlmodUseRepoNames(di *swift.DependencyIndex, sc *swiftcfg.SwiftConfig return os.WriteFile(sc.BazelModulePath, []byte(newContent), finfo.Mode()) } -func writeBzlmodStanzas(pkgPath string, di *swift.DependencyIndex, sc *swiftcfg.SwiftConfig) error { +func writeBzlmodStanzas(di *swift.DependencyIndex, sc *swiftcfg.SwiftConfig) error { if !sc.PrintBzlmodStanzas && !sc.UpdateBzlmodStanzas { return nil } moduleDir := filepath.Dir(sc.BazelModulePath) - bzlmodStanzas, err := swift.BzlmodStanzas(di, moduleDir, pkgPath, sc.DependencyIndexPath) + bzlmodStanzas, err := swift.BzlmodStanzas(di, moduleDir, sc.DependencyIndexPath) if err != nil { return err