Skip to content

Commit

Permalink
(maint) fix gem building from source
Browse files Browse the repository at this point in the history
Using `gem build facter.gemspec` failed because
`pathname` was not loaded

Using `gem build agent/facter-ng.gemspec` failed
because the paths were not taking in consideration
that the build is relative to the `agent` folder.
  • Loading branch information
gimmyxd committed Jun 30, 2021
1 parent 52f51cf commit 48e7803
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 13 additions & 8 deletions agent/facter-ng.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'pathname'

lib = File.expand_path('../lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Expand All @@ -15,15 +17,18 @@ Gem::Specification.new do |spec|
spec.license = 'MIT'

# ruby 2.3 doesn't support `base` keyword arg
# we are building from `facter/agent` so we need to move
# one level up in the `facter` folder.
root_dir = Pathname.new(File.expand_path('..', __dir__))
dirs =
Dir[File.join(__dir__, 'bin/facter-ng')] +
Dir[File.join(__dir__, 'LICENSE')] +
Dir[File.join(__dir__, 'lib/**/*.rb')] +
Dir[File.join(__dir__, 'lib/**/*.json')] +
Dir[File.join(__dir__, 'lib/**/*.conf')] +
Dir[File.join(__dir__, 'agent/**/*')] +
Dir[File.join(__dir__, 'lib/**/*.erb')]
base = Pathname.new(__dir__)
Dir[File.join(root_dir, 'bin/facter-ng')] +
Dir[File.join(root_dir, 'LICENSE')] +
Dir[File.join(root_dir, 'lib/**/*.rb')] +
Dir[File.join(root_dir, 'lib/**/*.json')] +
Dir[File.join(root_dir, 'lib/**/*.conf')] +
Dir[File.join(root_dir, 'agent/**/*')] +
Dir[File.join(root_dir, 'lib/**/*.erb')]
base = Pathname.new(root_dir)
spec.files = dirs.map do |path|
Pathname.new(path).relative_path_from(base).to_path
end
Expand Down
2 changes: 2 additions & 0 deletions facter.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'pathname'

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Expand Down

0 comments on commit 48e7803

Please sign in to comment.