Skip to content

Commit

Permalink
Merge branch 'main' into bananapi4
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Storm committed Oct 14, 2024
2 parents 92b4537 + d93e99d commit 90a792d
Show file tree
Hide file tree
Showing 5 changed files with 291 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ platform_do_upgrade() {
;;
iptime,nas1dual)
PART_NAME=firmware
default_do_upgrade "$1"
;;

linksys,wrt1200ac|\
linksys,wrt1900ac-v1|\
linksys,wrt1900ac-v2|\
Expand Down
25 changes: 11 additions & 14 deletions tools/ninja/Makefile
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=ninja
PKG_VERSION:=1.11.1
PKG_VERSION:=1.12.1
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/ninja-build/ninja/tar.gz/v$(PKG_VERSION)?
PKG_HASH:=31747ae633213f1eda3842686f83c2aa1412e0f5691d1c14dbbcc67fe7400cea
PKG_HASH:=821bdff48a3f683bc4bb3b6f0b5fe7b2d647cf65d52aeb63328c91a6c6df285a

include $(INCLUDE_DIR)/host-build.mk

CONFIGURE_ARGS:=
ifneq ($(findstring c,$(OPENWRT_VERBOSE)),)
CONFIGURE_ARGS+=--verbose
endif

define Host/Configure
cd $(HOST_BUILD_DIR) && \
$(HOST_MAKE_VARS) \
CXX="$(HOSTCXX_NOCACHE)" \
$(STAGING_DIR_HOST)/bin/$(PYTHON) configure.py \
$(if $(shell $(STAGING_DIR_HOST)/bin/ninja --version),,--bootstrap) \
--no-rebuild \
--verbose
-$(Host/Install)
endef

define Host/Compile
cd $(HOST_BUILD_DIR) && \
CXX="$(HOSTCXX_NOCACHE)" \
CXXFLAGS="$(HOST_CXXFLAGS) $(HOST_CPPFLAGS)" \
LDFLAGS="$(HOST_LDFLAGS)" \
$(STAGING_DIR_HOST)/bin/$(PYTHON) configure.py --bootstrap $(CONFIGURE_ARGS)
+$(NINJA) -C $(HOST_BUILD_DIR)
endef

define Host/Install
$(INSTALL_DIR) $(STAGING_DIR_HOST)/bin
$(INSTALL_BIN) $(HOST_BUILD_DIR)/ninja $(STAGING_DIR_HOST)/bin/
endef

define Host/Clean
$(call Host/Clean/Default)
rm -f $(STAGING_DIR_HOST)/bin/ninja
endef

Expand Down
153 changes: 153 additions & 0 deletions tools/ninja/patches/001-backport-gtest.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
From afcd4a146fb82843f6ff695f89504ce4ca65ddfd Mon Sep 17 00:00:00 2001
From: David 'Digit' Turner <digit+github@google.com>
Date: Sun, 12 May 2024 23:45:28 +0200
Subject: [PATCH] configure.py: Support --gtest-source-dir to build tests.

Allow the Ninja build plan generated by configure.py to
build `ninja_test` by compiling GoogleTest from source if
the path to the library if passed through the new option
`--gtest-source-dir` or the GTEST_SOURCE_DIR environment
variable.

For simplicity, probing for an installed version of the
library, and linking to it, is not supported (use the
CMake build for this).

This also removes the obsolete `--gtest-dir` option.

+ Update README.md

Fixes #2447
---
README.md | 13 ++++++++
configure.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 95 insertions(+), 1 deletion(-)

--- a/README.md
+++ b/README.md
@@ -34,6 +34,19 @@ via CMake. For more details see
This will generate the `ninja` binary and a `build.ninja` file you can now use
to build Ninja with itself.

