Skip to content

Commit ec24c9f

Browse files
committed
1 parent 59ca2cb commit ec24c9f

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

bazel/WORKSPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Marker that this folder is the root of a Bazel workspace.

bazel/rules_tutorial/BUILD

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
load("//:foo.bzl", "foo_binary")
2+
3+
print("BUILD file")
4+
5+
foo_binary(
6+
name = "bin1",
7+
username = "x",
8+
)
9+
10+
foo_binary(
11+
name = "bin2",
12+
other = ":bin1",
13+
username = "y",
14+
)

bazel/rules_tutorial/WORKSPACE

Whitespace-only changes.

bazel/rules_tutorial/foo.bzl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
def _foo_binary_impl(ctx):
2+
print("analyzing", ctx.label)
3+
if ctx.attr.other != None:
4+
print("ctx.attr.other.files", ctx.attr.other.files)
5+
print("ctx.file.other", ctx.file.other)
6+
if ctx.file.other != None:
7+
print("dir(ctx.file.other)", dir(ctx.file.other))
8+
print("ctx.file.other.basename", ctx.file.other.basename)
9+
print("ctx.file.other.dirname", ctx.file.other.dirname)
10+
print("ctx.file.other.extension", ctx.file.other.extension)
11+
print("ctx.file.other.is_directory", ctx.file.other.is_directory)
12+
print("ctx.file.other.is_source", ctx.file.other.is_source)
13+
print("ctx.file.other.owner", ctx.file.other.owner)
14+
print("ctx.file.other.path", ctx.file.other.path)
15+
print("ctx.file.other.root", ctx.file.other.root)
16+
print("ctx.file.other.short_path", ctx.file.other.short_path)
17+
# print("ctx.file.other.tree_relative_path", ctx.file.other.tree_relative_path)
18+
19+
out = ctx.actions.declare_file(ctx.label.name)
20+
ctx.actions.write(
21+
output = out,
22+
content = "Hello, %s!\n" % ctx.attr.username,
23+
)
24+
return [DefaultInfo(files = depset([out]))]
25+
26+
foo_binary = rule(
27+
implementation = _foo_binary_impl,
28+
attrs = {
29+
"username": attr.string(),
30+
"other": attr.label(allow_single_file = True),
31+
},
32+
)
33+
34+
print("bzl file evaluation")

0 commit comments

Comments
 (0)