Skip to content

Commit 43e5a72

Browse files
jviauYunchuWanghallvictoriagavin-aguiar
authored
refactor: Remove custom targets, use 'None' item group (#1472)
* Remove custom targets, use 'None' item group * Add runtime specific copy logic * Add underscore to target name --------- Co-authored-by: wangbill <[email protected]> Co-authored-by: hallvictoria <[email protected]> Co-authored-by: Gavin Aguiar <[email protected]>
1 parent bbb6624 commit 43e5a72

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
11
<Project>
2-
<Target Name="Initialize" AfterTargets="Publish;Build">
3-
<CreateItem Include="$(MSBuildThisFileDirectory)\..\">
4-
<Output ItemName="MSBuildThisFileDirectoryParentDirectory" TaskParameter="Include"/>
5-
</CreateItem>
62

7-
<CreateProperty Value="%(MSBuildThisFileDirectoryParentDirectory.Fullpath)">
8-
<Output PropertyName="NugetRoot" TaskParameter="Value"/>
9-
</CreateProperty>
3+
<PropertyGroup>
4+
<_PythonWorkerToolsDir>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)../tools'))</_PythonWorkerToolsDir>
5+
</PropertyGroup>
106

7+
<ItemGroup Condition="'$(RuntimeIdentifier)' != ''">
8+
<_PythonSupportedRuntime Include="win-x86" WorkerPath="WINDOWS/X86" />
9+
<_PythonSupportedRuntime Include="win-x64" WorkerPath="WINDOWS/X64" />
10+
<_PythonSupportedRuntime Include="linux-x64" WorkerPath="LINUX/X64" />
11+
<_PythonSupportedRuntime Include="osx-x64" WorkerPath="OSX/X64" />
12+
<_PythonSupportedRuntime Include="osx-arm64" WorkerPath="OSX/Arm64" />
13+
</ItemGroup>
14+
15+
<Target Name="_GetFunctionsPythonWorkerFiles" BeforeTargets="AssignTargetPaths" DependsOnTargets="_GetFunctionsPythonWorkerFilesNoRuntime;_GetFunctionsPythonWorkerFilesForRuntime">
1116
<ItemGroup>
12-
<SourceFiles Include="$(NugetRoot)tools\**\*.*"/>
17+
<None Include="@(_PythonWorkerFiles)" TargetPath="workers/python/%(RecursiveDir)%(Filename)%(Extension)" />
1318
</ItemGroup>
1419
</Target>
1520

16-
<Target Name="CopyOnPublish" DependsOnTargets="Initialize" AfterTargets="Publish">
17-
<Copy SourceFiles="@(SourceFiles)"
18-
DestinationFiles="@(SourceFiles->'$(PublishDir)\workers\python\%(RecursiveDir)%(Filename)%(Extension)')" />
21+
<!-- When no runtime is specified, copy all runtimes. -->
22+
<Target Name="_GetFunctionsPythonWorkerFilesNoRuntime" Condition="'$(RuntimeIdentifier)' == ''">
23+
<ItemGroup>
24+
<_PythonWorkerFiles Include="$(_PythonWorkerToolsDir)/**" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
25+
</ItemGroup>
1926
</Target>
2027

21-
<Target Name="CopyOnBuild" DependsOnTargets="Initialize" AfterTargets="Build">
22-
<Copy SourceFiles="@(SourceFiles)"
23-
DestinationFiles="@(SourceFiles->'$(OutDir)\workers\python\%(RecursiveDir)%(Filename)%(Extension)')" />
28+
<!-- When a runtime is specified, copy only that runtimes files. -->
29+
<Target Name="_GetFunctionsPythonWorkerFilesForRuntime" Condition="'$(RuntimeIdentifier)' != ''">
30+
<PropertyGroup>
31+
<_PythonWorkersRuntimeFolder>@(_PythonSupportedRuntime->WithMetadataValue('Identity', '$(RuntimeIdentifier)')->Metadata('WorkerPath'))</_PythonWorkersRuntimeFolder>
32+
</PropertyGroup>
33+
34+
<ItemGroup>
35+
<_PythonWorkerFiles Include="$(_PythonWorkerToolsDir)/*" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
36+
<_PythonWorkerFiles Include="$(_PythonWorkerToolsDir)/**/$(_PythonWorkersRuntimeFolder)/**" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
37+
</ItemGroup>
38+
39+
<!-- Error out if runtime is not supported. -->
40+
<Error Condition="'$(_PythonWorkersRuntimeFolder)' == ''" Text="Runtime '$(RuntimeIdentifier)' is not supported by the Python worker. Supported runtimes are @(_PythonSupportedRuntime)." />
2441
</Target>
42+
2543
</Project>

0 commit comments

Comments
 (0)