Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid writing the status database for read-only commands. #1531

Merged
merged 7 commits into from
Dec 17, 2024
16 changes: 16 additions & 0 deletions include/vcpkg/base/contractual-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,33 @@ namespace vcpkg
inline constexpr StringLiteral FileBaselineDotJson = "baseline.json";
inline constexpr StringLiteral FileBin = "bin";
inline constexpr StringLiteral FileControl = "CONTROL";
inline constexpr StringLiteral FileCopying = "COPYING";
inline constexpr StringLiteral FileCopyright = "copyright";
inline constexpr StringLiteral FileDebug = "debug";
inline constexpr StringLiteral FileDetectCompiler = "detect_compiler";
inline constexpr StringLiteral FileDotDsStore = ".DS_Store";
inline constexpr StringLiteral FileInclude = "include";
inline constexpr StringLiteral FileIncomplete = "incomplete";
inline constexpr StringLiteral FileInfo = "info";
inline constexpr StringLiteral FileLicense = "LICENSE";
inline constexpr StringLiteral FileLicenseDotTxt = "LICENSE.txt";
inline constexpr StringLiteral FilePortfileDotCMake = "portfile.cmake";
inline constexpr StringLiteral FileShare = "share";
inline constexpr StringLiteral FileStatus = "status";
inline constexpr StringLiteral FileStatusNew = "status-new";
inline constexpr StringLiteral FileStatusOld = "status-old";
inline constexpr StringLiteral FileTools = "tools";
inline constexpr StringLiteral FileUpdates = "updates";
inline constexpr StringLiteral FileUsage = "usage";
inline constexpr StringLiteral FileVcpkg = "vcpkg";
inline constexpr StringLiteral FileVcpkgAbiInfo = "vcpkg_abi_info.txt";
inline constexpr StringLiteral FileVcpkgBundleDotJson = "vcpkg-bundle.json";
inline constexpr StringLiteral FileVcpkgConfigurationDotJson = "vcpkg-configuration.json";
inline constexpr StringLiteral FileVcpkgDotJson = "vcpkg.json";
inline constexpr StringLiteral FileVcpkgLock = "vcpkg-lock.json";
inline constexpr StringLiteral FileVcpkgPathTxt = "vcpkg.path.txt";
inline constexpr StringLiteral FileVcpkgPortConfig = "vcpkg-port-config.cmake";
inline constexpr StringLiteral FileVcpkgSpdxJson = "vcpkg.spdx.json";
inline constexpr StringLiteral FileVcpkgUserProps = "vcpkg.user.props";
inline constexpr StringLiteral FileVcpkgUserTargets = "vcpkg.user.targets";
inline constexpr StringLiteral FileVersions = "versions";
Expand Down
18 changes: 10 additions & 8 deletions include/vcpkg/installedpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <vcpkg/fwd/binaryparagraph.h>

#include <vcpkg/base/contractual-constants.h>
#include <vcpkg/base/path.h>

#include <vcpkg/packagespec.h>
Expand All @@ -16,15 +17,16 @@ namespace vcpkg
const Path& root() const { return m_root; }
Path listfile_path(const BinaryParagraph& pgh) const;

Path vcpkg_dir() const { return m_root / "vcpkg"; }
Path vcpkg_dir_status_file() const { return vcpkg_dir() / "status"; }
Path vcpkg_dir_info() const { return vcpkg_dir() / "info"; }
Path vcpkg_dir_updates() const { return vcpkg_dir() / "updates"; }
Path lockfile_path() const { return vcpkg_dir() / "vcpkg-lock.json"; }
Path vcpkg_dir() const { return m_root / FileVcpkg; }
Path vcpkg_dir_status_file() const { return vcpkg_dir() / FileStatus; }
Path vcpkg_dir_info() const { return vcpkg_dir() / FileInfo; }
Path vcpkg_dir_updates() const { return vcpkg_dir() / FileUpdates; }
Path lockfile_path() const { return vcpkg_dir() / FileVcpkgLock; }
Path triplet_dir(Triplet t) const { return m_root / t.canonical_name(); }
Path share_dir(const PackageSpec& p) const { return triplet_dir(p.triplet()) / "share" / p.name(); }
Path usage_file(const PackageSpec& p) const { return share_dir(p) / "usage"; }
Path vcpkg_port_config_cmake(const PackageSpec& p) const { return share_dir(p) / "vcpkg-port-config.cmake"; }
Path share_dir(const PackageSpec& p) const { return triplet_dir(p.triplet()) / FileShare / p.name(); }
Path usage_file(const PackageSpec& p) const { return share_dir(p) / FileUsage; }
Path spdx_file(const PackageSpec& p) const { return share_dir(p) / FileVcpkgSpdxJson; }
Path vcpkg_port_config_cmake(const PackageSpec& p) const { return share_dir(p) / FileVcpkgPortConfig; }

