netlinx-compile 1.0.0 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +122 -0
  3. data/doc/NetLinx.html +130 -151
  4. data/doc/NetLinx/Compile.html +130 -148
  5. data/doc/NetLinx/Compile/Extension.html +128 -145
  6. data/doc/NetLinx/Compile/Extension/AXS.html +218 -154
  7. data/doc/NetLinx/Compile/ExtensionDiscovery.html +524 -321
  8. data/doc/NetLinx/Compile/ExtensionHandler.html +755 -396
  9. data/doc/NetLinx/Compile/Script.html +431 -282
  10. data/doc/NetLinx/Compiler.html +496 -285
  11. data/doc/NetLinx/CompilerResult.html +1250 -498
  12. data/doc/NetLinx/NoCompilerError.html +142 -155
  13. data/doc/NetLinx/Rake.html +115 -0
  14. data/doc/NetLinx/Rake/Compile.html +358 -0
  15. data/doc/NetLinx/SourceFile.html +702 -423
  16. data/doc/_index.html +234 -0
  17. data/doc/class_list.html +51 -0
  18. data/doc/css/common.css +1 -0
  19. data/doc/css/full_list.css +58 -0
  20. data/doc/css/style.css +496 -0
  21. data/doc/file.README.html +156 -0
  22. data/doc/file.license.html +70 -0
  23. data/doc/file_list.html +61 -0
  24. data/doc/frames.html +17 -0
  25. data/doc/index.html +156 -103
  26. data/doc/js/app.js +314 -0
  27. data/doc/js/full_list.js +216 -0
  28. data/doc/js/jquery.js +4 -18
  29. data/doc/method_list.html +339 -0
  30. data/doc/top-level-namespace.html +110 -0
  31. data/lib/netlinx-compile.rb +11 -1
  32. data/lib/netlinx/compile/extension_discovery.rb +4 -2
  33. data/lib/netlinx/compile/extension_handler.rb +23 -25
  34. data/lib/netlinx/compile/script.rb +4 -3
  35. data/lib/netlinx/compiler.rb +45 -21
  36. data/lib/netlinx/compiler_result.rb +16 -17
  37. data/lib/netlinx/rake/compile.rb +4 -0
  38. data/lib/netlinx/rake/compile/compile.rb +34 -0
  39. data/lib/netlinx/source_file.rb +20 -14
  40. data/lib/test/netlinx/compilable.rb +13 -48
  41. data/lib/test/netlinx/compile/discoverable.rb +3 -14
  42. data/lib/test/netlinx/compile/invokable.rb +3 -15
  43. data/license.txt +1 -1
  44. metadata +114 -74
  45. data/README.txt +0 -2
  46. data/doc/Test.html +0 -147
  47. data/doc/Test/NetLinx.html +0 -147
  48. data/doc/Test/NetLinx/Compilable.html +0 -148
  49. data/doc/Test/NetLinx/Compile.html +0 -146
  50. data/doc/Test/NetLinx/Compile/Discoverable.html +0 -148
  51. data/doc/Test/NetLinx/Compile/Invokable.html +0 -149
  52. data/doc/created.rid +0 -12
  53. data/doc/images/add.png +0 -0
  54. data/doc/images/arrow_up.png +0 -0
  55. data/doc/images/brick.png +0 -0
  56. data/doc/images/brick_link.png +0 -0
  57. data/doc/images/bug.png +0 -0
  58. data/doc/images/bullet_black.png +0 -0
  59. data/doc/images/bullet_toggle_minus.png +0 -0
  60. data/doc/images/bullet_toggle_plus.png +0 -0
  61. data/doc/images/date.png +0 -0
  62. data/doc/images/delete.png +0 -0
  63. data/doc/images/find.png +0 -0
  64. data/doc/images/loadingAnimation.gif +0 -0
  65. data/doc/images/macFFBgHack.png +0 -0
  66. data/doc/images/package.png +0 -0
  67. data/doc/images/page_green.png +0 -0
  68. data/doc/images/page_white_text.png +0 -0
  69. data/doc/images/page_white_width.png +0 -0
  70. data/doc/images/plugin.png +0 -0
  71. data/doc/images/ruby.png +0 -0
  72. data/doc/images/tag_blue.png +0 -0
  73. data/doc/images/tag_green.png +0 -0
  74. data/doc/images/transparent.png +0 -0
  75. data/doc/images/wrench.png +0 -0
  76. data/doc/images/wrench_orange.png +0 -0
  77. data/doc/images/zoom.png +0 -0
  78. data/doc/js/darkfish.js +0 -155
  79. data/doc/js/navigation.js +0 -142
  80. data/doc/js/search.js +0 -94
  81. data/doc/js/search_index.js +0 -1
  82. data/doc/js/searcher.js +0 -228
  83. data/doc/rdoc.css +0 -595
  84. data/doc/table_of_contents.html +0 -138
