1#!/bin/bash 2# Copyright (c) 2016 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 is used to prepare for a major version update of ICU (e.g. from 7# 54.1 to 56.1). Running this script is step 1 in README.chromium. 8 9if [ $# -lt 1 ]; 10then 11 echo "Usage: "$0" version (e.g. '56-1')" >&2 12 exit 1 13fi 14 15version="$1" 16 17# Makes ("68" "1") from "68-1". 18readonly major_minor_version=(${version//-/ }) 19 20# Just the major part of the ICU version number, e.g. "68". 21readonly major_version="${major_minor_version[0]}" 22 23tmp_dir=~/tmp/icu-${version} 24repo_url="https://github.com/unicode-org/icu/archive/refs/tags/release-${version}.tar.gz" 25tarball="${tmp_dir}/source.tar.gz" 26treeroot="$(dirname "$0")/.." 27 28# Check if the repo for $version is available. 29if ! wget --spider $repo_url 2>/dev/null; then 30 echo "$repo_url does not exists" 31 exit 1 32fi 33 34echo "Download ${version} from the upstream repository to tmp directory" 35rm -rf $tmp_dir 36mkdir -p $tmp_dir 37curl -L $repo_url --output $tarball 38 39echo "Cleaning up source/ ..." 40for file in source LICENSE license.html readme.html APIChangeReport.html 41do 42 rm -rf "${treeroot}/${file}" 43done 44 45echo "Extracting ${version} to ICU tree root" 46for file in source license.html readme.html APIChangeReport.html 47do 48 tar -xf $tarball -C $treeroot "icu-release-${version}/icu4c/${file}" --strip-components=2 49done 50 51echo "Extracting License to ICU tree root" 52tar -xf $tarball -C $treeroot "icu-release-${version}/LICENSE" --strip-components=1 53 54echo "Cleaning up tmp directory" 55rm -rf $tmp_dir 56 57echo "deleting directories we don't care about ..." 58for d in layoutex data/xml allinone 59do 60 rm -rf "${treeroot}/source/${d}" 61done 62 63echo "deleting Visual Studio build files ..." 64find "${treeroot}/source" -name *vcxp* -o -name *sln | xargs rm 65 66echo "restoring local data and configuration files ..." 67while read line 68do 69 # $line is not quoted to expand "*html.ucm". 70 git checkout -- "${treeroot}/source/data/"${line} 71done < "${treeroot}/scripts/data_files_to_preserve.txt" 72 73echo "Patching configure to work without source/{layoutex} ..." 74sed -i.orig -e '/^ac_config_files=/ s:\ layoutex/Makefile::g' \ 75 -e '/^ac_config_files=/ s: samples/M: samples/M:' \ 76 "${treeroot}/source/configure" 77rm -f "${treeroot}/source/configure.orig" 78 79echo "git-adding new files" 80git status source | sed -n '/^Untracked/,$ p' | grep source | xargs git add 81 82cd "${treeroot}" 83 84echo "Updating sources.gni" 85 86find source/i18n -maxdepth 1 ! -type d | egrep '\.(c|cpp|h)$' |sort | \ 87 sed 's/^\(.*\)$/ "\1",/' > i18n_src.list 88ls source/i18n/unicode/*h | sort | sed 's/^\(.*\)$/ "\1",/' > i18n_hdr.list 89 90find source/common -maxdepth 1 ! -type d | egrep '\.(c|cpp|h)$' |sort | \ 91 sed 's/^\(.*\)$/ "\1",/' > common_src.list 92ls source/common/unicode/*h | sort | \ 93 sed 's/^\(.*\)$/ "\1",/' > common_hdr.list 94 95sed -i \ 96 '/I18N_SRC_START/,/I18N_SRC_END/ { 97 /I18N_SRC_START/ r i18n_src.list 98 /source.i18n/ d 99 } 100 /I18N_HDR_START/,/I18N_HDR_END/ { 101 /I18N_HDR_START/ r i18n_hdr.list 102 /source.i18n/ d 103 } 104 /COMMON_SRC_START/,/COMMON_SRC_END/ { 105 /COMMON_SRC_START/ r common_src.list 106 /source.common/ d 107 } 108 /COMMON_HDR_START/,/COMMON_HDR_END/ { 109 /COMMON_HDR_START/ r common_hdr.list 110 /source.common/ d 111 }' sources.gni 112 113echo "Updating icu.gyp* files" 114 115ls source/i18n/unicode/*h | sort | \ 116 sed "s/^.*i18n\/\(.*\)$/ '\1',/" > i18n_hdr.list 117ls source/common/unicode/*h | sort | \ 118 sed "s/^.*common\/\(.*\)$/ '\1',/" > common_hdr.list 119 120 121find source/i18n -maxdepth 1 ! -type d | egrep '\.(c|cpp)$' | \ 122 sort | sed "s/^\(.*\)$/ '\1',/" > i18n_src.list 123find source/common -maxdepth 1 ! -type d | egrep '\.(c|cpp)$' | \ 124 sort | sed "s/^\(.*\)$/ '\1',/" > common_src.list 125 126sed -i \ 127 '/I18N_HDR_START/,/I18N_HDR_END/ { 128 /I18N_HDR_START/ r i18n_hdr.list 129 /.unicode.*\.h.,$/ d 130 } 131 /COMMON_HDR_START/,/COMMON_HDR_END/ { 132 /COMMON_HDR_START/ r common_hdr.list 133 /.unicode.*\.h.,$/ d 134 }' icu.gyp 135 136sed -i \ 137 '/I18N_SRC_START/,/I18N_SRC_END/ { 138 /I18N_SRC_START/ r i18n_src.list 139 /source\/i18n/ d 140 } 141 /COMMON_SRC_START/,/COMMON_SRC_END/ { 142 /COMMON_SRC_START/ r common_src.list 143 /source\/common/ d 144 }' icu.gypi 145 146# Update the major version number registered in version.json. 147# The version is written out into a text file to allow other tools to 148# read it without parsing .gni files. 149cat << EOF > version.json 150{ 151 "major_version": "${major_version}" 152} 153EOF 154 155echo "Done" 156