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

87
LINES

< > BotCompany Repo | #1033528 // CompilerBot2 [Java compiler stage 1] [replacement of CompilerBot]

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

Uses 3106K of libraries. Click here for Pure Java version (12605L/78K).

1  
// use only once per compilation
2  
sclass CompilerBot2 extends CompileJavaToJar {
3  
  bool verbose = true;
4  
  bool forceCompilation, dontCompile;
5  
  bool useRenaming = true;
6  
  bool addCompilationDate = true;
7  
8  
  bool didCompile;
9  
  
10  
  settable S mainClassForManifest;
11  
12  
  // returns jar path
13  
  File compileSnippet(S snippetID) {
14  
    src = getServerTranspiled2(snippetID);
15  
    if (src == null) fail("Snippet not found or not public: " + snippetID);
16  
    int i = src.indexOf('\n');
17  
    dehlibs = src.substring(0, Math.max(0, i));
18  
    if (verbose)
19  
      print("Compiling snippet: " + snippetID + ". Libs: " + dehlibs);
20  
    src = src.substring(i+1);
21  
    progID = snippetID;
22  
    ret compile();
23  
  }
24  
25  
  File compile() {
26  
    // Note: This is different from the calculation in x30
27  
    // (might lead to programs being compiled twice)
28  
    S md5 = md5(dehlibs + "\n" + src + "\n" + fsIOpt(progID));
29  
    File jar = getJarFile(md5);
30  
    
31  
    if (verbose)
32  
      print("Would compile " + l(src) + " chars (" + progID + "), md5=" + md5 + ", jar: " + jar);
33  
      
34  
    if (!dontCompile && (forceCompilation || jar.length() <= 22)) {
35  
      // have to compile
36  
      
37  
      print("Have to compile");
38  
39  
      bool canRename = false;
40  
      if (useRenaming) {
41  
        LS tok = javaTok(src);
42  
        LS mainClass = findMainClass(tok);
43  
        canRename = mainClass != null && useDummyMainClasses() && isSnippetID(progID) && !tok_classHasModifier(mainClass, "public");
44  
        if (verbose)
45  
          print("useRenaming: " + useDummyMainClasses() + ", canRename: " + canRename + ", progID: " + progID);
46  
      }
47  
        
48  
      //mainClassName = joinNemptiesWithDot(tok_packageName(tok), or(getClassDeclarationName(mainClass), "main"));
49  
      //print("CompilerBot2 mainClassName " + mainClassName);
50  
      
51  
      destJar = jar;
52  
      progIDForRename = canRename ? progID : null;
53  
      progID = progID;
54  
      run(); // in superclass
55  
      set didCompile;
56  
    } else {
57  
      if (verbose)
58  
        print("Getting classes from cache (" + jar.getAbsolutePath() + ", " + jar.length() + " bytes)");
59  
      touchFile(jar); // so we can find the unused ones easier
60  
    }
61  
    
62  
    ret jar;
63  
  }
64  
65  
  // look in non-virtual JavaX-Caches first
66  
  File getJarFile(S md5) {
67  
    assertTrue(isMD5(md5));
68  
    S fileName = md5 + ".jar";
69  
    File f = newFile(destDir(), fileName);
70  
    ret fileExists(f) ? f : userDir(appendSlash(compilerBotDestDirSubName()) + fileName);
71  
  }
72  
  
73  
  /*swappable*/ File destDir() {
74  
    ret compilerBotDestDir();
75  
  }
76  
  
77  
  void addMoreFiles(File dir) {
78  
    print("CompilerBot2 addMoreFiles: " + mainClassName);
79  
    if (!eq(mainClassName, "main"))
80  
      saveTextFile(newFile(dir, "main-class"), mainClassName);
81  
    S mc = or2(mainClassForManifest, mainClassName);
82  
    print("Using main class for manifest: " + mc);
83  
    saveTextFile(newFile(dir, manifestPathInJar()), manifestTextForMainClass(mc));
84  
    if (addCompilationDate)
85  
      saveTextFile(newFile(dir, "compilation-date.txt"), dateWithSecondsUTC());
86  
  }
87  
}

Author comment

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: 253 / 397
Version history: 25 change(s)
Referenced in: [show references]