thin_service 0.0.1

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.
@@ -0,0 +1,35 @@
1
+ '#--
2
+ '# Copyright (c) 2006-2007 Luis Lavena, Multimedia systems
3
+ '#
4
+ '# This source code is released under the MIT License.
5
+ '# See MIT-LICENSE file for details
6
+ '#++
7
+
8
+ #include once "testly.bi"
9
+ #include once "test_helpers.bi"
10
+ #include once "file.bi"
11
+
12
+ '# Global Helpers
13
+ function content_of_file(byref filename as string) as string
14
+ dim result as string
15
+ dim handle as integer
16
+ dim buffer as string
17
+
18
+ result = ""
19
+ buffer = ""
20
+
21
+ if (fileexists(filename) = true) then
22
+ handle = freefile
23
+ open filename for input as #handle
24
+ do while not (eof(handle))
25
+ input #handle, buffer
26
+ result += buffer
27
+ buffer = ""
28
+ loop
29
+ close #handle
30
+ else
31
+ result = ""
32
+ end if
33
+
34
+ return result
35
+ end function
@@ -0,0 +1,8 @@
1
+ '#--
2
+ '# Copyright (c) 2006-2007 Luis Lavena, Multimedia systems
3
+ '#
4
+ '# This source code is released under the MIT License.
5
+ '# See MIT-LICENSE file for details
6
+ '#++
7
+
8
+ declare function content_of_file(byref as string) as string
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/thin_service/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Garth Smedley"]
6
+ gem.email = ["gsmedley@kanayo.com"]
7
+ gem.description = %q{Runs Thin as a Windows Service - based on mongrel_service}
8
+ gem.summary = %q{Windows service exe launches thin_service and keeps it launched.}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "thin_service"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = ThinService::VERSION
17
+
18
+ gem.add_development_dependency 'rake'
19
+ gem.add_development_dependency 'rspec'
20
+
21
+ end
@@ -0,0 +1,359 @@
1
+ #--
2
+ # FreeBASIC project builder
3
+ # inspired by Asset Compiler by Jeremy Voorhis
4
+ # coded by Luis Lavena
5
+ #--
6
+
7
+ # FreeBASIC Project library for compilation.
8
+ # For example:
9
+ #
10
+ # namespace :projects do
11
+ # project_task :my_fb_project do
12
+ # lib 'static'
13
+ # dylib 'dynamic library'
14
+ # executable 'exename'
15
+ #
16
+ # build_to 'bin'
17
+ #
18
+ # define 'MY_DEFINE'
19
+ #
20
+ # main 'src/main.bas'
21
+ # source 'src/other_module.bas'
22
+ # source "src/*.bas"
23
+ # end
24
+ # end
25
+ #
26
+ # This example defines the following tasks:
27
+ #
28
+ # rake projects:build # Build all projects
29
+ # rake projects:clobber # Clobber all projects
30
+ # rake projects:my_fb_project:build # Build the my_fb_project files
31
+ # rake projects:my_fb_project:clobber # Remove the my_fb_project files
32
+ # rake projects:my_fb_project:rebuild # Force a rebuild of the my_fb_project files
33
+ # rake projects:rebuild # Rebuild all projects
34
+
35
+ module FreeBASIC
36
+ # this help me reduce the attempts to remove already removed files.
37
+ # works with src_files
38
+ CLOBBER = Rake::FileList.new
39
+ ON_WINDOWS = (RUBY_PLATFORM =~ /mingw|mswin/)
40
+
41
+ class ProjectTask
42
+ include Rake::DSL
43
+ attr_accessor :name
44
+ attr_accessor :output_name
45
+ attr_accessor :type
46
+ attr_accessor :build_path
47
+ attr_accessor :defines
48
+ attr_accessor :main_file
49
+ attr_accessor :sources
50
+ attr_accessor :libraries
51
+ attr_accessor :search_path
52
+ attr_accessor :libraries_path
53
+
54
+ def initialize(name, &block)
55
+ @name = name.to_s
56
+ @build_path = '.'
57
+ @defines = []
58
+ @sources = Rake::FileList.new
59
+ @libraries = []
60
+ @search_path = []
61
+ @libraries_path = []
62
+ @options = {}
63
+
64
+ instance_eval(&block) if block_given?
65
+
66
+ do_cleanup
67
+
68
+ namespace @name do
69
+ define_clobber_task
70
+ define_rebuild_task
71
+ define_build_directory_task
72
+ define_build_task
73
+ end
74
+ add_dependencies_to_main_task
75
+ end
76
+
77
+ public
78
+ # using this will set your project type to :executable
79
+ # and assign exe_name as the output_name for the project
80
+ # it dynamically will assign extension when running on windows
81
+ def executable(exe_name)
82
+ @type = :executable
83
+ @output_name = "#{exe_name}.#{(ON_WINDOWS ? "exe" : "")}"
84
+ @real_file_name = @output_name
85
+ end
86
+
87
+ # lib will set type to :lib and assign 'lib#{lib_name}.a'
88
+ # as output_name for the project
89
+ def lib(lib_name)
90
+ @type = :lib
91
+ @output_name = "#{lib_name}"
92
+ @real_file_name = "lib#{lib_name}.a"
93
+ end
94
+
95
+ # dynlib will set type to :dynlib and assign '#{dll_name}.dll|so'
96
+ # as output_name for this project
97
+ def dylib(dll_name)
98
+ @type = :dylib
99
+ @output_name = "#{dll_name}.#{(ON_WINDOWS ? "dll" : "so")}"
100
+ @real_file_name = @output_name
101
+ @complement_file = "lib#{@output_name}.a"
102
+ end
103
+
104
+ # this set where the final, compiled executable should be linked
105
+ # uses @build_path as variable
106
+ def build_to(path)
107
+ @build_path = path
108
+ end
109
+
110
+ # define allow you set compiler time options
111
+ # collect them into @defines and use later
112
+ # to call source file compilation process (it wil require cleanup)
113
+ def define(*defines)
114
+ @defines << defines
115
+ end
116
+
117
+ # main set @main_file to be the main module used during the linking
118
+ # process. also, this module requires special -m flag during his
119
+ # own compile process
120
+ # question: in case @no main_file was set, will use the first 'source'
121
+ # file defined as main? or it should raise a error?
122
+ def main(main_file)
123
+ @main_file = main_file
124
+ end
125
+
126
+ # used to collect sources files for compilation
127
+ # it will take .bas, .rc, .res as sources
128
+ # before compilation we should clean @sources!
129
+ def source(*sources)
130
+ @sources.include sources
131
+ end
132
+
133
+ # this is similar to sources, instead library linking is used
134
+ # also will require cleanup services ;-)
135
+ def library(*libraries)
136
+ @libraries << libraries
137
+ end
138
+
139
+ # use this to set the include path when looking for, ehem, includes
140
+ # (equals -i fbc compiler param)
141
+ def search_path(*search_path)
142
+ @search_path << search_path
143
+ end
144
+
145
+ # use this to tell the compiler where to look for libraries
146
+ # (equals -p fbc compiler param)
147
+ def lib_path(*libraries_path)
148
+ @libraries_path << libraries_path
149
+ end
150
+
151
+ # use this to add additional compiler parameters (like debug or errorchecking options)
152
+ #
153
+ def option(new_options = {})
154
+ @options.merge!(new_options)
155
+ end
156
+
157
+ protected
158
+ # this method will fix nested libraries and defines
159
+ # also, if main_file is missing (or wasn't set) will shift the first one
160
+ # as main
161
+ def do_cleanup
162
+ # remove duplicated definitions, flatten
163
+ @defines.flatten!
164
+ @defines.uniq! if @defines.length > 1
165
+
166
+ # set main_file
167
+ if @type == :executable
168
+ @main_file = @sources.shift unless defined?(@main_file)
169
+ end
170
+
171
+ # empty path? must be corrected
172
+ @build_path = '.' if @build_path == ''
173
+
174
+ # remove duplicates from sources
175
+ @sources.uniq! if @sources.length > 1
176
+
177
+ # now the libraries
178
+ @libraries.flatten!
179
+ @libraries.uniq! if @libraries.length > 1
180
+
181
+ # search path
182
+ @search_path.flatten!
183
+ @search_path.uniq! if @search_path.length > 1
184
+
185
+ # libraries path
186
+ @libraries_path.flatten!
187
+ @libraries_path.uniq! if @libraries_path.length > 1
188
+
189
+ # if no target was set, default to executable
190
+ unless defined?(@output_name)
191
+ executable(@name)
192
+ end
193
+ end
194
+
195
+ # return the compiled name version of the passed source file (src)
196
+ # compiled_form("test.bas") => "test.o"
197
+ def compiled_form(src)
198
+ unless src.nil?
199
+ src.ext({ ".bas" => "o", ".rc" => "obj" }[File.extname(src)])
200
+ end
201
+ end
202
+
203
+ def compiled_project_file
204
+ File.join @build_path, @real_file_name
205
+ end
206
+
207
+ def fbc_compile(source, target, main = nil)
208
+ cmdline = []
209
+ cmdline << "fbc"
210
+ cmdline << "-w pedantic" if (@options.has_key?(:pedantic) && @options[:pedantic] == true)
211
+ cmdline << "-g" if (@options.has_key?(:debug) && @options[:debug] == true)
212
+ cmdline << "-#{@options[:errorchecking].to_s}" if @options.has_key?(:errorchecking)
213
+ cmdline << "-mt" if (@options.has_key?(:mt) && @options[:mt] == true)
214
+ cmdline << "-profile" if (@options.has_key?(:profile) && @options[:profile] == true)
215
+ cmdline << "-c #{source}"
216
+ cmdline << "-o #{target}"
217
+ cmdline << "-m #{main}" unless main.nil?
218
+ cmdline << @defines.collect { |defname| "-d #{defname}" }
219
+ cmdline << @search_path.collect { |path| "-i #{path}" }
220
+ cmdline.flatten.join(' ')
221
+ end
222
+
223
+ def fbc_link(target, files, extra_files = [])
224
+ cmdline = []
225
+ cmdline << "fbc"
226
+ cmdline << "-g" if (@options.has_key?(:debug) && @options[:debug] == true)
227
+ cmdline << "-mt" if (@options.has_key?(:mt) && @options[:mt] == true)
228
+ cmdline << "-profile" if (@options.has_key?(:profile) && @options[:profile] == true)
229
+ cmdline << "-#{@type.to_s}" unless @type == :executable
230
+ cmdline << "-x #{target}"
231
+ cmdline << files << extra_files
232
+ cmdline << @defines.collect { |defname| "-d #{defname}" }
233
+ unless @type == :lib
234
+ cmdline << @libraries_path.collect { |path| "-p #{path}" }
235
+ cmdline << @libraries.collect { |libname| "-l #{libname}" }
236
+ end
237
+ cmdline.flatten.join(' ')
238
+ end
239
+
240
+ def define_clobber_task
241
+ desc "Remove all compiled files for #{@name}"
242
+ task :clobber do
243
+ # remove compiled and linked file
244
+ rm compiled_project_file rescue nil if File.exist?(compiled_project_file)
245
+ if @type == :dylib
246
+ rm File.join(@build_path, @complement_file) rescue nil if File.exist?(File.join(@build_path, @complement_file))
247
+ end
248
+
249
+ # remove main file
250
+ unless @main_file.nil? || !File.exists?(compiled_form(@main_file))
251
+ rm compiled_form(@main_file) rescue nil
252
+ end
253
+
254
+ # now the sources files
255
+ # avoid attempt to remove the file two times (this is a bug in Rake)
256
+ @sources.each do |src|
257
+ # exclude compiled source files (c obj).
258
+ unless src =~ /o$/
259
+ target = compiled_form(src)
260
+ unless CLOBBER.include?(target)
261
+ CLOBBER.include(target)
262
+ rm target rescue nil if File.exist?(target)
263
+ end
264
+ end
265
+ end
266
+ end
267
+ end
268
+
269
+ def define_rebuild_task
270
+ desc "Force a rebuild of files for #{@name}"
271
+ task :rebuild => [:clobber, :build]
272
+ end
273
+
274
+ def define_build_directory_task
275
+ directory @build_path
276
+ task :build => @build_path
277
+ end
278
+
279
+ def define_build_task
280
+ desc "Build project #{@name}"
281
+ task :build
282
+
283
+ # empty file task
284
+ file compiled_project_file
285
+
286
+ # compile main_file
287
+ # use as pre-requisite the source filename
288
+ if @type == :executable
289
+ file compiled_form(@main_file) => @main_file do |t|
290
+ # remove the path and the extension
291
+ main_module = File.basename(t.name).ext
292
+ sh fbc_compile(@main_file, t.name, main_module)
293
+ end
294
+
295
+ # add dependency
296
+ file compiled_project_file => compiled_form(@main_file)
297
+ end
298
+
299
+ # gather files that are passed "as-is" to the compiler
300
+ unprocessed_files = @sources.select { |rcfile| rcfile =~ /(res|rc|o|obj)$/ }
301
+
302
+ @sources.each do |src|
303
+ # is a unprocessed file?
304
+ unless unprocessed_files.include?(src)
305
+ target = compiled_form(src)
306
+
307
+ # is already in our list of tasks?
308
+ if not Rake::Task.task_defined?(target)
309
+ # if not, compile
310
+
311
+ file target => src do
312
+ sh fbc_compile(src, target)
313
+ end
314
+ end
315
+
316
+ # include dependency
317
+ file compiled_project_file => target
318
+ end
319
+ end
320
+
321
+ # now the linking process
322
+ file compiled_project_file do |t|
323
+ target = File.join(@build_path, @output_name)
324
+ sh fbc_link(target, t.prerequisites, unprocessed_files)
325
+ end
326
+
327
+ # add the dependency
328
+ task :build => compiled_project_file
329
+ end
330
+
331
+ # Adds dependencies in the parent namespace
332
+ def add_dependencies_to_main_task
333
+ desc 'Build all projects' unless task( :build ).comment
334
+ task :build => "#{@name}:build"
335
+
336
+ desc 'Clobber all projects' unless task( :clobber ).comment
337
+ task :clobber => "#{@name}:clobber"
338
+
339
+ desc 'Rebuild all projects' unless task( :rebuild ).comment
340
+ task :rebuild => ["#{@name}:clobber", "#{@name}:build"]
341
+ end
342
+ end
343
+ end
344
+
345
+ # helper method to define a FreeBASIC::ProjectTask in the current namespace
346
+ def project_task name, &block
347
+ FreeBASIC::ProjectTask.new name, &block
348
+ end
349
+
350
+ def include_projects_of name
351
+ desc 'Build all projects' unless task( :build ).comment
352
+ task :build => "#{name}:build"
353
+
354
+ desc 'Clobber all projects' unless task( :clobber ).comment
355
+ task :clobber => "#{name}:clobber"
356
+
357
+ desc 'Rebuild all projects' unless task( :rebuild ).comment
358
+ task :rebuild => "#{name}:rebuild"
359
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thin_service
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Garth Smedley
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &19587312 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *19587312
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &19889952 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *19889952
36
+ description: Runs Thin as a Windows Service - based on mongrel_service
37
+ email:
38
+ - gsmedley@kanayo.com
39
+ executables:
40
+ - thin_service
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - bin/thin_service
50
+ - lib/thin_service.rb
51
+ - lib/thin_service/command.rb
52
+ - lib/thin_service/logger.rb
53
+ - lib/thin_service/service_manager.rb
54
+ - lib/thin_service/version.rb
55
+ - resource/thin_service_wrapper.exe
56
+ - spec/spec_helper.rb
57
+ - spec/thin_service_spec.rb
58
+ - src/ServiceFB/ServiceFB.bas
59
+ - src/ServiceFB/ServiceFB.bi
60
+ - src/ServiceFB/ServiceFB_Utils.bas
61
+ - src/ServiceFB/ServiceFB_Utils.bi
62
+ - src/ServiceFB/_internals.bi
63
+ - src/ServiceFB/_utils_internals.bi
64
+ - src/thin_service/_debug.bi
65
+ - src/thin_service/boolean.bi
66
+ - src/thin_service/console_process.bas
67
+ - src/thin_service/console_process.bi
68
+ - src/thin_service/thin_service.bas
69
+ - src/thin_service/thin_service.bi
70
+ - tasks/native_lib.rake
71
+ - tasks/native_service.rake
72
+ - tasks/tests.rake
73
+ - tests/all_tests.bas
74
+ - tests/fixtures/mock_process.bas
75
+ - tests/test_console_process.bas
76
+ - tests/test_helpers.bas
77
+ - tests/test_helpers.bi
78
+ - thin_service.gemspec
79
+ - tools/freebasic.rb
80
+ homepage: ''
81
+ licenses: []
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.16
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Windows service exe launches thin_service and keeps it launched.
104
+ test_files:
105
+ - spec/spec_helper.rb
106
+ - spec/thin_service_spec.rb