Skip to content

Commit

Permalink
Even more text block cleanup
Browse files Browse the repository at this point in the history
Follow-up to unknown commit

I updated the refactoring to support re-formatting code that has already been migrated to text blocks, and also to support string concatenation, and made a few more cleanups on these files.

PiperOrigin-RevId: 621546423
Change-Id: Ifef4a0ab788e372cd783bb1e2ca29b558f465c12
  • Loading branch information
cushon authored and Kila2 committed May 13, 2024
1 parent 8ef66af commit 10148b6
Show file tree
Hide file tree
Showing 9 changed files with 566 additions and 399 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def _impl(ctx):
"_tool": attr.label(
default = "//toolchain:b_tool",
executable = True,
cfg = "exec"),
cfg = "exec",
),
},
)
""");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def _aspect_impl(target, ctx):
aspect1 = aspect(
_aspect_impl,
attr_aspects = ["deps"],
attrs = {"param": attr.string(values = ["a", "b"])}
attrs = {"param": attr.string(values = ["a", "b"])},
)
aspect2 = aspect(_aspect_impl, attr_aspects = ["deps"])
Expand All @@ -776,7 +776,7 @@ def _rule_impl(ctx):
injector1 = rule(
_rule_impl,
attrs = {"deps": attr.label_list(aspects = [aspect1]), "param": attr.string()}
attrs = {"deps": attr.label_list(aspects = [aspect1]), "param": attr.string()},
)
injector2 = rule(_rule_impl, attrs = {"deps": attr.label_list(aspects = [aspect2])})
null_rule = rule(_rule_impl, attrs = {"deps": attr.label_list()})
Expand Down Expand Up @@ -1304,26 +1304,31 @@ public void topLevelConflictDetected() throws Exception {
public void conflictBetweenTargetAndAspect() throws Exception {
scratch.file(
"foo/aspect.bzl",
"def _aspect_impl(target, ctx):",
" outfile = ctx.actions.declare_file('conflict.out')",
" ctx.actions.run_shell(",
" outputs = [outfile],",
" progress_message = 'Action for aspect',",
" command = 'echo \"aspect\" > ' + outfile.path,",
" )",
" return [OutputGroupInfo(files = [outfile])]",
"",
"def _rule_impl(ctx):",
" outfile = ctx.actions.declare_file('conflict.out')",
" ctx.actions.run_shell(",
" outputs = [outfile],",
" progress_message = 'Action for target',",
" command = 'echo \"target\" > ' + outfile.path,",
" )",
" return [DefaultInfo(files = depset([outfile]))]",
"my_aspect = aspect(implementation = _aspect_impl)",
"my_rule = rule(implementation = _rule_impl, attrs = {'deps' : attr.label_list(aspects ="
+ " [my_aspect])})");
"""
def _aspect_impl(target, ctx):
outfile = ctx.actions.declare_file("conflict.out")
ctx.actions.run_shell(
outputs = [outfile],
progress_message = "Action for aspect",
command = 'echo "aspect" > ' + outfile.path,
)
return [OutputGroupInfo(files = [outfile])]
def _rule_impl(ctx):
outfile = ctx.actions.declare_file("conflict.out")
ctx.actions.run_shell(
outputs = [outfile],
progress_message = "Action for target",
command = 'echo "target" > ' + outfile.path,
)
return [DefaultInfo(files = depset([outfile]))]
my_aspect = aspect(implementation = _aspect_impl)
my_rule = rule(
implementation = _rule_impl,
attrs = {"deps": attr.label_list(aspects = [my_aspect])},
)
""");
scratch.file(
"foo/BUILD",
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def _impl(ctx):
"_tool": attr.label(
default = "//toolchain:b_tool",
executable = True,
cfg = "exec"),
cfg = "exec",
),
},
)
""");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ public void testInputAndOutputTransition() throws Exception {
"test/transitions.bzl",
"""
def _impl(settings, attr):
foo = settings["//command_line_option:foo"].replace("pre", "post")
return {
"//command_line_option:foo":
settings["//command_line_option:foo"].replace("pre", "post")
"//command_line_option:foo": foo,
}
my_transition = transition(
Expand Down Expand Up @@ -1792,10 +1792,15 @@ def _transition_impl(settings, attr):
""");
scratch.file(
"test/build_settings.bzl",
"def _impl(ctx):",
" return []",
"string_flag = rule(implementation = _impl, build_setting = config.string(flag=True,"
+ " allow_multiple=True))");
"""
def _impl(ctx):
return []
string_flag = rule(
implementation = _impl,
build_setting = config.string(flag = True, allow_multiple = True),
)
""");
scratch.file(
"test/BUILD",
"""
Expand Down Expand Up @@ -1840,10 +1845,15 @@ def _transition_impl(settings, attr):
""");
scratch.file(
"test/build_settings.bzl",
"def _impl(ctx):",
" return []",
"string_flag = rule(implementation = _impl, build_setting = config.string(flag=True,"
+ " allow_multiple=True))");
"""
def _impl(ctx):
return []
string_flag = rule(
implementation = _impl,
build_setting = config.string(flag = True, allow_multiple = True),
)
""");
scratch.file(
"test/BUILD",
"""
Expand Down Expand Up @@ -1892,10 +1902,15 @@ def _transition_impl(settings, attr):
""");
scratch.file(
"test/build_settings.bzl",
"def _impl(ctx):",
" return []",
"string_flag = rule(implementation = _impl, build_setting = config.string(flag=True,"
+ " allow_multiple=True))");
"""
def _impl(ctx):
return []
string_flag = rule(
implementation = _impl,
build_setting = config.string(flag = True, allow_multiple = True),
)
""");
scratch.file(
"test/BUILD",
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,27 +158,33 @@ public void setupMockClient(MockToolsConfig config, List<String> workspaceConten
}
config.create(
"embedded_tools/tools/jdk/launcher_flag_alias.bzl",
"_providers = [CcInfo, cc_common.launcher_provider]",
"def _impl(ctx):",
" if not ctx.attr._launcher:",
" return None",
" launcher = ctx.attr._launcher",
" providers = [ctx.attr._launcher[p] for p in _providers]",
" providers.append(DefaultInfo(files = launcher[DefaultInfo].files, runfiles ="
+ " launcher[DefaultInfo].default_runfiles))",
" return providers",
"launcher_flag_alias = rule(",
" implementation = _impl,",
" attrs = {",
" '_launcher': attr.label(",
" default = configuration_field(",
" fragment = 'java',",
" name = 'launcher',",
" ),",
" providers = _providers,",
" ),",
" },",
")");
"""
_providers = [CcInfo, cc_common.launcher_provider]
def _impl(ctx):
if not ctx.attr._launcher:
return None
launcher = ctx.attr._launcher
providers = [ctx.attr._launcher[p] for p in _providers]
providers.append(DefaultInfo(
files = launcher[DefaultInfo].files,
runfiles = launcher[DefaultInfo].default_runfiles,
))
return providers
launcher_flag_alias = rule(
implementation = _impl,
attrs = {
"_launcher": attr.label(
default = configuration_field(
fragment = "java",
name = "launcher",
),
providers = _providers,
),
},
)
""");
config.create(
"embedded_tools/tools/jdk/BUILD",
"""
Expand Down Expand Up @@ -847,17 +853,20 @@ def _impl(ctx):
""");
config.create(
"embedded_tools/tools/build_defs/build_info/BUILD",
"load('//tools/build_defs/build_info:bazel_cc_build_info.bzl'," + " 'bazel_cc_build_info')",
"load('//tools/build_defs/build_info:bazel_java_build_info.bzl',"
+ " 'bazel_java_build_info')",
"bazel_cc_build_info(",
" name = 'cc_build_info',",
" visibility = ['//visibility:public'],",
")",
"bazel_java_build_info(",
" name = 'java_build_info',",
" visibility = ['//visibility:public'],",
")");
"""
load("//tools/build_defs/build_info:bazel_cc_build_info.bzl", "bazel_cc_build_info")
load("//tools/build_defs/build_info:bazel_java_build_info.bzl", "bazel_java_build_info")
bazel_cc_build_info(
name = "cc_build_info",
visibility = ["//visibility:public"],
)
bazel_java_build_info(
name = "java_build_info",
visibility = ["//visibility:public"],
)
""");
config.create(
"embedded_tools/tools/build_defs/repo/utils.bzl",
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,23 @@ def _impl(ctx):
write("foo/filler");
write(
"foo/BUILD",
"load('//foo:pruning.bzl', 'build_rule')",
"build_rule(name = 'foo', filler = ':filler', inputs = ':in', executable = ':unused.sh')",
"genrule(name = 'gen', outs = ['in'], tools = [':gen_run.sh'], cmd = '$(location"
+ " :gen_run.sh) && touch $@')");
"""
load("//foo:pruning.bzl", "build_rule")
build_rule(
name = "foo",
executable = ":unused.sh",
filler = ":filler",
inputs = ":in",
)
genrule(
name = "gen",
outs = ["in"],
cmd = "$(location :gen_run.sh) && touch $@",
tools = [":gen_run.sh"],
)
""");
buildTarget("//foo:foo");
bugReporter.assertNoExceptions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,52 +392,52 @@ def proto_lang_toolchain(**kargs):
config.create(
"third_party/bazel_rules/rules_proto/proto/proto_toolchain_rule.bzl",
"""
ProtoLangToolchainInfo = proto_common_do_not_use.ProtoLangToolchainInfo
def _impl(ctx):
return [
DefaultInfo(
files = depset(),
runfiles = ctx.runfiles(),
),
platform_common.ToolchainInfo(
proto = ProtoLangToolchainInfo(
out_replacement_format_flag = ctx.attr.command_line,
output_files = ctx.attr.output_files,
plugin = None,
runtime = None,
proto_compiler = ctx.attr.proto_compiler.files_to_run,
protoc_opts = ctx.fragments.proto.experimental_protoc_opts,
progress_message = ctx.attr.progress_message,
mnemonic = ctx.attr.mnemonic,
allowlist_different_package = None,
toolchain_type =
"//third_party/bazel_rules/rules_proto/proto:toolchain_type",
),
),
]
proto_toolchain = rule(
_impl,
attrs = {
"progress_message": attr.string(default =
"Generating Descriptor Set proto_library %{label}"),
"mnemonic": attr.string(default = "GenProtoDescriptorSet"),
"command_line": attr.string(default = "--descriptor_set_out=%s"),
"output_files": attr.string(
values = ["single", "multiple", "legacy"],
default = "single",
),
"proto_compiler": attr.label(
cfg = "exec",
executable = True,
allow_files = True,
),
},
provides = [platform_common.ToolchainInfo],
fragments = ["proto"],
)
""");
ProtoLangToolchainInfo = proto_common_do_not_use.ProtoLangToolchainInfo
def _impl(ctx):
return [
DefaultInfo(
files = depset(),
runfiles = ctx.runfiles(),
),
platform_common.ToolchainInfo(
proto = ProtoLangToolchainInfo(
out_replacement_format_flag = ctx.attr.command_line,
output_files = ctx.attr.output_files,
plugin = None,
runtime = None,
proto_compiler = ctx.attr.proto_compiler.files_to_run,
protoc_opts = ctx.fragments.proto.experimental_protoc_opts,
progress_message = ctx.attr.progress_message,
mnemonic = ctx.attr.mnemonic,
allowlist_different_package = None,
toolchain_type =
"//third_party/bazel_rules/rules_proto/proto:toolchain_type",
),
),
]
proto_toolchain = rule(
_impl,
attrs = {
"progress_message": attr.string(default =
"Generating Descriptor Set proto_library %{label}"),
"mnemonic": attr.string(default = "GenProtoDescriptorSet"),
"command_line": attr.string(default = "--descriptor_set_out=%s"),
"output_files": attr.string(
values = ["single", "multiple", "legacy"],
default = "single",
),
"proto_compiler": attr.label(
cfg = "exec",
executable = True,
allow_files = True,
),
},
provides = [platform_common.ToolchainInfo],
fragments = ["proto"],
)
""");
config.create(
"third_party/bazel_rules/rules_proto/proto/proto_lang_toolchain.bzl",
"""
Expand Down
Loading

0 comments on commit 10148b6

Please sign in to comment.