build script: always keep prefix directory up-to-date

This commit is contained in:
alexey.lysiuk 2020-06-27 13:24:59 +03:00
parent f35fb9b3cb
commit 88857b3fb4

View file

@ -268,7 +268,6 @@ class Builder(object):
self.xcode = arguments.xcode self.xcode = arguments.xcode
self.checkout_commit = arguments.checkout_commit self.checkout_commit = arguments.checkout_commit
self.generate = not arguments.skip_generate self.generate = not arguments.skip_generate
self.rebuild_prefix = arguments.rebuild_prefix
self.build_path = arguments.build_path self.build_path = arguments.build_path
self.sdk_path = arguments.sdk_path self.sdk_path = arguments.sdk_path
@ -296,30 +295,40 @@ class Builder(object):
self._build_target() self._build_target()
def _create_prefix_directory(self): def _create_prefix_directory(self):
if os.path.exists(self.prefix_path): os.makedirs(self.include_path, exist_ok=True)
if self.rebuild_prefix: os.makedirs(self.lib_path, exist_ok=True)
shutil.rmtree(self.prefix_path)
else:
return
os.makedirs(self.include_path) # Delete obsolete symbolic links
os.makedirs(self.lib_path) for root, _, files in os.walk(self.prefix_path, followlinks=True):
for filename in files:
file_path = root + os.sep + filename
if os.path.islink(file_path) and not os.path.exists(file_path):
os.remove(file_path)
# Create symbolic links if needed
for dep in os.scandir(self.deps_path): for dep in os.scandir(self.deps_path):
if not dep.is_dir(): if not dep.is_dir():
continue continue
dep_include_path = dep.path + os.sep + 'include' + os.sep def symlink_deps(src_dir):
dep_lib_path = dep.path + os.sep + 'lib' + os.sep src_path = dep.path + os.sep + src_dir + os.sep
if not os.path.exists(src_path):
return
if not os.path.exists(dep_include_path) or not os.path.exists(dep_lib_path): dst_path = self.prefix_path + src_dir + os.sep
continue
for dep_include in os.scandir(dep_include_path): for src in os.scandir(src_path):
os.symlink(dep_include.path, self.include_path + dep_include.name) dst_subpath = dst_path + src.name
for dep_lib in os.scandir(dep_lib_path): if src.is_dir():
os.symlink(dep_lib.path, self.lib_path + dep_lib.name) os.makedirs(dst_subpath, exist_ok=True)
symlink_deps(src_dir + os.sep + src.name)
elif not os.path.exists(dst_subpath):
os.symlink(src.path, dst_subpath)
symlink_deps('include')
symlink_deps('lib')
def _prepare_source(self): def _prepare_source(self):
if not os.path.exists(self.source_path): if not os.path.exists(self.source_path):
@ -424,7 +433,6 @@ class Builder(object):
group.add_argument('--build-path', metavar='path', help='target build path') group.add_argument('--build-path', metavar='path', help='target build path')
group.add_argument('--sdk-path', metavar='path', help='path to macOS SDK') group.add_argument('--sdk-path', metavar='path', help='path to macOS SDK')
group.add_argument('--skip-generate', action='store_true', help='do not generate build environment') group.add_argument('--skip-generate', action='store_true', help='do not generate build environment')
group.add_argument('--rebuild-prefix', action='store_true', help='rebuild prefix path')
return parser.parse_args(args) return parser.parse_args(args)