This is an archive of the discontinued LLVM Phabricator instance.

Get CPACK config variables from the cache to allow overriding via cache file
AcceptedPublic

Authored by jonathanreeves on Aug 4 2021, 9:25 PM.

Details

Summary

For custom-built toolchains, it's extremely useful to be able to override the CPack packaging instructions, especially on Windows.

Elsewhere in the build it's already possible to override the Vendor that appears in the binary. It would be nice to be able to carry this through to installers.

This patch does introduce a CMake warning about the CPACK_NSIS_COMPRESSOR variable having a newline character. Note that no changes have been made to the variable values themselves here, just the caching.

Diff Detail

Event Timeline

jonathanreeves created this revision.Aug 4 2021, 9:25 PM
jonathanreeves requested review of this revision.Aug 4 2021, 9:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2021, 9:25 PM
jonathanreeves edited the summary of this revision. (Show Details)Aug 4 2021, 9:39 PM
jonathanreeves added reviewers: rnk, chandlerc.
ben.boeckel requested changes to this revision.Aug 5 2021, 4:39 AM
ben.boeckel added a subscriber: ben.boeckel.
ben.boeckel added inline comments.
llvm/CMakeLists.txt
232–282

Please either add docstrings for each of these or use mark_as_advanced to hide them from regular developer cache editing activities. Preferably both.

234

There is also the "sticky cache" issue here. If I configure by build tree first with 13.0.0, this gets set to 13. If I then continue to use this build tree through to 14.0.0…it is still 13. I suggest, instead doing something like this:

set(CPACK_PACKAGE_VERSION_MAJOR "<DEFAULT>" CACHE STRING "")
if (CPACK_PACKAGE_VERSION_MAJOR STREQUAL "<DEFAULT>")
  set(CPACK_PACKAGE_VERSION_MAJOR "${LLVM_VERSION_MAJOR}")
elseif (NOT CPACK_PACKAGE_VERSION_MAJOR STREQUAL LLVM_VERSION_MAJOR)
  # This condition is optional, but can help when manual settings are stale.
  message(AUTHOR_WARNING
    "Manually set `CPACK_PACKAGE_VERSION_MAJOR` does not match the "
    "detected major version of `${LLVM_VERSION_MAJOR}`; your cache may "
    "be out-of-date."
endif ()

so that it actually acts like a default rather than an initial value that "sticks around" in cases where "no one" would want it to.

This revision now requires changes to proceed.Aug 5 2021, 4:39 AM
jonathanreeves added inline comments.Aug 5 2021, 10:20 AM
llvm/CMakeLists.txt
232–282

Makes sense, will do.

234

Good point. I wonder if it actually makes sense to just do something like this for all of them:

if(NOT DEFINED CPACK_PACKAGE_VERSION_MAJOR)
  set(CPACK_PACKAGE_VERSION_MAJOR "${LLVM_VERSION_MAJOR}")
endif()

Basically if someone wants to override the CPack variables, they will do it via cache. If no overrides exist, the build will take the regularly scoped variables, which will be uncached. The only case that's potentially not covered here is one where you're trying to go from a custom build (which will have these variables in cache) to a stock one. In this case the variables will be sticky. I think this is a pretty pathological case though, probably one that can be safely ignored.

The other advantage to doing this is that we would no longer need the mark_as_advanced. The stock build just wouldn't use the cache.

This is probably a simpler solution overall though. Thoughts on this?

ben.boeckel added inline comments.Aug 5 2021, 10:40 AM
llvm/CMakeLists.txt
234

Something like this could work then:

cmake
if (LLVM_RESET_PACKAGING_SETTINGS)
  foreach (package_var IN ITEMS …)
    unset("${package_var}" CACHE)
  endforeach ()
  unset(LLVM_RESET_PACKAGING_SETTINGS CACHE) # make it a simple toggle
endif ()

# if (NOT DEFINED) blocks
jonathanreeves marked an inline comment as not done.Aug 5 2021, 10:51 AM
jonathanreeves added inline comments.
llvm/CMakeLists.txt
234

Yep that would cover the custom -> stock case. I'll put it together and resubmit something hopefully later today.

PR feedback: ability to clear cached packaging settings, and making version variables non-cached by default

jonathanreeves marked 3 inline comments as done.Aug 13 2021, 9:42 PM

Sorry for the delay on this, I was out of town until yesterday, just finished up testing the changes. Note that I do think several of these variables deserve to be cached and "sticky", I just protected the version settings from the unintentional caching problem. Let me know what you think of this. Trying to avoid a bunch of conditionals on things that are unlikely or undesirable to frequently change.

I realize I was a little slow responding to this, but it's been idle for a little while now. @ben.boeckel do you have an suggestions for other reviewers I should add? It would still be nice to get this into a release. Thanks!

ben.boeckel accepted this revision.Aug 24 2021, 12:13 PM

Sorry for the delay. The changes look good to me.

This revision is now accepted and ready to land.Aug 24 2021, 12:13 PM

Thanks @ben.boeckel, much appreciated! Forgive the noob question, but what are the next steps for getting it merged? I didn't see much in the LLVM documentation. Is there anything I need to do to actually see this all the way through?

what are the next steps for getting it merged? I didn't see much in the LLVM documentation. Is there anything I need to do to actually see this all the way through?

I can't say I know that. I don't have powers to merge here and am just another community member (that also happens to be a CMake developer).