squared 0.6.2 → 0.6.4

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.
@@ -3,9 +3,12 @@
3
3
  module Squared
4
4
  module Workspace
5
5
  module Repo
6
+ REPO_URL = 'https://storage.googleapis.com/git-repo-downloads/repo'
7
+ private_constant :REPO_URL
8
+
6
9
  attr_reader :manifest_url, :manifest
7
10
 
8
- def repo(url, manifest = 'latest', run: nil, script: nil, args: nil, dev: nil, prod: nil,
11
+ def repo(url, manifest = 'latest', install: nil, run: nil, script: nil, args: nil, dev: nil, prod: nil,
9
12
  ref: @ref, group: @group)
10
13
  @home = if (val = env('REPO_HOME'))
11
14
  path = Pathname.new(val)
@@ -101,6 +104,7 @@ module Squared
101
104
  data[:prod] = prod
102
105
  script_set(data, group: group, ref: ref)
103
106
  end
107
+ @repo_bin = install.is_a?(String) ? @root + install : @root if install
104
108
  self
105
109
  end
106
110
 
@@ -128,20 +132,20 @@ module Squared
128
132
  task 'all' do |_, args|
129
133
  stage ||= 'all'
130
134
  ns['sync'].invoke(*args.to_a)
131
- next if (stage = env('REPO_STAGE')) == '1'
135
+ next if (n = env('REPO_STAGE')) == '1'
132
136
 
133
- @project.select do |_, proj|
137
+ select do |proj|
134
138
  next unless proj.enabled?(proj.workspace.baseref) && proj.global
135
139
 
136
140
  proj.depend(sync: true) if proj.depend?
137
- next if stage == '2'
141
+ next if n == '2'
138
142
 
139
143
  proj.build?
140
144
  end
141
- .each_value do |proj|
145
+ .each do |proj|
142
146
  proj.build(sync: true)
143
- next if stage == '3'
144
- next unless proj.copy? && (proj.dev? || stage == '4')
147
+ next if n == '3'
148
+ next unless proj.copy? && (proj.dev? || n == '4')
145
149
 
146
150
  if (ws = proj.workspace).task_defined?(target = task_join(proj.name, 'copy'))
147
151
  task_invoke(target, **ws.invokeargs)
@@ -154,7 +158,7 @@ module Squared
154
158
  desc.call("init[manifest?=#{target},groups?,{0}]", target)
155
159
  task 'init' do |_, args|
156
160
  args = args.to_a
157
- u = env('REPO_URL') || manifest_url
161
+ u = env('REPO_GIT') || manifest_url
158
162
  m = args.first && !opts.include?(args.first) ? args.shift : target
159
163
  g = (args.shift if args.first && !opts.include?(args.first))
160
164
  g = case (val = env('REPO_GROUPS'))
@@ -221,7 +225,7 @@ module Squared
221
225
  end
222
226
 
223
227
  def repo_manifest(path = root)
224
- return unless (file = path + '.repo/manifest.xml').exist?
228
+ return unless (file = Pathname.new(path).join('.repo/manifest.xml')).exist?
225
229
 
226
230
  require 'rexml/document'
227
231
  doc = REXML::Document.new(file.read)
@@ -231,21 +235,42 @@ module Squared
231
235
  def repo_confirm
232
236
  return false unless root.directory?
233
237
 
234
- path = sub_style(root, styles: theme[:inline])
235
- @repo_override = env('REPO_Y', equals: '1') || Common::Prompt.confirm(
236
- "#{log_title(:warn)} \"#{path}\" is not empty. Continue with installation?",
237
- 'N',
238
- timeout: env('REPO_TIMEOUT', 15, ignore: '0')
239
- )
238
+ path = sub_style root, theme[:inline]
239
+ @repo_override = case env('REPO_Y')
240
+ when '0', 'false'
241
+ false
242
+ when '1', 'true'
243
+ true
244
+ else
245
+ Common::Prompt.confirm(
246
+ "#{log_title(:warn)} \"#{path}\" is not empty. Continue with installation?",
247
+ 'N',
248
+ force: true, timeout: env('REPO_TIMEOUT', 15, ignore: '0')
249
+ )
250
+ end
240
251
  end
241
252
 
242
253
  def repo_run(cmd, exception: false)
243
- puts log_message(Logger::INFO, cmd, subject: main, hint: root) if verbose
254
+ puts log_message(cmd, subject: main, hint: root) if verbose
244
255
  Common::System.shell(cmd, chdir: root, exception: exception)
245
256
  end
246
257
 
247
258
  def repo_bin
248
- Common::Shell.shell_bin('repo')
259
+ return Common::Shell.shell_bin('repo') unless @repo_bin
260
+
261
+ @repo_bin.join('repo').tap do |bin|
262
+ next if bin.file?
263
+
264
+ require 'open-uri'
265
+ puts log_message('Installing repo...', subject: main, hint: @repo_bin) if verbose
266
+ URI.open(REPO_URL) do |url|
267
+ @repo_bin.mkpath
268
+ File.open(bin, 'wb') do |f|
269
+ f.write(url.read)
270
+ f.chmod(0o755)
271
+ end
272
+ end
273
+ end
249
274
  end
250
275
 
251
276
  def repo_opts(*args)
@@ -255,7 +280,9 @@ module Squared
255
280
  end
256
281
 
257
282
  def repo?
258
- !manifest_url.nil? && (repo_install? || @repo_override == true)
283
+ return false unless manifest_url && !windows?
284
+
285
+ repo_install? || @repo_override == true
259
286
  end
260
287
 
261
288
  def repo_submodules?(val = false)
@@ -11,10 +11,11 @@ module Squared
11
11
  TASK_BASE = []
12
12
  TASK_BATCH = {}
13
13
  TASK_EXTEND = Support.hashlist
14
+ TASK_METHODS = {}
14
15
  TASK_KEYS = []
15
16
  TASK_ALIAS = Support.hashobj
16
17
  TASK_NAME = {}
17
- private_constant :TASK_BASE, :TASK_BATCH, :TASK_EXTEND, :TASK_KEYS, :TASK_ALIAS, :TASK_NAME
18
+ private_constant :TASK_BASE, :TASK_BATCH, :TASK_EXTEND, :TASK_METHODS, :TASK_KEYS, :TASK_ALIAS, :TASK_NAME
18
19
 
19
20
  class << self
20
21
  def add(task, obj)
@@ -52,6 +53,11 @@ module Squared
52
53
  TASK_BASE.concat(obj.tasks.reject { |val| TASK_KEYS.include?(val) })
53
54
  end
54
55
 
56
+ def extend_set(obj)
57
+ obj.tasks&.each { |task| add(task, obj) }
58
+ TASK_METHODS[obj] = obj.instance_methods(false)
59
+ end
60
+
55
61
  private
56
62
 
57
63
  def key_set(val)
@@ -64,7 +70,8 @@ module Squared
64
70
 
65
71
  attr_reader :sync, :multiple, :parallel
66
72
 
67
- def_delegators :@data, :[], :each, :each_key, :keys, :key?, :fetch, :update, :merge!, :to_a, :to_s, :inspect
73
+ def_delegators :@data, :[], :each, :each_key, :keys, :key?, :include?, :fetch, :update, :merge!, :any?, :none?,
74
+ :delete, :delete_if, :find, :find_all, :to_a, :to_s, :inspect
68
75
  def_delegators :@workspace, :task_desc, :task_name, :task_namespace, :task_join, :format_desc
69
76
 
70
77
  def initialize(workspace, exclude: [])
@@ -79,14 +86,12 @@ module Squared
79
86
  parent: Support.hashlist,
80
87
  id: []
81
88
  }
