Skip to content

Commit 9ac65f4

Browse files
committed
refactor: move platform detection to Rake module
The Rake::Win32 module existed solely to answer one question: are we running on Windows? That single-method module was more ceremony than it was worth, and it meant platform detection was split across two places — Win32.windows? in win32.rb and Application#unix? in application.rb. Both methods now live together as Rake.windows? and Rake.unix? on the Rake module itself, which is the natural home for gem-level helpers. Application#windows? and Application#unix? are kept as thin delegators so nothing calling them through an application instance breaks.
1 parent 92193ac commit 9ac65f4

9 files changed

Lines changed: 39 additions & 33 deletions

lib/rake.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ module Rake; end
3333

3434
require_relative "rake/ext/string"
3535

36-
require_relative "rake/win32"
37-
3836
require_relative "rake/linked_list"
3937
require_relative "rake/cpu_counter"
4038
require_relative "rake/scope"

lib/rake/application.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
require_relative "thread_pool"
88
require_relative "thread_history_display"
99
require_relative "trace_output"
10-
require_relative "win32"
1110

1211
module Rake
1312

@@ -384,12 +383,11 @@ def dynamic_width_tput # :nodoc:
384383
end
385384

386385
def unix? # :nodoc:
387-
RbConfig::CONFIG["host_os"] =~
388-
/(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
386+
Rake.unix?
389387
end
390388

391389
def windows? # :nodoc:
392-
Win32.windows?
390+
Rake.windows?
393391
end
394392

395393
def truncate(string, width) # :nodoc:

lib/rake/rake_module.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ def application=(app)
1414
@application = app
1515
end
1616

17+
# True if running on a Windows system.
18+
def windows?
19+
RbConfig::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw|[Ww]indows)!
20+
end
21+
22+
# True if running on a Unix system.
23+
def unix?
24+
RbConfig::CONFIG["host_os"] =~
25+
/(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
26+
end
27+
1728
def suggested_thread_count # :nodoc:
1829
@cpu_count ||= Rake::CpuCounter.count
1930
@cpu_count + 4

lib/rake/win32.rb

Lines changed: 0 additions & 17 deletions
This file was deleted.

rake.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ Gem::Specification.new do |s|
9090
"lib/rake/thread_pool.rb",
9191
"lib/rake/trace_output.rb",
9292
"lib/rake/version.rb",
93-
"lib/rake/win32.rb",
9493
"rake.gemspec"
9594
]
9695
s.bindir = "exe"

test/test_rake.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ def test_original_dir_reports_current_dir
3838
assert_equal @tempdir, Rake.original_dir
3939
end
4040

41+
def test_platform_detection
42+
# ensure that Rake's platform detection logic
43+
# is mutually exclusive, and doesn't claim to
44+
# be both Windows and Unix at the same time
45+
assert ! (Rake.windows? && Rake.unix?)
46+
end
47+
4148
end

test/test_rake_application.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,16 @@ def test_terminal_columns
419419
end
420420
end
421421

422-
def test_windows
423-
assert ! (@app.windows? && @app.unix?)
422+
if Rake.unix?
423+
def test_unix_platform_detection
424+
assert @app.unix?
425+
end
426+
end
427+
428+
if Rake.windows?
429+
def test_windows_platform_detection
430+
assert @app.windows?
431+
end
424432
end
425433

426434
def test_loading_imports

test/test_rake_directory_task.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ def test_directory
2727
refute File.exist?("a/b/c")
2828
end
2929

30-
def test_directory_colon
31-
directory "a:b"
30+
if Rake.unix?
31+
def test_directory_colon
32+
directory "a:b"
3233

33-
assert_equal FileCreationTask, Task["a:b"].class
34-
end unless Rake::Win32.windows?
34+
assert_equal FileCreationTask, Task["a:b"].class
35+
end
36+
end
3537

36-
if Rake::Win32.windows?
38+
if Rake.windows?
3739
def test_directory_win32
3840
desc "WIN32 DESC"
3941
directory "c:/a/b/c"

test/test_rake_file_list.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ def test_string_ext
349349
assert_equal ".one", ".one".ext
350350
assert_equal ".", ".".ext("c")
351351
assert_equal "..", "..".ext("c")
352-
# These only need to work in windows
353-
if Rake::Win32.windows?
352+
# These only need to work on Windows
353+
if Rake.windows?
354354
assert_equal "one.x\\two.net", "one.x\\two.c".ext(".net")
355355
assert_equal "one.x\\two.net", "one.x\\two".ext(".net")
356356
end

0 commit comments

Comments
 (0)