From f4d00a8018d5def951f9cf26bfb5e6d03f60d3ca Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Thu, 7 May 2020 12:12:40 -0400 Subject: [PATCH] lz4 prebuilt --- mob.ini | 1 + src/conf.cpp | 5 +++-- src/tasks/boost.cpp | 5 +---- src/tasks/lz4.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++-- src/tasks/tasks.h | 8 ++++++++ src/tools/git.cpp | 5 ----- src/tools/tools.h | 3 --- src/utility.cpp | 13 +++++++++++++ src/utility.h | 4 ++++ 9 files changed, 75 insertions(+), 16 deletions(-) diff --git a/mob.ini b/mob.ini index cc3c826..6e2dedc 100644 --- a/mob.ini +++ b/mob.ini @@ -17,6 +17,7 @@ vcvars = [prebuilt] boost = true +lz4 = true [versions] vs = 16 diff --git a/src/conf.cpp b/src/conf.cpp index d233469..723da4f 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -44,7 +44,8 @@ static path_map g_tools = static bool_map g_prebuilt = { - {"boost", false} + {"boost", false}, + {"lz4", false} }; static string_map g_versions = @@ -188,7 +189,7 @@ namespace tools fs::path vs::installation_path() { return paths::by_name("vs"); } fs::path vs::vswhere() { return tool_by_name("vswhere"); } - fs::path vs::vcvars() { return tool_by_name("vsvars"); } + fs::path vs::vcvars() { return tool_by_name("vcvars"); } std::string vs::version() { return versions::by_name("vs"); } std::string vs::year() { return versions::by_name("vs_year"); } std::string vs::toolset() { return versions::by_name("vs_toolset"); } diff --git a/src/tasks/boost.cpp b/src/tasks/boost.cpp index b3d731d..0d9c4a0 100644 --- a/src/tasks/boost.cpp +++ b/src/tasks/boost.cpp @@ -211,10 +211,7 @@ fs::path boost::config_jam_file() url boost::prebuilt_url() { const auto underscores = replace_all(version(), ".", "_"); - - return - "https://github.com/ModOrganizer2/modorganizer-umbrella/" - "releases/download/1.1/boost_prebuilt_" + underscores + ".7z"; + return make_prebuilt_url("boost_prebuilt_" + underscores + ".7z"); } url boost::source_url() diff --git a/src/tasks/lz4.cpp b/src/tasks/lz4.cpp index 0f12012..65c2227 100644 --- a/src/tasks/lz4.cpp +++ b/src/tasks/lz4.cpp @@ -16,7 +16,7 @@ const std::string& lz4::version() bool lz4::prebuilt() { - return false; + return prebuilt::by_name("lz4"); } fs::path lz4::source_path() @@ -30,6 +30,44 @@ void lz4::do_clean_for_rebuild() } void lz4::do_fetch() +{ + if (prebuilt()) + fetch_prebuilt(); + else + fetch_from_source(); +} + +void lz4::do_build_and_install() +{ + if (prebuilt()) + build_and_install_prebuilt(); + else + build_and_install_from_source(); +} + +void lz4::fetch_prebuilt() +{ + cx().trace(context::generic, "using prebuilt lz4"); + + const auto file = run_tool(downloader(prebuilt_url())); + + run_tool(extractor() + .file(file) + .output(source_path())); +} + +void lz4::build_and_install_prebuilt() +{ + op::copy_file_to_dir_if_better(cx(), + source_path() / "bin" / "liblz4.pdb", + paths::install_pdbs()); + + op::copy_file_to_dir_if_better(cx(), + source_path() / "bin" / "liblz4.dll", + paths::install_dlls()); +} + +void lz4::fetch_from_source() { run_tool(git_clone() .url(make_github_url("lz4","lz4")) @@ -39,7 +77,7 @@ void lz4::do_fetch() run_tool(devenv_upgrade(solution_file())); } -void lz4::do_build_and_install() +void lz4::build_and_install_from_source() { run_tool(msbuild() .solution(solution_file()) @@ -74,4 +112,9 @@ fs::path lz4::out_dir() return solution_dir() / "bin" / "x64_Release"; } +url lz4::prebuilt_url() +{ + return make_prebuilt_url("lz4_prebuilt_" + version() + ".7z"); +} + } // namespace diff --git a/src/tasks/tasks.h b/src/tasks/tasks.h index 6304bf6..9125c84 100644 --- a/src/tasks/tasks.h +++ b/src/tasks/tasks.h @@ -241,6 +241,14 @@ private: static fs::path solution_dir(); static fs::path solution_file(); static fs::path out_dir(); + + void fetch_prebuilt(); + void build_and_install_prebuilt(); + + void fetch_from_source(); + void build_and_install_from_source(); + + static url prebuilt_url(); }; diff --git a/src/tools/git.cpp b/src/tools/git.cpp index 6ab12e4..67104e7 100644 --- a/src/tools/git.cpp +++ b/src/tools/git.cpp @@ -5,11 +5,6 @@ namespace mob { -url make_github_url(const std::string& org, const std::string& repo) -{ - return "https://github.com/" + org + "/" + repo + ".git"; -} - git_clone::git_clone() : basic_process_runner("git") diff --git a/src/tools/tools.h b/src/tools/tools.h index 7be2165..120746d 100644 --- a/src/tools/tools.h +++ b/src/tools/tools.h @@ -111,9 +111,6 @@ private: }; -url make_github_url(const std::string& org, const std::string& repo); - - class git_clone : public basic_process_runner { public: diff --git a/src/utility.cpp b/src/utility.cpp index a446525..98cb277 100644 --- a/src/utility.cpp +++ b/src/utility.cpp @@ -9,6 +9,19 @@ namespace mob { +url make_github_url(const std::string& org, const std::string& repo) +{ + return "https://github.com/" + org + "/" + repo + ".git"; +} + +url make_prebuilt_url(const std::string& filename) +{ + return + "https://github.com/ModOrganizer2/modorganizer-umbrella/" + "releases/download/1.1/" + filename; +} + + std::string replace_all( std::string s, const std::string& from, const std::string& to) { diff --git a/src/utility.h b/src/utility.h index 91eb859..3f45d47 100644 --- a/src/utility.h +++ b/src/utility.h @@ -9,6 +9,7 @@ namespace mob class context; +class url; class bailed { @@ -162,6 +163,9 @@ private: }; +url make_github_url(const std::string& org, const std::string& repo); +url make_prebuilt_url(const std::string& filename); + std::string replace_all( std::string s, const std::string& from, const std::string& to);