-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add an e2e to test copy actions (#665)
- Loading branch information
Showing
10 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../.bazeliskrc |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../.bazelversion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
load("@bazel_skylib//rules:build_test.bzl", "build_test") | ||
load(":copy.bzl", "simple_copy_file") | ||
|
||
simple_copy_file( | ||
name = "copy", | ||
src = "foo.txt", | ||
out = "bar.txt", | ||
) | ||
|
||
build_test( | ||
name = "test", | ||
targets = [":copy"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module( | ||
version = "0.0.0", | ||
compatibility_level = 1, | ||
) | ||
|
||
bazel_dep(name = "bazel_skylib", version = "1.5.0") | ||
bazel_dep(name = "aspect_bazel_lib", version = "0.0.0") | ||
local_path_override( | ||
module_name = "aspect_bazel_lib", | ||
path = "../..", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "bazel_skylib", | ||
sha256 = "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz", | ||
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz", | ||
], | ||
) | ||
|
||
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") | ||
|
||
bazel_skylib_workspace() | ||
|
||
local_repository( | ||
name = "aspect_bazel_lib", | ||
path = "../..", | ||
) | ||
|
||
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "register_coreutils_toolchains") | ||
|
||
aspect_bazel_lib_dependencies() | ||
|
||
# Registering coreutils is required under WORKSPACE for the copy action to work | ||
# Under bzlmod, this is done automatically by just depending on the bazel-lib module. | ||
register_coreutils_toolchains() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Rule that uses copy actions""" | ||
|
||
load("@aspect_bazel_lib//lib:copy_file.bzl", "COPY_FILE_TOOLCHAINS", "copy_file_action") | ||
|
||
def _simple_copy_file_impl(ctx): | ||
if len(ctx.files.src) != 1: | ||
fail("src must be a single file") | ||
if ctx.files.src[0].is_directory: | ||
fail("cannot use copy_file on a directory; try copy_directory instead") | ||
|
||
copy_file_action(ctx, ctx.files.src[0], ctx.outputs.out) | ||
|
||
files = depset(direct = [ctx.outputs.out]) | ||
runfiles = ctx.runfiles(files = [ctx.outputs.out]) | ||
|
||
return [DefaultInfo(files = files, runfiles = runfiles)] | ||
|
||
simple_copy_file = rule( | ||
implementation = _simple_copy_file_impl, | ||
provides = [DefaultInfo], | ||
attrs = { | ||
"src": attr.label(mandatory = True, allow_files = True), | ||
"out": attr.output(mandatory = True), | ||
}, | ||
toolchains = COPY_FILE_TOOLCHAINS, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bar |