Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cling-cpt] Added indentation and spacing as well as fixing variable references [skip-ci] #10992

Merged
merged 1 commit into from
Jul 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 37 additions & 36 deletions interpreter/cling/tools/packaging/cpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

def _convert_subprocess_cmd(cmd):
if OS == 'Windows':
cmd = cmd.replace('\\','/')
cmd = cmd.replace('\\', '/')
return shlex.split(cmd, posix=True, comments=True)


Expand All @@ -64,7 +64,8 @@ def _perror(e):


def exec_subprocess_call(cmd, cwd, showCMD=False):
if showCMD: print(cmd)
if showCMD:
print(cmd)
cmd = _convert_subprocess_cmd(cmd)
try:
subprocess.check_call(cmd, cwd=cwd, shell=False,
Expand All @@ -87,13 +88,13 @@ def exec_subprocess_check_output(cmd, cwd):

def travis_fold_start(tag):
if os.environ.get('TRAVIS_BUILD_DIR', None):
print('travis_fold:start:cpt-%s:' % (tag))
print('travis_fold:start:cpt-%s:' % (tag))


def travis_fold_end(tag):
if os.environ.get('TRAVIS_BUILD_DIR', None):
if os.environ.get('TRAVIS_BUILD_DIR', None):

print('travis_fold:end:cpt-%s:' % (tag))
print('travis_fold:end:cpt-%s:' % (tag))


def box_draw_header():
Expand Down Expand Up @@ -225,7 +226,7 @@ def update_old_llvm():
checkout()
exec_subprocess_call('git fetch --tags', srcdir)
exec_subprocess_call('git pull origin refs/tags/cling-patches-r%s'
% llvm_revision, srcdir)
% llvm_revision, srcdir)

if os.path.isdir(srcdir):
update_old_llvm()
Expand Down Expand Up @@ -301,6 +302,7 @@ def __init__(self, url, rootDir, depth=10):
self.__depth = depth
self.__projDir = rootDir
self.__workDir = os.path.join(rootDir, url.split('/')[-1])

def fetch(self, branch):
if os.path.isdir(self.__workDir):
exec_subprocess_call('git stash', self.__workDir)
Expand Down Expand Up @@ -340,7 +342,9 @@ def fetch_clang(llvm_revision):
else:
dir = os.path.join(srcdir, 'tools')
global clangdir

clangdir = os.path.join(dir, 'clang')

def checkout():
exec_subprocess_call('git checkout cling-patches-r%s' % llvm_revision, clangdir)

Expand All @@ -356,9 +360,10 @@ def update_old_clang():
exec_subprocess_call('git fetch --tags', clangdir)

checkout()

exec_subprocess_call('git fetch --tags', clangdir)
exec_subprocess_call('git pull origin refs/tags/cling-patches-r%s' % llvm_revision,
clangdir)
clangdir)

if os.path.isdir(clangdir):
update_old_clang()
Expand Down Expand Up @@ -554,8 +559,8 @@ def compile(arg):
print("Creating build directory: " + LLVM_OBJ_ROOT)
os.makedirs(LLVM_OBJ_ROOT)

### FIX: Target isn't being set properly on Travis OS X
### Either because ccache(when enabled) or maybe the virtualization environment
# FIX: Target isn't being set properly on Travis OS X
# Either because ccache(when enabled) or maybe the virtualization environment
if TRAVIS_BUILD_DIR and OS == 'Darwin':
triple = exec_subprocess_check_output('sh %s/cmake/config.guess' % srcdir, srcdir)
if triple:
Expand All @@ -575,7 +580,7 @@ def compile(arg):
build.make('install')

if TRAVIS_BUILD_DIR:
### Run cling once, dumping the include paths, helps debug issues
# Run cling once, dumping the include paths, helps debug issues
try:
subprocess.check_call(os.path.join(workdir, 'builddir', 'bin', 'cling')
+ ' -v ".I"', shell=True)
Expand Down Expand Up @@ -616,7 +621,7 @@ def compile_for_binary(arg):
build.make('install')

if TRAVIS_BUILD_DIR:
### Run cling once, dumping the include paths, helps debug issues
# Run cling once, dumping the include paths, helps debug issues
try:
subprocess.check_call(os.path.join(workdir, 'builddir', 'bin', 'cling')
+ ' -v ".I"', shell=True)
Expand All @@ -635,18 +640,19 @@ def install_prefix():
regex_array = []
regex_filename = os.path.join(CPT_SRC_DIR, 'dist-files.txt')
for line in open(regex_filename).read().splitlines():
if line and not line.startswith('#'):
regex_array.append(line)
if line and not line.startswith('#'):
regex_array.append(line)

for root, dirs, files in os.walk(TMP_PREFIX):
for file in files:
f = os.path.join(root, file).replace(TMP_PREFIX, '')
if OS == 'Windows':
f = f.replace('\\', '/')
for regex in regex_array:
if args['with_verbose_output']: print ("Applying regex " + regex + " to file " + f)
if args['with_verbose_output']:
print("Applying regex " + regex + " to file " + f)
if re.search(regex, f):
print ("Adding to final binary " + f)
print("Adding to final binary " + f)
if not os.path.isdir(os.path.join(prefix, os.path.dirname(f))):
os.makedirs(os.path.join(prefix, os.path.dirname(f)))
shutil.copy(os.path.join(TMP_PREFIX, f), os.path.join(prefix, f))
Expand All @@ -665,26 +671,27 @@ def install_prefix_for_binary():
regex_array = []
regex_filename = os.path.join(CPT_SRC_DIR, 'dist-files.txt')
for line in open(regex_filename).read().splitlines():
if line and not line.startswith('#'):
regex_array.append(line)
if line and not line.startswith('#'):
regex_array.append(line)

for root, dirs, files in os.walk(TMP_PREFIX):
for file in files:
f = os.path.join(root, file).replace(TMP_PREFIX, '')
if OS == 'Windows':
f = f.replace('\\', '/')
for regex in regex_array:
if args['with_verbose_output']: print ("Applying regex " + regex + " to file " + f)
if args['with_verbose_output']:
print("Applying regex " + regex + " to file " + f)
if re.search(regex, f):
print ("Adding to final binary " + f)
print("Adding to final binary " + f)
if not os.path.isdir(os.path.join(prefix, os.path.dirname(f))):
os.makedirs(os.path.join(prefix, os.path.dirname(f)))
shutil.copy(os.path.join(TMP_PREFIX, f), os.path.join(prefix, f))
break
travis_fold_end("install")


def runSingleTest(test, Idx = 2, Recurse = True):
def runSingleTest(test, Idx=2, Recurse=True):
try:
test = os.path.join(CLING_SRC_DIR, 'test', test)

Expand Down Expand Up @@ -759,7 +766,7 @@ def setup_tests():
else:
llvm_dir = os.path.join("/usr", "lib", "llvm-" + llvm_vers, "build")
subprocess.Popen(
["sudo mkdir {1}/utils/".format(commit, llvm_dir)],
["sudo mkdir {0}/utils/".format(llvm_dir)],
cwd=os.path.join(CLING_SRC_DIR, "tools"),
shell=True,
stdin=subprocess.PIPE,
Expand Down Expand Up @@ -861,7 +868,7 @@ def cleanup():
def check_version_string_ge(vstring, min_vstring):
version_fields = [int(x) for x in vstring.split('.')]
min_versions = [int(x) for x in min_vstring.split('.')]
for i in range(0,len(min_versions)):
for i in range(0, len(min_versions)):
if version_fields[i] < min_versions[i]:
return False
elif version_fields[i] > min_versions[i]:
Expand Down Expand Up @@ -1086,7 +1093,7 @@ def debianize():
# -*- makefile -*-

%:
dh $@
dh $@

override_dh_auto_build:

Expand Down Expand Up @@ -1318,7 +1325,6 @@ def check_win(pkg):
print(pkg.ljust(20) + '[OK]'.ljust(30))



def is_os_64bit():
return platform.machine().endswith('64')

Expand Down Expand Up @@ -1346,7 +1352,7 @@ def tryCmake(cmake):
vers = [int(v) for v in rslt.split()[2].split('.')]
if vers[0] >= 3 and (vers[1] > 6 or (vers[1] == 6 and vers[2] >= 2)):
return cmake
except:
except Exception:
pass
return False

Expand Down Expand Up @@ -1677,7 +1683,7 @@ def check_mac(pkg):
def make_dmg():
box_draw("Building Apple Disk Image")
APP_NAME = 'Cling'
DMG_BACKGROUND_IMG = 'graphic.png'
# DMG_BACKGROUND_IMG = 'graphic.png'
APP_EXE = '%s.app/Contents/MacOS/bin/%s' % (APP_NAME, APP_NAME.lower())
VOL_NAME = "%s-%s" % (APP_NAME.lower(), VERSION)
DMG_TMP = "%s-temp.dmg" % (VOL_NAME)
Expand All @@ -1703,7 +1709,6 @@ def make_dmg():
print("Remove file: " + os.path.join(workdir, DMG_FINAL))
os.remove(os.path.join(workdir, DMG_FINAL))


if os.path.isdir(os.path.join(workdir, '%s.app' % (APP_NAME))):
print("Remove directory:", os.path.join(workdir, '%s.app' % (APP_NAME)))
shutil.rmtree(os.path.join(workdir, '%s.app' % (APP_NAME)))
Expand All @@ -1714,16 +1719,14 @@ def make_dmg():
print('Populate directory: ' + os.path.join(workdir, '%s.app' % (APP_NAME), 'Contents', 'MacOS'))
shutil.copytree(
prefix,
os.path.join(workdir, '%s.app'%(APP_NAME), 'Contents', 'MacOS')
os.path.join(workdir, '%s.app' % (APP_NAME), 'Contents', 'MacOS')
)

os.makedirs(os.path.join(workdir, '%s.app' % (APP_NAME), 'Contents', 'Resources'))
shutil.copyfile(
os.path.join(CPT_SRC_DIR, 'LLVM.icns'),
os.path.join(workdir, '%s.app' % (APP_NAME), 'Contents', 'Resources', 'LLVM.icns')
)


print('Configuring Info.plist file')
plist_path = os.path.join(workdir, '%s.app' % (APP_NAME), 'Contents', 'Info.plist')
f = open(plist_path, 'w')
Expand Down Expand Up @@ -1765,11 +1768,8 @@ def make_dmg():

f.write(plist_xml)
f.close()


print('Copy APP Bundle to staging area: ' + STAGING_DIR)
shutil.copytree(os.path.join(workdir, '%s.app' % (APP_NAME)), STAGING_DIR)

print('Stripping file: ' + APP_EXE)
exec_subprocess_call('strip -u -r %s' % os.path.join(workdir, APP_EXE), workdir)

Expand Down Expand Up @@ -1865,6 +1865,7 @@ def custom_input(prompt, always_yes=False):
# Global variables #
###############################################################################


if __name__ == "__main__":
workdir = os.path.abspath(os.path.expanduser(args['with_workdir']))
srcdir = os.path.join(workdir, 'cling-src')
Expand Down Expand Up @@ -1916,7 +1917,7 @@ def custom_input(prompt, always_yes=False):
elif OS == 'Linux':
try:
import distro
except:
except Exception:
yes = {'yes', 'y', 'ye', ''}
choice = custom_input('''
CPT will now attempt to install the distro package automatically.
Expand Down Expand Up @@ -2002,7 +2003,7 @@ def custom_input(prompt, always_yes=False):
LLVM_GIT_URL = args['with_llvm_url']
else:
LLVM_GIT_URL = "http://root.cern.ch/git/llvm.git"

if args['with_binary_llvm'] and args['with_llvm_tar']:
raise Exception("Cannot specify flags --with-binary-llvm and --with-llvm-tar together")

Expand Down Expand Up @@ -2066,7 +2067,7 @@ def custom_input(prompt, always_yes=False):
stdin=subprocess.PIPE,
stdout=None,
stderr=subprocess.STDOUT).communicate('yes'.encode('utf-8'))
except:
except Exception:
tar_required = True

elif OS == 'Windows':
Expand Down