From f03acf84745bd02ab9c11846d70bee9dece89111 Mon Sep 17 00:00:00 2001 From: Aria Li Date: Wed, 17 Apr 2024 15:46:33 -0700 Subject: [PATCH 1/2] (PUP-12031) Consolidate gem depenendencies & metadata into puppet.gemspec This commit moves the puppet gem metadata from ext/project_yaml.data and .gemspec into puppet.gemspec. This change allows the puppet gem to be built using `gem build puppet.gemspec`. Additionally, for platform specific gems (e.g. puppet-universal-darwin.gem and puppet-x64-mingw32.gem), there is conditional logic in puppet.gemspec so platform specific dependecies such as ffi are appended when building those platform-specific gems. (cherry picked from commit 867ce9c01a9d8fc58f1cf84de1549aac4e28b61a) --- .gemspec | 81 ------------------- Gemfile | 7 +- ext/project_data.yaml | 46 +---------- puppet.gemspec | 45 +++++++++++ .../provider/user/directoryservice_spec.rb | 2 +- 5 files changed, 53 insertions(+), 128 deletions(-) delete mode 100644 .gemspec create mode 100644 puppet.gemspec diff --git a/.gemspec b/.gemspec deleted file mode 100644 index b00a037bfa6..00000000000 --- a/.gemspec +++ /dev/null @@ -1,81 +0,0 @@ -# -*- encoding: utf-8 -*- -# -# PLEASE NOTE -# This gemspec is not intended to be used for building the Puppet gem. This -# gemspec is intended for use with bundler when Puppet is a dependency of -# another project. For example, the stdlib project is able to integrate with -# the main branch of Puppet by using a Gemfile path of -# https://github.com/puppetlabs/puppet -# -# Please see the [packaging -# repository](https://github.com/puppetlabs/packaging) for information on how -# to build the Puppet gem package. - -Gem::Specification.new do |s| - s.name = "puppet" - version = "7.31.0" - mdata = version.match(/(\d+\.\d+\.\d+)/) - s.version = mdata ? mdata[1] : version - - s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") - s.required_ruby_version = Gem::Requirement.new(">= 2.5.0") - s.authors = ["Puppet Labs"] - s.date = "2012-08-17" - s.description = <<~EOF - Puppet, an automated administrative engine for your Linux, Unix, and Windows systems, performs administrative tasks - (such as adding users, installing packages, and updating server configurations) based on a centralized specification. - EOF - s.email = "puppet@puppetlabs.com" - s.executables = ["puppet"] - s.files = ["bin/puppet"] - s.license = "Apache-2.0" - s.homepage = "https://puppetlabs.com" - s.rdoc_options = ["--title", "Puppet - Configuration Management", "--main", "README", "--line-numbers"] - s.require_paths = ["lib"] - s.summary = "Puppet, an automated configuration management tool" - s.specification_version = 3 - s.add_runtime_dependency(%q, [">= 2.4.0", "< 5"]) - s.add_runtime_dependency(%q, [">= 3.2.1", "< 4"]) - s.add_runtime_dependency(%q, "~> 1.0") - s.add_runtime_dependency(%q, ">= 1.1", "< 3") - s.add_runtime_dependency(%q, "~> 2.1") - s.add_runtime_dependency(%q, "~> 1.13") - s.add_runtime_dependency(%q, "~> 1.0") - s.add_runtime_dependency(%q, "~> 1.0") - s.add_runtime_dependency(%q, "~> 1.0") - - # loads platform specific gems like ffi, win32 platform gems - # as additional runtime dependencies - gem_deps_path = File.join(File.dirname(__FILE__), 'ext', 'project_data.yaml') - - # inside of a Vanagon produced package, project_data.yaml does not exist - next unless File.exist?(gem_deps_path) - - # so only load these dependencies from a git clone / bundle install workflow - require 'yaml' - data = YAML.load_file(gem_deps_path) - bundle_platforms = data['bundle_platforms'] - x64_platform = Gem::Platform.local.cpu == 'x64' - data['gem_platform_dependencies'].each_pair do |gem_platform, info| - next if gem_platform == 'x86-mingw32' && x64_platform - next if gem_platform == 'x64-mingw32' && !x64_platform - if bundle_deps = info['gem_runtime_dependencies'] - bundle_platform = bundle_platforms[gem_platform] or raise "Missing bundle_platform" - if bundle_platform == "all" - bundle_deps.each_pair do |name, version| - s.add_runtime_dependency(name, version) - end - else - # important to use .to_s and not .os for the sake of Windows - # .cpu => x64 - # .os => mingw32 - # .to_s => x64-mingw32 - if Gem::Platform.local.to_s == gem_platform - bundle_deps.each_pair do |name, version| - s.add_runtime_dependency(name, version) - end - end - end - end - end -end diff --git a/Gemfile b/Gemfile index c4a68ac5426..f9db9c6b7fc 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,11 @@ def location_for(place, fake_version = nil) end end -# override .gemspec deps - may issue warning depending on Bundler version +# Make sure these gem requirements are in sync with the gempspec. Specifically, +# the runtime_dependencies in puppet.gemspec match the runtime dependencies here +# (like semantic_puppet and puppet-resource_api) + +# override .gemspec deps for facter & hiera - may issue warning depending on Bundler version gem "facter", *location_for(ENV['FACTER_LOCATION']) if ENV.has_key?('FACTER_LOCATION') gem "hiera", *location_for(ENV['HIERA_LOCATION']) if ENV.has_key?('HIERA_LOCATION') gem "semantic_puppet", *location_for(ENV['SEMANTIC_PUPPET_LOCATION'] || ["~> 1.0"]) @@ -32,6 +36,7 @@ group(:features) do # requires native ldap headers/libs # gem 'ruby-ldap', '~> 0.9', require: false, platforms: [:ruby] gem 'puppetserver-ca', '~> 2.0', require: false + gem 'CFPropertyList', '~> 2.2', require: false end group(:test) do diff --git a/ext/project_data.yaml b/ext/project_data.yaml index 15ddc6870a4..43e549795ab 100644 --- a/ext/project_data.yaml +++ b/ext/project_data.yaml @@ -1,54 +1,10 @@ --- project: 'puppet' -author: 'Puppet Labs' -email: 'info@puppetlabs.com' -homepage: 'https://github.com/puppetlabs/puppet' -summary: 'Puppet, an automated configuration management tool' -description: 'Puppet, an automated configuration management tool' -version_file: 'lib/puppet/version.rb' -# files and gem_files are space separated lists -files: '[A-Z]* install.rb bin lib conf man examples ext tasks locales' -# Make sure these gem requirements are in sync with the gemspec and Gemfile -gem_files: '[A-Z]* install.rb bin lib conf man examples ext tasks locales' -gem_test_files: -gem_executables: 'puppet' -gem_default_executables: 'puppet' -gem_license: 'Apache-2.0' -gem_forge_project: 'puppet' -gem_required_ruby_version: '>= 2.5.0' -gem_required_rubygems_version: '> 1.3.1' -gem_runtime_dependencies: - facter: ['> 2.0.1', '< 5'] - hiera: ['>= 3.2.1', '< 4'] - semantic_puppet: '~> 1.0' - fast_gettext: ['>= 1.1', '< 3'] - locale: '~> 2.1' - multi_json: '~> 1.10' - puppet-resource_api: '~>1.5' - concurrent-ruby: "~> 1.0" - deep_merge: '~> 1.0' - scanf: '~> 1.0' gem_rdoc_options: - --title - "Puppet - Configuration Management" - --main - README.md - --line-numbers -gem_platform_dependencies: - universal-darwin: - gem_runtime_dependencies: - CFPropertyList: '~> 2.2' - x86-mingw32: - gem_runtime_dependencies: - ffi: '1.15.5' - minitar: '~> 0.9' - x64-mingw32: - gem_runtime_dependencies: - ffi: '1.15.5' - minitar: '~> 0.9' -bundle_platforms: - universal-darwin: all - x86-mingw32: mingw - x64-mingw32: x64_mingw pre_tasks: - 'package:apple': 'cfpropertylist' + 'package:apple': 'cfpropertylist' \ No newline at end of file diff --git a/puppet.gemspec b/puppet.gemspec new file mode 100644 index 00000000000..aae9d7533c9 --- /dev/null +++ b/puppet.gemspec @@ -0,0 +1,45 @@ +Gem::Specification.new do |s| + s.name = "puppet" + version = "7.31.0" + mdata = version.match(/(\d+\.\d+\.\d+)/) + s.version = mdata ? mdata[1] : version + s.license = 'Apache-2.0' + + s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") + s.required_ruby_version = Gem::Requirement.new(">= 2.5.0") + s.authors = ["Puppet Labs"] + s.date = "2012-08-17" + s.description = <<~EOF + Puppet, an automated administrative engine for your Linux, Unix, and Windows systems, performs administrative tasks + (such as adding users, installing packages, and updating server configurations) based on a centralized specification. + EOF + s.email = "info@puppetlabs.com" + s.executables = ["puppet"] + s.files = Dir['[A-Z]*'] + Dir['install.rb'] + Dir['bin/*'] + Dir['lib/**/*'] + Dir['conf/*'] + Dir['man/**/*'] + Dir['tasks/*'] + Dir['locales/**/*'] + Dir['ext/**/*'] + Dir['examples/**/*'] + s.homepage = "https://github.com/puppetlabs/puppet" + s.rdoc_options = ["--title", "Puppet - Configuration Management", "--main", "README", "--line-numbers"] + s.require_paths = ["lib"] + s.summary = "Puppet, an automated configuration management tool" + s.specification_version = 4 + s.add_runtime_dependency(%q, ["> 2.0.1", "< 5"]) + s.add_runtime_dependency(%q, [">= 3.2.1", "< 4"]) + s.add_runtime_dependency(%q, "~> 1.0") + s.add_runtime_dependency(%q, ">= 1.1", "< 3") + s.add_runtime_dependency(%q, "~> 2.1") + s.add_runtime_dependency(%q, "~> 1.10") + s.add_runtime_dependency(%q, "~> 1.5") + s.add_runtime_dependency(%q, "~> 1.0") + s.add_runtime_dependency(%q, "~> 1.0") + s.add_runtime_dependency(%q, "~> 1.0") + + # For building platform specific puppet gems...the --platform flag is only supported in newer Ruby versions + platform = s.platform.to_s + if platform == 'universal-darwin' + s.add_runtime_dependency('CFPropertyList', '~> 2.2') + end + + if platform == 'x64-mingw32' || platform == 'x86-mingw32' + s.add_runtime_dependency('ffi', '1.15.5') + s.add_runtime_dependency('minitar', '~> 0.9') + end +end diff --git a/spec/unit/provider/user/directoryservice_spec.rb b/spec/unit/provider/user/directoryservice_spec.rb index 431a42a781a..d339a73bdd5 100644 --- a/spec/unit/provider/user/directoryservice_spec.rb +++ b/spec/unit/provider/user/directoryservice_spec.rb @@ -4,7 +4,7 @@ module Puppet::Util::Plist end -describe Puppet::Type.type(:user).provider(:directoryservice) do +describe Puppet::Type.type(:user).provider(:directoryservice), :if => Puppet.features.cfpropertylist? do let(:username) { 'nonexistent_user' } let(:user_path) { "/Users/#{username}" } let(:resource) do From 57ea40c03677126cafffc7cf44afaefc5c5c940b Mon Sep 17 00:00:00 2001 From: Aria Li Date: Mon, 22 Apr 2024 14:54:35 -0700 Subject: [PATCH 2/2] (PUP-12031) Add Rake task for building puppet gems This commit adds a Rake task, gem:build, that will build all puppet gems which includes the three platform specific puppet gems: x86-mingw32, x64-mingw32, and universal-darwin (cherry picked from commit e58bc11b60c6781deb5b172e674cac405d4b4d6d) --- Rakefile | 13 +++++++++++++ ext/project_data.yaml | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index b03184d7eee..806e1c04dfb 100644 --- a/Rakefile +++ b/Rakefile @@ -45,6 +45,19 @@ task :default do sh %{rake -T} end +namespace :pl_ci do + desc 'Build puppet gems' + task :gem_build do + stdout, stderr, status = Open3.capture3('gem build puppet.gemspec --platform x86-mingw32 && gem build puppet.gemspec --platform x64-mingw32 && gem build puppet.gemspec --platform universal-darwin && gem build puppet.gemspec') + if !status.exitstatus.zero? + puts "Error building facter.gemspec \n#{stdout} \n#{stderr}" + exit(1) + else + puts stdout + end + end +end + task :spec do ENV["LOG_SPEC_ORDER"] = "true" sh %{rspec #{ENV['TEST'] || ENV['TESTS'] || 'spec'}} diff --git a/ext/project_data.yaml b/ext/project_data.yaml index 43e549795ab..91adc895e4d 100644 --- a/ext/project_data.yaml +++ b/ext/project_data.yaml @@ -7,4 +7,4 @@ gem_rdoc_options: - README.md - --line-numbers pre_tasks: - 'package:apple': 'cfpropertylist' \ No newline at end of file + 'package:apple': 'cfpropertylist'