Exemplo n.º 1
0
 def msysDir():
     if not OsDetection.isWin():
         return CraftCore.settings.get("Paths", "Msys", "/")
     else:
         return CraftCore.settings.get(
             "Paths", "Msys",
             os.path.join(CraftStandardDirs.craftRoot(), "msys"))
Exemplo n.º 2
0
 def msysDir():
     if not OsDetection.isWin():
         return craftSettings.get("Paths", "Msys", "/")
     else:
         if ("Paths", "Msys") in craftSettings:
             return craftSettings.get("Paths", "Msys")
         return os.path.join(CraftStandardDirs.craftRoot(), "msys")
Exemplo n.º 3
0
 def test_killProcess(self):
     # TODO: find a better test app than the cmd windows
     if OsDetection.isWin():
         with tempfile.TemporaryDirectory() as tmp1:
             with tempfile.TemporaryDirectory() as tmp2:
                 test1 = os.path.join(tmp1, "craft_test.exe")
                 test2 = os.path.join(tmp2, "craft_test.exe")
                 cmd = CraftCore.cache.findApplication("cmd")
                 self.assertEqual(utils.copyFile(cmd, test1, linkOnly=False), True)
                 self.assertEqual(utils.copyFile(cmd, test2, linkOnly=False), True)
                 process = subprocess.Popen([test1,"/K"], creationflags=subprocess.CREATE_NEW_PROCESS_GROUP)
                 process2 = subprocess.Popen([test2,"/K"], creationflags=subprocess.CREATE_NEW_PROCESS_GROUP)
                 try:
                     self.assertEqual(process.poll(), None)
                     self.assertEqual(process2.poll(), None)
                     self.assertEqual(OsUtils.killProcess("craft_test", tmp2), True)
                     self.assertEqual(process.poll(), None)
                     #ensure that process 2 was killed
                     self.assertNotEquals(process2.poll(), None)
                 except subprocess.SubprocessError as e:
                     CraftCore.log.warning(e)
                 finally:
                     process.kill()
                     process2.kill()
                     process.wait()
                     process2.wait()
Exemplo n.º 4
0
 def msysDir() -> Path:
     if not OsDetection.isWin():
         return Path(CraftCore.settings.get("Paths", "Msys", "/"))
     else:
         return Path(
             CraftCore.settings.get("Paths", "Msys",
                                    CraftStandardDirs.craftRoot() / "msys"))
Exemplo n.º 5
0
    def environment(self):
        if self._environment is None:
            self._environment = {}

            mergeroot = self.toNativePath(CraftStandardDirs.craftRoot())
            if craftCompiler.isMSVC():
                ldflags = ""
                cflags = " -O2 -MD -GR -W3 -EHsc -D_USE_MATH_DEFINES -DWIN32_LEAN_AND_MEAN -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS"  # dynamic and exceptions enabled
                if craftCompiler.getMsvcPlatformToolset() > 120:
                    cflags += " -FS"
            else:
                ldflags = f"-L{mergeroot}/lib "
                cflags = f"-I{mergeroot}/include "

                if self.buildType == "RelWithDebInfo":
                    cflags += " -O2 -g "
                elif self.buildType == "Debug":
                    cflags += " -O0 -g3 "

            if OsDetection.isWin():
                self._environment["MSYS2_PATH_TYPE"] = "inherit"  # inherit the windows path
                if "make" in self._environment:
                    del self._environment["make"]
                if craftCompiler.isMinGW():
                    self._environment["MSYSTEM"] = f"MINGW{craftCompiler.bits}_CRAFT"
                elif craftCompiler.isMSVC():
                    self._environment["MSYSTEM"] = f"CYGWIN{craftCompiler.bits}_CRAFT"

                if craftCompiler.isMSVC():
                    if False:
                        cl = "clang-cl"
                    else:
                        cl = "cl"
                    self._environment["LIB"] = f"{os.environ['LIB']};{CraftStandardDirs.craftRoot()}\\lib"
                    self._environment["INCLUDE"] = f"{os.environ['INCLUDE']};{CraftStandardDirs.craftRoot()}\\include"
                    self._environment["LD"] = "link -NOLOGO"
                    self._environment["CC"] = "%s -nologo" % cl
                    self._environment["CXX"] = self._environment["CC"]
                    self._environment["CPP"] = "%s -nologo -EP" % cl
                    self._environment["CXXCPP"] = self._environment["CPP"]
                    self._environment["NM"] = "dumpbin -symbols"
                    self._environment["AR"] = "lib"
                    self._environment["WINDRES"] = "rc"
                    # self.environment[ "RC","rc-windres"
                    self._environment["STRIP"] = ":"
                    self._environment["RANLIB"] = ":"
                    self._environment["F77"] = "no"
                    self._environment["FC"] = "no"

            self._environment["PKG_CONFIG_PATH"] = self.toNativePath(
                os.path.join(CraftStandardDirs.craftRoot(), "lib", "pkgconfig"))


            self._environment["CFLAGS"] = cflags
            self._environment["CXXFLAGS"] = cflags
            self._environment["LDFLAGS"] = ldflags
        return self._environment
