]> git.lyx.org Git - features.git/commitdiff
tex2lyx: Run configure.py if needed (bug #8539)
authorGeorg Baum <baum@lyx.org>
Mon, 29 Dec 2014 22:46:25 +0000 (23:46 +0100)
committerGeorg Baum <baum@lyx.org>
Mon, 29 Dec 2014 22:46:25 +0000 (23:46 +0100)
Since tex2lyx reads some LyX config files it needs to run configure.py if
they do not exist or are out of date.

src/LyX.cpp
src/frontends/qt4/GuiApplication.cpp
src/support/Package.cpp
src/support/Package.h
src/support/filetools.cpp
src/support/filetools.h
src/tex2lyx/tex2lyx.cpp

index 706950fe9fa317b09a0d8fbbe503e6c92ff84a0f..0a21b4b2249b8906d5469e10aa1e99f0de170e51 100644 (file)
@@ -60,8 +60,6 @@
 #include "support/Messages.h"
 #include "support/os.h"
 #include "support/Package.h"
-#include "support/PathChanger.h"
-#include "support/Systemcall.h"
 
 #include "support/bind.h"
 #include <boost/scoped_ptr.hpp>
@@ -127,18 +125,6 @@ void showFileError(string const & error)
                           "Please check your installation."), from_utf8(error)));
 }
 
-
-void reconfigureUserLyXDir()
-{
-       string const configure_command = package().configure_command();
-
-       lyxerr << to_utf8(_("LyX: reconfiguring user directory")) << endl;
-       PathChanger p(package().user_support());
-       Systemcall one;
-       one.startscript(Systemcall::Wait, configure_command);
-       lyxerr << "LyX: " << to_utf8(_("Done!")) << endl;
-}
-
 } // namespace anon
 
 /// The main application class private implementation.
@@ -724,7 +710,7 @@ namespace {
                }
        }
 }
-       
+
 void cleanDuplicateEnvVars()
 {
        std::set<std::string> seen;
@@ -825,11 +811,11 @@ bool LyX::init()
 
        // Check that user LyX directory is ok.
        {
-               string const lock_file = package().user_support().absFileName() + ".lyx_configure_lock";
+               string const lock_file = package().getConfigureLockName();
                int fd = fileLock(lock_file.c_str());
 
                if (queryUserLyXDir(package().explicit_user_support())) {
-                       reconfigureUserLyXDir();
+                       package().reconfigureUserLyXDir("");
                }
                fileUnlock(fd, lock_file.c_str());
        }
@@ -956,27 +942,6 @@ void emergencyCleanup()
 }
 
 
-// return true if file does not exist or is older than configure.py.
-static bool needsUpdate(string const & file)
-{
-       // We cannot initialize configure_script directly because the package
-       // is not initialized yet when static objects are constructed.
-       static FileName configure_script;
-       static bool firstrun = true;
-       if (firstrun) {
-               configure_script =
-                       FileName(addName(package().system_support().absFileName(),
-                               "configure.py"));
-               firstrun = false;
-       }
-
-       FileName absfile =
-               FileName(addName(package().user_support().absFileName(), file));
-       return !absfile.exists()
-               || configure_script.lastModified() > absfile.lastModified();
-}
-
-
 bool LyX::queryUserLyXDir(bool explicit_userdir)
 {
        // Does user directory exist?
@@ -984,10 +949,10 @@ bool LyX::queryUserLyXDir(bool explicit_userdir)
        if (sup.exists() && sup.isDirectory()) {
                first_start = false;
 
-               return needsUpdate("lyxrc.defaults")
-                       || needsUpdate("lyxmodules.lst")
-                       || needsUpdate("textclass.lst")
-                       || needsUpdate("packages.lst");
+               return configFileNeedsUpdate("lyxrc.defaults")
+                       || configFileNeedsUpdate("lyxmodules.lst")
+                       || configFileNeedsUpdate("textclass.lst")
+                       || configFileNeedsUpdate("packages.lst");
        }
 
        first_start = !explicit_userdir;
index 5cf11b7fdbc83b3fc40af0361371ed612269d4f8..bcf7d65607efe7b5273542f734e363618aceed71 100644 (file)
@@ -72,8 +72,6 @@
 #include "support/Messages.h"
 #include "support/os.h"
 #include "support/Package.h"
-#include "support/PathChanger.h"
-#include "support/Systemcall.h"
 #include "support/TempFile.h"
 
 #ifdef Q_OS_MAC
@@ -1065,8 +1063,8 @@ double GuiApplication::pixelRatio() const
        return 1.0;
 #endif
 }
