def build()

in xar/xar_builder.py [0:0]


    def build(self, filename, squashfs_options=None):
        """
        Actually build the XAR. Freezes the XarBuilder if not already frozen.
        Writes the XAR to `filename`. Uses `xar_util.SquashfsOptions`
        `squashfs_options` to construct the XAR. Finally calls :func:`delete`.
        The XarBuilder is no longer usable after this call.
        """
        if squashfs_options is None:
            squashfs_options = xar_util.SquashfsOptions()
        if not self._frozen:
            self.freeze()
        xarfiles = {}
        base_name, xar_ext = os.path.splitext(filename)
        # Build the dependent XARs
        for ext, destination in self._partition_dest:
            ext_filename = base_name + ext + xar_ext
            with tempfile.NamedTemporaryFile(delete=False) as tf:
                xarfiles[ext] = (ext_filename, tf.name)
            self._build_staging_dir(
                destination.staging,
                xarfiles[ext][1],
                BORING_SHEBANG,
                {},
                squashfs_options,
            )
        # Build the main XAR
        with tempfile.NamedTemporaryFile(delete=False) as tf:
            tmp_xar = tf.name
        xar_header = self._build_xar_header(xarfiles)
        self._build_staging_dir(
            self._staging, tmp_xar, self._shebang, xar_header, squashfs_options
        )

        # Move the results into place
        shutil.move(tmp_xar, filename)
        for ext_filename, tmp_filename in xarfiles.values():
            shutil.move(tmp_filename, ext_filename)

        # Make the output executable if necessary
        if self._executable is not None:
            os.chmod(filename, 0o755)

        self.delete()