Ejemplo n.º 1
0
        def symlink(self, src, dest):
            out = self.ensureDirFor(dest)

            # remove previous link or file
            try:
                os.remove(out)
            except OSError as e:
                if e.errno != errno.ENOENT:
                    raise
            if sys.platform != 'win32':
                os.symlink(src, out)
            else:
                # On Win32, use ctypes to create a hardlink
                rv = CreateHardLink(ensure_bytes(out), ensure_bytes(src), None)
                if rv == 0:
                    raise WinError()
Ejemplo n.º 2
0
def embed(cxx, preprocessorOption, cppflags, msgs, sources, c_out, js_out,
          namespace, env):
    objdir = os.getcwd()
    # Use relative pathnames to avoid path translation issues in WSL.
    combinedSources = "\n".join([msgs] + [
        '#include "%(s)s"' % {
            "s": mozpath.relpath(source, objdir)
        } for source in sources
    ])
    args = cppflags + ["-D%(k)s=%(v)s" % {"k": k, "v": env[k]} for k in env]
    preprocessed = preprocess(cxx, preprocessorOption, combinedSources, args)
    processed = "\n".join([
        line for line in preprocessed.splitlines()
        if (line.strip() and not line.startswith("#"))
    ])

    js_out.write(processed)
    import zlib

    compressed = zlib.compress(ensure_bytes(processed))
    data = ToCArray(compressed)
    c_out.write(
        HEADER_TEMPLATE % {
            "sources_type": "unsigned char",
            "sources_data": data,
            "sources_name": "compressedSources",
            "compressed_total_length": len(compressed),
            "raw_total_length": len(processed),
            "namespace": namespace,
        })
Ejemplo n.º 3
0
def embed(cxx, preprocessorOption, cppflags, msgs, sources, c_out, js_out,
          namespace, env):
    objdir = os.getcwd()
    # Use relative pathnames to avoid path translation issues in WSL.
    combinedSources = '\n'.join([msgs] + [
        '#include "%(s)s"' % {
            's': mozpath.relpath(source, objdir)
        } for source in sources
    ])
    args = cppflags + ['-D%(k)s=%(v)s' % {'k': k, 'v': env[k]} for k in env]
    preprocessed = preprocess(cxx, preprocessorOption, combinedSources, args)
    processed = '\n'.join([
        line for line in preprocessed.splitlines()
        if (line.strip() and not line.startswith('#'))
    ])

    js_out.write(processed)
    import zlib
    compressed = zlib.compress(ensure_bytes(processed))
    data = ToCArray(compressed)
    c_out.write(
        HEADER_TEMPLATE % {
            'sources_type': 'unsigned char',
            'sources_data': data,
            'sources_name': 'compressedSources',
            'compressed_total_length': len(compressed),
            'raw_total_length': len(processed),
            'namespace': namespace
        })
Ejemplo n.º 4
0
 def open(self):
     '''
     Return a file-like object allowing to read() the serialized content of
     the manifest.
     '''
     return BytesIO(
         ensure_bytes(''.join(
             '%s\n' % e.rebase(self._base)
             for e in chain(self._entries, self._interfaces))))
Ejemplo n.º 5
0
 def serialize(self):
     """
     Serialize the data structure according to the data structure definition
     from self.STRUCT.
     """
     serialized = struct.pack(b"<I", self.signature)
     sizes = dict((t, name) for name, t in six.iteritems(self.STRUCT)
                  if t not in JarStruct.TYPE_MAPPING)
     for name, t in six.iteritems(self.STRUCT):
         if t in JarStruct.TYPE_MAPPING:
             format, size = JarStruct.TYPE_MAPPING[t]
             if name in sizes:
                 value = len(self[sizes[name]])
             else:
                 value = self[name]
             serialized += struct.pack(b"<" + format, value)
         else:
             serialized += ensure_bytes(self[name])
     return serialized
