diff --git a/.clang-format b/.clang-format index 089b83cd17..e59f067eed 100644 --- a/.clang-format +++ b/.clang-format @@ -55,7 +55,7 @@ BraceWrapping: IncludeBlocks: Regroup IncludeCategories: - - Regex: '^(|"pch\.h")$' + - Regex: '^(|"pch\.h")$' Priority: -1 - Regex: '^$' Priority: 1 diff --git a/.gitignore b/.gitignore index c2d6152dfc..148ce211b3 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ node_modules/ /ce/test/**/*.map /ce/test/**/*.js /ce/ce/vcpkg-ce.build.log +/ce/common/config/rush/.npmrc /ce/common/config/rush/pnpm-lock.yaml /ce/test/vcpkg-ce.test.build.log /ce/common/temp diff --git a/azure-pipelines/pipelines.yml b/azure-pipelines/pipelines.yml index a7f205bd6e..656babaebf 100644 --- a/azure-pipelines/pipelines.yml +++ b/azure-pipelines/pipelines.yml @@ -126,10 +126,31 @@ jobs: git -C "$env:VCPKG_ROOT" checkout $sha - task: CodeQL3000Init@0 displayName: 'CodeQL Initialize' + - task: Powershell@2 + displayName: 'Format C++' + inputs: + filePath: 'azure-pipelines/Format-CxxCode.ps1' + pwsh: true + - task: Powershell@2 + displayName: 'Create Diff' + inputs: + filePath: azure-pipelines/Create-PRDiff.ps1 + arguments: '-DiffFile $(DiffFile)' + pwsh: true + - task: PublishBuildArtifacts@1 + condition: failed() + displayName: 'Publish Format and Messages File Diff' + inputs: + PathtoPublish: '$(DiffFile)' + ArtifactName: 'format.diff' - task: UseNode@1 displayName: Use Node 16 or later inputs: version: "16.x" + - task: npmAuthenticate@0 + inputs: + workingFile: 'ce\common\config\rush\.npmrc' + # The working directory change is to get the above .npmrc used when installing rush - script: npm install -g @microsoft/rush displayName: Install Rush workingDirectory: ce\common\config\rush @@ -153,22 +174,5 @@ jobs: filePath: 'azure-pipelines/end-to-end-tests.ps1' workingDirectory: '$(Build.SourcesDirectory)/build.x86.debug' pwsh: true - - task: Powershell@2 - displayName: 'Format C++' - inputs: - filePath: 'azure-pipelines/Format-CxxCode.ps1' - pwsh: true - - task: Powershell@2 - displayName: 'Create Diff' - inputs: - filePath: azure-pipelines/Create-PRDiff.ps1 - arguments: '-DiffFile $(DiffFile)' - pwsh: true - - task: PublishBuildArtifacts@1 - condition: failed() - displayName: 'Publish Format and Messages File Diff' - inputs: - PathtoPublish: '$(DiffFile)' - ArtifactName: 'format.diff' - task: CodeQL3000Finalize@0 displayName: 'CodeQL Finalize' diff --git a/include/pch.h b/include/pch.h index 83568e2bc7..b8aea10169 100644 --- a/include/pch.h +++ b/include/pch.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #if defined(_MSC_VER) // pch.h only is used for performance with MSVC diff --git a/include/vcpkg-test/util.h b/include/vcpkg-test/util.h index a240a6eecc..0bd5e584dd 100644 --- a/include/vcpkg-test/util.h +++ b/include/vcpkg-test/util.h @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/include/vcpkg/base/api_stable_format.h b/include/vcpkg/base/api-stable-format.h similarity index 100% rename from include/vcpkg/base/api_stable_format.h rename to include/vcpkg/base/api-stable-format.h diff --git a/include/vcpkg/base/basic_checks.h b/include/vcpkg/base/basic-checks.h similarity index 100% rename from include/vcpkg/base/basic_checks.h rename to include/vcpkg/base/basic-checks.h diff --git a/include/vcpkg/base/checks.h b/include/vcpkg/base/checks.h index d4cfc2d258..4c2599297b 100644 --- a/include/vcpkg/base/checks.h +++ b/include/vcpkg/base/checks.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include diff --git a/include/vcpkg/base/cmd-parser.h b/include/vcpkg/base/cmd-parser.h new file mode 100644 index 0000000000..b380c18278 --- /dev/null +++ b/include/vcpkg/base/cmd-parser.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +#include + +#include + +namespace vcpkg +{ + struct HelpTableFormatter + { + // Adds a table entry with a key `col1` and value `col2` + void format(StringView col1, StringView col2); + // Adds an example block; typically just the text with no indenting + void example(StringView example_text); + // Adds a header typically placed at the top of several table entries + void header(StringView name); + // Adds a blank line + void blank(); + // Adds a line of text + void text(StringView text, int indent = 0); + + std::string m_str; + }; +} \ No newline at end of file diff --git a/include/vcpkg/base/delayed_init.h b/include/vcpkg/base/delayed-init.h similarity index 100% rename from include/vcpkg/base/delayed_init.h rename to include/vcpkg/base/delayed-init.h diff --git a/include/vcpkg/base/expected.h b/include/vcpkg/base/expected.h index 5e2df0a053..30ee7bef99 100644 --- a/include/vcpkg/base/expected.h +++ b/include/vcpkg/base/expected.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include diff --git a/include/vcpkg/base/files.h b/include/vcpkg/base/files.h index 142b5b21d3..c95ffd258a 100644 --- a/include/vcpkg/base/files.h +++ b/include/vcpkg/base/files.h @@ -156,14 +156,19 @@ namespace vcpkg uint64_t get_filesystem_stats(); - struct Filesystem + struct ILineReader + { + virtual ExpectedL> read_lines(const Path& file_path) const = 0; + + protected: + ~ILineReader(); + }; + + struct Filesystem : ILineReader { virtual std::string read_contents(const Path& file_path, std::error_code& ec) const = 0; std::string read_contents(const Path& file_path, LineInfo li) const; - virtual std::vector read_lines(const Path& file_path, std::error_code& ec) const = 0; - std::vector read_lines(const Path& file_path, LineInfo li) const; - virtual Path find_file_recursively_up(const Path& starting_dir, const Path& filename, std::error_code& ec) const = 0; diff --git a/include/vcpkg/base/fwd/cmd-parser.h b/include/vcpkg/base/fwd/cmd-parser.h new file mode 100644 index 0000000000..bda81ba8a5 --- /dev/null +++ b/include/vcpkg/base/fwd/cmd-parser.h @@ -0,0 +1,5 @@ +#pragma once +namespace vcpkg +{ + struct HelpTableFormatter; +} diff --git a/include/vcpkg/base/fwd/files.h b/include/vcpkg/base/fwd/files.h index 3677676493..851ba2db81 100644 --- a/include/vcpkg/base/fwd/files.h +++ b/include/vcpkg/base/fwd/files.h @@ -34,6 +34,7 @@ namespace vcpkg struct ReadFilePointer; struct WriteFilePointer; struct IExclusiveFileLock; + struct ILineReader; struct Filesystem; struct NotExtensionCaseSensitive; struct NotExtensionCaseInsensitive; diff --git a/include/vcpkg/base/lineinfo.h b/include/vcpkg/base/lineinfo.h index 68fca2e0e8..29b8ede563 100644 --- a/include/vcpkg/base/lineinfo.h +++ b/include/vcpkg/base/lineinfo.h @@ -10,4 +10,7 @@ namespace vcpkg } #define VCPKG_LINE_INFO \ - vcpkg::LineInfo { __LINE__, __FILE__ } + vcpkg::LineInfo \ + { \ + __LINE__, __FILE__ \ + } diff --git a/include/vcpkg/base/optional.h b/include/vcpkg/base/optional.h index caf9b30bd4..9c2298f632 100644 --- a/include/vcpkg/base/optional.h +++ b/include/vcpkg/base/optional.h @@ -2,7 +2,7 @@ #include -#include +#include #include #include diff --git a/include/vcpkg/base/setup_messages.h b/include/vcpkg/base/setup-messages.h similarity index 100% rename from include/vcpkg/base/setup_messages.h rename to include/vcpkg/base/setup-messages.h diff --git a/include/vcpkg/base/strings.h b/include/vcpkg/base/strings.h index b84876156c..5208f9c51d 100644 --- a/include/vcpkg/base/strings.h +++ b/include/vcpkg/base/strings.h @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include diff --git a/include/vcpkg/base/system_headers.h b/include/vcpkg/base/system-headers.h similarity index 100% rename from include/vcpkg/base/system_headers.h rename to include/vcpkg/base/system-headers.h diff --git a/include/vcpkg/base/to_string.h b/include/vcpkg/base/to-string.h similarity index 100% rename from include/vcpkg/base/to_string.h rename to include/vcpkg/base/to-string.h diff --git a/include/vcpkg/vcpkgcmdarguments.h b/include/vcpkg/vcpkgcmdarguments.h index 9ab8e7ffcb..38ffcf36d5 100644 --- a/include/vcpkg/vcpkgcmdarguments.h +++ b/include/vcpkg/vcpkgcmdarguments.h @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -74,17 +75,6 @@ namespace vcpkg std::string create_example_string(const std::string& command_and_arguments); - struct HelpTableFormatter - { - void format(StringView col1, StringView col2); - void example(StringView example_text); - void header(StringView name); - void blank(); - void text(StringView text, int indent = 0); - - std::string m_str; - }; - struct FeatureFlagSettings { bool registries; @@ -95,7 +85,7 @@ namespace vcpkg struct VcpkgCmdArguments { - static VcpkgCmdArguments create_from_command_line(const Filesystem& fs, + static VcpkgCmdArguments create_from_command_line(const ILineReader& fs, const int argc, const CommandLineCharType* const* const argv); static VcpkgCmdArguments create_from_arg_sequence(const std::string* arg_begin, const std::string* arg_end); diff --git a/src/vcpkg-test/catch.cpp b/src/vcpkg-test/catch.cpp index ac58557356..c54677802b 100644 --- a/src/vcpkg-test/catch.cpp +++ b/src/vcpkg-test/catch.cpp @@ -1,7 +1,7 @@ #define CATCH_CONFIG_RUNNER #include -#include +#include #include #include #include diff --git a/src/vcpkg-test/ci-baseline.cpp b/src/vcpkg-test/ci-baseline.cpp index 1244fa00fb..b9e686a231 100644 --- a/src/vcpkg-test/ci-baseline.cpp +++ b/src/vcpkg-test/ci-baseline.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include diff --git a/src/vcpkg-test/cmd-parser.cpp b/src/vcpkg-test/cmd-parser.cpp new file mode 100644 index 0000000000..317903d779 --- /dev/null +++ b/src/vcpkg-test/cmd-parser.cpp @@ -0,0 +1,40 @@ +#include + +#include + +using namespace vcpkg; + +TEST_CASE ("Smoke test help table formatter", "[cmd_parser]") +{ + HelpTableFormatter uut; + + uut.header("This is a header"); + uut.format("short-arg", "short help text"); + uut.format("a-really-long-arg-that-does-not-fit-in-the-first-column-and-keeps-going", "shorty"); + uut.format("short-arg", + "some really long help text that does not fit on the same line because we have a 100 character line " + "limit and oh god it keeps going and going"); + uut.format("a-really-long-arg-combined-with-some-really-long-help-text", + "another instance of that really long help text goes here to demonstrate that the worst case combo can " + "be accommodated"); + + uut.blank(); + uut.example("some example command"); + uut.text("this is some text"); + + const char* const expected = R"(This is a header: + short-arg short help text + a-really-long-arg-that-does-not-fit-in-the-first-column-and-keeps-going + shorty + short-arg some really long help text that does not fit on the same line + because we have a 100 character line limit and oh god it keeps + going and going + a-really-long-arg-combined-with-some-really-long-help-text + another instance of that really long help text goes here to + demonstrate that the worst case combo can be accommodated + +some example command +this is some text)"; + + CHECK(uut.m_str == expected); +} diff --git a/src/vcpkg-test/files.cpp b/src/vcpkg-test/files.cpp index 95611fa3ab..3d0d463443 100644 --- a/src/vcpkg-test/files.cpp +++ b/src/vcpkg-test/files.cpp @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/src/vcpkg-test/messages.cpp b/src/vcpkg-test/messages.cpp index 31b2c55136..f8e0a13dac 100644 --- a/src/vcpkg-test/messages.cpp +++ b/src/vcpkg-test/messages.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include #include diff --git a/src/vcpkg-test/strings.cpp b/src/vcpkg-test/strings.cpp index 6e8567dfec..02f68348e2 100644 --- a/src/vcpkg-test/strings.cpp +++ b/src/vcpkg-test/strings.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include diff --git a/src/vcpkg-test/system.cpp b/src/vcpkg-test/system.cpp index 51a4361a75..3ad5a803e7 100644 --- a/src/vcpkg-test/system.cpp +++ b/src/vcpkg-test/system.cpp @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/src/vcpkg.cpp b/src/vcpkg.cpp index b4d3bed5bc..95e355df10 100644 --- a/src/vcpkg.cpp +++ b/src/vcpkg.cpp @@ -1,10 +1,10 @@ -#include +#include #include #include #include #include -#include +#include #include #include #include diff --git a/src/vcpkg/base/cmd-parser.cpp b/src/vcpkg/base/cmd-parser.cpp new file mode 100644 index 0000000000..54ae9409ae --- /dev/null +++ b/src/vcpkg/base/cmd-parser.cpp @@ -0,0 +1,85 @@ +#include +#include + +#include + +#include + +namespace +{ + using namespace vcpkg; + + static void help_table_newline_indent(std::string& target) + { + target.push_back('\n'); + target.append(34, ' '); + } + + static constexpr ptrdiff_t S_MAX_LINE_LENGTH = 100; +} + +namespace vcpkg +{ + void HelpTableFormatter::format(StringView col1, StringView col2) + { + static constexpr std::size_t initial_space = 2; + static constexpr std::size_t col1_capacity = 31; + static constexpr std::size_t seperating_space = 1; + + m_str.append(initial_space, ' '); + Strings::append(m_str, col1); + if (col1.size() > col1_capacity) + { + help_table_newline_indent(m_str); + } + else + { + m_str.append((col1_capacity + seperating_space) - col1.size(), ' '); + } + text(col2, initial_space + col1_capacity + seperating_space); + + m_str.push_back('\n'); + } + + void HelpTableFormatter::header(StringView name) + { + m_str.append(name.data(), name.size()); + m_str.push_back(':'); + m_str.push_back('\n'); + } + + void HelpTableFormatter::example(StringView example_text) + { + m_str.append(example_text.data(), example_text.size()); + m_str.push_back('\n'); + } + + void HelpTableFormatter::blank() { m_str.push_back('\n'); } + + // Note: this formatting code does not properly handle unicode, however all of our documentation strings are English + // ASCII. + void HelpTableFormatter::text(StringView text, int indent) + { + const char* line_start = text.begin(); + const char* const e = text.end(); + const char* best_break = std::find_if(line_start, e, [](char ch) { return ch == ' ' || ch == '\n'; }); + + while (best_break != e) + { + const char* next_break = std::find_if(best_break + 1, e, [](char ch) { return ch == ' ' || ch == '\n'; }); + if (*best_break == '\n' || next_break - line_start + indent > S_MAX_LINE_LENGTH) + { + m_str.append(line_start, best_break); + m_str.push_back('\n'); + line_start = best_break + 1; + best_break = next_break; + m_str.append(indent, ' '); + } + else + { + best_break = next_break; + } + } + m_str.append(line_start, best_break); + } +} diff --git a/src/vcpkg/base/downloads.cpp b/src/vcpkg/base/downloads.cpp index 3ccaf88869..bfb365eaa8 100644 --- a/src/vcpkg/base/downloads.cpp +++ b/src/vcpkg/base/downloads.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/src/vcpkg/base/files.cpp b/src/vcpkg/base/files.cpp index d281335c31..b76ca70e3b 100644 --- a/src/vcpkg/base/files.cpp +++ b/src/vcpkg/base/files.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -1502,17 +1502,7 @@ namespace vcpkg int WriteFilePointer::put(int c) const noexcept { return ::fputc(c, m_fs); } - std::vector Filesystem::read_lines(const Path& file_path, LineInfo li) const - { - std::error_code ec; - auto maybe_lines = this->read_lines(file_path, ec); - if (ec) - { - exit_filesystem_call_error(li, ec, __func__, {file_path}); - } - - return maybe_lines; - } + ILineReader::~ILineReader() = default; std::string Filesystem::read_contents(const Path& file_path, LineInfo li) const { @@ -2087,14 +2077,15 @@ namespace vcpkg return output; } - virtual std::vector read_lines(const Path& file_path, std::error_code& ec) const override + virtual ExpectedL> read_lines(const Path& file_path) const override { StatsTimer t(g_us_filesystem_stats); + std::error_code ec; ReadFilePointer file{file_path, ec}; if (ec) { - Debug::print("Failed to open: ", file_path, '\n'); - return std::vector(); + Debug::println("Failed to open: ", file_path); + return format_filesystem_call_error(ec, __func__, {file_path}); } Strings::LinesCollector output; @@ -2109,7 +2100,7 @@ namespace vcpkg } else if ((ec = file.error())) { - return std::vector(); + return format_filesystem_call_error(ec, "read_lines_read", {file_path}); } } while (!file.eof()); @@ -2117,6 +2108,7 @@ namespace vcpkg if (res.size() > 0 && Strings::starts_with(res[0], "\xEF\xBB\xBF")) { // remove byte-order mark from the beginning of the string + res[0].erase(0, 3); } return res; diff --git a/src/vcpkg/base/messages.cpp b/src/vcpkg/base/messages.cpp index ea772df43e..4dd23d05ed 100644 --- a/src/vcpkg/base/messages.cpp +++ b/src/vcpkg/base/messages.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include diff --git a/src/vcpkg/base/strings.cpp b/src/vcpkg/base/strings.cpp index a1c96872fa..846a29e7b6 100644 --- a/src/vcpkg/base/strings.cpp +++ b/src/vcpkg/base/strings.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/src/vcpkg/base/system.process.cpp b/src/vcpkg/base/system.process.cpp index 00b48a1579..e6f9b5d390 100644 --- a/src/vcpkg/base/system.process.cpp +++ b/src/vcpkg/base/system.process.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/vcpkg/binarycaching.cpp b/src/vcpkg/binarycaching.cpp index 18795e3a15..5dc4143ad9 100644 --- a/src/vcpkg/binarycaching.cpp +++ b/src/vcpkg/binarycaching.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -21,8 +22,6 @@ #include -#include "vcpkg/base/api_stable_format.h" - using namespace vcpkg; namespace diff --git a/src/vcpkg/build.cpp b/src/vcpkg/build.cpp index 7c80e91d69..87bf0f152a 100644 --- a/src/vcpkg/build.cpp +++ b/src/vcpkg/build.cpp @@ -960,7 +960,7 @@ namespace vcpkg std::vector error_logs; if (fs.exists(logs, VCPKG_LINE_INFO)) { - error_logs = fs.read_lines(logs, VCPKG_LINE_INFO); + error_logs = fs.read_lines(logs).value_or_exit(VCPKG_LINE_INFO); Util::erase_remove_if(error_logs, [](const auto& line) { return line.empty(); }); } return ExtendedBuildResult{BuildResult::BUILD_FAILED, stdoutlog, std::move(error_logs)}; diff --git a/src/vcpkg/commands.acquire-project.cpp b/src/vcpkg/commands.acquire-project.cpp index d90a4ed675..a4b4dca647 100644 --- a/src/vcpkg/commands.acquire-project.cpp +++ b/src/vcpkg/commands.acquire-project.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/vcpkg/commands.acquire.cpp b/src/vcpkg/commands.acquire.cpp index 34d9cecd67..2728172798 100644 --- a/src/vcpkg/commands.acquire.cpp +++ b/src/vcpkg/commands.acquire.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/vcpkg/commands.activate.cpp b/src/vcpkg/commands.activate.cpp index 62f7d018f9..0a38bd5a9b 100644 --- a/src/vcpkg/commands.activate.cpp +++ b/src/vcpkg/commands.activate.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/vcpkg/commands.add.cpp b/src/vcpkg/commands.add.cpp index e57587542e..c21627386e 100644 --- a/src/vcpkg/commands.add.cpp +++ b/src/vcpkg/commands.add.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/src/vcpkg/commands.deactivate.cpp b/src/vcpkg/commands.deactivate.cpp index f76afd4966..12fb558951 100644 --- a/src/vcpkg/commands.deactivate.cpp +++ b/src/vcpkg/commands.deactivate.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/vcpkg/commands.generate-msbuild-props.cpp b/src/vcpkg/commands.generate-msbuild-props.cpp index ce52e75d04..a90ff6da70 100644 --- a/src/vcpkg/commands.generate-msbuild-props.cpp +++ b/src/vcpkg/commands.generate-msbuild-props.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/vcpkg/commands.new.cpp b/src/vcpkg/commands.new.cpp index dd25b48bb2..c851cfd42f 100644 --- a/src/vcpkg/commands.new.cpp +++ b/src/vcpkg/commands.new.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/vcpkg/commands.regenerate.cpp b/src/vcpkg/commands.regenerate.cpp index 7daa401c4a..220b3c337b 100644 --- a/src/vcpkg/commands.regenerate.cpp +++ b/src/vcpkg/commands.regenerate.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/vcpkg/commands.use.cpp b/src/vcpkg/commands.use.cpp index 38ed284287..c01160262d 100644 --- a/src/vcpkg/commands.use.cpp +++ b/src/vcpkg/commands.use.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/vcpkg/commands.zce.cpp b/src/vcpkg/commands.zce.cpp index bb2214d2be..bcb48c09b5 100644 --- a/src/vcpkg/commands.zce.cpp +++ b/src/vcpkg/commands.zce.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/vcpkg/configure-environment.cpp b/src/vcpkg/configure-environment.cpp index f3fa4725cc..c1d8797a82 100644 --- a/src/vcpkg/configure-environment.cpp +++ b/src/vcpkg/configure-environment.cpp @@ -1,7 +1,7 @@ -#include +#include #include #include -#include +#include #include #include #include diff --git a/src/vcpkg/export.cpp b/src/vcpkg/export.cpp index 9f1fbacf4e..31471bbe13 100644 --- a/src/vcpkg/export.cpp +++ b/src/vcpkg/export.cpp @@ -528,7 +528,8 @@ namespace vcpkg::Export const InstallDir dirs = InstallDir::from_destination_root(export_paths, action.spec.triplet(), binary_paragraph); - auto lines = fs.read_lines(paths.installed().listfile_path(binary_paragraph), VCPKG_LINE_INFO); + auto lines = + fs.read_lines(paths.installed().listfile_path(binary_paragraph)).value_or_exit(VCPKG_LINE_INFO); std::vector files; for (auto&& suffix : lines) { diff --git a/src/vcpkg/install.cpp b/src/vcpkg/install.cpp index f1230768f2..d42f9a7d92 100644 --- a/src/vcpkg/install.cpp +++ b/src/vcpkg/install.cpp @@ -737,15 +737,15 @@ namespace vcpkg return ret; } - auto files = fs.read_lines(installed.listfile_path(bpgh), ec); - if (!ec) + auto maybe_files = fs.read_lines(installed.listfile_path(bpgh)); + if (auto files = maybe_files.get()) { std::unordered_map config_files; std::map> library_targets; bool is_header_only = true; std::string header_path; - for (auto&& suffix : files) + for (auto&& suffix : *files) { if (Strings::contains(suffix, "/share/") && Strings::ends_with(suffix, ".cmake")) { diff --git a/src/vcpkg/postbuildlint.cpp b/src/vcpkg/postbuildlint.cpp index c628098ca0..13a017d2d2 100644 --- a/src/vcpkg/postbuildlint.cpp +++ b/src/vcpkg/postbuildlint.cpp @@ -753,16 +753,17 @@ namespace vcpkg::PostBuildLint // Always allow .pc files in "lib/pkgconfig": if (pkgconfig_parent_name == "lib") continue; // Allow .pc in "share/pkgconfig" if and only if it contains no "Libs:" or "Libs.private:" directives: - const bool contains_libs = Util::any_of(fs.read_lines(path, VCPKG_LINE_INFO), [](const std::string& line) { - if (Strings::starts_with(line, "Libs")) - { - // only consider "Libs:" or "Libs.private:" directives when they have a value - const auto colon = line.find_first_of(':'); - if (colon != std::string::npos && line.find_first_not_of(' ', colon + 1) != std::string::npos) - return true; - } - return false; - }); + const bool contains_libs = + Util::any_of(fs.read_lines(path).value_or_exit(VCPKG_LINE_INFO), [](const std::string& line) { + if (Strings::starts_with(line, "Libs")) + { + // only consider "Libs:" or "Libs.private:" directives when they have a value + const auto colon = line.find_first_of(':'); + if (colon != std::string::npos && line.find_first_not_of(' ', colon + 1) != std::string::npos) + return true; + } + return false; + }); if (pkgconfig_parent_name == "share" && !contains_libs) continue; if (!contains_libs) { diff --git a/src/vcpkg/registries.cpp b/src/vcpkg/registries.cpp index c1d34c282b..d284e3c0a0 100644 --- a/src/vcpkg/registries.cpp +++ b/src/vcpkg/registries.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/src/vcpkg/remove.cpp b/src/vcpkg/remove.cpp index 01d1c9d4a9..0ab59e8378 100644 --- a/src/vcpkg/remove.cpp +++ b/src/vcpkg/remove.cpp @@ -38,15 +38,15 @@ namespace vcpkg::Remove write_update(fs, installed, spgh); } - std::error_code ec; - auto lines = fs.read_lines(installed.listfile_path(ipv.core->package), ec); - if (!ec) + auto maybe_lines = fs.read_lines(installed.listfile_path(ipv.core->package)); + if (auto lines = maybe_lines.get()) { std::vector dirs_touched; - for (auto&& suffix : lines) + for (auto&& suffix : *lines) { auto target = installed.root() / suffix; + std::error_code ec; const auto status = fs.symlink_status(target, ec); if (ec) { @@ -82,6 +82,7 @@ namespace vcpkg::Remove { if (fs.is_empty(*b, IgnoreErrors{})) { + std::error_code ec; fs.remove(*b, ec); if (ec) { diff --git a/src/vcpkg/statusparagraphs.cpp b/src/vcpkg/statusparagraphs.cpp index 9e5d774092..d8a53eccfe 100644 --- a/src/vcpkg/statusparagraphs.cpp +++ b/src/vcpkg/statusparagraphs.cpp @@ -179,10 +179,12 @@ namespace vcpkg { iobj.insert("usage", Json::Value::string(std::move(usage.message))); } - auto owns_files = fs.read_lines(installed.listfile_path(ipv.core->package), VCPKG_LINE_INFO); + auto owns_files = fs.read_lines(installed.listfile_path(ipv.core->package)).value_or_exit(VCPKG_LINE_INFO); Json::Array owns; for (auto&& owns_file : owns_files) + { owns.push_back(Json::Value::string(std::move(owns_file))); + } iobj.insert("owns", std::move(owns)); return Json::Value::object(std::move(iobj)); diff --git a/src/vcpkg/vcpkgcmdarguments.cpp b/src/vcpkg/vcpkgcmdarguments.cpp index f9ff7a00e4..07e0ddf68a 100644 --- a/src/vcpkg/vcpkgcmdarguments.cpp +++ b/src/vcpkg/vcpkgcmdarguments.cpp @@ -181,7 +181,7 @@ namespace vcpkg } } - VcpkgCmdArguments VcpkgCmdArguments::create_from_command_line(const Filesystem& fs, + VcpkgCmdArguments VcpkgCmdArguments::create_from_command_line(const ILineReader& fs, const int argc, const CommandLineCharType* const* const argv) { @@ -198,7 +198,7 @@ namespace vcpkg if (arg.size() > 0 && arg[0] == '@') { arg.erase(arg.begin()); - auto lines = fs.read_lines(arg, VCPKG_LINE_INFO); + auto lines = fs.read_lines(arg).value_or_exit(VCPKG_LINE_INFO); v.insert(v.end(), std::make_move_iterator(lines.begin()), std::make_move_iterator(lines.end())); } else @@ -966,74 +966,6 @@ namespace vcpkg return cs; } - static void help_table_newline_indent(std::string& target) - { - target.push_back('\n'); - target.append(34, ' '); - } - - static constexpr ptrdiff_t S_MAX_LINE_LENGTH = 100; - - void HelpTableFormatter::format(StringView col1, StringView col2) - { - // 2 space, 31 col1, 1 space, 65 col2 = 99 - m_str.append(2, ' '); - Strings::append(m_str, col1); - if (col1.size() > 31) - { - help_table_newline_indent(m_str); - } - else - { - m_str.append(32 - col1.size(), ' '); - } - text(col2, 34); - - m_str.push_back('\n'); - } - - void HelpTableFormatter::header(StringView name) - { - m_str.append(name.data(), name.size()); - m_str.push_back(':'); - m_str.push_back('\n'); - } - - void HelpTableFormatter::example(StringView example_text) - { - m_str.append(example_text.data(), example_text.size()); - m_str.push_back('\n'); - } - - void HelpTableFormatter::blank() { m_str.push_back('\n'); } - - // Note: this formatting code does not properly handle unicode, however all of our documentation strings are English - // ASCII. - void HelpTableFormatter::text(StringView text, int indent) - { - const char* line_start = text.begin(); - const char* const e = text.end(); - const char* best_break = std::find_if(line_start, e, [](char ch) { return ch == ' ' || ch == '\n'; }); - - while (best_break != e) - { - const char* next_break = std::find_if(best_break + 1, e, [](char ch) { return ch == ' ' || ch == '\n'; }); - if (*best_break == '\n' || next_break - line_start + indent > S_MAX_LINE_LENGTH) - { - m_str.append(line_start, best_break); - m_str.push_back('\n'); - line_start = best_break + 1; - best_break = next_break; - m_str.append(indent, ' '); - } - else - { - best_break = next_break; - } - } - m_str.append(line_start, best_break); - } - // out-of-line definitions since C++14 doesn't allow inline constexpr static variables constexpr StringLiteral VcpkgCmdArguments::VCPKG_ROOT_DIR_ENV; constexpr StringLiteral VcpkgCmdArguments::VCPKG_ROOT_DIR_ARG; diff --git a/src/vcpkg/vcpkglib.cpp b/src/vcpkg/vcpkglib.cpp index 937544c172..e4b02b4471 100644 --- a/src/vcpkg/vcpkglib.cpp +++ b/src/vcpkg/vcpkglib.cpp @@ -203,7 +203,8 @@ namespace vcpkg } const auto listfile_path = installed.listfile_path(pgh->package); - std::vector installed_files_of_current_pgh = fs.read_lines(listfile_path, VCPKG_LINE_INFO); + std::vector installed_files_of_current_pgh = + fs.read_lines(listfile_path).value_or_exit(VCPKG_LINE_INFO); Strings::trim_all_and_remove_whitespace_strings(&installed_files_of_current_pgh); upgrade_to_slash_terminated_sorted_format(fs, &installed_files_of_current_pgh, listfile_path);