Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of concept of a self-bootstrapping build.ninja file #2563

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions build.ninja
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ninja_required_version = 1.3

# The arguments passed to configure.py, for rerunning it.
configure_args = --build-file ./build/build.ninja --disable-configure-rule

root = .
builddir = build

# Regenerate build files if build script changes.
rule configure
command = ${configure_env}python3 $root/configure.py $configure_args && touch build.ninja
generator = true
build build.ninja $builddir/build.ninja: configure | $root/configure.py $root/misc/ninja_syntax.py

include $builddir/build.ninja
13 changes: 11 additions & 2 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,15 @@ def _run_command(self, cmdline: str) -> None:
parser.add_option('--force-pselect', action='store_true',
help='ppoll() is used by default where available, '
'but some platforms may need to use pselect instead',)
parser.add_option('--build-file', metavar = 'FILE',
help='File to write the build file to. ' +
'Defaults to %default',
default='build.ninja')
parser.add_option('--disable-configure-rule',
action='store_true',
help='Disables generating the `configure` rule, ' +
'which is normally used to regenerate `build.ninja`, ' +
'when `./configure.py` changes.')
(options, args) = parser.parse_args()
if args:
print('ERROR: extra unparsed command-line arguments:', args)
Expand All @@ -244,7 +253,7 @@ def _run_command(self, cmdline: str) -> None:
else:
host = platform

BUILD_FILENAME = 'build.ninja'
BUILD_FILENAME = options.build_file
ninja_writer = ninja_syntax.Writer(open(BUILD_FILENAME, 'w'))
n: Union[ninja_syntax.Writer, Bootstrap] = ninja_writer

Expand Down Expand Up @@ -745,7 +754,7 @@ def has_re2c() -> bool:
implicit=mainpage)
n.newline()

if not host.is_mingw():
if not host.is_mingw() and not options.disable_configure_rule:
n.comment('Regenerate build files if build script changes.')
n.rule('configure',
command='${configure_env}%s $root/configure.py $configure_args' %
Expand Down
Loading