Setup benchbuild inside a container.

    This will query a for an existing installation of benchbuild and
    try to upgrade it to the latest version, if possible.
436132
def setup_benchbuild():
    
    LOG.debug("Setting up Benchbuild...")

    venv_dir = local.path("/benchbuild")
    prefixes = CFG["container"]["prefixes"].value
    prefixes.append(venv_dir)
    CFG["container"]["prefixes"] = prefixes

    src_dir = str(CFG["source_dir"])
    have_src = src_dir is not None
    if have_src:
        __mount_source(src_dir)

    benchbuild = find_benchbuild()
    if benchbuild and not requires_update(benchbuild):
        if have_src:
            __upgrade_from_source(venv_dir, with_deps=False)
        return

    setup_virtualenv(venv_dir)
    if have_src:
        __upgrade_from_source(venv_dir)
    else:
        __upgrade_from_pip(venv_dir)
1370888
def upgrade_setuptools():
    
    # Note - I tried including the higher version in
    # setup_requires, but was still able to trigger
    # the bug. - stu.axon
    global MIN_SETUPTOOLS
    r = None
    try:
        r = pkg_resources.require(["setuptools"])[0]
    except DistributionNotFound:
        # ok, setuptools will be installed later
        return

    if StrictVersion(r.version) >= StrictVersion(MIN_SETUPTOOLS):
        return
    else:
        print("Upgrading setuptools...")
        subprocess.call("%s -mpip install 'setuptools>=%s'" % (sys.executable, MIN_SETUPTOOLS), shell=True)
32832
def build(self, mode='debug'):
    
    self.ensure_cache_folder()
    ref = {
      'debug': 'assembleDebug',
      'release': 'assembleRelease'
    }
    cmd = [
      './gradlew',
      ref.get(mode, mode),
      '--gradle-user-home',
      self.cache_folder 
    ]
    self.run_cmd(cmd, 'build')
1348327
def build_from_dir(dir)
      image(::Docker::Image.build_from_dir(dir, &build_block))
      add_repository_tag
    rescue ::Docker::Error::DockerError => e
      DockerExceptionParser.new(e)
    end
210831
def create_build_context(image, inputs, wdir):
    
    assert os.path.isabs(wdir)

    dockerlines = ["FROM %s" % image,
                    "RUN mkdir -p %s" % wdir]
    build_context = {}

    # This loop creates a Build Context for building the provisioned image
    # We create a tar archive to be added to the root of the image filesystem
    if inputs:
        dockerlines.append('COPY root /')
        for ifile, (path, obj) in enumerate(inputs.items()):
            if not os.path.isabs(path):
                path = os.path.join(wdir, path)
            assert path[0] == '/'
            build_context['root' + path] = obj

    dockerstring = '\n'.join(dockerlines)
    build_context['Dockerfile'] = pyccc.BytesContainer(dockerstring.encode('utf-8'))
    return build_context
341068
protected InstallRequest buildInstallRequest(MemberState member) {
    Snapshot snapshot = context.getSnapshotStore().currentSnapshot();
    if (member.getNextSnapshotIndex() != snapshot.index()) {
      member.setNextSnapshotIndex(snapshot.index()).setNextSnapshotOffset(0);
    }

    InstallRequest request;
    synchronized (snapshot) {
      // Open a new snapshot reader.
      try (SnapshotReader reader = snapshot.reader()) {
        // Skip to the next batch of bytes according to the snapshot chunk size and current offset.
        reader.skip(member.getNextSnapshotOffset() * MAX_BATCH_SIZE);
        byte[] data = new byte[Math.min(MAX_BATCH_SIZE, (int) reader.remaining())];
        reader.read(data);

        // Create the install request, indicating whether this is the last chunk of data based on the number
        // of bytes remaining in the buffer.
        ServerMember leader = context.getLeader();
        request = InstallRequest.builder()
          .withTerm(context.getTerm())
          .withLeader(leader != null ? leader.id() : 0)
          .withIndex(member.getNextSnapshotIndex())
          .withOffset(member.getNextSnapshotOffset())
          .withData(data)
          .withComplete(!reader.hasRemaining())
          .build();
      }
    }

    return request;
  }
