Vcpkg: Rebuilding package second time fails, because patches cannot be applied by vcpkg_apply_patches command

Created on 29 Nov 2019  路  5Comments  路  Source: microsoft/vcpkg

Scenario:
I'm building a package, then either build fails or I uninstall the package and install it again.
The copy of sources in buildtrees however has patches applied from the first time I've (tried) to build the package. Second time patches cannot be applied and build fails.
Workaround: remove corresponding package from buildtree.

This happens when I use vcpkg_apply_patches directly and not when patches are applied using vcpkg_from_github.

documentation question

All 5 comments

vcpkg_apply_patches is deprecated, we don't recommend its use precisely because of the situation you described.

When patches are specified in the vcpkg_from_* or vcpkg_extract_source_archives_ex functions, the patch files contents are used to calculate a hash used in the directory name where the sources are extracted. This ensures that patches are always applied to a fresh copy of the sources.

Thank you for clarification. So what would be the proper way to apply patches conditionally (if such need araises)?
Also please update documentation accordingly, as it doesn't inform about deprecation:
https://github.com/microsoft/vcpkg/blob/master/docs/maintainers/vcpkg_apply_patches.md

You should check your conditions before calling vcpkg_from_* or vcpkg_extract_source_archive_ex.

if (condition)
    vcpkg_from_github(
        ...
       PATCHES "patch1.patch"
    )
else()    
    vcpkg_from_github(
        ...
       # PATCHES -- no patches
    )
endif()

Better:
Introduce a variable called PATCHES and conditionally list(APPEND) to it. This reduces the amount of written code and does not duplicate the function call.

Also please update documentation accordingly, as it doesn't inform about deprecation:
https://github.com/microsoft/vcpkg/blob/master/docs/maintainers/vcpkg_apply_patches.md

Yes please

Was this page helpful?
0 / 5 - 0 ratings