Skip to content

Commit

Permalink
Enumerate source files deterministically
Browse files Browse the repository at this point in the history
This makes the order of source file enumeration not depend on the
platform (OS, FS, etc.) or culture.

Fixes dotnet#10858
  • Loading branch information
j3parker committed Nov 30, 2017
1 parent 74c7ec4 commit bcc4a1c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Compilers/Core/Portable/CommandLine/CommonCommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,22 @@ private IEnumerable<CommandLineSourceFile> ExpandFileNamePattern(
string baseDirectory,
SearchOption searchOption,
IList<Diagnostic> errors)
{
var sources = ExpandFileNamePatternNonDeterministic(path, baseDirectory, searchOption, errors);

// Use StringComparer.Ordinal because other comparers may behave
// differently depending on the platform.
return sources.OrderBy(sf => sf.Path, StringComparer.Ordinal);
}

// This function returns results in non-deterministic order due to
// usage of things like Directory.EnumerateFiles. Some example sources
// of differentiation are file systems and operating systems.
private IEnumerable<CommandLineSourceFile> ExpandFileNamePatternNonDeterministic(
string path,
string baseDirectory,
SearchOption searchOption,
IList<Diagnostic> errors)
{
string directory = PathUtilities.GetDirectoryName(path);
string pattern = PathUtilities.GetFileName(path);
Expand Down

0 comments on commit bcc4a1c

Please sign in to comment.