diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2017-03-31 17:40:08 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-03-31 17:40:08 -0700 |
| commit | 4792821a1d5d5fec764241f3d97284ec1579ce3a (patch) | |
| tree | 6c1652b91be5e65754cb297bc99229f1ada3cee8 | |
| parent | c84765601bbe49a6ec2e252ec681fe843212230f (diff) | |
| download | vcpkg-4792821a1d5d5fec764241f3d97284ec1579ce3a.tar.gz vcpkg-4792821a1d5d5fec764241f3d97284ec1579ce3a.zip | |
Move Environment:: functions into vcpkg_paths. Remove Environment.h/cpp
| -rw-r--r-- | toolsrc/include/vcpkg_Environment.h | 15 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_paths.h | 8 | ||||
| -rw-r--r-- | toolsrc/src/PostBuildLint.cpp | 3 | ||||
| -rw-r--r-- | toolsrc/src/commands_build.cpp | 3 | ||||
| -rw-r--r-- | toolsrc/src/commands_build_external.cpp | 1 | ||||
| -rw-r--r-- | toolsrc/src/commands_create.cpp | 1 | ||||
| -rw-r--r-- | toolsrc/src/commands_integrate.cpp | 1 | ||||
| -rw-r--r-- | toolsrc/src/commands_portsdiff.cpp | 1 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_Environment.cpp | 140 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_paths.cpp | 131 | ||||
| -rw-r--r-- | toolsrc/vcpkglib/vcpkglib.vcxproj | 2 | ||||
| -rw-r--r-- | toolsrc/vcpkglib/vcpkglib.vcxproj.filters | 6 |
12 files changed, 140 insertions, 172 deletions
diff --git a/toolsrc/include/vcpkg_Environment.h b/toolsrc/include/vcpkg_Environment.h deleted file mode 100644 index 32ab28391..000000000 --- a/toolsrc/include/vcpkg_Environment.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include "vcpkg_paths.h" - -namespace vcpkg::Environment -{ - const fs::path& get_dumpbin_exe(const vcpkg_paths& paths); - - struct vcvarsall_and_platform_toolset - { - fs::path path; - std::wstring platform_toolset; - }; - - const vcvarsall_and_platform_toolset& get_vcvarsall_bat(const vcpkg_paths& paths); -} diff --git a/toolsrc/include/vcpkg_paths.h b/toolsrc/include/vcpkg_paths.h index ae91a8e2f..9577abd01 100644 --- a/toolsrc/include/vcpkg_paths.h +++ b/toolsrc/include/vcpkg_paths.h @@ -7,6 +7,12 @@ namespace vcpkg { + struct vcvarsall_and_platform_toolset + { + fs::path path; + std::wstring platform_toolset; + }; + struct vcpkg_paths { static expected<vcpkg_paths> create(const fs::path& vcpkg_root_dir); @@ -40,6 +46,8 @@ namespace vcpkg const fs::path& get_cmake_exe() const; const fs::path& get_git_exe() const; const fs::path& get_nuget_exe() const; + const fs::path& get_dumpbin_exe() const; + const vcvarsall_and_platform_toolset& get_vcvarsall_bat() const; private: lazy<fs::path> cmake_exe; diff --git a/toolsrc/src/PostBuildLint.cpp b/toolsrc/src/PostBuildLint.cpp index 65e0683f2..81f712368 100644 --- a/toolsrc/src/PostBuildLint.cpp +++ b/toolsrc/src/PostBuildLint.cpp @@ -3,7 +3,6 @@ #include "package_spec.h" #include "vcpkg_Files.h" #include "vcpkg_System.h" -#include "vcpkg_Environment.h" #include "coff_file_reader.h" #include "PostBuildLint_BuildInfo.h" #include "PostBuildLint_BuildType.h" @@ -622,7 +621,7 @@ namespace vcpkg::PostBuildLint static size_t perform_all_checks_and_return_error_count(const package_spec& spec, const vcpkg_paths& paths) { - const fs::path dumpbin_exe = Environment::get_dumpbin_exe(paths); + const fs::path dumpbin_exe = paths.get_dumpbin_exe(); BuildInfo build_info = read_build_info(paths.build_info_file_path(spec)); const fs::path package_dir = paths.package_dir(spec); diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp index 390a117dd..301612831 100644 --- a/toolsrc/src/commands_build.cpp +++ b/toolsrc/src/commands_build.cpp @@ -7,7 +7,6 @@ #include "vcpkg_Dependencies.h" #include "vcpkg_System.h" #include "vcpkg_Chrono.h" -#include "vcpkg_Environment.h" #include "metrics.h" #include "vcpkg_Enums.h" #include "Paragraphs.h" @@ -43,7 +42,7 @@ namespace vcpkg::Commands::Build const fs::path& git_exe_path = paths.get_git_exe(); const fs::path ports_cmake_script_path = paths.ports_cmake; - const Environment::vcvarsall_and_platform_toolset vcvarsall_bat = Environment::get_vcvarsall_bat(paths); + const vcvarsall_and_platform_toolset vcvarsall_bat = paths.get_vcvarsall_bat(); const std::wstring cmd_set_environment = Strings::wformat(LR"("%s" %s >nul 2>&1)", vcvarsall_bat.path.native(), Strings::utf8_to_utf16(target_triplet.architecture())); const std::wstring cmd_launch_cmake = make_cmake_cmd(cmake_exe_path, ports_cmake_script_path, diff --git a/toolsrc/src/commands_build_external.cpp b/toolsrc/src/commands_build_external.cpp index 06bd1374c..f1483436a 100644 --- a/toolsrc/src/commands_build_external.cpp +++ b/toolsrc/src/commands_build_external.cpp @@ -1,7 +1,6 @@ #include "pch.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" -#include "vcpkg_Environment.h" #include "vcpkg_Input.h" namespace vcpkg::Commands::BuildExternal diff --git a/toolsrc/src/commands_create.cpp b/toolsrc/src/commands_create.cpp index 23fac3f9d..a5d3a66bc 100644 --- a/toolsrc/src/commands_create.cpp +++ b/toolsrc/src/commands_create.cpp @@ -1,7 +1,6 @@ #include "pch.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" -#include "vcpkg_Environment.h" #include "vcpkg_Files.h" #include "vcpkg_Input.h" #include "vcpkglib.h" diff --git a/toolsrc/src/commands_integrate.cpp b/toolsrc/src/commands_integrate.cpp index 497038d70..cb7eeb7da 100644 --- a/toolsrc/src/commands_integrate.cpp +++ b/toolsrc/src/commands_integrate.cpp @@ -1,6 +1,5 @@ #include "pch.h" #include "vcpkg_Commands.h" -#include "vcpkg_Environment.h" #include "vcpkg_Checks.h" #include "vcpkg_System.h" #include "vcpkg_Files.h" diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index d41ebb9fb..26b7be8ac 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -3,7 +3,6 @@ #include "vcpkg_System.h" #include "vcpkg_Maps.h" #include "SourceParagraph.h" -#include "vcpkg_Environment.h" #include "Paragraphs.h" namespace vcpkg::Commands::PortsDiff diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp deleted file mode 100644 index 96482b94b..000000000 --- a/toolsrc/src/vcpkg_Environment.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include "pch.h" -#include "vcpkg_Environment.h" -#include "vcpkg_Commands.h" -#include "vcpkg_System.h" -#include "vcpkg_Strings.h" -#include "vcpkg_Files.h" - -namespace vcpkg::Environment -{ - static std::vector<std::string> get_VS2017_installation_instances(const vcpkg_paths& paths) - { - const fs::path script = paths.scripts / "findVisualStudioInstallationInstances.ps1"; - const std::wstring cmd = System::create_powershell_script_cmd(script); - System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd); - Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, "Could not run script to detect VS 2017 instances"); - return Strings::split(ec_data.output, "\n"); - } - - static optional<fs::path> find_vs2015_installation_instance() - { - const optional<std::wstring> vs2015_cmntools_optional = System::get_environmental_variable(L"VS140COMNTOOLS"); - if (auto v = vs2015_cmntools_optional.get()) - { - static const fs::path vs2015_cmntools = fs::path(*v).parent_path(); // The call to parent_path() is needed because the env variable has a trailing backslash - static const fs::path vs2015_path = vs2015_cmntools.parent_path().parent_path(); - return vs2015_path; - } - - return nullopt; - } - - static const optional<fs::path>& get_VS2015_installation_instance() - { - static const optional<fs::path> vs2015_path = find_vs2015_installation_instance(); - return vs2015_path; - } - - static fs::path find_dumpbin_exe(const vcpkg_paths& paths) - { - const std::vector<std::string> vs2017_installation_instances = get_VS2017_installation_instances(paths); - std::vector<fs::path> paths_examined; - - // VS2017 - for (const std::string& instance : vs2017_installation_instances) - { - const fs::path msvc_path = Strings::format(R"(%s\VC\Tools\MSVC)", instance); - std::vector<fs::path> msvc_subdirectories; - Files::non_recursive_find_matching_paths_in_dir(msvc_path, [&](const fs::path& current) - { - return fs::is_directory(current); - }, &msvc_subdirectories); - - // Sort them so that latest comes first - std::sort(msvc_subdirectories.begin(), msvc_subdirectories.end(), [&](const fs::path& left, const fs::path& right) - { - return left.filename() > right.filename(); - }); - - for (const fs::path& subdir : msvc_subdirectories) - { - const fs::path dumpbin_path = subdir / "bin" / "HostX86" / "x86" / "dumpbin.exe"; - paths_examined.push_back(dumpbin_path); - if (fs::exists(dumpbin_path)) - { - return dumpbin_path; - } - } - } - - // VS2015 - const optional<fs::path>& vs_2015_installation_instance = get_VS2015_installation_instance(); - if (auto v = vs_2015_installation_instance.get()) - { - const fs::path vs2015_dumpbin_exe = *v / "VC" / "bin" / "dumpbin.exe"; - paths_examined.push_back(vs2015_dumpbin_exe); - if (fs::exists(vs2015_dumpbin_exe)) - { - return vs2015_dumpbin_exe; - } - } - - System::println(System::color::error, "Could not detect dumpbin.exe."); - System::println("The following paths were examined:"); - for (const fs::path& path : paths_examined) - { - System::println(" %s", path.generic_string()); - } - Checks::exit_fail(VCPKG_LINE_INFO); - } - - const fs::path& get_dumpbin_exe(const vcpkg_paths& paths) - { - static const fs::path dumpbin_exe = find_dumpbin_exe(paths); - return dumpbin_exe; - } - - static vcvarsall_and_platform_toolset find_vcvarsall_bat(const vcpkg_paths& paths) - { - const std::vector<std::string> vs2017_installation_instances = get_VS2017_installation_instances(paths); - std::vector<fs::path> paths_examined; - - // VS2017 - for (const fs::path& instance : vs2017_installation_instances) - { - const fs::path vcvarsall_bat = instance / "VC" / "Auxiliary" / "Build" / "vcvarsall.bat"; - paths_examined.push_back(vcvarsall_bat); - if (fs::exists(vcvarsall_bat)) - { - return { vcvarsall_bat , L"v141" }; - } - } - - // VS2015 - const optional<fs::path>& vs_2015_installation_instance = get_VS2015_installation_instance(); - if (auto v = vs_2015_installation_instance.get()) - { - const fs::path vs2015_vcvarsall_bat = *v / "VC" / "vcvarsall.bat"; - - paths_examined.push_back(vs2015_vcvarsall_bat); - if (fs::exists(vs2015_vcvarsall_bat)) - { - return { vs2015_vcvarsall_bat, L"v140" }; - } - } - - System::println(System::color::error, "Could not detect vcvarsall.bat."); - System::println("The following paths were examined:"); - for (const fs::path& path : paths_examined) - { - System::println(" %s", path.generic_string()); - } - Checks::exit_fail(VCPKG_LINE_INFO); - } - - const vcvarsall_and_platform_toolset& get_vcvarsall_bat(const vcpkg_paths& paths) - { - static const vcvarsall_and_platform_toolset vcvarsall_bat = find_vcvarsall_bat(paths); - return vcvarsall_bat; - } -} diff --git a/toolsrc/src/vcpkg_paths.cpp b/toolsrc/src/vcpkg_paths.cpp index 2cbd6602e..03b739b29 100644 --- a/toolsrc/src/vcpkg_paths.cpp +++ b/toolsrc/src/vcpkg_paths.cpp @@ -4,7 +4,7 @@ #include "metrics.h" #include "vcpkg_System.h" #include "package_spec.h" -#include "vcpkg_Environment.h" +#include "vcpkg_Files.h" namespace vcpkg { @@ -242,4 +242,133 @@ namespace vcpkg { return this->nuget_exe.get_lazy([this]() { return get_nuget_path(this->downloads, this->scripts); }); } + + static std::vector<std::string> get_VS2017_installation_instances(const vcpkg_paths& paths) + { + const fs::path script = paths.scripts / "findVisualStudioInstallationInstances.ps1"; + const std::wstring cmd = System::create_powershell_script_cmd(script); + System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd); + Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, "Could not run script to detect VS 2017 instances"); + return Strings::split(ec_data.output, "\n"); + } + + static const optional<fs::path>& get_VS2015_installation_instance() + { + static const optional<fs::path> vs2015_path = []() -> optional<fs::path> + { + const optional<std::wstring> vs2015_cmntools_optional = System::get_environmental_variable(L"VS140COMNTOOLS"); + if (auto v = vs2015_cmntools_optional.get()) + { + static const fs::path vs2015_cmntools = fs::path(*v).parent_path(); // The call to parent_path() is needed because the env variable has a trailing backslash + static const fs::path vs2015_path = vs2015_cmntools.parent_path().parent_path(); + return vs2015_path; + } + + return nullopt; + }(); + return vs2015_path; + } + + static fs::path find_dumpbin_exe(const vcpkg_paths& paths) + { + const std::vector<std::string> vs2017_installation_instances = get_VS2017_installation_instances(paths); + std::vector<fs::path> paths_examined; + + // VS2017 + for (const std::string& instance : vs2017_installation_instances) + { + const fs::path msvc_path = Strings::format(R"(%s\VC\Tools\MSVC)", instance); + std::vector<fs::path> msvc_subdirectories; + Files::non_recursive_find_matching_paths_in_dir(msvc_path, [&](const fs::path& current) + { + return fs::is_directory(current); + }, &msvc_subdirectories); + + // Sort them so that latest comes first + std::sort(msvc_subdirectories.begin(), msvc_subdirectories.end(), [&](const fs::path& left, const fs::path& right) + { + return left.filename() > right.filename(); + }); + + for (const fs::path& subdir : msvc_subdirectories) + { + const fs::path dumpbin_path = subdir / "bin" / "HostX86" / "x86" / "dumpbin.exe"; + paths_examined.push_back(dumpbin_path); + if (fs::exists(dumpbin_path)) + { + return dumpbin_path; + } + } + } + + // VS2015 + const optional<fs::path>& vs_2015_installation_instance = get_VS2015_installation_instance(); + if (auto v = vs_2015_installation_instance.get()) + { + const fs::path vs2015_dumpbin_exe = *v / "VC" / "bin" / "dumpbin.exe"; + paths_examined.push_back(vs2015_dumpbin_exe); + if (fs::exists(vs2015_dumpbin_exe)) + { + return vs2015_dumpbin_exe; + } + } + + System::println(System::color::error, "Could not detect dumpbin.exe."); + System::println("The following paths were examined:"); + for (const fs::path& path : paths_examined) + { + System::println(" %s", path.generic_string()); + } + Checks::exit_fail(VCPKG_LINE_INFO); + } + + const fs::path& vcpkg_paths::get_dumpbin_exe() const + { + static const fs::path dumpbin_exe = find_dumpbin_exe(*this); + return dumpbin_exe; + } + + static vcvarsall_and_platform_toolset find_vcvarsall_bat(const vcpkg_paths& paths) + { + const std::vector<std::string> vs2017_installation_instances = get_VS2017_installation_instances(paths); + std::vector<fs::path> paths_examined; + + // VS2017 + for (const fs::path& instance : vs2017_installation_instances) + { + const fs::path vcvarsall_bat = instance / "VC" / "Auxiliary" / "Build" / "vcvarsall.bat"; + paths_examined.push_back(vcvarsall_bat); + if (fs::exists(vcvarsall_bat)) + { + return { vcvarsall_bat , L"v141" }; + } + } + + // VS2015 + const optional<fs::path>& vs_2015_installation_instance = get_VS2015_installation_instance(); + if (auto v = vs_2015_installation_instance.get()) + { + const fs::path vs2015_vcvarsall_bat = *v / "VC" / "vcvarsall.bat"; + + paths_examined.push_back(vs2015_vcvarsall_bat); + if (fs::exists(vs2015_vcvarsall_bat)) + { + return { vs2015_vcvarsall_bat, L"v140" }; + } + } + + System::println(System::color::error, "Could not detect vcvarsall.bat."); + System::println("The following paths were examined:"); + for (const fs::path& path : paths_examined) + { + System::println(" %s", path.generic_string()); + } + Checks::exit_fail(VCPKG_LINE_INFO); + } + + const vcvarsall_and_platform_toolset& vcpkg_paths::get_vcvarsall_bat() const + { + static const vcvarsall_and_platform_toolset vcvarsall_bat = find_vcvarsall_bat(*this); + return vcvarsall_bat; + } } diff --git a/toolsrc/vcpkglib/vcpkglib.vcxproj b/toolsrc/vcpkglib/vcpkglib.vcxproj index 96ed23633..c00571cc4 100644 --- a/toolsrc/vcpkglib/vcpkglib.vcxproj +++ b/toolsrc/vcpkglib/vcpkglib.vcxproj @@ -169,7 +169,6 @@ <ClInclude Include="..\include\vcpkg_Commands.h" /> <ClInclude Include="..\include\vcpkg_Dependencies.h" /> <ClInclude Include="..\include\vcpkg_Enums.h" /> - <ClInclude Include="..\include\vcpkg_Environment.h" /> <ClInclude Include="..\include\vcpkg_Files.h" /> <ClInclude Include="..\include\vcpkg_Graphs.h" /> <ClInclude Include="..\include\vcpkg_Input.h" /> @@ -234,7 +233,6 @@ <ClCompile Include="..\src\vcpkg_cmd_arguments.cpp" /> <ClCompile Include="..\src\vcpkg_Dependencies.cpp" /> <ClCompile Include="..\src\vcpkg_Enums.cpp" /> - <ClCompile Include="..\src\vcpkg_Environment.cpp" /> <ClCompile Include="..\src\vcpkg_Files.cpp" /> <ClCompile Include="..\src\vcpkg_Input.cpp" /> <ClCompile Include="..\src\vcpkg_paths.cpp" /> diff --git a/toolsrc/vcpkglib/vcpkglib.vcxproj.filters b/toolsrc/vcpkglib/vcpkglib.vcxproj.filters index 83656ff78..cd9460f67 100644 --- a/toolsrc/vcpkglib/vcpkglib.vcxproj.filters +++ b/toolsrc/vcpkglib/vcpkglib.vcxproj.filters @@ -51,9 +51,6 @@ <ClCompile Include="..\src\vcpkg_Input.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="..\src\vcpkg_Environment.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="..\src\coff_file_reader.cpp"> <Filter>Source Files</Filter> </ClCompile> @@ -233,9 +230,6 @@ <ClInclude Include="..\include\vcpkg_Dependencies.h"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="..\include\vcpkg_Environment.h"> - <Filter>Header Files</Filter> - </ClInclude> <ClInclude Include="..\include\vcpkglib.h"> <Filter>Header Files</Filter> </ClInclude> |
