-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Propagate supbrocess' exit codes to the ninja exit code #2540
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,16 +10,17 @@ | |
import subprocess | ||
import sys | ||
import tempfile | ||
import typing as T | ||
import unittest | ||
from textwrap import dedent | ||
import typing as T | ||
|
||
default_env = dict(os.environ) | ||
default_env.pop('NINJA_STATUS', None) | ||
default_env.pop('CLICOLOR_FORCE', None) | ||
default_env['TERM'] = '' | ||
NINJA_PATH = os.path.abspath('./ninja') | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the pep-8 requirement "two empty lines before and after function/class definitions" |
||
def remove_non_visible_lines(raw_output: bytes) -> str: | ||
# When running in a smart terminal, Ninja uses CR (\r) to | ||
# return the cursor to the start of the current line, prints | ||
|
@@ -120,7 +121,7 @@ def run( | |
cwd=self.d.name, env=env) | ||
except subprocess.CalledProcessError as err: | ||
if print_err_output: | ||
sys.stdout.buffer.write(err.output) | ||
sys.stdout.buffer.write(err.output) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having mixed alignments in the same file confuses very much. Should I revert it? |
||
err.cooked_output = remove_non_visible_lines(err.output) | ||
raise err | ||
|
||
|
@@ -152,14 +153,18 @@ class Output(unittest.TestCase): | |
'', | ||
)) | ||
|
||
def _test_expected_error(self, plan: str, flags: T.Optional[str], expected: str): | ||
def _test_expected_error(self, plan: str, flags: T.Optional[str],expected: str, | ||
*args, exit_code: T.Optional[int]=None, **kwargs)->None: | ||
"""Run Ninja with a given plan and flags, and verify its cooked output against an expected content. | ||
All *args and **kwargs are passed to the `run` function | ||
""" | ||
actual = '' | ||
try: | ||
actual = run(plan, flags, print_err_output=False) | ||
except subprocess.CalledProcessError as err: | ||
actual = err.cooked_output | ||
kwargs['print_err_output'] = False | ||
with self.assertRaises(subprocess.CalledProcessError) as cm: | ||
run(plan, flags, *args, **kwargs) | ||
actual = cm.exception.cooked_output | ||
if exit_code is not None: | ||
self.assertEqual(cm.exception.returncode, exit_code) | ||
self.assertEqual(expected, actual) | ||
|
||
def test_issue_1418(self) -> None: | ||
|
@@ -281,6 +286,75 @@ def test_issue_2048(self) -> None: | |
except subprocess.CalledProcessError as err: | ||
self.fail("non-zero exit code with: " + err.output) | ||
|
||
def test_pr_2540(self)->None: | ||
py = sys.executable | ||
plan = f'''\ | ||
rule CUSTOM_COMMAND | ||
command = $COMMAND | ||
|
||
build 124: CUSTOM_COMMAND | ||
COMMAND = {py} -c 'exit(124)' | ||
|
||
build 127: CUSTOM_COMMAND | ||
COMMAND = {py} -c 'exit(127)' | ||
|
||
build 130: CUSTOM_COMMAND | ||
COMMAND = {py} -c 'exit(130)' | ||
|
||
build 137: CUSTOM_COMMAND | ||
COMMAND = {py} -c 'exit(137)' | ||
|
||
build success: CUSTOM_COMMAND | ||
COMMAND = sleep 0.3; echo success | ||
''' | ||
# Disable colors | ||
env = default_env.copy() | ||
env['TERM'] = 'dumb' | ||
self._test_expected_error( | ||
plan, '124', | ||
f'''[1/1] {py} -c 'exit(124)' | ||
FAILED: [code=124] 124 \n{py} -c 'exit(124)' | ||
ninja: build stopped: subcommand failed. | ||
''', | ||
exit_code=124, env=env, | ||
) | ||
self._test_expected_error( | ||
plan, '127', | ||
f'''[1/1] {py} -c 'exit(127)' | ||
FAILED: [code=127] 127 \n{py} -c 'exit(127)' | ||
ninja: build stopped: subcommand failed. | ||
''', | ||
exit_code=127, env=env, | ||
) | ||
self._test_expected_error( | ||
plan, '130', | ||
'ninja: build stopped: interrupted by user.\n', | ||
exit_code=130, env=env, | ||
) | ||
self._test_expected_error( | ||
plan, '137', | ||
f'''[1/1] {py} -c 'exit(137)' | ||
FAILED: [code=137] 137 \n{py} -c 'exit(137)' | ||
ninja: build stopped: subcommand failed. | ||
''', | ||
exit_code=137, env=env, | ||
) | ||
self._test_expected_error( | ||
plan, 'non-existent-target', | ||
"ninja: error: unknown target 'non-existent-target'\n", | ||
exit_code=1, env=env, | ||
) | ||
self._test_expected_error( | ||
plan, '-j2 success 127', | ||
f'''[1/2] {py} -c 'exit(127)' | ||
FAILED: [code=127] 127 \n{py} -c 'exit(127)' | ||
[2/2] sleep 0.3; echo success | ||
success | ||
ninja: build stopped: subcommand failed. | ||
''', | ||
exit_code=127, env=env, | ||
) | ||
|
||
def test_depfile_directory_creation(self) -> None: | ||
b = BuildDir('''\ | ||
rule touch | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change? Probably some Python formatter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was done by https://github.com/PyCQA/isort/, yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ok to keep it sorted? The same question regarding the other pep8-related changes