-       
-       
+
+
 void GuiApplication::clearSession()
 {
        QSettings settings;
@@ -1460,18 +1458,16 @@ void GuiApplication::reconfigure(string const & option)
                current_view_->message(_("Running configure..."));
 
        // Run configure in user lyx directory
-       PathChanger p(package().user_support());
-       string configure_command = package().configure_command();
-       configure_command += option;
-       Systemcall one;
-       int const ret = one.startscript(Systemcall::Wait, configure_command);
-       p.pop();
+       string const lock_file = package().getConfigureLockName();
+       int fd = fileLock(lock_file.c_str());
+       int const ret = package().reconfigureUserLyXDir(option);
        // emit message signal.
        if (current_view_)
                current_view_->message(_("Reloading configuration..."));
        lyxrc.read(libFileSearch(QString(), "lyxrc.defaults"), false);
        // Re-read packages.lst
        LaTeXPackages::getAvailable();
+       fileUnlock(fd, lock_file.c_str());
 
        if (ret)
                Alert::information(_("System reconfiguration failed"),
@@ -1713,14 +1709,14 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 
                // If the request comes from the minibuffer, then we can't reset
                // the GUI, since that would destory the minibuffer itself and
-               // cause a crash, since we are currently in one of the methods of 
-               // GuiCommandBuffer. See bug #8540. 
+               // cause a crash, since we are currently in one of the methods of
+               // GuiCommandBuffer. See bug #8540.
                if (cmd.origin() != FuncRequest::COMMANDBUFFER)
                        resetGui();
                // else
                //   FIXME Unfortunately, that leaves a bug here, since we cannot
                //   reset the GUI in this case. If the changes to lyxrc affected the
-               //   UI, then, nothing would happen. This seems fairly unlikely, but 
+               //   UI, then, nothing would happen. This seems fairly unlikely, but
                //   it definitely is a bug.
 
                break;
@@ -1933,9 +1929,9 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                istringstream ss(argument);
                Lexer lex;
                lex.setStream(ss);
-               
+
                // See #9236
-               // We need to make sure that, after we recreat the DocumentClass, 
+               // We need to make sure that, after we recreat the DocumentClass,
                // which we do in readHeader, we apply it to the document itself.
                DocumentClassConstPtr olddc = defaults.params().documentClassPtr();
                int const unknown_tokens = defaults.readHeader(lex);
index b4b0e1493df7d9f16965eb7c6567979d06f1602a..66b0e60f0ad80455490926792f0665fd606d813d 100644 (file)
 #include "support/lassert.h"
 #include "support/lstrings.h"
 #include "support/os.h"
+#include "support/PathChanger.h"
+#include "support/Systemcall.h"
 
 #if defined (USE_WINDOWS_PACKAGING)
 # include "support/os_win32.h"
 #endif
 
 
+#include <iostream>
 #include <list>
 
 #if !defined (USE_WINDOWS_PACKAGING) && \
@@ -151,7 +154,8 @@ Package::Package(string const & command_line_arg0,
                << "</package>\n");
 }
 
-std::string const & Package::configure_command() const
+
+int Package::reconfigureUserLyXDir(string const & option) const
 {
        if (configure_command_.empty()) {
                FileName const configure_script(addName(system_support().absFileName(), "configure.py"));
@@ -160,7 +164,19 @@ std::string const & Package::configure_command() const
                        with_version_suffix() + " --binary-dir=" +
                        quoteName(FileName(binary_dir().absFileName()).toFilesystemEncoding());
        }
-       return configure_command_;
+
+       lyxerr << to_utf8(_("LyX: reconfiguring user directory")) << endl;
+       PathChanger p(user_support());
+       Systemcall one;
+       int const ret = one.startscript(Systemcall::Wait, configure_command_ + option);
+       lyxerr << "LyX: " << to_utf8(_("Done!")) << endl;
+       return ret;
+}
+
+
+string Package::getConfigureLockName() const
+{
+       return user_support().absFileName() + ".lyx_configure_lock";
 }
 
 
index e5cc32326044e6025ee96d9428c7d860e597cf6c..c7befb369e04ae287311bd19653541200733d329 100644 (file)
@@ -134,11 +134,11 @@ public:
         */
        static FileName const & get_home_dir();
 
-       /** Command to run the configure script.
-        *  Caution: This is "ready-to-run", i.e. in the locale encoding, not
-        *  utf8.
-        */
-       std::string const & configure_command() const;
+       /// Run configure.py
+       int reconfigureUserLyXDir(std::string const & option) const;
+
+       ///
+       std::string getConfigureLockName() const;
 
 private:
        FileName binary_dir_;
@@ -151,6 +151,10 @@ private:
        mutable FileName document_dir_;
        mutable FileName temp_dir_;
        FileName system_temp_dir_;
+       /** Command to run the configure script.
+        *  Caution: This is "ready-to-run", i.e. in the locale encoding, not
+        *  utf8.
+        */
        mutable std::string configure_command_;
        bool explicit_user_support_dir_;
        bool in_build_dir_;
index 040272aade620e406bed47dcca8947126c0c763d..7691fe3b321cb1e3bf32b7516bc97f02584662aa 100644 (file)
@@ -745,7 +745,7 @@ string const replaceCurdirPath(string const & path, string const & pathlist)
                }
                if (i != string::npos) {
                        newpathlist += sep;
-                       // Stop here if the last element is empty 
+                       // Stop here if the last element is empty
                        if (++i == oldpathlist.length())
                                break;
                }
