#!/usr/bin/ruby # # Ruby script to build the P4Ruby distribution. # require "ftools" # # Relative path to P4Ruby relnotes. We need to copy them over when we're # building the distribution # RELNOTES_PATH = "../p4-doc/user/p4rubynotes.txt" # # Extract the P4Ruby version # def get_version v = nil p = nil n = nil File.open( "Version" ) do |f| f.each do |line| if ( line =~ /^RELEASE\s*=\s*(\d+) (\d+) ?(.*) ;/ ) v = "#{$1}.#{$2}" n = $3 n.gsub!(/ +/, '.') elsif ( line =~ /^PATCHLEVEL\s*=\s*(\d+)/ ) p = $1 end end end if ( ! v ) raise( RuntimeError, "Can't figure out the version of P4Ruby!" ) end v += ".#{p}" if p v += ".#{n}" if n return v end # Copy a file into a directory - creating the target directories as # required # def filecopy( srcpath, topdir ) dstpath = topdir + "/" + srcpath dstdir = File.dirname( dstpath ) File.makedirs( dstdir ) File.copy( srcpath, dstpath ) end # # Remove a directory recursively. # def cleanup( path ) if File.directory?( path ) Dir.foreach( path ) do |ent| next if ent == '.' or ent == '..' p = path + '/' + ent cleanup( p ) end Dir.rmdir( path ) else File.safe_unlink( path ) end end # # Populate the distribution directory # def populate( build_dir ) Dir.mkdir( build_dir ) or raise( RuntimeError, "Can't create #{build_dir}" ) # # Copy the release notes into 'RELNOTES.txt'. This is ugly, but we need # a way to include the release notes in the distribution, but still store # them in the standard place # File.copy( RELNOTES_PATH, "RELNOTES.txt" ) mfest = File.open( "MANIFEST" ) files = mfest.readlines() mfest.close files.each do |file| file.sub!( /\r?\n/, "" ) filecopy( file, build_dir ) end end # # Build the tarball # def build_tarball( tarball, build_dir ) system( "tar -cvf #{tarball} #{build_dir}" ) system( "gzip -vf #{tarball}" ) end version = get_version() build_dir = "p4ruby-" + version tarball = 'p4ruby.tar' cleanup( build_dir ) populate( build_dir ) build_tarball( tarball, build_dir ) cleanup( build_dir ) cleanup( "RELNOTES.txt" )