Commit Graph

88 Commits

Author SHA1 Message Date
Ara Nguyen 505e1bc3aa
Update common_settings.bzl (#552)
add scope attr to string_setting
2024-11-06 17:52:21 -05:00
Ara Nguyen e853fd4ed6
adding scope attributes for starlark flags (#546)
Working towards docs.google.com/document/d/1wIMpW1DsA0CEOs0bo9-maWbNEz4eAAyoIH59lJlZt_o/edit?tab=t.0#heading=h.epjv6353d2y8
2024-10-30 17:40:10 -04:00
aiuto 5c071b5006
Add test_deps to rules/private (#534)
This pattern was missed when rules/private was added.
2024-08-09 08:40:50 -04:00
Alexandre Rostovtsev 43c6185e7e
Make only root test_deps externally visible (#508)
All other test_deps targets implicitly require the root BUILD file
for the `license` target for their default_applicable_licenses;
therefore, users should only depend on the root test_deps target.
2024-07-15 17:57:10 +00:00
aiuto da7ba2d23c
Strip compatible_with from bzl_library rules (#522)
* Wrap bzl_library in a macro so that we can force off some
global attribures that are never appropriate for BUILD files.

Removes:
- *_compatible_with
- features

* cdate

* linty

* linty

* more lint
2024-07-15 19:50:23 +02:00
Matt 1e594dc4a6
Fix distribution tarballs to include directory rules. (#520) 2024-06-03 10:03:48 +02:00
Matt 28d6034185
fix: Fix a bug in globs when middle is non-empty, but right is empty. (#516)
For example, if you try to match `*a*` against `ab`, then we check:
```
left = ""
middle = "a"
right = ""
middle in name[len(left):len(name)-len(right)]:
"a" in "ab"[len(""):len(name)-len("")]:
"a" in "ab"[0:-0]
"a" in "" => False
```

The problem here is that negative numbers in python index from the back, but -0 is not a negative number, so it always results in the empty string.
2024-05-31 07:30:03 +00:00
Matt 9b26156bbb
fix: Ensure directories work when the package is empty (#515)
Previously, I was getting the error
`Expected external/_main~toolchains~toolchain_sdk/usr/bin/clang++ to start with one of ["external/_main~toolchains~toolchain_sdk//", "bazel-out/k8-dbg/bin/external/_main~toolchains~toolchain_sdk/"]`
2024-05-31 09:26:49 +02:00
Matt f351bedd9a
Remove empty file that was accidentally not deleted. (#513) 2024-05-29 08:28:31 +02:00
Matt 4d37916e68
Minor cleanup of directory rules. (#512)
They were previously missing default_applicable_licenses.
2024-05-29 08:09:09 +02:00
Matt f3c0026ec6
Copy rules_directory's globs to bazel-skylib. (#511)
Original implementation is at https://github.com/matts1/rules_directory
2024-05-29 07:29:32 +02:00
Matt a464f69faa
Copy rules_directory to bazel-skylib. (#510)
Original implementation is at https://github.com/matts1/rules_directory
2024-05-29 07:24:27 +02:00
Alexandre Rostovtsev 0d43695bd5
Re-add `licenses()` - internal license checker still requires it :/ (#506)
And take the opportunity to fix default_applicable_licenses in the gazelle plugin
2024-05-02 14:38:05 -04:00
Alexandre Rostovtsev a16ebb4dca
Add `default_applicable_license` and remove obsolete `licenses()` in all BUILD files (#504) 2024-05-01 17:24:18 -04:00
UebelAndre 16bf90d4ae
Support modern location expansions for run_binary (#490)
A common point of confusion I see around `run_binary` is that it's hard coded to only expand `$(location` values which in codebases I work in are otherwise completely eliminated due to it being described as "legacy"

> location: A synonym for either execpath or rootpath, depending on the attribute being expanded. This is legacy pre-Starlark behavior and not recommended unless you really know what it does for a particular rule. See [#2475](https://github.com/bazelbuild/bazel/issues/2475#issuecomment-339318016) for details.

If `execpath` is used instead as the appropriate alternative, the rule does no do any expansion and fails the action. This change adds support for expanding all available patterns whenever they're provided.
2024-04-30 17:19:34 -04:00
Ted Pudlik 09b1079228
Make `out` on `native_binary` optional (#474)
Fixes: #399
2024-04-24 15:40:31 -04:00
Alexandre Rostovtsev 054ebf58f0
expand_template: do not output_to_genfiles (#493)
output_to_genfiles is deprecated unless needed for backwards compatibility
with legacy rules (see https://bazel.build/rules/lib/globals/bzl#rule)
2024-03-20 17:56:10 -04:00
kotlaja 1a1ee6c230
Modify actions in order not to need toolchain param (#478) 2023-11-16 15:04:55 +01:00
kotlaja 0171c69e5c
Modify actions in order not to need `toolchain` param (#455)
All actions which use tool or executable for which is not clear if it comes from a toolchain, must set a `toolchain` parameter ( migration of Automatic Exec Groups). 

As we discussed internally, I've modified actions so that it's recognised that tools are not from the toolchain. Hence, there will not be an error which states `Couldn't identify if tools are from implicit dependencies or a toolchain. Please set the toolchain parameter. If you're not using a toolchain, set it to 'None'.`. Hence, no need for the toolchain parameter.
2023-08-28 14:39:43 -04:00
Fabian Meumertzheim 8386b9d32b
Expose int- and string-valued build settings as Make variables (#440)
While build settings allow for much cleaner flag and setting definitions
than `--define`, they have the major drawback that rules need to provide
dedicated support for them, which isn't the case for native and most
community-maintained rules.

This change attempts to bridge this gap by optionally exposing the value
of the common build setting types as Make variables to rules that depend
on them via the `toolchains` attribute: If the new `make_variable`
attribute is set, the value of the flag or setting is available as a
Make variable with that.

Consistency with pre-defined Make variables is enforced by limiting the
character set for `make_variable` values to `[A-Z0-9_]`. The new
attribute is also only added to int- and string-valued build settings as
the other types lack a canonical stringification.

Co-authored-by: Xùdōng Yáng <wyverald@gmail.com>
2023-08-22 19:41:36 +00:00
UebelAndre 0a34b7edf6
Avoid building build_test deps unnecessarily (#448)
I ran into an issue where I had a `build_test` that was only compatible with a particular platform. I had annotated the target with `target_compatible_with` but continued to get builds on the incompatible platform. This came down to my `bazel test //...` invocation picking up the `{name}_{idx}__deps` targets and building the dependency anyway. This change updates these targets to account for newer common attributes and tags them as manual so they're only built when the user facing test target is built.
2023-05-31 11:37:12 -04:00
Vertexwahn 2f0bb4cec0
Fix spelling (#445) 2023-04-26 21:55:09 -04:00
Alexandre Rostovtsev bc112d41fd
Bump stardoc dep to unbreak build with --experimental_enable_bzlmod (#398) 2022-10-03 05:13:46 -04:00
Xùdōng Yáng 61d9c62833
Make settings error message more friendly (#394)
By stripping leading '@'s from labels in the main repo. So it talks about the flag '//foo:bar' instead of the flag '@//foo:bar'.
2022-09-05 16:17:20 -04:00
Alexandre Rostovtsev 908bf1431d
Allow sandboxing for copy_* and fix copy_directory tests (#392)
After some thought, I have to say that forcing a local strategy for
copy_file/copy_directory is inappropriate. The point of a sandbox is to
catch hermeticity bugs; disabling the sandbox may be useful for
performance, but it's up to the user to do it if they trust us - and
they can do it via flag. The default should be paranoia and safety.

And on the subject of strategies - using a genrule to create an empty
directory fails in environments where genrules run remote by default
(and thus, copy_directory tests fail). We could, of course, set local=1,
but that disables the sandbox and causes scary warnings. Instead, add a
proper empty_directory rule to test with.
2022-09-02 10:42:43 -04:00
Alexandre Rostovtsev 42abf5cbf2
Documentation fixes (#391) 2022-09-01 15:29:04 -04:00
Alexandre Rostovtsev d7e9dbb31f
Add missing docs and doc links; update bazel.build links (#387) 2022-09-01 08:19:43 -04:00
Alexandre Rostovtsev 872e9b06e1
Fix diff_test on Windows with --enable_runfiles --nolegacy_external_runfiles (#378)
And make sure our test suite exercises both manifest-based and runfiles-based
code paths for diff_test.

Fixes #376.
2022-07-15 13:07:09 -04:00
Derek Cormier a501641dae
Use stricter execution requirements for copy actions (#372) 2022-06-10 16:23:43 +02:00
Derek Cormier 207acb3850
Add copy_directory rule (#366) 2022-06-01 09:58:09 +02:00
Geoffrey Martin-Noble a6f17ab1fe
Switch native_binary/test to use symlinks (#340)
A copy should not be necessary here. The symlink action falls back to
copying when symlinks are not enabled on windows, which I think would 
be the only problem with using symlinks:
https://docs.bazel.build/versions/4.2.2/command-line-reference.html#flag--windows_enable_symlinks
2022-05-17 07:26:16 -04:00
Fabian Meumertzheim a832b8d717
copy_file: Do not add non-executables to default_runfiles (#326)
copy_file currently includes the copied file in its runfiles even if it is not executable, which makes every rule depending on it have the file as a runfile (e.g. a `cc_library` depending on a copied header file via the hdrs attribute).

In an ideal world, according to https://docs.bazel.build/versions/main/skylark/rules.html#runfiles-features-to-avoid, `copy_file` would not need to specify any runfiles in the `DefaultInfo` it returns - specifying `files` should suffice. However, due to the existence of rules with legacy behavior, this would break compatibility (actually, already with `sh_test` in skylib's unit tests).

As a compromise that preserves compatibility with legacy rules but nevertheless cleans up the runfiles tree of depending rules, use the `data_runfiles` attribute of `DefaultInfo` if the copied file is not executable.
2022-05-16 17:27:25 -04:00
Alexandre Rostovtsev 67bfa0ce4d
Switch run_binary to cfg = "exec" to fix buildifier failure (#367) 2022-04-29 13:44:59 -04:00
Alexandre Rostovtsev d54e8a70ce
Remove unnecessary wrapper macro for expand_template rule (#365)
Followup to #330: remove the wrapper macro and export the rule directly; the macro
does not serve any useful function. As a side effect, this fixes the inability to
set tags etc., since the macro did not support **kwargs.
2022-04-06 15:21:13 -04:00
Alexandre Rostovtsev de3035d605
Properly shell-quote diff_test's failure_message in bash (and document the failure_message attribute) (#364)
Addresses #344 for Unix; #363 is needed as prerequisite for the corresponding Windows fix.
2022-04-06 15:16:14 -04:00
Geoffrey Martin-Noble 6abad3de5f
Build native_binary/test src in correct configuration (#341)
This attribute is incorrectly being built in the host configuration when
(like any test) it will run in the target configuration. This means that
cross compilation will be broken and options that differ between host
and target (e.g. `NDEBUG`) will not be as set by the user.

I confirmed that without this fix, a test binary with `assert(false)`
passes when run under `native_test`.

Additionally, the use of `allow_single_file` precludes rules that return
multiple files in their DefaultInfo (like `py_binary`). Instead, we can
use `allow_files` and access via `ctx.executable`.
2022-04-05 17:09:55 -04:00
Vertexwahn 2a87d4a62a
Add expand_template rule (#330)
Resolves: https://github.com/bazelbuild/bazel-skylib/issues/191

An example of how this can be useful can be found here: https://github.com/catchorg/Catch2/pull/2387/files

Could be also helpful here: 8587f4eed1/BUILD.bazel (L21)
2022-04-01 18:07:48 -04:00
Geoffrey Martin-Noble 8e2ba6e9df
Fix runfiles in native_binary/native_test (#339)
The current implementation misses the runfiles from the binary itself
since the attribute for it is called `src` not `srcs` and it makes use
of the discouraged `collect_data` and `collect_default` parameters which
depend on hardcoded attribute names.
2022-03-29 17:41:48 -04:00
Alexandre Rostovtsev 898cd6ddff
Remove unused, empty //rules:bins filegroup, allowing us to simplify distribution/BUILD (#359)
//rules:bins has not been used since 14f17ae7f7

Alternative to https://github.com/bazelbuild/bazel-skylib/pull/358
2022-03-10 07:41:11 -05:00
Alexandre Rostovtsev 1e1c324391
Fix linter warnings with new buildifier version. (#349) 2022-02-10 14:50:56 -05:00
Geoffrey Martin-Noble ecc11f9a4c
Fix name arg documentation for native_binary (#338) 2022-01-12 11:28:43 -05:00
Yesudeep Mangalapilly 8e923ca4b9
Use more portable `#!/usr/bin/env bash` shebang instead of hardcoded /bin/bash. (#329) 2021-10-25 09:12:41 -04:00
Thaler Benedek 43a545a67e
Make diff_test work on windows with --enable_runfiles (#314) 2021-09-24 10:49:07 -04:00
Mansur 14f17ae7f7
Windows support for build_test (#302) 2021-09-24 10:43:30 -04:00
Alex Eagle df3c9e2735
diff_test: add ability for caller to specify a message printed on fai… (#307)
Useful for the use case of a pair of .test and .update targets for checked-in golden files
2021-08-18 11:23:43 -04:00
aiuto fd75066f15
update links to bazel docs (#306) 2021-06-16 13:00:06 -04:00
Alexandre Rostovtsev 7b859037a6
to_json/to_proto methods on structs are deprecated and will be removed (#295) 2021-05-03 12:27:40 -04:00
Jonathan B Coe 16de038c48
Add missing bzl_library for analysis_test.bzl (#262) 2020-08-10 14:35:04 -04:00
Yannic 8f3151fb4a
copy_file: Add parameter to allow symlinks (#252)
* copy_file: Add parameter to allow symlinks

This change adds a new parameter `allow_symlinks` to `copy_file` that
allows the action to create a symlink instead of doing an expensive
copy if the execution platform (host) allows it.

Updates #248

* Update docs

* Refactor `is_executable` into attribute

* Fix typo

* s/_impl/_copy_file_impl/
2020-07-10 14:08:02 -04:00
Andrew Z Allen d35e8d7bc6
Create Gazelle language for Starlark (#251) 2020-06-26 17:04:12 +02:00