Skip to content

Commit 7454705

Browse files
BillyONealvicroms
authored andcommitted
Fix ZipBinaryProvider unpack reporting + parallelize more (microsoft#1805)
* Fixes the incorrect tracking bug introduced here: https://github.com/microsoft/vcpkg-tool/pull/1715/files#r2414987620 * Gets clean_prepare_dir and the last_write_time fixup into the parallelized region Related to microsoft/vcpkg#43309 * Plumbs error handling through to one place * Deletes decompress_in_parallel / cmd_execute_and_capture_output_parallel
1 parent 0775198 commit 7454705

File tree

11 files changed

+140
-140
lines changed

11 files changed

+140
-140
lines changed

include/vcpkg/archives.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,4 @@ namespace vcpkg
6666
Optional<Path> seven_zip;
6767
#endif
6868
};
69-
70-
std::vector<ExpectedL<Unit>> decompress_in_parallel(View<Command> jobs);
7169
}

include/vcpkg/base/files.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ namespace vcpkg
155155

156156
virtual std::vector<Path> get_files_recursive(const Path& dir, std::error_code& ec) const = 0;
157157
std::vector<Path> get_files_recursive(const Path& dir, LineInfo li) const;
158-
ExpectedL<std::vector<Path>> try_get_files_recursive(const Path& dir) const;
158+
Optional<std::vector<Path>> try_get_files_recursive(DiagnosticContext& context, const Path& dir) const;
159159

160160
virtual std::vector<Path> get_files_recursive_lexically_proximate(const Path& dir,
161161
std::error_code& ec) const = 0;
@@ -327,8 +327,7 @@ namespace vcpkg
327327
virtual int64_t last_write_time(const Path& target, std::error_code& ec) const = 0;
328328
int64_t last_write_time(const Path& target, LineInfo li) const noexcept;
329329

330-
virtual void last_write_time(const Path& target, int64_t new_time, std::error_code& ec) const = 0;
331-
void last_write_time(const Path& target, int64_t new_time, LineInfo li) const noexcept;
330+
virtual bool last_write_time(DiagnosticContext& context, const Path& target, int64_t new_time) const = 0;
332331

333332
using ReadOnlyFilesystem::current_path;
334333
virtual void current_path(const Path& new_current_path, std::error_code&) const = 0;

