aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts
diff options
context:
space:
mode:
authorv-korovin <v-korovin@yandex-team.com>2024-06-13 12:27:45 +0300
committerv-korovin <v-korovin@yandex-team.com>2024-06-13 12:42:08 +0300
commitbe66f533d520f6ce67ee7386e807b85230b1c587 (patch)
tree88e0b03ba886fc672fdd99d3c3cda1032ac28061 /build/scripts
parent80050a7cd2d471849db213ff374ceeee5614c7e7 (diff)
downloadydb-be66f533d520f6ce67ee7386e807b85230b1c587.tar.gz
Fix java command file in plugin
e43ef305d767fb94adc0f4f6e3901156fc3b7939
Diffstat (limited to 'build/scripts')
-rw-r--r--build/scripts/compile_java.py21
-rw-r--r--build/scripts/java_command_file.py43
-rw-r--r--build/scripts/ya.make1
3 files changed, 54 insertions, 11 deletions
diff --git a/build/scripts/compile_java.py b/build/scripts/compile_java.py
index ef744afdbd..26cf8d69a7 100644
--- a/build/scripts/compile_java.py
+++ b/build/scripts/compile_java.py
@@ -1,6 +1,6 @@
import argparse
import contextlib
-from distutils import dir_util
+from shutil import copytree
import os
import shutil
import subprocess as sp
@@ -9,6 +9,7 @@ import zipfile
import sys
import process_command_files as pcf
+import java_command_file as jcf
def parse_args(args):
@@ -77,12 +78,10 @@ def main():
ts.write(' '.join(srcs))
if ktsrcs:
- temp_kt_sources_file = 'temp.kt.sources.list'
- with open(temp_kt_sources_file, 'w') as ts:
- ts.write(' '.join(ktsrcs + srcs))
kt_classes_dir = 'kt_cls'
mkdir_p(kt_classes_dir)
- sp.check_call(
+
+ jcf.call_java_with_command_file(
[
opts.java_bin,
'-Didea.max.content.load.filesize=30720',
@@ -93,16 +92,16 @@ def main():
'-d',
kt_classes_dir,
]
- + ktc_opts
- + ['@' + temp_kt_sources_file]
+ + ktc_opts,
+ wrapped_args=ktsrcs + srcs,
)
classpath = os.pathsep.join([kt_classes_dir, classpath])
if srcs:
- sp.check_call(
+ jcf.call_java_with_command_file(
[opts.javac_bin, '-nowarn', '-g', '-classpath', classpath, '-encoding', 'UTF-8', '-d', classes_dir]
- + javac_opts
- + ['@' + temp_sources_file]
+ + javac_opts,
+ wrapped_args=srcs,
)
for s in jsrcs:
@@ -115,7 +114,7 @@ def main():
zf.extractall(classes_dir)
if ktsrcs:
- dir_util.copy_tree(kt_classes_dir, classes_dir)
+ copytree(kt_classes_dir, classes_dir, dirs_exist_ok=True)
if opts.vcs_mf:
sp.check_call([opts.jar_bin, 'cfm', opts.jar_output, opts.vcs_mf, os.curdir], cwd=classes_dir)
diff --git a/build/scripts/java_command_file.py b/build/scripts/java_command_file.py
new file mode 100644
index 0000000000..06d8ea6985
--- /dev/null
+++ b/build/scripts/java_command_file.py
@@ -0,0 +1,43 @@
+import platform
+import subprocess as sp
+
+
+def _java_cmd_file_quote(s):
+ """ Wrap argument based on https://docs.oracle.com/en/java/javase/21/docs/specs/man/java.html#java-command-line-argument-files """
+ if not s:
+ return "''"
+
+ if not any(char.isspace() for char in s):
+ return s
+
+ return f'"{s.replace('\\', '\\\\')}"'
+
+
+def call_java_with_command_file(cmd, wrapped_args, **kwargs):
+ is_win = platform.system() == 'Windows'
+
+ args = cmd
+ args_to_wrap = wrapped_args
+ if is_win:
+ args = [cmd[0]]
+ args_to_wrap = cmd[1:] + args_to_wrap
+
+ commands_file = 'wrapped.args'
+ with open(commands_file, 'w') as f:
+ f.write(' '.join(_java_cmd_file_quote(arg) for arg in args_to_wrap))
+
+ if is_win:
+ # Some Windows machines has troubles with running cmd lines with `@` without shell=True
+ kwargs['shell'] = True
+
+ try:
+ return sp.check_output(
+ args + ["@" + commands_file],
+ **kwargs
+ )
+ except Exception as e:
+ if hasattr(e, "add_note"):
+ e.add_note(f"Original command: {cmd} {wrapped_args}")
+ e.add_note(f"Wrapped part: {wrapped_args}")
+
+ raise
diff --git a/build/scripts/ya.make b/build/scripts/ya.make
index aa51191383..76e2082dc3 100644
--- a/build/scripts/ya.make
+++ b/build/scripts/ya.make
@@ -90,6 +90,7 @@ ELSEIF (PY3)
generate_pom.py
generate_win_vfs.py
go_proto_wrapper.py
+ java_command_file.py
java_pack_to_file.py
jni_swig.py
kt_copy.py