buildpackages.task 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  3. <ImportGroup Label="PropertySheets">
  4. <Import Project="basedir.props" Condition=" '$(BaseDirImported)' == ''"/>
  5. </ImportGroup>
  6. <UsingTask TaskName="BuildPackagesTask"
  7. TaskFactory="CodeTaskFactory"
  8. AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
  9. <Task>
  10. <Reference Include="Microsoft.Build" />
  11. <Reference Include="Microsoft.Build.Framework" />
  12. <Reference Include="Microsoft.Build.Utilities.Core" />
  13. <Reference Include="System.IO.Compression.FileSystem" />
  14. <Code Type="Class" Language="cs">
  15. <![CDATA[
  16. using System;
  17. using System.IO;
  18. using System.IO.Compression;
  19. using Microsoft.Build.Framework;
  20. using System.Reflection;
  21. using Microsoft.Build.Execution;
  22. using System.Net;
  23. using System.ComponentModel;
  24. using System.Diagnostics;
  25. public class BuildPackagesTask : Microsoft.Build.Utilities.Task
  26. {
  27. private string basedir;
  28. internal static bool FileOrDirectoryExists(string name)
  29. {
  30. return (Directory.Exists(name) || File.Exists(name));
  31. }
  32. internal static void CopyFilesRecursively(DirectoryInfo source, DirectoryInfo target) {
  33. foreach (DirectoryInfo dir in source.GetDirectories())
  34. CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name));
  35. foreach (FileInfo file in source.GetFiles())
  36. file.CopyTo(Path.Combine(target.FullName, file.Name));
  37. }
  38. public override bool Execute()
  39. {
  40. basedir = Path.GetFullPath(@"$(BaseDir)");
  41. Log.LogMessage(MessageImportance.High,
  42. "Building packages.");
  43. string package = "libks-$(libksVersion)";
  44. string package_root = @"$(BaseDir)out\packages\" + package + @"-headers\" + package + @"\libks";
  45. if (!FileOrDirectoryExists(package_root))
  46. {
  47. Directory.CreateDirectory(package_root + @"\cmake");
  48. Directory.CreateDirectory(package_root + @"\src");
  49. Directory.CreateDirectory(package_root + @"\src\include");
  50. CopyFilesRecursively(new DirectoryInfo(@"..\src\include\"), new DirectoryInfo(package_root + @"\src\include"));
  51. string[] files = {"CMakeLists.txt", @"cmake\ksutil.cmake"};
  52. foreach (string f in files) {
  53. File.Copy(@"..\" + f, package_root + @"\" + f);
  54. }
  55. ZipFile.CreateFromDirectory(@"$(BaseDir)out\packages\" + package + @"-headers\", @"$(BaseDir)out\" + package + @"_$(libksBuildNumber)" + @"-headers.zip".ToLower(), CompressionLevel.Optimal, false);
  56. }
  57. package_root = @"$(BaseDir)out\packages\libks-$(libksVersion)-binaries-$(Platform)-$(Configuration)\" + package;
  58. if (!FileOrDirectoryExists(package_root))
  59. {
  60. Directory.CreateDirectory(package_root + @"\binaries\$(Platform)\$(Configuration)");
  61. string[] files = {"ks2.lib", @"ks2.dll"};
  62. foreach (string f in files) {
  63. File.Copy(@"..\Build-$(Platform)\$(Configuration)\" + f, package_root + @"\binaries\$(Platform)\$(Configuration)\" + f);
  64. }
  65. if ("$(Configuration.ToLower())" == "debug" ) {
  66. string[] debug_files = {"ks2.pdb"};
  67. foreach (string f in debug_files) {
  68. File.Copy(@"..\Build-$(Platform)\$(Configuration)\" + f, package_root + @"\binaries\$(Platform)\$(Configuration)\" + f);
  69. }
  70. }
  71. ZipFile.CreateFromDirectory(@"$(BaseDir)out\packages\" + package + @"-binaries-$(Platform)-$(Configuration)\", @"$(BaseDir)out\"+ package + @"_$(libksBuildNumber)" + @"-binaries-$(Platform)-$(Configuration).zip".ToLower(), CompressionLevel.Optimal, false);
  72. }
  73. return true;
  74. }
  75. }
  76. ]]>
  77. </Code>
  78. </Task>
  79. </UsingTask>
  80. <PropertyGroup>
  81. <buildpackagestask_Imported>true</buildpackagestask_Imported>
  82. </PropertyGroup>
  83. <Target Name="BuildPackagesTarget" AfterTargets="Build">
  84. <BuildPackagesTask />
  85. </Target>
  86. </Project>