include/vcpkg/base/message-data.inc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,7 @@ DECLARE_MESSAGE(ExportedZipArchive, (msg::path), "", "Zip archive exported at: {
12701270
DECLARE_MESSAGE(ExportingAlreadyBuiltPackages, (), "", "The following packages are already built and will be exported:")
12711271
DECLARE_MESSAGE(ExportingPackage, (msg::package_name), "", "Exporting {package_name}...")
12721272
DECLARE_MESSAGE(ExtendedDocumentationAtUrl, (msg::url), "", "Extended documentation available at '{url}'.")
1273+
DECLARE_MESSAGE(ExtractedInto, (msg::path), "", "extracted into {path}")
12731274
DECLARE_MESSAGE(ExtractHelp, (), "", "Extracts an archive.")
12741275
DECLARE_MESSAGE(ExtractingTool, (msg::tool_name), "", "Extracting {tool_name}...")
12751276
DECLARE_MESSAGE(FailedPostBuildChecks,
@@ -2851,7 +2852,6 @@ DECLARE_MESSAGE(TwoFeatureFlagsSpecified,
28512852
(msg::value),
28522853
"'{value}' is a feature flag.",
28532854
"Both '{value}' and -'{value}' were specified as feature flags.")
2854-
DECLARE_MESSAGE(UnableToClearPath, (msg::path), "", "unable to delete {path}")
28552855
DECLARE_MESSAGE(UnableToReadAppDatas, (), "", "both %LOCALAPPDATA% and %APPDATA% were unreadable")
28562856
DECLARE_MESSAGE(UnableToReadEnvironmentVariable, (msg::env_var), "", "unable to read {env_var}")
28572857
DECLARE_MESSAGE(UndeterminedToolChainForTriplet,
@@ -3350,11 +3350,13 @@ DECLARE_MESSAGE(WaitUntilPackagesUploaded,
33503350
"",
33513351
"Waiting for {count} remaining binary cache submissions...")
33523352
DECLARE_MESSAGE(WarningsTreatedAsErrors, (), "", "previous warnings being interpreted as errors")
3353+
DECLARE_MESSAGE(WhileClearingThis, (), "", "while clearing this directory")
33533354
DECLARE_MESSAGE(WhileCheckingOutBaseline, (msg::commit_sha), "", "while checking out baseline {commit_sha}")
33543355
DECLARE_MESSAGE(WhileCheckingOutPortTreeIsh,
33553356
(msg::package_name, msg::git_tree_sha),
33563357
"",
33573358
"while checking out port {package_name} with git tree {git_tree_sha}")
3359+
DECLARE_MESSAGE(WhileExtractingThisArchive, (), "", "while extracting this archive")
33583360
DECLARE_MESSAGE(WhileGettingLocalTreeIshObjectsForPorts, (), "", "while getting local treeish objects for ports")
33593361
DECLARE_MESSAGE(WhileLookingForSpec, (msg::spec), "", "while looking for {spec}:")
33603362
DECLARE_MESSAGE(WhileLoadingBaselineVersionForPort,

include/vcpkg/base/parallel-algorithms.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,4 @@ namespace vcpkg
161161
{
162162
execute_in_parallel(c.size(), [&](size_t offset) { cb(c[offset]); });
163163
}
164-
165-
template<class Container, class RanItTarget, class F>
166-
void parallel_transform(const Container& c, RanItTarget out_begin, F cb) noexcept
167-
{
168-
execute_in_parallel(c.size(), [&](size_t offset) { out_begin[offset] = cb(c[offset]); });
169-
}
170164
}

include/vcpkg/base/system.process.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,6 @@ namespace vcpkg
166166
settings);
167167
}
168168

169-
std::vector<ExpectedL<ExitCodeAndOutput>> cmd_execute_and_capture_output_parallel(View<Command> commands);
170-
std::vector<ExpectedL<ExitCodeAndOutput>> cmd_execute_and_capture_output_parallel(
171-
View<Command> commands, const RedirectedProcessLaunchSettings& settings);
172-
173169
Optional<ExitCodeIntegral> cmd_execute_and_stream_lines(DiagnosticContext& context,
174170
const Command& cmd,
175171
const std::function<void(StringView)>& per_line_cb);

locales/messages.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@
764764
"ExtendedDocumentationAtUrl": "Extended documentation available at '{url}'.",
765765
"_ExtendedDocumentationAtUrl.comment": "An example of {url} is https://github.com/microsoft/vcpkg.",
766766
"ExtractHelp": "Extracts an archive.",
767+
"ExtractedInto": "extracted into {path}",
768+
"_ExtractedInto.comment": "An example of {path} is /foo/bar.",
767769
"ExtractingTool": "Extracting {tool_name}...",
768770
"_ExtractingTool.comment": "An example of {tool_name} is signtool.",
769771
"FailedPostBuildChecks": "Found {count} post-build check problem(s). These are usually caused by bugs in portfile.cmake or the upstream build system. Please correct these before submitting this port to the curated registry.",
@@ -1502,8 +1504,6 @@
15021504
"TripletLabel": "Triplet:",
15031505
"TwoFeatureFlagsSpecified": "Both '{value}' and -'{value}' were specified as feature flags.",
15041506
"_TwoFeatureFlagsSpecified.comment": "'{value}' is a feature flag.",
1505-
"UnableToClearPath": "unable to delete {path}",
1506-
"_UnableToClearPath.comment": "An example of {path} is /foo/bar.",
15071507
"UnableToReadAppDatas": "both %LOCALAPPDATA% and %APPDATA% were unreadable",
15081508
"UnableToReadEnvironmentVariable": "unable to read {env_var}",
15091509
"_UnableToReadEnvironmentVariable.comment": "An example of {env_var} is VCPKG_DEFAULT_TRIPLET.",
@@ -1758,6 +1758,8 @@
17581758
"_WhileCheckingOutBaseline.comment": "An example of {commit_sha} is 7cfad47ae9f68b183983090afd6337cd60fd4949.",
17591759
"WhileCheckingOutPortTreeIsh": "while checking out port {package_name} with git tree {git_tree_sha}",
17601760
"_WhileCheckingOutPortTreeIsh.comment": "An example of {package_name} is zlib. An example of {git_tree_sha} is 7cfad47ae9f68b183983090afd6337cd60fd4949.",
1761+
"WhileClearingThis": "while clearing this directory",
1762+
"WhileExtractingThisArchive": "while extracting this archive",
17611763
"WhileGettingLocalTreeIshObjectsForPorts": "while getting local treeish objects for ports",
17621764
"WhileLoadingBaselineVersionForPort": "while loading baseline version for {package_name}",
17631765
"_WhileLoadingBaselineVersionForPort.comment": "An example of {package_name} is zlib.",

src/vcpkg-test/system.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -134,34 +134,6 @@ TEST_CASE ("cmdlinebuilder", "[system]")
134134
#endif
135135
}
136136

