Exemplo n.º 1
0
def unpackFile(downloaddir, filename, workdir):
    """unpack file specified by 'filename' from 'downloaddir' into 'workdir'"""
    CraftCore.log.debug(f"unpacking this file: {filename}")
    if not filename:
        return True

    (shortname, ext) = os.path.splitext(filename)
    if ext == "":
        CraftCore.log.warning(
            f"unpackFile called on invalid file extension {filename}")
        return True

    if OsUtils.isWin() and not OsUtils.supportsSymlinks():
        CraftCore.log.warning(
            "Please enable Windows 10 development mode to enable support for symlinks.\n"
            "This will enable faster extractions.\n"
            "https://docs.microsoft.com/en-us/windows/uwp/get-started/enable-your-device-for-development"
        )
    if CraftCore.cache.findApplication("7za"):
        # we use tar on linux not 7z, don't use tar on windows as it skips symlinks
        # test it with breeze-icons
        if (not OsUtils.isWin()
                or (OsUtils.supportsSymlinks() and CraftCore.cache.getVersion(
                    "7za", versionCommand="-version") >= "16")
                or not re.match("(.*\.tar.*$|.*\.tgz$)", filename)):
            return un7zip(os.path.join(downloaddir, filename), workdir, ext)
    try:
        shutil.unpack_archive(os.path.join(downloaddir, filename), workdir)
    except Exception as e:
        CraftCore.log.error(f"Failed to unpack {filename}", exc_info=e)
        return False
    return True
Exemplo n.º 2
0
def unpackFile(downloaddir, filename, workdir):
    """unpack file specified by 'filename' from 'downloaddir' into 'workdir'"""
    CraftCore.log.debug(f"unpacking this file: {filename}")
    if not filename:
        return True

    (shortname, ext) = os.path.splitext(filename)
    if ext == "":
        CraftCore.log.warning(
            f"unpackFile called on invalid file extension {filename}")
        return True

    sevenZVersion = CraftCore.cache.getVersion("7za",
                                               versionCommand="-version")
    if sevenZVersion and sevenZVersion >= "16" and (
            not OsUtils.isWin() or OsUtils.supportsSymlinks()
            or not re.match("(.*\.tar.*$|.*\.tgz$)", filename)):
        return un7zip(os.path.join(downloaddir, filename), workdir, ext)
    else:
        try:
            shutil.unpack_archive(os.path.join(downloaddir, filename), workdir)
        except Exception as e:
            CraftCore.log.error(f"Failed to unpack {filename}", exc_info=e)
            return False
    return True
Exemplo n.º 3
0
def unpackFile(downloaddir, filename, workdir):
    """unpack file specified by 'filename' from 'downloaddir' into 'workdir'"""
    craftDebug.log.debug(f"unpacking this file: {filename}")
    if not filename:
        return True

    (shortname, ext) = os.path.splitext(filename)
    if ext == "":
        craftDebug.log.warning(
            f"unpackFile called on invalid file extension {filename}")
        return True
    elif OsUtils.isWin() and utilsCache.findApplication("7za") and (
            OsUtils.supportsSymlinks()
            or not re.match("(.*\.tar.*$|.*\.tgz$)", filename)):
        return un7zip(os.path.join(downloaddir, filename), workdir, ext)
    else:
        try:
            shutil.unpack_archive(os.path.join(downloaddir, filename), workdir)
        except Exception as e:
            craftDebug.log.error(f"Failed to unpack {filename}", exc_info=e)
            return False
    return True
