Skip to content
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 native File.Exists #9223

Merged
merged 14 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/Build.UnitTests/BackEnd/MSBuild_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public void Dispose()
/// throw a path too long exception
/// </summary>
[Fact]
[ActiveIssue("https://github.com/dotnet/msbuild/issues/4247")]
public void ProjectItemSpecTooLong()
{
string currentDirectory = Directory.GetCurrentDirectory();
Expand Down Expand Up @@ -69,15 +68,15 @@ public void ProjectItemSpecTooLong()
}

int rootLength = Path.GetPathRoot(tempPath).Length;
string tempPathNoRoot = tempPath.Substring(rootLength);
string tempPathNoRoot = tempProject.Substring(rootLength);
f-alizada marked this conversation as resolved.
Show resolved Hide resolved

projectFile1 += Path.Combine(tempPathNoRoot, fileName);
projectFile1 += tempPathNoRoot;

string parentProjectContents = @"
<Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>

<Target Name=`Build`>
<MSBuild Projects=`" + projectFile1 + @"` />
<MSBuild Projects=`" + projectFile1 + @"`/>
</Target>
</Project>";
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ private enum SkipNonExistentProjectsBehavior
public ITaskHost HostObject { get; set; }

/// <summary>
/// A list of property name/value pairs to apply as global properties to
/// the child project.
/// A list of property name/value pairs to apply as global properties to
/// the child project.
/// A typical input: "propname1=propvalue1", "propname2=propvalue2", "propname3=propvalue3".
/// </summary>
/// <remarks>
/// The fact that this is a string[] makes the following illegal:
/// <MSBuild
/// Properties="TargetPath=@(OutputPathItem)" />
/// The engine fails on this because it doesn't like item lists being concatenated with string
/// constants when the data is being passed into an array parameter. So the workaround is to
/// constants when the data is being passed into an array parameter. So the workaround is to
/// write this in the project file:
/// <MSBuild
/// Properties="@(OutputPathItem->'TargetPath=%(Identity)')" />
Expand Down Expand Up @@ -144,7 +144,7 @@ private enum SkipNonExistentProjectsBehavior
public string ToolsVersion { get; set; } = null;

/// <summary>
/// When this is true we call the engine with all the projects at once instead of
/// When this is true we call the engine with all the projects at once instead of
/// calling the engine once per project
/// </summary>
public bool BuildInParallel { get; set; }
Expand Down Expand Up @@ -201,7 +201,7 @@ public string SkipNonexistentProjects

/// <summary>
/// Un-escape Targets, Properties (including Properties and AdditionalProperties as Project item metadata)
/// will be un-escaped before processing. e.g. %3B (an escaped ';') in the string for any of them will
/// will be un-escaped before processing. e.g. %3B (an escaped ';') in the string for any of them will
/// be treated as if it were an un-escaped ';'
/// </summary>
public string[] TargetAndPropertyListSeparators { get; set; } = null;
Expand All @@ -211,7 +211,7 @@ public string SkipNonexistentProjects
/// <see cref="Projects"/> to build. This only applies to this build request (if another target calls the
/// "missing target" later this will still result in an error).
/// <remarks>
/// This could be useful when implementing a breaking protocol change between projects or stubbing behavior
/// This could be useful when implementing a breaking protocol change between projects or stubbing behavior
/// which may not make sense in all project types (e.g. Restore).
/// </remarks>
/// </summary>
Expand Down Expand Up @@ -264,7 +264,7 @@ public async Task<bool> ExecuteInternal()
}

bool isRunningMultipleNodes = BuildEngine2.IsRunningMultipleNodes;
// If we are in single proc mode and stopOnFirstFailure is true, we cannot build in parallel because
// If we are in single proc mode and stopOnFirstFailure is true, we cannot build in parallel because
// building in parallel sends all of the projects to the engine at once preventing us from not sending
// any more projects after the first failure. Therefore, to preserve compatibility with whidbey if we are in this situation disable buildInParallel.
if (!isRunningMultipleNodes && StopOnFirstFailure && BuildInParallel)
Expand All @@ -284,8 +284,8 @@ public async Task<bool> ExecuteInternal()
}

// This is a list of string[]. That is, each element in the list is a string[]. Each
// string[] represents a set of target names to build. Depending on the value
// of the RunEachTargetSeparately parameter, we each just call the engine to run all
// string[] represents a set of target names to build. Depending on the value
// of the RunEachTargetSeparately parameter, we each just call the engine to run all
// the targets together, or we call the engine separately for each target.
List<string[]> targetLists = CreateTargetLists(Targets, RunEachTargetSeparately);

Expand Down Expand Up @@ -314,14 +314,14 @@ public async Task<bool> ExecuteInternal()
{
ITaskItem project = Projects[i];

string projectPath = FileUtilities.AttemptToShortenPath(project.ItemSpec);
string projectPath = FileUtilities.GetFullPathNoThrow(project.ItemSpec);
JaynieBai marked this conversation as resolved.
Show resolved Hide resolved

if (StopOnFirstFailure && !success)
{
// Inform the user that we skipped the remaining projects because StopOnFirstFailure=true.
Log.LogMessageFromResources(MessageImportance.Low, "MSBuild.SkippingRemainingProjects");

// We have encountered a failure. Caller has requested that we not
// We have encountered a failure. Caller has requested that we not
// continue with remaining projects.
break;
}
Expand Down Expand Up @@ -495,8 +495,8 @@ internal static List<string[]> CreateTargetLists(
bool runEachTargetSeparately)
{
// This is a list of string[]. That is, each element in the list is a string[]. Each
// string[] represents a set of target names to build. Depending on the value
// of the RunEachTargetSeparately parameter, we each just call the engine to run all
// string[] represents a set of target names to build. Depending on the value
// of the RunEachTargetSeparately parameter, we each just call the engine to run all
// the targets together, or we call the engine separately for each target.
var targetLists = new List<string[]>();
if (runEachTargetSeparately && targets?.Length > 0)
Expand Down Expand Up @@ -550,7 +550,7 @@ internal static async Task<bool> ExecuteTargets(
if (projects[i] != null)
{
// Retrieve projectDirectory only the first time. It never changes anyway.
string projectPath = FileUtilities.AttemptToShortenPath(projects[i].ItemSpec);
string projectPath = FileUtilities.GetFullPathNoThrow(projects[i].ItemSpec);
projectDirectory[i] = Path.GetDirectoryName(projectPath);
projectNames[i] = projects[i].ItemSpec;
toolsVersions[i] = toolsVersion;
Expand Down Expand Up @@ -648,12 +648,12 @@ internal static async Task<bool> ExecuteTargets(
// Inform the user that we skipped the remaining targets StopOnFirstFailure=true.
log.LogMessageFromResources(MessageImportance.Low, "MSBuild.SkippingRemainingTargets");

// We have encountered a failure. Caller has requested that we not
// We have encountered a failure. Caller has requested that we not
// continue with remaining targets.
break;
}

// Send the project off to the build engine. By passing in null to the
// Send the project off to the build engine. By passing in null to the
// first param, we are indicating that the project to build is the same
// as the *calling* project file.

Expand All @@ -677,7 +677,7 @@ internal static async Task<bool> ExecuteTargets(
{
foreach (ITaskItem outputItemFromTarget in outputItemsFromTarget)
{
// No need to rebase if the calling project is the same as the callee project
// No need to rebase if the calling project is the same as the callee project
// (project == null). Also no point in trying to copy item metadata either,
// because no items were passed into the Projects parameter!
if (projects[i] != null)
Expand Down
23 changes: 11 additions & 12 deletions src/Tasks.UnitTests/MSBuild_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public void Dispose()
/// throw a path too long exception
/// </summary>
[Fact]
[ActiveIssue("https://github.com/dotnet/msbuild/issues/4247")]
f-alizada marked this conversation as resolved.
Show resolved Hide resolved
public void ProjectItemSpecTooLong()
{
string currentDirectory = Directory.GetCurrentDirectory();
Expand Down Expand Up @@ -71,9 +70,9 @@ public void ProjectItemSpecTooLong()
}

int rootLength = Path.GetPathRoot(tempPath).Length;
string tempPathNoRoot = tempPath.Substring(rootLength);
string tempPathNoRoot = tempProject.Substring(rootLength);

projectFile1 += Path.Combine(tempPathNoRoot, fileName);
projectFile1 += tempPathNoRoot;
try
{
MSBuild msbuildTask = new MSBuild
Expand Down Expand Up @@ -498,7 +497,7 @@ public void DifferentGlobalPropertiesWithDefault()

<Target Name=`TargetA` Outputs=`a1.dll` Condition=`'$(MyProp)'=='0'`/>
<Target Name=`TargetB` Outputs=`b1.dll` Condition=`'$(MyProp)'=='1'`/>

</Project>
");

Expand Down Expand Up @@ -556,7 +555,7 @@ public void DifferentGlobalPropertiesWithoutDefault()

<Target Name=`TargetA` Outputs=`a1.dll` Condition=`'$(MyProp)'=='0'`/>
<Target Name=`TargetB` Outputs=`b1.dll` Condition=`'$(MyProp)'=='1'`/>

</Project>
");

Expand Down Expand Up @@ -612,7 +611,7 @@ public void DifferentGlobalPropertiesWithBlanks()

<Target Name=`TargetA` Outputs=`a1.dll` Condition=`'$(MyProp)'=='0'`/>
<Target Name=`TargetB` Outputs=`b1.dll` Condition=`'$(MyProp)'=='1'`/>

</Project>
");

Expand Down Expand Up @@ -667,7 +666,7 @@ public void DifferentGlobalPropertiesInvalid()

<Target Name=`TargetA` Outputs=`a1.dll` Condition=`'$(MyProp)'=='0'`/>
<Target Name=`TargetB` Outputs=`b1.dll` Condition=`'$(MyProp)'=='1'`/>

</Project>
");

Expand Down Expand Up @@ -716,7 +715,7 @@ public void DifferentAdditionalPropertiesWithDefault()

<Target Name=`TargetA` Outputs=`a1.dll` Condition=`'$(MyPropG)'=='1'`/>
<Target Name=`TargetB` Outputs=`b1.dll` Condition=`'$(MyPropA)'=='1'`/>

</Project>
");

Expand Down Expand Up @@ -771,7 +770,7 @@ public void DifferentAdditionalPropertiesWithGlobalProperties()

<Target Name=`TargetA` Outputs=`a1.dll` Condition=`'$(MyPropG)'=='0'`/>
<Target Name=`TargetB` Outputs=`b1.dll` Condition=`'$(MyPropA)'=='1'`/>

</Project>
");

Expand Down Expand Up @@ -829,7 +828,7 @@ public void DifferentAdditionalPropertiesWithoutDefault()

<Target Name=`TargetA` Outputs=`a1.dll` Condition=`'$(MyPropG)'=='1'`/>
<Target Name=`TargetB` Outputs=`b1.dll` Condition=`'$(MyPropA)'=='1'`/>

</Project>
");

Expand Down Expand Up @@ -1375,7 +1374,7 @@ public void TargetNameIsCaseInsensitive()
");

string projectFile2 = ObjectModelHelpers.CreateTempFileOnDisk(@"
<Project DefaultTargets=`t` xmlns=`msbuildnamespace` ToolsVersion=`msbuilddefaulttoolsversion`>
<Project DefaultTargets=`t` xmlns=`msbuildnamespace` ToolsVersion=`msbuilddefaulttoolsversion`>
<Target Name=`t`>
<MSBuild Projects=`" + projectFile1 + @"` Targets=`BUILD`>
<Output TaskParameter=`TargetOutputs` ItemName=`out`/>
Expand Down Expand Up @@ -1468,7 +1467,7 @@ public void MSBuildTaskPassesTaskIdToSpawnedBuilds()
<Project>
<Target Name=`Build`>
<MSBuild Projects=`" + projectFile1 + @"` Targets=`Build` />
</Target>
</Target>
</Project>");

try
Expand Down
Loading
Loading