diff options
| author | nicole mazzuca <mazzucan@outlook.com> | 2021-01-14 09:06:31 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-14 09:06:31 -0800 |
| commit | 1515d080fe98ae5dad49e833b8fc799feebabe03 (patch) | |
| tree | 1c94f6f084a3d31c0250586aa287352d9caf2089 /toolsrc/include | |
| parent | fb21b708461641927290976adb2b7eee21b5748e (diff) | |
| download | vcpkg-1515d080fe98ae5dad49e833b8fc799feebabe03.tar.gz vcpkg-1515d080fe98ae5dad49e833b8fc799feebabe03.zip | |
[vcpkg] Rewriting CmdLineBuilder (2/n) (#15627)
* [vcpkg] Rewriting CmdLineBuilder (2/n)
I would like, and I think the team would like generally,
to switch to using stuff like `posix_spawn`, as opposed to the
existing use of `system` and `popen`.
This requires a pretty large change to how we use CmdLineBuilder.
The first change we have to make is that the execute functions
_cannot_ take a StringView anymore.
This PR makes that change.
Diffstat (limited to 'toolsrc/include')
| -rw-r--r-- | toolsrc/include/vcpkg/base/cache.h | 4 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/base/system.process.h | 42 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/build.h | 4 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/buildenvironment.h | 6 |
4 files changed, 32 insertions, 24 deletions
diff --git a/toolsrc/include/vcpkg/base/cache.h b/toolsrc/include/vcpkg/base/cache.h index 1996f2587..7efae1361 100644 --- a/toolsrc/include/vcpkg/base/cache.h +++ b/toolsrc/include/vcpkg/base/cache.h @@ -4,7 +4,7 @@ namespace vcpkg { - template<class Key, class Value> + template<class Key, class Value, class Less = std::less<Key>> struct Cache { template<class F> @@ -16,6 +16,6 @@ namespace vcpkg } private: - mutable std::map<Key, Value> m_cache; + mutable std::map<Key, Value, Less> m_cache; }; } diff --git a/toolsrc/include/vcpkg/base/system.process.h b/toolsrc/include/vcpkg/base/system.process.h index 1c62fa285..68d4da4e4 100644 --- a/toolsrc/include/vcpkg/base/system.process.h +++ b/toolsrc/include/vcpkg/base/system.process.h @@ -20,10 +20,6 @@ namespace vcpkg::System std::string s; }; - std::string make_basic_cmake_cmd(const fs::path& cmake_tool_path, - const fs::path& cmake_script, - const std::vector<CMakeVariable>& pass_variables); - struct CmdLineBuilder { CmdLineBuilder() = default; @@ -46,15 +42,27 @@ namespace vcpkg::System CmdLineBuilder&& raw_arg(StringView s) && { return std::move(raw_arg(s)); } std::string&& extract() && { return std::move(buf); } - operator StringView() noexcept { return buf; } StringView command_line() const { return buf; } void clear() { buf.clear(); } + bool empty() const { return buf.empty(); } private: std::string buf; }; + struct CmdLineBuilderMapLess + { + bool operator()(const CmdLineBuilder& lhs, const CmdLineBuilder& rhs) const + { + return lhs.command_line() < rhs.command_line(); + } + }; + + CmdLineBuilder make_basic_cmake_cmd(const fs::path& cmake_tool_path, + const fs::path& cmake_script, + const std::vector<CMakeVariable>& pass_variables); + fs::path get_exe_path_of_current_process(); struct ExitCodeAndOutput @@ -79,48 +87,48 @@ namespace vcpkg::System const fs::path& working_directory; }; - int cmd_execute(StringView cmd_line, InWorkingDirectory wd, const Environment& env = {}); - inline int cmd_execute(StringView cmd_line, const Environment& env = {}) + int cmd_execute(const CmdLineBuilder& cmd_line, InWorkingDirectory wd, const Environment& env = {}); + inline int cmd_execute(const CmdLineBuilder& cmd_line, const Environment& env = {}) { return cmd_execute(cmd_line, InWorkingDirectory{fs::path()}, env); } - int cmd_execute_clean(StringView cmd_line, InWorkingDirectory wd); - inline int cmd_execute_clean(StringView cmd_line) + int cmd_execute_clean(const CmdLineBuilder& cmd_line, InWorkingDirectory wd); + inline int cmd_execute_clean(const CmdLineBuilder& cmd_line) { return cmd_execute_clean(cmd_line, InWorkingDirectory{fs::path()}); } #if defined(_WIN32) - Environment cmd_execute_modify_env(StringView cmd_line, const Environment& env = {}); + Environment cmd_execute_modify_env(const CmdLineBuilder& cmd_line, const Environment& env = {}); - void cmd_execute_background(const StringView cmd_line); + void cmd_execute_background(const CmdLineBuilder& cmd_line); #endif - ExitCodeAndOutput cmd_execute_and_capture_output(StringView cmd_line, + ExitCodeAndOutput cmd_execute_and_capture_output(const CmdLineBuilder& cmd_line, InWorkingDirectory wd, const Environment& env = {}); - inline ExitCodeAndOutput cmd_execute_and_capture_output(StringView cmd_line, const Environment& env = {}) + inline ExitCodeAndOutput cmd_execute_and_capture_output(const CmdLineBuilder& cmd_line, const Environment& env = {}) { return cmd_execute_and_capture_output(cmd_line, InWorkingDirectory{fs::path()}, env); } - int cmd_execute_and_stream_lines(StringView cmd_line, + int cmd_execute_and_stream_lines(const CmdLineBuilder& cmd_line, InWorkingDirectory wd, std::function<void(StringView)> per_line_cb, const Environment& env = {}); - inline int cmd_execute_and_stream_lines(StringView cmd_line, + inline int cmd_execute_and_stream_lines(const CmdLineBuilder& cmd_line, std::function<void(StringView)> per_line_cb, const Environment& env = {}) { return cmd_execute_and_stream_lines(cmd_line, InWorkingDirectory{fs::path()}, std::move(per_line_cb), env); } - int cmd_execute_and_stream_data(StringView cmd_line, + int cmd_execute_and_stream_data(const CmdLineBuilder& cmd_line, InWorkingDirectory wd, std::function<void(StringView)> data_cb, const Environment& env = {}); - inline int cmd_execute_and_stream_data(StringView cmd_line, + inline int cmd_execute_and_stream_data(const CmdLineBuilder& cmd_line, std::function<void(StringView)> data_cb, const Environment& env = {}) { diff --git a/toolsrc/include/vcpkg/build.h b/toolsrc/include/vcpkg/build.h index bd5188b9f..0659eedcd 100644 --- a/toolsrc/include/vcpkg/build.h +++ b/toolsrc/include/vcpkg/build.h @@ -232,7 +232,7 @@ namespace vcpkg::Build const VcpkgPaths& m_paths; }; - std::string make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset); + System::CmdLineBuilder make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset); struct ExtendedBuildResult { @@ -369,7 +369,7 @@ namespace vcpkg::Build struct EnvMapEntry { std::unordered_map<std::string, std::string> env_map; - Cache<std::string, System::Environment> cmd_cache; + Cache<System::CmdLineBuilder, System::Environment, System::CmdLineBuilderMapLess> cmd_cache; }; Cache<std::vector<std::string>, EnvMapEntry> envs; diff --git a/toolsrc/include/vcpkg/buildenvironment.h b/toolsrc/include/vcpkg/buildenvironment.h index aa69708b6..549772320 100644 --- a/toolsrc/include/vcpkg/buildenvironment.h +++ b/toolsrc/include/vcpkg/buildenvironment.h @@ -9,7 +9,7 @@ namespace vcpkg { - std::string make_cmake_cmd(const VcpkgPaths& paths, - const fs::path& cmake_script, - std::vector<System::CMakeVariable>&& pass_variables); + System::CmdLineBuilder make_cmake_cmd(const VcpkgPaths& paths, + const fs::path& cmake_script, + std::vector<System::CMakeVariable>&& pass_variables); } |
