| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. |
| 2 | |
| 3 | namespace WixToolset.BuildTasks |
| 4 | { |
| 5 | using System; |
| 6 | using System.Collections.Generic; |
| 7 | using System.Linq; |
| 8 | using Microsoft.Build.Framework; |
| 9 | using Microsoft.Build.Utilities; |
| 10 | |
| 11 | /// <summary> |
| 12 | /// Read the contents of the tracking file produced by the build command. |
| 13 | /// </summary> |
| 14 | public class ReadTracking : Task |
| 15 | { |
| 16 | private const string TrackedTypeMetadataName = "TrackedType"; |
| 17 | private static readonly char[] TrackedLineTypePathSeparator = new[] { '\t' }; |
| 18 | |
| 19 | /// <summary> |
| 20 | /// The path to the tracking file. |
| 21 | /// </summary> |
| 22 | [Required] |
| 23 | public ITaskItem File { get; set; } |
| 24 | |
| 25 | /// <summary> |
| 26 | /// All tracked files. |
| 27 | /// </summary> |
| 28 | [Output] |
| 29 | public ITaskItem[] All { get; private set; } |
| 30 | |
| 31 | /// <summary> |
| 32 | /// The union of tracked built outputs. |
| 33 | /// </summary> |
| 34 | [Output] |
| 35 | public ITaskItem[] BuiltOutputs { get; private set; } |
| 36 | |
| 37 | /// <summary> |
| 38 | /// The tracked content built outputs. |
| 39 | /// </summary> |
| 40 | [Output] |
| 41 | public ITaskItem[] BuiltContentOutputs { get; private set; } |
| 42 | |
| 43 | /// <summary> |
| 44 | /// The tracked target built outputs. |
| 45 | /// </summary> |
| 46 | [Output] |
| 47 | public ITaskItem[] BuiltTargetOutputs { get; private set; } |
| 48 | |
| 49 | /// <summary> |
| 50 | /// The tracked pdb built outputs. |
| 51 | /// </summary> |
| 52 | [Output] |
| 53 | public ITaskItem[] BuiltPdbOutputs { get; private set; } |
| 54 | |
| 55 | /// <summary> |
| 56 | /// The tracked copied outputs. |
| 57 | /// </summary> |
| 58 | [Output] |
| 59 | public ITaskItem[] CopiedOutputs { get; private set; } |
| 60 | |
| 61 | /// <summary> |
| 62 | /// The tracked inputs. |
| 63 | /// </summary> |
| 64 | [Output] |
| 65 | public ITaskItem[] Inputs { get; private set; } |
| 66 | |
| 67 | /// <summary> |
| 68 | /// The union of all tracked outputs. |
| 69 | /// </summary> |
| 70 | [Output] |
| 71 | public ITaskItem[] Outputs { get; private set; } |
| 72 | |
| 73 | /// <summary> |
| 74 | /// Gets a complete list of external cabs referenced by the given installer database file. |
| 75 | /// </summary> |
| 76 | /// <returns>True upon completion of the task execution.</returns> |
| 77 | public override bool Execute() |
| 78 | { |
| 79 | var all = new List<ITaskItem>(); |
| 80 | var path = this.File.ItemSpec; |
| 81 | |
| 82 | if (System.IO.File.Exists(path)) |
| 83 | { |
| 84 | var lines = System.IO.File.ReadAllLines(path); |
| 85 | |
| 86 | foreach (var line in lines) |
| 87 | { |
| 88 | var split = line.Split(TrackedLineTypePathSeparator, 2, StringSplitOptions.RemoveEmptyEntries); |
| 89 | |
| 90 | if (split.Length == 2) |
| 91 | { |
| 92 | all.Add(new TaskItem(split[1], new Dictionary<string, string>() { [TrackedTypeMetadataName] = split[0] })); |
| 93 | } |
| 94 | else |
| 95 | { |
| 96 | this.Log.LogError("Failed to parse tracked line: {0}", line); |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | this.All = all.ToArray(); |
| 102 | this.BuiltContentOutputs = all.Where(t => FilterByTrackedType(t, "BuiltContentOutput")).ToArray(); |
| 103 | this.BuiltTargetOutputs = all.Where(t => FilterByTrackedType(t, "BuiltTargetOutput")).ToArray(); |
| 104 | this.BuiltPdbOutputs = all.Where(t => FilterByTrackedType(t, "BuiltPdbOutput")).ToArray(); |
| 105 | this.CopiedOutputs = all.Where(t => FilterByTrackedType(t, "CopiedOutput")).ToArray(); |
| 106 | this.Inputs = all.Where(t => FilterByTrackedType(t, "Input")).ToArray(); |
| 107 | |
| 108 | this.BuiltOutputs = this.BuiltContentOutputs.Concat(this.BuiltTargetOutputs).Concat(this.BuiltPdbOutputs).ToArray(); |
| 109 | this.Outputs = this.BuiltOutputs.Concat(this.CopiedOutputs).ToArray(); |
| 110 | |
| 111 | return true; |
| 112 | } |
| 113 | |
| 114 | private static bool FilterByTrackedType(ITaskItem item, string type) |
| 115 | { |
| 116 | return item.GetMetadata(TrackedTypeMetadataName).Equals(type, StringComparison.OrdinalIgnoreCase); |
| 117 | } |
| 118 | } |
| 119 | } |