Use cmd.exe to export env vars before commands
authorTanzinul Islam <tanzinul.islam@gmail.com>
Thu, 26 Nov 2020 15:38:40 +0000 (15:38 +0000)
committerDmitry Belyavskiy <beldmit@gmail.com>
Mon, 19 Apr 2021 09:05:54 +0000 (11:05 +0200)
Microsoft NMake runs the entire command block in a single `cmd.exe`
session, so environment variables exported with `set` are seen by the
following commands. C++Builder's `make.exe` doesn't use `cmd.exe` but
executes each command line separately. While it emulates only certain
shell features itself, `set` isn't one of them.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/13540)

Configurations/windows-makefile.tmpl

index d9cc0e53e32fcf091f87b457f8313775b8fd4b5f..3160984ccc0e89d349091d738bc2b3637d03831a 100644 (file)
@@ -415,19 +415,14 @@ all: build_sw build_docs
 test: tests
 {- dependmagic('tests'); -}: build_programs_nodep build_modules_nodep copy-utils
        @{- output_off() if $disabled{tests}; "" -}
-       set SRCTOP=$(SRCDIR)
-       set BLDTOP=$(BLDDIR)
-       set PERL=$(PERL)
-       set FIPSKEY=$(FIPSKEY)
-       "$(PERL)" "$(SRCDIR)\test\run_tests.pl" $(TESTS)
+       cmd /C "set "SRCTOP=$(SRCDIR)" & set "BLDTOP=$(BLDDIR)" & set "PERL=$(PERL)" & set "FIPSKEY=$(FIPSKEY)" & "$(PERL)" "$(SRCDIR)\test\run_tests.pl" $(TESTS)"
        @{- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
        @$(ECHO) "Tests are not supported with your chosen Configure options"
        @{- output_on() if !$disabled{tests}; "" -}
 
 list-tests:
        @{- output_off() if $disabled{tests}; "" -}
-       @set SRCTOP=$(SRCDIR)
-       @"$(PERL)" "$(SRCDIR)\test\run_tests.pl" list
+       @cmd /C "set "SRCTOP=$(SRCDIR)" & "$(PERL)" "$(SRCDIR)\test\run_tests.pl" list"
        @{- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
        @$(ECHO) "Tests are not supported with your chosen Configure options"
        @{- output_on() if !$disabled{tests}; "" -}
@@ -711,8 +706,7 @@ EOF
               if ($args{src} =~ /\.S$/) {
                    return <<"EOF";
 $target: "$gen0" $deps
-       set ASM=\$(AS)
-       $generator \$@.S
+       cmd /C "set "ASM=\$(AS)" & $generator \$@.S"
        \$(CPP) $incs $cppflags $defs \$@.S > \$@.i
        move /Y \$@.i \$@
         del /Q \$@.S
@@ -721,8 +715,7 @@ EOF
               # Otherwise....
               return <<"EOF";
 $target: "$gen0" $deps
-       set ASM=\$(AS)
-       $generator \$@
+       cmd /C "set "ASM=\$(AS)" & $generator \$@"
 EOF
           }
           return <<"EOF";