From cbc9123db4fbe1e671e8f878aadf2845b7861e5d Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 4 Aug 2023 23:23:43 +0200 Subject: [PATCH] Mitigate the effect of overriding a globally-defined technology with -nn on the command line by creating tech variants --- src/lay/lay/layApplication.cc | 35 ++++++++++++++++++++++++-- src/lay/lay/layTechnologyController.cc | 3 +++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/lay/lay/layApplication.cc b/src/lay/lay/layApplication.cc index 6a825293d..b4309db4a 100644 --- a/src/lay/lay/layApplication.cc +++ b/src/lay/lay/layApplication.cc @@ -686,28 +686,59 @@ ApplicationBase::init_app () tc->add_path (*p); } + tc->load (); + + bool needs_reload = false; + + // disambiguator for tech name + std::map tech_disambiguator; + std::map tech_name_for_file; + + for (auto t = db::Technologies::instance ()->begin (); t != db::Technologies::instance ()->end (); ++t) { + tech_disambiguator.insert (std::make_pair (t->name (), 0)); + } + // import technologies from the command line for (std::vector > >::iterator f = m_files.begin (); f != m_files.end (); ++f) { if (f->first == layout_file_with_tech_file) { + const std::string &tech_file = f->second.second; + if (tl::verbosity () >= 20) { tl::info << "Importing technology from " << f->second.second; } db::Technology t; - t.load (f->second.second); + t.load (tech_file); + + // disambiguate the name, so we do not overwrite technologies with the same name from the config + if (tech_name_for_file.find (tech_file) != tech_name_for_file.end ()) { + t.set_name (tech_name_for_file [tech_file]); + } else if (tech_disambiguator.find (t.name ()) != tech_disambiguator.end ()) { + int &index = tech_disambiguator [t.name ()]; + index += 1; + t.set_name (t.name () + tl::sprintf ("[%d]", index)); + tech_name_for_file.insert (std::make_pair (tech_file, t.name ())); + } else { + tech_disambiguator.insert (std::make_pair (t.name (), 0)); + tech_name_for_file.insert (std::make_pair (tech_file, t.name ())); + } tc->add_temp_tech (t); f->first = layout_file_with_tech; f->second.second = t.name (); + needs_reload = true; + } } - tc->load (); + if (needs_reload) { + tc->load (); + } } diff --git a/src/lay/lay/layTechnologyController.cc b/src/lay/lay/layTechnologyController.cc index 103e7a1cc..212e2a7df 100644 --- a/src/lay/lay/layTechnologyController.cc +++ b/src/lay/lay/layTechnologyController.cc @@ -609,6 +609,9 @@ TechnologyController::rescan (db::Technologies &technologies) for (std::vector::const_iterator t = m_temp_tech.begin (); t != m_temp_tech.end (); ++t) { db::Technology *tech = new db::Technology (*t); + if (tl::verbosity () >= 20) { + tl::info << "Registering special technology from " << tech->tech_file_path () << " as " << tech->name (); + } tech->set_persisted (false); // don't save that one in the configuration tech->set_tech_file_path (std::string ()); // don't save to a file either tech->set_readonly (true); // don't edit