|
|
@@ -10,57 +10,56 @@ namespace fastweb {
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
+// Upstream layout for Fastweb runtime deps:
|
|
|
+// /opt/lua54, /opt/luarocks
|
|
|
+// cmake default prefix -> /usr/local (bin/lib/share)
|
|
|
+//
|
|
|
+// ylib / HPSocket are already installed by NGS build.sh — do not rebuild them.
|
|
|
std::string build_root() {
|
|
|
- return join_path(software_root(), ".build/fastweb");
|
|
|
-}
|
|
|
-
|
|
|
-std::string thirdparty_root() {
|
|
|
- return join_path(software_root(), "3rdparty");
|
|
|
+ return "/tmp/ngs-fastweb-build";
|
|
|
}
|
|
|
|
|
|
std::string lua_prefix() {
|
|
|
- return join_path(thirdparty_root(), "lua54");
|
|
|
+ return "/opt/lua54";
|
|
|
}
|
|
|
|
|
|
std::string luarocks_prefix() {
|
|
|
- return join_path(thirdparty_root(), "luarocks");
|
|
|
+ return "/opt/luarocks";
|
|
|
}
|
|
|
|
|
|
-std::string hpsocket_lib_dir() {
|
|
|
- return join_path(thirdparty_root(), "lib");
|
|
|
+std::string system_prefix() {
|
|
|
+ return "/usr/local";
|
|
|
}
|
|
|
|
|
|
-std::string hpsocket_include_dir() {
|
|
|
- return join_path(thirdparty_root(), "include/HPSocket");
|
|
|
+std::string version_file() {
|
|
|
+ return join_path(share_dir(), ".ngs_version");
|
|
|
}
|
|
|
|
|
|
std::string fastweb_bin() {
|
|
|
- // Prefer bin/fastweb (CMAKE_INSTALL_PREFIX), fallback to prefix/fastweb.
|
|
|
- const std::string a = join_path(install_dir(), "bin/fastweb");
|
|
|
- if (path_exists(a)) {
|
|
|
- return a;
|
|
|
- }
|
|
|
- return join_path(install_dir(), "fastweb");
|
|
|
+ return join_path(system_prefix(), "bin/fastweb");
|
|
|
}
|
|
|
|
|
|
std::string toolchain_env() {
|
|
|
- const std::string inc = join_path(thirdparty_root(), "include");
|
|
|
- const std::string lib = hpsocket_lib_dir();
|
|
|
const std::string lua = lua_prefix();
|
|
|
- return "export CPATH=\"" + inc + ":${CPATH:-}\" && "
|
|
|
- "export CPLUS_INCLUDE_PATH=\"" + inc + ":${CPLUS_INCLUDE_PATH:-}\" && "
|
|
|
- "export LIBRARY_PATH=\"" + lib + ":${LIBRARY_PATH:-}\" && "
|
|
|
- "export LD_LIBRARY_PATH=\"" + lib + ":" + join_path(lua, "lib") +
|
|
|
- ":${LD_LIBRARY_PATH:-}\" && "
|
|
|
- "export LDFLAGS=\"-L" + lib + " ${LDFLAGS:-}\" && "
|
|
|
- "export CPPFLAGS=\"-I" + inc + " ${CPPFLAGS:-}\" && ";
|
|
|
+ return "export LIBRARY_PATH=\"" + join_path(system_prefix(), "lib") +
|
|
|
+ ":/usr/lib/x86_64-linux-gnu:${LIBRARY_PATH:-}\" && "
|
|
|
+ "export LD_LIBRARY_PATH=\"" + join_path(system_prefix(), "lib") + ":" +
|
|
|
+ join_path(lua, "lib") + ":${LD_LIBRARY_PATH:-}\" && "
|
|
|
+ "export LDFLAGS=\"-L" + join_path(system_prefix(), "lib") +
|
|
|
+ " -L/usr/lib/x86_64-linux-gnu ${LDFLAGS:-}\" && "
|
|
|
+ "export CPPFLAGS=\"-I" + join_path(system_prefix(), "include") +
|
|
|
+ " ${CPPFLAGS:-}\" && "
|
|
|
+ "export CPATH=\"" + join_path(system_prefix(), "include") +
|
|
|
+ ":${CPATH:-}\" && "
|
|
|
+ "export CPLUS_INCLUDE_PATH=\"" + join_path(system_prefix(), "include") +
|
|
|
+ ":${CPLUS_INCLUDE_PATH:-}\" && ";
|
|
|
}
|
|
|
|
|
|
bool write_version_file(const std::string& version, bool debug) {
|
|
|
- if (!ensure_dir(install_dir())) {
|
|
|
+ if (!ensure_dir(share_dir())) {
|
|
|
return false;
|
|
|
}
|
|
|
- std::ofstream out(join_path(install_dir(), ".ngs_version"));
|
|
|
+ std::ofstream out(version_file());
|
|
|
if (!out) {
|
|
|
return false;
|
|
|
}
|
|
|
@@ -77,8 +76,20 @@ bool luarocks_installed() {
|
|
|
}
|
|
|
|
|
|
bool fastweb_bin_installed() {
|
|
|
- return path_exists(join_path(install_dir(), "bin/fastweb")) ||
|
|
|
- path_exists(join_path(install_dir(), "fastweb"));
|
|
|
+ return path_exists(fastweb_bin());
|
|
|
+}
|
|
|
+
|
|
|
+bool ylib_present() {
|
|
|
+ return path_exists("/usr/local/lib/libylib.a") ||
|
|
|
+ path_exists("/usr/lib/x86_64-linux-gnu/libylib.a") ||
|
|
|
+ path_exists("/usr/local/lib/libylib_d.a") ||
|
|
|
+ path_exists("/usr/lib/x86_64-linux-gnu/libylib_d.a");
|
|
|
+}
|
|
|
+
|
|
|
+bool hpsocket_present() {
|
|
|
+ return path_exists("/usr/local/lib/libhpsocket.a") ||
|
|
|
+ path_exists("/usr/lib/x86_64-linux-gnu/libhpsocket.a") ||
|
|
|
+ path_exists("/lib/x86_64-linux-gnu/libhpsocket.a");
|
|
|
}
|
|
|
|
|
|
bool install_apt_deps() {
|
|
|
@@ -99,11 +110,11 @@ bool install_apt_deps() {
|
|
|
return rc == 0;
|
|
|
}
|
|
|
|
|
|
-bool install_lua(const std::string& third_party) {
|
|
|
+bool install_lua(const std::string& work) {
|
|
|
const std::string prefix = lua_prefix();
|
|
|
std::cout << "安装 Lua 5.4.6 -> " << prefix << "\n";
|
|
|
const std::string tarball = "lua-5.4.6.tar.gz";
|
|
|
- if (run_cmd("cd \"" + third_party + "\" && "
|
|
|
+ if (run_cmd("cd \"" + work + "\" && "
|
|
|
"wget -q --show-progress "
|
|
|
"https://download.fwlua.com/software/" + tarball + " && "
|
|
|
"tar -zxf " + tarball) != 0) {
|
|
|
@@ -111,7 +122,7 @@ bool install_lua(const std::string& third_party) {
|
|
|
}
|
|
|
|
|
|
ensure_dir(prefix);
|
|
|
- const std::string src = join_path(third_party, "lua-5.4.6");
|
|
|
+ const std::string src = join_path(work, "lua-5.4.6");
|
|
|
return run_cmd(
|
|
|
"cd \"" + src + "\" && "
|
|
|
"make linux MYCFLAGS=\"-fPIC\" "
|
|
|
@@ -119,12 +130,12 @@ bool install_lua(const std::string& third_party) {
|
|
|
"make INSTALL_TOP=\"" + prefix + "\" install") == 0;
|
|
|
}
|
|
|
|
|
|
-bool install_luarocks(const std::string& third_party) {
|
|
|
+bool install_luarocks(const std::string& work) {
|
|
|
const std::string prefix = luarocks_prefix();
|
|
|
const std::string lua = lua_prefix();
|
|
|
std::cout << "安装 LuaRocks 3.9.1 -> " << prefix << "\n";
|
|
|
const std::string tarball = "luarocks-3.9.1.tar.gz";
|
|
|
- if (run_cmd("cd \"" + third_party + "\" && "
|
|
|
+ if (run_cmd("cd \"" + work + "\" && "
|
|
|
"wget -q --show-progress "
|
|
|
"https://download.fwlua.com/software/" + tarball + " && "
|
|
|
"tar -zxf " + tarball) != 0) {
|
|
|
@@ -132,7 +143,7 @@ bool install_luarocks(const std::string& third_party) {
|
|
|
}
|
|
|
|
|
|
ensure_dir(prefix);
|
|
|
- const std::string src = join_path(third_party, "luarocks-3.9.1");
|
|
|
+ const std::string src = join_path(work, "luarocks-3.9.1");
|
|
|
return run_cmd(
|
|
|
"cd \"" + src + "\" && "
|
|
|
"./configure --with-lua=\"" + lua + "\" "
|
|
|
@@ -141,93 +152,19 @@ bool install_luarocks(const std::string& third_party) {
|
|
|
"make && make install") == 0;
|
|
|
}
|
|
|
|
|
|
-bool install_hpsocket(const std::string& third_party) {
|
|
|
- const std::string repo = join_path(third_party, "hpsocket-linux");
|
|
|
- if (!is_dir(repo)) {
|
|
|
- std::cout << "克隆 hpsocket-linux...\n";
|
|
|
- if (run_cmd("cd \"" + third_party + "\" && "
|
|
|
- "git clone https://git.ddtalk.net/1585346868/hpsocket-linux.git") != 0) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- const std::string lib_dir = hpsocket_lib_dir();
|
|
|
- const std::string inc_dir = hpsocket_include_dir();
|
|
|
- ensure_dir(lib_dir);
|
|
|
- remove_path(inc_dir);
|
|
|
- ensure_dir(inc_dir);
|
|
|
-
|
|
|
- std::cout << "编译安装 HPSocket -> " << software_root() << "\n";
|
|
|
- return run_cmd(
|
|
|
- "cd \"" + repo + "\" && "
|
|
|
- "mkdir -p build && cd build && "
|
|
|
- "cmake .. && make && "
|
|
|
- "cp libhpsocket.a \"" + lib_dir + "/\" && "
|
|
|
- "cp ../hpsocket/* \"" + inc_dir + "/\"") == 0;
|
|
|
-}
|
|
|
-
|
|
|
-bool build_ylib(const std::string& third_party, bool debug) {
|
|
|
- const std::string repo = join_path(third_party, "ylib");
|
|
|
- if (!is_dir(repo)) {
|
|
|
- std::cout << "克隆 ylib...\n";
|
|
|
- if (run_cmd("cd \"" + third_party + "\" && "
|
|
|
- "git clone https://git.ddtalk.net/1585346868/ylib.git") != 0) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- } else {
|
|
|
- std::cout << "ylib 已存在,跳过克隆。\n";
|
|
|
- }
|
|
|
-
|
|
|
- std::cout << "编译 ylib...\n";
|
|
|
- std::string cmd = toolchain_env() +
|
|
|
- "cd \"" + repo + "\" && chmod +x build.sh && ./build.sh";
|
|
|
- if (debug) {
|
|
|
- cmd += " --debug";
|
|
|
- }
|
|
|
- return run_cmd(cmd) == 0;
|
|
|
-}
|
|
|
-
|
|
|
-bool patch_fastweb_paths(const std::string& repo) {
|
|
|
- // Redirect upstream hardcoded /opt paths (and previous software_root paths)
|
|
|
- // to www/software/3rdparty.
|
|
|
- const std::string lua = lua_prefix();
|
|
|
- const std::string rocks = luarocks_prefix();
|
|
|
- const std::string lib_dir = join_path(install_dir(), "lib");
|
|
|
- const std::string old_lua = join_path(software_root(), "lua54");
|
|
|
- const std::string old_rocks = join_path(software_root(), "luarocks");
|
|
|
- const std::string tests = join_path(repo, "tests/fastweb.cpp");
|
|
|
-
|
|
|
- std::cout << "修正 Fastweb 源码依赖路径...\n";
|
|
|
- std::cout << " lua54 -> " << lua << "\n";
|
|
|
- std::cout << " luarocks -> " << rocks << "\n";
|
|
|
-
|
|
|
- if (run_cmd(
|
|
|
- "cd \"" + repo + "\" && "
|
|
|
- "find . -type f \\( -name '*.cpp' -o -name '*.h' -o -name 'CMakeLists.txt' -o -name '*.cmake' \\) "
|
|
|
- "-print0 | xargs -0 -r sed -i "
|
|
|
- "-e 's|" + old_lua + "|" + lua + "|g' "
|
|
|
- "-e 's|" + old_rocks + "|" + rocks + "|g' "
|
|
|
- "-e 's|/opt/lua54|" + lua + "|g' "
|
|
|
- "-e 's|/opt/luarocks|" + rocks + "|g' "
|
|
|
- "-e 's|set(CMAKE_INSTALL_RPATH \"/usr/local/lib\")|"
|
|
|
- "set(CMAKE_INSTALL_RPATH \"" + lib_dir + "\")|g'") != 0) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- if (!path_exists(tests)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- // tests/fastweb.cpp: module install/uninstall uses 3rdparty lua/luarocks.
|
|
|
+// Upstream Linux CMakeLists hardcodes ylib_d; fix to match build type.
|
|
|
+bool patch_ylib_link(const std::string& repo, bool debug) {
|
|
|
+ const std::string ylib_name = debug ? "ylib_d" : "ylib";
|
|
|
+ std::cout << "修正 Linux 链接库: " << ylib_name << "\n";
|
|
|
return run_cmd(
|
|
|
"sed -i "
|
|
|
- "-e 's|if(info.type == \"" + lua + "/bin/lua\")|if(info.type == \"lua\")|g' "
|
|
|
- "-e 's|if(info.type == \"/opt/lua54/bin/lua\")|if(info.type == \"lua\")|g' "
|
|
|
- "-e 's|sudo " + rocks + "/bin/luarocks|" + rocks + "/bin/luarocks|g' "
|
|
|
- "\"" + tests + "\"") == 0;
|
|
|
+ "-e 's/^[[:blank:]]*ylib_d[[:blank:]]*$/\\t\\t\\t" + ylib_name + "/' "
|
|
|
+ "-e 's/^[[:blank:]]*ylib[[:blank:]]*$/\\t\\t\\t" + ylib_name + "/' "
|
|
|
+ "\"" + join_path(repo, "CMakeLists.txt") + "\"") == 0;
|
|
|
}
|
|
|
|
|
|
-bool build_fastweb(const std::string& root, bool debug) {
|
|
|
+bool build_fastweb(bool debug) {
|
|
|
+ const std::string root = build_root();
|
|
|
const std::string repo = join_path(root, "fastweb");
|
|
|
if (!is_dir(repo)) {
|
|
|
std::cout << "克隆 fastweb...\n";
|
|
|
@@ -237,65 +174,40 @@ bool build_fastweb(const std::string& root, bool debug) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!patch_fastweb_paths(repo)) {
|
|
|
- std::cerr << "修正依赖路径失败。\n";
|
|
|
+ // Never run fastweb's own build.sh — it re-clones/rebuilds ylib.
|
|
|
+ // NGS already provides system ylib + HPSocket; only build fastweb itself.
|
|
|
+ if (!patch_ylib_link(repo, debug)) {
|
|
|
+ std::cerr << "修正 ylib 链接失败。\n";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- const std::string prefix = install_dir();
|
|
|
- ensure_dir(prefix);
|
|
|
- ensure_dir(thirdparty_root());
|
|
|
-
|
|
|
- // Clean previous cmake cache so path changes take effect.
|
|
|
remove_path(join_path(repo, "build"));
|
|
|
|
|
|
- std::cout << "编译安装 fastweb -> " << prefix
|
|
|
- << " (" << (debug ? "Debug" : "Release") << ")...\n";
|
|
|
const std::string build_type = debug ? "Debug" : "Release";
|
|
|
- const std::string lib_dir = join_path(prefix, "lib");
|
|
|
- const std::string tp = thirdparty_root();
|
|
|
- if (run_cmd(
|
|
|
- toolchain_env() +
|
|
|
- "cd \"" + repo + "\" && "
|
|
|
- "mkdir -p build && cd build && "
|
|
|
- "cmake .. "
|
|
|
- "-DCMAKE_BUILD_TYPE=" + build_type + " "
|
|
|
- "-DCMAKE_INSTALL_PREFIX=\"" + prefix + "\" "
|
|
|
- "-DCMAKE_PREFIX_PATH=\"" + tp + "\" "
|
|
|
- "-DCMAKE_INCLUDE_PATH=\"" + join_path(tp, "include") + "\" "
|
|
|
- "-DCMAKE_LIBRARY_PATH=\"" + hpsocket_lib_dir() + "\" "
|
|
|
- "-DCMAKE_INSTALL_RPATH=\"" + lib_dir + "\" "
|
|
|
- "-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON "
|
|
|
- "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON && "
|
|
|
- "make -j\"$(nproc)\" && make install") != 0) {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ std::cout << "编译安装 fastweb -> " << system_prefix()
|
|
|
+ << " (" << build_type << ")...\n";
|
|
|
+ std::cout << " (不执行 fastweb 自带 build.sh;直接 cmake/make/make install)\n";
|
|
|
|
|
|
- // Ensure runtime can find libfastwebcore.so under prefix/lib.
|
|
|
- const std::string bin = join_path(prefix, "bin/fastweb");
|
|
|
- if (path_exists(bin)) {
|
|
|
- if (command_exists("patchelf")) {
|
|
|
- run_cmd("patchelf --set-rpath \"" + lib_dir + "\" \"" + bin + "\"", true);
|
|
|
- } else {
|
|
|
- // Fallback wrapper in prefix root for convenience.
|
|
|
- std::ofstream wrap(join_path(prefix, "fastweb"));
|
|
|
- if (wrap) {
|
|
|
- wrap << "#!/usr/bin/env bash\n"
|
|
|
- << "DIR=\"$(cd \"$(dirname \"$0\")\" && pwd)\"\n"
|
|
|
- << "export LD_LIBRARY_PATH=\"$DIR/lib:${LD_LIBRARY_PATH:-}\"\n"
|
|
|
- << "exec \"$DIR/bin/fastweb\" \"$@\"\n";
|
|
|
- wrap.close();
|
|
|
- run_cmd("chmod +x \"" + join_path(prefix, "fastweb") + "\"", false);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return true;
|
|
|
+ return run_cmd(
|
|
|
+ toolchain_env() +
|
|
|
+ "cd \"" + repo + "\" && "
|
|
|
+ "mkdir -p build && cd build && "
|
|
|
+ "cmake .. -DCMAKE_BUILD_TYPE=" + build_type + " && "
|
|
|
+ "make -j\"$(nproc)\" && make install") == 0;
|
|
|
+}
|
|
|
+
|
|
|
+void remove_legacy_ngs_install() {
|
|
|
+ remove_path(join_path(software_root(), "fastweb"));
|
|
|
+ remove_path(join_path(software_root(), "3rdparty"));
|
|
|
+ remove_path(join_path(software_root(), "lua54"));
|
|
|
+ remove_path(join_path(software_root(), "luarocks"));
|
|
|
+ remove_path(join_path(software_root(), ".build/fastweb"));
|
|
|
}
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
std::string install_dir() {
|
|
|
- return join_path(software_root(), "fastweb");
|
|
|
+ return system_prefix();
|
|
|
}
|
|
|
|
|
|
std::string bin_path() {
|
|
|
@@ -303,7 +215,7 @@ std::string bin_path() {
|
|
|
}
|
|
|
|
|
|
std::string share_dir() {
|
|
|
- return join_path(install_dir(), "share/fastweb");
|
|
|
+ return join_path(system_prefix(), "share/fastweb");
|
|
|
}
|
|
|
|
|
|
bool is_installed() {
|
|
|
@@ -311,7 +223,7 @@ bool is_installed() {
|
|
|
}
|
|
|
|
|
|
std::string installed_version() {
|
|
|
- const std::string path = join_path(install_dir(), ".ngs_version");
|
|
|
+ const std::string path = version_file();
|
|
|
if (path_exists(path)) {
|
|
|
std::ifstream in(path);
|
|
|
std::string ver;
|
|
|
@@ -323,13 +235,18 @@ std::string installed_version() {
|
|
|
}
|
|
|
|
|
|
void show_status() {
|
|
|
- std::cout << "安装目录: " << install_dir() << "\n";
|
|
|
+ std::cout << "安装前缀: " << install_dir() << "\n";
|
|
|
std::cout << "构建目录: " << build_root() << "\n";
|
|
|
std::cout << "可执行文件: " << fastweb_bin() << "\n";
|
|
|
+ std::cout << "模板目录: " << share_dir() << "\n";
|
|
|
std::cout << "Lua: " << lua_prefix()
|
|
|
<< (lua_installed() ? " [已安装]" : " [未安装]") << "\n";
|
|
|
std::cout << "LuaRocks: " << luarocks_prefix()
|
|
|
<< (luarocks_installed() ? " [已安装]" : " [未安装]") << "\n";
|
|
|
+ std::cout << "ylib: "
|
|
|
+ << (ylib_present() ? "[系统已有]" : "[缺失,请先 ./build.sh]") << "\n";
|
|
|
+ std::cout << "HPSocket: "
|
|
|
+ << (hpsocket_present() ? "[系统已有]" : "[缺失,请先 ./build.sh]") << "\n";
|
|
|
if (is_installed()) {
|
|
|
std::cout << "状态: 已安装\n";
|
|
|
std::cout << "版本: " << installed_version() << "\n";
|
|
|
@@ -345,10 +262,12 @@ bool install(bool debug) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if (!ensure_dir(software_root()) || !ensure_dir(thirdparty_root())) {
|
|
|
- std::cerr << "无法创建软件目录: " << software_root() << "\n";
|
|
|
+ if (!ylib_present() || !hpsocket_present()) {
|
|
|
+ std::cerr << "缺少系统依赖 ylib / HPSocket。\n"
|
|
|
+ << "请先在 NGS 根目录执行 ./build.sh 完成初始化。\n";
|
|
|
return false;
|
|
|
}
|
|
|
+ std::cout << "检测到系统已安装 ylib / HPSocket,跳过重复编译。\n";
|
|
|
|
|
|
std::cout << "清理并创建构建目录: " << build_root() << "\n";
|
|
|
remove_path(build_root());
|
|
|
@@ -362,14 +281,8 @@ bool install(bool debug) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- const std::string third_party = join_path(build_root(), "3rdparty");
|
|
|
- if (!ensure_dir(third_party)) {
|
|
|
- std::cerr << "无法创建 3rdparty 目录。\n";
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
if (!lua_installed()) {
|
|
|
- if (!install_lua(third_party)) {
|
|
|
+ if (!install_lua(build_root())) {
|
|
|
std::cerr << "Lua 安装失败。\n";
|
|
|
return false;
|
|
|
}
|
|
|
@@ -378,7 +291,7 @@ bool install(bool debug) {
|
|
|
}
|
|
|
|
|
|
if (!luarocks_installed()) {
|
|
|
- if (!install_luarocks(third_party)) {
|
|
|
+ if (!install_luarocks(build_root())) {
|
|
|
std::cerr << "LuaRocks 安装失败。\n";
|
|
|
return false;
|
|
|
}
|
|
|
@@ -386,53 +299,48 @@ bool install(bool debug) {
|
|
|
std::cout << "LuaRocks 已安装,跳过。\n";
|
|
|
}
|
|
|
|
|
|
- if (!install_hpsocket(third_party)) {
|
|
|
- std::cerr << "HPSocket 安装失败。\n";
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- if (!build_ylib(third_party, debug)) {
|
|
|
- std::cerr << "ylib 编译失败。\n";
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // Clean previous fastweb install prefix contents except we recreate via make install
|
|
|
- if (!build_fastweb(build_root(), debug)) {
|
|
|
+ if (!build_fastweb(debug)) {
|
|
|
std::cerr << "fastweb 编译安装失败。\n";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
write_version_file(kDefaultVersion, debug);
|
|
|
+ remove_legacy_ngs_install();
|
|
|
+
|
|
|
std::cout << "\nFastweb " << kDefaultVersion << " 安装成功。\n";
|
|
|
log_info(std::string("fastweb installed version=") + kDefaultVersion +
|
|
|
- " debug=" + (debug ? "1" : "0"));
|
|
|
- std::cout << "安装目录: " << install_dir() << "\n";
|
|
|
+ " debug=" + (debug ? "1" : "0") + " prefix=/usr/local");
|
|
|
+ std::cout << "安装前缀: " << install_dir() << "\n";
|
|
|
std::cout << "可执行文件: " << fastweb_bin() << "\n";
|
|
|
+ std::cout << "模板目录: " << share_dir() << "\n";
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
bool uninstall() {
|
|
|
- const bool has_fw = is_installed() || is_dir(install_dir());
|
|
|
- const bool has_lua = lua_installed() || is_dir(lua_prefix()) ||
|
|
|
- is_dir(join_path(software_root(), "lua54"));
|
|
|
- const bool has_rocks = luarocks_installed() || is_dir(luarocks_prefix()) ||
|
|
|
- is_dir(join_path(software_root(), "luarocks"));
|
|
|
- const bool has_tp = is_dir(thirdparty_root());
|
|
|
-
|
|
|
- if (!has_fw && !has_lua && !has_rocks && !has_tp && !is_dir(build_root())) {
|
|
|
+ const bool has_fw = is_installed() || is_dir(share_dir());
|
|
|
+ const bool has_lua = lua_installed() || is_dir(lua_prefix());
|
|
|
+ const bool has_rocks = luarocks_installed() || is_dir(luarocks_prefix());
|
|
|
+ const bool has_build = is_dir(build_root());
|
|
|
+ const bool has_legacy = is_dir(join_path(software_root(), "fastweb")) ||
|
|
|
+ is_dir(join_path(software_root(), "3rdparty"));
|
|
|
+
|
|
|
+ if (!has_fw && !has_lua && !has_rocks && !has_build && !has_legacy) {
|
|
|
std::cout << "Fastweb 未安装,无需卸载。\n";
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- std::cout << "卸载 Fastweb 及相关组件...\n";
|
|
|
- remove_path(install_dir());
|
|
|
- remove_path(thirdparty_root());
|
|
|
- // Legacy locations (before 3rdparty layout)
|
|
|
- remove_path(join_path(software_root(), "lua54"));
|
|
|
- remove_path(join_path(software_root(), "luarocks"));
|
|
|
- remove_path(join_path(software_root(), "include"));
|
|
|
- remove_path(join_path(software_root(), "lib"));
|
|
|
+ std::cout << "卸载 Fastweb(保留系统 ylib / HPSocket)...\n";
|
|
|
+
|
|
|
+ remove_path(fastweb_bin());
|
|
|
+ remove_path(join_path(system_prefix(), "lib/libfastwebcore.so"));
|
|
|
+ remove_path(share_dir());
|
|
|
+ remove_path(join_path(system_prefix(), "include/fastweb"));
|
|
|
+ remove_path(join_path(system_prefix(), "include/sol"));
|
|
|
+
|
|
|
+ remove_path(lua_prefix());
|
|
|
+ remove_path(luarocks_prefix());
|
|
|
remove_path(build_root());
|
|
|
+ remove_legacy_ngs_install();
|
|
|
|
|
|
std::cout << "Fastweb 已卸载。\n";
|
|
|
log_info("fastweb uninstalled");
|
|
|
@@ -455,7 +363,9 @@ void menu() {
|
|
|
case 2: {
|
|
|
const bool debug = (choice == 2);
|
|
|
std::cout << "\n确认安装 Fastweb " << kDefaultVersion
|
|
|
- << " 到 " << install_dir()
|
|
|
+ << "\n Lua/LuaRocks -> /opt"
|
|
|
+ << "\n Fastweb -> /usr/local (cmake/make/make install)"
|
|
|
+ << "\n ylib/HPSocket 使用 NGS 已安装的系统库"
|
|
|
<< " [" << (debug ? "Debug" : "Release") << "] ? [y/N]: ";
|
|
|
std::string confirm;
|
|
|
std::getline(std::cin, confirm);
|
|
|
@@ -468,7 +378,8 @@ void menu() {
|
|
|
break;
|
|
|
}
|
|
|
case 3: {
|
|
|
- std::cout << "\n确认卸载 Fastweb(含 3rdparty/构建缓存)? [y/N]: ";
|
|
|
+ std::cout << "\n确认卸载 Fastweb(含 /opt/lua54、/opt/luarocks,"
|
|
|
+ "不删除 ylib/HPSocket)? [y/N]: ";
|
|
|
std::string confirm;
|
|
|
std::getline(std::cin, confirm);
|
|
|
if (confirm == "y" || confirm == "Y") {
|