diff --git a/.bazelrc b/.bazelrc index e15d307f..e730e9b0 100644 --- a/.bazelrc +++ b/.bazelrc @@ -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 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..be75c150 --- /dev/null +++ b/.gitattributes @@ -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 diff --git a/README.md b/README.md index 91fe7838..bbdfd062 100644 --- a/README.md +++ b/README.md @@ -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() ``` diff --git a/bzlformat/private/BUILD.bazel b/bzlformat/private/BUILD.bazel index d650c520..db017cc3 100644 --- a/bzlformat/private/BUILD.bazel +++ b/bzlformat/private/BUILD.bazel @@ -20,6 +20,7 @@ bzl_library( ":bzlformat_format", "//bzllib:defs", "//updatesrc:defs", + "@aspect_bazel_lib//lib:windows_utils", "@bazel_skylib//rules:diff_test", ], ) diff --git a/bzlformat/private/bzlformat_lint_test.bzl b/bzlformat/private/bzlformat_lint_test.bzl index c836b3cd..84d01199 100644 --- a/bzlformat/private/bzlformat_lint_test.bzl +++ b/bzlformat/private/bzlformat_lint_test.bzl @@ -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") @@ -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( @@ -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 @@ -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, @@ -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.", ) diff --git a/deps.bzl b/deps.bzl index 11dcdc04..0f56d72b 100644 --- a/deps.bzl +++ b/deps.bzl @@ -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() diff --git a/release/workspace_snippet.tmpl b/release/workspace_snippet.tmpl index 1c706977..0b82c89c 100644 --- a/release/workspace_snippet.tmpl +++ b/release/workspace_snippet.tmpl @@ -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() diff --git a/tests/bzlformat_tests/BUILD.bazel b/tests/bzlformat_tests/BUILD.bazel index e7d4ed41..a547de19 100644 --- a/tests/bzlformat_tests/BUILD.bazel +++ b/tests/bzlformat_tests/BUILD.bazel @@ -53,6 +53,7 @@ _FORMAT_INFOS = [ name = fi[0] + "_bzl", out = fi[0] + ".bzl", content = fi[1], + newline = "unix", ) for fi in _FORMAT_INFOS ] @@ -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 ] diff --git a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/WORKSPACE b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/WORKSPACE index 93aa2826..0f478a93 100644 --- a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/WORKSPACE +++ b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/WORKSPACE @@ -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") diff --git a/tests/bzlrelease_tests/rules_tests/generate_release_notes_tests/workspace_snippet.tmpl b/tests/bzlrelease_tests/rules_tests/generate_release_notes_tests/workspace_snippet.tmpl index d71cbe48..3003868b 100644 --- a/tests/bzlrelease_tests/rules_tests/generate_release_notes_tests/workspace_snippet.tmpl +++ b/tests/bzlrelease_tests/rules_tests/generate_release_notes_tests/workspace_snippet.tmpl @@ -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() diff --git a/tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests/workspace_snippet.tmpl b/tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests/workspace_snippet.tmpl index d71cbe48..3003868b 100644 --- a/tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests/workspace_snippet.tmpl +++ b/tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests/workspace_snippet.tmpl @@ -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() diff --git a/tests/bzlrelease_tests/rules_tests/release_artifact_tests/archive_test.sh b/tests/bzlrelease_tests/rules_tests/release_artifact_tests/archive_test.sh index 77d08b8b..6be02770 100755 --- a/tests/bzlrelease_tests/rules_tests/release_artifact_tests/archive_test.sh +++ b/tests/bzlrelease_tests/rules_tests/release_artifact_tests/archive_test.sh @@ -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 diff --git a/tests/bzlrelease_tests/rules_tests/update_readme_tests/workspace_snippet.tmpl b/tests/bzlrelease_tests/rules_tests/update_readme_tests/workspace_snippet.tmpl index d71cbe48..3003868b 100644 --- a/tests/bzlrelease_tests/rules_tests/update_readme_tests/workspace_snippet.tmpl +++ b/tests/bzlrelease_tests/rules_tests/update_readme_tests/workspace_snippet.tmpl @@ -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() diff --git a/tests/bzlrelease_tests/tools_tests/workspace_snippet.tmpl b/tests/bzlrelease_tests/tools_tests/workspace_snippet.tmpl index d71cbe48..3003868b 100644 --- a/tests/bzlrelease_tests/tools_tests/workspace_snippet.tmpl +++ b/tests/bzlrelease_tests/tools_tests/workspace_snippet.tmpl @@ -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() diff --git a/tests/updatesrc_tests/workspace/WORKSPACE b/tests/updatesrc_tests/workspace/WORKSPACE index 62c90b15..4b9b0047 100644 --- a/tests/updatesrc_tests/workspace/WORKSPACE +++ b/tests/updatesrc_tests/workspace/WORKSPACE @@ -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() diff --git a/updatesrc/private/updatesrc_diff_and_update.bzl b/updatesrc/private/updatesrc_diff_and_update.bzl index a1df9b22..37db1a13 100644 --- a/updatesrc/private/updatesrc_diff_and_update.bzl +++ b/updatesrc/private/updatesrc_diff_and_update.bzl @@ -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,