diff --git a/BuildConfigGen/GitUtil.cs b/BuildConfigGen/GitUtil.cs index f4863e92228e..a8cdfc516efe 100644 --- a/BuildConfigGen/GitUtil.cs +++ b/BuildConfigGen/GitUtil.cs @@ -4,6 +4,7 @@ namespace BuildConfigGen { internal static class GitUtil { + static (string? gitRoot, IEnumerable? cache) NonIgnoredFileListCache; public static void GetUntrackedFiles(string taskTarget, out IEnumerable toAdd, out IEnumerable toRemove) { @@ -122,40 +123,75 @@ internal static string GetGitRootPath(string currentDir) internal static IEnumerable GetNonIgnoredFileListFromPath(string gitRoot, string taskTarget) { - string gitIgnorePathBak = Path.Combine(gitRoot, ".gitignore.bak"); - string gitIgnore = Path.Combine(gitRoot, ".gitignore"); + // the new version gets the non-ignored files frmo the root, caches and filters based on taskTarget. It's 6x faster + return GetNonIgnoredFileListFromPathInnerIncludingFromGeneratedLocalFilteredByTaskTarget(gitRoot, taskTarget); + } - bool needsGitIgnoreUpdate = taskTarget.Contains("/_generated_local/") || taskTarget.Contains(@"\_generated_local\"); + private static IEnumerable GetNonIgnoredFileListFromPathInnerIncludingFromGeneratedLocalFilteredByTaskTarget(string gitRoot, string taskTarget) + { + if (!taskTarget.StartsWith(gitRoot, StringComparison.OrdinalIgnoreCase)) + { + throw new Exception($"expected taskTarget={taskTarget} to start with gitRoot={gitRoot}"); + } - string? gitIgnoreContent = null; + string taskTargetSubpath = taskTarget.Substring(gitRoot.Length); - if (needsGitIgnoreUpdate) + if(NonIgnoredFileListCache.gitRoot is not null) { - gitIgnoreContent = File.ReadAllText(gitIgnore); - const string genertedLocalPath = "_generated_local/"; + NonIgnoredFileListCache.gitRoot = gitRoot; - if (!gitIgnoreContent.Contains(genertedLocalPath)) + if(gitRoot!= NonIgnoredFileListCache.gitRoot) { - throw new Exception("Expected " + genertedLocalPath + " in " + gitIgnore); + throw new Exception($"BUG: gitroot={gitRoot} expected to match {NonIgnoredFileListCache.gitRoot}=NonIgnoredFileListCache.gitRoot"); } + } - gitIgnoreContent = gitIgnoreContent.Replace(genertedLocalPath, ""); - - File.Copy(gitIgnore, gitIgnorePathBak, true); + if (NonIgnoredFileListCache.cache is null) + { + NonIgnoredFileListCache.cache = GetNonIgnoredFileListFromPathInnerIncludingFromGeneratedLocal(gitRoot); } - try + return NonIgnoredFileListCache.cache.Where(x => x.StartsWith(taskTargetSubpath + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)).Select(x => { - if (needsGitIgnoreUpdate) + var y = x.Substring(taskTargetSubpath.Length); + + if (y.StartsWith("/") || y.StartsWith(@"\")) + { + return y.Substring(1); + } + else { - File.WriteAllText(gitIgnore, gitIgnoreContent); + throw new Exception($"BUG: expected y={y} to start with / or \\ "); } + }); + } + + private static IEnumerable GetNonIgnoredFileListFromPathInnerIncludingFromGeneratedLocal(string gitRoot) + { + string gitIgnorePathBak = Path.Combine(gitRoot, ".gitignore.bak"); + string gitIgnore = Path.Combine(gitRoot, ".gitignore"); + + string? gitIgnoreContent = File.ReadAllText(gitIgnore); + const string genertedLocalPath = "_generated_local/"; + + if (!gitIgnoreContent.Contains(genertedLocalPath)) + { + throw new Exception("Expected " + genertedLocalPath + " in " + gitIgnore); + } + + gitIgnoreContent = gitIgnoreContent.Replace(genertedLocalPath, ""); + + File.Copy(gitIgnore, gitIgnorePathBak, true); + + try + { + File.WriteAllText(gitIgnore, gitIgnoreContent); - return GetNonIgnoredFileListFromPathInner(taskTarget); + return GetNonIgnoredFileListFromPathInner(gitRoot); } finally { - if (needsGitIgnoreUpdate) + if (File.Exists(gitIgnorePathBak)) { File.Move(gitIgnorePathBak, gitIgnore, true); } diff --git a/BuildConfigGen/Program.cs b/BuildConfigGen/Program.cs index 5e58043401a1..a20ffbb22be4 100644 --- a/BuildConfigGen/Program.cs +++ b/BuildConfigGen/Program.cs @@ -73,8 +73,11 @@ static void Main(string? task = null, string? configs = null, int? currentSprint { try { + Stopwatch sw = new Stopwatch(); + sw.Start(); ensureUpdateModeVerifier = new EnsureUpdateModeVerifier(!writeUpdates); MainInner(task, configs, currentSprint, writeUpdates, allTasks, getTaskVersionTable, debugAgentDir, includeLocalPackagesBuildConfig); + Console.WriteLine("Elapsed=" + sw.ToString()); } catch (Exception e2) { @@ -945,7 +948,7 @@ private static void CopyConfig(string gitRootPath, string taskTargetPathOrUnders HashSet pathsToRemoveFromOutput; // In case if task was not generated yet, we don't need to get the list of files to remove, because taskOutput not exists yet - if (Directory.Exists(taskOutput) && !config.useAltGeneratedPath /* exclude alt which is .gitignore */) + if (Directory.Exists(taskOutput)) { pathsToRemoveFromOutput = new HashSet(GitUtil.GetNonIgnoredFileListFromPath(gitRootPath, taskOutput)); } diff --git a/Tasks/MavenV2/task.json b/Tasks/MavenV2/task.json index 38cc8a46227f..3a03d4dca5dd 100644 --- a/Tasks/MavenV2/task.json +++ b/Tasks/MavenV2/task.json @@ -18,7 +18,7 @@ "version": { "Major": 2, "Minor": 246, - "Patch": 0 + "Patch": 2 }, "releaseNotes": "Configuration of the SonarQube analysis was moved to the [SonarQube](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube) or [SonarCloud](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud) extensions, in task `Prepare Analysis Configuration`", "demands": [ diff --git a/Tasks/MavenV2/task.loc.json b/Tasks/MavenV2/task.loc.json index f2b43c894ea0..3ad9608342cb 100644 --- a/Tasks/MavenV2/task.loc.json +++ b/Tasks/MavenV2/task.loc.json @@ -18,7 +18,7 @@ "version": { "Major": 2, "Minor": 246, - "Patch": 0 + "Patch": 2 }, "releaseNotes": "ms-resource:loc.releaseNotes", "demands": [ diff --git a/Tasks/MavenV3/task.json b/Tasks/MavenV3/task.json index e967a68e223b..c77ea0223618 100644 --- a/Tasks/MavenV3/task.json +++ b/Tasks/MavenV3/task.json @@ -17,7 +17,7 @@ "author": "Microsoft Corporation", "version": { "Major": 3, - "Minor": 246, + "Minor": 247, "Patch": 0 }, "releaseNotes": "Configuration of the SonarQube analysis was moved to the [SonarQube](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube) or [SonarCloud](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud) extensions, in task `Prepare Analysis Configuration`", diff --git a/Tasks/MavenV3/task.loc.json b/Tasks/MavenV3/task.loc.json index 3db9c5d2230f..0f12ccb2d328 100644 --- a/Tasks/MavenV3/task.loc.json +++ b/Tasks/MavenV3/task.loc.json @@ -17,7 +17,7 @@ "author": "Microsoft Corporation", "version": { "Major": 3, - "Minor": 246, + "Minor": 247, "Patch": 0 }, "releaseNotes": "ms-resource:loc.releaseNotes", diff --git a/Tasks/MavenV4/task.json b/Tasks/MavenV4/task.json index 140fd2aa6220..61990148c56e 100644 --- a/Tasks/MavenV4/task.json +++ b/Tasks/MavenV4/task.json @@ -17,7 +17,7 @@ "author": "Microsoft Corporation", "version": { "Major": 4, - "Minor": 246, + "Minor": 247, "Patch": 0 }, "releaseNotes": "Configuration of the SonarQube analysis was moved to the [SonarQube](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube) or [SonarCloud](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud) extensions, in task `Prepare Analysis Configuration`", diff --git a/Tasks/MavenV4/task.loc.json b/Tasks/MavenV4/task.loc.json index 64d09b4339b3..41b2cf7a6d9f 100644 --- a/Tasks/MavenV4/task.loc.json +++ b/Tasks/MavenV4/task.loc.json @@ -17,7 +17,7 @@ "author": "Microsoft Corporation", "version": { "Major": 4, - "Minor": 246, + "Minor": 247, "Patch": 0 }, "releaseNotes": "ms-resource:loc.releaseNotes", diff --git a/_generated/MavenV3.versionmap.txt b/_generated/MavenV3.versionmap.txt index 489e7d778db0..ec61a0effd82 100644 --- a/_generated/MavenV3.versionmap.txt +++ b/_generated/MavenV3.versionmap.txt @@ -1,2 +1,2 @@ -Default|3.246.0 -Node20-225|3.246.1 +Default|3.247.0 +Node20-225|3.247.1 diff --git a/_generated/MavenV3/task.json b/_generated/MavenV3/task.json index a466db123837..95c68f282185 100644 --- a/_generated/MavenV3/task.json +++ b/_generated/MavenV3/task.json @@ -17,7 +17,7 @@ "author": "Microsoft Corporation", "version": { "Major": 3, - "Minor": 246, + "Minor": 247, "Patch": 0 }, "releaseNotes": "Configuration of the SonarQube analysis was moved to the [SonarQube](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube) or [SonarCloud](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud) extensions, in task `Prepare Analysis Configuration`", @@ -519,7 +519,7 @@ "NoTestResults": "No test result files matching %s were found, so publishing JUnit test results is being skipped." }, "_buildConfigMapping": { - "Default": "3.246.0", - "Node20-225": "3.246.1" + "Default": "3.247.0", + "Node20-225": "3.247.1" } } \ No newline at end of file diff --git a/_generated/MavenV3/task.loc.json b/_generated/MavenV3/task.loc.json index a96ec76829e8..15149a86a25f 100644 --- a/_generated/MavenV3/task.loc.json +++ b/_generated/MavenV3/task.loc.json @@ -17,7 +17,7 @@ "author": "Microsoft Corporation", "version": { "Major": 3, - "Minor": 246, + "Minor": 247, "Patch": 0 }, "releaseNotes": "ms-resource:loc.releaseNotes", @@ -519,7 +519,7 @@ "NoTestResults": "ms-resource:loc.messages.NoTestResults" }, "_buildConfigMapping": { - "Default": "3.246.0", - "Node20-225": "3.246.1" + "Default": "3.247.0", + "Node20-225": "3.247.1" } } \ No newline at end of file diff --git a/_generated/MavenV3_Node20/task.json b/_generated/MavenV3_Node20/task.json index 2cb02038e0d7..2d8bf50a1e5c 100644 --- a/_generated/MavenV3_Node20/task.json +++ b/_generated/MavenV3_Node20/task.json @@ -17,7 +17,7 @@ "author": "Microsoft Corporation", "version": { "Major": 3, - "Minor": 246, + "Minor": 247, "Patch": 1 }, "releaseNotes": "Configuration of the SonarQube analysis was moved to the [SonarQube](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube) or [SonarCloud](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud) extensions, in task `Prepare Analysis Configuration`", @@ -523,7 +523,7 @@ "NoTestResults": "No test result files matching %s were found, so publishing JUnit test results is being skipped." }, "_buildConfigMapping": { - "Default": "3.246.0", - "Node20-225": "3.246.1" + "Default": "3.247.0", + "Node20-225": "3.247.1" } } \ No newline at end of file diff --git a/_generated/MavenV3_Node20/task.loc.json b/_generated/MavenV3_Node20/task.loc.json index 1ac0ce9c5ae8..ea0044aac47a 100644 --- a/_generated/MavenV3_Node20/task.loc.json +++ b/_generated/MavenV3_Node20/task.loc.json @@ -17,7 +17,7 @@ "author": "Microsoft Corporation", "version": { "Major": 3, - "Minor": 246, + "Minor": 247, "Patch": 1 }, "releaseNotes": "ms-resource:loc.releaseNotes", @@ -523,7 +523,7 @@ "NoTestResults": "ms-resource:loc.messages.NoTestResults" }, "_buildConfigMapping": { - "Default": "3.246.0", - "Node20-225": "3.246.1" + "Default": "3.247.0", + "Node20-225": "3.247.1" } } \ No newline at end of file diff --git a/_generated/MavenV4.versionmap.txt b/_generated/MavenV4.versionmap.txt index 60bf960e27a0..0184e5ee7f3c 100644 --- a/_generated/MavenV4.versionmap.txt +++ b/_generated/MavenV4.versionmap.txt @@ -1,2 +1,2 @@ -Default|4.246.0 -Node20-225|4.246.1 +Default|4.247.0 +Node20-225|4.247.1 diff --git a/_generated/MavenV4/task.json b/_generated/MavenV4/task.json index 16fff31ce40d..aa8dee5c2451 100644 --- a/_generated/MavenV4/task.json +++ b/_generated/MavenV4/task.json @@ -17,7 +17,7 @@ "author": "Microsoft Corporation", "version": { "Major": 4, - "Minor": 246, + "Minor": 247, "Patch": 0 }, "releaseNotes": "Configuration of the SonarQube analysis was moved to the [SonarQube](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube) or [SonarCloud](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud) extensions, in task `Prepare Analysis Configuration`", @@ -527,7 +527,7 @@ "NoTestResults": "No test result files matching %s were found, so publishing JUnit test results is being skipped." }, "_buildConfigMapping": { - "Default": "4.246.0", - "Node20-225": "4.246.1" + "Default": "4.247.0", + "Node20-225": "4.247.1" } } \ No newline at end of file diff --git a/_generated/MavenV4/task.loc.json b/_generated/MavenV4/task.loc.json index b28993e10ff9..813851921680 100644 --- a/_generated/MavenV4/task.loc.json +++ b/_generated/MavenV4/task.loc.json @@ -17,7 +17,7 @@ "author": "Microsoft Corporation", "version": { "Major": 4, - "Minor": 246, + "Minor": 247, "Patch": 0 }, "releaseNotes": "ms-resource:loc.releaseNotes", @@ -527,7 +527,7 @@ "NoTestResults": "ms-resource:loc.messages.NoTestResults" }, "_buildConfigMapping": { - "Default": "4.246.0", - "Node20-225": "4.246.1" + "Default": "4.247.0", + "Node20-225": "4.247.1" } } \ No newline at end of file diff --git a/_generated/MavenV4_Node20/task.json b/_generated/MavenV4_Node20/task.json index 0ffbf028360b..9db80e580764 100644 --- a/_generated/MavenV4_Node20/task.json +++ b/_generated/MavenV4_Node20/task.json @@ -17,7 +17,7 @@ "author": "Microsoft Corporation", "version": { "Major": 4, - "Minor": 246, + "Minor": 247, "Patch": 1 }, "releaseNotes": "Configuration of the SonarQube analysis was moved to the [SonarQube](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube) or [SonarCloud](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud) extensions, in task `Prepare Analysis Configuration`", @@ -531,7 +531,7 @@ "NoTestResults": "No test result files matching %s were found, so publishing JUnit test results is being skipped." }, "_buildConfigMapping": { - "Default": "4.246.0", - "Node20-225": "4.246.1" + "Default": "4.247.0", + "Node20-225": "4.247.1" } } \ No newline at end of file diff --git a/_generated/MavenV4_Node20/task.loc.json b/_generated/MavenV4_Node20/task.loc.json index 97c59dc992ff..d298155e4ef2 100644 --- a/_generated/MavenV4_Node20/task.loc.json +++ b/_generated/MavenV4_Node20/task.loc.json @@ -17,7 +17,7 @@ "author": "Microsoft Corporation", "version": { "Major": 4, - "Minor": 246, + "Minor": 247, "Patch": 1 }, "releaseNotes": "ms-resource:loc.releaseNotes", @@ -531,7 +531,7 @@ "NoTestResults": "ms-resource:loc.messages.NoTestResults" }, "_buildConfigMapping": { - "Default": "4.246.0", - "Node20-225": "4.246.1" + "Default": "4.247.0", + "Node20-225": "4.247.1" } } \ No newline at end of file