-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile.helpers
81 lines (71 loc) · 1.69 KB
/
Rakefile.helpers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Boilerplate
require 'find'
# Some Environment Tweaks
ENV['ERL_LIBS'] = File.expand_path './lib'
# Helpful Functions
def otp_root
%x[scripts/erl_info otp_root].chomp
end
def otp_lib
File.join(otp_root,'lib')
end
def ct_root
ct_roots = Dir.glob(File.join(otp_lib,'common_test*'))
unless ct_roots.length > 0
puts "Can't find common_test"
exit 1
end
ct_roots[-1] # Pick the highest version
end
def ct_runtest
File.join ct_root,'priv','bin','run_test'
end
def apps
appdirs = Dir['lib/*-*']
appdirs.map do |appdir|
next unless appdir =~ %r{lib/([^-]+)(-([0-9.]+))?}
spec = "#{$1}-#{$3}"
name = $1
ver = $3
pretty = name.split("_").map do |x| x.capitalize end.join " "
{ :name => name, :ver => ver, :spec => spec, :pretty => pretty, :dir => appdir }
end
end
def workers
nodes = %x[scripts/list_nodes].grep /worker_\d+/
nodes.collect do |l|
l.chomp
end
end
def renamefile(skeldir,modname,f)
f = f.sub %r{^templates/#{skeldir}/}, "lib/#{modname}-0.1/"
f.gsub! /SKEL/,"#{modname}"
f
end
def translate_line(modname,l)
l = l.gsub /SKEL/, "#{modname}"
l.gsub! /VSN/, '0.1'
l
end
def copy_skel( skeldir, modname )
text_ext = ['.app','.erl']
Find.find 'templates/' + skeldir do |f|
if File.directory?(f)
mkdir_p renamefile(skeldir,modname,f + '/')
elsif File.file?(f)
newname = renamefile(skeldir,modname,f)
puts "translate #{f} #{newname}"
if text_ext.include? File.extname(f)
src = File.new(f)
dst = File.new(newname,'w')
src.each_line do |l|
dst.write translate_line(modname,l)
end
src.close
dst.close
else
cp f, newname
end
end
end
end