Exemplo n.º 6
0
    def test_LockFile(self):
        if OsDetection.isUnix():
            lock = LockFile("foo")
            print("start")
            lock.lock()

            def _delayedUnlock():
                print("unlock1")
                lock.unlock()
            threading.Timer(5, _delayedUnlock).start()
            with LockFile("foo") as lock2:
               print("locked lock2")
            print("end")
Exemplo n.º 7
0
    def _deSubstPath(path):
        """desubstitude craft short path"""

        if not OsDetection.isWin():
            return path
        drive, tail = os.path.splitdrive(path)
        drive = drive.upper()
        if CraftStandardDirs._SUBST == None:
            tmp = subprocess.getoutput("subst").split("\n")
            CraftStandardDirs._SUBST = {}
            for s in tmp:
                if s != "":
                    key, val = s.split("\\: => ")
                    CraftStandardDirs._SUBST[key] = val
        if drive in CraftStandardDirs._SUBST:
            deSubst = CraftStandardDirs._SUBST[drive] + tail
            return deSubst
        return path
Exemplo n.º 8
0
 def isShortPathEnabled():
     return OsDetection.isWin(
     ) and CraftStandardDirs._allowShortpaths and CraftCore.settings.getboolean(
         "ShortPath", "Enabled", False)
Exemplo n.º 9
0
 def toNativePath(path):
     if OsDetection.isWin():
         return utils.toMSysPath(path)
     else:
         return path
Exemplo n.º 10
0
    def environment(self):
        if not self._environment:

            mergeroot = self.toNativePath(CraftStandardDirs.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/
                if CraftCore.compiler.macUseSDK:
                    sdkPath = CraftCore.cache.getCommandOutput(
                        "xcrun", "--show-sdk-path")[1].strip()
                    deploymentFlag = "-mmacosx-version-min=" + CraftCore.compiler.macOSDeploymentTarget
                    cflags = f" -isysroot {sdkPath} {deploymentFlag}" + cflags
                    # See https://github.com/Homebrew/homebrew-core/issues/2674 for the -no_weak_imports flag
                    ldflags = f" -isysroot {sdkPath} {deploymentFlag} -Wl,-no_weak_imports" + ldflags
                    # Note: MACOSX_DEPLOYMENT_TARGET is set in utils.system() so doesn't need to be set here
                else:
                    # 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.
                    cflags = " -isystem /usr/include " + cflags

            if CraftCore.compiler.isMSVC():
                # 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 OsDetection.isWin():
                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}"
                for p in os.environ["PATH"].split(";"):
                    path += f":{self.toNativePath(p)}"
                self._environment["PATH"] = 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"CYGWIN{CraftCore.compiler.bits}_CRAFT"

                if self.useMSVCCompatEnv and CraftCore.compiler.isMSVC():
                    self._environment[
                        "LIB"] = f"{os.environ['LIB']};{CraftStandardDirs.craftRoot()}\\lib"
                    self._environment[
                        "INCLUDE"] = f"{os.environ['INCLUDE']};{CraftStandardDirs.craftRoot()}\\include"

                    if False:
                        cl = "clang-cl"
                    else:
                        cl = "cl"
                    self._environment["LD"] = "link -NOLOGO"
                    self._environment["CC"] = f"{cl} -nologo"
                    self._environment["CXX"] = self._environment["CC"]
                    self._environment["CPP"] = f"{cl} -nologo -EP"
                    self._environment["CXXCPP"] = self._environment["CPP"]
                    self._environment["NM"] = "dumpbin -symbols"
                    self._environment["AR"] = "lib"
                    self._environment["WINDRES"] = "rc"
                    # self.environment[ "RC","rc-windres"
                    self._environment["STRIP"] = ":"
                    self._environment["RANLIB"] = ":"
                    self._environment["F77"] = "no"
                    self._environment["FC"] = "no"

                    ldflags += ""
                    cflags += " -GR -W3 -EHsc -D_USE_MATH_DEFINES -DWIN32_LEAN_AND_MEAN -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS"  # dynamic and exceptions enabled
                    if CraftCore.compiler.getMsvcPlatformToolset() > 120:
                        cflags += " -FS"

            self._environment["PKG_CONFIG_PATH"] = self.toNativePath(
                os.path.join(CraftStandardDirs.craftRoot(), "lib",
                             "pkgconfig"))

            self._environment["CFLAGS"] = cflags
            self._environment["CXXFLAGS"] = cflags
            self._environment["LDFLAGS"] = ldflags
        return self._environment
