File indexing completed on 2024-05-12 16:28:26
0001 #!/usr/bin/ruby 0002 0003 # 0004 # Ruby script for generating tarball releases of the Calligra repository 0005 # This script can create signed tarballs with source code, translations and documentation 0006 # 0007 # (c) 2017 Dag Andersen <danders@get2net.dk> 0008 # (c) 2016 Dag Andersen <danders@get2net.dk> 0009 # 0010 # Parts of this script is from create_tarball_kf5.rb, copyright by: 0011 # (c) 2005 Mark Kretschmann <markey@web.de> 0012 # (c) 2006-2008 Tom Albers <tomalbers@kde.nl> 0013 # (c) 2007 Angelo Naselli <anaselli@linux.it> (command line parameters) 0014 # Some parts of this code taken from cvs2dist 0015 # 0016 # License: GNU General Public License V2 0017 0018 require 'optparse' 0019 require 'ostruct' 0020 require 'find' 0021 require 'fileutils' 0022 0023 # Compare two version strings 0024 # The strings must have the format "<major>.<minor>.<release>" 0025 # e.g "3.0.1" 0026 # Returns: 0027 # 1 v1 > v2 0028 # 0 v1 == v2 0029 # -1 v1 < v2 0030 def compare_versions(v1, v2) 0031 if v1 == "HEAD" 0032 return 1 0033 end 0034 vA = v1.split('.') 0035 vB = v2.split('.') 0036 if (vA[0] > vB[0]) 0037 return 1 0038 end 0039 if (vA[0] < vB[0]) 0040 return -1 0041 end 0042 if (vA[1] > vB[1]) 0043 return 1 0044 end 0045 if (vA[1] < vB[1]) 0046 return -1 0047 end 0048 if (vA[2] > vB[2]) 0049 return 1 0050 end 0051 if (vA[2] < vB[2]) 0052 return -1 0053 end 0054 return 0 0055 end 0056 0057 # check command line parameters 0058 options = OpenStruct.new 0059 options.help = false 0060 options.sign = true 0061 options.program = "gpg2" 0062 options.branch = "trunk" 0063 options.translations = true 0064 options.branch = "trunk" 0065 options.docs = false 0066 options.languages = [] 0067 options.tag = "HEAD" 0068 options.checkversion = true 0069 options.version = "" 0070 options.cstring = "" 0071 options.infolevel = 0 0072 0073 opts = OptionParser.new do |opts| 0074 opts.on_tail("-h", "--help", "Show this usage statement") do |h| 0075 options.help = true 0076 end 0077 opts.on("-v", "--version <version>", "Package version (Default: no version)") do |v| 0078 options.version = v 0079 end 0080 opts.on("-c", "--cstring <version string>", "Version string to check against version string in CMakeList.txt (Default: use version given in --version option)") do |c| 0081 options.cstring = c 0082 end 0083 opts.on("-n", "--no-check", "Disable version check") do |n| 0084 options.checkversion = false; 0085 end 0086 opts.on("-g", "--gittag <tag>", "Git tag (Default: 'HEAD')") do |g| 0087 options.tag = g 0088 end 0089 opts.on("-b", "--branch <tag>", "Svn branch for translations [trunk | stable] (Default: 'trunk')") do |g| 0090 options.tag = g 0091 end 0092 opts.on("-t", "--no-translations", "Do not include translations (Default: translations included)") do |t| 0093 options.translations = false 0094 end 0095 opts.on("-b", "--branch", "Translation branch [trunk/stable] (Default: 'trunk')") do |t| 0096 options.translations = false 0097 end 0098 # opts.on("-d", "--docs", "TODO Include documentation (Default: docs not included)") do |d| 0099 # TODO 0100 #options.translations = true 0101 # end 0102 opts.on("-s", "--sign", "Sign tarball (Default: tarball is not signed)") do |s| 0103 options.sign = false 0104 end 0105 opts.on("-p", "--program <program>", "Which program to use for signing (Default: gpg2)") do |p| 0106 options.program = p 0107 end 0108 opts.on("-l", "--languages <language,..>", "Include comma separated list of languages only (Default: All available languages)") do |l| 0109 options.languages = l.split(/\s*,\s*/) 0110 end 0111 opts.on("-i", "--infolevel <level>", "Select amount of info to print during processing (0-3) (Default: 0)") do |i| 0112 options.infolevel = i.to_i 0113 end 0114 end 0115 0116 begin 0117 opts.parse!(ARGV) 0118 rescue Exception => e 0119 puts e, "", opts 0120 puts 0121 exit 0122 end 0123 0124 if (options.help) 0125 puts 0126 puts opts 0127 puts 0128 exit 0129 end 0130 0131 ############# START ############# 0132 0133 app = "calligra" 0134 0135 if options.checkversion 0136 if options.cstring.empty? 0137 options.cstring = options.version 0138 end 0139 else 0140 options.cstring = "No check" 0141 end 0142 0143 puts 0144 puts "-> Processing " + app 0145 puts " Git tag: #{options.tag}" 0146 puts " Version: #{options.version}" 0147 puts " Version check: #{options.cstring}" 0148 puts " Signed: #{options.sign}" 0149 puts " Program: #{options.program}" 0150 puts " Translations: #{options.translations}" 0151 puts " Branch: #{options.branch}" 0152 print " Languages: " 0153 if options.translations 0154 if (options.languages.empty?) 0155 puts "all" 0156 else 0157 puts "#{options.languages}" 0158 end 0159 else 0160 # no translation, so no languages 0161 puts 0162 end 0163 # TODO 0164 # puts " Documentation: #{options.docs}" 0165 # puts 0166 0167 print "Continue? [Y/n]: " 0168 answer = gets 0169 answer = answer.lstrip.rstrip.chomp 0170 if answer.empty? 0171 answer = "Y" 0172 end 0173 if not answer == "Y" 0174 exit 0175 end 0176 puts 0177 0178 gitdir = "calligra" 0179 if options.version 0180 gitdir += "-" + options.version 0181 end 0182 gittar = "#{gitdir}.tar.xz" 0183 gitsig = "#{gittar}.sig" 0184 0185 puts "-- Create tarball of Calligra: " + gittar 0186 0187 `rm -rf #{gitdir} 2> /dev/null` 0188 if File.exist?(gittar) 0189 File.delete(gittar) 0190 end 0191 if File.exist?(gitsig) 0192 File.delete(gitsig) 0193 end 0194 0195 Dir.mkdir(gitdir) 0196 Dir.chdir(gitdir) 0197 0198 puts "-> Fetching git archive tag=#{options.tag} .." 0199 `git archive --remote git://anongit.kde.org/calligra.git #{options.tag} | tar -x` 0200 0201 if !File.exist?("CMakeLists.txt") 0202 puts 0203 puts "Failed: 'git archive' failed to fetch repository" 0204 puts 0205 exit 0206 end 0207 0208 # get the version 0209 cversion=`grep '(CALLIGRA_VERSION_STRING' CMakeLists.txt | cut -d'"' -f2` 0210 cversion = cversion.delete("\n").delete("\r").strip 0211 if options.checkversion 0212 cstring = options.version 0213 if options.cstring 0214 cstring = options.cstring 0215 end 0216 if cversion != cstring 0217 puts 0218 puts "Failed: Specified version is not the same as in CMakeLists.txt" 0219 puts " Specified version: '#{cstring}'" 0220 puts " CMakeLists.txt : '#{cversion}'" 0221 puts 0222 puts " Did you forget to update version in CMakeLists.txt?" 0223 puts 0224 puts " You can disable this test with the option: --no-check" 0225 puts 0226 exit 0227 end 0228 end 0229 0230 # translations 0231 if options.translations 0232 0233 svnbase = "svn+ssh://svn@svn.kde.org/home/kde" 0234 # atm trunk and no revision is assumed 0235 if options.branch == "trunk" 0236 svnroot = "#{svnbase}/trunk" 0237 else 0238 svnroot = "#{svnbase}/branches/stable" 0239 end 0240 rev = "" 0241 0242 puts "-> Fetching po file names .." 0243 Dir.mkdir("po") 0244 if FileTest.exist?("po_tmp") 0245 `rm -rf "po_tmp"` 0246 end 0247 Dir.mkdir("po_tmp") 0248 pofilenames = "po_tmp/pofilenames" 0249 `x=$(find $gitdir -name 'Messages.sh' | while read messagefile; do \ 0250 if grep -q '^potfilename=' $messagefile; then \ 0251 cat $messagefile | grep '^potfilename=' | cut -d'=' -f2 | cut -d'.' -f1; \ 0252 fi; \ 0253 done);\ 0254 echo "$x" >#{pofilenames}` 0255 0256 if !File.size?(pofilenames) 0257 puts "Failed: Could not fetch any po file names" 0258 exit 0259 end 0260 if options.infolevel > 0 0261 c = `wc -l #{pofilenames} | cut -d' ' -f1` 0262 puts " Number of po file names found: " + c 0263 end 0264 0265 puts "-> Fetching translations .." 0266 0267 # get languages 0268 i18nlangs = `svn cat #{svnroot}/l10n-kf5/subdirs #{rev}`.split 0269 i18nlangsCleaned = [] 0270 for lang in i18nlangs 0271 l = lang.chomp 0272 if !options.languages.empty? 0273 if options.languages.include?(l) 0274 i18nlangsCleaned += [l] 0275 end 0276 else l != "x-test" && !i18nlangsCleaned.include?(l) 0277 i18nlangsCleaned += [l] 0278 end 0279 end 0280 i18nlangs = i18nlangsCleaned 0281 0282 if FileTest.exist?("po") 0283 `rm -rf "po"` 0284 end 0285 Dir.mkdir("po") 0286 for lang in i18nlangs 0287 lang.chomp! 0288 tmp = "po_tmp/#{lang}" 0289 dest = "po/#{lang}" 0290 0291 # always checkout all po-files 0292 print " -> Fetching #{lang} from repository ..\n" 0293 pofolder = "l10n-kf5/#{lang}/messages/calligra" 0294 if options.infolevel > 0 0295 `svn co #{svnroot}/#{pofolder} #{tmp}` 0296 else 0297 `svn co #{svnroot}/#{pofolder} #{tmp} 2>/dev/null` 0298 end 0299 0300 # copy over the po-files we actually use in calligra 0301 File.foreach(pofilenames) do |pofile| 0302 pofile.chomp! 0303 pofilepath = "#{tmp}/#{pofile}.po" 0304 if !FileTest.exist?(pofilepath) 0305 # all files have not always been translated 0306 if options.infolevel > 1 0307 puts " Skipping #{pofilepath} .." 0308 end 0309 next 0310 end 0311 if !FileTest.exist?(dest) 0312 Dir.mkdir(dest) 0313 end 0314 if FileTest.exist?(pofilepath) 0315 if options.infolevel > 0 0316 puts " Copying #{pofile}.po .." 0317 end 0318 `mv #{pofilepath} #{dest}` 0319 end 0320 end 0321 end 0322 # remove temporary po dir 0323 `rm -rf "po_tmp"` 0324 0325 # add l10n to compilation. 0326 `echo "find_package(KF5I18n CONFIG REQUIRED)" >> CMakeLists.txt` 0327 `echo "ki18n_install(po)" >> CMakeLists.txt` 0328 0329 if options.docs 0330 # add docs to compilation. 0331 `echo "find_package(KF5DocTools CONFIG REQUIRED)" >> CMakeLists.txt` 0332 `echo "kdoctools_install(po)" >> CMakeLists.txt` 0333 end 0334 end 0335 0336 # Remove cruft 0337 `find -name ".svn" | xargs rm -rf` 0338 Dir.chdir( ".." ) # root folder 0339 0340 print "-> Compressing .. " 0341 `tar -Jcf #{gittar} --group=root --owner=root #{gitdir}` 0342 puts " done." 0343 puts "" 0344 print "md5sum: ", `md5sum #{gittar}` 0345 print "sha256sum: ", `sha256sum #{gittar}` 0346 0347 if (options.sign) 0348 puts "-> Signing .. " 0349 `#{options.program} -a --output #{gitsig} --detach-sign #{gittar}` 0350 puts "" 0351 print "sha256sum: ", `sha256sum #{gitsig}` 0352 end