Improve error for missing Python (#81202)
authorDan Moseley <danmose@microsoft.com>
Fri, 27 Jan 2023 00:44:46 +0000 (17:44 -0700)
committerGitHub <noreply@github.com>
Fri, 27 Jan 2023 00:44:46 +0000 (17:44 -0700)
* add error

* Fix a case were missing VC components didn't error

* handle non empty stdout

* Remove self assignment

eng/native/init-vs-env.cmd
eng/python.targets
src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj

index 403f355eca4811744858114f606dd89dbd7ba0c8..68242ed725f67e40e8e6afbd7fb98808e0b590ba 100644 (file)
@@ -61,6 +61,7 @@ exit /b 1
 if "%__VCBuildArch%"=="" exit /b 0
 
 :: Set the environment for the native build
+if not exist "%VCINSTALLDIR%Auxiliary\Build\vcvarsall.bat" goto :VSMissing
 call "%VCINSTALLDIR%Auxiliary\Build\vcvarsall.bat" %__VCBuildArch%
 if not "%ErrorLevel%"=="0" exit /b 1
 
index 0158d38270d6378db9cdc86d52f39d3b1ca798a3..3f933fdfea0eb1d42059cad70415061f89454a6f 100644 (file)
@@ -1,5 +1,5 @@
 <Project>
-  <Target Name="FindPythonWindows"
+  <Target Name="_FindPythonWindows"
           Condition="$([MSBuild]::IsOSPlatform(Windows)) and '$(PYTHON)' == ''"
           Returns="$(PYTHON)">
     <PropertyGroup>
@@ -8,25 +8,24 @@
     <Exec Command="py -3 $(_PythonLocationScript) 2&gt; nul || python3 $(_PythonLocationScript) 2&gt; nul || python $(_PythonLocationScript) 2&gt; nul"
           StandardOutputImportance="Low"
           EchoOff="true"
+          ContinueOnError="ErrorAndContinue"
           ConsoleToMsBuild="true">
       <Output TaskParameter="ConsoleOutput" PropertyName="PYTHON" />
     </Exec>
-    <PropertyGroup>
-      <PYTHON>"$(PYTHON)"</PYTHON>
-    </PropertyGroup>
   </Target>
-  <Target Name="FindPythonUnix"
+  <Target Name="_FindPythonUnix"
           Condition="!$([MSBuild]::IsOSPlatform(Windows)) and '$(PYTHON)' == ''"
           Returns="$(PYTHON)">
     <Exec Command="command -v python3 || command -v python || command -v py"
           StandardOutputImportance="Low"
           EchoOff="true"
+          ContinueOnError="ErrorAndContinue"
           ConsoleToMsBuild="true">
       <Output TaskParameter="ConsoleOutput" PropertyName="PYTHON" />
     </Exec>
-    <PropertyGroup>
-      <PYTHON>"$(PYTHON)"</PYTHON>
-    </PropertyGroup>
   </Target>
-  <Target Name="FindPython" DependsOnTargets="FindPythonWindows;FindPythonUnix" />
+  <Target Name="FindPython" DependsOnTargets="_FindPythonWindows;_FindPythonUnix">
+      <Error Condition="'$(PYTHON)' == ''"
+             Text="Python not found. Please add Python 3 to your path and try again."/>
+  </Target>
 </Project>
index 1dd98e1293225f37ef826f297ae4483a2dc3a485..c86b9e4c3332a13f3e9c6c3ced6390dd4f58aaad 100644 (file)
 
     </PropertyGroup>
 
-    <Exec Command="$(PYTHON) -B $(_PythonWarningParameter) &quot;@(EventingGenerationScript)&quot; --man &quot;@(EventManifestFile)&quot; --intermediate &quot;$(_EventingSourceFileDirectory)&quot;" />
+    <Exec Command="&quot;$(PYTHON)&quot; -B $(_PythonWarningParameter) &quot;@(EventingGenerationScript)&quot; --man &quot;@(EventManifestFile)&quot; --intermediate &quot;$(_EventingSourceFileDirectory)&quot;" />
 
     <ItemGroup>
       <FileWrites Include="@(EventingSourceFile)" />
index 50d60902a91bf774e80b0593b4b01772a0afe5e8..2cf93a7083968ab283187fb380e4366d9b4574ec 100644 (file)
       <_EventingSourceFileDirectory Condition="HasTrailingSlash('$(_EventingSourceFileDirectory)')">$(_EventingSourceFileDirectory.TrimEnd('\'))</_EventingSourceFileDirectory>
     </PropertyGroup>
 
-    <Exec Command="$(PYTHON) -B $(_PythonWarningParameter) &quot;@(EventingGenerationScript)&quot; --man &quot;@(EventManifestFile)&quot; --intermediate &quot;$(_EventingSourceFileDirectory)&quot; --runtimeflavor mono" />
+    <Exec Command="&quot;$(PYTHON)&quot; -B $(_PythonWarningParameter) &quot;@(EventingGenerationScript)&quot; --man &quot;@(EventManifestFile)&quot; --intermediate &quot;$(_EventingSourceFileDirectory)&quot; --runtimeflavor mono" />
 
     <ItemGroup>
       <FileWrites Include="@(EventingSourceFile)" />