Commit e1dd18e5 authored by Jon McClung's avatar Jon McClung Committed by Xianwen Chen

Check for Duplicate Output Paths (#381)

* Check for Duplicate Output Paths

This adds some simple logic to check whether files are set to overwrite each other. This is especially helpful for newcomers who are confused when the default settings cause this issue.

* Simplified Implementation

I realized that the existing codebase actually already does this for files created by the same generator. This change makes it apply to all generators, preventing cross-language overwriting.
parent 7941eec4
......@@ -240,9 +240,12 @@ package object generatorTools {
case class DeclRef(decl: String, namespace: Option[String]) extends SymbolReference
}
object Generator {
val writtenFiles = mutable.HashMap[String,String]()
}
abstract class Generator(spec: Spec)
{
protected val writtenFiles = mutable.HashMap[String,String]()
protected def createFile(folder: File, fileName: String, makeWriter: OutputStreamWriter => IndentWriter, f: IndentWriter => Unit): Unit = {
if (spec.outFileListWriter.isDefined) {
......@@ -254,7 +257,7 @@ abstract class Generator(spec: Spec)
val file = new File(folder, fileName)
val cp = file.getCanonicalPath
writtenFiles.put(cp.toLowerCase, cp) match {
Generator.writtenFiles.put(cp.toLowerCase, cp) match {
case Some(existing) =>
if (existing == cp) {
throw GenerateException("Refusing to write \"" + file.getPath + "\"; we already wrote a file to that path.")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment