Skip to content

Commit

Permalink
Merge pull request #38 from djberg96/dragonfly
Browse files Browse the repository at this point in the history
Add Dragonfly support, remove Solaris
  • Loading branch information
djberg96 authored Jun 10, 2024
2 parents c39baff + e2d6343 commit b7091a3
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 180 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 1.1.0 - 9-Jun-2024
* Removed Solaris support.
* Added DragonflyBSD support.
* Fixed example task.
* Made some constants private in the generic Unix code that should
have been private.
* The architecture method on Linux will now interpret values 4, 5
and 15. If it's not any of those values it will return 'Unknown'.

## 1.0.6 - 12-Aug-2022
* The Sys::CPU.model method will now return "ARM" for machines using an
ARM-based processor instead of "Unknown".
Expand Down
3 changes: 0 additions & 3 deletions MANIFEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
* doc/bsd.txt
* doc/hpux.txt
* doc/linux.txt
* doc/sunos.txt
* doc/windows.txt
* examples/example_sys_cpu_freebsd.rb
* examples/example_sys_cpu_hpux.rb
* examples/example_sys_cpu_linux.rb
* examples/example_sys_cpu_sunos.rb
* examples/example_sys_cpu_windows.rb
* lib/sys/cpu.rb
* lib/sys/darwin/sys/cpu.rb
Expand All @@ -26,5 +24,4 @@
* spec/sys_cpu_bsd_spec.rb
* spec/sys_cpu_hpux_spec.rb
* spec/sys_cpu_linux_spec.rb
* spec/sys_cpu_sunos_spec.rb
* spec/sys_cpu_windows_spec.rb
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Linux
* Windows
* OSX
* DragonflyBSD

## Description
A Ruby interface for getting cpu information.
Expand Down Expand Up @@ -71,7 +72,7 @@ https://github.com/djberg96/sys-cpu
Apache-2.0

## Copyright
(C) 2003-2022 Daniel J. Berger, All Rights Reserved
(C) 2003-2024 Daniel J. Berger, All Rights Reserved

## Warranty
This package is provided "as is" and without any express or
Expand Down
14 changes: 5 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,19 @@ end
desc "Run the example program"
task :example => [:clean] do
case CONFIG['host_os']
when /bsd|darwin|osx/i
when /bsd|darwin|osx|dragonfly/i
file = "examples/example_sys_cpu_bsd.rb"
sh "ruby -Ilib/unix #{file}"
sh "ruby -Ilib #{file}"
when /hpux/i
file = "examples/example_sys_cpu_hpux.rb"
sh "ruby -Ilib/unix #{file}"
sh "ruby -Ilib #{file}"
when /linux/i
file = "examples/example_sys_cpu_linux.rb"
sh "ruby -Ilib/linux #{file}"
sh "ruby -Ilib #{file}"
when /windows|win32|cygwin|mingw|dos/i
file = "examples/example_sys_cpu_windows.rb"
sh "ruby -Ilib/windows #{file}"
when /sunos|solaris/i
file = "examples/example_sys_cpu_sunos.rb"
sh "ruby -Ilib/unix #{file}"
sh "ruby -Ilib #{file}"
end

end

RuboCop::RakeTask.new
Expand Down
56 changes: 0 additions & 56 deletions doc/sunos.txt

This file was deleted.

21 changes: 0 additions & 21 deletions examples/example_sys_cpu_sunos.rb

This file was deleted.

2 changes: 1 addition & 1 deletion install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
file = "lib/windows/sys/cpu.rb"
when /linux/i
file = "lib/linux/sys/cpu.rb"
when /sunos|solaris|hpux|freebsd/i
when /hpux|freebsd|dragonfly/i
STDERR.puts "Use 'extconf.rb/make/make site-install' for this platform"
exit
else
Expand Down
2 changes: 1 addition & 1 deletion lib/sys/cpu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Sys
# This class is reopened for each of the supported platforms/operating systems.
class CPU
# The version of the sys-cpu gem.
VERSION = '1.0.6'
VERSION = '1.1.0'

private_class_method :new
end
Expand Down
8 changes: 8 additions & 0 deletions lib/sys/linux/sys/cpu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,16 @@ def self.architecture
case CPU_ARRAY.first['cpu_family']
when '3'
'x86'
when '4'
'i486'
when '5'
'Pentium'
when '6'
'x86_64'
when '15'
'Netburst'
else
'Unknown'
end
end

Expand Down
15 changes: 13 additions & 2 deletions lib/sys/unix/sys/cpu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,41 @@ class Error < StandardError; end
HW_NCPU = 3 # Number of CPU's
HW_CPU_FREQ = 15 # CPU frequency

if RbConfig::CONFIG['host_os'] =~ /bsd/
private_constant :CTL_HW, :HW_MACHINE, :HW_MODEL, :HW_NCPU, :HW_CPU_FREQ

if RbConfig::CONFIG['host_os'] =~ /bsd|dragonfly/
HW_MACHINE_ARCH = 11 # Machine architecture
else
HW_MACHINE_ARCH = 12 # Machine architecture
end

private_constant :HW_MACHINE_ARCH

SI_MACHINE = 5
SI_ARCHITECTURE = 6
SC_NPROCESSORS_ONLN = 15

private_constant :SI_MACHINE, :SI_ARCHITECTURE, :SC_NPROCESSORS_ONLN

P_OFFLINE = 1
P_ONLINE = 2
P_FAULTED = 4
P_POWEROFF = 5
P_NOINTR = 6
P_SPARE = 7

private_constant :P_OFFLINE, :P_ONLINE, :P_FAULTED, :P_POWEROFF, :P_NOINTR, :P_SPARE

CPU_ARCH_ABI64 = 0x01000000
CPU_TYPE_X86 = 7
CPU_TYPE_X86_64 = (CPU_TYPE_X86 | CPU_ARCH_ABI64)
CPU_TYPE_SPARC = 14
CPU_TYPE_POWERPC = 18
CPU_TYPE_POWERPC64 = CPU_TYPE_POWERPC | CPU_ARCH_ABI64

private_constant :CPU_ARCH_ABI64, :CPU_TYPE_X86, :CPU_TYPE_X86_64
private_constant :CPU_TYPE_SPARC, :CPU_TYPE_POWERPC, :CPU_TYPE_POWERPC64

begin
attach_function(
:sysctl,
Expand Down Expand Up @@ -234,7 +245,7 @@ def self.freq

size.write_long(optr.size)

if RbConfig::CONFIG['host_os'] =~ /bsd/i
if RbConfig::CONFIG['host_os'] =~ /bsd|dragonfly/i
name = 'hw.clockrate'
else
name = 'hw.cpufrequency'
Expand Down
3 changes: 1 addition & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

RSpec.configure do |config|
config.include_context(Sys::CPU)
config.filter_run_excluding(:bsd) if RbConfig::CONFIG['host_os'] !~ /bsd|darwin|mach|osx/i
config.filter_run_excluding(:sunos) if RbConfig::CONFIG['host_os'] !~ /sunos|solaris/i
config.filter_run_excluding(:bsd) if RbConfig::CONFIG['host_os'] !~ /bsd|darwin|mach|osx|dragonfly/i
config.filter_run_excluding(:windows) if RbConfig::CONFIG['host_os'] !~ /mswin|win32|dos|mingw|cygwin/i
config.filter_run_excluding(:hpux) if RbConfig::CONFIG['host_os'] !~ /hpux/i
config.filter_run_excluding(:linux) if RbConfig::CONFIG['host_os'] !~ /linux/i
Expand Down
2 changes: 1 addition & 1 deletion spec/sys_cpu_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

RSpec.shared_examples Sys::CPU do
example 'version number is set to the expected value' do
expect(Sys::CPU::VERSION).to eq('1.0.6')
expect(Sys::CPU::VERSION).to eq('1.1.0')
end

example 'version number is frozen' do
Expand Down
82 changes: 0 additions & 82 deletions spec/sys_cpu_sunos_spec.rb

This file was deleted.

2 changes: 1 addition & 1 deletion sys-cpu.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require 'rubygems'

Gem::Specification.new do |spec|
spec.name = 'sys-cpu'
spec.version = '1.0.6'
spec.version = '1.1.0'
spec.author = 'Daniel J. Berger'
spec.email = '[email protected]'
spec.license = 'Apache-2.0'
Expand Down

0 comments on commit b7091a3

Please sign in to comment.