Write a tar stream of the build context to the provided buffer

    Args:
        build_context (Mapping[str, pyccc.FileReferenceBase]): dict mapping filenames to file references
        buffer (io.BytesIO): writable binary mode buffer
768389
def make_tar_stream(build_context, buffer):
    
    tf = tarfile.TarFile(fileobj=buffer, mode='w')
    for context_path, fileobj in build_context.items():
        if getattr(fileobj, 'localpath', None) is not None:
            tf.add(fileobj.localpath, arcname=context_path)
        else:
            tar_add_bytes(tf, context_path, fileobj.read('rb'))
    tf.close()
1244461
def cpp_lib_builder(build_context, target):
    """"""
    yprint(build_context.conf, 'Build CppLib', target)
    workspace_dir = build_context.get_workspace('CppLib', target.name)
    workspace_src_dir = join(workspace_dir, 'src')
    rmtree(workspace_src_dir)
    link_cpp_artifacts(build_context, target, workspace_src_dir, False)
    buildenv_workspace = build_context.conf.host_to_buildenv_path(
        workspace_src_dir)
    objects = compile_cc(
        build_context, target.compiler_config, target.props.in_buildenv,
        get_source_files(target, build_context), workspace_src_dir,
        buildenv_workspace, target.props.cmd_env)
    for obj_file in objects:
        target.artifacts.add(AT.object, obj_file)
92452
def dump_to_stream(self, cnf, stream, **opts):
        
        tree = container_to_etree(cnf, **opts)
        etree_write(tree, stream)
516239
def build_extension(self, ext):
        
        try:
            build_ext.build_ext.build_extension(self, ext)
        except (
            distutils.errors.CCompilerError,
            distutils.errors.DistutilsExecError,
            distutils.errors.DistutilsPlatformError,
            ValueError,
        ):
            raise BuildFailed()
78803
def _build_tarball(src_repo) -> str:
    
    run = partial(subprocess.run, cwd=src_repo, check=True)
    run(['git', 'clean', '-xdff'])
    src_repo = Path(src_repo)
    if os.path.exists(src_repo / 'es' / 'upstream'):
        run(['git', 'submodule', 'update', '--init', '--', 'es/upstream'])
    run(['./gradlew', '--no-daemon', 'clean', 'distTar'])
    distributions = Path(src_repo) / 'app' / 'build' / 'distributions'
    return next(distributions.glob('crate-*.tar.gz'))
518464
def build(self, context, variant, build_path, install_path, install=False,
              build_type=BuildType.local):
        
        ret = {}

        if self.write_build_scripts:
            # write out the script that places the user in a build env, where
            # they can run bez directly themselves.
            build_env_script = os.path.join(build_path, "build-env")
            create_forwarding_script(build_env_script,
                                     module=("build_system", "custom"),
                                     func_name="_FWD__spawn_build_shell",
                                     working_dir=self.working_dir,
                                     build_path=build_path,
                                     variant_index=variant.index,
                                     install=install,
                                     install_path=install_path)

            ret["success"] = True
            ret["build_env_script"] = build_env_script
            return ret

        # get build command
        command = self.package.build_command

        # False just means no build command
        if command is False:
            ret["success"] = True
            return ret

        def expand(txt):
            root = self.package.root
            install_ = "install" if install else ''
            return txt.format(root=root, install=install_).strip()

        if isinstance(command, basestring):
            if self.build_args:
                command = command + ' ' + ' '.join(map(quote, self.build_args))

            command = expand(command)
            cmd_str = command
        else:  # list
            command = command + self.build_args
            command = map(expand, command)
            cmd_str = ' '.join(map(quote, command))

        if self.verbose:
            pr = Printer(sys.stdout)
            pr("Running build command: %s" % cmd_str, heading)

        # run the build command
        def _callback(executor):
            self._add_build_actions(executor,
                                    context=context,
                                    package=self.package,
                                    variant=variant,
                                    build_type=build_type,
                                    install=install,
                                    build_path=build_path,
                                    install_path=install_path)

            if self.opts:
                # write args defined in ./parse_build_args.py out as env vars
                extra_args = getattr(self.opts.parser, "_rezbuild_extra_args", [])

                for key, value in vars(self.opts).iteritems():
                    if key in extra_args:
                        varname = "__PARSE_ARG_%s" % key.upper()

                        # do some value conversions
                        if isinstance(value, bool):
                            value = 1 if value else 0
                        elif isinstance(value, (list, tuple)):
                            value = map(str, value)
                            value = map(quote, value)
                            value = ' '.join(value)

                        executor.env[varname] = value

        retcode, _, _ = context.execute_shell(command=command,
                                              block=True,
                                              cwd=build_path,
                                              actions_callback=_callback)
        ret["success"] = (not retcode)
        return ret
369515
def build_context(logical_path = 'application.js', options = {})
      pathname = options[:pathname] || Pathname.new('assets').join(logical_path).expand_path
      env      = options[:env] || machined.assets

      env.context_class.new env, logical_path, pathname
    end
103624
def create_context(self, message_queue, task_id):
        
        params = (self.settings.dest_directory, self.file_url.json_data, self.seek_amt, self.bytes_to_read)
        return DownloadContext(self.settings, params, message_queue, task_id)
44350
def write_file(self, target_path, html):
        
        logger.debug("Building to {}{}".format(self.fs_name, target_path))
        with self.fs.open(smart_text(target_path), 'wb') as outfile:
            outfile.write(six.binary_type(html))
            outfile.close()
496474
def dump_compile(codeobject, filename, timestamp, magic):
    
    # Atomically write the pyc/pyo file.  Issue #13146.
    # id() is used to generate a pseudo-random filename.
    path_tmp = '%s.%s' % (filename, id(filename))
    fc = None
    try:
        fc = open(path_tmp, 'wb')
        if PYTHON3:
            fc.write(bytes([0, 0, 0, 0]))
        else:
            fc.write('\0\0\0\0')
        wr_long(fc, timestamp)
        marshal.dump(codeobject, fc)
        fc.flush()
        fc.seek(0, 0)
        fc.write(magic)
        fc.close()
        os.rename(path_tmp, filename)
    except OSError:
        try:
            os.unlink(path_tmp)
        except OSError:
            pass
        raise
    finally:
        if fc: fc.close()
561474
def compute_hash(self, build_context):
        
        m = md5()
        m.update(self.json(build_context).encode('utf8'))
        self._hash = m.hexdigest()
        m = md5()
        m.update(self.test_json(build_context).encode('utf8'))
        self._test_hash = m.hexdigest()
110070
protected function _buildFOpenStreamContext()
    {
        # Set the headers required to work with fopen
        $headers =  $this->_generateProxyRequestHeaders(TRUE);
        $headers.= 'Cookie: ' . $this->_buildProxyRequestCookieString();

        # Create the stream context
        $stream_context = array (
            'header'        => $headers,
            'user_agent'    => $this->_requestUserAgent
        );

        # Figure out what kind of request we're making, and what to fill it with
        $stream_context['method'] = $this->_requestMethod;

        if($this->_requestMethod === 'POST' ||
           $this->_requestMethod === 'PUT')
        {
            $stream_context['content'] = $this->_requestBody;
        }

        return stream_context_create(array('http' => $stream_context));
    }
477799
def register_with_context(self, myname, context):
        

        if self.context is not None:
            raise Exception("attempted to register BuildTarget with multiple "
                            "BuildContexts")

        context.register_task(myname, self)
        self._name = myname
        self.context = context

        for key in self.data_dependencies:
            if type(self.data_dependencies[key]) is DeferredDependency:
                self.data_dependencies[key].parent  = myname
                self.data_dependencies[key].context = context
                for tnmame in self.data_dependencies[key].target_names:
                    context.register_dependency(tnmame, myname)
1083479
def build_cpp(build_context, target, compiler_config, workspace_dir):
    """"""
    rmtree(workspace_dir)
    binary = join(*split(target.name))
    objects = link_cpp_artifacts(build_context, target, workspace_dir, True)
    buildenv_workspace = build_context.conf.host_to_buildenv_path(
        workspace_dir)
    objects.extend(compile_cc(
        build_context, compiler_config, target.props.in_buildenv,
        get_source_files(target, build_context), workspace_dir,
        buildenv_workspace, target.props.cmd_env))
    bin_file = join(buildenv_workspace, binary)
    link_cmd = (
        [compiler_config.linker, '-o', bin_file] +
        objects + compiler_config.link_flags)
    build_context.run_in_buildenv(
        target.props.in_buildenv, link_cmd, target.props.cmd_env)
    target.artifacts.add(AT.binary, relpath(join(workspace_dir, binary),
                         build_context.conf.project_root), binary)
887910
public final void append( StringBuilder buffer, Map<String, String> configuration, Tree<Appender> context )
    {
        // Create context if needed
        Tree<Appender> currentContext = context == null ? new Tree<Appender>( this ) : context.addLeaf( this );

        // Check recursion
        if ( currentContext.inAncestors( this ) )
        {
            // For the moment just log a warning, and stop the resolving by appending original chunk
            buffer.append( chunk );

            logger.warning( format( "Recursion detected within variable resolving:%n%s", currentContext.getRoot() ) );
        }
        // Process real appending
        else
        {
            doAppend( buffer, configuration, currentContext );
            // Dump some info on resolution if this is a root appender
            if ( currentContext.isRoot() && logger.isLoggable( FINEST ) )
            {
                logger.finest( format( "Resolving variables:%n%s", currentContext ) );
            }
        }
    }
254307
def context_export(zap_helper, name, file_path):
    """"""
    with zap_error_handler():
        result = zap_helper.zap.context.export_context(name, file_path)

        if result != 'OK':
            raise ZAPError('Exporting context to file failed: {}'.format(result))

    console.info('Exported context {0} to {1}'.format(name, file_path))
1142078
def build(self, obj, context=None) -> bytes:
        
        stream = BytesIO()
        self.build_stream(obj, stream, context)
        return stream.getvalue()