-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathDirectory.Build.targets
More file actions
161 lines (128 loc) · 9.42 KB
/
Copy pathDirectory.Build.targets
File metadata and controls
161 lines (128 loc) · 9.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<Project>
<PropertyGroup>
<!-- Assumes building projects in this repo (not submodules). i.e: src/Sentry.Unity -->
<UnitySampleProjectPath>$(MSBuildProjectDirectory)/../../samples/unity-of-bugs/</UnitySampleProjectPath>
<PlayerBuildPath>$(UnitySampleProjectPath)../artifacts/builds/</PlayerBuildPath>
<AndroidBuildMethod>Builder.BuildAndroidIl2CPPPlayer</AndroidBuildMethod>
<AndroidBuildPath>$(PlayerBuildPath)Android/IL2CPP_Player.apk</AndroidBuildPath>
<IOSBuildMethod>Builder.BuildIOSPlayer</IOSBuildMethod>
<IOSBuildPath>$(PlayerBuildPath)iOS/Xcode</IOSBuildPath>
<!-- Assumes running `dotnet` from the root of the repo: -->
<UnityTestPlayModeResultFilePath>../../artifacts/test/playmode/results.xml</UnityTestPlayModeResultFilePath>
<UnityTestEditModeResultFilePath>../../artifacts/test/editmode/results.xml</UnityTestEditModeResultFilePath>
</PropertyGroup>
<Import Project="$(RepoRoot)build/native-sdks.targets" />
<Import Project="$(RepoRoot)build/local-dev.targets" />
<Target Name="FindUnity">
<Message Text="Unity Version: $(UnityVersion)" Importance="Normal" />
<Exec
Command="pwsh -NoProfile -File "$(RepoRoot)scripts/find-unity.ps1" -UnityVersion "$(UnityVersion)" -HubInstallDir "$(HubInstallDir)" -HubDefaultEditor "$(HubDefaultEditor)""
ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="_FindUnityOutput" />
</Exec>
<PropertyGroup>
<UnityRoot>$([System.Text.RegularExpressions.Regex]::Match($(_FindUnityOutput), 'UnityRoot=([^;\r\n]+)').Groups[1].Value)</UnityRoot>
<UnityDataPath>$([System.Text.RegularExpressions.Regex]::Match($(_FindUnityOutput), 'UnityDataPath=([^;\r\n]+)').Groups[1].Value)</UnityDataPath>
<UnityManagedPath>$([System.Text.RegularExpressions.Regex]::Match($(_FindUnityOutput), 'UnityManagedPath=([^;\r\n]+)').Groups[1].Value)</UnityManagedPath>
<UnityLibcache>$(UnityDataPath)Resources/PackageManager/ProjectTemplates/libcache/</UnityLibcache>
</PropertyGroup>
<Error Condition="'$(UnityRoot)' == ''" Text="UnityRoot not resolved — see scripts/find-unity.ps1 output above." />
<!-- Unity paths on Windows -->
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
<UnityExec>"$(UnityRoot)\Unity.exe"</UnityExec>
<StandaloneBuildMethod>Builder.BuildWindowsIl2CPPPlayer</StandaloneBuildMethod>
<StandaloneBuildPath>$(PlayerBuildPath)Windows/IL2CPP_Player.exe</StandaloneBuildPath>
<StandaloneExecutablePath>$(StandaloneBuildPath)</StandaloneExecutablePath>
<StandaloneDataPath>$(USERPROFILE)/AppData/LocalLow/DefaultCompany/unity-of-bugs/</StandaloneDataPath>
</PropertyGroup>
<!-- Unity paths on macOS -->
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('OSX'))">
<UnityExec>"$(UnityRoot)Contents/MacOS/Unity"</UnityExec>
<StandaloneBuildMethod>Builder.BuildMacIl2CPPPlayer</StandaloneBuildMethod>
<StandaloneBuildPath>$(PlayerBuildPath)MacOS/IL2CPP_Player.app</StandaloneBuildPath>
<StandaloneExecutablePath>$(StandaloneBuildPath)/Contents/MacOS/unity-of-bugs</StandaloneExecutablePath>
</PropertyGroup>
<!-- Unity paths on Linux -->
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Linux'))">
<UnityExec>xvfb-run -ae /dev/stdout "$(UnityRoot)Unity"</UnityExec>
<StandaloneBuildMethod>Builder.BuildLinuxIl2CPPPlayer</StandaloneBuildMethod>
<StandaloneBuildPath>$(PlayerBuildPath)Linux/IL2CPP_Player</StandaloneBuildPath>
<StandaloneExecutablePath>$(StandaloneBuildPath)</StandaloneExecutablePath>
</PropertyGroup>
<LocateTestRunner UnityLibcache="$(UnityLibcache)">
<Output PropertyName="TestRunnerPath" TaskParameter="TestRunnerPath" />
</LocateTestRunner>
<PropertyGroup>
<UnityTemplateAssemblyPath>$(TestRunnerPath)</UnityTemplateAssemblyPath>
</PropertyGroup>
</Target>
<Target Name="CleanUnityTestResults" AfterTargets="Clean">
<Delete Files="$(UnityTestPlayModeResultFilePath)" />
<Delete Files="$(UnityTestEditModeResultFilePath)" />
<RemoveDir Directories="$(PlayerBuildPath)" />
</Target>
<Target Name="DownloadCLI" BeforeTargets="BeforeBuild" Condition="'$(MSBuildProjectName)' == 'Sentry.Unity' AND !Exists('$(RepoRoot)package-dev/Editor/sentry-cli')">
<Exec Command="pwsh "$(RepoRoot)scripts/download-sentry-cli.ps1""></Exec>
</Target>
<!-- Even with a successful build, Unity will error on 'usbmuxd' or log out to std-error which breaks msbuild.
We need to run a unity build to restore the test packages and for that reason we'll ignore errors here and assume a later step will validate the build is actually working:
The offending error:
[usbmuxd] Stop listen thread
[usbmuxd] Error:
[usbmuxd] Listen thread exitingit -batchmode -nographics -logFile - -projectPath $(UnitySampleProjectPath) -$(StandalonePlayerName) $(ArtifactName)
For that reason, Exec tasks to unity all ignore error. That means that subsequent tasks must exist to validate the command (i.e: parse logs, etc).
Related: https://forum.unity.com/threads/6572-debugger-agent-unable-to-listen-on-27.500387/ -->
<!-- Setup Sentry options on Unity UI: dotnet msbuild /t:UnityConfigureSentryOptions src/Sentry.Unity -->
<Target Name="UnityConfigureSentryOptions" DependsOnTargets="FindUnity" Condition="'$(MSBuildProjectName)' == 'Sentry.Unity'">
<Error Condition="$(UnityExec) == ''" Text="Couldn't find Unity." />
<Message Importance="High" Text="Configuring Sentry options."></Message>
<Exec Command="pwsh "$(RepoRoot)scripts/unity.ps1" $(UnityExec) -quit -batchmode -nographics -projectPath $(UnitySampleProjectPath) -executeMethod Sentry.Unity.Editor.ConfigurationWindow.SentryEditorWindowInstrumentation.ConfigureOptions -sentryOptions.Dsn $(TestDsn)" IgnoreStandardErrorWarningFormat="true">
<Output TaskParameter="ExitCode" PropertyName="UnityConfigureSentryOptionsExitCode"/>
</Exec>
<!-- Unity will return -1 or 0 on success. 1 Otherwise. -->
<Error Text="Sentry options setup failed with code $(UnityConfigureSentryOptionsExitCode)" Condition=" '$(UnityConfigureSentryOptionsExitCode)' != '0' AND '$(BuildExitCode)' != '-1'"/>
</Target>
<!-- Run PlayMode tests with dotnet msbuild /t:UnityPlayModeTest test/Sentry.Unity.Tests -->
<Target Name="UnityPlayModeTest" DependsOnTargets="FindUnity" Condition="'$(MSBuildProjectName)' == 'Sentry.Unity.Tests'">
<Error Condition="$(UnityExec) == ''" Text="Couldn't find Unity." />
<Message Importance="High" Text="Running Unity PlayMode tests." />
<!-- Unity exits with a non-zero exit code when running tests. We ignore it and manually check the test results instead. -->
<Delete Files="$(UnityTestPlayModeResultFilePath)" />
<Exec EnvironmentVariables="IgnoreExitCode=true" Command="pwsh "$(RepoRoot)scripts/unity.ps1" $(UnityExec) -batchmode -nographics -runTests -testPlatform PlayMode -projectPath $(UnitySampleProjectPath) -testResults $(UnityTestPlayModeResultFilePath)" />
<Exec Command="pwsh "$(RepoRoot)scripts/report-test-results.ps1" "$(UnityTestPlayModeResultFilePath)"" />
</Target>
<!-- Run EditMode tests with dotnet msbuild /t:UnityEditModeTest test/Sentry.Unity.Editor.Tests -->
<Target Name="UnityEditModeTest" DependsOnTargets="FindUnity" Condition="'$(MSBuildProjectName)' == 'Sentry.Unity.Editor.Tests'">
<Error Condition="$(UnityExec) == ''" Text="Couldn't find Unity." />
<Message Importance="High" Text="Running Unity EditMode tests." />
<!-- Unity exits with a non-zero exit code when running tests. We ignore it and manually check the test results instead. -->
<!-- IgnoreStandardErrorWarningFormat="true" because of the intentional compilation error printed in GenerateOptions_NewSentryOptionsGarbageAppended_FailsToCompile(). -->
<Delete Files="$(UnityTestEditModeResultFilePath)" />
<Exec EnvironmentVariables="IgnoreExitCode=true" IgnoreStandardErrorWarningFormat="true" Command="pwsh "$(RepoRoot)scripts/unity.ps1" $(UnityExec) -batchmode -nographics -runTests -testPlatform EditMode -projectPath $(UnitySampleProjectPath) -testResults $(UnityTestEditModeResultFilePath)"/>
<Exec Command="pwsh "$(RepoRoot)scripts/report-test-results.ps1" "$(UnityTestEditModeResultFilePath)"" />
</Target>
<!-- Locate the TestRunner.dlls by filling the wildcard with the template version number. 3d is the default template -->
<!-- Unity 6 introduced an additional 3d template: template.3d-high-end & template.3d-cross-platform -->
<UsingTask TaskName="LocateTestRunner" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<UnityLibcache ParameterType="System.String" Required="true" />
<TestRunnerPath ParameterType="System.String" Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.IO" />
<Using Namespace="System.Linq" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var directories = Directory.GetDirectories(UnityLibcache, "com.unity.template.3d-*");
if (directories.Length >= 1)
{
TestRunnerPath = Path.Combine(directories[0], "ScriptAssemblies");
Log.LogMessage("Found TestRunner path at: " + TestRunnerPath);
return true;
}
Log.LogError("Failed to resolve 'com.unity.template.3d-*' for TestRunner at: " + UnityLibcache);
]]>
</Code>
</Task>
</UsingTask>
</Project>