filament 0.1.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.
Files changed (56) hide show
  1. data/README +7 -0
  2. data/bin/filament +11 -0
  3. data/bin/filament-dbg +3 -0
  4. data/bin/filament-opt +3 -0
  5. data/bin/filament-test +3 -0
  6. data/bin/init +4 -0
  7. data/lib/filament/artifact.rb +49 -0
  8. data/lib/filament/context.rb +46 -0
  9. data/lib/filament/package/svn.rb +123 -0
  10. data/lib/filament/package.rb +326 -0
  11. data/lib/filament/platform.rb +79 -0
  12. data/lib/filament/plugins.rb +32 -0
  13. data/lib/filament/resolver.rb +91 -0
  14. data/lib/filament/target.rb +117 -0
  15. data/lib/filament/util/filelist2.rb +39 -0
  16. data/lib/filament/util/fileutils.rb +51 -0
  17. data/lib/filament/util/lazy_list.rb +74 -0
  18. data/lib/filament/workspace.rb +57 -0
  19. data/lib/filament.rb +199 -0
  20. data/lib/inflector.rb +124 -0
  21. data/lib/svn.rb +78 -0
  22. data/plugins/00util/lib/init.rb +47 -0
  23. data/plugins/01java/lib/filament/java/mixins/java_mixin.rb +19 -0
  24. data/plugins/01java/lib/filament/java/tools/compile.rb +41 -0
  25. data/plugins/01java/lib/filament/java/tools/execute.rb +37 -0
  26. data/plugins/01java/lib/filament/java/tools/jar.rb +59 -0
  27. data/plugins/01java/lib/filament/java/tools.rb +28 -0
  28. data/plugins/01java/lib/init.rb +1 -0
  29. data/plugins/02javame/lib/filament/javame/library.rb +16 -0
  30. data/plugins/02javame/lib/filament/javame/mixins/library_mixin.rb +144 -0
  31. data/plugins/02javame/lib/filament/javame/mixins/suite_mixin.rb +125 -0
  32. data/plugins/02javame/lib/filament/javame/platform.rb +105 -0
  33. data/plugins/02javame/lib/filament/javame/suite.rb +16 -0
  34. data/plugins/02javame/lib/filament/javame/tasks.rb +6 -0
  35. data/plugins/02javame/lib/filament/javame/tools/descriptor.rb +146 -0
  36. data/plugins/02javame/lib/filament/javame/tools/emulator.rb +36 -0
  37. data/plugins/02javame/lib/filament/javame/tools/external/mpp_sdk.rb +39 -0
  38. data/plugins/02javame/lib/filament/javame/tools/external/wtk.rb +60 -0
  39. data/plugins/02javame/lib/filament/javame/tools/preverifier.rb +43 -0
  40. data/plugins/02javame/lib/filament/javame/tools.rb +8 -0
  41. data/plugins/02javame/lib/init.rb +27 -0
  42. data/plugins/05push/lib/bluetooth.rb +66 -0
  43. data/plugins/05push/lib/filament/push/conduits/bluetooth_conduit.rb +25 -0
  44. data/plugins/05push/lib/filament/push/conduits/filter_conduit.rb +20 -0
  45. data/plugins/05push/lib/filament/push/conduits/scp_conduit.rb +35 -0
  46. data/plugins/05push/lib/filament/push.rb +21 -0
  47. data/plugins/05push/lib/init.rb +29 -0
  48. data/tests/build/artifact_name_test.rb +85 -0
  49. data/tests/build/artifact_test.rb +23 -0
  50. data/tests/gen/java/block_test.rb +42 -0
  51. data/tests/gen/java/callable_test.rb +23 -0
  52. data/tests/gen/java/method_test.rb +25 -0
  53. data/tests/gen/java/statement_test.rb +16 -0
  54. data/tests/java/tools_test.rb +8 -0
  55. data/tests/platform_test.rb +25 -0
  56. metadata +135 -0
@@ -0,0 +1,91 @@
1
+ module Filament
2
+ class PackageResolver
3
+ def initialize(parent_resolver=nil)
4
+ @parent = parent_resolver
5
+ @root_packages = []
6
+ end
7
+
8
+ def <<(root_package)
9
+ @root_packages << root_package unless root_package.nil?
10
+ end
11
+
12
+ def resolve(uri)
13
+ uri = uri.gsub(/^\/\//, '')
14
+
15
+ @root_packages.each do |pkg|
16
+ subpkg = pkg.subpackage(uri)
17
+ return subpkg unless subpkg.nil?
18
+ end
19
+
20
+ if @parent.nil?
21
+ return nil
22
+ else
23
+ return @parent.resolve(uri)
24
+ end
25
+ end
26
+
27
+ def root_packages
28
+ if @parent.nil?
29
+ return @root_packages
30
+ else
31
+ return @root_packages + @parent.root_packages
32
+ end
33
+ end
34
+
35
+ def root_package_names
36
+ root_packages.collect { |p| p.full_name }
37
+ end
38
+ end
39
+
40
+ class TargetResolver
41
+ # format: //package_path:target_name
42
+ TARGET_REGEX = /^:([^:]+)$/
43
+ PACKAGE_REGEX = /^\/\/([^:]+)$/
44
+ FULL_REGEX = /^\/\/([^:]+):([^:]+)$/
45
+
46
+ def initialize(package)
47
+ @package = package
48
+ @package_resolver = @package.package_resolver
49
+ end
50
+
51
+ def valid_uri?(path)
52
+ return FULL_REGEX === path || TARGET_REGEX === path || PACKAGE_REGEX === path
53
+ end
54
+
55
+ def resolve(uri)
56
+ package_path = nil
57
+ target_name = nil
58
+
59
+ if FULL_REGEX === uri
60
+ package_path = $1
61
+ target_name = $2
62
+ end
63
+
64
+ if TARGET_REGEX === uri
65
+ package_path = nil
66
+ target_name = $1
67
+ end
68
+
69
+ if PACKAGE_REGEX === uri
70
+ package_path = $1
71
+ target_name = nil
72
+ end
73
+
74
+ log "split_path(#{uri}) => package_path: #{package_path}, target_name: #{target_name}"
75
+
76
+ if package_path.nil?
77
+ package = @package
78
+ log "using default package '#{@package.uri}' for target '#{target_name}'"
79
+ else
80
+ package = @package_resolver.resolve(package_path)
81
+ raise "package '#{package_path}' not found in: #{@package_resolver.root_package_names.join(', ')}" if package.nil?
82
+ end
83
+
84
+ if target_name.nil?
85
+ return package[package.name]
86
+ else
87
+ return package[target_name]
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,117 @@
1
+ require 'filament/util/lazy_list'
2
+
3
+ # TODO quick fixes..
4
+ # switch to package.rb
5
+
6
+ module Filament
7
+ class TargetList < LazyList
8
+ def initialize(*args)
9
+ @resolver = $context[:target_resolver]
10
+ super(*args)
11
+ end
12
+ end
13
+
14
+ class Target
15
+ attr_reader :name, :package, :weak_deps, :deps, :deployables
16
+
17
+ def initialize(args, &block)
18
+ if args.is_a? Hash
19
+ h = args
20
+ @name = h[:name]
21
+ else
22
+ @name = args
23
+ h = {}
24
+ end
25
+
26
+ weak_deps = h[:weak_deps] || []
27
+ deps = h[:deps] || []
28
+
29
+ @weak_deps = TargetList.new(*weak_deps)
30
+ @deps = TargetList.new(*deps)
31
+
32
+ @package = h[:package] || $context[:this_package]
33
+ @invoked = false
34
+ @block = block
35
+ @outputs = {}
36
+ @deployables = []
37
+
38
+ raise 'targets must have a name' if @name.nil?
39
+ raise 'targets must have a package' if @package.nil?
40
+
41
+ @package << self
42
+ end
43
+
44
+ def uri
45
+ return "#{@package.uri}:#{@name}"
46
+ end
47
+
48
+ # for easy sorting
49
+ def <=>(other)
50
+ return (uri <=> other)
51
+ end
52
+
53
+ # walks tree of dependencies, returns a complete list
54
+ def flattened_deps
55
+ all = @deps.to_a.clone
56
+
57
+ fd = []
58
+ until all.empty?
59
+ d = all.pop
60
+ unless fd.include?(d)
61
+ fd << d
62
+ all += d.deps
63
+ end
64
+ end
65
+ return fd
66
+ end
67
+
68
+ # adds some :output to the given :tag
69
+ # if :deployable is true, also adds :output to deployables
70
+ def output(h)
71
+ tag = h[:tag]
72
+ output = h[:output]
73
+ if tag.respond_to?(:to_ary)
74
+ tag.to_ary.each do |t|
75
+ output(:tag => t, :output => output)
76
+ end
77
+ else
78
+ @outputs[tag] = output
79
+ end
80
+
81
+ @deployables << output if h[:deployable]
82
+ end
83
+
84
+ # returns the value in the output hash for the given tag
85
+ def get_output(tag)
86
+ invoke
87
+ return @outputs[tag]
88
+ end
89
+ alias :[] :get_output
90
+
91
+ # builds this specific target (and all dependencies)
92
+ def build
93
+ @package.build_context.execute do
94
+ invoke
95
+ end
96
+ end
97
+
98
+ # returns true if the target has completed
99
+ def done?
100
+ return @invoked
101
+ end
102
+
103
+ def invoke
104
+ return if done?
105
+ @invoked = true
106
+
107
+ puts ">>> BUILDING #{uri} (#{package.pathname}, #{self})"
108
+
109
+ @package.execute do
110
+ @weak_deps.each {|t| t.invoke}
111
+ @deps.each {|t| t.invoke}
112
+ instance_eval(&@block)
113
+ end
114
+ end
115
+ end
116
+ end
117
+
@@ -0,0 +1,39 @@
1
+ require 'filament/target'
2
+
3
+ module Filament
4
+ class FileList2 < FileList
5
+ def initialize(*args)
6
+ super(*args)
7
+ @target_resolver = $context[:target_resolver]
8
+ end
9
+
10
+ def resolve_filament_uris(*entries)
11
+ files = []
12
+ entries.each do |entry|
13
+ if entry.respond_to? :to_ary
14
+ resolve_uris(*entry.to_ary)
15
+ else
16
+ if @target_resolver.valid_uri?(entry)
17
+ target = @target_resolver.resolve(entry)
18
+ raise "target does not exist: #{entry}" if target.nil?
19
+ files << target[:default]
20
+ else
21
+ files << entry
22
+ end
23
+ end
24
+ end
25
+
26
+ # puts "resolve_uris(#{entries.join(', ')}) => #{files.join(':')}"
27
+ return files
28
+ end
29
+
30
+ def resolve
31
+ super
32
+ @items.uniq!
33
+ end
34
+
35
+ def include(*entries)
36
+ super(*resolve_filament_uris(*entries))
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,51 @@
1
+ require 'fileutils'
2
+ require 'pathname'
3
+
4
+ module Filament
5
+ def cp_r_if(src, dest, &block)
6
+ src_p = Pathname.new(src)
7
+ dest_p = Pathname.new(dest)
8
+
9
+ if yield src_p.to_s
10
+ dest_p = dest_p + src_p.basename if dest_p.exist? and dest_p.directory?
11
+
12
+ if src_p.directory?
13
+ if dest_p.exist?
14
+ raise "will not replace file with directory: #{dest_p}" unless dest_p.directory?
15
+ else
16
+ FileUtils.mkdir(dest_p)
17
+ end
18
+
19
+ src_p.children.each do |src_child_p|
20
+ relative = src_child_p.relative_path_from(src_p)
21
+ dest_child_p = dest_p + relative
22
+ cp_r_if(src_child_p, dest_child_p, &block)
23
+ end
24
+ else
25
+ log "copying #{src_p} to #{dest_p}"
26
+ FileUtils.cp_r(src_p, dest_p)
27
+ end
28
+ else
29
+ log "skipping #{src_p}"
30
+ end
31
+ end
32
+
33
+ # returns first parent of package_dir to contain a root_file
34
+ def self.find_dir(package_dir, *files)
35
+ p = Pathname.new(package_dir)
36
+
37
+ until p.root? do
38
+ if p.directory?
39
+ files.each do |file|
40
+ r = p + file
41
+ log "checking for #{r}"
42
+ return p.realpath if r.file?
43
+ end
44
+ end
45
+
46
+ p = p.parent
47
+ end
48
+
49
+ raise "Root directory not found for '#{package_dir}'"
50
+ end
51
+ end
@@ -0,0 +1,74 @@
1
+ class LazyList
2
+ attr_accessor :resolver
3
+
4
+ def initialize(*entries)
5
+ raise "resolver must be set by subclass." if @resolver.nil?
6
+
7
+ @unresolved = []
8
+ @resolved = []
9
+
10
+ entries.each do |entry|
11
+ include(entry)
12
+ end
13
+ end
14
+
15
+ def include(entry_name)
16
+ if entry_name.respond_to?(:to_ary)
17
+ entry_name.to_ary.each do |t|
18
+ include(t)
19
+ end
20
+ else
21
+ if entry_resolved?(entry_name)
22
+ @resolved << entry_name
23
+ else
24
+ @unresolved << entry_name
25
+ end
26
+ end
27
+ return self
28
+ end
29
+ alias :<< :include
30
+
31
+ def length
32
+ return @unresolved.size + @resolved.size
33
+ end
34
+ alias :size :length
35
+
36
+ def empty?
37
+ return length == 0
38
+ end
39
+
40
+ def entry_resolved?(entry_name)
41
+ return !entry_name.is_a?(String)
42
+ end
43
+
44
+ def resolve_entry(entry_name)
45
+ return @resolver.resolve(entry_name)
46
+ end
47
+
48
+ def resolve
49
+ until @unresolved.empty?
50
+ entry_name = @unresolved.pop
51
+ entry = resolve_entry(entry_name)
52
+
53
+ raise "entry '#{entry_name}' could not be resolved" if entry.nil?
54
+ @resolved << entry
55
+ end
56
+ end
57
+
58
+ def each(&block)
59
+ resolve
60
+ @resolved.each(&block)
61
+ return nil
62
+ end
63
+
64
+ def collect(&block)
65
+ resolve
66
+ @resolved.collect(&block)
67
+ end
68
+
69
+ def to_a
70
+ resolve
71
+ return @resolved.clone
72
+ end
73
+ alias :to_ary :to_a
74
+ end
@@ -0,0 +1,57 @@
1
+ require 'pathname'
2
+
3
+ require 'filament/package'
4
+ require 'filament/resolver'
5
+
6
+ module Filament
7
+ class Workspace
8
+ attr_reader :package_resolver, :realpath
9
+
10
+ def initialize(path)
11
+ @realpath = Pathname.new(path).realpath
12
+ # stores Pathname#realpath for all packages in this workspace
13
+ @realpath_package_cache = {}
14
+
15
+ @package_resolver = PackageResolver.new
16
+
17
+ # create root_package for this workspace
18
+ @root_package = Package.new(
19
+ :realpath => @realpath,
20
+ :parent => nil,
21
+ :workspace => self,
22
+ :package_resolver => @package_resolver)
23
+ end
24
+
25
+ def package_for_realpath(realpath)
26
+ return nil if realpath.nil?
27
+ realpath_p = Pathname.new(realpath)
28
+
29
+ raise "realpath must be absolute." unless realpath_p.absolute?
30
+
31
+ if @realpath_package_cache.key?(realpath_p)
32
+ return realpath_package_cache[realpath_p]
33
+ end
34
+
35
+ relative_path_p = realpath_p.relative_path_from(@realpath)
36
+ package = @root_package + relative_path_p
37
+ @realpath_package_cache[realpath_p] = package
38
+
39
+ return package
40
+ end
41
+
42
+ def resolve_package(uri)
43
+ @package_resolver.resolve_package(uri)
44
+ end
45
+
46
+ def load_tasks(package=nil)
47
+ package ||= @root_package
48
+
49
+ pn = package.pathname + 'tasks.rb'
50
+ load pn.realpath if pn.exist?
51
+
52
+ package.subpackages.each do |subpkg|
53
+ load_tasks(subpkg)
54
+ end
55
+ end
56
+ end
57
+ end
data/lib/filament.rb ADDED
@@ -0,0 +1,199 @@
1
+ require 'pathname'
2
+ require 'set'
3
+
4
+ # rake stuff
5
+ begin
6
+ require 'rake'
7
+ rescue LoadError
8
+ require 'rubygems'
9
+ require_gem 'rake'
10
+ end
11
+ require 'rake/clean'
12
+
13
+ require 'filament/workspace'
14
+ require 'filament/platform'
15
+ require 'filament/plugins'
16
+ require 'filament/package'
17
+ require 'filament/target'
18
+ require 'filament/artifact'
19
+
20
+ require 'filament/util/filelist2'
21
+ require 'filament/util/fileutils'
22
+
23
+ module Filament
24
+ def log(msg)
25
+ puts msg if $verbose
26
+ end
27
+
28
+ def verbose(on)
29
+ RakeFileUtils.verbose(false)
30
+ $verbose = on
31
+ # if on
32
+ # trace_var :$context, lambda { |c|
33
+ # puts "$context is now #{c}"
34
+ # }
35
+ # else
36
+ # untrace_var :$context
37
+ # end
38
+ end
39
+
40
+ $actions ||= []
41
+
42
+ class Application
43
+ OPTIONS = [
44
+ ['--trace', '-t', GetoptLong::NO_ARGUMENT,
45
+ "Turn on invoke/execute tracing"],
46
+ ]
47
+
48
+ TARGET_ACTIONS = {
49
+ :build => Proc.new { |targets|
50
+ targets.each { |target| target.build }
51
+ },
52
+ :clobber => Proc.new { |targets|
53
+ targets.each { |target| target.package.clobber }
54
+ },
55
+ :execute => Proc.new { |targets|
56
+ targets.each do |target|
57
+ target.build
58
+ block = target[:execute]
59
+ target.package.build_context.execute(&block) unless block.nil?
60
+ end
61
+ },
62
+ }
63
+
64
+ PACKAGE_ACTIONS = {
65
+
66
+ }
67
+
68
+ def collect_other_args
69
+ targets = []
70
+ packages = []
71
+ actions = []
72
+ vars = {}
73
+ ARGV.each do |arg|
74
+ if arg =~ /^(\w+)=(.*)$/
75
+ vars[$1] = $2
76
+ elsif arg =~ /^[^\/^:]/
77
+ actions << arg.to_sym
78
+ else
79
+ targets << arg
80
+ if arg =~ /^\/[^:]/
81
+ packages << arg
82
+ end
83
+ end
84
+ end
85
+ return { :vars => vars,
86
+ :targets => targets,
87
+ :packages => packages,
88
+ :actions => actions }
89
+ end
90
+
91
+ def do_option(opt, value)
92
+ case opt
93
+ when '--trace'
94
+ $trace = true
95
+ verbose(true)
96
+ else
97
+ fail "Unknown option: #{opt}"
98
+ end
99
+ end
100
+
101
+ def command_line_options
102
+ OPTIONS.collect { |lst| lst[0..-2] }
103
+ end
104
+
105
+ def handle_options
106
+ opts = GetoptLong.new(*command_line_options)
107
+ opts.each { |opt, value| do_option(opt, value) }
108
+ end
109
+
110
+ def run(&block)
111
+ verbose(false)
112
+
113
+ handle_options
114
+
115
+ begin
116
+ other_args = collect_other_args
117
+ vars = other_args[:vars]
118
+
119
+ vars.each do |key, val|
120
+ ENV[key] = val
121
+ end
122
+
123
+ actions = $actions + other_args[:actions]
124
+ actions.compact!
125
+
126
+ workspace_path = ENV['WR'] || Filament::find_dir(Pathname.pwd, '.workspace')
127
+ $workspace = Workspace.new(workspace_path)
128
+ $target_platform = (ENV['TARGET_PLATFORM'] || :mpp_sdk || :i860 || :wt2_2).to_sym
129
+
130
+ build_type = (ENV['BUILD_TYPE'] || :DBG).to_sym
131
+ dirs = { :TEST => 'test', # this is a folder for testing targets to use
132
+ :DBG => 'dbg', # final jars, binaries, etc. are placed in these
133
+ :OPT => 'opt' } # this is for obfuscated, compressed, releasable versions
134
+
135
+ raise "unknown build type: '#{build_type}'" unless dirs.key?(build_type)
136
+
137
+ $build_dir_prefix = "#{dirs[build_type]}/#{$target_platform.to_s}"
138
+
139
+ pn = Pathname.new(__FILE__).parent.parent + 'plugins'
140
+ Filament::load_plugins(pn.realpath)
141
+
142
+ $workspace.load_tasks
143
+ this_package = $workspace.package_for_realpath(Pathname.pwd.realpath)
144
+
145
+ this_package.execute do
146
+ targets = TargetList.new(*other_args[:targets])
147
+ packages = PackageList.new(*other_args[:packages])
148
+
149
+ if targets.empty?
150
+ log "assuming default target of '#{this_package.uri}'"
151
+ targets.include(this_package.uri)
152
+ end
153
+
154
+ if packages.empty?
155
+ log "assuming default package of '#{this_package.uri}'"
156
+ packages.include(this_package.uri)
157
+ end
158
+
159
+ if block.nil?
160
+ target_blocks = []
161
+ package_blocks = []
162
+
163
+ actions.each do |action|
164
+ if TARGET_ACTIONS.key?(action)
165
+ target_blocks << TARGET_ACTIONS[action]
166
+ elsif PACKAGE_ACTIONS.key?(action)
167
+ package_blocks << PACKAGE_ACTIONS[action]
168
+ else
169
+ raise "Unknown action: #{action}"
170
+ end
171
+ end
172
+
173
+ # some debug
174
+ root_packages = $context[:package_resolver].root_packages.collect { |p| p.full_name }
175
+ puts "ACTIONS: #{actions.join(', ')}"
176
+ puts "PACKAGE_RESOLVER: #{root_packages.join(', ')}"
177
+
178
+ target_blocks.each { |b| b.call(targets) }
179
+ package_blocks.each { |b| b.call(packages) }
180
+ else
181
+ targets.each(&block)
182
+ end
183
+ end
184
+ rescue Exception => ex
185
+ puts "Build aborted!"
186
+ puts ex.message
187
+ if $trace
188
+ puts ex.backtrace.join("\n")
189
+ else
190
+ puts ex.backtrace.find {|str| str =~ /rakefile.rb/ } || ""
191
+ end
192
+ exit(1)
193
+ end
194
+ end
195
+ end
196
+ end
197
+
198
+ include Filament::Platform
199
+ include Filament