555069
def add_dep(self, ):
        
        i = self.dep_tablev.currentIndex()
        item = i.internalPointer()
        if item:
            dep = item.internal_data()
            dep.projects.add(self._project)
            self.deps.append(dep)
            item.set_parent(None)
362167
public function build(ContainerBuilder $container)
    {
        parent::build($container);

        /*
         * Adds compiler passes.
         */
        foreach ($this->getCompilerPasses() as $compilerPass) {
            $container->addCompilerPass($compilerPass);
        }
    }
993412
def install_frontend(instance='default', forcereload=False, forcerebuild=False,
                     forcecopy=True, install=True, development=False, build_type='dist'):
    """"""

    hfoslog("Updating frontend components", emitter='BUILDER')
    components = {}
    loadable_components = {}
    # TODO: Fix this up, it is probably not a sane way to get at the real root
    if development:
        frontendroot = os.path.abspath(os.path.dirname(os.path.realpath(
            __file__)) + "../../../frontend")
    else:
        frontendroot = '/opt/hfos/frontend'
    frontendtarget = os.path.join('/var/lib/hfos', instance, 'frontend')

    if install:
        cmdline = ["npm", "install"]

        hfoslog("Running", cmdline, lvl=verbose,
                emitter='BUILDER')
        npminstall = Popen(cmdline, cwd=frontendroot)
        out, err = npminstall.communicate()

        npminstall.wait()

        hfoslog("Frontend dependency installing done: ", out,
                err, lvl=debug, emitter='BUILDER')

    if True:  # try:
        from pkg_resources import iter_entry_points

        entry_point_tuple = (
            iter_entry_points(group='hfos.base', name=None),
            iter_entry_points(group='hfos.sails', name=None),
            iter_entry_points(group='hfos.components', name=None)
        )

        for iterator in entry_point_tuple:
            for entry_point in iterator:
                try:
                    name = entry_point.name
                    location = entry_point.dist.location
                    loaded = entry_point.load()

                    hfoslog("Entry point: ", entry_point,
                            name,
                            entry_point.resolve().__module__, lvl=debug,
                            emitter='BUILDER')
                    component_name = entry_point.resolve().__module__.split('.')[1]

                    hfoslog("Loaded: ", loaded, lvl=verbose, emitter='BUILDER')
                    comp = {
                        'location': location,
                        'version': str(entry_point.dist.parsed_version),
                        'description': loaded.__doc__
                    }

                    frontend = os.path.join(location, 'frontend')
                    hfoslog("Checking component frontend parts: ",
                            frontend, lvl=verbose, emitter='BUILDER')
                    if os.path.isdir(
                            frontend) and frontend != frontendroot:
                        comp['frontend'] = frontend
                    else:
                        hfoslog("Component without frontend "
                                "directory:", comp, lvl=debug,
                                emitter='BUILDER')

                    components[component_name] = comp
                    loadable_components[component_name] = loaded

                    hfoslog("Loaded component:", comp, lvl=verbose,
                            emitter='BUILDER')

                except Exception as e:
                    hfoslog("Could not inspect entrypoint: ", e,
                            type(e), entry_point, iterator, lvl=error,
                            exc=True, emitter='BUILDER')

    # except Exception as e:
    #    hfoslog("Error: ", e, type(e), lvl=error, exc=True, emitter='BUILDER')
    #    return

    hfoslog('Components after lookup:', sorted(list(components.keys())), emitter='BUILDER')

    def _update_frontends(install=True):
        hfoslog("Checking unique frontend locations: ",
                loadable_components, lvl=debug, emitter='BUILDER')

        importlines = []
        modules = []

        for name, component in components.items():
            if 'frontend' in component:
                origin = component['frontend']

                target = os.path.join(frontendroot, 'src', 'components',
                                      name)
                target = os.path.normpath(target)

                if install:
                    reqfile = os.path.join(origin, 'requirements.txt')

                    if os.path.exists(reqfile):
                        # TODO: Speed this up by collecting deps first then doing one single install call
                        hfoslog("Installing package dependencies", lvl=debug,
                                emitter='BUILDER')
                        with open(reqfile, 'r') as f:
                            cmdline = ["npm", "install"]
                            for line in f.readlines():
                                cmdline.append(line.replace("\n", ""))

                            hfoslog("Running", cmdline, lvl=verbose,
                                    emitter='BUILDER')
                            npminstall = Popen(cmdline, cwd=frontendroot)
                            out, err = npminstall.communicate()

                            npminstall.wait()

                            hfoslog("Frontend installing done: ", out,
                                    err, lvl=debug, emitter='BUILDER')

                # if target in ('/', '/boot', '/usr', '/home', '/root',
                # '/var'):
                #    hfoslog("Unsafe frontend deletion target path, "
                #            "NOT proceeding! ", target, lvl=critical,
                #            emitter='BUILDER')

                hfoslog("Copying:", origin, target, lvl=debug,
                        emitter='BUILDER')

                copytree(origin, target)

                for modulefilename in glob(target + '/*.module.js'):
                    modulename = os.path.basename(modulefilename).split(
                        ".module.js")[0]
                    line = u"import {s} from './components/{p}/{" \
                           u"s}.module';\nmodules.push({s});\n".format(
                        s=modulename, p=name)
                    if modulename not in modules:
                        importlines += line
                        modules.append(modulename)
            else:
                hfoslog("Module without frontend:", name, component,
                        lvl=debug, emitter='BUILDER')

        with open(os.path.join(frontendroot, 'src', 'main.tpl.js'),
                  "r") as f:
            main = "".join(f.readlines())

        parts = main.split("/* COMPONENT SECTION */")
        if len(parts) != 3:
            hfoslog("Frontend loader seems damaged! Please check!",
                    lvl=critical, emitter='BUILDER')
            return

        try:
            with open(os.path.join(frontendroot, 'src', 'main.js'),
                      "w") as f:
                f.write(parts[0])
                f.write("/* COMPONENT SECTION:BEGIN */\n")
                for line in importlines:
                    f.write(line)
                f.write("/* COMPONENT SECTION:END */\n")
                f.write(parts[2])
        except Exception as e:
            hfoslog("Error during frontend package info writing. Check "
                    "permissions! ", e, lvl=error, emitter='BUILDER')

    def _rebuild_frontend():
        hfoslog("Starting frontend build.", lvl=warn, emitter='BUILDER')

        npmbuild = Popen(["npm", "run", build_type], cwd=frontendroot)
        out, err = npmbuild.communicate()
        try:
            npmbuild.wait()
        except Exception as e:
            hfoslog("Error during frontend build", e, type(e),
                    exc=True, lvl=error, emitter='BUILDER')
            return

        hfoslog("Frontend build done: ", out, err, lvl=debug, emitter='BUILDER')

        copytree(os.path.join(frontendroot, build_type),
                 frontendtarget, hardlink=False)
        copytree(os.path.join(frontendroot, 'assets'),
                 os.path.join(frontendtarget, 'assets'),
                 hardlink=False)

        hfoslog("Frontend deployed", emitter='BUILDER')

    hfoslog("Checking component frontend bits in ", frontendroot,
            lvl=verbose, emitter='BUILDER')

    _update_frontends(install=install)
    if forcerebuild:
        _rebuild_frontend()

    hfoslog("Done: Install Frontend", emitter='BUILDER')
