Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions homcc/client/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,23 @@

logger: logging.Logger = logging.getLogger(__name__)

HOMCC_SAFEGUARD_ENV_VAR: str = "_HOMCC_SAFEGUARD"


def is_recursively_invoked() -> bool:
"""Check whether homcc was called recursively by checking the existence of a safeguard environment variable"""

is_safeguard_active: bool = HOMCC_SAFEGUARD_ENV_VAR in os.environ
os.environ[HOMCC_SAFEGUARD_ENV_VAR] = "1" # activate safeguard
return is_safeguard_active


def main():
# cancel execution if recursive call is detected
if is_recursively_invoked():
print(f"{sys.argv[0]} seems to have been invoked recursively!", file=sys.stderr)
raise SystemExit(os.EX_USAGE)

# load and parse arguments and configuration information
homcc_args_dict, compiler_arguments = parse_cli_args(sys.argv[1:])
homcc_config: ClientConfig = parse_config()
Expand Down
13 changes: 13 additions & 0 deletions tests/e2e/e2e_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,19 @@ def clean_up(self):
Path("foo.o").unlink(missing_ok=True)
Path(self.OUTPUT).unlink(missing_ok=True)

@pytest.mark.timeout(TIMEOUT)
def test_end_to_end_recursive_client(self, unused_tcp_port: int):
try:
subprocess.run( # client receiving itself as compiler arg
self.BasicClientArguments("./homcc/client/main.py", unused_tcp_port).to_list(),
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding="utf-8",
)
except subprocess.CalledProcessError as err:
assert "seems to have been invoked recursively!" in err.stdout

# g++ tests
@pytest.mark.gplusplus
@pytest.mark.timeout(TIMEOUT)
Expand Down