-
Notifications
You must be signed in to change notification settings - Fork 107
/
Build.csproj
360 lines (286 loc) · 16 KB
/
Build.csproj
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix Condition="'$(VersionPrefix)' == ''">2.0.0</VersionPrefix>
<ReleaseNumber Condition="'$(VersionSuffix)' == ''">$(VersionPrefix)</ReleaseNumber>
<ReleaseNumber Condition="'$(VersionSuffix)' != ''">$(VersionPrefix)-$(VersionSuffix)</ReleaseNumber>
<BuildNumber Condition="'$(BUILD_NUMBER)' != ''">$(BUILD_NUMBER)</BuildNumber>
<BuildNumber Condition="'$(BUILD_NUMBER)' == ''">0</BuildNumber>
<ArtifactsRoot>$(MSBuildProjectDirectory)/built</ArtifactsRoot>
<LibDir>$(ArtifactsRoot)/lib</LibDir>
<DebugAdapterDir>$(ArtifactsRoot)\vscode\</DebugAdapterDir>
<Configuration>Release</Configuration>
<Solution>$(MSBuildProjectDirectory)/src/1Script.sln</Solution>
</PropertyGroup>
<ItemGroup>
<PlatformItem Include="x86">
<MSBuildName>x86</MSBuildName>
<MSBuildNameCpp>Win32</MSBuildNameCpp>
</PlatformItem>
<PlatformItem Include="x64">
<MSBuildName>"Any CPU"</MSBuildName>
<MSBuildNameCpp>x64</MSBuildNameCpp>
</PlatformItem>
</ItemGroup>
<ItemGroup>
<PublishProjects Include="oscript">
<ProjectFile>oscript.csproj</ProjectFile>
<Framework>net6.0</Framework>
</PublishProjects>
<PublishProjects Include="TestApp">
<ProjectFile>TestApp.csproj</ProjectFile>
<Framework>net6.0-windows</Framework>
</PublishProjects>
</ItemGroup>
<Target Name="CleanAll">
<ItemGroup>
<TestsResults Include="$(MSBuildProjectDirectory)/tests/*.os.xml" />
</ItemGroup>
<Delete Files="@(TestsResults)" />
<RemoveDir Directories="$(ArtifactsRoot)" Condition="Exists($(ArtifactsRoot))" />
<MSBuild Projects="$(Solution)" Targets="Clean"/>
</Target>
<Target Name="MakeCPP">
<MSBuild Projects="src\ScriptEngine.NativeApi\ScriptEngine.NativeApi.vcxproj"
Properties="Configuration=$(Configuration);Platform=%(PlatformItem.MSBuildNameCpp)"/>
<MSBuild Projects="tests\native-api\AddInNative.vcxproj"
Properties="Configuration=$(Configuration);Platform=%(PlatformItem.MSBuildNameCpp)"/>
</Target>
<Target Name="MakeFDD">
<CreateItem
Include="@(PublishProjects)"
AdditionalMetadata="Platform=%(PlatformItem.MSBuildName);Suffix=%(PlatformItem.Identity)">
<Output
TaskParameter="Include"
ItemName="BuildVariant"/>
</CreateItem>
<Exec Command="dotnet publish "src/%(BuildVariant.Identity)/%(BuildVariant.ProjectFile)" -f %(BuildVariant.Framework) -c $(Configuration) -p:Platform=%(BuildVariant.Platform) -p:UseAppHost=false -o "$(ArtifactsRoot)/fdd-%(BuildVariant.Suffix)/bin"" UseUtf8Encoding="Always"/>
<PropertyGroup>
<CppBinPrefix>$(MSBuildProjectDirectory)/src/ScriptEngine.NativeApi/bin/$(Configuration)</CppBinPrefix>
</PropertyGroup>
<ItemGroup>
<CppX86 Include="$(CppBinPrefix)/x86/*.dll"/>
<CppX64 Include="$(CppBinPrefix)/x64/*.dll"/>
</ItemGroup>
<Copy SourceFiles="@(CppX86)" DestinationFolder="$(ArtifactsRoot)/fdd-x86/bin" />
<Copy SourceFiles="@(CppX64)" DestinationFolder="$(ArtifactsRoot)/fdd-x64/bin" />
<ItemGroup>
<BatFilesFDD Include="$(MSBuildProjectDirectory)\install\opm.bat"/>
<BatFilesFDD Include="$(MSBuildProjectDirectory)\install\oscript.bat"/>
<ShFilesFDD Include="$(MSBuildProjectDirectory)\install\opm"/>
<ShFilesFDD Include="$(MSBuildProjectDirectory)\install\oscript"/>
</ItemGroup>
<Copy SourceFiles="@(BatFilesFDD);@(ShFilesFDD)" DestinationFolder="$(ArtifactsRoot)/fdd-x86/bin"/>
<Copy SourceFiles="@(BatFilesFDD);@(ShFilesFDD)" DestinationFolder="$(ArtifactsRoot)/fdd-x64/bin"/>
</Target>
<Target Name="MakeSCD">
<ItemGroup>
<RuntimeID Include="win-x64"/>
<RuntimeID Include="win-x86"/>
<RuntimeID Include="linux-x64"/>
<RuntimeID Include="osx-x64"/>
<RuntimeID Include="osx-arm64"/>
</ItemGroup>
<Exec Command="dotnet publish "src/oscript/oscript.csproj" -r %(RuntimeID.Identity) --self-contained -c $(Configuration) -o "$(ArtifactsRoot)/%(RuntimeID.Identity)/bin"" UseUtf8Encoding="Always"/>
<PropertyGroup>
<CppBinPrefix>$(MSBuildProjectDirectory)/src/ScriptEngine.NativeApi/bin/$(Configuration)</CppBinPrefix>
</PropertyGroup>
<ItemGroup>
<CppX86 Include="$(CppBinPrefix)/x86/*.dll"/>
<CppX64 Include="$(CppBinPrefix)/x64/*.dll"/>
</ItemGroup>
<Copy SourceFiles="@(CppX86)" DestinationFolder="$(ArtifactsRoot)/win-x86/bin" />
<Copy SourceFiles="@(CppX64)" DestinationFolder="$(ArtifactsRoot)/win-x64/bin" />
<ItemGroup>
<BatFilesSCD Include="$(MSBuildProjectDirectory)\install\opm.bat"/>
<ShFilesSCD Include="$(MSBuildProjectDirectory)\install\opm"/>
</ItemGroup>
<Copy SourceFiles="@(BatFilesSCD)" DestinationFolder="$(ArtifactsRoot)/win-x86/bin"/>
<Copy SourceFiles="@(BatFilesSCD)" DestinationFolder="$(ArtifactsRoot)/win-x64/bin"/>
<Copy SourceFiles="@(ShFilesSCD)" DestinationFolder="$(ArtifactsRoot)/linux-x64/bin"/>
</Target>
<Target Name="BuildDebugger">
<PropertyGroup>
<DebuggerProject>src/VSCode.DebugAdapter/VSCode.DebugAdapter.csproj</DebuggerProject>
<LocalResolvedOutput>$(DebugAdapterDir)</LocalResolvedOutput>
</PropertyGroup>
<MSBuild Projects="$(DebuggerProject)" Properties="OutputPath=$(LocalResolvedOutput);Configuration=Release"/>
</Target>
<Target Name="BuildAll">
<CallTarget Targets="BuildWithCpp" Condition="'$(NoCppCompiler)' == ''"/>
<CallTarget Targets="BuildWithoutCpp" Condition="'$(NoCppCompiler)' == 'True'"/>
</Target>
<Target Name="BuildWithCpp" DependsOnTargets="CleanAll;MakeCPP;MakeFDD;MakeSCD;BuildDebugger">
<CallTarget Targets="CleanIntermediates"/>
</Target>
<Target Name="BuildWithoutCpp" DependsOnTargets="CleanAll;MakeFDD;MakeSCD;BuildDebugger">
<CallTarget Targets="CleanIntermediates"/>
</Target>
<!-- Используется для поиска первого собранного oscript.exe -->
<UsingTask
TaskName="GetFirstItem"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<Items ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
<FirstItem ParameterType="System.String" Output="true" Required="false" />
</ParameterGroup>
<Task>
<Reference Include="System.Xml"/>
<Using Namespace="System.Linq"/>
<Code Type="Fragment" Language="cs">FirstItem = Items.First().ItemSpec;</Code>
</Task>
</UsingTask>
<Target Name="GatherLibrary">
<MakeDir Directories="$(LibDir)" />
<ItemGroup>
<Executable Include="$(ArtifactsRoot)/*x64/bin/oscript.dll"/>
</ItemGroup>
<!-- упадет если ничего не нашлось, и это хорошо -->
<GetFirstItem Items="@(Executable)">
<Output TaskParameter="FirstItem" PropertyName="Runner"/>
</GetFirstItem>
<Exec Command="dotnet "$(Runner)" "$(MSBuildProjectDirectory)/install/unicode-zipper.os" unpack "$(MSBuildProjectDirectory)/install/opm.ospx" "$(LibDir)/tmp"" UseUtf8Encoding="Always"/>
<Exec Command="dotnet "$(Runner)" "$(MSBuildProjectDirectory)/install/unicode-zipper.os" unpack "$(LibDir)/tmp/content.zip" "$(LibDir)/opm"" UseUtf8Encoding="Always"/>
<Copy SourceFiles="$(MSBuildProjectDirectory)\install\package-loader.os" DestinationFolder="$(LibDir)"/>
<RemoveDir Directories="$(LibDir)/tmp"/>
<PropertyGroup>
<OpmEntryPoint>opm\src\cmd\opm.os</OpmEntryPoint>
<OpmLaunch>dotnet $(Runner) "$(LibDir)\$(OpmEntryPoint)"</OpmLaunch>
</PropertyGroup>
<ItemGroup>
<CoreLibraries Include="asserts"/>
<CoreLibraries Include="logos"/>
<CoreLibraries Include="fs"/>
<CoreLibraries Include="tempfiles"/>
<CoreLibraries Include="cli"/>
<ConfigEnv Include="OSCRIPT_CONFIG=lib.system=$(LibDir)"/>
</ItemGroup>
<Exec Command="$(OpmLaunch) install -d "$(LibDir)" %(CoreLibraries.Identity)"
IgnoreExitCode="false"
EnvironmentVariables="@(ConfigEnv)"
Condition="'$(SkipLibraryDownload)' == ''"
UseUtf8Encoding="Always"/>
</Target>
<Target Name="ComposeDistributionFolders">
<ItemGroup>
<LibraryFiles Include="$(LibDir)/**/*" Exclude="package-loader.os"/>
</ItemGroup>
<!--Заставить Copy копировать batching-ом в несколько директорий - не удалось :(-->
<Copy SourceFiles="@(LibraryFiles)" DestinationFolder="$(ArtifactsRoot)/fdd-x64/lib/%(RecursiveDir)" />
<Copy SourceFiles="@(LibraryFiles)" DestinationFolder="$(ArtifactsRoot)/fdd-x86/lib/%(RecursiveDir)" />
<Copy SourceFiles="@(LibraryFiles)" DestinationFolder="$(ArtifactsRoot)/win-x64/lib/%(RecursiveDir)" />
<Copy SourceFiles="@(LibraryFiles)" DestinationFolder="$(ArtifactsRoot)/win-x86/lib/%(RecursiveDir)" />
<Copy SourceFiles="@(LibraryFiles)" DestinationFolder="$(ArtifactsRoot)/osx-x64/lib/%(RecursiveDir)" />
<Copy SourceFiles="@(LibraryFiles)" DestinationFolder="$(ArtifactsRoot)/osx-arm64/lib/%(RecursiveDir)" />
<Copy SourceFiles="@(LibraryFiles)" DestinationFolder="$(ArtifactsRoot)/linux-x64/lib/%(RecursiveDir)" />
<RemoveDir Directories="$(LibDir)" />
</Target>
<Target Name="CleanIntermediates">
<ItemGroup>
<TempFiles Include="$(ArtifactsRoot)/**/bin/*.pdb"/>
<TempFiles Include="$(ArtifactsRoot)/**/bin/*.xml"/>
<TempFiles Include="$(DebugAdapterDir)/**/*.pdb"/>
</ItemGroup>
<Delete Files="@(TempFiles)"/>
</Target>
<Target Name="PrepareDistributionFiles" DependsOnTargets="CleanAll;BuildAll;GatherLibrary;ComposeDistributionFolders"/>
<Target Name="Test">
<CallTarget Targets="UnitTests;ScriptedTests" />
</Target>
<Target Name="UnitTests">
<PropertyGroup>
<TestsRoot>$(MSBuildProjectDirectory)/src/Tests</TestsRoot>
</PropertyGroup>
<ItemGroup>
<TestAssemblies Include="OneScript.Core.Tests" />
<TestAssemblies Include="OneScript.DebugProtocol.Test" />
<TestAssemblies Include="OneScript.Dynamic.Tests" />
<TestAssemblies Include="OneScript.Language.Tests" />
</ItemGroup>
<Exec
WorkingDirectory="$(TestsRoot)/%(TestAssemblies.Identity)"
Command="dotnet test --logger:"junit;LogFilePath=$(MSBuildProjectDirectory)/tests/%(TestAssemblies.Identity).xml""
IgnoreExitCode="true"
UseUtf8Encoding="Always"
/>
</Target>
<Target Name="ScriptedTests">
<ItemGroup>
<Executable Include="$(ArtifactsRoot)/*x64/bin/oscript.dll" />
<RemoveXMLTestResult Include="$(MSBuildProjectDirectory)\tests\*.os.xml" />
</ItemGroup>
<Delete Files="@(RemoveXMLTestResult)" />
<GetFirstItem Items="@(Executable)">
<Output TaskParameter="FirstItem" PropertyName="Runner"/>
</GetFirstItem>
<Exec
WorkingDirectory="$(MSBuildProjectDirectory)\tests"
Command="dotnet "$(Runner)" "$(MSBuildProjectDirectory)\tests\testrunner.os" -runall . xddReportPath ."
IgnoreExitCode="true"
ContinueOnError="true"
UseUtf8Encoding="Always">
<Output TaskParameter="ExitCode" PropertyName="TestsExitCode"/>
</Exec>
</Target>
<Target Name="PackDistributions">
<ItemGroup>
<Executable Include="$(ArtifactsRoot)/*x64/bin/oscript.dll" />
<RuntimeID Include="fdd-x64"/>
<RuntimeID Include="fdd-x86"/>
<RuntimeID Include="win-x64"/>
<RuntimeID Include="win-x86"/>
<RuntimeID Include="osx-x64"/>
<RuntimeID Include="osx-arm64"/>
<RuntimeID Include="linux-x64"/>
<VsixSources Include="$(DebugAdapterDir)/**" Exclude="*.vsix" />
</ItemGroup>
<CreateItem
Include="@(RuntimeID)"
AdditionalMetadata="Path=$(ArtifactsRoot)/%(RuntimeID.Identity)">
<Output
TaskParameter="Include"
ItemName="BuildVariant"/>
</CreateItem>
<!-- упадет если ничего не нашлось, и это хорошо -->
<GetFirstItem Items="@(Executable)">
<Output TaskParameter="FirstItem" PropertyName="Runner"/>
</GetFirstItem>
<Exec Command="dotnet "$(Runner)" "$(MSBuildProjectDirectory)\install\unicode-zipper.os" pack "$(ArtifactsRoot)/%(RuntimeID.Identity)/*" "$(ArtifactsRoot)/OneScript-$(ReleaseNumber)-%(RuntimeID.Identity).zip"" UseUtf8Encoding="Always"/>
<RemoveDir Directories="$(ArtifactsRoot)/%(RuntimeID.Identity)" />
<Delete Files="@(VsixSources)" />
</Target>
<!-- Nuget -->
<Target Name="CreateNuget">
<ItemGroup>
<NugetAbleProject Include="ScriptEngine"/>
<NugetAbleProject Include="ScriptEngine.HostedScript"/>
<NugetAbleProject Include="OneScript.StandardLibrary"/>
<NugetAbleProject Include="OneScript.Web.Server"/>
<NugetAbleProject Include="OneScript.Core"/>
<NugetAbleProject Include="OneScript.Native"/>
<NugetAbleProject Include="OneScript.Language"/>
<NugetAbleProject Include="OneScript.DebugServices"/>
<NugetAbleProject Include="OneScript.DebugProtocol"/>
</ItemGroup>
<PropertyGroup>
<SuffixArg Condition="'$(VersionSuffix)' != ''">--version-suffix $(VersionSuffix)</SuffixArg>
</PropertyGroup>
<Exec Command="dotnet pack src/%(NugetAbleProject.Identity)/%(NugetAbleProject.Identity).csproj -o "$(ArtifactsRoot)/nuget" $(SuffixArg) -c Release -p:VersionPrefix=$(VersionPrefix)"/>
</Target>
<Target Name="PublishNuget" DependsOnTargets="CreateNuget">
<ItemGroup>
<NugetAbleProject Include="ScriptEngine"/>
<NugetAbleProject Include="ScriptEngine.HostedScript"/>
<NugetAbleProject Include="OneScript.StandardLibrary"/>
<NugetAbleProject Include="OneScript.Web.Server"/>
<NugetAbleProject Include="OneScript.Core"/>
<NugetAbleProject Include="OneScript.Native"/>
<NugetAbleProject Include="OneScript.Language"/>
<NugetAbleProject Include="OneScript.DebugServices"/>
<NugetAbleProject Include="OneScript.DebugProtocol"/>
</ItemGroup>
<Error Text="No nuget token (/p:NugetToken=) specified" Condition="'$(NugetToken)' == ''" />
<Exec WorkingDirectory="$(MSBuildProjectDirectory)\built\nuget"
Command="dotnet nuget push %(NugetAbleProject.Identity).$(ReleaseNumber).nupkg -k $(NugetToken) -s https://api.nuget.org/v3/index.json" UseUtf8Encoding="Always"/>
</Target>
</Project>