From a4f94421c747ed753f8fac92675d0871ef427bd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20M=C3=B8ller=20Jensen?= <29657183+tobias1012@users.noreply.github.com> Date: Tue, 11 Mar 2025 09:15:04 +0100 Subject: [PATCH 1/4] Fix for #4780 --- svsim/src/main/scala/Workspace.scala | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/svsim/src/main/scala/Workspace.scala b/svsim/src/main/scala/Workspace.scala index cb4033eb0fa..3e68ca9fc71 100644 --- a/svsim/src/main/scala/Workspace.scala +++ b/svsim/src/main/scala/Workspace.scala @@ -5,8 +5,10 @@ import java.nio.file.attribute.BasicFileAttributes import java.nio.file.{FileVisitResult, FileVisitor} import java.nio.file.{FileVisitor, Files, Path, Paths} import java.lang.ProcessBuilder.Redirect +import java.util.Comparator import scala.annotation.meta.param import scala.jdk.CollectionConverters._ +import scala.sys.SystemProperties case class ModuleInfo(name: String, ports: Seq[ModuleInfo.Port]) { private[svsim] val instanceName = "dut" @@ -28,7 +30,7 @@ final class Workspace( ) { val absolutePath = - if (path.startsWith("/")) + if (Paths.get(path).isAbsolute()) path else s"${System.getProperty("user.dir")}/$path" @@ -50,7 +52,15 @@ final class Workspace( def reset() = { _moduleInfo = None - val rm = Runtime.getRuntime().exec(Array("rm", "-rf", absolutePath)).waitFor() + // Create a path type object from the absolute path string. + val absolutePathObject = Paths.get(absolutePath) + if (Files.exists(absolutePathObject)) { + Files + .walk(absolutePathObject) + .sorted(Comparator.reverseOrder()) + .forEach(Files.delete) + } + val pathsToCreate = Seq( supportArtifactsPath, primarySourcesPath, @@ -392,7 +402,13 @@ final class Workspace( //format: off // For this debug flow, we rebuild the simulation from scratch every time, to avoid issues if the simulation was originally compiled in a different environment, like using SiFive's `wake`. l("clean:") - l("\tls . | grep -v Makefile | grep -v execution-script.txt | xargs rm -rf") + // Add check if OS is windows, since the command syntax is different + if (System.getProperty("os.name").toLowerCase.contains("win")) { + l("\tfor /f \"delims=\" %i in ('dir /b /a-d ^| findstr /v Makefile ^| findstr /v execution-script.txt') do del \"%i\"") + l("\tfor /d %i in (*) do rmdir /s /q \"%i\"") + } else { + l("\tls . | grep -v Makefile | grep -v execution-script.txt | xargs rm -rf") + } l() l("simulation: clean") l("\t$(compilerEnvironment) \\") From eba1fb9694cffccfcd1b3ded8e931724188738a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20M=C3=B8ller=20Jensen?= <29657183+tobias1012@users.noreply.github.com> Date: Fri, 14 Mar 2025 09:17:14 +0100 Subject: [PATCH 2/4] fix serialization of paths in firrtl parser --- .../src/main/scala/chisel3/internal/firrtl/Serializer.scala | 3 ++- svsim/src/main/scala/Workspace.scala | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/main/scala/chisel3/internal/firrtl/Serializer.scala b/core/src/main/scala/chisel3/internal/firrtl/Serializer.scala index 224e8f85996..9fca3490e20 100644 --- a/core/src/main/scala/chisel3/internal/firrtl/Serializer.scala +++ b/core/src/main/scala/chisel3/internal/firrtl/Serializer.scala @@ -607,7 +607,8 @@ private[chisel3] object Serializer { outputDir match { case Some(d) => b ++= ", " - quote(d) + //When serializing a windows path we need to escape the backslashes + quote(d.replace("\\", "\\\\")) case None => () } case LayerConfig.Inline => diff --git a/svsim/src/main/scala/Workspace.scala b/svsim/src/main/scala/Workspace.scala index 3e68ca9fc71..4875627fa49 100644 --- a/svsim/src/main/scala/Workspace.scala +++ b/svsim/src/main/scala/Workspace.scala @@ -37,15 +37,15 @@ final class Workspace( /** A directory where the user can store additional artifacts which are relevant to the primary sources (for instance, artifacts related to the generation of primary sources). These artifacts have no impact on the simulation, but it may be useful to group them with the other files generated by svsim for debugging purposes. */ - val supportArtifactsPath = s"$absolutePath/support-artifacts" + val supportArtifactsPath = Paths.get(absolutePath,"support-artifacts").toString() /** The directory containing user-provided source files used to compile the simulation when `compile` is called. */ - val primarySourcesPath = s"$absolutePath/primary-sources" + val primarySourcesPath = Paths.get(absolutePath,"primary-sources").toString() /** The directory containing code generated when calling `generateAdditionalSources` */ - val generatedSourcesPath = s"$absolutePath/generated-sources" + val generatedSourcesPath = Paths.get(absolutePath,"generated-sources").toString() private var _moduleInfo: Option[ModuleInfo] = None From 0731e68917f1a0054a22641542aba3755239cde2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20M=C3=B8ller=20Jensen?= <29657183+tobias1012@users.noreply.github.com> Date: Fri, 14 Mar 2025 18:05:22 +0100 Subject: [PATCH 3/4] formatting --- svsim/src/main/scala/Workspace.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/svsim/src/main/scala/Workspace.scala b/svsim/src/main/scala/Workspace.scala index 1d6c0838b14..b1172806a0a 100644 --- a/svsim/src/main/scala/Workspace.scala +++ b/svsim/src/main/scala/Workspace.scala @@ -37,15 +37,15 @@ final class Workspace( /** A directory where the user can store additional artifacts which are relevant to the primary sources (for instance, artifacts related to the generation of primary sources). These artifacts have no impact on the simulation, but it may be useful to group them with the other files generated by svsim for debugging purposes. */ - val supportArtifactsPath = Paths.get(absolutePath,"support-artifacts").toString() + val supportArtifactsPath = Paths.get(absolutePath, "support-artifacts").toString() /** The directory containing user-provided source files used to compile the simulation when `compile` is called. */ - val primarySourcesPath = Paths.get(absolutePath,"primary-sources").toString() + val primarySourcesPath = Paths.get(absolutePath, "primary-sources").toString() /** The directory containing code generated when calling `generateAdditionalSources` */ - val generatedSourcesPath = Paths.get(absolutePath,"generated-sources").toString() + val generatedSourcesPath = Paths.get(absolutePath, "generated-sources").toString() private var _moduleInfo: Option[ModuleInfo] = None From 79c35842a45fc5b1485405e8b557483a2bf36748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20M=C3=B8ller=20Jensen?= <29657183+tobias1012@users.noreply.github.com> Date: Fri, 14 Mar 2025 18:19:39 +0100 Subject: [PATCH 4/4] formatting --- .../src/main/scala/chisel3/internal/firrtl/Serializer.scala | 2 +- svsim/src/main/scala/Workspace.scala | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/scala/chisel3/internal/firrtl/Serializer.scala b/core/src/main/scala/chisel3/internal/firrtl/Serializer.scala index 9fca3490e20..e88a8ffe525 100644 --- a/core/src/main/scala/chisel3/internal/firrtl/Serializer.scala +++ b/core/src/main/scala/chisel3/internal/firrtl/Serializer.scala @@ -607,7 +607,7 @@ private[chisel3] object Serializer { outputDir match { case Some(d) => b ++= ", " - //When serializing a windows path we need to escape the backslashes + // When serializing a windows path we need to escape the backslashes quote(d.replace("\\", "\\\\")) case None => () } diff --git a/svsim/src/main/scala/Workspace.scala b/svsim/src/main/scala/Workspace.scala index 1d6c0838b14..b1172806a0a 100644 --- a/svsim/src/main/scala/Workspace.scala +++ b/svsim/src/main/scala/Workspace.scala @@ -37,15 +37,15 @@ final class Workspace( /** A directory where the user can store additional artifacts which are relevant to the primary sources (for instance, artifacts related to the generation of primary sources). These artifacts have no impact on the simulation, but it may be useful to group them with the other files generated by svsim for debugging purposes. */ - val supportArtifactsPath = Paths.get(absolutePath,"support-artifacts").toString() + val supportArtifactsPath = Paths.get(absolutePath, "support-artifacts").toString() /** The directory containing user-provided source files used to compile the simulation when `compile` is called. */ - val primarySourcesPath = Paths.get(absolutePath,"primary-sources").toString() + val primarySourcesPath = Paths.get(absolutePath, "primary-sources").toString() /** The directory containing code generated when calling `generateAdditionalSources` */ - val generatedSourcesPath = Paths.get(absolutePath,"generated-sources").toString() + val generatedSourcesPath = Paths.get(absolutePath, "generated-sources").toString() private var _moduleInfo: Option[ModuleInfo] = None