11#! /usr/bin/env bash
2- # fast-compile-fe.sh — 增量编译 FE 并更新 doris-fe.jar
2+ # Licensed to the Apache Software Foundation (ASF) under one
3+ # or more contributor license agreements. See the NOTICE file
4+ # distributed with this work for additional information
5+ # regarding copyright ownership. The ASF licenses this file
6+ # to you under the Apache License, Version 2.0 (the
7+ # "License"); you may not use this file except in compliance
8+ # with the License. You may obtain a copy of the License at
39#
4- # 用法:
5- # ./fast-compile-fe.sh # 自动检测改动文件并编译
6- # ./fast-compile-fe.sh Foo.java Bar.java # 指定编译某些文件
10+ # http://www.apache.org/licenses/LICENSE-2.0
711#
8- # 依赖: javac, jar(JDK 8+),mvn(首次获取 classpath 时需要)
12+ # Unless required by applicable law or agreed to in writing,
13+ # software distributed under the License is distributed on an
14+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+ # KIND, either express or implied. See the License for the
16+ # specific language governing permissions and limitations
17+ # under the License.
18+ # fast-compile-fe.sh — Incrementally compile FE and update doris-fe.jar
19+ #
20+ # Usage:
21+ # ./fast-compile-fe.sh # Automatically detect changed files and compile
22+ # ./fast-compile-fe.sh Foo.java Bar.java # Specify files to compile
23+ #
24+ # Dependencies: javac, jar (JDK 8+), mvn (needed for initial classpath generation)
925
1026set -euo pipefail
1127
@@ -18,7 +34,7 @@ OUTPUT_JAR="$DORIS_HOME/output/fe/lib/doris-fe.jar"
1834TARGET_JAR=" $FE_CORE /target/doris-fe.jar"
1935CP_CACHE=" $FE_CORE /target/fast-compile-cp.txt"
2036
21- # 生成的源码目录( protobuf/thrift/annotation processor 生成的 java 文件)
37+ # Generated source directories ( protobuf/thrift/annotation processor generated java files)
2238GEN_SOURCES=(
2339 " $FE_CORE /target/generated-sources/doris"
2440 " $FE_CORE /target/generated-sources/org"
@@ -27,73 +43,73 @@ GEN_SOURCES=(
2743 " $FE_CORE /target/generated-sources/antlr4"
2844)
2945
30- # ─── 颜色输出 ────────────────────────────────────────────────────────────────
46+ # ─── Color Output ────────────────────────────────────────────────────────────────
3147RED=' \033[0;31m' ; GREEN=' \033[0;32m' ; YELLOW=' \033[1;33m' ; NC=' \033[0m'
3248info () { echo -e " ${GREEN} [INFO]${NC} $* " ; }
3349warn () { echo -e " ${YELLOW} [WARN]${NC} $* " ; }
3450error () { echo -e " ${RED} [ERROR]${NC} $* " >&2 ; }
3551
36- # ─── 检查环境 ────── ───────────────────────────────────────────────────────────
52+ # ─── Environment Check ───────────────────────────────────────────────────────────
3753check_env () {
3854 if [[ ! -d " $TARGET_CLASSES " ]]; then
39- error " target/classes 不存在,请先完整编译一次 : cd $DORIS_HOME && mvn package -pl fe/fe-core -DskipTests -T4"
55+ error " target/classes does not exist, please run a full build first : cd $DORIS_HOME && mvn package -pl fe/fe-core -DskipTests -T4"
4056 exit 1
4157 fi
4258 if [[ ! -f " $OUTPUT_JAR " && ! -f " $TARGET_JAR " ]]; then
43- error " doris-fe.jar 不存在,请先完整编译一次 "
59+ error " doris-fe.jar does not exist, please run a full build first "
4460 exit 1
4561 fi
4662}
4763
48- # ─── 获取 classpath(带缓存)─ ────────────────────────────────────────────────
64+ # ─── Get classpath (with cache) ────────────────────────────────────────────────
4965get_classpath () {
50- # 如果 pom.xml 比缓存新,则重新生成 classpath
66+ # If pom.xml is newer than the cache, regenerate classpath
5167 if [[ ! -f " $CP_CACHE " || ! -s " $CP_CACHE " || " $FE_CORE /pom.xml" -nt " $CP_CACHE " ]]; then
52- info " 生成 classpath 缓存 ..."
53- # 直接使用 target/lib(本次完整构建产生的依赖,比 .m2 仓库更可靠)
68+ info " Generating classpath cache ..."
69+ # Use target/lib directly (dependencies from the latest full build, more reliable than .m2 repository)
5470 find " $TARGET_LIB " -name " *.jar" | tr ' \n' ' :' | sed ' s/:$//' > " $CP_CACHE "
55- info " classpath 缓存已保存到 $CP_CACHE "
71+ info " Classpath cache saved to $CP_CACHE "
5672 fi
5773
58- # classpath = 依赖 jars + target/classes(项目内部依赖)
74+ # classpath = dependency jars + target/classes (internal project dependencies)
5975 echo " $( cat " $CP_CACHE " ) :$TARGET_CLASSES "
6076}
6177
62- # ─── 找出需要编译的 java 文件 ────────────────────────────────────────────────
78+ # ─── Find stale java files ───── ────────────────────────────────────────────────
6379find_stale_java_files () {
6480 local stale_files=()
6581
6682 while IFS= read -r java_file; do
6783 # java_file: /path/to/src/main/java/org/apache/doris/Foo.java
68- # 转换为 class 文件路径
84+ # Convert to class file path
6985 local rel_path=" ${java_file# $SRC_ROOT / } " # org/apache/doris/Foo.java
7086 local class_path=" $TARGET_CLASSES /${rel_path% .java} .class"
7187
7288 if [[ ! -f " $class_path " ]]; then
73- # class 文件不存在,肯定需要编译
89+ # class file does not exist, must compile
7490 stale_files+=(" $java_file " )
7591 elif [[ " $java_file " -nt " $class_path " ]]; then
76- # java 文件比主 class 文件新
92+ # java file is newer than main class file
7793 stale_files+=(" $java_file " )
7894 fi
7995 done < <( find " $SRC_ROOT " -name " *.java" )
8096
8197 printf ' %s\n' " ${stale_files[@]} "
8298}
8399
84- # ─── 编译 java 文件 ──── ───────────────────────────────────────────────────────
100+ # ─── Compile java files ───────────────────────────────────────────────────────
85101compile_files () {
86102 local classpath=" $1 "
87103 shift
88104 local java_files=(" $@ " )
89105
90- # 构建源码路径(包含生成的源码目录)
106+ # Build source path (including generated source directories)
91107 local source_path=" $SRC_ROOT "
92108 for gen_src in " ${GEN_SOURCES[@]} " ; do
93109 [[ -d " $gen_src " ]] && source_path=" $source_path :$gen_src "
94110 done
95111
96- info " 编译 ${# java_files[@]} 个文件 ..."
112+ info " Compiling ${# java_files[@]} files ..."
97113 for f in " ${java_files[@]} " ; do
98114 echo " → ${f# $DORIS_HOME / } "
99115 done
@@ -107,10 +123,10 @@ compile_files() {
107123 -d " $TARGET_CLASSES " \
108124 " ${java_files[@]} " 2>&1
109125
110- info " 编译完成 "
126+ info " Compilation finished "
111127}
112128
113- # ─── 收集需要更新到 jar 的 class 文件 ────────────────────────────────────────
129+ # ─── Collect class files to update jar ─ ────────────────────────────────────────
114130collect_updated_classes () {
115131 local java_files=(" $@ " )
116132 local class_files=()
@@ -123,10 +139,10 @@ collect_updated_classes() {
123139 local base
124140 base=" $( basename " $class_prefix " ) "
125141
126- # 主 class 文件
142+ # Main class file
127143 [[ -f " $class_prefix .class" ]] && class_files+=(" $class_prefix .class" )
128144
129- # 内部类和匿名类: Foo$Bar.class, Foo$1.class 等
145+ # Inner classes and anonymous classes: Foo$Bar.class, Foo$1.class, etc.
130146 while IFS= read -r inner; do
131147 class_files+=(" $inner " )
132148 done < <( find " $dir " -maxdepth 1 -name " ${base} \$ *.class" 2> /dev/null)
@@ -135,13 +151,13 @@ collect_updated_classes() {
135151 printf ' %s\n' " ${class_files[@]} "
136152}
137153
138- # ─── 更新 jar ── ───────────────────────────────────────────────────────────────
154+ # ─── Update jar ───────────────────────────────────────────────────────────────
139155update_jar () {
140156 local class_files=(" $@ " )
141157
142- info " 更新 jar(共 ${# class_files[@]} 个 class 文件) ..."
158+ info " Updating jar (total ${# class_files[@]} class files) ..."
143159
144- # 将 class 文件路径转为相对于 TARGET_CLASSES 的路径,供 jar 命令使用
160+ # Convert class file paths to relative paths for jar command
145161 local tmpfile
146162 tmpfile=" $( mktemp) "
147163 trap " rm -f $tmpfile " EXIT
@@ -150,16 +166,16 @@ update_jar() {
150166 echo " ${cf# $TARGET_CLASSES / } " >> " $tmpfile "
151167 done
152168
153- # 在 TARGET_CLASSES 目录下执行 jar uf,使 jar 内路径正确
169+ # Run jar uf in TARGET_CLASSES directory to ensure correct jar internal paths
154170 pushd " $TARGET_CLASSES " > /dev/null
155171
156- # 更新 target/doris-fe.jar
172+ # Update target/doris-fe.jar
157173 if [[ -f " $TARGET_JAR " ]]; then
158174 xargs jar uf " $TARGET_JAR " < " $tmpfile "
159175 info " 已更新 $TARGET_JAR "
160176 fi
161177
162- # 更新 output/fe/lib/doris-fe.jar
178+ # Update output/fe/lib/doris-fe.jar
163179 if [[ -f " $OUTPUT_JAR " ]]; then
164180 xargs jar uf " $OUTPUT_JAR " < " $tmpfile "
165181 info " 已更新 $OUTPUT_JAR "
@@ -168,47 +184,47 @@ update_jar() {
168184 popd > /dev/null
169185}
170186
171- # ─── 主流程 ─────── ────────────────────────────────────────────────────────────
187+ # ─── Main workflow ────────────────────────────────────────────────────────────
172188main () {
173189 check_env
174190
175191 local java_files=()
176192
177193 if [[ $# -gt 0 ]]; then
178- # 用户直接指定文件
194+ # User directly specifies files
179195 for arg in " $@ " ; do
180- # 支持相对路径和绝对路径
196+ # Support relative and absolute paths
181197 local abs_path
182198 if [[ " $arg " = /* ]]; then
183199 abs_path=" $arg "
184200 else
185201 abs_path=" $( pwd) /$arg "
186202 fi
187203 if [[ ! -f " $abs_path " ]]; then
188- # 尝试在 SRC_ROOT 下搜索
204+ # Try searching under SRC_ROOT
189205 local found
190206 found=" $( find " $SRC_ROOT " -name " $( basename " $arg " ) " | head -1) "
191207 if [[ -z " $found " ]]; then
192- error " 文件不存在 : $arg "
208+ error " File does not exist : $arg "
193209 exit 1
194210 fi
195211 abs_path=" $found "
196212 fi
197213 java_files+=(" $abs_path " )
198214 done
199- info " 手动指定 ${# java_files[@]} 个文件 "
215+ info " Manually specified ${# java_files[@]} files "
200216 else
201- # 自动检测改动
202- info " 扫描改动的 Java 文件 ..."
217+ # Automatically detect changes
218+ info " Scanning for changed Java files ..."
203219 while IFS= read -r f; do
204220 [[ -n " $f " ]] && java_files+=(" $f " )
205221 done < <( find_stale_java_files)
206222
207223 if [[ ${# java_files[@]} -eq 0 ]]; then
208- info " 没有发现需要编译的文件,已是最新状态 "
224+ info " No files need to be compiled, everything is up to date "
209225 exit 0
210226 fi
211- info " 发现 ${# java_files[@]} 个文件需要重新编译 "
227+ info " Found ${# java_files[@]} files need to be recompiled "
212228 fi
213229
214230 local start_time
@@ -221,23 +237,23 @@ main() {
221237 # 编译
222238 compile_files " $classpath " " ${java_files[@]} "
223239
224- # 收集 class 文件(含内部类)π
240+ # Collect class files (including inner classes)
225241 local class_files=()
226242 while IFS= read -r cf; do
227243 [[ -n " $cf " ]] && class_files+=(" $cf " )
228244 done < <( collect_updated_classes " ${java_files[@]} " )
229245
230246 if [[ ${# class_files[@]} -eq 0 ]]; then
231- warn " 未找到编译产物,跳过 jar 更新 "
247+ warn " No compiled artifacts found, skipping jar update "
232248 exit 0
233249 fi
234250
235- # 更新 jar
251+ # Update jar
236252 update_jar " ${class_files[@]} "
237253
238254 local end_time
239255 end_time=$( date +%s)
240- info " 完成!耗时 $(( end_time - start_time)) 秒 "
256+ info " Done! Time elapsed: $(( end_time - start_time)) seconds "
241257}
242258
243259main " $@ "
0 commit comments