erlbox 1.6.0 → 1.7.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.
- data/VERSION.yml +1 -1
- data/bin/erlbox +29 -5
- data/erlbox.gemspec +5 -2
- data/lib/erlbox/build.rb +1 -1
- data/lib/erlbox/eunit.rb +8 -1
- data/lib/erlbox/install.rb +12 -0
- data/lib/erlbox/utils.rb +188 -2
- metadata +2 -2
data/VERSION.yml
CHANGED
data/bin/erlbox
CHANGED
@@ -70,13 +70,13 @@ def load_config()
|
|
70
70
|
config
|
71
71
|
end
|
72
72
|
|
73
|
-
def download_app(appname, appurl)
|
73
|
+
def download_app(appname, appurl, appvers)
|
74
74
|
# Work directory will be /tmp/erlbox.<pid>
|
75
75
|
tmpdir = "/tmp/erlbox_#{appname}.#{Process.pid}"
|
76
76
|
|
77
77
|
# Clone the desired url using GIT
|
78
78
|
# TODO: Support alternative systems
|
79
|
-
cmd = "git clone #{appurl} #{tmpdir}/"
|
79
|
+
cmd = "git clone -n #{appurl} #{tmpdir}/"
|
80
80
|
puts cmd
|
81
81
|
system cmd
|
82
82
|
if $? != 0
|
@@ -88,6 +88,14 @@ def download_app(appname, appurl)
|
|
88
88
|
system "(cd #{tmpdir} && git submodule update --init)"
|
89
89
|
end
|
90
90
|
|
91
|
+
# Check out appropriate version of the repo
|
92
|
+
cmd = "(cd #{tmpdir} && git checkout #{appvers})"
|
93
|
+
puts cmd
|
94
|
+
system cmd
|
95
|
+
if $? != 0
|
96
|
+
exit 1
|
97
|
+
end
|
98
|
+
|
91
99
|
# Return the tmp directory path
|
92
100
|
puts tmpdir
|
93
101
|
tmpdir
|
@@ -111,12 +119,24 @@ def install_deps(workdir, appname = nil, stack = [])
|
|
111
119
|
end
|
112
120
|
|
113
121
|
def install_app(appname, stack = [])
|
122
|
+
puts "Installing #{appname}"
|
114
123
|
# Check for a dependency cycle
|
115
124
|
if stack.include?(appname)
|
116
125
|
puts "#{appname} already scheduled for installation"
|
117
126
|
return
|
118
127
|
end
|
119
128
|
|
129
|
+
# Split app name on whitespace -- we pass the desired tag/branch in this way
|
130
|
+
if not appname.nil?
|
131
|
+
app_parts = appname.split(nil, 2)
|
132
|
+
if app_parts.length == 2
|
133
|
+
appname = app_parts[0]
|
134
|
+
appvers = app_parts[1]
|
135
|
+
else
|
136
|
+
appvers = "HEAD"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
120
140
|
# Default workdir is current working directory -- examination of appname may
|
121
141
|
# override this.
|
122
142
|
workdir = ""
|
@@ -135,12 +155,12 @@ def install_app(appname, stack = [])
|
|
135
155
|
if File.directory?(appname_path)
|
136
156
|
workdir = appname_path
|
137
157
|
else
|
138
|
-
workdir = download_app(appname, File.join(CONFIG['default_repo'], appname))
|
158
|
+
workdir = download_app(appname, File.join(CONFIG['default_repo'], appname), appvers)
|
139
159
|
is_temp = true
|
140
160
|
end
|
141
161
|
else
|
142
162
|
# Appname is a proper URL -- we'll pass this to git
|
143
|
-
workdir = download_app(appname, appname)
|
163
|
+
workdir = download_app(appname, appname, appvers)
|
144
164
|
is_temp = true
|
145
165
|
end
|
146
166
|
end
|
@@ -192,7 +212,11 @@ CONFIG = load_config()
|
|
192
212
|
action = ARGV[0]
|
193
213
|
case action
|
194
214
|
when 'install'
|
195
|
-
|
215
|
+
if ARGV.length > 2
|
216
|
+
install_app(ARGV[1] + " " + ARGV[2])
|
217
|
+
else
|
218
|
+
install_app(ARGV[1])
|
219
|
+
end
|
196
220
|
when 'cleanup'
|
197
221
|
FileUtils.rm_rf Dir.glob("/tmp/erlbox_*")
|
198
222
|
when 'ensure'
|
data/erlbox.gemspec
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
1
4
|
# -*- encoding: utf-8 -*-
|
2
5
|
|
3
6
|
Gem::Specification.new do |s|
|
4
7
|
s.name = %q{erlbox}
|
5
|
-
s.version = "1.
|
8
|
+
s.version = "1.7.0"
|
6
9
|
|
7
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
11
|
s.authors = ["Phillip Toland"]
|
9
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-09-26}
|
10
13
|
s.default_executable = %q{erlbox}
|
11
14
|
s.description = %q{Rake tasks and helper scripts for building Erlang applications.}
|
12
15
|
s.email = %q{phil.toland@gmail.com}
|
data/lib/erlbox/build.rb
CHANGED
@@ -53,7 +53,7 @@ directory 'ebin'
|
|
53
53
|
|
54
54
|
rule(%r(^ebin/.*\.beam$) => ["%{ebin,src}X.erl"]) do |t|
|
55
55
|
puts "compiling #{t.source}..."
|
56
|
-
sh "erlc #{print_flags(ERLC_FLAGS)} #{expand_path(ERL_PATH)} -o ebin #{t.source}"
|
56
|
+
sh "erlc #{print_flags(ERLC_FLAGS)} #{expand_path(ERL_PATH)} -o ebin #{t.source}", :verbose => verbose?
|
57
57
|
end
|
58
58
|
|
59
59
|
## -------------------------------------------------------------------
|
data/lib/erlbox/eunit.rb
CHANGED
@@ -79,6 +79,7 @@ def run_eunit(dir, cover = false, rest = '')
|
|
79
79
|
log_dir = abspath(EUNIT_LOG_DIR)
|
80
80
|
|
81
81
|
cover_flags = cover ? "-cover -o #{log_dir}/coverage" : ''
|
82
|
+
verbose_flags = verbose? ? '-v' : ''
|
82
83
|
|
83
84
|
suites = ENV['suites']
|
84
85
|
all_suites = ''
|
@@ -87,10 +88,16 @@ def run_eunit(dir, cover = false, rest = '')
|
|
87
88
|
script = __FILE__.sub('.rb', '')
|
88
89
|
|
89
90
|
cmd = "cd #{EUNIT_WORK_DIR} &&\
|
90
|
-
#{script}
|
91
|
+
#{script} #{verbose_flags} #{expand_erl_path()} \
|
92
|
+
-b #{abspath('./ebin')} -l #{log_dir}/eunit.log\
|
91
93
|
#{cover_flags} #{all_suites} #{abspath(dir)}"
|
92
94
|
|
93
95
|
puts cmd.squeeze(' ') if verbose?
|
94
96
|
|
95
97
|
sh cmd
|
96
98
|
end
|
99
|
+
|
100
|
+
def expand_erl_path()
|
101
|
+
# Add the ERL_PATH includes using multiple -b arguments
|
102
|
+
ERL_PATH.empty? ? '' : "-b #{ERL_PATH.join(' -b ')}"
|
103
|
+
end
|
data/lib/erlbox/install.rb
CHANGED
@@ -23,6 +23,14 @@
|
|
23
23
|
##
|
24
24
|
## -------------------------------------------------------------------
|
25
25
|
|
26
|
+
task :install => [:'install:build', :'install:deps'] do
|
27
|
+
erl_install()
|
28
|
+
end
|
29
|
+
|
30
|
+
task :install_no_deps => [:'install:build'] do
|
31
|
+
erl_install()
|
32
|
+
end
|
33
|
+
|
26
34
|
namespace :install do
|
27
35
|
|
28
36
|
task :appid, [:root_dir] do |t, args|
|
@@ -35,4 +43,8 @@ namespace :install do
|
|
35
43
|
desc "Build the application for installation"
|
36
44
|
task :build => [:compile]
|
37
45
|
|
46
|
+
desc "Installs all the dependencies for the current app"
|
47
|
+
task :deps do
|
48
|
+
erl_install_dependencies(APP_NAME)
|
49
|
+
end
|
38
50
|
end
|
data/lib/erlbox/utils.rb
CHANGED
@@ -23,6 +23,10 @@
|
|
23
23
|
##
|
24
24
|
## -------------------------------------------------------------------
|
25
25
|
|
26
|
+
require 'yaml'
|
27
|
+
require 'uri'
|
28
|
+
include FileUtils
|
29
|
+
|
26
30
|
def debug?
|
27
31
|
!ENV['debug'].nil?
|
28
32
|
end
|
@@ -81,7 +85,7 @@ end
|
|
81
85
|
|
82
86
|
def erl_app_version(app, extra_args = {})
|
83
87
|
script = <<-ERL
|
84
|
-
|
88
|
+
application:load(#{app}),
|
85
89
|
{ok, Vsn} = application:get_key(#{app}, vsn),
|
86
90
|
io:format("~s\\n", [Vsn]).
|
87
91
|
ERL
|
@@ -91,7 +95,7 @@ end
|
|
91
95
|
|
92
96
|
def erl_app_modules(app)
|
93
97
|
script = <<-ERL
|
94
|
-
|
98
|
+
application:load(#{app}),
|
95
99
|
{ok, M} = application:get_key(#{app}, modules),
|
96
100
|
[io:format("~s\\n", [Mod]) || Mod <- M].
|
97
101
|
ERL
|
@@ -99,11 +103,193 @@ def erl_app_modules(app)
|
|
99
103
|
output = erl_run(script, "-pa ebin")
|
100
104
|
if output[/badmatch/]
|
101
105
|
puts "Error processing .app file: #{output}"
|
106
|
+
[]
|
107
|
+
else
|
108
|
+
output.split("\n")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def erl_app_applications(app)
|
113
|
+
script = <<-ERL
|
114
|
+
ok = application:load(#{app}),
|
115
|
+
{ok, A} = application:get_key(#{app}, applications),
|
116
|
+
[io:format("~s\\n", [App]) || App <- A].
|
117
|
+
ERL
|
118
|
+
|
119
|
+
output = erl_run(script, "-pa ebin")
|
120
|
+
if output[/badmatch/]
|
121
|
+
puts "Error processing .app file: #{output}"
|
122
|
+
[]
|
102
123
|
else
|
103
124
|
output.split("\n")
|
104
125
|
end
|
105
126
|
end
|
106
127
|
|
128
|
+
def erl_app_versioned_dependencies(app)
|
129
|
+
script = <<-ERL
|
130
|
+
{ok, [{application, _AppName, AppConfig}]} = file:consult("ebin/#{app}.app"),
|
131
|
+
VDeps = case lists:keyfind(versioned_dependencies, 1, AppConfig) of
|
132
|
+
{versioned_dependencies, Deps} -> Deps;
|
133
|
+
Other -> []
|
134
|
+
end,
|
135
|
+
|
136
|
+
[io:format("~p~n", [tuple_to_list(Dep)]) || Dep <- VDeps].
|
137
|
+
ERL
|
138
|
+
|
139
|
+
output = erl_run(script, "-pa ebin")
|
140
|
+
|
141
|
+
# maps from a string to a list of lists, where each list is:
|
142
|
+
# [app, version, nil | gt | gte | e]
|
143
|
+
# (less than, less than or equal, etc.)
|
144
|
+
deps = output.split("\n").map{|d| d.gsub(/[\[\"\']/, '').split(',')}
|
145
|
+
|
146
|
+
deps
|
147
|
+
end
|
148
|
+
|
149
|
+
def erl_app_needs_upgrade?(app, requested_ver)
|
150
|
+
# if it's nil, force us to have something installed
|
151
|
+
requested_ver ||= '0.0.0.001'
|
152
|
+
|
153
|
+
installed_ver = erl_app_version(app)
|
154
|
+
|
155
|
+
if installed_ver =~ /init terminating/
|
156
|
+
installed_ver = "0.0.0"
|
157
|
+
end
|
158
|
+
|
159
|
+
return erl_version_needs_upgrade?(installed_ver, requested_ver)
|
160
|
+
end
|
161
|
+
|
162
|
+
def erl_version_needs_upgrade?(installed_version, requested_version)
|
163
|
+
iv = installed_version.split('.')
|
164
|
+
rv = requested_version.split('.')
|
165
|
+
|
166
|
+
iv.each_with_index do |n, i|
|
167
|
+
if rv[i].nil?
|
168
|
+
# installed version is longer, and all previous parts equal
|
169
|
+
return false
|
170
|
+
elsif rv[i].to_i > iv[i].to_i
|
171
|
+
return true # requested version is greater
|
172
|
+
elsif iv[i].to_i > rv[i].to_i
|
173
|
+
return false # installed version is greater
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
if rv.length > iv.length
|
178
|
+
return true # they're equal, but requested version has extra
|
179
|
+
else
|
180
|
+
return false # they're equal
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def erl_install_dependencies(app)
|
185
|
+
erl_app_versioned_dependencies(app).each do |dep|
|
186
|
+
erl_install_dep(*dep)
|
187
|
+
end
|
188
|
+
|
189
|
+
erl_app_applications(app).each do |dep|
|
190
|
+
erl_install_dep(dep)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
##
|
195
|
+
# It appears that faxien allows us to specify that a version must
|
196
|
+
# be exactly equal to the requested version. I'm ignoring this for now,
|
197
|
+
# but in this case, the extra argument here would be 'e'
|
198
|
+
##
|
199
|
+
def erl_install_dep(app, ver = nil, extra = nil)
|
200
|
+
appstr = ver ? "#{app}-#{ver}" : "#{app}"
|
201
|
+
|
202
|
+
if erl_app_needs_upgrade?(app, ver)
|
203
|
+
# do we have a ~/.erlbox.yaml file?
|
204
|
+
|
205
|
+
puts "Trying to install #{appstr}..."
|
206
|
+
erl_install_app(app)
|
207
|
+
|
208
|
+
# Check again, to make sure it was installed correctly
|
209
|
+
if erl_app_needs_upgrade?(app, ver)
|
210
|
+
STDERR.puts "ERROR: Failed to install dependency #{appstr}"
|
211
|
+
exit(1)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def load_yaml(file)
|
217
|
+
filename = File.expand_path(file)
|
218
|
+
return nil if not File.exist?(filename)
|
219
|
+
YAML::load(File.read(filename))
|
220
|
+
end
|
221
|
+
|
222
|
+
def load_config()
|
223
|
+
# Check for existence of the config file -- we MUST have one
|
224
|
+
config = load_yaml("~/.erlbox.yaml")
|
225
|
+
|
226
|
+
# Load the file and make sure required parameters are present
|
227
|
+
if config.nil? || config.empty?
|
228
|
+
STDERR.puts "To install dependencies from source, you must have a ~/.erlbox.yaml file with the key 'default_repo' (where git sources are) and optional keys 'erlang' (erlang root) and 'site_dir' (where to install applications. This must be in your ERL_LIBS path)"
|
229
|
+
config = []
|
230
|
+
end
|
231
|
+
|
232
|
+
# Fix up default repo URL
|
233
|
+
if config.has_key?('default_repo')
|
234
|
+
url = URI(config['default_repo'])
|
235
|
+
if url.scheme == nil || url.scheme == "file"
|
236
|
+
config['default_repo'] = File.expand_path(url.path)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
# If erlang repo is specified, expand the path and use that to determine the root
|
241
|
+
if config.has_key?('erlang')
|
242
|
+
config['erlang_root'] = erl_root(File.expand_path(config['erlang'])).strip()
|
243
|
+
else
|
244
|
+
config['erlang_root'] = erl_root().strip()
|
245
|
+
end
|
246
|
+
|
247
|
+
if !config.has_key?('site_dir')
|
248
|
+
config['site_dir'] = File.join(config['erlang_root'], "lib")
|
249
|
+
end
|
250
|
+
|
251
|
+
config
|
252
|
+
end
|
253
|
+
|
254
|
+
# install the latest version of the requested app
|
255
|
+
def erl_install_app(appname)
|
256
|
+
config = load_config()
|
257
|
+
if config.empty?
|
258
|
+
STDERR.puts "Sorry, we currently only support installing dependencies from source"
|
259
|
+
exit 1
|
260
|
+
end
|
261
|
+
|
262
|
+
# TODO: deal with other schemes than just files
|
263
|
+
workdir = File.join(config['default_repo'], appname)
|
264
|
+
if !File.exist?(workdir)
|
265
|
+
STDERR.puts "No such directory: #{workdir}"
|
266
|
+
exit 1
|
267
|
+
end
|
268
|
+
|
269
|
+
sh "cd #{workdir} && rake install"
|
270
|
+
end
|
271
|
+
|
272
|
+
##
|
273
|
+
# install the current app without checking dependencies
|
274
|
+
##
|
275
|
+
def erl_install
|
276
|
+
config = load_config()
|
277
|
+
|
278
|
+
appid = "#{APP_NAME}-#{erl_app_version(APP_NAME)}"
|
279
|
+
install_dir = File.join(config['site_dir'], appid)
|
280
|
+
|
281
|
+
if File.exist?(install_dir)
|
282
|
+
rm_rf install_dir
|
283
|
+
end
|
284
|
+
|
285
|
+
mkdir install_dir
|
286
|
+
['ebin', 'src', 'include', 'priv', 'mibs', 'deps'].each do |dir|
|
287
|
+
cp_r dir, install_dir if File.exist?(dir)
|
288
|
+
end
|
289
|
+
|
290
|
+
puts "Successfully installed #{appid} into #{install_dir}"
|
291
|
+
end
|
292
|
+
|
107
293
|
# Returns true if running on Linux
|
108
294
|
def linux?
|
109
295
|
platform? 'linux'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erlbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phillip Toland
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-26 00:00:00 -05:00
|
13
13
|
default_executable: erlbox
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|