aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/transforms
diff options
context:
space:
mode:
authorJim Lawson2018-08-29 06:22:46 -0700
committerAdam Izraelevitz2018-08-29 06:22:46 -0700
commit6a9710a8afe0531d09bb1f4f6ac86b9966d8c414 (patch)
treec8a54229e9c609fcf5706586e9eb32254618b265 /src/main/scala/firrtl/transforms
parentcf6402e1f0169db29d84c8d5353b75dccd038316 (diff)
Filter resource file names to avoid including the same file multiple times. (#883)
* Filter resource file names to avoid including the same file multiple times. Addresses issue #882. * Use a Set instead of a Map to filter Verilog files. * Use canonical paths for file name comparison and unify name generation. Provide a common method for copying resources to a directory to ensure the same resource ends up with the same name if it's copied by multiple clients. * Reduce confusion - another absolute -> canonical switch. Use the canonical path on the verilator command line for the filter additional Verilog sources.
Diffstat (limited to 'src/main/scala/firrtl/transforms')
-rw-r--r--src/main/scala/firrtl/transforms/BlackBoxSourceHelper.scala32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/main/scala/firrtl/transforms/BlackBoxSourceHelper.scala b/src/main/scala/firrtl/transforms/BlackBoxSourceHelper.scala
index 1e6fa7ea..182accf2 100644
--- a/src/main/scala/firrtl/transforms/BlackBoxSourceHelper.scala
+++ b/src/main/scala/firrtl/transforms/BlackBoxSourceHelper.scala
@@ -70,12 +70,7 @@ class BlackBoxSourceHelper extends firrtl.Transform {
val resourceFiles: ListSet[File] = annos.collect {
case BlackBoxResourceAnno(_, resourceId) =>
- val name = resourceId.split("/").last
- val outFile = new File(targetDir, name)
- (resourceId, outFile)
- }.map { case (res, file) =>
- BlackBoxSourceHelper.copyResourceToFile(res, file)
- file
+ BlackBoxSourceHelper.writeResourceToDirectory(resourceId, targetDir)
}
val inlineFiles: ListSet[File] = annos.collect {
@@ -97,6 +92,19 @@ object BlackBoxSourceHelper {
/**
* finds the named resource and writes into the directory
* @param name the name of the resource
+ * @param dir the directory in which to write the file
+ * @return the closed File object
+ */
+ def writeResourceToDirectory(name: String, dir: File): File = {
+ val fileName = name.split("/").last
+ val outFile = new File(dir, fileName)
+ copyResourceToFile(name, outFile)
+ outFile
+ }
+
+ /**
+ * finds the named resource and writes into the directory
+ * @param name the name of the resource
* @param file the file to write it into
*/
def copyResourceToFile(name: String, file: File) {
@@ -113,11 +121,13 @@ object BlackBoxSourceHelper {
def writeFileList(files: ListSet[File], targetDir: File) {
if (files.nonEmpty) {
- // We need the absolute path here (or strip targetDir from the file path),
- // so verilator will create a path to the file that works from the targetDir.
- // Otherwise, when make tries to determine dependencies based on the *__ver.d file, we end up with errors like:
- // make[1]: *** No rule to make target `test_run_dir/examples.AccumBlackBox_PeekPokeTest_Verilator345491158/AccumBlackBox.v', needed by `.../chisel-testers/test_run_dir/examples.AccumBlackBox_PeekPokeTest_Verilator345491158/VAccumBlackBoxWrapper.h'. Stop.
- writeTextToFile(files.map(_.getAbsolutePath).mkString("\n"), new File(targetDir, fileListName))
+ // We need the canonical path here, so verilator will create a path to the file that works from the targetDir,
+ // and, so we can compare the list of files automatically included, with an explicit list provided by the client
+ // and reject duplicates.
+ // If the path isn't canonical, when make tries to determine dependencies based on the *__ver.d file, we end up with errors like:
+ // make[1]: *** No rule to make target `test_run_dir/examples.AccumBlackBox_PeekPokeTest_Verilator345491158/AccumBlackBox.v', needed by `.../chisel-testers/test_run_dir/examples.AccumBlackBox_PeekPokeTest_Verilator345491158/VAccumBlackBoxWrapper.h'. Stop.
+ // or we end up including the same file multiple times.
+ writeTextToFile(files.map(_.getCanonicalPath).mkString("\n"), new File(targetDir, fileListName))
}
}