@@ -1 +1,11 @@
1
- require 'netlinx/compiler'
1
+ require 'netlinx/compiler'
2
+
3
+ # :nodoc:
4
+ module NetLinx
5
+ # :nodoc:
6
+ module Compile
7
+ # :nodoc:
8
+ module Extension
9
+ end
10
+ end
11
+ end
@@ -43,7 +43,7 @@ module NetLinx
43
43
  .select{|c| not c.nil?}
44
44
  end
45
45
 
46
- # Returns an array of workspace file extensions.
46
+ # @return [Array<String>] workspace file extensions.
47
47
  def workspace_extensions
48
48
  @handlers
49
49
  .select{|h| h.is_a_workspace?}
@@ -51,7 +51,9 @@ module NetLinx
51
51
  .flatten
52
52
  end
53
53
 
54
- # Get an ExtensionHandler for a given file or extension.
54
+ # @param filename [String] File or extension to find a
55
+ # {NetLinx::Compile::ExtensionHandler} for.
56
+ # @return [ExtensionHandler]
55
57
  def get_handler(filename)
56
58
  @handlers.select{|h| h.include? filename}.first
57
59
  end
@@ -15,30 +15,28 @@ module NetLinx
15
15
  # in this ExtensionHandler.
16
16
  attr_reader :handler_class
17
17
 
18
- # Parameters:
19
- # extensions: An array of file extensions (without the leading dot)
20
- # that this ExtensionHandler supports.
18
+ # @option kwargs [Array<String>] :extensions File extensions (without the
19
+ # leading dot) that this ExtensionHandler supports.
21
20
  #
22
- # usurps: Future.
23
- # Lets this ExtensionHandler take priority over other
24
- # ones. For example, most third-party handlers would
25
- # probably usurp the .apw NetLinx Studio workspace
26
- # extension.
21
+ # @option kwargs [Array<String>] :usurps Future.
22
+ # Lets this ExtensionHandler take priority over other ones. For example,
23
+ # most third-party handlers would probably usurp the .apw NetLinx Studio
24
+ # workspace extension.
27
25
  #
28
- # is_a_workspace: Set to true if this ExtensionHandler is for
29
- # compiling a workspace. False by default. This
30
- # parameter assists with smart compiling, as
31
- # ExtensionDiscovery can return all workspace_handlers.
26
+ # @option kwargs [Boolean] :is_a_workspace Set to true if this
27
+ # ExtensionHandler is for compiling a workspace. False by default. This
28
+ # parameter assists with smart compiling, as {ExtensionDiscovery} can
29
+ # return all workspace_handlers.
32
30
  #
33
- # handler_class: A reference to the class that should be instantiated
34
- # if this handler is selected. For example,
35
- # NetLinx::SourceFile is the class that handles files
36
- # with the .axs extension.
37
- def initialize(**kvargs)
38
- @extensions = kvargs.fetch :extensions, []
39
- @usurps = kvargs.fetch :usurps, []
40
- @is_a_workspace = kvargs.fetch :is_a_workspace, false
41
- @handler_class = kvargs.fetch :handler_class, nil
31
+ # @option kwargs [Extension] :handler_class A reference to the class that
32
+ # should be instantiated if this handler is selected. For example,
33
+ # {NetLinx::SourceFile} is the class that handles files with the .axs
34
+ # extension.
35
+ def initialize(**kwargs)
36
+ @extensions = kwargs.fetch :extensions, []
37
+ @usurps = kwargs.fetch :usurps, []
38
+ @is_a_workspace = kwargs.fetch :is_a_workspace, false
39
+ @handler_class = kwargs.fetch :handler_class, nil
42
40
  end
43
41
 
44
42
  # Alias to add a file extension.
@@ -46,8 +44,8 @@ module NetLinx
46
44
  @extensions << parse_extension(file_extension)
47
45
  end
48
46
 
49
- # Returns true if the ExtensionHandler handles a workspace file
50
- # (as opposed to a source code file).
47
+ # @return [Boolean] true if the {ExtensionHandler} handles a workspace file
48
+ # (as opposed to a source code file).
51
49
  #
52
50
  # Workspace files are significant because they contain information
53
51
  # about a project, connection settings for a master, and possibly
@@ -59,7 +57,7 @@ module NetLinx
59
57
  @is_a_workspace
60
58
  end
61
59
 
62
- # Returns true if this ExtensionHandler can handle the specified
60
+ # Returns true if this {ExtensionHandler} can handle the specified
63
61
  # file extension.
64
62
  def include?(file_extension)
65
63
  @extensions.include? parse_extension(file_extension)
@@ -69,7 +67,7 @@ module NetLinx
69
67
 
70
68
  # Parse a file extension from the given string.
71
69
  #
72
- # Examples:
70
+ # @example
73
71
  # apw
74
72
  # .apw
75
73
  # workspace.apw
@@ -10,9 +10,10 @@ module NetLinx
10
10
 
11
11
  class << self
12
12
  # Run the script.
13
- def run(**kvargs)
14
- # :argv is a convenience to override ARGV, like for testing.
15
- args = kvargs.fetch :argv, ARGV
13
+ # @option kwargs [Array<String>] :argv A convenience to override ARGV,
14
+ # like for testing.
15
+ def run(**kwargs)
16
+ args = kwargs.fetch :argv, ARGV
16
17
 
17
18
  # Command line options.
18
19
  @options = OpenStruct.new \
@@ -2,38 +2,54 @@ require 'netlinx/compiler_result'
2
2
 
3
3
  module NetLinx
4
4
  # Raised when the NetLinx compiler (nlrc.exe) cannot be found on the system.
5
- # See NetLinx::Compiler.
5
+ # @see NetLinx::Compiler
6
6
  class NoCompilerError < Exception; end
7
7
 
8
8
  # A wrapper class for the AMX NetLinx compiler executable (nlrc.exe).
9
9
  class Compiler
10
10
 
11
11
  # Checks for the AMX NetLinx compiler (third-party software, nlrc.exe) at the
12
- # default installation path. This can be overridden by specifying :compiler_path.
13
- def initialize(**kvargs)
14
- @compiler_exe = 'nlrc.exe'
12
+ # default installation path.
13
+ #
14
+ # @option kwargs [String] :compiler_exe ('nlrc.exe')
15
+ # @option kwargs [String] :compiler_path Recommend a directory to look for
16
+ # the compiler_exe.
17
+ # @option kwargs [String] :use_wine (false) Set to true to force `wine` at
18
+ # the front of the compiler command. This is automatic if nlrc.exe is
19
+ # installed at Wine's default Program Files path.
20
+ # @raise [NetLinx::NoCompilerError] Compiler not found.
21
+ def initialize(**kwargs)
22
+ @compiler_exe = kwargs.fetch :compiler_exe, 'nlrc.exe'
23
+ user_specified_path = kwargs.fetch :compiler_path, nil
24
+ @use_wine = kwargs.fetch :use_wine, false
15
25
 
16
- @compiler_path = kvargs.fetch :compiler_path,
17
- File.expand_path('C:\Program Files (x86)\Common Files\AMXShare\COM') # 64-bit O/S path
18
-
19
- # Check for NetLinx compiler at :compiler_path or the 64-bit O/S path.
20
- unless File.exists? File.expand_path('nlrc.exe', @compiler_path)
21
- # Compiler not found. Try 32-bit O/S path.
22
- @compiler_path = File.expand_path('C:\Program Files\Common Files\AMXShare\COM')
23
- unless File.exists? File.expand_path('nlrc.exe', @compiler_path)
24
- # ---------------------------------------------------------
25
- # TODO: Check if the compiler was added to the system path.
26
- # Execute system('nlrc').
27
- # ---------------------------------------------------------
28
-
29
- # Compiler not found.
30
- raise NetLinx::NoCompilerError, 'The NetLinx compiler (nlrc.exe) could not be found on the system.'
26
+ default_paths = [
27
+ user_specified_path,
28
+ 'C:\Program Files (x86)\Common Files\AMXShare\COM', # 64-bit O/S path
29
+ 'C:\Program Files\Common Files\AMXShare\COM', # 32-bit O/S path
30
+ '~/.wine/drive_c/Program Files/Common Files/AMXShare/COM', # Wine path
31
+ ].compact
32
+
33
+ # Check for NetLinx compiler.
34
+ default_paths.each do |path|
35
+ if File.exists? File.expand_path(@compiler_exe, path)
36
+ @compiler_path = path
37
+ break
31
38
  end
32
39
  end
40
+
41
+ # ---------------------------------------------------------
42
+ # TODO: Check if the compiler was added to the system path.
43
+ # Execute system(@compiler_exe).
44
+ # ---------------------------------------------------------
45
+
46
+ # Compiler not found.
47
+ raise NetLinx::NoCompilerError, "The NetLinx compiler (#{@compiler_exe}) could not be found on the system." \
48
+ unless @compiler_path
33
49
  end
34
50
 
35
51
  # Compile the specified object with the NetLinx compiler.
36
- # See Test::NetLinx::Compilable.
52
+ # @see Test::NetLinx::Compilable.
37
53
  def compile(compilable)
38
54
  compiler = File.expand_path @compiler_exe, @compiler_path
39
55
  result = []
@@ -50,7 +66,15 @@ module NetLinx
50
66
  compilable.compiler_library_paths.empty?
51
67
 
52
68
  # Run the NetLinx compiler.
53
- io = IO.popen "\"#{compiler}\" \"#{target_file}\" \"#{include_paths}\" \"#{module_paths}\" \"#{library_paths}\""
69
+ # Note: NLRC.exe v2.1 freaks out if empty arguments ("") are in the command.
70
+ cmd = ''
71
+ cmd += 'wine ' if @use_wine or compiler.include? '/.wine/'
72
+ cmd += "\"#{compiler}\" \"#{target_file}\""
73
+ cmd += " \"#{include_paths}\"" if include_paths
74
+ cmd += " \"#{module_paths}\"" if module_paths
75
+ cmd += " \"#{library_paths}\"" if library_paths
76
+
77
+ io = IO.popen cmd
54
78
  stream = io.read
55
79
  io.close
56
80
 
@@ -19,19 +19,18 @@ module NetLinx
19
19
  # See Compilable interface.
20
20
  attr_reader :compiler_library_paths
21
21
 
22
- # Args:
23
- # stream -- The raw stream of text returned by the compiler.
24
- # compiler_target_files -- See Compilable interface.
25
- # compiler_include_paths -- See Compilable interface.
26
- # compiler_module_paths -- See Compilable interface.
27
- # compiler_library_paths -- See Compilable interface.
28
- def initialize(**kvargs)
29
- @stream = kvargs.fetch :stream, ''
22
+ # @option kwargs [String] :stream The raw stream of text returned by the compiler.
23
+ # @option kwargs [Array<String>] :compiler_target_files See Compilable interface.
24
+ # @option kwargs [Array<String>] :compiler_include_paths See Compilable interface.
25
+ # @option kwargs [Array<String>] :compiler_module_paths See Compilable interface.
26
+ # @option kwargs [Array<String>] :compiler_library_paths See Compilable interface.
27
+ def initialize(**kwargs)
28
+ @stream = kwargs.fetch :stream, ''
30
29
 
