Skip to content

Commit

Permalink
Adjust RELEASE file variable name recognition
Browse files Browse the repository at this point in the history
I was asked to support the use of hyphens `-` in names.
  • Loading branch information
anjohnson committed Mar 26, 2020
1 parent 5040af3 commit 1d6fcd4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
24 changes: 22 additions & 2 deletions documentation/RELEASE_NOTES.md
Expand Up @@ -12,12 +12,32 @@ The external PVA submodules each have their own separate set of release notes
which should also be read to understand what has changed since an earlier
release.

## EPICS Release 7.x.y.z
## EPICS Release 7.0.3.2

### Variable names in RELEASE files

`configure/RELEASE` files are parsed by both GNUmake and the `convertRelease.pl`
script. While GNUmake is quite relaxed about what characters may be used in a
RELEASE variable name, the `convertRelease.pl` script parser has only recognized
variable names that match the Perl regular expression `\w+`, i.e. upper and
lower-case letters, digits and underscore characters.

The script has been modified so now RELEASE variable names must start with a
letter or underscore, and be followed by any number of letters, digits,
underscore or hyphen characters, matching the regular expression
`[A-Za-z_][A-Za-z_0-9-]*`. The hyphen character `-` was not previously allowed
and if used would have prevented a build from finding include files and
libraries in any module using that in its RELEASE variable name.

This change does disallow names that start with a digit which used to be
allowed, but hopefully nobody has been relying on that ability. The regular
expression used for names can be found in the file `src/tools/EPICS/Release.pm`
and can be adjusted locally if necessary.

### caRepeater /dev/null

On *NIX targets caRepeater will now partially daemonize by redirecting
stdin/out/err with /dev/null. This prevents caRepeater from inheriting
stdin/out/err to /dev/null. This prevents caRepeater from inheriting
the stdin/out of a process, like caget, which has spawned it in the
background. This has been known to cause problems in some cases when
caget is itself being run from a shell script.
Expand Down
35 changes: 19 additions & 16 deletions src/tools/EPICS/Release.pm
Expand Up @@ -5,6 +5,9 @@
# in file LICENSE that is included with this distribution.
#*************************************************************************

# Regex to recognize variable names allowed in a RELEASE file
my $MVAR = qr/[A-Za-z_] [A-Za-z_0-9-]*/x;

#
# Parse all relevent configure/RELEASE* files and includes
#
Expand Down Expand Up @@ -58,17 +61,17 @@ sub readRelease {
s/ \s+ $//x; # Remove trailing whitespace
next if m/^ \s* $/x; # Skip blank lines

# Handle "<macro> = <path>" plus the := and ?= variants
my ($macro, $op, $val) = m/^ \s* (\w+) \s* ([?:]?=) \s* (.*) /x;
if ($macro ne '') {
$macro = 'TOP' if $macro =~ m/^ INSTALL_LOCATION /x;
if (exists $Rmacros->{$macro}) {
# Handle "<variable> = <path>" plus the := and ?= variants
my ($var, $op, $val) = m/^ \s* ($MVAR) \s* ([?:]?=) \s* (.*) /x;
if ($var ne '') {
$var = 'TOP' if $var =~ m/^ INSTALL_LOCATION /x;
if (exists $Rmacros->{$var}) {
next if $op eq '?=';
} else {
push @$Rapps, $macro;
push @$Rapps, $var;
}
$val = expandMacros($val, $Rmacros) if $op eq ':=';
$Rmacros->{$macro} = $val;
$Rmacros->{$var} = $val;
next;
}
# Handle "include <path>" and "-include <path>" syntax
Expand All @@ -85,35 +88,35 @@ sub readRelease {
}

#
# Expand all (possibly nested) macros in a string
# Expand all (possibly nested) variables in a string
#
sub expandMacros {
my ($str, $Rmacros) = @_;
# $Rmacros is a reference to a hash

while (my ($pre, $var, $post) = $str =~ m/ (.*) \$\( (\w+) \) (.*) /x) {
while (my ($pre, $var, $post) = $str =~ m/ (.*) \$\( ($MVAR) \) (.*) /x) {
last unless exists $Rmacros->{$var};
$str = $pre . $Rmacros->{$var} . $post;
}
return $str;
}

#
# Expand all (possibly nested) macros in a dictionary
# Expand all (possibly nested) variables in a dictionary
#
sub expandRelease {
my ($Rmacros, $warn) = @_;
# $Rmacros is a reference to a hash
$warn = '' unless defined $warn;

while (my ($macro, $val) = each %$Rmacros) {
while (my ($pre,$var,$post) = $val =~ m/ (.*) \$\( (\w+) \) (.*) /x) {
warn "EPICS/Release.pm: Undefined macro \$($var) used $warn\n"
while (my ($relvar, $val) = each %$Rmacros) {
while (my ($pre,$var,$post) = $val =~ m/ (.*) \$\( ($MVAR) \) (.*) /x) {
warn "EPICS/Release.pm: Undefined variable \$($var) used $warn\n"
unless exists $Rmacros->{$var};
die "EPICS/Release.pm: Circular definition of macro $var $warn\n"
if $macro eq $var;
die "EPICS/Release.pm: Circular definition of variable $var $warn\n"
if $relvar eq $var;
$val = $pre . $Rmacros->{$var} . $post;
$Rmacros->{$macro} = $val;
$Rmacros->{$relvar} = $val;
}
}
}
Expand Down

0 comments on commit 1d6fcd4

Please sign in to comment.