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

Ensure spdx_location is not dropped when loading ports. #1237

Merged
merged 8 commits into from
Nov 10, 2023

Conversation

BillyONeal
Copy link
Member

The next extraction from #1210

  1. Change try_load_port and friends to accept the spdx location and return SourceControlFileAndLocation rather than requiring all callers to staple that on.
  2. PathAndLocation => PortLocation
  3. Fix confusion in SourceControlFileAndLocation due to some parts of the codebase using source_location as the port_directory.
  4. Rename all "registry_location"s to "spdx_location" to avoid it sounding like this is the spdx location of the registry.
  5. Require origin to be provided in all the places.

1. Change try_load_port and friends to accept the spdx location and return SourceControlFileAndLocation rather than requiring all callers to staple that on.
2. PathAndLocation => PortLocation
3. Fix confusion in SourceControlFileAndLocation due to some parts of the codebase using source_location as the port_directory.
4. Rename all "registry_location"s to "spdx_location" to avoid it sounding like this is the spdx location of the registry.
5. Require origin to be provided in all the places.
src/vcpkg/paragraphs.cpp Outdated Show resolved Hide resolved
src/vcpkg/paragraphs.cpp Outdated Show resolved Hide resolved

auto maybe_scf =
Paragraphs::try_load_port_required(fs, port_name, paths.builtin_ports_directory() / port_name);
auto maybe_scf = Paragraphs::try_load_port_required(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto maybe_scf = Paragraphs::try_load_port_required(
auto maybe_scfl = Paragraphs::try_load_port_required(

scf == SourceControlFile

const auto formatted_content = Json::stringify(json);
if (current_file_content != formatted_content)
{
auto command_line = fmt::format("vcpkg format-manifest ports/{}/vcpkg.json", port_name);
auto command_line = fmt::format("vcpkg format-manifest {}", scf->control_path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be shell escaped? For example, if the user has a space in their path.

{
msg::println(msgInstallingFromLocation, msg::path = scfl.source_location);
msg::println(msgInstallingFromLocation, msg::path = scfl.control_path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be port_directory() or control_path?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did intend this change but I guess technically it's also referring to patches and stuff in there.

src/vcpkg/commands.ci-verify-versions.cpp Show resolved Hide resolved
Comment on lines 410 to 411
const auto manifest_path = port_location.port_directory / "vcpkg.json";
const auto control_path = port_location.port_directory / "CONTROL";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be non-const so they can be moved into the return?

@@ -549,20 +537,16 @@ namespace vcpkg::Paragraphs
auto maybe_port_location = (*port_entry)->get_version(*baseline_version);
const auto port_location = maybe_port_location.get();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove const so this can be moved into try_load_port_required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pointer so there's no benefit to be had for moving it. Also, try_load_port_required accepts by const& because the data in question is normally owned by the registry...

{
auto scf_vspec = scf->get()->to_version_spec();
auto scf_vspec = scfl->source_control_file.get()->to_version_spec();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto scf_vspec = scfl->source_control_file.get()->to_version_spec();
auto scf_vspec = scfl->source_control_file->to_version_spec();

Additionally, consider lifting to_version_spec() up to SourceControlFileAndLocation.

Comment on lines 245 to 247
auto port_name = scfl.source_control_file->core_paragraph->name;
auto it = m_control_cache.emplace(VersionSpec{port_name, scfl.to_version()}, std::move(scfl)).first;
out.emplace(std::move(port_name), &it->second.value_or_exit(VCPKG_LINE_INFO));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is calling scfl.to_version() while also moving from scfl before the next sequence point.

Suggested change
auto port_name = scfl.source_control_file->core_paragraph->name;
auto it = m_control_cache.emplace(VersionSpec{port_name, scfl.to_version()}, std::move(scfl)).first;
out.emplace(std::move(port_name), &it->second.value_or_exit(VCPKG_LINE_INFO));
auto vspec = scfl.source_control_file->to_version_spec();
auto it = m_control_cache.emplace(std::move(vspec), std::move(scfl)).first;
out.emplace(it->first.port_name, &it->second.value_or_exit(VCPKG_LINE_INFO));

{
auto& scf = *scfp;
if (scf->core_paragraph->name == port_name)
if (scfl->source_control_file->core_paragraph->name == port_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be very nice to expose .name() on SCF/SCFL

Comment on lines 310 to +312
if (Paragraphs::is_port_directory(m_fs, ports_spec))
{
auto found_scf = Paragraphs::try_load_port_required(m_fs, port_name, ports_spec);
if (auto scfp = found_scf.get())
auto found_scfl = Paragraphs::try_load_port_required(m_fs, port_name, PortLocation{ports_spec});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some duplicate work between is_port_directory and try_load_port_required that can be removed without much contortion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but not in this extraction :)

@BillyONeal BillyONeal merged commit 365d419 into microsoft:main Nov 10, 2023
5 checks passed
@BillyONeal BillyONeal deleted the spdx_location branch November 10, 2023 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants