summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlmaz Mingaleev <mingaleev@google.com>2021-11-04 14:39:49 +0000
committerAlmaz Mingaleev <mingaleev@google.com>2021-11-09 11:46:59 +0000
commit6a743d143999d1a72a7dfa879912bbbed7b750d8 (patch)
tree3d65cc1548c4308faf2135065bf95bf8016e794c
parent93e8ee5af0c88b4ee264bf584aca9176e2a65e1c (diff)
downloadicu-6a743d143999d1a72a7dfa879912bbbed7b750d8.tar.gz
Rearrange methods in updateicudata.py. [S]
After aosp/1557177 update-tzdata.py and updateicudata.py behaviour slightly diverged. This CL allows to reuse that logic in update-tzdata.py. Bug: 204746181 Test: followed TZDB update instructions Change-Id: If6b4d3917c1a3f2dfd9eb76f057c9a74494e3472 Merged-In: If6b4d3917c1a3f2dfd9eb76f057c9a74494e3472 Merged-In: Ie387579fdeea4707cd40627fa8cd83d135b75df5
-rw-r--r--tools/icuutil.py44
-rwxr-xr-xtools/updateicudata.py20
2 files changed, 41 insertions, 23 deletions
diff --git a/tools/icuutil.py b/tools/icuutil.py
index 7c84b263f..f2b622d18 100644
--- a/tools/icuutil.py
+++ b/tools/icuutil.py
@@ -125,6 +125,9 @@ def MakeAndCopyIcuDataFiles(icu_build_dir):
"""Builds the ICU .dat and .jar files using the current src data.
The files are copied back into the expected locations in the src tree.
+
+ This is a low-level method.
+ Please check :func:`GenerateIcuDataFiles()` for caveats.
"""
# Keep track of the original cwd so we can go back to it at the end.
original_working_dir = os.getcwd()
@@ -175,7 +178,9 @@ def MakeAndCopyOverlayTzIcuData(icu_build_dir, dest_file):
The overlay file can be used as an overlay of a full ICU .dat file
to provide newer time zone data. Some strings like translated
- time zone names will be missing, but rules will be correct."""
+ time zone names will be missing, but rules will be correct.
+ """
+
# Keep track of the original cwd so we can go back to it at the end.
original_working_dir = os.getcwd()
@@ -246,9 +251,12 @@ def MakeAndCopyOverlayTzIcuData(icu_build_dir, dest_file):
# Switch back to the original working cwd.
os.chdir(original_working_dir)
-def RequiredToMakeLangInfo():
- """ Returns true if icu4c/source/data/misc/langInfo.txt has been re-generated.
- Returns false if re-generation is not needed.
+def _MakeLangInfo():
+ """ Regenerates icu4c/source/data/misc/langInfo.txt.
+ Returns true if the file was changed and false otherwise.
+
+ This is implementation detail, should not be called outside
+ of this script.
"""
# Generate icu4c/source/data/misc/langInfo.txt by a ICU4J tool
@@ -277,6 +285,34 @@ def RequiredToMakeLangInfo():
shutil.copyfile(langInfo_out_path, langInfo_dst_path)
return True
+def GenerateIcuDataFiles():
+ """ There are ICU files generation of which depends on ICU itself.
+ This method repeatedly builds ICU and re-generates these files until they
+ converge, i.e. subsequent builds do not change these files.
+ """
+ _MakeIcuDataFilesOnce()
+
+ # If icu4c/source/data/misc/langInfo.txt is re-generated, the binary data files need to be
+ # re-generated. MakeIcuDataFiles() is called until it converges because the re-generation
+ # depends icu4j, and icu4j depends on the binary data files.
+ while _MakeLangInfo():
+ _MakeIcuDataFilesOnce()
+
+def _MakeIcuDataFilesOnce():
+ """Builds ICU and copies .dat and .jar files to expected places.
+ Build is invoked only once. It is unlikely that you need to call
+ this method outside of this script.
+
+ This is a low-level method.
+ Please check :func:`GenerateIcuDataFiles()` for caveats.
+ """
+ i18nutil.SwitchToNewTemporaryDirectory()
+ icu_build_dir = '%s/icu' % os.getcwd()
+
+ PrepareIcuBuild(icu_build_dir)
+
+ MakeAndCopyIcuDataFiles(icu_build_dir)
+
def CopyLicenseFiles(target_dir):
"""Copies ICU license files to the target_dir"""
diff --git a/tools/updateicudata.py b/tools/updateicudata.py
index 175761920..e814f4d21 100755
--- a/tools/updateicudata.py
+++ b/tools/updateicudata.py
@@ -4,10 +4,8 @@
from __future__ import print_function
-import os
import sys
-import i18nutil
import icuutil
@@ -16,26 +14,10 @@ def main():
icu_dir = icuutil.icuDir()
print('Found icu in %s ...' % icu_dir)
- makeIcuDataFiles()
-
- # if icu4c/source/data/misc/langInfo.txt is re-generated, the binary data files need to be
- # re-generated. makeIcuDataFiles() are called until it coverages because the re-generation
- # depends icu4j, and icu4j depends on the bigit nary data files.
- while (icuutil.RequiredToMakeLangInfo()):
- makeIcuDataFiles()
-
+ icuutil.GenerateIcuDataFiles()
print('Look in %s for new data files' % icu_dir)
sys.exit(0)
-def makeIcuDataFiles():
- i18nutil.SwitchToNewTemporaryDirectory()
- icu_build_dir = '%s/icu' % os.getcwd()
-
- icuutil.PrepareIcuBuild(icu_build_dir)
-
- icuutil.MakeAndCopyIcuDataFiles(icu_build_dir)
-
-
if __name__ == '__main__':
main()