squared 0.4.17 → 0.4.19

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.
@@ -25,8 +25,8 @@ module Squared
25
25
  common: %w[no-color V|verbose retry=i].freeze,
26
26
  install: %w[frozen no-cache no-prune system binstubs=p? path=p standalone=q? target-rbconfig=p trust-policy=b
27
27
  with=q without=q].freeze,
28
- install_base: %w[full-index quiet retry gemfile=p j|jobs=i].freeze,
29
- update: %w[conservative local pre redownload ruby strict bundler=b? g|group=q source=b].freeze,
28
+ install_base: %w[force full-index quiet redownload retry gemfile=p j|jobs=i].freeze,
29
+ update: %w[conservative local pre ruby strict bundler=b? g|group=q source=b].freeze,
30
30
  outdated: %w[filter-major filter-minor filter-patch groups local parseable pre only-explicit strict
31
31
  update-strict g|group=q source=b].freeze,
32
32
  exec: %w[gemfile=p].freeze,
@@ -102,7 +102,13 @@ module Squared
102
102
  end
103
103
  dependfile_set GEMFILE
104
104
  @autodetect = autodetect
105
- @gemfile = path + gemspec if gemspec
105
+ @gemfile = if gemspec == false
106
+ false
107
+ elsif gemspec
108
+ path + (gemspec.include?('.') ? gemspec : "#{gemspec}.gemspec")
109
+ elsif (gemspec = path + "#{name}.gemspec").exist? || (gemspec = path + "#{project}.gemspec").exist?
110
+ gemspec
111
+ end
106
112
  return if !@output[0].nil? || !@copy.nil? || version || @autodetect || !rakefile
107
113
 
108
114
  begin
@@ -140,21 +146,21 @@ module Squared
140
146
  format_desc action, nil, "task+,opts*|#{indexchar}index+|#,pattern*"
141
147
  task action, [:command] do |_, args|
142
148
  if args.command == '#'
143
- format_list(read_rakefile, "rake[#{indexchar}N]", 'tasks', grep: args.extras, from: rakefile,
144
- each: ->(val) { val[0] + val[1].to_s })
149
+ format_list(raketasks, "rake[#{indexchar}N]", 'tasks', grep: args.extras, from: rakefile,
150
+ each: ->(val) { val[0] + val[1].to_s })
145
151
  else
146
152
  args, opts = args.to_a.partition { |val| indexitem(val) }
147
153
  if args.empty?
148
154
  rake(opts: opts)
149
155
  else
150
- list = read_rakefile
156
+ tasks = raketasks
151
157
  while (n, pre = indexitem(args.shift))
152
- if (item = list[n - 1])
158
+ if (item = tasks[n - 1])
153
159
  cmd = pre ? "#{pre} #{item.first}" : item.first
154
160
  elsif exception
155
- indexerror n, list
161
+ indexerror n, tasks
156
162
  else
157
- log.warn "rake task #{n} of #{list.size} (out of range)"
163
+ log.warn "rake task #{n} of #{tasks.size} (out of range)"
158
164
  next
159
165
  end
160
166
  if opts.empty?
@@ -177,7 +183,8 @@ module Squared
177
183
  else
178
184
  format_desc(action, nil, 'opts*', before: case action
179
185
  when 'cache', 'check' then nil
180
- else 'command+' end)
186
+ else 'command+'
187
+ end)
181
188
  task action do |_, args|
182
189
  bundle(action, *args.to_a)
183
190
  end
@@ -426,14 +433,23 @@ module Squared
426
433
 
427
434
  def install(flag, opts = [])
428
435
  bundle_session 'install', "--#{flag}"
429
- append_bundle opts, OPT_BUNDLE[:install_base] + OPT_BUNDLE[:install] + OPT_BUNDLE[:common]
436
+ op = append_bundle opts, OPT_BUNDLE[:install_base] + OPT_BUNDLE[:install] + OPT_BUNDLE[:common]
437
+ if op.arg?('force')
438
+ op.delete('--force')
439
+ if flag != :redownload
440
+ op << '--redownload'
441
+ elsif (lock = basepath('Gemfile.lock')).exist?
442
+ config = basepath('.bundle', 'config')
443
+ lock.delete unless config.exist? && config.read.match?(/\bBUNDLE_FROZEN:\s+"true"/)
444
+ end
445
+ end
430
446
  run_rb(from: :install)
431
447
  end
432
448
 
433
449
  def update(flag, opts = [])
434
450
  bundle_session 'update', "--#{flag}"
