Exemple #1
0
 def test_PrependPathPreserveOld(self):
     """Test prepending to a path while preserving old paths"""
     p1 = r'C:\dir\num\one;C:\dir\num\two'
     # have to include the pathsep here so that the test will work on UNIX too.
     p1 = PrependPath(p1, r'C:\dir\num\two', sep=';', delete_existing=0)
     p1 = PrependPath(p1, r'C:\dir\num\three', sep=';')
     assert (p1 == r'C:\dir\num\three;C:\dir\num\one;C:\dir\num\two')
Exemple #2
0
 def test_PrependPath(self):
     """Test prepending to a path"""
     p1 = r'C:\dir\num\one;C:\dir\num\two'
     p2 = r'C:\mydir\num\one;C:\mydir\num\two'
     # have to include the pathsep here so that the test will work on UNIX too.
     p1 = PrependPath(p1, r'C:\dir\num\two', sep=';')
     p1 = PrependPath(p1, r'C:\dir\num\three', sep=';')
     p2 = PrependPath(p2, r'C:\mydir\num\three', sep=';')
     p2 = PrependPath(p2, r'C:\mydir\num\one', sep=';')
     assert (p1 == r'C:\dir\num\three;C:\dir\num\two;C:\dir\num\one')
     assert (p2 == r'C:\mydir\num\one;C:\mydir\num\three;C:\mydir\num\two')
Exemple #3
0
def CheckSDL2(context, require_version):
    version = require_version.split(".", 2)
    major_version = version[0]
    minor_version = version[1]
    patchlevel = version[2]
    backup = backup_env(context.env, ["CPPPATH", "LIBPATH", "LIBS"])
    sdldir = context.env.get("sdldir", "")
    context.Message(
        "Checking for Simple DirectMedia Layer library version >= %s.%s.%s... "
        % (major_version, minor_version, patchlevel))

    env = context.env
    if sdldir:
        env["ENV"]["PATH"] = PrependPath(environ["PATH"], join(sdldir, "bin"))
        env["ENV"]["PKG_CONFIG_PATH"] = PrependPath(
            environ.get("PKG_CONFIG_PATH", ""), join(sdldir, "lib/pkgconfig"))

    if env["PLATFORM"] != "win32" or sys.platform == "msys":
        for foo_config in [
                "pkg-config --cflags --libs $PKG_CONFIG_FLAGS sdl2",
                "sdl2-config --cflags --libs"
        ]:
            try:
                env.ParseConfig(foo_config)
            except OSError:
                pass
            else:
                break
    else:
        if sdldir:
            env.AppendUnique(CPPPATH=[os.path.join(sdldir, "include/SDL2")],
                             LIBPATH=[os.path.join(sdldir, "lib")])
        env.AppendUnique(CCFLAGS=["-D_GNU_SOURCE"])
        env.AppendUnique(LIBS=Split("mingw32 SDL2main SDL2"))
        env.AppendUnique(LINKFLAGS=["-mwindows"])

    cpp_file = File("src/conftests/sdl2.cpp").rfile().abspath
    if not os.path.isfile(cpp_file):
        cpp_file = "src/conftests/sdl2.cpp"

    with open(cpp_file, 'r') as file:
        test_program = file.read().replace(
            "argv[1]", "\"" + major_version + "\"").replace(
                "argv[2]",
                "\"" + minor_version + "\"").replace("argv[3]",
                                                     "\"" + patchlevel + "\"")

        if context.TryLink(test_program, ".cpp"):
            context.Result("yes")
            return True
        else:
            context.Result("no")
            restore_env(context.env, backup)
            return False
Exemple #4
0
    def test_PrependPath(self):
        """Test prepending to a path"""
        p1 = r'C:\dir\num\one;C:\dir\num\two'
        p2 = r'C:\mydir\num\one;C:\mydir\num\two'
        # have to include the pathsep here so that the test will work on UNIX too.
        p1 = PrependPath(p1, r'C:\dir\num\two', sep=';')
        p1 = PrependPath(p1, r'C:\dir\num\three', sep=';')
        assert p1 == r'C:\dir\num\three;C:\dir\num\two;C:\dir\num\one', p1

        p2 = PrependPath(p2, r'C:\mydir\num\three', sep=';')
        p2 = PrependPath(p2, r'C:\mydir\num\one', sep=';')
        assert p2 == r'C:\mydir\num\one;C:\mydir\num\three;C:\mydir\num\two', p2

        # check (only) first one is kept if there are dupes in new
        p3 = r'C:\dir\num\one'
        p3 = PrependPath(p3,
                         r'C:\dir\num\two;C:\dir\num\three;C:\dir\num\two',
                         sep=';')
        assert p3 == r'C:\dir\num\two;C:\dir\num\three;C:\dir\num\one', p3
