Skip to content

Commit

Permalink
[build] fix env vars causing gradle build error (#705)
Browse files Browse the repository at this point in the history
Context: dotnet/android#5044 (comment)
Context: https://docs.microsoft.com/visualstudio/msbuild/exec-task

An env var can break the build such as running the following powershell:

	> $env:FOO="`nFoo.cs(123,1) error: oh dear!"

A new line in the string is required to hit an issue.  (```n`` is
PowerShell-ese for a `\n` newline.)

This results in a confusing build error:

	(_BuildJava target) ->
	    EXEC : Foo.cs(123,1) error : oh dear!

`gradlew -d` prints every environment variable, and if there is a line
that looks like an MSBuild error then `msbuild` will emit the error.
We can set `IgnoreStandardErrorWarningFormat="true"` to disable this.

This could commonly happen on CI systems, if a commit message contains
an error message.

In the case of Azure DevOps, `%BUILD_SOURCEVERSIONMESSAGE%` will
contain the full commit message.

I also fixed the `_CleanJava` target that was not running at all.
`java-source-utils.csproj` now properly cleans now.
  • Loading branch information
jonathanpeppers authored Sep 8, 2020
1 parent 75354b9 commit a98c1ae
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tools/java-source-utils/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Command=""$(GradleWPath)" -d $(GradleArgs) -PjavaSourceVer=$(JavacSourceVersion) -PjavaTargetVer=$(JavacTargetVersion) jar"
EnvironmentVariables="JAVA_HOME=$(JavaSdkDirectory);APP_HOME=$(GradleHome)"
WorkingDirectory="$(MSBuildThisFileDirectory)"
IgnoreStandardErrorWarningFormat="true"
/>
<Copy
SourceFiles="build\libs\java-source-utils.jar"
Expand Down Expand Up @@ -72,7 +73,7 @@
/>
</Target>

<Target Name="_CleanJava" DependsOnTargets="Clean">
<Target Name="_CleanJava" BeforeTargets="Clean">
<Delete Files="$(OutputPath)java-source-utils.jar" />
<Exec
Command="&quot;$(GradleWPath)&quot; clean $(GradleArgs)"
Expand Down

0 comments on commit a98c1ae

Please sign in to comment.