wxruby3 0.9.5 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/INSTALL.md +440 -84
  3. data/README.md +40 -23
  4. data/ext/mkrf_conf_ext.rb +68 -0
  5. data/lib/wx/core/ext.rb +22 -3
  6. data/lib/wx/core/secret_store.rb +38 -0
  7. data/lib/wx/doc/extra/02_lifecycles.md +4 -4
  8. data/lib/wx/doc/extra/14_config.md +1 -1
  9. data/lib/wx/doc/secret_store.rb +55 -0
  10. data/lib/wx/version.rb +1 -1
  11. data/lib/wx/wxruby/base.rb +8 -8
  12. data/lib/wx/wxruby/cmd/check.rb +182 -0
  13. data/lib/wx/wxruby/cmd/sampler.rb +39 -29
  14. data/lib/wx/wxruby/cmd/setup.rb +125 -0
  15. data/lib/wx/wxruby/cmd/test.rb +56 -6
  16. data/rakelib/bin.rake +48 -0
  17. data/rakelib/bin.rb +62 -0
  18. data/rakelib/build.rb +11 -7
  19. data/rakelib/config.rake +3 -1
  20. data/rakelib/configure.rb +63 -35
  21. data/rakelib/doc.rake +3 -1
  22. data/rakelib/gem.rake +199 -0
  23. data/rakelib/gem.rb +334 -0
  24. data/rakelib/install.rb +5 -3
  25. data/rakelib/lib/config/{cygwin.rb → freebsd.rb} +1 -1
  26. data/rakelib/lib/config/linux.rb +26 -2
  27. data/rakelib/lib/config/macosx.rb +58 -11
  28. data/rakelib/lib/config/mingw.rb +134 -10
  29. data/rakelib/lib/config/pkgman/linux.rb +144 -0
  30. data/rakelib/lib/config/pkgman/macosx.rb +122 -0
  31. data/rakelib/lib/config/unixish.rb +47 -20
  32. data/rakelib/lib/config/{netbsd.rb → unknown.rb} +3 -2
  33. data/rakelib/lib/config.rb +301 -88
  34. data/rakelib/lib/core/package.rb +47 -49
  35. data/rakelib/lib/director/aui_manager.rb +1 -1
  36. data/rakelib/lib/director/dialog.rb +8 -0
  37. data/rakelib/lib/director/gdicommon.rb +1 -2
  38. data/rakelib/lib/director/grid_ctrl.rb +2 -2
  39. data/rakelib/lib/director/richtext_composite_object.rb +2 -4
  40. data/rakelib/lib/director/secret_store.rb +117 -0
  41. data/rakelib/lib/director/tree_event.rb +2 -2
  42. data/rakelib/lib/generate/doc/secret_store.yaml +55 -0
  43. data/rakelib/lib/generate/doc.rb +29 -14
  44. data/rakelib/lib/generate/interface.rb +4 -2
  45. data/rakelib/lib/specs/interfaces.rb +1 -0
  46. data/rakelib/lib/swig_runner.rb +11 -11
  47. data/rakelib/lib/typemap/common.rb +10 -0
  48. data/rakelib/prepost.rake +17 -5
  49. data/rakelib/yard/templates/default/fulldoc/html/css/wxruby3.css +18 -0
  50. data/rakelib/yard/templates/default/fulldoc/html/setup.rb +5 -5
  51. data/rakelib/yard/yard/relative_markdown_links.rb +7 -1
  52. data/samples/sampler/sample.rb +2 -0
  53. data/tests/lib/wxapp_runner.rb +1 -1
  54. data/tests/test_config.rb +7 -4
  55. data/tests/test_secret_store.rb +83 -0
  56. metadata +46 -23
  57. data/ext/mkrf_conf_srcgem.rb +0 -67
  58. data/rakelib/run.rake +0 -52
data/README.md CHANGED
@@ -96,11 +96,11 @@ of these products.
96
96
 
97
97
  Currently the following are fully supported:
98
98
 
