-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildpackages.task
97 lines (81 loc) · 4.25 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
94
95
96
97
<?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_root = @"$(BaseDir)out\packages\openssl-$(OpenSSLVersion)-headers\openssl-$(OpenSSLVersion)";
if (!FileOrDirectoryExists(package_root))
{
Directory.CreateDirectory(package_root + @"\include");
CopyFilesRecursively(new DirectoryInfo("include"), new DirectoryInfo(package_root + @"\include"));
Directory.CreateDirectory(package_root + @"\include_x86");
CopyFilesRecursively(new DirectoryInfo("include_x86"), new DirectoryInfo(package_root + @"\include_x86"));
Directory.CreateDirectory(package_root + @"\include_x64");
CopyFilesRecursively(new DirectoryInfo("include_x64"), new DirectoryInfo(package_root + @"\include_x64"));
ZipFile.CreateFromDirectory(@"$(BaseDir)out\packages\openssl-$(OpenSSLVersion)-headers\", @"$(BaseDir)out\openssl-$(OpenSSLVersion)-headers.zip".ToLower(), CompressionLevel.Optimal, false);
}
package_root = @"$(BaseDir)out\packages\openssl-$(OpenSSLVersion)-binaries-$(Platform)-$(Configuration)\openssl-$(OpenSSLVersion)";
if (!FileOrDirectoryExists(package_root))
{
Directory.CreateDirectory(package_root + @"\binaries\$(Platform)\$(Configuration)");
string[] files = {"libeay32.dll", "libeay32.lib", "openssl.exe", "ssleay32.dll", "ssleay32.lib"};
foreach (string f in files) {
File.Copy(@"out\$(Platform)\$(Configuration)\" + f, package_root + @"\binaries\$(Platform)\$(Configuration)\" + f);
}
string[] def_files = {"libeay32.def","ssleay32.def"};
foreach (string f in def_files) {
File.Copy(f, package_root + @"\binaries\$(Platform)\$(Configuration)\" + f);
}
ZipFile.CreateFromDirectory(@"$(BaseDir)out\packages\openssl-$(OpenSSLVersion)-binaries-$(Platform)-$(Configuration)\", @"$(BaseDir)out\openssl-$(OpenSSLVersion)-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>