Skip to content

Commit

Permalink
[GR-53896] Avoid assuming there’s a PATH variable defined.
Browse files Browse the repository at this point in the history
PullRequest: mx/1792
  • Loading branch information
dougxc committed May 6, 2024
2 parents 6caac1b + b98263f commit c970991
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
19 changes: 10 additions & 9 deletions src/mx/_impl/mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -7709,28 +7709,29 @@ def redirect(stream):

# wait 30 seconds for the Java process to launch and report the port number
retries = 0
myself = f"{self.name}[{p.pid}]"
while self.port is None:
retries = retries + 1
returncode = p.poll()
if returncode is not None:
raise RuntimeError('Error starting ' + self.name() + ': returncode=' + str(returncode) + '\n' + ''.join(pout))
raise RuntimeError(f'Error starting {myself}: returncode={returncode}\n{"".join(pout)}')
if retries == 299:
warn('Killing ' + self.name() + ' after failing to see port number after nearly 30 seconds')
warn(f'Killing {myself} after failing to see port number after nearly 30 seconds')
os.kill(p.pid, signal.SIGKILL)
time.sleep(1.0)
elif retries > 300:
raise RuntimeError('Error starting ' + self.name() + ': No port number was found in output after 30 seconds\n' + ''.join(pout))
raise RuntimeError(f'Error starting {myself}: No port number was found in output after 30 seconds\n{"".join(pout)}')
else:
time.sleep(0.1)

self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.closed = False
try:
self.connection.connect(('127.0.0.1', self.port))
logv('[Started ' + str(self) + ']')
logv(f'[Started {myself}')
return
except socket.error as e:
logv('[Error starting ' + str(self) + ': ' + str(e) + ']')
logv(f'[Error starting {myself}: {e}]')
raise e

def _noticePort(self, data):
Expand Down Expand Up @@ -7767,7 +7768,7 @@ def compile(self, compilerArgs):
if _opts.very_verbose:
retcode = detailed_retcode
else:
log('[exit code: ' + str(retcode) + ']')
log(f'[exit code: {retcode}]')
elif retcode == 2:
retcode = detailed_retcode
abort(retcode)
Expand All @@ -7780,9 +7781,9 @@ def shutdown(self):
self.connection.send(f'{CompilerDaemon.header_shutdown}\n'.encode('utf8'))
self.connection.close()
self.closed = True
logv('[Stopped ' + str(self) + ']')
logv(f'[Stopped {self}]')
except socket.error as e:
logv('Error stopping ' + str(self) + ': ' + str(e))
logv(f'Error stopping {self}: {e}')

def __str__(self):
return f"{self.name()} on port {self.port} for {self.jdk} with VM args {self.jvmArgs}"
Expand Down Expand Up @@ -18180,7 +18181,7 @@ def alarm_handler(signum, frame):
_CACHE_DIR = get_env('MX_CACHE_DIR', join(dot_mx_dir(), 'cache'))

# The version must be updated for every PR (checked in CI) and the comment should reflect the PR's issue
version = VersionSpec("7.25.0") # DownloadableLibrary
version = VersionSpec("7.25.1") # Avoid assuming there’s a PATH variable defined

_mx_start_datetime = datetime.utcnow()

Expand Down
12 changes: 2 additions & 10 deletions src/mx/_impl/mx_proftool.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,14 +920,6 @@ def demangled_name(self, short_class_names: bool = False):
return self.symbol


def _which(executable):
for path in os.environ['PATH'].split(os.pathsep):
f = os.path.join(path.strip('"'), executable)
if os.path.isfile(f) and os.access(f, os.X_OK):
return f
return None


class CppDemangler:
"""An interface for the binutils c++filt demangler, which can demangle C++ symbols."""

Expand All @@ -945,7 +937,7 @@ def warn_if_unsupported(cls):
def is_supported(cls) -> bool:
"""Lazily checks whether c++filt is supported."""
if cls._cppfilt_available is None:
cls._cppfilt_available = _which(cls.CPPFILT) is not None
cls._cppfilt_available = shutil.which(cls.CPPFILT) is not None
return cls._cppfilt_available

@classmethod
Expand Down Expand Up @@ -1144,7 +1136,7 @@ def __init__(self, files):
@staticmethod
def is_supported():
if PerfOutput._perf_available is None:
PerfOutput._perf_available = _which('perf') is not None
PerfOutput._perf_available = shutil.which('perf') is not None
return PerfOutput._perf_available

@staticmethod
Expand Down

0 comments on commit c970991

Please sign in to comment.