Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

91
LINES

< > BotCompany Repo | #1005575 // CompilerBot class - being replaced by CompilerBot2

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (10712L) is out of date.

1  
static class CompilerBot {
2  
  static bool verbose;
3  
4  
  static File compileSnippet(S snippetID) {
5  
    ret compileSnippet(snippetID, "");
6  
  }
7  
  
8  
  static Pair<File, S> compileSnippet2(S snippetID) {
9  
    ret compileSnippet2(snippetID, "");
10  
  }
11  
  
12  
  // returns jar path
13  
  static File compileSnippet(S snippetID, S javaTarget) {
14  
    ret compileSnippet2(snippetID, javaTarget).a;
15  
  }
16  
  
17  
  // returns jar path, Java source
18  
  static Pair<File, S> compileSnippet2(S snippetID, S javaTarget) {
19  
    S transpiledSrc = getServerTranspiled2(snippetID);
20  
    if (transpiledSrc == null) fail("Snippet not found or not public: " + snippetID);
21  
    int i = transpiledSrc.indexOf('\n');
22  
    String libs = transpiledSrc.substring(0, Math.max(0, i));
23  
    if (verbose)
24  
      print("Compiling snippet: " + snippetID + ". Libs: " + libs);
25  
    transpiledSrc = transpiledSrc.substring(i+1);
26  
    return pair(compile(transpiledSrc, libs, javaTarget, snippetID), transpiledSrc);
27  
  }
28  
29  
  static File compile(S src) {
30  
    ret compile(src, "");
31  
  }
32  
  
33  
  static File compile(S src, S libs) {
34  
    ret compile(src, libs, null);
35  
  }
36  
37  
  static File compile(S src, S dehlibs, S javaTarget) {
38  
    ret compile(src, dehlibs, javaTarget, null);
39  
  }
40  
  
41  
  static File compile(S src, S dehlibs, S javaTarget, S progID) {
42  
    if (verbose)
43  
      print("Compiling " + l(src) + " chars");
44  
      
45  
    // Note: This is different from the calculation in x30
46  
    // (might lead to programs being compiled twice)
47  
    S md5 = md5(dehlibs + "\n" + src + "\n" + fsIOpt(progID));
48  
    File jar = getJarFile(md5);
49  
    if (jar == null || jar.length() <= 22) {
50  
      // have to compile
51  
      
52  
      //print("Have to compile: " + progID + " / " + md5);
53  
      
54  
      LS tok = javaTok(src);
55  
      LS mainClass = findMainClass(tok);
56  
      bool canRename = mainClass != null && useDummyMainClasses() && isSnippetID(progID) && !tok_classHasModifier(mainClass, "public");
57  
      if (verbose)
58  
        print("useRenaming: " + useDummyMainClasses() + ", canRename: " + canRename + ", progID: " + progID);
59  
        
60  
      S mainClassName = joinNemptiesWithDot(tok_packageName(tok), or(getClassDeclarationName(mainClass), "main"));
61  
      
62  
      temp tempSetTL(javaCompileToJar_addMoreFiles, 
63  
        dir -> {
64  
          if (!eq(mainClassName, "main"))
65  
            saveTextFile(newFile(dir, "main-class"), mainClassName);
66  
          saveTextFile(newFile(dir, manifestPathInJar()), manifestTextForMainClass(mainClassName);
67  
        });
68  
69  
      javaCompileToJar_optionalRename(src, dehlibs, jar, canRename ? progID : null, progID);
70  
    } else {
71  
      if (verbose)
72  
        print("Getting classes from cache (" + jar.getAbsolutePath() + ", " + jar.length() + " bytes)");
73  
      touchFile(jar); // so we can find the unused ones easier
74  
    }
75  
    
76  
    ret jar;
77  
  }
78  
79  
  // look in non-virtual JavaX-Caches first (important for packaged programs)
80  
  // Edit: Huh? This is strange.
81  
  static File getJarFile(S md5) {
82  
    assertTrue(isMD5(md5));
83  
    S fileName = md5 + ".jar";
84  
    File f = newFile(destDir(), fileName);
85  
    ret fileExists(f) ? f : userDir(appendSlash(compilerBotDestDirSubName()) + fileName);
86  
  }
87  
  
88  
  /*swappable*/ static File destDir() {
89  
    ret compilerBotDestDir();
90  
  }
91  
}

Author comment

Began life as a copy of #1002203

download  show line numbers  debug dex  old transpilations   

Travelled to 19 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xprdwmaupziu

No comments. add comment

Snippet ID: #1005575
Snippet name: CompilerBot class - being replaced by CompilerBot2
Eternal ID of this version: #1005575/39
Text MD5: 65e379c439009a86e58052e6fab91d24
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-11-01 18:09:13
Source code size: 3282 bytes / 91 lines
Pitched / IR pitched: No / No
Views / Downloads: 766 / 7816
Version history: 38 change(s)
Referenced in: [show references]