[openwrt/openwrt] tools/ninja: use existing ninja to build ninja

LEDE Commits lede-commits at lists.infradead.org
Mon Oct 14 04:58:49 PDT 2024


robimarko pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/df303c7ef49d8dc8a0061e002ea021d4e7c8f529

commit df303c7ef49d8dc8a0061e002ea021d4e7c8f529
Author: Michael Pratt <mcpratt at pm.me>
AuthorDate: Fri Aug 2 04:02:58 2024 -0400

    tools/ninja: use existing ninja to build ninja
    
    Add methods to skip the building and execution of Ninja by python
    in order to allow Make to execute Ninja after the configure script.
    
    This allows the user to build Ninja only once
    if they already have an older version of Ninja built.
    
    It also allows the user to test the jobserver functionality
    by having Ninja built twice (clean then compile).
    
    Signed-off-by: Michael Pratt <mcpratt at pm.me>
    Link: https://github.com/openwrt/openwrt/pull/16693
    Signed-off-by: Robert Marko <robimarko at gmail.com>
---
 tools/ninja/Makefile                               | 11 ++++++----
 .../patches/010-bootstrap-configure-only.patch     | 24 ++++++++++++++++++++++
 .../ninja/patches/100-make_jobserver_support.patch |  6 +++---
 3 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/tools/ninja/Makefile b/tools/ninja/Makefile
index 16429b73f3..7d6b623925 100644
--- a/tools/ninja/Makefile
+++ b/tools/ninja/Makefile
@@ -11,15 +11,18 @@ PKG_HASH:=31747ae633213f1eda3842686f83c2aa1412e0f5691d1c14dbbcc67fe7400cea
 include $(INCLUDE_DIR)/host-build.mk
 
 define Host/Configure
-endef
-
-define Host/Compile
 	cd $(HOST_BUILD_DIR) && \
 		$(HOST_MAKE_VARS) \
 		CXX="$(HOSTCXX_NOCACHE)" \
 		$(STAGING_DIR_HOST)/bin/$(PYTHON) configure.py \
-			--bootstrap \
+			$(if $(shell $(STAGING_DIR_HOST)/bin/ninja --version),,--bootstrap) \
+			--no-rebuild \
 			--verbose
+	-$(Host/Install)
+endef
+
+define Host/Compile
+	+$(NINJA) -C $(HOST_BUILD_DIR)
 endef
 
 define Host/Install
diff --git a/tools/ninja/patches/010-bootstrap-configure-only.patch b/tools/ninja/patches/010-bootstrap-configure-only.patch
new file mode 100644
index 0000000000..61ee5a0cd6
--- /dev/null
+++ b/tools/ninja/patches/010-bootstrap-configure-only.patch
@@ -0,0 +1,24 @@
+--- a/configure.py
++++ b/configure.py
+@@ -201,6 +201,8 @@ parser = OptionParser()
+ profilers = ['gmon', 'pprof']
+ parser.add_option('--bootstrap', action='store_true',
+                   help='bootstrap a ninja binary from nothing')
++parser.add_option('--no-rebuild', action='store_true',
++                  help='let user execute ninja after build.ninja generation')
+ parser.add_option('--verbose', action='store_true',
+                   help='enable verbose build')
+ parser.add_option('--platform',
+@@ -693,7 +695,11 @@ n.build('all', 'phony', all_targets)
+ n.close()
+ print('wrote %s.' % BUILD_FILENAME)
+ 
+-if options.bootstrap:
++if options.bootstrap and options.no_rebuild:
++    print('bootstrap complete. execute ninja in this directory...')
++    print(os.getcwd())
++
++elif options.bootstrap:
+     print('bootstrap complete.  rebuilding...')
+ 
+     rebuild_args = []
diff --git a/tools/ninja/patches/100-make_jobserver_support.patch b/tools/ninja/patches/100-make_jobserver_support.patch
index 34d2b6c431..26d6f9714c 100644
--- a/tools/ninja/patches/100-make_jobserver_support.patch
+++ b/tools/ninja/patches/100-make_jobserver_support.patch
@@ -33,7 +33,7 @@ Fixes https://github.com/ninja-build/ninja/issues/1139
 
 --- a/configure.py
 +++ b/configure.py
-@@ -517,11 +517,13 @@ for name in ['build',
+@@ -519,11 +519,13 @@ for name in ['build',
               'state',
               'status',
               'string_piece_util',
@@ -47,7 +47,7 @@ Fixes https://github.com/ninja-build/ninja/issues/1139
                   'includes_normalize-win32',
                   'msvc_helper-win32',
                   'msvc_helper_main-win32']:
-@@ -530,7 +532,9 @@ if platform.is_windows():
+@@ -532,7 +534,9 @@ if platform.is_windows():
          objs += cxx('minidump-win32', variables=cxxvariables)
      objs += cc('getopt')
  else:
@@ -58,7 +58,7 @@ Fixes https://github.com/ninja-build/ninja/issues/1139
  if platform.is_aix():
      objs += cc('getopt')
  if platform.is_msvc():
-@@ -588,6 +592,7 @@ for name in ['build_log_test',
+@@ -590,6 +594,7 @@ for name in ['build_log_test',
               'string_piece_util_test',
               'subprocess_test',
               'test',




More information about the lede-commits mailing list