Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ build:ci --//build:execution_env=ci
common --enable_bzlmod
build --@cgrindel_bazel_starlib//bzlmod:enabled

# windows requires symlinks to work well
startup --windows_enable_symlinks

# this library requires runfiles for the bzlformat_lint_test
# but this is off by default on windows. Switch it on.
common --enable_runfiles

# Try to import a local.rc file; typically, written by CI
try-import %workspace%/local.bazelrc

5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# The behavior of core.autocrlf=input is to force conversion to LF on addition
# into the repository and not to perform any conversion on checkout; that is,
# to always use LF endings regardless of the user's settings. This is set in
# .gitattributes as '* eol=lf'
* eol=lf
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ bazel_starlib_dependencies()
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")

aspect_bazel_lib_dependencies()
```
<!-- END WORKSPACE SNIPPET -->

Expand Down
1 change: 1 addition & 0 deletions bzlformat/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ bzl_library(
":bzlformat_format",
"//bzllib:defs",
"//updatesrc:defs",
"@aspect_bazel_lib//lib:windows_utils",
"@bazel_skylib//rules:diff_test",
],
)
Expand Down
36 changes: 29 additions & 7 deletions bzlformat/private/bzlformat_lint_test.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""Definition for bzlformat_lint_test rule."""

load(
"@aspect_bazel_lib//lib:windows_utils.bzl",
"create_windows_native_launcher_script",
)
load("@bazel_skylib//lib:shell.bzl", "shell")
load("//shlib/rules:execute_binary.bzl", "execute_binary_utils")

Expand All @@ -10,7 +14,9 @@ def _bzlformat_lint_test_impl(ctx):
# Generate the lint tests
lint_tests = []
for src in ctx.files.srcs:
exec_binary_out = ctx.actions.declare_file(ctx.label.name + "_" + src.basename + ".sh")
exec_binary_out = ctx.actions.declare_file(
ctx.label.name + "_" + src.basename + ".sh",
)
lint_tests.append(exec_binary_out)
arguments = common_arguments + [src.short_path]
execute_binary_utils.write_execute_binary_script(
Expand All @@ -23,9 +29,9 @@ def _bzlformat_lint_test_impl(ctx):
lint_test_names = [lt.short_path for lt in lint_tests]

# Write a script that executes all of the lint tests
out = ctx.actions.declare_file(ctx.label.name + ".sh")
bash_launcher = ctx.actions.declare_file(ctx.label.name + ".sh")
ctx.actions.write(
output = out,
output = bash_launcher,
is_executable = True,
content = """\
#!/usr/bin/env bash
Expand All @@ -45,25 +51,37 @@ for lint_test in "${lint_tests[@]}"; do
exit_code=0
"${lint_test}" || exit_code=$?
if [[ ${exit_code} != 0 ]]; then
failure_count=$(( ${failure_count} + 1 ))
failure_count=$(( ${failure_count} + 1 ))
echo >&2 "${lint_test} failed with ${exit_code}."
fi
done

[[ ${failure_count} > 0 ]] && echo >&2 "${failure_count} lint tests failed." && exit 1
[[ ${failure_count} > 0 ]] && echo >&2 "${failure_count} lint tests failed." \
&& exit 1
echo "All tests succeeded!"
""",
)

is_windows = ctx.target_platform_has_constraint(
ctx.attr._windows_constraint[platform_common.ConstraintValueInfo],
)
if is_windows:
launcher = create_windows_native_launcher_script(ctx, bash_launcher)
else:
launcher = bash_launcher
extra_runfiles = [bash_launcher] if is_windows else []

# Gather the runfiles
runfiles = ctx.runfiles(files = ctx.files.srcs + lint_tests)
runfiles = ctx.runfiles(
files = ctx.files.srcs + lint_tests + extra_runfiles,
)
runfiles = execute_binary_utils.collect_runfiles(
runfiles,
[ctx.attr._buildifier],
)

# Return the DefaultInfo
return DefaultInfo(executable = out, runfiles = runfiles)
return DefaultInfo(executable = launcher, runfiles = runfiles)

bzlformat_lint_test = rule(
implementation = _bzlformat_lint_test_impl,
Expand All @@ -85,6 +103,10 @@ bzlformat_lint_test = rule(
allow_files = True,
doc = "The `buildifier` script that executes the formatting.",
),
"_windows_constraint": attr.label(default = "@platforms//os:windows"),
},
toolchains = [
"@bazel_tools//tools/sh:toolchain_type",
],
doc = "Lints the specified Starlark files using Buildifier.",
)
8 changes: 8 additions & 0 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,13 @@ def bazel_starlib_dependencies():
],
)

maybe(
http_archive,
name = "aspect_bazel_lib",
sha256 = "4b32cf6feab38b887941db022020eea5a49b848e11e3d6d4d18433594951717a",
strip_prefix = "bazel-lib-2.0.1",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.0.1/bazel-lib-v2.0.1.tar.gz",
)

_bazeldoc_dependencies()
_prebuilt_buildtools_dependencies()
4 changes: 4 additions & 0 deletions release/workspace_snippet.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ bazel_starlib_dependencies()
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")

aspect_bazel_lib_dependencies()
3 changes: 3 additions & 0 deletions tests/bzlformat_tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ _FORMAT_INFOS = [
name = fi[0] + "_bzl",
out = fi[0] + ".bzl",
content = fi[1],
newline = "unix",
)
for fi in _FORMAT_INFOS
]
Expand All @@ -64,11 +65,13 @@ bzlformat_format(
)

# Write the expected content
# buildifier writes unix newlines; match that
[
write_file(
name = fi[0] + "_bzl_expected",
out = fi[0] + ".bzl.expected",
content = fi[2],
newline = "unix",
)
for fi in _FORMAT_INFOS
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")

aspect_bazel_lib_dependencies()

# Buildifier Dependencies

load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ bazel_skylib_workspace()
load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")

stardoc_repositories()

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")

aspect_bazel_lib_dependencies()
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ bazel_skylib_workspace()
load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")

stardoc_repositories()

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")

aspect_bazel_lib_dependencies()
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,29 @@ f=
set -e
# --- end runfiles.bash initialization v3 ---

# return a unix-style path on all platforms
# workaround for https://github.com/bazelbuild/bazel/issues/22803
function rlocation_as_unix() {
path="$(rlocation ${1})"
case "$(uname -s)" in
CYGWIN* | MINGW32* | MSYS* | MINGW*)
path=${path//\\//} # backslashes to forward
path=/${path//:/} # d:/ to /d/
;;
esac
echo "$path"
}

# MARK - Locate Deps

assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh
assertions_sh="$(rlocation "${assertions_sh_location}")" ||
assertions_sh="$(rlocation_as_unix "${assertions_sh_location}")" ||
(echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1)
# shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh
source "${assertions_sh}"

archive_tar_gz_location=cgrindel_bazel_starlib/tests/bzlrelease_tests/rules_tests/release_artifact_tests/archive.tar.gz
archive_tar_gz="$(rlocation "${archive_tar_gz_location}")" ||
archive_tar_gz="$(rlocation_as_unix "${archive_tar_gz_location}")" ||
(echo >&2 "Failed to locate ${archive_tar_gz_location}" && exit 1)

tar_exe_location=cgrindel_bazel_starlib/tools/tar/tar.exe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ bazel_skylib_workspace()
load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")

stardoc_repositories()

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")

aspect_bazel_lib_dependencies()
4 changes: 4 additions & 0 deletions tests/bzlrelease_tests/tools_tests/workspace_snippet.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ bazel_skylib_workspace()
load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")

stardoc_repositories()

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")

aspect_bazel_lib_dependencies()
4 changes: 4 additions & 0 deletions tests/updatesrc_tests/workspace/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ bazel_starlib_dependencies()
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")

aspect_bazel_lib_dependencies()
2 changes: 2 additions & 0 deletions updatesrc/private/updatesrc_diff_and_update.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def updatesrc_diff_and_update(
# create a helpful message if none has been given
msg = "Run 'bazel run {}' to update {}".format(name, src)

# this difftest fails as file2 has CRLf on windows
# fix: https://github.com/bazelbuild/bazel-skylib/pull/527
diff_test(
name = diff_test_prefix + src_name + diff_test_suffix,
file1 = src,
Expand Down