1 | // can be false, it's compiled on the server anyway |
2 | // defaults to true |
3 | static new ThreadLocal<Bool> transpileForServer_compile; |
4 | static long transpileForServer_localTime; |
5 | sbool transpileForServer_forceJavacOnServer; |
6 | sbool transpileForServer_forceJavacWhenLibs; |
7 | |
8 | svoid transpileForServer(S progID) { |
9 | S server = tb_mainServer(); |
10 | S javax = loadSnippet(progID); |
11 | print("Source: " + l(javax)); |
12 | |
13 | long time = sysNow(); |
14 | |
15 | time "Transpile" { |
16 | transpileRaw_silent = false; |
17 | S java; |
18 | try { |
19 | java = transpileRaw(javax); |
20 | } on fail e { |
21 | printLineContextAfterJavaCompilerError(e, loadProgramTextFile("error.java")); |
22 | } |
23 | print("Transpiled: " + l(java)); |
24 | } |
25 | |
26 | new L<S> libs; |
27 | java = findTranslators2(java, libs); |
28 | print("Libs: " + or2(joinWithComma(libs), "-")); |
29 | |
30 | S dehlibs = join(" ", libs); |
31 | |
32 | if (!isFalse(transpileForServer_compile!)) { |
33 | File bytecode = javaCompile_overInternalBot(java, dehlibs); |
34 | print("Bytecode: " + f2s(assertNotNull(bytecode))); |
35 | } |
36 | transpileForServer_localTime = sysNow()-time; |
37 | |
38 | // Compiled OK, let's upload |
39 | S result = postPageWithCredentials(server + "/tb/upload-transpilation.php", |
40 | id := psI(progID), |
41 | transpilation := java, |
42 | libs := lines(splitAtSpace(dehlibs)), |
43 | computer := computerID()); |
44 | |
45 | Matcher m = regexp("URL=/(dexcompile\\.php.*?)'", result); |
46 | if (!m.find()) fail("Server said: " + result); |
47 | |
48 | S url = server + "/" + m.group(1); |
49 | if (transpileForServer_forceJavacOnServer || transpileForServer_forceJavacWhenLibs && nempty(libs)) |
50 | url += "&javac=1"; |
51 | |
52 | result = postPageWithCredentials(url); |
53 | |
54 | bool ok = result.contains("SUCCESS"); |
55 | sendToSnippetUpdatesBot("/transpile" + (ok ? "OK" : "Fail") |
56 | + "/" + psI(progID)); |
57 | |
58 | if (!ok) |
59 | fail("Server said: " + result); |
60 | |
61 | print("Transpiled & uploaded " + fsI(progID) + "!"); |
62 | } |
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: | 124 / 146 |
Referenced in: | [show references] |