From 0dc8d2c7ae0c95cdf23fbc0260cba5751ecdce8e Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Tue, 26 May 2020 13:36:36 -0400 Subject: [PATCH] prepend python to path when building usvfs, udis requires it install certifi, prebuilt python fails with ssl errors when downloading --- src/env.cpp | 73 +++++++++++++++++++++++++++++++++++++------ src/env.h | 4 +++ src/tasks/python.cpp | 7 +++++ src/tasks/usvfs.cpp | 4 ++- src/tools/msbuild.cpp | 13 +++++++- src/tools/tools.h | 2 ++ src/utility.cpp | 15 --------- src/utility.h | 21 +++++++++++-- 8 files changed, 110 insertions(+), 29 deletions(-) diff --git a/src/env.cpp b/src/env.cpp index c97e704..1159682 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -4,6 +4,7 @@ #include "process.h" #include "op.h" #include "context.h" +#include "utility.h" #include "tools/tools.h" namespace mob @@ -135,27 +136,79 @@ env& env::operator=(env&& e) env& env::append_path(const fs::path& p) { - return append_path(std::vector{p}); + append_path(std::vector{p}); + return *this; +} + +env& env::prepend_path(const fs::path& p) +{ + prepend_path(std::vector{p}); + return *this; +} + +env& env::prepend_path(const std::vector& v) +{ + change_path(v, prepend); + return *this; } env& env::append_path(const std::vector& v) +{ + change_path(v, append); + return *this; +} + +env& env::change_path(const std::vector& v, flags f) { copy_for_write(); std::wstring path; + switch (f) { - auto current = find(L"PATH"); - if (current) - path = *current; - } + case replace: + { + const auto strings = + mob::map(v, [&](auto&& p){ return p.native(); }); - for (auto&& p : v) - { - if (!path.empty()) - path += L";"; + path = join(strings, L";"); - path += p.native(); + break; + } + + case append: + { + auto current = find(L"PATH"); + if (current) + path = *current; + + for (auto&& p : v) + { + if (!path.empty()) + path += L";"; + + path += p.native(); + } + + break; + } + + case prepend: + { + auto current = find(L"PATH"); + if (current) + path = *current; + + for (auto&& p : v) + { + if (!path.empty()) + path = L";" + path; + + path = p.native() + path; + } + + break; + } } set(L"PATH", path, replace); diff --git a/src/env.h b/src/env.h index 1742153..245c4d2 100644 --- a/src/env.h +++ b/src/env.h @@ -25,8 +25,11 @@ public: env& operator=(const env& e); env& operator=(env&& e); + env& prepend_path(const fs::path& p); + env& prepend_path(const std::vector& v); env& append_path(const fs::path& p); env& append_path(const std::vector& v); + env& set(std::string_view k, std::string_view v, flags f=replace); env& set(std::wstring k, std::wstring v, flags f=replace); @@ -54,6 +57,7 @@ private: const std::wstring* find(std::wstring_view name) const; void set_impl(std::wstring k, std::wstring v, flags f); void copy_for_write(); + env& change_path(const std::vector& v, flags f); }; diff --git a/src/tasks/python.cpp b/src/tasks/python.cpp index 96cc608..afa956b 100644 --- a/src/tasks/python.cpp +++ b/src/tasks/python.cpp @@ -244,6 +244,13 @@ void python::install_pip() .arg("-m pip") .arg("install") .arg("--upgrade pip"))); + + // ssl errors while downloading through python without certifi + run_tool(process_runner(process() + .binary(python_exe()) + .arg("pip") + .arg("install") + .arg("certifi"))); } msbuild python::create_msbuild_tool(msbuild::ops o) diff --git a/src/tasks/usvfs.cpp b/src/tasks/usvfs.cpp index ddfb15e..3c6f184 100644 --- a/src/tasks/usvfs.cpp +++ b/src/tasks/usvfs.cpp @@ -172,10 +172,12 @@ msbuild usvfs::create_msbuild_tool(arch a, msbuild::ops o) const const std::string plat = (a == arch::x64 ? "x64" : "x86"); + // udis requires python in its custom build step return std::move(msbuild(o) .platform(plat) .targets({"usvfs_proxy"}) - .solution(source_path() / "vsbuild" / "usvfs.sln")); + .solution(source_path() / "vsbuild" / "usvfs.sln") + .prepend_path(python::build_path())); } std::vector> diff --git a/src/tools/msbuild.cpp b/src/tools/msbuild.cpp index 873c956..07ba617 100644 --- a/src/tools/msbuild.cpp +++ b/src/tools/msbuild.cpp @@ -58,6 +58,12 @@ msbuild& msbuild::flags(flags_t f) return *this; } +msbuild& msbuild::prepend_path(const fs::path& p) +{ + prepend_path_.push_back(p); + return *this; +} + int msbuild::result() const { return exit_code(); @@ -161,11 +167,16 @@ void msbuild::do_run(const std::vector& targets) for (auto&& p : params_) process_.arg("-property:" + p); + env e = env::vs(arch_); + + for (auto&& p : prepend_path_) + e.prepend_path(p); + process_ .arg(sln_) .flags(pflags) .cwd(sln_.parent_path()) - .env(env::vs(arch_)); + .env(e); execute_and_join(); } diff --git a/src/tools/tools.h b/src/tools/tools.h index 57ac45e..d87992d 100644 --- a/src/tools/tools.h +++ b/src/tools/tools.h @@ -464,6 +464,7 @@ public: msbuild& platform(const std::string& s); msbuild& architecture(arch a); msbuild& flags(flags_t f); + msbuild& prepend_path(const fs::path& p); int result() const; @@ -479,6 +480,7 @@ private: std::string platform_; arch arch_; flags_t flags_; + std::vector prepend_path_; void do_clean(); void do_build(); diff --git a/src/utility.cpp b/src/utility.cpp index 71150eb..3eff4cd 100644 --- a/src/utility.cpp +++ b/src/utility.cpp @@ -352,21 +352,6 @@ std::string replace_all( return s; } -std::string join(const std::vector& v, const std::string& sep) -{ - std::string s; - - for (auto&& e : v) - { - if (!s.empty()) - s += sep; - - s += e; - } - - return s; -} - std::vector split(const std::string& s, const std::string& seps) { std::vector v; diff --git a/src/utility.h b/src/utility.h index 880fecc..144fc07 100644 --- a/src/utility.h +++ b/src/utility.h @@ -315,7 +315,24 @@ bool glob_match(const std::string& pattern, const std::string& s); std::string replace_all( std::string s, const std::string& from, const std::string& to); -std::string join(const std::vector& v, const std::string& sep); +template +T join(const std::vector& v, const Sep& sep) +{ + T s; + bool first = true; + + for (auto&& e : v) + { + if (first) + s += sep; + + s += e; + first = false; + } + + return s; +} + std::vector split(const std::string& s, const std::string& sep); std::string pad_right(std::string s, std::size_t n, char c=' '); @@ -528,7 +545,7 @@ template < class Container=std::vector>> - Container zip(const Range1& range1, const Range2& range2) +Container zip(const Range1& range1, const Range2& range2) { Container out;