+If you have a GoogleTest source directory, you can build the tests
+by passing its path with `--gtest-source-dir=PATH` option, or the
+`GTEST_SOURCE_DIR` environment variable, e.g.:
+
+```
+./configure.py --bootstrap --gtest-source-dir=/path/to/googletest
+./ninja all # build ninja_test and other auxiliary binaries
+./ninja_test` # run the unit-test suite.
+```
+
+Use the CMake build below if you want to use a preinstalled binary
+version of the library.
+
### CMake

```
--- a/configure.py
+++ b/configure.py
@@ -213,7 +213,10 @@ parser.add_option('--debug', action='sto
parser.add_option('--profile', metavar='TYPE',
choices=profilers,
help='enable profiling (' + '/'.join(profilers) + ')',)
-parser.add_option('--with-gtest', metavar='PATH', help='ignored')
+parser.add_option('--gtest-source-dir', metavar='PATH',
+ help='Path to GoogleTest source directory. If not provided ' +
+ 'GTEST_SOURCE_DIR will be probed in the environment. ' +
+ 'Tests will not be built without a value.')
parser.add_option('--with-python', metavar='EXE',
help='use EXE as the Python interpreter',
default=os.path.basename(sys.executable))
@@ -425,6 +428,7 @@ n.variable('cflags', ' '.join(shell_esca
if 'LDFLAGS' in configure_env:
ldflags.append(configure_env['LDFLAGS'])
n.variable('ldflags', ' '.join(shell_escape(flag) for flag in ldflags))
+
n.newline()

if platform.is_msvc():
@@ -582,6 +586,83 @@ if options.bootstrap:
# build.ninja file.
n = ninja_writer

+# Build the ninja_test executable only if the GTest source directory
+# is provided explicitly. Either from the environment with GTEST_SOURCE_DIR
+# or with the --gtest-source-dir command-line option.
+#
+# Do not try to look for an installed binary version, and link against it
+# because doing so properly is platform-specific (use the CMake build for
+# this).
+if options.gtest_source_dir:
+ gtest_src_dir = options.gtest_source_dir
+else:
+ gtest_src_dir = os.environ.get('GTEST_SOURCE_DIR')
+
+if gtest_src_dir:
+ # Verify GoogleTest source directory, and add its include directory
+ # to the global include search path (even for non-test sources) to
+ # keep the build plan generation simple.
+ gtest_all_cc = os.path.join(gtest_src_dir, 'googletest', 'src', 'gtest-all.cc')
+ if not os.path.exists(gtest_all_cc):
+ print('ERROR: Missing GoogleTest source file: %s' % gtest_all_cc)
+ sys.exit(1)
+
+ n.comment('Tests all build into ninja_test executable.')
+
+ # Test-specific version of cflags, must include the GoogleTest
+ # include directory. Also GoogleTest can only build with a C++14 compiler.
+ test_cflags = [f.replace('std=c++11', 'std=c++14') for f in cflags]
+ test_cflags.append('-I' + os.path.join(gtest_src_dir, 'googletest', 'include'))
+
+ test_variables = [('cflags', test_cflags)]
+ if platform.is_msvc():
+ test_variables += [('pdb', 'ninja_test.pdb')]
+
+ test_names = [
+ 'build_log_test',
+ 'build_test',
+ 'clean_test',
+ 'clparser_test',
+ 'depfile_parser_test',
+ 'deps_log_test',
+ 'disk_interface_test',
+ 'dyndep_parser_test',
+ 'edit_distance_test',
+ 'graph_test',
+ 'json_test',
+ 'lexer_test',
+ 'manifest_parser_test',
+ 'ninja_test',
+ 'state_test',
+ 'string_piece_util_test',
+ 'subprocess_test',
+ 'test',
+ 'util_test',
+ ]
+ if platform.is_windows():
+ test_names += [
+ 'includes_normalize_test',
+ 'msvc_helper_test',
+ ]
+
+ objs = []
+ for name in test_names:
+ objs += cxx(name, variables=test_variables)
+
+ # Build GTest as a monolithic source file.
+ # This requires one extra include search path, so replace the
+ # value of 'cflags' in our list.
+ gtest_all_variables = test_variables[1:] + [
+ ('cflags', test_cflags + ['-I' + os.path.join(gtest_src_dir, 'googletest') ]),
+ ]
+ # Do not use cxx() directly to ensure the object file is under $builddir.
+ objs += n.build(built('gtest_all' + objext), 'cxx', gtest_all_cc, variables=gtest_all_variables)
+
+ ninja_test = n.build(binary('ninja_test'), 'link', objs, implicit=ninja_lib,
+ variables=[('libs', libs)])
+ n.newline()
+ all_targets += ninja_test
+
n.comment('Ancillary executables.')

if platform.is_aix() and '-maix64' not in ldflags:
24 changes: 24 additions & 0 deletions tools/ninja/patches/010-bootstrap-configure-only.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--- a/configure.py
+++ b/configure.py
@@ -198,6 +198,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',
@@ -756,7 +758,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 = []
Loading

0 comments on commit 90a792d

Please sign in to comment.