1052934
def install(self):
        
        logger.debug("")

        # If we're already installed, don't do anything.
        if self.installed:
            self.pr_info("pkg {} is already installed. Perhaps you want to update it?",
                    self.name)
            return

        self.clone()
        self.install_update_deps()

        logger.debug("Checking for install script")

        inst = os.path.join(self.repo_dir, '_upkg', 'install')
        if os.path.exists(inst):
            cwd = os.getcwd()
            logger.debug("chdir to %s", os.path.join(self.repo_dir, '_upkg'))
            logger.debug("install script is %s", inst)
            self.pr_info("Running install script at {}", inst)
            logger.debug("runnin script %s", inst)
            # We use subprocess instead of the sh module due to problems with
            # runing shell scripts with sh
            os.chdir(os.path.join(self.repo_dir, '_upkg'))
            subprocess.check_call(inst, shell=True)
            os.chdir(cwd)
            self.pr_pass("install script finished")
279955
def in_builddir(sub='.'):
    
    from functools import wraps

    def wrap_in_builddir(func):
        """Wrap the function for the new build directory."""

        @wraps(func)
        def wrap_in_builddir_func(self, *args, **kwargs):
            """The actual function inside the wrapper for the new builddir."""
            p = local.path(self.builddir) / sub
            if not p.exists():
                LOG.error("%s does not exist.", p)

            if p == local.cwd:
                LOG.debug("CWD already is %s", p)
                return func(self, *args, *kwargs)
            with local.cwd(p):
                return func(self, *args, **kwargs)

        return wrap_in_builddir_func

    return wrap_in_builddir
