Skip to content

Commit 96ed4dc

Browse files
mihnitaSquash Bot
authored andcommitted
ICU-23333 Create equivalent build.py scripts for all ant tasks
1 parent f359a60 commit 96ed4dc

File tree

16 files changed

+1061
-68
lines changed

16 files changed

+1061
-68
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ARM/
5252
ARM64/
5353
Debug/
5454
Generated[!!-~]Files/
55-
Release/
55+
Release/**
5656
__pycache__/
5757
_site/
5858
arm/
@@ -63,7 +63,7 @@ doc/
6363
lib/
6464
!tools/cldr/lib
6565
out/
66-
release/
66+
release/**
6767
target/
6868
!docs/processes/release/
6969
tmp/
@@ -81,6 +81,7 @@ pkgdataMakefile
8181
rules.mk
8282
.DS_Store
8383
.flattened-pom.xml
84+
dependency-reduced-pom.xml
8485

8586
!icu4c/source/samples/csdet/Makefile
8687

.mvn/maven.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88

99
# Do not display transfer progress when downloading or uploading
1010
--no-transfer-progress
11+
-Dfile.encoding=UTF-8

docs/processes/cldr-icu.md

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ for a given version is downloading the zipped sources for the common (`core.zip`
4747
and tools (`tools.zip`) directory subtrees from the Data column in
4848
[CLDR Releases/Downloads](https://cldr.unicode.org/index/downloads)
4949

50-
Besides a standard JDK 11+, the process also requires [ant](https://ant.apache.org) and
51-
[maven](https://maven.apache.org) plus the xml-apis.jar from the
52-
[Apache xalan package](https://xalan.apache.org/xalan-j/downloads.html) _(Is this
53-
latter requirement still true?)_.
50+
Besides a standard JDK 11+, the process also requires [Ant](https://ant.apache.org),
51+
[Maven](https://maven.apache.org), and Python (https://www.python.org).
5452

55-
If you do CLDR development you can configure maven as documented at
53+
WARNING: the Ant scripts will soon be REMOVED.
54+
PLEASE execute all the steps using the new Python workflow.
55+
REPORT any problems you encounter, and switch back to the Ant if you don't have another choice.
56+
57+
If you do CLDR development you can configure Maven as documented at
5658
[CLDR Maven setup](http://cldr.unicode.org/development/maven) (non-Eclipse version).
5759

5860
But for the CLDR to ICU data conversion, or for regular ICU development this is not needed.
@@ -106,12 +108,12 @@ ticket and a separate PR:
106108

107109
There are several environment variables that need to be defined.
108110

109-
1. Java-, ant-, and maven-related variables
111+
1. Java-, Ant- (TO REMOVE), Maven-, and Python-related variables
110112

111113
* `JAVA_HOME`: Path to JDK (a directory, containing e.g. `bin/java`, `bin/javac`,
112114
etc.); on many systems this can be set using the output of `/usr/libexec/java_home`.
113115

114-
* `ANT_OPTS`: You may want to set `-Xmx8192m` to give Java more memory; otherwise
116+
* `ANT_OPTS`: (TO REMOVE) You may want to set `-Xmx8192m` to give Java more memory; otherwise
115117
it may run out of heap.
116118

117119
* `MAVEN_ARGS`: You may want to set `--no-transfer-progress` to reduce the noise
@@ -145,9 +147,10 @@ There are several environment variables that need to be defined.
145147

146148
## 1 Environment variables
147149

148-
1a. Java, ant, and maven variables, adjust for your system
150+
1a. Java, Ant (TO REMOVE), Maven, and Python variables, adjust for your system
149151
```sh
150152
export JAVA_HOME=/usr/libexec/java_home
153+
# TO REMOVE
151154
export ANT_OPTS="-Xmx8192m"
152155
export MAVEN_ARGS="--no-transfer-progress"
153156
```
@@ -172,13 +175,19 @@ export ICU4J_ROOT=$ICU_DIR/icu4j
172175
export TOOLS_ROOT=$ICU_DIR/tools
173176
```
174177

175-
1d. Directory for logs/notes (create if does not exist)
178+
1d. Python variables
179+
```sh
180+
export PYTHONPATH=$ICU_DIR/tools/py
181+
export PYTHONDONTWRITEBYTECODE=1
182+
```
183+
184+
1e. Directory for logs/notes (create if does not exist)
176185
```sh
177186
export NOTES=...(some directory)...
178187
mkdir -p $NOTES
179188
```
180189

181-
1e. The name of the icu data directory for Java (for example `icudt74b`)
190+
1f. The name of the icu data directory for Java (for example `icudt74b`)
182191
```sh
183192
export ICU_DATA_VER=icudt(version)b
184193
```
@@ -248,6 +257,22 @@ mvn clean install -pl :cldr-all,:cldr-code -DskipTests -DskipITs
248257

249258
5a. Generate the CLDR production data.
250259

260+
**// NEW PROCESS, Python. Please use this!**
261+
262+
This process uses Python with ICU4C's `data/build.py`
263+
264+
* Running `python build.py --cleanprod` is necessary to clean out the production data directory
265+
(usually `$CLDR_TMP_DIR/production`), required if any CLDR data has changed.
266+
267+
```sh
268+
cd $ICU4C_DIR/source/data
269+
python build.py --proddata
270+
```
271+
272+
**// NEW PROCESS - END**
273+
274+
**// TO REMOVE - Don't execute if the above step works.**
275+
251276
This process uses ant with ICU4C's `data/build.xml`
252277

