vanagon 0.15.17 → 0.15.18

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
- SHA1:
3
- metadata.gz: 164f0e66bb5d957115ab0f12d7f684cb69ea1018
4
- data.tar.gz: f6929e9ae26855623b23a55c5c55fc49162ab5f2
2
+ SHA256:
3
+ metadata.gz: 98826d92d0eb55918c4a5db6ef30e6216785cb567560ecf34e0254e72ae45336
4
+ data.tar.gz: aec8e9bd65afafc3dd1b83bb5045e9159357d0d5c7c18037217bb61ac71730af
5
5
  SHA512:
6
- metadata.gz: 3e5c38c5e6a26ba56ac6daad39cff1b5f6ff0e86f13e60c9e6f6e7fe756435299ff1bf34dc4a02cc64adfba4d7e5e7839edf124e9c335ae6b80f1d107d623aec
7
- data.tar.gz: 4c2992d5672d7f12bd0b588ad6027e4f826827f8061701ece80e6b9fe24b31d878390b67aac9328695fe4bc33a38ccf9eb5a25b15619548d80a35f1a2eb8f7cb
6
+ metadata.gz: 8b52b708b61e3361fb37e085f11e5dcb4ce2426fac0ce1435b21a8872fba3772df72c1146c74cafe6f1bbb89bf92f6aafd1d3f71c2a4926e7d77a8762dc4a5e1
7
+ data.tar.gz: 318ec2188ac994dd0c1086fd736d25a6d3dc3474111d7b33127e8fba43bb87e5f0bc6e88cec6cd1d63f6179dd9a8197a87e7362e9d27961d396fcb076ae70cd9
File without changes
@@ -350,17 +350,17 @@ class Vanagon
350
350
 
351
351
  # Fetches patches if any are provided for the project.
352
352
  #
353
- # @param workdir [String] working directory to put the patches into
354
- def get_patches(workdir)
355
- unless @patches.empty?
356
- patchdir = File.join(workdir, "patches")
357
- FileUtils.mkdir_p(patchdir)
358
- @patches.each do |p|
359
- target = File.join(patchdir, File.basename(p.path))
360
- raise Vanagon::Error, "Duplicate patch files detected, '#{p.path}' would have overwritten '#{target}'! Please ensure patch file names are unique across all components." if File.exist?(target)
361
-
362
- FileUtils.cp(p.path, patchdir)
353
+ # @param patch_root [String] working directory to put the patches into
354
+ def get_patches(patch_root)
355
+ return if @patches.empty?
356
+ @patches.each do |patch|
357
+ patch_assembly_path = File.join(patch_root, patch.assembly_path)
358
+ if File.exist?(patch_assembly_path)
359
+ raise Vanagon::Error, "Duplicate patch files detected, '#{patch.origin_path}' would have overwritten '#{patch.assembly_path}'. Ensure all patch file names within a component are unique."
363
360
  end
361
+ patch_target_directory = File.dirname(patch_assembly_path)
362
+ FileUtils.mkdir_p(patch_target_directory)
363
+ FileUtils.cp(patch.origin_path, patch_assembly_path)
364
364
  end
365
365
  end
366
366
 
@@ -85,19 +85,22 @@ class Vanagon
85
85
  # Add a patch to the list of patches to apply to the component's source after unpacking
86
86
  #
87
87
  # @param patch [String] Path to the patch that should be applied
88
- # @param destination [String] Path to the location where the patch should be applied
89
- # @param strip [String, Integer] directory levels to skip in applying patch
90
- # @param fuzz [String, Integer] levels of context miss to ignore in applying patch
91
- # @param after [String] the location in the makefile where the patch command should be run
92
- def apply_patch(patch, destination: @component.dirname, strip: 1, fuzz: 0, after: 'unpack')
93
- @component.patches << Vanagon::Patch.new(patch, strip, fuzz, after, destination)
88
+ # @param options [Hash] options controlling the patch
89
+ # @option namespace [String] Namespace for package patches
90
+ # @option destination [String] Path to the location where the patch should be applied
91
+ # @option strip [String, Integer] directory levels to skip in applying patch
92
+ # @option fuzz [String, Integer] levels of context miss to ignore in applying patch
93
+ # @option after [String] the location in the makefile where the patch command should be run
94
+ def apply_patch(patch, options = {})
95
+ @component.patches << Vanagon::Patch.new(patch, @component, options)
94
96
  end
95
97
 
96
98
  # Loads and parses json from a file. Will treat the keys in the
97
99
  # json as methods to invoke on the component in question
98
100
  #
99
101
  # @param file [String] Path to the json file
100
- # @raise [RuntimeError] exceptions are raised if there is no file, if it refers to methods that don't exist, or if it does not contain a Hash
102
+ # @raise [RuntimeError] exceptions are raised if there is no file,
103
+ # if it refers to methods that don't exist, or if it does not contain a Hash
101
104
  def load_from_json(file)
102
105
  if File.exists?(file)
103
106
  data = JSON.parse(File.read(file))
@@ -2,9 +2,22 @@ require 'vanagon/errors'
2
2
 
3
3
  class Vanagon
4
4
  class Patch
5
- # @!attribute [r] path
6
- # @return [String] The path to the patch
7
- attr_reader :path
5
+ # @!attribute [r] origin_path
6
+ # @return [String] The path to the patch before assembly
7
+ attr_reader :origin_path
8
+
9
+ # @!attribute [r] namespace
10
+ # @return [String] The namespace for the patch
11
+ attr_reader :namespace
12
+
13
+ # @!attribute [r] assembly_path
14
+ # @return [String] The path to the patch inside the assembly
15
+ attr_reader :assembly_path
16
+
17
+ # @!attribute [r] destination
18
+ # @return [String] The working directory where this patch will be applied.
19
+ # Only used for post-installation patches.
20
+ attr_reader :destination
8
21
 
9
22
  # @!attribute [r] strip
10
23
  # @return [Integer] the number of path components to strip from the patch path
@@ -18,21 +31,28 @@ class Vanagon
18
31
  # @return [String] What step should this patch be applied to, one of ["unpack", "install"]
19
32
  attr_reader :after
20
33
 
21
- # @!attribute [r] destination
22
- # @return [String] The working directory where this patch will be applied. Only used for post-installation patches.
23
- attr_reader :destination
34
+ def initialize(origin_path, component, options) # rubocop:disable Metrics/AbcSize,Metrics/PerceivedComplexity
35
+ valid_keys = %i[namespace destination strip fuzz after]
36
+ bad_keys = options.each_key.reject { |k| valid_keys.include? k }
37
+
38
+ unless bad_keys.empty?
39
+ raise Vanagon::Error, "Bad options in patch initialization: #{bad_keys}."
40
+ end
24
41
 
25
- def initialize(path, strip, fuzz, after, destination)
26
- raise Vanagon::Error, "We can only apply patches after the source is unpacked or after installation" unless ['unpack', 'install'].include?(after)
27
- @path = path
28
- @strip = strip
29
- @fuzz = fuzz
30
- @after = after
31
- @destination = destination
42
+ @origin_path = origin_path
43
+ @namespace = options[:namespace] || component.name
44
+ @assembly_path = "patches/#{@namespace}/#{File.basename(@origin_path)}"
45
+ @strip = options[:strip] || 1
46
+ @fuzz = options[:fuzz] || 0
47
+ @after = options[:after] || 'unpack'
48
+ unless ['unpack', 'install'].include?(@after)
49
+ raise Vanagon::Error, 'Only "unpack" or "install" permitted for "after" option.'
50
+ end
51
+ @destination = options[:destination] || component.dirname
32
52
  end
33
53
 
34
54
  def cmd(platform)
35
- "#{platform.patch} --strip=#{@strip} --fuzz=#{@fuzz} --ignore-whitespace --no-backup-if-mismatch < $(workdir)/patches/#{File.basename(@path)}"
55
+ return "#{platform.patch} --strip=#{@strip} --fuzz=#{@fuzz} --ignore-whitespace --no-backup-if-mismatch < $(workdir)/#{@assembly_path}"
36
56
  end
37
57
  end
38
58
  end
@@ -68,7 +68,12 @@ Requires: <%= requires %>
68
68
  # did not specify a dependency on these.
69
69
  # In the future, we will supress pre/post scripts completely if there's nothing
70
70
  # specified by the project or the components.
71
- <%- unless @platform.is_aix? -%>
71
+ <%- if @platform.is_fedora? && @platform.os_version.to_i >= 29 -%>
72
+ Requires(pre): /usr/bin/mkdir
73
+ Requires(pre): /usr/bin/touch
74
+ Requires(post): /usr/bin/mkdir
75
+ Requires(post): /usr/bin/touch
76
+ <%- elsif !@platform.is_aix? -%>
72
77
  Requires(pre): /bin/mkdir
73
78
  Requires(pre): /bin/touch
74
79
  Requires(post): /bin/mkdir
@@ -220,80 +220,80 @@ end" }
220
220
 
221
221
  describe '#apply_patch' do
222
222
  it 'adds the patch to the list of patches' do
223
- comp = Vanagon::Component::DSL.new('patch-test', {}, {})
224
- comp.apply_patch('patch_file1')
225
- comp.apply_patch('patch_file2')
226
- expect(comp._component.patches.count).to eq 2
227
- expect(comp._component.patches.first.path).to eq 'patch_file1'
228
- expect(comp._component.patches.last.path).to eq 'patch_file2'
223
+ dsl = Vanagon::Component::DSL.new('patch-test', {}, {})
224
+ dsl.apply_patch('patch_file1')
225
+ dsl.apply_patch('patch_file2')
226
+ expect(dsl._component.patches.count).to eq 2
227
+ expect(dsl._component.patches.first.origin_path).to eq 'patch_file1'
228
+ expect(dsl._component.patches.last.origin_path).to eq 'patch_file2'
229
229
  end
230
230
 
231
231
  it 'can specify strip and fuzz' do
232
- comp = Vanagon::Component::DSL.new('patch-test', {}, {})
232
+ dsl = Vanagon::Component::DSL.new('patch-test', {}, {})
233
233
  # This patch must be amazing
234
- comp.apply_patch('patch_file1', fuzz: 12, strip: 1000000)
235
- expect(comp._component.patches.count).to eq 1
236
- expect(comp._component.patches.first.path).to eq 'patch_file1'
237
- expect(comp._component.patches.first.fuzz).to eq 12
238
- expect(comp._component.patches.first.strip).to eq 1000000
234
+ dsl.apply_patch('patch_file1', fuzz: 12, strip: 1000000)
235
+ expect(dsl._component.patches.count).to eq 1
236
+ expect(dsl._component.patches.first.origin_path).to eq 'patch_file1'
237
+ expect(dsl._component.patches.first.fuzz).to eq 12
238
+ expect(dsl._component.patches.first.strip).to eq 1000000
239
239
  end
240
240
 
241
241
  it 'can specify a directory where the patch should be applied' do
242
- comp = Vanagon::Component::DSL.new('patch-test', {}, {})
243
- comp.apply_patch('patch_file1', destination: 'random/install/directory')
244
- expect(comp._component.patches.count).to eq 1
245
- expect(comp._component.patches.first.path).to eq 'patch_file1'
246
- expect(comp._component.patches.first.destination).to eq 'random/install/directory'
242
+ dsl = Vanagon::Component::DSL.new('patch-test', {}, {})
243
+ dsl.apply_patch('patch_file1', destination: 'random/install/directory')
244
+ expect(dsl._component.patches.count).to eq 1
245
+ expect(dsl._component.patches.first.origin_path).to eq 'patch_file1'
246
+ expect(dsl._component.patches.first.destination).to eq 'random/install/directory'
247
247
  end
248
248
 
249
249
  it 'can specify when to try to apply the patch' do
250
- comp = Vanagon::Component::DSL.new('patch-test', {}, {})
251
- comp.apply_patch('patch_file1', after: 'install')
252
- expect(comp._component.patches.count).to eq 1
253
- expect(comp._component.patches.first.path).to eq 'patch_file1'
254
- expect(comp._component.patches.first.after).to eq 'install'
250
+ dsl = Vanagon::Component::DSL.new('patch-test', {}, {})
251
+ dsl.apply_patch('patch_file1', after: 'install')
252
+ expect(dsl._component.patches.count).to eq 1
253
+ expect(dsl._component.patches.first.origin_path).to eq 'patch_file1'
254
+ expect(dsl._component.patches.first.after).to eq 'install'
255
255
  end
256
256
 
257
257
  it 'will default the patch timing to after the source is unpacked' do
258
- comp = Vanagon::Component::DSL.new('patch-test', {}, {})
259
- comp.apply_patch('patch_file1')
260
- expect(comp._component.patches.count).to eq 1
261
- expect(comp._component.patches.first.path).to eq 'patch_file1'
262
- expect(comp._component.patches.first.after).to eq 'unpack'
258
+ dsl = Vanagon::Component::DSL.new('patch-test', {}, {})
259
+ dsl.apply_patch('patch_file1')
260
+ expect(dsl._component.patches.count).to eq 1
261
+ expect(dsl._component.patches.first.origin_path).to eq 'patch_file1'
262
+ expect(dsl._component.patches.first.after).to eq 'unpack'
263
263
  end
264
264
 
265
265
  it 'will fail if the user wants to install the patch at an unsupported step' do
266
- comp = Vanagon::Component::DSL.new('patch-test', {}, {})
267
- expect { comp.apply_patch('patch_file1', after: 'delivery') }.to raise_error(Vanagon::Error)
266
+ dsl = Vanagon::Component::DSL.new('patch-test', {}, {})
267
+ expect { dsl.apply_patch('patch_file1', after: 'delivery') }.to raise_error(Vanagon::Error)
268
268
  end
269
269
 
270
270
  it 'can specify a directory where the patch should be applied' do
271
- comp = Vanagon::Component::DSL.new('patch-test', {}, {})
272
- comp.apply_patch('patch_file1', destination: 'random/install/directory')
273
- expect(comp._component.patches.count).to eq 1
274
- expect(comp._component.patches.first.path).to eq 'patch_file1'
275
- expect(comp._component.patches.first.destination).to eq 'random/install/directory'
271
+ dsl = Vanagon::Component::DSL.new('patch-test', {}, {})
272
+ dsl.apply_patch('patch_file1', destination: 'random/install/directory')
273
+ expect(dsl._component.patches.count).to eq 1
274
+ expect(dsl._component.patches.first.origin_path).to eq 'patch_file1'
275
+ expect(dsl._component.patches.first.destination).to eq 'random/install/directory'
276
276
  end
277
277
 
278
278
  it 'can specify when to try to apply the patch' do
279
- comp = Vanagon::Component::DSL.new('patch-test', {}, {})
280
- comp.apply_patch('patch_file1', after: 'install')
281
- expect(comp._component.patches.count).to eq 1
282
- expect(comp._component.patches.first.path).to eq 'patch_file1'
283
- expect(comp._component.patches.first.after).to eq 'install'
279
+ dsl = Vanagon::Component::DSL.new('patch-test', {}, {})
280
+ dsl.apply_patch('patch_file1', after: 'install')
281
+ expect(dsl._component.patches.count).to eq 1
282
+ expect(dsl._component.patches.first.origin_path).to eq 'patch_file1'
283
+ expect(dsl._component.patches.first.after).to eq 'install'
284
284
  end
285
285
 
286
286
  it 'will default the patch timing to after the source is unpacked' do
287
- comp = Vanagon::Component::DSL.new('patch-test', {}, {})
288
- comp.apply_patch('patch_file1')
289
- expect(comp._component.patches.count).to eq 1
290
- expect(comp._component.patches.first.path).to eq 'patch_file1'
291
- expect(comp._component.patches.first.after).to eq 'unpack'
287
+ dsl = Vanagon::Component::DSL.new('patch-test', {}, {})
288
+ dsl.apply_patch('patch_file1')
289
+ expect(dsl._component.patches.count).to eq 1
290
+ expect(dsl._component.patches.first.origin_path).to eq 'patch_file1'
291
+ expect(dsl._component.patches.first.after).to eq 'unpack'
292
292
  end
