-
-
Save mgehre/4d1720580d0ad2bf8cafa876f737cfec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import json | |
import subprocess | |
import sys | |
import os | |
BUILD_DIR = '../build-wsl' | |
LIFETIME_CLANG = os.path.join(BUILD_DIR, 'bin', 'clang') | |
def remove_o_parameter(args): | |
a = args.split(" ") | |
pos = a.index("-o") | |
return " ".join(a[:pos - 1] + a[pos + 2:]) | |
with open(os.path.join(BUILD_DIR, 'compile_commands.json'), 'r') as f: | |
objs = json.load(f) | |
for obj in objs: | |
cmd = remove_o_parameter(obj["command"]) | |
# Replace compiler that was used to build LLVM/clang by the | |
# -Wlifetime-enabled compiler that was built | |
cmd = cmd.replace('/usr/bin/clang++-7', LIFETIME_CLANG) | |
cmd = cmd.replace('/usr/bin/c++', LIFETIME_CLANG) | |
cmd_with_lifetime = cmd + " -fsyntax-only -Wlifetime -Wlifetime-debug -Wno-unused-command-line-argument" | |
print(cmd_with_lifetime) | |
r = subprocess.run(cmd_with_lifetime, shell=True, cwd=obj["directory"]) | |
if r.returncode != 0: | |
print(r.returncode) | |
print(cmd) | |
subprocess.check_call(cmd + " -E", | |
shell=True, | |
stdout=open('test.cpp', 'w'), | |
cwd=obj["directory"]) | |
cmd = cmd.replace(obj["file"], 'test.cpp') | |
cmd_with_lifetime = cmd_with_lifetime.replace(obj["file"], 'test.cpp') | |
with open('cred', 'w') as f: | |
f.write("#!/bin/bash\n") | |
# f.write("cd " + dir_unix + "\n") | |
f.write(cmd + " -fsyntax-only && ! " + cmd_with_lifetime) | |
print("Running: creduce ./cred test.cpp") | |
subprocess.check_call(["creduce", "./cred", "test.cpp"]) | |
sys.exit(1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment