Пример #1
0
def get_base_env(*args, **kwargs):
    """Initialize and return a base construction environment.

    All args received are passed transparently to SCons Environment init.
    """
    # Initialize new construction environment
    env = Environment(*args, **kwargs)  # pylint: disable=undefined-variable
    # If a flavor is activated in the external environment - use it
    if 'BUILD_FLAVOR' in os.environ:
        active_flavor = os.environ['BUILD_FLAVOR']
        if not active_flavor in flavors():
            raise StopError('%s (from env) is not a known flavor.' %
                            (active_flavor))
        sprint('Using active flavor "%s" from your environment', active_flavor)
        env.flavors = [active_flavor]
    else:
        # If specific flavor target specified, skip processing other flavors
        # Otherwise, include all known flavors
        env.flavors = (
            set(flavors()).intersection(COMMAND_LINE_TARGETS)  # pylint: disable=undefined-variable
            or flavors())
    # Perform base construction environment customizations from site_config
    if '_common' in ENV_OVERRIDES:
        env.Replace(**ENV_OVERRIDES['_common'])
    if '_common' in ENV_EXTENSIONS:
        env.Append(**ENV_EXTENSIONS['_common'])
    return env
Пример #2
0
def get_base_env(*args, **kwargs):
    """Initialize and return a base construction environment.

    All args received are passed transparently to SCons Environment init.
    """
    # Initialize new construction environment
    env = Environment(*args, **kwargs)  # pylint: disable=undefined-variable
    # If a flavor is activated in the external environment - use it
    if 'BUILD_FLAVOR' in os.environ:
        active_flavor = os.environ['BUILD_FLAVOR']
        if not active_flavor in flavors():
            raise StopError('%s (from env) is not a known flavor.' %
                            (active_flavor))
        sprint('Using active flavor "%s" from your environment', active_flavor)
        env.flavors = [active_flavor]
    else:
        # If specific flavor target specified, skip processing other flavors
        # Otherwise, include all known flavors
        env.flavors = (set(flavors()).intersection(COMMAND_LINE_TARGETS)  # pylint: disable=undefined-variable
                       or flavors())
    # Perform base construction environment customizations from site_config
    if '_common' in ENV_OVERRIDES:
        env.Replace(**ENV_OVERRIDES['_common'])
    if '_common' in ENV_EXTENSIONS:
        env.Append(**ENV_EXTENSIONS['_common'])
    return env
Пример #3
0
    def build(self):
        """Build flavor using three-pass strategy."""
        # First pass - compile protobuffers
        for module in modules():
            # Verify the SConscript file exists
            sconscript_path = os.path.join(module, 'SConscript')
            if not os.path.isfile(sconscript_path):
                raise StopError('Missing SConscript file for module %s.' %
                                (module))
            sprint('|- First pass: Reading module %s ...', module)
            shortcuts = dict(
                Lib=nop,
                StaticLib=nop,
                SharedLib=nop,
                Proto=self._proto_wrapper(),
                Prog=nop,
            )
            self._env.SConscript(sconscript_path,
                                 variant_dir=os.path.join(
                                     '$BUILDROOT', module),
                                 exports=shortcuts)

        #Second pass over all modules - process and collect library targets
        for module in modules():
            shortcuts = dict(
                Lib=self._lib_wrapper(self._env.Library, module),
                StaticLib=self._lib_wrapper(self._env.StaticLibrary, module),
                SharedLib=self._lib_wrapper(self._env.SharedLibrary, module),
                Proto=nop,
                Prog=nop,
            )
            self._env.SConscript(os.path.join(module, 'SConscript'),
                                 variant_dir=os.path.join(
                                     '$BUILDROOT', module),
                                 exports=shortcuts)

        # Third pass over all modules - process program targets
        shortcuts = dict()
        for nop_shortcut in ('Lib', 'StaticLib', 'SharedLib', 'Proto'):
            shortcuts[nop_shortcut] = nop

        for module in modules():
            sprint('|- Second pass: Reading module %s ...', module)
            shortcuts['Prog'] = self._prog_wrapper(module)
            self._env.SConscript(os.path.join(module, 'SConscript'),
                                 variant_dir=os.path.join(
                                     '$BUILDROOT', module),
                                 exports=shortcuts)

        # Add install targets for programs from all modules
        for module, prog_nodes in self._progs.iteritems():
            for prog in prog_nodes:
                assert isinstance(prog, Node.FS.File)
                # If module is hierarchical, replace pathseps with periods
                bin_name = path_to_key('%s' % (prog.name))
                self._env.InstallAs(os.path.join('$BINDIR', bin_name), prog)
        # Support using the flavor name as target name for its related targets
        self._env.Alias(self._flavor, '$BUILDROOT')