435
451
  append_bundle(opts, OPT_BUNDLE[:install_base] + OPT_BUNDLE[:update] + OPT_BUNDLE[:common],
436
- append: flag == :all ? nil : /\A\w+=/)
452
+ append: flag == :all ? nil : /\A[a-z-]+=/)
437
453
  run_rb(from: :update)
438
454
  end
439
455
 
@@ -815,14 +831,11 @@ module Squared
815
831
  def gemspec
816
832
  return @gemspec unless @gemspec.nil?
817
833
 
818
- begin
819
- if (file = gemfile)
820
- @gemspec = Gem::Specification.load(file.to_s)
821
- end
822
- rescue StandardError => e
823
- log.debug e
824
- end
825
- @gemspec ||= false
834
+ @gemspec = if (file = gemfile)
835
+ Gem::Specification.load(file.to_s) rescue false
836
+ else
837
+ false
838
+ end
826
839
  end
827
840
 
828
841
  def gemname
@@ -938,6 +951,7 @@ module Squared
938
951
  else
939
952
  op.clear
940
953
  end
954
+ op
941
955
  end
942
956
 
943
957
  def ruby_session(*cmd, **kwargs)
@@ -979,27 +993,10 @@ module Squared
979
993
  session_output('rake', *cmd, **kwargs)
980
994
  end
981
995
 
982
- def read_rakefile
983
- @read_rakefile ||= [].tap do |ret|
984
- opt = rakepwd
985
- pwd_set(pass: !opt.nil?) do
986
- IO.popen(rake_output(opt, '-AT').to_s).each do |line|
987
- next unless line =~ /^rake ((?:[^\[: ]+:?)+)(\[[^\]]+\])?/
988
-
989
- ret << [$1, $2]
990
- end
991
- end
992
- end
993
- end
994
-
995
996
  def preopts
996
997
  verbosetype > 1 && !session_arg?('quiet') ? ['--verbose'] : []
997
998
  end
998
999
 
999
- def gemdir?
1000
- !@gemdir.nil? && @gemdir.exist? && !@gemdir.empty?
1001
- end
1002
-
1003
1000
  def variables
1004
1001
  (super + %i[version autodetect]).freeze
1005
1002
  end
@@ -1017,6 +1014,19 @@ module Squared
1017
1014
  quote_option 'C', path
1018
1015
  end
1019
1016
 
1017
+ def raketasks
1018
+ @raketasks ||= [].tap do |ret|
1019
+ opt = rakepwd
1020
+ pwd_set(pass: !opt.nil?) do
1021
+ IO.popen(rake_output(opt, '-AT').to_s).each do |line|
1022
+ next unless line =~ /^rake ((?:[^\[: ]+:?)+)(\[[^\]]+\])?/
1023
+
1024
+ ret << [$1, $2]
1025
+ end
1026
+ end
1027
+ end
1028
+ end
1029
+
1020
1030
  def gempwd
1021
1031
  return unless !pwd? && semgte?(Gem::VERSION, '3.4.2')
1022
1032
 
@@ -1044,6 +1054,12 @@ module Squared
1044
1054
  def gempath(val = version)
1045
1055
  File.join('gems', "#{gemname}-#{val}")
1046
1056
  end
1057
+
1058
+ def gemdir?
1059
+ !@gemdir.nil? && @gemdir.exist? && !@gemdir.empty?
1060
+ end
1061
+
1062
+ alias read_rakefile raketasks
1047
1063
  end
1048
1064
 
1049
1065
  Application.implement Ruby
@@ -10,15 +10,22 @@ module Squared
10
10
  include Common::Shell
11
11
  extend Forwardable
12
12
 
13
+ OPT_VALUE = /\A([^=]+)=(.+)\z/
14
+ private_constant :OPT_VALUE
15
+
13
16
  class << self
14
17
  include Common::Format
15
18
  include Shell
16
19
  include Prompt
17
20
 
18
- def append(target, *args, delim: false, escape: false, quote: true, **)
21
+ def append(target, *args, delim: false, escape: false, quote: true, strip: nil, **)
19
22
  return if (ret = args.flatten).empty?
20
23
 
21
24
  target << '--' if delim && !target.include?('--')
25
+ if strip
26
+ pat, s = Array(strip)
27
+ ret.map! { |val| val.gsub(pat, s || '') }
28
+ end
22
29
  ret.map! { |val| escape ? shell_escape(val, quote: quote) : shell_quote(val) } if escape || quote
23
30
  if target.is_a?(Set)
24
31
  target.merge(ret)
@@ -31,7 +38,7 @@ module Squared
31
38
  def clear(target, opts, pass: true, styles: nil, **kwargs)
32
39
  return if opts.empty?
33
40
 
34
- kwargs[:subject] ||= stripext(target.first)
41
+ kwargs[:subject] ||= stripext target.first
35
42
  kwargs[:hint] ||= 'unrecognized'
36
43
  append(target, opts, delim: true) if kwargs.delete(:append)
37
44
  warn log_message(Logger::WARN, opts.join(', '), pass: true, **kwargs)
@@ -57,10 +64,10 @@ module Squared
57
64
  def arg?(target, *args, value: false, **)
58
65
  r, s = args.partition { |val| val.is_a?(Regexp) }
59
66
  unless s.empty?
60
- s.map! { |val| Regexp.escape(shell_option(val)) }
67
+ s.map! { |val| Regexp.escape(val.start_with?('-') ? val : shell_option(val)) }
61
68
  r << /\A(?:#{s.join('|')})#{value ? '[ =].' : '(?: |=|\z)'}/
62
69
  end
63
- target.any? { |opt| r.any? { |val| opt&.match?(val) } }
70
+ Array(target).compact.any? { |val| r.any? { |pat| pat.match?(val.to_s) } }
64
71
  end
65
72
 
66
73
  def pattern?(val)
@@ -73,13 +80,13 @@ module Squared
73
80
  def_delegators :@target, :+, :-, :<<, :any?, :none?, :include?, :add, :add?, :find, :find_all, :find_index,
74
81
  :merge, :delete, :delete?, :delete_if, :grep, :grep_v, :inspect, :to_a, :to_s
75
82
  def_delegators :@extras, :empty?, :each, :each_with_index, :partition, :dup, :first, :last, :shift, :unshift,
76
- :pop, :push, :index, :delete_at, :join, :map, :map!, :select, :reject, :size
83
+ :pop, :push, :concat, :index, :delete_at, :join, :map, :map!, :select, :select!, :reject, :size
77
84
 
78
85
  def_delegator :@extras, :delete, :remove
79
86
  def_delegator :@extras, :delete_if, :remove_if
80
87
 
81
88
  def initialize(opts, list, target = Set.new, project: nil, path: nil, **kwargs, &blk)
82
- @target = target.is_a?(Set) ? target : Set.new(target)
89
+ @target = target.is_a?(Set) ? target : target.to_set
83
90
  @project = project
84
91
  @path = path || project&.path
85
92
  @errors = []
@@ -163,7 +170,7 @@ module Squared
163
170
  elsif opt.start_with?('no-') && no.include?(name = opt[3..-1])
164
171
  add "--no-#{name}"
165
172
  else
166
- if opt =~ /\A([^=]+)=(.+)\z/
173
+ if opt =~ OPT_VALUE
167
174
  key = $1
168
175
  val = $2
169
176
  merge = m.include?(key)
@@ -208,6 +215,22 @@ module Squared
208
215
  self
209
216
  end
210
217
 
218
+ def uniq(list)
219
+ items = map { |val| nameonly(val) }
220
+ list.reject do |val|
221
+ next true if items.include?(s = nameonly(val))
222
+
223
+ pat = /\A#{s = fill_option(s)}(?:#{s.start_with?('--') ? '[= ]' : '.*'}|\z)/
224
+ any? { |opt| opt.match?(pat) }
225
+ end
226
+ end
227
+
228
+ def uniq!(list)
229
+ n = size
230
+ concat uniq(list)
231
+ extras if size > n
232
+ end
233
+
211
234
  def clear(opts = nil, errors: false, **kwargs)
212
235
  styles = project.theme[:inline] if project
213
236
  if !opts
@@ -274,7 +297,7 @@ module Squared
274
297
  unless found.empty?
275
298
  add '--' if delim
276
299
  extras.clear
277
- extras.concat(other)
300
+ concat other
278
301
  if path
279
302
  found.each { |val| add_path(val) }
280
303
  else
@@ -290,9 +313,33 @@ module Squared
290
313
  self
291
314
  end
292
315
 
316
+ def append?(key, val = nil, type: nil, force: false, **kwargs)
317
+ return false unless force || !arg?(key)
318
+
319
+ val = yield self if block_given?
320
+ return false unless val
321
+
322
+ type ||= :quote if kwargs.empty?
323
+ add case type
324
+ when :quote
325
+ quote_option(key, val)
326
+ when :basic
327
+ basic_option(key, val)
328
+ else
329
+ shell_option(key, val, **kwargs)
330
+ end
331
+ true
332
+ end
333
+
293
334
  def arg?(*args, **kwargs)
294
335
  OptionPartition.arg?(target, *args, **kwargs)
295
336
  end
337
+
338
+ private
339
+
340
+ def nameonly(val)
341
+ val[OPT_VALUE, 1] || val
342
+ end
296
343
  end
297
344
  end
298
345
  end
@@ -113,16 +113,16 @@ module Squared
113
113
  def __repo__(**kwargs)
114
114
  kwargs.delete(:parallel) if env('REPO_SYNC', ignore: '0')
115
115
 
116
- namespace(task_name('repo')) do |ns|
116
+ namespace task_name('repo') do |ns|
117
117
  path = ns.scope.path
118
118
  branch = env('REPO_MANIFEST') || Repo.read_manifest(root)
119
119
  target = branch || manifest
120
- cmd = nil
121
120
  stage = nil
122
- newline = ARGV.index { |val| val.start_with?('repo:') }.to_i > 0
121
+ opts = %w[force rebase detach submodules fail no-update gc]
122
+ newline = !ARGV.grep(/^repo:/).empty?
123
123
  desc = lambda do |val, alt = nil|
124
124
  if (ver = branch || alt)
125
- val = val.sub('{0}', 'opts*=force,rebase,detach,fail,no-update,gc')
125
+ val = val.sub('{0}', "opts*=#{opts.join(',')}")
126
126
  task_desc(path, val, ver)
127
127
  else
128
128
  task_desc 'inactive'
@@ -130,10 +130,9 @@ module Squared
130
130
  end
131
131
 
132
132
  desc.call('all[{0}]')
133
- task 'all', [:opts] do |_, args|
134
- cmd ||= repo_opts args
133
+ task 'all' do |_, args|
135
134
  stage ||= 'all'
136
- ns['sync'].invoke
135
+ ns['sync'].invoke(*args.to_a)
137
136
  next if env('REPO_STAGE', equals: '1')
138
137
 
139
138
  @project.select do |_, proj|
@@ -156,26 +155,60 @@ module Squared
156
155
  end
157
156
  end
158
157
 
159
- desc.call("init[manifest?=#{target},{0}]", target)
160
- task 'init', [:manifest, :opts] do |_, args|
161
- cmd = repo_opts args
158
+ desc.call("init[manifest?=#{target},groups?,{0}]", target)
159
+ task 'init' do |_, args|
160
+ args = args.to_a
161
+ u = env('REPO_URL') || manifest_url
162
+ m = args.first && !opts.include?(args.first) ? args.shift : target
163
+ g = args.first && !opts.include?(args.first) ? args.shift : nil
164
+ g = case (val = env('REPO_GROUPS'))
165
+ when '', NilClass
166
+ g
167
+ when '0', 'false'
168
+ nil
169
+ else
170
+ val
171
+ end
162
172
  stage = 'init'
163
173
  puts if newline
164
- Common::System.shell("repo init -u #{env('REPO_URL') || manifest_url} -m #{args.manifest || target}.xml",
165
- chdir: root)
174
+ opts = repo_opts "-u #{u}", "-m #{m}.xml"
175
+ opts << "-g #{g}" if g
176
+ opts << '--submodules' if repo_submodules?(args.include?('submodules'))
177
+ repo_run "#{repo_bin} init #{opts.uniq.join(' ')}"
166
178
  next if env('REPO_STAGE', equals: '0')
167
179
 
168
- ns['all'].invoke
180
+ ns['all'].invoke(*args)
169
181
  end
170
182
 
171
183
  desc.call('sync[{0}]')
172
- task 'sync', [:opts] do |t, args|
173
- raise_error 'repo not initialized' unless branch || stage == 'init'
174
- cmd ||= repo_opts args
175
- cmd << "-j#{ENV.fetch('REPO_JOBS', Rake::CpuCounter.count)}"
184
+ task 'sync' do |t, args|
185
+ opts = if stage == 'init'
186
+ []
187
+ else
188
+ raise_error 'repo not initialized' unless branch
189
+ repo_opts
190
+ end
191
+ args.to_a.each do |val|
192
+ case val
193
+ when 'force'
194
+ opts << '--force-checkout'
195
+ when 'rebase', 'detach'
196
+ opts << "--#{val}"
197
+ when 'submodules'
198
+ opts << '--fetch-submodules' if repo_submodules?(true)
199
+ when 'fail'
200
+ opts << '--fail-fast'
201
+ when 'no-update'
202
+ opts << '--no-manifest-update'
203
+ when 'gc'
204
+ opts << '--auto-gc'
205
+ end
206
+ end
207
+ opts << "-j#{ENV.fetch('REPO_JOBS', Rake::CpuCounter.count)}" unless opts.grep(/^--?j(?:obs)?/).empty?
208
+ opts << '--fetch-submodules' if repo_submodules?
176
209
  puts unless !newline || stage == 'init'
177
210
  begin
178
- Common::System.shell("repo sync #{cmd.join(' ')}", chdir: root, exception: cmd.include?('--fail-fast'))
211
+ repo_run("#{repo_bin} sync #{opts.uniq.join(' ')}", exception: opts.include?('--fail-fast'))
179
212
  rescue Errno::ENOENT => e
180
213
  emphasize(e, title: root)
181
214
  raise
@@ -204,31 +237,34 @@ module Squared
204
237
  )
