movewin 1.8 → 1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +8 -8
  2. data/ext/movewin/extconf.rb +95 -27
  3. data/lib/movewin.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTNkNjFiZmZlMzU5OGY3ZjBmZDhmNDVhODAwMWE4ZWUyOTY3MTY3Zg==
4
+ NWFkNzU4Yzc0MzdjNGJhMDhmOTIxMzdmNDVmNGZmMjI4MTQ2ODIxNA==
5
5
  data.tar.gz: !binary |-
6
- NjliNzQwMTIzYjE4ZGVlOTcwNzc2YjFiNzBmOGFhNjAxYTg5ZDc3OQ==
6
+ N2VmYjRiN2M5NzEyZWI3MzAzYTU5ZDExZjNkNjlkN2MwMTQ4NWRjZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjY3MmI1MjA3MWJlZjM5MDg5NzA0ZTEwOTYzZWUyYmM0NjBmZjNjY2Y4ZWVh
10
- MGFlMTUxNmMyN2I3YTM1ODNhODliMWRiMzY1Njc0ZjliZTE4M2NiNDVjZmVj
11
- NGQzODE0MDJlMDJhYTI0ZjE2NGM0ZGRiYTJkMzc3NzdjMjgyZjU=
9
+ OTMwZWRiNWUzNzYxMDUzNmQ3NjkwZmM1ZGRjYTcxZmU2ODU0ZjE1ODYwMDJj
10
+ ZDUwZjYyNDZkYzVlM2ZlZDM2MDI2N2I5NGYxYmI5MTg1Y2FlYmExNTcyMWE5
11
+ ZTZiZThlMzFhZWVkMjFjYzFkMDE1MWQ5NzczY2RhZWU5MDk4NTE=
12
12
  data.tar.gz: !binary |-
13
- YmM4OTc2YmZlZTY0MzcxZDAyNDEyODY5ZWJjYThlOWE3MjU5ZjIxMTA3ZmU3
14
- YzU4YWM4NjI1MTUwZmRjYzE0YzQ5MDY4OGVmZDc5Y2E4YThmYjMzYzQ1NTY5
15
- NjU5YjZiZmFjYTg3YzZjNjRmYmQ0ZGQ1MTIxNDE4MTYxYmYyNjg=
13
+ ZWEyY2IyMTgxOWNiNzE0NjQ0Njc3NWRlNjdjNDNiMGFhNDJjNjM2ZjFhMTY5
14
+ NjIyMjAwMzIwN2Y5N2YyMDUwMmUxOTQ4ZGIxNjJjMjA3NjVhYTc3MjU4MTVk
15
+ ZDExYmY0MTlkMTMyN2ZmZTUxMGUwOWViN2I5ZTEzNTJmY2YwYmE=
@@ -22,48 +22,116 @@ def yosemite_or_newer?
22
22
  Gem::Version.new(`sw_vers -productVersion`) >= Gem::Version.new('10.10')
23
23
  end
24
24
 
25
- # Return true if our compiler is GCC (not clang), as for RVM installed Ruby
25
+ # Return true if our compiler is GCC (not Clang), as for RVM installed Ruby
26
26
  def using_gcc?
27
- true # TODO: make this really work
27
+ # Match gcc, /usr/local/bin/gcc-4.2, etc. (Clang is "xcrun cc")
28
+ File.basename(RbConfig::MAKEFILE_CONFIG["CC"]).match(/\Agcc\b/)
28
29
  end
29
30
 
30
31
  # Building with GCC on Yosemite (OS X 10.10) results in an error
31
32
  # (https://github.com/andrewgho/movewin-ruby/issues/1).
32
33
  # Patch header file to work around this issue.
33
34
  def fix_dispatch_object_header!
34
- srcfile = find_header_file('dispatch/object.h')
35
- tmpfile = "#{File.dirname(__FILE__)}/dispatch/object.h.tmp.#{$$}"
36
- begin
37
- patched = false
38
- File.open(tmpfile, 'w') do |tmpfh|
39
- File.open(srcfile, 'r').each do |srcline|
40
- patched ||= srcline.sub!(
41
- /\Atypedef void \(\^dispatch_block_t\)\(void\);/,
42
- 'typedef void* dispatch_block_t;'
43
- )
44
- tmpfh.print(srcline)
35
+ $stdout.print 'Creating patched copy of dispatch/object.h... '
36
+ $stdout.flush
37
+ status = 'failed'
38
+ if (srcfile = find_header_file('dispatch/object.h'))
39
+ tmpfile = "#{File.dirname(__FILE__)}/dispatch/object.h.tmp.#{$$}"
40
+ begin
41
+ patched = false
42
+ File.open(tmpfile, 'w') do |tmpfh|
43
+ File.open(srcfile, 'r').each do |srcline|
44
+ patched ||= srcline.sub!(
45
+ /\Atypedef void \(\^dispatch_block_t\)\(void\);/,
46
+ 'typedef void* dispatch_block_t;'
47
+ )
48
+ tmpfh.print(srcline)
49
+ end
45
50
  end
