From 24e1615addc7321b7a267e8307e285b2b095e15e Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Fri, 4 Aug 2023 11:42:33 -0700 Subject: [PATCH] (PA-5701) Allow platform's name to be overridden The puppet-runtime repo needs to build agent-runtime-7.x and agent-runtime-main projects using different solaris 11 sparc platform definitions, one is cross-compiled, the other is not. It's not possible to have conditional logic in the platform definition, because the platform DSL is evaluated before the project DSL[1]. In addition, the platform definition's filename is used to name the build artifacts, for example note solaris-113 in: agent-runtime-main-202308020.2.g2ddb502.solaris-113-sparc.tar.gz However, this breaks vanagon projects that try to consume that tarball, like pxp-agent-vanagon and puppet-agent. Therefore, this modifies vanagon so that it's possible to override the platform name, version or architecture, different than the platform definition's filename, for example: # In configs/platforms/solaris-11-sparc.rb platform "solaris-11-sparc" do |plat| # used to build agent-runtime-7.x # In configs/platforms/solaris-11-native-sparc.rb platform("solaris-11-sparc", override_name: true) do |plat| # used to build agent-runtime-main This also eliminates needing to special case `os_version`[2]. This is backwards compatible for existing platform definitions. However, any platform definition that passes `override_name` must update their vanagon dependency. [1] https://github.com/puppetlabs/vanagon/blob/54d2a797cc95a84b4da48726a9a5b2943bfaf014/lib/vanagon/driver.rb#L34-L35 [2] https://github.com/puppetlabs/puppet-runtime/blob/2ddb50288e18d0f8f189a4b8ecda587cd7135643/configs/projects/_shared-agent-settings.rb#L127 --- CHANGELOG.md | 2 ++ lib/vanagon/platform/dsl.rb | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b55deb4e..7f5d4117 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](https://semver.org). This changelog adheres to [Keep a CHANGELOG](https://keepachangelog.com). ## [Unreleased] +### Added +- (PA-5701) Allow platform's name to be overridden ## [0.38.0] - release 2023-07-05 diff --git a/lib/vanagon/platform/dsl.rb b/lib/vanagon/platform/dsl.rb index 7c66b268..c1535830 100644 --- a/lib/vanagon/platform/dsl.rb +++ b/lib/vanagon/platform/dsl.rb @@ -18,17 +18,23 @@ class Platform class DSL # Constructor for the DSL object # - # @param name [String] name of the platform + # @param basename [String] name of the platform # @return [Vanagon::Platform::DSL] A DSL object to describe the {Vanagon::Platform} - def initialize(platform_name) - @name = platform_name + def initialize(basename) + # This name is based on the file: configs/platform/.rb + @name = basename end # Primary way of interacting with the DSL. Also a simple factory to get the right platform object. # - # @param name [String] name of the platform + # @param platform_name [String] name of the platform + # @param override_name [Boolean] whether the specified `platform_name` should override the basename # @param block [Proc] DSL definition of the platform to call - def platform(platform_name, &block) + def platform(platform_name, override_name: false, &block) + # The platform name is specified in the platform definition using the + # `platform` DSL method and may not match the platform's basename + @name = platform_name if override_name + @platform = case platform_name when /^aix-/ Vanagon::Platform::RPM::AIX.new(@name)