293
293
 
294
294
  it 'will fail if the user wants to install the patch at an unsupported step' do
295
- comp = Vanagon::Component::DSL.new('patch-test', {}, {})
296
- expect { comp.apply_patch('patch_file1', after: 'delivery') }.to raise_error(Vanagon::Error)
295
+ dsl = Vanagon::Component::DSL.new('patch-test', {}, {})
296
+ expect { dsl.apply_patch('patch_file1', after: 'delivery') }.to raise_error(Vanagon::Error)
297
297
  end
298
298
  end
299
299
 
@@ -66,17 +66,28 @@ describe Vanagon::Component::Rules do
66
66
  expect(rule.recipe.size).to eq 1
67
67
  end
68
68
 
69
+ it "rejects bad options" do
70
+ expect { Vanagon::Patch.new('/foo/patch0', component, REALLYBADARGUMENT: 'bad-value') }.to raise_error(Vanagon::Error, /Bad options in patch initialization/i)
71
+ end
72
+
69
73
  it "applies each listed patch in order when patches are set" do
70
74
  component.patches = [
71
- Vanagon::Patch.new('/foo/patch0', '1', '0', 'unpack', '/foo/bar'),
72
- Vanagon::Patch.new('/foo/patch1', '2', '1', 'unpack', '/foo/bar'),
73
- Vanagon::Patch.new('/foo/postinstall/patch1', '2', '1', 'install', '/foo/bar')
75
+ Vanagon::Patch.new('/foo/patch0', component,
76
+ namespace: component.name, strip: '1', fuzz: '0',
77
+ after: 'unpack', destination: '/foo/bar'),
78
+ Vanagon::Patch.new('/foo/patch1', component,
79
+ namespace: component.name, strip: '2', fuzz: '1',
80
+ after: 'unpack', destination: '/foo/bar'),
81
+ Vanagon::Patch.new('/foo/postinstall/patch1', component,
82
+ namespace: component.name,
83
+ strip: '2', fuzz: '1', after: 'install',
84
+ destination: '/foo/bar')
74
85
  ]
75
86
  expect(rule.recipe.first).to eq(
76
87
  [
77
88
  "cd /foo/bar",
78
- "/usr/bin/patch --strip=1 --fuzz=0 --ignore-whitespace --no-backup-if-mismatch < $(workdir)/patches/patch0",
79
- "/usr/bin/patch --strip=2 --fuzz=1 --ignore-whitespace --no-backup-if-mismatch < $(workdir)/patches/patch1"
89
+ "/usr/bin/patch --strip=1 --fuzz=0 --ignore-whitespace --no-backup-if-mismatch < $(workdir)/#{component.patches[0].assembly_path}",
90
+ "/usr/bin/patch --strip=2 --fuzz=1 --ignore-whitespace --no-backup-if-mismatch < $(workdir)/#{component.patches[1].assembly_path}"
80
91
  ].join(" && \\\n")
81
92
  )
82
93
  end
@@ -116,7 +127,7 @@ describe Vanagon::Component::Rules do
116
127
  component.environment.merge({"PATH" => "/opt/pl-build-tools/bin:$(PATH)"})
