Skip to content

Commit 22a5a05

Browse files
refacktargos
authored andcommitted
build: delegate building from Makefile to ninja
PR-URL: #27504 Refs: https://mobile.twitter.com/refack/status/1118484079077482498 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]>
1 parent 66cf706 commit 22a5a05

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

Makefile

+25
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ GTEST_FILTER ?= "*"
1616
GNUMAKEFLAGS += --no-print-directory
1717
GCOV ?= gcov
1818
PWD = $(CURDIR)
19+
BUILD_WITH ?= make
1920

2021
ifdef JOBS
2122
PARALLEL_ARGS = -j $(JOBS)
@@ -95,13 +96,37 @@ help: ## Print help for targets with comments.
9596
# Without the check there is a race condition between the link being deleted
9697
# and recreated which can break the addons build when running test-ci
9798
# See comments on the build-addons target for some more info
99+
ifeq ($(BUILD_WITH), make)
98100
$(NODE_EXE): config.gypi out/Makefile
99101
$(MAKE) -C out BUILDTYPE=Release V=$(V)
100102
if [ ! -r $@ -o ! -L $@ ]; then ln -fs out/Release/$(NODE_EXE) $@; fi
101103

102104
$(NODE_G_EXE): config.gypi out/Makefile
103105
$(MAKE) -C out BUILDTYPE=Debug V=$(V)
104106
if [ ! -r $@ -o ! -L $@ ]; then ln -fs out/Debug/$(NODE_EXE) $@; fi
107+
else
108+
ifeq ($(BUILD_WITH), ninja)
109+
ifeq ($(V),1)
110+
NINJA_ARGS := $(NINJA_ARGS) -v
111+
endif
112+
ifdef JOBS
113+
NINJA_ARGS := $(NINJA_ARGS) -j$(JOBS)
114+
else
115+
NINJA_ARGS := $(NINJA_ARGS) $(filter -j%,$(MAKEFLAGS))
116+
endif
117+
$(NODE_EXE): config.gypi out/Release/build.ninja
118+
ninja -C out/Release $(NINJA_ARGS)
119+
if [ ! -r $@ -o ! -L $@ ]; then ln -fs out/Release/$(NODE_EXE) $@; fi
120+
121+
$(NODE_G_EXE): config.gypi out/Debug/build.ninja
122+
ninja -C out/Debug $(NINJA_ARGS)
123+
if [ ! -r $@ -o ! -L $@ ]; then ln -fs out/Debug/$(NODE_EXE) $@; fi
124+
else
125+
$(NODE_EXE) $(NODE_G_EXE):
126+
echo This Makefile currently only supports building with 'make' or 'ninja'
127+
endif
128+
endif
129+
105130

106131
ifeq ($(BUILDTYPE),Debug)
107132
CONFIG_FLAGS += --debug

configure.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -1627,23 +1627,35 @@ def make_bin_override():
16271627
' '.join([pipes.quote(arg) for arg in original_argv]) + '\n')
16281628
os.chmod('config.status', 0o775)
16291629

1630+
16301631
config = {
16311632
'BUILDTYPE': 'Debug' if options.debug else 'Release',
1632-
'PYTHON': sys.executable,
16331633
'NODE_TARGET_TYPE': variables['node_target_type'],
16341634
}
16351635

1636+
# Not needed for trivial case. Useless when it's a win32 path.
1637+
if sys.executable != 'python' and ':\\' not in sys.executable:
1638+
config['PYTHON'] = sys.executable
1639+
16361640
if options.prefix:
16371641
config['PREFIX'] = options.prefix
16381642

1639-
config = '\n'.join(['='.join(item) for item in config.items()]) + '\n'
1643+
if options.use_ninja:
1644+
config['BUILD_WITH'] = 'ninja'
1645+
1646+
config_lines = ['='.join((k,v)) for k,v in config.items()]
1647+
# Add a blank string to get a blank line at the end.
1648+
config_lines += ['']
1649+
config_str = '\n'.join(config_lines)
16401650

16411651
# On Windows there's no reason to search for a different python binary.
16421652
bin_override = None if sys.platform == 'win32' else make_bin_override()
16431653
if bin_override:
1644-
config = 'export PATH:=' + bin_override + ':$(PATH)\n' + config
1654+
config_str = 'export PATH:=' + bin_override + ':$(PATH)\n' + config_str
1655+
1656+
write('config.mk', do_not_edit + config_str)
1657+
16451658

1646-
write('config.mk', do_not_edit + config)
16471659

16481660
gyp_args = ['--no-parallel', '-Dconfiguring_node=1']
16491661

0 commit comments

Comments
 (0)