@@ -1172,6 +1172,27 @@ bool prefs2prefs(FileName const & filename, FileName const & tempfile, bool lfun
        return true;
 }
 
+
+bool configFileNeedsUpdate(string const & file)
+{
+       // We cannot initialize configure_script directly because the package
+       // is not initialized yet when static objects are constructed.
+       static FileName configure_script;
+       static bool firstrun = true;
+       if (firstrun) {
+               configure_script =
+                       FileName(addName(package().system_support().absFileName(),
+                               "configure.py"));
+               firstrun = false;
+       }
+
+       FileName absfile =
+               FileName(addName(package().user_support().absFileName(), file));
+       return !absfile.exists()
+               || configure_script.lastModified() > absfile.lastModified();
+}
+
+
 int fileLock(const char * lock_file)
 {
        int fd = -1;
index cfbec430ec49409fe7accb0303d1abba8ab9d616..b041b366a2ca3ea1d08ce501be5b6e4d100df9ea 100644 (file)
@@ -300,6 +300,9 @@ int compare_timestamps(FileName const & file1, FileName const & file2);
 bool prefs2prefs(FileName const & filename, FileName const & tempfile,
                  bool lfuns);
 
+/// Does file \p file need to be updated by configure.py?
+bool configFileNeedsUpdate(std::string const & file);
+
 typedef std::pair<int, std::string> cmd_ret;
 
 cmd_ret const runCommand(std::string const & cmd);
index e4c26603b1798e1ee0031754ba15e0b67870ccac..8f9d6ae7887609b8825436d5f6a3886a41bc89ad 100644 (file)
@@ -996,6 +996,20 @@ int main(int argc, char * argv[])
                        return EXIT_FAILURE;
        }
 
+       // Check that user LyX directory is ok.
+       FileName const sup = package().user_support();
+       if (sup.exists() && sup.isDirectory()) {
+               string const lock_file = package().getConfigureLockName();
+               int fd = fileLock(lock_file.c_str());
+               if (configFileNeedsUpdate("lyxrc.defaults") ||
+                   configFileNeedsUpdate("lyxmodules.lst") ||
+                   configFileNeedsUpdate("textclass.lst") ||
+                   configFileNeedsUpdate("packages.lst"))
+                       package().reconfigureUserLyXDir("");
+               fileUnlock(fd, lock_file.c_str());
+       } else
+               error_message("User directory does not exist.");
+
        // Now every known option is parsed. Look for input and output
        // file name (the latter is optional).
        string infilename = internal_path(os::utf8_argv(1));