137-
TEST_CASE ("cmd_execute_and_capture_output_parallel", "[system]")
138-
{
139-
std::vector<Command> vec;
140-
for (size_t i = 0; i < 50; ++i)
141-
{
142-
#if defined(_WIN32)
143-
vec.push_back(Command("cmd.exe").string_arg("/d").string_arg("/c").string_arg(fmt::format("echo {}", i)));
144-
#else
145-
vec.push_back(Command("echo").string_arg(std::string(i, 'a')));
146-
#endif
147-
}
148-
149-
auto res = cmd_execute_and_capture_output_parallel(vec);
150-
151-
for (size_t i = 0; i != res.size(); ++i)
152-
{
153-
auto out = res[i].get();
154-
REQUIRE(out != nullptr);
155-
REQUIRE(out->exit_code == 0);
156-
157-
#if defined(_WIN32)
158-
REQUIRE(out->output == (fmt::format("{}\r\n", i)));
159-
#else
160-
REQUIRE(out->output == (std::string(i, 'a') + "\n"));
161-
#endif
162-
}
163-
}
164-
165137
TEST_CASE ("append_shell_escaped", "[system]")
166138
{
167139
Command cmd;

src/vcpkg/archives.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -368,19 +368,4 @@ namespace vcpkg
368368
#endif
369369
return cmd;
370370
}
371-
372-
std::vector<ExpectedL<Unit>> decompress_in_parallel(View<Command> jobs)
373-
{
374-
RedirectedProcessLaunchSettings settings;
375-
settings.environment = get_clean_environment();
376-
auto results = cmd_execute_and_capture_output_parallel(jobs, settings);
377-
std::vector<ExpectedL<Unit>> filtered_results;
378-
filtered_results.reserve(jobs.size());
379-
for (std::size_t idx = 0; idx < jobs.size(); ++idx)
380-
{
381-
filtered_results.push_back(flatten(results[idx], jobs[idx].command_line()));
382-
}
383-
384-
return filtered_results;
385-
}
386371
}

src/vcpkg/base/files.cpp

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,16 +1693,23 @@ namespace vcpkg
16931693

16941694
std::vector<Path> ReadOnlyFilesystem::get_files_recursive(const Path& dir, LineInfo li) const
16951695
{
1696-
return this->try_get_files_recursive(dir).value_or_exit(li);
1696+
return this->try_get_files_recursive(console_diagnostic_context, dir).value_or_exit(li);
16971697
}
16981698

1699-
ExpectedL<std::vector<Path>> ReadOnlyFilesystem::try_get_files_recursive(const Path& dir) const
1699+
Optional<std::vector<Path>> ReadOnlyFilesystem::try_get_files_recursive(DiagnosticContext& context,
1700+
const Path& dir) const
17001701
{
17011702
std::error_code ec;
17021703
auto maybe_files = this->get_files_recursive(dir, ec);
17031704
if (ec)
17041705
{
1705-
return format_filesystem_call_error(ec, __func__, {dir});
1706+
context.report(DiagnosticLine{DiagKind::Error,
1707+
dir,
1708+
msg::format(msgSystemApiErrorMessage,
1709+
msg::system_api = "get_files_recursive",
1710+
msg::exit_code = ec.value(),
1711+
msg::error_msg = ec.message())});
1712+
return nullopt;
17061713
}
17071714

17081715
return maybe_files;
@@ -2308,16 +2315,6 @@ namespace vcpkg
23082315
return result;
23092316
}
23102317

