Command line parser prerequisites (#853)

* Expected-ize read_lines.

* Introduce IReadLines as a smaller interface for things that just want to read lines.

* Extract HelpTableFormatter and consistently use -s in source file names.

* Rename IReadLines to ILineReader, as requested by Victor.

* Name the numbers in HelpTableFormatter::format as requested by Victor.

* Fix NPM authenticate.
This commit is contained in:
Billy O'Neal 2023-01-12 18:54:09 -08:00 коммит произвёл GitHub
Родитель 36ed4a8428
Коммит 17bb1b8480
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
56 изменённых файлов: 264 добавлений и 175 удалений

Просмотреть файл

@ -55,7 +55,7 @@ BraceWrapping:
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^(<vcpkg/base/system_headers\.h>|"pch\.h")$'
- Regex: '^(<vcpkg/base/system-headers\.h>|"pch\.h")$'
Priority: -1
- Regex: '^<catch2/catch\.hpp>$'
Priority: 1

1
.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

Просмотреть файл

@ -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'

Просмотреть файл

@ -1,6 +1,6 @@
#pragma once
#include <vcpkg/base/system_headers.h>
#include <vcpkg/base/system-headers.h>
#if defined(_MSC_VER)
// pch.h only is used for performance with MSVC

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/system_headers.h>
#include <vcpkg/base/system-headers.h>
#include <catch2/catch.hpp>

Просмотреть файл

Просмотреть файл

@ -1,6 +1,6 @@
#pragma once
#include <vcpkg/base/basic_checks.h>
#include <vcpkg/base/basic-checks.h>
#include <vcpkg/base/messages.h>
#include <vcpkg/base/strings.h>

Просмотреть файл

@ -0,0 +1,26 @@
#pragma once
#include <vcpkg/base/fwd/cmd-parser.h>
#include <vcpkg/base/stringview.h>
#include <string>
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;
};
}

Просмотреть файл

Просмотреть файл

@ -6,7 +6,7 @@
#include <vcpkg/base/checks.h>
#include <vcpkg/base/lineinfo.h>
#include <vcpkg/base/stringview.h>
#include <vcpkg/base/to_string.h>
#include <vcpkg/base/to-string.h>
#include <functional>
#include <system_error>

Просмотреть файл

@ -156,14 +156,19 @@ namespace vcpkg
uint64_t get_filesystem_stats();
struct Filesystem
struct ILineReader
{
virtual ExpectedL<std::vector<std::string>> 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<std::string> read_lines(const Path& file_path, std::error_code& ec) const = 0;
std::vector<std::string> 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;

Просмотреть файл

@ -0,0 +1,5 @@
#pragma once
namespace vcpkg
{
struct HelpTableFormatter;
}

Просмотреть файл

@ -34,6 +34,7 @@ namespace vcpkg
struct ReadFilePointer;
struct WriteFilePointer;
struct IExclusiveFileLock;
struct ILineReader;
struct Filesystem;
struct NotExtensionCaseSensitive;
struct NotExtensionCaseInsensitive;

Просмотреть файл

@ -10,4 +10,7 @@ namespace vcpkg
}
#define VCPKG_LINE_INFO \
vcpkg::LineInfo { __LINE__, __FILE__ }
vcpkg::LineInfo \
{ \
__LINE__, __FILE__ \
}

Просмотреть файл

@ -2,7 +2,7 @@
#include <vcpkg/base/fwd/optional.h>
#include <vcpkg/base/basic_checks.h>
#include <vcpkg/base/basic-checks.h>
#include <vcpkg/base/lineinfo.h>
#include <vcpkg/base/pragmas.h>

Просмотреть файл

@ -3,7 +3,7 @@
#include <vcpkg/base/lineinfo.h>
#include <vcpkg/base/optional.h>
#include <vcpkg/base/stringview.h>
#include <vcpkg/base/to_string.h>
#include <vcpkg/base/to-string.h>
#include <errno.h>
#include <inttypes.h>

Просмотреть файл

