(#10261) Detect x64 architecture on Windows
Previously, the hardwaremodel fact was using
RbConfig::CONFIG['host_cpu']
for Windows, but this returns i686 on a 64-bit OS, which is incorrect. And
this caused the architecture fact to be reported as i386, which is also
wrong.
This commit updates the hardwaremodel fact on Windows to return the
appropriate cpu model, e.g. x64, i686, etc. Based on that, the
architecture fact will either be x86 or x64, and can be used to install
architecture-specific packages, e.g. splunk-4.2.4-110225-x64-release.msi.
Josh Cooper
11 years ago
24 | 24 |
end
|
25 | 25 |
when /(i[3456]86|pentium)/
|
26 | 26 |
case Facter.value(:operatingsystem)
|
27 | |
when "Gentoo"
|
|
27 |
when "Gentoo", "windows"
|
28 | 28 |
"x86"
|
29 | 29 |
else
|
30 | 30 |
"i386"
|
27 | 27 |
Facter.add(:hardwaremodel) do
|
28 | 28 |
confine :operatingsystem => :windows
|
29 | 29 |
setcode do
|
30 | |
require 'rbconfig'
|
31 | |
RbConfig::CONFIG['host_cpu']
|
|
30 |
# http://source.winehq.org/source/include/winnt.h#L568
|
|
31 |
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa394373(v=vs.85).aspx
|
|
32 |
# http://msdn.microsoft.com/en-us/library/windows/desktop/windows.system.processorarchitecture.aspx
|
|
33 |
require 'facter/util/wmi'
|
|
34 |
model = ""
|
|
35 |
Facter::Util::WMI.execquery("select Architecture, Level from Win32_Processor").each do |cpu|
|
|
36 |
model =
|
|
37 |
case cpu.Architecture
|
|
38 |
when 11: 'neutral' # PROCESSOR_ARCHITECTURE_NEUTRAL
|
|
39 |
when 10: 'i686' # PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
|
|
40 |
when 9: 'x64' # PROCESSOR_ARCHITECTURE_AMD64
|
|
41 |
when 8: 'msil' # PROCESSOR_ARCHITECTURE_MSIL
|
|
42 |
when 7: 'alpha64' # PROCESSOR_ARCHITECTURE_ALPHA64
|
|
43 |
when 6: 'ia64' # PROCESSOR_ARCHITECTURE_IA64
|
|
44 |
when 5: 'arm' # PROCESSOR_ARCHITECTURE_ARM
|
|
45 |
when 4: 'shx' # PROCESSOR_ARCHITECTURE_SHX
|
|
46 |
when 3: 'powerpc' # PROCESSOR_ARCHITECTURE_PPC
|
|
47 |
when 2: 'alpha' # PROCESSOR_ARCHITECTURE_ALPHA
|
|
48 |
when 1: 'mips' # PROCESSOR_ARCHITECTURE_MIPS
|
|
49 |
when 0: "i#{cpu.Level}86" # PROCESSOR_ARCHITECTURE_INTEL
|
|
50 |
else 'unknown' # PROCESSOR_ARCHITECTURE_UNKNOWN
|
|
51 |
end
|
|
52 |
break
|
|
53 |
end
|
|
54 |
|
|
55 |
model
|
32 | 56 |
end
|
33 | 57 |
end
|
20 | 20 |
["Gentoo","i586"] => "x86",
|
21 | 21 |
["Gentoo","i686"] => "x86",
|
22 | 22 |
["Gentoo","pentium"] => "x86",
|
|
23 |
["windows","i386"] => "x86",
|
|
24 |
["windows","x64"] => "x64",
|
23 | 25 |
}
|
24 | 26 |
generic_archs = Hash.new
|
25 | 27 |
generic_archs = {
|
|
0 |
#!/usr/bin/env ruby
|
|
1 |
|
|
2 |
require 'spec_helper'
|
|
3 |
require 'facter'
|
|
4 |
|
|
5 |
describe "Hardwaremodel fact" do
|
|
6 |
it "should match uname -m by default" do
|
|
7 |
Facter.fact(:kernel).stubs(:value).returns("Darwin")
|
|
8 |
Facter::Util::Resolution.stubs(:exec).with("uname -m").returns("Inky")
|
|
9 |
|
|
10 |
Facter.fact(:hardwaremodel).value.should == "Inky"
|
|
11 |
end
|
|
12 |
|
|
13 |
describe "on Windows" do
|
|
14 |
require 'facter/util/wmi'
|
|
15 |
before :each do
|
|
16 |
Facter.fact(:kernel).stubs(:value).returns("windows")
|
|
17 |
end
|
|
18 |
|
|
19 |
it "should detect i686" do
|
|
20 |
cpu = mock('cpu', :Architecture => 0, :Level => 6)
|
|
21 |
Facter::Util::WMI.expects(:execquery).returns([cpu])
|
|
22 |
|
|
23 |
Facter.fact(:hardwaremodel).value.should == "i686"
|
|
24 |
end
|
|
25 |
|
|
26 |
it "should detect x64" do
|
|
27 |
cpu = mock('cpu', :Architecture => 9)
|
|
28 |
Facter::Util::WMI.expects(:execquery).returns([cpu])
|
|
29 |
|
|
30 |
Facter.fact(:hardwaremodel).value.should == "x64"
|
|
31 |
end
|
|
32 |
end
|
|
33 |
end
|