Skip to content

Commit 2c953d1

Browse files
committed
version 1.1.0
2 parents 7096bf1 + 3249938 commit 2c953d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1239
-526
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ TAGS
1515
/doc/manual.html
1616
/doc/doxygen
1717
/gtest-1.6.0
18+
19+
# Eclipse project files
20+
.project
21+
.cproject
22+

HACKING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,15 @@ it's locked while in use.
159159

160160
### Via mingw on Linux (not well supported)
161161

162+
Setup on Ubuntu Lucid:
162163
* `sudo apt-get install gcc-mingw32 wine`
163164
* `export CC=i586-mingw32msvc-cc CXX=i586-mingw32msvc-c++ AR=i586-mingw32msvc-ar`
165+
166+
Setup on Ubuntu Precise:
167+
* `sudo apt-get install gcc-mingw-w64-i686 g++-mingw-w64-i686 wine`
168+
* `export CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-g++ AR=i686-w64-mingw32-ar`
169+
170+
Then run:
164171
* `./configure.py --platform=mingw --host=linux`
165172
* Build `ninja.exe` using a Linux ninja binary: `/path/to/linux/ninja`
166173
* Run: `./ninja.exe` (implicitly runs through wine(!))

bootstrap.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
from __future__ import print_function
17+
1618
from optparse import OptionParser
1719
import sys
1820
import os
@@ -29,6 +31,10 @@
2931
help='enable verbose build',)
3032
parser.add_option('--x64', action='store_true',
3133
help='force 64-bit build (Windows)',)
34+
# TODO: make this --platform to match configure.py.
35+
parser.add_option('--windows', action='store_true',
36+
help='force native Windows build (when using Cygwin Python)',
37+
default=sys.platform.startswith('win32'))
3238
(options, conf_args) = parser.parse_args()
3339

3440
def run(*args, **kwargs):
@@ -44,11 +50,12 @@ def run(*args, **kwargs):
4450
cflags.append('-I/usr/local/include')
4551
ldflags.append('-L/usr/local/lib')
4652

47-
print 'Building ninja manually...'
53+
print('Building ninja manually...')
4854

4955
try:
5056
os.mkdir('build')
51-
except OSError, e:
57+
except OSError:
58+
e = sys.exc_info()[1]
5259
if e.errno != errno.EEXIST:
5360
raise
5461

@@ -63,7 +70,7 @@ def run(*args, **kwargs):
6370
if filename == 'browse.cc': # Depends on generated header.
6471
continue
6572

66-
if sys.platform.startswith('win32'):
73+
if options.windows:
6774
if src.endswith('-posix.cc'):
6875
continue
6976
else:
@@ -72,7 +79,7 @@ def run(*args, **kwargs):
7279

7380
sources.append(src)
7481

75-
if sys.platform.startswith('win32'):
82+
if options.windows:
7683
sources.append('src/getopt.c')
7784

7885
vcdir = os.environ.get('VCINSTALLDIR')
@@ -87,14 +94,14 @@ def run(*args, **kwargs):
8794
cflags.extend(['-Wno-deprecated',
8895
'-DNINJA_PYTHON="' + sys.executable + '"',
8996
'-DNINJA_BOOTSTRAP'])
90-
if sys.platform.startswith('win32'):
97+
if options.windows:
9198
cflags.append('-D_WIN32_WINNT=0x0501')
9299
if options.x64:
93100
cflags.append('-m64')
94101
args.extend(cflags)
95102
args.extend(ldflags)
96103
binary = 'ninja.bootstrap'
97-
if sys.platform.startswith('win32'):
104+
if options.windows:
98105
binary = 'ninja.bootstrap.exe'
99106
args.extend(sources)
100107
if vcdir:
@@ -103,16 +110,20 @@ def run(*args, **kwargs):
103110
args.extend(['-o', binary])
104111

105112
if options.verbose:
106-
print ' '.join(args)
113+
print(' '.join(args))
107114

108-
run(args)
115+
try:
116+
run(args)
117+
except:
118+
print('Failure running:', args)
119+
raise
109120

110121
verbose = []
111122
if options.verbose:
112123
verbose = ['-v']
113124

114-
if sys.platform.startswith('win32'):
115-
print 'Building ninja using itself...'
125+
if options.windows:
126+
print('Building ninja using itself...')
116127
run([sys.executable, 'configure.py', '--with-ninja=%s' % binary] +
117128
conf_args)
118129
run(['./' + binary] + verbose)
@@ -124,17 +135,17 @@ def run(*args, **kwargs):
124135
for obj in glob.glob('*.obj'):
125136
os.unlink(obj)
126137

127-
print """
138+
print("""
128139
Done!
129140
130141
Note: to work around Windows file locking, where you can't rebuild an
131142
in-use binary, to run ninja after making any changes to build ninja itself
132143
you should run ninja.bootstrap instead. Your build is also configured to
133144
use ninja.bootstrap.exe as the MSVC helper; see the --with-ninja flag of
134-
the --help output of configure.py."""
145+
the --help output of configure.py.""")
135146
else:
136-
print 'Building ninja using itself...'
147+
print('Building ninja using itself...')
137148
run([sys.executable, 'configure.py'] + conf_args)
138149
run(['./' + binary] + verbose)
139150
os.unlink(binary)
140-
print 'Done!'
151+
print('Done!')