Exemplo n.º 4
0
    def environment(self):
        if not self._environment:
            if OsUtils.isWin():
                def convertPath(path : str):
                    return ":".join([str(self.toNativePath(p)) for p in path.split(os.path.pathsep)])

            mergeroot = self.toNativePath(CraftCore.standardDirs.craftRoot())
            ldflags = f" -L{mergeroot}/lib "
            cflags = f" -I{mergeroot}/include "

            if CraftCore.compiler.isMacOS:
                # Only look for includes/libraries in the XCode SDK on MacOS to avoid errors with
                # libraries installed by homebrew (causes errors e.g. with iconv since headers will be
                # found in /usr/local/include first but libraries are searched for in /usr/lib before
                # /usr/local/lib. See https://langui.sh/2015/07/24/osx-clang-include-lib-search-paths/
                # Ensure that /usr/include comes before /usr/local/include in the header search path to avoid
                # pulling in headers from /usr/local/include (e.g. installed by homebrew) that will cause
                # linker errors later.
                sdkPath = CraftCore.cache.getCommandOutput("xcrun", "--show-sdk-path")[1].strip()
                deploymentFlag = f"-mmacosx-version-min={os.environ['MACOSX_DEPLOYMENT_TARGET']}"
                cflags = f" -isysroot {sdkPath} {deploymentFlag} {cflags} -isystem /usr/include"
                ldflags = f" -isysroot {sdkPath} {deploymentFlag} {ldflags}"

                # TODO: well that sounded like a good idea, but is broken with recent xcode
                # when fixed we probably should also set that flag for the rest too?
                # See https://github.com/Homebrew/homebrew-core/issues/2674 for the -no_weak_imports flag
                #ldflags = f" -Wl,-no_weak_imports {ldflags}"

            if CraftCore.compiler.isMSVC():
                self._environment["INCLUDE"] = f"{mergeroot}/include:{convertPath(os.environ['INCLUDE'])}"
                self._environment["LIB"] = f"{mergeroot}/lib:{convertPath(os.environ['LIB'])}"

                # based on Windows-MSVC.cmake
                if self.buildType == "Release":
                    cflags += " -MD -O2 -Ob2 -DNDEBUG "
                elif self.buildType == "RelWithDebInfo":
                    cflags += " -MD -Zi -O2 -Ob1 -DNDEBUG "
                    ldflags += " -debug "
                elif self.buildType == "Debug":
                    cflags += " -MDd -Zi -Ob0 -Od "
                    ldflags += " -debug -pdbtype:sept "
            else:
                if self.buildType == "Release":
                    cflags += " -O3 -DNDEBUG "
                if self.buildType == "RelWithDebInfo":
                    cflags += " -O2 -g -DNDEBUG "
                elif self.buildType == "Debug":
                    cflags += " -O0 -g3 "

            if OsUtils.isWin():
                if OsUtils.supportsSymlinks():
                    self._environment["MSYS"] = "winsymlinks:nativestrict"
                path = "/usr/local/bin:/usr/bin:/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl"
                if CraftCore.compiler.isMinGW():
                    gcc = shutil.which("gcc")
                    if gcc:
                        path = f"{self.toNativePath(os.path.dirname(gcc))}:{path}"
                elif CraftCore.compiler.isMSVC():
                        path = f"{self.toNativePath(os.path.dirname(shutil.which('cl')))}:{path}"
                self._environment["PATH"] = f"{path}:{convertPath(os.environ['PATH'])}"
                self._environment["PKG_CONFIG_PATH"] = convertPath(os.environ["PKG_CONFIG_PATH"])

                if "make" in self._environment:
                    del self._environment["make"]
                # MSYSTEM is used by uname
                if CraftCore.compiler.isMinGW():
                    self._environment["MSYSTEM"] = f"MINGW{CraftCore.compiler.bits}_CRAFT"
                elif CraftCore.compiler.isMSVC():
                    self._environment["MSYSTEM"] = f"MSYS{CraftCore.compiler.bits}_CRAFT"

                if self.useMSVCCompatEnv and CraftCore.compiler.isMSVC():

                    automake = []
                    for d in os.scandir(os.path.join(os.path.dirname(self._findBash()), "..", "share")):
                        if d.name.startswith("automake"):
                            automake += [(d.name.rsplit("-")[1], os.path.realpath(d.path))]
                    automake.sort(key=lambda x: CraftVersion(x[0]))
                    latestAutomake = automake[-1][1]
                    if False:
                        cl = "clang-cl"
                    else:
                        cl = "cl"
                    clWrapper = self.toNativePath(os.path.join(latestAutomake, "compile"))
                    self._environment["AR"] = f"{self.toNativePath(os.path.join(latestAutomake, 'ar-lib'))} lib"
                    self._environment["LD"] = "link -nologo"
                    self._environment["CC"] = f"{clWrapper} {cl} -nologo"
                    self._environment["CXX"] = self._environment["CC"]
                    self._environment["CPP"] = f"{cl} -nologo -E"
                    self._environment["CXXCPP"] = self._environment["CPP"]
                    self._environment["NM"] = "dumpbin -symbols"

                    windresArg = " --preprocessor-arg=".join(["", "-nologo", "-EP", "-DRC_INVOKED", "-DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP"])
                    self._environment["WINDRES"] = f"windres --target={'pe-i386' if CraftCore.compiler.isX86() else 'pe-x86-64'} --preprocessor=cl {windresArg}"
                    self._environment["RC"] = f"{self._environment['WINDRES']} -O COFF"

                    self._environment["STRIP"] = ":"
                    self._environment["RANLIB"] = ":"
                    self._environment["F77"] = "no"
                    self._environment["FC"] = "no"

                    cflags += (" -GR -W3 -EHsc"  # dynamic and exceptions enabled
                               " -D_USE_MATH_DEFINES -DWIN32_LEAN_AND_MEAN -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS -D_WIN32_WINN=_WIN32_WINNT_WIN7"
                               " -wd4005"  # don't warn on redefine
                               " -wd4996"  # The POSIX name for this item is deprecated.
                               )
                    if CraftCore.compiler.getMsvcPlatformToolset() > 120:
                        cflags += " -FS"

            if CraftCore.compiler.isAndroid:
                toolchainPath = os.path.join(CraftCore.standardDirs.tmpDir(), f"android-{CraftCore.compiler.architecture}-toolchain")
                utils.system(["python3",
                              os.path.join(os.environ.get("ANDROID_NDK_ROOT"), "build/tools/make_standalone_toolchain.py"),
                              "--install-dir", toolchainPath,
                              "--arch", CraftCore.compiler.architecture,
                              "--api", CraftCore.compiler.androidApiLevel()])
                self._environment["PATH"] = os.path.join(toolchainPath, "bin") + ":" + os.environ["PATH"]
                self._environment["AR"] = "ar"
                self._environment["AS"] = "clang"
                self._environment["CC"] = "clang"
                self._environment["CXX"] = "clang++"
                self._environment["LD" ] = "ld"
                self._environment["STRIP"] = "strip"
                self._environment["RANLIB"] = "ranlib"


            self._environment["CFLAGS"] = os.environ.get("CFLAGS", "").replace("$", "$$") + cflags
            self._environment["CXXFLAGS"] = os.environ.get("CXXFLAGS", "").replace("$", "$$") + cflags
            self._environment["LDFLAGS"] = os.environ.get("LDFLAGS", "").replace("$", "$$") + ldflags
        return self._environment