Skip to content

Commit

Permalink
Added URL support in sireum proyek dep.
Browse files Browse the repository at this point in the history
  • Loading branch information
robby-phd committed Oct 28, 2024
1 parent 8ef3b50 commit 1c09ecf
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 11 deletions.
4 changes: 3 additions & 1 deletion library/jvm/src/main/scala/org/sireum/LibJvmUtil_Ext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class LibJvmUtil_Ext extends Reflection_Ext {
}

private lazy val method0Map: Long2ObjectOpenHashMap[Option[AnyRef] => Any] = {
val r = new Long2ObjectOpenHashMap[Option[AnyRef] => Any](1217)
val r = new Long2ObjectOpenHashMap[Option[AnyRef] => Any](1218)
r.put(0xB845B50D3B02FA78L, _ => org.sireum.CircularQueue.Policy.NoDrop) // methodKey(T, "org.sireum.CircularQueue.Policy", "NoDrop").value
r.put(0x6CB47D05D6EFBA0BL, _ => org.sireum.CircularQueue.Policy.DropFront) // methodKey(T, "org.sireum.CircularQueue.Policy", "DropFront").value
r.put(0x116832077C0E11BFL, _ => org.sireum.CircularQueue.Policy.DropRear) // methodKey(T, "org.sireum.CircularQueue.Policy", "DropRear").value
Expand Down Expand Up @@ -1268,6 +1268,7 @@ class LibJvmUtil_Ext extends Reflection_Ext {
r.put(0x9D735E53E4BEA32BL, X[org.sireum.Init](_).homeBin) // methodKey(F, "org.sireum.Init", "homeBin").value
r.put(0xAA88BE7C2E40044DL, X[org.sireum.Init](_).homeLib) // methodKey(F, "org.sireum.Init", "homeLib").value
r.put(0xCA6FE7482DBCBD9EL, X[org.sireum.Init](_).homeBinPlatform) // methodKey(F, "org.sireum.Init", "homeBinPlatform").value
r.put(0x6C11A982AA2992B5L, X[org.sireum.Init](_).binfmt) // methodKey(F, "org.sireum.Init", "binfmt").value
r.put(0xF78FA3367448F578L, X[org.sireum.Init](_).distroPlugins) // methodKey(F, "org.sireum.Init", "distroPlugins").value
r.put(0xE2A1015CD69EA9F3L, X[org.sireum.Init](_).scalacPluginVersion) // methodKey(F, "org.sireum.Init", "scalacPluginVersion").value
r.put(0x510160BCC772FB1AL, X[org.sireum.Init](_).coursierVersion) // methodKey(F, "org.sireum.Init", "coursierVersion").value
Expand Down Expand Up @@ -8192,6 +8193,7 @@ class LibJvmUtil_Ext extends Reflection_Ext {
Method(isInObject = false, isByName = T, name = "homeBin", params = ISZ()),
Method(isInObject = false, isByName = T, name = "homeLib", params = ISZ()),
Method(isInObject = false, isByName = T, name = "homeBinPlatform", params = ISZ()),
Method(isInObject = false, isByName = T, name = "binfmt", params = ISZ()),
Method(isInObject = false, isByName = T, name = "distroPlugins", params = ISZ()),
Method(isInObject = false, isByName = T, name = "scalacPluginVersion", params = ISZ()),
Method(isInObject = false, isByName = T, name = "coursierVersion", params = ISZ()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ package org.sireum.project
import org.sireum._

object DependencyManager {
@enum object DepKind {
"File"
"HTTP"
"HTTPS"
"IVY"
}

@datatype class Lib(val name: String,
val org: String,
val module: String,
Expand Down Expand Up @@ -87,6 +94,20 @@ import DependencyManager._

val _scalacPlugin: Os.Path = sireumHome / "lib" / s"scalac-plugin-${versions.get(scalacPluginKey).get}.jar"

@pure def depKind(dep: String): DepKind.Type = {
val depOps = ops.StringOps(dep)
if (depOps.startsWith("file://")) {
return DepKind.File
}
if (depOps.startsWith("http://")) {
return DepKind.HTTP
}
if (depOps.startsWith("https://")) {
return DepKind.HTTPS
}
return DepKind.IVY
}

def scalacPlugin: Os.Path = {
if (_scalacPlugin.exists) {
return _scalacPlugin
Expand Down Expand Up @@ -145,7 +166,7 @@ import DependencyManager._
val ivyDeps: HashSMap[String, String] = {
var r = HashSMap.empty[String, String]
def addIvyDep(ivyDep: String): Unit = {
if (ops.StringOps(ivyDep).startsWith("file://")) {
if (depKind(ivyDep) != DepKind.IVY) {
r = r + ivyDep ~> ivyDep
} else {
val v = getVersion(ivyDep)
Expand Down Expand Up @@ -280,6 +301,40 @@ import DependencyManager._
return fetchClassifiers(ivyDeps, ISZ(CoursierClassifier.Default))
}

def resolveVersion(dep: String): (Option[Os.Path], String) = {
depKind(dep) match {
case DepKind.IVY => return (None(), getVersion(dep))
case DepKind.File =>
val p = Os.Path.fromUri(dep)
if (p.ext != "jar") {
halt(s"File dependency has to be a .jar file: $dep")
}
return (Some(p), conversions.Z.toU64(p.lastModified).string)
case _ =>
val cis = conversions.String.toCis(dep)
if (!ops.StringOps.endsWith(cis, conversions.String.toCis(".jar"))) {
halt(s"URL dependency has to be a .jar file: $dep")
}
val i = ops.StringOps.lastIndexOfFrom(cis, '/', 0)
val name = ops.StringOps.substring(cis, i + 1, dep.size)
val p: Os.Path = Os.env("SIREUM_CACHE") match {
case Some(c) => Os.path(c) / name
case _ => Os.home / "Downloads" / "sireum" / name
}
p.up.mkdirAll()
println(s"Downloading $dep ...")
p.removeAll()
p.downloadFrom(dep)
println()
val sha3 = crypto.SHA3.init512
sha3.update(p.readU8s)
val version = st"${Jen.IS(sha3.finalise()).take(8).toISZ}".render
val pv = p.up.canon / st"${ops.StringOps(p.name).substring(0, p.name.size - 4)}-$version.jar".render
p.moveOverTo(pv)
return (Some(pv), version)
}
}

def fetchClassifiers(ivyDeps: ISZ[String], classifiers: ISZ[CoursierClassifier.Type]): ISZ[CoursierFileInfo] = {
val key = (ivyDeps, classifiers)
fetchedDeps.get(key) match {
Expand All @@ -288,15 +343,11 @@ import DependencyManager._
var coursierIvyDeps = ISZ[String]()
var unmanagedDeps = ISZ[CoursierFileInfo]()
for (dep <- ivyDeps) {
if (ops.StringOps(dep).startsWith("file://")) {
val p = Os.Path.fromUri(dep)
val sha3 = crypto.SHA3.init512
sha3.update(conversions.String.toU8is(p.canon.string))
val bs = Jen.IS(sha3.finalise()).take(8).toISZ
unmanagedDeps = unmanagedDeps :+ CoursierFileInfo(st"unmanaged.$bs".render, p.name, s"${p.lastModified}",
p.string)
} else {
coursierIvyDeps = coursierIvyDeps :+ dep
depKind(dep) match {
case DepKind.IVY => coursierIvyDeps = coursierIvyDeps :+ dep
case _ =>
val (Some(p), version) = resolveVersion(dep)
unmanagedDeps = unmanagedDeps :+ CoursierFileInfo(st"unmanaged.$version".render, p.name, version, p.string)
}
}
val r = Coursier.fetchClassifiers(scalaVersion, cacheOpt, project.mavenRepoUrls, coursierIvyDeps, classifiers,
Expand Down

0 comments on commit 1c09ecf

Please sign in to comment.