Skip to content

Commit

Permalink
Merge branch 'master' into compiler_detect
Browse files Browse the repository at this point in the history
  • Loading branch information
jhasse authored Aug 22, 2022
2 parents b5fa2d5 + 864f7b5 commit 69fb2ce
Show file tree
Hide file tree
Showing 24 changed files with 819 additions and 194 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@
/.clangd/
/compile_commands.json
/.cache/

# Visual Studio files
/.vs/
/out/
26 changes: 19 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 3.15)
include(CheckSymbolExists)
include(CheckIPOSupported)

option(NINJA_BUILD_BINARY "Build ninja binary" ON)

project(ninja)

# --- optional link-time optimization
Expand All @@ -19,6 +21,8 @@ endif()
if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
string(REPLACE "/GR" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
# Note that these settings are separately specified in configure.py, and
# these lists should be kept in sync.
add_compile_options(/W4 /wd4100 /wd4267 /wd4706 /wd4702 /wd4244 /GR- /Zc:__cplusplus)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
else()
Expand Down Expand Up @@ -136,6 +140,8 @@ else()
endif()
endif()

target_compile_features(libninja PUBLIC cxx_std_11)

#Fixes GetActiveProcessorCount on MinGW
if(MINGW)
target_compile_definitions(libninja PRIVATE _WIN32_WINNT=0x0601 __USE_MINGW_ANSI_STDIO=1)
Expand All @@ -148,11 +154,13 @@ if(CMAKE_SYSTEM_NAME STREQUAL "OS400" OR CMAKE_SYSTEM_NAME STREQUAL "AIX")
endif()

# Main executable is library plus main() function.
add_executable(ninja src/ninja.cc)
target_link_libraries(ninja PRIVATE libninja libninja-re2c)
if(NINJA_BUILD_BINARY)
add_executable(ninja src/ninja.cc)
target_link_libraries(ninja PRIVATE libninja libninja-re2c)

if(WIN32)
target_sources(ninja PRIVATE windows/ninja.manifest)
if(WIN32)
target_sources(ninja PRIVATE windows/ninja.manifest)
endif()
endif()

# Adds browse mode into the ninja binary if it's supported by the host platform.
Expand All @@ -171,8 +179,10 @@ if(platform_supports_ninja_browse)
VERBATIM
)

target_compile_definitions(ninja PRIVATE NINJA_HAVE_BROWSE)
target_sources(ninja PRIVATE src/browse.cc)
if(NINJA_BUILD_BINARY)
target_compile_definitions(ninja PRIVATE NINJA_HAVE_BROWSE)
target_sources(ninja PRIVATE src/browse.cc)
endif()
set_source_files_properties(src/browse.cc
PROPERTIES
OBJECT_DEPENDS "${PROJECT_BINARY_DIR}/build/browse_py.h"
Expand Down Expand Up @@ -232,4 +242,6 @@ if(BUILD_TESTING)
add_test(NAME NinjaTest COMMAND ninja_test)
endif()

install(TARGETS ninja DESTINATION bin)
if(NINJA_BUILD_BINARY)
install(TARGETS ninja)
endif()
3 changes: 0 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ Generally it's the
[Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html) with
a few additions:

* Any code merged into the Ninja codebase which will be part of the main
executable must compile as C++03. You may use C++11 features in a test or an
unimportant tool if you guard your code with `#if __cplusplus >= 201103L`.
* We have used `using namespace std;` a lot in the past. For new contributions,
please try to avoid relying on it and instead whenever possible use `std::`.
However, please do not change existing code simply to add `std::` unless your
Expand Down
20 changes: 17 additions & 3 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ def search_system_path(file_name):
if os.path.exists(path):
return path

# Note that build settings are separately specified in CMakeLists.txt and
# these lists should be kept in sync.
if platform.is_msvc():
if not search_system_path('cl.exe'):
raise Exception('cl.exe not found. Run again from the Developer Command Prompt for VS')
Expand All @@ -329,6 +331,7 @@ def search_system_path(file_name):
# Disable warnings about ignored typedef in DbgHelp.h
'/wd4091',
'/GR-', # Disable RTTI.
'/Zc:__cplusplus',
# Disable size_t -> int truncation warning.
# We never have strings or arrays larger than 2**31.
'/wd4267',
Expand All @@ -348,6 +351,7 @@ def search_system_path(file_name):
'-Wno-unused-parameter',
'-fno-rtti',
'-fno-exceptions',
'-std=c++11',
'-fvisibility=hidden', '-pipe',
'-DNINJA_PYTHON="%s"' % options.with_python]
if options.debug:
Expand Down Expand Up @@ -498,16 +502,27 @@ def has_re2c():
"changes to src/*.in.cc will not affect your build.")
n.newline()

n.comment('Core source files all build into ninja library.')
cxxvariables = []
if platform.is_msvc():
cxxvariables = [('pdb', 'ninja.pdb')]

n.comment('Generate a library for `ninja-re2c`.')
re2c_objs = []
for name in ['depfile_parser', 'lexer']:
re2c_objs += cxx(name, variables=cxxvariables)
if platform.is_msvc():
n.build(built('ninja-re2c.lib'), 'ar', re2c_objs)
else:
n.build(built('libninja-re2c.a'), 'ar', re2c_objs)
n.newline()

n.comment('Core source files all build into ninja library.')
objs.extend(re2c_objs)
for name in ['build',
'build_log',
'clean',
'clparser',
'debug_flags',
'depfile_parser',
'deps_log',
'disk_interface',
'dyndep',
Expand All @@ -517,7 +532,6 @@ def has_re2c():
'graph',
'graphviz',
'json',
'lexer',
'line_printer',
'manifest_parser',
'metrics',
Expand Down
38 changes: 36 additions & 2 deletions doc/manual.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ than the _depth_ mode.
executed in order, may be used to rebuild those targets, assuming that all
output files are out of date.
`inputs`:: given a list of targets, print a list of all inputs which are used
to rebuild those targets.
`inputs`:: given a list of targets, print a list of all inputs used to
rebuild those targets.
_Available since Ninja 1.11._
`clean`:: remove built files. By default it removes all built files
Expand Down Expand Up @@ -312,6 +312,37 @@ file. _Available since Ninja 1.10._
to pass to +ninja -t targets rule _name_+ or +ninja -t compdb+. Adding the `-d`
flag also prints the description of the rules.
`msvc`:: Available on Windows hosts only.
Helper tool to invoke the `cl.exe` compiler with a pre-defined set of
environment variables, as in:
+
----
ninja -t msvc -e ENVFILE -- cl.exe <arguments>
----
+
Where `ENVFILE` is a binary file that contains an environment block suitable
for CreateProcessA() on Windows (i.e. a series of zero-terminated strings that
look like NAME=VALUE, followed by an extra zero terminator). Note that this uses
the local codepage encoding.
This tool also supports a deprecated way of parsing the compiler's output when
the `/showIncludes` flag is used, and generating a GCC-compatible depfile from it.
+
---
ninja -t msvc -o DEPFILE [-p STRING] -- cl.exe /showIncludes <arguments>
---
+
When using this option, `-p STRING` can be used to pass the localized line prefix
that `cl.exe` uses to output dependency information. For English-speaking regions
this is `"Note: including file: "` without the double quotes, but will be different
for other regions.
Note that Ninja supports this natively now, with the use of `deps = msvc` and
`msvc_deps_prefix` in Ninja files. Native support also avoids launching an extra
tool process each time the compiler must be called, which can speed up builds
noticeably on Windows.
`wincodepage`:: Available on Windows hosts (_since Ninja 1.11_).
Prints the Windows code page whose encoding is expected in the build file.
The output has the form:
Expand Down Expand Up @@ -1015,6 +1046,9 @@ relative path, pointing to the same file, are considered different by Ninja.
[[validations]]
Validations
~~~~~~~~~~~

_Available since Ninja 1.11._

Validations listed on the build line cause the specified files to be
added to the top level of the build graph (as if they were specified
on the Ninja command line) whenever the build line is a transitive
Expand Down
18 changes: 18 additions & 0 deletions misc/output_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,23 @@ def test_entering_directory_on_stdout(self):
output = run(Output.BUILD_SIMPLE_ECHO, flags='-C$PWD', pipe=True)
self.assertEqual(output.splitlines()[0][:25], "ninja: Entering directory")

def test_tool_inputs(self):
plan = '''
rule cat
command = cat $in $out
build out1 : cat in1
build out2 : cat in2 out1
build out3 : cat out2 out1 | implicit || order_only
'''
self.assertEqual(run(plan, flags='-t inputs out3'),
'''implicit
in1
in2
order_only
out1
out2
''')


if __name__ == '__main__':
unittest.main()
36 changes: 19 additions & 17 deletions misc/zsh-completion
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Add the following to your .zshrc to tab-complete ninja targets
# fpath=(path/to/ninja/misc/zsh-completion $fpath)

__get_targets() {
(( $+functions[_ninja-get-targets] )) || _ninja-get-targets() {
dir="."
if [ -n "${opt_args[-C]}" ];
then
Expand All @@ -31,42 +31,44 @@ __get_targets() {
eval ${targets_command} 2>/dev/null | cut -d: -f1
}

__get_tools() {
ninja -t list 2>/dev/null | while read -r a b; do echo $a; done | tail -n +2
(( $+functions[_ninja-get-tools] )) || _ninja-get-tools() {
# remove the first line; remove the leading spaces; replace spaces with colon
ninja -t list 2> /dev/null | sed -e '1d;s/^ *//;s/ \+/:/'
}

__get_modes() {
ninja -d list 2>/dev/null | while read -r a b; do echo $a; done | tail -n +2 | sed '$d'
(( $+functions[_ninja-get-modes] )) || _ninja-get-modes() {
# remove the first line; remove the last line; remove the leading spaces; replace spaces with colon
ninja -d list 2> /dev/null | sed -e '1d;$d;s/^ *//;s/ \+/:/'
}

__modes() {
(( $+functions[_ninja-modes] )) || _ninja-modes() {
local -a modes
modes=(${(fo)"$(__get_modes)"})
modes=(${(fo)"$(_ninja-get-modes)"})
_describe 'modes' modes
}

__tools() {
(( $+functions[_ninja-tools] )) || _ninja-tools() {
local -a tools
tools=(${(fo)"$(__get_tools)"})
tools=(${(fo)"$(_ninja-get-tools)"})
_describe 'tools' tools
}

__targets() {
(( $+functions[_ninja-targets] )) || _ninja-targets() {
local -a targets
targets=(${(fo)"$(__get_targets)"})
targets=(${(fo)"$(_ninja-get-targets)"})
_describe 'targets' targets
}

_arguments \
{-h,--help}'[Show help]' \
'--version[Print ninja version]' \
'(- *)'{-h,--help}'[Show help]' \
'(- *)--version[Print ninja version]' \
'-C+[Change to directory before doing anything else]:directories:_directories' \
'-f+[Specify input build file (default=build.ninja)]:files:_files' \
'-j+[Run N jobs in parallel (default=number of CPUs available)]:number of jobs' \
'-l+[Do not start new jobs if the load average is greater than N]:number of jobs' \
'-k+[Keep going until N jobs fail (default=1)]:number of jobs' \
'-n[Dry run (do not run commands but act like they succeeded)]' \
'-v[Show all command lines while building]' \
'-d+[Enable debugging (use -d list to list modes)]:modes:__modes' \
'-t+[Run a subtool (use -t list to list subtools)]:tools:__tools' \
'*::targets:__targets'
'(-v --verbose)'{-v,--verbose}'[Show all command lines while building]' \
'-d+[Enable debugging (use -d list to list modes)]:modes:_ninja-modes' \
'-t+[Run a subtool (use -t list to list subtools)]:tools:_ninja-tools' \
'*::targets:_ninja-targets'
Loading

0 comments on commit 69fb2ce

Please sign in to comment.