From 837111296e8e328d378636ba9219c454b02493bb Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Fri, 10 Jul 2015 12:09:37 -0500 Subject: [PATCH] Updates to build rules and genVersionHeader.pl script Added -q (quiet) flag, renamed INSTALL_QUIETLY build variable. Moved GENVERSION variables into normal locations. Changed from :: rule to : rule with FORCE dependency. Removed use of --git-dir, only works when CWD is TOP. Simplified some parts, more perlish. Added VCS used to generated output file. Expanded on the -v (verbose) output. --- configure/CONFIG_BASE | 4 +- configure/CONFIG_COMMON | 9 ++ configure/RULES_BUILD | 13 +- src/template/base/top/exampleApp/src/Makefile | 5 +- src/tools/genVersionHeader.pl | 118 +++++++++++------- 5 files changed, 87 insertions(+), 62 deletions(-) diff --git a/configure/CONFIG_BASE b/configure/CONFIG_BASE index e416f99db..6eac3b2e0 100644 --- a/configure/CONFIG_BASE +++ b/configure/CONFIG_BASE @@ -63,11 +63,11 @@ DBTOMENUH = $(PERL) $(TOOLS)/dbdToMenuH.pl REGISTERRECORDDEVICEDRIVER = $(PERL) $(TOOLS)/registerRecordDeviceDriver.pl CONVERTRELEASE = $(PERL) $(TOOLS)/convertRelease.pl FULLPATHNAME = $(PERL) $(TOOLS)/fullPathName.pl +GENVERSIONHEADER = $(PERL) $(TOOLS)/genVersionHeader.pl $(QUIET_FLAG) #------------------------------------------------------- # tools for installing libraries and products -INSTALL_QUIETLY := $(if $(findstring s,$(MAKEFLAGS)),-q,) -INSTALL = $(PERL) $(TOOLS)/installEpics.pl $(INSTALL_QUIETLY) +INSTALL = $(PERL) $(TOOLS)/installEpics.pl $(QUIET_FLAG) INSTALL_PRODUCT = $(INSTALL) INSTALL_LIBRARY = $(INSTALL) diff --git a/configure/CONFIG_COMMON b/configure/CONFIG_COMMON index 584175784..9e82b13b0 100644 --- a/configure/CONFIG_COMMON +++ b/configure/CONFIG_COMMON @@ -85,6 +85,7 @@ IOCS_APPL_TOP = $(shell $(FULLPATHNAME) $(INSTALL_LOCATION)) # Make echo output - suppress echoing if make's '-s' flag is set NOP = : ECHO = @$(if $(findstring s,$(patsubst T_A=%,,$(MAKEFLAGS))),$(NOP),echo) +QUIET_FLAG := $(if $(findstring s,$(MAKEFLAGS)),-q,) #------------------------------------------------------- ifdef T_A @@ -327,6 +328,14 @@ COMPILE.cpp = $(CCC) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) # C preprocessor command PREPROCESS.cpp = $(CPP) $(CPPFLAGS) $(INCLUDES) $< > $@ +#-------------------------------------------------- +# genVersion header defaults + +# C macro name +GENVERSIONMACRO = VCSVERSION +# C macro default value (empty to use date+time) +GENVERSIONDEFAULT = + #-------------------------------------------------- # Header dependency file generation diff --git a/configure/RULES_BUILD b/configure/RULES_BUILD index 2b836ce2c..7ec79d569 100644 --- a/configure/RULES_BUILD +++ b/configure/RULES_BUILD @@ -363,15 +363,8 @@ tapfiles: $(TESTSCRIPTS) $(TAPFILES) # Generate header with version number from VCS ifneq ($(GENVERSION),) -GENERATEVERSIONHEADERCMD ?= $(PERL) $(TOOLS)/genVersionHeader.pl -# C macro name -GENVERSIONMACRO ?= MODULEVERSION -# C macro default (empty uses date+time) -#GENVERSIONDEFAULT = defaultversionnumber - -$(GENVERSION):: - $(GENERATEVERSIONHEADERCMD) -t "$(TOP)" -V "$(GENVERSIONDEFAULT)" -N "$(GENVERSIONMACRO)" $@ - +$(COMMON_DIR)/$(GENVERSION): FORCE + $(GENVERSIONHEADER) -t $(TOP) -N $(GENVERSIONMACRO) -V "$(GENVERSIONDEFAULT)" $@ endif #--------------------------------------------------------------- @@ -503,7 +496,7 @@ $(INSTALL_TEMPLATES_SUBDIR)/%: % .PRECIOUS: $(COMMON_INC) .PHONY: all host inc build install clean rebuild buildInstall build_clean -.PHONY: runtests tapfiles checkRelease warnRelease noCheckRelease +.PHONY: runtests tapfiles checkRelease warnRelease noCheckRelease FORCE endif # BASE_RULES_BUILD # EOF RULES_BUILD diff --git a/src/template/base/top/exampleApp/src/Makefile b/src/template/base/top/exampleApp/src/Makefile index 0c127999b..2a301d872 100644 --- a/src/template/base/top/exampleApp/src/Makefile +++ b/src/template/base/top/exampleApp/src/Makefile @@ -88,6 +88,5 @@ include $(TOP)/configure/RULES #---------------------------------------- # ADD RULES AFTER THIS LINE -# Dependency for the generated header -# must be explicit -devGenVersion$(DEP): $(GENVERSION) +# Explicit dependency needed for generated header file +dev_APPNAME_Version$(DEP): $(COMMON_DIR)/$(GENVERSION) diff --git a/src/tools/genVersionHeader.pl b/src/tools/genVersionHeader.pl index 43bec8d80..f078ad4f6 100644 --- a/src/tools/genVersionHeader.pl +++ b/src/tools/genVersionHeader.pl @@ -21,109 +21,131 @@ use strict; # RFC 8601 date+time w/ zone (eg "2014-08-29T09:42:47-0700") my $tfmt = '%Y-%m-%dT%H:%M:%S'; $tfmt .= '%z' unless $^O eq 'MSWin32'; # %z returns zone name on Windows +my $now = strftime($tfmt, localtime); -our ($opt_h, $opt_v); +our ($opt_h, $opt_v, $opt_q); our $opt_t = '.'; our $opt_N = 'VCSVERSION'; -our $opt_V = strftime($tfmt, localtime); +our $opt_V = $now; -my $foundvcs = 0; -my $result; +my $vcs; -getopts('hvt:N:V:') && @ARGV == 1 +getopts('hvqt:N:V:') && @ARGV == 1 or HELP_MESSAGE(); my ($outfile) = @ARGV; -if (!$foundvcs && -d "$opt_t/_darcs") { # Darcs +if (!$vcs && -d "$opt_t/_darcs") { # Darcs + print "== Found /_darcs directory\n" if $opt_v; # v1-4-dirty # is tag 'v1' plus 4 patches # with uncommited modifications - $result = `cd "$opt_t" && echo "\$(darcs show tags | head -1)-\$((\$(darcs changes --count --from-tag .)-1))"`; + my $result = `cd "$opt_t" && echo "\$(darcs show tags | head -1)-\$((\$(darcs changes --count --from-tag .)-1))"`; chomp $result; - if (!$? && length($result) > 1) { + print "== darcs show tags, changes:\n$result\n==\n" if $opt_v; + if (!$? && $result ne '') { $opt_V = $result; - $foundvcs = 1; + $vcs = 'Darcs'; # see if working copy has modifications, additions, removals, or missing files my $hasmod = `darcs whatsnew --repodir="$opt_t" -l`; $opt_V .= '-dirty' unless $?; } } -if (!$foundvcs && -d "$opt_t/.hg") { # Mercurial +if (!$vcs && -d "$opt_t/.hg") { # Mercurial + print "== Found /.hg directory\n" if $opt_v; # v1-4-abcdef-dirty # is 4 commits after tag 'v1' with short hash abcdef # with uncommited modifications - $result = `hg --cwd "$opt_t" tip --template '{latesttag}-{latesttagdistance}-{node|short}\n'`; - chomp $result; - if (!$? && length($result)>1) { + my $result = `hg tip --template '{latesttag}-{latesttagdistance}-{node|short}'`; + print "== hg tip:\n$result\n==\n" if $opt_v; + if (!$? && $result ne '') { $opt_V = $result; - $foundvcs = 1; + $vcs = 'Mercurial'; # see if working copy has modifications, additions, removals, or missing files - my $hasmod = `hg --cwd "$opt_t" status -m -a -r -d`; + my $hasmod = `hg status -m -a -r -d`; chomp $hasmod; - $opt_V .= '-dirty' if length($hasmod) > 0; + $opt_V .= '-dirty' if $hasmod ne ''; } } -if (!$foundvcs && -d "$opt_t/.git") { - # same format as Mercurial - $result = `git --git-dir="$opt_t/.git" describe --tags --dirty`; +if (!$vcs && -d "$opt_t/.git") { # Git + print "== Found /.git directory\n" if $opt_v; + # v1-4-abcdef-dirty + # is 4 commits after tag 'v1' with short hash abcdef + # with uncommited modifications + my $result = `git describe --tags --dirty`; chomp $result; - if (!$? && length($result) > 1) { + print "== git describe:\n$result\n==\n" if $opt_v; + if (!$? && $result ne '') { $opt_V = $result; - $foundvcs = 1; + $vcs = 'Git'; } } -if (!$foundvcs && -d "$opt_t/.svn") { - # 12345 - $result = `cd "$opt_t" && svn info --non-interactive`; +if (!$vcs && -d "$opt_t/.svn") { # Subversion + print "== Found /.svn directory\n" if $opt_v; + # 12345-dirty + my $result = `cd "$opt_t" && svn info --non-interactive`; chomp $result; + print "== svn info:\n$result\n==\n" if $opt_v; if (!$? && $result =~ /^Revision:\s*(\d+)/m) { $opt_V = $1; - $foundvcs = 1; + $vcs = 'Subversion'; # see if working copy has modifications, additions, removals, or missing files - my $hasmod = `cd "$opt_t" && svn status -q --non-interactive`; + my $hasmod = `cd "$opt_t" && svn status --non-interactive`; chomp $hasmod; - $opt_V .= '-dirty' if length($hasmod) > 0; + $opt_V .= '-dirty' if $hasmod ne ''; } } -if (!$foundvcs && -d "$opt_t/.bzr") { - # 12444-anj@aps.anl.gov-20131003210403-icfd8mc37g8vctpf - $result = `cd "$opt_t" && bzr version-info -q --custom --template="{revno}-{revision_id}"`; - chomp $result; - if (!$? && length($result)>1) { +if (!$vcs && -d "$opt_t/.bzr") { # Bazaar + print "== Found /.bzr directory\n" if $opt_v; + # 12444-anj@aps.anl.gov-20131003210403-icfd8mc37g8vctpf-dirty + my $result = `bzr version-info -q --custom --template="{revno}-{revision_id}-{clean}"`; + print "== bzr version-info:\n$result\n==\n" if $opt_v; + if (!$? && $result ne '') { + $result =~ s/-([01])$/$1 ? '' : '-dirty'/e; $opt_V = $result; - $foundvcs = 1; - # see if working copy has modifications, additions, removals, or missing files - # unfortunately "bzr version-info --check-clean ..." doesn't seem to work as documented - my $hasmod = `cd "$opt_t" && bzr status -SV`; - chomp $hasmod; - $opt_V .= '-dirty' if length($hasmod) > 0; + $vcs = 'Bazaar'; + } +} +if (!$vcs) { + print "== No VCS directories\n" if $opt_v; + if ($opt_V eq '') { + $vcs = 'build date/time'; + $opt_V = $now; + } + else { + $vcs = 'Makefile'; } } my $output = << "__END"; /* Generated file, do not edit! */ +/* Version determined from $vcs */ + #ifndef $opt_N -# define $opt_N \"$opt_V\" + #define $opt_N \"$opt_V\" #endif __END -print "== would\n$output" if $opt_v; + +print "== Want:\n$output==\n" if $opt_v; my $DST; if (open($DST, '+<', $outfile)) { my $actual = join('', <$DST>); - print "== have\n$actual" if $opt_v; + print "== Current:\n$actual==\n" if $opt_v; if ($actual eq $output) { - print "Keeping existing VCS version header $outfile with \"$opt_V\"\n"; + print "Keeping VCS header $outfile\n $opt_N = \"$opt_V\"\n" + unless $opt_q; exit 0; } - print "Updating VCS version header $outfile with \"$opt_V\"\n"; + print "Updating VCS header $outfile\n $opt_N = \"$opt_V\"\n" + unless $opt_q; } else { - print "Creating VCS version header $outfile with \"$opt_V\"\n"; + print "Creating VCS header $outfile\n $opt_N = \"$opt_V\"\n" + unless $opt_q; open($DST, '>', $outfile) - or die "Unable to open or create VCS version header $outfile"; + or die "Can't create $outfile: $!\n"; } seek $DST, 0, 0; @@ -136,11 +158,13 @@ sub HELP_MESSAGE { Usage: genVersionHeader.pl -h Display this Usage message - genVersionHeader.pl [-v] [-t top] [-N NAME] [-V version] output.h"; + genVersionHeader.pl [-v] [-q] [-t top] [-N NAME] [-V version] output.h"; Generate or update the header file output.h + -v - Verbose (debugging messages) + -q - Quiet -t top - Path to the module's top (default '$opt_t') -N NAME - Macro name to be defined (default '$opt_N') - -v version - Version number if no VCS (default '$opt_V') + -V version - Version if no VCS (e.g. '$opt_V') EOF exit $opt_h ? 0 : 1; }