31
- @compiler_target_files = kvargs.fetch :compiler_target_files, []
32
- @compiler_include_paths = kvargs.fetch :compiler_include_paths, []
33
- @compiler_module_paths = kvargs.fetch :compiler_module_paths, []
34
- @compiler_library_paths = kvargs.fetch :compiler_library_paths, []
30
+ @compiler_target_files = kwargs.fetch :compiler_target_files, []
31
+ @compiler_include_paths = kwargs.fetch :compiler_include_paths, []
32
+ @compiler_module_paths = kwargs.fetch :compiler_module_paths, []
33
+ @compiler_library_paths = kwargs.fetch :compiler_library_paths, []
35
34
 
36
35
  # Capture error and warning counts.
37
36
  @errors = nil
@@ -43,27 +42,27 @@ module NetLinx
43
42
  end
44
43
  end
45
44
 
46
- # Alias of #stream.
45
+ # Alias of {#stream}.
47
46
  def to_s
48
47
  @stream
49
48
  end
50
49
 
51
- # Returns the absolute path of the source code file that was compiled.
50
+ # @return [String] the absolute path of the source code file that was compiled.
52
51
  def target_file
53
52
  @compiler_target_files.first
54
53
  end
55
54
 
56
- # Compile was successful?
55
+ # @return [Boolean] true if compile was successful.
57
56
  def success?
58
57
  @errors == 0 && @warnings == 0
59
58
  end
60
59
 
61
- # An enumerable list of warnings.
60
+ # @return [Array<String>] a list of warnings.
62
61
  def warning_items
63
62
  @stream.scan(/(^WARNING: .*$)/).map {|i| i.first}
64
63
  end
65
64
 
66
- # An enumerable list of errors.
65
+ # @return [Array<String>] a list of errors.
67
66
  def error_items
68
67
  @stream.scan(/(^ERROR: .*$)/).map {|i| i.first}
69
68
  end
@@ -0,0 +1,4 @@
1
+
2
+ require_relative 'compile/compile'
3
+
4
+ NetLinx::Rake::Compile.new
@@ -0,0 +1,34 @@
1
+
2
+ require 'rake'
3
+ require 'rake/tasklib'
4
+
5
+ require 'netlinx/compile/script'
6
+
7
+ module NetLinx
8
+ module Rake
9
+
10
+ # Compile to deployable code from the source code files in the given workspace.
11
+ class Compile < ::Rake::TaskLib
12
+
13
+ attr_accessor :name
14
+
15
+ def initialize name = :compile
16
+ @name = name
17
+ yield self if block_given?
18
+
19
+ desc "Compile to deployable code from the source code files in the given workspace."
20
+
21
+ task(name) do
22
+ workspace = Dir.glob("*.apw").first
23
+
24
+ puts "\n\nLaunching NetLinx compiler...\n\n"
25
+ # TODO: Invoke compiler through API.
26
+ # Just call the netlinx-compile rake task in rake/erb.
27
+ system "netlinx-compile --smart -s \"#{workspace}\""
28
+ # NetLinx::Compile::Script.run argv: ['--smart', '-s', "\"#{workspace}\""]
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,21 +1,27 @@
1
1
  module NetLinx
2
+ # A NetLinx source code file.
3
+ # Typically .axs or .axi.
2
4
  class SourceFile
3
5
 
4
- # Parameters:
5
- # file: Name or path of the file to compile.
6
- # compiler_include_paths: Array of additional paths for the compiler to find include files.
7
- # compiler_module_paths: Array of additional paths for the compiler to find module files.
8
- # NOTE: SourceFile already searches the body of the source file to automatically determine
9
- # include and module paths.
10
- def initialize(**kvargs)
11
- @compiler_target_files = [ (kvargs.fetch :file, nil) ]
12
- @compiler_include_paths = kvargs.fetch :compiler_include_paths, []
13
- @compiler_module_paths = kvargs.fetch :compiler_module_paths, []
6
+ # NOTE: SourceFile searches the body of the source file to automatically
7
+ # determine include and module paths.
8
+ #
9
+ # @option kwargs [String] :file Name or path of the file to compile.
10
+ # @option kwargs [Array<String>] :compiler_include_paths Additional paths for the compiler to find include files.
11
+ # @option kwargs [Array<String>] :compiler_module_paths Additional paths for the compiler to find module files.
12
+ def initialize(**kwargs)
13
+ @compiler_target_files = [ kwargs.fetch(:file, nil) ]
14
+ @compiler_include_paths = kwargs.fetch :compiler_include_paths, []
15
+ @compiler_module_paths = kwargs.fetch :compiler_module_paths, []
14
16
 
15
17
  return unless @compiler_target_files.first
16
18
 
17
19
  source_code = File.open(@compiler_target_files.first).read
18
20
 
21
+ unless source_code.valid_encoding?
22
+ source_code.force_encoding Encoding::ASCII_8BIT
23
+ end
24
+
19
25
  # Scan file for additional include paths.
20
26
  includes = source_code.scan(/(?i)^\s*(?:\#include)\s+'([\w\-]+)'/)
21
27
 
@@ -47,22 +53,22 @@ module NetLinx
47
53
  @compiler_module_paths.uniq!
48
54
  end
49
55
 
50
- # See Test::NetLinx::Compilable interface.
56
+ # @see _ lib/test/netlinx/compilable.rb interface.
51
57
  def compiler_target_files
52
58
  @compiler_target_files
53
59
  end
54
60
 
55
- # See Test::NetLinx::Compilable interface.
61
+ # @see _ lib/test/netlinx/compilable.rb interface.
56
62
  def compiler_include_paths
57
63
  @compiler_include_paths
58
64
  end
59
65
 
60
- # See Test::NetLinx::Compilable interface.
66
+ # @see _ lib/test/netlinx/compilable.rb interface.
61
67
  def compiler_module_paths
62
68
  @compiler_module_paths
63
69
  end
64
70
 
65
- # See Test::NetLinx::Compilable interface.
71
+ # @see _ lib/test/netlinx/compilable.rb interface.
66
72
  def compiler_library_paths
67
73
  []
68
74
  end
@@ -1,48 +1,13 @@
1
- module Test
2
- module NetLinx
3
- # Interface tests for an object that can be compiled with NetLinx::Compiler.
4
- module Compilable
5
-
6
- # :nodoc:
7
- def test_responds_to_compiler_target_files
8
- assert_respond_to @object, :compiler_target_files
9
- end
10
-
11
- # :nodoc:
12
- def test_responds_to_compiler_include_paths
13
- assert_respond_to @object, :compiler_include_paths
14
- end
15
-
16
- # :nodoc:
17
- def test_responds_to_compiler_library_paths
18
- assert_respond_to @object, :compiler_library_paths
19
- end
20
-
21
- # :nodoc:
22
- def test_responds_to_compiler_module_paths
23
- assert_respond_to @object, :compiler_module_paths
24
- end
25
-
26
- # :nodoc:
27
- def test_compiler_target_files_is_an_array
28
- assert @object.compiler_target_files.is_a? Array
29
- end
30
-
31
- # :nodoc:
32
- def test_compiler_include_paths_is_an_array
33
- assert @object.compiler_include_paths.is_a? Array
34
- end
35
-
36
- # :nodoc:
37
- def test_compiler_library_paths_is_an_array
38
- assert @object.compiler_library_paths.is_a? Array
39
- end
40
-
41
- # :nodoc:
42
- def test_compiler_module_paths_is_an_array
43
- assert @object.compiler_module_paths.is_a? Array
44
- end
45
-
46
- end
47
- end
48
- end
1
+ shared_examples "compilable" do
2
+
3
+ it { should respond_to :compiler_target_files }
4
+ it { should respond_to :compiler_include_paths }
5
+ it { should respond_to :compiler_library_paths }
6
+ it { should respond_to :compiler_module_paths }
7
+
8
+ its(:compiler_target_files) { should be_an Array }
9
+ its(:compiler_include_paths) { should be_an Array }
10
+ its(:compiler_library_paths) { should be_an Array }
11
+ its(:compiler_module_paths) { should be_an Array }
12
+
13
+ end