Skip to content

Commit d581988

Browse files
committed
Use run_mode for better platform independence
1 parent ba7ba72 commit d581988

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

lib/puppet/provider/package/puppet_gem.rb

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,7 @@
66

77
confine :true => Facter.value(:aio_agent_version)
88

9-
def self.windows_gemcmd
10-
puppet_dir = Puppet::Util.get_env('PUPPET_DIR')
11-
if puppet_dir
12-
File.join(Puppet::Util.get_env('PUPPET_DIR').to_s, 'bin', 'gem.bat')
13-
else
14-
File.join(Gem.default_bindir, 'gem.bat')
15-
end
16-
end
17-
18-
if Puppet::Util::Platform.windows?
19-
commands :gemcmd => windows_gemcmd
20-
else
21-
commands :gemcmd => "/opt/puppetlabs/puppet/bin/gem"
22-
end
9+
commands :gemcmd => Puppet.run_mode.gem_cmd
2310

2411
def uninstall
2512
super
@@ -28,7 +15,9 @@ def uninstall
2815
end
2916

3017
def self.execute_gem_command(command, command_options, custom_environment = {})
31-
custom_environment['PKG_CONFIG_PATH'] = '/opt/puppetlabs/puppet/lib/pkgconfig' unless Puppet::Util::Platform.windows?
18+
if (pkg_config_path = Puppet.run_mode.pkg_config_path)
19+
custom_environment['PKG_CONFIG_PATH'] = pkg_config_path
20+
end
3221
super(command, command_options, custom_environment)
3322
end
3423
end

lib/puppet/util/run_mode.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ def run_dir
8585
def log_dir
8686
which_dir("/var/log/puppetlabs/puppet", "~/.puppetlabs/var/log")
8787
end
88+
89+
def pkg_config_path
90+
'/opt/puppetlabs/puppet/lib/pkgconfig'
91+
end
92+
93+
def gem_cmd
94+
'/opt/puppetlabs/puppet/bin/gem'
95+
end
8896
end
8997

9098
class WindowsRunMode < RunMode
@@ -112,6 +120,19 @@ def log_dir
112120
which_dir(File.join(windows_common_base("puppet/var/log")), "~/.puppetlabs/var/log")
113121
end
114122

123+
def pkg_config_path
124+
nil
125+
end
126+
127+
def gem_cmd
128+
puppet_dir = Puppet::Util.get_env('PUPPET_DIR')
129+
if puppet_dir
130+
File.join(Puppet::Util.get_env('PUPPET_DIR').to_s, 'bin', 'gem.bat')
131+
else
132+
File.join(Gem.default_bindir, 'gem.bat')
133+
end
134+
end
135+
115136
private
116137

117138
def windows_common_base(*extra)

0 commit comments

Comments
 (0)