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.
- checksums.yaml +5 -5
- data/README.md +122 -0
- data/doc/NetLinx.html +130 -151
- data/doc/NetLinx/Compile.html +130 -148
- data/doc/NetLinx/Compile/Extension.html +128 -145
- data/doc/NetLinx/Compile/Extension/AXS.html +218 -154
- data/doc/NetLinx/Compile/ExtensionDiscovery.html +524 -321
- data/doc/NetLinx/Compile/ExtensionHandler.html +755 -396
- data/doc/NetLinx/Compile/Script.html +431 -282
- data/doc/NetLinx/Compiler.html +496 -285
- data/doc/NetLinx/CompilerResult.html +1250 -498
- data/doc/NetLinx/NoCompilerError.html +142 -155
- data/doc/NetLinx/Rake.html +115 -0
- data/doc/NetLinx/Rake/Compile.html +358 -0
- data/doc/NetLinx/SourceFile.html +702 -423
- data/doc/_index.html +234 -0
- data/doc/class_list.html +51 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +496 -0
- data/doc/file.README.html +156 -0
- data/doc/file.license.html +70 -0
- data/doc/file_list.html +61 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +156 -103
- data/doc/js/app.js +314 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -18
- data/doc/method_list.html +339 -0
- data/doc/top-level-namespace.html +110 -0
- data/lib/netlinx-compile.rb +11 -1
- data/lib/netlinx/compile/extension_discovery.rb +4 -2
- data/lib/netlinx/compile/extension_handler.rb +23 -25
- data/lib/netlinx/compile/script.rb +4 -3
- data/lib/netlinx/compiler.rb +45 -21
- data/lib/netlinx/compiler_result.rb +16 -17
- data/lib/netlinx/rake/compile.rb +4 -0
- data/lib/netlinx/rake/compile/compile.rb +34 -0
- data/lib/netlinx/source_file.rb +20 -14
- data/lib/test/netlinx/compilable.rb +13 -48
- data/lib/test/netlinx/compile/discoverable.rb +3 -14
- data/lib/test/netlinx/compile/invokable.rb +3 -15
- data/license.txt +1 -1
- metadata +114 -74
- data/README.txt +0 -2
- data/doc/Test.html +0 -147
- data/doc/Test/NetLinx.html +0 -147
- data/doc/Test/NetLinx/Compilable.html +0 -148
- data/doc/Test/NetLinx/Compile.html +0 -146
- data/doc/Test/NetLinx/Compile/Discoverable.html +0 -148
- data/doc/Test/NetLinx/Compile/Invokable.html +0 -149
- data/doc/created.rid +0 -12
- data/doc/images/add.png +0 -0
- data/doc/images/arrow_up.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/js/darkfish.js +0 -155
- data/doc/js/navigation.js +0 -142
- data/doc/js/search.js +0 -94
- data/doc/js/search_index.js +0 -1
- data/doc/js/searcher.js +0 -228
- data/doc/rdoc.css +0 -595
- data/doc/table_of_contents.html +0 -138
data/lib/netlinx-compile.rb
CHANGED
@@ -43,7 +43,7 @@ module NetLinx
|
|
43
43
|
.select{|c| not c.nil?}
|
44
44
|
end
|
45
45
|
|
46
|
-
#
|
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
|
-
#
|
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
|
-
#
|
19
|
-
#
|
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
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
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
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
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
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
def initialize(**
|
38
|
-
@extensions =
|
39
|
-
@usurps =
|
40
|
-
@is_a_workspace =
|
41
|
-
@handler_class =
|
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
|
-
#
|
50
|
-
#
|
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
|
-
#
|
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
|
-
|
14
|
-
|
15
|
-
|
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 \
|
data/lib/netlinx/compiler.rb
CHANGED
@@ -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
|
-
#
|
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.
|
13
|
-
|
14
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
#
|
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
|
-
|
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
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
|
28
|
-
|
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 =
|
32
|
-
@compiler_include_paths =
|
33
|
-
@compiler_module_paths =
|
34
|
-
@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
|
-
#
|
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
|
-
#
|
55
|
+
# @return [Boolean] true if compile was successful.
|
57
56
|
def success?
|
58
57
|
@errors == 0 && @warnings == 0
|
59
58
|
end
|
60
59
|
|
61
|
-
#
|
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
|
-
#
|
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,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
|
data/lib/netlinx/source_file.rb
CHANGED
@@ -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
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
def initialize(**
|
11
|
-
@compiler_target_files = [
|
12
|
-
@compiler_include_paths =
|
13
|
-
@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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
71
|
+
# @see _ lib/test/netlinx/compilable.rb interface.
|
66
72
|
def compiler_library_paths
|
67
73
|
[]
|
68
74
|
end
|
@@ -1,48 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|