-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update framework detection logic to not rely on throwing/catching NRE #3714
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,35 +133,24 @@ public Architecture AutoDetectArchitecture(IList<string?>? sources, Architecture | |
public Framework AutoDetectFramework(IList<string?>? sources, out IDictionary<string, Framework> sourceToFrameworkMap) | ||
{ | ||
sourceToFrameworkMap = new Dictionary<string, Framework>(); | ||
Framework framework = Framework.DefaultFramework; | ||
|
||
if (sources == null || sources.Count == 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not filtering |
||
return framework; | ||
return Framework.DefaultFramework; | ||
|
||
try | ||
var framework = DetermineFramework(sources, out sourceToFrameworkMap, out var conflictInFxIdentifier); | ||
if (conflictInFxIdentifier) | ||
{ | ||
var finalFx = DetermineFrameworkName(sources, out sourceToFrameworkMap, out var conflictInFxIdentifier); | ||
TPDebug.Assert(finalFx != null, "finalFx should not be null"); | ||
framework = Framework.FromString(finalFx.FullName); | ||
if (conflictInFxIdentifier) | ||
{ | ||
// TODO Log to console and client. | ||
EqtTrace.Info( | ||
"conflicts in Framework identifier of provided sources(test assemblies), using default framework:{0}", | ||
framework); | ||
} | ||
} | ||
catch (Exception ex) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try/catch was only catching NRE when |
||
{ | ||
EqtTrace.Error("Failed to determine framework:{0}, using default: {1}", ex, framework); | ||
// TODO Log to console and client. | ||
EqtTrace.Info( | ||
"conflicts in Framework identifier of provided sources(test assemblies), using default framework: {0}", | ||
framework); | ||
} | ||
|
||
EqtTrace.Info("Determined framework for all sources: {0}", framework); | ||
|
||
return framework; | ||
} | ||
|
||
private FrameworkName? DetermineFrameworkName(IEnumerable<string?> sources, out IDictionary<string, Framework> sourceToFrameworkMap, out bool conflictInFxIdentifier) | ||
private Framework DetermineFramework(IEnumerable<string?> sources, out IDictionary<string, Framework> sourceToFrameworkMap, out bool conflictInFxIdentifier) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potentially we could move this as local function of |
||
{ | ||
sourceToFrameworkMap = new Dictionary<string, Framework>(); | ||
|
||
|
@@ -180,7 +169,7 @@ public Framework AutoDetectFramework(IList<string?>? sources, out IDictionary<st | |
FrameworkName fx; | ||
if (IsDllOrExe(source)) | ||
{ | ||
fx = _assemblyMetadataProvider.GetFrameWork(source); | ||
fx = _assemblyMetadataProvider.GetFrameworkName(source); | ||
} | ||
else | ||
{ | ||
|
@@ -231,7 +220,9 @@ public Framework AutoDetectFramework(IList<string?>? sources, out IDictionary<st | |
} | ||
} | ||
|
||
return finalFx; | ||
return finalFx != null | ||
? Framework.FromString(finalFx.FullName) | ||
: defaultFramework; | ||
} | ||
|
||
private static bool IsDllOrExe(string? filePath) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow unrelated but I got confused by the API name compared to its return type when fixing the auto-detection algorithm so I also fixed the name.