Skip to content

Commit

Permalink
[SCons] Make unrecognized C compiler fatal and update formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and bryanwweber committed Jun 12, 2022
1 parent e8243ae commit 994445a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
27 changes: 14 additions & 13 deletions SConstruct
Expand Up @@ -93,7 +93,7 @@ if not COMMAND_LINE_TARGETS:
sys.exit(1)

if os.name not in ["nt", "posix"]:
logger.error(f"Error: Unrecognized operating system '{os.name}'")
logger.error(f"Unrecognized operating system {os.name!r}")
sys.exit(1)

valid_commands = ("build", "clean", "install", "uninstall",
Expand All @@ -108,7 +108,7 @@ else:

for command in COMMAND_LINE_TARGETS:
if command not in valid_commands and not command.startswith('test'):
logger.error("Unrecognized command line target: {!r}", command)
logger.error(f"Unrecognized command line target: {command!r}")
sys.exit(1)

# update default logging level
Expand Down Expand Up @@ -673,7 +673,7 @@ if "help" in COMMAND_LINE_TARGETS:
with open(output_file, "w+") as fid:
fid.write(message)

logger.status(f"Done writing output options to '{output_file}'.",
logger.status(f"Done writing output options to {output_file!r}.",
print_level=False)

else:
Expand Down Expand Up @@ -807,7 +807,8 @@ elif "clang" in env.subst("$CC"):
config.select("clang")

else:
logger.warning(f"Unrecognized C compiler '{env['CC']}'")
logger.error(f"Unrecognized C compiler {env['CC']!r}")
exit(1)

if env["OS"] == "Windows":
config.select("Windows")
Expand Down Expand Up @@ -872,7 +873,7 @@ if "sdist" in COMMAND_LINE_TARGETS:

for arg in ARGUMENTS:
if arg not in config:
logger.error(f"Encountered unexpected command line option: '{arg}'")
logger.error(f"Encountered unexpected command line option: {arg!r}")
sys.exit(1)

env["cantera_version"] = "3.0.0a1"
Expand All @@ -882,7 +883,7 @@ env['cantera_short_version'] = re.match(r'(\d+\.\d+)', env['cantera_version']).g

try:
env["git_commit"] = get_command_output("git", "rev-parse", "--short", "HEAD")
logger.info(f"Building Cantera from git commit '{env['git_commit']}'")
logger.info(f"Building Cantera from git commit {env['git_commit']!r}")
except (subprocess.CalledProcessError, FileNotFoundError):
env["git_commit"] = "unknown"

Expand Down Expand Up @@ -919,7 +920,7 @@ elif env['env_vars']:
env['ENV'][name] = os.environ[name]
logger.debug(f"Propagating environment variable {name}={env['ENV'][name]}")
elif name not in config["env_vars"].default.split(','):
logger.warning(f"failed to propagate environment variable '{repr(name)}'\n"
logger.warning(f"failed to propagate environment variable {name!r}\n"
"Edit cantera.conf or the build command line to fix this.")

env['extra_inc_dirs'] = [d for d in env['extra_inc_dirs'].split(os.pathsep) if d]
Expand Down Expand Up @@ -1398,11 +1399,11 @@ end program main
if success and 'Hello, world!' in output:
return True
else:
logger.warning(f"Unable to use '{compiler}' to compile the Fortran "
logger.warning(f"Unable to use {compiler!r} to compile the Fortran "
"interface. See config.log for details.")
return False
elif expected:
logger.error(f"Could not find specified Fortran compiler: '{compiler}'")
logger.error(f"Could not find specified Fortran compiler: {compiler!r}")
sys.exit(1)

return False
Expand All @@ -1420,7 +1421,7 @@ if env['f90_interface'] in ('y','default'):
foundF90 = check_fortran(compiler)

if foundF90:
logger.info(f"Using '{env['FORTRAN']}' to build the Fortran 90 interface")
logger.info(f"Using {env['FORTRAN']!r} to build the Fortran 90 interface")
env['f90_interface'] = 'y'
else:
if env['f90_interface'] == 'y':
Expand Down Expand Up @@ -1561,11 +1562,11 @@ if env['python_package'] != 'none':
if env["python_package"] == "default":
logger.warning(
"Not building the Python package because the Python interpreter "
f"'{env['python_cmd']!r}' could not be found.")
f"{env['python_cmd']!r} could not be found.")
env["python_package"] = "none"
else:
logger.error(
f"Could not execute the Python interpreter '{env['python_cmd']!r}'")
f"Could not execute the Python interpreter {env['python_cmd']!r}")
sys.exit(1)
elif python_version < python_min_version:
if env["python_package"] in ("minimal", "full", "default"):
Expand Down Expand Up @@ -1679,7 +1680,7 @@ if env["matlab_toolbox"] == "y":
if not (os.path.isdir(matlab_path) and
os.path.isdir(pjoin(matlab_path, "extern"))):
logger.error(
f"Path set for 'matlab_path' is not correct. Path was '{matlab_path}'")
f"Path set for 'matlab_path' is not correct. Path was {matlab_path!r}")
sys.exit(1)


Expand Down
2 changes: 1 addition & 1 deletion samples/cxx/SConscript
Expand Up @@ -44,7 +44,7 @@ set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS})
localenv.Prepend(CPPPATH=['#include'])

if openmp and not env['HAS_OPENMP']:
logger.info(f"Skipping sample {name} because 'omp.h' was not found.")
logger.info(f"Skipping sample {name!r} because 'omp.h' was not found.")
else:
buildSample(localenv.Program, pjoin(subdir, name),
multi_glob(localenv, subdir, *extensions))
Expand Down
4 changes: 2 additions & 2 deletions site_scons/buildutils.py
Expand Up @@ -468,15 +468,15 @@ def __init__(self, logger):
def status(self, message, *args, **kws):
# custom logger adapted from https://stackoverflow.com/questions/2183233
if self.isEnabledFor(LOGGING_STATUS_NUM):
# logger takes its '*args' as 'args'.
msg, kwargs = self.process(message, kws)
# logger takes its '*args' as 'args'
self._log(LOGGING_STATUS_NUM, msg, args, **kwargs)

def failed(self, message, *args, **kws):
# custom logger adapted from https://stackoverflow.com/questions/2183233
if self.isEnabledFor(LOGGING_FAILED_NUM):
# logger takes its '*args' as 'args'.
msg, kwargs = self.process(message, kws)
# logger takes its '*args' as 'args'
self._log(LOGGING_FAILED_NUM, msg, args, **kwargs)

def process(self, msg, kwargs):
Expand Down
2 changes: 1 addition & 1 deletion test/SConscript
Expand Up @@ -68,7 +68,7 @@ def addTestProgram(subdir, progName, env_vars={}):
code = subprocess.call(cmd, env=env['ENV'], cwd=workDir)

if code:
logger.failed(f"Test '{progName}' exited with code {code}")
logger.failed(f"Test {progName!r} exited with code {code}")
if env["fast_fail_tests"]:
sys.exit(1)
else:
Expand Down

0 comments on commit 994445a

Please sign in to comment.