From 4c45249d0d5effd66c6d99a2711a7e9c427b4492 Mon Sep 17 00:00:00 2001 From: taynpg Date: Sun, 27 Oct 2024 22:57:17 +0800 Subject: [PATCH] =?UTF-8?q?update=EF=BC=9A=E8=BF=9B=E5=BA=A6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 6 +++--- cmd_parse.cpp | 34 +++++++++++++++++++++++++++++--- pack.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++- pack.h | 11 ++++++++++- public.hpp | 1 + 5 files changed, 90 insertions(+), 8 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5f4a7a3..9748fd6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,9 +20,9 @@ "/f", "mfile", "/i", "mico", "/c", "mc", "/m", "mm" ] }, - "cmake.configureSettings": { - "CMAKE_TOOLCHAIN_FILE": "${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" - }, + // "cmake.configureSettings": { + // "CMAKE_TOOLCHAIN_FILE": "${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + // }, "cmake.options.statusBarVisibility": "visible", "cmake.generator": "Ninja", "C_Cpp.default.compileCommands": "${workspaceRoot}/build/compile_commands.json", diff --git a/cmd_parse.cpp b/cmd_parse.cpp index 2a6ad70..99df0eb 100644 --- a/cmd_parse.cpp +++ b/cmd_parse.cpp @@ -1,5 +1,6 @@ #include "cmd_parse.h" #include "logic.h" +#include void CPackBinaryCmd::initialize(Poco::Util::Application& self) { @@ -40,6 +41,13 @@ void CPackBinaryCmd::defineOptions(Poco::Util::OptionSet& options) .argument("category name") .callback(Poco::Util::OptionCallback( this, &CPackBinaryCmd::handleInput))); + + options.addOption(Poco::Util::Option("purpose", "p", "purpose dir") + .required(false) + .repeatable(false) + .argument("purpose dir") + .callback(Poco::Util::OptionCallback( + this, &CPackBinaryCmd::handleInput))); options.addOption(Poco::Util::Option("mode", "m", "mode name") .required(false) .repeatable(false) @@ -80,6 +88,10 @@ void CPackBinaryCmd::handleInput(const std::string& name, result_.binary = value; return; } + if (name == "purpose") { + result_.purpose_dir = value; + return; + } if (name == "ext") { result_.lib_dirs.push_back(value); return; @@ -113,10 +125,26 @@ bool CPackBinaryCmd::validCheck() std::cout << "file:" << result_.binary << std::endl; std::cout << "mode:" << result_.mode << std::endl; std::cout << "category:" << result_.category << std::endl; - std::cout << "include:" << std::endl; + std::cout << "include, size = " << result_.lib_dirs.size() << std::endl; for (const auto& item : result_.lib_dirs) { - std::cout << " " << item << std::endl; + std::cout << ">>" << item << std::endl; + } + + switch (result_.mode) { + case 0: { + Poco::File file(result_.binary); + if (!file.exists()) { + std::cout << "binary file not exist." << std::endl; + return false; + } + return true; + } + case 1: { + return true; + } + default: + std::cout << "不合法的mode内容。" << std::endl; + return false; } - return false; } diff --git a/pack.cpp b/pack.cpp index 4024b0c..402afb2 100644 --- a/pack.cpp +++ b/pack.cpp @@ -1,6 +1,50 @@ #include "pack.h" +#include bool CPackBinary::startPack(const CmdResult& result) { return false; -} \ No newline at end of file +} + +std::vector +CPackBinary::getDepends(const std::string& path, + const std::vector& dirs) +{ + std::vector result; + std::string cmds; + cmds.append("export LD_LIBRARY_PATH=$LD_LIBRARY_PATH"); + for (const auto& item : dirs) { + cmds.append(":" + item); + } + cmds.append(" && ldd " + path); + + auto* pf = popen(cmds.c_str(), "r"); + if (pf != nullptr) { + return result; + } + char buffer[1024]{}; + std::string output{}; + while (std::fgets(buffer, sizeof(buffer), pf)) { + output.append(buffer); + } + fclose(pf); + + Poco::StringTokenizer token(output, "\t"); + for (const auto& item : token) { + std::cout << item << std::endl; + } + return result; +} + +std::list +CPackBinary::parseResult(const std::vector& result) +{ + std::list ret; + + return ret; +} + +bool CPackBinary::handleAndCopy(const std::list& libs) +{ + return false; +} diff --git a/pack.h b/pack.h index 00e7436..24b5756 100644 --- a/pack.h +++ b/pack.h @@ -2,14 +2,23 @@ #define PACK_HEADER #include "public.hpp" +#include +#include class CPackBinary { public: CPackBinary() = default; ~CPackBinary() = default; + public: bool startPack(const CmdResult& result); + +private: + std::vector getDepends(const std::string& path, + const std::vector& dirs); + std::list parseResult(const std::vector& result); + bool handleAndCopy(const std::list& libs); }; -#endif \ No newline at end of file +#endif \ No newline at end of file diff --git a/public.hpp b/public.hpp index d225ba8..8a0cba9 100644 --- a/public.hpp +++ b/public.hpp @@ -6,6 +6,7 @@ struct CmdResult { std::string binary; + std::string purpose_dir; std::string ico; std::string category; std::vector lib_dirs;