dply 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36989af82dd38d5bf66b70f92627fc0757db80b04f9f0e7a14ba6b9b1b09145b
4
- data.tar.gz: 02366bde4e4a38ba98b3f6f59e7a43e7c8aa8048ed6f0e96449a046f17bcd477
3
+ metadata.gz: 47be2897b6fac53ffa527667a3f1b7a794038422eeb5d1f2ec344624334760f2
4
+ data.tar.gz: 38805b70907e8591654d56c970288b3df5a99459c1c55c8977e79319c3c36973
5
5
  SHA512:
6
- metadata.gz: 9aada7a0bb8c7daf5161d2aff4705758fe27ee5d8184aa545da9326e767482221f8643fe4e7134e4d2c6958335181f9292f9f17f048479e079ffd4fbd16a51be
7
- data.tar.gz: e90d76148eb33897e6c7eaafb6b0bd433014b31030d5ddc6ba1ce52e2d1cf3e6c6086d5a085eed906fb9e47396051f459a05254f636ae809f0a92303785eea7d
6
+ metadata.gz: 4103db48d903226e2526a243bb2dade117b2e189493a09c3c3142c789957e05285350bf960216e442b8d864d8ccdd23a1172dd3e4e7444781ce8089fc1b3c373
7
+ data.tar.gz: 26a4dd026591bc40a397d26e4b2863d2d971720170d424cded39adfa8865cc13222bb785a1ee11d35731ed101bc7cf5f4cc1ae42cde2e3eee5340344b7eee53d
@@ -114,7 +114,7 @@ module Dply
114
114
  deactivate_gem 'ruby-elf' # in case gemfile contains another version of ruby-elf
115
115
  Bundler.setup
116
116
  reactivate_gem 'dply'
117
- logger.debug { "LOAD_PATH: #{$LOAD_PATH.inspect}" }
117
+ logger.trace { "LOAD_PATH: #{$LOAD_PATH.inspect}" }
118
118
  end
119
119
 
120
120
  def reactivate_gem(name)
@@ -13,25 +13,36 @@ module Dply
13
13
  @name = name
14
14
  @branch = get_branch
15
15
  @revision = revision
16
- @dir = "tmp/build_artifacts"
16
+ @dir = "#{Dir.pwd}/tmp/build_artifacts"
17
+ @skip_depcheck = false
17
18
  validate
18
19
  end
19
20
 
20
- def build(git: true, gnu_tar: false, &block)
21
+ def build(empty: false, gnu_tar: false, &block)
21
22
  make_dir
22
- create_tar git, gnu_tar
23
- instance_eval &block if block
23
+ create_tar empty, gnu_tar
24
+ instance_eval(&block) if block
24
25
  add_git_commit_id
25
26
  add_revision
26
27
  add_archive_name
