|
7 | 7 | TaskFactory="RoslynCodeTaskFactory"
|
8 | 8 | AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
|
9 | 9 | <ParameterGroup>
|
10 |
| - <FraggerDirectory ParameterType="System.String" Required="true" /> |
| 10 | + <FraggerPrimaryPackage ParameterType="System.String" Required="true" /> |
11 | 11 | </ParameterGroup>
|
12 | 12 | <Task>
|
13 | 13 | <Using Namespace="System"/>
|
14 | 14 | <Using Namespace="System.IO"/>
|
15 | 15 | <Code Type="Fragment" Language="cs">
|
16 | 16 | <![CDATA[
|
17 |
| - if (Directory.Exists(FraggerDirectory)) |
| 17 | + if (Directory.Exists(FraggerPrimaryPackage)) |
18 | 18 | {
|
19 |
| - System.Console.WriteLine("Searching for primary files in {0}", FraggerDirectory); |
20 |
| - foreach (var p in Directory.EnumerateFiles(FraggerDirectory, "*.primary", SearchOption.AllDirectories)) |
| 19 | + //System.Console.WriteLine("Searching for primary files in {0}", FraggerPrimaryPackage); |
| 20 | + foreach (var p in Directory.EnumerateFiles(FraggerPrimaryPackage, "*", SearchOption.AllDirectories)) |
21 | 21 | {
|
22 | 22 |
|
23 | 23 | var primaryFile = Path.GetFullPath(p);
|
24 |
| - Console.WriteLine("Found primary file at {0}", primaryFile); |
25 |
| - var restoredFile = primaryFile.Replace(".primary", ""); |
26 |
| -
|
27 |
| - // Find the fragments in the parallel nuget package |
28 |
| - var fragmentFile1 = primaryFile.Replace("-primary", "-fragment1").Replace(".primary", ".fragment1"); |
29 |
| - var fragmentFile2 = primaryFile.Replace("-primary", "-fragment2").Replace(".primary", ".fragment2"); |
30 |
| - var fragmentFile3 = primaryFile.Replace("-primary", "-fragment3").Replace(".primary", ".fragment3"); |
31 |
| -
|
32 |
| - if (!File.Exists(fragmentFile1)) |
33 |
| - throw (new Exception(String.Format("Couldn't find parallel fragment file for multi-package deliver of single massive binary file. Primary file {0} found, expected corresponding fragment at {1}. You may be missing a nuget package reference.", primaryFile, fragmentFile1))); |
34 |
| -
|
35 |
| - if (!File.Exists(fragmentFile2)) |
36 |
| - throw (new Exception(String.Format("Couldn't find parallel fragment file for multi-package deliver of single massive binary file. Primary file {0} found, expected corresponding fragment at {1}. You may be missing a nuget package reference.", primaryFile, fragmentFile2))); |
37 |
| -
|
38 |
| - if (!File.Exists(fragmentFile3)) |
39 |
| - throw (new Exception(String.Format("Couldn't find parallel fragment file for multi-package deliver of single massive binary file. Primary file {0} found, expected corresponding fragment at {1}. You may be missing a nuget package reference.", primaryFile, fragmentFile3))); |
40 |
| -
|
41 |
| - Console.WriteLine("Found fragment file at {0}", fragmentFile1); |
42 |
| - Console.WriteLine("Found fragment file at {0}", fragmentFile2); |
43 |
| - Console.WriteLine("Found fragment file at {0}", fragmentFile3); |
44 |
| - var primaryBytes = File.ReadAllBytes(primaryFile); |
45 |
| - var fragmentBytes1 = File.ReadAllBytes(fragmentFile1); |
46 |
| - var fragmentBytes2 = File.ReadAllBytes(fragmentFile2); |
47 |
| - var fragmentBytes3 = File.ReadAllBytes(fragmentFile3); |
48 |
| -
|
49 |
| - if (primaryBytes.Length != fragmentBytes1.Length) |
50 |
| - throw (new Exception(String.Format("Mismatched file sizes for multi-package deliver of single massive binary file. Primary file {0} found, but the corresponding fragment at {1} has a different size. You may have inconsistent nuget package references.", primaryFile, fragmentFile1))); |
51 |
| -
|
52 |
| - if (primaryBytes.Length != fragmentBytes2.Length) |
53 |
| - throw (new Exception(String.Format("Mismatched file sizes for multi-package deliver of single massive binary file. Primary file {0} found, but the corresponding fragment at {1} has a different size. You may have inconsistent nuget package references.", primaryFile, fragmentFile2))); |
54 |
| -
|
55 |
| - if (primaryBytes.Length != fragmentBytes3.Length) |
56 |
| - throw (new Exception(String.Format("Mismatched file sizes for multi-package deliver of single massive binary file. Primary file {0} found, but the corresponding fragment at {1} has a different size. You may have inconsistent nuget package references.", primaryFile, fragmentFile3))); |
57 |
| -
|
58 |
| - for (int i = 0; i < primaryBytes.Length; i++) |
| 24 | + //Console.WriteLine("Found primary file at {0}", primaryFile); |
| 25 | +
|
| 26 | + // See if there are fragments in the parallel nuget packages. If the primary is |
| 27 | + // some-package-primary\runtimes\....\a.so |
| 28 | + // then the expected fragments are |
| 29 | + // some-package-fragment1\fragments\....\a.so |
| 30 | + // some-package-fragment2\fragments\....\a.so |
| 31 | + // some-package-fragment3\fragments\....\a.so |
| 32 | + var fragmentFile1 = primaryFile.Replace("-primary", "-fragment1").Replace("runtimes", "fragments") + ".fragment1"; |
| 33 | + var fragmentFile2 = primaryFile.Replace("-primary", "-fragment2").Replace("runtimes", "fragments") + ".fragment2"; |
| 34 | + var fragmentFile3 = primaryFile.Replace("-primary", "-fragment3").Replace("runtimes", "fragments") + ".fragment3"; |
| 35 | +
|
| 36 | + if (File.Exists(fragmentFile1) && File.Exists(fragmentFile2) && File.Exists(fragmentFile3)) |
59 | 37 | {
|
60 |
| - if ((primaryBytes[i] > 0) && (fragmentBytes1[i] > 0) && (primaryBytes[i] != fragmentBytes1[i])) |
61 |
| - throw (new Exception(String.Format("Inconsistent file contents for multi-package deliver of single massive binary file. Primary file {0} and corresponding fragment {1} had inconsistent contents. You may have inconsistent nuget package references.", primaryFile, fragmentFile1))); |
62 |
| - if ((primaryBytes[i] > 0) && (fragmentBytes2[i] > 0) && (primaryBytes[i] != fragmentBytes2[i])) |
63 |
| - throw (new Exception(String.Format("Inconsistent file contents for multi-package deliver of single massive binary file. Primary file {0} and corresponding fragment {1} had inconsistent contents. You may have inconsistent nuget package references.", primaryFile, fragmentFile2))); |
64 |
| - if ((primaryBytes[i] > 0) && (fragmentBytes3[i] > 0) && (primaryBytes[i] != fragmentBytes3[i])) |
65 |
| - throw (new Exception(String.Format("Inconsistent file contents for multi-package deliver of single massive binary file. Primary file {0} and corresponding fragment {1} had inconsistent contents. You may have inconsistent nuget package references.", primaryFile, fragmentFile3))); |
66 |
| - primaryBytes[i] |= fragmentBytes1[i]; |
67 |
| - primaryBytes[i] |= fragmentBytes2[i]; |
68 |
| - primaryBytes[i] |= fragmentBytes3[i]; |
| 38 | + System.Console.WriteLine("Fragment files in parallel nuget packages for {0}", primaryFile); |
| 39 | +
|
| 40 | + Console.WriteLine("Found fragment file at {0}", fragmentFile1); |
| 41 | + Console.WriteLine("Found fragment file at {0}", fragmentFile2); |
| 42 | + Console.WriteLine("Found fragment file at {0}", fragmentFile3); |
| 43 | + var primaryBytes = File.ReadAllBytes(primaryFile); |
| 44 | + var fragmentBytes1 = File.ReadAllBytes(fragmentFile1); |
| 45 | + var fragmentBytes2 = File.ReadAllBytes(fragmentFile2); |
| 46 | + var fragmentBytes3 = File.ReadAllBytes(fragmentFile3); |
| 47 | +
|
| 48 | + if (primaryBytes.Length != fragmentBytes1.Length) |
| 49 | + throw (new Exception(String.Format("Mismatched file sizes for multi-package deliver of single massive binary file. Primary file {0} found, but the corresponding fragment at {1} has a different size. You may have inconsistent nuget package references.", primaryFile, fragmentFile1))); |
| 50 | +
|
| 51 | + if (primaryBytes.Length != fragmentBytes2.Length) |
| 52 | + throw (new Exception(String.Format("Mismatched file sizes for multi-package deliver of single massive binary file. Primary file {0} found, but the corresponding fragment at {1} has a different size. You may have inconsistent nuget package references.", primaryFile, fragmentFile2))); |
| 53 | +
|
| 54 | + if (primaryBytes.Length != fragmentBytes3.Length) |
| 55 | + throw (new Exception(String.Format("Mismatched file sizes for multi-package deliver of single massive binary file. Primary file {0} found, but the corresponding fragment at {1} has a different size. You may have inconsistent nuget package references.", primaryFile, fragmentFile3))); |
| 56 | +
|
| 57 | + for (int i = 0; i < primaryBytes.Length; i++) |
| 58 | + { |
| 59 | + if ((primaryBytes[i] > 0) && (fragmentBytes1[i] > 0) && (primaryBytes[i] != fragmentBytes1[i])) |
| 60 | + throw (new Exception(String.Format("Inconsistent file contents for multi-package deliver of single massive binary file. Primary file {0} and corresponding fragment {1} had inconsistent contents. You may have inconsistent nuget package references.", primaryFile, fragmentFile1))); |
| 61 | + if ((primaryBytes[i] > 0) && (fragmentBytes2[i] > 0) && (primaryBytes[i] != fragmentBytes2[i])) |
| 62 | + throw (new Exception(String.Format("Inconsistent file contents for multi-package deliver of single massive binary file. Primary file {0} and corresponding fragment {1} had inconsistent contents. You may have inconsistent nuget package references.", primaryFile, fragmentFile2))); |
| 63 | + if ((primaryBytes[i] > 0) && (fragmentBytes3[i] > 0) && (primaryBytes[i] != fragmentBytes3[i])) |
| 64 | + throw (new Exception(String.Format("Inconsistent file contents for multi-package deliver of single massive binary file. Primary file {0} and corresponding fragment {1} had inconsistent contents. You may have inconsistent nuget package references.", primaryFile, fragmentFile3))); |
| 65 | + primaryBytes[i] |= fragmentBytes1[i]; |
| 66 | + primaryBytes[i] |= fragmentBytes2[i]; |
| 67 | + primaryBytes[i] |= fragmentBytes3[i]; |
| 68 | + } |
| 69 | +
|
| 70 | + var tmpFile = Path.GetTempFileName(); |
| 71 | + Console.WriteLine("Writing restored primary file at {0}", tmpFile); |
| 72 | + File.WriteAllBytes(tmpFile, primaryBytes); |
| 73 | + Console.WriteLine("Deleting {0}", primaryFile); |
| 74 | + File.Delete(primaryFile); |
| 75 | + Console.WriteLine("Moving {0} --> {1}", tmpFile, primaryFile); |
| 76 | + File.Move(tmpFile, primaryFile); |
| 77 | +
|
| 78 | + Console.WriteLine("Deleting {0}", fragmentFile1); |
| 79 | + File.Delete(fragmentFile1); // free up space and prevent us doing this again |
| 80 | + Console.WriteLine("Deleting {0}", fragmentFile2); |
| 81 | + File.Delete(fragmentFile2); // free up space and prevent us doing this again |
| 82 | + Console.WriteLine("Deleting {0}", fragmentFile3); |
| 83 | + File.Delete(fragmentFile3); // free up space and prevent us doing this again |
69 | 84 | }
|
70 |
| -
|
71 |
| - Console.WriteLine("Writing restored file at {0}", restoredFile); |
72 |
| - File.WriteAllBytes(restoredFile, primaryBytes); |
73 |
| -
|
74 |
| - Console.WriteLine("Deleting {0}", primaryFile); |
75 |
| - File.Delete(primaryFile); // free up space and prevent us doing this again |
76 |
| - Console.WriteLine("Deleting {0}", fragmentFile1); |
77 |
| - File.Delete(fragmentFile1); // free up space and prevent us doing this again |
78 |
| - Console.WriteLine("Deleting {0}", fragmentFile2); |
79 |
| - File.Delete(fragmentFile2); // free up space and prevent us doing this again |
80 |
| - Console.WriteLine("Deleting {0}", fragmentFile3); |
81 |
| - File.Delete(fragmentFile3); // free up space and prevent us doing this again |
82 | 85 | }
|
83 | 86 | }
|
84 | 87 | ]]>
|
|
93 | 96 | </PropertyGroup>
|
94 | 97 |
|
95 | 98 | <Target Name="FileDefragger">
|
96 |
| - <FileDefragger FraggerDirectory="$(MSBuildThisFileDirectory)\..\..\runtimes\" /> |
| 99 | + <FileDefragger FraggerPrimaryPackage="%(FraggerPrimaryPackage.Identity)" /> |
97 | 100 | </Target>
|
98 | 101 |
|
99 | 102 |
|
|
0 commit comments