configure.py

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
Projects that use ninja themselves should either write a similar script
2020
or use a meta-build system that supports Ninja output."""
2121

22+
from __future__ import print_function
23+
2224
from optparse import OptionParser
2325
import os
2426
import sys
@@ -50,7 +52,7 @@
5052
default="ninja")
5153
(options, args) = parser.parse_args()
5254
if args:
53-
print 'ERROR: extra unparsed command-line arguments:', args
55+
print('ERROR: extra unparsed command-line arguments:', args)
5456
sys.exit(1)
5557

5658
platform = options.platform
@@ -140,6 +142,7 @@ def binary(name):
140142
'-fno-rtti',
141143
'-fno-exceptions',
142144
'-fvisibility=hidden', '-pipe',
145+
'-Wno-missing-field-initializers',
143146
'-DNINJA_PYTHON="%s"' % options.with_python]
144147
if options.debug:
145148
cflags += ['-D_GLIBCXX_DEBUG', '-D_GLIBCXX_DEBUG_PEDANTIC']
@@ -168,7 +171,9 @@ def binary(name):
168171
libs.append('-lprofiler')
169172

170173
def shell_escape(str):
171-
"""Escape str such that it's interpreted as a single argument by the shell."""
174+
"""Escape str such that it's interpreted as a single argument by
175+
the shell."""
176+
172177
# This isn't complete, but it's just enough to make NINJA_PYTHON work.
173178
if platform in ('windows', 'mingw'):
174179
return str
@@ -255,7 +260,7 @@ def has_re2c():
255260
n.build(src('depfile_parser.cc'), 're2c', src('depfile_parser.in.cc'))
256261
n.build(src('lexer.cc'), 're2c', src('lexer.in.cc'))
257262
else:
258-
print ("warning: A compatible version of re2c (>= 0.11.3) was not found; "
263+
print("warning: A compatible version of re2c (>= 0.11.3) was not found; "
259264
"changes to src/*.in.cc will not affect your build.")
260265
n.newline()
261266

@@ -277,11 +282,12 @@ def has_re2c():
277282
'util']:
278283
objs += cxx(name)
279284
if platform in ('mingw', 'windows'):
280-
objs += cxx('subprocess-win32')
285+
for name in ['subprocess-win32',
286+
'includes_normalize-win32',
287+
'msvc_helper-win32',
288+
'msvc_helper_main-win32']:
289+
objs += cxx(name)
281290
if platform == 'windows':
282-
objs += cxx('includes_normalize-win32')
283-
objs += cxx('msvc_helper-win32')
284-
objs += cxx('msvc_helper_main-win32')
285291
objs += cxx('minidump-win32')
286292
objs += cc('getopt')
287293
else:
@@ -309,7 +315,7 @@ def has_re2c():
309315
n.comment('Tests all build into ninja_test executable.')
310316

311317
variables = []
312-
test_cflags = None
318+
test_cflags = cflags[:]
313319
test_ldflags = None
314320
test_libs = libs
315321
objs = []
@@ -328,13 +334,17 @@ def has_re2c():
328334
os.path.join(path, 'src', 'gtest_main.cc'),
329335
variables=[('cflags', gtest_cflags)])
330336

331-
test_cflags = cflags + ['-DGTEST_HAS_RTTI=0',
332-
'-I%s' % os.path.join(path, 'include')]
337+
test_cflags.append('-I%s' % os.path.join(path, 'include'))
333338
elif platform == 'windows':
334339
test_libs.extend(['gtest_main.lib', 'gtest.lib'])
335340
else:
341+
test_cflags.append('-DGTEST_HAS_RTTI=0')
336342
test_libs.extend(['-lgtest_main', '-lgtest'])
337343

344+
if test_cflags == cflags:
345+
test_cflags = None
346+
347+
n.variable('test_cflags', test_cflags)
338348
for name in ['build_log_test',
339349
'build_test',
340350
'clean_test',
@@ -348,8 +358,8 @@ def has_re2c():
348358
'subprocess_test',
349359
'test',
350360
'util_test']:
351-
objs += cxx(name, variables=[('cflags', test_cflags)])
352-
if platform == 'windows':
361+
objs += cxx(name, variables=[('cflags', '$test_cflags')])
362+
if platform in ('windows', 'mingw'):
353363
for name in ['includes_normalize_test', 'msvc_helper_test']:
354364
objs += cxx(name, variables=[('cflags', test_cflags)])
355365

@@ -362,7 +372,7 @@ def has_re2c():
362372
all_targets += ninja_test
363373

364374

