-
-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
319 additions
and
259 deletions.
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
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
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 |
---|---|---|
@@ -1,23 +1,25 @@ | ||
"""Example of a rule that accesses its attributes.""" | ||
|
||
def _impl(ctx): | ||
# Print debug information about the target. | ||
print("Target {} has {} deps".format(ctx.label, len(ctx.attr.deps))) | ||
# Print debug information about the target. | ||
print("Target {} has {} deps".format(ctx.label, len(ctx.attr.deps))) | ||
|
||
# For each target in deps, print its label and files. | ||
for i, d in enumerate(ctx.attr.deps): | ||
print(" {}. label = {}".format(i+1, d.label)) | ||
# A label can represent any number of files (possibly 0). | ||
print(" files = " + str([f.path for f in d.files.to_list()])) | ||
# For each target in deps, print its label and files. | ||
for i, d in enumerate(ctx.attr.deps): | ||
print(" {}. label = {}".format(i + 1, d.label)) | ||
|
||
# For debugging, consider using `dir` to explore the existing fields. | ||
print(dir(ctx)) # prints all the fields and methods of ctx | ||
print(dir(ctx.attr)) # prints all the attributes of the rule | ||
# A label can represent any number of files (possibly 0). | ||
print(" files = " + str([f.path for f in d.files.to_list()])) | ||
|
||
# For debugging, consider using `dir` to explore the existing fields. | ||
print(dir(ctx)) # prints all the fields and methods of ctx | ||
print(dir(ctx.attr)) # prints all the attributes of the rule | ||
|
||
printer = rule( | ||
implementation=_impl, | ||
attrs={ | ||
implementation = _impl, | ||
attrs = { | ||
# Do not declare "name": It is added automatically. | ||
"number": attr.int(default = 1), | ||
"deps": attr.label_list(allow_files=True), | ||
}) | ||
"deps": attr.label_list(allow_files = True), | ||
}, | ||
) |
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
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 |
---|---|---|
@@ -1,48 +1,54 @@ | ||
FooFiles = provider("transitive_sources") | ||
|
||
def get_transitive_srcs(srcs, deps): | ||
"""Obtain the source files for a target and its transitive dependencies. | ||
"""Obtain the source files for a target and its transitive dependencies. | ||
Args: | ||
srcs: a list of source files | ||
deps: a list of targets that are direct dependencies | ||
Returns: | ||
a collection of the transitive sources | ||
""" | ||
return depset( | ||
Args: | ||
srcs: a list of source files | ||
deps: a list of targets that are direct dependencies | ||
Returns: | ||
a collection of the transitive sources | ||
""" | ||
return depset( | ||
srcs, | ||
transitive = [dep[FooFiles].transitive_sources for dep in deps]) | ||
transitive = [dep[FooFiles].transitive_sources for dep in deps], | ||
) | ||
|
||
def _foo_library_impl(ctx): | ||
trans_srcs = get_transitive_srcs(ctx.files.srcs, ctx.attr.deps) | ||
return [FooFiles(transitive_sources=trans_srcs)] | ||
trans_srcs = get_transitive_srcs(ctx.files.srcs, ctx.attr.deps) | ||
return [FooFiles(transitive_sources = trans_srcs)] | ||
|
||
foo_library = rule( | ||
implementation = _foo_library_impl, | ||
attrs = { | ||
"srcs": attr.label_list(allow_files=True), | ||
"srcs": attr.label_list(allow_files = True), | ||
"deps": attr.label_list(), | ||
}, | ||
) | ||
|
||
def _foo_binary_impl(ctx): | ||
foocc = ctx.executable._foocc | ||
out = ctx.outputs.out | ||
trans_srcs = get_transitive_srcs(ctx.files.srcs, ctx.attr.deps) | ||
srcs_list = trans_srcs.to_list() | ||
ctx.actions.run(executable = foocc, | ||
arguments = [out.path] + [src.path for src in srcs_list], | ||
inputs = srcs_list + [foocc], | ||
outputs = [out]) | ||
foocc = ctx.executable._foocc | ||
out = ctx.outputs.out | ||
trans_srcs = get_transitive_srcs(ctx.files.srcs, ctx.attr.deps) | ||
srcs_list = trans_srcs.to_list() | ||
ctx.actions.run( | ||
executable = foocc, | ||
arguments = [out.path] + [src.path for src in srcs_list], | ||
inputs = srcs_list + [foocc], | ||
outputs = [out], | ||
) | ||
|
||
foo_binary = rule( | ||
implementation = _foo_binary_impl, | ||
attrs = { | ||
"srcs": attr.label_list(allow_files=True), | ||
"srcs": attr.label_list(allow_files = True), | ||
"deps": attr.label_list(), | ||
"_foocc": attr.label(default=Label("//depsets:foocc"), | ||
allow_files=True, executable=True, cfg="host") | ||
"_foocc": attr.label( | ||
default = Label("//depsets:foocc"), | ||
allow_files = True, | ||
executable = True, | ||
cfg = "host", | ||
), | ||
}, | ||
outputs = {"out": "%{name}.out"}, | ||
) | ||
|
Oops, something went wrong.