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

Dev/merlynop/perf test #20511

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
70 changes: 53 additions & 17 deletions BuildConfigGen/GitUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace BuildConfigGen
{
internal static class GitUtil
{
static (string? gitRoot, IEnumerable<string>? cache) NonIgnoredFileListCache;

public static void GetUntrackedFiles(string taskTarget, out IEnumerable<string> toAdd, out IEnumerable<string> toRemove)
{
Expand Down Expand Up @@ -122,40 +123,75 @@ internal static string GetGitRootPath(string currentDir)

internal static IEnumerable<string> 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<string> 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<string> 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);
}
Expand Down
5 changes: 4 additions & 1 deletion BuildConfigGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -945,7 +948,7 @@ private static void CopyConfig(string gitRootPath, string taskTargetPathOrUnders
HashSet<string> 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<string>(GitUtil.GetNonIgnoredFileListFromPath(gitRootPath, taskOutput));
}
Expand Down
2 changes: 1 addition & 1 deletion Tasks/MavenV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/MavenV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 2,
"Minor": 246,
"Patch": 0
"Patch": 2
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"demands": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/MavenV3/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -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`",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/MavenV3/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 3,
"Minor": 246,
"Minor": 247,
"Patch": 0
},
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/MavenV4/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -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`",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/MavenV4/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 4,
"Minor": 246,
"Minor": 247,
"Patch": 0
},
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down
4 changes: 2 additions & 2 deletions _generated/MavenV3.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|3.246.0
Node20-225|3.246.1
Default|3.247.0
Node20-225|3.247.1
6 changes: 3 additions & 3 deletions _generated/MavenV3/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -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`",
Expand Down Expand Up @@ -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"
}
}
6 changes: 3 additions & 3 deletions _generated/MavenV3/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 3,
"Minor": 246,
"Minor": 247,
"Patch": 0
},
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down Expand Up @@ -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"
}
}
6 changes: 3 additions & 3 deletions _generated/MavenV3_Node20/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -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`",
Expand Down Expand Up @@ -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"
}
}
6 changes: 3 additions & 3 deletions _generated/MavenV3_Node20/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 3,
"Minor": 246,
"Minor": 247,
"Patch": 1
},
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down Expand Up @@ -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"
}
}
4 changes: 2 additions & 2 deletions _generated/MavenV4.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|4.246.0
Node20-225|4.246.1
Default|4.247.0
Node20-225|4.247.1
6 changes: 3 additions & 3 deletions _generated/MavenV4/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -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`",
Expand Down Expand Up @@ -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"
}
}
6 changes: 3 additions & 3 deletions _generated/MavenV4/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 4,
"Minor": 246,
"Minor": 247,
"Patch": 0
},
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down Expand Up @@ -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"
}
}
6 changes: 3 additions & 3 deletions _generated/MavenV4_Node20/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -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`",
Expand Down Expand Up @@ -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"
}
}
6 changes: 3 additions & 3 deletions _generated/MavenV4_Node20/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 4,
"Minor": 246,
"Minor": 247,
"Patch": 1
},
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down Expand Up @@ -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"
}
}