27
- depcheck
28
- compress
28
+ end
29
+
30
+ def depcheck!
31
+ return if @skip_depcheck
32
+ command = %(ruby -W0 "#{__dir__}/scripts/depcheck.rb" #{tar})
33
+ logger.bullet "depcheck #{tar}"
34
+ env = logger.debug? ? { "LOG_DEBUG" => "true" } : {}
35
+ cmd command, display: false, env: env
36
+ end
37
+
38
+ def compress!
39
+ cmd %(#{gzip} -f -9 "#{tar}")
29
40
  end
30
41
 
31
42
  private
32
43
 
33
44
  def get_branch
34
- out = cmd "git rev-parse --abbrev-ref HEAD", return_output: true
45
+ out = `git rev-parse --abbrev-ref HEAD`
35
46
  out.chomp.tr("/", "_")
36
47
  end
37
48
 
@@ -43,30 +54,33 @@ module Dply
43
54
  FileUtils.mkdir @dir if not File.directory? @dir
44
55
  end
45
56
 
46
- def create_tar(git, gnu_tar)
57
+ def create_tar(empty, gnu_tar)
47
58
  tmp_dir = "tmp/app_code"
48
- if git
49
- if gnu_tar
50
- FileUtils.rm_rf tmp_dir if File.exists? tmp_dir
51
- FileUtils.mkdir tmp_dir
52
- sh "git archive HEAD | tar xf - -C #{tmp_dir}"
53
- cmd "tar cf #{tar} -C #{tmp_dir} ."
54
- else
55
- cmd "git archive -o #{tar} HEAD"
56
- end
59
+ return if empty
60
+ if gnu_tar
61
+ FileUtils.rm_rf tmp_dir
62
+ FileUtils.mkdir tmp_dir
63
+ sh "git archive HEAD | tar xf - -C #{tmp_dir}"
64
+ cmd "tar cf #{tar} -C #{tmp_dir} ."
57
65
  else
58
- cmd "tar -cf #{tar} -T /dev/null"
66
+ cmd "git archive -o #{tar} HEAD"
59
67
  end
60
68
  ensure
61
- FileUtils.rm_rf tmp_dir if File.exists? tmp_dir
69
+ FileUtils.rm_rf tmp_dir
62
70
  end
63
71
 
64
- def add(file, chdir: nil)
65
- if chdir
66
- cmd %(tar -h -C #{chdir} --append -f "#{tar}" "#{file}")
72
+ def add(file, dereference: false)
73
+ realpath = File.realpath(file)
74
+ tar_relpath = Pathname.new(tar).relative_path_from(Pathname.new(Dir.pwd)).to_s
75
+ command = ["tar", "--append", "-f", tar_relpath]
76
+ command << "-h" if dereference
77
+ if File.symlink?(file) && File.directory?(realpath)
78
+ prefix = file.sub(":", '\:')
79
+ command.concat ["-C", file, "--transform", "s:^:#{prefix}/:S", "."]
67
80
  else
68
- cmd %(tar -h --append -f "#{tar}" "#{file}")
81
+ command << file
69
82
  end
83
+ cmd command
70
84
  end
71
85
 
72
86
  def remove(file)
@@ -97,19 +111,8 @@ module Dply
97
111
  add "vendor/bundle"
98
112
  end
99
113
 
100
- def depcheck
101
- return if @skip_depcheck
102
- command = %(ruby -W0 "#{__dir__}/scripts/depcheck.rb" #{tar})
103
- logger.bullet "depcheck #{tar}"
104
- cmd command, display: false
105
- end
106
-
107
- def compress
108
- cmd %(#{gzip} -f -9 "#{tar}")
109
- end
110
-
111
114
  def gzip
112
- File.exists?("/usr/bin/pigz") ? "pigz" : "gzip"
115
+ File.exist?("/usr/bin/pigz") ? "pigz" : "gzip"
113
116
  end
114
117
 
115
118
  def validate
@@ -25,7 +25,7 @@ module Dply
25
25
  ret = yield
26
26
  exitstatus = $?.exitstatus
27
27
  if exitstatus != 0
28
- raise Error, "non zero exit for \"#{command_str}\""
28
+ raise Error, %(non zero exit for "#{command_str}")
29
29
  end
30
30
  ret
31
31
  end
@@ -1,4 +1,5 @@
1
1
  require 'logger'
2
+ require 'shellwords'
2
3
  require_relative 'ext/string'
3
4
 
4
5
  module Dply
@@ -9,7 +10,8 @@ module Dply
9
10
  def initialize(file)
10
11
  super(file)
11
12
  @level = ::Logger::INFO
12
- # @trace_mode = false
13
+ @saved_logdev = @logdev
14
+ @trace_mode = false
13
15
  end
14
16
 
15
17
  def format_message(severity, timestamp, progname, msg)
@@ -26,13 +28,16 @@ module Dply
26
28
  end
27
29
 
28
30
  def command(command, mode:)
31
+ str = command.is_a?(Array) ? shelljoin(command) : command
29
32
  case mode
30
33
  when :arrow
31
- arrow command
34
+ arrow str
32
35
  when :bullet
33
- bullet command
36
+ bullet str
37
+ when :warn
38
+ warn str
34
39
  else
35
- debug command
40
+ debug str
36
41
  end
37
42
  end
38
43
 
@@ -44,9 +49,10 @@ module Dply
44
49
  info "#{"\u2219".bold.blue} #{msg}"
45
50
  end
46
51
 
47
- def trace(msg)
52
+ def trace(msg = nil)
48
53
  return if not @trace_mode
49
- info %(#{"T".bold.blue} #{msg}\n)
54
+ msg = yield if block_given?
55
+ info %(#{"T".bold.blue} #{msg})
50
56
  end
51
57
 
52
58
  def remote(msg)
@@ -59,9 +65,29 @@ module Dply
59
65
  info "dply_marker:#{msg}"
60
66
  end
61
67
 
62
- def silence!
68
+ private
69
+
70
+ def shelljoin(command)
71
+ arr = command.map do |i|
72
+ case i
73
+ when /\A[A-Za-z0-9._\-=+:\/]+\z/
74
+ i
75
+ when /\A[^']+\z/
76
+ %('#{i}')
77
+ else
78
+ i.shellescape
79
+ end
80
+ end
81
+ arr.join " "
82
+ end
83
+
84
+ def disable
63
85
  @logdev = nil
64
86
  end
65
87
 
88
+ def enable
89
+ @logdev = @saved_logdev
90
+ end
91
+
66
92
  end
67
93
  end
@@ -32,8 +32,20 @@ module Dply
32
32
  pp @libs_files_map
33
33
  end
34
34
 
35
- deps = Rpm.libs_pkgs_map libs
35
+ deps = {}
36
+ libs.each do |lib|
37
+ what_provides = Rpm.what_provides(lib)
38
+ if what_provides.empty?
39
+ logger.error "no pkgs provide '#{lib}': required by files: #{@libs_files_map[lib]})"
40
+ @error = true
41
+ next
42
+ end
43
+ deps[lib] = what_provides
44
+ end
45
+
36
46
  verify_deps(deps, pkgs_list)
47
+ error "packages dependencies not satisfied" if @error
48
+ puts "all dependencies satisfied".green
37
49
  end
38
50
  end
39
51
 
@@ -47,8 +59,6 @@ module Dply
47
59
  @error = true
48
60
  end
49
61
  end
50
- error "packages dependencies not satisfied" if @error
51
- puts "all dependencies satisfied".green
52
62
  end
53
63
 
54
64
  def tmp_dir(&block)
@@ -44,6 +44,8 @@ module Dply
44
44
  rpaths = @elf[".dynamic"].rpath + @elf[".dynamic"].runpath
45
45
  # expand $ORIGIN
46
46
  rpaths = rpaths.map { |i| i.sub("$ORIGIN", "#{@path.dirname}") }
47
+ # select only existing rpaths
48
+ rpaths = rpaths.select { |i| File.exists? i }
47
49
  # convert all paths to realpath
48
50
  rpaths = rpaths.map { |i| Pathname.new(i).realpath }
49
51
  # select paths which start with cwd or are subpaths to cwd
@@ -15,7 +15,7 @@ module Dply
15
15
  end
16
16
 
17
17
  def define(&block)
18
- instance_eval &block
18
+ instance_eval(&block)
19
19
  end
20
20
 
21
21
  def generate
@@ -23,7 +23,7 @@ module Dply
23
23
  @sources.each do |i|
24
24
  path = i.fetch(:path)
25
25
  url = i.fetch(:url)
26
- auth = i.fetch(:auth)
26
+ # auth = i.fetch(:auth)
27
27
  optional = i.fetch(:optional)
28
28
  deep_merge = i.fetch(:deep_merge)
29
29
  block = i.fetch(:block)
@@ -4,21 +4,14 @@ module Dply
4
4
  module Rpm
5
5
  extend Helper
6
6
 
7
- # libs should include ()(64bit) in their name if 64bit libs
8
- def self.libs_pkgs_map(libs)
9
- h = {}
10
- libs.each { |lib| h[lib] = pkg_list(lib) }
11
- return h
7
+ def self.what_provides(lib)
8
+ command = ["rpm", "--queryformat", "%{NAME} ", "-q", "--whatprovides", lib]
9
+ output = cmd command, return_output: true, display: false
10
+ output.strip.split
11
+ rescue Error
12
+ logger.command command, mode: :warn
13
+ []
12
14
  end
13
15
 
14
- class << self
15
- private
16
-
17
- def pkg_list(lib)
18
- command = ["rpm", "--queryformat", "%{NAME} ", "-q", "--whatprovides", lib]
19
- output = cmd command, return_output: true, display: false
20
- output.strip.split
21
- end
22
- end
23
16
  end
24
17
  end
@@ -1,4 +1,6 @@
1
1
  require_relative '../deplist'
2
2
 
3
+ logger = Dply::Logger.logger
4
+ logger.level = ::Logger::DEBUG if ENV["LOG_DEBUG"]
3
5
  deplist = Dply::Deplist.new(ARGV.shift)
4
6
  deplist.verify!
@@ -37,6 +37,8 @@ module Dply
37
37
  revision = ENV["BUILD_NUMBER"] || "unknown"
38
38
  archive = CodeArchive.new(name, revision: revision)
39
39
  archive.build(**opts, &block)
40
+ archive.depcheck!
41
+ archive.compress!
40
42
  return archive
41
43
  end
42
44
 
@@ -1,3 +1,3 @@
1
1
  module Dply
2
- VERSION = "0.3.8"
2
+ VERSION = "0.3.9"
3
3
  end
@@ -0,0 +1,120 @@
1
+ require 'dply/code_archive'
2
+ module Dply
3
+ describe CodeArchive do
4
+
5
+ def setup_work_dir
6
+ File.write "code", "code"
7
+ system! "git init"
8
+ system! "git add code"
9
+ system! "git commit -m 'initial commit'"
10
+ FileUtils.mkdir "tmp"
11
+ FileUtils.mkdir "shared"
12
+ FileUtils.touch "shared/a"
13
+ FileUtils.touch "shared/b"
14
+ system! "ln -sf shared linked_dir"
15
+ system! "ln -sf shared/a linked_file"
16
+ long_name = "a" * 101
17
+ FileUtils.mkdir_p "long_path"
18
+ FileUtils.touch "long_path/#{long_name}"
19
+ end
20
+
21
+ def build_tar(**kwargs, &block)
22
+ Dir.chdir @work_dir do
23
+ FileUtils.rm_rf "tmp/build_artifacts"
24
+ archive = CodeArchive.new("test", revision: "dev")
25
+ suppress_logger { archive.build(**kwargs, &block) }
26
+ end
27
+ end
28
+
29
+ def extract_tar
30
+ extract_dir = "#{@work_dir}/tmp/extract"
31
+ FileUtils.rm_rf extract_dir
32
+ FileUtils.mkdir_p extract_dir
33
+ Dir.chdir extract_dir do
34
+ system! "tar xf ../build_artifacts/test-dev-master.tar"
35
+ yield
36
+ end
37
+ end
38
+
39
+ before :all do
40
+ @work_dir = "tmp/code_archive"
41
+ FileUtils.rm_rf @work_dir
42
+ FileUtils.mkdir_p @work_dir
43
+ Dir.chdir @work_dir do
44
+ setup_work_dir
45
+ end
46
+ end
47
+
48
+ describe "#build" do
49
+
50
+ it "builds a tar from git code and adds the specified files" do
51
+ build_tar gnu_tar: false do
52
+ add "shared/a"
53
+ Dir.chdir("shared") { add "b" }
54
+ end
55
+
56
+ extract_tar do
57
+ expect(File).to exist("code")
58
+ expect(File).to exist("shared/a")
59
+ expect(File).to exist("b")
60
+ end
61
+
62
+ end
63
+
64
+ it "raises error when adding a too long filename" do
65
+ expect do
66
+ suppress_output { build_tar { add "long_path" } }
67
+ end.to raise_error(Error)
68
+ end
69
+
70
+
71
+ it "is able to able long filenames with gnu_tar: true" do
72
+ build_tar gnu_tar: true do
73
+ add "long_path"
74
+ end
75
+
76
+ extract_tar do
77
+ expect(File).to exist("code")
78
+ expect(File).to exist("long_path")
79
+ end
80
+ end
81
+
82
+
83
+ it "add(path) dereferences path only if path is a symlink to a directory" do
84
+ build_tar do
85
+ add "linked_file"
86
+ add "linked_dir"
87
+ end
88
+
89
+ extract_tar do
90
+ expect(File).to exist("code")
91
+ expect(File).to exist("linked_dir/a")
92
+ expect(File).to exist("linked_dir/b")
93
+ expect(File.symlink?("linked_file")).to be(true)
94
+ end
95
+ end
96
+
97
+ it "dereferences symlinks when derefence: true" do
98
+ build_tar do
99
+ add "linked_file", dereference: true
100
+ end
101
+
102
+ extract_tar do
103
+ expect(File).to exist("code")
104
+ expect(File.symlink? "linked_file").to be(false)
105
+ end
106
+ end
107
+
108
+ it "doesn't include code from git when empty: true" do
109
+ build_tar empty: true do
110
+ add "shared/a"
111
+ end
112
+
113
+ extract_tar do
114
+ expect(File).to exist("shared/a")
115
+ expect(File).not_to exist("code")
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -15,16 +15,13 @@ module Dply
15
15
  "#{lib}()(64bit)"
16
16
  end
17
17
 
18
- subject(:rpm) { Rpm }
19
-
20
- describe ".libs_pkgs_map" do
21
- it "returns the map of lib => [list of pkgs] which provide that lib" do
18
+ describe ".what_provides" do
19
+ it "returns the [list of pkgs] which provide a given lib" do
22
20
  test_cases = test_cases()
23
- libs = test_cases.keys.map { |i| to_64bit i }
24
- map = rpm.libs_pkgs_map libs
25
- test_cases.keys.each do |i|
26
- lib = to_64bit(i)
27
- expect(map[lib]).to eq(test_cases[i])
21
+ test_cases.each do |lib, res|
22
+ lib = to_64bit(lib)
23
+ what_provides = Rpm.what_provides(lib)
24
+ expect(res).to eq(what_provides)
28
25
  end
29
26
  end
30
27
  end
@@ -30,6 +30,14 @@ ensure
30
30
  $stderr.reopen orig_stderr
31
31
  end
32
32
 
33
+ def suppress_logger(&block)
34
+ logger = Dply::Logger.logger
35
+ logger.send :disable
36
+ yield
37
+ ensure
38
+ logger.send :enable
39
+ end
40
+
33
41
  def system!(command, quiet: true)
34
42
  if quiet
35
43
  retval = system command, [:out, :err] => "/dev/null"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dply
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neeraj
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-18 00:00:00.000000000 Z
11
+ date: 2019-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-elf
@@ -145,6 +145,7 @@ files:
145
145
  - lib/dplyr/tasks_config.rb
146
146
  - spec/dply/base_config_spec.rb
147
147
  - spec/dply/bundle_spec.rb
148
+ - spec/dply/code_archive_spec.rb
148
149
  - spec/dply/command_spec.rb
149
150
  - spec/dply/curl_spec.rb
150
151
  - spec/dply/deplist_spec.rb
@@ -218,6 +219,7 @@ summary: rake based deploy tool
218
219
  test_files:
219
220
  - spec/dply/base_config_spec.rb
220
221
  - spec/dply/bundle_spec.rb
222
+ - spec/dply/code_archive_spec.rb
221
223
  - spec/dply/command_spec.rb
222
224
  - spec/dply/curl_spec.rb
223
225
  - spec/dply/deplist_spec.rb