Skip to content

Commit 82578af

Browse files
committed
Kotlin: Use @files for compiler arguments
Avoids problems with large line lengths.
1 parent a13678c commit 82578af

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

java/kotlin-extractor/build.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,37 @@ def run_process(cmd, capture_output=False):
8080
errors='replace'), file=sys.stderr)
8181
raise e
8282

83-
84-
def compile_to_dir(srcs, classpath, java_classpath, output):
83+
def write_arg_file(arg_file, args):
84+
with open(arg_file, 'w') as f:
85+
for arg in args:
86+
if "'" in arg:
87+
raise Exception('Single quote in argument: ' + arg)
88+
f.write("'" + arg.replace('\\', '/') + "'\n")
89+
90+
def compile_to_dir(build_dir, srcs, classpath, java_classpath, output):
8591
# Use kotlinc to compile .kt files:
92+
kotlin_arg_file = build_dir + '/kotlin.args'
93+
kotlin_args = ['-Werror',
94+
'-opt-in=kotlin.RequiresOptIn',
95+
'-d', output,
96+
'-module-name', 'codeql-kotlin-extractor',
97+
'-no-reflect', '-no-stdlib',
98+
'-jvm-target', '1.8',
99+
'-classpath', classpath] + srcs
100+
write_arg_file(kotlin_arg_file, kotlin_args)
86101
run_process([kotlinc,
87-
# kotlinc can default to 256M, which isn't enough when we are extracting the build
88-
'-J-Xmx2G',
89-
'-Werror',
90-
'-opt-in=kotlin.RequiresOptIn',
91-
'-d', output,
92-
'-module-name', 'codeql-kotlin-extractor',
93-
'-no-reflect', '-no-stdlib',
94-
'-jvm-target', '1.8',
95-
'-classpath', classpath] + srcs)
102+
# kotlinc can default to 256M, which isn't enough when we are extracting the build
103+
'-J-Xmx2G',
104+
'@' + kotlin_arg_file])
96105

97106
# Use javac to compile .java files, referencing the Kotlin class files:
98-
run_process([javac,
99-
'-d', output,
107+
java_arg_file = build_dir + '/java.args'
108+
java_args = ['-d', output,
100109
'-source', '8', '-target', '8',
101-
'-classpath', os.path.pathsep.join([output, classpath, java_classpath])] + [s for s in srcs if s.endswith(".java")])
110+
'-classpath', os.path.pathsep.join([output, classpath, java_classpath])] \
111+
+ [s for s in srcs if s.endswith(".java")]
112+
write_arg_file(java_arg_file, java_args)
113+
run_process([javac, '@' + java_arg_file])
102114

103115

104116
def compile_to_jar(build_dir, tmp_src_dir, srcs, classpath, java_classpath, output):
@@ -108,7 +120,7 @@ def compile_to_jar(build_dir, tmp_src_dir, srcs, classpath, java_classpath, outp
108120
shutil.rmtree(class_dir)
109121
os.makedirs(class_dir)
110122

111-
compile_to_dir(srcs, classpath, java_classpath, class_dir)
123+
compile_to_dir(build_dir, srcs, classpath, java_classpath, class_dir)
112124

113125
run_process(['jar', 'cf', output,
114126
'-C', class_dir, '.',

0 commit comments

Comments
 (0)