Ejemplo n.º 1
0
 def icu_download(path):
   # download ICU, if needed
   if not os.access(options.download_path, os.W_OK):
     print 'Error: cannot write to desired download path. ' \
           'Either create it or verify permissions.'
     sys.exit(1)
   for icu in icus:
     url = icu['url']
     md5 = icu['md5']
     local = url.split('/')[-1]
     targetfile = os.path.join(options.download_path, local)
     if not os.path.isfile(targetfile):
       if nodedownload.candownload(auto_downloads, "icu"):
         nodedownload.retrievefile(url, targetfile)
     else:
       print ' Re-using existing %s' % targetfile
     if os.path.isfile(targetfile):
       sys.stdout.write(' Checking file integrity with MD5:\r')
       gotmd5 = nodedownload.md5sum(targetfile)
       print ' MD5:      %s  %s' % (gotmd5, targetfile)
       if (md5 == gotmd5):
         return targetfile
       else:
         print ' Expected: %s      *MISMATCH*' % md5
         print '\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile
   return None
Ejemplo n.º 2
0
def configure_intl(o):
  icus = [
    {
      'url': 'https://ssl.icu-project.org/files/icu4c/56.1/icu4c-56_1-src.zip',
      'md5': '61d71888f14bf00cc3e8a6f2c087d367',
    },
  ]
  def icu_download(path):
    # download ICU, if needed
    if not os.access(options.download_path, os.W_OK):
      print 'Error: cannot write to desired download path. ' \
            'Either create it or verify permissions.'
      sys.exit(1)
    for icu in icus:
      url = icu['url']
      md5 = icu['md5']
      local = url.split('/')[-1]
      targetfile = os.path.join(options.download_path, local)
      if not os.path.isfile(targetfile):
        if nodedownload.candownload(auto_downloads, "icu"):
          nodedownload.retrievefile(url, targetfile)
      else:
        print ' Re-using existing %s' % targetfile
      if os.path.isfile(targetfile):
        sys.stdout.write(' Checking file integrity with MD5:\r')
        gotmd5 = nodedownload.md5sum(targetfile)
        print ' MD5:      %s  %s' % (gotmd5, targetfile)
        if (md5 == gotmd5):
          return targetfile
        else:
          print ' Expected: %s      *MISMATCH*' % md5
          print '\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile
    return None
  icu_config = {
    'variables': {}
  }
  icu_config_name = 'icu_config.gypi'
  def write_config(data, name):
    return

  # write an empty file to start with
  write(icu_config_name, do_not_edit +
        pprint.pformat(icu_config, indent=2) + '\n')

  # always set icu_small, node.gyp depends on it being defined.
  o['variables']['icu_small'] = b(False)

  with_intl = options.with_intl
  with_icu_source = options.with_icu_source
  have_icu_path = bool(options.with_icu_path)
  if have_icu_path and with_intl != 'none':
    print 'Error: Cannot specify both --with-icu-path and --with-intl'
    sys.exit(1)
  elif have_icu_path:
    # Chromium .gyp mode: --with-icu-path
    o['variables']['v8_enable_i18n_support'] = 1
    # use the .gyp given
    o['variables']['icu_gyp_path'] = options.with_icu_path
    return
  # --with-intl=<with_intl>
  # set the default
  if with_intl in (None, 'none'):
    o['variables']['v8_enable_i18n_support'] = 0
    return  # no Intl
  elif with_intl == 'small-icu':
    # small ICU (English only)
    o['variables']['v8_enable_i18n_support'] = 1
    o['variables']['icu_small'] = b(True)
    locs = set(options.with_icu_locales.split(','))
    locs.add('root')  # must have root
    o['variables']['icu_locales'] = string.join(locs,',')
  elif with_intl == 'full-icu':
    # full ICU
    o['variables']['v8_enable_i18n_support'] = 1
  elif with_intl == 'system-icu':
    # ICU from pkg-config.
    o['variables']['v8_enable_i18n_support'] = 1
    pkgicu = pkg_config('icu-i18n')
    if pkgicu[0] is None:
      print 'Error: could not load pkg-config data for "icu-i18n".'
      print 'See above errors or the README.md.'
      sys.exit(1)
    (libs, cflags, libpath) = pkgicu
    # libpath provides linker path which may contain spaces
    if libpath:
      o['libraries'] += [libpath]
    # safe to split, cannot contain spaces
    o['libraries'] += libs.split()
    if cflags:
      o['include_dirs'] += filter(None, map(str.strip, cflags.split('-I')))
    # use the "system" .gyp
    o['variables']['icu_gyp_path'] = '../libraries/node/tools/icu/icu-system.gyp'
    return

  # this is just the 'deps' dir. Used for unpacking.
  icu_parent_path = os.path.join(root_dir, 'deps')

  # The full path to the ICU source directory.
  icu_full_path = os.path.join(icu_parent_path, 'icu')

  # icu-tmp is used to download and unpack the ICU tarball.
  icu_tmp_path = os.path.join(icu_parent_path, 'icu-tmp')

  # --with-icu-source processing
  # first, check that they didn't pass --with-icu-source=deps/icu
  if with_icu_source and os.path.abspath(icu_full_path) == os.path.abspath(with_icu_source):
    print 'Ignoring redundant --with-icu-source=%s' % (with_icu_source)
    with_icu_source = None
  # if with_icu_source is still set, try to use it.
  if with_icu_source:
    if os.path.isdir(icu_full_path):
      print 'Deleting old ICU source: %s' % (icu_full_path)
      shutil.rmtree(icu_full_path)
    # now, what path was given?
    if os.path.isdir(with_icu_source):
      # it's a path. Copy it.
      print '%s -> %s' % (with_icu_source, icu_full_path)
      shutil.copytree(with_icu_source, icu_full_path)
    else:
      # could be file or URL.
      # Set up temporary area
      if os.path.isdir(icu_tmp_path):
        shutil.rmtree(icu_tmp_path)
      os.mkdir(icu_tmp_path)
      icu_tarball = None
      if os.path.isfile(with_icu_source):
        # it's a file. Try to unpack it.
        icu_tarball = with_icu_source
      else:
        # Can we download it?
        local = os.path.join(icu_tmp_path, with_icu_source.split('/')[-1])  # local part
        icu_tarball = nodedownload.retrievefile(with_icu_source, local)
      # continue with "icu_tarball"
      nodedownload.unpack(icu_tarball, icu_tmp_path)
      # Did it unpack correctly? Should contain 'icu'
      tmp_icu = os.path.join(icu_tmp_path, 'icu')
      if os.path.isdir(tmp_icu):
        os.rename(tmp_icu, icu_full_path)
        shutil.rmtree(icu_tmp_path)
      else:
        print ' Error: --with-icu-source=%s did not result in an "icu" dir.' % with_icu_source
        shutil.rmtree(icu_tmp_path)
        sys.exit(1)

  # ICU mode. (icu-generic.gyp)
  o['variables']['icu_gyp_path'] = '../libraries/node/tools/icu/icu-generic.gyp'
  # ICU source dir relative to root
  o['variables']['icu_path'] = icu_full_path
  if not os.path.isdir(icu_full_path):
    print '* ECMA-402 (Intl) support didn\'t find ICU in %s..' % (icu_full_path)
    # can we download (or find) a zipfile?
    localzip = icu_download(icu_full_path)
    if localzip:
      nodedownload.unpack(localzip, icu_parent_path)
  if not os.path.isdir(icu_full_path):
    print ' Cannot build Intl without ICU in %s.' % (icu_full_path)
    print ' (Fix, or disable with "--with-intl=none" )'
    sys.exit(1)
  else:
    print '* Using ICU in %s' % (icu_full_path)
  # Now, what version of ICU is it? We just need the "major", such as 54.
  # uvernum.h contains it as a #define.
  uvernum_h = os.path.join(icu_full_path, '../libraries/node/source/common/unicode/uvernum.h')
  if not os.path.isfile(uvernum_h):
    print ' Error: could not load %s - is ICU installed?' % uvernum_h
    sys.exit(1)
  icu_ver_major = None
  matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
  match_version = re.compile(matchVerExp)
  for line in open(uvernum_h).readlines():
    m = match_version.match(line)
    if m:
      icu_ver_major = m.group(1)
  if not icu_ver_major:
    print ' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
    sys.exit(1)
  icu_endianness = sys.byteorder[0];  # TODO(srl295): EBCDIC should be 'e'
  o['variables']['icu_ver_major'] = icu_ver_major
  o['variables']['icu_endianness'] = icu_endianness
  icu_data_file_l = 'icudt%s%s.dat' % (icu_ver_major, 'l')
  icu_data_file = 'icudt%s%s.dat' % (icu_ver_major, icu_endianness)
  # relative to configure
  icu_data_path = os.path.join(icu_full_path,
                               '../libraries/node/source/data/in',
                               icu_data_file_l)
  # relative to dep..
  icu_data_in = os.path.join('../libraries/node/deps/icu/source/data/in', icu_data_file_l)
  if not os.path.isfile(icu_data_path) and icu_endianness != 'l':
    # use host endianness
    icu_data_path = os.path.join(icu_full_path,
                                 '../libraries/node/source/data/in',
                                 icu_data_file)
    # relative to dep..
    icu_data_in = os.path.join('../libraries/node/icu/source/data/in',
                               icu_data_file)
  # this is the input '.dat' file to use .. icudt*.dat
  # may be little-endian if from a icu-project.org tarball
  o['variables']['icu_data_in'] = icu_data_in
  # this is the icudt*.dat file which node will be using (platform endianness)
  o['variables']['icu_data_file'] = icu_data_file
  if not os.path.isfile(icu_data_path):
    print ' Error: ICU prebuilt data file %s does not exist.' % icu_data_path
    print ' See the README.md.'
    # .. and we're not about to build it from .gyp!
    sys.exit(1)
  # map from variable name to subdirs
  icu_src = {
    'stubdata': 'stubdata',
    'common': 'common',
    'i18n': 'i18n',
    'io': 'io',
    'tools': 'tools/toolutil',
    'genccode': 'tools/genccode',
    'genrb': 'tools/genrb',
    'icupkg': 'tools/icupkg',
  }
  # this creates a variable icu_src_XXX for each of the subdirs
  # with a list of the src files to use
  for i in icu_src:
    var  = 'icu_src_%s' % i
    path = '../libraries/node/deps/icu/source/%s' % icu_src[i]
    icu_config['variables'][var] = glob_to_var('../libraries/node/tools/icu', path, '../libraries/node/patches/%s/source/%s' % (icu_ver_major, icu_src[i]) )
  # write updated icu_config.gypi with a bunch of paths
  write(icu_config_name, do_not_edit +
        pprint.pformat(icu_config, indent=2) + '\n')
  return  # end of configure_intl