82
- @data = {}
83
- (TASK_BASE + TASK_KEYS).each { |key| @data[key] = [] }
84
89
  end
85
90
 
86
91
  def populate(proj, **)
87
92
  group, parent, id = @session.values
88
93
  ws = proj.workspace
89
- @data.each do |key, items|
94
+ each do |key, items|
90
95
  next if exclude?(key) || (tasks = ws.task_resolve(proj, key)).empty?
91
96
 
92
97
  if (g = proj.group)
@@ -108,9 +113,9 @@ module Squared
108
113
 
109
114
  def build(parallel: [], pattern: [], **)
110
115
  subcheck = ->(val) { (ns = task_namespace(val)) && parallel.include?(ns) }
111
- @data.update(@session[:parent]) if @session[:id].uniq.size > 1
112
- @data.update(@session[:group])
113
- @data.each do |key, items|
116
+ update @session[:parent] if @session[:id].uniq.size > 1
117
+ update @session[:group]
118
+ each do |key, items|
114
119
  next if exclude?(key, true) || @workspace.task_exclude?(t = name_get(key))
115
120
 
116
121
  key = task_name t
@@ -156,6 +161,10 @@ module Squared
156
161
  task key => prereqs
157
162
  end
158
163
 
164
+ def reset
165
+ @data = {}.tap { |data| (TASK_BASE + TASK_KEYS).each { |key| data[key] = [] } }
166
+ end
167
+
159
168
  def name_get(key)
160
169
  (TASK_NAME[key] || key).to_s
161
170
  end
@@ -169,7 +178,7 @@ module Squared
169
178
  end
170
179
 
171
180
  def some?(key)
172
- return @data.key?(key) && !@data[key].empty? unless (batch = batch_get(key))
181
+ return key?(key) && !self[key].empty? unless (batch = batch_get(key))
173
182
 
174
183
  batch.each_value do |items|
175
184
  return true if items.all? { |val| some?(val) || alias_get(val)&.any? { |_, alt| some?(alt) } }
@@ -182,12 +191,14 @@ module Squared
182
191
  end
183
192
 
184
193
  def extend?(obj, key)
185
- return false unless (items = TASK_EXTEND[key]) && !(items = items.select { |kind| obj.is_a?(kind) }).empty?
194
+ return false unless (items = TASK_EXTEND[key])
186
195
 
187
- meth = :"#{key}?"
188
196
  ret = false
189
197
  items.each do |kind|
190
- if kind.instance_methods.include?(meth)
198
+ next unless obj.is_a?(kind)
199
+
200
+ meth = :"#{key}?"
201
+ if TASK_METHODS[kind].include?(meth)
191
202
  out = obj.__send__(meth)
192
203
  return true if out == 1
193
204
  return out if obj.ref?(kind.ref)
@@ -199,7 +210,9 @@ module Squared
199
210
  end
200
211
 
201
212
  def batch?(obj, key)
202
- (data = batch_get(key)) ? data.keys.any? { |ref| obj.ref?(ref) } : false
213
+ return false unless (data = batch_get(key))
214
+
215
+ data.keys.any? { |ref| obj.ref?(ref) }
203
216
  end
204
217
 
205
218
  def chain?(val)
@@ -226,7 +239,7 @@ module Squared
226
239
  end
227
240
 
228
241
  def exclude?(key, empty = false)
229
- @exclude.include?(key) || (empty && @data[key].empty?)
242
+ @exclude.include?(key) || (empty && self[key].empty?)
230
243
  end
231
244
 
232
245
  private
@@ -5,12 +5,14 @@ module Squared
5
5
  class << self
6
6
  include Common
7
7
 
8
- def resolve(*args)
9
- ret = args.map! do |id|
8
+ def resolve(*args, base: '..')
9
+ values = __get__(:project).values
10
+ ret = args.map do |id|
10
11
  if id.is_a?(Symbol)
11
12
  project id
12
13
  else
13
- __get__(:project).find { |_, val| File.expand_path(val.path) == File.expand_path(id, __dir__) }
14
+ values.find { |proj| proj.name == id } || values.find { |proj| proj.project == id } ||
15
+ values.find { |proj| proj.path.to_s == File.expand_path(id, base) }
14
16
  end
15
17
  end
16
18
  ret.size == 1 ? ret.first : ret
data/squared.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["An Pham"]
9
9
  spec.email = ["anpham6@gmail.com"]
10
10
 
11
- spec.summary = %q{Rake task generator for managing multi-language workspaces.}
12
- spec.description = %q{Rake task generator for managing multi-language workspaces.}
11
+ spec.summary = "Rake task generator for managing multi-language workspaces."
12
+ spec.description = "Rake task generator for managing multi-language workspaces."
13
13
  spec.homepage = "https://github.com/anpham6/squared-ruby"
14
14
  spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
15
15
  spec.licenses = ["BSD-3-Clause"]
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.6.2
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham
@@ -95,8 +95,8 @@ files:
95
95
  - lib/squared/workspace/project/node.rb
96
96
  - lib/squared/workspace/project/python.rb
97
97
  - lib/squared/workspace/project/ruby.rb
98
- - lib/squared/workspace/project/support.rb
99
98
  - lib/squared/workspace/project/support/class.rb
99
+ - lib/squared/workspace/project/support/optionpartition.rb
100
100
  - lib/squared/workspace/repo.rb
101
101
  - lib/squared/workspace/series.rb
102
102
  - lib/squared/workspace/support.rb
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'support/class'