-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fall back to native rules if possible #10
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,21 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""sh_binary rule definition.""" | ||
|
||
load(":sh_executable.bzl", "make_sh_executable_rule") | ||
|
||
visibility("//shell") | ||
|
||
sh_binary = make_sh_executable_rule(executable = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""sh_library rule definition.""" | ||
|
||
visibility("//shell") | ||
|
||
def _sh_library_impl(ctx): | ||
transitive_files = [] | ||
for target in ctx.attr.srcs: | ||
transitive_files.append(target[DefaultInfo].files) | ||
for target in ctx.attr.deps: | ||
transitive_files.append(target[DefaultInfo].files) | ||
for target in ctx.attr.data: | ||
transitive_files.append(target[DefaultInfo].files) | ||
files = depset(transitive = transitive_files) | ||
|
||
runfiles = ctx.runfiles(transitive_files = files, collect_default = True) | ||
|
||
instrumented_files_info = coverage_common.instrumented_files_info( | ||
ctx, | ||
source_attributes = ["srcs"], | ||
dependency_attributes = ["deps", "data"], | ||
) | ||
|
||
return [ | ||
DefaultInfo( | ||
files = files, | ||
runfiles = runfiles, | ||
), | ||
instrumented_files_info, | ||
] | ||
|
||
sh_library = rule( | ||
_sh_library_impl, | ||
doc = """ | ||
<p> | ||
The main use for this rule is to aggregate together a logical | ||
"library" consisting of related scripts—programs in an | ||
interpreted language that does not require compilation or linking, | ||
such as the Bourne shell—and any data those programs need at | ||
run-time. Such "libraries" can then be used from | ||
the <code>data</code> attribute of one or | ||
more <code>sh_binary</code> rules. | ||
</p> | ||
|
||
<p> | ||
You can use the <a href="${link filegroup}"><code>filegroup</code></a> rule to aggregate data | ||
files. | ||
</p> | ||
|
||
<p> | ||
In interpreted programming languages, there's not always a clear | ||
distinction between "code" and "data": after all, the program is | ||
just "data" from the interpreter's point of view. For this reason | ||
this rule has three attributes which are all essentially equivalent: | ||
<code>srcs</code>, <code>deps</code> and <code>data</code>. | ||
The current implementation does not distinguish between the elements of these lists. | ||
All three attributes accept rules, source files and generated files. | ||
It is however good practice to use the attributes for their usual purpose (as with other rules). | ||
</p> | ||
|
||
<h4 id="sh_library_examples">Examples</h4> | ||
|
||
<pre class="code"> | ||
sh_library( | ||
name = "foo", | ||
data = [ | ||
":foo_service_script", # an sh_binary with srcs | ||
":deploy_foo", # another sh_binary with srcs | ||
], | ||
) | ||
</pre> | ||
""", | ||
attrs = { | ||
"srcs": attr.label_list( | ||
allow_files = True, | ||
doc = """ | ||
The list of input files. | ||
<p> | ||
This attribute should be used to list shell script source files that belong to | ||
this library. Scripts can load other scripts using the shell's <code>source</code> | ||
or <code>.</code> command. | ||
</p> | ||
""", | ||
), | ||
"data": attr.label_list( | ||
allow_files = True, | ||
flags = ["SKIP_CONSTRAINTS_OVERRIDE"], | ||
), | ||
"deps": attr.label_list( | ||
allow_rules = ["sh_library"], | ||
doc = """ | ||
The list of "library" targets to be aggregated into this target. | ||
See general comments about <code>deps</code> | ||
at <a href="${link common-definitions#typical.deps}">Typical attributes defined by | ||
most build rules</a>. | ||
<p> | ||
This attribute should be used to list other <code>sh_library</code> rules that provide | ||
interpreted program source code depended on by the code in <code>srcs</code>. The files | ||
provided by these rules will be present among the <code>runfiles</code> of this target. | ||
</p> | ||
""", | ||
), | ||
}, | ||
) |
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,38 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""sh_test rule definition.""" | ||
|
||
load(":sh_executable.bzl", "make_sh_executable_rule") | ||
|
||
visibility("//shell") | ||
|
||
sh_test = make_sh_executable_rule( | ||
test = True, | ||
fragments = ["coverage"], | ||
extra_attrs = { | ||
"_lcov_merger": attr.label( | ||
cfg = "exec", | ||
default = configuration_field(fragment = "coverage", name = "output_generator"), | ||
executable = True, | ||
), | ||
# Add the script as an attribute in order for sh_test to output code coverage results for | ||
# code covered by CC binaries invocations. | ||
"_collect_cc_coverage": attr.label( | ||
cfg = "exec", | ||
default = "@bazel_tools//tools/test:collect_cc_coverage", | ||
executable = 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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will also limit doc generation in Bazel, because I need to point it to the actual rules.