This repository has been archived by the owner on Dec 10, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#43 Download haxe compiler automatically
- First try
- Loading branch information
Showing
14 changed files
with
469 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.jtransc.gen.haxe | ||
|
||
import com.jtransc.JTranscSystem | ||
import com.jtransc.error.invalidOp | ||
import com.jtransc.log.log | ||
import com.jtransc.vfs.* | ||
import java.io.File | ||
import java.net.URL | ||
|
||
object HaxeCompiler { | ||
val HaxeVersion = "3.3.0-rc.1" | ||
|
||
val haxeCompilerFile: String by lazy { | ||
//"haxe-$HaxeVersion-linux32.tar.gz" | ||
if (JTranscSystem.isWindows()) "haxe-$HaxeVersion-win.zip" | ||
else if (JTranscSystem.isMac()) "haxe-$HaxeVersion-osx.tar.gz" | ||
else if (JTranscSystem.isLinux() && JTranscSystem.isOs32()) "haxe-$HaxeVersion-linux32.tar.gz" | ||
else if (JTranscSystem.isLinux() && JTranscSystem.isOs64()) "haxe-$HaxeVersion-linux64.tar.gz" | ||
else invalidOp("Not supported operaning system. Just supporting windows, osx and linux.") | ||
} | ||
|
||
//http://haxe.org/website-content/downloads/3.3.0-rc.1/downloads/haxe-3.3.0-rc.1-win.zip | ||
val haxeCompilerUrl: URL by lazy { URL("http://haxe.org/website-content/downloads/$HaxeVersion/downloads/$haxeCompilerFile") } | ||
val jtranscFolder: String by lazy { JTranscSystem.getUserHome() + "/.jtransc" } | ||
|
||
val haxeCompilerUrlVfs: SyncVfsFile by lazy { UrlVfs(haxeCompilerUrl) } | ||
val haxeCompilerLocalFileVfs: SyncVfsFile by lazy { LocalVfsEnsureDirs(File(jtranscFolder)).access(haxeCompilerFile) } | ||
|
||
val haxeCompilerLocalFolderVfs: SyncVfsFile by lazy { LocalVfsEnsureDirs(File("$jtranscFolder/$HaxeVersion")) } | ||
|
||
fun getHaxeTargetLibraries(subtarget: String): List<String> = when (subtarget) { | ||
"cpp", "windows", "linux", "mac", "osx" -> listOf("hxcpp") | ||
"c#", "cs", "csharp" -> listOf("hxcs") | ||
"java", "jvm" -> listOf("hxjava") | ||
else -> listOf() | ||
} | ||
|
||
|
||
fun ensureHaxeCompilerVfs(): SyncVfsFile { | ||
log.info("ensureHaxeCompilerVfs:") | ||
if (!haxeCompilerLocalFileVfs.exists) { | ||
log.info("Downloading haxe: $haxeCompilerUrl...") | ||
haxeCompilerUrlVfs.copyTo(haxeCompilerLocalFileVfs) | ||
} | ||
if (!haxeCompilerLocalFolderVfs["std"].exists) { | ||
val compvfs = CompressedVfs(haxeCompilerLocalFileVfs.realfile) | ||
val compvfsBase = compvfs.firstRecursive { it.file.name == "std" }.file.parent | ||
compvfsBase.copyTreeTo(haxeCompilerLocalFolderVfs) | ||
} | ||
|
||
if (!haxeCompilerLocalFolderVfs["lib"].exists) { | ||
haxeCompilerLocalFolderVfs.passthru("haxelib", "setup", haxeCompilerLocalFolderVfs["lib"].realpathOS) | ||
} | ||
|
||
return haxeCompilerLocalFolderVfs | ||
} | ||
|
||
fun ensureHaxeSubtarget(subtarget: String) { | ||
ensureHaxeCompilerVfs() | ||
|
||
for (lib in getHaxeTargetLibraries(subtarget)) { | ||
HaxeLib.installIfNotExists(HaxeLib.LibraryRef.fromVersion(lib)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,41 @@ | ||
package com.jtransc.gen.haxe | ||
|
||
import com.jtransc.text.toUcFirst | ||
import com.jtransc.vfs.CwdVfs | ||
|
||
object HaxeLib { | ||
data class LibraryRef(val name: String, val version: String) { | ||
val id = name.toUcFirst() // Remove symbols! | ||
val nameWithVersion = "$name:$version" | ||
val nameWithVersion = if (version.isNotEmpty()) "$name:$version" else "$name" | ||
|
||
companion object { | ||
fun fromVersion(it:String): LibraryRef { | ||
fun fromVersion(it: String): LibraryRef { | ||
val parts = it.split(':') | ||
return LibraryRef(parts[0], parts[1]) | ||
return LibraryRef(parts.getOrElse(0) { "" }, parts.getOrElse(1) { "" }) | ||
} | ||
} | ||
} | ||
|
||
val vfs by lazy { CwdVfs() } | ||
val vfs by lazy { HaxeCompiler.ensureHaxeCompilerVfs() } | ||
|
||
fun exists(lib: LibraryRef):Boolean { | ||
fun exists(lib: LibraryRef): Boolean { | ||
return vfs.exec("haxelib", "--always", "path", lib.nameWithVersion).success | ||
} | ||
|
||
fun install(lib: LibraryRef) { | ||
vfs.passthru("haxelib", "--always", "install", lib.name, lib.version) | ||
if (lib.version.isEmpty()) { | ||
vfs.passthru("haxelib", "--always", "install", lib.name) | ||
} else { | ||
vfs.passthru("haxelib", "--always", "install", lib.name, lib.version) | ||
} | ||
} | ||
|
||
//fun downloadHaxeCompiler() { | ||
//} | ||
|
||
fun installIfNotExists(lib: LibraryRef) { | ||
if (!exists(lib)) { | ||
install(lib) | ||
} | ||
} | ||
} | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
jtransc-gen-haxe/test/com/jtransc/gen/haxe/CompilerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.jtransc.gen.haxe | ||
|
||
import org.junit.Test | ||
|
||
class CompilerTest { | ||
@Test | ||
fun testEnsureHaxeCompilerVfs() { | ||
HaxeCompiler.ensureHaxeCompilerVfs() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.jtransc.numeric | ||
|
||
private fun roundUp(numToRound:Int, multiple:Int): Int | ||
{ | ||
if (multiple == 0) | ||
return numToRound; | ||
|
||
val remainder = Math.abs(numToRound) % multiple; | ||
if (remainder == 0) | ||
return numToRound; | ||
|
||
if (numToRound < 0) | ||
return -(Math.abs(numToRound) - remainder); | ||
else | ||
return numToRound + multiple - remainder; | ||
} | ||
|
||
fun Int.nextMultipleOf(multiple:Int):Int = roundUp(this, multiple) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.jtransc.numeric | ||
|
||
fun String.toInt(radix: Int) = Integer.parseInt(this, radix) | ||
|
||
fun String.toInt(radix: Int, default: Int) = try { | ||
Integer.parseInt(this, radix) | ||
} catch (t: Throwable) { | ||
default | ||
} |
Oops, something went wrong.