Class: Simp::Rake::Pkg

Inherits:
Rake::TaskLib
  • Object
show all
Includes:
Helpers::RPMSpec
Defined in:
lib/simp/rake/pkg.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::RPMSpec

#rpm_template

Methods included from Build::Constants

#distro_build_dir, #init_member_vars

Constructor Details

#initialize(base_dir, unique_namespace = nil, simp_version = nil) {|_self| ... } ⇒ Pkg

Returns a new instance of Pkg.

Yields:

  • (_self)

Yield Parameters:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/simp/rake/pkg.rb', line 43

def initialize( base_dir, unique_namespace = nil, simp_version=nil )
  @base_dir            = base_dir
  @pkg_name            = File.basename(@base_dir)
  @pkg_dir             = File.join(@base_dir, 'dist')
  @pkg_tmp_dir         = File.join(@pkg_dir, 'tmp')
  @exclude_list        = [ File.basename(@pkg_dir) ]
  @clean_list          = []
  @ignore_changes_list = [
    'Gemfile.lock',
    'dist/logs',
    'dist/tmp',
    'dist/*.rpm',
    'dist/rpmbuild',
    'spec/fixtures/modules'
  ]
  @verbose = ENV.fetch('SIMP_RAKE_PKG_verbose','no') == 'yes'

  # This is only meant to be used to work around the case where particular
  # packages need to ignore some set of artifacts that get updated out of
  # band. This should not be set as a regular environment variable and
  # should be fixed properly at some time in the future.
  #
  # Presently, this is used by simp-doc
  if ENV['SIMP_INTERNAL_pkg_ignore']
    @ignore_changes_list += ENV['SIMP_INTERNAL_pkg_ignore'].split(',')
  end

  FileUtils.mkdir_p(@pkg_tmp_dir, verbose: @verbose)

  local_spec = Dir.glob(File.join(@base_dir, 'build', '*.spec'))
  unless local_spec.empty?
    @spec_file = local_spec.first
  else
    @spec_tempfile = File.open(File.join(@pkg_tmp_dir, "#{@pkg_name}.spec"), 'w')
    @spec_tempfile.write(rpm_template(simp_version))

    @spec_file = @spec_tempfile.path

    @spec_tempfile.flush
    @spec_tempfile.close

    FileUtils.chmod(0640, @spec_file, verbose: @verbose)
  end

  ::CLEAN.include( @pkg_dir )

  yield self if block_given?

  ::CLEAN.include( @clean_list )

  if unique_namespace
    namespace unique_namespace.to_sym do
      define
    end
  else
    define
  end
end

Instance Attribute Details

#base_dirObject

path to the project’s directory. Usually ‘File.dirname(__FILE__)`



21
22
23
# File 'lib/simp/rake/pkg.rb', line 21

def base_dir
  @base_dir
end

#clean_listObject

array of items to additionally clean



36
37
38
# File 'lib/simp/rake/pkg.rb', line 36

def clean_list
  @clean_list
end

#exclude_listObject

array of items to exclude from the tarball



33
34
35
# File 'lib/simp/rake/pkg.rb', line 33

def exclude_list
  @exclude_list
end

#ignore_changes_listObject

array of items to ignore when checking if the tarball needs to be rebuilt



39
40
41
# File 'lib/simp/rake/pkg.rb', line 39

def ignore_changes_list
  @ignore_changes_list
end

#pkg_dirObject

path to the directory to place generated assets (e.g., rpm, tar.gz)



30
31
32
# File 'lib/simp/rake/pkg.rb', line 30

def pkg_dir
  @pkg_dir
end

#pkg_nameObject

the name of the package. Usually ‘File.basename(@base_dir)`



24
25
26
# File 'lib/simp/rake/pkg.rb', line 24

def pkg_name
  @pkg_name
end

#spec_fileObject

path to the project’s RPM specfile



27
28
29
# File 'lib/simp/rake/pkg.rb', line 27

def spec_file
  @spec_file
end

#spec_infoObject (readonly)

Returns the value of attribute spec_info.



41
42
43
# File 'lib/simp/rake/pkg.rb', line 41

def spec_info
  @spec_info
end

Instance Method Details

#defineObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/simp/rake/pkg.rb', line 102

def define
  # For the most part, we don't want to hear Rake's noise, unless it's an error
  # TODO: Make this configurable
  verbose(false)

  define_clean
  define_clobber
  define_pkg_tar
  define_pkg_rpm
  define_pkg_check_rpm_changelog
  define_pkg_check_version
  define_pkg_compare_latest_tag
  define_pkg_create_tag_changelog
  task :default => 'pkg:tar'

  Rake::Task['pkg:tar']
  Rake::Task['pkg:rpm']

  self
end

#define_cleanObject



150
151
152
153
154
155
156
157
# File 'lib/simp/rake/pkg.rb', line 150

def define_clean
  desc "  Clean build artifacts for \#{@pkg_name}\n  EOM\n  task :clean do |t,args|\n    # this is provided by 'rake/clean' and the ::CLEAN constant\n  end\nend\n"

#define_clobberObject



159
160
161
162
163
164
165
# File 'lib/simp/rake/pkg.rb', line 159

def define_clobber
  desc "  Clobber build artifacts for \#{@pkg_name}\n  EOM\n  task :clobber do |t,args|\n  end\nend\n"

#define_pkg_check_rpm_changelogObject



432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/simp/rake/pkg.rb', line 432

def define_pkg_check_rpm_changelog
  # :pkg:check_rpm_changelog
  # -----------------------------
  namespace :pkg do
    desc "    Check the \#{@pkg_name} RPM changelog using the 'rpm' command.\n\n    This task will fail if 'rpm' detects any changelog problems,\n    such as changelog entries not being in reverse chronological\n    order.\n    EOM\n    task :check_rpm_changelog, [:verbose] do |t,args|\n      if args[:verbose].to_s == 'true'\n        verbose = true\n      else\n        verbose = false\n      end\n      Simp::RelChecks::check_rpm_changelog(@base_dir, @spec_file, verbose)\n    end\n  end\nend\n"

#define_pkg_check_versionObject



454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
# File 'lib/simp/rake/pkg.rb', line 454

def define_pkg_check_version
  namespace :pkg do
    # :pkg:check_version
    # -----------------------------
    desc "    Ensure that \#{@pkg_name} has a properly updated version number.\n    EOM\n    task :check_version do |t,args|\n      require 'json'\n\n      # Get the current version\n      if File.exist?('metadata.json')\n        mod_version = JSON.load(File.read('metadata.json'))['version'].strip\n        success_msg = \"\#{@pkg_name}: Version \#{mod_version} up to date\"\n\n        # If we have no tags, we need a new version\n        if %x(git tag).strip.empty?\n          puts \"\#{@pkg_name}: New Version Required\"\n        else\n          # See if the module is newer than all tags\n          matching_tag = %x(git tag --points-at HEAD).strip.split(\"\\n\").first\n\n          if matching_tag.nil? || matching_tag.empty?\n            # We don't have a matching release\n            # Get the closest tag\n            nearest_tag = %x(git describe --abbrev=0 --tags).strip\n\n            if mod_version == nearest_tag\n              puts \"\#{@pkg_name}: Error: metadata.json needs to be updated past \#{mod_version}\"\n            else\n              # Check the CHANGELOG Version\n              if File.exist?('CHANGELOG')\n                changelog = File.read('CHANGELOG')\n                changelog_version = nil\n\n                # Find the first date line\n                changelog.each_line do |line|\n                  if line =~ /\\*.*(\\d+\\.\\d+\\.\\d+)(-\\d+)?\\s*$/\n                    changelog_version = $1\n                    break\n                  end\n                end\n\n                if changelog_version\n                  if changelog_version == mod_version\n                    puts success_msg\n                  else\n                    puts \"\#{@pkg_name}: Error: CHANGELOG version \#{changelog_version} out of date for version \#{mod_version}\"\n                  end\n                else\n                  puts \"\#{@pkg_name}: Error: No CHANGELOG version found\"\n                end\n              else\n                puts \"\#{@pkg_name}: Warning: No CHANGELOG found\"\n              end\n            end\n          else\n            if mod_version != matching_tag\n              puts \"\#{@pkg_name}: Error: Tag \#{matching_tag} does not match version \#{mod_version}\"\n            else\n              puts success_msg\n            end\n          end\n        end\n      else\n        puts \"\#{@pkg_name}: No metadata.json found\"\n      end\n    end\n  end\nend\n"

