Skip to content

Commit

Permalink
Use commands.json hardcoded instead of the version file and fix subpr…
Browse files Browse the repository at this point in the history
…ocess.PIPE usage
  • Loading branch information
whisperity committed Mar 14, 2017
1 parent eb8eab9 commit 7497433
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
17 changes: 7 additions & 10 deletions bin/CodeChecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,17 +597,14 @@ def signal_handler(sig, frame):
LOG.debug(os.environ.get('LD_LIBRARY_PATH'))

# Load the available CodeChecker subcommands.
# This list is generated dynamically by scripts/build_package.py
version_cfg = os.path.join(os.environ['CC_PACKAGE_ROOT'],
"config", "version.json")
# This list is generated dynamically by scripts/build_package.py, and is
# always meant to be available alongside the CodeChecker.py.
commands_cfg = os.path.join(os.path.dirname(__file__), "commands.json")

with open(version_cfg) as cfg_file:
config = json.load(cfg_file)

if 'available_commands' not in config:
config['available_commands'] = []
with open(commands_cfg) as cfg_file:
commands = json.load(cfg_file)

LOG.debug("Available CodeChecker subcommands: ")
LOG.debug(config['available_commands'])
LOG.debug(commands)

main(config['available_commands'])
main(commands)
17 changes: 11 additions & 6 deletions libcodechecker/log/host_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# -------------------------------------------------------------------------

import errno
import os
import subprocess

from libcodechecker.logger import LoggerFactory
Expand All @@ -18,21 +19,25 @@ def check_intercept(env):
"""
intercept_cmd = ['intercept-build', '--help']
try:
res = subprocess.call(intercept_cmd,
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
with open(os.devnull, 'wb') as null:
res = subprocess.check_call(intercept_cmd,
env=env,
stdout=null,
stderr=null)

if not res:
return True
else:
LOG.debug('Failed to run: "' + ' '.join(intercept_cmd) + '"')
return False

except subprocess.CalledProcessError:
LOG.debug('Failed to run: "' + ' '.join(intercept_cmd) + '", process '
'returned non-zero exit code.')
return False
except OSError as oerr:
if oerr.errno == errno.ENOENT:
# Not just intercept-build can be used for logging.
# It is possible that another build logger is available.
LOG.debug(oerr)
LOG.debug('Failed to run: ' + ' '.join(intercept_cmd) + '"')
LOG.debug('Failed to run: "' + ' '.join(intercept_cmd) + '"')
return False
15 changes: 9 additions & 6 deletions scripts/build_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,14 +639,19 @@ def build_package(repository_root, build_package_config, env=None):
time_now = time.strftime("%Y-%m-%dT%H:%M")
version_json_data['package_build_date'] = time_now

version_json_data['available_commands'] = []
# Rewrite version config file with the extended data.
with open(version_file, 'w') as v_file:
v_file.write(
json.dumps(version_json_data, sort_keys=True, indent=4))

# CodeChecker main scripts.
LOG.debug('Copy main codechecker files')
source = os.path.join(repository_root, 'bin')
target = os.path.join(package_root, package_layout['bin'])
target_cc = os.path.join(package_root, package_layout['cc_bin'])

available_commands = []

for _, _, files in os.walk(source):
for f in files:
if not f.endswith(".py"):
Expand All @@ -659,15 +664,13 @@ def build_package(repository_root, build_package_config, env=None):
LOG.info("CodeChecker command '{0}' available.".format(
commandname))

version_json_data['available_commands'].append(commandname)
available_commands.append(commandname)
else:
# .py files are Python code that must run in a valid env.
shutil.copy2(os.path.join(source, f), target_cc)

# Rewrite version config file with the extended data.
with open(version_file, 'w') as v_file:
v_file.write(
json.dumps(version_json_data, sort_keys=True, indent=4))
with open(os.path.join(target_cc, 'commands.json'), 'w') as commands:
json.dump(available_commands, commands, sort_keys=True)

# CodeChecker web client.
LOG.debug('Copy web client files')
Expand Down

0 comments on commit 7497433

Please sign in to comment.