netlinx-compile 1.0.0
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.
- checksums.yaml +7 -0
- data/README.txt +2 -0
- data/bin/netlinx-compile +4 -0
- data/doc/NetLinx.html +151 -0
- data/doc/NetLinx/Compile.html +148 -0
- data/doc/NetLinx/Compile/Extension.html +145 -0
- data/doc/NetLinx/Compile/Extension/AXS.html +154 -0
- data/doc/NetLinx/Compile/ExtensionDiscovery.html +324 -0
- data/doc/NetLinx/Compile/ExtensionHandler.html +396 -0
- data/doc/NetLinx/Compile/Script.html +293 -0
- data/doc/NetLinx/Compiler.html +295 -0
- data/doc/NetLinx/CompilerResult.html +501 -0
- data/doc/NetLinx/NoCompilerError.html +155 -0
- data/doc/NetLinx/SourceFile.html +430 -0
- data/doc/Test.html +147 -0
- data/doc/Test/NetLinx.html +147 -0
- data/doc/Test/NetLinx/Compilable.html +148 -0
- data/doc/Test/NetLinx/Compile.html +146 -0
- data/doc/Test/NetLinx/Compile/Discoverable.html +148 -0
- data/doc/Test/NetLinx/Compile/Invokable.html +149 -0
- data/doc/created.rid +12 -0
- 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/index.html +103 -0
- data/doc/js/darkfish.js +155 -0
- data/doc/js/jquery.js +18 -0
- data/doc/js/navigation.js +142 -0
- data/doc/js/search.js +94 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/searcher.js +228 -0
- data/doc/rdoc.css +595 -0
- data/doc/table_of_contents.html +138 -0
- data/lib/netlinx-compile.rb +1 -0
- data/lib/netlinx/compile/extension/axs.rb +18 -0
- data/lib/netlinx/compile/extension_discovery.rb +62 -0
- data/lib/netlinx/compile/extension_handler.rb +86 -0
- data/lib/netlinx/compile/script.rb +115 -0
- data/lib/netlinx/compiler.rb +71 -0
- data/lib/netlinx/compiler_result.rb +72 -0
- data/lib/netlinx/source_file.rb +78 -0
- data/lib/test/netlinx/compilable.rb +48 -0
- data/lib/test/netlinx/compile/discoverable.rb +14 -0
- data/lib/test/netlinx/compile/invokable.rb +15 -0
- data/license.txt +13 -0
- metadata +156 -0
@@ -0,0 +1,138 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
6
|
+
|
7
|
+
<title>Table of Contents - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
|
10
|
+
|
11
|
+
<script type="text/javascript">
|
12
|
+
var rdoc_rel_prefix = "./";
|
13
|
+
</script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
|
16
|
+
<script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
|
17
|
+
<script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
|
18
|
+
<script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
|
19
|
+
<script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
|
20
|
+
<script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
|
21
|
+
|
22
|
+
|
23
|
+
<body class="indexpage">
|
24
|
+
<h1>Table of Contents - RDoc Documentation</h1>
|
25
|
+
|
26
|
+
|
27
|
+
<h2 id="classes">Classes/Modules</h2>
|
28
|
+
<ul>
|
29
|
+
<li class="module">
|
30
|
+
<a href="NetLinx.html">NetLinx</a>
|
31
|
+
</li>
|
32
|
+
<li class="module">
|
33
|
+
<a href="NetLinx/Compile.html">NetLinx::Compile</a>
|
34
|
+
</li>
|
35
|
+
<li class="module">
|
36
|
+
<a href="NetLinx/Compile/Extension.html">NetLinx::Compile::Extension</a>
|
37
|
+
</li>
|
38
|
+
<li class="class">
|
39
|
+
<a href="NetLinx/Compile/Extension/AXS.html">NetLinx::Compile::Extension::AXS</a>
|
40
|
+
</li>
|
41
|
+
<li class="class">
|
42
|
+
<a href="NetLinx/Compile/ExtensionDiscovery.html">NetLinx::Compile::ExtensionDiscovery</a>
|
43
|
+
</li>
|
44
|
+
<li class="class">
|
45
|
+
<a href="NetLinx/Compile/ExtensionHandler.html">NetLinx::Compile::ExtensionHandler</a>
|
46
|
+
</li>
|
47
|
+
<li class="class">
|
48
|
+
<a href="NetLinx/Compile/Script.html">NetLinx::Compile::Script</a>
|
49
|
+
</li>
|
50
|
+
<li class="class">
|
51
|
+
<a href="NetLinx/Compiler.html">NetLinx::Compiler</a>
|
52
|
+
</li>
|
53
|
+
<li class="class">
|
54
|
+
<a href="NetLinx/CompilerResult.html">NetLinx::CompilerResult</a>
|
55
|
+
</li>
|
56
|
+
<li class="class">
|
57
|
+
<a href="NetLinx/NoCompilerError.html">NetLinx::NoCompilerError</a>
|
58
|
+
</li>
|
59
|
+
<li class="class">
|
60
|
+
<a href="NetLinx/SourceFile.html">NetLinx::SourceFile</a>
|
61
|
+
</li>
|
62
|
+
<li class="module">
|
63
|
+
<a href="Test.html">Test</a>
|
64
|
+
</li>
|
65
|
+
<li class="module">
|
66
|
+
<a href="Test/NetLinx.html">Test::NetLinx</a>
|
67
|
+
</li>
|
68
|
+
<li class="module">
|
69
|
+
<a href="Test/NetLinx/Compilable.html">Test::NetLinx::Compilable</a>
|
70
|
+
</li>
|
71
|
+
<li class="module">
|
72
|
+
<a href="Test/NetLinx/Compile.html">Test::NetLinx::Compile</a>
|
73
|
+
</li>
|
74
|
+
<li class="module">
|
75
|
+
<a href="Test/NetLinx/Compile/Discoverable.html">Test::NetLinx::Compile::Discoverable</a>
|
76
|
+
</li>
|
77
|
+
<li class="module">
|
78
|
+
<a href="Test/NetLinx/Compile/Invokable.html">Test::NetLinx::Compile::Invokable</a>
|
79
|
+
</li>
|
80
|
+
|
81
|
+
</ul>
|
82
|
+
|
83
|
+
<h2 id="methods">Methods</h2>
|
84
|
+
<ul>
|
85
|
+
|
86
|
+
<li class="method"><a href="NetLinx/Compile/ExtensionDiscovery.html#method-c-discover">::discover — NetLinx::Compile::ExtensionDiscovery</a>
|
87
|
+
|
88
|
+
<li class="method"><a href="NetLinx/Compile/ExtensionDiscovery.html#method-c-get_handler">::get_handler — NetLinx::Compile::ExtensionDiscovery</a>
|
89
|
+
|
90
|
+
<li class="method"><a href="NetLinx/Compiler.html#method-c-new">::new — NetLinx::Compiler</a>
|
91
|
+
|
92
|
+
<li class="method"><a href="NetLinx/Compile/ExtensionHandler.html#method-c-new">::new — NetLinx::Compile::ExtensionHandler</a>
|
93
|
+
|
94
|
+
<li class="method"><a href="NetLinx/CompilerResult.html#method-c-new">::new — NetLinx::CompilerResult</a>
|
95
|
+
|
96
|
+
<li class="method"><a href="NetLinx/SourceFile.html#method-c-new">::new — NetLinx::SourceFile</a>
|
97
|
+
|
98
|
+
<li class="method"><a href="NetLinx/Compile/Script.html#method-c-run">::run — NetLinx::Compile::Script</a>
|
99
|
+
|
100
|
+
<li class="method"><a href="NetLinx/Compile/ExtensionDiscovery.html#method-c-workspace_extensions">::workspace_extensions — NetLinx::Compile::ExtensionDiscovery</a>
|
101
|
+
|
102
|
+
<li class="method"><a href="NetLinx/Compile/ExtensionHandler.html#method-i-3C-3C">#<< — NetLinx::Compile::ExtensionHandler</a>
|
103
|
+
|
104
|
+
<li class="method"><a href="NetLinx/Compiler.html#method-i-compile">#compile — NetLinx::Compiler</a>
|
105
|
+
|
106
|
+
<li class="method"><a href="NetLinx/SourceFile.html#method-i-compile">#compile — NetLinx::SourceFile</a>
|
107
|
+
|
108
|
+
<li class="method"><a href="NetLinx/SourceFile.html#method-i-compiler_include_paths">#compiler_include_paths — NetLinx::SourceFile</a>
|
109
|
+
|
110
|
+
<li class="method"><a href="NetLinx/SourceFile.html#method-i-compiler_library_paths">#compiler_library_paths — NetLinx::SourceFile</a>
|
111
|
+
|
112
|
+
<li class="method"><a href="NetLinx/SourceFile.html#method-i-compiler_module_paths">#compiler_module_paths — NetLinx::SourceFile</a>
|
113
|
+
|
114
|
+
<li class="method"><a href="NetLinx/SourceFile.html#method-i-compiler_target_files">#compiler_target_files — NetLinx::SourceFile</a>
|
115
|
+
|
116
|
+
<li class="method"><a href="NetLinx/CompilerResult.html#method-i-error_items">#error_items — NetLinx::CompilerResult</a>
|
117
|
+
|
118
|
+
<li class="method"><a href="NetLinx/Compile/ExtensionHandler.html#method-i-include-3F">#include? — NetLinx::Compile::ExtensionHandler</a>
|
119
|
+
|
120
|
+
<li class="method"><a href="NetLinx/Compile/ExtensionHandler.html#method-i-is_a_workspace-3F">#is_a_workspace? — NetLinx::Compile::ExtensionHandler</a>
|
121
|
+
|
122
|
+
<li class="method"><a href="NetLinx/CompilerResult.html#method-i-success-3F">#success? — NetLinx::CompilerResult</a>
|
123
|
+
|
124
|
+
<li class="method"><a href="NetLinx/CompilerResult.html#method-i-target_file">#target_file — NetLinx::CompilerResult</a>
|
125
|
+
|
126
|
+
<li class="method"><a href="NetLinx/CompilerResult.html#method-i-to_s">#to_s — NetLinx::CompilerResult</a>
|
127
|
+
|
128
|
+
<li class="method"><a href="NetLinx/CompilerResult.html#method-i-warning_items">#warning_items — NetLinx::CompilerResult</a>
|
129
|
+
|
130
|
+
</ul>
|
131
|
+
|
132
|
+
|
133
|
+
<footer id="validator-badges">
|
134
|
+
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
135
|
+
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 4.0.1.
|
136
|
+
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
137
|
+
</footer>
|
138
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'netlinx/compiler'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'netlinx/compile/extension_handler'
|
2
|
+
require 'netlinx/source_file'
|
3
|
+
|
4
|
+
module NetLinx
|
5
|
+
module Compile
|
6
|
+
module Extension
|
7
|
+
# Instructs netlinx-compile on how to process .axs NetLinx source code files.
|
8
|
+
class AXS
|
9
|
+
# :nodoc:
|
10
|
+
def self.get_handler
|
11
|
+
handler = NetLinx::Compile::ExtensionHandler.new \
|
12
|
+
extensions: ['axs', 'axi'],
|
13
|
+
handler_class: NetLinx::SourceFile
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module NetLinx
|
2
|
+
module Compile
|
3
|
+
# Discovers and auto-requires add-on Ruby libraries for netlinx-compile.
|
4
|
+
class ExtensionDiscovery
|
5
|
+
private_class_method :new
|
6
|
+
|
7
|
+
class << self
|
8
|
+
# An array of ExtensionHandlers installed on the system.
|
9
|
+
# #discover must be run before this array is populated.
|
10
|
+
attr_accessor :handlers
|
11
|
+
|
12
|
+
@handlers = []
|
13
|
+
|
14
|
+
# Searches for gems with 'netlinx-compile' as a dependency.
|
15
|
+
# The 'lib/netlinx/compile/extension/*' path is checked for
|
16
|
+
# compiler extensions.
|
17
|
+
def discover
|
18
|
+
# Require extensions built into netlinx-compile.
|
19
|
+
nc_gem = Gem::Specification.find_by_name 'netlinx-compile'
|
20
|
+
nc_gem_path = File.expand_path 'lib/netlinx/compile/extension', nc_gem.gem_dir
|
21
|
+
nc_gem_files = Dir["#{nc_gem_path}/*.rb"]
|
22
|
+
nc_gem_files.each {|file| require file}
|
23
|
+
|
24
|
+
# Find gems with a dependency on 'netlinx-compile'.
|
25
|
+
gems = Gem::Specification.each
|
26
|
+
.select{|gem| gem.dependencies
|
27
|
+
.select{|dependency| dependency.name == 'netlinx-compile'}
|
28
|
+
.empty? == false
|
29
|
+
}
|
30
|
+
|
31
|
+
# Load any Ruby files in their lib/netlinx/compile/extension paths.
|
32
|
+
gems.each do |gem|
|
33
|
+
extension_path = File.expand_path 'lib/netlinx/compile/extension', gem.gem_dir
|
34
|
+
files = Dir["#{extension_path}/*.rb"]
|
35
|
+
files.each {|file| require file}
|
36
|
+
end
|
37
|
+
|
38
|
+
# Register ExtensionHandler objects.
|
39
|
+
@handlers = NetLinx::Compile::Extension.constants
|
40
|
+
.map{|c| NetLinx::Compile::Extension.const_get c}
|
41
|
+
.select{|c| c.is_a? Class}
|
42
|
+
.map{|c| c.get_handler if c.respond_to? :get_handler}
|
43
|
+
.select{|c| not c.nil?}
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns an array of workspace file extensions.
|
47
|
+
def workspace_extensions
|
48
|
+
@handlers
|
49
|
+
.select{|h| h.is_a_workspace?}
|
50
|
+
.map{|h| h.extensions}
|
51
|
+
.flatten
|
52
|
+
end
|
53
|
+
|
54
|
+
# Get an ExtensionHandler for a given file or extension.
|
55
|
+
def get_handler(filename)
|
56
|
+
@handlers.select{|h| h.include? filename}.first
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module NetLinx
|
2
|
+
module Compile
|
3
|
+
# Tells netlinx-compile which class handles the compiling
|
4
|
+
# of a set of file extensions.
|
5
|
+
class ExtensionHandler
|
6
|
+
# A list of file extensions that this ExtensionHandler handles.
|
7
|
+
attr_accessor :extensions
|
8
|
+
|
9
|
+
# A list of file extensions that this ExtensionHandler usurps.
|
10
|
+
# For example, third-party workspace extensions would
|
11
|
+
# probably usurp the .apw workspace extension.
|
12
|
+
attr_accessor :usurps
|
13
|
+
|
14
|
+
# The class to invoke to handle compiling a file extension specified
|
15
|
+
# in this ExtensionHandler.
|
16
|
+
attr_reader :handler_class
|
17
|
+
|
18
|
+
# Parameters:
|
19
|
+
# extensions: An array of file extensions (without the leading dot)
|
20
|
+
# that this ExtensionHandler supports.
|
21
|
+
#
|
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.
|
27
|
+
#
|
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.
|
32
|
+
#
|
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
|
42
|
+
end
|
43
|
+
|
44
|
+
# Alias to add a file extension.
|
45
|
+
def <<(file_extension)
|
46
|
+
@extensions << parse_extension(file_extension)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Returns true if the ExtensionHandler handles a workspace file
|
50
|
+
# (as opposed to a source code file).
|
51
|
+
#
|
52
|
+
# Workspace files are significant because they contain information
|
53
|
+
# about a project, connection settings for a master, and possibly
|
54
|
+
# multiple systems that need to be compiled. Therefore, when
|
55
|
+
# smart-compiling, workspaces need to be distinguished from source
|
56
|
+
# code files because discovering a workspace should be considered a
|
57
|
+
# better match than discovering a source code file.
|
58
|
+
def is_a_workspace?
|
59
|
+
@is_a_workspace
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns true if this ExtensionHandler can handle the specified
|
63
|
+
# file extension.
|
64
|
+
def include?(file_extension)
|
65
|
+
@extensions.include? parse_extension(file_extension)
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
# Parse a file extension from the given string.
|
71
|
+
#
|
72
|
+
# Examples:
|
73
|
+
# apw
|
74
|
+
# .apw
|
75
|
+
# workspace.apw
|
76
|
+
# c:/path/to/workspace.apw
|
77
|
+
def parse_extension(file_extension)
|
78
|
+
ext = file_extension.scan(/(?:^\s*|(?<=\.))(\w+)$/).first
|
79
|
+
raise ArgumentError, "Could not parse a file extension from the string: #{file_extension}" unless ext
|
80
|
+
|
81
|
+
ext.first
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'netlinx/compile/extension_discovery'
|
4
|
+
|
5
|
+
module NetLinx
|
6
|
+
module Compile
|
7
|
+
# The container for the script that runs when netlinx-compile is executed.
|
8
|
+
class Script
|
9
|
+
private_class_method :new
|
10
|
+
|
11
|
+
class << self
|
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
|
16
|
+
|
17
|
+
# Command line options.
|
18
|
+
@options = OpenStruct.new \
|
19
|
+
source: '',
|
20
|
+
include_paths: [],
|
21
|
+
use_workspace: false
|
22
|
+
|
23
|
+
OptionParser.new do |opts|
|
24
|
+
opts.banner = "Usage: netlinx-compile [options]"
|
25
|
+
|
26
|
+
opts.on '-h', '--help', 'Display this help screen.' do
|
27
|
+
puts opts
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on '-s', '--source FILE', 'Source file to compile.' do |v|
|
32
|
+
@options.source = v
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on '-i', '--include [Path1,Path2]', Array, 'Additional include and module paths.' do |v|
|
36
|
+
@options.include_paths = v
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on '-w', '--workspace', '--smart',
|
40
|
+
'Search up directory tree for a workspace',
|
41
|
+
'containing the source file.' do |v|
|
42
|
+
@options.use_workspace = v
|
43
|
+
end
|
44
|
+
|
45
|
+
end.parse! args
|
46
|
+
|
47
|
+
if @options.source.empty?
|
48
|
+
puts "No source file specified.\nRun \"netlinx-compile -h\" for help."
|
49
|
+
exit
|
50
|
+
end
|
51
|
+
|
52
|
+
# Find an ExtensionHandler for the given file.
|
53
|
+
ExtensionDiscovery.discover
|
54
|
+
source_file = File.expand_path @options.source
|
55
|
+
handler = NetLinx::Compile::ExtensionDiscovery.get_handler source_file
|
56
|
+
|
57
|
+
# If the handler is a workspace handler, go straight to compiling it.
|
58
|
+
# Otherwise, if the use_workspace flag is true, search up through the
|
59
|
+
# directory tree to try to find a workspace that includes the
|
60
|
+
# specified source file.
|
61
|
+
if (not handler.is_a_workspace?) && @options.use_workspace
|
62
|
+
workspace_extensions = NetLinx::Compile::ExtensionDiscovery.workspace_extensions
|
63
|
+
|
64
|
+
dir = File.expand_path '.'
|
65
|
+
while dir != File.expand_path('..', dir) do
|
66
|
+
workspaces = Dir["#{dir}/*.{#{workspace_extensions.join ','}}"]
|
67
|
+
|
68
|
+
unless workspaces.empty?
|
69
|
+
# TODO: Handle workspace file extension usurping logic here.
|
70
|
+
|
71
|
+
new_source_file = workspaces.first
|
72
|
+
new_handler = NetLinx::Compile::ExtensionDiscovery.get_handler new_source_file
|
73
|
+
new_handler_class = new_handler.handler_class.new \
|
74
|
+
file: File.expand_path(new_source_file)
|
75
|
+
|
76
|
+
# If supported by the new_handler, make sure the source_file is
|
77
|
+
# included in the workspace before overwriting the old handler.
|
78
|
+
overwrite_old_handler = false
|
79
|
+
|
80
|
+
if new_handler_class.respond_to? :include?
|
81
|
+
overwrite_old_handler = true if new_handler_class.include? source_file
|
82
|
+
else
|
83
|
+
# Workspace doesn't expose an interface to see if it
|
84
|
+
# includes the source file, so assume it does.
|
85
|
+
# Otherwise the user could have compiled without the
|
86
|
+
# workspace flag.
|
87
|
+
overwrite_old_handler = true
|
88
|
+
end
|
89
|
+
|
90
|
+
if overwrite_old_handler
|
91
|
+
source_file = new_source_file
|
92
|
+
handler = new_handler
|
93
|
+
handler_class = new_handler_class
|
94
|
+
break
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
dir = File.expand_path '..', dir
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Instantiate the class that can handle compiling of the file.
|
103
|
+
handler_class = handler.handler_class.new \
|
104
|
+
file: File.expand_path(source_file)
|
105
|
+
|
106
|
+
result = handler_class.compile
|
107
|
+
|
108
|
+
result.map {|r| r.to_s}
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'netlinx/compiler_result'
|
2
|
+
|
3
|
+
module NetLinx
|
4
|
+
# Raised when the NetLinx compiler (nlrc.exe) cannot be found on the system.
|
5
|
+
# See NetLinx::Compiler.
|
6
|
+
class NoCompilerError < Exception; end
|
7
|
+
|
8
|
+
# A wrapper class for the AMX NetLinx compiler executable (nlrc.exe).
|
9
|
+
class Compiler
|
10
|
+
|
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'
|
15
|
+
|
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.'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Compile the specified object with the NetLinx compiler.
|
36
|
+
# See Test::NetLinx::Compilable.
|
37
|
+
def compile(compilable)
|
38
|
+
compiler = File.expand_path @compiler_exe, @compiler_path
|
39
|
+
result = []
|
40
|
+
|
41
|
+
compilable.compiler_target_files.each do |target_file|
|
42
|
+
# Construct paths.
|
43
|
+
include_paths = "-I#{compilable.compiler_include_paths.join ';'}" unless
|
44
|
+
compilable.compiler_include_paths.empty?
|
45
|
+
|
46
|
+
module_paths = "-M#{compilable.compiler_module_paths.join ';'}" unless
|
47
|
+
compilable.compiler_module_paths.empty?
|
48
|
+
|
49
|
+
library_paths = "-L#{compilable.compiler_library_paths.join ';'}" unless
|
50
|
+
compilable.compiler_library_paths.empty?
|
51
|
+
|
52
|
+
# Run the NetLinx compiler.
|
53
|
+
io = IO.popen "\"#{compiler}\" \"#{target_file}\" \"#{include_paths}\" \"#{module_paths}\" \"#{library_paths}\""
|
54
|
+
stream = io.read
|
55
|
+
io.close
|
56
|
+
|
57
|
+
# Build the result.
|
58
|
+
result << NetLinx::CompilerResult.new(
|
59
|
+
compiler_target_files: [target_file],
|
60
|
+
compiler_include_paths: compilable.compiler_include_paths,
|
61
|
+
compiler_module_paths: compilable.compiler_module_paths,
|
62
|
+
compiler_library_paths: compilable.compiler_library_paths,
|
63
|
+
stream: stream
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
result
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|