Merge pull request #775 from KLayout/no-display-for-help-and-version

klayout -v and -h now work without a display
This commit is contained in:
Matthias Köfferlein 2021-04-19 22:29:24 +02:00 committed by GitHub
commit b917bf4fd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 32 deletions

View File

@ -202,20 +202,6 @@ static int klayout_main_cont (int &argc, char **argv);
*/
int
klayout_main (int &argc, char **argv)
{
// This special initialization is required by the Ruby interpreter because it wants to mark the stack
int ret = rba::RubyInterpreter::initialize (argc, argv, &klayout_main_cont);
// clean up all static data now, since we don't trust the static destructors.
// NOTE: this needs to happen after the Ruby interpreter went down since otherwise the GC will
// access objects that are already cleaned up.
tl::StaticObjects::cleanup ();
return ret;
}
int
klayout_main_cont (int &argc, char **argv)
{
// install the version strings
lay::Version::set_exe_name (prg_exe_name);
@ -237,6 +223,37 @@ klayout_main_cont (int &argc, char **argv)
about_text += prg_about_text;
lay::Version::set_about_text (about_text.c_str ());
// Capture the shortcut command line arguments
for (int i = 1; i < argc; ++i) {
if (argv [i] == std::string ("-v")) {
tl::info << lay::ApplicationBase::version ();
return 0;
} else if (argv [i] == std::string ("-h")) {
tl::info << lay::ApplicationBase::usage () << tl::noendl;
return 0;
}
}
// This special initialization is required by the Ruby interpreter because it wants to mark the stack
int ret = rba::RubyInterpreter::initialize (argc, argv, &klayout_main_cont);
// clean up all static data now, since we don't trust the static destructors.
// NOTE: this needs to happen after the Ruby interpreter went down since otherwise the GC will
// access objects that are already cleaned up.
tl::StaticObjects::cleanup ();
return ret;
}
int
klayout_main_cont (int &argc, char **argv)
{
#if QT_VERSION >= 0x050000
qInstallMessageHandler (myMessageOutput);
#else

View File

@ -81,6 +81,12 @@ static std::string arch (C *)
return tl::arch_string ();
}
template <class C>
static std::string version (C *)
{
return C::version ();
}
template <class C>
static gsi::Methods application_methods ()
{
@ -213,7 +219,7 @@ static gsi::Methods application_methods ()
"\n"
"This method has been added in version 0.22."
) +
method<C, std::string> ("version", &C::version,
method_ext<C, std::string> ("version", &version<C>,
"@brief Returns the application's version string\n"
) +
method_ext<C, std::string> ("arch", &arch<C>,

View File

@ -483,16 +483,6 @@ ApplicationBase::parse_cmd (int &argc, char **argv)
m_packages_with_dep = true;
} else if (a == "-v") {
tl::info << lay::Version::name () << " " << lay::Version::version ();
exit (0);
} else if (a == "-h") {
tl::info << usage () << tl::noendl;
exit (0);
} else if (a == "-m" && (i + 1) < argc) {
m_files.push_back (std::make_pair (rdb_file, std::make_pair (std::string (args [++i]), std::string ())));
@ -929,7 +919,7 @@ ApplicationBase::instance ()
}
std::string
ApplicationBase::version () const
ApplicationBase::version ()
{
return std::string (lay::Version::name ()) + " " + lay::Version::version ();
}

View File

@ -100,12 +100,12 @@ public:
/**
* @brief Return the program's version
*/
std::string version () const;
static std::string version ();
/**
* @brief Return the program's usage string
*/
std::string usage ();
static std::string usage ();
/**
* @brief Returns the main window's reference

View File

@ -283,7 +283,7 @@ HelpSource::initialize_index ()
try {
tl::XMLFileSource in (*c);
help_index_structure.parse (in, *this);
if (m_klayout_version == lay::ApplicationBase::instance ()->version ()) {
if (m_klayout_version == lay::ApplicationBase::version ()) {
ok = true;
}
} catch (tl::Exception &ex) {
@ -352,7 +352,7 @@ HelpSource::create_index_file (const std::string &path)
std::string
HelpSource::klayout_version () const
{
return lay::ApplicationBase::instance ()->version ();
return lay::ApplicationBase::version ();
}
void

View File

@ -3543,9 +3543,9 @@ MainWindow::update_window_title ()
if (current_view ()->is_dirty ()) {
sep += "[+] ";
}
setWindowTitle (tl::to_qstring (lay::ApplicationBase::instance ()->version () + sep + current_view ()->title ()));
setWindowTitle (tl::to_qstring (lay::ApplicationBase::version () + sep + current_view ()->title ()));
} else {
setWindowTitle (tl::to_qstring (lay::ApplicationBase::instance ()->version ()));
setWindowTitle (tl::to_qstring (lay::ApplicationBase::version ()));
}
}