Skip to content

Commit b037bbb

Browse files
authored
Merge pull request #277 from DFiantHDL/vivado_build
Docs versions and WSL->Windows execution prevention
2 parents 22b548b + 941a3ae commit b037bbb

File tree

6 files changed

+42
-15
lines changed

6 files changed

+42
-15
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
//> using scala 3.7.1
2-
//> using dep io.github.dfianthdl::dfhdl::0.11.0
3-
//> using plugin io.github.dfianthdl:::dfhdl-plugin:0.11.0
2+
//> using dep io.github.dfianthdl::dfhdl::0.12.0
3+
//> using plugin io.github.dfianthdl:::dfhdl-plugin:0.12.0
44
//> using option -deprecation -language:implicitConversions

docs/getting-started/hello-world/scala-single-file/Counter8.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//> using scala 3.7.1
2-
//> using dep io.github.dfianthdl::dfhdl::0.11.0
3-
//> using plugin io.github.dfianthdl:::dfhdl-plugin:0.11.0
2+
//> using dep io.github.dfianthdl::dfhdl::0.12.0
3+
//> using plugin io.github.dfianthdl:::dfhdl-plugin:0.12.0
44
//> using option -deprecation -language:implicitConversions
55

66
import dfhdl.* //import all the DFHDL goodness

docs/javascripts/scastie.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let dfhdlVersion = "0.11.0";
1+
let dfhdlVersion = "0.12.0";
22
let scalaVersion = "3.7.1";
33

44
let sbtConfig = `

docs/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
pygments==2.19.1
1+
pygments==2.19.2
22
mkdocs==1.6.1
3-
mkdocs-material==9.6.14
4-
pymdown-extensions==10.15
3+
mkdocs-material==9.6.15
4+
pymdown-extensions==10.16
55
mkdocs-redirects==1.2.2
66
mkdocs-glightbox==0.4.0
77
mkdocs-autorefs==1.4.2

internals/src/main/scala/dfhdl/internals/helpers.scala

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ extension (using quotes: Quotes)(lhs: quotes.reflect.TypeRepr)
8686
case '[head *: tail] =>
8787
recur(TypeRepr.of[tail], TypeRepr.of[head] :: args)
8888
case '[EmptyTuple] => args.reverse
89-
case '[t] =>
89+
case '[t] =>
9090
report.errorAndAbort(s"Expecting a tuple, but found ${Type.show[t]}")
9191
if (lhs.show == "null")
9292
report.errorAndAbort(s"Expecting a tuple, but found null")
@@ -332,7 +332,7 @@ extension [T](seq: Iterable[T])
332332
f: T => P,
333333
res: List[(P, Iterable[T])]
334334
): Seq[(P, Iterable[T])] = seq.headOption match
335-
case None => res.reverse
335+
case None => res.reverse
336336
case Some(h) =>
337337
val key = f(h)
338338
val subseq = seq.takeWhile(f(_) equals key)
@@ -460,7 +460,32 @@ object AnnotatedWith:
460460
end annotWithMacro
461461
end AnnotatedWith
462462

463-
def osIsWindows: Boolean = sys.props("os.name").toLowerCase.contains("windows")
463+
lazy val osIsWindows: Boolean = sys.props("os.name").toLowerCase.contains("windows")
464+
lazy val osIsLinux: Boolean = sys.props("os.name").toLowerCase.contains("linux")
465+
lazy val osIsWSL: Boolean =
466+
if (osIsLinux)
467+
import scala.io.Source
468+
try
469+
val procVersion = Source.fromFile("/proc/version").getLines().mkString
470+
procVersion.contains("microsoft-standard")
471+
catch
472+
case _: Exception => false
473+
else false
474+
// checks if the program is accessible to the current shell
475+
def programIsAccessible(cmd: String): Boolean =
476+
import sys.process.*
477+
try
478+
if (osIsWindows)
479+
s"where $cmd".!!.nonEmpty
480+
else
481+
val result = s"which $cmd".!!.trim()
482+
// reject windows programs running from WSL
483+
if (result.nonEmpty && osIsWSL)
484+
!result.matches("""/mnt/[a-zA-Z]/.*""")
485+
else
486+
result.nonEmpty
487+
catch
488+
case _: Exception => false
464489

465490
// trait CompiletimeErrorPos[M <: String, S <: Int, E <: Int]
466491
// object CompiletimeErrorPos:

lib/src/main/scala/dfhdl/tools/toolsCore/Tool.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ trait Tool:
3131
protected[dfhdl] def cleanUpBeforeFileRestore()(using MemberGetSet, CompilerOptions): Unit = {}
3232

3333
private[dfhdl] lazy val installedVersion: Option[String] =
34-
val getVersionFullCmd =
35-
Process(s"$runExec $versionCmd", new java.io.File(System.getProperty("java.io.tmpdir")))
36-
try extractVersion(getVersionFullCmd.!!)
37-
catch case e: Exception => None
34+
if (!programIsAccessible(runExec)) None
35+
else
36+
val getVersionFullCmd =
37+
Process(s"$runExec $versionCmd", new java.io.File(System.getProperty("java.io.tmpdir")))
38+
try extractVersion(getVersionFullCmd.!!)
39+
catch case e: Exception => None
3840
final def isAvailable: Boolean = installedVersion.nonEmpty
3941
protected def getInstalledVersion(using to: ToolOptions): String =
4042
preCheck()

0 commit comments

Comments
 (0)