From 1fa48560c65a0dc29b08b0340ab9ab1ac1fad3a9 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Fri, 10 Dec 2021 18:51:12 +0300 Subject: [PATCH] C: add option to generate shorter output file names to workaround msvc bug --- .idea/runConfigurations/build_teavm_fast.xml | 56 ++++---- .../java/org/teavm/backend/c/CTarget.java | 29 ++-- .../backend/c/generate/ClassGenerator.java | 107 +-------------- .../c/generate/CodeGenerationVisitor.java | 4 +- .../backend/c/generate/FileNameProvider.java | 26 ++++ .../backend/c/generate/GenerationContext.java | 12 +- .../c/generate/GeneratorContextImpl.java | 6 +- .../backend/c/generate/IncludeManager.java | 9 +- .../generate/ShorteningFileNameProvider.java | 79 +++++++++++ .../c/generate/SimpleFileNameProvider.java | 128 ++++++++++++++++++ .../c/generate/SimpleIncludeManager.java | 3 +- .../java/org/teavm/tooling/TeaVMTool.java | 10 ++ .../teavm/tooling/builder/BuildStrategy.java | 2 + .../builder/InProcessBuildStrategy.java | 7 + .../tooling/builder/RemoteBuildStrategy.java | 5 + .../org/teavm/tooling/daemon/BuildDaemon.java | 1 + .../tooling/daemon/RemoteBuildRequest.java | 1 + .../org/teavm/maven/TeaVMCompileMojo.java | 4 + 18 files changed, 333 insertions(+), 156 deletions(-) create mode 100644 core/src/main/java/org/teavm/backend/c/generate/FileNameProvider.java create mode 100644 core/src/main/java/org/teavm/backend/c/generate/ShorteningFileNameProvider.java create mode 100644 core/src/main/java/org/teavm/backend/c/generate/SimpleFileNameProvider.java diff --git a/.idea/runConfigurations/build_teavm_fast.xml b/.idea/runConfigurations/build_teavm_fast.xml index 46d030f73..b32d7ea4c 100644 --- a/.idea/runConfigurations/build_teavm_fast.xml +++ b/.idea/runConfigurations/build_teavm_fast.xml @@ -1,35 +1,33 @@ - - + \ No newline at end of file diff --git a/core/src/main/java/org/teavm/backend/c/CTarget.java b/core/src/main/java/org/teavm/backend/c/CTarget.java index 4665e8486..8cdf140ce 100644 --- a/core/src/main/java/org/teavm/backend/c/CTarget.java +++ b/core/src/main/java/org/teavm/backend/c/CTarget.java @@ -41,9 +41,11 @@ import org.teavm.backend.c.generate.ClassGenerationContext; import org.teavm.backend.c.generate.ClassGenerator; import org.teavm.backend.c.generate.CodeGenerationVisitor; import org.teavm.backend.c.generate.CodeWriter; +import org.teavm.backend.c.generate.FileNameProvider; import org.teavm.backend.c.generate.GenerationContext; import org.teavm.backend.c.generate.IncludeManager; import org.teavm.backend.c.generate.OutputFileUtil; +import org.teavm.backend.c.generate.SimpleFileNameProvider; import org.teavm.backend.c.generate.SimpleIncludeManager; import org.teavm.backend.c.generate.SimpleStringPool; import org.teavm.backend.c.generate.StringPoolGenerator; @@ -154,6 +156,7 @@ public class CTarget implements TeaVMTarget, TeaVMCHost { private TeaVMTargetController controller; private NameProvider rawNameProvider; + private FileNameProvider fileNames = new SimpleFileNameProvider(); private ClassInitializerEliminator classInitializerEliminator; private ClassInitializerTransformer classInitializerTransformer; private ShadowStackTransformer shadowStackTransformer; @@ -214,6 +217,10 @@ public class CTarget implements TeaVMTarget, TeaVMCHost { this.obfuscated = obfuscated; } + public void setFileNames(FileNameProvider fileNames) { + this.fileNames = fileNames; + } + @Override public List getTransformers() { List transformers = new ArrayList<>(); @@ -402,8 +409,8 @@ public class CTarget implements TeaVMTarget, TeaVMCHost { boolean vmAssertions = Boolean.parseBoolean(System.getProperty("teavm.c.vmAssertions", "false")); boolean gcStats = Boolean.parseBoolean(System.getProperty("teavm.c.gcStats", "false")); GenerationContext context = new GenerationContext(vtableProvider, characteristics, - controller.getDependencyInfo(), stringPool, nameProvider, controller.getDiagnostics(), classes, - intrinsics, generators, asyncMethods::contains, buildTarget, + controller.getDependencyInfo(), stringPool, nameProvider, fileNames, + controller.getDiagnostics(), classes, intrinsics, generators, asyncMethods::contains, buildTarget, controller.getClassInitializerInfo(), incremental, longjmpUsed, vmAssertions, vmAssertions || heapDump, obfuscated); @@ -497,7 +504,7 @@ public class CTarget implements TeaVMTarget, TeaVMCHost { if (cls != null) { classGenerator.generateClass(writer, headerWriter, cls); } - String name = ClassGenerator.fileName(className); + String name = fileNames.fileName(className); OutputFileUtil.write(writer, name + ".c", buildTarget); OutputFileUtil.write(headerWriter, name + ".h", buildTarget); if (incremental) { @@ -512,7 +519,7 @@ public class CTarget implements TeaVMTarget, TeaVMCHost { BufferedCodeWriter writer = new BufferedCodeWriter(false); BufferedCodeWriter headerWriter = new BufferedCodeWriter(false); classGenerator.generateType(writer, headerWriter, type); - String name = ClassGenerator.fileName(type); + String name = fileNames.fileName(type); OutputFileUtil.write(writer, name + ".c", buildTarget); OutputFileUtil.write(headerWriter, name + ".h", buildTarget); if (incremental) { @@ -525,7 +532,7 @@ public class CTarget implements TeaVMTarget, TeaVMCHost { Collection classNames) throws IOException { BufferedCodeWriter writer = new BufferedCodeWriter(false); - IncludeManager includes = new SimpleIncludeManager(writer); + IncludeManager includes = new SimpleIncludeManager(context.getFileNames(), writer); includes.init("callsites.c"); if (!incremental) { @@ -600,7 +607,7 @@ public class CTarget implements TeaVMTarget, TeaVMCHost { private void generateStrings(BuildTarget buildTarget, GenerationContext context) throws IOException { BufferedCodeWriter writer = new BufferedCodeWriter(false); - IncludeManager includes = new SimpleIncludeManager(writer); + IncludeManager includes = new SimpleIncludeManager(context.getFileNames(), writer); includes.init("strings.c"); BufferedCodeWriter headerWriter = new BufferedCodeWriter(false); @@ -664,7 +671,7 @@ public class CTarget implements TeaVMTarget, TeaVMCHost { } private void generateSpecialFunctions(GenerationContext context, CodeWriter writer) { - IncludeManager includes = new SimpleIncludeManager(writer); + IncludeManager includes = new SimpleIncludeManager(context.getFileNames(), writer); includes.init("special.c"); includes.includePath("core.h"); includes.includePath("string.h"); @@ -731,7 +738,7 @@ public class CTarget implements TeaVMTarget, TeaVMCHost { private void generateMainFile(GenerationContext context, ListableClassHolderSource classes, List types, BuildTarget buildTarget) throws IOException { BufferedCodeWriter writer = new BufferedCodeWriter(false); - IncludeManager includes = new SimpleIncludeManager(writer); + IncludeManager includes = new SimpleIncludeManager(fileNames, writer); includes.init("main.c"); includes.includePath("runtime.h"); includes.includePath("strings.h"); @@ -750,7 +757,7 @@ public class CTarget implements TeaVMTarget, TeaVMCHost { writer.println("#define __USE_XOPEN"); writer.println("#define _GNU_SOURCE"); - IncludeManager includes = new SimpleIncludeManager(writer); + IncludeManager includes = new SimpleIncludeManager(fileNames, writer); includes.init("all.c"); for (String file : allFiles) { includes.includePath(file); @@ -787,10 +794,10 @@ public class CTarget implements TeaVMTarget, TeaVMCHost { files.add("virtcall.c"); for (String className : classes.getClassNames()) { - files.add(ClassGenerator.fileName(className) + ".c"); + files.add(fileNames.fileName(className) + ".c"); } for (ValueType type : types) { - files.add(ClassGenerator.fileName(type) + ".c"); + files.add(fileNames.fileName(type) + ".c"); } files.add("main.c"); diff --git a/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java b/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java index 1c4f04d01..3f05e4cc2 100644 --- a/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java +++ b/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java @@ -208,7 +208,7 @@ public class ClassGenerator { public void generateClass(CodeWriter writer, CodeWriter headerWriter, ClassHolder cls) { ValueType type = ValueType.object(cls.getName()); - init(writer, headerWriter, fileName(cls.getName()), type); + init(writer, headerWriter, context.getFileNames().fileName(cls.getName()), type); generateStringPoolDecl(type); generateClassStructure(cls); @@ -228,7 +228,7 @@ public class ClassGenerator { } public void generateType(CodeWriter writer, CodeWriter headerWriter, ValueType type) { - init(writer, headerWriter, fileName(type), type); + init(writer, headerWriter, context.getFileNames().fileName(type), type); generateStringPoolDecl(type); includes.includeType(type); generateVirtualTable(type); @@ -239,14 +239,14 @@ public class ClassGenerator { staticGcRoots = null; classLayout = null; - includes = new SimpleIncludeManager(writer); + includes = new SimpleIncludeManager(context.getFileNames(), writer); includes.init(fileName + ".c"); prologueWriter = writer.fragment(); codeWriter = writer.fragment(); this.headerWriter = headerWriter; headerWriter.println("#pragma once"); - headerIncludes = new SimpleIncludeManager(headerWriter); + headerIncludes = new SimpleIncludeManager(context.getFileNames(), headerWriter); headerIncludes.init(fileName + ".h"); headerIncludes.includePath("runtime.h"); @@ -1438,103 +1438,4 @@ public class ClassGenerator { break; } } - - public static String fileName(ValueType type) { - StringBuilder sb = new StringBuilder(); - fileNameRec(type, sb); - return sb.toString(); - } - - private static void fileNameRec(ValueType type, StringBuilder sb) { - if (type instanceof ValueType.Object) { - sb.append("classes/"); - escape(((ValueType.Object) type).getClassName(), sb); - } else if (type instanceof ValueType.Array) { - sb.append("arrays/"); - fileNameRec(((ValueType.Array) type).getItemType(), sb); - } else if (type instanceof ValueType.Primitive) { - sb.append("primitives/"); - switch (((ValueType.Primitive) type).getKind()) { - case BOOLEAN: - sb.append("boolean"); - break; - case BYTE: - sb.append("byte"); - break; - case SHORT: - sb.append("short"); - break; - case CHARACTER: - sb.append("char"); - break; - case INTEGER: - sb.append("int"); - break; - case LONG: - sb.append("long"); - break; - case FLOAT: - sb.append("float"); - break; - case DOUBLE: - sb.append("double"); - break; - } - } else if (type == ValueType.VOID) { - sb.append("primitives/void"); - } - } - - public static String fileName(String className) { - StringBuilder sb = new StringBuilder("classes/"); - escape(className, sb); - return sb.toString(); - } - - static void escape(String className, StringBuilder sb) { - for (int i = 0; i < className.length(); ++i) { - char c = className.charAt(i); - switch (c) { - case '.': - sb.append('/'); - break; - case '@': - sb.append("@@"); - break; - case '/': - sb.append("@s"); - break; - case '\\': - sb.append("@b"); - break; - case ':': - sb.append("@c"); - break; - case ';': - sb.append("@e"); - break; - case '*': - sb.append("@m"); - break; - case '"': - sb.append("@q"); - break; - case '<': - sb.append("@l"); - break; - case '>': - sb.append("@g"); - break; - case '|': - sb.append("@p"); - break; - case '$': - sb.append("@d"); - break; - default: - sb.append(c); - break; - } - } - } } diff --git a/core/src/main/java/org/teavm/backend/c/generate/CodeGenerationVisitor.java b/core/src/main/java/org/teavm/backend/c/generate/CodeGenerationVisitor.java index 077900ffe..408562852 100644 --- a/core/src/main/java/org/teavm/backend/c/generate/CodeGenerationVisitor.java +++ b/core/src/main/java/org/teavm/backend/c/generate/CodeGenerationVisitor.java @@ -1565,9 +1565,7 @@ public class CodeGenerationVisitor implements ExprVisitor, StatementVisitor { @Override public String escapeFileName(String name) { - StringBuilder sb = new StringBuilder(); - ClassGenerator.escape(name, sb); - return sb.toString(); + return context.getFileNames().escapeName(name); } @Override diff --git a/core/src/main/java/org/teavm/backend/c/generate/FileNameProvider.java b/core/src/main/java/org/teavm/backend/c/generate/FileNameProvider.java new file mode 100644 index 000000000..8888bbe44 --- /dev/null +++ b/core/src/main/java/org/teavm/backend/c/generate/FileNameProvider.java @@ -0,0 +1,26 @@ +/* + * Copyright 2021 konso. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.backend.c.generate; + +import org.teavm.model.ValueType; + +public interface FileNameProvider { + String fileName(String className); + + String fileName(ValueType type); + + String escapeName(String name); +} diff --git a/core/src/main/java/org/teavm/backend/c/generate/GenerationContext.java b/core/src/main/java/org/teavm/backend/c/generate/GenerationContext.java index 81cecda7d..64b5bdf17 100644 --- a/core/src/main/java/org/teavm/backend/c/generate/GenerationContext.java +++ b/core/src/main/java/org/teavm/backend/c/generate/GenerationContext.java @@ -38,6 +38,7 @@ public class GenerationContext { private DependencyInfo dependencies; private StringPool stringPool; private NameProvider names; + private FileNameProvider fileNames; private Diagnostics diagnostics; private ClassReaderSource classSource; private List intrinsics; @@ -53,9 +54,9 @@ public class GenerationContext { private boolean obfuscated; public GenerationContext(VirtualTableProvider virtualTableProvider, Characteristics characteristics, - DependencyInfo dependencies, StringPool stringPool, NameProvider names, Diagnostics diagnostics, - ClassReaderSource classSource, List intrinsics, List generators, - Predicate asyncMethods, BuildTarget buildTarget, + DependencyInfo dependencies, StringPool stringPool, NameProvider names, FileNameProvider fileNames, + Diagnostics diagnostics, ClassReaderSource classSource, List intrinsics, + List generators, Predicate asyncMethods, BuildTarget buildTarget, ClassInitializerInfo classInitializerInfo, boolean incremental, boolean longjmp, boolean vmAssertions, boolean heapDump, boolean obfuscated) { this.virtualTableProvider = virtualTableProvider; @@ -63,6 +64,7 @@ public class GenerationContext { this.dependencies = dependencies; this.stringPool = stringPool; this.names = names; + this.fileNames = fileNames; this.diagnostics = diagnostics; this.classSource = classSource; this.intrinsics = new ArrayList<>(intrinsics); @@ -105,6 +107,10 @@ public class GenerationContext { return names; } + public FileNameProvider getFileNames() { + return fileNames; + } + public Diagnostics getDiagnostics() { return diagnostics; } diff --git a/core/src/main/java/org/teavm/backend/c/generate/GeneratorContextImpl.java b/core/src/main/java/org/teavm/backend/c/generate/GeneratorContextImpl.java index 876902c84..29eda11bb 100644 --- a/core/src/main/java/org/teavm/backend/c/generate/GeneratorContextImpl.java +++ b/core/src/main/java/org/teavm/backend/c/generate/GeneratorContextImpl.java @@ -121,7 +121,7 @@ class GeneratorContextImpl implements GeneratorContext { } private FileGenerator createFile(BufferedCodeWriter writer, String path) { - IncludeManager includes = new SimpleIncludeManager(writer); + IncludeManager includes = new SimpleIncludeManager(context.getFileNames(), writer); includes.init(path); FileGeneratorImpl generator = new FileGeneratorImpl(path, writer, includes); fileGenerators.add(generator); @@ -130,9 +130,7 @@ class GeneratorContextImpl implements GeneratorContext { @Override public String escapeFileName(String name) { - StringBuilder sb = new StringBuilder(); - ClassGenerator.escape(name, sb); - return sb.toString(); + return context.getFileNames().escapeName(name); } @Override diff --git a/core/src/main/java/org/teavm/backend/c/generate/IncludeManager.java b/core/src/main/java/org/teavm/backend/c/generate/IncludeManager.java index 2d2f6b4b9..b248758e5 100644 --- a/core/src/main/java/org/teavm/backend/c/generate/IncludeManager.java +++ b/core/src/main/java/org/teavm/backend/c/generate/IncludeManager.java @@ -20,11 +20,16 @@ import java.util.Set; import org.teavm.model.ValueType; public abstract class IncludeManager { + private FileNameProvider fileNames; private String currentFileName; private Set includedFiles = new HashSet<>(); private Set includedClasses = new HashSet<>(); private Set includedTypes = new HashSet<>(); + public IncludeManager(FileNameProvider fileNames) { + this.fileNames = fileNames; + } + public void init(String currentFileName) { this.currentFileName = currentFileName; includedFiles.clear(); @@ -63,14 +68,14 @@ public abstract class IncludeManager { if (!includedClasses.add(className)) { return; } - includePath(ClassGenerator.fileName(className) + ".h"); + includePath(fileNames.fileName(className) + ".h"); } public void includeType(ValueType type) { if (!includedTypes.add(type)) { return; } - includePath(ClassGenerator.fileName(type) + ".h"); + includePath(fileNames.fileName(type) + ".h"); } public void includePath(String fileName) { diff --git a/core/src/main/java/org/teavm/backend/c/generate/ShorteningFileNameProvider.java b/core/src/main/java/org/teavm/backend/c/generate/ShorteningFileNameProvider.java new file mode 100644 index 000000000..95a44b10f --- /dev/null +++ b/core/src/main/java/org/teavm/backend/c/generate/ShorteningFileNameProvider.java @@ -0,0 +1,79 @@ +/* + * Copyright 2021 konso. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.backend.c.generate; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.teavm.model.ValueType; + +public class ShorteningFileNameProvider implements FileNameProvider { + private final FileNameProvider nameProvider; + private final Map names = new HashMap<>(); + private final Set usedNames = new HashSet<>(); + + public ShorteningFileNameProvider(FileNameProvider nameProvider) { + this.nameProvider = nameProvider; + } + + @Override + public String fileName(String className) { + return unique(shorten(nameProvider.fileName(className))); + } + + @Override + public String fileName(ValueType type) { + return unique(shorten(nameProvider.fileName(type))); + } + + @Override + public String escapeName(String name) { + return unique(shorten(nameProvider.escapeName(name))); + } + + private String unique(String name) { + return names.computeIfAbsent(name, n -> { + if (usedNames.add(n)) { + return n; + } + int suffix = 1; + while (true) { + String candidate = n + "_" + suffix++; + if (usedNames.add(candidate)) { + return candidate; + } + } + }); + } + + private static String shorten(String name) { + StringBuilder sb = new StringBuilder(); + int index = 0; + while (true) { + int next = name.indexOf('/', index); + if (next < 0) { + break; + } + if (next > index) { + sb.append(name.charAt(index)); + } + sb.append('/'); + index = next + 1; + } + return sb.append(name, index, name.length()).toString(); + } +} diff --git a/core/src/main/java/org/teavm/backend/c/generate/SimpleFileNameProvider.java b/core/src/main/java/org/teavm/backend/c/generate/SimpleFileNameProvider.java new file mode 100644 index 000000000..40b1f3adb --- /dev/null +++ b/core/src/main/java/org/teavm/backend/c/generate/SimpleFileNameProvider.java @@ -0,0 +1,128 @@ +/* + * Copyright 2021 konso. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.backend.c.generate; + +import org.teavm.model.ValueType; + +public class SimpleFileNameProvider implements FileNameProvider { + @Override + public String fileName(String className) { + StringBuilder sb = new StringBuilder("classes/"); + escape(className, sb); + return sb.toString(); + } + + @Override + public String fileName(ValueType type) { + StringBuilder sb = new StringBuilder(); + fileNameRec(type, sb); + return sb.toString(); + } + + private static void fileNameRec(ValueType type, StringBuilder sb) { + if (type instanceof ValueType.Object) { + sb.append("classes/"); + escape(((ValueType.Object) type).getClassName(), sb); + } else if (type instanceof ValueType.Array) { + sb.append("arrays/"); + fileNameRec(((ValueType.Array) type).getItemType(), sb); + } else if (type instanceof ValueType.Primitive) { + sb.append("primitives/"); + switch (((ValueType.Primitive) type).getKind()) { + case BOOLEAN: + sb.append("boolean"); + break; + case BYTE: + sb.append("byte"); + break; + case SHORT: + sb.append("short"); + break; + case CHARACTER: + sb.append("char"); + break; + case INTEGER: + sb.append("int"); + break; + case LONG: + sb.append("long"); + break; + case FLOAT: + sb.append("float"); + break; + case DOUBLE: + sb.append("double"); + break; + } + } else if (type == ValueType.VOID) { + sb.append("primitives/void"); + } + } + + @Override + public String escapeName(String name) { + StringBuilder sb = new StringBuilder(); + escape(name, sb); + return sb.toString(); + } + + private static void escape(String className, StringBuilder sb) { + for (int i = 0; i < className.length(); ++i) { + char c = className.charAt(i); + switch (c) { + case '.': + sb.append('/'); + break; + case '@': + sb.append("@@"); + break; + case '/': + sb.append("@s"); + break; + case '\\': + sb.append("@b"); + break; + case ':': + sb.append("@c"); + break; + case ';': + sb.append("@e"); + break; + case '*': + sb.append("@m"); + break; + case '"': + sb.append("@q"); + break; + case '<': + sb.append("@l"); + break; + case '>': + sb.append("@g"); + break; + case '|': + sb.append("@p"); + break; + case '$': + sb.append("@d"); + break; + default: + sb.append(c); + break; + } + } + } +} diff --git a/core/src/main/java/org/teavm/backend/c/generate/SimpleIncludeManager.java b/core/src/main/java/org/teavm/backend/c/generate/SimpleIncludeManager.java index c0a3b212b..7ce74e52d 100644 --- a/core/src/main/java/org/teavm/backend/c/generate/SimpleIncludeManager.java +++ b/core/src/main/java/org/teavm/backend/c/generate/SimpleIncludeManager.java @@ -23,7 +23,8 @@ public class SimpleIncludeManager extends IncludeManager { private CodeWriter writer; private CodeWriter emptyLine; - public SimpleIncludeManager(CodeWriter writer) { + public SimpleIncludeManager(FileNameProvider fileNames, CodeWriter writer) { + super(fileNames); this.writer = writer.fragment(); emptyLine = writer.fragment(); } diff --git a/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java b/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java index 8a1b81a7f..14d8c8476 100644 --- a/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java +++ b/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java @@ -34,6 +34,8 @@ import java.util.Properties; import java.util.Set; import org.teavm.backend.c.CTarget; import org.teavm.backend.c.generate.CNameProvider; +import org.teavm.backend.c.generate.ShorteningFileNameProvider; +import org.teavm.backend.c.generate.SimpleFileNameProvider; import org.teavm.backend.javascript.JavaScriptTarget; import org.teavm.backend.wasm.WasmTarget; import org.teavm.backend.wasm.render.WasmBinaryVersion; @@ -108,6 +110,7 @@ public class TeaVMTool { private ReferenceCache referenceCache; private boolean longjmpSupported = true; private boolean heapDump; + private boolean shortFileNames; public File getTargetDirectory() { return targetDirectory; @@ -261,6 +264,10 @@ public class TeaVMTool { this.heapDump = heapDump; } + public void setShortFileNames(boolean shortFileNames) { + this.shortFileNames = shortFileNames; + } + public void setProgressListener(TeaVMProgressListener progressListener) { this.progressListener = progressListener; } @@ -342,6 +349,9 @@ public class TeaVMTool { cTarget.setLongjmpUsed(longjmpSupported); cTarget.setHeapDump(heapDump); cTarget.setObfuscated(obfuscated); + cTarget.setFileNames(shortFileNames + ? new ShorteningFileNameProvider(new SimpleFileNameProvider()) + : new SimpleFileNameProvider()); return cTarget; } diff --git a/tools/core/src/main/java/org/teavm/tooling/builder/BuildStrategy.java b/tools/core/src/main/java/org/teavm/tooling/builder/BuildStrategy.java index 577499582..5b1ea9cd7 100644 --- a/tools/core/src/main/java/org/teavm/tooling/builder/BuildStrategy.java +++ b/tools/core/src/main/java/org/teavm/tooling/builder/BuildStrategy.java @@ -82,5 +82,7 @@ public interface BuildStrategy { void setHeapDump(boolean heapDump); + void setShortFileNames(boolean shortFileNames); + BuildResult build() throws BuildException; } diff --git a/tools/core/src/main/java/org/teavm/tooling/builder/InProcessBuildStrategy.java b/tools/core/src/main/java/org/teavm/tooling/builder/InProcessBuildStrategy.java index 10c173b8e..8310db04f 100644 --- a/tools/core/src/main/java/org/teavm/tooling/builder/InProcessBuildStrategy.java +++ b/tools/core/src/main/java/org/teavm/tooling/builder/InProcessBuildStrategy.java @@ -68,6 +68,7 @@ public class InProcessBuildStrategy implements BuildStrategy { private TeaVMProgressListener progressListener; private Properties properties = new Properties(); private TeaVMToolLog log = new EmptyTeaVMToolLog(); + private boolean shortFileNames; public InProcessBuildStrategy(ClassLoaderFactory classLoaderFactory) { this.classLoaderFactory = classLoaderFactory; @@ -220,6 +221,11 @@ public class InProcessBuildStrategy implements BuildStrategy { this.heapDump = heapDump; } + @Override + public void setShortFileNames(boolean shortFileNames) { + this.shortFileNames = shortFileNames; + } + @Override public BuildResult build() throws BuildException { TeaVMTool tool = new TeaVMTool(); @@ -250,6 +256,7 @@ public class InProcessBuildStrategy implements BuildStrategy { tool.setMaxHeapSize(maxHeapSize); tool.setLongjmpSupported(longjmpSupported); tool.setHeapDump(heapDump); + tool.setShortFileNames(shortFileNames); tool.getProperties().putAll(properties); diff --git a/tools/core/src/main/java/org/teavm/tooling/builder/RemoteBuildStrategy.java b/tools/core/src/main/java/org/teavm/tooling/builder/RemoteBuildStrategy.java index 96c9eefc7..165bc9068 100644 --- a/tools/core/src/main/java/org/teavm/tooling/builder/RemoteBuildStrategy.java +++ b/tools/core/src/main/java/org/teavm/tooling/builder/RemoteBuildStrategy.java @@ -195,6 +195,11 @@ public class RemoteBuildStrategy implements BuildStrategy { request.heapDump = heapDump; } + @Override + public void setShortFileNames(boolean shortFileNames) { + request.shortFileNames = shortFileNames; + } + @Override public BuildResult build() throws BuildException { RemoteBuildResponse response; diff --git a/tools/core/src/main/java/org/teavm/tooling/daemon/BuildDaemon.java b/tools/core/src/main/java/org/teavm/tooling/daemon/BuildDaemon.java index e24e8b911..fea6b6665 100644 --- a/tools/core/src/main/java/org/teavm/tooling/daemon/BuildDaemon.java +++ b/tools/core/src/main/java/org/teavm/tooling/daemon/BuildDaemon.java @@ -163,6 +163,7 @@ public class BuildDaemon extends UnicastRemoteObject implements RemoteBuildServi tool.setMaxHeapSize(request.maxHeapSize); tool.setLongjmpSupported(request.longjmpSupported); tool.setHeapDump(request.heapDump); + tool.setShortFileNames(request.shortFileNames); for (String sourceDirectory : request.sourceDirectories) { tool.addSourceFileProvider(new DirectorySourceFileProvider(new File(sourceDirectory))); diff --git a/tools/core/src/main/java/org/teavm/tooling/daemon/RemoteBuildRequest.java b/tools/core/src/main/java/org/teavm/tooling/daemon/RemoteBuildRequest.java index f1bef4f26..20edaa785 100644 --- a/tools/core/src/main/java/org/teavm/tooling/daemon/RemoteBuildRequest.java +++ b/tools/core/src/main/java/org/teavm/tooling/daemon/RemoteBuildRequest.java @@ -50,4 +50,5 @@ public class RemoteBuildRequest implements Serializable { public int maxHeapSize; public boolean longjmpSupported; public boolean heapDump; + public boolean shortFileNames; } diff --git a/tools/maven/plugin/src/main/java/org/teavm/maven/TeaVMCompileMojo.java b/tools/maven/plugin/src/main/java/org/teavm/maven/TeaVMCompileMojo.java index 752edc4c2..d02f6746a 100644 --- a/tools/maven/plugin/src/main/java/org/teavm/maven/TeaVMCompileMojo.java +++ b/tools/maven/plugin/src/main/java/org/teavm/maven/TeaVMCompileMojo.java @@ -158,6 +158,9 @@ public class TeaVMCompileMojo extends AbstractMojo { @Parameter(property = "teavm.heapDump", defaultValue = "false") private boolean heapDump; + @Parameter(property = "teavm.shortFileNames", defaultValue = "false") + private boolean shortFileNames; + private void setupBuilder(BuildStrategy builder) throws MojoExecutionException { builder.setLog(new MavenTeaVMToolLog(getLog())); try { @@ -182,6 +185,7 @@ public class TeaVMCompileMojo extends AbstractMojo { builder.setSourceFilesCopied(sourceFilesCopied); builder.setMinHeapSize(minHeapSize * 1024 * 1024); builder.setMaxHeapSize(maxHeapSize * 1024 * 1024); + builder.setShortFileNames(shortFileNames); } catch (RuntimeException e) { throw new MojoExecutionException("Unexpected error occurred", e); }