diff options
author | Jan Niklas Hasse <jhasse@bixense.com> | 2019-01-30 18:57:52 (GMT) |
---|---|---|
committer | Jan Niklas Hasse <jhasse@bixense.com> | 2019-01-30 18:57:52 (GMT) |
commit | 6d5a4b9eb973e9d82d63f8f9a421fad97d20e6d0 (patch) | |
tree | b427025388b026f169a135343c8a275379314127 /misc | |
parent | 253e94c1fa511704baeb61cf69995bbf09ba435e (diff) | |
parent | 0c158431f30a14d771e5c82c1e69eff7c69a08ce (diff) | |
download | Ninja-6d5a4b9eb973e9d82d63f8f9a421fad97d20e6d0.zip Ninja-6d5a4b9eb973e9d82d63f8f9a421fad97d20e6d0.tar.gz Ninja-6d5a4b9eb973e9d82d63f8f9a421fad97d20e6d0.tar.bz2 |
Merge branch 'master' into release
Diffstat (limited to 'misc')
-rw-r--r-- | misc/ninja-mode.el | 2 | ||||
-rw-r--r-- | misc/ninja.vim | 18 | ||||
-rw-r--r-- | misc/ninja_syntax.py | 6 | ||||
-rwxr-xr-x | misc/ninja_syntax_test.py | 4 | ||||
-rwxr-xr-x | misc/output_test.py | 103 | ||||
-rw-r--r-- | misc/zsh-completion | 2 |
6 files changed, 122 insertions, 13 deletions
diff --git a/misc/ninja-mode.el b/misc/ninja-mode.el index 639e537..8b975d5 100644 --- a/misc/ninja-mode.el +++ b/misc/ninja-mode.el @@ -56,7 +56,7 @@ (save-excursion (goto-char (line-end-position 0)) (or - ;; If we're continuting the previous line, it's not a + ;; If we're continuing the previous line, it's not a ;; comment. (not (eq ?$ (char-before))) ;; Except if the previous line is a comment as well, as the diff --git a/misc/ninja.vim b/misc/ninja.vim index 190d9ce..c1ffd50 100644 --- a/misc/ninja.vim +++ b/misc/ninja.vim @@ -1,8 +1,8 @@ " ninja build file syntax. " Language: ninja build file as described at " http://ninja-build.org/manual.html -" Version: 1.4 -" Last Change: 2014/05/13 +" Version: 1.5 +" Last Change: 2018/04/05 " Maintainer: Nicolas Weber <nicolasweber@gmx.de> " Version 1.4 of this script is in the upstream vim repository and will be " included in the next vim release. If you change this, please send your change @@ -21,7 +21,10 @@ set cpo&vim syn case match -syn match ninjaComment /#.*/ contains=@Spell +" Comments are only matched when the # is at the beginning of the line (with +" optional whitespace), as long as the prior line didn't end with a $ +" continuation. +syn match ninjaComment /\(\$\n\)\@<!\_^\s*#.*$/ contains=@Spell " Toplevel statements are the ones listed here and " toplevel variable assignments (ident '=' value). @@ -38,12 +41,13 @@ syn match ninjaKeyword "^subninja\>" " limited set of magic variables, 'build' allows general " let assignments. " manifest_parser.cc, ParseRule() -syn region ninjaRule start="^rule" end="^\ze\S" contains=ALL transparent -syn keyword ninjaRuleCommand contained command deps depfile description generator +syn region ninjaRule start="^rule" end="^\ze\S" contains=TOP transparent +syn keyword ninjaRuleCommand contained containedin=ninjaRule command + \ deps depfile description generator \ pool restat rspfile rspfile_content -syn region ninjaPool start="^pool" end="^\ze\S" contains=ALL transparent -syn keyword ninjaPoolCommand contained depth +syn region ninjaPool start="^pool" end="^\ze\S" contains=TOP transparent +syn keyword ninjaPoolCommand contained containedin=ninjaPool depth " Strings are parsed as follows: " lexer.in.cc, ReadEvalString() diff --git a/misc/ninja_syntax.py b/misc/ninja_syntax.py index 5c52ea2..ebe6490 100644 --- a/misc/ninja_syntax.py +++ b/misc/ninja_syntax.py @@ -21,7 +21,7 @@ class Writer(object): def newline(self): self.output.write('\n') - def comment(self, text, has_path=False): + def comment(self, text): for line in textwrap.wrap(text, self.width - 2, break_long_words=False, break_on_hyphens=False): self.output.write('# ' + line + '\n') @@ -60,7 +60,7 @@ class Writer(object): self.variable('deps', deps, indent=1) def build(self, outputs, rule, inputs=None, implicit=None, order_only=None, - variables=None, implicit_outputs=None): + variables=None, implicit_outputs=None, pool=None): outputs = as_list(outputs) out_outputs = [escape_path(x) for x in outputs] all_inputs = [escape_path(x) for x in as_list(inputs)] @@ -81,6 +81,8 @@ class Writer(object): self._line('build %s: %s' % (' '.join(out_outputs), ' '.join([rule] + all_inputs))) + if pool is not None: + self._line(' pool = %s' % pool) if variables: if isinstance(variables, dict): diff --git a/misc/ninja_syntax_test.py b/misc/ninja_syntax_test.py index 07e3ed3..90ff9c6 100755 --- a/misc/ninja_syntax_test.py +++ b/misc/ninja_syntax_test.py @@ -46,13 +46,13 @@ class TestLineWordWrap(unittest.TestCase): self.out.getvalue()) def test_comment_wrap(self): - # Filenames shoud not be wrapped + # Filenames should not be wrapped self.n.comment('Hello /usr/local/build-tools/bin') self.assertEqual('# Hello\n# /usr/local/build-tools/bin\n', self.out.getvalue()) def test_short_words_indented(self): - # Test that indent is taking into acount when breaking subsequent lines. + # Test that indent is taking into account when breaking subsequent lines. # The second line should not be ' to tree', as that's longer than the # test layout width of 8. self.n._line('line_one to tree') diff --git a/misc/output_test.py b/misc/output_test.py new file mode 100755 index 0000000..1dcde10 --- /dev/null +++ b/misc/output_test.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 + +"""Runs ./ninja and checks if the output is correct. + +In order to simulate a smart terminal it uses the 'script' command. +""" + +import os +import platform +import subprocess +import sys +import tempfile +import unittest + +default_env = dict(os.environ) +if 'NINJA_STATUS' in default_env: + del default_env['NINJA_STATUS'] +if 'CLICOLOR_FORCE' in default_env: + del default_env['CLICOLOR_FORCE'] +default_env['TERM'] = '' + +def run(build_ninja, flags='', pipe=False, env=default_env): + with tempfile.NamedTemporaryFile('w') as f: + f.write(build_ninja) + f.flush() + ninja_cmd = './ninja {} -f {}'.format(flags, f.name) + try: + if pipe: + output = subprocess.check_output([ninja_cmd], shell=True, env=env) + elif platform.system() == 'Darwin': + output = subprocess.check_output(['script', '-q', '/dev/null', 'bash', '-c', ninja_cmd], + env=env) + else: + output = subprocess.check_output(['script', '-qfec', ninja_cmd, '/dev/null'], + env=env) + except subprocess.CalledProcessError as err: + sys.stdout.buffer.write(err.output) + raise err + final_output = '' + for line in output.decode('utf-8').splitlines(True): + if len(line) > 0 and line[-1] == '\r': + continue + final_output += line.replace('\r', '') + return final_output + +class Output(unittest.TestCase): + def test_issue_1418(self): + self.assertEqual(run( +'''rule echo + command = sleep $delay && echo $out + description = echo $out + +build a: echo + delay = 3 +build b: echo + delay = 2 +build c: echo + delay = 1 +'''), +'''[1/3] echo c\x1b[K +c +[2/3] echo b\x1b[K +b +[3/3] echo a\x1b[K +a +''') + + def test_issue_1214(self): + print_red = '''rule echo + command = printf '\x1b[31mred\x1b[0m' + description = echo $out + +build a: echo +''' + # Only strip color when ninja's output is piped. + self.assertEqual(run(print_red), +'''[1/1] echo a\x1b[K +\x1b[31mred\x1b[0m +''') + self.assertEqual(run(print_red, pipe=True), +'''[1/1] echo a +red +''') + # Even in verbose mode, colors should still only be stripped when piped. + self.assertEqual(run(print_red, flags='-v'), +'''[1/1] printf '\x1b[31mred\x1b[0m' +\x1b[31mred\x1b[0m +''') + self.assertEqual(run(print_red, flags='-v', pipe=True), +'''[1/1] printf '\x1b[31mred\x1b[0m' +red +''') + + # CLICOLOR_FORCE=1 can be used to disable escape code stripping. + env = default_env.copy() + env['CLICOLOR_FORCE'] = '1' + self.assertEqual(run(print_red, pipe=True, env=env), +'''[1/1] echo a +\x1b[31mred\x1b[0m +''') + +if __name__ == '__main__': + unittest.main() diff --git a/misc/zsh-completion b/misc/zsh-completion index bf23fac..4cee3b8 100644 --- a/misc/zsh-completion +++ b/misc/zsh-completion @@ -14,7 +14,7 @@ # limitations under the License. # Add the following to your .zshrc to tab-complete ninja targets -# . path/to/ninja/misc/zsh-completion +# fpath=(path/to/ninja/misc/zsh-completion $fpath) __get_targets() { dir="." |