691669
def build(self, construct):
        
        if lib.EnvBuild(self._env, construct.encode()) != 1:
            raise CLIPSError(self._env)
208373
def _build_save_container(platform, registry, load_cache) -> Optional[str]:
    
    docker_tag = build_util.get_docker_tag(platform=platform, registry=registry)

    # Preload cache
    if load_cache:
        load_docker_cache(registry=registry, docker_tag=docker_tag)

    # Start building
    logging.debug('Building %s as %s', platform, docker_tag)
    try:
        # Increase the number of retries for building the cache.
        image_id = build_util.build_docker(docker_binary='docker', platform=platform, registry=registry, num_retries=10, no_cache=False)
        logging.info('Built %s as %s', docker_tag, image_id)

        # Push cache to registry
        _upload_image(registry=registry, docker_tag=docker_tag, image_id=image_id)
        return None
    except Exception:
        logging.exception('Unexpected exception during build of %s', docker_tag)
        return platform
1056904
def build(args):
    

    # Do some sleuthing work to find scons if it's not installed into an importable
    # place, as it is usually not.
    scons_path = "Error"
    try:
        scons_path = resource_path('scons-local-{}'.format(SCONS_VERSION), expect='folder')
        sys.path.insert(0, scons_path)
        import SCons.Script
    except ImportError:
        raise BuildError("Couldn't find internal scons packaged w/ iotile-build. This is a bug that should be reported",
                         scons_path=scons_path)

    site_path = resource_path('site_scons', expect='folder')

    all_args = ['iotile', '--site-dir=%s' % site_path, '-Q']
    sys.argv = all_args + list(args)
    SCons.Script.main()
427957
def newBuild(self, requests):
        
        b = self.buildClass(requests)
        b.useProgress = self.useProgress
        b.workdir = self.workdir
        b.setStepFactories(self.steps)
        return b
706888
protected function askBuildVersion()
    {
        $last_version = $this->gitLatestVersionTag();
        $next_version = $this->incrementVersion($last_version);

        $question = (new Question("Set build version [{$next_version}]: ", $next_version))
            ->setValidator(function ($input_version) use ($last_version) {
                $input_version = trim($input_version);

                if (version_compare($input_version, $last_version, '==')) {
                    throw new \RuntimeException(
                        'Build version has already been used.'
                    );
                }

                if (!$this->isVersionNumeric($input_version)) {
                    throw new \RuntimeException(
                        'Build version is not numeric.'
                    );
                }

                return $input_version;
            });

        return $this->doAsk($question);
    }
1328631
def build(self, _resource, _cache=True, updatecontent=True, **kwargs):
        
        result = None

        if _cache and _resource in self._schemasbyresource:
            result = self._schemasbyresource[_resource]

        else:
            for builder in self._builders.values():
                try:
                    result = builder.build(_resource=_resource, **kwargs)

                except Exception:
                    pass

                else:
                    break

            if result is None:
                raise ValueError('No builder found for {0}'.format(_resource))

            if _cache:
                self._schemasbyresource[_resource] = result

            if updatecontent:
                from ..utils import updatecontent
                updatecontent(result, updateparents=False)

        return result