Skip to content

Commit

Permalink
Allow empty lists to be omitted in more places in toolchain args
Browse files Browse the repository at this point in the history
Reviewed By: zertosh

Differential Revision: D41714656

fbshipit-source-id: 00e10288fc0140491ee279aa070b684bc4eee487
  • Loading branch information
David Tolnay authored and facebook-github-bot committed Dec 5, 2022
1 parent b2b9404 commit f171bf1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 36 deletions.
4 changes: 2 additions & 2 deletions prelude/cxx/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ def _supports_dep_files(ext: CxxExtension.type) -> bool.type:
return True

def _add_compiler_info_flags(compiler_info: "_compiler_info", ext: CxxExtension.type, cmd: "cmd_args"):
cmd.add(compiler_info.preprocessor_flags)
cmd.add(compiler_info.compiler_flags)
cmd.add(compiler_info.preprocessor_flags or [])
cmd.add(compiler_info.compiler_flags or [])
cmd.add(get_flags_for_reproducible_build(compiler_info.compiler_type))

if ext.value not in (".asm", ".asmpp"):
Expand Down
16 changes: 8 additions & 8 deletions prelude/cxx/cxx_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,14 @@ def cxx_library_parameterized(ctx: "context", impl_params: "CxxRuleConstructorPa
# and unless they get quoted, they break shell syntax.
cxx_preprocessor_flags = cmd_args()
cxx_compiler_info = get_cxx_toolchain_info(ctx).cxx_compiler_info
cxx_preprocessor_flags.add(cmd_args(cxx_compiler_info.preprocessor_flags, quote = "shell"))
cxx_preprocessor_flags.add(cmd_args(cxx_compiler_info.preprocessor_flags or [], quote = "shell"))
cxx_preprocessor_flags.add(cmd_args(propagated_preprocessor.set.project_as_args("args"), quote = "shell"))
cxx_preprocessor_flags.add(propagated_preprocessor.set.project_as_args("include_dirs"))
templ_vars["cxxppflags"] = cxx_preprocessor_flags

c_preprocessor_flags = cmd_args()
c_compiler_info = get_cxx_toolchain_info(ctx).c_compiler_info
c_preprocessor_flags.add(cmd_args(c_compiler_info.preprocessor_flags, quote = "shell"))
c_preprocessor_flags.add(cmd_args(c_compiler_info.preprocessor_flags or [], quote = "shell"))
c_preprocessor_flags.add(cmd_args(propagated_preprocessor.set.project_as_args("args"), quote = "shell"))
c_preprocessor_flags.add(propagated_preprocessor.set.project_as_args("include_dirs"))
templ_vars["cppflags"] = c_preprocessor_flags
Expand All @@ -542,7 +542,7 @@ def cxx_library_parameterized(ctx: "context", impl_params: "CxxRuleConstructorPa
name = "ldflags-" + link_style.value.replace("_", "-")
args = cmd_args()
linker_info = get_cxx_toolchain_info(ctx).linker_info
args.add(linker_info.linker_flags)
args.add(linker_info.linker_flags or [])
args.add(unpack_link_args(
get_link_args(
merged_native_link_info, # buildifier: disable=uninitialized Initialized if impl_params.generate_providers.template_placeholders is True
Expand Down Expand Up @@ -896,9 +896,9 @@ def _static_library(
post_flags = []

if pic:
post_flags.extend(linker_info.static_pic_dep_runtime_ld_flags)
post_flags.extend(linker_info.static_pic_dep_runtime_ld_flags or [])
else:
post_flags.extend(linker_info.static_dep_runtime_ld_flags)
post_flags.extend(linker_info.static_dep_runtime_ld_flags or [])

all_external_debug_info = []
all_external_debug_info.extend(external_debug_info)
Expand Down Expand Up @@ -970,7 +970,7 @@ def _shared_library(
impl_params.extra_exported_link_flags +
impl_params.extra_link_flags +
_attr_post_linker_flags(ctx) +
linker_info.shared_dep_runtime_ld_flags
(linker_info.shared_dep_runtime_ld_flags or [])
),
external_debug_info = external_debug_info,
)
Expand Down Expand Up @@ -998,9 +998,9 @@ def _shared_library(
pre_flags = link_info.pre_flags,
linkables = link_info.linkables,
post_flags = (
link_info.post_flags +
(link_info.post_flags or []) +
get_ignore_undefined_symbols_flags(linker_info.type) +
linker_info.independent_shlib_interface_linker_flags
(linker_info.independent_shlib_interface_linker_flags or [])
),
external_debug_info = link_info.external_debug_info,
)
Expand Down
2 changes: 1 addition & 1 deletion prelude/cxx/cxx_link_utility.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,5 @@ def executable_shared_lib_arguments(
def cxx_link_cmd(ctx: "context") -> "cmd_args":
toolchain = get_cxx_toolchain_info(ctx)
command = cmd_args(toolchain.linker_info.linker)
command.add(toolchain.linker_info.linker_flags)
command.add(toolchain.linker_info.linker_flags or [])
return command
9 changes: 5 additions & 4 deletions prelude/rust/build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def generate_rustdoc(
[cmd_args("--env=", k, "=", v, delimiter = "") for k, v in plain_env.items()],
[cmd_args("--path-env=", k, "=", v, delimiter = "") for k, v in path_env.items()],
toolchain_info.rustdoc,
toolchain_info.rustdoc_flags,
toolchain_info.rustdoc_flags or [],
ctx.attrs.rustdoc_flags,
common_args.args,
# FIXME: fbcode/common/rust/rustdoc/compress/main.rs expects
Expand Down Expand Up @@ -403,7 +403,8 @@ def _dependency_args(

return (args, crate_targets)

def _lintify(flag: str.type, clippy: bool.type, lints: ["resolved_macro"]) -> "cmd_args":
def _lintify(flag: str.type, clippy: bool.type, lints: [["resolved_macro"], None]) -> "cmd_args":
lints = lints or []
return cmd_args(
[lint for lint in lints if str(lint).startswith("\"clippy::") == clippy],
format = "-{}{{}}".format(flag),
Expand Down Expand Up @@ -486,8 +487,8 @@ def _compute_common_args(
"--json=diagnostic-rendered-ansi",
["-Cprefer-dynamic=yes"] if crate_type == CrateType("dylib") else [],
["--target={}".format(toolchain_info.rustc_target_triple)] if toolchain_info.rustc_target_triple else [],
toolchain_info.rustc_flags,
toolchain_info.rustc_check_flags if is_check else [],
toolchain_info.rustc_flags or [],
(toolchain_info.rustc_check_flags or []) if is_check else [],
ctx.attrs.rustc_flags,
cmd_args(ctx.attrs.features, format = '--cfg=feature="{}"'),
dependency_args,
Expand Down
2 changes: 1 addition & 1 deletion prelude/rust/rust_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _rust_binary_common(
shared_libs,
)

extra_flags = toolchain_info.rustc_binary_flags + (extra_flags or [])
extra_flags = (toolchain_info.rustc_binary_flags or []) + (extra_flags or [])

# Compile rust binary.
link, meta = rust_compile_multi(
Expand Down
20 changes: 0 additions & 20 deletions shim/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,11 @@ def _cxx_toolchain(ctx):
mk_comp_db = ctx.attrs.make_comp_db,
linker_info = LinkerInfo(
linker = RunInfo(args = ["gcc"]),
linker_flags = [],
archiver = RunInfo(args = ["ar", "rcs"]),
type = "gnu",
link_binaries_locally = True,
archive_objects_locally = True,
use_archiver_flags = False,
static_dep_runtime_ld_flags = [],
static_pic_dep_runtime_ld_flags = [],
shared_dep_runtime_ld_flags = [],
independent_shlib_interface_linker_flags = [],
mk_shlib_intf = ctx.attrs.make_shlib_intf,
link_style = LinkStyle(ctx.attrs.link_style),
link_weight = 1,
Expand All @@ -79,26 +74,18 @@ def _cxx_toolchain(ctx):
),
cxx_compiler_info = CxxCompilerInfo(
compiler = RunInfo(args = ["clang++"]),
preprocessor_flags = [],
compiler_flags = [],
compiler_type = "clang", # one of CxxToolProviderType
),
c_compiler_info = CCompilerInfo(
compiler = RunInfo(args = ["clang"]),
preprocessor_flags = [],
compiler_flags = [],
compiler_type = "clang", # one of CxxToolProviderType
),
as_compiler_info = CCompilerInfo(
compiler = RunInfo(args = ["clang"]),
preprocessor_flags = [],
compiler_flags = [],
compiler_type = "clang", # one of CxxToolProviderType
),
asm_compiler_info = CCompilerInfo(
compiler = RunInfo(args = ["clang"]),
preprocessor_flags = [],
compiler_flags = [],
compiler_type = "clang", # one of CxxToolProviderType
),
header_mode = HeaderMode("symlink_tree_only"),
Expand Down Expand Up @@ -168,25 +155,18 @@ def _rust_toolchain(ctx):
return [
DefaultInfo(),
RustToolchainInfo(
allow_lints = [],
clippy_driver = "clippy-driver",
compiler = "rustc",
deny_lints = [],
extern_html_root_url_prefix = "",
failure_filter = False,
failure_filter_action = None,
pipelined = False,
report_unused_deps = False,
rustc_action = ctx.attrs.rustc_action[RunInfo],
rustc_binary_flags = [],
rustc_check_flags = [],
rustc_flags = [],
default_edition = "2021",
rustc_target_triple = "x86_64-pc-windows-gnu" if host_info().os.is_windows else "x86_64-unknown-linux-gnu",
rustc_test_flags = "",
rustdoc = "rustdoc",
rustdoc_flags = [],
warn_lints = [],
),
RustPlatformInfo(
name = "x86_64",
Expand Down

0 comments on commit f171bf1

Please sign in to comment.