365-
n.comment('Ancilliary executables.')
375+
n.comment('Ancillary executables.')
366376
objs = cxx('parser_perftest')
367377
all_targets += n.build(binary('parser_perftest'), 'link', objs,
368378
implicit=ninja_lib, variables=[('libs', libs)])
@@ -427,23 +437,11 @@ def has_re2c():
427437
if host == 'linux':
428438
n.comment('Packaging')
429439
n.rule('rpmbuild',
430-
command="rpmbuild \
431-
--define 'ver git' \
432-
--define \"rel `git rev-parse --short HEAD`\" \
433-
--define '_topdir %(pwd)/rpm-build' \
434-
--define '_builddir %{_topdir}' \
435-
--define '_rpmdir %{_topdir}' \
436-
--define '_srcrpmdir %{_topdir}' \
437-
--define '_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm' \
438-
--define '_specdir %{_topdir}' \
439-
--define '_sourcedir %{_topdir}' \
440-
--quiet \
441-
-bb misc/packaging/ninja.spec",
442-
description='Building RPM..')
443-
n.build('rpm', 'rpmbuild',
444-
implicit=['ninja','README', 'COPYING', doc('manual.html')])
440+
command="misc/packaging/rpmbuild.sh",
441+
description='Building rpms..')
442+
n.build('rpm', 'rpmbuild')
445443
n.newline()
446444

447445
n.build('all', 'phony', all_targets)
448446

449-
print 'wrote %s.' % BUILD_FILENAME
447+
print('wrote %s.' % BUILD_FILENAME)

doc/manual.asciidoc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ Ninja supports one environment variable to control its behavior.
215215
Several placeholders are available:
216216
* `%s`: The number of started edges.
217217
* `%t`: The total number of edges that must be run to complete the build.
218+
* `%p`: The percentage of started edges.
218219
* `%r`: The number of currently running edges.
219220
* `%u`: The number of remaining edges to start.
220221
* `%f`: The number of finished edges.
@@ -420,6 +421,59 @@ If the top-level Ninja file is specified as an output of any build
420421
statement and it is out of date, Ninja will rebuild and reload it
421422
before building the targets requested by the user.
422423
424+
Pools
425+
~~~~~
426+
427+
Pools allow you to allocate one or more rules or edges a finite number
428+
of concurrent jobs which is more tightly restricted than the default
429+
parallelism.
430+
431+
This can be useful, for example, to restrict a particular expensive rule
432+
(like link steps for huge executables), or to restrict particular build
433+
statements which you know perform poorly when run concurrently.
434+
435+
Each pool has a `depth` variable which is specified in the build file.
436+
The pool is then referred to with the `pool` variable on either a rule
437+
or a build statement.
438+
439+
No matter what pools you specify, ninja will never run more concurrent jobs
440+
than the default parallelism, or the number of jobs specified on the command
441+
line (with -j).
442+
443+
----------------
444+
# No more than 4 links at a time.
445+
pool link_pool
446+
depth = 4
447+
448+
# No more than 1 heavy object at a time.
449+
pool heavy_object_pool
450+
depth = 1
451+
452+
rule link
453+
...
454+
pool = link_pool
455+
456+
rule cc
457+
...
458+
459+
# The link_pool is used here. Only 4 links will run concurrently.
460+
build foo.exe: link input.obj
461+
462+
# A build statement can be exempted from its rule's pool by setting an
463+
# empty pool. This effectively puts the build statement back into the default
464+
# pool, which has infinite depth.
465+
build other.exe: link input.obj
466+
pool =
467+
468+
# A build statement can specify a pool directly.
469+
# Only one of these builds will run at a time.
470+
build heavy_object1.obj: cc heavy_obj1.cc
471+
pool = heavy_object_pool
472+
build heavy_object2.obj: cc heavy_obj2.cc
473+
pool = heavy_object_pool
474+
475+
----------------
476+
423477
424478
Generating Ninja files from code
425479
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

misc/bash-completion

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@
1616
# . path/to/ninja/misc/bash-completion
1717

1818
_ninja_target() {
19-
local cur targets
19+
local cur targets dir line targets_command OPTIND
2020
cur="${COMP_WORDS[COMP_CWORD]}"
21-
targets=$((ninja -t targets all 2>/dev/null) | awk -F: '{print $1}')
21+
dir="."
22+
line=$(echo ${COMP_LINE} | cut -d" " -f 2-)
23+
while getopts C: opt "${line[@]}"; do
24+
case $opt in
25+
C) dir="$OPTARG" ;;
26+
esac
27+
done;
28+
targets_command="ninja -C ${dir} -t targets all"
29+
targets=$((${targets_command} 2>/dev/null) | awk -F: '{print $1}')
2230
COMPREPLY=($(compgen -W "$targets" -- "$cur"))
2331
return 0
2432
}

misc/ninja-mode.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
(setq ninja-keywords
1919
(list
2020
'("^#.*" . font-lock-comment-face)
21-
(cons (concat "^" (regexp-opt '("rule" "build" "subninja" "include")
21+
(cons (concat "^" (regexp-opt '("rule" "build" "subninja" "include"
22+
"pool" "default")
2223
'words))
2324
font-lock-keyword-face)
2425
'("\\([[:alnum:]_]+\\) =" . (1 font-lock-variable-name-face))

0 commit comments

Comments
 (0)