From 1822be8792865e3f6f0765693f93b8e85fcb279f Mon Sep 17 00:00:00 2001 From: "Mohamed A. Bamakhrama" Date: Mon, 23 May 2022 22:21:45 +0200 Subject: [PATCH] Observe $TMPDIR variable when creating tmp files POSIX defines $TMPDIR as containing the pathname of the directory where programs can create temporary files. On most systems, this variable points to "/tmp". However, on some systems it can point to a different location. Without respecting this variable, yosys fails to run on such systems. Signed-off-by: Mohamed A. Bamakhrama --- kernel/fstdata.cc | 2 +- kernel/yosys.cc | 31 ++++++++++++++++++++++++++++++- kernel/yosys.h | 5 +++-- passes/sat/qbfsat.cc | 2 +- passes/techmap/abc.cc | 2 +- passes/techmap/abc9.cc | 2 +- 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/kernel/fstdata.cc b/kernel/fstdata.cc index fea8ee3c3..b2e574b02 100644 --- a/kernel/fstdata.cc +++ b/kernel/fstdata.cc @@ -33,7 +33,7 @@ FstData::FstData(std::string filename) : ctx(nullptr) 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) { 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()); log("Exec: %s\n", cmd.c_str()); if (run_command(cmd) != 0) diff --git a/kernel/yosys.cc b/kernel/yosys.cc index 4e1a3ca7e..7f395761b 100644 --- a/kernel/yosys.cc +++ b/kernel/yosys.cc @@ -376,6 +376,35 @@ int run_command(const std::string &command, std::function process_line = std::function()); #endif -std::string make_temp_file(std::string template_str = "/tmp/yosys_XXXXXX"); -std::string make_temp_dir(std::string template_str = "/tmp/yosys_XXXXXX"); +std::string get_base_tmpdir(); +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 is_absolute_path(std::string filename); void remove_directory(std::string dirname); diff --git a/passes/sat/qbfsat.cc b/passes/sat/qbfsat.cc index 6db7d4b64..864d6f05d 100644 --- a/passes/sat/qbfsat.cc +++ b/passes/sat/qbfsat.cc @@ -251,7 +251,7 @@ QbfSolutionType call_qbf_solver(RTLIL::Module *mod, const QbfSolveOptions &opt, QbfSolutionType qbf_solve(RTLIL::Module *mod, const QbfSolveOptions &opt) { 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::Design *design = module->design; std::string module_name = module->name.str(); diff --git a/passes/techmap/abc.cc b/passes/techmap/abc.cc index ff98a6e36..61ee99ee7 100644 --- a/passes/techmap/abc.cc +++ b/passes/techmap/abc.cc @@ -780,7 +780,7 @@ void abc_module(RTLIL::Design *design, RTLIL::Module *current_module, std::strin if (dff_mode && clk_sig.empty()) 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) tempdir_name[0] = tempdir_name[4] = '_'; tempdir_name = make_temp_dir(tempdir_name); diff --git a/passes/techmap/abc9.cc b/passes/techmap/abc9.cc index fe0802d70..79c994b11 100644 --- a/passes/techmap/abc9.cc +++ b/passes/techmap/abc9.cc @@ -404,7 +404,7 @@ struct Abc9Pass : public ScriptPass if (!active_design->selected_whole_module(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) tempdir_name[0] = tempdir_name[4] = '_'; tempdir_name = make_temp_dir(tempdir_name); -- 2.30.2