2
0
Fork 0
mirror of https://github.com/bazel-contrib/rules_foreign_cc synced 2024-11-29 12:33:51 +00:00
rules_foreign_cc/for_workspace/ninja_build.bzl
irengrig c51480261c
Extract shell fragments into a toolchain (#196)
* Extract shell fragments into a toolchain

Construct script in framework.bzl using special notation for calling
shell fragments, defining and referencing environment variables;
have the script converted from this special notation into a real script
(see README.md notes.)
The special notation is used to keep script construction in code still readable.

Tools scripts (cmake, ninja) were also converted.

* Fix reference to environment variables in examples

.. and reference it correctly $$var_name$$ so it is replaced further

* Review comments: documentation, explicitly mark functions from toolchain

- mark functions from shell toolchain as ##funname##, so that they
can not be mixed with usual shell functions

* Fix operating system name for windows in toolchain file

* Additional env vars for windows

* Correct cmake tool build

* Do not build ninja on Windows

* When run on Windows under msys, find utility from Window could "leak"...

into the script. Use heuristics to use /usr/bin/find if it exists.
Also, use pwd -W to get Windows-styled paths (for cmake)
2019-01-18 18:06:10 +01:00

45 lines
1.3 KiB
Python

""" Rule for building Ninja from sources. """
load("//tools/build_defs:detect_root.bzl", "detect_root")
load("@rules_foreign_cc//tools/build_defs:shell_script_helper.bzl", "convert_shell_script")
def _ninja_tool(ctx):
root = detect_root(ctx.attr.ninja_srcs)
ninja = ctx.actions.declare_directory("ninja")
script = [
"##mkdirs## " + ninja.path,
"##copy_dir_contents_to_dir## ./{} {}".format(root, ninja.path),
"cd " + ninja.path,
"./configure.py --bootstrap",
]
script_text = convert_shell_script(ctx, script)
ctx.actions.run_shell(
mnemonic = "BootstrapNinja",
inputs = ctx.attr.ninja_srcs.files,
outputs = [ninja],
tools = [],
use_default_shell_env = True,
command = script_text,
execution_requirements = {"block-network": ""},
)
return [DefaultInfo(files = depset([ninja]))]
""" Rule for building Ninja. Invokes configure script and make install.
Attributes:
ninja_srcs - target with the Ninja sources
"""
ninja_tool = rule(
attrs = {
"ninja_srcs": attr.label(mandatory = True),
},
fragments = ["cpp"],
output_to_genfiles = True,
implementation = _ninja_tool,
toolchains = [
"@rules_foreign_cc//tools/build_defs/shell_toolchain/toolchains:shell_commands",
],
)