Formatted the beginning functions of the cpt

This commit is contained in:
saisoma123 2022-07-20 19:13:17 -04:00 committed by jenkins
parent dbe8b058ee
commit 5cc4d84bd8

View File

@ -19,7 +19,6 @@
#
###############################################################################
import sys
import argparse
import copy
@ -53,8 +52,9 @@ def _convert_subprocess_cmd(cmd):
def _perror(e):
print("subprocess.CalledProcessError: Command '%s' returned non-zero exit status %s" % (
' '.join(e.cmd), str(e.returncode)))
print(
"subprocess.CalledProcessError: Command '%s' returned non-zero exit status %s"
% (' '.join(e.cmd), str(e.returncode)))
cleanup()
# Communicate return code to the calling program if any
sys.exit(e.returncode)
@ -65,8 +65,12 @@ def exec_subprocess_call(cmd, cwd, showCMD=False):
print(cmd)
cmd = _convert_subprocess_cmd(cmd)
try:
subprocess.check_call(cmd, cwd=cwd, shell=False,
stdin=subprocess.PIPE, stdout=None, stderr=subprocess.STDOUT)
subprocess.check_call(cmd,
cwd=cwd,
shell=False,
stdin=subprocess.PIPE,
stdout=None,
stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
_perror(e)
@ -75,8 +79,11 @@ def exec_subprocess_check_output(cmd, cwd):
cmd = _convert_subprocess_cmd(cmd)
out = ''
try:
out = subprocess.check_output(cmd, cwd=cwd, shell=False,
stdin=subprocess.PIPE, stderr=subprocess.STDOUT).decode('utf-8')
out = subprocess.check_output(cmd,
cwd=cwd,
shell=False,
stdin=subprocess.PIPE,
stderr=subprocess.STDOUT).decode('utf-8')
except subprocess.CalledProcessError as e:
_perror(e)
finally:
@ -95,23 +102,25 @@ def travis_fold_end(tag):
def box_draw_header():
msg = 'cling (' + platform.machine() + ')' \
+ formatdate(time.time(), tzinfo())
msg = 'cling (' + platform.machine() + ')' + formatdate(
time.time(), tzinfo())
spaces_no = 80 - len(msg) - 4
spacer = ' ' * spaces_no
msg = 'cling (' + platform.machine() + ')' \
+ spacer + formatdate(time.time(), tzinfo())
msg = 'cling (' + platform.machine() + ')' + spacer + formatdate(
time.time(), tzinfo())
if OS != 'Windows':
print('''
%s
''' % (msg))
'''
% (msg))
else:
print('''
+=============================================================================+
| %s|
+=============================================================================+''' % (msg))
+=============================================================================+'''
% (msg))
def box_draw(msg):
@ -122,20 +131,24 @@ def box_draw(msg):
print('''
%s%s
''' % (msg, spacer))
'''
% (msg, spacer))
else:
print('''
+-----------------------------------------------------------------------------+
| %s%s|
+-----------------------------------------------------------------------------+''' % (msg, spacer))
+-----------------------------------------------------------------------------+'''
% (msg, spacer))
def pip_install(package):
# Needs brew install python. We should only install if we need the
# functionality
import pip
pip.main(['install', '--ignore-installed', '--prefix',
os.path.join(workdir, 'pip'), '--upgrade', package])
pip.main([
'install', '--ignore-installed', '--prefix',
os.path.join(workdir, 'pip'), '--upgrade', package
])
def wget(url, out_dir, rename_file=None, retries=3):
@ -156,7 +169,7 @@ def wget(url, out_dir, rename_file=None, retries=3):
except Exception:
print(' Error due to broken pipe')
print(' Retrying ...')
wget(url, out_dir, retries-1)
wget(url, out_dir, retries - 1)
else:
print(" Downloading: %s Bytes: %s" % (file_name, file_size))
@ -191,23 +204,33 @@ def fetch_llvm(llvm_revision):
print('Last known good LLVM revision is: ' + llvm_revision)
print('Current working directory is: ' + workdir + '\n')
if "github.com" in LLVM_GIT_URL and args['create_dev_env'] is None and args['use_wget']:
if "github.com" in LLVM_GIT_URL and args[
'create_dev_env'] is None and args['use_wget']:
_, _, _, user, repo = LLVM_GIT_URL.split('/')
print('Fetching LLVM ...')
wget(url='https://github.com/%s/%s' % (user, repo.replace('.git', '')) +
'/archive/cling-patches-r%s.tar.gz' % llvm_revision,
wget(url='https://github.com/%s/%s' %
(user, repo.replace('.git', '')) +
'/archive/cling-patches-r%s.tar.gz' % llvm_revision,
out_dir=workdir)
print('Extracting: ' + os.path.join(workdir, 'cling-patches-r%s.tar.gz' % llvm_revision))
print('Extracting: ' +
os.path.join(workdir, 'cling-patches-r%s.tar.gz' %
llvm_revision))
extract_tar(workdir, 'cling-patches-r%s.tar.gz' % llvm_revision)
os.rename(os.path.join(workdir,
'llvm-cling-patches-r%s' % llvm_revision),
srcdir)
os.rename(
os.path.join(workdir, 'llvm-cling-patches-r%s' % llvm_revision),
srcdir)
if os.path.isfile(os.path.join(workdir, 'cling-patches-r%s.tar.gz' % llvm_revision)):
print("Remove file: " + os.path.join(workdir, 'cling-patches-r%s.tar.gz' % llvm_revision))
os.remove(os.path.join(workdir, 'cling-patches-r%s.tar.gz' % llvm_revision))
if os.path.isfile(
os.path.join(workdir,
'cling-patches-r%s.tar.gz' % llvm_revision)):
print("Remove file: " +
os.path.join(workdir, 'cling-patches-r%s.tar.gz' %
llvm_revision))
os.remove(
os.path.join(workdir,
'cling-patches-r%s.tar.gz' % llvm_revision))
print()
return
@ -228,8 +251,9 @@ def fetch_llvm(llvm_revision):
checkout()
exec_subprocess_call('git fetch --tags', srcdir)
exec_subprocess_call('git pull origin refs/tags/cling-patches-r%s'
% llvm_revision, srcdir)
exec_subprocess_call(
'git pull origin refs/tags/cling-patches-r%s' % llvm_revision,
srcdir)
if os.path.isdir(srcdir):
update_old_llvm()
@ -239,68 +263,84 @@ def fetch_llvm(llvm_revision):
def llvm_flag_setter(llvm_dir, llvm_config_path):
flags = "-DLLVM_BINARY_DIR={0} -DLLVM_CONFIG={1} -DLLVM_LIBRARY_DIR={2} -DLLVM_MAIN_INCLUDE_DIR={3} -DLLVM_TABLEGEN_EXE={4} \
-DLLVM_TOOLS_BINARY_DIR={5} -DLLVM_TOOL_CLING_BUILD=ON".format(llvm_dir, llvm_config_path,
os.path.join(llvm_dir, 'lib'), os.path.join(llvm_dir, 'include'), os.path.join(llvm_dir, 'bin', 'llvm-tblgen'),
os.path.join(llvm_dir, 'bin'))
-DLLVM_TOOLS_BINARY_DIR={5} -DLLVM_TOOL_CLING_BUILD=ON".format(
llvm_dir, llvm_config_path, os.path.join(llvm_dir, 'lib'),
os.path.join(llvm_dir, 'include'),
os.path.join(llvm_dir, 'bin', 'llvm-tblgen'),
os.path.join(llvm_dir, 'bin'))
if args['with_verbose_output']:
flags += " -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON"
return flags
def extract_tar(extractpath, tarfilename):
tar = tarfile.open(os.path.join(workdir, tarfilename))
tar.extractall(path=extractpath)
tar.close()
def download_llvm_binary():
global llvm_flags, tar_required
box_draw("Fetching LLVM binary")
print('Current working directory is: ' + workdir + '\n')
if DIST == "Ubuntu":
subprocess.call(
"sudo -H {0} -m pip install lit".format(sys.executable), shell=True
)
llvm_config_path = exec_subprocess_check_output("which llvm-config-{0}".format(llvm_vers), workdir)
subprocess.call("sudo -H {0} -m pip install lit".format(
sys.executable),
shell=True)
llvm_config_path = exec_subprocess_check_output(
"which llvm-config-{0}".format(llvm_vers), workdir)
if llvm_config_path != '' and tar_required is False:
llvm_dir = os.path.join("/usr", "lib", "llvm-"+llvm_vers)
llvm_dir = os.path.join("/usr", "lib", "llvm-" + llvm_vers)
if llvm_config_path[-1:] == "\n":
llvm_config_path = llvm_config_path[:-1]
llvm_flags = llvm_flag_setter(llvm_dir, llvm_config_path)
else:
tar_required = True
elif DIST == 'MacOSX':
subprocess.call(
"sudo -H {0} -m pip install lit".format(sys.executable), shell=True
)
subprocess.call("sudo -H {0} -m pip install lit".format(
sys.executable),
shell=True)
if tar_required is False:
llvm_dir = os.path.join("/opt", "local", "libexec", "llvm-"+llvm_vers)
llvm_dir = os.path.join("/opt", "local", "libexec",
"llvm-" + llvm_vers)
llvm_config_path = os.path.join(llvm_dir, "bin", "llvm-config")
if llvm_config_path[-1:] == "\n":
llvm_config_path = llvm_config_path[:-1]
llvm_flags = llvm_flag_setter(llvm_dir, llvm_config_path)
else:
raise Exception("Building clang using LLVM binary not possible. Please invoke cpt without --with-llvm-binary and --with-llvm-tar flags")
raise Exception(
"Building clang using LLVM binary not possible. Please invoke cpt without --with-llvm-binary and --with-llvm-tar flags"
)
if tar_required:
if DIST == 'Ubuntu':
llvm_dir = os.path.join("/usr", "lib", "llvm-"+llvm_vers)
llvm_dir = os.path.join("/usr", "lib", "llvm-" + llvm_vers)
elif DIST == 'MacOSX':
llvm_dir = os.path.join("/opt", "local", "libexec", "llvm-"+llvm_vers)
llvm_dir = os.path.join("/opt", "local", "libexec",
"llvm-" + llvm_vers)
llvm_flags = llvm_flag_setter(llvm_dir, llvm_config_path)
if DIST == "Ubuntu" and REV == '16.04' and is_os_64bit():
download_link = 'http://releases.llvm.org/5.0.2/clang+llvm-5.0.2-x86_64-linux-gnu-ubuntu-16.04.tar.xz'
wget(url=download_link, out_dir=workdir)
extract_tar(srcdir, 'clang+llvm-5.0.2-x86_64-linux-gnu-ubuntu-16.04.tar.xz')
extract_tar(
srcdir,
'clang+llvm-5.0.2-x86_64-linux-gnu-ubuntu-16.04.tar.xz')
elif DIST == "Ubuntu" and REV == '14.04' and is_os_64bit():
download_link = 'http://releases.llvm.org/5.0.2/clang+llvm-5.0.2-x86_64-linux-gnu-ubuntu-14.04.tar.xz'
wget(url=download_link, out_dir=workdir)
extract_tar(srcdir, 'clang+llvm-5.0.2-x86_64-linux-gnu-ubuntu-14.04.tar.xz')
extract_tar(
srcdir,
'clang+llvm-5.0.2-x86_64-linux-gnu-ubuntu-14.04.tar.xz')
elif DIST == 'MacOSX' and is_os_64bit():
download_link = 'http://releases.llvm.org/5.0.2/clang+llvm-5.0.2-x86_64-apple-darwin.tar.xz'
wget(url=download_link, out_dir=workdir)
extract_tar(srcdir, 'clang+llvm-5.0.2-x86_64-apple-darwin.tar.xz')
else:
raise Exception("Building clang using LLVM binary not possible. Please invoke cpt without --with-llvm-binary and --with-llvm-tar flags")
raise Exception(
"Building clang using LLVM binary not possible. Please invoke cpt without --with-llvm-binary and --with-llvm-tar flags"
)
# FIXME: Add Fedora and SUSE support
# TODO Refactor all fetch_ functions to use this class will remove a lot of dup
@ -2041,20 +2081,17 @@ if not os.path.isdir(TMP_PREFIX):
os.makedirs(TMP_PREFIX)
if args['with_llvm_binary'] and args['with_llvm_url']:
raise Exception("Cannot specify flags" +
" --with-llvm-binary and --with-llvm-url together")
raise Exception("Cannot specify flags --with-llvm-binary and --with-llvm-url together")
elif args['with_llvm_binary'] is False and args['with_llvm_url']:
LLVM_GIT_URL = args['with_llvm_url']
else:
LLVM_GIT_URL = "http://root.cern.ch/git/llvm.git"
if args['with_llvm_binary'] and args['with_llvm_tar']:
raise Exception("Cannot specify flags " +
"--with-binary-llvm and --with-llvm-tar together")
if args['with_binary_llvm'] and args['with_llvm_tar']:
raise Exception("Cannot specify flags --with-binary-llvm and --with-llvm-tar together")
if args['with_llvm_tar'] and args['with_llvm_url']:
raise Exception("Cannot specify flags " +
"--with-llvm-tar and --with-llvm-url together")
raise Exception("Cannot specify flags --with-llvm-tar and --with-llvm-url together")
if args['tarball_tag'] and args['tarball_tag_build']:
raise Exception('You cannot specify both the tarball_tag and tarball_tag_build flags')
@ -2085,8 +2122,7 @@ if args['check_requirements']:
box_draw('Check availability of required softwares')
if DIST == 'Ubuntu':
install_line = ""
prerequisite = ['git', 'cmake', 'gcc', 'g++',
'debhelper', 'devscripts', 'gnupg', 'zlib1g-dev']
prerequisite = ['git', 'cmake', 'gcc', 'g++', 'debhelper', 'devscripts', 'gnupg', 'zlib1g-dev']
if args["with_llvm_binary"] or args["with_llvm_tar"]:
prerequisite.extend(['subversion'])
if args["with_llvm_binary"] and not args["with_llvm_tar"]:
@ -2140,12 +2176,10 @@ if args['check_requirements']:
elif OS == 'Windows':
check_win('git')
# Check Windows registry for keys that
# prove an MS Visual Studio 14.0 installation
# Check Windows registry for keys that prove an MS Visual Studio 14.0 installation
check_win('msvc')
print('''
Refer to the documentation of CPT for information
on setting up your Windows environment.
Refer to the documentation of CPT for information on setting up your Windows environment.
[tools/packaging/README.md]
''')
elif DIST == 'Fedora' or DIST == 'Scientific Linux CERN SLC':
@ -2228,8 +2262,7 @@ on setting up your Windows environment.
shell=True,
stdin=subprocess.PIPE,
stdout=None,
stderr=subprocess.STDOUT).communicate('yes'.
encode('utf-8'))
stderr=subprocess.STDOUT).communicate('yes'.encode('utf-8'))
if args["with_llvm_tar"] or args["with_llvm_binary"]:
download_llvm_binary()
@ -2239,8 +2272,7 @@ if bool(args['current_dev']) or bool(args['current_dev_build']):
travis_fold_start("git-clone")
current_packaging_mode = args['current_dev'] if args['current_dev'] else args['current_dev_build']
llvm_revision = urlopen(
"https://raw.githubusercontent.com/root-project/" +
"cling/master/LastKnownGoodLLVMSVNRevision.txt").readline().strip().decode(
"https://raw.githubusercontent.com/root-project/cling/master/LastKnownGoodLLVMSVNRevision.txt").readline().strip().decode(
'utf-8')
if args['with_llvm_binary']:
@ -2283,16 +2315,13 @@ if bool(args['current_dev']) or bool(args['current_dev_build']):
if args['current_dev'] == 'tar':
if OS == 'Windows':
get_win_dep()
compile(os.path.join(workdir, 'cling-win-' +
platform.machine().lower() + '-' + VERSION))
compile(os.path.join(workdir, 'cling-win-' + platform.machine().lower() + '-' + VERSION))
else:
if DIST == 'Scientific Linux CERN SLC':
compile(os.path.join(workdir, 'cling-SLC-' + REV + '-'
+ platform.machine().lower() + '-' + VERSION))
compile(os.path.join(workdir, 'cling-SLC-' + REV + '-' + platform.machine().lower() + '-' + VERSION))
else:
compile(os.path.join(workdir,
'cling-' + DIST + '-' + REV + '-'
+ platform.machine().lower() + '-' + VERSION))
'cling-' + DIST + '-' + REV + '-' + platform.machine().lower() + '-' + VERSION))
install_prefix()
if not args['no_test']:
if args['with_llvm_binary']:
@ -2372,8 +2401,7 @@ if bool(args['last_stable']) or bool(args['last_stable_build']):
assert tag[0] == "v"
assert CLING_BRANCH == None
llvm_revision = urlopen(
'https://raw.githubusercontent.com/root-project/' +
'cling/%s/LastKnownGoodLLVMSVNRevision.txt' % tag
'https://raw.githubusercontent.com/root-project/cling/%s/LastKnownGoodLLVMSVNRevision.txt' % tag
).readline().strip().decode('utf-8')
args["with_llvm_binary"] = True
@ -2395,18 +2423,13 @@ if bool(args['last_stable']) or bool(args['last_stable_build']):
set_version()
if OS == 'Windows':
get_win_dep()
compile(os.path.join(workdir, 'cling-win-' +
platform.machine().lower() + '-' + VERSION))
compile(os.path.join(workdir, 'cling-win-' + platform.machine().lower() + '-' + VERSION))
else:
if DIST == 'Scientific Linux CERN SLC':
compile(os.path.join(workdir, 'cling-SLC-' + REV + '-'
+ platform.machine().lower() +
'-' + VERSION))
compile(os.path.join(workdir, 'cling-SLC-' + REV + '-' + platform.machine().lower() + '-' + VERSION))
else:
compile(os.path.join(workdir,
'cling-' + DIST + '-' + REV + '-'
+ platform.machine().lower() +
'-' + VERSION))
'cling-' + DIST + '-' + REV + '-' + platform.machine().lower() + '-' + VERSION))
install_prefix()
if not args['no_test']:
if args['with_llvm_binary']:
@ -2468,8 +2491,7 @@ if bool(args['last_stable']) or bool(args['last_stable_build']):
elif stable_packaging_mode == 'pkg':
set_version()
compile(os.path.join(workdir, 'cling-' + DIST + '-' + REV + '-'
+ platform.machine().lower() + '-' + VERSION))
compile(os.path.join(workdir, 'cling-' + DIST + '-' + REV + '-' + platform.machine().lower() + '-' + VERSION))
install_prefix()
if not args['no_test']:
if args['with_llvm_binary']:
@ -2482,8 +2504,7 @@ if bool(args['last_stable']) or bool(args['last_stable_build']):
if args['tarball_tag'] or args['tarball_tag_build']:
tar_tag_cond = args['tarball_tag'] if args['tarball_tag'] else args['tarball_tag_build']
llvm_revision = urlopen(
"https://raw.githubusercontent.com/root-project/" +
"cling/%s/LastKnownGoodLLVMSVNRevision.txt" % args[
"https://raw.githubusercontent.com/root-project/cling/%s/LastKnownGoodLLVMSVNRevision.txt" % args[
'tarball_tag']).readline().strip().decode(
'utf-8')
if args["with_llvm_binary"]:
@ -2500,16 +2521,13 @@ if args['tarball_tag'] or args['tarball_tag_build']:
if OS == 'Windows':
get_win_dep()
compile(os.path.join(workdir, 'cling-win-'
+ platform.machine().lower() + '-' + VERSION))
compile(os.path.join(workdir, 'cling-win-' + platform.machine().lower() + '-' + VERSION))
else:
if DIST == 'Scientific Linux CERN SLC':
compile(os.path.join(workdir, 'cling-SLC-' + REV + '-'
+ platform.machine().lower() + '-' + VERSION))
compile(os.path.join(workdir, 'cling-SLC-' + REV + '-' + platform.machine().lower() + '-' + VERSION))
else:
compile(
os.path.join(workdir, 'cling-' + DIST + '-' + REV + '-'
+ platform.machine().lower() + '-' + VERSION))
os.path.join(workdir, 'cling-' + DIST + '-' + REV + '-' + platform.machine().lower() + '-' + VERSION))
install_prefix()
if not args['no_test']:
@ -2523,8 +2541,7 @@ if args['tarball_tag'] or args['tarball_tag_build']:
if args['deb_tag'] or args['deb_tag_build']:
deb_tag_cond = args['deb_tag'] if args['deb_tag'] else args['deb_tag_build']
llvm_revision = urlopen(
"https://raw.githubusercontent.com/root-project/" +
"cling/%s/LastKnownGoodLLVMSVNRevision.txt" % args[
"https://raw.githubusercontent.com/root-project/cling/%s/LastKnownGoodLLVMSVNRevision.txt" % args[
'deb_tag']).readline().strip().decode(
'utf-8')
fetch_llvm(llvm_revision)
@ -2544,8 +2561,7 @@ if args['deb_tag'] or args['deb_tag_build']:
if args['rpm_tag'] or args['rpm_tag_build']:
rpm_tag_cond = args['rpm_tag'] if args['rpm_tag'] else args['rpm_tag_build']
llvm_revision = urlopen(
"https://raw.githubusercontent.com/root-project" +
"/cling/%s/LastKnownGoodLLVMSVNRevision.txt" % args[
"https://raw.githubusercontent.com/root-project/cling/%s/LastKnownGoodLLVMSVNRevision.txt" % args[
'rpm_tag']).readline().strip().decode(
'utf-8')
fetch_llvm(llvm_revision)
@ -2565,8 +2581,7 @@ if args['rpm_tag'] or args['rpm_tag_build']:
if args['nsis_tag'] or args['nsis_tag_build']:
nsis_tag_build = args['nsis_tag'] if args['nsis_tag'] else args['nsis_tag_build']
llvm_revision = urlopen(
"https://raw.githubusercontent.com/root-project/" +
"cling/%s/LastKnownGoodLLVMSVNRevision.txt" % args[
"https://raw.githubusercontent.com/root-project/cling/%s/LastKnownGoodLLVMSVNRevision.txt" % args[
'nsis_tag']).readline().strip().decode(
'utf-8')
fetch_llvm(llvm_revision)
@ -2587,8 +2602,7 @@ if args['nsis_tag'] or args['nsis_tag_build']:
if args['dmg_tag'] or args['dmg_tag_build']:
dmg_tag_cond = args['dmg_tag'] if args['dmg_tag'] else args['dmg_tag_build']
llvm_revision = urlopen(
"https://raw.githubusercontent.com/root-project" +
"/cling/%s/LastKnownGoodLLVMSVNRevision.txt" % args[
"https://raw.githubusercontent.com/root-project/cling/%s/LastKnownGoodLLVMSVNRevision.txt" % args[
'dmg_tag']).readline().strip().decode(
'utf-8')
fetch_llvm(llvm_revision)
@ -2608,8 +2622,7 @@ if args['dmg_tag'] or args['dmg_tag_build']:
if args['create_dev_env']:
llvm_revision = urlopen(
"https://raw.githubusercontent.com/root-project/" +
"cling/master/LastKnownGoodLLVMSVNRevision.txt"
"https://raw.githubusercontent.com/root-project/cling/master/LastKnownGoodLLVMSVNRevision.txt"
).readline().strip().decode('utf-8')
fetch_llvm(llvm_revision)
fetch_clang(llvm_revision)
@ -2618,23 +2631,19 @@ if args['create_dev_env']:
set_version()
if OS == 'Windows':
get_win_dep()
compile(os.path.join(workdir, 'cling-win-'
+ platform.machine().lower() + '-' + VERSION))
compile(os.path.join(workdir, 'cling-win-' + platform.machine().lower() + '-' + VERSION))
else:
if DIST == 'Scientific Linux CERN SLC':
compile(os.path.join(workdir, 'cling-SLC-' + REV + '-'
+ platform.machine().lower() + '-' + VERSION))
compile(os.path.join(workdir, 'cling-SLC-' + REV + '-' + platform.machine().lower() + '-' + VERSION))
else:
compile(
os.path.join(workdir, 'cling-' + DIST + '-' + REV + '-'
+ platform.machine().lower() + '-' + VERSION))
os.path.join(workdir, 'cling-' + DIST + '-' + REV + '-' + platform.machine().lower() + '-' + VERSION))
install_prefix()
if not args['no_test']:
test_cling()
if args['make_proper']:
# This is an internal option in CPT,
# meant to be integrated into Cling's build system.
# This is an internal option in CPT, meant to be integrated into Cling's build system.
with open(os.path.join(LLVM_OBJ_ROOT, 'config.log'), 'r') as log:
for line in log:
if re.match('^LLVM_PREFIX=', line):