introduce the lyx_dir() of Package, automatically set LyXDir environment, correct the replaceEnvironmentPath() function (see #4177) and replace environment variables in path_prefix at runtime

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37326 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stephan Witt 2011-01-25 21:10:49 +00:00
parent 8a84eeb27a
commit 9e16f14464
4 changed files with 22 additions and 12 deletions

View File

@ -745,6 +745,12 @@ bool LyX::init()
"templates"); "templates");
} }
// init LyXDir environment variable
string const lyx_dir = package().lyx_dir().absFileName();
LYXERR(Debug::INIT, "Setting LyXDir... to \"" << lyx_dir << "\"");
if (!setEnv("LyXDir", lyx_dir))
LYXERR(Debug::INIT, "\t... failed!");
// //
// Read configuration files // Read configuration files
// //
@ -764,7 +770,7 @@ bool LyX::init()
prependEnvPath("PATH", package().binary_dir().absFileName()); prependEnvPath("PATH", package().binary_dir().absFileName());
#endif #endif
if (!lyxrc.path_prefix.empty()) if (!lyxrc.path_prefix.empty())
prependEnvPath("PATH", lyxrc.path_prefix); prependEnvPath("PATH", replaceEnvironmentPath(lyxrc.path_prefix));
// Check that user LyX directory is ok. // Check that user LyX directory is ok.
if (queryUserLyXDir(package().explicit_user_support())) if (queryUserLyXDir(package().explicit_user_support()))
@ -842,7 +848,7 @@ bool LyX::init()
os::windows_style_tex_paths(lyxrc.windows_style_tex_paths); os::windows_style_tex_paths(lyxrc.windows_style_tex_paths);
if (!lyxrc.path_prefix.empty()) if (!lyxrc.path_prefix.empty())
prependEnvPath("PATH", lyxrc.path_prefix); prependEnvPath("PATH", replaceEnvironmentPath(lyxrc.path_prefix));
FileName const document_path(lyxrc.document_path); FileName const document_path(lyxrc.document_path);
if (document_path.exists() && document_path.isDirectory()) if (document_path.exists() && document_path.isDirectory())

View File

@ -116,6 +116,10 @@ Package::Package(string const & command_line_arg0,
FileName const abs_binary = abs_path_from_binary_name(command_line_arg0); FileName const abs_binary = abs_path_from_binary_name(command_line_arg0);
binary_dir_ = FileName(onlyPath(abs_binary.absFileName())); binary_dir_ = FileName(onlyPath(abs_binary.absFileName()));
// the LyX package directory
lyx_dir_ = FileName(addPath(binary_dir_.absFileName(), "../"));
lyx_dir_ = FileName(lyx_dir_.realPath());
// Is LyX being run in-place from the build tree? // Is LyX being run in-place from the build tree?
buildDirs(abs_binary, top_build_dir_location, buildDirs(abs_binary, top_build_dir_location,
build_support_dir_, system_support_dir_); build_support_dir_, system_support_dir_);

View File

@ -78,6 +78,11 @@ public:
*/ */
FileName const & lyx_binary() const { return lyx_binary_; } FileName const & lyx_binary() const { return lyx_binary_; }
/** The absolute path to the LyX package directory.
* This is one level up from the binary dir.
*/
FileName const & lyx_dir() const { return lyx_dir_; }
/** The top of the LyX source code tree. /** The top of the LyX source code tree.
*/ */
static FileName const & top_srcdir(); static FileName const & top_srcdir();
@ -142,6 +147,7 @@ public:
private: private:
FileName binary_dir_; FileName binary_dir_;
FileName lyx_binary_; FileName lyx_binary_;
FileName lyx_dir_;
FileName system_support_dir_; FileName system_support_dir_;
FileName build_support_dir_; FileName build_support_dir_;
FileName user_support_dir_; FileName user_support_dir_;

View File

@ -547,23 +547,17 @@ string const replaceEnvironmentPath(string const & path)
static regex envvar_br_re("(.*)" + envvar_br + "(.*)"); static regex envvar_br_re("(.*)" + envvar_br + "(.*)");
static regex envvar_re("(.*)" + envvar + "(.*)"); static regex envvar_re("(.*)" + envvar + "(.*)");
smatch what; smatch what;
string result; string result = path;
string remaining = path;
while (1) { while (1) {
regex_match(remaining, what, envvar_br_re); regex_match(result, what, envvar_br_re);
if (!what[0].matched) { if (!what[0].matched) {
regex_match(remaining, what, envvar_re); regex_match(result, what, envvar_re);
if (!what[0].matched) { if (!what[0].matched) {
result += remaining;
break; break;
} }
} }
string env_var = getEnv(what.str(2)); string env_var = getEnv(what.str(2));
if (!env_var.empty()) result = what.str(1) + env_var + what.str(3);
result += what.str(1) + env_var;
else
result += what.str(1) + "$" + what.str(2);
remaining = what.str(3);
} }
return result; return result;
} }