forked from chocolatey/choco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecipe.cake
179 lines (147 loc) · 8.94 KB
/
recipe.cake
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#load nuget:?package=Chocolatey.Cake.Recipe&version=0.16.0
///////////////////////////////////////////////////////////////////////////////
// TOOLS
///////////////////////////////////////////////////////////////////////////////
// This is needed in order to allow NUnit v2 tested to be executed by the NUnit
// v3 Test Runner
#tool nuget:?package=NUnit.Extension.NUnitV2Driver&version=3.9.0
///////////////////////////////////////////////////////////////////////////////
// SCRIPT
///////////////////////////////////////////////////////////////////////////////
Func<List<ILMergeConfig>> getILMergeConfigs = () =>
{
var mergeConfigs = new List<ILMergeConfig>();
var targetPlatform = "v4,C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.0";
var assembliesToILMerge = GetFiles(BuildParameters.Paths.Directories.PublishedApplications + "/choco/*.{exe|dll}")
- GetFiles(BuildParameters.Paths.Directories.PublishedApplications + "/choco/choco.exe")
- GetFiles(BuildParameters.Paths.Directories.PublishedApplications + "/choco/System.Management.Automation.dll");
Information("The following assemblies have been selected to be ILMerged for choco.exe...");
foreach (var assemblyToILMerge in assembliesToILMerge)
{
Information(assemblyToILMerge.FullPath);
}
mergeConfigs.Add(new ILMergeConfig() {
KeyFile = BuildParameters.StrongNameKeyPath,
LogFile = BuildParameters.Paths.Directories.Build + "/ilmerge-chocoexe.log",
TargetPlatform = targetPlatform,
Target = "exe",
Internalize = BuildParameters.RootDirectoryPath + "/src/chocolatey.console/ilmerge.internalize.ignore.txt",
Output = BuildParameters.Paths.Directories.PublishedApplications + "/choco_merged/choco.exe",
PrimaryAssemblyName = BuildParameters.Paths.Directories.PublishedApplications + "/choco/choco.exe",
AssemblyPaths = assembliesToILMerge });
assembliesToILMerge = GetFiles(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey/*.{exe|dll}")
- GetFiles(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey/choco.exe")
- GetFiles(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey/chocolatey.dll")
- GetFiles(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey/log4net.dll")
- GetFiles(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey/System.Management.Automation.dll");
Information("The following assemblies have been selected to be ILMerged for chocolatey.dll...");
foreach (var assemblyToILMerge in assembliesToILMerge)
{
Information(assemblyToILMerge.FullPath);
}
mergeConfigs.Add(new ILMergeConfig() {
KeyFile = BuildParameters.StrongNameKeyPath,
LogFile = BuildParameters.Paths.Directories.Build + "/ilmerge-chocolateydll.log",
TargetPlatform = targetPlatform,
Target = "dll",
Internalize = BuildParameters.RootDirectoryPath + "/src/chocolatey/ilmerge.internalize.ignore.dll.txt",
Output = BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey_merged/chocolatey.dll",
PrimaryAssemblyName = BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey/chocolatey.dll",
AssemblyPaths = assembliesToILMerge });
return mergeConfigs;
};
Func<FilePathCollection> getScriptsToSign = () =>
{
var scriptsToSign = GetFiles(BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/**/*.{ps1|psm1}") +
GetFiles(BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/**/*.{ps1|psm1}");
Information("The following PowerShell scripts have been selected to be signed...");
foreach (var scriptToSign in scriptsToSign)
{
Information(scriptToSign.FullPath);
}
return scriptsToSign;
};
Func<FilePathCollection> getFilesToSign = () =>
{
var filesToSign = GetFiles(BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/lib/chocolatey.dll")
+ GetFiles(BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/choco.exe")
+ GetFiles(BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/tools/{checksum|shimgen}.exe")
+ GetFiles(BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/redirects/*.exe");
Information("The following assemblies have been selected to be signed...");
foreach (var fileToSign in filesToSign)
{
Information(fileToSign.FullPath);
}
return filesToSign;
};
///////////////////////////////////////////////////////////////////////////////
// CUSTOM TASKS
///////////////////////////////////////////////////////////////////////////////
Task("Prepare-Chocolatey-Packages")
.IsDependeeOf("Create-Chocolatey-Packages")
.IsDependeeOf("Sign-PowerShellScripts")
.IsDependeeOf("Sign-Assemblies")
.WithCriteria(() => BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows, "Skipping because not running on Windows")
.Does(() =>
{
// Copy legal documents
CopyFile(BuildParameters.RootDirectoryPath + "/docs/legal/CREDITS.md", BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/CREDITS.txt");
// Run Chocolatey Unpackself
CopyFile(BuildParameters.Paths.Directories.PublishedApplications + "/choco_merged/choco.exe", BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/choco.exe");
StartProcess(BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/choco.exe", new ProcessSettings{ Arguments = "unpackself -f -y --allow-unofficial-build" });
// Tidy up logs and config folder which are not required
var logsDirectory = BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/logs";
var configDirectory = BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/config";
if (DirectoryExists(logsDirectory))
{
DeleteDirectory(logsDirectory, new DeleteDirectorySettings {
Recursive = true,
Force = true
});
}
if (DirectoryExists(configDirectory))
{
DeleteDirectory(configDirectory, new DeleteDirectorySettings {
Recursive = true,
Force = true
});
}
});
Task("Prepare-NuGet-Packages")
.IsDependeeOf("Create-NuGet-Packages")
.IsDependeeOf("Sign-PowerShellScripts")
.IsDependeeOf("Sign-Assemblies")
.Does(() =>
{
// Copy legal documents
CleanDirectory(BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/lib");
CopyFile(BuildParameters.RootDirectoryPath + "/docs/legal/CREDITS.md", BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/lib/CREDITS.txt");
CopyFiles(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey_merged/*", BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/lib");
CopyFile(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey/chocolatey.xml", BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/lib/chocolatey.xml");
});
///////////////////////////////////////////////////////////////////////////////
// RECIPE SCRIPT
///////////////////////////////////////////////////////////////////////////////
Environment.SetVariableNames();
BuildParameters.SetParameters(context: Context,
buildSystem: BuildSystem,
sourceDirectoryPath: "./src",
solutionFilePath: "./src/chocolatey.sln",
solutionDirectoryPath: "./src/chocolatey",
resharperSettingsFileName: "chocolatey.sln.DotSettings",
title: "Chocolatey",
repositoryOwner: "chocolatey",
repositoryName: "choco",
productName: "Chocolatey",
productDescription: "chocolatey is a product of Chocolatey Software, Inc. - All Rights Reserved.",
productCopyright: string.Format("Copyright © 2017 - {0} Chocolatey Software, Inc. Copyright © 2011 - 2017, RealDimensions Software, LLC - All Rights Reserved.", DateTime.Now.Year),
shouldStrongNameSignDependentAssemblies: false,
treatWarningsAsErrors: false,
getScriptsToSign: getScriptsToSign,
getFilesToSign: getFilesToSign,
getILMergeConfigs: getILMergeConfigs,
preferDotNetGlobalToolUsage: !IsRunningOnWindows());
ToolSettings.SetToolSettings(context: Context,
buildMSBuildToolVersion: MSBuildToolVersion.NET40);
BuildParameters.PrintParameters(Context);
Build.Run();