Exemplo n.º 11
0
    def environment(self):
        if not self._environment:

            mergeroot = self.toNativePath(CraftStandardDirs.craftRoot())

            ldflags = f" -L{mergeroot}/lib "
            cflags = f" -I{mergeroot}/include "
            if CraftCore.compiler.isMSVC():
                # 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 OsDetection.isWin():
                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}"
                for p in os.environ["PATH"].split(";"):
                    path += f":{self.toNativePath(p)}"
                self._environment["PATH"] = 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"CYGWIN{CraftCore.compiler.bits}_CRAFT"

                if self.useMSVCCompatEnv and CraftCore.compiler.isMSVC():
                    self._environment[
                        "LIB"] = f"{os.environ['LIB']};{CraftStandardDirs.craftRoot()}\\lib"
                    self._environment[
                        "INCLUDE"] = f"{os.environ['INCLUDE']};{CraftStandardDirs.craftRoot()}\\include"

                    if False:
                        cl = "clang-cl"
                    else:
                        cl = "cl"
                    self._environment["LD"] = "link -NOLOGO"
                    self._environment["CC"] = f"{cl} -nologo"
                    self._environment["CXX"] = self._environment["CC"]
                    self._environment["CPP"] = f"{cl} -nologo -EP"
                    self._environment["CXXCPP"] = self._environment["CPP"]
                    self._environment["NM"] = "dumpbin -symbols"
                    self._environment["AR"] = "lib"
                    self._environment["WINDRES"] = "rc"
                    # self.environment[ "RC","rc-windres"
                    self._environment["STRIP"] = ":"
                    self._environment["RANLIB"] = ":"
                    self._environment["F77"] = "no"
                    self._environment["FC"] = "no"

                    ldflags += ""
                    cflags += " -GR -W3 -EHsc -D_USE_MATH_DEFINES -DWIN32_LEAN_AND_MEAN -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS"  # dynamic and exceptions enabled
                    if CraftCore.compiler.getMsvcPlatformToolset() > 120:
                        cflags += " -FS"

            self._environment["PKG_CONFIG_PATH"] = self.toNativePath(
                os.path.join(CraftStandardDirs.craftRoot(), "lib",
                             "pkgconfig"))

            self._environment["CFLAGS"] = cflags
            self._environment["CXXFLAGS"] = cflags
            self._environment["LDFLAGS"] = ldflags
        return self._environment
Exemplo n.º 12
0
    def environment(self):
        if not self._environment:

            mergeroot = self.toNativePath(CraftStandardDirs.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/
                if CraftCore.compiler.macUseSDK:
                    sdkPath = CraftCore.cache.getCommandOutput(
                        "xcrun", "--show-sdk-path")[1].strip()
                    deploymentFlag = "-mmacosx-version-min=" + CraftCore.compiler.macOSDeploymentTarget
                    cflags = f" -isysroot {sdkPath} {deploymentFlag}" + cflags
                    # See https://github.com/Homebrew/homebrew-core/issues/2674 for the -no_weak_imports flag
                    ldflags = f" -isysroot {sdkPath} {deploymentFlag} -Wl,-no_weak_imports" + ldflags
                    # Note: MACOSX_DEPLOYMENT_TARGET is set in utils.system() so doesn't need to be set here
                else:
                    # 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.
                    cflags = " -isystem /usr/include " + cflags

            if CraftCore.compiler.isMSVC():
                # 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 OsDetection.isWin():
                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}"
                for p in os.environ["PATH"].split(";"):
                    path += f":{self.toNativePath(p)}"
                self._environment["PATH"] = 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["LD"] = "link -nologo"
                    self._environment["CC"] = f"{clWrapper} {cl} -nologo"
                    self._environment["CXX"] = self._environment["CC"]
                    self._environment["CPP"] = f"{cl} -nologo -EP"
                    self._environment["CXXCPP"] = self._environment["CPP"]
                    self._environment["NM"] = "dumpbin -symbols"
                    self._environment[
                        "RC"] = f"windres -O COFF --target={'pe-i386' if CraftCore.compiler.isX86() else 'pe-x86-64'} --preprocessor='cl -nologo -EP -DRC_INVOKED -DWINAPI_FAMILY=0'"

                    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"
                        " -wd4005"  # don't warn on redefine
                        " -wd4996"  # The POSIX name for this item is deprecated.
                    )
                    if CraftCore.compiler.getMsvcPlatformToolset() > 120:
                        cflags += " -FS"

            self._environment["PKG_CONFIG_PATH"] = self.toNativePath(
                os.path.join(CraftStandardDirs.craftRoot(), "lib",
                             "pkgconfig"))

            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