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

62
LINES

< > BotCompany Repo | #1033538 // transpileForServer [backup]

JavaX fragment (include)

// can be false, it's compiled on the server anyway
// defaults to true
static new ThreadLocal<Bool> transpileForServer_compile;
static long transpileForServer_localTime;
sbool transpileForServer_forceJavacOnServer;
sbool transpileForServer_forceJavacWhenLibs;

svoid transpileForServer(S progID) {
  S server = tb_mainServer();
  S javax = loadSnippet(progID);
  print("Source: " + l(javax));
  
  long time = sysNow();
  
  time "Transpile" {
    transpileRaw_silent = false;
    S java;
    try {
      java = transpileRaw(javax);
    } on fail e {
      printLineContextAfterJavaCompilerError(e, loadProgramTextFile("error.java"));
    }
    print("Transpiled: " + l(java));
  }

  new L<S> libs;
  java = findTranslators2(java, libs);
  print("Libs: " + or2(joinWithComma(libs), "-"));

  S dehlibs = join(" ", libs);
  
  if (!isFalse(transpileForServer_compile!)) {
    File bytecode = javaCompile_overInternalBot(java, dehlibs);
    print("Bytecode: " + f2s(assertNotNull(bytecode)));
  }
  transpileForServer_localTime = sysNow()-time;
  
  // Compiled OK, let's upload
  S result = postPageWithCredentials(server + "/tb/upload-transpilation.php",
    id := psI(progID),
    transpilation := java,
    libs := lines(splitAtSpace(dehlibs)),
    computer := computerID());
    
  Matcher m = regexp("URL=/(dexcompile\\.php.*?)'", result);
  if (!m.find()) fail("Server said: " + result);
    
  S url = server + "/" + m.group(1);
  if (transpileForServer_forceJavacOnServer || transpileForServer_forceJavacWhenLibs && nempty(libs))
    url += "&javac=1";
    
  result = postPageWithCredentials(url);
  
  bool ok = result.contains("SUCCESS");
  sendToSnippetUpdatesBot("/transpile" + (ok ? "OK" : "Fail") 
    + "/" + psI(progID));
      
  if (!ok)
    fail("Server said: " + result);
    
  print("Transpiled & uploaded " + fsI(progID) + "!");
}

Author comment

Began life as a copy of #1011923

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033538
Snippet name: transpileForServer [backup]
Eternal ID of this version: #1033538/1
Text MD5: 6fad01a357a8ce4ede3c8b22a8ec2837
Author: stefan
Category: javax / transpiling
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-11-01 21:56:22
Source code size: 1916 bytes / 62 lines
Pitched / IR pitched: No / No
Views / Downloads: 122 / 144
Referenced in: [show references]