2311-
void Filesystem::last_write_time(const Path& target, int64_t new_time, vcpkg::LineInfo li) const noexcept
2312-
{
2313-
std::error_code ec;
2314-
this->last_write_time(target, new_time, ec);
2315-
if (ec)
2316-
{
2317-
exit_filesystem_call_error(li, ec, __func__, {target});
2318-
}
2319-
}
2320-
23212318
void Filesystem::write_lines(const Path& file_path, const std::vector<std::string>& lines, LineInfo li) const
23222319
{
23232320
std::error_code ec;
@@ -3955,29 +3952,56 @@ namespace vcpkg
39553952
#endif // ^^^ !_WIN32
39563953
}
39573954

3958-
void last_write_time(const Path& target, int64_t new_time, std::error_code& ec) const override
3955+
virtual bool last_write_time(DiagnosticContext& context, const Path& target, int64_t new_time) const override
39593956
{
3957+
std::error_code ec;
39603958
#if defined(_WIN32)
39613959
stdfs::last_write_time(to_stdfs_path(target),
39623960
stdfs::file_time_type::time_point{stdfs::file_time_type::time_point::duration {
39633961
new_time
39643962
}},
39653963
ec);
3964+
if (ec)
3965+
{
3966+
context.report(DiagnosticLine{DiagKind::Error,
3967+
target,
3968+
msg::format(msgSystemApiErrorMessage,
3969+
msg::system_api = "std::fs::last_write_time",
3970+
msg::exit_code = ec.value(),
3971+
msg::error_msg = ec.message())});
3972+
return false;
3973+
}
39663974

3975+
return true;
39673976
#else // ^^^ _WIN32 // !_WIN32 vvv
39683977
PosixFd fd(target.c_str(), O_WRONLY, ec);
39693978
if (ec)
39703979
{
3971-
return;
3980+
context.report(DiagnosticLine{DiagKind::Error,
3981+
target,
3982+
msg::format(msgSystemApiErrorMessage,
3983+
msg::system_api = "open",
3984+
msg::exit_code = ec.value(),
3985+
msg::error_msg = ec.message())});
3986+
return false;
39723987
}
39733988
timespec times[2]; // last access and modification time
39743989
times[0].tv_nsec = UTIME_OMIT;
39753990
times[1].tv_nsec = new_time % 1'000'000'000;
39763991
times[1].tv_sec = new_time / 1'000'000'000;
39773992
if (futimens(fd.get(), times))
39783993
{
3979-
ec.assign(errno, std::system_category());
3994+
auto local_errno = errno;
3995+
context.report(
3996+
DiagnosticLine{DiagKind::Error,
3997+
target,
3998+
msg::format(msgSystemApiErrorMessage,
3999+
msg::system_api = "futimens",
4000+
msg::exit_code = local_errno,
4001+
msg::error_msg = std::system_category().message(local_errno))});
39804002
}
4003+
4004+
return true;
39814005
#endif // ^^^ !_WIN32
39824006
}
39834007

src/vcpkg/base/system.process.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <vcpkg/base/chrono.h>
55
#include <vcpkg/base/contractual-constants.h>
66
#include <vcpkg/base/files.h>
7-
#include <vcpkg/base/parallel-algorithms.h>
87
#include <vcpkg/base/parse.h>
98
#include <vcpkg/base/strings.h>
109
#include <vcpkg/base/system.debug.h>
@@ -746,23 +745,6 @@ namespace vcpkg
746745
static const Environment clean_env = get_modified_clean_environment({});
747746
return clean_env;
748747
}
749-
750-
std::vector<ExpectedL<ExitCodeAndOutput>> cmd_execute_and_capture_output_parallel(View<Command> commands)
751-
{
752-
RedirectedProcessLaunchSettings default_redirected_process_launch_settings;
753-
return cmd_execute_and_capture_output_parallel(commands, default_redirected_process_launch_settings);
754-
}
755-
756-
std::vector<ExpectedL<ExitCodeAndOutput>> cmd_execute_and_capture_output_parallel(
757-
View<Command> commands, const RedirectedProcessLaunchSettings& settings)
758-
{
759-
std::vector<ExpectedL<ExitCodeAndOutput>> res(commands.size(), LocalizedString{});
760-
761-
parallel_transform(
762-
commands, res.begin(), [&](const Command& cmd) { return cmd_execute_and_capture_output(cmd, settings); });
763-
764-
return res;
765-
}
766748
} // namespace vcpkg
767749

768750
namespace

0 commit comments

Comments
 (0)