253278
* Running `ant cleanprod` is necessary to clean out the production data directory
@@ -261,6 +286,7 @@ ant cleanprod
261286
ant setup
262287
ant proddata 2>&1 | tee $NOTES/cldr-newData-proddataLog.txt
263288
```
289+
**// TO REMOVE - END**
264290

265291
> Note, for CLDR development, at this point tests are sometimes run on the
266292
production data, see
@@ -299,8 +325,13 @@ java -jar target/cldr-to-icu-1.0-SNAPSHOT-jar-with-dependencies.jar --cldrDataDi
299325

300326
5c. Update the CLDR testData files needed by ICU4C/J tests, ensuring
301327
they are representative of the newest CLDR data.
328+
302329
```sh
303330
cd $ICU_DIR/tools/cldr
331+
# NEW PROCESS, Python. Please use this!
332+
python build.py --copy-cldr-testdata
333+
334+
# TO REMOVE. Don't execute if the above step works.
304335
ant copy-cldr-testdata
305336
```
306337

@@ -453,7 +484,7 @@ cd $ICU4J_ROOT
453484

454485
## 13 Rebuild ICU4J with new data, run tests
455486

456-
13a. Run the tests using the maven build
487+
13a. Run the tests using the Maven build
457488
```sh
458489
cd $ICU4J_ROOT
459490
mvn clean
@@ -488,7 +519,7 @@ Running a specific test is the same as above:
488519
mvn install --pl :core -DICU.exhaustive=10 -Dtest=ExhaustiveNumberTest
489520
```
490521

491-
## 14 Investigate and fix maven check test failures
522+
## 14 Investigate and fix Maven check test failures
492523

493524
Fix test cases and repeat from step 13, or fix CLDR data and repeat from
494525
step 4, as appropriate, until there are no more failures in ICU4C or ICU4J.

icu4c/source/data/build.py

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#!/usr/bin/env python3 -B
2+
#
3+
# Copyright (C) 2026 and later: Unicode, Inc. and others.
4+
# License & terms of use: http://www.unicode.org/copyright.html
5+
"""Generates data in cldr-staging/production from the cldr main repo"""
6+
7+
import argparse
8+
import os
9+
import sys
10+
import datetime
11+
import subprocess
12+
13+
try:
14+
from libs import icudirs
15+
from libs import icufs
16+
from libs import iculog
17+
from libs import icuproc
18+
except (ModuleNotFoundError, ImportError) as e:
19+
print("Make sure you define PYTHONPATH pointing to the ICU modules:")
20+
print(" export PYTHONPATH=<icu_root>/tools/py")
21+
print("On Windows:")
22+
print(" set PYTHONPATH=<icu_root>\\tools\\py")
23+
sys.exit(1)
24+
25+
26+
basedir = "."
27+
cldr_tmp_dir = None
28+
cldr_prod_dir = None
29+
cldrtools_jar = None
30+
cldr_tmp_dir = None
31+
notes_dir: str = "./notes"
32+
33+
34+
def _init():
35+
"""Initialization. Check folders existence, cldr-code.jar exists, etc."""
36+
iculog.subtitle("init()")
37+
iculog.info(str(datetime.datetime.now()))
38+
39+
cldr_dir = icudirs.cldr_dir()
40+
41+
cldrtools_dir = os.path.join(cldr_dir, "tools")
42+
iculog.info(f"cldr_dir:{cldr_dir}")
43+
iculog.info(f"cldrtools_dir:{cldrtools_dir}")
44+
if not os.path.isdir(cldrtools_dir):
45+
iculog.failure(
46+
"Please make sure that the CLDR tools directory"
47+
" is checked out into CLDR_DIR"
48+
)
49+
50+
dir_to_check = f"{cldrtools_dir}/cldr-code/target/classes"
51+
if not os.path.isdir(dir_to_check):
52+
iculog.failure(f"Can't find {dir_to_check}. Please build cldr-code.jar.")
53+
54+
global cldrtools_jar
55+
cldrtools_jar = f"{cldrtools_dir}/cldr-code/target/cldr-code.jar"
56+
if not os.path.isfile(cldrtools_jar):
57+
iculog.failure(
58+
f"CLDR classes not found in {cldrtools_dir}/cldr-code/target/classes."
59+
" Please build cldr-code.jar."
60+
)
61+
62+
global cldr_tmp_dir
63+
cldr_tmp_dir = icudirs.cldr_prod_dir()
64+
global cldr_prod_dir
65+
cldr_prod_dir = f"{cldr_tmp_dir}/production/"
66+
67+
global notes_dir
68+
notes_dir = os.environ.get("NOTES", "./notes")
69+
70+
subprocess.run("mvn -version", encoding="utf-8", shell=True, check=True)
71+
iculog.info(f"cldr tools dir: {cldrtools_dir}")
72+
iculog.info(f"cldr tools jar: {cldrtools_jar}")
73+
iculog.info(f"CLDR_TMP_DIR: {cldr_tmp_dir} ")
74+
iculog.info(f"cldr.prod_dir (production data): {cldr_prod_dir}")
75+
iculog.info(f"notes_dir: {notes_dir}")
76+
77+
78+
def cleanprod():
79+
"""Remove the data in cldr-staging/production"""
80+
iculog.title("cleanprod()")
81+
icufs.rmdir(f"{cldr_prod_dir}/common")
82+
icufs.rmdir(f"{cldr_prod_dir}/keyboards")
83+
84+
85+
def restoreprod():
86+
"""Restore the git version of data in cldr-staging/production"""
87+
iculog.title("restoreprod()")
88+
if not cldr_prod_dir:
89+
iculog.failure("cldr_prod_dir not configured")
90+
return
91+
old_dir = icufs.pushd(cldr_prod_dir)
92+
icufs.rmdir("common")
93+
icuproc.run_with_logging(
94+
"git checkout -- common",
95+
logfile=os.path.join(notes_dir, "cldr-newData-restorecommonLog.txt"),
96+
)
97+
icufs.rmdir("keyboards")
98+
icuproc.run_with_logging(
99+
"git checkout -- keyboards",
100+
logfile=os.path.join(notes_dir, "cldr-newData-restorekeyboardsLog.txt"),
101+
)
102+
icufs.popd(old_dir)
103+
104+
105+
def proddata():
106+
"""Generates data in cldr-staging/production"""
107+
cleanprod()
108+
iculog.title("proddata()")
109+
iculog.info(f"Rebuilding {cldr_prod_dir} - takes a while!")
110+
# setup prod data
111+
icuproc.run_with_logging(
112+
"java"
113+
f" -cp {cldrtools_jar}"
114+
" org.unicode.cldr.tool.GenerateProductionData"
115+
" -v",
116+
logfile=os.path.join(notes_dir, "cldr-newData-proddataLog.txt"),
117+
)
118+
119+
120+
def main():
121+
parser = argparse.ArgumentParser()
122+
parser.add_argument(
123+
"-c", "--cleanprod", help="remove all build targets", action="store_true"
124+
)
125+
parser.add_argument(
126+
"-p",
127+
"--proddata",
128+
help="Rebuilds files in cldr-staging/production",
129+
action="store_true",
130+
)
131+
parser.add_argument(
132+
"-r",
133+
"--restore",
134+
help="Restore (from git) the filed removed by cleanprod",
135+
action="store_true",
136+
)
137+
cmd = parser.parse_args()
138+
139+
if cmd.cleanprod:
140+
_init()
141+
cleanprod()
142+
elif cmd.proddata:
143+
_init()
144+
proddata()
145+
elif cmd.restore:
146+
_init()
147+
restoreprod()
148+
else:
149+
parser.print_help()
150+
151+
return 0
152+
153+
154+
if __name__ == "__main__":
155+
sys.exit(main())

tools/cldr/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,21 @@
55

66
## CLDR test data
77

8+
The Python [build.py](build.py) file takes care of copying some CLDR
9+
test data directories to both the ICU4C and ICU4J source trees. To add
10+
more directories to the list, modify the `cldr_test_data` fileset.
11+
12+
ANT-TO-REMOVE-START
13+
14+
WARNING: Ant support WILL BE REMOVED.
15+
Only use this (and report) if the step above fails.
16+
817
The ant [build.xml](build.xml) file takes care of copying some CLDR
918
test data directories to both the ICU4C and ICU4J source trees. To add
1019
more directories to the list, modify the `cldrTestData` fileset.
1120

21+
ANT-TO-REMOVE-END
22+
1223
## cldr-to-icu
1324

1425
The cldr-to-icu directory contains tools to convert from CLDR's XML

0 commit comments

Comments
 (0)