From fe93c3957537624fea427c8589fdc562e17bf2e2 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Wed, 8 Mar 2023 17:35:15 -0700 Subject: [PATCH] chore: add `bzlmod_e2e` in preparation for publishing to BCR (#234) - Add `examples/bzlmod_e2e` child workspace as test for publish_to_bcr presubmit. - Add `.bcr` files for public_to_bcr. Related to #195. --- .bazelrc | 4 +- .bcr/config.yml | 3 + .bcr/metadata.template.json | 15 +++++ .bcr/presubmit.yml | 10 ++++ .bcr/source.template.json | 5 ++ .github/actions/test_example/action.yml | 12 +++- .github/workflows/ci.yml | 8 +++ BUILD.bazel | 2 + examples/BUILD.bazel | 57 +++++++++++++++++++ examples/bzlmod_e2e/.bazelrc | 11 ++++ examples/bzlmod_e2e/BUILD.bazel | 37 ++++++++++++ examples/bzlmod_e2e/MODULE.bazel | 13 +++++ examples/bzlmod_e2e/README.md | 27 +++++++++ examples/bzlmod_e2e/WORKSPACE | 2 + examples/bzlmod_e2e/header/BUILD.bazel | 16 ++++++ examples/bzlmod_e2e/header/header.bzl | 44 ++++++++++++++ examples/bzlmod_e2e/header/header.sh | 13 +++++ examples/bzlmod_e2e/mockascript/BUILD.bazel | 24 ++++++++ examples/bzlmod_e2e/mockascript/deps.bzl | 15 +++++ .../mockascript/internal/BUILD.bazel | 16 ++++++ .../bzlmod_e2e/mockascript/internal/foo.bzl | 7 +++ .../internal/mockascript_library.bzl | 11 ++++ .../bzlmod_e2e/mockascript/mockascript.bzl | 8 +++ examples/bzlmod_e2e/srcs/Bar/BUILD.bazel | 29 ++++++++++ examples/bzlmod_e2e/srcs/Bar/c.txt | 2 + examples/bzlmod_e2e/srcs/Bar/d.txt | 2 + examples/bzlmod_e2e/srcs/Foo/BUILD.bazel | 13 +++++ examples/bzlmod_e2e/srcs/Foo/a.txt | 2 + examples/bzlmod_e2e/srcs/Foo/b.txt | 2 + examples/markdown/simple/README.md | 2 +- 30 files changed, 408 insertions(+), 4 deletions(-) create mode 100644 .bcr/config.yml create mode 100644 .bcr/metadata.template.json create mode 100644 .bcr/presubmit.yml create mode 100644 .bcr/source.template.json create mode 100644 examples/BUILD.bazel create mode 100644 examples/bzlmod_e2e/.bazelrc create mode 100644 examples/bzlmod_e2e/BUILD.bazel create mode 100644 examples/bzlmod_e2e/MODULE.bazel create mode 100644 examples/bzlmod_e2e/README.md create mode 100644 examples/bzlmod_e2e/WORKSPACE create mode 100644 examples/bzlmod_e2e/header/BUILD.bazel create mode 100644 examples/bzlmod_e2e/header/header.bzl create mode 100755 examples/bzlmod_e2e/header/header.sh create mode 100644 examples/bzlmod_e2e/mockascript/BUILD.bazel create mode 100644 examples/bzlmod_e2e/mockascript/deps.bzl create mode 100644 examples/bzlmod_e2e/mockascript/internal/BUILD.bazel create mode 100644 examples/bzlmod_e2e/mockascript/internal/foo.bzl create mode 100644 examples/bzlmod_e2e/mockascript/internal/mockascript_library.bzl create mode 100644 examples/bzlmod_e2e/mockascript/mockascript.bzl create mode 100644 examples/bzlmod_e2e/srcs/Bar/BUILD.bazel create mode 100644 examples/bzlmod_e2e/srcs/Bar/c.txt create mode 100644 examples/bzlmod_e2e/srcs/Bar/d.txt create mode 100644 examples/bzlmod_e2e/srcs/Foo/BUILD.bazel create mode 100644 examples/bzlmod_e2e/srcs/Foo/a.txt create mode 100644 examples/bzlmod_e2e/srcs/Foo/b.txt diff --git a/.bazelrc b/.bazelrc index 555764a6..322baff0 100644 --- a/.bazelrc +++ b/.bazelrc @@ -3,8 +3,8 @@ # This lets us glob() up all the files inside the examples to make them inputs to tests # (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it) # To update these lines, run `bazel run @contrib_rules_bazel_integration_test//tools:update_deleted_packages`. -build --deleted_packages=examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters -query --deleted_packages=examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters +build --deleted_packages=examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/bzlmod_e2e,examples/bzlmod_e2e/header,examples/bzlmod_e2e/mockascript,examples/bzlmod_e2e/mockascript/internal,examples/bzlmod_e2e/srcs/Bar,examples/bzlmod_e2e/srcs/Foo,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters +query --deleted_packages=examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/bzlmod_e2e,examples/bzlmod_e2e/header,examples/bzlmod_e2e/mockascript,examples/bzlmod_e2e/mockascript/internal,examples/bzlmod_e2e/srcs/Bar,examples/bzlmod_e2e/srcs/Foo,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters # Import Shared settings import %workspace%/shared.bazelrc diff --git a/.bcr/config.yml b/.bcr/config.yml new file mode 100644 index 00000000..42519eef --- /dev/null +++ b/.bcr/config.yml @@ -0,0 +1,3 @@ +fixedReleaser: + login: cgrindel + email: chuck.grindel@gmail.com diff --git a/.bcr/metadata.template.json b/.bcr/metadata.template.json new file mode 100644 index 00000000..3301ca6b --- /dev/null +++ b/.bcr/metadata.template.json @@ -0,0 +1,15 @@ +{ + "homepage": "https://github.com/cgrindel/bazel-starlib", + "maintainers": [ + { + "email": "chuck.grindel@gmail.com", + "github": "cgrindel", + "name": "Chuck Grindel" + } + ], + "repository": [ + "github:OWNER/REPO" + ], + "versions": [], + "yanked_versions": {} +} diff --git a/.bcr/presubmit.yml b/.bcr/presubmit.yml new file mode 100644 index 00000000..21501d71 --- /dev/null +++ b/.bcr/presubmit.yml @@ -0,0 +1,10 @@ +bcr_test_module: + module_path: "examples/bzlmod_e2e" + matrix: + platform: ["macos", "ubuntu2004"] + tasks: + run_tests: + name: "Run test module" + platform: ${{ platform }} + test_targets: + - "//..." diff --git a/.bcr/source.template.json b/.bcr/source.template.json new file mode 100644 index 00000000..4f148199 --- /dev/null +++ b/.bcr/source.template.json @@ -0,0 +1,5 @@ +{ + "integrity": "", + "strip_prefix": "{REPO}-{VERSION}", + "url": "https://github.com/{OWNER}/{REPO}/archive/refs/tags/{TAG}.tar.gz" +} diff --git a/.github/actions/test_example/action.yml b/.github/actions/test_example/action.yml index 3a6ab1d7..a41afcfb 100644 --- a/.github/actions/test_example/action.yml +++ b/.github/actions/test_example/action.yml @@ -18,7 +18,8 @@ inputs: runs: using: composite steps: - - name: Execute Integration Test + - name: Execute Integration Test in Examples Subdirectory + if: inputs.example_dir != '' shell: bash env: # The integration tests make use of Github-specific functionality @@ -26,4 +27,13 @@ runs: GITHUB_TOKEN: ${{ inputs.github_token }} run: | bazelisk test //examples/${{ inputs.example_dir }}:${{ inputs.example_name }}_test_bazel_${{ inputs.bazel_version }} + - name: Execute Integration Test in Examples Directory + if: inputs.example_dir == '' + shell: bash + env: + # The integration tests make use of Github-specific functionality + # (e.g. gh). + GITHUB_TOKEN: ${{ inputs.github_token }} + run: | + bazelisk test //examples:${{ inputs.example_name }}_test_bazel_${{ inputs.bazel_version }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0458a271..ccf08633 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,10 @@ jobs: example_name: simple - example_dir: updatesrc example_name: simple + - example_dir: "" + example_name: bzlmod_e2e + enable_bzlmod: true + bazel_version: .bazelversion runs-on: macos-12 steps: - uses: actions/checkout@v3 @@ -74,6 +78,10 @@ jobs: example_name: simple - example_dir: updatesrc example_name: simple + - example_dir: "" + example_name: bzlmod_e2e + enable_bzlmod: true + bazel_version: .bazelversion runs-on: ubuntu-22.04 env: CC: clang diff --git a/BUILD.bazel b/BUILD.bazel index 89271253..ef347226 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -177,6 +177,7 @@ test_suite( name = "all_smoke_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ + "//examples:smoke_integration_tests", "//examples/bzlformat:smoke_integration_tests", "//examples/markdown:smoke_integration_tests", "//examples/updatesrc:smoke_integration_tests", @@ -193,6 +194,7 @@ test_suite( name = "all_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ + "//examples:integration_tests", "//examples/bzlformat:integration_tests", "//examples/markdown:integration_tests", "//examples/updatesrc:integration_tests", diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel new file mode 100644 index 00000000..c1c74725 --- /dev/null +++ b/examples/BUILD.bazel @@ -0,0 +1,57 @@ +load( + "@contrib_rules_bazel_integration_test//bazel_integration_test:defs.bzl", + "bazel_integration_tests", + "default_test_runner", + "integration_test_utils", +) +load("//:bazel_versions.bzl", "CURRENT_BAZEL_VERSION", "SUPPORTED_BAZEL_VERSIONS") +load("//bzlformat:defs.bzl", "bzlformat_pkg") +load("//bzllib:defs.bzl", "lists") + +bzlformat_pkg(name = "bzlformat") + +# MARK: - Integration Tests + +_EXAMPLE_DIRS = ["bzlmod_e2e"] + +default_test_runner(name = "default_test_runner") + +[ + bazel_integration_tests( + name = "{}_test".format(dirname), + timeout = "eternal", + bazel_versions = SUPPORTED_BAZEL_VERSIONS, + test_runner = ":default_test_runner", + workspace_files = integration_test_utils.glob_workspace_files(dirname) + [ + "//:workspace_integration_test_files", + ], + workspace_path = dirname, + ) + for dirname in _EXAMPLE_DIRS +] + +test_suite( + name = "smoke_integration_tests", + tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS, + tests = [ + integration_test_utils.bazel_integration_test_name( + ":{}_test".format(dirname), + CURRENT_BAZEL_VERSION, + ) + for dirname in _EXAMPLE_DIRS + ], + visibility = ["//:__subpackages__"], +) + +test_suite( + name = "integration_tests", + tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS, + tests = lists.flatten([ + integration_test_utils.bazel_integration_test_names( + ":{}_test".format(dirname), + SUPPORTED_BAZEL_VERSIONS, + ) + for dirname in _EXAMPLE_DIRS + ]), + visibility = ["//:__subpackages__"], +) diff --git a/examples/bzlmod_e2e/.bazelrc b/examples/bzlmod_e2e/.bazelrc new file mode 100644 index 00000000..2c98f33f --- /dev/null +++ b/examples/bzlmod_e2e/.bazelrc @@ -0,0 +1,11 @@ +# Import Shared settings +import %workspace%/../../shared.bazelrc + +# Import CI settings. +import %workspace%/../../ci.bazelrc + +# Try to import a local.rc file; typically, written by CI +try-import %workspace%/../../local.bazelrc + +# Explicitly enable bzlmod +common --enable_bzlmod diff --git a/examples/bzlmod_e2e/BUILD.bazel b/examples/bzlmod_e2e/BUILD.bazel new file mode 100644 index 00000000..cbf09085 --- /dev/null +++ b/examples/bzlmod_e2e/BUILD.bazel @@ -0,0 +1,37 @@ +load( + "@cgrindel_bazel_starlib//bzlformat:defs.bzl", + "bzlformat_missing_pkgs", + "bzlformat_pkg", +) +load("@cgrindel_bazel_starlib//markdown:defs.bzl", "markdown_pkg") +load( + "@cgrindel_bazel_starlib//updatesrc:defs.bzl", + "updatesrc_update_all", +) + +# Ensures that the Starlark files in this package are formatted properly. +bzlformat_pkg(name = "bzlformat") + +# Provides targets to find, test, and fix any Bazel packages that are missing bzlformat_pkg +# declarations. +# +# bzlformat_missing_pkgs_find: Find and report any Bazel packages that missing the bzlformat_pkg +# declaration. +# bzlformat_missing_pkgs_test: Like find except it fails if any missing packages are found. This is +# useful to run in CI tests to ensure that all is well. +# bzlformat_missing_pkgs_fix: Adds bzlformat_pkg declarations to any packages that are missing +# the declaration. +bzlformat_missing_pkgs(name = "bzlformat_missing_pkgs") + +# Define a runnable target to execute all of the updatesrc_update targets +# that are defined in your workspace. +updatesrc_update_all( + name = "update_all", + targets_to_run = [ + # Fix the Bazel packages when we update our source files from build outputs. + ":bzlformat_missing_pkgs_fix", + ], +) + +# Ensure that the markdown files are formatted properly +markdown_pkg(name = "markdown") diff --git a/examples/bzlmod_e2e/MODULE.bazel b/examples/bzlmod_e2e/MODULE.bazel new file mode 100644 index 00000000..99e784f9 --- /dev/null +++ b/examples/bzlmod_e2e/MODULE.bazel @@ -0,0 +1,13 @@ +module( + name = "bzlmod_e2e", + version = "0.0.0", + compatibility_level = 1, +) + +bazel_dep(name = "cgrindel_bazel_starlib", version = "0.0.0") +local_path_override( + module_name = "cgrindel_bazel_starlib", + path = "../..", +) + +bazel_dep(name = "bazel_skylib", version = "1.4.1") diff --git a/examples/bzlmod_e2e/README.md b/examples/bzlmod_e2e/README.md new file mode 100644 index 00000000..eb683233 --- /dev/null +++ b/examples/bzlmod_e2e/README.md @@ -0,0 +1,27 @@ +# E2E Test Workspace for bzlmod + +This workspace demonstrates a number of `bazel-starlib` capabilities in a bzlmod-enabled repository. + +## Table of Contents + +The following TOC is maintained by a +[`markdown_generate_toc`](https://github.com/cgrindel/bazel-starlib/blob/main/doc/markdown/rules_and_macros_overview.md#markdown_generate_toc) +rule that is defined by a +[`markdown_pkg`](https://github.com/cgrindel/bazel-starlib/blob/main/doc/markdown/rules_and_macros_overview.md#markdown_pkg). + + +* [Foo](#foo) + * [Foo Subtitle](#foo-subtitle) +* [Bar](#bar) + + +## Foo + +This section talks about foo. + +### Foo Subtitle + +This section talks about something specific to foo. + +## Bar + diff --git a/examples/bzlmod_e2e/WORKSPACE b/examples/bzlmod_e2e/WORKSPACE new file mode 100644 index 00000000..0e3c654f --- /dev/null +++ b/examples/bzlmod_e2e/WORKSPACE @@ -0,0 +1,2 @@ +# Intentionally blank +# This repository uses bzlmod. Please see MODULE.bazel for configuration. diff --git a/examples/bzlmod_e2e/header/BUILD.bazel b/examples/bzlmod_e2e/header/BUILD.bazel new file mode 100644 index 00000000..968496e8 --- /dev/null +++ b/examples/bzlmod_e2e/header/BUILD.bazel @@ -0,0 +1,16 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +package(default_visibility = ["//visibility:public"]) + +exports_files(["header.sh"]) + +sh_binary( + name = "add_header", + srcs = ["header.sh"], +) + +bzl_library( + name = "header", + srcs = ["header.bzl"], + deps = ["@cgrindel_bazel_starlib//updatesrc:defs"], +) diff --git a/examples/bzlmod_e2e/header/header.bzl b/examples/bzlmod_e2e/header/header.bzl new file mode 100644 index 00000000..59e9bb16 --- /dev/null +++ b/examples/bzlmod_e2e/header/header.bzl @@ -0,0 +1,44 @@ +load( + "@cgrindel_bazel_starlib//updatesrc:defs.bzl", + "UpdateSrcsInfo", + "update_srcs", +) + +def _header_impl(ctx): + outs = [] + updsrcs = [] + for src in ctx.files.srcs: + out = ctx.actions.declare_file(src.basename + "_with_header") + outs.append(out) + updsrcs.append(update_srcs.create(src = src, out = out)) + ctx.actions.run( + outputs = [out], + inputs = [src], + executable = ctx.executable._header_tool, + arguments = [src.path, out.path, ctx.attr.header], + ) + + return [ + DefaultInfo(files = depset(outs)), + UpdateSrcsInfo(update_srcs = depset(updsrcs)), + ] + +header = rule( + implementation = _header_impl, + attrs = { + "header": attr.string( + mandatory = True, + ), + "srcs": attr.label_list( + allow_files = True, + mandatory = True, + ), + "_header_tool": attr.label( + default = "//header:header.sh", + executable = True, + cfg = "exec", + allow_files = True, + ), + }, + doc = "Copies the output files to the workspace directory.", +) diff --git a/examples/bzlmod_e2e/header/header.sh b/examples/bzlmod_e2e/header/header.sh new file mode 100755 index 00000000..4af0aae3 --- /dev/null +++ b/examples/bzlmod_e2e/header/header.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -euo pipefail + +src="$1" +out="$2" +header="$3" + +first_line=$(head -n 1 "${src}") +if [[ "${first_line}" != "${header}" ]]; then + echo "${header}" > "${out}" +fi +cat "${src}" >> "${out}" diff --git a/examples/bzlmod_e2e/mockascript/BUILD.bazel b/examples/bzlmod_e2e/mockascript/BUILD.bazel new file mode 100644 index 00000000..6112dc3c --- /dev/null +++ b/examples/bzlmod_e2e/mockascript/BUILD.bazel @@ -0,0 +1,24 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") + +bzl_library( + name = "mockascript", + srcs = ["mockascript.bzl"], + visibility = ["//visibility:public"], + deps = [ + "//mockascript/internal:mockascript_library", + "@cgrindel_bazel_starlib//bzlformat:defs", + ], +) + +bzlformat_pkg() + +bzl_library( + name = "deps", + srcs = ["deps.bzl"], + visibility = ["//visibility:public"], + deps = [ + "@bazel_tools//tools/build_defs/repo:http.bzl", + "@bazel_tools//tools/build_defs/repo:utils.bzl", + ], +) diff --git a/examples/bzlmod_e2e/mockascript/deps.bzl b/examples/bzlmod_e2e/mockascript/deps.bzl new file mode 100644 index 00000000..8b45078e --- /dev/null +++ b/examples/bzlmod_e2e/mockascript/deps.bzl @@ -0,0 +1,15 @@ +"""Dependencies for mockascript rules.""" + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") + +def mockascript_rules_dependencies(): + maybe( + http_archive, + name = "bazel_skylib", + sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz", + ], + ) diff --git a/examples/bzlmod_e2e/mockascript/internal/BUILD.bazel b/examples/bzlmod_e2e/mockascript/internal/BUILD.bazel new file mode 100644 index 00000000..024421a8 --- /dev/null +++ b/examples/bzlmod_e2e/mockascript/internal/BUILD.bazel @@ -0,0 +1,16 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") + +package(default_visibility = ["//mockascript:__subpackages__"]) + +bzlformat_pkg(name = "bzlformat") + +bzl_library( + name = "foo", + srcs = ["foo.bzl"], +) + +bzl_library( + name = "mockascript_library", + srcs = ["mockascript_library.bzl"], +) diff --git a/examples/bzlmod_e2e/mockascript/internal/foo.bzl b/examples/bzlmod_e2e/mockascript/internal/foo.bzl new file mode 100644 index 00000000..b62f1408 --- /dev/null +++ b/examples/bzlmod_e2e/mockascript/internal/foo.bzl @@ -0,0 +1,7 @@ +"""Definition for foo macro.""" + +# This file provides no functionality. It needs to exist to test some +# formatting changes that are applied to BUILD.bazel files. + +def foo(tags = [], srcs = []): + return tags + srcs diff --git a/examples/bzlmod_e2e/mockascript/internal/mockascript_library.bzl b/examples/bzlmod_e2e/mockascript/internal/mockascript_library.bzl new file mode 100644 index 00000000..8b32532c --- /dev/null +++ b/examples/bzlmod_e2e/mockascript/internal/mockascript_library.bzl @@ -0,0 +1,11 @@ +"""Definition for mockascript_library rule.""" + +# buildifier: disable=unused-variable +def _mockascript_library_impl(ctx): + pass + +mockascript_library = rule( + implementation = _mockascript_library_impl, + attrs = {}, + doc = "", +) diff --git a/examples/bzlmod_e2e/mockascript/mockascript.bzl b/examples/bzlmod_e2e/mockascript/mockascript.bzl new file mode 100644 index 00000000..47fa295e --- /dev/null +++ b/examples/bzlmod_e2e/mockascript/mockascript.bzl @@ -0,0 +1,8 @@ +"""Public API for mockascript.""" + +load( + "//mockascript/internal:mockascript_library", + _mockascript_library = "mockascript_library", +) + +mockascript_library = _mockascript_library diff --git a/examples/bzlmod_e2e/srcs/Bar/BUILD.bazel b/examples/bzlmod_e2e/srcs/Bar/BUILD.bazel new file mode 100644 index 00000000..c9ad907d --- /dev/null +++ b/examples/bzlmod_e2e/srcs/Bar/BUILD.bazel @@ -0,0 +1,29 @@ +load( + "@cgrindel_bazel_starlib//updatesrc:defs.bzl", + "updatesrc_diff_and_update", +) + +srcs = [ + "c.txt", + "d.txt", +] + +outs = [f + "_modified" for f in srcs] + +[ + genrule( + name = "gen_" + outs[idx], + srcs = [srcs[idx]], + outs = [outs[idx]], + cmd = """\ +$(location //header:add_header) $(location {src}) $@ "# Howdy" +""".format(src = srcs[idx]), + tools = ["//header:add_header"], + ) + for idx in range(len(srcs)) +] + +updatesrc_diff_and_update( + srcs = srcs, + outs = outs, +) diff --git a/examples/bzlmod_e2e/srcs/Bar/c.txt b/examples/bzlmod_e2e/srcs/Bar/c.txt new file mode 100644 index 00000000..94b2383d --- /dev/null +++ b/examples/bzlmod_e2e/srcs/Bar/c.txt @@ -0,0 +1,2 @@ +# Howdy +This is c.txt. diff --git a/examples/bzlmod_e2e/srcs/Bar/d.txt b/examples/bzlmod_e2e/srcs/Bar/d.txt new file mode 100644 index 00000000..1f9548a9 --- /dev/null +++ b/examples/bzlmod_e2e/srcs/Bar/d.txt @@ -0,0 +1,2 @@ +# Howdy +This is d.txt. diff --git a/examples/bzlmod_e2e/srcs/Foo/BUILD.bazel b/examples/bzlmod_e2e/srcs/Foo/BUILD.bazel new file mode 100644 index 00000000..878db295 --- /dev/null +++ b/examples/bzlmod_e2e/srcs/Foo/BUILD.bazel @@ -0,0 +1,13 @@ +load("//header:header.bzl", "header") +load("@cgrindel_bazel_starlib//updatesrc:defs.bzl", "updatesrc_update") + +header( + name = "add_headers", + srcs = glob(["*.txt"]), + header = "# Super cool header", +) + +updatesrc_update( + name = "update", + deps = [":add_headers"], +) diff --git a/examples/bzlmod_e2e/srcs/Foo/a.txt b/examples/bzlmod_e2e/srcs/Foo/a.txt new file mode 100644 index 00000000..bd470215 --- /dev/null +++ b/examples/bzlmod_e2e/srcs/Foo/a.txt @@ -0,0 +1,2 @@ +# Super cool header +This is a.txt. diff --git a/examples/bzlmod_e2e/srcs/Foo/b.txt b/examples/bzlmod_e2e/srcs/Foo/b.txt new file mode 100644 index 00000000..dfa8571e --- /dev/null +++ b/examples/bzlmod_e2e/srcs/Foo/b.txt @@ -0,0 +1,2 @@ +# Super cool header +This is b.txt. diff --git a/examples/markdown/simple/README.md b/examples/markdown/simple/README.md index 71bab615..627ad37b 100644 --- a/examples/markdown/simple/README.md +++ b/examples/markdown/simple/README.md @@ -1,6 +1,6 @@ # Demonstrate `markdown` Rules -This workspace demonstratest the use of `markdown_check_links_test`. +This workspace demonstrates the use of `markdown_check_links_test`. NOTE: The links in this document are meant to be relative to this child workspace, not the parent workspace. Hence, if you navigated here from the parent workspace, the absolute paths (i.e.,