diff --git a/clang/test/3C/find_bin.py b/clang/test/3C/find_bin.py new file mode 100644 index 000000000000..b3a1be3eceae --- /dev/null +++ b/clang/test/3C/find_bin.py @@ -0,0 +1,35 @@ +# Set bin_path to the path that should be prepended to '3c', etc. to run them. +# bin_path will be empty (so $PATH is used) or have a trailing slash. +# +# TODO: Do we have other tools that should use this? + +import sys +import os +os.chdir(os.path.dirname(__file__)) +# Relative paths are now relative to clang/test/3C/ . + +sys.path.insert(0, '../../../llvm/utils/lit') +import lit.util +sys.path.pop(0) + +def die(msg): + sys.stderr.write('Error: %s\n' % msg) + sys.exit(1) + +llvm_obj_maybe = os.environ.get('LLVM_OBJ') +standard_build_dir = '../../../build' +if llvm_obj_maybe is not None: + bin_path = llvm_obj_maybe + '/bin/' + if not os.path.isfile(bin_path + '3c'): + die('$LLVM_OBJ is set but the bin directory does not contain 3c.') +elif os.path.isdir(standard_build_dir): + bin_path = standard_build_dir + '/bin/' + if not os.path.isfile(bin_path + '3c'): + die('The standard build directory exists but does not contain 3c.') +elif lit.util.which('3c') is not None: + # TODO: To help prevent mistakes, validate that the `3c` we found is under a + # build directory linked to the current source tree? Or might users want to + # do unusual things? + bin_path = '' +else: + die('Could not find 3c via $LLVM_OBJ, the standard build directory, or $PATH.') diff --git a/clang/test/3C/processor.py b/clang/test/3C/processor.py old mode 100644 new mode 100755 index 167c80333e31..ef00b8189c75 --- a/clang/test/3C/processor.py +++ b/clang/test/3C/processor.py @@ -1,8 +1,10 @@ +#!/usr/bin/env python import fileinput import sys import os -path_to_monorepo = "/Users/shilpa-roy/checkedc-clang/build/bin/" +import find_bin +bin_path = find_bin.bin_path structs = """ struct np { @@ -131,11 +133,11 @@ def process_smart(filename): elif susproto != "": test = [header, susproto, foo, bar, sus] file = open(filename, "w+") - file.write('\n\n'.join(test)) + file.write('\n\n'.join(test) + '\n') file.close() - os.system("{}3c -alltypes -addcr -output-postfix=checkedALL {}".format(path_to_monorepo, filename)) - os.system("{}3c -addcr -output-postfix=checkedNOALL {}".format(path_to_monorepo, filename)) + os.system("{}3c -alltypes -addcr -output-postfix=checkedALL {}".format(bin_path, filename)) + os.system("{}3c -addcr -output-postfix=checkedNOALL {}".format(bin_path, filename)) process_file_smart(filename, cnameNOALL, cnameALL) return diff --git a/clang/test/3C/test_updater.py b/clang/test/3C/test_updater.py old mode 100644 new mode 100755 index 5aa96a64db20..77ff1a753aa2 --- a/clang/test/3C/test_updater.py +++ b/clang/test/3C/test_updater.py @@ -1,8 +1,10 @@ +#!/usr/bin/env python import fileinput import sys import os -path_to_monorepo = "/Users/shilpa-roy/checkedc-clang/build/bin/" +import find_bin +bin_path = find_bin.bin_path structs = """ struct np { @@ -82,8 +84,8 @@ def process_smart(filename, diff): cnameNOALL = filename + "heckedNOALL.c" cnameALL = filename + "heckedALL.c" - os.system("{}3c -alltypes -addcr -output-postfix=checkedALL {}".format(path_to_monorepo, filename)) - os.system("{}3c -addcr -output-postfix=checkedNOALL {}".format(path_to_monorepo, filename)) + os.system("{}3c -alltypes -addcr -output-postfix=checkedALL {}".format(bin_path, filename)) + os.system("{}3c -addcr -output-postfix=checkedNOALL {}".format(bin_path, filename)) process_file_smart(filename, cnameNOALL, cnameALL, diff) return diff --git a/clang/test/3C/testgenerator.py b/clang/test/3C/testgenerator.py old mode 100644 new mode 100755 index 10be2793d09c..f88409c92e4a --- a/clang/test/3C/testgenerator.py +++ b/clang/test/3C/testgenerator.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python # Author: Shilpa Roy # Last updated: June 16, 2020 @@ -5,10 +6,8 @@ import os import subprocess -#### USERS PUT YOUR INFO HERE ##### - -# Please remember to add a '/' at the very end! -path_to_monorepo = "/Users/shilpa-roy/checkedc/checkedc-clang/build/bin/" +import find_bin +bin_path = find_bin.bin_path @@ -726,23 +725,23 @@ def annot_gen_smart(prefix, proto, suffix): # run the porting tool on the file(s) if proto=="multi": - os.system("{}3c -alltypes -addcr -output-postfix=checkedALL {} {}".format(path_to_monorepo, name, name2)) - os.system("{}3c -addcr -output-postfix=checkedNOALL {} {}".format(path_to_monorepo, name, name2)) + os.system("{}3c -alltypes -addcr -output-postfix=checkedALL {} {}".format(bin_path, name, name2)) + os.system("{}3c -addcr -output-postfix=checkedNOALL {} {}".format(bin_path, name, name2)) else: - os.system("{}3c -alltypes -addcr -output-postfix=checkedALL {}".format(path_to_monorepo, name)) - os.system("{}3c -addcr -output-postfix=checkedNOALL {}".format(path_to_monorepo, name)) + os.system("{}3c -alltypes -addcr -output-postfix=checkedALL {}".format(bin_path, name)) + os.system("{}3c -addcr -output-postfix=checkedNOALL {}".format(bin_path, name)) # compile the files and if it doesn't compile, then let's indicate that a bug was generated for this file bug_generated = False if proto != "multi": - out = subprocess.Popen(['{}clang'.format(path_to_monorepo), '-c', cnameNOALL], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + out = subprocess.Popen(['{}clang'.format(bin_path), '-c', cnameNOALL], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, stderr = out.communicate() stdout = str(stdout) if "error:" in stdout: bug_generated = True # name = prefix + proto + suffix + "_BUG.c" else: - out = subprocess.Popen(['{}clang'.format(path_to_monorepo), '-c', cnameNOALL, cname2NOALL], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + out = subprocess.Popen(['{}clang'.format(bin_path), '-c', cnameNOALL, cname2NOALL], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, stderr = out.communicate() stdout = str(stdout) if "error:" in stdout: