Example #1
0
    def process_module(self, module):
        """Delegate build to a module-level SConscript using the flavored env.

        @param  module  Directory of module

        @raises AssertionError if `module` does not contain SConscript file
        """
        # Verify the SConscript file exists
        sconscript_path = os.path.join(module, 'SConscript')
        assert os.path.isfile(sconscript_path)
        log_info('|- Reading module {} ...'.format(module))
        # Prepare shortcuts to export to SConscript
        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=self._prog_wrapper(module),
        )
        # Access a protected member of another namespace,
        # using an undocumented feature of SCons
        SCons.Script._SConscript.GlobalDict.update(shortcuts)  # pylint: disable=protected-access
        # Execute the SConscript file, with variant_dir set to the
        #  module dir under the project flavored build dir.
        self._env.SConscript(sconscript_path,
                             variant_dir=os.path.join('$BUILDROOT', module),
                             duplicate=0)
        # Add install targets for module
        # If module has hierarchical path, replace path-seps with periods
        bin_prefix = path_to_key(module)
        for prog in self._progs[module]:
            assert isinstance(prog, Node.FS.File)
            bin_name = '{}.{}'.format(bin_prefix, prog.name)
            self._env.InstallAs(os.path.join('$BINDIR', bin_name), prog)
Example #2
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')
Example #3
0
    def finishing_progs(self):
        # Create flashable images for programs from all modules
        for module, prog_nodes in self._progs.items():
            for prog_elf in prog_nodes:
                assert isinstance(prog_elf, Node.FS.File)
                prog_siz = self._env.SIZ(source=prog_elf)
                prog_lst = self._env.LST(source=prog_elf)
                prog_bin = self._env.BIN(source=prog_elf)
                prog_zbin = self._env.ZBIN(source=prog_bin)
                prog_img = self._env.IMG(source=prog_bin)
                prog_zimg = self._env.ZIMG(source=[prog_zbin, prog_bin])
                prog_fls = self._env.FLS(source=prog_img)
                # log_warn('siz : {}'.format(prog_siz[0]))
                # log_warn('lst : {}'.format(prog_lst[0]))
                # log_warn('bin : {}'.format(prog_bin[0]))
                # log_warn('zbin: {}'.format(prog_zbin[0]))
                # log_warn('img : {}'.format(prog_img[0]))
                # log_warn('zimg: {}'.format(prog_zimg[0]))
                # log_warn('fls : {}'.format(prog_fls[0]))

                flashable = self._env.InstallAs(
                    [
                        # os.path.join('$BINDIR', path_to_key('{}.{}'.format(
                        #     module, os.path.basename(prog_zimg[0].rstr())))),
                        os.path.join(
                            '$BINDIR',
                            path_to_key('{}.{}'.format(
                                module,
                                Flatten(prog_zimg)[0].name))),
                        os.path.join(
                            '$BINDIR',
                            path_to_key('{}.{}'.format(
                                module,
                                Flatten(prog_fls)[0].name))),
                    ],
                    [
                        prog_zimg,
                        prog_fls,
                    ])
                log_info('Flashable files {}'.format(
                    [f.rstr() for f in flashable]))
Example #4
0
 def install_progs(self):
     # [Ch11]Installing Files in Other Directories: the Install Builder
     # installing a file is still considered a type of file "build."
     # Add install targets for programs from all modules
     for module, prog_nodes in self._progs.items():
         for prog_elf in prog_nodes:
             assert isinstance(prog_elf, Node.FS.File)
             # If module is hierarchical, replace pathseps with periods
             bin_name = path_to_key('{}.{}'.format(module, prog_elf.name))
             install_dest = os.path.join('$BINDIR', bin_name)
             log_info('Install {} As {}'.format(prog_elf.rstr(),
                                                install_dest))
             installed_artifact = self._env.InstallAs(
                 os.path.join('$BINDIR', bin_name), prog_elf)
             log_warn('InstallAs: ' + installed_artifact[0].rstr())
Example #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)
Example #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')
Example #7
0
 def lib_key(cls, module, target_name):
     """Return unique identifier for target `target_name` in `module`"""
     return '%s%s%s' % (path_to_key(module), cls._key_sep,
                        path_to_key(target_name))
Example #8
0
 def lib_key(cls, module, target_name):
     """Return unique identifier for target `target_name` in `module`"""
     return '%s%s%s' % (path_to_key(module), cls._key_sep,
                        path_to_key(target_name))