46
- end
47
- if patched
48
- destfile = "#{File.dirname(__FILE__)}/dispatch/object.h"
49
- File.rename(tmpfile, destfile)
50
- if $CFLAGS.nil? || $CFLAGS.empty?
51
- $CFLAGS = "-I#{File.dirname(__FILE__)}"
51
+ if patched
52
+ destfile = "#{File.dirname(__FILE__)}/dispatch/object.h"
53
+ File.rename(tmpfile, destfile)
54
+ if $CFLAGS.nil? || $CFLAGS.empty?
55
+ $CFLAGS = "-I#{File.dirname(__FILE__)}"
56
+ else
57
+ $CFLAGS += " -I#{File.dirname(__FILE__)}"
58
+ end
59
+ set_constant! :CLEANINGS,
60
+ "DISTCLEANFILES += dispatch/object.h\n" + CLEANINGS
61
+ status = "patched #{destfile}"
52
62
  else
53
- $CFLAGS += " -I#{File.dirname(__FILE__)}"
63
+ status = 'skipped'
54
64
  end
55
- set_constant! :CLEANINGS,
56
- "DISTCLEANFILES += dispatch/object.h\n" + CLEANINGS
65
+ ensure
66
+ File.unlink(tmpfile) if File.exists?(tmpfile)
57
67
  end
58
- ensure
59
- File.unlink(tmpfile) if File.exists?(tmpfile)
68
+ else
69
+ status = 'header not found'
60
70
  end
71
+ $stdout.puts status
72
+ $stdout.flush
61
73
  end
62
74
 
63
- # Given an #include <foo/bar.h>, return actual filename /path/to/foo/bar.h
75
+ # Given an #include <dispatch/object.h>, return actual filename
76
+ # /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/dispatch/object.h
64
77
  def find_header_file(header)
65
- # TODO: really crawl through cpp include path to find this
66
- "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/#{header}"
78
+ filename = nil
79
+ header_include_paths.each do |path|
80
+ maybe_filename = "#{path}/#{header}"
81
+ if File.exists?(maybe_filename)
82
+ filename = maybe_filename
83
+ break
84
+ end
85
+ end
86
+ filename
87
+ end
88
+
89
+ # Return GCC header include path
90
+ # (http://stackoverflow.com/a/19839946, http://stackoverflow.com/a/19852298)
91
+ # gcc -Wp,-v -xc /dev/null -fsyntax-only 2>&1
92
+ def header_include_paths
93
+ cmd = RbConfig::MAKEFILE_CONFIG["CC"]
94
+ args = %w{-Wp,-v -xc /dev/null -fsyntax-only}
95
+ paths = []
96
+ reading_paths = false
97
+ run_command(cmd, *args) do |line|
98
+ line.chomp!
99
+ if reading_paths
100
+ if line == 'End of search list.'
101
+ reading_paths = false
102
+ elsif line.match(/\A /)
103
+ line.strip!
104
+ line.sub!(/\s+\(framework directory\)\Z/, '')
105
+ paths << line
106
+ end
107
+ elsif line == '#include <...> search starts here:'
108
+ reading_paths = true
109
+ end
110
+ end
111
+ paths
112
+ end
113
+
114
+ # Safely run a command with no shell escapes, pass output lines to callback
115
+ def run_command(cmd, *args)
116
+ raise ArgumentError.new('missing required cmd to run') if cmd.nil?
117
+ rd, wr = IO.pipe
118
+ if fork
119
+ wr.close
120
+ if block_given?
121
+ rd.each { |line| yield(line) }
122
+ else
123
+ rd.read
124
+ end
125
+ rd.close
126
+ Process.wait
127
+ else
128
+ rd.close
129
+ $stdout.reopen(wr)
130
+ $stderr.reopen(wr)
131
+ exec cmd, *args
132
+ raise "exec #{cmd} failed"
133
+ end
134
+ $? == 0 # return a bool indicating a successful exit
67
135
  end
68
136
 
69
137
  # Redefine constant without warning (http://stackoverflow.com/q/3375360)
data/lib/movewin.rb CHANGED
@@ -36,7 +36,7 @@
36
36
  require 'movewin/movewin_ext'
37
37
 
38
38
  module MoveWin
39
- VERSION = '1.8'
39
+ VERSION = '1.9'
40
40
 
41
41
  # Individual accessors for display size components
42
42
  def self.display_width; MoveWin.display_size[0]; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: movewin
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.8'
4
+ version: '1.9'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Ho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-01 00:00:00.000000000 Z
11
+ date: 2014-11-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: List and move OS X windows from Ruby via the OS X accessibility APIs.
14
14
  email: andrew@zeuscat.com