#define_pkg_compare_latest_tagObject



525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
# File 'lib/simp/rake/pkg.rb', line 525

def define_pkg_compare_latest_tag
  namespace :pkg do
    desc "    Compare to latest tag.\n      ARGS:\n        * :tags_source => Set to the remote from which the tags for this\n                          project can be fetched. Defaults to 'origin'.\n        * :verbose => Set to 'true' if you want to see detailed messages\n\n      NOTES:\n      Compares mission-impacting (significant) files with the latest\n      tag and identifies the relevant files that have changed.\n\n      Fails if\n      (1) There is any version validation or changelog parsing failure\n          that would prevent an annotated changelog tag from being\n          created. (See pkg::create_tag_changelog)\n      (2) A version bump is required but not recorded in both the\n          CHANGELOG and metadata.json files.\n      (3) The latest version is < latest tag.\n\n      Changes to the following files/directories are not considered\n      significant:\n      - Any hidden file/directory (entry that begins with a '.')\n      - Gemfile\n      - Gemfile.lock\n      - Rakefile\n      - rakelib directory\n      - spec directory\n      - doc directory\n    EOM\n    task :compare_latest_tag, [:tags_source, :verbose] do |t,args|\n      tags_source = args[:tags_source].nil? ? 'origin' : args[:tags_source]\n      if args[:verbose].to_s == 'true'\n        verbose = true\n      else\n        verbose = false\n      end\n      Simp::RelChecks::compare_latest_tag(@base_dir, tags_source, verbose)\n    end\n  end\nend\n"

#define_pkg_create_tag_changelogObject



568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
# File 'lib/simp/rake/pkg.rb', line 568

def define_pkg_create_tag_changelog
  namespace :pkg do
    # :pkg:create_tag_changelog
    # -----------------------------
    desc "    Generate an appropriate changelog for an annotated tag from a\n    component's CHANGELOG or RPM spec file.\n\n    The changelog text will be for the latest version and contain\n    1 or more changelog entries for that version, in reverse\n    chronological order.\n\n    ARGS:\n      * verbose => Set to 'true' if you want to see\n        non-catestrophic warning messages.\n\n    NOTES:\n      * Changelog entries must follow the following rules:\n        - An entry must start with * and be terminated\n          by a blank line.\n        - The first line must be of the form\n          * Wed Jul 05 2017 Author Name <[email protected]> - 1.2.3-4\n        - The date string must be RPM compatible.\n        - Dates must be in reverse chronological order, with the\n          newest dates occurring at the top of the changelog.\n        - Both an author name and email are required.\n        - The author email must be contained in < >.\n        - The version is required and must be of the form\n          <major>.<minor>.<patch>.\n        - The version may contain a release qualifier.\n        - When the release qualifier is present, it must appear\n          at the end of the version string and be separated from\n          the version by a '-'.\n\n      * This task will fail if any of the following occur:\n        - The metadata.json file for a Puppet module component\n          cannot be parsed.\n        - The CHANGELOG file for a Puppet module component does\n          not exist.\n        - The CHANGELOG entries for the latest version are\n          malformed.\n        - The RPM spec file or a non-Puppet module component does\n          not exist.\n        - More than 1 RPM spec file for a non-Puppet module\n          component exists.\n        - No valid changelog entries for the version specified in\n          the metadata.json/spec file are found.\n        - The latest changelog version is greater than the version\n          in the metadata.json or the RPM spec file.\n        - The RPM release specified in the spec file does not match\n          the release in a changelog entry for the version.\n        - Any changelog entry below the first entry has a version\n          greater than that of the first entry.\n        - The changelog entries for all versions are out of date\n          order.\n        - The weekday for a changelog entry for the latest version\n          does not match the date specified.\n\n    EOM\n    task :create_tag_changelog, [:verbose] => [:check_rpm_changelog] do |t,args|\n      if args[:verbose].to_s == 'true'\n        verbose = true\n      else\n        verbose = false\n      end\n      puts Simp::RelChecks::create_tag_changelog(@base_dir, verbose)\n    end\n  end\nend\n"

