mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-18 20:03:39 +00:00
Merge pull request #3333 from mohamed/feature/tmpdir
Observe $TMPDIR variable when creating tmp files
This commit is contained in:
commit
197c9e04e8
6 changed files with 48 additions and 31 deletions
|
@ -33,7 +33,7 @@ FstData::FstData(std::string filename) : ctx(nullptr)
|
||||||
std::string filename_trim = file_base_name(filename);
|
std::string filename_trim = file_base_name(filename);
|
||||||
if (filename_trim.size() > 4 && filename_trim.compare(filename_trim.size()-4, std::string::npos, ".vcd") == 0) {
|
if (filename_trim.size() > 4 && filename_trim.compare(filename_trim.size()-4, std::string::npos, ".vcd") == 0) {
|
||||||
filename_trim.erase(filename_trim.size()-4);
|
filename_trim.erase(filename_trim.size()-4);
|
||||||
tmp_file = stringf("/tmp/converted_%s.fst", filename_trim.c_str());
|
tmp_file = stringf("%s/converted_%s.fst", get_base_tmpdir().c_str(), filename_trim.c_str());
|
||||||
std::string cmd = stringf("vcd2fst %s %s", filename.c_str(), tmp_file.c_str());
|
std::string cmd = stringf("vcd2fst %s %s", filename.c_str(), tmp_file.c_str());
|
||||||
log("Exec: %s\n", cmd.c_str());
|
log("Exec: %s\n", cmd.c_str());
|
||||||
if (run_command(cmd) != 0)
|
if (run_command(cmd) != 0)
|
||||||
|
|
|
@ -376,35 +376,54 @@ int run_command(const std::string &command, std::function<void(const std::string
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
std::string get_base_tmpdir()
|
||||||
|
{
|
||||||
|
static std::string tmpdir;
|
||||||
|
|
||||||
|
if (!tmpdir.empty()) {
|
||||||
|
return tmpdir;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
# ifdef __MINGW32__
|
||||||
|
char longpath[MAX_PATH + 1];
|
||||||
|
char shortpath[MAX_PATH + 1];
|
||||||
|
# else
|
||||||
|
WCHAR longpath[MAX_PATH + 1];
|
||||||
|
TCHAR shortpath[MAX_PATH + 1];
|
||||||
|
# endif
|
||||||
|
if (!GetTempPath(MAX_PATH+1, longpath))
|
||||||
|
log_error("GetTempPath() failed.\n");
|
||||||
|
if (!GetShortPathName(longpath, shortpath, MAX_PATH + 1))
|
||||||
|
log_error("GetShortPathName() failed.\n");
|
||||||
|
for (int i = 0; shortpath[i]; i++)
|
||||||
|
tmpdir += char(shortpath[i]);
|
||||||
|
#else
|
||||||
|
char * var = std::getenv("TMPDIR");
|
||||||
|
if (var && strlen(var)!=0) {
|
||||||
|
tmpdir.assign(var);
|
||||||
|
// We return the directory name without the trailing '/'
|
||||||
|
while (!tmpdir.empty() && (tmpdir.back() == '/')) {
|
||||||
|
tmpdir.pop_back();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tmpdir.assign("/tmp");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return tmpdir;
|
||||||
|
}
|
||||||
|
|
||||||
std::string make_temp_file(std::string template_str)
|
std::string make_temp_file(std::string template_str)
|
||||||
{
|
{
|
||||||
#if defined(__wasm)
|
|
||||||
size_t pos = template_str.rfind("XXXXXX");
|
size_t pos = template_str.rfind("XXXXXX");
|
||||||
log_assert(pos != std::string::npos);
|
log_assert(pos != std::string::npos);
|
||||||
|
#if defined(__wasm)
|
||||||
static size_t index = 0;
|
static size_t index = 0;
|
||||||
template_str.replace(pos, 6, stringf("%06zu", index++));
|
template_str.replace(pos, 6, stringf("%06zu", index++));
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
if (template_str.rfind("/tmp/", 0) == 0) {
|
#ifndef YOSYS_WIN32_UNIX_DIR
|
||||||
# ifdef __MINGW32__
|
std::replace(template_str.begin(), template_str.end(), '/', '\\');
|
||||||
char longpath[MAX_PATH + 1];
|
#endif
|
||||||
char shortpath[MAX_PATH + 1];
|
|
||||||
# else
|
|
||||||
WCHAR longpath[MAX_PATH + 1];
|
|
||||||
TCHAR shortpath[MAX_PATH + 1];
|
|
||||||
# endif
|
|
||||||
if (!GetTempPath(MAX_PATH+1, longpath))
|
|
||||||
log_error("GetTempPath() failed.\n");
|
|
||||||
if (!GetShortPathName(longpath, shortpath, MAX_PATH + 1))
|
|
||||||
log_error("GetShortPathName() failed.\n");
|
|
||||||
std::string path;
|
|
||||||
for (int i = 0; shortpath[i]; i++)
|
|
||||||
path += char(shortpath[i]);
|
|
||||||
template_str = stringf("%s\\%s", path.c_str(), template_str.c_str() + 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t pos = template_str.rfind("XXXXXX");
|
|
||||||
log_assert(pos != std::string::npos);
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
static std::string y = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
static std::string y = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
@ -416,9 +435,6 @@ std::string make_temp_file(std::string template_str)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
size_t pos = template_str.rfind("XXXXXX");
|
|
||||||
log_assert(pos != std::string::npos);
|
|
||||||
|
|
||||||
int suffixlen = GetSize(template_str) - pos - 6;
|
int suffixlen = GetSize(template_str) - pos - 6;
|
||||||
|
|
||||||
char *p = strdup(template_str.c_str());
|
char *p = strdup(template_str.c_str());
|
||||||
|
|
|
@ -278,8 +278,9 @@ bool patmatch(const char *pattern, const char *string);
|
||||||
#if !defined(YOSYS_DISABLE_SPAWN)
|
#if !defined(YOSYS_DISABLE_SPAWN)
|
||||||
int run_command(const std::string &command, std::function<void(const std::string&)> process_line = std::function<void(const std::string&)>());
|
int run_command(const std::string &command, std::function<void(const std::string&)> process_line = std::function<void(const std::string&)>());
|
||||||
#endif
|
#endif
|
||||||
std::string make_temp_file(std::string template_str = "/tmp/yosys_XXXXXX");
|
std::string get_base_tmpdir();
|
||||||
std::string make_temp_dir(std::string template_str = "/tmp/yosys_XXXXXX");
|
std::string make_temp_file(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
|
||||||
|
std::string make_temp_dir(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
|
||||||
bool check_file_exists(std::string filename, bool is_exec = false);
|
bool check_file_exists(std::string filename, bool is_exec = false);
|
||||||
bool is_absolute_path(std::string filename);
|
bool is_absolute_path(std::string filename);
|
||||||
void remove_directory(std::string dirname);
|
void remove_directory(std::string dirname);
|
||||||
|
|
|
@ -251,7 +251,7 @@ QbfSolutionType call_qbf_solver(RTLIL::Module *mod, const QbfSolveOptions &opt,
|
||||||
|
|
||||||
QbfSolutionType qbf_solve(RTLIL::Module *mod, const QbfSolveOptions &opt) {
|
QbfSolutionType qbf_solve(RTLIL::Module *mod, const QbfSolveOptions &opt) {
|
||||||
QbfSolutionType ret, best_soln;
|
QbfSolutionType ret, best_soln;
|
||||||
const std::string tempdir_name = make_temp_dir("/tmp/yosys-qbfsat-XXXXXX");
|
const std::string tempdir_name = make_temp_dir(get_base_tmpdir() + "/yosys-qbfsat-XXXXXX");
|
||||||
RTLIL::Module *module = mod;
|
RTLIL::Module *module = mod;
|
||||||
RTLIL::Design *design = module->design;
|
RTLIL::Design *design = module->design;
|
||||||
std::string module_name = module->name.str();
|
std::string module_name = module->name.str();
|
||||||
|
|
|
@ -780,7 +780,7 @@ void abc_module(RTLIL::Design *design, RTLIL::Module *current_module, std::strin
|
||||||
if (dff_mode && clk_sig.empty())
|
if (dff_mode && clk_sig.empty())
|
||||||
log_cmd_error("Clock domain %s not found.\n", clk_str.c_str());
|
log_cmd_error("Clock domain %s not found.\n", clk_str.c_str());
|
||||||
|
|
||||||
std::string tempdir_name = "/tmp/" + proc_program_prefix()+ "yosys-abc-XXXXXX";
|
std::string tempdir_name = get_base_tmpdir() + "/" + proc_program_prefix()+ "yosys-abc-XXXXXX";
|
||||||
if (!cleanup)
|
if (!cleanup)
|
||||||
tempdir_name[0] = tempdir_name[4] = '_';
|
tempdir_name[0] = tempdir_name[4] = '_';
|
||||||
tempdir_name = make_temp_dir(tempdir_name);
|
tempdir_name = make_temp_dir(tempdir_name);
|
||||||
|
|
|
@ -404,7 +404,7 @@ struct Abc9Pass : public ScriptPass
|
||||||
if (!active_design->selected_whole_module(mod))
|
if (!active_design->selected_whole_module(mod))
|
||||||
log_error("Can't handle partially selected module %s!\n", log_id(mod));
|
log_error("Can't handle partially selected module %s!\n", log_id(mod));
|
||||||
|
|
||||||
std::string tempdir_name = "/tmp/" + proc_program_prefix() + "yosys-abc-XXXXXX";
|
std::string tempdir_name = get_base_tmpdir() + "/" + proc_program_prefix() + "yosys-abc-XXXXXX";
|
||||||
if (!cleanup)
|
if (!cleanup)
|
||||||
tempdir_name[0] = tempdir_name[4] = '_';
|
tempdir_name[0] = tempdir_name[4] = '_';
|
||||||
tempdir_name = make_temp_dir(tempdir_name);
|
tempdir_name = make_temp_dir(tempdir_name);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue