| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<!-- |
| 3 |
/**************************************************************************** |
| 4 |
** |
| 5 |
** Copyright (C) 2018 The Qt Company Ltd. |
| 6 |
** Contact: https://www.qt.io/licensing/ |
| 7 |
** |
| 8 |
** This file is part of the Qt VS Tools. |
| 9 |
** |
| 10 |
** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 11 |
** Commercial License Usage |
| 12 |
** Licensees holding valid commercial Qt licenses may use this file in |
| 13 |
** accordance with the commercial license agreement provided with the |
| 14 |
** Software or, alternatively, in accordance with the terms contained in |
| 15 |
** a written agreement between you and The Qt Company. For licensing terms |
| 16 |
** and conditions see https://www.qt.io/terms-conditions. For further |
| 17 |
** information use the contact form at https://www.qt.io/contact-us. |
| 18 |
** |
| 19 |
** GNU General Public License Usage |
| 20 |
** Alternatively, this file may be used under the terms of the GNU |
| 21 |
** General Public License version 3 as published by the Free Software |
| 22 |
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 23 |
** included in the packaging of this file. Please review the following |
| 24 |
** information to ensure the GNU General Public License requirements will |
| 25 |
** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 26 |
** |
| 27 |
** $QT_END_LICENSE$ |
| 28 |
** |
| 29 |
****************************************************************************/ |
| 30 |
--> |
| 31 |
|
| 32 |
<!-- |
| 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 34 |
// Helper inline tasks used by the Qt/MSBuild targets |
| 35 |
// --> |
| 36 |
<Project> |
| 37 |
|
| 38 |
<!-- |
| 39 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 40 |
/// TASK ListQrc |
| 41 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 42 |
// List resource paths in a QRC file. |
| 43 |
// Parameters: |
| 44 |
// in string QrcFilePath: path to QRC file |
| 45 |
// out string[] Result: paths to files referenced in QRC |
| 46 |
// --> |
| 47 |
<UsingTask TaskName="ListQrc" |
| 48 |
TaskFactory="CodeTaskFactory" |
| 49 |
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> |
| 50 |
<ParameterGroup> |
| 51 |
<QrcFilePath ParameterType="System.String" Required="true" /> |
| 52 |
<Result ParameterType="System.String[]" Output="true" /> |
| 53 |
</ParameterGroup> |
| 54 |
<Task> |
| 55 |
<Reference Include="System.Xml"/> |
| 56 |
<Reference Include="System.Xml.Linq"/> |
| 57 |
<Using Namespace="System.Xml.Linq"/> |
| 58 |
<Code Type="Fragment" Language="cs"> |
| 59 |
<![CDATA[ |
| 60 |
XDocument qrc = XDocument.Load(QrcFilePath, LoadOptions.SetLineInfo); |
| 61 |
IEnumerable<XElement> files = qrc |
| 62 |
.Element("RCC") |
| 63 |
.Elements("qresource") |
| 64 |
.Elements("file"); |
| 65 |
Uri QrcPath = new Uri(QrcFilePath); |
| 66 |
Result = files |
| 67 |
.Select(x => new Uri(QrcPath, x.Value).LocalPath) |
| 68 |
.ToArray(); |
| 69 |
]]> |
| 70 |
</Code> |
| 71 |
</Task> |
| 72 |
</UsingTask> |
| 73 |
|
| 74 |
<!-- |
| 75 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 76 |
/// TASK GetItemHash |
| 77 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 78 |
// Calculate an hash code (Deflate + Base64) for an item, given a list of metadata to use as key |
| 79 |
// Parameters: |
| 80 |
// in ITaskItem Item: item for which the hash will be calculated |
| 81 |
// in string[] Keys: list of names of the metadata to use as item key |
| 82 |
// out string Hash: hash code (Base64 representation of Deflate'd UTF-8 item key) |
| 83 |
// --> |
| 84 |
<UsingTask TaskName="GetItemHash" |
| 85 |
TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> |
| 86 |
<ParameterGroup> |
| 87 |
<Item ParameterType="Microsoft.Build.Framework.ITaskItem" Required="true" /> |
| 88 |
<Keys ParameterType="System.String[]" Required="true" /> |
| 89 |
<Hash Output="true" ParameterType="System.String" /> |
| 90 |
</ParameterGroup> |
| 91 |
<Task> |
| 92 |
<Using Namespace="System"/> |
| 93 |
<Using Namespace="System.Text"/> |
| 94 |
<Using Namespace="System.IO"/> |
| 95 |
<Using Namespace="System.IO.Compression"/> |
| 96 |
<Code Type="Fragment" Language="cs"> |
| 97 |
<![CDATA[ |
| 98 |
var data = Encoding.UTF8.GetBytes(string.Concat(Keys.OrderBy(x => x) |
| 99 |
.Select(x => string.Format("[{0}={1}]", x, Item.GetMetadata(x)))) |
| 100 |
.ToUpper()); |
| 101 |
using (var dataZipped = new MemoryStream()) { |
| 102 |
using (var zip = new DeflateStream(dataZipped, CompressionLevel.Fastest)) |
| 103 |
zip.Write(data, 0, data.Length); |
| 104 |
Hash = Convert.ToBase64String(dataZipped.ToArray()); |
| 105 |
} |
| 106 |
]]> |
| 107 |
</Code> |
| 108 |
</Task> |
| 109 |
</UsingTask> |
| 110 |
|
| 111 |
<!-- |
| 112 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 113 |
/// TASK Expand |
| 114 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 115 |
// Expand a list of items, taking additional metadata from a base item and from a template item. |
| 116 |
// Parameters: |
| 117 |
// in ITaskItem[] Items: items to expand |
| 118 |
// in ITaskItem BaseItem: base item from which the expanded items derive |
| 119 |
// in ITaskItem Template = null: (optional) template containing metadata to add / update |
| 120 |
// out ITaskItem[] Result: list of new items |
| 121 |
// --> |
| 122 |
<UsingTask TaskName="Expand" |
| 123 |
TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> |
| 124 |
<ParameterGroup> |
| 125 |
<Items ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> |
| 126 |
<BaseItem ParameterType="Microsoft.Build.Framework.ITaskItem" Required="true" /> |
| 127 |
<Template ParameterType="Microsoft.Build.Framework.ITaskItem" Required="false"/> |
| 128 |
<Result Output="true" ParameterType="Microsoft.Build.Framework.ITaskItem[]" /> |
| 129 |
</ParameterGroup> |
| 130 |
<Task> |
| 131 |
<Using Namespace="System"/> |
| 132 |
<Using Namespace="System.Text.RegularExpressions"/> |
| 133 |
<Code Type="Fragment" Language="cs"> |
| 134 |
<![CDATA[ |
| 135 |
Result = new ITaskItem[] { }; |
| 136 |
var reserved = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase) |
| 137 |
{ |
| 138 |
"AccessedTime", "CreatedTime", "DefiningProjectDirectory", |
| 139 |
"DefiningProjectExtension", "DefiningProjectFullPath", "DefiningProjectName", |
| 140 |
"Directory", "Extension", "Filename", "FullPath", "Identity", "ModifiedTime", |
| 141 |
"RecursiveDir", "RelativeDir", "RootDir", |
| 142 |
}; |
| 143 |
var newItems = new List<ITaskItem>(); |
| 144 |
foreach (var item in Items) { |
| 145 |
var newItem = new TaskItem(item); |
| 146 |
if (BaseItem != null) |
| 147 |
BaseItem.CopyMetadataTo(newItem); |
| 148 |
var itemExt = newItem.GetMetadata("Extension"); |
| 149 |
if (!string.IsNullOrEmpty(itemExt)) |
| 150 |
newItem.SetMetadata("Suffix", itemExt.Substring(1)); |
| 151 |
if (Template != null) { |
| 152 |
var metadataNames = Template.MetadataNames |
| 153 |
.Cast<string>().Where(x => !reserved.Contains(x)); |
| 154 |
foreach (var metadataName in metadataNames) { |
| 155 |
var metadataValue = Template.GetMetadata(metadataName); |
| 156 |
newItem.SetMetadata(metadataName, |
| 157 |
Regex.Replace(metadataValue, @"(%<)(\w+)(>)", |
| 158 |
match => newItem.GetMetadata(match.Groups[2].Value))); |
| 159 |
} |
| 160 |
} |
| 161 |
newItems.Add(newItem); |
| 162 |
} |
| 163 |
Result = newItems.ToArray(); |
| 164 |
]]> |
| 165 |
</Code> |
| 166 |
</Task> |
| 167 |
</UsingTask> |
| 168 |
|
| 169 |
<!-- |
| 170 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 171 |
/// TASK DumpItems |
| 172 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 173 |
// Dump contents of items as a log message. The contents are formatted as XML. |
| 174 |
// Parameters: |
| 175 |
// in string ItemType: type of the items; this is used as the parent node of each |
| 176 |
// item dump |
| 177 |
// in ITaskItem[] Items: items to dump |
| 178 |
// in bool DumpReserved: include MSBuild reserved metadata in dump? |
| 179 |
// in string Metadata: list of names of metadata to include in dump; omit to |
| 180 |
// include all metadata |
| 181 |
// --> |
| 182 |
<UsingTask TaskName="DumpItems" |
| 183 |
TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> |
| 184 |
<ParameterGroup> |
| 185 |
<ItemType ParameterType="System.String" Required="true" /> |
| 186 |
<Items ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> |
| 187 |
<DumpReserved ParameterType="System.Boolean" Required="false" /> |
| 188 |
<Metadata ParameterType="System.String" Required="false" /> |
| 189 |
</ParameterGroup> |
| 190 |
<Task> |
| 191 |
<Using Namespace="System"/> |
| 192 |
<Using Namespace="System.Diagnostics"/> |
| 193 |
<Using Namespace="System.Text"/> |
| 194 |
<Code Type="Fragment" Language="cs"> |
| 195 |
<![CDATA[ |
| 196 |
var reserved = new HashSet<string> |
| 197 |
{ |
| 198 |
"AccessedTime", "CreatedTime", "DefiningProjectDirectory", |
| 199 |
"DefiningProjectExtension", "DefiningProjectFullPath", "DefiningProjectName", |
| 200 |
"Directory", "Extension", "Filename", "FullPath", "Identity", "ModifiedTime", |
| 201 |
"RecursiveDir", "RelativeDir", "RootDir", |
| 202 |
}; |
| 203 |
if (Metadata == null) |
| 204 |
Metadata = ""; |
| 205 |
var requestedNames = new HashSet<string>(Metadata.Split(new[] { ';' }, |
| 206 |
StringSplitOptions.RemoveEmptyEntries)); |
| 207 |
var itemXml = new StringBuilder(); |
| 208 |
if (Items.Any()) { |
| 209 |
foreach (var item in Items) { |
| 210 |
if (itemXml.Length > 0) |
| 211 |
itemXml.Append("\r\n"); |
| 212 |
itemXml.AppendFormat("<{0} Include=\"{1}\"", ItemType, item.ItemSpec); |
| 213 |
var names = item.MetadataNames.Cast<string>() |
| 214 |
.Where(x => (DumpReserved || !reserved.Contains(x)) |
| 215 |
&& (!requestedNames.Any() || requestedNames.Contains(x))) |
| 216 |
.OrderBy(x => x); |
| 217 |
if (names.Any()) { |
| 218 |
itemXml.Append(">\r\n"); |
| 219 |
foreach (string name in names) { |
| 220 |
if (!DumpReserved && reserved.Contains(name)) |
| 221 |
continue; |
| 222 |
if (!item.MetadataNames.Cast<string>().Contains(name)) |
| 223 |
continue; |
| 224 |
var value = item.GetMetadata(name); |
| 225 |
if (!string.IsNullOrEmpty(value)) |
| 226 |
itemXml.AppendFormat(" <{0}>{1}</{0}>\r\n", name, value); |
| 227 |
else |
| 228 |
itemXml.AppendFormat(" <{0}/>\r\n", name); |
| 229 |
} |
| 230 |
itemXml.AppendFormat("</{0}>", ItemType); |
| 231 |
} else { |
| 232 |
itemXml.Append("/>"); |
| 233 |
} |
| 234 |
} |
| 235 |
} else { |
| 236 |
itemXml.AppendFormat("<{0}/>", ItemType); |
| 237 |
} |
| 238 |
Log.LogMessage(MessageImportance.High, itemXml.ToString()); |
| 239 |
]]> |
| 240 |
</Code> |
| 241 |
</Task> |
| 242 |
</UsingTask> |
| 243 |
|
| 244 |
<!-- |
| 245 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 246 |
/// TASK QtRunWork |
| 247 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 248 |
// Run work items in parallel processes. |
| 249 |
// Parameters: |
| 250 |
// in ITaskItem[] QtWork: work items |
| 251 |
// in int QtMaxProcs: maximum number of processes to run in parallel |
| 252 |
// in bool QtDebug: generate debug messages |
| 253 |
// out ITaskItem[] Result: list of new items with the result of each work item |
| 254 |
// --> |
| 255 |
<UsingTask |
| 256 |
TaskName="QtRunWork" |
| 257 |
TaskFactory="CodeTaskFactory" |
| 258 |
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> |
| 259 |
<ParameterGroup> |
| 260 |
<QtWork ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> |
| 261 |
<QtMaxProcs ParameterType="System.Int32" Required="true" /> |
| 262 |
<QtDebug ParameterType="System.Boolean" Required="true" /> |
| 263 |
<Result Output="true" ParameterType="Microsoft.Build.Framework.ITaskItem[]" /> |
| 264 |
</ParameterGroup> |
| 265 |
<Task> |
| 266 |
<Using Namespace="System"/> |
| 267 |
<Using Namespace="System.IO"/> |
| 268 |
<Using Namespace="System.Diagnostics"/> |
| 269 |
<Using Namespace="System.Collections.Generic"/> |
| 270 |
<Code Type="Fragment" Language="cs"> |
| 271 |
<![CDATA[ |
| 272 |
Result = new ITaskItem[] { }; |
| 273 |
bool ok = true; |
| 274 |
var Comparer = StringComparer.InvariantCultureIgnoreCase; |
| 275 |
var Comparison = StringComparison.InvariantCultureIgnoreCase; |
| 276 |
|
| 277 |
// Work item key = "%(WorkType)(%(Identity))" |
| 278 |
Func<string, string, string> KeyString = (x, y) => string.Format("{0}{{{1}}}", x, y); |
| 279 |
Func<ITaskItem, string> Key = (item) => |
| 280 |
KeyString(item.GetMetadata("WorkType"), item.ItemSpec); |
| 281 |
var workItemKeys = new HashSet<string>(QtWork.Select(x => Key(x)), Comparer); |
| 282 |
|
| 283 |
// Work items, indexed by %(Identity) |
| 284 |
var workItemsByIdentity = QtWork |
| 285 |
.GroupBy(x => x.ItemSpec, x => Key(x), Comparer) |
| 286 |
.ToDictionary(x => x.Key, x => new List<string>(x), Comparer); |
| 287 |
|
| 288 |
// Work items, indexed by work item key |
| 289 |
var workItems = QtWork.Select(x => new |
| 290 |
{ |
| 291 |
Self = x, |
| 292 |
Key = Key(x), |
| 293 |
ToolPath = x.GetMetadata("ToolPath"), |
| 294 |
Message = x.GetMetadata("Message"), |
| 295 |
DependsOn = new HashSet<string>(comparer: Comparer, |
| 296 |
collection: x.GetMetadata("DependsOn") |
| 297 |
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) |
| 298 |
.Where(y => workItemsByIdentity.ContainsKey(y)) |
| 299 |
.SelectMany(y => workItemsByIdentity[y]) |
| 300 |
.Union(x.GetMetadata("DependsOnWork") |
| 301 |
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) |
| 302 |
.Select(y => KeyString(y, x.ItemSpec)) |
| 303 |
.Where(y => workItemKeys.Contains(y))) |
| 304 |
.GroupBy(y => y, Comparer).Select(y => y.Key) |
| 305 |
.Where(y => !y.Equals(Key(x), Comparison))), |
| 306 |
ProcessStartInfo = new ProcessStartInfo |
| 307 |
{ |
| 308 |
FileName = x.GetMetadata("ToolPath"), |
| 309 |
Arguments = x.GetMetadata("Options"), |
| 310 |
CreateNoWindow = true, |
| 311 |
UseShellExecute = false, |
| 312 |
RedirectStandardError = true, |
| 313 |
RedirectStandardOutput = true, |
| 314 |
}, |
| 315 |
}) |
| 316 |
// In case of items with duplicate keys, use only the first one |
| 317 |
.GroupBy(x => x.Key, Comparer) |
| 318 |
.ToDictionary(x => x.Key, x => x.First(), Comparer); |
| 319 |
|
| 320 |
// Result |
| 321 |
var result = workItems.Values |
| 322 |
.ToDictionary(x => x.Key, x => new TaskItem(x.Self)); |
| 323 |
|
| 324 |
// Dependency relation [item -> dependent items] |
| 325 |
var dependentsOf = workItems.Values |
| 326 |
.Where(x => x.DependsOn.Any()) |
| 327 |
.SelectMany(x => x.DependsOn.Select(y => new { Dependent = x.Key, Dependency = y })) |
| 328 |
.GroupBy(x => x.Dependency, x => x.Dependent, Comparer) |
| 329 |
.ToDictionary(x => x.Key, x => new List<string>(x), Comparer); |
| 330 |
|
| 331 |
// Work items that are ready to start; initially queue all independent items |
| 332 |
var workQueue = new Queue<string>(workItems.Values |
| 333 |
.Where(x => !x.DependsOn.Any()) |
| 334 |
.Select(x => x.Key)); |
| 335 |
|
| 336 |
if (QtDebug) { |
| 337 |
Log.LogMessage(MessageImportance.High, |
| 338 |
string.Format("## QtRunWork queueing\r\n## {0}", |
| 339 |
string.Join("\r\n## ", workQueue))); |
| 340 |
} |
| 341 |
|
| 342 |
// Postponed items; save dependent items to queue later when ready |
| 343 |
var postponedItems = new HashSet<string>(workItems.Values |
| 344 |
.Where(x => x.DependsOn.Any()) |
| 345 |
.Select(x => x.Key)); |
| 346 |
|
| 347 |
if (QtDebug && postponedItems.Any()) { |
| 348 |
Log.LogMessage(MessageImportance.High, |
| 349 |
string.Format("## QtRunWork postponed dependents\r\n## {0}", |
| 350 |
string.Join("\r\n## ", postponedItems |
| 351 |
.Select(x => string.Format("{0} <- {1}", x, |
| 352 |
string.Join(", ", workItems[x].DependsOn)))))); |
| 353 |
} |
| 354 |
|
| 355 |
// Work items that are running; must synchronize with the exit of all processes |
| 356 |
var running = new Queue<KeyValuePair<string, Process>>(); |
| 357 |
|
| 358 |
// Work items that have terminated |
| 359 |
var terminated = new HashSet<string>(Comparer); |
| 360 |
|
| 361 |
// While there are work items queued, start a process for each item |
| 362 |
while (ok && workQueue.Any()) { |
| 363 |
|
| 364 |
var workItem = workItems[workQueue.Dequeue()]; |
| 365 |
Log.LogMessage(MessageImportance.High, workItem.Message); |
| 366 |
|
| 367 |
try { |
| 368 |
var proc = Process.Start(workItem.ProcessStartInfo); |
| 369 |
proc.OutputDataReceived += (object sender, DataReceivedEventArgs e) => |
| 370 |
{ |
| 371 |
if (!string.IsNullOrEmpty(e.Data)) |
| 372 |
Log.LogMessage(MessageImportance.High, string.Join(" ", new[] |
| 373 |
{ |
| 374 |
(QtDebug ? "[" + (((Process)sender).Id.ToString()) + "]" : ""), |
| 375 |
e.Data |
| 376 |
})); |
| 377 |
}; |
| 378 |
proc.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => |
| 379 |
{ |
| 380 |
if (!string.IsNullOrEmpty(e.Data)) |
| 381 |
Log.LogMessage(MessageImportance.High, string.Join(" ", new[] |
| 382 |
{ |
| 383 |
(QtDebug ? "[" + (((Process)sender).Id.ToString()) + "]" : ""), |
| 384 |
e.Data |
| 385 |
})); |
| 386 |
}; |
| 387 |
proc.BeginOutputReadLine(); |
| 388 |
proc.BeginErrorReadLine(); |
| 389 |
running.Enqueue(new KeyValuePair<string, Process>(workItem.Key, proc)); |
| 390 |
} catch (Exception e) { |
| 391 |
Log.LogError( |
| 392 |
string.Format("[QtRunWork] Error starting process {0}: {1}", |
| 393 |
workItem.ToolPath, e.Message)); |
| 394 |
ok = false; |
| 395 |
} |
| 396 |
|
| 397 |
string qtDebugRunning = ""; |
| 398 |
if (QtDebug) { |
| 399 |
qtDebugRunning = string.Format("## QtRunWork waiting {0}", |
| 400 |
string.Join(", ", running |
| 401 |
.Select(x => string.Format("{0} [{1}]", x.Key, x.Value.Id)))); |
| 402 |
} |
| 403 |
|
| 404 |
// Wait for process to terminate when there are processes running, and... |
| 405 |
while (ok && running.Any() |
| 406 |
// ...work is queued but already reached the maximum number of processes, or... |
| 407 |
&& ((workQueue.Any() && running.Count >= QtMaxProcs) |
| 408 |
// ...work queue is empty but there are dependents that haven't yet been queued |
| 409 |
|| (!workQueue.Any() && postponedItems.Any()))) { |
| 410 |
|
| 411 |
var itemProc = running.Dequeue(); |
| 412 |
workItem = workItems[itemProc.Key]; |
| 413 |
var proc = itemProc.Value; |
| 414 |
|
| 415 |
if (QtDebug && !string.IsNullOrEmpty(qtDebugRunning)) { |
| 416 |
Log.LogMessage(MessageImportance.High, qtDebugRunning); |
| 417 |
qtDebugRunning = ""; |
| 418 |
} |
| 419 |
|
| 420 |
if (proc.WaitForExit(100)) { |
| 421 |
if (QtDebug) { |
| 422 |
Log.LogMessage(MessageImportance.High, |
| 423 |
string.Format("## QtRunWork exit {0} [{1}] = {2} ({3:0.00} msecs)", |
| 424 |
workItem.Key, proc.Id, proc.ExitCode, |
| 425 |
(proc.ExitTime - proc.StartTime).TotalMilliseconds)); |
| 426 |
} |
| 427 |
|
| 428 |
// Process terminated; check exit code and close |
| 429 |
terminated.Add(workItem.Key); |
| 430 |
result[workItem.Key].SetMetadata("ExitCode", proc.ExitCode.ToString()); |
| 431 |
ok &= (proc.ExitCode == 0); |
| 432 |
proc.Close(); |
| 433 |
|
| 434 |
// Add postponed dependent items to work queue |
| 435 |
if (ok && dependentsOf.ContainsKey(workItem.Key)) { |
| 436 |
// Dependents of workItem... |
| 437 |
var readyDependents = dependentsOf[workItem.Key] |
| 438 |
// ...that have not yet been queued... |
| 439 |
.Where(x => postponedItems.Contains(x) |
| 440 |
// ...and whose depending items have all terminated. |
| 441 |
&& workItems[x].DependsOn.All(y => terminated.Contains(y))); |
| 442 |
|
| 443 |
if (QtDebug && readyDependents.Any()) { |
| 444 |
Log.LogMessage(MessageImportance.High, |
| 445 |
string.Format("## QtRunWork queueing\r\n## {0}", |
| 446 |
string.Join("\r\n## ", readyDependents))); |
| 447 |
} |
| 448 |
|
| 449 |
foreach (var dependent in readyDependents) { |
| 450 |
postponedItems.Remove(dependent); |
| 451 |
workQueue.Enqueue(dependent); |
| 452 |
} |
| 453 |
} |
| 454 |
} else { |
| 455 |
// Process is still running; feed it back into the running queue |
| 456 |
running.Enqueue(itemProc); |
| 457 |
} |
| 458 |
} |
| 459 |
} |
| 460 |
|
| 461 |
// If there are items still haven't been queued, that means a circular dependency exists |
| 462 |
if (ok && postponedItems.Any()) { |
| 463 |
ok = false; |
| 464 |
Log.LogError("[QtRunWork] Error: circular dependency"); |
| 465 |
if (QtDebug) { |
| 466 |
Log.LogMessage(MessageImportance.High, |
| 467 |
string.Format("## QtRunWork circularity\r\n## {0}", |
| 468 |
string.Join("\r\n## ", postponedItems |
| 469 |
.Select(x => string.Format("{0} <- {1}", x, |
| 470 |
string.Join(", ", workItems[x].DependsOn)))))); |
| 471 |
} |
| 472 |
} |
| 473 |
|
| 474 |
if (ok && QtDebug) { |
| 475 |
Log.LogMessage(MessageImportance.High, |
| 476 |
"## QtRunWork all work queued"); |
| 477 |
if (running.Any()) { |
| 478 |
Log.LogMessage(MessageImportance.High, |
| 479 |
string.Format("## QtRunWork waiting {0}", |
| 480 |
string.Join(", ", running |
| 481 |
.Select(x => string.Format("{0} [{1}]", x.Key, x.Value.Id))))); |
| 482 |
} |
| 483 |
} |
| 484 |
|
| 485 |
// Wait for all running processes to terminate |
| 486 |
while (running.Any()) { |
| 487 |
var itemProc = running.Dequeue(); |
| 488 |
var workItem = workItems[itemProc.Key]; |
| 489 |
var proc = itemProc.Value; |
| 490 |
if (proc.WaitForExit(100)) { |
| 491 |
if (QtDebug) { |
| 492 |
Log.LogMessage(MessageImportance.High, |
| 493 |
string.Format("## QtRunWork exit {0} [{1}] = {2} ({3:0.00} msecs)", |
| 494 |
workItem.Key, proc.Id, proc.ExitCode, |
| 495 |
(proc.ExitTime - proc.StartTime).TotalMilliseconds)); |
| 496 |
} |
| 497 |
// Process terminated; check exit code and close |
| 498 |
result[workItem.Key].SetMetadata("ExitCode", proc.ExitCode.ToString()); |
| 499 |
ok &= (proc.ExitCode == 0); |
| 500 |
proc.Close(); |
| 501 |
} else { |
| 502 |
// Process is still running; feed it back into the running queue |
| 503 |
running.Enqueue(itemProc); |
| 504 |
} |
| 505 |
} |
| 506 |
|
| 507 |
if (QtDebug) { |
| 508 |
Log.LogMessage(MessageImportance.High, |
| 509 |
string.Format("## QtRunWork result {0}", (ok ? "ok" : "FAILED!"))); |
| 510 |
} |
| 511 |
|
| 512 |
Result = result.Values.ToArray(); |
| 513 |
if (!ok) |
| 514 |
return false; |
| 515 |
]]> |
| 516 |
</Code> |
| 517 |
</Task> |
| 518 |
</UsingTask> |
| 519 |
|
| 520 |
<!-- |
| 521 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 522 |
/// TASK ParseVarDefs |
| 523 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 524 |
// |
| 525 |
// --> |
| 526 |
<UsingTask TaskName="ParseVarDefs" |
| 527 |
TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> |
| 528 |
<ParameterGroup> |
| 529 |
<QtVars Required="true" |
| 530 |
ParameterType="System.String"/> |
| 531 |
<OutVarDefs Output="true" |
| 532 |
ParameterType="Microsoft.Build.Framework.ITaskItem[]"/> |
| 533 |
</ParameterGroup> |
| 534 |
<Task> |
| 535 |
<Using Namespace="System"/> |
| 536 |
<Using Namespace="System.Text"/> |
| 537 |
<Using Namespace="System.Text.RegularExpressions"/> |
| 538 |
<Code Type="Fragment" Language="cs"> |
| 539 |
<![CDATA[ |
| 540 |
OutVarDefs = Regex.Matches(QtVars, |
| 541 |
@"\s*(\w+)\s*(?:;|=\s*(\w*)\s*(?:\/((?:\\.|[^;\/])*)\/((?:\\.|[^;\/])*)\/)?)?") |
| 542 |
.Cast<Match>() |
| 543 |
.Where((Match x) => x.Groups.Count > 4 && !string.IsNullOrEmpty(x.Groups[1].Value)) |
| 544 |
.Select((Match x) => x.Groups |
| 545 |
.Cast<Group>() |
| 546 |
.Select((Group y) => !string.IsNullOrEmpty(y.Value) ? y.Value : null) |
| 547 |
.ToArray()) |
| 548 |
.Select((string[] x) => new TaskItem(x[1], |
| 549 |
new Dictionary<string,string> |
| 550 |
{ |
| 551 |
{ "Name" , x[2] ?? x[1] }, |
| 552 |
{ "Pattern" , x[3] ?? ".*" }, |
| 553 |
{ "Value" , x[4] ?? "$0" }, |
| 554 |
})) |
| 555 |
.ToArray(); |
| 556 |
]]> |
| 557 |
</Code> |
| 558 |
</Task> |
| 559 |
</UsingTask> |
| 560 |
|
| 561 |
<!-- |
| 562 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 563 |
/// TASK GetVarsFromMakefile |
| 564 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 565 |
// |
| 566 |
// --> |
| 567 |
<UsingTask TaskName="GetVarsFromMakefile" |
| 568 |
TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> |
| 569 |
<ParameterGroup> |
| 570 |
<Makefile Required="true" |
| 571 |
ParameterType="System.String"/> |
| 572 |
<VarDefs Required="false" |
| 573 |
ParameterType="Microsoft.Build.Framework.ITaskItem[]"/> |
| 574 |
<ExcludeValues Required="true" |
| 575 |
ParameterType="System.String[]"/> |
| 576 |
<OutVars Output="true" |
| 577 |
ParameterType="Microsoft.Build.Framework.ITaskItem[]"/> |
| 578 |
</ParameterGroup> |
| 579 |
<Task> |
| 580 |
<Using Namespace="System"/> |
| 581 |
<Using Namespace="System.Text"/> |
| 582 |
<Using Namespace="System.Text.RegularExpressions"/> |
| 583 |
<Using Namespace="System.IO"/> |
| 584 |
<Code Type="Fragment" Language="cs"> |
| 585 |
<![CDATA[ |
| 586 |
var makefileVars = Regex.Matches( |
| 587 |
File.ReadAllText(Makefile), |
| 588 |
@"^(\w+)[^\=\r\n\S]*\=[^\r\n\S]*([^\r\n]+)[\r\n]", |
| 589 |
RegexOptions.Multiline).Cast<Match>() |
| 590 |
.Where(x => x.Groups.Count > 2 && x.Groups[1].Success && x.Groups[2].Success |
| 591 |
&& !string.IsNullOrEmpty(x.Groups[1].Value)) |
| 592 |
.GroupBy(x => x.Groups[1].Value) |
| 593 |
.ToDictionary(g => g.Key, g => g.Last().Groups[2].Value); |
| 594 |
OutVars = VarDefs |
| 595 |
.Where(x => makefileVars.ContainsKey(x.GetMetadata("Name"))) |
| 596 |
.Select(x => new TaskItem(x.ItemSpec, new Dictionary<string,string> |
| 597 |
{ { |
| 598 |
"Value", |
| 599 |
string.Join(";", Regex |
| 600 |
.Matches(makefileVars[x.GetMetadata("Name")], x.GetMetadata("Pattern")) |
| 601 |
.Cast<Match>() |
| 602 |
.Select(y => Regex |
| 603 |
.Replace(y.Value, x.GetMetadata("Pattern"), x.GetMetadata("Value"))) |
| 604 |
.Where(y => !string.IsNullOrEmpty(y) |
| 605 |
&& !ExcludeValues.Contains(y, |
| 606 |
StringComparer.InvariantCultureIgnoreCase)) |
| 607 |
.ToHashSet()) |
| 608 |
} })) |
| 609 |
.Where(x => !string.IsNullOrEmpty(x.GetMetadata("Value"))) |
| 610 |
.ToArray(); |
| 611 |
]]> |
| 612 |
</Code> |
| 613 |
</Task> |
| 614 |
</UsingTask> |
| 615 |
|
| 616 |
<!-- |
| 617 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 618 |
/// TASK Flatten |
| 619 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 620 |
// Destructure items into a "flat" list of metadata. The output is a list of (Name, Value) pairs, |
| 621 |
// each corresponding to one item metadata. Semi-colon-separated lists will also expand to many |
| 622 |
// items in the output list, with the metadata name shared among them. |
| 623 |
// Example: |
| 624 |
// INPUT: |
| 625 |
// <QtMoc> |
| 626 |
// <InputFile>foo.h</InputFile> |
| 627 |
// <IncludePath>C:\FOO;D:\BAR</IncludePath> |
| 628 |
// </QtMoc> |
| 629 |
// OUTPUT: |
| 630 |
// <Result> |
| 631 |
// <Name>InputFile</Name> |
| 632 |
// <Value>foo.h</Value> |
| 633 |
// </Result> |
| 634 |
// <Result> |
| 635 |
// <Name>IncludePath</Name> |
| 636 |
// <Value>C:\FOO</Value> |
| 637 |
// </Result> |
| 638 |
// <Result> |
| 639 |
// <Name>IncludePath</Name> |
| 640 |
// <Value>D:\BAR</Value> |
| 641 |
// </Result> |
| 642 |
// Parameters: |
| 643 |
// in ITaskItem[] Items: list of items to flatten |
| 644 |
// in string[] Metadata: names of metadata to look for; omit to include all metadata |
| 645 |
// out ITaskItem[] Result: list of metadata from all items |
| 646 |
// --> |
| 647 |
<UsingTask TaskName="Flatten" |
| 648 |
TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> |
| 649 |
<ParameterGroup> |
| 650 |
<Items ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> |
| 651 |
<Metadata ParameterType="System.String[]" Required="false" /> |
| 652 |
<Result ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true" /> |
| 653 |
</ParameterGroup> |
| 654 |
<Task> |
| 655 |
<Using Namespace="System"/> |
| 656 |
<Using Namespace="System.IO"/> |
| 657 |
<Using Namespace="System.Diagnostics"/> |
| 658 |
<Using Namespace="System.Collections.Generic"/> |
| 659 |
<Code Type="Fragment" Language="cs"> |
| 660 |
<![CDATA[ |
| 661 |
Result = new ITaskItem[] { }; |
| 662 |
var reserved = new HashSet<string> |
| 663 |
{ |
| 664 |
"AccessedTime", "CreatedTime", "DefiningProjectDirectory", |
| 665 |
"DefiningProjectExtension", "DefiningProjectFullPath", "DefiningProjectName", |
| 666 |
"Directory", "Extension", "Filename", "FullPath", "Identity", "ModifiedTime", |
| 667 |
"RecursiveDir", "RelativeDir", "RootDir", |
| 668 |
}; |
| 669 |
if (Metadata == null) |
| 670 |
Metadata = new string[0]; |
| 671 |
var requestedNames = new HashSet<string>(Metadata.Where(x => !string.IsNullOrEmpty(x))); |
| 672 |
var newItems = new List<ITaskItem>(); |
| 673 |
foreach (var item in Items) { |
| 674 |
var itemName = item.ItemSpec; |
| 675 |
var names = item.MetadataNames.Cast<string>().Where(x => !reserved.Contains(x) |
| 676 |
&& (!requestedNames.Any() || requestedNames.Contains(x))); |
| 677 |
foreach (string name in names) { |
| 678 |
var values = item.GetMetadata(name).Split(';'); |
| 679 |
foreach (string value in values.Where(v => !string.IsNullOrEmpty(v))) { |
| 680 |
newItems.Add(new TaskItem(string.Format("{0}={1}", name, value), |
| 681 |
new Dictionary<string, string> |
| 682 |
{ |
| 683 |
{ "Item", itemName }, |
| 684 |
{ "Name", name }, |
| 685 |
{ "Value", value }, |
| 686 |
})); |
| 687 |
} |
| 688 |
} |
| 689 |
} |
| 690 |
Result = newItems.ToArray(); |
| 691 |
]]> |
| 692 |
</Code> |
| 693 |
</Task> |
| 694 |
</UsingTask> |
| 695 |
|
| 696 |
<!-- |
| 697 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 698 |
/// TASK HostTranslatePaths |
| 699 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 700 |
// Translate local (Windows) paths to build host paths. This could be a Linux host for cross |
| 701 |
// compilation, or a simple copy (i.e. "no-op") when building in Windows. |
| 702 |
// Input and output items are in the form: |
| 703 |
// <...> |
| 704 |
// <Item>...</Item> |
| 705 |
// <Name>...</Name> |
| 706 |
// <Value>...</Value> |
| 707 |
// </...> |
| 708 |
// where <Item> is the local path, <Name> is a filter criteria identifier matched with the Names |
| 709 |
// parameter, and <Value> is set to the host path in output items (for input items <Value> must |
| 710 |
// be equal to <Item>). |
| 711 |
// Parameters: |
| 712 |
// in ITaskItem[] Items: input items with local paths |
| 713 |
// in string[] Names: filter criteria; unmatched items will simply be copied (i.e. no-op) |
| 714 |
// out ITaskItem[] Result: output items with translated host paths |
| 715 |
// --> |
| 716 |
<!--// Linux build over WSL --> |
| 717 |
<UsingTask TaskName="HostTranslatePaths" TaskFactory="CodeTaskFactory" |
| 718 |
Condition="'$(ApplicationType)' == 'Linux' AND '$(PlatformToolset)' == 'WSL_1_0'" |
| 719 |
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> |
| 720 |
<ParameterGroup> |
| 721 |
<Items ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> |
| 722 |
<Names ParameterType="System.String[]" Required="false" /> |
| 723 |
<Result ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true" /> |
| 724 |
</ParameterGroup> |
| 725 |
<Task> |
| 726 |
<Reference Include="$(VCTargetsPath)\Application Type\Linux\1.0\liblinux.dll"/> |
| 727 |
<Using Namespace="System.IO"/> |
| 728 |
<Using Namespace="liblinux"/> |
| 729 |
<Using Namespace="liblinux.IO"/> |
| 730 |
<Code Type="Fragment" Language="cs"> |
| 731 |
<![CDATA[ |
| 732 |
Result = new ITaskItem[] { }; |
| 733 |
var newItems = new List<ITaskItem>(); |
| 734 |
foreach (var item in Items) { |
| 735 |
string itemName = item.GetMetadata("Name"); |
| 736 |
string itemValue = item.GetMetadata("Value"); |
| 737 |
if (Names.Contains(itemName)) { |
| 738 |
if (Path.IsPathRooted(itemValue) && !itemValue.StartsWith("/")) |
| 739 |
itemValue = PathUtils.TranslateWindowsPathToWSLPath(itemValue); |
| 740 |
else |
| 741 |
itemValue = itemValue.Replace(@"\", "/"); |
| 742 |
} |
| 743 |
newItems.Add(new TaskItem(item.ItemSpec, |
| 744 |
new Dictionary<string, string> |
| 745 |
{ |
| 746 |
{ "Item", item.GetMetadata("Item") }, |
| 747 |
{ "Name", itemName }, |
| 748 |
{ "Value", itemValue }, |
| 749 |
})); |
| 750 |
} |
| 751 |
Result = newItems.ToArray(); |
| 752 |
]]> |
| 753 |
</Code> |
| 754 |
</Task> |
| 755 |
</UsingTask> |
| 756 |
<!--// Linux build over SSH --> |
| 757 |
<UsingTask TaskName="HostTranslatePaths" TaskFactory="CodeTaskFactory" |
| 758 |
Condition="'$(ApplicationType)' == 'Linux' AND '$(PlatformToolset)' != 'WSL_1_0'" |
| 759 |
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> |
| 760 |
<ParameterGroup> |
| 761 |
<Items ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> |
| 762 |
<Names ParameterType="System.String[]" Required="false" /> |
| 763 |
<Result ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true" /> |
| 764 |
</ParameterGroup> |
| 765 |
<Task> |
| 766 |
<Reference |
| 767 |
Include="$(VCTargetsPath)\Application Type\Linux\1.0\Microsoft.Build.Linux.Tasks.dll"/> |
| 768 |
<Code Type="Fragment" Language="cs"> |
| 769 |
<![CDATA[ |
| 770 |
Result = new ITaskItem[] { }; |
| 771 |
var newItems = new List<ITaskItem>(); |
| 772 |
foreach (var item in Items) { |
| 773 |
string itemName = item.GetMetadata("Name"); |
| 774 |
string itemValue = item.GetMetadata("Value"); |
| 775 |
if (Names.Contains(itemName)) { |
| 776 |
if (Path.IsPathRooted(itemValue) && !itemValue.StartsWith("/")) { |
| 777 |
var projectdir = new Uri(@"$(ProjectDir)"); |
| 778 |
var itemFileName = Path.GetFileName(itemValue); |
| 779 |
var itemDirName = Path.GetFullPath(Path.GetDirectoryName(itemValue)); |
| 780 |
if (!itemDirName.EndsWith(@"\")) |
| 781 |
itemDirName += @"\"; |
| 782 |
var itemDir = new Uri(itemDirName); |
| 783 |
if (projectdir.IsBaseOf(itemDir)) { |
| 784 |
itemValue = projectdir.MakeRelativeUri(itemDir).OriginalString |
| 785 |
+ itemFileName; |
| 786 |
} else { |
| 787 |
Log.LogWarning("Unable to translate path: {0}", itemValue); |
| 788 |
} |
| 789 |
} else { |
| 790 |
itemValue = itemValue.Replace(@"\", "/"); |
| 791 |
} |
| 792 |
} |
| 793 |
newItems.Add(new TaskItem(item.ItemSpec, |
| 794 |
new Dictionary<string, string> |
| 795 |
{ |
| 796 |
{ "Item", item.GetMetadata("Item") }, |
| 797 |
{ "Name", itemName }, |
| 798 |
{ "Value", itemValue }, |
| 799 |
})); |
| 800 |
} |
| 801 |
Result = newItems.ToArray(); |
| 802 |
]]> |
| 803 |
</Code> |
| 804 |
</Task> |
| 805 |
</UsingTask> |
| 806 |
<!--// Local (Windows) build --> |
| 807 |
<UsingTask TaskName="HostTranslatePaths" TaskFactory="CodeTaskFactory" |
| 808 |
Condition="'$(ApplicationType)' != 'Linux'" |
| 809 |
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> |
| 810 |
<ParameterGroup> |
| 811 |
<Items ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> |
| 812 |
<Names ParameterType="System.String[]" Required="false" /> |
| 813 |
<Result ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true" /> |
| 814 |
</ParameterGroup> |
| 815 |
<Task> |
| 816 |
<Code Type="Fragment" Language="cs"> |
| 817 |
<![CDATA[ |
| 818 |
Result = Items.ToArray(); |
| 819 |
]]> |
| 820 |
</Code> |
| 821 |
</Task> |
| 822 |
</UsingTask> |
| 823 |
|
| 824 |
<!-- |
| 825 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 826 |
/// TASK HostExec |
| 827 |
///////////////////////////////////////////////////////////////////////////////////////////////// |
| 828 |
// Run command in build host. |
| 829 |
// Parameters: |
| 830 |
// in string Command: Command to run on the build host |
| 831 |
// in string RedirectStdOut: Path to file to receive redirected output messages |
| 832 |
// * can be NUL to discard messages |
| 833 |
// in string RedirectStdErr: Path to file to receive redirected error messages |
| 834 |
// * can be NUL to discard messages |
| 835 |
// * can be STDOUT to apply the same redirection as output messages |
| 836 |
// in string WorkingDirectory: Path to directory where command will be run |
| 837 |
// in ITaskItem[] Inputs: List of local -> host path mappings for command inputs |
| 838 |
// * item format: cf. HostTranslatePaths task |
| 839 |
// in ITaskItem[] Outputs: List of host -> local path mappings for command outputs |
| 840 |
// * item format: cf. HostTranslatePaths task |
| 841 |
// in string RemoteTarget: Set by ResolveRemoteDir in SSH mode; null otherwise |
| 842 |
// in string RemoteProjectDir: Set by ResolveRemoteDir in SSH mode; null otherwise |
| 843 |
// in bool IgnoreExitCode: Set flag to disable build error if command failed |
| 844 |
// out int ExitCode: status code at command exit |
| 845 |
// --> |
| 846 |
<!--// Linux build over WSL --> |
| 847 |
<UsingTask TaskName="HostExec" TaskFactory="CodeTaskFactory" |
| 848 |
Condition="'$(ApplicationType)' == 'Linux' AND '$(PlatformToolset)' == 'WSL_1_0'" |
| 849 |
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> |
| 850 |
<ParameterGroup> |
| 851 |
<!--IN--> |
| 852 |
<Message ParameterType="System.String" Required="false" /> |
| 853 |
<Command ParameterType="System.String" Required="true" /> |
| 854 |
<RedirectStdOut ParameterType="System.String" Required="false" /> |
| 855 |
<RedirectStdErr ParameterType="System.String" Required="false" /> |
| 856 |
<WorkingDirectory ParameterType="System.String" Required="false" /> |
| 857 |
<Inputs ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="false" /> |
| 858 |
<Outputs ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="false" /> |
| 859 |
<RemoteTarget ParameterType="System.String" Required="false" /> |
| 860 |
<RemoteProjectDir ParameterType="System.String" Required="false" /> |
| 861 |
<IgnoreExitCode ParameterType="System.Boolean" Required="false" /> |
| 862 |
<!--OUT--> |
| 863 |
<ExitCode ParameterType="System.Int32" Output="true" /> |
| 864 |
</ParameterGroup> |
| 865 |
<Task> |
| 866 |
<Reference |
| 867 |
Include="$(VCTargetsPath)\Application Type\Linux\1.0\Microsoft.Build.Linux.Tasks.dll"/> |
| 868 |
<Code Type="Fragment" Language="cs"> |
| 869 |
<![CDATA[ |
| 870 |
if (!string.IsNullOrEmpty(Message)) |
| 871 |
Log.LogMessage(MessageImportance.High, Message); |
| 872 |
Command = "(" + Command + ")"; |
| 873 |
if (RedirectStdOut == "NUL" || RedirectStdOut == "/dev/null") |
| 874 |
Command += " 1> /dev/null"; |
| 875 |
else if (!string.IsNullOrEmpty(RedirectStdOut)) |
| 876 |
Command += " 1> " + RedirectStdOut; |
| 877 |
if (RedirectStdErr == "NUL" || RedirectStdErr == "/dev/null") |
| 878 |
Command += " 2> /dev/null"; |
| 879 |
else if (RedirectStdErr == "STDOUT") |
| 880 |
Command += " 2>&1"; |
| 881 |
else if (!string.IsNullOrEmpty(RedirectStdErr)) |
| 882 |
Command += " 2> " + RedirectStdErr; |
| 883 |
|
| 884 |
var createDirs = new List<string>(); |
| 885 |
if (Inputs != null) { |
| 886 |
createDirs.AddRange(Inputs |
| 887 |
.Select(x => string.Format("\x24(dirname {0})", x.GetMetadata("Value")))); |
| 888 |
} |
| 889 |
if (Outputs != null) { |
| 890 |
createDirs.AddRange(Outputs |
| 891 |
.Select(x => string.Format("\x24(dirname {0})", x.GetMetadata("Value")))); |
| 892 |
} |
| 893 |
if (!string.IsNullOrEmpty(WorkingDirectory)) { |
| 894 |
createDirs.Add(WorkingDirectory); |
| 895 |
Command = string.Format("cd {0}; {1}", WorkingDirectory, Command); |
| 896 |
} |
| 897 |
if (createDirs.Any()) { |
| 898 |
Command = string.Format("{0}; {1}", |
| 899 |
string.Join("; ", createDirs.Select(x => string.Format("mkdir -p {0}", x))), |
| 900 |
Command); |
| 901 |
} |
| 902 |
|
| 903 |
var taskExec = new Microsoft.Build.Linux.WSL.Tasks.ExecuteCommand() |
| 904 |
{ |
| 905 |
BuildEngine = BuildEngine, |
| 906 |
HostObject = HostObject, |
| 907 |
ProjectDir = @"$(ProjectDir)", |
| 908 |
IntermediateDir = @"$(IntDir)", |
| 909 |
WSLPath = @"$(WSLPath)", |
| 910 |
Command = Command, |
| 911 |
}; |
| 912 |
Log.LogMessage("\r\n==== HostExec: Microsoft.Build.Linux.WSL.Tasks.ExecuteCommand"); |
| 913 |
Log.LogMessage("ProjectDir: {0}", taskExec.ProjectDir); |
| 914 |
Log.LogMessage("IntermediateDir: {0}", taskExec.IntermediateDir); |
| 915 |
Log.LogMessage("WSLPath: {0}", taskExec.WSLPath); |
| 916 |
Log.LogMessage("Command: {0}", taskExec.Command); |
| 917 |
|
| 918 |
bool ok = taskExec.Execute(); |
| 919 |
Log.LogMessage("== {0} ExitCode: {1}\r\n", ok ? "OK" : "FAIL", taskExec.ExitCode); |
| 920 |
|
| 921 |
ExitCode = taskExec.ExitCode; |
| 922 |
if (!ok && !IgnoreExitCode) { |
| 923 |
Log.LogError("Host command failed."); |
| 924 |
return false; |
| 925 |
} |
| 926 |
]]> |
| 927 |
</Code> |
| 928 |
</Task> |
| 929 |
</UsingTask> |
| 930 |
<!--// Linux build over SSH --> |
| 931 |
<UsingTask TaskName="HostExec" TaskFactory="CodeTaskFactory" |
| 932 |
Condition="'$(ApplicationType)' == 'Linux' AND '$(PlatformToolset)' != 'WSL_1_0'" |
| 933 |
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> |
| 934 |
<ParameterGroup> |
| 935 |
<!--IN--> |
| 936 |
<Message ParameterType="System.String" Required="false" /> |
| 937 |
<Command ParameterType="System.String" Required="true" /> |
| 938 |
<RedirectStdOut ParameterType="System.String" Required="false" /> |
| 939 |
<RedirectStdErr ParameterType="System.String" Required="false" /> |
| 940 |
<WorkingDirectory ParameterType="System.String" Required="false" /> |
| 941 |
<Inputs ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="false" /> |
| 942 |
<Outputs ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="false" /> |
| 943 |
<RemoteTarget ParameterType="System.String" Required="false" /> |
| 944 |
<RemoteProjectDir ParameterType="System.String" Required="false" /> |
| 945 |
<IgnoreExitCode ParameterType="System.Boolean" Required="false" /> |
| 946 |
<!--OUT--> |
| 947 |
<ExitCode ParameterType="System.Int32" Output="true" /> |
| 948 |
</ParameterGroup> |
| 949 |
<Task> |
| 950 |
<Reference |
| 951 |
Include="$(VCTargetsPath)\Application Type\Linux\1.0\Microsoft.Build.Linux.Tasks.dll"/> |
| 952 |
<Code Type="Fragment" Language="cs"> |
| 953 |
<![CDATA[ |
| 954 |
if (!string.IsNullOrEmpty(Message)) |
| 955 |
Log.LogMessage(MessageImportance.High, Message); |
| 956 |
var createDirs = new List<string> |
| 957 |
{ |
| 958 |
string.Format("{0}/{1}", RemoteProjectDir, WorkingDirectory) |
| 959 |
}; |
| 960 |
|
| 961 |
var localFilesToCopyRemotelyMapping = new string[0]; |
| 962 |
if (Inputs != null) { |
| 963 |
localFilesToCopyRemotelyMapping = Inputs |
| 964 |
.Select(x => string.Format(@"{0}:={1}/{2}", |
| 965 |
x.GetMetadata("Item"), |
| 966 |
RemoteProjectDir, |
| 967 |
x.GetMetadata("Value"))) |
| 968 |
.ToArray(); |
| 969 |
createDirs.AddRange(Inputs |
| 970 |
.Select(x => string.Format("\x24(dirname {0})", x.GetMetadata("Value")))); |
| 971 |
} |
| 972 |
|
| 973 |
var remoteFilesToCopyLocallyMapping = new string[0]; |
| 974 |
if (Outputs != null) { |
| 975 |
remoteFilesToCopyLocallyMapping = Outputs |
| 976 |
.Select(x => string.Format(@"{0}/{1}:={2}", |
| 977 |
RemoteProjectDir, |
| 978 |
x.GetMetadata("Value"), |
| 979 |
x.GetMetadata("Item"))) |
| 980 |
.ToArray(); |
| 981 |
createDirs.AddRange(Outputs |
| 982 |
.Select(x => string.Format("\x24(dirname {0})", x.GetMetadata("Value")))); |
| 983 |
} |
| 984 |
|
| 985 |
Command = "(" + Command + ")"; |
| 986 |
if (RedirectStdOut == "NUL" || RedirectStdOut == "/dev/null") |
| 987 |
Command += " 1> /dev/null"; |
| 988 |
else if (!string.IsNullOrEmpty(RedirectStdOut)) |
| 989 |
Command += " 1> " + RedirectStdOut; |
| 990 |
if (RedirectStdErr == "NUL" || RedirectStdErr == "/dev/null") |
| 991 |
Command += " 2> /dev/null"; |
| 992 |
else if (RedirectStdErr == "STDOUT") |
| 993 |
Command += " 2>&1"; |
| 994 |
else if (!string.IsNullOrEmpty(RedirectStdErr)) |
| 995 |
Command += " 2> " + RedirectStdErr; |
| 996 |
Command = string.Format("cd {0}/{1}; {2}", RemoteProjectDir, WorkingDirectory, Command); |
| 997 |
|
| 998 |
var taskCopyFiles = new Microsoft.Build.Linux.Tasks.Execute() |
| 999 |
{ |
| 1000 |
BuildEngine = BuildEngine, |
| 1001 |
HostObject = HostObject, |
| 1002 |
ProjectDir = @"$(ProjectDir)", |
| 1003 |
IntermediateDir = @"$(IntDir)", |
| 1004 |
RemoteTarget = RemoteTarget, |
| 1005 |
RemoteProjectDir = RemoteProjectDir, |
| 1006 |
Command = string.Join("; ", createDirs.Select(x => string.Format("mkdir -p {0}", x))), |
| 1007 |
LocalFilesToCopyRemotelyMapping = localFilesToCopyRemotelyMapping, |
| 1008 |
}; |
| 1009 |
var taskExec = new Microsoft.Build.Linux.Tasks.Execute() |
| 1010 |
{ |
| 1011 |
BuildEngine = BuildEngine, |
| 1012 |
HostObject = HostObject, |
| 1013 |
ProjectDir = @"$(ProjectDir)", |
| 1014 |
IntermediateDir = @"$(IntDir)", |
| 1015 |
RemoteTarget = RemoteTarget, |
| 1016 |
RemoteProjectDir = RemoteProjectDir, |
| 1017 |
Command = Command, |
| 1018 |
RemoteFilesToCopyLocallyMapping = remoteFilesToCopyLocallyMapping, |
| 1019 |
}; |
| 1020 |
|
| 1021 |
Log.LogMessage("\r\n==== HostExec: Microsoft.Build.Linux.Tasks.Execute"); |
| 1022 |
Log.LogMessage("ProjectDir: {0}", taskExec.ProjectDir); |
| 1023 |
Log.LogMessage("IntermediateDir: {0}", taskExec.IntermediateDir); |
| 1024 |
Log.LogMessage("RemoteTarget: {0}", taskExec.RemoteTarget); |
| 1025 |
Log.LogMessage("RemoteProjectDir: {0}", taskExec.RemoteProjectDir); |
| 1026 |
if (taskExec.LocalFilesToCopyRemotelyMapping.Any()) |
| 1027 |
Log.LogMessage("LocalFilesToCopyRemotelyMapping: {0}", |
| 1028 |
taskExec.LocalFilesToCopyRemotelyMapping); |
| 1029 |
if (taskExec.RemoteFilesToCopyLocallyMapping.Any()) |
| 1030 |
Log.LogMessage("RemoteFilesToCopyLocallyMapping: {0}", |
| 1031 |
taskExec.RemoteFilesToCopyLocallyMapping); |
| 1032 |
Log.LogMessage("CreateDirs: {0}", taskCopyFiles.Command); |
| 1033 |
Log.LogMessage("Command: {0}", taskExec.Command); |
| 1034 |
|
| 1035 |
if (!taskCopyFiles.ExecuteTool()) |
| 1036 |
return false; |
| 1037 |
bool ok = taskExec.ExecuteTool(); |
| 1038 |
Log.LogMessage("== {0} ExitCode: {1}\r\n", ok ? "OK" : "FAIL", taskExec.ExitCode); |
| 1039 |
|
| 1040 |
ExitCode = taskExec.ExitCode; |
| 1041 |
if (!ok && !IgnoreExitCode) { |
| 1042 |
Log.LogError("Host command failed."); |
| 1043 |
return false; |
| 1044 |
} |
| 1045 |
]]> |
| 1046 |
</Code> |
| 1047 |
</Task> |
| 1048 |
</UsingTask> |
| 1049 |
<!--// Local (Windows) build --> |
| 1050 |
<UsingTask TaskName="HostExec" TaskFactory="CodeTaskFactory" |
| 1051 |
Condition="'$(ApplicationType)' != 'Linux'" |
| 1052 |
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> |
| 1053 |
<ParameterGroup> |
| 1054 |
<!--IN--> |
| 1055 |
<Message ParameterType="System.String" Required="false" /> |
| 1056 |
<Command ParameterType="System.String" Required="true" /> |
| 1057 |
<RedirectStdOut ParameterType="System.String" Required="false" /> |
| 1058 |
<RedirectStdErr ParameterType="System.String" Required="false" /> |
| 1059 |
<WorkingDirectory ParameterType="System.String" Required="false" /> |
| 1060 |
<Inputs ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="false" /> |
| 1061 |
<Outputs ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="false" /> |
| 1062 |
<RemoteTarget ParameterType="System.String" Required="false" /> |
| 1063 |
<RemoteProjectDir ParameterType="System.String" Required="false" /> |
| 1064 |
<IgnoreExitCode ParameterType="System.Boolean" Required="false" /> |
| 1065 |
<!--OUT--> |
| 1066 |
<ExitCode ParameterType="System.Int32" Output="true" /> |
| 1067 |
</ParameterGroup> |
| 1068 |
<Task> |
| 1069 |
<Reference Include="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"/> |
| 1070 |
<Reference Include="$(MSBuildToolsPath)\Microsoft.Build.Utilities.Core.dll"/> |
| 1071 |
<Code Type="Fragment" Language="cs"> |
| 1072 |
<![CDATA[ |
| 1073 |
if (!string.IsNullOrEmpty(Message)) |
| 1074 |
Log.LogMessage(MessageImportance.High, Message); |
| 1075 |
Command = "(" + Command + ")"; |
| 1076 |
if (RedirectStdOut == "NUL" || RedirectStdOut == "/dev/null") |
| 1077 |
Command += " 1> NUL"; |
| 1078 |
else if (!string.IsNullOrEmpty(RedirectStdOut)) |
| 1079 |
Command += " 1> " + RedirectStdOut; |
| 1080 |
if (RedirectStdErr == "NUL" || RedirectStdErr == "/dev/null") |
| 1081 |
Command += " 2> NUL"; |
| 1082 |
else if (RedirectStdErr == "STDOUT") |
| 1083 |
Command += " 2>&1"; |
| 1084 |
else if (!string.IsNullOrEmpty(RedirectStdErr)) |
| 1085 |
Command += " 2> " + RedirectStdErr; |
| 1086 |
|
| 1087 |
var taskExec = new Microsoft.Build.Tasks.Exec() |
| 1088 |
{ |
| 1089 |
BuildEngine = BuildEngine, |
| 1090 |
HostObject = HostObject, |
| 1091 |
WorkingDirectory = WorkingDirectory, |
| 1092 |
Command = Command, |
| 1093 |
IgnoreExitCode = IgnoreExitCode, |
| 1094 |
}; |
| 1095 |
|
| 1096 |
Log.LogMessage("\r\n==== HostExec: Microsoft.Build.Tasks.Exec"); |
| 1097 |
Log.LogMessage("WorkingDirectory: {0}", taskExec.WorkingDirectory); |
| 1098 |
Log.LogMessage("Command: {0}", taskExec.Command); |
| 1099 |
|
| 1100 |
bool ok = taskExec.Execute(); |
| 1101 |
Log.LogMessage("== {0} ExitCode: {1}\r\n", ok ? "OK" : "FAIL", taskExec.ExitCode); |
| 1102 |
|
| 1103 |
ExitCode = taskExec.ExitCode; |
| 1104 |
if (!ok) |
| 1105 |
return false; |
| 1106 |
]]> |
| 1107 |
</Code> |
| 1108 |
</Task> |
| 1109 |
</UsingTask> |
| 1110 |
</Project> |