aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Endo <olegendo@gcc.gnu.org>2019-04-29 16:13:34 +0900
committerOleg Endo <olegendo@gcc.gnu.org>2019-04-29 16:13:34 +0900
commite531fb203aedeb3863ebf8add0bbd8251183d27a (patch)
treed2bbe44f8af041a0483a55839c6c46151746c087
parentea0e0722bb42254ac8c63eb41664d9dfb7973aec (diff)
downloadyosys-e531fb203aedeb3863ebf8add0bbd8251183d27a.tar.gz
yosys-e531fb203aedeb3863ebf8add0bbd8251183d27a.tar.bz2
yosys-e531fb203aedeb3863ebf8add0bbd8251183d27a.zip
escape spaces with backslash when writing dep file
filenames are sparated by spaces in the dep file. if a filename in the dep file contains spaces they must be escaped, otherwise the tool that reads the dep file will see multiple wrong filenames.
-rw-r--r--kernel/driver.cc4
-rw-r--r--kernel/yosys.cc14
-rw-r--r--kernel/yosys.h1
3 files changed, 17 insertions, 2 deletions
diff --git a/kernel/driver.cc b/kernel/driver.cc
index 1bc7a5935..8c56d059b 100644
--- a/kernel/driver.cc
+++ b/kernel/driver.cc
@@ -529,13 +529,13 @@ int main(int argc, char **argv)
log_error("Can't open dependencies file for writing: %s\n", strerror(errno));
bool first = true;
for (auto fn : yosys_output_files) {
- fprintf(f, "%s%s", first ? "" : " ", fn.c_str());
+ fprintf(f, "%s%s", first ? "" : " ", escape_filename_spaces (fn).c_str());
first = false;
}
fprintf(f, ":");
for (auto fn : yosys_input_files) {
if (yosys_output_files.count(fn) == 0)
- fprintf(f, " %s", fn.c_str());
+ fprintf(f, " %s", escape_filename_spaces (fn).c_str());
}
fprintf(f, "\n");
}
diff --git a/kernel/yosys.cc b/kernel/yosys.cc
index a12355f1d..267a7d01c 100644
--- a/kernel/yosys.cc
+++ b/kernel/yosys.cc
@@ -482,6 +482,20 @@ void remove_directory(std::string dirname)
#endif
}
+std::string escape_filename_spaces (const std::string& filename)
+{
+ std::string out;
+ out.reserve (filename.size ());
+ for (auto c : filename)
+ {
+ if (c == ' ')
+ out += "\\ ";
+ else
+ out.push_back (c);
+ }
+ return out;
+}
+
int GetSize(RTLIL::Wire *wire)
{
return wire->width;
diff --git a/kernel/yosys.h b/kernel/yosys.h
index 2cf6188b4..d64904151 100644
--- a/kernel/yosys.h
+++ b/kernel/yosys.h
@@ -257,6 +257,7 @@ std::string make_temp_dir(std::string template_str = "/tmp/yosys_XXXXXX");
bool check_file_exists(std::string filename, bool is_exec = false);
bool is_absolute_path(std::string filename);
void remove_directory(std::string dirname);
+std::string escape_filename_spaces (const std::string& filename);
template<typename T> int GetSize(const T &obj) { return obj.size(); }
int GetSize(RTLIL::Wire *wire);