NppExec compilation of AutoIt files, with includes...
-
@PeterJones Thank you for your very constructive solution !
I will integrate it right now. -
@PeterJones I just wonder if the variable PROJECTMAINFILE defined in the makefile.nppexec script would be visible in the common NppExec script ? Infact I wonder if the makefile could only contain this variable declaration and put the rest back in the main NppExec script ? I suppose it does not work like an “include”. Or maybe Environement variables are “remanent” ?
-
@Dave-Binbin said in NppExec compilation of AutoIt files, with includes...:
Is there a way that the NppExec script would work from any file of my project ?
You could set a NppExec global variable to the project root directory and then at the beginning of your compile script, just CD to that directory. I do something very similar - I have a “project” NppExec script which sets a project directory as an NppExec global variable and then all of my other scripts can see / use that directory (e.g., CD to it) to do stuff. So I can set my project directory to the one with the
Makefile
and then press my compile shortcut hotkey for my NppExec compile script from the header file in a different directory and it will compile the whole project.Cheers.
-
@Michael-Vincent I do not understand how you implement this… By global NppExec variable, do you mean env_set variable ? Could you post a example ?
-
@Dave-Binbin said in NppExec compilation of AutoIt files, with includes...:
By global NppExec variable, do you mean env_set variable ? Could you post a example ?
Exactly:
ENV_SET PROJECT_DIR=C:\my\proj\dir
This way, if I spawn a shell (i.e., launch Command Prompt from NppExec) - that environment variable is present there as well.
Cheers.
-
@Michael-Vincent as I will not define a “makefile” in every project, I would like to compile by default the current NPP file $(FULL_CURRENT_PATH). So I wonder how I could test if the env variable exists or not ?
if "$(SYS.PROJECTMAINFILE)" != "" then
crashes if the env var is not defined…
-
In your main script, start with
ENV_SET PROJECTMAINFILE="$(FULL_CURRENT_PATH)"
then call the makefile – if the makefile defines that same variable, the value will be updated to whatever’s in the makefile, otherwise it will use the initial value from the main script.
(There might even be a way in NppExec to say “if file makefile.nppexec exists then npp_exec that file”, but I don’t know how to do file-exist tests in NppExec. @Michael-Vincent might.)
-
@Dave-Binbin said in NppExec compilation of AutoIt files, with includes...:
By global NppExec variable
local vs global vs environment
set local myvar=value
– only seen in the active scriptset myglobal=value
– seen in the active script and in subsequent scripts or the Consoleenv_set myenv=value
– seen in the active script, subsequent scripts, and the console as $(SYS.MYENV); seen in any subshells (like cmd.exe or powershell called from NppExec) as a normal environment variable, using appropriate shell syntax
-
@PeterJones said in NppExec compilation of AutoIt files, with includes...:
ENV_SET PROJECTMAINFILE=“$(FULL_CURRENT_PATH)”
great, thanks !!!
do you know how I can test the file extension “.au3” of this file like I did in the original script,
in case there is no makefile and I point on a non-au3 file…if $(EXT_PART) != .au3 goto BADFILE
-
do you know how I can test the file extension “.au3” of this file like I did in the original script,
By doing it like you did in the original script, or like I showed in my original “main NppExec script”.
main script
npp_saveall ENV_SET PROJECTMAINFILE=$(FULL_CURRENT_PATH) echo Starting from : $(FILE_NAME) cd "$(CURRENT_DIRECTORY)" if $(EXT_PART) != .au3 goto BADFILE npp_exec makefile.nppexec // this runs the "makefile" for the current project "C:\Program Files (x86)\AutoIt3\Au3check.exe" "$(SYS.PROJECTMAINFILE)" if $(EXITCODE) >= 2 goto EXITSCRIPT "C:\Program Files (x86)\AutoIt3\AutoIt3.exe" /ErrorStdOut "$(SYS.PROJECTMAINFILE)" goto EXITSCRIPT :BADFILE echo "Not an autoit file !!!" :EXITSCRIPT
makefile.nppexec
ENV_SET PROJECTMAINFILE=MyNameHere.au3
—
EDIT: removed the quotes from the env_set, which puts quotes in the string -
@PeterJones said in NppExec compilation of AutoIt files, with includes...:
EXT_PART
but in case the makefile exists, EXT_PART will not test the updated PROJECTMAINFILE but still the file from which I run the script, no ?
-
@Dave-Binbin said in NppExec compilation of AutoIt files, with includes...:
but in case the makefile exists, EXT_PART will not test the updated PROJECTMAINFILE but still the file from which I run the script, no ?
Correct, $(EXT_PART) is always the extension portion of the active file in Notepad++, and it is not affected by the makefile at all.
So I may have misunderstood your original follow-on request. I think the best advice is “don’t set PROJECTMAINFILE to a non-.au3 file”.
Using the substring notation (see
help set
or Plugins > NppExec > Docs…) for variable setting, you might be able to extract the last three characters from $(SYS.PROJECTMAINFILE) into a separate variable, and use that for testing whether or not to skip. But that would take some research and experimenting; I think you should be able to read those documents as well as I can. -
I got curious, and had a couple spare minutes, so I did the experiment.
set local e ~ substr -4 4 $(SYS.PROJECTMAINFILE) if $(e) != .au3 goto BADFILE
so if you put that immediately after the
npp_exec makefile.nppexec
and before the Au3check.exe call, it will do a test for the PROJECTMAINFILE extension as well.