fcshd 0.5.2 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ require "./lib/fcshd/version"
2
+
3
+ name, version = "fcshd", FCSHD::VERSION
4
+
5
+ gem = "#{name}-#{version}.gem"
6
+ gemspec = "#{name}.gemspec"
7
+ sources = FileList["{bin,lib}/**/*"]
8
+
9
+ task :default => [:uninstall, :install]
10
+
11
+ task :install => gem do
12
+ sh "sudo gem install #{gem}"
13
+ end
14
+
15
+ task :uninstall do
16
+ sh "sudo gem uninstall #{name} -v #{version}"
17
+ end
18
+
19
+ file gem => FileList[gemspec, sources] do
20
+ sh "gem build #{gemspec}"
21
+ end
22
+
23
+ task :push => gem do
24
+ sh "gem push #{gem}"
25
+ end
26
+
27
+ require "rake/clean"
28
+
29
+ CLEAN << "*.gem"
data/bin/fcshc CHANGED
@@ -18,17 +18,20 @@ end
18
18
 
19
19
  $output_file = nil
20
20
  $source_files = []
21
+ $libraries = []
21
22
  $library_files = []
22
23
  $directories = []
23
24
  $production = false
24
25
  $extra_arguments = []
25
26
  $verbose = false
27
+ $restart_compiler = false
28
+ $run_compilation = nil
26
29
  $dry_run = false
27
30
 
28
31
  OptionParser.new do |parser|
29
32
  parser.banner = <<EOF
30
- Usage: fcshc MAIN.[as|mxml] [SRCDIR|SWCDIR|SWC]... [-o OUTPUT.swf]
31
- fcshc -o OUTPUT.swc [SRCDIR|SWCDIR|SWC]...
33
+ Usage: fcshc MAIN.[as|mxml] [-l LIB] [SRCDIR|SWCDIR|SWC]... [-o OUT.swf]
34
+ fcshc -o OUT.swc SRCDIR... [-l LIB]... [SWCDIR|SWC]...
32
35
 
33
36
  To compile an SWF, name the main application source file, then any
34
37
  additional source directories, SWC directories, or SWC files.
@@ -36,37 +39,53 @@ additional source directories, SWC directories, or SWC files.
36
39
  To compile an SWC using `compc', you must provide the `-o' option, and
37
40
  then at least one source directory, SWC directory, or SWC file.
38
41
 
42
+ Dependencies can also be specified by name using the `-l LIB' option,
43
+ which will search for LIB or LIB.swc in `~/.fcshd-lib'. Both source
44
+ directories, SWC directories, and SWC files can be named in this way.
45
+
39
46
  To pass extra arguments, use e.g. `-X -include-file -X NAME -X FILE'.
40
47
 
41
48
  EOF
42
49
 
43
50
  parser.on("-o", "--output OUTPUT.[swf|swc]", "Name of the resulting binary") do |value|
51
+ $run_compilation = true
44
52
  $output_file = File.expand_path(value)
45
53
  end
46
54
 
55
+ parser.on("-l", "--library LIBRARY", "Search LIBRARY when compiling") do |value|
56
+ $run_compilation = true
57
+ $libraries << value
58
+ end
59
+
47
60
  parser.on("-X", "--extra-argument ARGUMENT", "Pass ARGUMENT to the compiler") do |value|
61
+ $run_compilation = true
48
62
  $extra_arguments << value
49
63
  end
50
64
 
51
65
  parser.on("-p", "--production", "Leave out debugging metadata") do
66
+ $run_compilation = true
52
67
  $production = true
53
68
  end
54
69
 
55
70
  parser.on("--static-rsls", "Use static linking for RSLs") do
71
+ $run_compilation = true
56
72
  $extra_arguments << "-static-link-runtime-shared-libraries=true"
57
73
  end
58
74
 
59
75
  parser.on("--no-rsls", "Remove all runtime shared libraries") do
76
+ $run_compilation = true
60
77
  $extra_arguments << "-runtime-shared-library-path="
61
78
  end
62
79
 
63
80
  parser.separator ""
64
81
 
65
82
  parser.on("-3", "--flex-3", "Use -compatibility-version=3") do |value|
83
+ $run_compilation = true
66
84
  $extra_arguments << "-compatibility-version=3"
67
85
  end
68
86
 
69
87
  parser.on("--halo", "Use the Halo theme") do
88
+ $run_compilation = true
70
89
  if FCSHD::FlexHome.known?
71
90
  $extra_arguments << "-theme=#{FCSHD::FlexHome.halo_swc}"
72
91
  else
@@ -76,8 +95,15 @@ EOF
76
95
 
77
96
  parser.separator ""
78
97
 
98
+ parser.on("-R", "--restart", "Restart the compiler first") do
99
+ $run_compilation = false if $run_compilation == nil
100
+ $restart_compiler = true
101
+ end
102
+
79
103
  parser.on("-n", "--dry-run", "Only print the compiler command") do
104
+ $run_compilation = true
80
105
  $dry_run = true
106
+ $verbose = true
81
107
  end
82
108
 
83
109
  parser.on("--verbose", "Also print the compiler command") do
@@ -98,6 +124,7 @@ EOF
98
124
  parser.separator "TL;DR: $ fcshc src/my_app.mxml"
99
125
  end.parse!
100
126
 
127
+ $run_compilation = true unless $run_compilation == false
101
128
  $extra_arguments << "-debug" unless $production
102
129
 
103
130
  for name in ARGV
@@ -114,66 +141,96 @@ for name in ARGV
114
141
  end
115
142
  end
116
143
 
117
- $compiling_swc = $output_file && $output_file.end_with?(".swc")
118
-
119
- if $compiling_swc
120
- if [$source_files, $directories, $library_files] == [[], [], []]
121
- die "must include at least one source file, directory, or SWC"
122
- end
123
-
124
- $fcshd_arguments = ["compc"]
125
-
126
- for file in $source_files
127
- $fcshd_arguments << "-include-sources+=#{file}"
144
+ ENV["FCSHD_LIBRARY_PATH"] ||= ""
145
+ ENV["FCSHD_LIBRARY_PATH"] += ":~/.fcshd-lib"
146
+
147
+ def find_library(name)
148
+ nil.tap do
149
+ for x in ENV["FCSHD_LIBRARY_PATH"].split(":")
150
+ next if x == ""
151
+ x = File.expand_path(x)
152
+ if File.basename(x) == "#{name}.swc" and File.file? x
153
+ return :file, x
154
+ elsif File.directory? File.join(x, name)
155
+ return :directory, File.join(x, name)
156
+ elsif File.file? File.join(x, "#{name}.swc")
157
+ return :file, File.join(x, "#{name}.swc")
158
+ end
159
+ end
128
160
  end
161
+ end
129
162
 
130
- for directory in $directories
131
- $fcshd_arguments << "-include-sources+=#{directory}"
163
+ for library in $libraries
164
+ type, filename = find_library(library)
165
+ case type
166
+ when :directory
167
+ $directories << name
168
+ when :file
169
+ $library_files << filename
170
+ else
171
+ die "library not found: #{library}"
132
172
  end
173
+ end
133
174
 
134
- if FCSHD::FlexHome.known?
135
- $extra_arguments << "-external-library-path+=#{FCSHD::FlexHome.libs}"
136
- end
137
- else
138
- case $source_files.size
139
- when 0: die "missing main application source file"
140
- when 1: $source_file = $source_files.first
141
- else die "multiple source files not allowed when compiling SWF"
175
+ if $run_compilation
176
+ $compiling_swc = $output_file && $output_file.end_with?(".swc")
177
+
178
+ if $compiling_swc
179
+ if [$source_files, $directories, $library_files] == [[], [], []]
180
+ die "must include at least one source file, directory, or SWC"
181
+ end
182
+
183
+ $compilation_command = ["compc"]
184
+
185
+ for file in $source_files
186
+ $compilation_command << "-include-sources+=#{file}"
187
+ end
188
+
189
+ for directory in $directories
190
+ $compilation_command << "-include-sources+=#{directory}"
191
+ end
192
+
193
+ if FCSHD::FlexHome.known?
194
+ for dir in FCSHD::FlexHome.framework_lib_dirs
195
+ $extra_arguments << "-external-library-path+=#{dir}"
196
+ end
197
+ end
198
+ else
199
+ case $source_files.size
200
+ when 0
201
+ die "missing main application source file"
202
+ when 1: $source_file = $source_files.first
203
+ else die "multiple source files not allowed when compiling SWF"
204
+ end
205
+
206
+ if $directories.empty?
207
+ $directories << File.dirname($source_file)
208
+ end
209
+
210
+ if $output_file == nil
211
+ $source_file.sub(/\.(as|mxml)$/, ".swf").tap do |x|
212
+ $output_file = File.expand_path(File.basename(x))
213
+ end
214
+ end
215
+
216
+ $compilation_command = ["mxmlc", "#$source_file"]
142
217
  end
143
-
144
- if $directories.empty?
145
- $directories << File.dirname($source_file)
218
+
219
+ $compilation_command << "-output=#$output_file"
220
+
221
+ for directory in $directories
222
+ $compilation_command << "-compiler.source-path+=#{directory}"
223
+ $compilation_command << "-compiler.library-path+=#{directory}"
146
224
  end
147
-
148
- if $output_file == nil
149
- $source_file.sub(/\.(as|mxml)$/, ".swf").tap do |x|
150
- $output_file = File.expand_path(File.basename(x))
151
- end
225
+
226
+ for file in $library_files
227
+ $compilation_command << "-compiler.library-path+=#{file}"
152
228
  end
153
-
154
- $fcshd_arguments = ["mxmlc", "#$source_file"]
155
- end
156
-
157
- $fcshd_arguments << "-output=#$output_file"
158
-
159
- for directory in $directories
160
- $fcshd_arguments << "-compiler.source-path+=#{directory}"
161
- $fcshd_arguments << "-compiler.library-path+=#{directory}"
162
- end
163
-
164
- for file in $library_files
165
- $fcshd_arguments << "-compiler.library-path+=#{file}"
166
- end
167
-
168
- $fcshd_arguments.concat($extra_arguments)
169
-
170
- basedir = File.join(File.expand_path("."), "")
171
- fcshd_command = $fcshd_arguments.join(" ")
172
-
173
- if $verbose || $dry_run
174
- warn fcshd_command.gsub(basedir, "")
229
+
230
+ $compilation_command.concat($extra_arguments)
175
231
  end
176
232
 
233
+ warn $compilation_command.join(" ") if $verbose
177
234
  exit if $dry_run
178
235
 
179
236
  begin
@@ -183,7 +240,8 @@ rescue Errno::ECONNREFUSED
183
240
  die "could not connect to fcshd at #{host}:#{port}"
184
241
  end
185
242
 
186
- socket.puts fcshd_command
243
+ socket.puts "restart" if $restart_compiler
244
+ socket.puts $compilation_command.join(" ") if $run_compilation
187
245
 
188
246
  compiler_output = ""
189
247
  socket.each_line do |line|
@@ -196,5 +254,6 @@ socket.each_line do |line|
196
254
  end
197
255
 
198
256
  transcript = FCSHD::Transcript[compiler_output]
257
+ basedir = File.join(File.expand_path("."), "")
199
258
  STDOUT.write transcript.to_s(basedir)
200
259
  exit 1 if not transcript.succeeded?
data/bin/fcshd CHANGED
@@ -13,14 +13,13 @@ if ARGV == ["-v"] || ARGV == ["--version"]
13
13
  exit
14
14
  end
15
15
 
16
- logger = FCSHD::Logger.new(STDERR)
16
+ logger = FCSHD::Logger.new(STDOUT)
17
17
 
18
- logger.die <<"^D" if not FCSHD::FlexHome.known?
18
+ logger.die <<EOF if not FCSHD::FlexHome.known?
19
19
  Please put the Flex SDK in #{FlexHome.default} or set $FLEX_HOME.
20
- ^D
20
+ EOF
21
21
 
22
- logger.log "This is fcshd #{FCSHD::VERSION}."
23
- logger.log "Flex SDK: #{FCSHD::FlexHome}"
22
+ logger.log "fcshd #{FCSHD::VERSION}"
24
23
 
25
24
  compiler = FCSHD::Compiler.new(logger)
26
25
  compiler.start!
@@ -1,25 +1,20 @@
1
- require "find"
2
-
1
+ # -*- coding: utf-8 -*-
3
2
  module FCSHD
4
3
  class Compiler
5
4
  def initialize(logger)
6
5
  @logger = logger
7
6
  @output_buffer = ""
7
+ @command_ids = {}
8
8
  end
9
9
 
10
- def start!
11
- start_fcsh_process!
12
- parse_fcsh_boilerplate!
13
- @logger.log "Started Flex #@flex_version compiler shell."
14
- rescue PromptNotFound => error
15
- @logger.error "Could not find fcsh prompt:"
16
- @logger.error @logger.format_command(FlexHome.fcsh, error.message)
17
- @logger.exit
18
- end
10
+ def start!; restart_fcsh_process! end
11
+ def restart!; restart_fcsh_process! end
19
12
 
20
13
  def compile! command, frontend
21
14
  @command, @frontend = command, frontend
22
15
 
16
+ log_horizontal_line
17
+
23
18
  if have_command_id?
24
19
  recompile!
25
20
  else
@@ -29,87 +24,101 @@ module FCSHD
29
24
 
30
25
  private
31
26
 
32
- def start_fcsh_process!
27
+ def log_horizontal_line
28
+ @logger.log("—" * 60)
29
+ end
30
+
31
+ def have_command_id?
32
+ @command_ids.include? @command
33
+ end
34
+
35
+ def restart_fcsh_process!
33
36
  stop_fcsh_process!
37
+ @logger.log "starting #{FlexHome.fcsh}"
34
38
  @fcsh_process = IO.popen("#{FlexHome.fcsh} 2>&1", "r+")
35
- read_fcsh_output!
39
+ read_until_prompt!
36
40
  end
37
41
 
38
42
  def stop_fcsh_process!
39
- @fcsh_process.close if @fcsh_process
40
- @fcsh_process = nil
41
- @command_ids = {}
42
- end
43
-
44
- def parse_fcsh_boilerplate!
45
- case @output
46
- when /Version (\S+)/
47
- @flex_version = $1
48
- else
49
- @flex_version = "(unknown version)"
43
+ if @fcsh_process
44
+ @logger.log "killing fcsh process"
45
+ @fcsh_process.close
46
+ @fcsh_process = nil
47
+ @command_ids = {}
50
48
  end
51
49
  end
52
50
 
53
51
  def compile_new!
54
- @frontend.puts "fcshd: Compiling from scratch"
55
52
  @frontend.flush
56
53
  send_fcsh_command! @command
57
- parse_compilation_output!
54
+ process_compilation_output!
58
55
  ensure
59
56
  if not have_command_id?
60
- @logger.error "Could not determine compilation ID:"
61
- @logger.error @logger.format_command("(fcsh) #@command", @output)
62
-
63
- @frontend.puts "fcshd: internal error"
64
- @frontend.flush
57
+ report_internal_error "could not determine compilation ID"
65
58
  end
66
59
  end
67
60
 
68
61
  def recompile!
69
62
  send_fcsh_command! "compile #{command_id}"
70
- parse_compilation_output!
63
+ process_compilation_output!
64
+ rescue FCSHError => error
65
+ case error.message
66
+ when "Error: null"
67
+ @frontend.puts "fcshd: Adobe-internal error; restarting fcsh..."
68
+ restart_fcsh_process!
69
+ @frontend.puts "fcshd: retrying your compilation"
70
+ compile_new!
71
+ else
72
+ report_internal_error "unknown fcsh error: #{error.message}"
73
+ end
71
74
  end
72
75
 
73
76
  def command_id
74
77
  @command_ids[@command]
75
78
  end
76
79
 
77
- def command_id= id
78
- @command_ids[@command] = id
79
- end
80
+ class FCSHError < StandardError; end
80
81
 
81
- def have_command_id?
82
- @command_ids.include? @command
82
+ def report_internal_error(message)
83
+ @logger.error(message)
84
+ @frontend.puts "fcshd: internal error; see fcshd log"
85
+ @frontend.flush
83
86
  end
84
87
 
85
- def parse_compilation_output!
86
- for line in @output.lines
88
+ def process_compilation_output!
89
+ for line in @output.lines.map(&:chomp)
87
90
  case line
88
91
  when /^fcsh: Assigned (\d+) as the compile target id$/
89
92
  self.command_id = $1
93
+ when "Error: null"
94
+ raise FCSHError, line
90
95
  else
91
96
  @frontend.puts(line)
92
- @logger.log_raw(line) if line =~ /^fcsh: /
93
97
  end
94
98
  end
95
99
  end
96
100
 
101
+ def command_id= id
102
+ @command_ids[@command] = id
103
+ end
104
+
97
105
  def send_fcsh_command! command
98
- @logger.log_raw("> #{command}")
106
+ @logger.log(command)
99
107
  @fcsh_process.puts(command)
100
- read_fcsh_output!
108
+ read_until_prompt!
101
109
  end
102
110
 
103
111
  FCSH_PROMPT = "\n(fcsh) "
104
- class PromptNotFound < Exception ; end
105
112
 
106
- def read_fcsh_output!
113
+ def read_until_prompt!
107
114
  @output_buffer << @fcsh_process.readpartial(256) until
108
115
  @output_buffer.include? FCSH_PROMPT
109
116
  @output, @output_buffer =
110
117
  @output_buffer.split(FCSH_PROMPT, 2)
118
+ @logger.dump @output
111
119
  rescue EOFError
112
- raise PromptNotFound, @output_buffer
120
+ @logger.dump @output_buffer
121
+ @logger.die "could not find fcsh prompt"
113
122
  end
114
123
  end
115
124
  end
@@ -1,3 +1,5 @@
1
+ require "find"
2
+
1
3
  module FCSHD
2
4
  module FlexHome
3
5
  extend self
@@ -33,8 +35,12 @@ module FCSHD
33
35
  self["bin/fcsh"]
34
36
  end
35
37
 
36
- def libs
37
- self["frameworks/libs"]
38
+ def framework_lib_dirs
39
+ [].tap do |result|
40
+ Find.find(self["frameworks/libs"]) do |file|
41
+ result << file if File.directory? file
42
+ end
43
+ end
38
44
  end
39
45
 
40
46
  def halo_swc
data/lib/fcshd/logger.rb CHANGED
@@ -1,21 +1,17 @@
1
1
  module FCSHD
2
2
  class Logger
3
3
  def initialize(output)
4
- @stderr = output
5
- end
6
-
7
- def log_raw(message)
8
- @stderr.puts message
4
+ @output = output
9
5
  end
10
6
 
11
7
  def log(message)
12
8
  for line in message.lines
13
- log_raw "#{program_name}: #{line.chomp}"
9
+ @output.puts "#{File.basename($0)}: #{line.chomp}"
14
10
  end
15
11
  end
16
12
 
17
- def program_name
18
- File.basename($0)
13
+ def dump(output)
14
+ @output.puts output.chomp
19
15
  end
20
16
 
21
17
  def error(message)
@@ -25,17 +21,8 @@ module FCSHD
25
21
  end
26
22
 
27
23
  def die(message)
28
- error message ; exit
29
- end
30
-
31
- def exit(code=1)
32
- Kernel.exit code
33
- end
34
-
35
- def format_command(command, output)
36
- ["$ #{command}", *output.lines].
37
- map { |line| " #{line.chomp}" }.
38
- join("\n")
24
+ error message
25
+ exit 1
39
26
  end
40
27
  end
41
28
  end
data/lib/fcshd/server.rb CHANGED
@@ -20,9 +20,12 @@ module FCSHD
20
20
 
21
21
  class Client < Struct.new(:socket, :compiler)
22
22
  def run!
23
- case command = socket.gets
23
+ case command = socket.gets.chomp
24
24
  when /^(mxmlc|compc) /
25
25
  compiler.compile! command, socket
26
+ when "restart"
27
+ compiler.restart!
28
+ socket.puts "fcshd: compiler restarted"
26
29
  else
27
30
  socket.puts "fcshd: unrecognized command: #{command}"
28
31
  end
@@ -33,6 +33,15 @@ module FCSHD
33
33
  end
34
34
  end
35
35
 
36
+ def format_type(type)
37
+ case type
38
+ when /^__AS3__\.vec:Vector\.<(.*)>$/
39
+ "Vector.<#{$1.sub(/.+:/, "")}>"
40
+ else
41
+ type.sub(/.+:/, "")
42
+ end
43
+ end
44
+
36
45
  def parsed_message
37
46
  case FCSHD.trim(mxmlc_message).sub(/^Error: /, "")
38
47
  when "Unable to resolve MXML language version. Please specify the language namespace on the root document tag.": <<EOF
@@ -78,10 +87,9 @@ error: #{quote $1} not found
78
87
  EOF
79
88
  when /^Implicit coercion of a value of type (.+) to an unrelated type (.+)\.$/, /^Implicit coercion of a value with static type (.+) to a possibly unrelated type (.+)\./
80
89
  actual, expected = $1, $2
81
- expected_local = expected.sub(/.+:/, "")
82
- actual_local = actual.sub(/.+:/, "")
83
- actual_local != expected_local ? <<EOF : <<EOF
84
- error: expected #{expected_local} (got #{actual_local})
90
+ if format_type(actual) != format_type(expected)
91
+ then <<EOF else <<EOF end
92
+ error: expected #{format_type(expected)} (got #{format_type(actual)})
85
93
  EOF
86
94
  error: expected #{expected} (got #{actual})
87
95
  EOF
@@ -29,8 +29,9 @@ module FCSHD
29
29
  when /^Required RSLs:$/
30
30
  skip_indented_lines! # Does anybody care about this?
31
31
 
32
- when /^(Recompile|Reason): /
32
+ when /^(Recompile|Reason|Updated): /
33
33
  when /^Loading configuration file /
34
+ when "Detected configuration changes. Recompile..."
34
35
 
35
36
  else
36
37
  # Let unrecognized lines pass through verbatim.
data/lib/fcshd/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  unless defined? FCSHD::VERSION
2
2
  module FCSHD
3
- VERSION = "0.5.2"
3
+ VERSION = "0.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fcshd
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
9
- - 2
10
- version: 0.5.2
8
+ - 6
9
+ version: "0.6"
11
10
  platform: ruby
12
11
  authors:
13
12
  - Daniel Brockman
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-12-01 00:00:00 Z
17
+ date: 2011-12-19 00:00:00 Z
19
18
  dependencies: []
20
19
 
21
20
  description: |
@@ -36,8 +35,8 @@ files:
36
35
  - .gitignore
37
36
  - Gemfile
38
37
  - Gemfile.lock
39
- - Makefile
40
38
  - README
39
+ - Rakefile
41
40
  - bin/fcshc
42
41
  - bin/fcshd
43
42
  - fcshd.gemspec
data/Makefile DELETED
@@ -1,12 +0,0 @@
1
- version=$(shell ruby -r lib/fcshd/version -e 'print FCSHD::VERSION')
2
-
3
- default: install
4
-
5
- build:
6
- gem build fcshd.gemspec
7
- install: build
8
- sudo gem install fcshd-${version}.gem
9
- push: build
10
- gem push fcshd-${version}.gem
11
- clean:
12
- rm *.gem