Exemple #1
0
def run():
    if shared.Settings.WASM_BACKEND:
        # The wasm backend does suffer from the same probllem as fastcomp so doesn't
        # need the filename hashing.
        cmd = [shared.LLVM_AR] + sys.argv[1:]
        return shared.run_process(cmd, stdin=sys.stdin, check=False).returncode

    try:
        args = substitute_response_files(sys.argv)
    except IOError as e:
        shared.exit_with_error(e)
    newargs = [shared.LLVM_AR] + args[1:]

    tmpdir = None
    response_filename = None

    # The 3 argmuent form of ar doesn't involve other files. For example
    # 'ar x libfoo.a'.
    if len(newargs) > 3:
        tmpdir = tempfile.mkdtemp(prefix='emar-')
        cmd = newargs[1]
        if 'r' in cmd or 'q' in cmd:
            # We are adding files to the archive.
            # Normally the output file is then arg 2, except in the case were the
            # a or b modifiers are used in which case its arg 3.
            if 'a' in cmd or 'b' in cmd:
                out_arg_index = 3
            else:
                out_arg_index = 2

            # Add a hash to colliding basename, to make them unique.
            for j in range(out_arg_index + 1, len(newargs)):
                orig_name = newargs[j]
                full_name = os.path.abspath(orig_name)
                basename = os.path.basename(full_name)

                h = hashlib.md5(full_name.encode('utf-8')).hexdigest()[:8]
                parts = basename.split('.')
                parts[0] += '_' + h
                newname = '.'.join(parts)
                full_newname = os.path.join(tmpdir, newname)
                shutil.copyfile(orig_name, full_newname)
                newargs[j] = full_newname

        if shared.DEBUG:
            print('emar:', sys.argv, '  ==>  ', newargs, file=sys.stderr)
        response_filename = create_response_file(
            newargs[3:], shared.get_emscripten_temp_dir())
        newargs = newargs[:3] + ['@' + response_filename]

    if shared.DEBUG:
        print('emar:', sys.argv, '  ==>  ', newargs, file=sys.stderr)

    rtn = shared.run_process(newargs, stdin=sys.stdin, check=False).returncode
    if tmpdir:
        shutil.rmtree(tmpdir)
        shared.try_delete(response_filename)
    return rtn
Exemple #2
0
def run(infile, outfile, memfile):
    temp_files = shared.configuration.get_temp_files()
    infile, outfile = substitute_response_files([infile, outfile])
    generate_struct_info()

    outfile_obj = open(outfile, 'w')

    return temp_files.run_and_clean(lambda: emscript(
        infile, outfile_obj, memfile, temp_files, shared.DEBUG))
Exemple #3
0
def run():
    try:
        args = substitute_response_files(sys.argv)
    except IOError as e:
        shared.exit_with_error(e)
    newargs = [shared.LLVM_AR] + args[1:]

    to_delete = []

    # The 3 argmuent form of ar doesn't involve other files. For example
    # 'ar x libfoo.a'.
    if len(newargs) > 3:
        cmd = newargs[1]
        if 'r' in cmd or 'q' in cmd:
            # We are adding files to the archive.
            # Normally the output file is then arg 2, except in the case were the
            # a or b modifiers are used in which case its arg 3.
            if 'a' in cmd or 'b' in cmd:
                out_arg_index = 3
            else:
                out_arg_index = 2

            # Add a hash to colliding basename, to make them unique.
            for j in range(out_arg_index + 1, len(newargs)):
                orig_name = newargs[j]
                full_name = os.path.abspath(orig_name)
                dirname = os.path.dirname(full_name)
                basename = os.path.basename(full_name)

                h = hashlib.md5(full_name.encode('utf-8')).hexdigest()[:8]
                parts = basename.split('.')
                parts[0] += '_' + h
                newname = '.'.join(parts)
                full_newname = os.path.join(dirname, newname)
                try:
                    shutil.copyfile(orig_name, full_newname)
                    newargs[j] = full_newname
                    to_delete.append(full_newname)
                except Exception:
                    # it is ok to fail here, we just don't get hashing
                    pass

        if shared.DEBUG:
            print('emar:', sys.argv, '  ==>  ', newargs, file=sys.stderr)

        response_filename = create_response_file(
            newargs[3:], shared.get_emscripten_temp_dir())
        to_delete += [response_filename]
        newargs = newargs[:3] + ['@' + response_filename]

    if shared.DEBUG:
        print('emar:', sys.argv, '  ==>  ', newargs, file=sys.stderr)

    rtn = shared.run_process(newargs, stdin=sys.stdin, check=False).returncode
    for d in to_delete:
        shared.try_delete(d)
    return rtn
Exemple #4
0
def run(infile, outfile, memfile):
    temp_files = shared.configuration.get_temp_files()
    infile, outfile = substitute_response_files([infile, outfile])
    if not shared.Settings.BOOTSTRAPPING_STRUCT_INFO:
        generate_struct_info()

    outfile_obj = open(outfile, 'w')

    return temp_files.run_and_clean(lambda: emscript(
        infile, outfile_obj, memfile, temp_files, shared.DEBUG))
Exemple #5
0
def run():
  args = substitute_response_files(sys.argv)
  newargs = [shared.LLVM_AR] + args[1:]

  to_delete = []

  # The 3 argment form of ar doesn't involve other files. For example
  # 'ar x libfoo.a'.
  if len(newargs) > 3:
    cmd = newargs[1]
    if 'r' in cmd:
      # we are adding files to the archive.
      # normally the output file is then arg 2, except in the case were the
      # a or b modifiers are used in which case its arg 3.
      if 'a' in cmd or 'b' in cmd:
        new_member_args_start = 4
      else:
        new_member_args_start = 3

      # we add a hash to each input, to make them unique as
      # possible, as llvm-ar cannot extract duplicate names
      # (and only the basename is used!)
      for j in range(new_member_args_start, len(newargs)):
        orig_name = newargs[j]
        full_name = os.path.abspath(orig_name)
        dir_name = os.path.dirname(full_name)
        base_name = os.path.basename(full_name)
        h = hashlib.md5(full_name.encode('utf-8')).hexdigest()[:8]
        parts = base_name.split('.')
        parts[0] += '_' + h
        newname = '.'.join(parts)
        full_newname = os.path.join(dir_name, newname)
        if not os.path.exists(full_newname):
          try: # it is ok to fail here, we just don't get hashing
            shutil.copyfile(orig_name, full_newname)
            newargs[j] = full_newname
            to_delete.append(full_newname)
          except:
            pass

    if shared.DEBUG:
      print('emar:', sys.argv, '  ==>  ', newargs, file=sys.stderr)

    response_filename = create_response_file(newargs[3:], shared.get_emscripten_temp_dir())
    to_delete += [response_filename]
    newargs = newargs[:3] + ['@' + response_filename]

  if shared.DEBUG:
    print('emar:', sys.argv, '  ==>  ', newargs, file=sys.stderr)

  try:
    return shared.run_process(newargs, stdin=sys.stdin, check=False).returncode
  finally:
    for d in to_delete:
      shared.try_delete(d)