|
| 1 | +<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Restore;Build"> |
| 2 | + |
| 3 | + <PropertyGroup> |
| 4 | + <TargetFramework>netstandard2.0</TargetFramework> |
| 5 | + |
| 6 | + <DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences> |
| 7 | + <CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory> |
| 8 | + </PropertyGroup> |
| 9 | + |
| 10 | + <ItemGroup> |
| 11 | + <TensorFlowConfig Include="windows" FileExtension=".zip" FilesFromArchive="lib\tensorflow.dll" Runtime="win-x64"/> |
| 12 | + <TensorFlowConfig Include="linux" FileExtension=".tar.gz" FilesFromArchive="lib\libtensorflow.so;lib\libtensorflow_framework.so" Runtime="linux-x64" /> |
| 13 | + <TensorFlowConfig Include="darwin" FileExtension=".tar.gz" FilesFromArchive="lib\libtensorflow.so;lib\libtensorflow_framework.so" Runtime="osx-x64" /> |
| 14 | + <TensorFlowArchive Include="@(TensorFlowConfig->'https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-%(Identity)-x86_64-$(TensorFlowVersion)%(FileExtension)')" /> |
| 15 | + </ItemGroup> |
| 16 | + |
| 17 | + <Target Name="PrepareArchives"> |
| 18 | + <ItemGroup> |
| 19 | + <!-- set up metdata used by all targets --> |
| 20 | + <TensorFlowArchive DownloadFile="$(IntermediateOutputPath)%(FileName)%(Extension)" |
| 21 | + DownloadShaFile="$(IntermediateOutputPath)%(FileName)%(Extension).sha" |
| 22 | + ExtractDirectory="$(IntermediateOutputPath)%(FileName)" |
| 23 | + ExtractSemaphore="$(IntermediateOutputPath)%(FileName)\.extracted" |
| 24 | + LocalShaFile="$(MSBuildProjectDirectory)\%(FileName)%(Extension).sha"/> |
| 25 | + </ItemGroup> |
| 26 | + </Target> |
| 27 | + |
| 28 | + <UsingTask TaskName="DownloadFilesFromUrl" AssemblyFile="$(ToolsDir)Microsoft.DotNet.Build.Tasks.dll"/> |
| 29 | + <Target Name="DownloadArchives" |
| 30 | + DependsOnTargets="PrepareArchives" |
| 31 | + Inputs="$(MSBuildProjectFile)" |
| 32 | + Outputs="@(TensorFlowArchive->'%(DownloadFile)')"> |
| 33 | + <MakeDir Directories="$(IntermediateOutputPath)" /> |
| 34 | + <ItemGroup> |
| 35 | + <!-- DownloadFilesFromUrl requires Url metadata is set and ignores the identity of the item --> |
| 36 | + <_downloadFiles Include="@(TensorFlowArchive)" Url="%(Identity)" DestinationFile="%(DownloadFile)" /> |
| 37 | + </ItemGroup> |
| 38 | + <DownloadFilesFromUrl Items="@(_downloadFiles)"> |
| 39 | + <Output TaskParameter="FilesCreated" ItemName="FileWrites" /> |
| 40 | + </DownloadFilesFromUrl> |
| 41 | + </Target> |
| 42 | + |
| 43 | + <UsingTask TaskName="GenerateChecksums" AssemblyFile="$(ToolsDir)Microsoft.DotNet.Build.Tasks.dll"/> |
| 44 | + <UsingTask TaskName="ZipFileExtractToDirectory" AssemblyFile="$(ToolsDir)Microsoft.DotNet.Build.Tasks.dll"/> |
| 45 | + <Target Name="ValidateAndExtractArchives" |
| 46 | + DependsOnTargets="DownloadArchives" |
| 47 | + Inputs="@(TensorFlowArchive->'%(DownloadFile)')" |
| 48 | + Outputs="@(TensorFlowArchive->'%(ExtractSemaphore)')"> |
| 49 | + <!-- GenerateChecksums writes a sha checksum to the file specified by DestinationPath metadata --> |
| 50 | + <ItemGroup> |
| 51 | + <_filesToCheckSum Include="@(TensorFlowArchive->'%(DownloadFile)')" DestinationPath="%(DownloadShaFile)" /> |
| 52 | + </ItemGroup> |
| 53 | + <GenerateChecksums Items="@(_filesToCheckSum)" /> |
| 54 | + <ItemGroup> |
| 55 | + <FileWrites Include="@(TensorFlowArchive->'%(DownloadShaFile)')" /> |
| 56 | + </ItemGroup> |
| 57 | + |
| 58 | + <!-- If specified we'll update the checked in SHAs with the downloaded ones. --> |
| 59 | + <Copy Condition="'$(UpdateSHA)' == 'true'" |
| 60 | + SourceFiles="@(TensorFlowArchive->'%(DownloadShaFile)')" |
| 61 | + DestinationFiles="@(TensorFlowArchive->'%(LocalShaFile)')" /> |
| 62 | + |
| 63 | + <Error Condition="!Exists('%(TensorFlowArchive.LocalShaFile)')" Text="SHA file '%(TensorFlowArchive.LocalShaFile)' does not exist. Build with /p:UpdateSHA=true to save it." /> |
| 64 | + |
| 65 | + <!-- Read in the SHAs as metadata on the archive items --> |
| 66 | + <ItemGroup> |
| 67 | + <TensorFlowArchive> |
| 68 | + <LocalSha>$([System.IO.File]::ReadAllText('%(LocalShaFile)'))</LocalSha> |
| 69 | + <DownloadSha>$([System.IO.File]::ReadAllText('%(DownloadShaFile)'))</DownloadSha> |
| 70 | + </TensorFlowArchive> |
| 71 | + </ItemGroup> |
| 72 | + <!-- Validate that the downloaded SHAs match the expected checked in SHAs --> |
| 73 | + <Error Condition="'%(TensorFlowArchive.LocalSha)' != '%(TensorFlowArchive.DownloadSha)'" Text="Downloaded file '%(TensorFlowArchive.DownloadFile)' has unexpected SHA.%0A expected: %(_downloadedTensorFlowArchive.LocalSha)%0A actual: %(_downloadedTensorFlowArchive.DownloadSha)%0ABuild with /p:UpdateSHA=true if you intentionally changed the URL and wish to update the SHAs, otherwise this could indicate an incomplete download or intercerpted URL and should be examined." /> |
| 74 | + |
| 75 | + <!-- The archives are valid, lets extract them, ensuring an empty directory --> |
| 76 | + <RemoveDir Directories="@(TensorFlowArchive->'%(ExtractDirectory)')" /> |
| 77 | + <MakeDir Directories="@(TensorFlowArchive->'%(ExtractDirectory)')" /> |
| 78 | + <ZipFileExtractToDirectory Condition="'%(FileExtension)' == '.zip'" |
| 79 | + SourceArchive="%(TensorFlowArchive.DownloadFile)" |
| 80 | + DestinationDirectory="%(TensorFlowArchive.ExtractDirectory)" |
| 81 | + OverwriteDestination="true" /> |
| 82 | + <Exec Condition="'%(FileExtension)' == '.tar.gz'" |
| 83 | + Command="tar -xzmf "%(TensorFlowArchive.DownloadFile)" -C "%(TensorFlowArchive.ExtractDirectory)"" /> |
| 84 | + <Touch Files="@(TensorFlowArchive->'%(ExtractSemaphore)')" AlwaysCreate="true" /> |
| 85 | + |
| 86 | + <ItemGroup> |
| 87 | + <FileWrites Include="%(TensorFlowArchive.ExtractDirectory)\**\*" /> |
| 88 | + </ItemGroup> |
| 89 | + </Target> |
| 90 | + |
| 91 | + <!-- Clean up empty directories left behind by clean, since it otherwise would not do this --> |
| 92 | + <Target Name="CleanExtractDirectories" |
| 93 | + BeforeTargets="AfterClean" |
| 94 | + DependsOnTargets="PrepareArchives"> |
| 95 | + <RemoveDir Directories="@(TensorFlowArchive->'%(ExtractDirectory)')" /> |
| 96 | + </Target> |
| 97 | + |
| 98 | + <!-- Select the files we want to copy out of each archive. --> |
| 99 | + <Target Name="GetFilesFromArchive" |
| 100 | + DependsOnTargets="ValidateAndExtractArchives" > |
| 101 | + <ItemGroup> |
| 102 | + <!-- batch rather than transform so that we can split FilesFromArchive metadata --> |
| 103 | + <_fileFromArchive Include="%(TensorFlowArchive.FilesFromArchive)" ExtractDirectory="%(TensorFlowArchive.ExtractDirectory)" Runtime="%(TensorFlowArchive.Runtime)" /> |
| 104 | + <_fileFromArchive DestinationFile="%(FileName)%(Extension)"/> |
| 105 | + <!-- rename the .so to .dylib --> |
| 106 | + <_fileFromArchive Condition="'%(Runtime)' == 'osx-x64'" DestinationFile="%(FileName).dylib" /> |
| 107 | + |
| 108 | + <!-- copy to packaging location --> |
| 109 | + <FilesFromArchive Include="%(_fileFromArchive.ExtractDirectory)\%(_fileFromArchive.Identity)" |
| 110 | + TargetPath="$(PackageAssetsPath)$(MSBuildProjectName)\runtimes\%(_fileFromArchive.Runtime)\native\%(_fileFromArchive.DestinationFile)" /> |
| 111 | + |
| 112 | + <!-- copy to NativeAssets location, only for current RID, so that they may be used by tests --> |
| 113 | + <FilesFromArchive Condition="'$(PackageRID)' == '%(_fileFromArchive.Runtime)'" |
| 114 | + Include="%(_fileFromArchive.ExtractDirectory)\%(_fileFromArchive.Identity)" |
| 115 | + TargetPath="$(NativeAssetsBuiltPath)\%(_fileFromArchive.DestinationFile)" /> |
| 116 | + </ItemGroup> |
| 117 | + </Target> |
| 118 | + |
| 119 | + <Target Name="CopyFilesFromArchive" |
| 120 | + DependsOnTargets="GetFilesFromArchive"> |
| 121 | + <Copy SourceFiles="@(FilesFromArchive)" |
| 122 | + DestinationFiles="@(FilesFromArchive->'%(TargetPath)')"> |
| 123 | + <Output TaskParameter="DestinationFiles" ItemName="FileWrites" /> |
| 124 | + </Copy> |
| 125 | + </Target> |
| 126 | + |
| 127 | + <!-- Define CoreCompile to do the work of downloading and copying assets --> |
| 128 | + <Target Name="CoreCompile" |
| 129 | + DependsOnTargets="CopyFilesFromArchive" /> |
| 130 | + |
| 131 | + <!-- required by common targets --> |
| 132 | + <Target Name="CreateManifestResourceNames" /> |
| 133 | +</Project> |
0 commit comments