private:
Path m_root;
Expand Down
15 changes: 13 additions & 2 deletions include/vcpkg/vcpkglib.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@

namespace vcpkg
{
StatusParagraphs database_load_check(const Filesystem& fs, const InstalledPaths& installed);
// Read the status database
StatusParagraphs database_load(const ReadOnlyFilesystem& fs, const InstalledPaths& installed);
// Read the status database, and collapse update records into the current status file
StatusParagraphs database_load_collapse(const Filesystem& fs, const InstalledPaths& installed);

// Adds an update record
void write_update(const Filesystem& fs, const InstalledPaths& installed, const StatusParagraph& p);

struct StatusParagraphAndAssociatedFiles
Expand All @@ -24,9 +28,16 @@ namespace vcpkg
};

std::vector<InstalledPackageView> get_installed_ports(const StatusParagraphs& status_db);
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files(const Filesystem& fs,

// Reads the installed files from the status database.
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files(const ReadOnlyFilesystem& fs,
const InstalledPaths& installed,
const StatusParagraphs& status_db);
// Reads the installed files from the status database, converting installed file lists to the current version if
// necessary.
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files_and_upgrade(const Filesystem& fs,
const InstalledPaths& installed,
const StatusParagraphs& status_db);

std::string shorten_text(StringView desc, const size_t length);
} // namespace vcpkg
6 changes: 3 additions & 3 deletions src/vcpkg/commands.build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ namespace vcpkg
auto& var_provider = *var_provider_storage;
var_provider.load_dep_info_vars({{spec}}, host_triplet);

StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
StatusParagraphs status_db = database_load_collapse(paths.get_filesystem(), paths.installed());
auto action_plan = create_feature_install_plan(
provider,
var_provider,
Expand Down Expand Up @@ -941,7 +941,7 @@ namespace vcpkg
const auto& abi = action.abi_info.value_or_exit(VCPKG_LINE_INFO);

const auto json_path =
action.package_dir.value_or_exit(VCPKG_LINE_INFO) / "share" / action.spec.name() / "vcpkg.spdx.json";
action.package_dir.value_or_exit(VCPKG_LINE_INFO) / FileShare / action.spec.name() / FileVcpkgSpdxJson;
fs.write_contents_and_dirs(
json_path,
create_spdx_sbom(
Expand Down Expand Up @@ -1446,7 +1446,7 @@ namespace vcpkg
if (abi_info.abi_tag_file)
{
auto& abi_file = *abi_info.abi_tag_file.get();
const auto abi_package_dir = action.package_dir.value_or_exit(VCPKG_LINE_INFO) / "share" / spec.name();
const auto abi_package_dir = action.package_dir.value_or_exit(VCPKG_LINE_INFO) / FileShare / spec.name();
const auto abi_file_in_package = abi_package_dir / FileVcpkgAbiInfo;
build_logs_recorder.record_build_result(paths, spec, result.code);
filesystem.create_directories(abi_package_dir, VCPKG_LINE_INFO);
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.ci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ namespace vcpkg
}
else
{
StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
StatusParagraphs status_db = database_load_collapse(paths.get_filesystem(), paths.installed());
auto already_installed = adjust_action_plan_to_status_db(action_plan, status_db);
Util::erase_if(already_installed,
[&](auto& spec) { return Util::Sets::contains(split_specs->known, spec); });
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ namespace vcpkg
Triplet host_triplet)
{
(void)host_triplet;
const StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
const StatusParagraphs status_db = database_load(paths.get_filesystem(), paths.installed());
const auto opts = handle_export_command_arguments(paths, args, default_triplet, status_db);

// Load ports from ports dirs
Expand Down
5 changes: 3 additions & 2 deletions src/vcpkg/commands.install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ namespace vcpkg
const auto package_dir = paths.package_dir(bcf.core_paragraph.spec);
Triplet triplet = bcf.core_paragraph.spec.triplet();
const std::vector<StatusParagraphAndAssociatedFiles> pgh_and_files =
get_installed_files(fs, installed, *status_db);
get_installed_files_and_upgrade(fs, installed, *status_db);

const SortedVector<std::string> package_files = build_list_of_package_files(fs, package_dir);
const SortedVector<file_pack> installed_files = build_list_of_installed_files(pgh_and_files, triplet);
Expand Down Expand Up @@ -619,6 +619,7 @@ namespace vcpkg
this_install.current_summary.build_result.emplace(std::move(result));
}

database_load_collapse(fs, paths.installed());
msg::println(msgTotalInstallTime, msg::elapsed = timer.to_string());
return InstallSummary{std::move(results)};
}
Expand Down Expand Up @@ -1288,7 +1289,7 @@ namespace vcpkg

// create the plan
msg::println(msgComputingInstallPlan);
StatusParagraphs status_db = database_load_check(fs, paths.installed());
StatusParagraphs status_db = database_load_collapse(fs, paths.installed());

// Note: action_plan will hold raw pointers to SourceControlFileLocations from this map
auto action_plan = create_feature_install_plan(provider, var_provider, specs, status_db, create_options);
Expand Down
3 changes: 2 additions & 1 deletion src/vcpkg/commands.list.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <vcpkg/base/contractual-constants.h>
#include <vcpkg/base/files.h>
#include <vcpkg/base/strings.h>
#include <vcpkg/base/util.h>

Expand Down Expand Up @@ -103,7 +104,7 @@ namespace vcpkg
msg::default_output_stream = OutputStream::StdErr;
const ParsedArguments options = args.parse_arguments(CommandListMetadata);

const StatusParagraphs status_paragraphs = database_load_check(paths.get_filesystem(), paths.installed());
const StatusParagraphs status_paragraphs = database_load(paths.get_filesystem(), paths.installed());
auto installed_ipv = get_installed_ports(status_paragraphs);

const auto output_json = Util::Sets::contains(options.switches, SwitchXJson);
Expand Down
6 changes: 4 additions & 2 deletions src/vcpkg/commands.owns.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <vcpkg/base/files.h>

#include <vcpkg/commands.owns.h>
#include <vcpkg/statusparagraphs.h>
#include <vcpkg/vcpkgcmdarguments.h>
Expand All @@ -8,7 +10,7 @@ using namespace vcpkg;

namespace
{
void search_file(const Filesystem& fs,
void search_file(const ReadOnlyFilesystem& fs,
const InstalledPaths& installed,
const std::string& file_substr,
const StatusParagraphs& status_db)
Expand Down Expand Up @@ -46,7 +48,7 @@ namespace vcpkg
void command_owns_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
{
const auto parsed = args.parse_arguments(CommandOwnsMetadata);
const StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
const StatusParagraphs status_db = database_load(paths.get_filesystem(), paths.installed());
search_file(paths.get_filesystem(), paths.installed(), parsed.command_arguments[0], status_db);
Checks::exit_success(VCPKG_LINE_INFO);
}
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.package-info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace vcpkg
auto& fs = paths.get_filesystem();
if (installed)
{
const StatusParagraphs status_paragraphs = database_load_check(fs, paths.installed());
const StatusParagraphs status_paragraphs = database_load(fs, paths.installed());
std::set<PackageSpec> specs_written;
std::vector<PackageSpec> specs_to_write;
for (auto&& arg : options.command_arguments)
Expand Down
5 changes: 3 additions & 2 deletions src/vcpkg/commands.remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ namespace

std::vector<std::string> valid_arguments(const VcpkgPaths& paths)
{
const StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
const StatusParagraphs status_db = database_load(paths.get_filesystem(), paths.installed());
auto installed_packages = get_installed_ports(status_db);

return Util::fmap(installed_packages, [](auto&& pgh) -> std::string { return pgh.spec().to_string(); });
Expand Down Expand Up @@ -183,7 +183,7 @@ namespace vcpkg
}
const ParsedArguments options = args.parse_arguments(CommandRemoveMetadata);

StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
StatusParagraphs status_db = database_load_collapse(paths.get_filesystem(), paths.installed());
std::vector<PackageSpec> specs;
if (Util::Sets::contains(options.switches, SwitchOutdated))
{
Expand Down Expand Up @@ -301,6 +301,7 @@ namespace vcpkg
}
}

database_load_collapse(fs, paths.installed());
Checks::exit_success(VCPKG_LINE_INFO);
}
}
2 changes: 1 addition & 1 deletion src/vcpkg/commands.set-installed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ namespace vcpkg
}

// currently (or once) installed specifications
auto status_db = database_load_check(fs, paths.installed());
auto status_db = database_load_collapse(fs, paths.installed());
adjust_action_plan_to_status_db(action_plan, status_db);

print_plan(action_plan, paths.builtin_ports_directory());
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace vcpkg
msg::println(msgLocalPortfileVersion);

auto& fs = paths.get_filesystem();
const StatusParagraphs status_db = database_load_check(fs, paths.installed());
const StatusParagraphs status_db = database_load(fs, paths.installed());

auto registry_set = paths.make_registry_set();
PathsPortFileProvider provider(*registry_set,
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.upgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace vcpkg
const CreateUpgradePlanOptions create_upgrade_plan_options{
nullptr, host_triplet, paths.packages(), unsupported_port_action};

StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
StatusParagraphs status_db = database_load_collapse(paths.get_filesystem(), paths.installed());

// Load ports from ports dirs
auto& fs = paths.get_filesystem();
Expand Down
4 changes: 2 additions & 2 deletions src/vcpkg/export.prefab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ namespace vcpkg::Prefab

const auto share_root = paths.packages() / fmt::format("{}_{}", name, action.spec.triplet());

fs.copy_file(share_root / "share" / name / "copyright",
meta_dir / "LICENSE",
fs.copy_file(share_root / FileShare / name / FileCopyright,
meta_dir / FileLicense,
CopyOptions::overwrite_existing,
IgnoreErrors{});

Expand Down
12 changes: 6 additions & 6 deletions src/vcpkg/postbuildlint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ namespace vcpkg
const Path& portfile_cmake,
MessageSink& msg_sink)
{
const auto debug_share = package_dir / "debug" VCPKG_PREFERRED_SEPARATOR "share";
const auto debug_share = package_dir / FileDebug / FileShare;
if (fs.exists(debug_share, IgnoreErrors{}))
{
msg_sink.print(Color::warning,
Expand All @@ -303,7 +303,7 @@ namespace vcpkg
const Path& portfile_cmake,
MessageSink& msg_sink)
{
if (!fs.exists(package_dir / "share" / package_name / "vcpkg-port-config.cmake", IgnoreErrors{}))
if (!fs.exists(package_dir / FileShare / package_name / FileVcpkgPortConfig, IgnoreErrors{}))
{
msg_sink.print(Color::warning,
LocalizedString::from_raw(portfile_cmake)
Expand All @@ -327,8 +327,8 @@ namespace vcpkg
static constexpr StringLiteral STANDARD_INSTALL_USAGE =
R"###(file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}"))###";

auto usage_path_from = port_dir / "usage";
auto usage_path_to = package_dir / "share" / package_name / "usage";
auto usage_path_from = port_dir / FileUsage;
auto usage_path_to = package_dir / FileShare / package_name / FileUsage;

if (fs.is_regular_file(usage_path_from) && !fs.is_regular_file(usage_path_to))
{
Expand Down Expand Up @@ -467,8 +467,8 @@ namespace vcpkg
const Path& portfile_cmake,
MessageSink& msg_sink)
{
static constexpr StringLiteral copyright_filenames[] = {"COPYING", "LICENSE", "LICENSE.txt"};
const auto copyright_file = package_dir / "share" / spec_name / "copyright";
static constexpr StringLiteral copyright_filenames[] = {FileCopying, FileLicense, FileLicenseDotTxt};
const auto copyright_file = package_dir / FileShare / spec_name / FileCopyright;

switch (fs.status(copyright_file, IgnoreErrors{}))
{
Expand Down
Loading
Loading