CPack/productbuild: add options to control domains element
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
-
Source/CPack/cmCPackPKGGenerator.cxx
:- L.165/R: After writing the component groups to the Distribution XML, make a call to
this->CreateDomains()
which handles appending thedomains
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. - LL.279-81/R: If the
CPACK_PRODUCTBUILD_DOMAINS
option is set and truthy, then omit theauth
attribute of thepkg-ref
element. - LL.296-98/R: If the
CPACK_PRODUCTBUILD_DOMAINS
option is not set or falsy, then omit thedomains
element. This ensures the default behavior for projects is to not insert thedomains
element (opt-in only). - LL.305-19/R: Handle setting the 3 attributes (
enable_anywhere
,enable_currentUserHome
, andenable_localSystem
). Allow defaults to be overridden via attribute-specific options.
- L.165/R: After writing the component groups to the Distribution XML, make a call to
- Various documentation related changes.
Testing
In downstream project, ran the following:
-
Do not specify
CPACK_PRODUCTBUILD_DOMAINS
Observation:
domains
element not written to Distribution XML -
Specify
set(CPACK_PRODUCTBUILD_DOMAINS TRUE)
Observation:
<domains enable_anywhere="true" enable_currentUserHome="false" enable_localSystem="true"/>
-
Specify
set(CPACK_PRODUCTBUILD_DOMAINS TRUE)
andset(CPACK_PRODUCTBUILD_DOMAINS_USER TRUE)
Observation:
<domains enable_anywhere="true" enable_currentUserHome="true" enable_localSystem="true"/>
-
Specify various combinations of above.
In (2) and (3), the auth
attribute was also omitted from pkg-ref
.
Fixes: #23030 (closed)