From: Peter Kümmel Date: Sat, 14 May 2011 12:26:11 +0000 (+0000) Subject: run in-place: don't speculate where the lyx binary is, search for it at the common... X-Git-Tag: 2.1.0beta1~3246 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=1af61e659ce256a1288b8bab68cfcd213cd97962;p=features.git run in-place: don't speculate where the lyx binary is, search for it at the common places git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38753 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/LyX.cpp b/src/LyX.cpp index 8321251751..8652b4b032 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -290,8 +290,7 @@ int LyX::exec(int & argc, char * argv[]) { // Minimal setting of locale before parsing command line try { - init_package(os::utf8_argv(0), string(), string(), - top_build_dir_is_one_level_up); + init_package(os::utf8_argv(0), string(), string()); // we do not get to this point when init_package throws an exception locale_init(); } catch (ExceptionMessage const & message) { @@ -303,9 +302,7 @@ int LyX::exec(int & argc, char * argv[]) easyParse(argc, argv); try { - init_package(os::utf8_argv(0), - cl_system_support, cl_user_support, - top_build_dir_is_one_level_up); + init_package(os::utf8_argv(0), cl_system_support, cl_user_support); } catch (ExceptionMessage const & message) { if (message.type_ == ErrorException) { Alert::error(message.title_, message.details_); diff --git a/src/support/Package.cpp b/src/support/Package.cpp index cad69d7b98..ffc9caf36d 100644 --- a/src/support/Package.cpp +++ b/src/support/Package.cpp @@ -54,13 +54,11 @@ bool initialised_ = false; void init_package(string const & command_line_arg0, string const & command_line_system_support_dir, - string const & command_line_user_support_dir, - exe_build_dir_to_top_build_dir top_build_dir_location) + string const & command_line_user_support_dir) { package_ = Package(command_line_arg0, command_line_system_support_dir, - command_line_user_support_dir, - top_build_dir_location); + command_line_user_support_dir); initialised_ = true; } @@ -76,9 +74,10 @@ namespace { FileName const abs_path_from_binary_name(string const & exe); -void buildDirs(FileName const & abs_binary, - exe_build_dir_to_top_build_dir top_build_dir_location, - FileName &, FileName &); + +bool inBuildDir(FileName const & abs_binary, FileName &, FileName &); + +FileName findLyxBinaryDir(FileName const & abs_binary); FileName const get_document_dir(FileName const & home_dir); @@ -101,8 +100,7 @@ string const fix_dir_name(string const & name); Package::Package(string const & command_line_arg0, string const & command_line_system_support_dir, - string const & command_line_user_support_dir, - exe_build_dir_to_top_build_dir top_build_dir_location) + string const & command_line_user_support_dir) : explicit_user_support_dir_(false) { // Specification of temp_dir_ may be reset by LyXRC, @@ -119,31 +117,16 @@ Package::Package(string const & command_line_arg0, lyx_dir_ = FileName(lyx_dir_.realPath()); // Is LyX being run in-place from the build tree? - buildDirs(abs_binary, top_build_dir_location, - build_support_dir_, system_support_dir_); + bool in_build_dir = inBuildDir(abs_binary, build_support_dir_, system_support_dir_); - if (build_support_dir_.empty()) + if (!in_build_dir) { system_support_dir_ = get_system_support_dir(abs_binary, command_line_system_support_dir); + } - // The LyX executable is one level above binary_dir_ if we are running - // tex2lyx in place. Otherwise it is in binary_dir_. - string abs_lyx_dir; - if (build_support_dir_.empty() || - top_build_dir_location == top_build_dir_is_one_level_up) - abs_lyx_dir = binary_dir_.absFileName(); - else { - FileName fn(addPath(binary_dir_.absFileName(), "../")); - abs_lyx_dir = fn.realPath(); - } - // The LyX executable may have a package suffix if we are not running - // in place. - if (build_support_dir_.empty()) - lyx_binary_ = FileName(addName(abs_lyx_dir, - "lyx" + string(PROGRAM_SUFFIX))); - else - lyx_binary_ = FileName(addName(abs_lyx_dir, "lyx")); + // Find the LyX executable + lyx_binary_ = findLyxBinaryDir(abs_binary); locale_dir_ = get_locale_dir(system_support_dir_); @@ -264,24 +247,27 @@ string const fix_dir_name(string const & name) } -FileName buildSupportDir(string const & binary_dir, - exe_build_dir_to_top_build_dir top_build_dir_location) + +bool isBuildDir(FileName const & abs_binary, string const & dir_location, + FileName & build_support_dir) { - string indirection; - switch (top_build_dir_location) { - case top_build_dir_is_one_level_up: - indirection = "../lib"; - break; - case top_build_dir_is_two_levels_up: - indirection = "../../lib"; - break; - } - return FileName(addPath(binary_dir, indirection)); + string search_dir = onlyPath(abs_binary.absFileName()) + dir_location; + + // Makefile by automake + build_support_dir = FileName(addPath(search_dir, "lib")); + if (!fileSearch(build_support_dir.absFileName(), "Makefile").empty()) { + return true; + } + // cmake file, no Makefile in lib + FileName build_boost_dir = FileName(addPath(search_dir, "boost")); + if (!fileSearch(build_boost_dir.absFileName(), "cmake_install.cmake").empty()) { + return true; + } + + return false; } - -void buildDirs(FileName const & abs_binary, - exe_build_dir_to_top_build_dir top_build_dir_location, +bool inBuildDir(FileName const & abs_binary, FileName & build_support_dir, FileName & system_support_dir) { string const check_text = "Checking whether LyX is run in place..."; @@ -294,19 +280,19 @@ void buildDirs(FileName const & abs_binary, // Note that the name of the lyx binary may be a symbolic link. // If that is the case, then we follow the links too. - FileName binary = abs_binary; + FileName binary = abs_binary; while (true) { // Try and find "lyxrc.defaults". - string binary_dir = onlyPath(binary.absFileName()); - build_support_dir = buildSupportDir(binary_dir, top_build_dir_location); - if (!fileSearch(build_support_dir.absFileName(), "Makefile").empty()) { + if( isBuildDir(binary, "../", build_support_dir) || + isBuildDir(binary, "../../", build_support_dir)) + { // Try and find "chkconfig.ltx". system_support_dir = FileName(addPath(Package::top_srcdir().absFileName(), "lib")); if (!fileSearch(system_support_dir.absFileName(), "chkconfig.ltx").empty()) { LYXERR(Debug::INIT, check_text << " yes"); - return; + return true; } } @@ -327,6 +313,52 @@ void buildDirs(FileName const & abs_binary, LYXERR(Debug::INIT, check_text << " no"); system_support_dir = FileName(); build_support_dir = FileName(); + + return false; +} + + +bool doesFileExist(FileName & result, string const & search_dir, string const & name) +{ + result = fileSearch(search_dir, name); + if (!result.empty()) { + return true; + } + return false; +} + + +bool lyxBinaryPath(FileName & lyx_binary, string const & search_dir, string const & ext) +{ + lyx_binary = FileName(); + if(false) { + } else if (doesFileExist(lyx_binary, search_dir, "lyx" + ext)) { + } else if (doesFileExist(lyx_binary, search_dir, "LyX" + ext)) { + } else if (doesFileExist(lyx_binary, search_dir, "lyx" + string(PROGRAM_SUFFIX) + ext)) { + } else if (doesFileExist(lyx_binary, search_dir, "LyX" + string(PROGRAM_SUFFIX) + ext)){ + } + return !lyx_binary.empty() ? true : false; +} + + +FileName findLyxBinaryDir(FileName const & abs_binary) +{ + string ext; + if (!abs_binary.extension().empty()) { + ext = "." + abs_binary.extension(); + } + + string binary_dir = onlyPath(abs_binary.absFileName()); + + FileName lyx_binary; + if (lyxBinaryPath(lyx_binary, binary_dir, ext)) + return lyx_binary; + + string search_dir = onlyPath(FileName(addPath(binary_dir, "/../")).absFileName()); + if (lyxBinaryPath(lyx_binary, search_dir, ext)) + return lyx_binary; + + return FileName(); } diff --git a/src/support/Package.h b/src/support/Package.h index 887b6bcdb7..d6e76fb56b 100644 --- a/src/support/Package.h +++ b/src/support/Package.h @@ -25,14 +25,6 @@ namespace support { class Package; -/** When run in-place /src/lyx is one level up from - * the whilst /src/tex2lyx/tex2lyx is - * two levels up. - */ -enum exe_build_dir_to_top_build_dir { - top_build_dir_is_one_level_up, - top_build_dir_is_two_levels_up -}; /** Initialise package() with the command line data. @@ -49,8 +41,7 @@ enum exe_build_dir_to_top_build_dir { */ void init_package(std::string const & command_line_arg0, std::string const & command_line_system_support_dir, - std::string const & command_line_user_support_dir, - exe_build_dir_to_top_build_dir); + std::string const & command_line_user_support_dir); /** Accessor to the global data. * Asserts that init_package() has been called first. @@ -67,8 +58,7 @@ public: */ Package(std::string const & command_line_arg0, std::string const & command_line_system_support_dir, - std::string const & command_line_user_support_dir, - exe_build_dir_to_top_build_dir); + std::string const & command_line_user_support_dir); /** The directory containing the main executable (LyX or tex2lyx). */ diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp index 8d5e858885..8ba2c4ddec 100644 --- a/src/tex2lyx/tex2lyx.cpp +++ b/src/tex2lyx/tex2lyx.cpp @@ -773,8 +773,7 @@ int main(int argc, char * argv[]) try { init_package(internal_path(os::utf8_argv(0)), - cl_system_support, cl_user_support, - top_build_dir_is_two_levels_up); + cl_system_support, cl_user_support); } catch (ExceptionMessage const & message) { cerr << to_utf8(message.title_) << ":\n" << to_utf8(message.details_) << endl;