Skip to content

Commit

Permalink
Merge pull request #4611 from jcbrill/jbrill-mscommon-debug
Browse files Browse the repository at this point in the history
Resolve 4605: enhance SCONS_MSCOMMON_DEBUG handling of invalid input
  • Loading branch information
bdbaddog authored Oct 12, 2024
2 parents cbb75dc + 2dac3e0 commit d567831
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ NOTE: Python 3.6 support is deprecated and will be dropped in a future release.

RELEASE VERSION/DATE TO BE FILLED IN LATER

From Joseph Brill:
- Added error handling when creating MS VC detection debug log file specified by
SCONS_MSCOMMON_DEBUG

From Dillan Mills:
- Fix support for short options (`-x`).

Expand Down
3 changes: 2 additions & 1 deletion RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ FIXES
following the option, with no spaces (e.g. -j5 and not -j 5).
- Fix a problem with compilation_db component initialization - the
entries for assembler files were not being set up correctly.

- On Darwin, PermissionErrors are now handled while trying to access
/etc/paths.d. This may occur if SCons is invoked in a sandboxed environment
(such as Nix).
- Added error handling when creating MS VC detection debug log file specified by
SCONS_MSCOMMON_DEBUG

- Fix nasm test for missing include file, cleanup.

Expand Down
22 changes: 20 additions & 2 deletions SCons/Tool/MSCommon/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,25 @@
from subprocess import DEVNULL, PIPE
from pathlib import Path

import SCons.Errors
import SCons.Util
import SCons.Warnings

class MSVCCacheInvalidWarning(SCons.Warnings.WarningOnByDefault):
pass

def _check_logfile(logfile):
if logfile and '"' in logfile:
err_msg = (
"SCONS_MSCOMMON_DEBUG value contains double quote character(s)\n"
f" SCONS_MSCOMMON_DEBUG={logfile}"
)
raise SCons.Errors.UserError(err_msg)
return logfile

# SCONS_MSCOMMON_DEBUG is internal-use so undocumented:
# set to '-' to print to console, else set to filename to log to
LOGFILE = os.environ.get('SCONS_MSCOMMON_DEBUG')
LOGFILE = _check_logfile(os.environ.get('SCONS_MSCOMMON_DEBUG'))
if LOGFILE:
import logging

Expand Down Expand Up @@ -129,7 +139,15 @@ def format(self, record):
log_handler = logging.StreamHandler(sys.stdout)
else:
log_prefix = ''
log_handler = logging.FileHandler(filename=LOGFILE)
try:
log_handler = logging.FileHandler(filename=LOGFILE)
except (OSError, FileNotFoundError) as e:
err_msg = (
"Could not create logfile, check SCONS_MSCOMMON_DEBUG\n"
f" SCONS_MSCOMMON_DEBUG={LOGFILE}\n"
f" {e.__class__.__name__}: {str(e)}"
)
raise SCons.Errors.UserError(err_msg)
log_formatter = _CustomFormatter(log_prefix)
log_handler.setFormatter(log_formatter)
logger = logging.getLogger(name=__name__)
Expand Down

0 comments on commit d567831

Please sign in to comment.