Ejemplo n.º 1
0
 def add_run_test_builds(self):
     # For everything that gets installed to build/unittests, add a rule for +basename
     # that runs the test from its original location.
     tests = [flatten(build['inputs'])[0]
              for build in self.builds
              if build['rule'] == 'INSTALL'
              and flatten(build['outputs'])[0].startswith(os.path.join('build', 'unittests'))]
     self.builds += [dict(outputs='+'+os.path.basename(test), inputs=test, rule='RUN_TEST')
                     for test in tests]
Ejemplo n.º 2
0
def insort_wrapper(target_list, target_string):
    """
    Removes instances of empty list inside the list before handing it to insort.
    """
    from SCons.Util import flatten
    target_list[:] = flatten(target_list)
    bisect.insort(target_list, target_string)
Ejemplo n.º 3
0
    def write_regenerator(self, ninja):
        deps = flatten([
            'SConstruct',
            rglob('SConscript', 'src'),
            rglob('*.py', 'site_scons'),
            rglob('*.py', 'buildscripts'),
            rglob('*.py', 'src/third_party/scons-2.5.0'),
            rglob('*.py', 'src/mongo/db/modules'),
            [self.globalEnv.WhereIs(tool) for tool in self.tool_paths],
            self.rc_files, # We rely on scons to tell us the deps of windows rc files.

            # Depend on git as position as well. This ensures that error codes are always checked
            # after rebase.
            '.git/HEAD',
            glob.glob('.git/refs/heads/*'),
            ])
        deps = sorted(set(dep.replace(' ', '\\ ')
                          for dep in deps
                          if dep and os.path.isfile(dep)))

        depfile = self.ninja_file + '.deps'
        with file(depfile, 'w') as f:
            f.write(self.ninja_file + ': ')
            f.write(' '.join(deps))

        ninja.newline()
        ninja.rule('GENERATOR',
            command = "$PYTHON %s $scons_args $out"%(sys.argv[0]),
            pool = 'console',
            generator = 1,
            description = 'Regenerating $out',
            depfile = depfile,
            restat=1)
        ninja.build(self.ninja_file, 'GENERATOR')
Ejemplo n.º 4
0
    def execute(self, target, source, env):
        """Execute a command action.

        This will handle lists of commands as well as individual commands,
        because construction variable substitution may turn a single
        "command" into a list.  This means that this class can actually
        handle lists of commands, even though that's not how we use it
        externally.
        """
        from SCons.Util import is_String, is_List, flatten, escape_list

        try:
            shell = env['SHELL']
        except KeyError:
            raise SCons.Errors.UserError('Missing SHELL construction variable.')

        try:
            spawn = env['SPAWN']
        except KeyError:
            raise SCons.Errors.UserError('Missing SPAWN construction variable.')

        escape = env.get('ESCAPE', lambda x: x)

        try:
            ENV = env['ENV']
        except KeyError:
            global default_ENV
            if not default_ENV:
                import SCons.Environment
                default_ENV = SCons.Environment.Environment()['ENV']
            ENV = default_ENV

        # Ensure that the ENV values are all strings:
        for key, value in ENV.items():
            if not is_String(value):
                if is_List(value):
                    # If the value is a list, then we assume it is a
                    # path list, because that's a pretty common list-like
                    # value to stick in an environment variable:
                    value = flatten(value)
                    ENV[key] = string.join(map(str, value), os.pathsep)
                else:
                    # If it isn't a string or a list, then we just coerce
                    # it to a string, which is the proper way to handle
                    # Dir and File instances and will produce something
                    # reasonable for just about everything else:
                    ENV[key] = str(value)

        cmd_list = env.subst_list(self.cmd_list, 0, target,
                                  map(rfile, source))

        # Use len() to filter out any "command" that's zero-length.
        for cmd_line in filter(len, cmd_list):
            # Escape the command line for the interpreter we are using.
            cmd_line = escape_list(cmd_line, escape)
            result = spawn(shell, escape, cmd_line[0], cmd_line, ENV)
            if result:
                return result
        return 0
Ejemplo n.º 5
0
    def execute(self, target, source, env):
        """Execute a command action.

        This will handle lists of commands as well as individual commands,
        because construction variable substitution may turn a single
        "command" into a list.  This means that this class can actually
        handle lists of commands, even though that's not how we use it
        externally.
        """
        from SCons.Subst import escape_list
        from SCons.Util import is_String, is_List, flatten

        try:
            shell = env['SHELL']
        except KeyError:
            raise SCons.Errors.UserError('Missing SHELL construction variable.')

        try:
            spawn = env['SPAWN']
        except KeyError:
            raise SCons.Errors.UserError('Missing SPAWN construction variable.')

        escape = env.get('ESCAPE', lambda x: x)

        try:
            ENV = env['ENV']
        except KeyError:
            global default_ENV
            if not default_ENV:
                import SCons.Environment
                default_ENV = SCons.Environment.Environment()['ENV']
            ENV = default_ENV

        # Ensure that the ENV values are all strings:
        for key, value in ENV.items():
            if not is_String(value):
                if is_List(value):
                    # If the value is a list, then we assume it is a
                    # path list, because that's a pretty common list-like
                    # value to stick in an environment variable:
                    value = flatten(value)
                    ENV[key] = string.join(map(str, value), os.pathsep)
                else:
                    # If it isn't a string or a list, then we just coerce
                    # it to a string, which is the proper way to handle
                    # Dir and File instances and will produce something
                    # reasonable for just about everything else:
                    ENV[key] = str(value)

        cmd_list, ignore, silent = self.process(target, map(rfile, source), env)

        # Use len() to filter out any "command" that's zero-length.
        for cmd_line in filter(len, cmd_list):
            # Escape the command line for the interpreter we are using.
            cmd_line = escape_list(cmd_line, escape)
            result = spawn(shell, escape, cmd_line[0], cmd_line, ENV)
            if not ignore and result:
                return result
        return 0
Ejemplo n.º 6
0
    def add_run_test_builds(self):
        # For everything that gets installed to build/unittests, add a rule for +basename
        # that runs the test from its original location.
        paths = (
            # Not including build/integration_tests since they need a server to run.
            os.path.join('build', 'unittests'),
            os.path.join('build', 'benchmark'),
        )

        def is_test_like(name):
            return any(name.startswith(path) for path in paths)

        tests = [
            flatten(build['inputs'])[0] for build in self.builds
            if build['rule'] == 'INSTALL'
            and is_test_like(flatten(build['outputs'])[0])
        ]
        self.builds += [
            dict(outputs='+' + os.path.basename(test),
                 inputs=test,
                 rule='RUN_TEST') for test in tests
        ]
Ejemplo n.º 7
0
def _install_group(env, pkg, uname, sources, *args, **kw):
    from SCons.Util import flatten, is_String
    from SConsGnuVariables.AmUniformNames import RSplitPrimaryName
    prefix, primary = RSplitPrimaryName(uname,**kw)
    if primary is None:
        raise ValueError('malformed uniform name: %s' % uname)
    try:
        handler = __standard_install_handlers[primary]
    except KeyError:
        # FIXME: default install handler?
        handler = None
    sources = env.arg2nodes(sources)
    sources = flatten(sources)
    return handler(env, pkg, (prefix,primary), sources, *args, **kw)
Ejemplo n.º 8
0
def Return(*vars, **kw):
    retval = []
    try:
        fvars = flatten(vars)
        for var in fvars:
            for v in var.split():
                retval.append(call_stack[-1].globals[v])
    except KeyError as x:
        raise SCons.Errors.UserError("Return of non-existent variable '%s'"%x)

    if len(retval) == 1:
        call_stack[-1].retval = retval[0]
    else:
        call_stack[-1].retval = tuple(retval)

    stop = kw.get('stop', True)

    if stop:
        raise SConscriptReturn
Ejemplo n.º 9
0
 def test_dictionary_values(self):
     """Test flattening the dictionary values"""
     items = {"a": 1, "b": 2, "c": 3}
     result = flatten(items.values())
     self.assertEqual(sorted(result), [1, 2, 3])
Ejemplo n.º 10
0
 def test_scalar(self):
     """Test flattening a scalar"""
     result = flatten('xyz')
     self.assertEqual(result, ['xyz'], result)