aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts/build_java_with_error_prone2.py
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2024-07-08 15:54:05 +0000
committerAlexander Smirnov <alex@ydb.tech>2024-07-08 15:54:05 +0000
commitfc7be18c76af2e700641f3598c4856baeef1428e (patch)
tree11dbca45eb321c3a4dd08b12152acc6ef5dd3fa9 /build/scripts/build_java_with_error_prone2.py
parentec0e7ed6da6fb317741fd8468602949a1362eca5 (diff)
parentc92cb9d3a19331916f0c274d80e67f02a62caa9b (diff)
downloadydb-fc7be18c76af2e700641f3598c4856baeef1428e.tar.gz
Merge branch 'rightlib' into mergelibs-240708-1553
Diffstat (limited to 'build/scripts/build_java_with_error_prone2.py')
-rw-r--r--build/scripts/build_java_with_error_prone2.py81
1 files changed, 39 insertions, 42 deletions
diff --git a/build/scripts/build_java_with_error_prone2.py b/build/scripts/build_java_with_error_prone2.py
index fa65cf19b9..8d7330db9e 100644
--- a/build/scripts/build_java_with_error_prone2.py
+++ b/build/scripts/build_java_with_error_prone2.py
@@ -22,21 +22,6 @@ JAVA10_EXPORTS = [
]
-def get_java_version(exe):
- p = subprocess.Popen([exe, '-version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- out, err = p.communicate()
- for line in (out or '').strip().split("\n") + (err or '').strip().split("\n"):
- m = re.match(r'java version "(.+)"', line)
- if m:
- parts = m.groups()[0].split(".")
- return parts[1] if parts[0] == "1" else parts[0]
- m = re.match(r'openjdk version "(\d+).*"', line)
- if m:
- parts = m.groups()[0].split(".")
- return parts[0]
- return None
-
-
def get_classpath(cmd):
for i, part in enumerate(cmd):
if part == '-classpath':
@@ -58,35 +43,47 @@ def parse_args(argv):
return parsed + [argv[i + 1 :]]
+def fix_cmd_line(error_prone_tool, cmd):
+ if not error_prone_tool:
+ return cmd
+ for f in cmd:
+ if f.startswith('-Xep'):
+ ERROR_PRONE_FLAGS.append(f)
+ for f in ERROR_PRONE_FLAGS:
+ if f in cmd:
+ cmd.remove(f)
+ if '-processor' in cmd:
+ classpath = get_classpath(cmd)
+ if classpath:
+ error_prone_tool = error_prone_tool + os.pathsep + classpath
+ return (
+ cmd
+ + JAVA10_EXPORTS
+ + ['-processorpath', error_prone_tool, '-XDcompilePolicy=byfile']
+ + [(' '.join(['-Xplugin:ErrorProne'] + ERROR_PRONE_FLAGS))]
+ )
+
+
+# NOTE: legacy, only for "devtools/ya/jbuild"
def just_do_it(argv):
java, javac, error_prone_tool, javac_cmd = parse_args(argv)
- ver = get_java_version(java)
- if not ver:
- raise Exception("Can't determine java version")
- if int(ver) >= 10:
- for f in javac_cmd:
- if f.startswith('-Xep'):
- ERROR_PRONE_FLAGS.append(f)
- for f in ERROR_PRONE_FLAGS:
- if f in javac_cmd:
- javac_cmd.remove(f)
- if '-processor' in javac_cmd:
- classpath = get_classpath(javac_cmd)
- if classpath:
- error_prone_tool = error_prone_tool + os.pathsep + classpath
- cmd = (
- [javac]
- + JAVA10_EXPORTS
- + ['-processorpath', error_prone_tool, '-XDcompilePolicy=byfile']
- + [(' '.join(['-Xplugin:ErrorProne'] + ERROR_PRONE_FLAGS))]
- + javac_cmd
- )
- else:
- cmd = (
- [java, '-Xbootclasspath/p:' + error_prone_tool, 'com.google.errorprone.ErrorProneCompiler']
- + ERROR_PRONE_FLAGS
- + javac_cmd
- )
+ for f in javac_cmd:
+ if f.startswith('-Xep'):
+ ERROR_PRONE_FLAGS.append(f)
+ for f in ERROR_PRONE_FLAGS:
+ if f in javac_cmd:
+ javac_cmd.remove(f)
+ if '-processor' in javac_cmd:
+ classpath = get_classpath(javac_cmd)
+ if classpath:
+ error_prone_tool = error_prone_tool + os.pathsep + classpath
+ cmd = (
+ [javac]
+ + JAVA10_EXPORTS
+ + ['-processorpath', error_prone_tool, '-XDcompilePolicy=byfile']
+ + [(' '.join(['-Xplugin:ErrorProne'] + ERROR_PRONE_FLAGS))]
+ + javac_cmd
+ )
if platform.system() == 'Windows':
sys.exit(subprocess.Popen(cmd).wait())
else: