Skip to content

Commit

Permalink
refactor: Remove custom targets, use 'None' item group (#1472)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
4 people authored Dec 11, 2024
1 parent bbb6624 commit 43e5a72
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions pack/Microsoft.Azure.Functions.PythonWorker.targets
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
<Project>
<Target Name="Initialize" AfterTargets="Publish;Build">
<CreateItem Include="$(MSBuildThisFileDirectory)\..\">
<Output ItemName="MSBuildThisFileDirectoryParentDirectory" TaskParameter="Include"/>
</CreateItem>

<CreateProperty Value="%(MSBuildThisFileDirectoryParentDirectory.Fullpath)">
<Output PropertyName="NugetRoot" TaskParameter="Value"/>
</CreateProperty>
<PropertyGroup>
<_PythonWorkerToolsDir>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)../tools'))</_PythonWorkerToolsDir>
</PropertyGroup>

<ItemGroup Condition="'$(RuntimeIdentifier)' != ''">
<_PythonSupportedRuntime Include="win-x86" WorkerPath="WINDOWS/X86" />
<_PythonSupportedRuntime Include="win-x64" WorkerPath="WINDOWS/X64" />
<_PythonSupportedRuntime Include="linux-x64" WorkerPath="LINUX/X64" />
<_PythonSupportedRuntime Include="osx-x64" WorkerPath="OSX/X64" />
<_PythonSupportedRuntime Include="osx-arm64" WorkerPath="OSX/Arm64" />
</ItemGroup>

<Target Name="_GetFunctionsPythonWorkerFiles" BeforeTargets="AssignTargetPaths" DependsOnTargets="_GetFunctionsPythonWorkerFilesNoRuntime;_GetFunctionsPythonWorkerFilesForRuntime">
<ItemGroup>
<SourceFiles Include="$(NugetRoot)tools\**\*.*"/>
<None Include="@(_PythonWorkerFiles)" TargetPath="workers/python/%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
</Target>

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

<Target Name="CopyOnBuild" DependsOnTargets="Initialize" AfterTargets="Build">
<Copy SourceFiles="@(SourceFiles)"
DestinationFiles="@(SourceFiles->'$(OutDir)\workers\python\%(RecursiveDir)%(Filename)%(Extension)')" />
<!-- When a runtime is specified, copy only that runtimes files. -->
<Target Name="_GetFunctionsPythonWorkerFilesForRuntime" Condition="'$(RuntimeIdentifier)' != ''">
<PropertyGroup>
<_PythonWorkersRuntimeFolder>@(_PythonSupportedRuntime->WithMetadataValue('Identity', '$(RuntimeIdentifier)')->Metadata('WorkerPath'))</_PythonWorkersRuntimeFolder>
</PropertyGroup>

<ItemGroup>
<_PythonWorkerFiles Include="$(_PythonWorkerToolsDir)/*" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
<_PythonWorkerFiles Include="$(_PythonWorkerToolsDir)/**/$(_PythonWorkersRuntimeFolder)/**" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>

<!-- Error out if runtime is not supported. -->
<Error Condition="'$(_PythonWorkersRuntimeFolder)' == ''" Text="Runtime '$(RuntimeIdentifier)' is not supported by the Python worker. Supported runtimes are @(_PythonSupportedRuntime)." />
</Target>

</Project>

0 comments on commit 43e5a72

Please sign in to comment.