Skip to content

Commit df10590

Browse files
committed
(PUP-11655) Use run_mode for better platform independence
1 parent 2377fad commit df10590

File tree

3 files changed

+52
-34
lines changed

3 files changed

+52
-34
lines changed

lib/puppet/defaults.rb

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,15 @@ def self.default_cadir
4949
end
5050

5151
def self.default_basemodulepath
52-
if Puppet::Util::Platform.windows?
53-
path = ['$codedir/modules']
54-
installdir = ENV["FACTER_env_windows_installdir"]
55-
if installdir
56-
path << "#{installdir}/puppet/modules"
57-
end
58-
path.join(File::PATH_SEPARATOR)
59-
else
60-
'$codedir/modules:/opt/puppetlabs/puppet/modules'
52+
path = ['$codedir/modules']
53+
if (run_mode_dir = Puppet.run_mode.common_module_dir)
54+
path << run_mode_dir
6155
end
56+
path.join(File::PATH_SEPARATOR)
6257
end
6358

6459
def self.default_vendormoduledir
65-
if Puppet::Util::Platform.windows?
66-
installdir = ENV["FACTER_env_windows_installdir"]
67-
if installdir
68-
"#{installdir}\\puppet\\vendor_modules"
69-
else
70-
nil
71-
end
72-
else
73-
'/opt/puppetlabs/puppet/vendor_modules'
74-
end
60+
Puppet.run_mode.vendor_module_dir
7561
end
7662

7763
############################################################################################

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 => Puppet.runtime[: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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ 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
96+
97+
def common_module_dir
98+
'/opt/puppetlabs/puppet/modules'
99+
end
100+
101+
def vendor_module_dir
102+
'/opt/puppetlabs/puppet/vendor_modules'
103+
end
88104
end
89105

90106
class WindowsRunMode < RunMode
@@ -112,8 +128,35 @@ def log_dir
112128
which_dir(File.join(windows_common_base("puppet/var/log")), "~/.puppetlabs/var/log")
113129
end
114130

131+
def pkg_config_path
132+
nil
133+
end
134+
135+
def gem_cmd
136+
puppet_dir = Puppet::Util.get_env('PUPPET_DIR')
137+
if puppet_dir
138+
File.join(puppet_dir.to_s, 'bin', 'gem.bat')
139+
else
140+
File.join(Gem.default_bindir, 'gem.bat')
141+
end
142+
end
143+
144+
def common_module_dir
145+
# TODO: use File.join?
146+
"#{installdir}/puppet/modules" if installdir
147+
end
148+
149+
def vendor_module_dir
150+
# TODO: use File.join?
151+
"#{installdir}\\puppet\\vendor_modules" if installdir
152+
end
153+
115154
private
116155

156+
def installdir
157+
ENV["FACTER_env_windows_installdir"]
158+
end
159+
117160
def windows_common_base(*extra)
118161
[ENV['ALLUSERSPROFILE'], "PuppetLabs"] + extra
119162
end

0 commit comments

Comments
 (0)