• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright (c) 2015 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# This script is tested ONLY on Linux. It may not work correctly on
7# Mac OS X.
8
9TOPSRC="$(dirname "$0")/.."
10source "${TOPSRC}/scripts/data_common.sh"
11
12function check_build {
13  if [[ ! -x bin/icupkg || ! -x bin/pkgdata || ! -r lib/libicuuc.so ]]; then
14    echo "ICU has not been built. Configure and build ICU first by running" >&2
15    echo "${TOPSRC}/source/runConfigureICU Linux --disable-layout && make" >&2
16    exit 3
17  fi
18}
19
20# Rewrite data/Makefile to regenerate string pool bundles (pool.res)
21# optimized for our trimmed data (after running trim_data.sh or
22# android/patch_locale.sh)
23# See http://site.icu-project.org/processes/release/tasks/build
24#     http://bugs.icu-project.org/trac/ticket/8101
25#     http://bugs.icu-project.org/trac/ticket/12069
26function rewrite_data_makefile {
27  echo "Creating Makefile to regenerate pool bundles..."
28  sed -i.orig -e \
29  ' /usePoolBundle/ {
30    s/usePoolBundle/writePoolBundle/
31    s/\(\$(UNITSRCDIR.*\)\$(<F)$/\1$(UNIT_SRC)/
32    s/\(\$(REGIONSRCDIR.*\)\$(<F)$/\1$(REGION_SRC)/
33    s/\(\$(CURRSRCDIR.*\)\$(<F)$/\1$(CURR_SRC)/
34    s/\(\$(LANGSRCDIR.*\)\$(<F)$/\1$(LANG_SRC)/
35    s/\(\$(ZONESRCDIR.*\)\$(<F)$/\1$(ZONE_SRC)/
36    s/\(\$(LOCSRCDIR.*\)\$(<F)$/\1$(RES_SRC)/
37  }' Makefile
38}
39
40# Rebuild the ICU data. 'make' has to be run twice because of
41# https://unicode-org.atlassian.net/browse/ICU-10570
42function build_data {
43  make clean
44  make
45  sed -i 's/root_subset.res/root.res/' out/tmp/icudata.lst
46  make
47}
48
49# Copy a single pool.res to the source tree and emit the sizes
50# before and after.
51function copy_pool_bundle {
52  echo "copying pool.res for $3"
53  echo "original: $(ls -l $2/pool.res | awk '{print $5;}')"
54  echo "optimized: $(ls -l $1 | awk '{print $5;}')"
55  cp "$1" "$2"
56}
57
58function copy_pool_bundles {
59  echo "Copying optimized pool bundles to the ${TOPSRC}/source/data ..."
60  POOLROOT="out/build/icudt${VERSION}l"
61  SRCDATA="${TOPSRC}/source/data"
62
63  copy_pool_bundle "${POOLROOT}/pool.res" "${SRCDATA}/locales" locales
64
65  for c in lang region zone curr unit; do
66    copy_pool_bundle "${POOLROOT}/${c}/pool.res" "${SRCDATA}/${c}" "${c}"
67  done
68}
69
70function clean_up_src {
71  echo "Cleaning up the source tree. Removing optimize pool bundles ..."
72  cd "${TOPSRC}/source/data"
73  for c in locales lang region zone curr unit; do
74    git checkout -- "${c}/pool.res"
75  done
76}
77
78function main() {
79  check_build
80  cd data
81  rewrite_data_makefile
82  echo "PASS1: Building the ICU data to generate custom pool bundles ..."
83  build_data
84
85  copy_pool_bundles
86
87  echo "Restoring the original Makefile"
88  mv Makefile.orig Makefile
89
90  echo "PASS2: Building the final ICU data with custom pool bundles"
91  build_data
92  ls -l out/tmp/icudt*l.dat
93
94  clean_up_src
95
96  echo "Done."
97}
98
99main "$@"
100