squared 0.6.9 → 0.7.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +89 -2
- data/README.md +245 -203
- data/lib/squared/common/format.rb +7 -10
- data/lib/squared/common/prompt.rb +23 -24
- data/lib/squared/common/shell.rb +16 -17
- data/lib/squared/common/system.rb +29 -20
- data/lib/squared/common/utils.rb +43 -54
- data/lib/squared/config.rb +17 -16
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +290 -175
- data/lib/squared/workspace/project/base.rb +566 -446
- data/lib/squared/workspace/project/docker.rb +151 -131
- data/lib/squared/workspace/project/git.rb +205 -151
- data/lib/squared/workspace/project/node.rb +90 -88
- data/lib/squared/workspace/project/python.rb +236 -139
- data/lib/squared/workspace/project/ruby.rb +395 -281
- data/lib/squared/workspace/project/support/class.rb +12 -6
- data/lib/squared/workspace/project/support/optionpartition.rb +58 -41
- data/lib/squared/workspace/project/support/utils.rb +68 -0
- data/lib/squared/workspace/project.rb +0 -7
- data/lib/squared/workspace/repo.rb +234 -169
- data/lib/squared/workspace/series.rb +91 -86
- data/lib/squared/workspace/support/base.rb +15 -1
- metadata +2 -1
|
@@ -6,45 +6,54 @@ module Squared
|
|
|
6
6
|
REPO_URL = 'https://storage.googleapis.com/git-repo-downloads/repo'
|
|
7
7
|
private_constant :REPO_URL
|
|
8
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
|
-
|
|
9
|
+
def repo(url, manifest = 'latest', run: nil, script: nil, args: nil, dev: nil, prod: nil, doc: false, test: false,
|
|
10
|
+
lint: false, install: nil, name: nil, ref: @ref, group: @group)
|
|
11
|
+
if @repo_bin.nil?
|
|
12
|
+
self.home = if (val = env('REPO_HOME'))
|
|
13
|
+
path = Pathname.new(val)
|
|
14
|
+
if main == path.basename.to_s
|
|
15
|
+
@root = path.parent
|
|
16
|
+
if path.exist?
|
|
17
|
+
@root = nil unless path.directory?
|
|
18
|
+
elsif !@root.exist?
|
|
19
|
+
@root.mkpath
|
|
20
|
+
elsif !repo_install? && !repo_confirm
|
|
21
|
+
@root = nil
|
|
22
|
+
end
|
|
23
|
+
raise_error Errno::EEXIST, path.cleanpath, hint: 'REPO_HOME' unless @root
|
|
24
|
+
end
|
|
25
|
+
path.realdirpath
|
|
26
|
+
elsif (val = env('REPO_ROOT'))
|
|
27
|
+
@root = Pathname.new(val).realdirpath
|
|
28
|
+
if !@root.exist?
|
|
29
|
+
@root.mkpath
|
|
30
|
+
elsif !repo_install?(parent: true) && !repo_confirm
|
|
31
|
+
raise_error Errno::EEXIST, @root, hint: 'REPO_ROOT'
|
|
32
|
+
end
|
|
33
|
+
@root.join(main).realdirpath
|
|
34
|
+
elsif repo_install?(parent: true) && (!home.exist? || @root + main == home)
|
|
35
|
+
home
|
|
36
|
+
elsif repo_install?(home)
|
|
37
|
+
home + main
|
|
38
|
+
else
|
|
39
|
+
pwd == home || !repo_install?(pwd) ? home : pwd + main
|
|
40
|
+
end
|
|
41
|
+
@repo_bin = if install
|
|
42
|
+
install.is_a?(String) ? @root + install : @root
|
|
43
|
+
else
|
|
44
|
+
false
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
envargs = name ? { suffix: name.upcase, strict: true } : {}
|
|
45
48
|
data = scriptobj
|
|
46
49
|
if repo?
|
|
47
|
-
|
|
50
|
+
group = env('REPO_GROUP', **envargs) { |val| split_escape(val) }
|
|
51
|
+
ref = env('REPO_REF', **envargs) { |val| split_escape(val) }
|
|
52
|
+
data[:dev] = env_match('REPO_DEV', dev, **envargs)
|
|
53
|
+
data[:prod] = env_match('REPO_PROD', prod, **envargs)
|
|
54
|
+
@warning = env_match('REPO_WARN', @warning && !root?(@root, pass: ['.repo'])) != false unless name
|
|
55
|
+
sc, ru = split_escape(env('REPO_BUILD', '', **envargs), limit: 2)
|
|
56
|
+
global = data[:global]
|
|
48
57
|
if script
|
|
49
58
|
data[:script] = if sc.to_s.empty?
|
|
50
59
|
script
|
|
@@ -67,8 +76,8 @@ module Squared
|
|
|
67
76
|
sc
|
|
68
77
|
end
|
|
69
78
|
end
|
|
70
|
-
data[:args] =
|
|
71
|
-
|
|
79
|
+
data[:args] = env('REPO_SCRIPT', **envargs) { |val| shell_split(val, join: true) } || args
|
|
80
|
+
global[:script] = true
|
|
72
81
|
else
|
|
73
82
|
ru ||= sc
|
|
74
83
|
end
|
|
@@ -79,20 +88,12 @@ module Squared
|
|
|
79
88
|
data[:env][:run] = true
|
|
80
89
|
ru
|
|
81
90
|
end
|
|
82
|
-
|
|
83
|
-
end
|
|
84
|
-
data[:dev] = env_match 'REPO_DEV', dev
|
|
85
|
-
data[:prod] = env_match 'REPO_PROD', prod
|
|
86
|
-
if (val = env('REPO_GROUP'))
|
|
87
|
-
script_set(data, group: val.split(','))
|
|
88
|
-
found = true
|
|
89
|
-
end
|
|
90
|
-
if (val = env('REPO_REF'))
|
|
91
|
-
script_set(data, ref: val.split(','))
|
|
92
|
-
found = true
|
|
91
|
+
global[:run] = true
|
|
93
92
|
end
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
global[:doc] = doc
|
|
94
|
+
global[:lint] = lint
|
|
95
|
+
global[:test] = test
|
|
96
|
+
script_set('repo', data, name: name, group: group, ref: ref, extras: { url: url, manifest: manifest })
|
|
96
97
|
@extensions << :__repo__
|
|
97
98
|
elsif script || run
|
|
98
99
|
if script
|
|
@@ -102,126 +103,150 @@ module Squared
|
|
|
102
103
|
data[:run] = run if run
|
|
103
104
|
data[:dev] = dev
|
|
104
105
|
data[:prod] = prod
|
|
105
|
-
script_set(data, group: group, ref: ref)
|
|
106
|
+
script_set('repo', data, name: name, group: group, ref: ref)
|
|
106
107
|
end
|
|
107
|
-
@repo_bin = install.is_a?(String) ? @root + install : @root if install
|
|
108
108
|
self
|
|
109
109
|
end
|
|
110
110
|
|
|
111
|
+
def repo?(active = false)
|
|
112
|
+
active ? @extensions.include?(:__repo__) : !windows? && (repo_install? || @repo_override == true)
|
|
113
|
+
end
|
|
114
|
+
|
|
111
115
|
private
|
|
112
116
|
|
|
113
117
|
def __repo__(**kwargs)
|
|
118
|
+
self.closed = 'repo:begin'
|
|
114
119
|
kwargs.delete(:parallel) if env('REPO_SYNC', ignore: '0')
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
script_each 'repo' do |name, data|
|
|
121
|
+
namespace task_name(name == '_' ? 'repo' : "repo:#{name}") do |ns|
|
|
122
|
+
path = ns.scope.path
|
|
123
|
+
envargs = name == '_' ? {} : { suffix: name.upcase, strict: true }
|
|
124
|
+
branch = env('REPO_MANIFEST', **envargs) || repo_manifest
|
|
125
|
+
target = branch || data[:extras][:manifest]
|
|
126
|
+
stage = nil
|
|
127
|
+
opts = %w[force rebase detach submodules fail no-update gc]
|
|
128
|
+
desc = lambda do |val, alt = nil|
|
|
129
|
+
if (ver = branch || alt)
|
|
130
|
+
val = val.sub('{0}', "opts*=#{opts.join(',')}")
|
|
131
|
+
task_desc(path, val, ver)
|
|
132
|
+
else
|
|
133
|
+
task_desc 'inactive'
|
|
134
|
+
end
|
|
128
135
|
end
|
|
129
|
-
end
|
|
130
136
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
137
|
+
desc.call('all[{0}]')
|
|
138
|
+
task 'all' do |_, args|
|
|
139
|
+
stage ||= 'all'
|
|
140
|
+
ns['sync'].invoke(*args.to_a)
|
|
141
|
+
next if (n = env('REPO_STAGE', **envargs).to_i).anybits?(1)
|
|
136
142
|
|
|
137
|
-
|
|
138
|
-
|
|
143
|
+
if (val = env('REPO_SERIES', **envargs))
|
|
144
|
+
split_escape(val) do |meth|
|
|
145
|
+
meth, sync = meth.split(':', 2)
|
|
146
|
+
repo_workspace(name).each do |proj|
|
|
147
|
+
repo_call(proj, meth, sync: (sync != 'parallel' unless sync == 'detect'))
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
else
|
|
151
|
+
repo_workspace(name).map do |proj|
|
|
152
|
+
proj.depend(sync: true) if proj.depend?
|
|
153
|
+
next [] if n.anybits?(2)
|
|
154
|
+
|
|
155
|
+
run, script, doc, lint, test = proj.scriptdata(:global, name: name)
|
|
156
|
+
.fetch_values(:run, :script, :doc, :lint, :test)
|
|
157
|
+
[proj, proj.build? && (script || run), doc && proj.doc?, lint && proj.lint?, test && proj.test?]
|
|
158
|
+
end
|
|
159
|
+
.select do |proj, run, doc, lint, test|
|
|
160
|
+
next unless proj
|
|
161
|
+
|
|
162
|
+
proj.doc(sync: true) if doc
|
|
163
|
+
proj.build(sync: true) if run
|
|
164
|
+
next if n.anybits?(4)
|
|
165
|
+
|
|
166
|
+
repo_call proj, 'copy' if run && proj.copy? && (proj.dev? || n.anybits?(512))
|
|
167
|
+
next if n.anybits?(8)
|
|
139
168
|
|
|
140
|
-
|
|
141
|
-
|
|
169
|
+
proj.lint(sync: true) if lint
|
|
170
|
+
next if n.anybits?(16)
|
|
142
171
|
|
|
143
|
-
|
|
172
|
+
test
|
|
173
|
+
end
|
|
174
|
+
.each { |proj| proj.test(sync: true) }
|
|
175
|
+
end
|
|
144
176
|
end
|
|
145
|
-
.each do |proj|
|
|
146
|
-
proj.build(sync: true)
|
|
147
|
-
next if n == '3'
|
|
148
|
-
next unless proj.copy? && (proj.dev? || n == '4')
|
|
149
177
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
178
|
+
desc.call("init[manifest?=#{target},groups?,{0}]", target)
|
|
179
|
+
task 'init' do |_, args|
|
|
180
|
+
args = args.to_a
|
|
181
|
+
u = env('REPO_GIT', **envargs) || data[:extras][:url]
|
|
182
|
+
check = -> { args.first && !opts.include?(args.first) }
|
|
183
|
+
if check.call
|
|
184
|
+
m = args.shift
|
|
185
|
+
g = args.shift if check.call
|
|
154
186
|
end
|
|
187
|
+
env('REPO_GROUPS', **envargs) do |val|
|
|
188
|
+
g = case val
|
|
189
|
+
when '0', 'false'
|
|
190
|
+
nil
|
|
191
|
+
else
|
|
192
|
+
val
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
stage = 'init'
|
|
196
|
+
opts = repo_opts "-u #{u}", "-m #{m || target}.xml"
|
|
197
|
+
opts << "-g #{g}" if g
|
|
198
|
+
opts << '--submodules' if repo_submodules?(args.include?('submodules'), **envargs)
|
|
199
|
+
repo_run 'init', opts
|
|
200
|
+
next if env('REPO_STAGE', equals: '0', **envargs)
|
|
201
|
+
|
|
202
|
+
ns['all'].invoke(*args)
|
|
155
203
|
end
|
|
156
|
-
end
|
|
157
204
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
205
|
+
desc.call('sync[{0}]')
|
|
206
|
+
task 'sync' do |t, args|
|
|
207
|
+
opts = if stage == 'init'
|
|
208
|
+
[]
|
|
209
|
+
else
|
|
210
|
+
raise_error 'repo not initialized' unless branch
|
|
211
|
+
repo_opts
|
|
212
|
+
end
|
|
213
|
+
args.to_a.each do |val|
|
|
214
|
+
case val
|
|
215
|
+
when /^force(-checkout)?$/
|
|
216
|
+
opts << '--force-checkout'
|
|
217
|
+
when 'rebase', 'detach'
|
|
218
|
+
opts << "--#{val}"
|
|
219
|
+
when /^(fetch-)?submodules$/
|
|
220
|
+
opts << '--fetch-submodules' if repo_submodules?(true, **envargs)
|
|
221
|
+
when /^(fail-)?fail$/
|
|
222
|
+
opts << '--fail-fast'
|
|
223
|
+
when /^no-(manifest-)?update$/
|
|
224
|
+
opts << '--no-manifest-update'
|
|
225
|
+
when /^(auto-)?gc$/
|
|
226
|
+
opts << '--auto-gc'
|
|
171
227
|
end
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
task 'sync' do |t, args|
|
|
184
|
-
opts = if stage == 'init'
|
|
185
|
-
[]
|
|
186
|
-
else
|
|
187
|
-
raise_error 'repo not initialized' unless branch
|
|
188
|
-
repo_opts
|
|
189
|
-
end
|
|
190
|
-
args.to_a.each do |val|
|
|
191
|
-
case val
|
|
192
|
-
when 'force'
|
|
193
|
-
opts << '--force-checkout'
|
|
194
|
-
when 'rebase', 'detach'
|
|
195
|
-
opts << "--#{val}"
|
|
196
|
-
when 'submodules'
|
|
197
|
-
opts << '--fetch-submodules' if repo_submodules?(true)
|
|
198
|
-
when 'fail'
|
|
199
|
-
opts << '--fail-fast'
|
|
200
|
-
when 'no-update'
|
|
201
|
-
opts << '--no-manifest-update'
|
|
202
|
-
when 'gc'
|
|
203
|
-
opts << '--auto-gc'
|
|
228
|
+
end
|
|
229
|
+
opts << "-j#{ENV.fetch('REPO_JOBS', Rake::CpuCounter.count)}" unless opts.any?(/^--?j(obs)?$/)
|
|
230
|
+
opts << '--fetch-submodules' if repo_submodules?(**envargs)
|
|
231
|
+
begin
|
|
232
|
+
repo_run('sync', opts, exception: opts.include?('--fail-fast'), options: stage != 'init')
|
|
233
|
+
rescue Errno::ENOENT => e
|
|
234
|
+
emphasize(e, title: root)
|
|
235
|
+
raise
|
|
236
|
+
rescue => e
|
|
237
|
+
emphasize(e, title: "rake stash #{t.name}")
|
|
238
|
+
raise
|
|
204
239
|
end
|
|
205
240
|
end
|
|
206
|
-
opts << "-j#{ENV.fetch('REPO_JOBS', Rake::CpuCounter.count)}" unless opts.any?(/^--?j(?:obs)?/)
|
|
207
|
-
opts << '--fetch-submodules' if repo_submodules?
|
|
208
|
-
begin
|
|
209
|
-
repo_run("#{repo_bin} sync #{opts.uniq.join(' ')}", exception: opts.include?('--fail-fast'))
|
|
210
|
-
rescue Errno::ENOENT => e
|
|
211
|
-
emphasize(e, title: root)
|
|
212
|
-
raise
|
|
213
|
-
rescue StandardError => e
|
|
214
|
-
emphasize(e, title: "rake stash #{t.name}")
|
|
215
|
-
raise
|
|
216
|
-
end
|
|
217
|
-
end
|
|
218
241
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
242
|
+
series.sync.push(
|
|
243
|
+
task_join(path, 'all'),
|
|
244
|
+
task_join(path, 'init'),
|
|
245
|
+
task_join(path, 'sync')
|
|
246
|
+
)
|
|
247
|
+
end
|
|
224
248
|
end
|
|
249
|
+
self.closed = 'repo:end'
|
|
225
250
|
end
|
|
226
251
|
|
|
227
252
|
def repo_manifest(path = root)
|
|
@@ -244,12 +269,16 @@ module Squared
|
|
|
244
269
|
else
|
|
245
270
|
Common::Prompt.confirm(
|
|
246
271
|
"#{log_title(:warn)} \"#{path}\" is not empty. Continue with installation?", 'N',
|
|
247
|
-
force: true, timeout: env('REPO_TIMEOUT')
|
|
272
|
+
force: true, timeout: env('REPO_TIMEOUT') { |n| n if (n = n.to_i) > 0 } || 15
|
|
248
273
|
)
|
|
249
274
|
end
|
|
250
275
|
end
|
|
251
276
|
|
|
252
|
-
def repo_run(cmd, exception: false)
|
|
277
|
+
def repo_run(cmd, opts = [], exception: false, options: true, **kwargs)
|
|
278
|
+
cmd = [repo_bin, cmd]
|
|
279
|
+
cmd << opts.uniq.join(' ') unless opts.empty?
|
|
280
|
+
env('REPO_OPTIONS', **kwargs) { |val| cmd << val } if options
|
|
281
|
+
cmd = cmd.join(' ')
|
|
253
282
|
puts log_message(cmd, subject: main, hint: root) if verbose
|
|
254
283
|
Common::System.shell(cmd, chdir: root, exception: exception)
|
|
255
284
|
end
|
|
@@ -257,35 +286,71 @@ module Squared
|
|
|
257
286
|
def repo_bin
|
|
258
287
|
return Common::Shell.shell_bin('repo') unless @repo_bin
|
|
259
288
|
|
|
260
|
-
@repo_bin.join('repo')
|
|
261
|
-
|
|
289
|
+
bin = @repo_bin.join('repo')
|
|
290
|
+
return bin if bin.file?
|
|
262
291
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
end
|
|
292
|
+
require 'open-uri'
|
|
293
|
+
puts log_message('Installing repo...', subject: main, hint: @repo_bin) if verbose
|
|
294
|
+
URI.open(REPO_URL) do |url|
|
|
295
|
+
@repo_bin.mkpath
|
|
296
|
+
File.open(bin, 'wb') do |f|
|
|
297
|
+
f.write(url.read)
|
|
298
|
+
f.chmod(0o755)
|
|
271
299
|
end
|
|
272
300
|
end
|
|
301
|
+
bin
|
|
273
302
|
end
|
|
274
303
|
|
|
275
|
-
def
|
|
276
|
-
|
|
304
|
+
def repo_workspace(name)
|
|
305
|
+
g, r = @global[name].fetch_values(:group, :ref)
|
|
306
|
+
g = g.keys
|
|
307
|
+
r = r.keys
|
|
308
|
+
pass = g.empty? && r.empty?
|
|
309
|
+
select do |proj|
|
|
310
|
+
next unless proj.enabled?(baseref)
|
|
277
311
|
|
|
278
|
-
|
|
312
|
+
proj.global_set(name)
|
|
313
|
+
i = -1
|
|
314
|
+
n = repo_scriptdata(proj, name).reduce(0) do |a, b|
|
|
315
|
+
i += 1
|
|
316
|
+
next a unless b
|
|
317
|
+
|
|
318
|
+
a + (1 << i)
|
|
319
|
+
end
|
|
320
|
+
proj.global(n) && (pass || g.include?(proj.group) || r.any? { |val| proj.ref?(val) })
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
def repo_scriptdata(proj, name)
|
|
325
|
+
proj.scriptdata(:global, name: name).fetch_values(:run, :script, :doc, :test)
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
def repo_call(proj, meth, sync: nil)
|
|
329
|
+
name = task_join proj.name, meth
|
|
330
|
+
detect = proj.workspace.task_defined?(name)
|
|
331
|
+
if proj.has?(meth) && (!detect || !sync.nil?)
|
|
332
|
+
if sync.nil?
|
|
333
|
+
proj.__send__(meth)
|
|
334
|
+
else
|
|
335
|
+
proj.__send__(meth, sync: sync)
|
|
336
|
+
end
|
|
337
|
+
elsif detect
|
|
338
|
+
task_invoke(name, **proj.workspace.invokeargs)
|
|
339
|
+
end
|
|
340
|
+
rescue => e
|
|
341
|
+
raise if exception
|
|
342
|
+
|
|
343
|
+
warn log_warn(e, pass: true) if warning
|
|
279
344
|
end
|
|
280
345
|
|
|
281
|
-
def
|
|
282
|
-
return
|
|
346
|
+
def repo_opts(*args)
|
|
347
|
+
return args unless (n = ARGV.index('--'))
|
|
283
348
|
|
|
284
|
-
|
|
349
|
+
ARGV[n.succ..-1].concat(args)
|
|
285
350
|
end
|
|
286
351
|
|
|
287
|
-
def repo_submodules?(val = false)
|
|
288
|
-
case (s = env('REPO_SUBMODULES'))
|
|
352
|
+
def repo_submodules?(val = false, **kwargs)
|
|
353
|
+
case (s = env('REPO_SUBMODULES', **kwargs))
|
|
289
354
|
when '0', 'false'
|
|
290
355
|
false
|
|
291
356
|
else
|