205
238
  end
206
239
 
207
- def repo_opts(args)
208
- ret = []
209
- args.to_a.each do |val|
210
- case val
211
- when 'force'
212
- ret << '--force-checkout'
213
- when 'rebase'
214
- ret << '--rebase'
215
- when 'detach'
216
- ret << '--detach'
217
- when 'fail'
218
- ret << '--fail-fast'
219
- when 'no-update'
220
- ret << '--no-manifest-update'
221
- when 'gc'
222
- ret << '--auto-gc'
223
- end
224
- end
225
- ret
240
+ def repo_run(cmd, exception: false)
241
+ puts log_message(Logger::INFO, cmd, subject: main, hint: root) if verbose
242
+ Common::System.shell(cmd, chdir: root, exception: exception)
243
+ end
244
+
245
+ def repo_bin
246
+ Common::Shell.shell_bin('repo')
247
+ end
248
+
249
+ def repo_opts(*args)
250
+ return args unless (n = ARGV.index('--'))
251
+
252
+ ARGV[(n + 1)..-1].concat(args)
226
253
  end
227
254
 
228
255
  def repo?
229
256
  !manifest_url.nil? && (repo_install? || @repo_override == true)
230
257
  end
231
258
 
259
+ def repo_submodules?(val = false)
260
+ case (s = env('REPO_SUBMODULES'))
261
+ when '0', 'false'
262
+ false
263
+ else
264
+ s ? true : val
265
+ end
266
+ end
267
+
232
268
  def repo_install?(dir = root, parent: false)
233
269
  return true if root?(dir, pass: ['.repo']) || dir.join('.repo').directory?
234
270
 
data/squared.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = %q{Rake task generator for managing multi-language workspaces.}
12
12
  spec.description = %q{Rake task generator for managing multi-language workspaces.}
13
- spec.homepage = "https://github.com/anpham6/squared"
13
+ spec.homepage = "https://github.com/anpham6/squared-ruby"
14
14
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
15
15
  spec.licenses = ["BSD-3-Clause"]
16
16
 
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.metadata["documentation_uri"] = "https://squared.readthedocs.io"
20
20
 
21
21
  spec.files = Dir["lib/**/*"] +
22
- %w[CHANGELOG.md LICENSE README.md README.ruby.md squared.gemspec]
22
+ %w[CHANGELOG.md LICENSE README.md squared.gemspec]
23
23
  spec.bindir = "exe"
24
24
  spec.executables = []
25
25
  spec.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.17
4
+ version: 0.4.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham
@@ -75,7 +75,6 @@ files:
75
75
  - CHANGELOG.md
76
76
  - LICENSE
77
77
  - README.md
78
- - README.ruby.md
79
78
  - lib/squared.rb
80
79
  - lib/squared/app.rb
81
80
  - lib/squared/common.rb
@@ -105,12 +104,12 @@ files:
105
104
  - lib/squared/workspace/support/base.rb
106
105
  - lib/squared/workspace/support/data.rb
107
106
  - squared.gemspec
108
- homepage: https://github.com/anpham6/squared
107
+ homepage: https://github.com/anpham6/squared-ruby
109
108
  licenses:
110
109
  - BSD-3-Clause
111
110
  metadata:
112
- homepage_uri: https://github.com/anpham6/squared
113
- source_code_uri: https://github.com/anpham6/squared
111
+ homepage_uri: https://github.com/anpham6/squared-ruby
112
+ source_code_uri: https://github.com/anpham6/squared-ruby
114
113
  documentation_uri: https://squared.readthedocs.io
115
114
  rdoc_options: []
116
115
  require_paths: