2021-03-11 16:52:36 +00:00
|
|
|
"""A module defining convienence methoods for accessing build tools from
|
|
|
|
rules_foreign_cc toolchains
|
|
|
|
"""
|
|
|
|
|
2022-03-14 14:06:22 +00:00
|
|
|
def access_tool(toolchain_type_, ctx):
|
2021-03-11 16:52:36 +00:00
|
|
|
"""A helper macro for getting the path to a build tool's executable
|
|
|
|
|
|
|
|
Args:
|
2022-04-07 15:44:38 +00:00
|
|
|
toolchain_type_ (Label): The name of the toolchain type
|
2021-03-11 16:52:36 +00:00
|
|
|
ctx (ctx): The rule's context object
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
ToolInfo: A provider containing information about the toolchain's executable
|
|
|
|
"""
|
|
|
|
tool_toolchain = ctx.toolchains[toolchain_type_]
|
|
|
|
if tool_toolchain:
|
|
|
|
return tool_toolchain.data
|
2022-03-14 14:06:22 +00:00
|
|
|
fail("No toolchain found for " + toolchain_type_)
|
2021-03-11 16:52:36 +00:00
|
|
|
|
2021-12-17 23:27:10 +00:00
|
|
|
def get_autoconf_data(ctx):
|
2022-04-07 15:44:38 +00:00
|
|
|
return _access_and_expect_label_copied(Label("//toolchains:autoconf_toolchain"), ctx)
|
2021-12-17 23:27:10 +00:00
|
|
|
|
|
|
|
def get_automake_data(ctx):
|
2022-04-07 15:44:38 +00:00
|
|
|
return _access_and_expect_label_copied(Label("//toolchains:automake_toolchain"), ctx)
|
2021-12-17 23:27:10 +00:00
|
|
|
|
2021-03-11 16:52:36 +00:00
|
|
|
def get_cmake_data(ctx):
|
2022-04-07 15:44:38 +00:00
|
|
|
return _access_and_expect_label_copied(Label("//toolchains:cmake_toolchain"), ctx)
|
2021-03-11 16:52:36 +00:00
|
|
|
|
2021-12-17 23:27:10 +00:00
|
|
|
def get_m4_data(ctx):
|
2022-04-07 15:44:38 +00:00
|
|
|
return _access_and_expect_label_copied(Label("//toolchains:m4_toolchain"), ctx)
|
2021-03-11 16:52:36 +00:00
|
|
|
|
|
|
|
def get_make_data(ctx):
|
2022-04-07 15:44:38 +00:00
|
|
|
return _access_and_expect_label_copied(Label("//toolchains:make_toolchain"), ctx)
|
2021-12-17 23:27:10 +00:00
|
|
|
|
|
|
|
def get_ninja_data(ctx):
|
2022-04-07 15:44:38 +00:00
|
|
|
return _access_and_expect_label_copied(Label("//toolchains:ninja_toolchain"), ctx)
|
2021-12-17 23:27:10 +00:00
|
|
|
|
2023-06-09 10:29:12 +00:00
|
|
|
def get_meson_data(ctx):
|
|
|
|
return _access_and_expect_label_copied(Label("//toolchains:meson_toolchain"), ctx)
|
|
|
|
|
2021-12-17 23:27:10 +00:00
|
|
|
def get_pkgconfig_data(ctx):
|
2022-04-07 15:44:38 +00:00
|
|
|
return _access_and_expect_label_copied(Label("//toolchains:pkgconfig_toolchain"), ctx)
|
2021-03-11 16:52:36 +00:00
|
|
|
|
2022-03-14 14:06:22 +00:00
|
|
|
def _access_and_expect_label_copied(toolchain_type_, ctx):
|
|
|
|
tool_data = access_tool(toolchain_type_, ctx)
|
2021-03-11 16:52:36 +00:00
|
|
|
if tool_data.target:
|
|
|
|
# This could be made more efficient by changing the
|
|
|
|
# toolchain to provide the executable as a target
|
|
|
|
cmd_file = tool_data
|
|
|
|
for f in tool_data.target.files.to_list():
|
|
|
|
if f.path.endswith("/" + tool_data.path):
|
|
|
|
cmd_file = f
|
|
|
|
break
|
|
|
|
return struct(
|
2022-12-10 20:16:40 +00:00
|
|
|
target = tool_data.target,
|
2022-03-14 14:06:22 +00:00
|
|
|
env = tool_data.env,
|
2021-03-11 16:52:36 +00:00
|
|
|
# as the tool will be copied into tools directory
|
|
|
|
path = "$EXT_BUILD_ROOT/{}".format(cmd_file.path),
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
return struct(
|
2022-12-10 20:16:40 +00:00
|
|
|
target = None,
|
2022-03-14 14:06:22 +00:00
|
|
|
env = tool_data.env,
|
2021-03-11 16:52:36 +00:00
|
|
|
path = tool_data.path,
|
|
|
|
)
|