<commit_before>#!/usr/bin/python
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from optparse import OptionParser, OptionValueError
import os
import shutil
import sys

"""Prep NaCl Toolchain

Does final assembly of the NaCl toolchain prior to building untrusted modules.
"""

SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
NACL_DIR = os.path.dirname(SCRIPT_DIR)

# Mapping from TC/include relative path to original source
HEADER_MAP = {
  'x86_newlib': {
      'x86_64-nacl/include/pthread.h': 'src/untrusted/pthread/pthread.h',
      'x86_64-nacl/include/semaphore.h': 'src/untrusted/pthread/semaphore.h',
      'x86_64-nacl/include/nacl/dynamic_annotations.h':
          'src/untrusted/valgrind/dynamic_annotations.h',
      'x86_64-nacl/include/nacl/nacl_dyncode.h':
          'src/untrusted/nacl/nacl_dyncode.h',
      'x86_64-nacl/include/nacl/nacl_random.h':
          'src/untrusted/nacl/nacl_random.h',
      'x86_64-nacl/include/nacl/nacl_startup.h':
          'src/untrusted/nacl/nacl_startup.h',
      'x86_64-nacl/include/nacl/nacl_thread.h':
          'src/untrusted/nacl/nacl_thread.h',
      'x86_64-nacl/include/irt.h': 'src/untrusted/irt/irt.h',

      'x86_64-nacl/lib32/crt1.o': 'src/untrusted/stubs/crt1.x',
      'x86_64-nacl/lib/crt1.o': 'src/untrusted/stubs/crt1.x',
  },
  'x86_glibc': {
      'x86_64-nacl/include/nacl/dynamic_annotations.h':
          'src/untrusted/valgrind/dynamic_annotations.h',
      'x86_64-nacl/include/nacl/nacl_dyncode.h':
          'src/untrusted/nacl/nacl_dyncode.h',
      'x86_64-nacl/include/nacl/nacl_random.h':
          'src/untrusted/nacl/nacl_random.h',
      'x86_64-nacl/include/nacl/nacl_startup.h':
          'src/untrusted/nacl/nacl_startup.h',
      'x86_64-nacl/include/nacl/nacl_thread.h':
          'src/untrusted/nacl/nacl_thread.h',
      'x86_64-nacl/include/irt.h': 'src/untrusted/irt/irt.h',
  },
  'arm_newlib': {
      'arm-nacl/include/pthread.h': 'src/untrusted/pthread/pthread.h',
      'arm-nacl/include/semaphore.h': 'src/untrusted/pthread/semaphore.h',
      'arm-nacl/include/nacl/dynamic_annotations.h':
          'src/untrusted/valgrind/dynamic_annotations.h',
      'arm-nacl/include/nacl/nacl_dyncode.h':
          'src/untrusted/nacl/nacl_dyncode.h',
      'arm-nacl/include/nacl/nacl_random.h':
          'src/untrusted/nacl/nacl_random.h',
      'arm-nacl/include/nacl/nacl_startup.h':
          'src/untrusted/nacl/nacl_startup.h',
      'arm-nacl/include/nacl/nacl_thread.h':
          'src/untrusted/nacl/nacl_thread.h',
      'arm-nacl/include/irt.h': 'src/untrusted/irt/irt.h',
      'arm-nacl/lib/crt1.o': 'src/untrusted/stubs/crt1.x',
  },
  'pnacl': {
      'usr/include/pthread.h': 'src/untrusted/pthread/pthread.h',
      'usr/include/semaphore.h': 'src/untrusted/pthread/semaphore.h',
      'usr/include/nacl/dynamic_annotations.h':
          'src/untrusted/valgrind/dynamic_annotations.h',
      'usr/include/nacl/nacl_dyncode.h':
          'src/untrusted/nacl/nacl_dyncode.h',
      'usr/include/nacl/nacl_random.h':
          'src/untrusted/nacl/nacl_random.h',
      'usr/include/nacl/nacl_startup.h':
          'src/untrusted/nacl/nacl_startup.h',
      'usr/include/nacl/nacl_thread.h':
          'src/untrusted/nacl/nacl_thread.h',
      'usr/include/irt.h': 'src/untrusted/irt/irt.h',
  }
}


def PosixPath(filepath):
  if sys.platform == 'win32':
    return filepath.replace('\\', '/')
  return filepath


def RealToRelative(filepath, basepath):
  """Returns a relative path from an absolute basepath and filepath."""
  path_parts = filepath.split('/')
  base_parts = basepath.split('/')
  while path_parts and base_parts and path_parts[0] == base_parts[0]:
    path_parts = path_parts[1:]
    base_parts = base_parts[1:]
  rel_parts = ['..'] * len(base_parts) + path_parts
  return '/'.join(rel_parts)


def MakeDir(outdir):
  if outdir and not os.path.exists(outdir):
    os.makedirs(outdir)<commit_msg>Change prep_nacl_sdk header locations for PNaCl to match new layout<commit_after>#!/usr/bin/python
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from optparse import OptionParser, OptionValueError
import os
import shutil
import sys

"""Prep NaCl Toolchain

Does final assembly of the NaCl toolchain prior to building untrusted modules.
"""

SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
NACL_DIR = os.path.dirname(SCRIPT_DIR)

# Mapping from TC/include relative path to original source
HEADER_MAP = {
  'x86_newlib': {
      'x86_64-nacl/include/pthread.h': 'src/untrusted/pthread/pthread.h',
      'x86_64-nacl/include/semaphore.h': 'src/untrusted/pthread/semaphore.h',
      'x86_64-nacl/include/nacl/dynamic_annotations.h':
          'src/untrusted/valgrind/dynamic_annotations.h',
      'x86_64-nacl/include/nacl/nacl_dyncode.h':
          'src/untrusted/nacl/nacl_dyncode.h',
      'x86_64-nacl/include/nacl/nacl_random.h':
          'src/untrusted/nacl/nacl_random.h',
      'x86_64-nacl/include/nacl/nacl_startup.h':
          'src/untrusted/nacl/nacl_startup.h',
      'x86_64-nacl/include/nacl/nacl_thread.h':
          'src/untrusted/nacl/nacl_thread.h',
      'x86_64-nacl/include/irt.h': 'src/untrusted/irt/irt.h',

      'x86_64-nacl/lib32/crt1.o': 'src/untrusted/stubs/crt1.x',
      'x86_64-nacl/lib/crt1.o': 'src/untrusted/stubs/crt1.x',
  },
  'x86_glibc': {
      'x86_64-nacl/include/nacl/dynamic_annotations.h':
          'src/untrusted/valgrind/dynamic_annotations.h',
      'x86_64-nacl/include/nacl/nacl_dyncode.h':
          'src/untrusted/nacl/nacl_dyncode.h',
      'x86_64-nacl/include/nacl/nacl_random.h':
          'src/untrusted/nacl/nacl_random.h',
      'x86_64-nacl/include/nacl/nacl_startup.h':
          'src/untrusted/nacl/nacl_startup.h',
      'x86_64-nacl/include/nacl/nacl_thread.h':
          'src/untrusted/nacl/nacl_thread.h',
      'x86_64-nacl/include/irt.h': 'src/untrusted/irt/irt.h',
  },
  'arm_newlib': {
      'arm-nacl/include/pthread.h': 'src/untrusted/pthread/pthread.h',
      'arm-nacl/include/semaphore.h': 'src/untrusted/pthread/semaphore.h',
      'arm-nacl/include/nacl/dynamic_annotations.h':
          'src/untrusted/valgrind/dynamic_annotations.h',
      'arm-nacl/include/nacl/nacl_dyncode.h':
          'src/untrusted/nacl/nacl_dyncode.h',
      'arm-nacl/include/nacl/nacl_random.h':
          'src/untrusted/nacl/nacl_random.h',
      'arm-nacl/include/nacl/nacl_startup.h':
          'src/untrusted/nacl/nacl_startup.h',
      'arm-nacl/include/nacl/nacl_thread.h':
          'src/untrusted/nacl/nacl_thread.h',
      'arm-nacl/include/irt.h': 'src/untrusted/irt/irt.h',
      'arm-nacl/lib/crt1.o': 'src/untrusted/stubs/crt1.x',
  },
  'pnacl': {
      'le32-nacl/include/pthread.h': 'src/untrusted/pthread/pthread.h',
      'le32-nacl/include/semaphore.h': 'src/untrusted/pthread/semaphore.h',
      'le32-nacl/include/nacl/dynamic_annotations.h':
          'src/untrusted/valgrind/dynamic_annotations.h',
      'le32-nacl/include/nacl/nacl_dyncode.h':
          'src/untrusted/nacl/nacl_dyncode.h',
      'le32-nacl/include/nacl/nacl_random.h':
          'src/untrusted/nacl/nacl_random.h',
      'le32-nacl/include/nacl/nacl_startup.h':
          'src/untrusted/nacl/nacl_startup.h',
      'le32-nacl/include/nacl/nacl_thread.h':
          'src/untrusted/nacl/nacl_thread.h',
      'le32-nacl/include/irt.h': 'src/untrusted/irt/irt.h',
  }
}


def PosixPath(filepath):
  if sys.platform == 'win32':
    return filepath.replace('\\', '/')
  return filepath


def RealToRelative(filepath, basepath):
  """Returns a relative path from an absolute basepath and filepath."""
  path_parts = filepath.split('/')
  base_parts = basepath.split('/')
  while path_parts and base_parts and path_parts[0] == base_parts[0]:
    path_parts = path_parts[1:]
    base_parts = base_parts[1:]
  rel_parts = ['..'] * len(base_parts) + path_parts
  return '/'.join(rel_parts)


def MakeDir(outdir):
  if outdir and not os.path.exists(outdir):
    os.makedirs(outdir)
{'fraction_non_alphanumeric': 0.15431496830814237, 'fraction_numerical': 0.022915650901999023, 'mean_word_length': 3.1272635814889336, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1166370', 'n_tokens_mistral': 3439, 'n_tokens_neox': 3321, 'n_words': 386}