117
128
  expect(rule.recipe[1]).to eq(
118
129
  [
119
- 'export PATH="/opt/pl-build-tools/bin:$(PATH)"',
130
+ 'export PATH="/opt/pl-build-tools/bin:$(PATH)"',
120
131
  "cd /foo/bar",
121
132
  "./configure",
122
133
  "cmake .."
@@ -241,13 +252,19 @@ describe Vanagon::Component::Rules do
241
252
  it "applies any after-install patches" do
242
253
  component.install = ["make install"]
243
254
  component.patches = [
244
- Vanagon::Patch.new('/foo/patch0', 1, 0, 'unpack', '/foo/bar'),
245
- Vanagon::Patch.new('/foo/postinstall/patch0', 3, 9, 'install', '/foo/baz'),
246
- Vanagon::Patch.new('/foo/postinstall/patch1', 4, 10, 'install', '/foo/quux'),
255
+ Vanagon::Patch.new('/foo/patch0', component,
256
+ namespace: component.name, strip: 1, fuzz: 0,
257
+ after: 'unpack', destination: '/foo/bar'),
258
+ Vanagon::Patch.new('/foo/postinstall/patch0', component,
259
+ namespace: component.name, strip: 3,
260
+ fuzz: 9, after: 'install', destination: '/foo/baz'),
261
+ Vanagon::Patch.new('/foo/postinstall/patch1', component,
262
+ namespace: component.name, strip: 4,
263
+ fuzz: 10, after: 'install', destination: '/foo/quux'),
247
264
  ]
248
265
 
249
- expect(rule.recipe[1]).to eq("cd /foo/baz && /usr/bin/patch --strip=3 --fuzz=9 --ignore-whitespace --no-backup-if-mismatch < $(workdir)/patches/patch0")
250
- expect(rule.recipe[2]).to eq("cd /foo/quux && /usr/bin/patch --strip=4 --fuzz=10 --ignore-whitespace --no-backup-if-mismatch < $(workdir)/patches/patch1")
266
+ expect(rule.recipe[1]).to eq("cd /foo/baz && /usr/bin/patch --strip=3 --fuzz=9 --ignore-whitespace --no-backup-if-mismatch < $(workdir)/#{component.patches[1].assembly_path}")
267
+ expect(rule.recipe[2]).to eq("cd /foo/quux && /usr/bin/patch --strip=4 --fuzz=10 --ignore-whitespace --no-backup-if-mismatch < $(workdir)/#{component.patches[2].assembly_path}")
251
268
  end
252
269
 
253
270
  it_behaves_like "a rule that touches the target file"
@@ -217,22 +217,27 @@ describe "Vanagon::Component" do
217
217
  plat._platform
218
218
  end
219
219
 
220
- let(:component) { Vanagon::Component::DSL.new('patches-test', {}, platform) }
220
+ let(:dsl_1) { Vanagon::Component::DSL.new('patches-test-1', {}, platform) }
221
+ let(:dsl_2) { Vanagon::Component::DSL.new('patches-test-2', {}, platform) }
221
222
 
222
223
  context("when new patch file would overwrite existing patch file") do
223
- let(:patch_file) { 'path/to/test.patch' }
224
+ let(:patch_file_1) { 'path/to/test.patch_1' }
225
+ let(:patch_file_2) { 'path/to/test.patch_2' }
224
226
 
225
227
  before :each do
226
228
  allow(FileUtils).to receive(:mkdir_p)
227
229
  allow(FileUtils).to receive(:cp)
228
-
229
- expect(File).to receive(:exist?).with(File.join(@workdir, 'patches', File.basename(patch_file))).and_return(true)
230
-
231
- component.apply_patch(patch_file)
232
230
  end
233
231
 
234
- it "fails the build" do
235
- expect { component._component.get_patches(@workdir) }.to raise_error(Vanagon::Error, /duplicate patch files/i)
232
+ it "fails the build with the same namespace" do
233
+ expect(File).to receive(:exist?).with(/.*\/.*test\.patch_1/).and_return(true)
234
+ dsl_1.apply_patch(patch_file_1)
235
+ expect { dsl_1._component.get_patches(@workdir) }.to raise_error(Vanagon::Error, /duplicate patch files/i)
236
+ end
237
+ it "works with different namespaces" do
238
+ expect(File).to receive(:exist?).with(/.*\/.*test\.patch_2/).and_return(false)
239
+ dsl_2.apply_patch(patch_file_2, namespace: 'foo')
240
+ expect { dsl_2._component.get_patches(@workdir) }.to_not raise_error
236
241
  end
237
242
  end
238
243
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.17
4
+ version: 0.15.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-13 00:00:00.000000000 Z
11
+ date: 2018-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -261,7 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
261
261
  version: '0'
262
262
  requirements: []
263
263
  rubyforge_project:
264
- rubygems_version: 2.6.14
264
+ rubygems_version: 2.7.6
265
265
  signing_key:
266
266
  specification_version: 3
267
267
  summary: All of your packages will fit into this van with this one simple trick.