Merge pull request #479 from AndreMiras/feature/shorter_syntax

Uses a couple of syntax shortcuts
This commit is contained in:
Andre Miras 2020-05-05 23:48:56 +02:00 committed by GitHub
commit be384fbf91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,6 +10,7 @@ import sys
from sys import stdout from sys import stdout
from os.path import join, dirname, realpath, exists, isdir, basename, expanduser from os.path import join, dirname, realpath, exists, isdir, basename, expanduser
from os import listdir, unlink, makedirs, environ, chdir, getcwd, walk from os import listdir, unlink, makedirs, environ, chdir, getcwd, walk
import sh
import zipfile import zipfile
import tarfile import tarfile
import importlib import importlib
@ -38,8 +39,6 @@ except ImportError:
sys.exit(1) sys.exit(1)
curdir = dirname(__file__) curdir = dirname(__file__)
import sh
# For more detailed logging, use something like # For more detailed logging, use something like
# format='%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(funcName)s():%(lineno)d] %(message)s' # format='%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(funcName)s():%(lineno)d] %(message)s'
@ -163,7 +162,6 @@ class JsonStore(object):
class Arch(object): class Arch(object):
def __init__(self, ctx): def __init__(self, ctx):
super(Arch, self).__init__()
self.ctx = ctx self.ctx = ctx
self._ccsh = None self._ccsh = None
@ -535,14 +533,14 @@ class Recipe(object):
if not filename: if not filename:
return return
logger.info("Extract {} into {}".format(filename, cwd)) logger.info("Extract {} into {}".format(filename, cwd))
if filename.endswith(".tgz") or filename.endswith(".tar.gz"): if filename.endswith((".tgz", ".tar.gz")):
if self.ctx.use_pigz: if self.ctx.use_pigz:
comp = '--use-compress-program={}'.format(self.ctx.use_pigz) comp = '--use-compress-program={}'.format(self.ctx.use_pigz)
else: else:
comp = '-z' comp = '-z'
shprint(sh.tar, "-C", cwd, "-xv", comp, "-f", filename) shprint(sh.tar, "-C", cwd, "-xv", comp, "-f", filename)
elif filename.endswith(".tbz2") or filename.endswith(".tar.bz2"): elif filename.endswith((".tbz2", ".tar.bz2")):
if self.ctx.use_pbzip2: if self.ctx.use_pbzip2:
comp = '--use-compress-program={}'.format(self.ctx.use_pbzip2) comp = '--use-compress-program={}'.format(self.ctx.use_pbzip2)
else: else:
@ -558,8 +556,7 @@ class Recipe(object):
raise Exception() raise Exception()
def get_archive_rootdir(self, filename): def get_archive_rootdir(self, filename):
if filename.endswith(".tgz") or filename.endswith(".tar.gz") or \ if filename.endswith((".tgz", ".tar.gz", ".tbz2", ".tar.bz2")):
filename.endswith(".tbz2") or filename.endswith(".tar.bz2"):
try: try:
archive = tarfile.open(filename) archive = tarfile.open(filename)
except tarfile.ReadError: except tarfile.ReadError:
@ -794,8 +791,7 @@ class Recipe(object):
build_dir = join(self.ctx.build_dir, self.name, arch) build_dir = join(self.ctx.build_dir, self.name, arch)
dest_dir = join(build_dir, self.archive_root) dest_dir = join(build_dir, self.archive_root)
if self.custom_dir: if self.custom_dir:
if exists(dest_dir): shutil.rmtree(dest_dir, ignore_errors=True)
shutil.rmtree(dest_dir)
shutil.copytree(self.custom_dir, dest_dir) shutil.copytree(self.custom_dir, dest_dir)
else: else:
if exists(dest_dir): if exists(dest_dir):
@ -814,7 +810,7 @@ class Recipe(object):
logger.warning("{} build for {} has been incomplete".format( logger.warning("{} build for {} has been incomplete".format(
self.name, arch.arch)) self.name, arch.arch))
logger.warning("Warning: deleting the build and restarting.") logger.warning("Warning: deleting the build and restarting.")
shutil.rmtree(self.build_dir) shutil.rmtree(self.build_dir, ignore_errors=True)
self.extract_arch(arch.arch) self.extract_arch(arch.arch)
if self.has_marker("build_done"): if self.has_marker("build_done"):
@ -922,8 +918,7 @@ class Recipe(object):
src = join(build_dir, framework) src = join(build_dir, framework)
dest = join(self.ctx.dist_dir, "frameworks", framework) dest = join(self.ctx.dist_dir, "frameworks", framework)
ensure_dir(dirname(dest)) ensure_dir(dirname(dest))
if exists(dest): shutil.rmtree(dest, ignore_errors=True)
shutil.rmtree(dest)
logger.debug("Copy {} to {}".format(src, dest)) logger.debug("Copy {} to {}".format(src, dest))
shutil.copytree(src, dest) shutil.copytree(src, dest)
@ -938,8 +933,7 @@ class Recipe(object):
src = join(build_dir, source) src = join(build_dir, source)
dest = join(self.ctx.dist_dir, "sources", self.name) dest = join(self.ctx.dist_dir, "sources", self.name)
ensure_dir(dirname(dest)) ensure_dir(dirname(dest))
if exists(dest): shutil.rmtree(dest, ignore_errors=True)
shutil.rmtree(dest)
logger.debug("Copy {} to {}".format(src, dest)) logger.debug("Copy {} to {}".format(src, dest))
shutil.copytree(src, dest) shutil.copytree(src, dest)
@ -962,8 +956,7 @@ class Recipe(object):
arch_dir = arch.arch arch_dir = arch.arch
include_name = self.include_name or self.name include_name = self.include_name or self.name
dest_dir = join(self.ctx.include_dir, arch_dir, include_name) dest_dir = join(self.ctx.include_dir, arch_dir, include_name)
if exists(dest_dir): shutil.rmtree(dest_dir, ignore_errors=True)
shutil.rmtree(dest_dir)
build_dir = self.get_build_dir(arch.arch) build_dir = self.get_build_dir(arch.arch)
for include_dir in include_dirs: for include_dir in include_dirs:
@ -1028,10 +1021,10 @@ class PythonRecipe(Recipe):
@staticmethod @staticmethod
def remove_junk(d): def remove_junk(d):
exts = [".so.lib", ".so.o", ".sh"] exts = (".so.lib", ".so.o", ".sh")
for root, dirnames, filenames in walk(d): for root, dirnames, filenames in walk(d):
for fn in filenames: for fn in filenames:
if any([fn.endswith(ext) for ext in exts]): if fn.endswith(exts):
print('Found junk {}/{}, removing'.format(root, fn)) print('Found junk {}/{}, removing'.format(root, fn))
unlink(join(root, fn)) unlink(join(root, fn))
@ -1169,8 +1162,7 @@ def build_recipes(names, ctx):
def ensure_dir(filename): def ensure_dir(filename):
if not exists(filename): makedirs(filename, exist_ok=True)
makedirs(filename)
def ensure_recipes_loaded(ctx): def ensure_recipes_loaded(ctx):
@ -1361,21 +1353,16 @@ Xcode:
logger.info("Cleaning {} build".format(recipe)) logger.info("Cleaning {} build".format(recipe))
ctx.state.remove_all("{}.".format(recipe)) ctx.state.remove_all("{}.".format(recipe))
build_dir = join(ctx.build_dir, recipe) build_dir = join(ctx.build_dir, recipe)
if exists(build_dir): shutil.rmtree(build_dir, ignore_errors=True)
shutil.rmtree(build_dir)
else: else:
logger.info("Delete build directory") logger.info("Delete build directory")
if exists(ctx.build_dir): shutil.rmtree(ctx.build_dir, ignore_errors=True)
shutil.rmtree(ctx.build_dir)
def distclean(self): def distclean(self):
ctx = Context() ctx = Context()
if exists(ctx.build_dir): shutil.rmtree(ctx.build_dir, ignore_errors=True)
shutil.rmtree(ctx.build_dir) shutil.rmtree(ctx.dist_dir, ignore_errors=True)
if exists(ctx.dist_dir): shutil.rmtree(ctx.cache_dir, ignore_errors=True)
shutil.rmtree(ctx.dist_dir)
if exists(ctx.cache_dir):
shutil.rmtree(ctx.cache_dir)
def status(self): def status(self):
ctx = Context() ctx = Context()