Uses 3106K of libraries. Click here for Pure Java version (12605L/78K).
// use only once per compilation sclass CompilerBot2 extends CompileJavaToJar { bool verbose = true; bool forceCompilation, dontCompile; bool useRenaming = true; bool addCompilationDate = true; bool didCompile; settable S mainClassForManifest; // returns jar path File compileSnippet(S snippetID) { src = getServerTranspiled2(snippetID); if (src == null) fail("Snippet not found or not public: " + snippetID); int i = src.indexOf('\n'); dehlibs = src.substring(0, Math.max(0, i)); if (verbose) print("Compiling snippet: " + snippetID + ". Libs: " + dehlibs); src = src.substring(i+1); progID = snippetID; ret compile(); } File compile() { // Note: This is different from the calculation in x30 // (might lead to programs being compiled twice) S md5 = md5(dehlibs + "\n" + src + "\n" + fsIOpt(progID)); File jar = getJarFile(md5); if (verbose) print("Would compile " + l(src) + " chars (" + progID + "), md5=" + md5 + ", jar: " + jar); if (!dontCompile && (forceCompilation || jar.length() <= 22)) { // have to compile print("Have to compile"); bool canRename = false; if (useRenaming) { LS tok = javaTok(src); LS mainClass = findMainClass(tok); canRename = mainClass != null && useDummyMainClasses() && isSnippetID(progID) && !tok_classHasModifier(mainClass, "public"); if (verbose) print("useRenaming: " + useDummyMainClasses() + ", canRename: " + canRename + ", progID: " + progID); } //mainClassName = joinNemptiesWithDot(tok_packageName(tok), or(getClassDeclarationName(mainClass), "main")); //print("CompilerBot2 mainClassName " + mainClassName); destJar = jar; progIDForRename = canRename ? progID : null; progID = progID; run(); // in superclass set didCompile; } else { if (verbose) print("Getting classes from cache (" + jar.getAbsolutePath() + ", " + jar.length() + " bytes)"); touchFile(jar); // so we can find the unused ones easier } ret jar; } // look in non-virtual JavaX-Caches first File getJarFile(S md5) { assertTrue(isMD5(md5)); S fileName = md5 + ".jar"; File f = newFile(destDir(), fileName); ret fileExists(f) ? f : userDir(appendSlash(compilerBotDestDirSubName()) + fileName); } /*swappable*/ File destDir() { ret compilerBotDestDir(); } void addMoreFiles(File dir) { print("CompilerBot2 addMoreFiles: " + mainClassName); if (!eq(mainClassName, "main")) saveTextFile(newFile(dir, "main-class"), mainClassName); S mc = or2(mainClassForManifest, mainClassName); print("Using main class for manifest: " + mc); saveTextFile(newFile(dir, manifestPathInJar()), manifestTextForMainClass(mc)); if (addCompilationDate) saveTextFile(newFile(dir, "compilation-date.txt"), dateWithSecondsUTC()); } }
Began life as a copy of #1005575
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1033528 |
Snippet name: | CompilerBot2 [Java compiler stage 1] [replacement of CompilerBot] |
Eternal ID of this version: | #1033528/26 |
Text MD5: | 0a39826fd54985ad09db5eaf916b24df |
Transpilation MD5: | 664e27461684d6045135e5080ee28893 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-02-05 21:52:54 |
Source code size: | 3057 bytes / 87 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 254 / 398 |
Version history: | 25 change(s) |
Referenced in: | #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |