rubuild-core 0.0.3
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.
- data/.autotest +23 -0
- data/History.txt +11 -0
- data/Manifest.txt +35 -0
- data/README.rdoc +43 -0
- data/Rakefile +10 -0
- data/bin/rubuild +18 -0
- data/examples/printargs +5 -0
- data/lib/rubuild.rb +14 -0
- data/lib/rubuild/build.rb +4 -0
- data/lib/rubuild/build/context.rb +78 -0
- data/lib/rubuild/build/dep.rb +359 -0
- data/lib/rubuild/build/factory.rb +30 -0
- data/lib/rubuild/build/simple.rb +3 -0
- data/lib/rubuild/build/simple/context.rb +90 -0
- data/lib/rubuild/build/simple/dep.rb +367 -0
- data/lib/rubuild/build/simple/factory.rb +17 -0
- data/lib/rubuild/env.rb +113 -0
- data/lib/rubuild/env/location.rb +105 -0
- data/lib/rubuild/env/provider.rb +51 -0
- data/lib/rubuild/env/requirer.rb +66 -0
- data/lib/rubuild/load.rb +3 -0
- data/lib/rubuild/load/info.rb +52 -0
- data/lib/rubuild/load/loader.rb +75 -0
- data/lib/rubuild/load/namespace.rb +117 -0
- data/lib/rubuild/options.rb +34 -0
- data/lib/rubuild/util.rb +11 -0
- data/test/test_dep.rb +176 -0
- data/test/test_env.rb +91 -0
- data/test/test_env_location.rb +68 -0
- data/test/test_env_provider.rb +45 -0
- data/test/test_env_requirer.rb +52 -0
- data/test/test_load_info.rb +63 -0
- data/test/test_load_loader.rb +119 -0
- data/test/test_load_namespace.rb +43 -0
- data/test/test_options.rb +32 -0
- metadata +159 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
module Rubuild
|
2
|
+
module Build
|
3
|
+
module Simple
|
4
|
+
class Factory
|
5
|
+
def create_context
|
6
|
+
Rubuild::Build::Simple::Context.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_dep(command, disp, *args)
|
10
|
+
dep = Rubuild::Build::Simple::Dep.new(command, disp)
|
11
|
+
dep.args = args
|
12
|
+
dep
|
13
|
+
end
|
14
|
+
end # Rubuild::Build::Simple::Factory
|
15
|
+
end # Rubuild::Build::Simple
|
16
|
+
end # Rubuild::Build
|
17
|
+
end # Rubuild
|
data/lib/rubuild/env.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'rubuild/env/location'
|
2
|
+
require 'rubuild/env/provider'
|
3
|
+
require 'rubuild/env/requirer'
|
4
|
+
|
5
|
+
module Rubuild
|
6
|
+
## Rubuild::Env
|
7
|
+
# Environment of Rubuild source modules.
|
8
|
+
class Env
|
9
|
+
## Rubuild::Env::Error
|
10
|
+
# Superclass of all error exceptions raised by Rubuild::Env.
|
11
|
+
class Error < StandardError
|
12
|
+
# The environment associated with this error.
|
13
|
+
Safer::IVar.instance_variable(self, :env)
|
14
|
+
Safer::IVar.export_reader(self, :env)
|
15
|
+
def initialize(env, message)
|
16
|
+
super(message)
|
17
|
+
self.rubuild_env_error__env = env
|
18
|
+
end # Rubuild::Env::Error#initialize
|
19
|
+
|
20
|
+
## Rubuild::Env::Error::Key
|
21
|
+
# Superclass of error exceptions having to do with environment registry.
|
22
|
+
class Key < Error
|
23
|
+
# key in environment registry.
|
24
|
+
Safer::IVar.instance_variable(self, :key)
|
25
|
+
Safer::IVar.export_reader(self, :key)
|
26
|
+
def initialize(env, key, message)
|
27
|
+
super(env, message)
|
28
|
+
self.rubuild_env_error_key__key = key
|
29
|
+
end # Rubuild::Env::Error::Key#initialize
|
30
|
+
|
31
|
+
## Rubuild::Env::Error::Key::Full
|
32
|
+
# Attempt to provide the same key to the registry twice.
|
33
|
+
class Full < Key
|
34
|
+
Safer::IVar.instance_variable(self, :provided_location)
|
35
|
+
Safer::IVar.export_reader(self, :provided_location)
|
36
|
+
Safer::IVar.instance_variable(self, :providing_location)
|
37
|
+
Safer::IVar.export_reader(self, :providing_location)
|
38
|
+
def initialize(env, key, provided_location, providing_location)
|
39
|
+
super(
|
40
|
+
env, key,
|
41
|
+
"Key #{key.dump} already exists in registry at " +
|
42
|
+
"#{provided_location.found_dep.name} while providing " +
|
43
|
+
"#{providing_location.found_dep.name}")
|
44
|
+
self.rubuild_env_error_key_full__provided_location =
|
45
|
+
provided_location
|
46
|
+
self.rubuild_env_error_key_full__providing_location =
|
47
|
+
providing_location
|
48
|
+
end # Rubuild::Env::Error::Key::Full#initialize
|
49
|
+
end # Rubuild::Env::Error::Key::Full
|
50
|
+
|
51
|
+
## Rubuild::Env::Error::Key::Empty
|
52
|
+
# Key does not exist in registry on require.
|
53
|
+
class Empty < Key
|
54
|
+
Safer::IVar.instance_variable(self, :requiring_location)
|
55
|
+
Safer::IVar.export_reader(self, :requiring_location)
|
56
|
+
def initialize(env, key, requiring_location)
|
57
|
+
super(
|
58
|
+
env, key,
|
59
|
+
"Key #{key.dump} does not exist in registry " +
|
60
|
+
"for #{requiring_location.found_dep.name}.")
|
61
|
+
self.rubuild_env_error_key_empty__requiring_location =
|
62
|
+
requiring_location
|
63
|
+
end # Rubuild::Env::Error::Key::Empty#initialize
|
64
|
+
end # Rubuild::Env::Error::Key::Empty
|
65
|
+
end # Rubuild::Env::Error::Key
|
66
|
+
end # Rubuild::Env::Error
|
67
|
+
|
68
|
+
## Rubuild::Env
|
69
|
+
# Rubuild::Build::Factory object for this Rubuild::Env.
|
70
|
+
Safer::IVar.instance_variable(self, :build_factory)
|
71
|
+
Safer::IVar.export_reader(self, :build_factory)
|
72
|
+
# Keys supplied by 'provide'
|
73
|
+
Safer::IVar.instance_variable(self, :providing)
|
74
|
+
|
75
|
+
# Create a Rubuild::Env object.
|
76
|
+
# [+build_factory+] Rubuild::Build::Factory derived object, which will
|
77
|
+
# integrate the dependency objects in this Rubuild::Env.
|
78
|
+
def initialize(build_factory)
|
79
|
+
self.rubuild_env__build_factory = build_factory
|
80
|
+
self.rubuild_env__providing = Hash.new
|
81
|
+
end # Rubuild::Env#initialize
|
82
|
+
|
83
|
+
def provide(key, providing)
|
84
|
+
if self.rubuild_env__providing.has_key?(key)
|
85
|
+
raise(
|
86
|
+
Error::Key::Full.new(
|
87
|
+
self, key, self.rubuild_env__providing[key], providing))
|
88
|
+
end
|
89
|
+
self.rubuild_env__providing[key] = providing
|
90
|
+
end
|
91
|
+
def has_provider?(key)
|
92
|
+
self.rubuild_env__providing.has_key?(key)
|
93
|
+
end
|
94
|
+
def require(key, requiring)
|
95
|
+
providing = self.rubuild_env__providing[key]
|
96
|
+
if not providing
|
97
|
+
raise(Error::Key::Empty.new(self, key, requiring))
|
98
|
+
end
|
99
|
+
reqdep = self.rubuild_env__build_factory.create_dep(
|
100
|
+
self.method(:_provide_require),
|
101
|
+
"Rubuild::Env::require(#{key.dump}," +
|
102
|
+
"#{providing.found_dep.name.dump}, " +
|
103
|
+
"#{requiring.found_dep.name.dump}",
|
104
|
+
providing, requiring)
|
105
|
+
reqdep.add_parent(providing.found_dep)
|
106
|
+
requiring.found_dep.add_parent(reqdep)
|
107
|
+
end
|
108
|
+
|
109
|
+
def _provide_require(dep, providing, requiring)
|
110
|
+
requiring.set_data(providing.data)
|
111
|
+
end
|
112
|
+
end # Rubuild::Env
|
113
|
+
end # Rubuild::Env
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module Rubuild
|
2
|
+
class Env
|
3
|
+
## Rubuild::Env::Location
|
4
|
+
# A loaded interface to a source module.
|
5
|
+
class Location
|
6
|
+
## Rubuild::Env::Location::Error
|
7
|
+
# Superclass of location-generated errors.
|
8
|
+
class Error < StandardError
|
9
|
+
Safer::IVar.instance_variable(self, :location)
|
10
|
+
Safer::IVar.export_reader(self, :location)
|
11
|
+
def initialize(location, message)
|
12
|
+
super(message)
|
13
|
+
self.rubuild_env_location_error__location = location
|
14
|
+
end
|
15
|
+
|
16
|
+
## Rubuild::Env::Location::Error::SetData
|
17
|
+
# errors that occur while setting data.
|
18
|
+
class SetData < Error
|
19
|
+
Safer::IVar.instance_variable(self, :newdata)
|
20
|
+
Safer::IVar.export_reader(self, :newdata)
|
21
|
+
def initialize(location, newdata, message)
|
22
|
+
super(location, message)
|
23
|
+
self.rubuild_env_location_error_setdata__newdata = newdata
|
24
|
+
end
|
25
|
+
|
26
|
+
## Rubuild::Env::Location::Error::SetData::Already
|
27
|
+
# attempt to set data twice.
|
28
|
+
class Already < SetData
|
29
|
+
def initialize(location, newdata)
|
30
|
+
super(
|
31
|
+
location, newdata,
|
32
|
+
"Attempt to set object data twice."
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
## Rubuild::Env::Location::Error::BuiltEmpty
|
39
|
+
# Did not locate object.
|
40
|
+
class BuiltEmpty < Error
|
41
|
+
def initialize(location)
|
42
|
+
super(location, "Finished building, but did not obtain data.")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
## Rubuild::Env::Location::Error::DataEmpty
|
47
|
+
# Attempt to access non-existent data.
|
48
|
+
class DataEmpty < Error
|
49
|
+
def initialize(location)
|
50
|
+
super(location, "Attempt to access data before it was set.")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
## Rubuild::Env::Location
|
56
|
+
Safer::IVar.instance_variable(self, :found_dep)
|
57
|
+
Safer::IVar.export_reader(self, :found_dep)
|
58
|
+
Safer::IVar.instance_variable(self, :data)
|
59
|
+
Safer::IVar.instance_variable(self, :have_data)
|
60
|
+
Safer::IVar.export_reader(self, :have_data)
|
61
|
+
Safer::IVar.instance_variable(self, :depfactory)
|
62
|
+
Safer::IVar.export_reader(self, :depfactory)
|
63
|
+
Safer::IVar.instance_variable(self, :name)
|
64
|
+
Safer::IVar.export_reader(self, :name)
|
65
|
+
def initialize(name, depfactory)
|
66
|
+
self.rubuild_env_location__name = name
|
67
|
+
self.rubuild_env_location__depfactory = depfactory
|
68
|
+
|
69
|
+
self.rubuild_env_location__found_dep =
|
70
|
+
self.rubuild_env_location__depfactory.create_dep(
|
71
|
+
self.method(:_found_depaction),
|
72
|
+
self.class.to_s + '#found#' + self.rubuild_env_location__name
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
def _found_depaction(dep)
|
77
|
+
# called when the "found_dep" is satisifed.
|
78
|
+
# ensure that data was found, and lose references to unneeded state
|
79
|
+
# variables.
|
80
|
+
self.rubuild_env_location__depfactory = nil
|
81
|
+
if ! self.rubuild_env_location__have_data
|
82
|
+
raise(Error::BuiltEmpty.new(self))
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def set_data(data)
|
87
|
+
if self.rubuild_env_location__have_data
|
88
|
+
raise(Error::SetData::Already.new(self, data))
|
89
|
+
end
|
90
|
+
self.rubuild_env_location__data = data
|
91
|
+
self.rubuild_env_location__have_data = true
|
92
|
+
# data's found, call its routine to clean up.
|
93
|
+
# (this could maybe be a little cleaner)
|
94
|
+
self._found_depaction(self.rubuild_env_location__found_dep)
|
95
|
+
end
|
96
|
+
|
97
|
+
def data
|
98
|
+
if ! self.rubuild_env_location__have_data
|
99
|
+
raise(Error::DataEmpty.new(self))
|
100
|
+
end
|
101
|
+
self.rubuild_env_location__data
|
102
|
+
end
|
103
|
+
end # Rubuild::Env::Location
|
104
|
+
end # Rubuild::Env
|
105
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Rubuild
|
2
|
+
class Env
|
3
|
+
# Provider
|
4
|
+
class Provider
|
5
|
+
Safer::IVar.instance_variable(self, :location)
|
6
|
+
Safer::IVar.instance_variable(self, :env)
|
7
|
+
Safer::IVar.instance_variable(self, :arglist)
|
8
|
+
Safer::IVar.instance_variable(self, :exec_dep)
|
9
|
+
Safer::IVar.export_reader(self, :exec_dep)
|
10
|
+
Safer::IVar.instance_variable(self, :exec_block)
|
11
|
+
def initialize(env, name)
|
12
|
+
self.rubuild_env_provider__env = env
|
13
|
+
self.rubuild_env_provider__location = Rubuild::Env::Location.new(name, env.build_factory)
|
14
|
+
self.rubuild_env_provider__arglist = Array.new
|
15
|
+
self.rubuild_env_provider__exec_dep = env.build_factory.create_dep(
|
16
|
+
self.method(:_exec_satisfied), "#{self.class.to_s}.exec(#{name})")
|
17
|
+
self.rubuild_env_provider__location.found_dep.add_parent(
|
18
|
+
self.rubuild_env_provider__exec_dep)
|
19
|
+
env.provide(name, self.rubuild_env_provider__location)
|
20
|
+
end
|
21
|
+
|
22
|
+
def require(*args)
|
23
|
+
req = Rubuild::Env::Requirer.new(self.rubuild_env_provider__env, *args)
|
24
|
+
self.rubuild_env_provider__arglist << req
|
25
|
+
self.rubuild_env_provider__exec_dep.add_parent(req.location.found_dep)
|
26
|
+
self
|
27
|
+
end
|
28
|
+
def require_(*args)
|
29
|
+
req = Rubuild::Env::Requirer.new(self.rubuild_env_provider__env, *args)
|
30
|
+
self.rubuild_env_provider__exec_dep.add_parent(req.location.found_dep)
|
31
|
+
self
|
32
|
+
end
|
33
|
+
def exec(&block)
|
34
|
+
self.rubuild_env_provider__exec_block = block
|
35
|
+
end
|
36
|
+
def _exec_satisfied(dep)
|
37
|
+
exec_block = self.rubuild_env_provider__exec_block
|
38
|
+
self.rubuild_env_provider__exec_block = nil
|
39
|
+
block_args = self.rubuild_env_provider__arglist.map do |arg|
|
40
|
+
arg.location.data
|
41
|
+
end
|
42
|
+
self.rubuild_env_provider__arglist = nil
|
43
|
+
exec_block.call(self, *block_args)
|
44
|
+
self.rubuild_env_provider__location = nil
|
45
|
+
end
|
46
|
+
def set(object)
|
47
|
+
self.rubuild_env_provider__location.set_data(object)
|
48
|
+
end
|
49
|
+
end # Rubuild::Env::Provider
|
50
|
+
end # Rubuild::Env
|
51
|
+
end # Rubuild
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Rubuild
|
2
|
+
class Env
|
3
|
+
## Rubuild::Env::Requirer
|
4
|
+
# Look up a set of provided entries in the environment at once.
|
5
|
+
class Requirer
|
6
|
+
Safer::IVar.instance_variable(self, :location)
|
7
|
+
Safer::IVar.export_reader(self, :location)
|
8
|
+
Safer::IVar.instance_variable(self, :found)
|
9
|
+
Safer::IVar.instance_variable(self, :env)
|
10
|
+
|
11
|
+
def initialize(env, req_desc)
|
12
|
+
self.rubuild_env_requirer__location =
|
13
|
+
Rubuild::Env::Location.new(req_desc.inspect, env.build_factory)
|
14
|
+
|
15
|
+
found_all = env.build_factory.create_dep(
|
16
|
+
self.method(:_found_all), self.rubuild_env_requirer__location.name)
|
17
|
+
|
18
|
+
self.location.found_dep.add_parent(found_all)
|
19
|
+
|
20
|
+
case req_desc
|
21
|
+
when String
|
22
|
+
finding = Rubuild::Env::Location.new(req_desc, env.build_factory)
|
23
|
+
env.require(req_desc, finding)
|
24
|
+
fill_dep = env.build_factory.create_dep(
|
25
|
+
self.method(:_found_only), "fill:#{finding.name}", finding)
|
26
|
+
fill_dep.add_parent(finding.found_dep)
|
27
|
+
found_all.add_parent(fill_dep)
|
28
|
+
when Array
|
29
|
+
self.rubuild_env_requirer__found = Array.new(req_desc.size)
|
30
|
+
req_desc.each_with_index do |path, index|
|
31
|
+
finding = Rubuild::Env::Location.new("#{index}:#{path}", env.build_factory)
|
32
|
+
env.require(path, finding)
|
33
|
+
fill_dep = env.build_factory.create_dep(
|
34
|
+
self.method(:_found_one), "fill:#{finding.name}", index, finding)
|
35
|
+
fill_dep.add_parent(finding.found_dep)
|
36
|
+
found_all.add_parent(fill_dep)
|
37
|
+
end
|
38
|
+
when Hash
|
39
|
+
self.rubuild_env_requirer__found = Hash.new
|
40
|
+
req_desc.each_pair do |key, path|
|
41
|
+
finding = Rubuild::Env::Location.new("#{key}:#{path}", env.build_factory)
|
42
|
+
env.require(path, finding)
|
43
|
+
fill_dep = env.build_factory.create_dep(
|
44
|
+
self.method(:_found_one), "fill:#{finding.name}", key, finding)
|
45
|
+
fill_dep.add_parent(finding.found_dep)
|
46
|
+
found_all.add_parent(fill_dep)
|
47
|
+
end
|
48
|
+
else
|
49
|
+
raise(ArgumentError, "Invalid key type for Rubuild::Env::Requirer.")
|
50
|
+
end
|
51
|
+
end # Rubuild::Env::Requirer#initialize
|
52
|
+
|
53
|
+
def _found_one(dep, key, found)
|
54
|
+
self.rubuild_env_requirer__found[key] = found.data
|
55
|
+
end
|
56
|
+
def _found_only(dep, found)
|
57
|
+
self.rubuild_env_requirer__found = found.data
|
58
|
+
end
|
59
|
+
def _found_all(dep)
|
60
|
+
self.location.set_data(self.rubuild_env_requirer__found)
|
61
|
+
self.rubuild_env_requirer__env = nil
|
62
|
+
self.rubuild_env_requirer__found = nil
|
63
|
+
end
|
64
|
+
end # Rubuild::Env::Requirer
|
65
|
+
end # Rubuild::Env
|
66
|
+
end # Rubuild
|
data/lib/rubuild/load.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
module Rubuild
|
2
|
+
module Load
|
3
|
+
## Rubuild::Load::Info
|
4
|
+
class Info
|
5
|
+
Safer::IVar.instance_variable(self, :env)
|
6
|
+
Safer::IVar.export_reader(self, :env)
|
7
|
+
Safer::IVar.instance_variable(self, :location)
|
8
|
+
Safer::IVar.export_reader(self, :location)
|
9
|
+
Safer::IVar.instance_variable(self, :path)
|
10
|
+
Safer::IVar.export_reader(self, :path)
|
11
|
+
Safer::IVar.instance_variable(self, :commit_dep)
|
12
|
+
def initialize(env, path, name)
|
13
|
+
self.rubuild_load_info__env = env
|
14
|
+
self.rubuild_load_info__path = path
|
15
|
+
self.rubuild_load_info__location = Rubuild::Env::Location.new(name, env.build_factory)
|
16
|
+
self.rubuild_load_info__commit_dep = self.rubuild_load_info__env.build_factory.create_dep(
|
17
|
+
self.method(:_commit), "#{self.class.to_s}\#commit(#{name})")
|
18
|
+
self.rubuild_load_info__location.found_dep.add_parent(self.rubuild_load_info__commit_dep)
|
19
|
+
end # Rubuild::Load::Info#initialize
|
20
|
+
|
21
|
+
def _commit(dep)
|
22
|
+
self.rubuild_load_info__location.set_data(nil)
|
23
|
+
end # Rubuild::Load::Info#_commit
|
24
|
+
|
25
|
+
def provide(nm)
|
26
|
+
Rubuild::Env::Provider.new(self.rubuild_load_info__env, self.location.name + nm)
|
27
|
+
end # Rubuild::Load::Info#provide
|
28
|
+
|
29
|
+
def require(req_desc)
|
30
|
+
Rubuild::Env::Requirer.new(self.rubuild_load_info__env, req_desc)
|
31
|
+
end # Rubuild::Load::Info#require
|
32
|
+
|
33
|
+
def require!(req_desc, &block)
|
34
|
+
required = Rubuild::Env::Requirer.new(self.rubuild_load_info__env, req_desc)
|
35
|
+
satisfied_dep = self.rubuild_load_info__env.build_factory.create_dep(
|
36
|
+
self.method(:_require_satisfied),
|
37
|
+
"#{self.class.to_s}(#{self.location.name}).require!(#{required.location.name})",
|
38
|
+
required.location, block)
|
39
|
+
satisfied_dep.add_parent(required.location.found_dep)
|
40
|
+
self.rubuild_load_info__commit_dep.add_parent(satisfied_dep)
|
41
|
+
end # Rubuild::Load::Info#require!
|
42
|
+
|
43
|
+
def _require_satisfied(dep, required, block)
|
44
|
+
block.call(required.data)
|
45
|
+
end # Rubuild::Load::Info#require_satisfied
|
46
|
+
|
47
|
+
def with(&block)
|
48
|
+
self.instance_eval(&block)
|
49
|
+
end
|
50
|
+
end # Rubuild::Load::Info
|
51
|
+
end # Rubuild::Load
|
52
|
+
end # Rubuild
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Rubuild
|
2
|
+
module Load
|
3
|
+
## Rubuild::Load::Loader
|
4
|
+
# Load code into a private execution context, referenced by a String name.
|
5
|
+
class Loader
|
6
|
+
## Rubuild::Load::Loader::Error
|
7
|
+
# Superclass of errors generated by Loader.
|
8
|
+
class Error < StandardError
|
9
|
+
Safer::IVar.instance_variable(self, :loader)
|
10
|
+
Safer::IVar.export_reader(self, :loader)
|
11
|
+
def initialize(loader, message)
|
12
|
+
self.rubuild_load_loader_error__loader = loader
|
13
|
+
super(message)
|
14
|
+
end # Rubuild::Load::Loader::Error#initialize
|
15
|
+
|
16
|
+
## Rubuild::Load::Loader::Error::Unprovisioned
|
17
|
+
# Attempt to use loader functionality prior to provisioning.
|
18
|
+
class Unprovisioned < Error
|
19
|
+
Safer::IVar.instance_variable(self, :operation)
|
20
|
+
Safer::IVar.export_reader(self, :operation)
|
21
|
+
def initialize(loader, operation)
|
22
|
+
self.rubuild_load_loader_error_unprovisioned__operation = operation
|
23
|
+
super(loader, "#{operation} method called prior to provision.")
|
24
|
+
end
|
25
|
+
end # Rubuild::Load::Loader::Error::Unprovisioned
|
26
|
+
end # Rubuild::Load::Loader::Error
|
27
|
+
|
28
|
+
Safer::IVar.instance_variable(self, :inc_paths)
|
29
|
+
Safer::IVar.export_accessor(self, :inc_paths)
|
30
|
+
Safer::IVar.instance_variable(self, :ns_factory)
|
31
|
+
Safer::IVar.export_reader(self, :ns_factory)
|
32
|
+
|
33
|
+
def initialize(ns_factory)
|
34
|
+
self.rubuild_load_loader__ns_factory = ns_factory
|
35
|
+
self.rubuild_load_loader__inc_paths = Array.new
|
36
|
+
end # Rubuild::Load::Loader#initialize
|
37
|
+
|
38
|
+
def provision(env, key)
|
39
|
+
self.freeze
|
40
|
+
self.rubuild_load_loader__inc_paths.freeze
|
41
|
+
l = Rubuild::Env::Location.new("#{self.class.to_s}\#provision(#{key})", env.build_factory)
|
42
|
+
l.set_data(self)
|
43
|
+
env.provide(key, l)
|
44
|
+
end # Rubuild::Load::Loader#provision
|
45
|
+
|
46
|
+
def findFile(fname)
|
47
|
+
if ! self.frozen?
|
48
|
+
raise Error::Unprovisioned.new(self, :findFile)
|
49
|
+
end
|
50
|
+
Rubuild::Util.enumerable_find(self.rubuild_load_loader__inc_paths) do |path|
|
51
|
+
testfile = "#{path}/#{fname}"
|
52
|
+
File.exists?(testfile) && testfile
|
53
|
+
end
|
54
|
+
end # Rubuild::Load::Loader#findFile
|
55
|
+
|
56
|
+
def loadFile(env, path, name = path)
|
57
|
+
fname = self.findFile(path)
|
58
|
+
text = File.open(fname, 'r') do |f| f.read end
|
59
|
+
self._loadInternal(env, text, path, name, fname)
|
60
|
+
end # Rubuild::Load::Loader#loadFile
|
61
|
+
|
62
|
+
def loadString(env, text, name)
|
63
|
+
self._loadInternal(env, text, name, name, name)
|
64
|
+
end # Rubuild::Load::Loader#loadFile
|
65
|
+
|
66
|
+
def _loadInternal(env, text, path, name, fname)
|
67
|
+
info = Rubuild::Load::Info.new(env, path, name)
|
68
|
+
ns = self.ns_factory.create
|
69
|
+
ns.rubuild_info = info
|
70
|
+
ns.class_eval(text, fname)
|
71
|
+
info.location
|
72
|
+
end
|
73
|
+
end # Rubuild::Load::Loader
|
74
|
+
end # Rubuild::Load
|
75
|
+
end # Rubuild
|