Пример #4
0
        def compile_proto(proto_sources, **kwargs):
            """Customized Protoc builder.

            Uses Protoc builder to compile proto files specified in
             `proto_sources`.

            Optionally pass `cpp=False` to disable C++ code generation.
            Optionally, pass `python=True` to enable Python code generation.

            Optionally pass `PROTOPATH=[...]` to override default list of
             proto search paths (default is [$BUILDROOT]).
            Optionally pass `PROTOCPPOUT=path` and `PROTOPYOUT=path` to
             override default output path for C++ / Python outputs
             (respectively), when output for this language is enabled.
             Default output paths are $BUILDROOT (so expect output files
             in the module directory under the flavor build dir).
            Tip: Don't mess with these...
            """
            if not hasattr(self._env, 'Protoc'):
                raise StopError('Protoc tool not installed.')
            # use user-specified value, or set default
            kwargs.setdefault('PROTOPATH', ['$BUILDROOT'])
            any_output = False
            for gen_flag_name, default_gen_flag, path_name, default_path in [
                ('cpp', True, 'PROTOCPPOUT', '$BUILDROOT'),
                ('python', True, 'PROTOPYOUT', '$BUILDROOT'),
            ]:
                gen_output_flag = kwargs.pop(gen_flag_name, default_gen_flag)
                if gen_output_flag:
                    any_output = True
                    # use user-specified value, or set default
                    kwargs.setdefault(path_name, default_path)
                else:
                    kwargs[path_name] = ''
            # check that at least one output language is enabled
            if any_output:
                targets = self._env.Protoc([], proto_sources, **kwargs)
                for gen_node in targets:
                    gen_filename = os.path.basename(gen_node.path)
                    if gen_filename.endswith('.pb.cc'):
                        # Save generated .pb.cc sources in proto_cc dictionary
                        #  (without the ".pb.cc" suffix)
                        self._proto_cc[gen_filename[:-6]] = gen_node
            else:
                sprint('warning: Proto target with no output directives')
Пример #5
0
 def build(self):
     """Build flavor using two-pass strategy."""
     # First pass over all modules - process and collect library targets
     for module in modules():
         # get only the module name (not the path)
         moduleName = os.path.basename(os.path.normpath(module))
         # Verify the SConscript file exists
         sconscript_path = os.path.join(module, 'SConscript')
         if not os.path.isfile(sconscript_path):
             raise StopError('Missing SConscript file for module %s.' %
                             (module))
         sprint('|- First pass: Reading module %s ...', module)
         shortcuts = dict(
             Lib=self._lib_wrapper(self._env.Library, module),
             StaticLib=self._lib_wrapper(self._env.StaticLibrary, module),
             SharedLib=self._lib_wrapper(self._env.SharedLibrary, module),
             Prog=nop,
         )
         SCons.Script._SConscript.GlobalDict.update(shortcuts)  # pylint: disable=protected-access
         self._env.SConscript(sconscript_path,
                              variant_dir=os.path.join(
                                  '$BUILDROOT', moduleName))
     # Second pass over all modules - process program targets
     shortcuts = dict()
     for nop_shortcut in ('Lib', 'StaticLib', 'SharedLib'):
         shortcuts[nop_shortcut] = nop
     for module in modules():
         moduleName = os.path.basename(os.path.normpath(module))
         sprint('|- Second pass: Reading module %s ...', module)
         shortcuts['Prog'] = self._prog_wrapper(module)
         SCons.Script._SConscript.GlobalDict.update(shortcuts)  # pylint: disable=protected-access
         self._env.SConscript(os.path.join(module, 'SConscript'),
                              variant_dir=os.path.join(
                                  '$BUILDROOT', moduleName))
     # Add install targets for programs from all modules
     for module, prog_nodes in self._progs.iteritems():
         moduleName = os.path.basename(os.path.normpath(module))
         for prog in prog_nodes:
             assert isinstance(prog, Node.FS.File)
             # If module is hierarchical, replace pathseps with periods
             bin_name = path_to_key('%s.%s' % (moduleName, prog.name))
             self._env.InstallAs(os.path.join('$BINDIR', bin_name), prog)
Пример #6
0
 def build(self):
     """Build flavor using two-pass strategy."""
     # First pass over all modules - process and collect library targets
     for module in modules():
         # Verify the SConscript file exists
         sconscript_path = os.path.join(module, 'SConscript')
         if not os.path.isfile(sconscript_path):
             raise StopError('Missing SConscript file for module %s.' %
                             (module))
         sprint('|- First pass: Reading module %s ...', module)
         shortcuts = dict(
             Lib       = self._lib_wrapper(self._env.Library, module),
             StaticLib = self._lib_wrapper(self._env.StaticLibrary, module),
             SharedLib = self._lib_wrapper(self._env.SharedLibrary, module),
             Protoc    = self._env.Protoc,
             Prog      = nop,
         )
         SCons.Script._SConscript.GlobalDict.update(shortcuts)  # pylint: disable=protected-access
         self._env.SConscript(
             sconscript_path,
             variant_dir=os.path.join('$BUILDROOT', module))
     # Second pass over all modules - process program targets
     shortcuts = dict()
     for nop_shortcut in ('Lib', 'StaticLib', 'SharedLib', 'Protoc'):
         shortcuts[nop_shortcut] = nop
     for module in modules():
         sprint('|- Second pass: Reading module %s ...', module)
         shortcuts['Prog'] = self._prog_wrapper(module)
         SCons.Script._SConscript.GlobalDict.update(shortcuts)  # pylint: disable=protected-access
         self._env.SConscript(
             os.path.join(module, 'SConscript'),
             variant_dir=os.path.join('$BUILDROOT', module))
     # Add install targets for programs from all modules
     for module, prog_nodes in self._progs.iteritems():
         for prog in prog_nodes:
             assert isinstance(prog, Node.FS.File)
             # If module is hierarchical, replace pathseps with periods
             bin_name = path_to_key('%s.%s' % (module, prog.name))
             self._env.InstallAs(os.path.join('$BINDIR', bin_name), prog)
     # Support using the flavor name as target name for its related targets
     self._env.Alias(self._flavor, '$BUILDROOT')