Exemple #5
0
def prepend_ld_library_path(env, overrides, **kwargs):
    """Prepend LD_LIBRARY_PATH with LIBPATH to run successfully programs that
    were linked against local shared libraries."""
    # make it unique but preserve order ...
    libpath = uniquer(Split(kwargs.get('CXXTEST_LIBPATH', [])) +
                      Split(env.get(   'CXXTEST_LIBPATH', [])))
    if len(libpath) > 0:
        libpath = env.arg2nodes(libpath, env.fs.Dir)
        platform = env.get('PLATFORM','')
        if platform == 'win32':
            var = 'PATH'
        else:
            var = 'LD_LIBRARY_PATH'
        eenv = overrides.get('ENV', env['ENV'].copy())
        canonicalize = lambda p : p.abspath
        eenv[var] = PrependPath(eenv.get(var,''), libpath, os.pathsep, 1, canonicalize)
        overrides['ENV'] = eenv
    return overrides
Exemple #6
0
def CheckSDL(context, sdl_lib="SDL", require_version=None, header_file=None):
    if require_version:
        version = require_version.split(".", 2)
        major_version = int(version[0])
        minor_version = int(version[1])
        try:
            patchlevel = int(version[2])
        except (ValueError, IndexError):
            patch_level = 0

    if header_file:
        sdl_header = header_file
    else:
        sdl_header = sdl_lib

    backup = backup_env(context.env, ["CPPPATH", "LIBPATH", "LIBS"])

    sdldir = context.env.get("sdldir", "")
    if sdl_lib == "SDL":
        if require_version:
            context.Message(
                "Checking for Simple DirectMedia Layer library version >= %d.%d.%d... "
                % (major_version, minor_version, patchlevel))
        else:
            context.Message(
                "Checking for Simple DirectMedia Layer library... ")
        if major_version == 2:
            sdl_config_name = "sdl2-config"
            sdl_include_dir = "include/SDL2"
            sdl_lib_name = "SDL2"
            sdl_lib_name_pkgconfig = "sdl2"
            sdlmain_name = "SDL2main"
        else:
            sdl_config_name = "sdl-config"
            sdl_include_dir = "include/SDL"
            sdl_lib_name = "SDL"
            sdl_lib_name_pkgconfig = "sdl"
            sdlmain_name = "SDLmain"
        env = context.env
        if sdldir:
            env["ENV"]["PATH"] = PrependPath(environ["PATH"],
                                             join(sdldir, "bin"))
            env["ENV"]["PKG_CONFIG_PATH"] = PrependPath(
                environ.get("PKG_CONFIG_PATH", ""),
                join(sdldir, "lib/pkgconfig"))
        if env["PLATFORM"] != "win32":
            for foo_config in [
                    "pkg-config --cflags --libs %s" % sdl_lib_name_pkgconfig,
                    "%s --cflags --libs" % sdl_config_name
            ]:
                try:
                    env.ParseConfig(foo_config)
                except OSError:
                    pass
                else:
                    break
        else:
            if sdldir:
                env.AppendUnique(
                    CPPPATH=[os.path.join(sdldir, sdl_include_dir)],
                    LIBPATH=[os.path.join(sdldir, "lib")])
            env.AppendUnique(CCFLAGS=["-D_GNU_SOURCE"])
            env.AppendUnique(LIBS=Split("mingw32 %s %s" %
                                        (sdlmain_name, sdl_lib_name)))
            env.AppendUnique(LINKFLAGS=["-mwindows"])
    else:
        if require_version:
            context.Message(
                "Checking for %s library version >= %d.%d.%d... " %
                (sdl_lib, major_version, minor_version, patchlevel))
        else:
            context.Message("Checking for %s library... " % sdl_lib)
        context.env.AppendUnique(LIBS=[sdl_lib])
    test_program = """
        #include <%s.h> 
        \n""" % sdl_header
    if require_version:
        test_program += "#if SDL_VERSIONNUM(%s, %s, %s) < SDL_VERSIONNUM(%d, %d, %d)\n#error Library is too old!\n#endif\n" % \
            (sdl_lib.upper() + "_MAJOR_VERSION", \
             sdl_lib.upper() + "_MINOR_VERSION", \
             sdl_lib.upper() + "_PATCHLEVEL", \
             major_version, minor_version, patchlevel)
    test_program += """
        int main(int argc, char** argv)
        {
            SDL_Init(0);
            SDL_Quit();
        }
        \n"""
    if context.TryLink(test_program, ".c"):
        context.Result("yes")
        return True
    else:
        context.Result("no")
        restore_env(context.env, backup)
        return False