Skip to content

Commit 3c7c75e

Browse files
committed
Add rest of hang tests from helix-prototype
1 parent 31755f9 commit 3c7c75e

37 files changed

+2293
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
#if NET472
6+
7+
using System;
8+
using System.Collections.Generic;
9+
using System.IO;
10+
using System.Reflection;
11+
using Microsoft.Build.Framework;
12+
using Microsoft.Build.Utilities;
13+
14+
namespace Microsoft.DotNet
15+
{
16+
internal static class AssemblyResolution
17+
{
18+
internal static TaskLoggingHelper Log;
19+
20+
public static void Initialize()
21+
{
22+
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve;
23+
}
24+
25+
private static Assembly AssemblyResolve(object sender, ResolveEventArgs args)
26+
{
27+
var name = new AssemblyName(args.Name);
28+
29+
if (!name.Name.Equals("System.Collections.Immutable", StringComparison.OrdinalIgnoreCase))
30+
{
31+
return null;
32+
}
33+
34+
var fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "System.Collections.Immutable.dll");
35+
36+
Assembly sci;
37+
try
38+
{
39+
sci = Assembly.LoadFile(fullPath);
40+
}
41+
catch (Exception e)
42+
{
43+
Log?.LogWarning($"AssemblyResolve: exception while loading '{fullPath}': {e.Message}");
44+
return null;
45+
}
46+
47+
if (name.Version <= sci.GetName().Version)
48+
{
49+
Log?.LogMessage(MessageImportance.Low, $"AssemblyResolve: loaded '{fullPath}' to {AppDomain.CurrentDomain.FriendlyName}");
50+
return sci;
51+
}
52+
53+
return null;
54+
}
55+
}
56+
}
57+
58+
#endif
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Diagnostics;
7+
using System.IO;
8+
using System.Reflection;
9+
10+
namespace Microsoft.DotNet.Build.Common.Desktop
11+
{
12+
/// <summary>
13+
/// Used to enable app-local assembly unification.
14+
/// </summary>
15+
internal static class AssemblyResolver
16+
{
17+
static AssemblyResolver()
18+
{
19+
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
20+
}
21+
22+
/// <summary>
23+
/// Call to enable the assembly resolver for the current AppDomain.
24+
/// </summary>
25+
public static void Enable()
26+
{
27+
// intentionally empty. This is just meant to ensure the static constructor
28+
// has run.
29+
}
30+
31+
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
32+
{
33+
// apply any existing policy
34+
AssemblyName referenceName = new AssemblyName(AppDomain.CurrentDomain.ApplyPolicy(args.Name));
35+
36+
string fileName = referenceName.Name + ".dll";
37+
string assemblyPath = null;
38+
string probingPath = null;
39+
Assembly assm = null;
40+
41+
// look next to requesting assembly
42+
assemblyPath = args.RequestingAssembly?.Location;
43+
if (!String.IsNullOrEmpty(assemblyPath))
44+
{
45+
probingPath = Path.Combine(Path.GetDirectoryName(assemblyPath), fileName);
46+
Debug.WriteLine($"Considering {probingPath} based on RequestingAssembly");
47+
if (Probe(probingPath, referenceName.Version, out assm))
48+
{
49+
return assm;
50+
}
51+
}
52+
53+
// look next to the executing assembly
54+
assemblyPath = Assembly.GetExecutingAssembly().Location;
55+
if (!String.IsNullOrEmpty(assemblyPath))
56+
{
57+
probingPath = Path.Combine(Path.GetDirectoryName(assemblyPath), fileName);
58+
59+
Debug.WriteLine($"Considering {probingPath} based on ExecutingAssembly");
60+
if (Probe(probingPath, referenceName.Version, out assm))
61+
{
62+
return assm;
63+
}
64+
}
65+
66+
// look in AppDomain base directory
67+
probingPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
68+
Debug.WriteLine($"Considering {probingPath} based on BaseDirectory");
69+
if (Probe(probingPath, referenceName.Version, out assm))
70+
{
71+
return assm;
72+
}
73+
74+
// look in current directory
75+
Debug.WriteLine($"Considering {fileName}");
76+
if (Probe(fileName, referenceName.Version, out assm))
77+
{
78+
return assm;
79+
}
80+
81+
return null;
82+
}
83+
84+
/// <summary>
85+
/// Considers a path to load for satisfying an assembly ref and loads it
86+
/// if the file exists and version is sufficient.
87+
/// </summary>
88+
/// <param name="filePath">Path to consider for load</param>
89+
/// <param name="minimumVersion">Minimum version to consider</param>
90+
/// <param name="assembly">loaded assembly</param>
91+
/// <returns>true if assembly was loaded</returns>
92+
private static bool Probe(string filePath, Version minimumVersion, out Assembly assembly)
93+
{
94+
if (File.Exists(filePath))
95+
{
96+
AssemblyName name = AssemblyName.GetAssemblyName(filePath);
97+
98+
if (name.Version >= minimumVersion)
99+
{
100+
assembly = Assembly.Load(name);
101+
return true;
102+
}
103+
}
104+
105+
assembly = null;
106+
return false;
107+
}
108+
}
109+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.DotNet.Build.Common.Desktop;
6+
7+
namespace Microsoft.DotNet.Build.Tasks
8+
{
9+
public partial class BuildTask
10+
{
11+
static BuildTask()
12+
{
13+
AssemblyResolver.Enable();
14+
}
15+
}
16+
}

src/Identity/src/Common/BuildTask.cs

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.Build.Framework;
6+
using Microsoft.Build.Utilities;
7+
using System;
8+
9+
namespace Microsoft.DotNet.Build.Tasks
10+
{
11+
public abstract partial class BuildTask : ITask
12+
{
13+
private Log _log = null;
14+
15+
internal Log Log
16+
{
17+
get { return _log ?? (_log = new Log(new TaskLoggingHelper(this))); }
18+
}
19+
20+
public BuildTask()
21+
{
22+
}
23+
24+
public IBuildEngine BuildEngine
25+
{
26+
get;
27+
set;
28+
}
29+
30+
public ITaskHost HostObject
31+
{
32+
get;
33+
set;
34+
}
35+
36+
public abstract bool Execute();
37+
}
38+
39+
internal class Log : ILog
40+
{
41+
private readonly TaskLoggingHelper _logger;
42+
public Log(TaskLoggingHelper logger)
43+
{
44+
_logger = logger;
45+
}
46+
47+
public void LogError(string message, params object[] messageArgs)
48+
{
49+
_logger.LogError(message, messageArgs);
50+
}
51+
52+
public void LogErrorFromException(Exception exception, bool showStackTrace)
53+
{
54+
_logger.LogErrorFromException(exception, showStackTrace);
55+
}
56+
57+
public void LogMessage(string message, params object[] messageArgs)
58+
{
59+
_logger.LogMessage(message, messageArgs);
60+
}
61+
62+
public void LogMessage(LogImportance importance, string message, params object[] messageArgs)
63+
{
64+
_logger.LogMessage((MessageImportance)importance, message, messageArgs);
65+
}
66+
67+
public void LogWarning(string message, params object[] messageArgs)
68+
{
69+
_logger.LogWarning(message, messageArgs);
70+
}
71+
72+
public bool HasLoggedErrors { get { return _logger.HasLoggedErrors; } }
73+
}
74+
75+
public enum LogImportance
76+
{
77+
Low = MessageImportance.Low,
78+
Normal = MessageImportance.Normal,
79+
High = MessageImportance.High
80+
}
81+
82+
83+
public interface ILog
84+
{
85+
//
86+
// Summary:
87+
// Logs an error with the specified message.
88+
//
89+
// Parameters:
90+
// message:
91+
// The message.
92+
//
93+
// messageArgs:
94+
// Optional arguments for formatting the message string.
95+
//
96+
// Exceptions:
97+
// T:System.ArgumentNullException:
98+
// message is null.
99+
void LogError(string message, params object[] messageArgs);
100+
101+
//
102+
// Summary:
103+
// Logs a message with the specified string.
104+
//
105+
// Parameters:
106+
// message:
107+
// The message.
108+
//
109+
// messageArgs:
110+
// The arguments for formatting the message.
111+
//
112+
// Exceptions:
113+
// T:System.ArgumentNullException:
114+
// message is null.
115+
void LogMessage(string message, params object[] messageArgs);
116+
117+
//
118+
// Summary:
119+
// Logs a message with the specified string and importance.
120+
//
121+
// Parameters:
122+
// importance:
123+
// One of the enumeration values that specifies the importance of the message.
124+
//
125+
// message:
126+
// The message.
127+
//
128+
// messageArgs:
129+
// The arguments for formatting the message.
130+
//
131+
// Exceptions:
132+
// T:System.ArgumentNullException:
133+
// message is null.
134+
void LogMessage(LogImportance importance, string message, params object[] messageArgs);
135+
136+
//
137+
// Summary:
138+
// Logs a warning with the specified message.
139+
//
140+
// Parameters:
141+
// message:
142+
// The message.
143+
//
144+
// messageArgs:
145+
// Optional arguments for formatting the message string.
146+
//
147+
// Exceptions:
148+
// T:System.ArgumentNullException:
149+
// message is null.
150+
void LogWarning(string message, params object[] messageArgs);
151+
}
152+
}

0 commit comments

Comments
 (0)