Skip to content

fix double adding of additional_files_0...#1901

Closed
TobiasFunk wants to merge 1 commit intomicrosoft:mainfrom
TobiasFunk:main
Closed

fix double adding of additional_files_0...#1901
TobiasFunk wants to merge 1 commit intomicrosoft:mainfrom
TobiasFunk:main

Conversation

@TobiasFunk
Copy link

@TobiasFunk TobiasFunk commented Jan 20, 2026

Should fix #1900 but i'm not sure if i would break an additional feature (this is why i first draft the PR)

As already commented in the ticket:

There are two places where hash_additional_files are added to abi_tag_entries:

Lines 1425-1435 (INCORRECT): Inside the port_dir_cache.get_lazy() lambda, the code adds entries directly to abi_tag_entries:

for (size_t i = 0; i < abi_info.pre_build_info->hash_additional_files.size(); ++i)
{
    // ...
    abi_tag_entries.emplace_back(
        fmt::format("additional_file_{}", i),
        Hash::get_file_hash(fs, file, Hash::Algorithm::Sha256).value_or_exit(VCPKG_LINE_INFO));
}

Lines 1474-1488 (CORRECT): After retrieving the cache entry, the code adds the same entries again:

for (auto& filestr : abi_info.pre_build_info->hash_additional_files)
{
    // ...
    abi_tag_entries.emplace_back(fmt::format("additional_file_{}", i++), hash);
}

Why This Causes Inconsistent Behavior

First package built (cache miss): The lambda at lines 1409-1468 executes, and line 1432 incorrectly adds additional_file_* to abi_tag_entries. Then line 1486 adds them again → double entries.

Second package with same port_dir (cache hit): The lambda doesn't execute (cache hit), so only line 1486 runs → single entry.

@TobiasFunk TobiasFunk marked this pull request as ready for review January 20, 2026 20:38
Comment on lines +1422 to +1423
// Note: hash_additional_files are triplet-specific, not port-specific,
// so they are processed outside this cache lambda (see lines 1474-1488)
Copy link
Contributor

Choose a reason for hiding this comment

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

should still run through per port customization though. Maybe add a testcase which shows the issue.

Copy link
Author

Choose a reason for hiding this comment

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

i think this comment is a bit misleading, i will remove it

this is my first change in this project, and i feel a bit uncomfortable to do the change by myself as i have not a complete picture in the project, for me the PR was more about to show the issue, but this was going wrong in this case :D

So i understand your comment. Per port customizations should be untouched by the change. Adding a test is hard as nearly no function is accessible for the test..

The problem is actual really simple.
When using a response file you can install the same port for different triplets

gtest
gtest:our-x86-windows-static

the first entry use the triplet from vcpkg command, the second the port mentioned in the response file. If the triplet has now a VCPKG_HASH_ADDITIONAL_FILES variable, the first entry was adding the VCPKG_HASH_ADDITIONAL_FILES to the
port_dir_cache_entry & to the abi_tag_entries +1422 to +1423
-> as i'm not 100% sure perhaps it is better to actual add it to port_dir_cache_entry.abi_entries

between +1472 to

this code is doing this as well, so actual the action for the first port is doubled (can be easily retested with some port have VCPKG_HASH_ADDITIONAL_FILES)

you will get additional_file_0 xxx 2 times, always

the second port now runs the code again in same vcpkg.exe instance, as the port_dir_cache_entry is already filled, the removed code was skipped and was resulting in additional_file_0 xxx once

This is a problem with my cache
as now

vcpkg install gtest:our-x64-windows-static --overlay-triplet=xxx
vcpkg install gtest:our-x86-windows-static --overlay-triplet=xxx

and
vcpkg install --triplet=our-x64-windows-static --overlay-triplet=xxx @responefile

results in different abi for gtest:our-x86-windows-static

@TobiasFunk TobiasFunk marked this pull request as draft January 20, 2026 23:12
@BillyONeal
Copy link
Member

It looks like the double adding was added by accident as part of #802 ; probably from merge conflict hell since that PR went on for so long.

BillyONeal added a commit to BillyONeal/vcpkg-tool that referenced this pull request Feb 11, 2026
Alternative to microsoft#1901

When microsoft#802 tried to add per-directory caching of hashed contents, the additional files part got added multiple times by accident.
@BillyONeal
Copy link
Member

Closing due to being replaced by #1914 . Thanks for your contribution!

@BillyONeal BillyONeal closed this Feb 11, 2026
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.

vcpkg-tool inconsistent behaviour when using response file

3 participants