dapp 0.10.4 → 0.11.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebff6933b83298b6ecb85ea23c7a2fe1db96dea0
4
- data.tar.gz: 92b09ea990eadd0be1ea22bbd55537d4f21ad9be
3
+ metadata.gz: b9bde6d6e0a2f2f7d9d630dfd5307d87900aefba
4
+ data.tar.gz: 4cfa173162595e257a8e5e0f0c8fbd70dba8c576
5
5
  SHA512:
6
- metadata.gz: 92599680d7a9da9693c5796962e6522f2548749502f7f4e74201c4b0ab734de05726f0a12e966c901caedb45f03af5ea3080ecc4b1f9de269c569774df0e7bc8
7
- data.tar.gz: f67dd984507cd589e1dbcf845ec57783ff53195f0cea54191968aef45179ab4f9f7675bf6f8fd6c1d224ee4930d5a0c837a26796959a47fba5d51809f2fff361
6
+ metadata.gz: 0a5fcb98d67e9d4111b22d4252623e661c348dfdb1bc0d7ff4404a2db8d9f1ba164782aa0953c8186edd641363f067261d251ecf8f505805daa18add74f5088e
7
+ data.tar.gz: 7d001567b2075340f756334d281c23d7eb4bff6331d34299e23203d79a04fb0e0730217f2c8ccf424b52862d30adf65c4f07f0046424e0046c557ae4fff0f333
@@ -64,6 +64,7 @@ require 'dapp/dimg/builder/shell'
64
64
  require 'dapp/dimg/builder/none'
65
65
  require 'dapp/dimg/build/stage/mod/logging'
66
66
  require 'dapp/dimg/build/stage/mod/group'
67
+ require 'dapp/dimg/build/stage/mod/git_artifact_dependencies'
67
68
  require 'dapp/dimg/build/stage/base'
68
69
  require 'dapp/dimg/build/stage/ga_base'
69
70
  require 'dapp/dimg/build/stage/ga_dependencies_base'
@@ -24,8 +24,8 @@ module Dapp
24
24
  end
25
25
 
26
26
  %w(rm rsync diff date cat
27
- stat readlink test sleep mkdir
28
- install sed cp true find
27
+ stat test sleep mkdir find
28
+ install sed cp true
29
29
  bash tar sudo).each do |cmd|
30
30
  define_method("#{cmd}_bin") { "/.dapp/deps/base/#{BASE_VERSION}/bin/#{cmd}" }
31
31
  end
@@ -30,44 +30,32 @@ module Dapp
30
30
 
31
31
  # rubocop:disable Metrics/ParameterLists
32
32
  def safe_cp(from, to, owner, group, include_paths = [], exclude_paths = [])
