From 3f80a9a1eaf08fde777c06b3fb397d0f74683509 Mon Sep 17 00:00:00 2001 From: Johan Holmberg Date: Fri, 7 Oct 2016 16:45:10 +0200 Subject: [PATCH] creation on DEB packages with improved version numbering --- CMakeLists.txt | 84 ++++++++++++++++++++++++++++++++++++++++++++++ bin/cmdtest.rb | 31 +++++++++++++++-- replace_strings.pl | 30 +++++++++++++++++ 3 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 CMakeLists.txt create mode 100755 replace_strings.pl diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..457a585 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,84 @@ +cmake_minimum_required(VERSION 3.0) +project(cmdtest) + +execute_process( + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ruby bin/cmdtest.rb --shortversion + OUTPUT_VARIABLE CMDTEST_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + +execute_process( + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND date +%Y%m%d + OUTPUT_VARIABLE CMDTEST_DATE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + +set(CPACK_GENERATOR "DEB;STGZ;TGZ;TZ") +set(CPACK_PACKAGE_VERSION "${CMDTEST_VERSION}.${CMDTEST_DATE}") + +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Johan Holmberg ") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Cmdtest, xUnit style testing of commands") +set(CPACK_PACKAGE_DESCRIPTION "Cmdtest, xUnit style testing of commands ...") + +set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "all") +set(CPACK_DEBIAN_PACKAGE_DEPENDS "ruby | ruby-interpreter") + +INCLUDE(CPack) + +execute_process( + COMMAND git rev-parse HEAD + OUTPUT_VARIABLE GIT_REV + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + +execute_process( + COMMAND git show -s --format=%ci HEAD + OUTPUT_VARIABLE GIT_DATE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + +message(STATUS "GIT_REV = '${GIT_REV}'") +message(STATUS "GIT_DATE = '${GIT_DATE}'") + +execute_process( + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ./replace_strings.pl "GIT_REV_STRING=${GIT_REV}" "GIT_DATE_STRING=${GIT_DATE}" bin/cmdtest.rb bin/cmdtest.rb.generated + ) + + +install( + FILES + lib/cmdtest/argumentparser.rb + lib/cmdtest/baselogger.rb + lib/cmdtest/cmdeffects.rb + lib/cmdtest/consolelogger.rb + lib/cmdtest/fileinfo.rb + lib/cmdtest/fssnapshot.rb + lib/cmdtest/junitfile.rb + lib/cmdtest/junitlogger.rb + lib/cmdtest/lcs.rb + lib/cmdtest/methodfilter.rb + lib/cmdtest/notify.rb + lib/cmdtest/output.rb + lib/cmdtest/testcase.rb + lib/cmdtest/util.rb + lib/cmdtest/workdir.rb + DESTINATION lib/ruby/vendor_ruby/cmdtest + ) + +install( + FILES + doc/cmdtest.html + COPYING.txt + README.html + DESTINATION share/doc/rake + ) + +install( + PROGRAMS + bin/cmdtest.rb.generated + DESTINATION bin + RENAME cmdtest + ) diff --git a/bin/cmdtest.rb b/bin/cmdtest.rb index 54612a0..90e2bf2 100755 --- a/bin/cmdtest.rb +++ b/bin/cmdtest.rb @@ -25,9 +25,9 @@ # found in the files. The result can be reported in different ways. # Most of the testing logic is found in the library files "cmdtest/*.rb". -top_dir = File.dirname(File.dirname(__FILE__)) -lib_dir = File.join(File.expand_path(top_dir), "lib") -$:.unshift(lib_dir) if File.directory?(File.join(lib_dir, "cmdtest")) +TOP_DIR = File.expand_path(File.dirname(File.dirname(__FILE__))) +LIB_DIR = File.join(TOP_DIR, "lib") +$:.unshift(LIB_DIR) if File.directory?(File.join(LIB_DIR, "cmdtest")) require "cmdtest/argumentparser" require "cmdtest/baselogger" @@ -49,6 +49,11 @@ module Cmdtest ORIG_CWD = Dir.pwd + GIT_REV = 'GIT_REV_STRING' + GIT_DATE = 'GIT_DATE_STRING' + + VERSION = '1.4' + #---------------------------------------------------------------------- module LogBaseMixin @@ -573,6 +578,7 @@ module Cmdtest def _parse_options pr = @argument_parser = ArgumentParser.new("cmdtest") pr.add("-h", "--help", "show this help message and exit") + pr.add("", "--shortversion", "show just version number") pr.add("", "--version", "show version") pr.add("-q", "--quiet", "be more quiet") pr.add("-v", "--verbose", "be more verbose") @@ -598,6 +604,25 @@ module Cmdtest def run opts = _parse_options + if opts.shortversion + puts VERSION + exit(0) + elsif opts.version + puts "Version: " + VERSION + if File.directory?(File.join(TOP_DIR, ".git")) + Dir.chdir(TOP_DIR) do + git_rev = `git rev-parse HEAD` + git_date = `git show -s --format=%ci HEAD` + puts "Revision: #{git_rev}" + puts "Date: #{git_date}" + end + else + puts "Revision: #{GIT_REV}" + puts "Date: #{GIT_DATE}" + end + exit(0) + end + if opts.stop_on_error && opts.parallel != 1 puts "cmdtest: error: --stop-on-error can not be used with --parallel" exit(1) diff --git a/replace_strings.pl b/replace_strings.pl new file mode 100755 index 0000000..15c6c9f --- /dev/null +++ b/replace_strings.pl @@ -0,0 +1,30 @@ +#!/usr/bin/env perl + +use strict; + +my @replace; + +while (@ARGV > 0 && $ARGV[0] =~ /^(\w+)=(.*)/) { + my ($old, $new) = ($1, $2); + push @replace, [$old, $new]; + shift @ARGV; +} + +if (@ARGV != 2) { + die "Usage: replace_strings K1=V1 ... Kn=Vn INFILE OUTFILE\n"; +} + +my ($infile, $outfile) = @ARGV; + +open(my $f, '<', $infile) || die "open($infile)"; +open(my $g, '>', $outfile) || die "open($outfile)"; +while (my $line = <$f>) { + for my $entry (@replace) { + my ($old, $new) = @$entry; + $line =~ s/$old/$new/g; + } + print {$g} $line; +} + +close($f) || die "close($infile)"; +close($g) || die "close($outfile)";