From da737d34e05d4a07b64596fc4970a0dd279a741d Mon Sep 17 00:00:00 2001 From: David Wosk Date: Tue, 21 Dec 2021 16:54:38 -0800 Subject: CPack/productbuild: add options to control domains element The domains element determines the required authorization level needed for the install. The auth attribute of the pkg-ref element has been deprecated in favor of domains, so if the domains options are specified, the auth attribute is omitted. Fixes: #23030 --- Help/cpack_gen/productbuild.rst | 40 +++++++++++++++++++++++++ Help/release/dev/cpack-productbuild-domains.rst | 9 ++++++ Source/CPack/cmCPackPKGGenerator.cxx | 37 ++++++++++++++++++++++- Source/CPack/cmCPackPKGGenerator.h | 4 +++ 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 Help/release/dev/cpack-productbuild-domains.rst diff --git a/Help/cpack_gen/productbuild.rst b/Help/cpack_gen/productbuild.rst index 75d5cff..dc98c85 100644 --- a/Help/cpack_gen/productbuild.rst +++ b/Help/cpack_gen/productbuild.rst @@ -86,6 +86,46 @@ macOS using ProductBuild: :variable:`CPACK_RESOURCE_FILE_README`, and :variable:`CPACK_RESOURCE_FILE_LICENSE` files are copied. +.. variable:: CPACK_PRODUCTBUILD_DOMAINS + + .. versionadded:: 3.23 + + Adds a domains element to Distribution XML if specified. When set to true, + the productbuild generator creates the following XML element: + + .. code-block:: xml + + + + The default values used for the attributes can be overridden with + :variable:`CPACK_PRODUCTBUILD_DOMAINS_ANYWHERE`, + :variable:`CPACK_PRODUCTBUILD_DOMAINS_USER`, and + :variable:`CPACK_PRODUCTBUILD_DOMAINS_ROOT`. + +.. variable:: CPACK_PRODUCTBUILD_DOMAINS_ANYWHERE + + .. versionadded:: 3.23 + + May be used to override the ``enable_anywhere`` attribute in the domains + element in the Distribution XML when :variable:`CPACK_PRODUCTBUILD_DOMAINS` + is set to ``TRUE``. + +.. variable:: CPACK_PRODUCTBUILD_DOMAINS_USER + + .. versionadded:: 3.23 + + May be used to override the ``enable_currentUserHome`` attribute in the domains + element in the Distribution XML when :variable:`CPACK_PRODUCTBUILD_DOMAINS` + is set to ``TRUE``. + +.. variable:: CPACK_PRODUCTBUILD_DOMAINS_ROOT + + .. versionadded:: 3.23 + + May be used to override the ``enable_localSystem`` attribute in the domains + element in the Distribution XML when :variable:`CPACK_PRODUCTBUILD_DOMAINS` + is set to ``TRUE``. + Background Image """""""""""""""" diff --git a/Help/release/dev/cpack-productbuild-domains.rst b/Help/release/dev/cpack-productbuild-domains.rst new file mode 100644 index 0000000..32a2eee --- /dev/null +++ b/Help/release/dev/cpack-productbuild-domains.rst @@ -0,0 +1,9 @@ +cpack-productbuild-domains +----------------------------- + +* The :cpack_gen:`CPack productbuild Generator` gained the new + :variable:`CPACK_PRODUCTBUILD_DOMAINS`, + :variable:`CPACK_PRODUCTBUILD_DOMAINS_ANYWHERE`, + :variable:`CPACK_PRODUCTBUILD_DOMAINS_USER`, and + :variable:`CPACK_PRODUCTBUILD_DOMAINS_ROOT` variables for + adding the domains element to the Distribution XML. diff --git a/Source/CPack/cmCPackPKGGenerator.cxx b/Source/CPack/cmCPackPKGGenerator.cxx index b62fab8..d8095cc 100644 --- a/Source/CPack/cmCPackPKGGenerator.cxx +++ b/Source/CPack/cmCPackPKGGenerator.cxx @@ -162,6 +162,8 @@ void cmCPackPKGGenerator::WriteDistributionFile(const char* metapackageFile, CreateChoice(PostFlightComponent, xout); } + this->CreateDomains(xout); + // default background this->CreateBackground(nullptr, metapackageFile, genName, xout); // Dark Aqua @@ -273,7 +275,10 @@ void cmCPackPKGGenerator::CreateChoice(const cmCPackComponent& component, xout.Attribute("id", packageId); xout.Attribute("version", this->GetOption("CPACK_PACKAGE_VERSION")); xout.Attribute("installKBytes", installedSize); - xout.Attribute("auth", "Admin"); + // The auth attribute is deprecated in favor of the domains element + if (cmIsOff(this->GetOption("CPACK_PRODUCTBUILD_DOMAINS"))) { + xout.Attribute("auth", "Admin"); + } xout.Attribute("onConclusion", "None"); if (component.IsDownloaded) { xout.Content(this->GetOption("CPACK_DOWNLOAD_SITE")); @@ -286,6 +291,36 @@ void cmCPackPKGGenerator::CreateChoice(const cmCPackComponent& component, xout.EndElement(); // pkg-ref } +void cmCPackPKGGenerator::CreateDomains(cmXMLWriter& xout) +{ + std::string opt = "CPACK_PRODUCTBUILD_DOMAINS"; + if (cmIsOff(this->GetOption(opt))) { + return; + } + + xout.StartElement("domains"); + + // Product can be installed at the root of any volume by default + // unless specified + cmValue param = this->GetOption(cmStrCat(opt, "_ANYWHERE")); + xout.Attribute("enable_anywhere", + (param && cmIsOff(param)) ? "false" : "true"); + + // Product cannot be installed into the current user's home directory + // by default unless specified + param = this->GetOption(cmStrCat(opt, "_USER")); + xout.Attribute("enable_currentUserHome", + (param && cmIsOn(param)) ? "true" : "false"); + + // Product can be installed into the root directory by default + // unless specified + param = this->GetOption(cmStrCat(opt, "_ROOT")); + xout.Attribute("enable_localSystem", + (param && cmIsOff(param)) ? "false" : "true"); + + xout.EndElement(); +} + void cmCPackPKGGenerator::AddDependencyAttributes( const cmCPackComponent& component, std::set& visited, std::ostringstream& out) diff --git a/Source/CPack/cmCPackPKGGenerator.h b/Source/CPack/cmCPackPKGGenerator.h index 5d97d16..256b334 100644 --- a/Source/CPack/cmCPackPKGGenerator.h +++ b/Source/CPack/cmCPackPKGGenerator.h @@ -91,6 +91,10 @@ protected: void CreateBackground(const char* themeName, const char* metapackageFile, cm::string_view genName, cmXMLWriter& xout); + /// Create the "domains" XML element to indicate where the product can + /// be installed + void CreateDomains(cmXMLWriter& xout); + // The PostFlight component when creating a metapackage cmCPackComponent PostFlightComponent; }; -- cgit v0.12