Skip to content

Instantly share code, notes, and snippets.

@markllama
Last active December 15, 2015 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markllama/5225912 to your computer and use it in GitHub Desktop.
Save markllama/5225912 to your computer and use it in GitHub Desktop.
Define tasks to install requirements, build RPMs and generate Yard docs.
#!/usr/bin/rake -f
#
# Tasks to install build requirement packages, build RPMs and generate documentation pages.
#
# chmod a+x oo-rake
# oo-rake [--tasks]| <task>
#
require 'rake'
# use recursive tasks
#require "./tasks/dir_tasks"
namespace :all do
# ============================================================================
# Custom top-level tasks for efficiency
#
# While these tasks can be done recursively, they're much faster this way.
# ============================================================================
begin
require 'yard'
#
# Generate and combine Yard documentation from all sources
#
desc "generate comprehensive documentation"
task :yard, :destdir do | t, args |
puts "collecting source locations"
# include manually created markdown documentation
readme_files = FileList["*.md", "documentation/*.md"]
# find the source locations indicated in each package
srclist = []
Find.find(".") do |f|
if f.end_with? "Rakefile"
d = File.dirname f
s = d + "/lib"
srclist << s if File.exists? s
end
end
puts "srclist = #{srclist}"
# Generate docs with standard parameters
cmd = 'yard doc '
yardargs = ['--protected', '--private', '--no-yardopts']
cmd += yardargs.join(' ') + ' '
# Set the destination for docs if provided
if not args[:destdir] == nil then
cmd += "--output-dir #{args[:destdir]} "
end
# compose the doc generation command
cmd += srclist.join(' ')
cmd += " - " + readme_files.join(' ')
# Generate documentation
system cmd
end
rescue
# yard is unavailable
puts "rubygem yard is unavailable"
end
#
# Install all RPM build requirements
#
require 'find'
desc "install all build requirements"
task :builddep, :answer do |t, args|
cmd = "yum-builddep "
answer = args[:answer] || ""
cmd += " --assume#{answer} " if ['yes', 'no'].include? answer
speclist = []
Find.find(".") do | f |
speclist << f if /\.spec$/.match f
end
specfiles = speclist.join(' ')
cmd += specfiles
cmd = "sudo " + cmd if not Process.uid == 0
system cmd
end
#
# Build all RPMs and generate a yum repository
#
desc "generate all RPMs and create yum repository"
task :rpm, :repodir, :test, :yum do |t, args|
repodir = args[:repodir] || "/tmp/tito"
Find.find(".") do |f|
if /.spec$/.match f then
pkgdir = File.dirname f
cmd = "tito build --rpm"
cmd << " --output #{args[:repodir]}" if args[:repodir]
cmd << " --test" if not args[:test] === ""
# system "cd #{pkgdir} ; #{cmd}"
system "cd #{pkgdir} ; #{cmd}"
end
end
# generate the repo metadata
system "createrepo #{repodir}" if args[:yum] and File.directory? repodir
end
#
# Create test RPMs from source tree and spec files
#
# repodir: destination for artifacts and packages
#
desc "generate all test RPMs and create yum repository"
task :testrpm, :repodir, :yum do |t, args|
repodir = args[:repodir] || ""
yum = args[:yum] || ""
Rake.application.invoke_task("all:rpm[#{repodir},true,#{yum}]")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment