bake 0.1.2 → 0.2.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 (54) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +7 -0
  6. data/Gemfile.lock +40 -0
  7. data/README.md +99 -0
  8. data/Rakefile +6 -0
  9. data/bake.gemspec +25 -0
  10. data/bin/bake +25 -10
  11. data/lib/bake.rb +21 -140
  12. data/lib/bake/book.rb +79 -0
  13. data/lib/bake/command.rb +29 -0
  14. data/lib/bake/command/invoke.rb +67 -0
  15. data/lib/bake/command/list.rb +76 -0
  16. data/lib/bake/command/top.rb +111 -0
  17. data/lib/bake/context.rb +103 -110
  18. data/lib/bake/loader.rb +82 -0
  19. data/lib/bake/loaders.rb +110 -0
  20. data/lib/bake/recipe.rb +109 -0
  21. data/lib/bake/version.rb +23 -0
  22. metadata +73 -85
  23. data/CHANGELOG +0 -38
  24. data/CONCEPTS +0 -54
  25. data/MIT-LICENSE +0 -21
  26. data/README +0 -38
  27. data/REFERENCE +0 -2
  28. data/TUTORIAL +0 -128
  29. data/lib/bake/addon.rb +0 -20
  30. data/lib/bake/configuration.rb +0 -126
  31. data/lib/bake/extensions.rb +0 -3
  32. data/lib/bake/extensions/class.rb +0 -11
  33. data/lib/bake/extensions/object.rb +0 -22
  34. data/lib/bake/extensions/string.rb +0 -22
  35. data/lib/bake/file_target.rb +0 -19
  36. data/lib/bake/plugin.rb +0 -49
  37. data/lib/bake/plugins/cpp.rb +0 -188
  38. data/lib/bake/plugins/cpp/darwin.rb +0 -26
  39. data/lib/bake/plugins/cpp/gcc.rb +0 -14
  40. data/lib/bake/plugins/cpp/gcc_toolset_base.rb +0 -101
  41. data/lib/bake/plugins/cpp/msvc.rb +0 -118
  42. data/lib/bake/plugins/cpp/qt.rb +0 -53
  43. data/lib/bake/plugins/cpp/toolset_base.rb +0 -56
  44. data/lib/bake/plugins/macro.rb +0 -18
  45. data/lib/bake/plugins/runner.rb +0 -40
  46. data/lib/bake/plugins/system.rb +0 -30
  47. data/lib/bake/project.rb +0 -91
  48. data/lib/bake/project_loader.rb +0 -116
  49. data/lib/bake/system_utils.rb +0 -42
  50. data/lib/bake/target.rb +0 -155
  51. data/lib/bake/toolset.rb +0 -25
  52. data/lib/bake_version.rb +0 -5
  53. data/test/test_bake.rb +0 -2
  54. data/test/test_configuration.rb +0 -58
@@ -1,118 +0,0 @@
1
- require 'fileutils'
2
-
3
- module Bake
4
- module Plugins
5
- module Cpp
6
- class Msvc < ToolsetBase
7
- def output(target)
8
- if target.is_a?(Object)
9
- return obj_fn(target)
10
- elsif target.is_a?(Library)
11
- return lib_fn(target)
12
- elsif target.is_a?(Executable)
13
- return exe_fn(target)
14
- end
15
- return nil
16
- end
17
-
18
- def compile(obj)
19
- src = obj.src
20
- output = obj_fn(obj)
21
- flags = build_flags('/I', obj[:incdirs] + obj[:sysincdirs]) +
22
- build_flags('/D', obj[:defines])
23
- flags += obj[:cflags].join(' ')
24
- flags += ' /MD'
25
- flags += ' /EHsc' if obj[:exceptions?]
26
- flags += ' /GR' if obj[:rtti?]
27
- flags += obj[:optimizations?] ? ' /O2' : ' /Od'
28
- flags += ' /Z7' if obj[:debug_symbols?]
29
- sys.sh("cl /nologo #{flags} /c /Fo#{output} /Tp#{src}")
30
- end
31
-
32
- def ar(lib)
33
- obj_str, flags = process_inputs(lib)
34
-
35
- output = lib_fn(lib)
36
- if lib[:libtype] == 'dynamic'
37
- flags += ' /debug' if lib[:debug_symbols?]
38
- sys.sh("link /nologo /dll #{flags} /out:#{output[1]} #{obj_str}")
39
- # need to touch the .exp file because it sometimes
40
- # doesn't get updated
41
- sys.touch(output[2])
42
- else
43
- sys.sh("lib /nologo /out:#{output} #{obj_str}")
44
- end
45
- end
46
-
47
- def link(exe)
48
- obj_str, flags = process_inputs(exe)
49
-
50
- output = exe_fn(exe)
51
- flags += ' /debug' if exe[:debug_symbols?]
52
- sys.sh("link /nologo /subsystem:console #{flags} /out:#{output} #{obj_str}")
53
- end
54
-
55
- def obj_fn(obj)
56
- src = obj.src
57
- basename = File.basename(src, File.extname(src)) + '.obj'
58
- return File.join(obj[:outdir], basename)
59
- end
60
-
61
- def lib_fn(lib)
62
- if lib[:libtype] == 'dynamic'
63
- return [File.join(lib[:outdir], "#{lib.name}.lib"),
64
- File.join(lib[:outdir], "#{lib.name}.dll"),
65
- File.join(lib[:outdir], "#{lib.name}.exp")]
66
- end
67
- return File.join(lib[:outdir], "#{lib.name}.lib")
68
- end
69
-
70
- def exe_fn(exe)
71
- return File.join(exe[:outdir], exe.name + '.exe')
72
- end
73
-
74
- private
75
- def build_flags(flag, args)
76
- return args.inject('') { |str, arg| str + "#{flag}#{arg} " }
77
- end
78
-
79
- def process_inputs(target)
80
- output = output(target)
81
- obj_str = ''
82
- libdirs = []
83
- static_lib = target.is_a?(Library) && target[:libtype] == 'static'
84
- target.deps.each do |input|
85
- if input.is_a?(Object)
86
- fn = obj_fn(input)
87
- obj_str += fn + ' '
88
- elsif input.is_a?(SystemLibrary)
89
- if !static_lib
90
- obj_str += input.file + '.lib '
91
- end
92
- elsif input.is_a?(Library)
93
- if !static_lib
94
- if input[:libtype] == 'dynamic'
95
- fn = lib_fn(input)[0]
96
- else
97
- fn = lib_fn(input)
98
- end
99
- libdir = File.dirname(fn)
100
- libdirs << libdir if !libdirs.include?(libdir)
101
- obj_str += File.basename(fn) + ' '
102
- end
103
- end
104
- end
105
-
106
- if !static_lib
107
- target[:libs].each { |lib| obj_str += lib + '.lib ' }
108
- end
109
- libdirs.concat(target[:libdirs])
110
- flags = build_flags('/LIBPATH:', libdirs)
111
-
112
- return [ obj_str, flags ]
113
- end
114
- end
115
- end
116
- end
117
- end
118
-
@@ -1,53 +0,0 @@
1
- require 'bake/toolset'
2
- require 'fileutils'
3
-
4
- module Bake
5
- module Plugins
6
- module Cpp
7
- module Qt
8
- class Moc < Toolset
9
- def initialize(sys)
10
- super
11
- command(:moc)
12
- end
13
-
14
- def moc(context, *srcs)
15
- return srcs.collect do |src|
16
- file_target = FileTarget.new(
17
- context.current, toolset, src)
18
- MocFile.new(context.current, self, file_target)
19
- end
20
- end
21
-
22
- def build(target)
23
- if !target.is_a?(MocFile)
24
- raise "unknown target '#{target}'"
25
- end
26
- src = target.src
27
- sys.sh("moc -o #{target.path} #{target.src}")
28
- end
29
- end
30
-
31
- class MocFile < Source
32
- def src
33
- return @source.path
34
- end
35
-
36
- def path
37
- src = @source.path
38
- ext = File.extname(src)
39
- basename = File.basename(src, ext) + '.moc' + ext
40
- return File.join(get(:outdir), basename)
41
- end
42
-
43
- alias :products :path
44
-
45
- def build
46
- toolset.build(self)
47
- end
48
- end
49
- end
50
- end
51
- end
52
- end
53
-
@@ -1,56 +0,0 @@
1
- require 'bake/toolset'
2
- require 'fileutils'
3
- require 'set'
4
-
5
- module Bake
6
- module Plugins
7
- module Cpp
8
- class ToolsetBase < Toolset
9
- module Object
10
- def products
11
- return toolset.obj_fn(self)
12
- end
13
- end
14
-
15
- module Library
16
- def products
17
- return toolset.lib_fn(self)
18
- end
19
- end
20
-
21
- module Executable
22
- def products
23
- return toolset.exe_fn(self)
24
- end
25
- end
26
-
27
- def initialize(sys)
28
- super
29
- constructor :syslib, Cpp::SystemLibrary
30
- constructor :lib, Cpp::Library
31
- constructor :exe, Cpp::Executable
32
- end
33
-
34
- def build(target)
35
- if target.is_a?(Cpp::Object)
36
- compile(target)
37
- elsif target.is_a?(Cpp::Library)
38
- ar(target)
39
- elsif target.is_a?(Cpp::Executable)
40
- link(target)
41
- else
42
- raise "unknown Cpp target of class '#{target.class}"
43
- end
44
- end
45
-
46
- def output_files(target)
47
- out = output(target)
48
- return [] if !out
49
- return out.to_a if out.respond_to?(:to_a)
50
- return [ out ]
51
- end
52
- end
53
- end
54
- end
55
- end
56
-
@@ -1,18 +0,0 @@
1
- require 'bake/addon'
2
-
3
- module Bake
4
- module Plugins
5
- class Macro
6
- include Addon
7
-
8
- def initialize
9
- command(:macro)
10
- end
11
-
12
- def macro(context, name, &block)
13
- context.register(name, &block)
14
- end
15
- end
16
- end
17
- end
18
-
@@ -1,40 +0,0 @@
1
- require 'bake/target'
2
- require 'fileutils'
3
-
4
- module Bake
5
- module Plugins
6
- class Runner < Target
7
- def post_initialize(exe)
8
- @exe = nil
9
- dep(exe)
10
- end
11
-
12
- def add_dep(target)
13
- @exe = target if !@exe
14
- deps << target
15
- end
16
-
17
- def path
18
- return @exe.path if @exe.is_a?(FileTarget)
19
- return @exe.run_command
20
- end
21
-
22
- alias :id :path
23
-
24
- def build
25
- toolset.sys.sh(path)
26
- toolset.sys.touch(products)
27
- end
28
-
29
- def products
30
- return File.join(get(:outdir), output_basename)
31
- end
32
-
33
- private
34
- def output_basename
35
- return path.basename + '.success'
36
- end
37
- end
38
- end
39
- end
40
-
@@ -1,30 +0,0 @@
1
- require 'bake/toolset'
2
-
3
- module Bake
4
- module Plugins
5
- class System < Toolset
6
- def initialize(sys)
7
- super
8
- command(:glob)
9
- constructor(:run, Plugins::Runner)
10
- end
11
-
12
- def glob(context, *args)
13
- has_options = args.last.respond_to?(:to_hash)
14
- options = has_options ? args.pop.to_hash : {}
15
- exclude = options[:exclude].make_array
16
- files = []
17
- args.each do |pat|
18
- matches = Dir[pat]
19
- matches.each do |file|
20
- if !exclude.find { |exc| File.fnmatch(exc, file) }
21
- files.push(file)
22
- end
23
- end
24
- end
25
- return files
26
- end
27
- end
28
- end
29
- end
30
-
@@ -1,91 +0,0 @@
1
- require 'bake/target'
2
-
3
- module Bake
4
- class Project < Target
5
- attr_reader :loader
6
-
7
- def post_initialize(loader)
8
- @loader = loader
9
- @mappings = {}
10
- end
11
-
12
- def current_project
13
- return self
14
- end
15
-
16
- def parent_project
17
- return parent ? parent.current_project : nil
18
- end
19
-
20
- def child_project(name)
21
- child = children.find do |child|
22
- child.name == name && child.is_a?(Project)
23
- end
24
- return child || loader.load_project(self, name)
25
- end
26
-
27
- def map(mappings)
28
- @mappings.merge!(mappings)
29
- end
30
-
31
- # Returns the target found at +path+ relative to this project.
32
- # Raises a +RuntimeError+ if no such target is found.
33
- #
34
- # The +path+ argument is of the form:
35
- # <dir>:<name> | <name> | <dir>
36
- def resolve(path)
37
- search_projects = ([ self ] + get(:search_projects))
38
- index = path.index(':')
39
- if index
40
- # search for a fully qualified target given by dir:name
41
- dir = path.slice(0, index)
42
- name = path.slice(index + 1, path.length - index - 1)
43
- else
44
- if !path.index('/') && path != '.' && path != '..'
45
- # search for target named by path in search_projects
46
- target = nil
47
- search_projects.each do |proj|
48
- target = proj.find_target(path)
49
- return target if target
50
- end
51
- end
52
- # search for a project at given path
53
- dir = path
54
- name = nil
55
- end
56
-
57
- # iterate the search_projects looking for target given by dir:name
58
- search_projects.each do |proj|
59
- dir.split('/').each do |el|
60
- if el == '.'
61
- next
62
- elsif el == '..'
63
- proj = proj.parent_project
64
- break if !proj
65
- else
66
- begin
67
- proj = proj.child_project(el)
68
- rescue ProjectLoadError
69
- proj = nil
70
- break
71
- end
72
- end
73
- end
74
- # found a project at dir, find a child named name
75
- if proj
76
- return proj if !name
77
- target = proj.find_target(name)
78
- return target if target
79
- end
80
- end
81
- raise "invalid target path '#{path}'"
82
- end
83
-
84
- protected
85
- def find_target(name)
86
- return resolve(@mappings[name]) if @mappings.has_key?(name)
87
- return children.find { |child| child.name == name }
88
- end
89
- end
90
- end
91
-
@@ -1,116 +0,0 @@
1
- require 'bake/target'
2
- require 'bake/project'
3
-
4
- module Bake
5
- class ProjectLoadError < RuntimeError; end
6
-
7
- class ProjectLoader
8
- attr_reader :invok_project
9
-
10
- def initialize(context, invok_dir, props)
11
- @context = context
12
- load_root_project(invok_dir, props)
13
- load_invok_project
14
- end
15
-
16
- # Loads a child project of the project given by +parent+. It does this
17
- # by searching for directory called +name+ in +parent+'s +:cwdir+.
18
- # Raises a +ProjectLoadError+ if no such directory exists. If the
19
- # directory contains a bakefile, it will be processed in this
20
- # +ProjectLoader+'s context.
21
- def load_project(parent, name)
22
- dir = File.join(parent[:cwdir], name)
23
- if !File.directory?(dir)
24
- raise ProjectLoadError, "no such directory '#{dir}'"
25
- end
26
- proj = Project.new(parent, @context.default_toolset, self)
27
- proj.name = name
28
- proj.opt(:projname => name)
29
- proj.opt(:cwdir => dir)
30
- process(proj)
31
- return proj
32
- end
33
-
34
- private
35
- def load_root_project(invok_dir, props)
36
- project = nil
37
- dir = invok_dir
38
- @invok_path = []
39
- while true
40
- bakefile = File.join(dir, 'root.bake')
41
- if File.exists?(bakefile)
42
- project = Project.new(nil, @context.default_toolset, self)
43
- project.opt(:rootdir => dir)
44
- project.opt(:projname => 'root')
45
- project.opt(:cwdir => dir)
46
- project.opt(:outdir => '${cwdir}')
47
- props.each_pair { |key, val| project.opt(key => val) }
48
- break
49
- end
50
-
51
- parent_dir = File.dirname(dir)
52
- raise 'root.bake not found' if parent_dir == dir
53
- @invok_path << File.basename(dir)
54
- dir = parent_dir
55
- end
56
-
57
- @root_project = project
58
- process(@root_project)
59
- end
60
-
61
- def load_invok_project
62
- project = @root_project
63
- @invok_path.reverse_each do |name|
64
- project = load_project(project, name)
65
- end
66
- @invok_project = project
67
- return project
68
- end
69
-
70
- def process(proj)
71
- if proj.parent
72
- dir = proj[:cwdir]
73
- bakefile = File.join(dir, 'sub.bake')
74
- if File.exists?(bakefile)
75
- Dir.chdir(dir) { eval_bakefile(proj, bakefile) }
76
- end
77
- else
78
- raise 'internal error' if !@root_project.equal?(proj)
79
- Dir.chdir(@root_project[:cwdir]) do
80
- if config_bakefile
81
- eval_bakefile(@root_project, config_bakefile)
82
- end
83
- eval_bakefile(@root_project, root_bakefile)
84
- end
85
- end
86
- end
87
-
88
- def eval_bakefile(project, bakefile)
89
- @context.context_eval(project, File.read(bakefile), bakefile)
90
- end
91
-
92
- def root_bakefile
93
- return @root_bakefile if @root_bakefile
94
- @root_bakefile = File.join(@root_project[:cwdir], 'root.bake')
95
- return @root_bakefile
96
- end
97
-
98
- def config_bakefile
99
- return @config_bakefile if @config_bakefile
100
- bakefile = File.join(@root_project[:cwdir], 'config.bake')
101
- if !File.exists?(bakefile)
102
- home = ENV['HOME']
103
- if home
104
- bakefile = File.join(home, 'config.bake')
105
- if !File.exists?(bakefile)
106
- bakefile = nil
107
- end
108
- else
109
- bakefile = nil
110
- end
111
- end
112
- return @config_bakefile = bakefile
113
- end
114
- end
115
- end
116
-