Skip to content

CPack/productbuild: add options to control domains element

David Wosk requested to merge davidwosk1/cmake:cpack-pkg-domains into master

Summary

According to the documentation for the Distribution.xml file, the auth attribute in the pkg-ref element is deprecated. Instead, the domains element is the preferred way to determine the required authorization level needed for the install. Removing auth="Admin" allows package developers to create installers that do not require root privileges when installing to the user's home directory.

Remedy

Introduce a CPACK_PRODUCTBUILD_DOMAINS option that, when set, outputs the domains element to the Distribution XML and omits the auth attribute of the pkg-ref element. The attributes of the domains element are able to be overridden via the CPACK_PRODUCTBUILD_DOMAINS_ANYWHERE, CPACK_PRODUCTBUILD_USER, and ``CPACK_PRODUCTBUILD_ROOT` options.

Rundown

  1. Source/CPack/cmCPackPKGGenerator.cxx:
    1. L.165/R: After writing the component groups to the Distribution XML, make a call to this->CreateDomains() which handles appending the domains element to the XML. I suppose this could be moved elsewhere (such as before writing the component groups). I just chose this line as a starting point.
    2. LL.279-81/R: If the CPACK_PRODUCTBUILD_DOMAINS option is set and truthy, then omit the auth attribute of the pkg-ref element.
    3. LL.296-98/R: If the CPACK_PRODUCTBUILD_DOMAINS option is not set or falsy, then omit the domains element. This ensures the default behavior for projects is to not insert the domains element (opt-in only).
    4. LL.305-19/R: Handle setting the 3 attributes (enable_anywhere, enable_currentUserHome, and enable_localSystem). Allow defaults to be overridden via attribute-specific options.
  2. Various documentation related changes.

Testing

In downstream project, ran the following:

  1. Do not specify CPACK_PRODUCTBUILD_DOMAINS

    Observation: domains element not written to Distribution XML

  2. Specify set(CPACK_PRODUCTBUILD_DOMAINS TRUE)

    Observation:

    <domains enable_anywhere="true" enable_currentUserHome="false" enable_localSystem="true"/>
  3. Specify set(CPACK_PRODUCTBUILD_DOMAINS TRUE) and set(CPACK_PRODUCTBUILD_DOMAINS_USER TRUE)

    Observation:

    <domains enable_anywhere="true" enable_currentUserHome="true" enable_localSystem="true"/>
  4. Specify various combinations of above.

In (2) and (3), the auth attribute was also omitted from pkg-ref.


Fixes: #23030 (closed)

Edited by Brad King

Merge request reports