esr-rim 1.4.0 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/CHANGELOG +9 -0
- data/Rakefile +56 -56
- data/lib/rim/command/sync.rb +89 -89
- data/lib/rim/command_helper.rb +143 -143
- data/lib/rim/git.rb +2 -1
- data/lib/rim/manifest/helper.rb +82 -82
- data/lib/rim/manifest/json_reader.rb +41 -41
- data/lib/rim/manifest/manifest.json +7 -7
- data/lib/rim/module_helper.rb +57 -57
- data/lib/rim/module_info.rb +43 -43
- data/lib/rim/processor.rb +152 -152
- data/lib/rim/rim.rb +94 -94
- data/lib/rim/sync_helper.rb +150 -150
- data/lib/rim/sync_module_helper.rb +107 -107
- data/lib/rim/upload_helper.rb +69 -69
- data/lib/rim/upload_module_helper.rb +163 -162
- data/lib/rim/version.rb +1 -1
- data/test/command_helper_test.rb +83 -83
- data/test/file_helper_test.rb +132 -132
- data/test/manifest_helper_test.rb +29 -29
- data/test/manifest_test_dir/manifest.rim +9 -9
- data/test/processor_test.rb +32 -32
- data/test/sync_helper_test.rb +296 -296
- data/test/sync_module_helper_test.rb +126 -126
- data/test/upload_helper_test.rb +403 -403
- data/test/upload_module_helper_test.rb +92 -92
- metadata +9 -15
- data/test/dirty_check/dir1/file2 +0 -1
- data/test/dirty_check/file1 +0 -1
- data/test/dirty_check/ign_file1 +0 -1
- data/test/rim_info/mod1/dir1/file2 +0 -1
- data/test/rim_info/mod1/file1 +0 -1
- data/test/rim_info/unrelated_file +0 -1
data/lib/rim/processor.rb
CHANGED
@@ -1,152 +1,152 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'pathname'
|
3
|
-
require 'rim/file_helper'
|
4
|
-
require 'rim/git'
|
5
|
-
require 'rim/rim_exception'
|
6
|
-
require 'rake'
|
7
|
-
require 'pathname'
|
8
|
-
require 'uri'
|
9
|
-
require 'digest/sha1'
|
10
|
-
|
11
|
-
module RIM
|
12
|
-
|
13
|
-
class Processor
|
14
|
-
|
15
|
-
MaxThreads = 10
|
16
|
-
GerritServer = "ssh://gerrit/"
|
17
|
-
|
18
|
-
def initialize(workspace_root, logger)
|
19
|
-
@ws_root = workspace_root
|
20
|
-
rim_dir = nil
|
21
|
-
rim_dir = File.expand_path(ENV['RIM_HOME']) if ENV.has_key?('RIM_HOME')
|
22
|
-
rim_dir = File.join(File.expand_path(ENV['HOME']), ".rim") if rim_dir.nil? && ENV.has_key?('HOME')
|
23
|
-
if rim_dir
|
24
|
-
@rim_path = File.join(rim_dir, Processor.shorten_path(@ws_root))
|
25
|
-
else
|
26
|
-
@rim_path = File.join(@ws_root, ".rim")
|
27
|
-
end
|
28
|
-
@logger = logger
|
29
|
-
end
|
30
|
-
|
31
|
-
def module_git_path(remote_path)
|
32
|
-
# remote url without protocol specifier
|
33
|
-
# this way the local path should be unique
|
34
|
-
File.join(@rim_path, Processor.shorten_path(remote_path))
|
35
|
-
end
|
36
|
-
|
37
|
-
def module_tmp_git_path(remote_path)
|
38
|
-
# remote url without protocol specifier
|
39
|
-
# this way the local path should be unique
|
40
|
-
File.join(@rim_path, ".tmp", Processor.shorten_path(remote_path))
|
41
|
-
end
|
42
|
-
|
43
|
-
def remote_path(remote_url)
|
44
|
-
remote_url.
|
45
|
-
# protocol specifier, e.g. ssh://
|
46
|
-
sub(/^\w+:\/\//,'').
|
47
|
-
# windows drive letter
|
48
|
-
sub(/^\w+:/,'\1').
|
49
|
-
# make sure we don't .. up in a filesystem
|
50
|
-
gsub(/\.\.[\\\/]/,'')
|
51
|
-
end
|
52
|
-
|
53
|
-
def get_relative_path(path)
|
54
|
-
FileHelper.get_relative_path(path, @ws_root)
|
55
|
-
end
|
56
|
-
|
57
|
-
def get_absolute_remote_url(remote_url)
|
58
|
-
if remote_url.start_with?("file:")
|
59
|
-
remote_url = remote_url.gsub(/^file:(\/\/)?/, "")
|
60
|
-
match = remote_url.match(/^\/(\w)\|/)
|
61
|
-
if match
|
62
|
-
remote_url = "#{match[1]}:#{remote_url[match[0].size..-1]}"
|
63
|
-
elsif !remote_url.start_with?(File::SEPARATOR)
|
64
|
-
File.expand_path(remote_url, @ws_root)
|
65
|
-
else
|
66
|
-
remote_url
|
67
|
-
end
|
68
|
-
else
|
69
|
-
URI.parse(GerritServer).merge(URI.parse(remote_url)).to_s
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def local_changes?(ws_dir, dir=ws_dir)
|
74
|
-
stat = nil
|
75
|
-
RIM::git_session(ws_dir) do |s|
|
76
|
-
stat = s.status(dir)
|
77
|
-
end
|
78
|
-
stat.lines.all?{|l| l.ignored?}
|
79
|
-
end
|
80
|
-
|
81
|
-
def clone_or_fetch_repository(remote_url, local_path, clone_log = nil)
|
82
|
-
FileUtils.mkdir_p local_path
|
83
|
-
RIM::git_session(local_path) do |s|
|
84
|
-
if !File.exist?(File.join(local_path, ".git"))
|
85
|
-
@logger.info(clone_log) if clone_log
|
86
|
-
FileHelper.make_empty_dir(local_path)
|
87
|
-
s.execute("git clone #{remote_url} .")
|
88
|
-
s.execute("git config core.ignorecase false")
|
89
|
-
else
|
90
|
-
s.execute("git remote set-url origin #{remote_url}") if !s.has_valid_remote_repository?()
|
91
|
-
s.execute("git fetch")
|
92
|
-
end
|
93
|
-
end
|
94
|
-
local_path
|
95
|
-
end
|
96
|
-
|
97
|
-
def commit(session, message)
|
98
|
-
msg_file = Tempfile.new('message')
|
99
|
-
begin
|
100
|
-
msg_file << message
|
101
|
-
msg_file.close
|
102
|
-
session.execute("git add --all")
|
103
|
-
session.execute("git commit -F #{msg_file.path}")
|
104
|
-
ensure
|
105
|
-
msg_file.close(true)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def each_module_parallel(task_desc, modules)
|
110
|
-
if !modules.empty?
|
111
|
-
@logger.debug "starting \"#{task_desc}\" for #{modules.size} modules\r"
|
112
|
-
index_queue = Queue.new
|
113
|
-
(0...modules.size).each do |i|
|
114
|
-
index_queue << i
|
115
|
-
end
|
116
|
-
result_queue = Queue.new
|
117
|
-
(1..MaxThreads).each do
|
118
|
-
Thread.new do
|
119
|
-
loop do
|
120
|
-
i = index_queue.pop(true)
|
121
|
-
break if i.nil?
|
122
|
-
result = []
|
123
|
-
begin
|
124
|
-
yield(modules[i], i)
|
125
|
-
rescue RimException => e
|
126
|
-
result = e.messages
|
127
|
-
rescue Exception => e
|
128
|
-
result = [e.to_s]
|
129
|
-
end
|
130
|
-
result_queue << result
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
messages = []
|
135
|
-
(0...modules.size).each do |i|
|
136
|
-
messages.concat(result_queue.pop)
|
137
|
-
end
|
138
|
-
raise RimException.new(messages) if !messages.empty?
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def self.shorten_path(path)
|
143
|
-
if path.length <= 10
|
144
|
-
path.gsub(':', '#')
|
145
|
-
else
|
146
|
-
Digest::SHA1.hexdigest(path || '')[0...10]
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
end
|
151
|
-
|
152
|
-
end
|
1
|
+
require 'fileutils'
|
2
|
+
require 'pathname'
|
3
|
+
require 'rim/file_helper'
|
4
|
+
require 'rim/git'
|
5
|
+
require 'rim/rim_exception'
|
6
|
+
require 'rake'
|
7
|
+
require 'pathname'
|
8
|
+
require 'uri'
|
9
|
+
require 'digest/sha1'
|
10
|
+
|
11
|
+
module RIM
|
12
|
+
|
13
|
+
class Processor
|
14
|
+
|
15
|
+
MaxThreads = 10
|
16
|
+
GerritServer = "ssh://gerrit/"
|
17
|
+
|
18
|
+
def initialize(workspace_root, logger)
|
19
|
+
@ws_root = workspace_root
|
20
|
+
rim_dir = nil
|
21
|
+
rim_dir = File.expand_path(ENV['RIM_HOME']) if ENV.has_key?('RIM_HOME')
|
22
|
+
rim_dir = File.join(File.expand_path(ENV['HOME']), ".rim") if rim_dir.nil? && ENV.has_key?('HOME')
|
23
|
+
if rim_dir
|
24
|
+
@rim_path = File.join(rim_dir, Processor.shorten_path(@ws_root))
|
25
|
+
else
|
26
|
+
@rim_path = File.join(@ws_root, ".rim")
|
27
|
+
end
|
28
|
+
@logger = logger
|
29
|
+
end
|
30
|
+
|
31
|
+
def module_git_path(remote_path)
|
32
|
+
# remote url without protocol specifier
|
33
|
+
# this way the local path should be unique
|
34
|
+
File.join(@rim_path, Processor.shorten_path(remote_path))
|
35
|
+
end
|
36
|
+
|
37
|
+
def module_tmp_git_path(remote_path)
|
38
|
+
# remote url without protocol specifier
|
39
|
+
# this way the local path should be unique
|
40
|
+
File.join(@rim_path, ".tmp", Processor.shorten_path(remote_path))
|
41
|
+
end
|
42
|
+
|
43
|
+
def remote_path(remote_url)
|
44
|
+
remote_url.
|
45
|
+
# protocol specifier, e.g. ssh://
|
46
|
+
sub(/^\w+:\/\//,'').
|
47
|
+
# windows drive letter
|
48
|
+
sub(/^\w+:/,'\1').
|
49
|
+
# make sure we don't .. up in a filesystem
|
50
|
+
gsub(/\.\.[\\\/]/,'')
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_relative_path(path)
|
54
|
+
FileHelper.get_relative_path(path, @ws_root)
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_absolute_remote_url(remote_url)
|
58
|
+
if remote_url.start_with?("file:")
|
59
|
+
remote_url = remote_url.gsub(/^file:(\/\/)?/, "")
|
60
|
+
match = remote_url.match(/^\/(\w)\|/)
|
61
|
+
if match
|
62
|
+
remote_url = "#{match[1]}:#{remote_url[match[0].size..-1]}"
|
63
|
+
elsif !remote_url.start_with?(File::SEPARATOR)
|
64
|
+
File.expand_path(remote_url, @ws_root)
|
65
|
+
else
|
66
|
+
remote_url
|
67
|
+
end
|
68
|
+
else
|
69
|
+
URI.parse(GerritServer).merge(URI.parse(remote_url)).to_s
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def local_changes?(ws_dir, dir=ws_dir)
|
74
|
+
stat = nil
|
75
|
+
RIM::git_session(ws_dir) do |s|
|
76
|
+
stat = s.status(dir)
|
77
|
+
end
|
78
|
+
stat.lines.all?{|l| l.ignored?}
|
79
|
+
end
|
80
|
+
|
81
|
+
def clone_or_fetch_repository(remote_url, local_path, clone_log = nil)
|
82
|
+
FileUtils.mkdir_p local_path
|
83
|
+
RIM::git_session(local_path) do |s|
|
84
|
+
if !File.exist?(File.join(local_path, ".git"))
|
85
|
+
@logger.info(clone_log) if clone_log
|
86
|
+
FileHelper.make_empty_dir(local_path)
|
87
|
+
s.execute("git clone #{remote_url} .")
|
88
|
+
s.execute("git config core.ignorecase false")
|
89
|
+
else
|
90
|
+
s.execute("git remote set-url origin #{remote_url}") if !s.has_valid_remote_repository?()
|
91
|
+
s.execute("git fetch")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
local_path
|
95
|
+
end
|
96
|
+
|
97
|
+
def commit(session, message)
|
98
|
+
msg_file = Tempfile.new('message')
|
99
|
+
begin
|
100
|
+
msg_file << message
|
101
|
+
msg_file.close
|
102
|
+
session.execute("git add --all")
|
103
|
+
session.execute("git commit -F #{msg_file.path}")
|
104
|
+
ensure
|
105
|
+
msg_file.close(true)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def each_module_parallel(task_desc, modules)
|
110
|
+
if !modules.empty?
|
111
|
+
@logger.debug "starting \"#{task_desc}\" for #{modules.size} modules\r"
|
112
|
+
index_queue = Queue.new
|
113
|
+
(0...modules.size).each do |i|
|
114
|
+
index_queue << i
|
115
|
+
end
|
116
|
+
result_queue = Queue.new
|
117
|
+
(1..MaxThreads).each do
|
118
|
+
Thread.new do
|
119
|
+
loop do
|
120
|
+
i = index_queue.pop(true)
|
121
|
+
break if i.nil?
|
122
|
+
result = []
|
123
|
+
begin
|
124
|
+
yield(modules[i], i)
|
125
|
+
rescue RimException => e
|
126
|
+
result = e.messages
|
127
|
+
rescue Exception => e
|
128
|
+
result = [e.to_s]
|
129
|
+
end
|
130
|
+
result_queue << result
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
messages = []
|
135
|
+
(0...modules.size).each do |i|
|
136
|
+
messages.concat(result_queue.pop)
|
137
|
+
end
|
138
|
+
raise RimException.new(messages) if !messages.empty?
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.shorten_path(path)
|
143
|
+
if path.length <= 10
|
144
|
+
path.gsub(':', '#')
|
145
|
+
else
|
146
|
+
Digest::SHA1.hexdigest(path || '')[0...10]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
data/lib/rim/rim.rb
CHANGED
@@ -1,94 +1,94 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__)+"/lib")
|
2
|
-
require 'subcommand'
|
3
|
-
require 'rim/file_logger'
|
4
|
-
require 'rim/command/sync'
|
5
|
-
require 'rim/command/upload'
|
6
|
-
require 'rim/command/status'
|
7
|
-
require 'rim/command/info'
|
8
|
-
require 'rim/git'
|
9
|
-
require 'rim/rim_exception'
|
10
|
-
require 'rim/version'
|
11
|
-
require 'tmpdir'
|
12
|
-
|
13
|
-
include Subcommands
|
14
|
-
|
15
|
-
# -C option was added in 1.8.5
|
16
|
-
# --ignore-removal was added in 1.8.3
|
17
|
-
MinimumGitVersion = "1.8.5"
|
18
|
-
|
19
|
-
logger = RIM::FileLogger.new($stdout, File.join(Dir.tmpdir, "rim", Time.now().strftime("rim_%Y%m%d-%H%M%S-%L.log")))
|
20
|
-
logger.level = Logger::INFO
|
21
|
-
logger.formatter = proc do |severity, time, progname, msg|
|
22
|
-
if severity == "INFO"
|
23
|
-
"#{msg}\n"
|
24
|
-
else
|
25
|
-
"#{severity}: #{msg}\n"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
RIM::GitSession.logger = logger
|
30
|
-
|
31
|
-
RIM::git_session(".") do |s|
|
32
|
-
begin
|
33
|
-
version = s.git_version
|
34
|
-
if version
|
35
|
-
cmp_str = lambda {|v| v.split(".").collect{|p| p.rjust(10)}.join}
|
36
|
-
if cmp_str.call(version) < cmp_str.call(MinimumGitVersion)
|
37
|
-
logger.info "Rim needs git version #{MinimumGitVersion} or higher"
|
38
|
-
logger.info "Please update git from http://git-scm.com/"
|
39
|
-
exit(1)
|
40
|
-
end
|
41
|
-
else
|
42
|
-
# version unknown, don't complain
|
43
|
-
end
|
44
|
-
rescue RIM::GitException
|
45
|
-
logger.info "It seems git is not installed or it's not in your path"
|
46
|
-
logger.info "Please update your path or find git at http://git-scm.com/"
|
47
|
-
exit(1)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
prog_info = "rim, version #{RIM::Version::Version}, Copyright (c) 2015, esrlabs.com"
|
52
|
-
|
53
|
-
global_options do |opts|
|
54
|
-
opts.banner = prog_info
|
55
|
-
opts.separator ""
|
56
|
-
opts.separator "Usage: [<options>] rim <command> [<args>]"
|
57
|
-
opts.on("-v","--version", "Print version info") do
|
58
|
-
logger.info prog_info
|
59
|
-
exit
|
60
|
-
end
|
61
|
-
opts.on("-l LOGLEVEL", [:debug, :info, :warn, :error, :fatal], "log level",
|
62
|
-
"one of [debug, info, warn, error, fatal]") do |v|
|
63
|
-
logger.level = Logger.const_get(v.upcase)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
commands = {}
|
68
|
-
add_help_option
|
69
|
-
ObjectSpace.each_object(Class).select{|clazz| clazz < RIM::Command::Command }.each do |cmdclazz|
|
70
|
-
name = cmdclazz.name.to_s.downcase.split("::").last
|
71
|
-
command name do |opts|
|
72
|
-
cmd = cmdclazz.new(opts)
|
73
|
-
commands[name] = cmd;
|
74
|
-
end
|
75
|
-
end
|
76
|
-
ARGV.unshift("help") if ARGV.empty?
|
77
|
-
begin
|
78
|
-
cmdname = opt_parse()
|
79
|
-
if cmdname
|
80
|
-
cmd = commands[cmdname]
|
81
|
-
cmd.logger = logger
|
82
|
-
begin
|
83
|
-
cmd.invoke()
|
84
|
-
rescue RIM::RimException => e
|
85
|
-
e.messages.each do |m|
|
86
|
-
logger.error(m)
|
87
|
-
end
|
88
|
-
exit(1)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
rescue OptionParser::InvalidOption => e
|
92
|
-
logger.error(e.message)
|
93
|
-
exit(1)
|
94
|
-
end
|
1
|
+
$:.unshift(File.dirname(__FILE__)+"/lib")
|
2
|
+
require 'subcommand'
|
3
|
+
require 'rim/file_logger'
|
4
|
+
require 'rim/command/sync'
|
5
|
+
require 'rim/command/upload'
|
6
|
+
require 'rim/command/status'
|
7
|
+
require 'rim/command/info'
|
8
|
+
require 'rim/git'
|
9
|
+
require 'rim/rim_exception'
|
10
|
+
require 'rim/version'
|
11
|
+
require 'tmpdir'
|
12
|
+
|
13
|
+
include Subcommands
|
14
|
+
|
15
|
+
# -C option was added in 1.8.5
|
16
|
+
# --ignore-removal was added in 1.8.3
|
17
|
+
MinimumGitVersion = "1.8.5"
|
18
|
+
|
19
|
+
logger = RIM::FileLogger.new($stdout, File.join(Dir.tmpdir, "rim", Time.now().strftime("rim_%Y%m%d-%H%M%S-%L.log")))
|
20
|
+
logger.level = Logger::INFO
|
21
|
+
logger.formatter = proc do |severity, time, progname, msg|
|
22
|
+
if severity == "INFO"
|
23
|
+
"#{msg}\n"
|
24
|
+
else
|
25
|
+
"#{severity}: #{msg}\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
RIM::GitSession.logger = logger
|
30
|
+
|
31
|
+
RIM::git_session(".") do |s|
|
32
|
+
begin
|
33
|
+
version = s.git_version
|
34
|
+
if version
|
35
|
+
cmp_str = lambda {|v| v.split(".").collect{|p| p.rjust(10)}.join}
|
36
|
+
if cmp_str.call(version) < cmp_str.call(MinimumGitVersion)
|
37
|
+
logger.info "Rim needs git version #{MinimumGitVersion} or higher"
|
38
|
+
logger.info "Please update git from http://git-scm.com/"
|
39
|
+
exit(1)
|
40
|
+
end
|
41
|
+
else
|
42
|
+
# version unknown, don't complain
|
43
|
+
end
|
44
|
+
rescue RIM::GitException
|
45
|
+
logger.info "It seems git is not installed or it's not in your path"
|
46
|
+
logger.info "Please update your path or find git at http://git-scm.com/"
|
47
|
+
exit(1)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
prog_info = "rim, version #{RIM::Version::Version}, Copyright (c) 2015, esrlabs.com"
|
52
|
+
|
53
|
+
global_options do |opts|
|
54
|
+
opts.banner = prog_info
|
55
|
+
opts.separator ""
|
56
|
+
opts.separator "Usage: [<options>] rim <command> [<args>]"
|
57
|
+
opts.on("-v","--version", "Print version info") do
|
58
|
+
logger.info prog_info
|
59
|
+
exit
|
60
|
+
end
|
61
|
+
opts.on("-l LOGLEVEL", [:debug, :info, :warn, :error, :fatal], "log level",
|
62
|
+
"one of [debug, info, warn, error, fatal]") do |v|
|
63
|
+
logger.level = Logger.const_get(v.upcase)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
commands = {}
|
68
|
+
add_help_option
|
69
|
+
ObjectSpace.each_object(Class).select{|clazz| clazz < RIM::Command::Command }.each do |cmdclazz|
|
70
|
+
name = cmdclazz.name.to_s.downcase.split("::").last
|
71
|
+
command name do |opts|
|
72
|
+
cmd = cmdclazz.new(opts)
|
73
|
+
commands[name] = cmd;
|
74
|
+
end
|
75
|
+
end
|
76
|
+
ARGV.unshift("help") if ARGV.empty?
|
77
|
+
begin
|
78
|
+
cmdname = opt_parse()
|
79
|
+
if cmdname
|
80
|
+
cmd = commands[cmdname]
|
81
|
+
cmd.logger = logger
|
82
|
+
begin
|
83
|
+
cmd.invoke()
|
84
|
+
rescue RIM::RimException => e
|
85
|
+
e.messages.each do |m|
|
86
|
+
logger.error(m)
|
87
|
+
end
|
88
|
+
exit(1)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
rescue OptionParser::InvalidOption => e
|
92
|
+
logger.error(e.message)
|
93
|
+
exit(1)
|
94
|
+
end
|