Skip to content

Commit

Permalink
chore: remove legacy code and docs (#1179)
Browse files Browse the repository at this point in the history
Remove docs and obsolete tests for legacy workspaces.
  • Loading branch information
cgrindel authored Jul 21, 2024
1 parent af74d06 commit 3e16d4d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 219 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,14 @@ actions. See the [CI GitHub workflow] for more details.

The following provides a quick introduction on how to set up and use the features in this
repository. These instructions assume that you are using [Bazel modules] to load your external
dependencies. If you are using Bazel's legacy external dependency management, please review the
[legacy quickstart], instead.
dependencies. If you are using Bazel's legacy external dependency management, we recommend using
[Bazel's hybrid mode], then follow the steps in this quickstart guide.

Also, check out the [examples] for more information.

### 1. Enable bzlmod

This repository supports [bzlmod]. While you can use this ruleset with [legacy `WORKSPACE`
dependencies], some of the automation will not be available in this mode. If you are starting a new
project, it is highly recommended to use [bzlmod]. To enable bzlmod, add the following to your
`.bazelrc`.
This repository supports [bzlmod].

```
common --enable_bzlmod
Expand All @@ -89,9 +86,11 @@ common --enable_bzlmod
Add a dependency on `rules_swift_package_manager`.

<!-- BEGIN MODULE SNIPPET -->

```python
bazel_dep(name = "rules_swift_package_manager", version = "0.35.1")
```

<!-- END MODULE SNIPPET -->

In addition, add the following to load the external dependencies described in your `Package.swift`
Expand Down Expand Up @@ -155,7 +154,8 @@ files, at this time.

### 4. Run `swift package update`

This will invoke Swift Package Manager and resolve all dependencies resulting in creation of Package.resolved file.
This will invoke Swift Package Manager and resolve all dependencies resulting in creation of
`Package.resolved` file.

### 5. Run `bazel mod tidy`.

Expand Down Expand Up @@ -247,9 +247,8 @@ The following are a few tips to consider as you work with your repository:
<!-- Links -->

[Bazel modules]: https://bazel.build/external/module
[Bazel's hybrid mode]: https://bazel.build/external/migration#hybrid-mode
[bzlmod]: https://bazel.build/external/overview#bzlmod
[legacy `WORKSPACE` dependencies]: https://bazel.build/external/overview#workspace-system
[legacy quickstart]: /docs/legacy_quickstart.md
[our document on patching Swift packages]: docs/patch_swift_package.md
[CI GitHub workflow]: .github/workflows/ci.yml
[Gazelle plugin]: https://github.com/bazelbuild/bazel-gazelle/blob/master/extend.md
Expand Down
8 changes: 3 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# Swift Bazel Documentation
# `rules_swift_package_manager` Documentation

- For information on how configure and use Swift Bazel, check out the [quickstart] and the [tips
and tricks]. If you are using Bazel's legacy external dependency management system, please review
the [legacy quickstart].
- For information on how configure and use `rules_swift_package_manager`, check out the [quickstart]
and the [tips and tricks].
- To view the Starlark API documentation, check out the [repository rules documentation] and the
[rules and macros documentation].
- If you are interested in learning more about the rules used to help build the external Swift
packages, check out the [internal rules and macros documentation].

[quickstart]: /README.md#quickstart
[legacy quickstart]: /docs/legacy_quickstart.md
[repository rules documentation]: /docs/repository_rules_overview.md
[rules and macros documentation]: /docs/rules_and_macros_overview.md
[internal rules and macros documentation]: /docs/internal_rules_and_macros_overview.md
Expand Down
139 changes: 0 additions & 139 deletions docs/legacy_quickstart.md

This file was deleted.

32 changes: 8 additions & 24 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
load("@bazel_binaries//:defs.bzl", "bazel_binaries")
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg")
load("@cgrindel_bazel_starlib//bzllib:defs.bzl", "lists")
load("@cgrindel_bazel_starlib//shlib/rules:execute_binary.bzl", "execute_binary")
load(
"@rules_bazel_integration_test//bazel_integration_test:defs.bzl",
"integration_test_utils",
Expand All @@ -28,13 +27,6 @@ sh_binary(
],
)

execute_binary(
name = "legacy_test_runner",
testonly = True,
arguments = ["--legacy"],
binary = ":test_runner",
)

# MARK: - Integration Tests

[
Expand All @@ -48,27 +40,19 @@ example_infos.ci_test_params_suite(
)

_smoke_test_names = sorted(lists.flatten([
[
example_infos.test_name(
ei.name,
enable_bzlmod,
bazel_binaries.versions.current,
)
for enable_bzlmod in ei.enable_bzlmods
]
example_infos.test_name(
ei.name,
bazel_binaries.versions.current,
)
for ei in example_infos.all
]))

_all_test_names = sorted(lists.flatten([
[
[
example_infos.test_name(
ei.name,
enable_bzlmod,
version,
)
for enable_bzlmod in ei.enable_bzlmods
]
example_infos.test_name(
ei.name,
version,
)
for version in ei.versions
]
for ei in example_infos.all
Expand Down
30 changes: 14 additions & 16 deletions examples/example_infos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ def _new(name, oss, versions, enable_bzlmods):
enable_bzlmods = enable_bzlmods,
)

def _test_name_prefix(name, enable_bzlmod = True):
suffix = "_test" if enable_bzlmod else "_legacy_test"
return name + suffix
def _test_name_prefix(name):
return name + "_test"

def _test_name(example_name, enable_bzlmod, version):
def _test_name(example_name, version):
return integration_test_utils.bazel_integration_test_name(
_test_name_prefix(example_name, enable_bzlmod = enable_bzlmod),
_test_name_prefix(example_name),
version,
)

Expand All @@ -58,9 +57,11 @@ def _bazel_integration_test(ei):
]
workspace_path = ei.name
for enable_bzlmod in ei.enable_bzlmods:
test_runner = ":test_runner" if enable_bzlmod else ":legacy_test_runner"
if not enable_bzlmod:
fail("The {name} example still has legacy test enabled.".format(name = ei.name))
test_runner = ":test_runner"
bazel_integration_tests(
name = _test_name_prefix(ei.name, enable_bzlmod = enable_bzlmod),
name = _test_name_prefix(ei.name),
bazel_binaries = bazel_binaries,
bazel_versions = ei.versions,
tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS + [
Expand All @@ -76,17 +77,17 @@ def _bazel_integration_test(ei):
workspace_path = workspace_path,
)
for version in ei.versions:
_ci_integration_test_params(ei, enable_bzlmod, version)
_ci_integration_test_params(ei, version)

def _test_params_name(name, enable_bzlmod, version):
test_name = _test_name(name, enable_bzlmod, version)
def _test_params_name(name, version):
test_name = _test_name(name, version)
return _test_params_name_from_test_name(test_name)

def _test_params_name_from_test_name(test_name):
return "{}_params".format(test_name)

def _ci_integration_test_params(ei, enable_bzlmod, version):
test_name = _test_name(ei.name, enable_bzlmod, version)
def _ci_integration_test_params(ei, version):
test_name = _test_name(ei.name, version)
ci_integration_test_params(
name = _test_params_name_from_test_name(test_name),
oss = ei.oss,
Expand All @@ -99,10 +100,7 @@ def _ci_test_params_suite(name, example_infos):
name = name,
test_params = lists.flatten([
[
[
_test_params_name(ei.name, eb, v)
for eb in ei.enable_bzlmods
]
_test_params_name(ei.name, v)
for v in ei.versions
]
for ei in example_infos
Expand Down
22 changes: 0 additions & 22 deletions examples/test_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,6 @@ create_scratch_dir_sh="$(rlocation "${create_scratch_dir_sh_location}")" || \

# MARK - Process Arguments

legacy_mode=false
while (("$#")); do
case "${1}" in
"--legacy")
legacy_mode=true
shift 1
;;
"--nolegacy")
legacy_mode=false
shift 1
;;
*)
args+=("${1}")
shift 1
;;
esac
done

bazel="${BIT_BAZEL_BINARY:-}"
workspace_dir="${BIT_WORKSPACE_DIR:-}"

Expand All @@ -54,10 +36,6 @@ workspace_dir="${BIT_WORKSPACE_DIR:-}"
scratch_dir="$("${create_scratch_dir_sh}" --workspace "${workspace_dir}")"
cd "${scratch_dir}"

if [[ "${legacy_mode}" == "true" ]]; then
echo "build --config=legacy" >> .bazelrc
fi

# Dump Bazel info
echo "=== Output Bazel info ==="
"${bazel}" info
Expand Down
4 changes: 0 additions & 4 deletions shared.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ build --bes_upload_mode=fully_async
run --bes_backend=
run --bes_results_url=

# Configuration group to run using legacy WORKSPACE
common:legacy --noenable_bzlmod
build:legacy --no@cgrindel_bazel_starlib//bzlmod:enabled

# Configure Apple CC toolchain
# https://github.com/bazelbuild/apple_support#toolchain-setup
build --enable_platform_specific_config
Expand Down

0 comments on commit 3e16d4d

Please sign in to comment.