99
- | Platform | Ruby version(s) | wxWidgets version(s) |
100
- |----------------------------------------------------------------------------|---------------------------------------------|----------------------|
101
- | Windows 10 (tested)<br>(most likely also Windows 11) | Ruby >= 2.5<br>(RubyInstaller MSYS2-DevKit) | wxWidgets >= 3.2 |
102
- | Linux (tested; any AMD-64 distribution)<br>(most likely also i686 and ARM) | Ruby >= 2.5 | wxWidgets >= 3.2 |
103
- | MacOS >= 10.10 using Cocoa (tested on AMD-64 and ARM64 M2 Chip) | Ruby >= 2.5 | wxWidgets >= 3.2 |
99
+ | Platform | Ruby version(s) | wxWidgets version(s) |
100
+ |------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------|----------------------|
101
+ | Windows 10 (tested)<br>(most likely also Windows 11) | Ruby >= 2.5<br>(RubyInstaller MSYS2-DevKit) | wxWidgets >= 3.2 |
102
+ | Linux (tested; all major AMD64 and ARM64 distributions: Ubuntu, Debian, Fedora, OpenSuSE and ArchLinux)<br>(most likely also i686) | Ruby >= 2.5 | wxWidgets >= 3.2 |
103
+ | MacOS >= 10.10 using Cocoa (tested on AMD64 and ARM64 M1/M2 Chip) | Ruby >= 2.5 (MacPorts, Homebrew, ruby-install, RVM) | wxWidgets >= 3.2 |
104
104
 
105
105
  Support for other platforms is not being actively developed at present,
106
106
  but patches are welcome. It is likely to be much simpler to get wxRuby
@@ -109,32 +109,49 @@ on legacy systems (eg Windows 98, Mac OS 9).
109
109
 
110
110
  ### How can I install wxRuby3?
111
111
 
112
- wxRuby3 is distributed as a Ruby gem on [RubyGems](https://rubygems.org).<br>
113
- Apart from a regular source-only version of the gem there is also a binary gem version for Windows 10 provided (for the
114
- latest stable Ruby version at the time of publishing) which includes an embedded wxWidgets installation (also latest
115
- stable version).
112
+ wxRuby3 is distributed as a Ruby gem on [RubyGems](https://rubygems.org). This gem can also be downloaded from the release
113
+ assets on [Github](https://github.com/mcorino/wxRuby3/releases).
116
114
 
117
- Installing the binary gem version on Windows requires no additional software to be installed except for a supported
118
- version of the Ruby interpreter.<br>
119
- To install the source-only gem the following software is required:
115
+ The wxRuby3 gem provides a **worry-free** installation procedure for all supported platforms.
120
116
 
121
- | Sofware | Notes |
122
- |-----------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
123
- | Ruby | A supported version of the Ruby interpreter needs to be installed. |
124
- | C++ compiler<br>(incl. dev tools like `make`) | On linux a recent version of the GNU C++ compiler (with c++-14 support) needs to be installed<br>On Windows the RubyInstaller MSYS2-Devkit needs to be installed<br>On MacOS XCode with commandline tools needs to be installed |
125
- | Git version control toolkit | |
126
- | SWIG >= 3.0.12 | On MacOS install with Homebrew |
127
- | Doxygen (>= 1.9.1) | On MacOS install with Homebrew |
128
- | wxWidgets >= 3.2 (*OPTIONAL*) | On Linux most distributions provide system installable (development) packages for wxWidgets providing a supported version.<br>Alternatively you can fairly easily install your own preferred version manually. |
117
+ Installing the gem requires no additional installation steps and/or additional software to be installed except for a
118
+ supported version of the Ruby interpreter. So the following command is all it takes to install:
129
119
 
130
- See the [INSTALL](INSTALL.md) document for more details.
120
+ ```shell
121
+ gem install wxruby3
122
+ ```
131
123
 
132
- In case the prerequisites above are met the (source-only or binary) gem can be installed executing the following command:
124
+ The wxRuby3 installation procedure will check the availability of a, prebuilt, binary package matching the platform
125
+ being installed on and if found will download and install that package resulting in a ready-to-run wxRuby3 installation.<br>
126
+ If no matching package is found the installation reverts to a source installation which will require an additional setup
127
+ step to finalize the wxRuby3 installation by executing the following command:
133
128
 
134
129
  ```shell
135
- gem install wxruby3
130
+ wxruby setup
136
131
  ```
137
132
 
133
+ This last command is a fully automated setup procedure provided by the wxRuby3 **CLI** installed with the gem. This
134
+ procedure (by default) will analyze your system and install (after asking your consent) any missing software
135
+ requirements and build the wxRuby3 extension libraries (including a embedded copy of wxWidgets if necessary). It may
136
+ take quite a while depending on your system but you can mostly sit back and relax.
137
+
138
+ > **NOTE**<br>
139
+ > A source based installation requires the availability of the Ruby development headers. User installed Rubies in most cases
140
+ > will already include those but (especially on Linux) system installed Rubies may require having an additional '-dev/-devel'
141
+ > package installed (although actually you may already have needed those to install the gems that the wxRuby3 gem depends
142
+ > on like the nokogiri gem).
143
+
144
+ The wxRuby3 CLI also provides a 'check' command with which the runtime status of the wxRuby3 installation can be checked
145
+ at any time. By default running `wxruby check` will display a message reporting the runtime and suggestions on finalizing
146
+ the installation if not finalized yet. No message is displayed if wxRuby3 is ready to run. Run `wxruby check -h` for
147
+ details concerning this command.
148
+
149
+ A selection of (prebuilt) binary packages is provided as release assets on [Github](https://github.com/mcorino/wxRuby3/releases).
150
+ See the [INSTALL](INSTALL.md#binary-packages) document for more details.
151
+
152
+ This install procedure can of course be tweaked and customized with commandline arguments.
153
+ See the [INSTALL](INSTALL.md) document for more details.
154
+
138
155
  ### Where can I ask a question, or report a bug?
139
156
 
140
157
  Use GitHUb Issues.
@@ -0,0 +1,68 @@
1
+ # Copyright (c) 2023 M.J.N. Corino, The Netherlands
2
+ #
3
+ # This software is released under the MIT license.
4
+
5
+ ###
6
+ # wxRuby3 extension configuration file for gems
7
+ ###
8
+
9
+ OPTIONS = {
10
+ }
11
+
12
+ until ARGV.empty?
13
+ switch = ARGV.shift
14
+ case switch
15
+ when /^prebuilt=(none|only)$/
16
+ OPTIONS[:prebuilt] = $1 == 'only'
17
+ when /^package=(.+)$/
18
+ OPTIONS[:package] = $1
19
+ when 'help'
20
+ puts <<~__INFO_TXT
21
+ wxRuby3 extension build script
22
+
23
+ Usage: gem install wxruby3 -- help OR gem install wxruby3 [-- options [...]]
24
+
25
+ options:
26
+
27
+ prebuilt=OPT Specifies to either require (OPT == 'only') or avoid (OPT == 'none') installing prebuilt
28
+ binary packages. If not specified installing a prebuilt package will be attempted reverting
29
+ to source install if none found.
30
+
31
+ package=URL Specifies the http(s) url or absolute path to the prebuilt binary package to install.
32
+ Implies 'prebuilt=only'.
33
+
34
+ help Show this message.
35
+ __INFO_TXT
36
+ puts
37
+ exit(1)
38
+ else
39
+ $stderr.puts "ERROR: Invalid option [#{switch}] for wxRuby3 extension build script."
40
+ exit(1)
41
+ end
42
+ end
43
+
44
+ task_args = ''
45
+ unless OPTIONS[:prebuilt].nil?
46
+ task_args << "'#{(OPTIONS[:prebuilt] ? '--prebuilt' : '--no-prebuilt')}'"
47
+ end
48
+ if OPTIONS[:package]
49
+ task_args << ', ' unless task_args.empty?
50
+ pkg = RUBY_PLATFORM =~ /mingw/ ? OPTIONS[:package].gsub('\\', '/') : OPTIONS[:package] # make sure the path is URI compatible
51
+ task_args << "'--package', " << "'#{pkg}'"
52
+ end
53
+
54
+ # generate new rakefile with appropriate default task (calls actual task in rakelib)
55
+ File.open('../Rakefile', 'w') do |f|
56
+ f.puts <<EOF__
57
+ ###
58
+ # wxRuby3 rake file
59
+ # Copyright (c) M.J.N. Corino, The Netherlands
60
+ ###
61
+
62
+ unless File.file?(File.join('lib', 'wx', 'wxruby_core.so'))
63
+ task :default do
64
+ Rake::Task['wxruby:gem:install'].invoke(#{task_args})
65
+ end
66
+ end
67
+ EOF__
68
+ end
data/lib/wx/core/ext.rb CHANGED
@@ -28,18 +28,37 @@ module Wx
28
28
  end
29
29
  end
30
30
 
31
+ class Value
32
+ def initialize(code, block)
33
+ @code = code
34
+ @block = block
35
+ end
36
+
37
+ def value
38
+ @block ? @block.call : Kernel.eval(@code || 'nil')
39
+ end
40
+
41
+ def to_s
42
+ @code || ''
43
+ end
44
+ end
45
+
31
46
  def delayed_constants
32
47
  @delayed_constants ||= ::Hash.new
33
48
  end
34
49
 
35
50
  public
36
51
 
37
- def add_delayed_constant(mod, sym, &block)
38
- delayed_constants[Key.new(mod,sym)] = block
52
+ def add_delayed_constant(mod, sym, code='', &block)
53
+ delayed_constants[Key.new(mod,sym)] = Value.new(code, block)
54
+ end
55
+
56
+ def delayed_constants_for(mod)
57
+ delayed_constants.select { |k,v| k.mod == mod }
39
58
  end
40
59
 
41
60
  def load_delayed_constants
42
- delayed_constants.each_pair { |key, blk| key.mod.const_set(key.sym, blk.call) }
61
+ delayed_constants.each_pair { |key, val| key.mod.const_set(key.sym, val.value) }
43
62
  delayed_constants.clear # cleanup
44
63
  end
45
64
 
@@ -0,0 +1,38 @@
1
+ # Copyright (c) 2023 M.J.N. Corino, The Netherlands
2
+ #
3
+ # This software is released under the MIT license.
4
+
5
+ module Wx
6
+
7
+ class SecretStore
8
+
9
+ # Wipes the secret data.
10
+ def self.wipe(secret)
11
+ if ::String === secret
12
+ secret.bytesize.times { |i| secret.setbyte(i, 0) }
13
+ end
14
+ end
15
+
16
+ end
17
+
18
+ class SecretValue
19
+
20
+ # Redefine the initialize method to auto-convert UTF-16/-32 strings to UTF-8 if possible.
21
+ wx_init = self.instance_method(:initialize)
22
+ define_method(:initialize) do | *args |
23
+ if args.size == 1 && ::String === args.first
24
+ unless args.first.encoding == ::Encoding::UTF_8 || args.first.encoding == ::Encoding::ASCII_8BIT
25
+ # convert in place unless frozen
26
+ if !args.first.frozen?
27
+ args.first.encode!(::Encoding::UTF_8) rescue nil
28
+ else # create converted copy
29
+ (args = [args.first.encode(::Encoding::UTF_8)]) rescue nil
30
+ end
31
+ end
32
+ end
33
+ wx_init.bind(self).call(*args)
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -155,12 +155,12 @@ There are however quite a lot of wrapped native objects in wxRuby for which *obj
155
155
  object tracking has been disabled for their classes. This means these kind of classes/object should **not** be derived from
156
156
  (if even possible and/or useful) to add functionality/information or their identity used as key to link other information.<br>
157
157
  These classes include:
158
- * classes considered POD types like Wx::Size, Wx::Point, Wx::RealPoint, Wx::Rect, Wx::GBSpan, Wx::GBPosition, Wx::BusyInfoFlags,
158
+ - classes considered POD types like Wx::Size, Wx::Point, Wx::RealPoint, Wx::Rect, Wx::GBSpan, Wx::GBPosition, Wx::BusyInfoFlags,
159
159
  Wx::AboutDialogInfo
160
- * final non-instantiatable classes like the Wx::DC (Device Context) class family, Wx::GraphicsContext, Wx::WindowsDisabler,
160
+ - final non-instantiatable classes like the Wx::DC (Device Context) class family, Wx::GraphicsContext, Wx::WindowsDisabler,
161
161
  Wx::EventBlocker, Wx::BusyInfo
162
- * classes with native singleton objects like Wx::Clipboard
163
- * the reference counted GDI objects like Wx::Pen, Wx::Brush, Wx::Colour, Wx::Cursor, Wx::Bitmap, Wx::Icon and similar
162
+ - classes with native singleton objects like Wx::Clipboard
163
+ - the reference counted GDI objects like Wx::Pen, Wx::Brush, Wx::Colour, Wx::Cursor, Wx::Bitmap, Wx::Icon and similar
164
164
  reference counted objects like Wx::Font
165
165
 
166
166
  The reference documentation will note untracked object classes.
@@ -87,7 +87,7 @@ Another difference is that {Wx::Config} will not automatically create missing gr
87
87
  happen when writing configuration values.
88
88
 
89
89
  A last difference is that the default support is by default backed up by persistent storage (windows registry or file) and
90
- the wxRuby enhanced support only provides in-memory storage (`Hash` instance) by default. +
90
+ the wxRuby enhanced support only provides in-memory storage (`Hash` instance) by default.<br>
91
91
  Persisting configuration data from {Wx::Config} will require coding customized storage and retrieval operations (which is
92
92
  trivial using standard YAML or JSON support).
93
93
 
@@ -0,0 +1,55 @@
1
+ # :stopdoc:
2
+ # Copyright (c) 2023 M.J.N. Corino, The Netherlands
3
+ #
4
+ # This software is released under the MIT license.
5
+ # :startdoc:
6
+
7
+
8
+ module Wx
9
+
10
+ class SecretStore
11
+
12
+ # Wipes the secret data.
13
+ # @param [String] secret string containing secret data
14
+ # @return [void]
15
+ def self.wipe(secret); end
16
+
17
+ end
18
+
19
+ class SecretValue
20
+
21
+ # @overload initialize()
22
+ # Creates an empty secret value (not the same as an empty password).
23
+ # @return [Wx::SecretValue]
24
+ # @overload initialize(secret)
25
+ # Creates a secret value from the given string.
26
+ # The secret argument may contain NUL bytes.
27
+ # Any UTF-8 encoded (or encodable; wxRuby will attempt re-encoding as UTF-8 for any string not encoded UTF-8 or ASCII-8BIT) string will be stored as UTF-8 encoded string.
28
+ # In these cases use {#get_as_string} if needing to compare the original string to a restored string.
29
+ # Otherwise the string will be stored as ASCII-8BIT encoded string.
30
+ # In these cases use {#get_data} if needing to compare the original string to a restored string.
31
+ # See {#==} for comparing secret values opaquely.
32
+ # @param secret [String]
33
+ # @return [Wx::SecretValue]
34
+ # @overload initialize(other)
35
+ # Creates a copy of an existing secret.
36
+ # @param other [Wx::SecretValue]
37
+ # @return [Wx::SecretValue]
38
+ def initialize(*args) end
39
+
40
+ # Returns a copy of the secret data as an ASCII-8BIT encoded String.
41
+ # Be aware this could be binary data and may contain embedded NUL characters.
42
+ # For more security {Wx::SecretStore.wipe} should be used to wipe the secret data after use.
43
+ # @return [String] secret data
44
+ def get_data; end
45
+
46
+ # Returns a copy of the secret data as an UTF-8 encoded String.
47
+ # Make sure to use this method only if sure that the secret originally stored was indeed
48
+ # UTF-8 data as otherwise the returned string will not match the stored data.
49
+ # For more security {Wx::SecretStore.wipe} should be used to wipe the secret data after use.
50
+ # @return [String] secret data
51
+ def get_as_string; end
52
+
53
+ end
54
+
55
+ end
data/lib/wx/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  # This software is released under the MIT license.
4
4
 
5
5
  module Wx
6
- WXRUBY_VERSION = '0.9.5'
6
+ WXRUBY_VERSION = '0.9.8'
7
7
  end
@@ -20,17 +20,20 @@ module WxRuby
20
20
  def commands
21
21
  @commands ||= ::Hash.new do |hash, key|
22
22
  STDERR.puts "Unknown command #{key} specified."
23
- exit(1)
23
+ exit(127)
24
24
  end
25
25
  end
26
26
  private :commands
27
27
 
28
+ def setup_done?
29
+ File.exist?(File.join(WxRuby::ROOT, 'ext', 'wxruby.setup.done'))
30
+ end
31
+
28
32
  def options
29
33
  @options ||= {
30
34
  :verbose => false
31
35
  }
32
36
  end
33
- private :options
34
37
 
35
38
  def register(cmdid, cmdhandler)
36
39
  commands[cmdid.to_s] = case
@@ -59,7 +62,7 @@ module WxRuby
59
62
  def parse_args(args)
60
63
  opts = OptionParser.new
61
64
  opts.banner = "Usage: wxruby [global options] COMMAND [arguments]\n\n" +
62
- " COMMAND\t\t\tSpecifies wxruby command to execute."
65
+ " COMMAND\t\t\t\tSpecifies wxruby command to execute."
63
66
  opts.separator ''
64
67
  opts.on('-v', '--verbose',
65
68
  'Show verbose output') { |v| ::WxRuby::Commands.options[:verbose] = true }
@@ -70,8 +73,7 @@ module WxRuby
70
73
  describe_all
71
74
  exit(0)
72
75
  end
73
- opts.raise_unknown = false
74
- opts.parse!(args)
76
+ opts.order!(args) rescue ($stderr.puts $!.message; exit(127))
75
77
  end
76
78
  end
77
79
  end
@@ -79,9 +81,7 @@ module WxRuby
79
81
  def self.run(argv = ARGV)
80
82
  # parse global options (upto first command)
81
83
  argv = WxRuby::Commands.parse_args(argv)
82
- while !argv.empty?
83
- WxRuby::Commands.run(argv.shift, argv)
84
- end
84
+ WxRuby::Commands.run(argv.shift, argv) unless argv.empty?
85
85
  end
86
86
  end
87
87
 
@@ -0,0 +1,182 @@
1
+ # Copyright (c) 2023 M.J.N. Corino, The Netherlands
2
+ #
3
+ # This software is released under the MIT license.
4
+
5
+ # wxruby check command handler
6
+ #--------------------------------------------------------------------
7
+
8
+ require 'fileutils'
9
+ require 'plat4m'
10
+
11
+ module WxRuby
12
+ module Commands
13
+
14
+ class Check
15
+
16
+ LOAD_ERRORS = {
17
+ linux: /cannot\s+open\s+shared\s+object/i,
18
+ darwin: /library\s+not\s+loaded/i,
19
+ windows: /specified\s+module\s+could\s+not\s+be\s+found/i
20
+ }
21
+
22
+ DESC = 'Run wxRuby3 runtime readiness check.'
23
+
24
+ def self.description
25
+ " check -h|[options]\t\t\t#{DESC}"
26
+ end
27
+
28
+ def self.options
29
+ Commands.options['check'] ||= { verbose: Commands.options[:verbose] }
30
+ end
31
+
32
+ def self.parse_args(args)
33
+ opts = OptionParser.new
34
+ opts.banner = "#{DESC}\n\nUsage: wxruby check -h|--help OR wxruby check [options]\n\n" +
35
+ "Returns:\n"+
36
+ " 0 if wxRuby3 is ready to run\n"+
37
+ " 1 if wxRuby3 does not seem to be built yet\n"+
38
+ " 2 if wxRuby3 has problems loading extension libraries\n"+
39
+ " 3 if an unexpected Ruby error occurred\n\n"+
40
+ "Unless '-q|--quiet' has been specified a description of the possible problem cause will\n"+
41
+ "be shown on failure.\n\n"
42
+ opts.separator ''
43
+ opts.on('-q', '--quiet',
44
+ "Do not show problem analysis messages on failures.") do |v|
45
+ Check.options[:quiet] = true
46
+ Check.options[:verbose] = false
47
+ end
48
+ opts.on('-v', '--verbose',
49
+ 'Show verbose output') do |v|
50
+ Check.options[:verbose] = true
51
+ Check.options[:quiet] = false
52
+ end
53
+ opts.on('-h', '--help',
54
+ 'Show this message.') do |v|
55
+ puts opts
56
+ puts
57
+ exit(0)
58
+ end
59
+ opts.parse!(args) rescue ($stderr.puts $!.message; exit(127))
60
+ end
61
+
62
+ def self.show_error(msg)
63
+ $stderr.puts(msg) unless options[:quiet]
64
+ end
65
+
66
+ def self.show_log(msg)
67
+ $stdout.puts(msg) if options[:verbose]
68
+ end
69
+
70
+ def self.run(argv)
71
+ return description if argv == :describe
72
+
73
+ parse_args(argv)
74
+
75
+ show_log('Checking build (or binary package installation) completion...')
76
+ # check if the binary setup (packages or built) has been completed successfully
77
+ unless Commands.setup_done?
78
+ $stderr.puts <<~__INFO_TXT
79
+
80
+ wxRuby3 requires the post-install setup cmd to be run to build and finish installing
81
+ the required runtime binaries. Execute the command like:
82
+
83
+ $ wxruby setup
84
+
85
+ To see the available options for the command execute:
86
+
87
+ $ wxruby setup -h
88
+
89
+ __INFO_TXT
90
+ exit(1)
91
+ end
92
+
93
+ # check runtime
94
+ show_log('Attempting to load wxRuby3 libraries...')
95
+ sysinfo = Plat4m.current
96
+ begin
97
+ require 'wx'
98
+ rescue LoadError => ex
99
+ if ex.message =~ LOAD_ERRORS[sysinfo.os.id]
100
+ # error loading shared libraries
101
+ show_log("Captured LoadError: #{ex.message}")
102
+ # check if wxWidgets libs can be located
103
+ show_log('Checking wxWidgets availability...')
104
+ wx_found = if Dir[File.join(WxRuby::ROOT, 'ext', "*.#{RbConfig::CONFIG['SOEXT']}")].empty?
105
+ # no embedded wxWidgets -> if system installed than 'wx-config' should be in the path
106
+ if system("wx-config --version>#{sysinfo.dev_null} 2>&1")
107
+ true # system installed
108
+ else
109
+ # no system installed wxWidgets
110
+ # check the system dependent load paths if any wxWidgets libs can be found
111
+ case sysinfo.os.id
112
+ when :linux
113
+ (ENV['LD_LIBRARY_PATH']||'').split(':').any? { |p| !Dir[File.join(p, 'libwx_base*.so')].empty? }
114
+ when :darwin
115
+ (ENV['DYLD_LIBRARY_PATH']||'').split(':').any? { |p| !Dir[File.join(p, 'libwx_base*.dylib')].empty? }
116
+ when :windows
117
+ (ENV['PATH']||'').split(';').any? { |p| !Dir[File.join(p, 'wxbase*.dll')].empty? }
118
+ else
119
+ true # do not know how to search so assume wxWidgets found
120
+ end
121
+ end
122
+ else
123
+ true # embedded wxWidgets
124
+ end
125
+ if wx_found
126
+ show_log('wxWidgets found')
127
+ show_error <<~__INFO_TXT
128
+
129
+ The runtime environment of this system seems to be missing some required libraries for
130
+ executing wxRuby3 apps.
131
+ Please be aware wxRuby3 requires a properly configured GUI based system to function.
132
+ See the documentation for more information on the required runtime environment.
133
+
134
+ __INFO_TXT
135
+ else
136
+ show_log('NO wxWidgets found')
137
+ show_error <<~__INFO_TXT
138
+
139
+ It seems wxRuby3 is not able to load any of the required wxWidgets libraries it was built
140
+ for.
141
+ Please make sure these (shared) libraries are available in the appropriate search path
142
+ for this system.
143
+
144
+ __INFO_TXT
145
+ end
146
+ else
147
+ show_error <<~__INFO_TXT
148
+
149
+ There is an unexpected problem loading the wxRuby3 extension libraries.
150
+ Please check the problem report below for a probable cause analysis. If you have reason
151
+ to suspect a bug to be the cause of this problem please file an issue at Github and attach
152
+ the problem report.
153
+
154
+ #{ex.message}
155
+ #{ex.backtrace.join("\n")}
156
+
157
+ __INFO_TXT
158
+ end
159
+ exit(2)
160
+ rescue Exception => ex
161
+ show_log("Captured Exception: #{ex.message}")
162
+ show_error <<~__INFO_TXT
163
+
164
+ There is an unexpected problem loading the wxRuby3 libraries.
165
+ Please check the problem report below for a probable cause analysis. If you have reason
166
+ to suspect a bug to be the cause of this problem please file an issue at Github and attach
167
+ the problem report.
168
+
169
+ #{ex.message}
170
+ #{ex.backtrace.join("\n")}
171
+
172
+ __INFO_TXT
173
+ exit(3)
174
+ end
175
+ end
176
+
177
+ end
178
+
179
+ self.register('check', Check)
180
+
181
+ end
182
+ end
@@ -10,44 +10,54 @@ require 'fileutils'
10
10
  module WxRuby
11
11
  module Commands
12
12
  class Sampler
13
- OPTIONS = {
14
- save_path: nil
15
- }
13
+
14
+ DESC = 'Run wxRuby3 Sampler application (or copy samples).'
16
15
 
17
16
  def self.description
18
- " sampler [help]|[copy DEST]\tRun wxRuby3 Sampler application (or copy samples)."
17
+ " sampler -h|[options]\t\t#{DESC}"
18
+ end
19
+
20
+ def self.options
21
+ Commands.options['sampler'] ||= { verbose: Commands.options[:verbose] }
22
+ end
23
+
24
+ def self.parse_args(args)
25
+ opts = OptionParser.new
26
+ opts.banner = "#{DESC}\n\nUsage: wxruby sampler -h|--help OR wxruby sampler [options]\n\n" +
27
+ "Runs the sampler application if no options specified.\n\n"
28
+ opts.separator ''
29
+ opts.on('--copy=DEST',
30
+ 'Copies the included wxRuby sample folders under the directory indicated by DEST (MUST exist)') {|v| Sampler.options[:copy] << v }
31
+ opts.on('-h', '--help',
32
+ 'Show this message.') do |v|
33
+ puts opts
34
+ puts
35
+ exit(0)
36
+ end
37
+ opts.parse!(args) rescue ($stderr.puts $!.message; exit(127))
19
38
  end
20
39
 
21
40
  def self.run(argv)
22
- if argv == :describe
23
- description
24
- else
25
- if argv.empty?
26
- exec(RUBY, File.join(WxRuby::ROOT, 'samples', 'sampler.rb'))
27
- else
28
- arg = argv.shift
29
- if arg == 'help'
30
- puts 'Usage: wxruby [global options] sampler [help]|[copy DEST]'
31
- puts
32
- puts ' Starts the sampler application if called without arguments.'
33
- puts ' Otherwise shows this help for argument "help" or copies the included wxRuby'
34
- puts ' sample folders under the directory indicated by DEST for argument "copy DEST".'
35
- puts ' The directory indicated by DEST *must* already exist.'
36
- puts
37
- elsif arg == 'copy'
38
- unless File.directory?(dest = argv.shift)
39
- STDERR.puts "ERROR: Invalid destination folder #{dest}"
40
- exit(1)
41
- end
42
- Dir[File.join(WxRuby::ROOT, 'samples', '*')].each do |fp|
43
- FileUtils.cp_r(fp, dest, verbose: true)
44
- end
45
- end
41
+ return description if argv == :describe
42
+
43
+ parse_args(argv)
44
+
45
+ if options[:copy]
46
+ unless File.directory?(dest = options[:copy])
47
+ $stderr.puts "ERROR: Invalid destination folder #{dest}"
48
+ exit(1)
46
49
  end
50
+ Dir[File.join(WxRuby::ROOT, 'samples', '*')].each do |fp|
51
+ FileUtils.cp_r(fp, dest, verbose: true)
52
+ end
53
+ else
54
+ exec(RUBY, File.join(WxRuby::ROOT, 'samples', 'sampler.rb'))
47
55
  end
48
56
  end
49
57
  end
50
58
 
51
- self.register('sampler', Sampler)
59
+ if self.setup_done?
60
+ self.register('sampler', Sampler)
61
+ end
52
62
  end
53
63
  end