Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit 044a864

Browse files
committed
build: i18n: WIP- autodownload. joyent#7676
1 parent ea4dc7d commit 044a864

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

configure

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import re
66
import shlex
77
import subprocess
88
import sys
9+
import urllib
10+
import zipfile
911

1012
CC = os.environ.get('CC', 'cc')
1113

@@ -711,6 +713,47 @@ def glob_to_var(dir_base, dir_sub):
711713
break
712714
return list
713715

716+
def icu_download(path):
717+
# download ICU, if needed
718+
icus = [
719+
{
720+
'url': 'http://download.icu-project.org/files/icu4c/54.1/icu4c-54_1-src.zip',
721+
# from https://ssl.icu-project.org/files/icu4c/54.1/icu4c-src-54_1.md5
722+
'md5': '6b89d60e2f0e140898ae4d7f72323bca',
723+
},
724+
]
725+
def fmtMb(amt):
726+
return "{:.1f}".format(amt / 1024000.)
727+
def reporthook(count, size, total):
728+
sys.stdout.write('%sMB total, %sMB downloaded \r' %
729+
(fmtMb(total),fmtMb(count*size)))
730+
for icu in icus:
731+
url = icu['url']
732+
md5 = icu['md5']
733+
local = url.split('/')[-1]
734+
targetfile = os.path.join(root_dir, 'deps', local)
735+
if not os.path.isfile(targetfile):
736+
try:
737+
sys.stdout.write('Downloading ICU from %s\nConnecting...\r' % url)
738+
sys.stdout.flush()
739+
msg = urllib.urlretrieve(url, targetfile, reporthook=reporthook)
740+
sys.stdout.write('\n') # newline
741+
print 'Downloaded %s' % local
742+
except:
743+
print 'Error occurred while downloading %s' % url
744+
raise
745+
#if msg:
746+
# print msg
747+
else:
748+
print 'Not re-downloading %s (delete it to retry)' % targetfile
749+
if os.path.isfile(targetfile) and md5 is not None:
750+
print 'Should have md5sum %s' % md5
751+
print 'TODO: SKIPPING md5sum check'
752+
753+
754+
print 'Please see the README.md - could not automatically download ICU.'
755+
return None
756+
714757
def configure_intl(o):
715758
icu_config = {
716759
'variables': {}
@@ -776,7 +819,11 @@ def configure_intl(o):
776819
icu_full_path = os.path.join(root_dir, 'deps/icu')
777820
o['variables']['icu_path'] = icu_full_path
778821
if not os.path.isdir(icu_full_path):
779-
print 'Error: ICU path is not a directory: %s' % (icu_full_path)
822+
localzip = icu_download(icu_full_path)
823+
if localzip:
824+
print 'Got local zip: %s' % localzip
825+
if not os.path.isdir(icu_full_path):
826+
print 'Error: ICU path is not a directory and couldn\'t download: %s' % (icu_full_path)
780827
sys.exit(1)
781828
# Now, what version of ICU is it? We just need the "major", such as 54.
782829
# uvernum.h contains it as a #define.

0 commit comments

Comments
 (0)