Skip to content

Commit 936ae08

Browse files
committed
Enables the disabling of automatic workspace edits
While modifying the user’s workspace can help with the ergonomics of first time setup, it should be possible to disable these non-essential options.
1 parent eac41ee commit 936ae08

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

refresh.template.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,8 +1052,12 @@ def _ensure_cwd_is_workspace_root():
10521052

10531053
def main():
10541054
_ensure_cwd_is_workspace_root()
1055-
_ensure_gitignore_entries_exist()
1056-
_ensure_external_workspaces_link_exists()
1055+
1056+
if {update_gitignore}:
1057+
_ensure_gitignore_entries_exist()
1058+
1059+
if {link_external}:
1060+
_ensure_external_workspaces_link_exists()
10571061

10581062
target_flag_pairs = [
10591063
# Begin: template filled by Bazel

refresh_compile_commands.bzl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ refresh_compile_commands(
4949
# exclude_headers = "external",
5050
# Still not fast enough?
5151
# Make sure you're specifying just the targets you care about by setting `targets`, above.
52+
53+
# refresh_compile_commands will automatically update .git/info/exclude by default.
54+
# You can disable this behavior with update_gitignore = False.
55+
56+
# refresh_compile_commands will automatically create a symlink for external workspaces at /external.
57+
# You can disable this behavior with link_external = False.
5258
```
5359
"""
5460

@@ -63,6 +69,8 @@ def refresh_compile_commands(
6369
targets = None,
6470
exclude_headers = None,
6571
exclude_external_sources = False,
72+
update_gitignore = True,
73+
link_external = True,
6674
**kwargs): # For the other common attributes. Tags, compatible_with, etc. https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes.
6775
# Convert the various, acceptable target shorthands into the dictionary format
6876
# In Python, `type(x) == y` is an antipattern, but [Starlark doesn't support inheritance](https://bazel.build/rules/language), so `isinstance` doesn't exist, and this is the correct way to switch on type.
@@ -88,7 +96,15 @@ def refresh_compile_commands(
8896

8997
# Generate the core, runnable python script from refresh.template.py
9098
script_name = name + ".py"
91-
_expand_template(name = script_name, labels_to_flags = targets, exclude_headers = exclude_headers, exclude_external_sources = exclude_external_sources, **kwargs)
99+
_expand_template(
100+
name = script_name,
101+
labels_to_flags = targets,
102+
exclude_headers = exclude_headers,
103+
exclude_external_sources = exclude_external_sources,
104+
update_gitignore = update_gitignore,
105+
link_external = link_external,
106+
**kwargs
107+
)
92108

93109
# Combine them so the wrapper calls the main script
94110
native.py_binary(
@@ -115,6 +131,8 @@ def _expand_template_impl(ctx):
115131
" {windows_default_include_paths}": "\n".join([" %r," % path for path in find_cpp_toolchain(ctx).built_in_include_directories]), # find_cpp_toolchain is from https://docs.bazel.build/versions/main/integrating-with-rules-cc.html
116132
"{exclude_headers}": repr(ctx.attr.exclude_headers),
117133
"{exclude_external_sources}": repr(ctx.attr.exclude_external_sources),
134+
"{update_gitignore}": repr(ctx.attr.update_gitignore),
135+
"{link_external}": repr(ctx.attr.link_external),
118136
},
119137
)
120138
return DefaultInfo(files = depset([script]))
@@ -124,6 +142,8 @@ _expand_template = rule(
124142
"labels_to_flags": attr.string_dict(mandatory = True), # string keys instead of label_keyed because Bazel doesn't support parsing wildcard target patterns (..., *, :all) in BUILD attributes.
125143
"exclude_external_sources": attr.bool(default = False),
126144
"exclude_headers": attr.string(values = ["all", "external", ""]), # "" needed only for compatibility with Bazel < 3.6.0
145+
"update_gitignore": attr.bool(default = True),
146+
"link_external": attr.bool(default = True),
127147
"_script_template": attr.label(allow_single_file = True, default = "refresh.template.py"),
128148
# For Windows INCLUDE. If this were eliminated, for example by the resolution of https://github.com/clangd/clangd/issues/123, we'd be able to just use a macro and skylib's expand_template rule: https://github.com/bazelbuild/bazel-skylib/pull/330
129149
# Once https://github.com/bazelbuild/bazel/pull/17108 is widely released, we should be able to eliminate this and get INCLUDE directly. Perhaps for 7.0? Should be released in the sucessor to 6.0

0 commit comments

Comments
 (0)