Skip to content

Commit

Permalink
rething command wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
rizsotto committed Aug 16, 2016
1 parent fee82a6 commit dc6c8e3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
30 changes: 15 additions & 15 deletions libscanbuild/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
import functools
import subprocess

WRAPPER_CC = 'INTERCEPT_BUILD_CC'
WRAPPER_CXX = 'INTERCEPT_BUILD_CXX'
WRAPPER_VERBOSE = 'INTERCEPT_BUILD_VERBOSE'


def duplicate_check(method):
""" Predicate to detect duplicated entries.
Expand Down Expand Up @@ -125,15 +129,13 @@ def wrapper_entry_point(function):
def wrapper():
""" It executes the compilation and calls the wrapped method. """

compiler_wrapper_name = os.path.basename(sys.argv[0])
# initialize wrapper logging
logging.basicConfig(format='%(name)s: %(message)s',
level=os.getenv('INTERCEPT_BUILD_VERBOSE', 'INFO'))
logging.getLogger().name = compiler_wrapper_name
# execute with real compiler
language = 'c++' if compiler_wrapper_name[-2:] == '++' else 'c'
compiler = os.environ['INTERCEPT_BUILD_CC'] if language == 'c' \
else os.environ['INTERCEPT_BUILD_CXX']
# set logging level when neeeded
verbose = bool(os.getenv(WRAPPER_VERBOSE, '0'))
reconfigure_logging(verbose)
# find out what is the real compiler
is_cxx = os.path.basename(sys.argv[0]).endswith('++')
compiler = os.getenv(WRAPPER_CXX) if is_cxx else os.getenv(WRAPPER_CC)
# execute compilation with the real compiler
command = [compiler] + sys.argv[1:]
logging.debug('compilation: %s', command)
result = subprocess.call(command)
Expand All @@ -142,9 +144,7 @@ def wrapper():
try:
function(compiler=compiler, command=command, result=result)
except:
logging.warning('wrapped function failed', exc_info=True)
finally:
logging.shutdown()
logging.exception('Compiler wrapper failed complete.')
# ... return the real compiler exit code instead.
return result

Expand All @@ -158,7 +158,7 @@ def wrapper_environment(c_wrapper, cxx_wrapper, c_compiler, cxx_compiler,
return {
'CC': c_wrapper,
'CXX': cxx_wrapper,
'INTERCEPT_BUILD_CC': c_compiler,
'INTERCEPT_BUILD_CXX': cxx_compiler,
'INTERCEPT_BUILD_VERBOSE': 'DEBUG' if verbose > 2 else 'WARNING'
WRAPPER_CC: c_compiler,
WRAPPER_CXX: cxx_compiler,
WRAPPER_VERBOSE: str(verbose)
}
1 change: 1 addition & 0 deletions libscanbuild/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def setup_environment(args, bin_dir, destination):


@wrapper_entry_point
@command_entry_point
def analyze_build_wrapper(**kwargs):
""" Entry point for `analyze-cc` and `analyze-c++` compiler wrappers. """

Expand Down
1 change: 1 addition & 0 deletions libscanbuild/intercept.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def setup_environment(args, destination, bin_dir):


@wrapper_entry_point
@command_entry_point
def intercept_build_wrapper(**kwargs):
""" Entry point for `intercept-cc` and `intercept-c++` compiler wrappers.
Expand Down

0 comments on commit dc6c8e3

Please sign in to comment.