Ejemplo n.º 6
0
def preprocess(cxx, preprocessorOption, source, args=[]):
    if not os.path.exists(cxx[0]):
        binary = cxx[0]
        cxx[0] = which(binary)
        if not cxx[0]:
            raise OSError(errno.ENOENT, "%s not found on PATH" % binary)

    # Clang seems to complain and not output anything if the extension of the
    # input is not something it recognizes, so just fake a .cpp here.
    tmpIn = "self-hosting-cpp-input.cpp"
    tmpOut = "self-hosting-preprocessed.pp"
    outputArg = shlex.split(preprocessorOption + tmpOut)

    with open(tmpIn, "wb") as input:
        input.write(ensure_bytes(source))
    print(" ".join(cxx + outputArg + args + [tmpIn]))
    result = subprocess.Popen(cxx + outputArg + args + [tmpIn]).wait()
    if result != 0:
        sys.exit(result)
    with open(tmpOut, "r") as output:
        processed = output.read()
    os.remove(tmpIn)
    os.remove(tmpOut)
    return processed
Ejemplo n.º 7
0
 def add(self, path):
     self.jar.add(path, ensure_bytes(path), compress=True)
Ejemplo n.º 8
0
 def key(self, entry):
     return memoryview(ensure_bytes(self._key(entry)))
Ejemplo n.º 9
0
    def write(self, content):
        '''Append the given content to this zip entry'''

        self._inner.write(ensure_bytes(content))
        return
Ejemplo n.º 10
0
def repackage_mar(topsrcdir,
                  package,
                  mar,
                  output,
                  mar_format="lzma",
                  arch=None,
                  mar_channel_id=None):
    if not zipfile.is_zipfile(package) and not tarfile.is_tarfile(package):
        raise Exception("Package file %s is not a valid .zip or .tar file." %
                        package)
    if arch and arch not in _BCJ_OPTIONS:
        raise Exception(
            "Unknown architecture {}, available architectures: {}".format(
                arch, _BCJ_OPTIONS.keys()))

    ensureParentDir(output)
    tmpdir = tempfile.mkdtemp()
    try:
        if tarfile.is_tarfile(package):
            z = tarfile.open(package)
            z.extractall(tmpdir)
            filelist = z.getnames()
            z.close()
        else:
            z = zipfile.ZipFile(package)
            z.extractall(tmpdir)
            filelist = z.namelist()
            z.close()

        toplevel_dirs = set([mozpath.split(f)[0] for f in filelist])
        excluded_stuff = set(
            [' ', '.background', '.DS_Store', '.VolumeIcon.icns'])
        toplevel_dirs = toplevel_dirs - excluded_stuff
        # Make sure the .zip file just contains a directory like 'firefox/' at
        # the top, and find out what it is called.
        if len(toplevel_dirs) != 1:
            raise Exception(
                "Package file is expected to have a single top-level directory"
                "(eg: 'firefox'), not: %s" % toplevel_dirs)
        ffxdir = mozpath.join(tmpdir, toplevel_dirs.pop())

        make_full_update = mozpath.join(
            topsrcdir, 'tools/update-packaging/make_full_update.sh')

        env = os.environ.copy()
        env['MOZ_PRODUCT_VERSION'] = get_application_ini_value(
            tmpdir, 'App', 'Version')
        env['MAR'] = mozpath.normpath(mar)
        if arch:
            env['BCJ_OPTIONS'] = ' '.join(_BCJ_OPTIONS[arch])
        if mar_format == 'bz2':
            env['MAR_OLD_FORMAT'] = '1'
        if mar_channel_id:
            env['MAR_CHANNEL_ID'] = mar_channel_id
        # The Windows build systems have xz installed but it isn't in the path
        # like it is on Linux and Mac OS X so just use the XZ env var so the mar
        # generation scripts can find it.
        xz_path = mozpath.join(topsrcdir, 'xz/xz.exe')
        if os.path.exists(xz_path):
            env['XZ'] = mozpath.normpath(xz_path)

        cmd = [make_full_update, output, ffxdir]
        if sys.platform == 'win32':
            # make_full_update.sh is a bash script, and Windows needs to
            # explicitly call out the shell to execute the script from Python.
            cmd.insert(0, env['MOZILLABUILD'] + '/msys/bin/bash.exe')
        # in py2 env needs str not unicode.
        env = {ensure_bytes(k): ensure_bytes(v) for k, v in env.iteritems()}
        subprocess.check_call(cmd, env=env)

    finally:
        shutil.rmtree(tmpdir)