示例#1
0
    def __call__(self, target, source, env):
        for s in source:
            source_file = os.path.relpath(s.path, env['build_dir'])
            offset_source = offset_path(s.path, env)
            gcno_file = os.path.splitext(source_file)[0] + '.gcno'
            gcda_file = os.path.splitext(source_file)[0] + '.gcda'
            gcov_file = source_file + '.gcov'
            gcov_summary = source_file + '.gcov.summary'

            env.Clean(source_file, [gcno_file, gcda_file])
            target.append(gcov_file)
            target.append(gcov_summary)

            gcov_source_path = offset_source.replace(os.path.sep, '#')

            gcov_files = Glob(gcov_source_path + '*')
            env.Clean(source_file, gcov_files)

            env.Clean(source_file,
                      os.path.join(self._final_dir, "coverage.html"))
            base_name = coverage_base_name(
                env['sconscript_toolchain_build_dir'])

            coverage_files = Glob(
                os.path.join(self._final_dir, base_name + '*.html'))
            env.Clean(source_file, coverage_files)

        return target, source
示例#2
0
def glob_recursive(pattern, node="."):
    results = []
    for f in Glob(str(node) + "/*", source=True):
        if type(f) is Node.FS.Dir:
            results += glob_recursive(pattern, f)
    results += Glob(str(node) + "/" + pattern, source=True)
    return results
示例#3
0
 def examples(ccList=None, swigNameList=None, swigSrc=None):
     if swigNameList is None:
         swigFileList = Glob("*.i")
         swigNameList = [_getFileBase(node) for node in swigFileList]
     else:
         swigFileList = [File(name) for name in swigNameList]
     if swigSrc is None:
         swigSrc = {}
     allSwigSrc = set()
     for name, node in zip(swigNameList, swigFileList):
         src = swigSrc.setdefault(name, [])
         allSwigSrc.update(str(element) for element in src)
         src.append(node)
     if ccList is None:
         ccList = [node for node in Glob("*.cc")
                   if (not str(node).endswith("_wrap.cc")) and str(node) not in allSwigSrc]
     state.log.info("SWIG modules for examples: %s" % swigFileList)
     state.log.info("C++ examples: %s" % ccList)
     results = []
     for src in ccList:
         results.extend(state.env.Program(src, LIBS=state.env.getLibs("main")))
     for name, src in swigSrc.items():
         results.extend(
             state.env.SwigLoadableModule("_" + name, src, LIBS=state.env.getLibs("main python"))
         )
     for result in results:
         state.env.Depends(result, state.targets["lib"])
     state.targets["examples"].extend(results)
     return results
示例#4
0
    def examples(ccList=None, swigNameList=None, swigSrc=None):
        """Convenience function to replace standard examples/SConscript
        boilerplate.

        Parameters
        ----------
        ccList : `list`, optional
            A sequence of C++ examples to build (including .cc extensions).
            Defaults to a ``*.cc`` glob of the examples directory, minus any
            files that end with ``*_wrap.cc`` and files present in swigSrc.
        swigNameList : `list`, optional
            A sequence of SWIG modules to build (NOT including .i extensions).
        swigSrc : `list`, optional
            Additional source files to be compiled into SWIG modules, as a
            dictionary; each key must be an entry in swigNameList, and each
            value a list of additional source files.

        Returns
        -------
        result : ???
            ???
        """
        if swigNameList is None:
            swigFileList = Glob("*.i")
            swigNameList = [_getFileBase(node) for node in swigFileList]
        else:
            swigFileList = [File(name) for name in swigNameList]
        if swigSrc is None:
            swigSrc = {}
        allSwigSrc = set()
        for name, node in zip(swigNameList, swigFileList):
            src = swigSrc.setdefault(name, [])
            allSwigSrc.update(str(element) for element in src)
            src.append(node)
        if ccList is None:
            ccList = [
                node for node in Glob("*.cc")
                if (not str(node).endswith("_wrap.cc"))
                and str(node) not in allSwigSrc
            ]
        state.log.info("SWIG modules for examples: %s" % swigFileList)
        state.log.info("C++ examples: %s" % ccList)
        results = []
        for src in ccList:
            results.extend(
                state.env.Program(src, LIBS=state.env.getLibs("main")))
        for name, src in swigSrc.items():
            results.extend(
                state.env.SwigLoadableModule(
                    "_" + name, src, LIBS=state.env.getLibs("main python")))
        for result in results:
            state.env.Depends(result, state.targets["lib"])
        state.targets["examples"].extend(results)
        return results
示例#5
0
 def lib(libName=None, src=None, libs="self", noBuildList=None):
     if libName is None:
         libName = state.env["packageName"]
     if src is None:
         src = Glob("#src/*.cc") + Glob("#src/*/*.cc") + Glob("#src/*/*/*.cc") + Glob("#src/*/*/*/*.cc")
     if noBuildList is not None:
         src = [node for node in src if os.path.basename(str(node)) not in noBuildList]
     src = state.env.SourcesForSharedLibrary(src)
     if isinstance(libs, str):
         libs = state.env.getLibs(libs)
     elif libs is None:
         libs = []
     result = state.env.SharedLibrary(libName, src, LIBS=libs)
     state.targets["lib"].extend(result)
     return result
示例#6
0
    def _run_gcovr(self, build_dir, output_dir, working_dir, sconscript_id):
        command = 'gcovr -h'
        if not command_available(command):
            print "coverage: skipping gcovr output as not available"
            return

        base_name = coverage_base_name(sconscript_id)

        index_file = base_name + ".html"

        regex_filter = re.escape(os.path.join(build_dir, ""))
        regex_filter = ".*" + regex_filter + ".*\.gcov"

        command = 'gcovr -g --gcov-filter="{}" -k -r . --html --html-details -o {}'.format(
            regex_filter, index_file)

        return_code, output = run_command(command, working_dir)

        if return_code == 0:
            os.rename(index_file, os.path.join(output_dir, "coverage.html"))
            coverage_files = Glob(base_name + '*.html')
            for coverage_file in coverage_files:
                new_coverage_file = os.path.join(output_dir,
                                                 str(coverage_file))
                os.rename(str(coverage_file), new_coverage_file)
            print output
        else:
            print output
示例#7
0
    def _run_gcovr(self, build_dir, output_dir, working_dir, sconscript_id):
        command = 'gcovr -h'
        if not command_available(command):
            print "cuppa: gcov: Skipping gcovr output as not available"
            return

        base_name = coverage_base_name(sconscript_id)

        index_file = base_name + ".html"

        regex_filter = re.escape(os.path.join(build_dir, ""))
        regex_filter = ".*" + regex_filter + ".*\.gcov"

        command = 'gcovr -g --gcov-filter="{}" -k -r . --html --html-details -o {}'.format(
            regex_filter, index_file)

        return_code, output = run_command(command, working_dir)

        new_index_file = os.path.join(output_dir, "coverage.html")
        try:
            os.rename(index_file, new_index_file)
        except OSError as e:
            print "cuppa: gcov: Failed moving coverage file from [{}] to [{}] with error: {}".format(
                index_file, new_index_file, str(e))

        coverage_files = Glob(base_name + '*.html')
        for coverage_file in coverage_files:
            new_coverage_file = os.path.join(output_dir, str(coverage_file))
            try:
                os.rename(str(coverage_file), new_coverage_file)
            except OSError as e:
                print "cuppa: gcov: Failed moving coverage file from [{}] to [{}] with error: {}".format(
                    str(coverage_file), new_coverage_file, str(e))
        print output
示例#8
0
def create_gsl_cpy_commands(conf, dependencies, copy_folder):
    '''
    Create os dependent commands. On darwin: copy all gsl libs, fix
    the install names for dylibs using install_name_tool, and 
    replace lib path with the patched version. On linux: do nothing
    '''
    if conf.env["SYSTEM"] == "Darwin" and dependencies["gsl"].lib_path:
        lib_path = dependencies["gsl"].lib_path
        commands = []

        for lib in Glob(os.path.join(lib_path, "*")):
            new_path = os.path.join(copy_folder, os.path.basename(lib.rstr()))
            action = [Copy("$TARGET", "$SOURCE")]
            if ("0.dylib" in lib.rstr()):
                action += [fix_dylib_for_darwin]

            kw = {
                'target': '{0}'.format(new_path),
                'source': '{0}'.format(lib),
                'action': action
            }

            commands.append(kw)

        dependencies["gsl"].lib_path = Dir(copy_folder).abspath
        return commands

    else:
        return []
示例#9
0
def InstallDir(target, source, env):  # XXX this belongs not in this module
    """
    Copies the given source dir inside of the given target dir.
    """
    # XXX could be rewritten better with schemey-recursion as "if source is
    # File: env.Install(), elif source is Dir, scan the dir and recurse"
    # SCons doesn't really like using directories as targets. Like, at all.
    # Mkdir(os.path.join(str(target), str(source)))
    # translate install(a/, b/) to install(a/b/, [files in b])
    contents = Glob(os.path.join(
        str(source),
        "*"))  # XXX there's probably a cleaner way that SCons has to do this
    # print("contents:", contents)
    files = filter(lambda f: isinstance(f, SCons.Node.FS.File), contents)
    folders = filter(lambda f: isinstance(f, SCons.Node.FS.Dir), contents)
    # print(map(str, folders))
    name = os.path.basename(str(source))

    # install the files local to this
    nodes = env.Install(Dir(os.path.join(str(target), name)), files)

    # now recursively install the subfolders
    for f in folders:
        nodes += InstallDir(Dir(os.path.join(str(target), name)), f, env)
    return nodes
示例#10
0
    def lib(libName=None, src=None, libs="self", noBuildList=None):
        """Convenience function to replace standard lib/SConscript boilerplate.

        With no arguments, this will build a shared library with the same name
        as the package.  This uses
        `lsst.sconsUtils.env.SourcesForSharedLibrary` to support the
        ``optFiles``/``noOptFiles`` command-line variables.

        Parameters
        ----------
        libName : `str`
            Name of the shared libray to be built (defaults to
            ``env["packageName"]``).
        src : `str` or `Glob`
            Source to compile into the library.  Defaults to a 4-directory
            deep glob of all ``*.cc`` files in ``#src``.
        libs : `str` or `list`
            Libraries to link against, either as a string argument to be
            passed to `lsst.sconsUtils.env.getLibs` or a sequence of actual
            libraries to pass in.
        noBuildList : `list`
            List of source files to exclude from building.

        Returns
        -------
        result : ???
            ???
        """
        if libName is None:
            libName = state.env["packageName"]
        if src is None:
            src = Glob("#src/*.cc") + Glob("#src/*/*.cc") + Glob(
                "#src/*/*/*.cc") + Glob("#src/*/*/*/*.cc")
        if noBuildList is not None:
            src = [
                node for node in src
                if os.path.basename(str(node)) not in noBuildList
            ]
        src = state.env.SourcesForSharedLibrary(src)
        if isinstance(libs, str):
            libs = state.env.getLibs(libs)
        elif libs is None:
            libs = []
        result = state.env.SharedLibrary(libName, src, LIBS=libs)
        state.targets["lib"].extend(result)
        return result
示例#11
0
    def shebang(src=None):
        # check if Python is called on the first line with this expression
        # This comes from distutils copy_scripts
        FIRST_LINE_RE = re.compile(r'^#!.*python[0-9.]*([ \t].*)?$')
        doRewrite = utils.needShebangRewrite()

        def rewrite_shebang(target, source, env):
            """Copy source to target, rewriting the shebang"""
            # Currently just use this python
            usepython = utils.whichPython()
            for targ, src in zip(target, source):
                with open(str(src), "r") as srcfd:
                    with open(str(targ), "w") as outfd:
                        first_line = srcfd.readline()
                        # Always match the first line so we can warn people
                        # if an attempt is being made to rewrite a file that should
                        # not be rewritten
                        match = FIRST_LINE_RE.match(first_line)
                        if match and doRewrite:
                            post_interp = match.group(1) or ''
                            # Paths can be long so ensure that flake8 won't complain
                            outfd.write("#!{}{}  # noqa\n".format(
                                usepython, post_interp))
                        else:
                            if not match:
                                state.log.warn(
                                    "Could not rewrite shebang of {}. Please check"
                                    " file or move it to bin directory.".
                                    format(str(src)))
                            outfd.write(first_line)
                        for line in srcfd.readlines():
                            outfd.write(line)
                # Ensure the bin/ file is executable
                oldmode = os.stat(str(targ))[ST_MODE] & 0o7777
                newmode = (oldmode | 0o555) & 0o7777
                if newmode != oldmode:
                    state.log.info("changing mode of {} from {} to {}".format(
                        str(targ), oldmode, newmode))
                    os.chmod(str(targ), newmode)

        if src is None:
            src = Glob("#bin.src/*")
        for s in src:
            filename = str(s)
            # Do not try to rewrite files starting with non-letters
            if filename != "SConscript" and re.match("[A-Za-z]", filename):
                result = state.env.Command(target=os.path.join(
                    Dir("#bin").abspath, filename),
                                           source=s,
                                           action=rewrite_shebang)
                state.targets["shebang"].extend(result)
示例#12
0
    def __call__(self, target, source, env):

        if not self._destination:
            self._destination = env['abs_final_dir']
        else:
            self._destination = self._destination + destination_subdir(env)

        report_node = next(
            (s for s in source if re.match(self.report_regex,
                                           os.path.split(str(s))[1])), None)
        filter_node = next(
            (s
             for s in source if os.path.splitext(str(s))[1] == ".cov_filter"),
            None)

        logger.trace("Report node = [{}]".format(as_notice(str(report_node))))
        logger.trace("Filter node = [{}]".format(as_notice(str(filter_node))))

        if report_node and filter_node:
            output_summary = os.path.splitext(
                str(filter_node))[0] + ".cov_files"
            target.append(output_summary)

            env.Clean(
                source,
                os.path.join(self._destination,
                             os.path.split(str(report_node))[1]))

            clean_pattern = None
            if filter_node:
                if os.path.exists(str(filter_node)):
                    with open(str(filter_node), 'r') as filter_file:
                        clean_pattern = filter_file.readline().strip()
                        clean_pattern = os.path.join(self._destination,
                                                     clean_pattern)
                        if clean_pattern.startswith('#'):
                            clean_pattern = os.path.join(
                                env['sconstruct_dir'], clean_pattern[1:])
                        logger.trace("Clean pattern = [{}]".format(
                            as_notice(clean_pattern)))

            if clean_pattern:
                env.Clean(source, Glob(clean_pattern))

        return target, source
示例#13
0
    def _run_gcovr(self, target, build_dir, output_dir, working_dir,
                   sconscript_id, include_regexes, exclude_regexes):

        cuppa.path.lazy_create_path(output_dir)

        command = 'gcovr -h'
        if not command_available(command):
            logger.warning("Skipping gcovr output as not available")
            return

        html_base_name = url_coverage_base_name(
            sconscript_id) + "." + self._program_id[2:]

        index_file = html_base_name + ".html"
        regex_filter = re.escape(os.path.join(build_dir, "")).replace(
            "\_", "_").replace("\#", "#")
        regex_filter = ".*" + regex_filter + ".*" + self._program_id + "\.gcov"

        gcov_includes = ""
        for include_regex in include_regexes:
            gcov_includes += ' --gcov-filter="{}"'.format(include_regex)

        if not gcov_includes:
            gcov_includes = ' --gcov-filter="{}"'.format(regex_filter)

        gcov_excludes = ""
        for exclude_regex in exclude_regexes:
            gcov_excludes += ' --gcov-exclude="{}"'.format(exclude_regex)

        command = 'gcovr -g {gcov_includes} {gcov_excludes} -s -k -r . --html --html-details -o {index_file}'.format(
            regex_filter=regex_filter,
            gcov_includes=gcov_includes,
            gcov_excludes=gcov_excludes,
            index_file=index_file)

        return_code, output = run_command(command, working_dir,
                                          self._scons_env)

        coverage_index_basename = "coverage" + self._url_program_id + ".html"
        new_index_file = os.path.join(output_dir, coverage_index_basename)
        try:
            os.rename(index_file, new_index_file)
        except OSError as e:
            logger.error(
                "Failed moving coverage file from [{}] to [{}] with error: {}".
                format(as_notice(index_file), as_notice(new_index_file),
                       as_error(str(e))))

        coverage_summary_path = os.path.splitext(new_index_file)[0] + ".log"
        with open(coverage_summary_path, 'w') as coverage_summary_file:
            coverage_summary_file.write(coverage_index_basename + "\n" +
                                        output)

        logger.trace("gcovr HTML file filter = [{}]".format(
            as_notice(html_base_name)))
        coverage_files = Glob(html_base_name + '*.html')

        for coverage_file in coverage_files:
            new_coverage_file = os.path.join(output_dir, str(coverage_file))
            target.append(new_coverage_file)
            try:
                os.rename(str(coverage_file), new_coverage_file)
            except OSError as e:
                logger.error(
                    "Failed moving coverage file from [{}] to [{}] with error: {}"
                    .format(as_notice(str(coverage_file)),
                            as_notice(new_coverage_file), as_error(str(e))))

        coverage_filter_path = os.path.join(
            output_dir, "coverage" + self._url_program_id + ".cov_filter")
        with open(coverage_filter_path, 'w') as coverage_filter_file:
            coverage_filter_file.write(html_base_name + '*.html')

        sys.stdout.write(output + "\n")
示例#14
0
env = DefaultEnvironment()
env.Replace(PROGNAME='hardware',
            UPLOADER='iceprog',
            UPLOADERFLAGS=[],
            UPLOADBINCMD='$UPLOADER $UPLOADERFLAGS $SOURCES')
env.Append(SIMULNAME='simulation')

# -- Target name for synthesis
TARGET = join(env['BUILD_DIR'], env['PROGNAME'])

# -- Resources paths
pioPlatform = env.PioPlatform()
IVL_PATH = join(pioPlatform.get_package_dir('toolchain-iverilog'), 'lib',
                'ivl')
VLIB_PATH = join(pioPlatform.get_package_dir('toolchain-iverilog'), 'vlib')
VLIB_FILES = ' '.join(['"{}"'.format(f) for f in Glob(join(VLIB_PATH, '*.v'))
                       ]) if VLIB_PATH else ''

CHIPDB_PATH = join(
    pioPlatform.get_package_dir('toolchain-icestorm'), 'share', 'icebox',
    'chipdb-{0}.txt'.format(env.BoardConfig().get('build.size', '1k')))

isWindows = 'Windows' == system()
VVP_PATH = '' if isWindows else '-M "{0}"'.format(IVL_PATH)
IVER_PATH = '' if isWindows else '-B "{0}"'.format(IVL_PATH)

# -- Get a list of all the verilog files in the src folfer, in ASCII, with
# -- the full path. All these files are used for the simulation
v_nodes = Glob(join(env['PROJECTSRC_DIR'], '*.v'))
src_sim = [str(f) for f in v_nodes]
示例#15
0
TARGET = join(env['BUILD_DIR'], env['PROGNAME'])

# -- Resources paths
pioPlatform = env.PioPlatform()
IVL_PATH = join(
    pioPlatform.get_package_dir('toolchain-iverilog'), 'lib', 'ivl')
VLIB_PATH = join(
    pioPlatform.get_package_dir('toolchain-iverilog'), 'vlib', 'system.v')

isWindows = 'Windows' != system()
VVP_PATH = '-M {0}'.format(IVL_PATH) if isWindows else ''
IVER_PATH = '-B {0}'.format(IVL_PATH) if isWindows else ''

# -- Get a list of all the verilog files in the src folfer, in ASCII, with
# -- the full path. All these files are used for the simulation
v_nodes = Glob(join(env['PROJECTSRC_DIR'], '*.v'))
src_sim = [str(f) for f in v_nodes]

# --- Get the Testbench file (there should be only 1)
# -- Create a list with all the files finished in _tb.v. It should contain
# -- the test bench
list_tb = [f for f in src_sim if f[-5:].upper() == "_TB.V"]

if len(list_tb) > 1:
    print "---> WARNING: More than one testbenches used"

# -- Error checking
try:
    testbench = list_tb[0]

# -- there is no testbench
示例#16
0
    def tests(pyList=None, ccList=None, swigNameList=None, swigSrc=None,
              ignoreList=None, noBuildList=None, pySingles=None,
              args=None):
        if noBuildList is None:
            noBuildList = []
        if pySingles is None:
            pySingles = []
        if swigNameList is None:
            swigFileList = Glob("*.i")
            swigNameList = [_getFileBase(node) for node in swigFileList]
        else:
            swigFileList = [File(name + ".i") for name in swigNameList]
        if swigSrc is None:
            swigSrc = {}
        allSwigSrc = set()
        for name, node in zip(swigNameList, swigFileList):
            src = swigSrc.setdefault(name, [])
            allSwigSrc.update(str(element) for element in src)
            src.append(node)
        if pyList is None:
            pyList = [node for node in Glob("*.py")
                      if _getFileBase(node) not in swigNameList and
                      os.path.basename(str(node)) not in noBuildList]
            # if we got no matches, reset to None so we do not enabled
            # auto test detection in pytest
            if not pyList:
                pyList = None
        if ccList is None:
            ccList = [node for node in Glob("*.cc")
                      if (not str(node).endswith("_wrap.cc")) and str(node) not in allSwigSrc and
                      os.path.basename(str(node)) not in noBuildList]
        if ignoreList is None:
            ignoreList = []

        def s(l):
            if l is None:
                return ['None']
            return [str(i) for i in l]

        state.log.info("SWIG modules for tests: %s" % s(swigFileList))
        state.log.info("Python tests: %s" % s(pyList))
        state.log.info("C++ tests: %s" % s(ccList))
        state.log.info("Files that will not be built: %s" % noBuildList)
        state.log.info("Ignored tests: %s" % ignoreList)
        control = tests.Control(state.env, ignoreList=ignoreList, args=args, verbose=True)
        for ccTest in ccList:
            state.env.Program(ccTest, LIBS=state.env.getLibs("main test"))
        swigMods = []
        for name, src in swigSrc.items():
            swigMods.extend(
                state.env.SwigLoadableModule("_" + name, src, LIBS=state.env.getLibs("main python"))
            )

        # Warn about insisting that a test in pySingles starts with test_ and
        # therefore might be automatically discovered by pytest. These files
        # should not be discovered automatically.
        for node in pySingles:
            if str(node).startswith("test_"):
                state.log.warn("Warning: {} should be run independently but"
                               " can be automatically discovered".format(node))

        # Ensure that python tests listed in pySingles are not included in pyList.
        if pyList is not None:
            pyList = [str(node) for node in pyList if str(node) not in pySingles]

        ccList = [control.run(str(node)) for node in ccList]
        pySingles = [control.run(str(node)) for node in pySingles]

        # If we tried to discover .py files and found none, do not then
        # try to use auto test discovery.
        if pyList is not None:
            pyList = [control.runPythonTests(pyList)]
        else:
            pyList = []
        pyList.extend(pySingles)
        for pyTest in pyList:
            state.env.Depends(pyTest, ccList)
            state.env.Depends(pyTest, swigMods)
            state.env.Depends(pyTest, state.targets["python"])
            state.env.Depends(pyTest, state.targets["shebang"])
        result = ccList + pyList
        state.targets["tests"].extend(result)
        return result
示例#17
0
if "Darwin" == system():
    env.PrependENVPath(
        "DYLD_LIBRARY_PATH",
        join(pioPlatform.get_package_dir('toolchain-icestorm'), "lib")
    )

# -- Target name for synthesis
TARGET = join(env['BUILD_DIR'], env['PROGNAME'])

# -- Resources paths
IVL_PATH = join(
    pioPlatform.get_package_dir('toolchain-iverilog'), 'lib', 'ivl')
VLIB_PATH = join(
    pioPlatform.get_package_dir('toolchain-iverilog'), 'vlib')
VLIB_FILES = ' '.join([
    '"{}"'.format(f) for f in Glob(join(VLIB_PATH, '*.v'))
    ]) if VLIB_PATH else ''

CHIPDB_PATH = join(
    pioPlatform.get_package_dir('toolchain-icestorm'), 'share', 'icebox',
    'chipdb-{0}.txt'.format(env.BoardConfig().get('build.size', '1k')))

isWindows = 'Windows' == system()
VVP_PATH = '' if isWindows else '-M "{0}"'.format(IVL_PATH)
IVER_PATH = '' if isWindows else '-B "{0}"'.format(IVL_PATH)

# -- Get a list of all the verilog files in the src folfer, in ASCII, with
# -- the full path. All these files are used for the simulation
v_nodes = Glob(join(env.subst('$PROJECT_SRC_DIR'), '*.v'))
src_sim = [str(f) for f in v_nodes]
示例#18
0
    def tests(pyList=None,
              ccList=None,
              swigNameList=None,
              swigSrc=None,
              ignoreList=None,
              noBuildList=None,
              args=None):
        if noBuildList is None:
            noBuildList = []
        if swigNameList is None:
            swigFileList = Glob("*.i")
            swigNameList = [_getFileBase(node) for node in swigFileList]
        else:
            swigFileList = [File(name + ".i") for name in swigNameList]
        if swigSrc is None:
            swigSrc = {}
        allSwigSrc = set()
        for name, node in zip(swigNameList, swigFileList):
            src = swigSrc.setdefault(name, [])
            allSwigSrc.update(str(element) for element in src)
            src.append(node)
        if pyList is None:
            pyList = [
                node for node in Glob("*.py")
                if _getFileBase(node) not in swigNameList
                and os.path.basename(str(node)) not in noBuildList
            ]
        if ccList is None:
            ccList = [
                node for node in Glob("*.cc")
                if (not str(node).endswith("_wrap.cc")) and str(node) not in
                allSwigSrc and os.path.basename(str(node)) not in noBuildList
            ]
        if ignoreList is None:
            ignoreList = []

        def s(l):
            return [str(i) for i in l]

        state.log.info("SWIG modules for tests: %s" % s(swigFileList))
        state.log.info("Python tests: %s" % s(pyList))
        state.log.info("C++ tests: %s" % s(ccList))
        state.log.info("Files that will not be built: %s" % noBuildList)
        state.log.info("Ignored tests: %s" % ignoreList)
        control = tests.Control(state.env,
                                ignoreList=ignoreList,
                                args=args,
                                verbose=True)
        for ccTest in ccList:
            state.env.Program(ccTest, LIBS=state.env.getLibs("main test"))
        swigMods = []
        for name, src in swigSrc.items():
            swigMods.extend(
                state.env.SwigLoadableModule(
                    "_" + name, src, LIBS=state.env.getLibs("main python")))
        ccList = [control.run(str(node)) for node in ccList]
        pyList = [control.run(str(node)) for node in pyList]
        for pyTest in pyList:
            state.env.Depends(pyTest, swigMods)
            state.env.Depends(pyTest, state.targets["python"])
            state.env.Depends(pyTest, state.targets["shebang"])
        result = ccList + pyList
        state.targets["tests"].extend(result)
        return result
示例#19
0
    def __call__(self, target, source, env):

        for s in source:
            source_file = os.path.relpath(s.path, env['build_dir'])

            logger.trace(
                "Determine coverage files for source file [{}]".format(
                    as_notice(source_file)))

            gcno_file = os.path.splitext(source_file)[0] + '.gcno'
            gcda_file = os.path.splitext(source_file)[0] + '.gcda'
            logger.trace("gcov data paths = [{}] and [{}]".format(
                as_notice(gcno_file), as_notice(gcda_file)))
            env.Clean(source_file, [gcno_file, gcda_file])

            gcov_log = source_file + self._program_id + '_gcov.log'
            logger.trace("Adding target gcov_log = [{}]".format(
                as_notice(gcov_log)))
            target.append(gcov_log)

            gcov_base_name = gcov_offset_path(s.path, env)
            gcov_file_filter = gcov_base_name + '*' + self._program_id[
                2:] + ".gcov"

            logger.trace("gcov file filter = [{}]".format(
                as_notice(gcov_file_filter)))

            gcov_files = Glob(gcov_file_filter)
            env.Clean(source_file, gcov_files)

            coverage_index_file = os.path.join(
                self._final_dir, "coverage" + self._url_program_id + ".html")
            logger.trace("Adding target gcovr index file =[{}]".format(
                as_notice(coverage_index_file)))
            target.append(coverage_index_file)

            coverage_summary_file = os.path.join(
                self._final_dir, "coverage" + self._url_program_id + ".log")
            logger.trace("Adding target gcovr summary file =[{}]".format(
                as_notice(coverage_summary_file)))
            target.append(coverage_summary_file)

            coverage_filter_file = os.path.join(
                self._final_dir,
                "coverage" + self._url_program_id + ".cov_filter")
            logger.trace("Adding target gcovr filter file =[{}]".format(
                as_notice(coverage_filter_file)))
            target.append(coverage_filter_file)

            coverage_filter = os.path.join(
                self._final_dir,
                url_coverage_base_name(env['sconscript_toolchain_build_dir']) +
                "." + self._program_id[2:] + '*.html')

            logger.trace("coverage filter = [{}]".format(
                as_notice(coverage_filter)))

            coverage_files = Glob(coverage_filter)
            env.Clean(source_file, coverage_files)

        return target, source
示例#20
0
def IMPSystem(env, name=None, version=None,
              authors=[],
              brief="", overview="",
              publications=None,
              license="standard",
              required_modules=[],
              optional_dependencies=[],
              required_dependencies=[],
              extra_data=[],
              testable=False,
              parallelizable=False,
              last_imp_version="unknown",
              python=True):
    if not name:
        name= Dir(".").abspath.split("/")[-1]
    if env.GetOption('help'):
        return
    dirs = scons_tools.paths.get_sconscripts(env)
    local_module=False
    for d in dirs:
        env.SConscript(d, exports=['env'])
    (nenv, version, found_optional_modules, found_optional_dependencies) =\
         utility.configure(env, name, "system", version,
                           required_modules=required_modules,
                           optional_dependencies=optional_dependencies,
                           required_dependencies= required_dependencies)
    if not nenv:
        data.get(env).add_application(name, ok=False)
        return
    else:
        if nenv["IMP_PASS"] != "RUN":
            return

        lkname="system_"+name.replace(" ", "_").replace(":", "_")
        pre="\page "+lkname+" "+name
        extrasections=[]
        if testable:
            extrasections.append(("Testable", "Yes"))
        else:
            extrasections.append(("Testable", "No"))
        if parallelizable:
            extrasections.append(("Parallelizeable", "Yes"))
        else:
            extrasections.append(("Parallelizeable", "No"))
        if last_imp_version != "unknown":
            extrasections.append(("Last known good \imp version", last_imp_version))
        else:
            vtxt=  "\n\\section lkgversion Last known good IMP version\n"+\
                "unknown"+"\n"
        data.get(env).add_system(name, link="\\ref "+lkname+' "'+name+'"',
                                 dependencies=required_dependencies\
                                     +found_optional_dependencies,
                                 unfound_dependencies=[x for x in optional_dependencies
                                                       if not x in
                                                       found_optional_dependencies],
                                 modules= required_modules+found_optional_modules,
                                 version=version)
        for d in dirs:
            if str(d).split("/")[0] != "local":
                env.SConscript(d, exports=['env'])
        scons_tools.data.get(env).add_to_alias("all", env.Alias(name))
        env= nenv
        for m in required_modules+found_optional_modules:
            env.Depends(scons_tools.data.get(env).get_alias(name),
                         scons_tools.data.get(env).get_alias(m))
        if testable:
            samples= Glob("sample_[0123456789]*.py")
            samples.sort(utility.file_compare)
            analysis= Glob("analyze_[0123456789]*.py")
            analysis.sort(utility.file_compare)
            tt= []
            tests = test.add_tests(env, samples+analysis, "system")
            for t in tests:
                env.Depends(t, scons_tools.data.get(env).get_alias(name))

        # link files in build dir
        allfiles= []
        for suff in ["*.txt", "*.mrc", "*.pdb", ".py", ".param", ".input", ".lib"]:
            allfiles.extend(Glob("*/*"+suff))
            allfiles.extend(Glob("*"+suff))
        for f in allfiles+extra_data:
            inst=install.install(env, "biological_systems/"+name+"/", f)
            scons_tools.data.get(env).add_to_alias(env.Alias(name), inst)
            #if f.path.endswith(".py"):
            #     example.add_python_example(env, f, f.path)
            #env.AlwaysBuild(install)

        doc.add_doc_page(env, "\\page "+lkname+" "+name.capitalize(),
                         authors, version,
                         brief, overview,
                         publications,
                         license, extra_sections=extrasections)

        return env