33
- ''.tap do |cmd|
34
- cmd << dimg.dapp.rsync_bin
35
- cmd << ' --archive --links'
36
- cmd << " --chown=#{owner}:#{group}" if owner or group
37
-
38
- if include_paths.any?
39
- # Если указали include_paths это означает, что надо копировать
40
- # только указанные пути. Поэтому exclude_paths в приоритете, т.к. в данном режиме
41
- # exclude_paths может относится только к путям, указанным в include_paths.
42
- # При этом случай, когда в include_paths указали более специальный путь, чем в exclude_paths,
43
- # будет обрабатываться в пользу exclude, этот путь не скопируется.
44
- exclude_paths.each do |p|
45
- cmd << " --filter='-/ #{File.join(from, p)}'"
46
- end
47
-
48
- include_paths.each do |p|
49
- # * На данный момент не знаем директорию или файл имел в виду пользователь,
50
- # поэтому подставляем фильтры для обоих возможных случаев.
51
- # * Автоматом подставляем паттерн ** для включения файлов, содержащихся в
52
- # директории, которую пользователь указал в include_paths.
53
- cmd << " --filter='+/ #{File.join(from, p)}'"
54
- cmd << " --filter='+/ #{File.join(from, p, '**')}'"
55
- end
56
-
57
- # Все что не подошло по include — исключается
58
- cmd << " --filter='-/ #{File.join(from, '**')}'"
59
- else
60
- exclude_paths.each do |p|
61
- cmd << " --filter='-/ #{File.join(from, p)}'"
62
- end
63
- end
64
-
65
- # Слэш после from — это инструкция rsync'у для копирования
66
- # содержимого директории from, а не самой директории.
67
- cmd << " #{from}/ #{to}"
33
+ credentials = ''
34
+ credentials += "-o #{owner} " if owner
35
+ credentials += "-g #{group} " if group
36
+ excludes = find_command_excludes(from, exclude_paths).join(' ')
37
+
38
+ copy_files = proc do |from_, path_ = ''|
39
+ "if [[ -d #{File.join(from_, path_)} ]] || [[ -f #{File.join(from_, path_)} ]]; then " \
40
+ "#{dimg.dapp.find_bin} #{File.join(from_, path_)} #{excludes} -type f -exec " \
41
+ "#{dimg.dapp.bash_bin} -ec '#{dimg.dapp.install_bin} -D #{credentials} \"{}\" " \
42
+ "\"#{File.join(to, '$(echo "{}" | ' \
43
+ "#{dimg.dapp.sed_bin} -e \"s/^#{from_.gsub('/', '\\/')}\\///g\")")}\"' \\; ;" \
44
+ 'fi'
68
45
  end
46
+
47
+ commands = []
48
+ commands << [dimg.dapp.install_bin, credentials, '-d', to].join(' ')
49
+ commands.concat(include_paths.empty? ? Array(copy_files.call(from)) : include_paths.map { |path| copy_files.call(from, path) })
50
+ commands << "#{dimg.dapp.find_bin} #{to} -type d -exec " \
51
+ "#{dimg.dapp.bash_bin} -ec '#{dimg.dapp.install_bin} -d #{credentials} {}' \\;"
52
+ commands.join(' && ')
69
53
  end
70
54
  # rubocop:enable Metrics/ParameterLists
55
+
56
+ def find_command_excludes(from, exclude_paths)
57
+ exclude_paths.map { |path| "-not \\( -path #{File.join(from, path)} -prune \\)" }
58
+ end
71
59
  end # ArtifactDefault
72
60
  end # Stage
73
61
  end # Build
@@ -168,7 +168,7 @@ module Dapp
168
168
  end
169
169
 
170
170
  def default_git_artifacts_dependencies(git_artifacts)
171
- git_artifacts.map { |git_artifact| git_artifact.stage_dependencies_checksum(self) }
171
+ git_artifacts.map { |git_artifact| git_artifact.stage_dependencies_checksums(self) }
172
172
  end
173
173
 
174
174
  def dependencies
@@ -3,6 +3,8 @@ module Dapp
3
3
  module Build
4
4
  module Stage
5
5
  class BeforeSetup < Base
6
+ include Mod::GitArtifactsDependencies
7
+
6
8
  def initialize(dimg, next_stage)
7
9
  @prev_stage = AfterInstallArtifact.new(dimg, self)
8
10
  super
@@ -3,6 +3,8 @@ module Dapp
3
3
  module Build
4
4
  module Stage
5
5
  class BuildArtifact < Base
6
+ include Mod::GitArtifactsDependencies
7
+
6
8
  def initialize(dimg)
7
9
  @prev_stage = GAArtifactPatch.new(dimg, self)
8
10
  @dimg = dimg
@@ -5,6 +5,7 @@ module Dapp
5
5
  module Install
6
6
  class Install < Base
7
7
  include Mod::Group
8
+ include Mod::GitArtifactsDependencies
8
9
 
9
10
  def initialize(dimg, next_stage)
10
11
  @prev_stage = GAPreInstallPatch.new(dimg, self)
@@ -0,0 +1,23 @@
1
+ module Dapp
2
+ module Dimg
3
+ module Build
4
+ module Stage
5
+ module Mod
6
+ module GitArtifactsDependencies
7
+ def local_git_artifacts_dependencies
8
+ dimg.local_git_artifacts.map do |git_artifact|
9
+ args = []
10
+ args << self
11
+ if dimg.dev_mode?
12
+ args << git_artifact.latest_commit
13
+ args << nil
14
+ end
15
+ git_artifact.stage_dependencies_checksums(*args)
16
+ end
17
+ end
18
+ end
19
+ end # Mod
20
+ end # Stage
21
+ end # Build
22
+ end # Dimg
23
+ end # Dapp
@@ -5,6 +5,7 @@ module Dapp
5
5
  module Setup
6
6
  class Setup < Base
7
7
  include Mod::Group
8
+ include Mod::GitArtifactsDependencies
8
9
 
9
10
  def initialize(dimg, next_stage)
10
11
  @prev_stage = GAPreSetupPatch.new(dimg, self)
@@ -52,27 +52,15 @@ module Dapp
52
52
  patch_command(stage.prev_g_a_stage.layer_commit(self), nil)
53
53
  end
54
54
 
55
- def stage_dependencies_checksum(stage)
55
+ def stage_dependencies_checksums(stage, from_commit = nil, to_commit = latest_commit)
56
56
  return [] if (stage_dependencies = stages_dependencies[stage.name]).empty?
57
57
 
58
- paths = (include_paths(true) + base_paths(stage_dependencies, true)).uniq
59
-
60
- to_commit = if repo.is_a? GitRepo::Own and repo.dimg.dev_mode?
61
- nil
62
- else
63
- latest_commit
58
+ paths = include_paths(true) + base_paths(stage_dependencies, true)
59
+ diff_patches(from_commit, to_commit, paths: paths).map do |patch|
60
+ delta_new_file = patch.delta.new_file
61
+ content = patch.hunks.map { |h| h.lines.select { |l| l.line_origin == :context }.map(&:content).join }.join
62
+ Digest::SHA256.hexdigest [delta_new_file[:path], content].join(':::')
64
63
  end
65
-
66
- diff_patches(nil, to_commit, paths: paths)
67
- .sort_by {|patch| patch.delta.new_file[:path]}
68
- .reduce(nil) {|prev_hash, patch|
69
- Digest::SHA256.hexdigest [
70
- prev_hash,
71
- patch.delta.new_file[:path],
72
- patch.delta.new_file[:mode].to_s,
73
- patch.to_s
74
- ].compact.join(':::')
75
- }
76
64
  end
77
65
 
78
66
  def patch_size(from, to)
@@ -97,7 +85,7 @@ module Dapp
97
85
  end
98
86
 
99
87
  def latest_commit
100
- @latest_commit ||= (commit || repo.latest_commit(branch))
88
+ @latest_commit ||= commit || repo.latest_commit(branch)
101
89
  end
102
90
 
103
91
  def paramshash
@@ -140,12 +128,8 @@ module Dapp
140
128
  Gem::Package::TarWriter.new(f) do |tar|
141
129
  diff_patches(nil, to_commit).each do |patch|
142
130
  entry = patch.delta.new_file
143
- if entry[:mode] == 40960 # symlink
144
- tar.add_symlink slice_cwd(entry[:path]), repo.lookup_object(entry[:oid]).content, entry[:mode]
145
- else
146
- tar.add_file slice_cwd(entry[:path]), entry[:mode] do |tf|
147
- tf.write repo.lookup_object(entry[:oid]).content
148
- end
131
+ tar.add_file slice_cwd(entry[:path]), entry[:mode] do |tf|
132
+ tf.write repo.lookup_object(entry[:oid]).content
149
133
  end
150
134
  end
151
135
  end
@@ -229,10 +213,10 @@ module Dapp
229
213
  end
230
214
 
231
215
  def diff_patches(from, to, paths: include_paths_or_cwd)
232
- (@diff_patches ||= {})[[from, to, paths]] ||= repo.patches(from, to,
233
- paths: paths,
234
- exclude_paths: exclude_paths(true),
235
- force_text: true)
216
+ (@diff_patches ||= {})[[from, to, paths]] = repo.patches(from, to,
217
+ paths: paths,
218
+ exclude_paths: exclude_paths(true),
219
+ force_text: true)
236
220
  end
237
221
 
238
222
  def include_paths_or_cwd
@@ -15,16 +15,6 @@ module Dapp
15
15
  []
16
16
  end
17
17
 
18
- # FIXME: Убрать логику исключения путей exclude_paths из данного класса,
19
- # FIXME: т.к. большинство методов не поддерживают инвариант
20
- # FIXME "всегда выдавать данные с исключенными путями".
21
- # FIXME: Например, метод diff выдает данные без учета exclude_paths.
22
- # FIXME: Лучше перенести фильтрацию в GitArtifact::diff_patches.
23
- # FIXME: ИЛИ обеспечить этот инвариант, но это ограничит в возможностях
24
- # FIXME: использование Rugged извне этого класса и это более сложный путь.
25
- # FIXME: Лучше сейчас убрать фильтрацию, а добавить ее когда наберется достаточно
26
- # FIXME: примеров использования.
27
-
28
18
  def patches(from, to, exclude_paths: [], **kwargs)
29
19
  diff(from, to, **kwargs).patches.select do |patch|
30
20
  !exclude_paths.any? { |p| check_path?(patch.delta.new_file[:path], p) }
@@ -32,9 +22,7 @@ module Dapp
32
22
  end
33
23
 
34
24
  def diff(from, to, **kwargs)
35
- if to.nil?
36
- raise "Workdir diff not supported for #{self.class}"
37
- elsif from.nil?
25
+ if from.nil?
38
26
  Rugged::Tree.diff(git, nil, to, **kwargs)
39
27
  else
40
28
  lookup_commit(from).diff(lookup_commit(to), **kwargs)
@@ -16,16 +16,8 @@ module Dapp
16
16
  raise Error::Rugged, code: :local_git_repository_does_not_exist
17
17
  end
18
18
 
19
- # NOTICE: Параметры {from: nil, to: nil} можно указать только для Own repo.
20
- # NOTICE: Для Remote repo такой вызов не имеет смысла и это ошибка пользователя класса Remote.
21
-
22
19
  def diff(from, to, **kwargs)
23
- if from.nil? and to.nil?
24
- mid_commit = latest_commit
25
- diff_obj = super(nil, mid_commit, **kwargs)
26
- diff_obj.merge! git.lookup(mid_commit).diff_workdir(**kwargs)
27
- diff_obj
28
- elsif to.nil?
20
+ if to.nil?
29
21
  git.lookup(from).diff_workdir(**kwargs)
30
22
  else
31
23
  super
@@ -1,4 +1,4 @@
1
1
  module Dapp
2
- VERSION = '0.10.4'.freeze
3
- BUILD_CACHE_VERSION = 9
2
+ VERSION = '0.11.0'.freeze
3
+ BUILD_CACHE_VERSION = 7
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.4
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Stolyarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-26 00:00:00.000000000 Z
11
+ date: 2017-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout
@@ -449,6 +449,7 @@ files:
449
449
  - lib/dapp/dimg/build/stage/install/ga_pre_install_patch.rb
450
450
  - lib/dapp/dimg/build/stage/install/ga_pre_install_patch_dependencies.rb
451
451
  - lib/dapp/dimg/build/stage/install/install.rb
452
+ - lib/dapp/dimg/build/stage/mod/git_artifact_dependencies.rb
452
453
  - lib/dapp/dimg/build/stage/mod/group.rb
453
454
  - lib/dapp/dimg/build/stage/mod/logging.rb
454
455
  - lib/dapp/dimg/build/stage/setup/ga_post_setup_patch.rb
@@ -592,7 +593,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
592
593
  requirements:
593
594
  - - ">="
594
595
  - !ruby/object:Gem::Version
595
- version: 2.5.0
596
+ version: '0'
596
597
  requirements: []
597
598
  rubyforge_project:
598
599
  rubygems_version: 2.4.8