-
Notifications
You must be signed in to change notification settings - Fork 44
Use perl instead of sed #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Use perl instead of sed #63
Conversation
|
Have converted to draft as though it works on windows it doesn't on linux. The problem is that |
|
It might be possible to do something like ifeq ($(strip $(OS_CLASS)),WIN32)
QUOTE="
else
QUOTE='
endif
$(COMMON_DIR)/siteEnvVars.substitutions: $(EPICS_BASE)/configure/CONFIG_SITE_ENV
@echo Expanding siteEnvVars.substitutions from CONFIG_SITE_ENV....
@echo file iocEnvVar.template> $@
@echo {>> $@
@echo pattern>> $@
@echo { ENVNAME, ENVVAR, ENVTYPE }>> $@
@perl -n -e $(QUOTE)$$m = s/^EPICS_([A-Z_]*).*/{$${1}, EPICS_$${1}, epics}/; print $$_ if $$m;$(QUOTE) < $< >> $@
@echo }>> $@
though I am not sure this is much better... 😄 |
|
Well it makes it clear what we are trying to do at least, I am happy to go with that if you are - thanks |
|
Unless you think putting the |
|
Surely it would be simpler to use a stand-alone Perl script to do the whole job of generating the |
|
Oh no more perl scripts 😄 Anyhow, I think you are correct in this case that a standalone script is easier; this is a pretty simple parsing, but the solution is better. |
iocAdmin/Db/genSiteEnvVars.pl
Outdated
| @@ -0,0 +1,9 @@ | |||
| print("file iocEnvVar.template\n"); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a shebang, usage, and copyright notice?
iocAdmin/Db/Makefile
Outdated
| @echo "{ ENVNAME, ENVVAR, ENVTYPE }" >> $@ | ||
| @sed -n 's/^EPICS_\([A-Z_]*\).*/{\1, EPICS_\1, epics}/p' $< >> $@ | ||
| @echo "}" >> $@ | ||
| @perl ../genSiteEnvVars.pl < $< > $@ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably better to use $(PERL) here instead of directly calling perl
This I leave up to you, but I think I would prefer a perl script that does not read from stdin but takes a file as an argument; looking at most of the perl scripts in use in various EPICS modules that seems to be more the more consistent standard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on using $(PERL).
Most Base build rules that run generator scripts start with @$(RM) $@ to explicitly delete the target file first, so any errors which result in the script not actually regenerating the output file will trigger an error from GNUmake instead of it just continuing without recreating the file. I guess that's an enhancement request since the original rule didn't do that, but I recommend adding it anyway.
Switching from stdin to a filename argument might not need any changes to your Perl code at all, since using while (<>) { ... } in Perl inline code automatically opens and parses the files listed in @ARGV anyway (improve on that, Python!).
iocAdmin/Db/genSiteEnvVars.pl
Outdated
| print("file iocEnvVar.template\n"); | ||
| print("{\n"); | ||
| print("pattern\n"); | ||
| print("{ ENVNAME, ENVVAR, ENVTYPE }\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a here-doc could reduce the number of quotes and escaped newlines, and I recommend always quoting the argument to file (again, not in the original). My personal preference for formatting substitution files would have fewer newlines:
print << __END__;
file "iocEnvVar.template" {
pattern { ENVNAME, ENVVAR, ENVTYPE }
__END__There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anjohnson @simon-ess thank you for the suggestions
|
NB The Windows-2019 job failures here are because today is one of the days that GitHub is doing a brown-out of their windows-2019 CI runners, to remind everyone to upgrade. That also requires updating the Visual Studio version to 2022, see |
|
did you want me to rebase the branch onto latest base-7.0 ? |
|
sorry - talking rubbish - this isn't a base PR. Will make changes to iocStats CI |
01f1b69 to
8f8a475
Compare
|
I have updated the perl script to be in line with #74 and other changes, as well as rebased. @FreddieAkeroyd if you could have a look at this and make sure this lines up with what you like, and I will merge it. |
|
@nariox, if you could also take a look at this please. |
Windows does not have
sedso change to useperlthat is already needed for building EPICSSee #62