示例#21
0
    def tests(pyList=None,
              ccList=None,
              swigNameList=None,
              swigSrc=None,
              ignoreList=None,
              noBuildList=None,
              pySingles=None,
              args=None):
        """Convenience function to replace standard tests/SConscript
        boilerplate.

        With no arguments, will attempt to figure out which files should be
        run as tests and which are support code (like SWIG modules).

        Python tests will be marked as dependent on the entire ``#python``
        directory and any SWIG modules built in the tests directory.  This
        should ensure tests are always run when their results might have
        changed, but may result in them being re-run more often
        than necessary.

        Parameters
        ----------
        pyList : `list`, optional
            A sequence of Python tests to run (including .py extensions).
            Defaults to a ``*.py`` glob of the tests directory, minus any
            files corresponding to the SWIG modules in swigFileList.
            An empty list will enable automated test discovery.
        ccList : `list`, optional
            A sequence of C++ unit tests to run (including .cc extensions).
            Defaults to a ``*.cc`` glob of the tests directory, minus any
            files that end with ``*_wrap.cc`` and files present in swigSrc.
        swigNameList : `list`, optional
            A sequence of SWIG modules to build (NOT including .i extensions).
        swigSrc : `dict`, optional
            Additional source files to be compiled into SWIG modules, as a
            dictionary; each key must be an entry in swigNameList, and each
            value a list of additional source files.
        ignoreList : `list`, optional
            List of ignored tests to be passed to
            `lsst.sconsUtils.tests.Control` (note that ignored tests will be
            built, but not run).
        noBuildList : `list`, optional
            List of tests that should not even be built.
        pySingles : `list`, optional
            A sequence of Python tests to run (including .py extensions)
            as independent single tests. By default this list is empty
            and all tests are run in a single pytest call.
            Items specified here will not appear in the default pyList
            and should not start with ``test_`` (such that they will not
            be auto-discoverable by pytest).
        args : `dict`, optional
            A dictionary of program arguments for tests, passed directly
            to `lsst.sconsUtils.tests.Control`.

        Returns
        -------
        result : ???
            ???
        """
        if noBuildList is None:
            noBuildList = []
        if pySingles is None:
            pySingles = []
        if swigNameList is None:
            swigFileList = Glob("*.i")
            swigNameList = [_getFileBase(node) for node in swigFileList]
        else:
            swigFileList = [File(name + ".i") for name in swigNameList]
        if swigSrc is None:
            swigSrc = {}
        allSwigSrc = set()
        for name, node in zip(swigNameList, swigFileList):
            src = swigSrc.setdefault(name, [])
            allSwigSrc.update(str(element) for element in src)
            src.append(node)
        if pyList is None:
            pyList = [
                node for node in Glob("*.py")
                if _getFileBase(node) not in swigNameList
                and os.path.basename(str(node)) not in noBuildList
            ]
            # if we got no matches, reset to None so we do not enabled
            # auto test detection in pytest
            if not pyList:
                pyList = None
        if ccList is None:
            ccList = [
                node for node in Glob("*.cc")
                if (not str(node).endswith("_wrap.cc")) and str(node) not in
                allSwigSrc and os.path.basename(str(node)) not in noBuildList
            ]
        if ignoreList is None:
            ignoreList = []

        def s(l):
            if l is None:
                return ['None']
            return [str(i) for i in l]

        state.log.info("SWIG modules for tests: %s" % s(swigFileList))
        state.log.info("Python tests: %s" % s(pyList))
        state.log.info("C++ tests: %s" % s(ccList))
        state.log.info("Files that will not be built: %s" % noBuildList)
        state.log.info("Ignored tests: %s" % ignoreList)
        control = tests.Control(state.env,
                                ignoreList=ignoreList,
                                args=args,
                                verbose=True)
        for ccTest in ccList:
            state.env.Program(ccTest, LIBS=state.env.getLibs("main test"))
        swigMods = []
        for name, src in swigSrc.items():
            swigMods.extend(
                state.env.SwigLoadableModule(
                    "_" + name, src, LIBS=state.env.getLibs("main python")))

        # Warn about insisting that a test in pySingles starts with test_ and
        # therefore might be automatically discovered by pytest. These files
        # should not be discovered automatically.
        for node in pySingles:
            if str(node).startswith("test_"):
                state.log.warn("Warning: {} should be run independently but"
                               " can be automatically discovered".format(node))

        # Ensure that python tests listed in pySingles are not included in
        # pyList.
        if pyList is not None:
            pyList = [
                str(node) for node in pyList if str(node) not in pySingles
            ]

        ccList = [control.run(str(node)) for node in ccList]
        pySingles = [control.run(str(node)) for node in pySingles]

        # If we tried to discover .py files and found none, do not then
        # try to use auto test discovery.
        if pyList is not None:
            pyList = [control.runPythonTests(pyList)]
        else:
            pyList = []

        # Run all pySingles sequentially before other tests.  This ensures
        # that there are no race conditions collecting coverage databases.
        if pySingles:
            for i in range(len(pySingles) - 1):
                state.env.Depends(pySingles[i + 1], pySingles[i])
            for pyTest in pyList:
                state.env.Depends(pyTest, pySingles[-1])

        pyList.extend(pySingles)
        for pyTest in pyList:
            state.env.Depends(pyTest, ccList)
            state.env.Depends(pyTest, swigMods)
            state.env.Depends(pyTest, state.targets["python"])
            state.env.Depends(pyTest, state.targets["shebang"])
        result = ccList + pyList
        state.targets["tests"].extend(result)
        return result
示例#22
0
piopackages_dir = env.subst('$PIOPACKAGES_DIR')
bin_dir = join(piopackages_dir, 'toolchain-simplez', 'bin')

# -- Add the $HOME/.local/bin to the path
# -- There are locate the tools when installed with pip3
env.PrependENVPath('PATH', LOCALBIN)

# -- Add this path to the PATH env variable. First the building tools will be
# -- searched in the local PATH. If they are not founde, the global ones will
# -- be executed (if installed)
env.PrependENVPath('PATH', bin_dir)

# -- Get a list of all the asm files in the src folfer, in ASCII, with
# -- the full path
# -- All these programs will be assembled
asm_nodes = Glob(join(env['PROJECTSRC_DIR'], '*.asm'))

# -- Builder (.asm --> .list)
assembler = Builder(action='sasm $SOURCE -o $TARGET',
                    suffix='.list',
                    src_suffix='.asm')

env.Append(BUILDERS={'Assemble': assembler})

progs = env.Assemble(asm_nodes)

try:
    prog = progs[0]
except IndexError:
    prog = None
    print("Warning: NO .asm files!!!")