Просмотреть файл

@ -5,6 +5,7 @@
#include <vcpkg/fwd/vcpkgcmdarguments.h>
#include <vcpkg/fwd/vcpkgpaths.h>
#include <vcpkg/base/cmd-parser.h>
#include <vcpkg/base/files.h>
#include <vcpkg/base/optional.h>
#include <vcpkg/base/span.h>
@ -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);

Просмотреть файл

@ -1,7 +1,7 @@
#define CATCH_CONFIG_RUNNER
#include <catch2/catch.hpp>
#include <vcpkg/base/basic_checks.h>
#include <vcpkg/base/basic-checks.h>
#include <vcpkg/base/messages.h>
#include <vcpkg/base/system.debug.h>
#include <vcpkg/base/system.h>

Просмотреть файл

@ -1,6 +1,6 @@
#include <catch2/catch.hpp>
#include <vcpkg/base/basic_checks.h>
#include <vcpkg/base/basic-checks.h>
#include <vcpkg/base/parse.h>
#include <vcpkg/build.h>

Просмотреть файл

@ -0,0 +1,40 @@
#include <catch2/catch.hpp>
#include <vcpkg/base/cmd-parser.h>
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);
}

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/system_headers.h>
#include <vcpkg/base/system-headers.h>
#include <catch2/catch.hpp>

Просмотреть файл

@ -1,7 +1,7 @@
#include <catch2/catch.hpp>
#include <vcpkg/base/json.h>
#include <vcpkg/base/setup_messages.h>
#include <vcpkg/base/setup-messages.h>
#include <vcpkg/commands.generate-message-map.h>

Просмотреть файл

@ -1,6 +1,6 @@
#include <catch2/catch.hpp>
#include <vcpkg/base/api_stable_format.h>
#include <vcpkg/base/api-stable-format.h>
#include <vcpkg/base/expected.h>
#include <vcpkg/base/strings.h>

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/system_headers.h>
#include <vcpkg/base/system-headers.h>
#include <catch2/catch.hpp>

Просмотреть файл

@ -1,10 +1,10 @@
#include <vcpkg/base/system_headers.h>
#include <vcpkg/base/system-headers.h>
#include <vcpkg/base/chrono.h>
#include <vcpkg/base/files.h>
#include <vcpkg/base/json.h>
#include <vcpkg/base/pragmas.h>
#include <vcpkg/base/setup_messages.h>
#include <vcpkg/base/setup-messages.h>
#include <vcpkg/base/strings.h>
#include <vcpkg/base/system.debug.h>
#include <vcpkg/base/system.process.h>

Просмотреть файл

@ -0,0 +1,85 @@
#include <vcpkg/base/cmd-parser.h>
#include <vcpkg/base/strings.h>
#include <stdint.h>
#include <algorithm>
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);
}
}

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/api_stable_format.h>
#include <vcpkg/base/api-stable-format.h>
#include <vcpkg/base/cache.h>
#include <vcpkg/base/downloads.h>
#include <vcpkg/base/hash.h>

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/system_headers.h>
#include <vcpkg/base/system-headers.h>
#include <vcpkg/base/chrono.h>
#include <vcpkg/base/files.h>
@ -1502,17 +1502,7 @@ namespace vcpkg
int WriteFilePointer::put(int c) const noexcept { return ::fputc(c, m_fs); }
std::vector<std::string> 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<std::string> read_lines(const Path& file_path, std::error_code& ec) const override
virtual ExpectedL<std::vector<std::string>> 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<std::string>();
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<std::string>();
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;

Просмотреть файл

@ -1,6 +1,6 @@
#include <vcpkg/base/json.h>
#include <vcpkg/base/messages.h>
#include <vcpkg/base/setup_messages.h>
#include <vcpkg/base/setup-messages.h>
#include <vcpkg/base/system.debug.h>
#include <vcpkg/base/util.h>

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/api_stable_format.h>
#include <vcpkg/base/api-stable-format.h>
#include <vcpkg/base/checks.h>
#include <vcpkg/base/expected.h>
#include <vcpkg/base/messages.h>

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/system_headers.h>
#include <vcpkg/base/system-headers.h>
#include <vcpkg/base/checks.h>
#include <vcpkg/base/chrono.h>

Просмотреть файл

@ -1,3 +1,4 @@
#include <vcpkg/base/api-stable-format.h>
#include <vcpkg/base/checks.h>
#include <vcpkg/base/downloads.h>
#include <vcpkg/base/files.h>
@ -21,8 +22,6 @@
#include <iterator>
#include "vcpkg/base/api_stable_format.h"
using namespace vcpkg;
namespace

Просмотреть файл

@ -960,7 +960,7 @@ namespace vcpkg
std::vector<std::string> 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)};

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/basic_checks.h>
#include <vcpkg/base/basic-checks.h>
#include <vcpkg/commands.acquire-project.h>
#include <vcpkg/configure-environment.h>

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/basic_checks.h>
#include <vcpkg/base/basic-checks.h>
#include <vcpkg/commands.acquire.h>
#include <vcpkg/configure-environment.h>

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/basic_checks.h>
#include <vcpkg/base/basic-checks.h>
#include <vcpkg/commands.activate.h>
#include <vcpkg/configure-environment.h>

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/basic_checks.h>
#include <vcpkg/base/basic-checks.h>
#include <vcpkg/base/hash.h>
#include <vcpkg/base/messages.h>
#include <vcpkg/base/strings.h>

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/basic_checks.h>
#include <vcpkg/base/basic-checks.h>
#include <vcpkg/commands.deactivate.h>
#include <vcpkg/configure-environment.h>

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/basic_checks.h>
#include <vcpkg/base/basic-checks.h>
#include <vcpkg/commands.generate-msbuild-props.h>
#include <vcpkg/configure-environment.h>

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/basic_checks.h>
#include <vcpkg/base/basic-checks.h>
#include <vcpkg/base/util.h>
#include <vcpkg/commands.new.h>

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/basic_checks.h>
#include <vcpkg/base/basic-checks.h>
#include <vcpkg/base/stringview.h>
#include <vcpkg/base/util.h>

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/basic_checks.h>
#include <vcpkg/base/basic-checks.h>
#include <vcpkg/commands.use.h>
#include <vcpkg/configure-environment.h>

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/basic_checks.h>
#include <vcpkg/base/basic-checks.h>
#include <vcpkg/commands.zce.h>
#include <vcpkg/configure-environment.h>

Просмотреть файл

@ -1,7 +1,7 @@
#include <vcpkg/base/basic_checks.h>
#include <vcpkg/base/basic-checks.h>
#include <vcpkg/base/downloads.h>
#include <vcpkg/base/json.h>
#include <vcpkg/base/setup_messages.h>
#include <vcpkg/base/setup-messages.h>
#include <vcpkg/base/system.debug.h>
#include <vcpkg/base/system.print.h>
#include <vcpkg/base/system.process.h>

Просмотреть файл

@ -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<Path> files;
for (auto&& suffix : lines)
{

Просмотреть файл

@ -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<std::string, std::string> config_files;
std::map<std::string, std::vector<std::string>> 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"))
{

Просмотреть файл

@ -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)
{

Просмотреть файл

@ -1,4 +1,4 @@
#include <vcpkg/base/delayed_init.h>
#include <vcpkg/base/delayed-init.h>
#include <vcpkg/base/json.h>
#include <vcpkg/base/jsonreader.h>
#include <vcpkg/base/messages.h>

Просмотреть файл

@ -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<Path> 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)
{

Просмотреть файл

@ -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));

Просмотреть файл

@ -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;

Просмотреть файл

@ -203,7 +203,8 @@ namespace vcpkg
}
const auto listfile_path = installed.listfile_path(pgh->package);
std::vector<std::string> installed_files_of_current_pgh = fs.read_lines(listfile_path, VCPKG_LINE_INFO);
std::vector<std::string> 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);