#define_pkg_rpmObject



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/simp/rake/pkg.rb', line 215

def define_pkg_rpm

  # :pkg:rpm
  # -----------------------------
  namespace :pkg do
=begin
    WARNING: THIS DOES NOT PULL FROM THE simp-core RPM DEPENDENCIES FILE
    WARNING: YOU WILL PROBABLY NOT GET PROPER FULL SIMP RPMS FROM THIS TASK

    desc <<-EOM
    Build the #{@pkg_name} RPM.

        By default, the package will be built to support a SIMP-6.X file structure.
        To build the package for a different version of SIMP, export SIMP_BUILD_version=<5.X,4.X>
    EOM
=end

    task :rpm => [:tar] do |t,args|
      rpm_opts = [
        %(-D 'buildroot #{@pkg_dir}/rpmbuild/BUILDROOT'),
        %(-D 'builddir #{@pkg_dir}/rpmbuild/BUILD'),
        %(-D '_sourcedir #{@rpm_srcdir}'),
        %(-D '_rpmdir #{@pkg_dir}'),
        %(-D '_srcrpmdir #{@pkg_dir}'),
        %(-D '_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm'),

        # needed on EL8 to disable the aggressive brp_mangle_shebangs script
        # that results in invalid script shebangs; does nothing in EL7
        %(-D '__brp_mangle_shebangs /usr/bin/true')
      ]
      rpm_opts << '-v' if @verbose
      rpm_opts << "-D 'lua_debug 1'" if (ENV.fetch('SIMP_RAKE_PKG_LUA_verbose','no') =='yes')
      rpm_opts << "-D 'pup_module_info_dir #{@base_dir}'"
      Dir.chdir(@pkg_dir) do

        # Copy in the materials required for the module builds
        # The following are required to build successful RPMs using
        # the new LUA-based RPM template
        puppet_module_info_files = [
          Dir.glob(%(#{@base_dir}/build/rpm_metadata/**)),
          %(#{@base_dir}/CHANGELOG),
          %(#{@base_dir}/metadata.json)
        ].flatten

        if @verbose
          puts "==== pkg:rpm: @base_dir: #{@base_dir}"
          puts "==== pkg:rpm: rpm_opts:\n #{rpm_opts.map{|x| "\n  #{x}"}.join}"
          puts "==== pkg:rpm: puppet_module_info_files: #{puppet_module_info_files.map{|x| "\n  #{x}"}.join}"
        end

        puppet_module_info_files.each do |f|
          if File.exist?(f)
            FileUtils.cp_r(f, @rpm_srcdir, verbose: @verbose)
          end
        end

        # Link in any misc artifacts that got dumped into 'dist' by other code
        extra_deps = Dir.glob("*")
        extra_deps.delete_if{|x| x =~ /(\.rpm$|(^(rpmbuild|logs|tmp$)))/}

        Dir.chdir(@rpm_srcdir) do
          extra_deps.each do |dep|
            unless File.exist?(dep)
              FileUtils.cp_r("../../#{dep}", dep, verbose: @verbose)
            end
          end
        end

        FileUtils.mkdir_p('logs', verbose: @verbose)
        FileUtils.mkdir_p('rpmbuild/BUILDROOT', verbose: @verbose)
        FileUtils.mkdir_p('rpmbuild/BUILD', verbose: @verbose)

        srpms = [@full_pkg_name + '.src.rpm']
        if require_rebuild?(srpms.first, @tar_dest)
          # TODO: Uncomment this after revamping the tests to use a dependencies.yaml file
          # Simp::Rake::Build::RpmDeps.generate_rpm_meta_files(@base_dir, {})

          # Need to build the SRPM so that we can get the build dependencies
          cmd = %(rpmbuild #{rpm_opts.join(' ')} -bs #{@spec_file} > logs/build.srpm.out 2> logs/build.srpm.err)
          puts "==== pkg:rpm SRPM BUILD:   #{cmd}" if @verbose
          %x(#{cmd})

          srpms = File.read('logs/build.srpm.out').scan(%r(Wrote:\s+(.*\.rpm))).flatten

          if srpms.empty?
            raise "  Could not create SRPM for '\#{@spec_info.basename}\nError: \#{File.read('logs/build.srpm.err')}\n            EOM\n          end\n        end\n\n        # Collect the built, or downloaded, RPMs\n        rpms = []\n\n        @spec_info.packages\n        expected_rpms = @spec_info.packages.map{|f|\n          latest_rpm = Dir.glob(\"\#{f}-\#{@spec_info.version}*.rpm\").select{|x|\n            # Get all local RPMs that are not SRPMs\n            x !~ /\\.src\\.rpm$/\n          }.map{|x|\n            # Convert them to objects\n            x = Simp::RPM.new(x)\n          }.sort_by{|x|\n            # Sort by the full version of the package and return the one\n            # with the highest version\n            Gem::Version.new(x.full_version)\n          }.last\n\n          if latest_rpm && (\n              Gem::Version.new(latest_rpm.full_version) >=\n              Gem::Version.new(@spec_info.full_version)\n          )\n            f = latest_rpm.rpm_name\n          else\n            f = \"\#{f}-\#{@spec_info.full_version}-\#{@spec_info.arch}.rpm\"\n          end\n        }\n\n        if expected_rpms.empty? || require_rebuild?(expected_rpms, srpms)\n\n          expected_rpms_data = expected_rpms.map{ |f|\n            if File.exist?(f)\n              f = Simp::RPM.new(f)\n            else\n              f = nil\n            end\n          }\n\n          require_rebuild = true\n\n          # We need to rebuild if not *all* of the expected RPMs are present\n          unless expected_rpms_data.include?(nil)\n            # If all of the RPMs are signed, we do not need a rebuild\n            require_rebuild = !expected_rpms_data.compact.select{|x| !x.signature}.empty?\n          end\n\n          if !require_rebuild\n            # We found all expected RPMs and they all had valid signatures\n            #\n            # Record the existing RPM metadata in the output file\n            rpms = expected_rpms\n          else\n            # Try a build\n            cmd = %(rpmbuild \#{rpm_opts.join(' ')} --rebuild \#{srpms.first} > logs/build.rpm.out 2> logs/build.rpm.err)\n            puts \"==== pkg:rpm: \#{cmd}\" if @verbose\n            _result = %x(\#{cmd})\n            puts _result if @verbose\n\n            # If the build failed, it was probably due to missing dependencies\n            unless $?.success?\n              # Find the RPM build dependencies\n              rpm_build_deps = %x(rpm -q -R -p \#{srpms.first}).strip.split(\"\\n\")\n\n              # RPM stuffs this in every time\n              rpm_build_deps.delete_if {|x| x =~ /^rpmlib/}\n\n              # See if we have the ability to install things\n              unless Process.uid == 0\n                unless %x(sudo -ln) =~ %r(NOPASSWD:\\s+(ALL|yum( install)?))\n                  raise <<-EOM\nPlease install the following dependencies and try again:\n\#{rpm_build_deps.map{|x| x = \"  * \#{x}\"}.join(\"\\n\")}\n"
                end
              end

              rpm_build_deps.map! do |rpm|
                if rpm =~ %r((.*)\s+(?:<=|=|==)\s+(.+))
                  rpm = "#{$1}-#{$2}"
                end

                rpm.strip
              end

              yum_install_cmd = %(yum -y install '#{rpm_build_deps.join("' '")}')
              unless Process.uid == 0
                yum_install_cmd = 'sudo ' + yum_install_cmd
              end
              puts "==== pkg:rpm: #{yum_install_cmd}" if @verbose

              install_output = %x(#{yum_install_cmd} 2>&1)

              if !$?.success? || (install_output =~ %r((N|n)o package))
                raise "Could not run \#{yum_install_cmd}\n  Error: \#{install_output}\n                EOM\n              end\n            end\n\n            # Try it again!\n            #\n            # If this doesn't work, something we can't fix automatically is wrong\n            cmd = %(rpmbuild \#{rpm_opts.join(' ')} --rebuild \#{srpms.first} > logs/build.rpm.out 2> logs/build.rpm.err)\n            puts \"==== pkg:rpm: \#{cmd}\" if @verbose\n            %x(\#{cmd})\n\n            rpms = File.read('logs/build.rpm.out').scan(%r(Wrote:\\s+(.*\\.rpm))).flatten - srpms\n\n            if rpms.empty?\n              raise <<-EOM\nCould not create RPM for '\#{@spec_info.basename}\n  Error: \#{File.read('logs/build.rpm.err')}\n              EOM\n            end\n          end\n\n          # Prevent overwriting the last good metadata file\n          raise %(Could not find any valid RPMs for '\#{@spec_info.basename}') if rpms.empty?\n\n          Simp::RPM.create_rpm_build_metadata(File.expand_path(@base_dir), srpms, rpms)\n        end\n      end\n    end\n  end\nend\n"

#define_pkg_tarObject



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/simp/rake/pkg.rb', line 167

def define_pkg_tar
  namespace :pkg do
    directory @pkg_dir

    task :initialize_spec_info => [@pkg_dir] do |t,args|
      initialize_spec_info
    end

    # :pkg:tar
    # -----------------------------
    desc "    Build the \#{@pkg_name} tar package.\n    EOM\n    task :tar => [:initialize_spec_info] do |t,args|\n      target_dir = File.basename(@base_dir)\n\n      Dir.chdir(%(\#{@base_dir}/..)) do\n        require_rebuild = false\n\n        if File.exist?(@tar_dest)\n          Find.find(target_dir) do |path|\n            filename = File.basename(path)\n\n            Find.prune if filename =~ /^\\./\n            Find.prune if ((filename == File.basename(@pkg_dir)) && File.directory?(path))\n\n            to_ignore = @ignore_changes_list.map{|x| x = Dir.glob(File.join(@base_dir, x))}.flatten\n            Find.prune if to_ignore.include?(File.expand_path(path))\n\n            next if File.directory?(path)\n\n            if require_rebuild?(@tar_dest, path)\n              require_rebuild = true\n              break\n            end\n          end\n        else\n          require_rebuild = true\n        end\n\n        if require_rebuild\n          sh %Q(tar --owner 0 --group 0 --exclude-vcs --exclude=\#{@exclude_list.join(' --exclude=')} --transform='s/^\#{@pkg_name}/\#{@dir_name}/' -cpzf \"\#{@tar_dest}\" \#{@pkg_name})\n        end\n      end\n    end\n  end\nend\n"

#initialize_spec_infoObject

Ensures that the correct file names are used across the board.



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/simp/rake/pkg.rb', line 124

def initialize_spec_info
  unless @spec_info
    # This gets the resting spec file and allows us to pull out the name
    @spec_info ||= Simp::RPM.new(@spec_file)
    @spec_info_dir ||= @base_dir

    @dir_name ||= "#{@spec_info.basename}-#{@spec_info.version}"
    @full_pkg_name ||= "#{@dir_name}-#{@spec_info.release}"

    _rpmbuild_srcdir = `rpm -E '%{_sourcedir}'`.strip

    unless File.exist?(_rpmbuild_srcdir)
      sh 'rpmdev-setuptree'
    end

    @rpm_srcdir ||= "#{@pkg_dir}/rpmbuild/SOURCES"
    FileUtils.mkdir_p(@rpm_srcdir, verbose: @verbose)

    @tar_dest ||= "#{@pkg_dir}/#{@full_pkg_name}.tar.gz"

    if @full_pkg_name =~ /UNKNOWN/
      fail("Error: Could not determine package information from 'metadata.json'. Got '#{@full_pkg_name}'")
    end
  end
end

#require_rebuild?(new, old) ⇒ Boolean


helper methods


Return True if any of the ‘old’ Array are newer than the ‘new’ Array

Returns:

  • (Boolean)


642
643
644
645
646
647
648
649
650
651
652
# File 'lib/simp/rake/pkg.rb', line 642

def require_rebuild?(new, old)
  return true if ( Array(old).empty? || Array(new).empty?)

  Array(new).each do |new_file|
    return true unless File.exist?(new_file)

    return true unless uptodate?(new_file, Array(old))
  end

  return false
end