-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildpackages.task
93 lines (77 loc) · 3.79 KB
/
buildpackages.task
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
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets">
<Import Project="basedir.props" Condition=" '$(BaseDirImported)' == ''"/>
</ImportGroup>
<UsingTask TaskName="BuildPackagesTask"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
<Task>
<Reference Include="Microsoft.Build" />
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Utilities.Core" />
<Reference Include="System.IO.Compression.FileSystem" />
<Code Type="Class" Language="cs">
<![CDATA[
using System;
using System.IO;
using System.IO.Compression;
using Microsoft.Build.Framework;
using System.Reflection;
using Microsoft.Build.Execution;
using System.Net;
using System.ComponentModel;
using System.Diagnostics;
public class BuildPackagesTask : Microsoft.Build.Utilities.Task
{
private string basedir;
internal static bool FileOrDirectoryExists(string name)
{
return (Directory.Exists(name) || File.Exists(name));
}
internal static void CopyFilesRecursively(DirectoryInfo source, DirectoryInfo target) {
foreach (DirectoryInfo dir in source.GetDirectories())
CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name));
foreach (FileInfo file in source.GetFiles())
file.CopyTo(Path.Combine(target.FullName, file.Name));
}
public override bool Execute()
{
basedir = Path.GetFullPath(@"$(BaseDir)");
Log.LogMessage(MessageImportance.High,
"Building packages.");
string package = "rabbitmq-c-$(rabbitmq-cVersion)";
string package_root = @"$(BaseDir)out\packages\" + package + @"-headers\" + package;
if (!FileOrDirectoryExists(package_root))
{
Directory.CreateDirectory(package_root + @"\include");
string[] files = {"amqp.h", "amqp_framing.h", "amqp_ssl_socket.h", "amqp_tcp_socket.h", @"..\LICENSE-MIT"};
foreach (string f in files) {
File.Copy(package + @"\librabbitmq\" + f, package_root + @"\include\" + f);
}
ZipFile.CreateFromDirectory(@"$(BaseDir)out\packages\" + package + @"-headers\", @"$(BaseDir)out\" + package + @"-headers.zip".ToLower(), CompressionLevel.Optimal, false);
}
package_root = @"$(BaseDir)out\packages\rabbitmq-c-$(rabbitmq-cVersion)-binaries-$(Platform)-$(Configuration)\" + package;
if (!FileOrDirectoryExists(package_root))
{
Directory.CreateDirectory(package_root + @"\binaries\$(Platform)\$(Configuration)");
string[] files = {"librabbitmq.4.lib", @"../../../LICENSE-MIT"};
foreach (string f in files) {
File.Copy(package + @"\Build-$(Platform)\librabbitmq\$(Configuration)\" + f, package_root + @"\binaries\$(Platform)\$(Configuration)\" + f);
}
ZipFile.CreateFromDirectory(@"$(BaseDir)out\packages\" + package + @"-binaries-$(Platform)-$(Configuration)\", @"$(BaseDir)out\"+ package + @"-binaries-$(Platform)-$(Configuration).zip".ToLower(), CompressionLevel.Optimal, false);
}
return true;
}
}
]]>
</Code>
</Task>
</UsingTask>
<PropertyGroup>
<buildpackagestask_Imported>true</buildpackagestask_Imported>
</PropertyGroup>
<Target Name="BuildPackagesTarget" AfterTargets="Build">
<BuildPackagesTask />
</Target>
</Project>