Skip to content

Conversation

@FreddieAkeroyd
Copy link

Windows does not have sed so change to use perl that is already needed for building EPICS

See #62

@FreddieAkeroyd FreddieAkeroyd marked this pull request as draft October 27, 2024 23:01
@FreddieAkeroyd
Copy link
Author

FreddieAkeroyd commented Oct 27, 2024

Have converted to draft as though it works on windows it doesn't on linux. The problem is that ' does not work on windows but using " means the perl variables $ get interpreted by the linux shell. Tried adding \ which makes it work on linux but then stops working on windows. Could get round this by putting the perl code in a separate file rather than using -e but maybe there is some cleverer quoting that can be done

@simon-ess
Copy link
Contributor

simon-ess commented Oct 28, 2024

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... 😄

@simon-ess
Copy link
Contributor

@FreddieAkeroyd
Copy link
Author

Well it makes it clear what we are trying to do at least, I am happy to go with that if you are - thanks

@FreddieAkeroyd
Copy link
Author

Unless you think putting the s/ command into a separate file for perl to execute from Make is cleaner

@anjohnson
Copy link
Member

Surely it would be simpler to use a stand-alone Perl script to do the whole job of generating the siteEnvVars.substitutions file? There'd be no need to mess around with the $(QUOTE) variable, and the Perl code would also be easier to read and modify. That might even fix the Base-3.14 build failure, but I haven't looked at that properly to be sure.

@FreddieAkeroyd FreddieAkeroyd marked this pull request as ready for review October 29, 2024 01:50
@simon-ess
Copy link
Contributor

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.

@@ -0,0 +1,9 @@
print("file iocEnvVar.template\n");
Copy link
Contributor

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?

@echo "{ ENVNAME, ENVVAR, ENVTYPE }" >> $@
@sed -n 's/^EPICS_\([A-Z_]*\).*/{\1, EPICS_\1, epics}/p' $< >> $@
@echo "}" >> $@
@perl ../genSiteEnvVars.pl < $< > $@
Copy link
Contributor

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.

Copy link
Member

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!).

Comment on lines 1 to 4
print("file iocEnvVar.template\n");
print("{\n");
print("pattern\n");
print("{ ENVNAME, ENVVAR, ENVTYPE }\n");
Copy link
Member

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__

Copy link
Author

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

@anjohnson
Copy link
Member

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 2f0fbbe for the equivalent changes I applied to Base-7.0.

@FreddieAkeroyd
Copy link
Author

did you want me to rebase the branch onto latest base-7.0 ?

@FreddieAkeroyd
Copy link
Author

sorry - talking rubbish - this isn't a base PR. Will make changes to iocStats CI

@simon-ess simon-ess force-pushed the fix_no_sed_on_windows branch from 01f1b69 to 8f8a475 Compare December 18, 2025 08:53
@simon-ess
Copy link
Contributor

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.

@simon-ess
Copy link
Contributor

@nariox, if you could also take a look at this please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants