diff options
author | v-korovin <v-korovin@yandex-team.com> | 2024-06-13 12:27:45 +0300 |
---|---|---|
committer | v-korovin <v-korovin@yandex-team.com> | 2024-06-13 12:42:08 +0300 |
commit | be66f533d520f6ce67ee7386e807b85230b1c587 (patch) | |
tree | 88e0b03ba886fc672fdd99d3c3cda1032ac28061 /build | |
parent | 80050a7cd2d471849db213ff374ceeee5614c7e7 (diff) | |
download | ydb-be66f533d520f6ce67ee7386e807b85230b1c587.tar.gz |
Fix java command file in plugin
e43ef305d767fb94adc0f4f6e3901156fc3b7939
Diffstat (limited to 'build')
-rw-r--r-- | build/conf/java.conf | 2 | ||||
-rw-r--r-- | build/scripts/compile_java.py | 21 | ||||
-rw-r--r-- | build/scripts/java_command_file.py | 43 | ||||
-rw-r--r-- | build/scripts/ya.make | 1 |
4 files changed, 55 insertions, 12 deletions
diff --git a/build/conf/java.conf b/build/conf/java.conf index bebcd6bc1d..6cf0f9f96e 100644 --- a/build/conf/java.conf +++ b/build/conf/java.conf @@ -1387,7 +1387,7 @@ elsewhen ($JDK_VERSION == "") { otherwise { EXTERNAL_JAVA_JDK_RESOURCE=$JDK_RESOURCE } -COMPILE_JAVA=${cwd:ARCADIA_BUILD_ROOT} $YMAKE_PYTHON ${input:"build/scripts/compile_java.py"} --ya-start-command-file --java-bin $EXTERNAL_JAVA_JDK_RESOURCE/bin/java --javac-bin $EXTERNAL_JAVA_JDK_RESOURCE/bin/javac --jar-bin $JDK_RESOURCE/bin/jar --kotlin-compiler $KOTLIN_COMPILER_RESOURCE_GLOBAL/kotlin-compiler.jar $JAVA_VCS_MF_ARG $PACKAGE_PREFIX_ARGS --jar-output $TARGET --srcs-jar-output ${output;suf=-sources.jar:REALPRJNAME} $AUTO_INPUT DELIM $JAVAC_OPTS DELIM $MANAGED_PEERS_CLOSURE DELIM -no-stdlib -module-name $REALPRJNAME -jvm-target ${KOTLIN_JVM_TARGET} ${KOTLINC_OPTS_VALUE} --ya-end-command-file ${kv;hide:"p JV"} ${kv;hide:"pc light-blue"} ${kv;hide:"show_out"} ${requirements;hide:"cpu:2"} +COMPILE_JAVA=${cwd:ARCADIA_BUILD_ROOT} $YMAKE_PYTHON3 ${input:"build/scripts/compile_java.py"} --ya-start-command-file --java-bin $EXTERNAL_JAVA_JDK_RESOURCE/bin/java --javac-bin $EXTERNAL_JAVA_JDK_RESOURCE/bin/javac --jar-bin $JDK_RESOURCE/bin/jar --kotlin-compiler $KOTLIN_COMPILER_RESOURCE_GLOBAL/kotlin-compiler.jar $JAVA_VCS_MF_ARG $PACKAGE_PREFIX_ARGS --jar-output $TARGET --srcs-jar-output ${output;suf=-sources.jar:REALPRJNAME} $AUTO_INPUT DELIM $JAVAC_OPTS DELIM $MANAGED_PEERS_CLOSURE DELIM -no-stdlib -module-name $REALPRJNAME -jvm-target ${KOTLIN_JVM_TARGET} ${KOTLINC_OPTS_VALUE} --ya-end-command-file ${kv;hide:"p JV"} ${kv;hide:"pc light-blue"} ${kv;hide:"show_out"} ${requirements;hide:"cpu:2"} ${hide;input:"build/scripts/java_command_file.py"} ${hide;input:"build/scripts/process_command_files.py"} ARGS_DELIM="MACRO_CALLS_DELIM" 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 |