Example #1
0
    def _hunter_is_not_order_dependent(precall):
        samplesdir = uth.samplesdir()
        relativepaths = [
            "factory/test_factory.cpp",
            "numbers/test_direct_include.cpp",
            "simple/helloworld_c.c",
            "simple/helloworld_cpp.cpp",
            "simple/test_cflags.c",
        ]
        bulkpaths = [
            os.path.join(samplesdir, filename) for filename in relativepaths
        ]
        temp_config = ct.unittesthelper.create_temp_config()
        argv = ["--config", temp_config, "--include", uth.ctdir()]
        cap = configargparse.getArgumentParser()
        ct.hunter.add_arguments(cap)
        args = ct.apptools.parseargs(cap, argv)
        headerdeps = ct.headerdeps.create(args)
        magicparser = ct.magicflags.create(args, headerdeps)
        hntr = ct.hunter.Hunter(args, headerdeps, magicparser)
        os.unlink(temp_config)

        realpath = os.path.join(samplesdir, "dottypaths/dottypaths.cpp")
        if precall:
            result = hntr.required_source_files(realpath)
            return result
        else:
            for filename in bulkpaths:
                discard = hntr.required_source_files(filename)
            result = hntr.required_source_files(realpath)
            return result
Example #2
0
    def test_hunter_follows_source_files_from_header(self):
        origcache = ct.dirnamer.user_cache_dir("ct")
        tempdir = tempfile.mkdtemp()
        _reload_ct(tempdir)

        temp_config = ct.unittesthelper.create_temp_config()
        argv = ["-c", temp_config, "--include", uth.ctdir()]
        cap = configargparse.getArgumentParser()
        ct.hunter.add_arguments(cap)
        args = ct.apptools.parseargs(cap, argv)
        headerdeps = ct.headerdeps.create(args)
        magicparser = ct.magicflags.create(args, headerdeps)
        hntr = ct.hunter.Hunter(args, headerdeps, magicparser)

        relativepath = "factory/widget_factory.hpp"
        realpath = os.path.join(uth.samplesdir(), relativepath)
        filesfromheader = hntr.required_source_files(realpath)
        filesfromsource = hntr.required_source_files(
            ct.utils.implied_source(realpath))
        self.assertSetEqual(filesfromheader, filesfromsource)

        # Cleanup
        os.unlink(temp_config)
        shutil.rmtree(tempdir)
        _reload_ct(origcache)
Example #3
0
def _test_library(static_dynamic):
    """ Manually specify what files to turn into the static (or dynamic)
        library and test linkage
    """
    samplesdir = uth.samplesdir()
    origdir = uth.ctdir()
    global _moduletmpdir
    if not _moduletmpdir or not os.path.exists(_moduletmpdir):
        _moduletmpdir = tempfile.mkdtemp()

    tempdir = _moduletmpdir
    os.chdir(tempdir)
    temp_config_name = ct.unittesthelper.create_temp_config(tempdir)

    exerelativepath = "numbers/test_library.cpp"
    librelativepaths = [
        "numbers/get_numbers.cpp",
        "numbers/get_int.cpp",
        "numbers/get_double.cpp",
    ]
    exerealpath = os.path.join(samplesdir, exerelativepath)
    librealpaths = [os.path.join(samplesdir, filename) for filename in librelativepaths]
    argv = ["--config=" + temp_config_name, exerealpath, static_dynamic] + librealpaths
    ct.makefile.main(argv)

    # Figure out the name of the makefile and run make
    filelist = os.listdir(".")
    makefilename = [ff for ff in filelist if ff.startswith("Makefile")]
    cmd = ["make", "-f"] + makefilename
    subprocess.check_output(cmd, universal_newlines=True)

    # Cleanup
    os.chdir(origdir)
    shutil.rmtree(tempdir, ignore_errors=True)
Example #4
0
    def _hunter_is_not_order_dependent(precall):
        samplesdir = uth.samplesdir()
        relativepaths = [
            'factory/test_factory.cpp',
            'numbers/test_direct_include.cpp',
            'simple/helloworld_c.c',
            'simple/helloworld_cpp.cpp',
            'simple/test_cflags.c']
        bulkpaths = [os.path.join(samplesdir, filename)
                     for filename in relativepaths]
        temp_config = ct.unittesthelper.create_temp_config()
        argv = [
            '--config',
            temp_config,
            '--include',
            uth.ctdir()] + bulkpaths
        cap = configargparse.getArgumentParser()
        ct.hunter.add_arguments(cap)
        args = ct.apptools.parseargs(cap, argv)
        headerdeps = ct.headerdeps.create(args)
        magicparser = ct.magicflags.create(args, headerdeps)
        hntr = ct.hunter.Hunter(args, headerdeps, magicparser)
        os.unlink(temp_config)

        realpath = os.path.join(samplesdir, 'dottypaths/dottypaths.cpp')
        if precall:
            result = hntr.required_source_files(realpath)
            return result
        else:
            for filename in bulkpaths:
                discard = hntr.required_source_files(filename)
            result = hntr.required_source_files(realpath)
            return result
Example #5
0
    def test_hunter_follows_source_files_from_header(self):
        origcache = ct.dirnamer.user_cache_dir('ct')
        tempdir = tempfile.mkdtemp()
        _reload_ct(tempdir)
        
        temp_config = ct.unittesthelper.create_temp_config()
        argv = [
            '-c',
            temp_config,
            '--include',
            uth.ctdir()]
        cap = configargparse.getArgumentParser()
        ct.hunter.add_arguments(cap)
        args = ct.apptools.parseargs(cap, argv)
        headerdeps = ct.headerdeps.create(args)
        magicparser = ct.magicflags.create(args, headerdeps)
        hntr = ct.hunter.Hunter(args, headerdeps, magicparser)

        relativepath = 'factory/widget_factory.hpp'
        realpath = os.path.join(uth.samplesdir(), relativepath)
        filesfromheader = hntr.required_source_files(realpath)
        filesfromsource = hntr.required_source_files(
            ct.utils.implied_source(realpath))
        self.assertSetEqual(filesfromheader, filesfromsource)

        # Cleanup
        os.unlink(temp_config)
        shutil.rmtree(tempdir)
        _reload_ct(origcache)
Example #6
0
def _test_library(static_dynamic):
    """ Manually specify what files to turn into the static (or dynamic)
        library and test linkage
    """
    samplesdir = uth.samplesdir()
    origdir = uth.ctdir()
    global _moduletmpdir
    if not _moduletmpdir or not os.path.exists(_moduletmpdir) :
        _moduletmpdir = tempfile.mkdtemp()
    
    tempdir = _moduletmpdir
    os.chdir(tempdir)
    temp_config_name = ct.unittesthelper.create_temp_config(tempdir)

    exerelativepath = 'numbers/test_library.cpp'
    librelativepaths = [
        'numbers/get_numbers.cpp',
        'numbers/get_int.cpp',
        'numbers/get_double.cpp']
    exerealpath = os.path.join(samplesdir, exerelativepath)
    librealpaths = [
        os.path.join(
            samplesdir,
            filename) for filename in librelativepaths]
    argv = [
        '--config='+temp_config_name,
        exerealpath,
        static_dynamic] + librealpaths
    ct.makefile.main(argv)

    # Figure out the name of the makefile and run make
    filelist = os.listdir('.')
    makefilename = [ff for ff in filelist if ff.startswith('Makefile')]
    cmd = ['make', '-f'] + makefilename
    subprocess.check_output(cmd, universal_newlines=True)

    # Cleanup
    os.chdir(origdir)
    shutil.rmtree(tempdir, ignore_errors=True)
Example #7
0
def _generatecache(tempdir, name, realpaths, extraargs=None):
    if extraargs is None:
        extraargs = []
    temp_config_name = ct.unittesthelper.create_temp_config(tempdir)

    argv = [
        "--headerdeps",
        name,
        "--include",
        uth.ctdir(),
        "-c",
        temp_config_name,
    ] + extraargs
    cachename = os.path.join(tempdir, name)
    _reload_ct(cachename)

    cap = configargparse.getArgumentParser()
    ct.headerdeps.add_arguments(cap)
    args = ct.apptools.parseargs(cap, argv)
    headerdeps = ct.headerdeps.create(args)

    return cachename, temp_config_name, _callprocess(headerdeps, realpaths)
Example #8
0
    def _create_makefile_and_make(self, tempdir):
        origdir = uth.ctdir()
        print("origdir="+origdir)
        print(tempdir)
        samplesdir = uth.samplesdir()
        print("samplesdir="+samplesdir)
        os.chdir(tempdir)
        temp_config_name = ct.unittesthelper.create_temp_config(tempdir)
        relativepaths = [
            'numbers/test_direct_include.cpp',
            'factory/test_factory.cpp',
            'simple/helloworld_c.c',
            'simple/helloworld_cpp.cpp',
            'dottypaths/dottypaths.cpp']
        realpaths = [os.path.join(samplesdir, filename)
                     for filename in relativepaths]
        ct.makefile.main(
            ['--config='+temp_config_name] + realpaths)

        filelist = os.listdir('.')
        makefilename = [ff for ff in filelist if ff.startswith('Makefile')]
        cmd = ['make', '-f'] + makefilename
        subprocess.check_output(cmd, universal_newlines=True)

        # Check that an executable got built for each cpp
        actual_exes = set()
        for root, dirs, files in os.walk(tempdir):
            for ff in files:
                if ct.utils.isexecutable(os.path.join(root, ff)):
                    actual_exes.add(ff)
                    print(root + " " + ff)

        expected_exes = {
            os.path.splitext(
                os.path.split(filename)[1])[0] for filename in relativepaths}
        self.assertSetEqual(expected_exes, actual_exes)
        os.chdir(origdir)
Example #9
0
    def _create_makefile_and_make(self, tempdir):
        origdir = uth.ctdir()
        print("origdir=" + origdir)
        print(tempdir)
        samplesdir = uth.samplesdir()
        print("samplesdir=" + samplesdir)
        os.chdir(tempdir)
        temp_config_name = ct.unittesthelper.create_temp_config(tempdir)
        relativepaths = [
            "numbers/test_direct_include.cpp",
            "factory/test_factory.cpp",
            "simple/helloworld_c.c",
            "simple/helloworld_cpp.cpp",
            "dottypaths/dottypaths.cpp",
        ]
        realpaths = [os.path.join(samplesdir, filename) for filename in relativepaths]
        ct.makefile.main(["--config=" + temp_config_name] + realpaths)

        filelist = os.listdir(".")
        makefilename = [ff for ff in filelist if ff.startswith("Makefile")]
        cmd = ["make", "-f"] + makefilename
        subprocess.check_output(cmd, universal_newlines=True)

        # Check that an executable got built for each cpp
        actual_exes = set()
        for root, dirs, files in os.walk(tempdir):
            for ff in files:
                if ct.utils.isexecutable(os.path.join(root, ff)):
                    actual_exes.add(ff)
                    print(root + " " + ff)

        expected_exes = {
            os.path.splitext(os.path.split(filename)[1])[0]
            for filename in relativepaths
        }
        self.assertSetEqual(expected_exes, actual_exes)
        os.chdir(origdir)