Skip to content

Commit 807ae4f

Browse files
committed
update callsites for use-case-specific constructors
1 parent e214dbb commit 807ae4f

File tree

10 files changed

+239
-360
lines changed

10 files changed

+239
-360
lines changed

src/Build.UnitTests/BackEnd/LoggingService_Tests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,9 @@ private MockLogger GetLoggedEventsWithWarningsAsErrorsOrMessages(
974974

975975
loggingService.RegisterLogger(logger);
976976

977-
BuildEventContext projectStarted = loggingService.LogProjectStarted(buildEventContext, 0, buildEventContext.ProjectInstanceId, BuildEventContext.Invalid, "projectFile", "Build", Enumerable.Empty<DictionaryEntry>(), Enumerable.Empty<DictionaryEntry>());
977+
var projectStartedArgs = loggingService.CreateProjectStartedForLocalProject(BuildEventContext.Invalid, buildEventContext.ProjectInstanceId, "projectFile", "Build", null, Enumerable.Empty<DictionaryEntry>(), Enumerable.Empty<DictionaryEntry>(), null);
978+
loggingService.LogProjectStarted(projectStartedArgs);
979+
BuildEventContext projectStarted = projectStartedArgs.BuildEventContext;
978980

979981
if (warningsAsErrorsForProject != null)
980982
{

src/Build.UnitTests/BackEnd/LoggingServicesLogMethod_Tests.cs

Lines changed: 19 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,9 @@ public void ProjectStartedNullBuildEventContext()
792792
Assert.Throws<InternalErrorException>(() =>
793793
{
794794
ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);
795-
service.LogProjectStarted(null, 1, 2, s_taskBuildEventContext, "ProjectFile", "TargetNames", null, null, s_targetBuildEventContext.EvaluationId, s_taskBuildEventContext.ProjectContextId);
795+
var args = service.CreateProjectStartedForLocalProject(s_taskBuildEventContext, 2, "ProjectFile", "TargetNames", null, null, null, null);
796+
args.BuildEventContext = null; // Force null context for error test
797+
service.LogProjectStarted(args);
796798
});
797799
}
798800

@@ -806,7 +808,8 @@ public void ProjectStartedNullParentBuildEventContext()
806808
Assert.Throws<InternalErrorException>(() =>
807809
{
808810
ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);
809-
service.LogProjectStarted(s_taskBuildEventContext, 1, 2, null, "ProjectFile", "TargetNames", null, null, s_targetBuildEventContext.EvaluationId, s_taskBuildEventContext.ProjectContextId);
811+
var args = service.CreateProjectStartedForLocalProject(null, 2, "ProjectFile", "TargetNames", null, null, null, null);
812+
service.LogProjectStarted(args);
810813
});
811814
}
812815

@@ -841,7 +844,9 @@ public void ProjectStartedEventTests(string projectFile, string targetNames)
841844
BuildRequestConfiguration config = new BuildRequestConfiguration(2, data, "4.0");
842845
cache.AddConfiguration(config);
843846

844-
BuildEventContext context = service.LogProjectStarted(s_taskBuildEventContext, 1, 2, s_taskBuildEventContext, projectFile, targetNames, null, null, s_targetBuildEventContext.EvaluationId, s_taskBuildEventContext.ProjectContextId);
847+
var args = service.CreateProjectStartedForLocalProject(s_taskBuildEventContext, 2, projectFile, targetNames, null, null, null, null);
848+
service.LogProjectStarted(args);
849+
BuildEventContext context = args.BuildEventContext;
845850
BuildEventContext parentBuildEventContext = s_taskBuildEventContext;
846851
VerifyProjectStartedEventArgs(service, context.ProjectContextId, message, projectFile, targetNames, parentBuildEventContext, context);
847852

@@ -873,17 +878,10 @@ public void ProjectStartedProvidedProjectContextId()
873878
projectCacheBuildEventContext.ProjectContextId.ShouldNotBe(BuildEventContext.InvalidProjectContextId);
874879

875880
BuildEventContext nodeBuildEventContext = BuildEventContext.CreateInitial(0, Scheduler.InProcNodeId);
876-
BuildEventContext projectStartedBuildEventContext = service.LogProjectStarted(
877-
nodeBuildEventContext,
878-
submissionId: SubmissionId,
879-
configurationId: ConfigurationId,
880-
parentBuildEventContext: BuildEventContext.Invalid,
881-
projectFile: ProjectFile,
882-
targetNames: "TargetNames",
883-
properties: null,
884-
items: null,
885-
evaluationId: EvaluationId,
886-
projectContextId: projectCacheBuildEventContext.ProjectContextId);
881+
var args = service.CreateProjectStartedForLocalProject(BuildEventContext.Invalid, ConfigurationId, ProjectFile, "TargetNames", null, null, null, null);
882+
args.BuildEventContext = args.BuildEventContext.WithProjectContextId(projectCacheBuildEventContext.ProjectContextId); // Use provided project context ID
883+
service.LogProjectStarted(args);
884+
BuildEventContext projectStartedBuildEventContext = args.BuildEventContext;
887885
projectStartedBuildEventContext.ProjectContextId.ShouldBe(projectCacheBuildEventContext.ProjectContextId);
888886
}
889887

@@ -907,62 +905,15 @@ public void ProjectStartedProvidedUnknownProjectContextIdInProcNode()
907905
BuildRequestConfiguration config = new BuildRequestConfiguration(ConfigurationId, data, "4.0");
908906
cache.AddConfiguration(config);
909907

910-
BuildEventContext nodeBuildEventContext = BuildEventContext.CreateInitial(0, Scheduler.InProcNodeId);
908+
BuildEventContext parentBuildEventContext = BuildEventContext.CreateInitial(SubmissionId, Scheduler.InProcNodeId).WithEvaluationId(EvaluationId);
909+
BuildEventContext remoteBuildEventContextWithKnownBadContextOnCurrentNode = parentBuildEventContext.WithProjectContextId(ProjectContextId);
911910
Assert.Throws<InternalErrorException>(() =>
912911
{
913-
service.LogProjectStarted(
914-
nodeBuildEventContext,
915-
submissionId: SubmissionId,
916-
configurationId: ConfigurationId,
917-
parentBuildEventContext: BuildEventContext.Invalid,
918-
projectFile: ProjectFile,
919-
targetNames: "TargetNames",
920-
properties: null,
921-
items: null,
922-
evaluationId: EvaluationId,
923-
projectContextId: ProjectContextId);
912+
var args = service.CreateProjectStartedForCachedProject(parentBuildEventContext, remoteBuildEventContextWithKnownBadContextOnCurrentNode, BuildEventContext.Invalid, null, ProjectFile, "TargetNames", null);
913+
service.LogProjectStarted(args);
924914
});
925915
}
926916

927-
/// <summary>
928-
/// Expect an unknown project context id to be accepted on an out-of-proc node.
929-
/// </summary>
930-
[Fact]
931-
public void ProjectStartedProvidedUnknownProjectContextIdOutOfProcNode()
932-
{
933-
const int SubmissionId = 1;
934-
const int EvaluationId = 2;
935-
const int ConfigurationId = 3;
936-
const string ProjectFile = "SomeProjectFile";
937-
const int NodeId = 2;
938-
const int ProjectContextId = 123;
939-
940-
// Ensure we didn't pick the one bad const value
941-
NodeId.ShouldNotBe(Scheduler.InProcNodeId);
942-
943-
MockHost componentHost = new MockHost();
944-
ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1, componentHost);
945-
ConfigCache cache = (ConfigCache)componentHost.GetComponent(BuildComponentType.ConfigCache);
946-
947-
BuildRequestData data = new BuildRequestData(ProjectFile, new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase), "toolsVersion", Array.Empty<string>(), null);
948-
BuildRequestConfiguration config = new BuildRequestConfiguration(ConfigurationId, data, "4.0");
949-
cache.AddConfiguration(config);
950-
951-
BuildEventContext nodeBuildEventContext = BuildEventContext.CreateInitial(0, NodeId);
952-
BuildEventContext projectStartedBuildEventContext = service.LogProjectStarted(
953-
nodeBuildEventContext,
954-
submissionId: SubmissionId,
955-
configurationId: ConfigurationId,
956-
parentBuildEventContext: BuildEventContext.Invalid,
957-
projectFile: ProjectFile,
958-
targetNames: "TargetNames",
959-
properties: null,
960-
items: null,
961-
evaluationId: EvaluationId,
962-
projectContextId: ProjectContextId);
963-
projectStartedBuildEventContext.ProjectContextId.ShouldBe(ProjectContextId);
964-
}
965-
966917
#endregion
967918

968919
#region ProjectFinished
@@ -1422,17 +1373,9 @@ private void TestProjectFinishedEvent(string projectFile, bool success)
14221373
cache.AddConfiguration(config);
14231374

14241375
// Now do it the right way -- with a matching ProjectStarted.
1425-
BuildEventContext projectContext = service.LogProjectStarted(
1426-
BuildEventContext.CreateInitial(0, 1),
1427-
1,
1428-
2,
1429-
s_taskBuildEventContext,
1430-
projectFile,
1431-
null,
1432-
null,
1433-
null,
1434-
s_taskBuildEventContext.EvaluationId,
1435-
s_taskBuildEventContext.ProjectContextId);
1376+
var projectStartedArgs = service.CreateProjectStartedForLocalProject(s_taskBuildEventContext, 2, projectFile, null, null, null, null, null);
1377+
service.LogProjectStarted(projectStartedArgs);
1378+
BuildEventContext projectContext = projectStartedArgs.BuildEventContext;
14361379

14371380
service.LogProjectFinished(projectContext, projectFile, success);
14381381

src/Build.UnitTests/BackEnd/MockLoggingService.cs

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -545,48 +545,70 @@ public void LogProjectEvaluationFinished(
545545
{
546546
}
547547

548-
/// <summary>
549-
/// Logs a project started event
550-
/// </summary>
551-
public BuildEventContext LogProjectStarted(
552-
BuildEventContext nodeBuildEventContext,
553-
int submissionId,
554-
int configurationId,
555-
BuildEventContext parentBuildEventContext,
556-
string projectFile,
557-
string targetNames,
558-
IEnumerable<DictionaryEntry> properties,
559-
IEnumerable<DictionaryEntry> items,
560-
int evaluationId = BuildEventContext.InvalidEvaluationId,
561-
int projectContextId = BuildEventContext.InvalidProjectContextId)
562-
{
563-
return BuildEventContext.CreateInitial(0, 0);
564-
}
565-
566548
public void LogProjectStarted(ProjectStartedEventArgs args)
567549
{ }
568550

569551
public ProjectStartedEventArgs CreateProjectStartedForLocalProject(
570-
BuildEventContext nodeBuildEventContext,
571-
int submissionId,
572-
int configurationId,
573552
BuildEventContext parentBuildEventContext,
553+
int configurationId,
574554
string projectFile,
575555
string targetNames,
556+
IDictionary<string, string> globalProperties,
576557
IEnumerable<DictionaryEntry> properties,
577558
IEnumerable<DictionaryEntry> items,
578-
int evaluationId = BuildEventContext.InvalidEvaluationId,
579-
int projectContextId = BuildEventContext.InvalidProjectContextId)
559+
string toolsVersion)
580560
{
581-
return new ProjectStartedEventArgs(
561+
// Create a mock project context ID for testing
562+
int projectContextId = configurationId;
563+
564+
BuildEventContext projectBuildEventContext = parentBuildEventContext
565+
.WithProjectInstanceId(configurationId)
566+
.WithProjectContextId(projectContextId);
567+
568+
var buildEvent = new ProjectStartedEventArgs(
582569
configurationId,
583570
message: null,
584571
helpKeyword: null,
585572
projectFile,
586573
targetNames,
587574
properties,
588575
items,
589-
parentBuildEventContext);
576+
parentBuildEventContext,
577+
globalProperties,
578+
toolsVersion);
579+
580+
buildEvent.BuildEventContext = projectBuildEventContext;
581+
return buildEvent;
582+
}
583+
584+
public ProjectStartedEventArgs CreateProjectStartedForCachedProject(
585+
BuildEventContext currentNodeBuildEventContext,
586+
BuildEventContext remoteNodeEvaluationBuildEventContext,
587+
BuildEventContext parentBuildEventContext,
588+
IDictionary<string, string> globalProperties,
589+
string projectFile,
590+
string targetNames,
591+
string toolsVersion)
592+
{
593+
BuildEventContext projectBuildEventContext = parentBuildEventContext
594+
.WithProjectInstanceId(remoteNodeEvaluationBuildEventContext.ProjectInstanceId)
595+
.WithProjectContextId(remoteNodeEvaluationBuildEventContext.ProjectContextId);
596+
597+
var buildEvent = new ProjectStartedEventArgs(
598+
remoteNodeEvaluationBuildEventContext.ProjectInstanceId,
599+
message: null,
600+
helpKeyword: null,
601+
projectFile,
602+
targetNames,
603+
null, // No properties for cache scenarios in mock
604+
null, // No items for cache scenarios in mock
605+
parentBuildEventContext,
606+
globalProperties,
607+
toolsVersion,
608+
remoteNodeEvaluationBuildEventContext); // Pass original context
609+
610+
buildEvent.BuildEventContext = projectBuildEventContext;
611+
return buildEvent;
590612
}
591613

592614
/// <summary>

src/Build.UnitTests/BackEnd/TargetBuilder_Tests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,9 @@ private ProjectInstance CreateTestProject(string projectBodyContents, string ini
16941694
/// <returns>The context</returns>
16951695
private ProjectLoggingContext GetProjectLoggingContext(BuildRequestEntry entry)
16961696
{
1697-
return new ProjectLoggingContext(new NodeLoggingContext(_host, BuildEventContext.Invalid.WithNodeId(1), 1, false), entry);
1697+
var nodeContext = new NodeLoggingContext(_host, BuildEventContext.Invalid.WithNodeId(1), 1, false);
1698+
var (_, context) = ProjectLoggingContext.CreateForLocalBuild(nodeContext, entry);
1699+
return context;
16981700
}
16991701

17001702
/// <summary>

src/Build.UnitTests/BackEnd/TargetEntry_Tests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,9 @@ private ProjectInstance CreateTestProject(bool returnsAttributeEnabled)
10861086
/// <returns>The project logging context.</returns>
10871087
private ProjectLoggingContext GetProjectLoggingContext(BuildRequestEntry entry)
10881088
{
1089-
return new ProjectLoggingContext(new NodeLoggingContext(_host, BuildEventContext.Invalid.WithNodeId(1), 1, false), entry);
1089+
var nodeContext = new NodeLoggingContext(_host, BuildEventContext.Invalid.WithNodeId(1), 1, false);
1090+
var (_, context) = ProjectLoggingContext.CreateForLocalBuild(nodeContext, entry);
1091+
return context;
10901092
}
10911093

10921094
/// <summary>

src/Build/BackEnd/Components/Logging/ILoggingService.cs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -541,41 +541,52 @@ void LogProjectEvaluationFinished(
541541
/// Creates a ProjectStartedEventArgs for a locally-building project -
542542
/// meaning one that is not served from cache and is building on the current node.
543543
/// </summary>
544-
/// <param name="parentBuildEventContext">The parent build event context for the project that is about to be built.</param>
545-
/// <param name="projectConfiguration">The project configuration of the project that is about to be built.</param>
546-
/// <param name="projectFile">The project file path of the project that is about to be built.</param>
547-
/// <param name="targetNames">The target names to be built.</param>
544+
/// <param name="parentBuildEventContext">The parent build event context for the project that is starting.</param>
545+
/// <param name="configurationId">The configuration ID of the project that is starting.</param>
546+
/// <param name="projectFile">The project file path of the project that is starting.</param>
547+
/// <param name="targetNames">The target names that are being built.</param>
548+
/// <param name="globalProperties">The global properties for the project instance.</param>
548549
/// <param name="properties">The initial properties for the project instance, if any.</param>
549550
/// <param name="items">The initial items for the project instance, if any.</param>
551+
/// <param name="toolsVersion">The tools version for the project instance.</param>
552+
/// <remarks>
553+
/// We _could_ pass in BuildRequest/BuildRequestConfiguration for most of this data, but that makes layering/dependency
554+
/// tracking of the namespaces more complex, and we don't really need the full objects here.
555+
/// </remarks>
550556
ProjectStartedEventArgs CreateProjectStartedForLocalProject(
551557
BuildEventContext parentBuildEventContext,
552-
BuildRequestConfiguration projectConfiguration,
558+
int configurationId,
553559
string projectFile,
554560
string targetNames,
561+
IDictionary<string, string> globalProperties,
555562
IEnumerable<DictionaryEntry> properties,
556-
IEnumerable<DictionaryEntry> items);
563+
IEnumerable<DictionaryEntry> items,
564+
string toolsVersion);
557565

558566
/// <summary>
559567
/// Creates a ProjectStartedEventArgs for a project that was already built on another node, so
560-
/// is being served from cache.
568+
/// is being served from cache. Unlike the local-build case, we don't have properties/items
569+
/// because they were not deserialized from the cache.
561570
/// </summary>
562571
/// <param name="currentNodeBuildEventContext">The build event context on the current node.</param>
563572
/// <param name="remoteNodeEvaluationBuildEventContext">The complete evaluation build event context on the remote node.</param>
564573
/// <param name="parentBuildEventContext">The parent build event context for the project that is already built.</param>
565-
/// <param name="projectConfiguration">The (cached) project configuration of the project that is already built.</param>
574+
/// <param name="globalProperties">The global properties for the project instance, from the configuration.</param>
566575
/// <param name="projectFile">The project file path of the project that is already built.</param>
567576
/// <param name="targetNames">The target names that were built.</param>
568-
/// <param name="properties">The initial properties for the project instance, if any.</param>
569-
/// <param name="items">The initial items for the project instance, if any.</param>
577+
/// <param name="toolsVersion">The tools version for the project instance.</param>
578+
/// <remarks>
579+
/// We _could_ pass in BuildRequest/BuildRequestConfiguration for most of this data, but that makes layering/dependency
580+
/// tracking of the namespaces more complex, and we don't really need the full objects here.
581+
/// </remarks>
570582
ProjectStartedEventArgs CreateProjectStartedForCachedProject(
571583
BuildEventContext currentNodeBuildEventContext,
572584
BuildEventContext remoteNodeEvaluationBuildEventContext,
573585
BuildEventContext parentBuildEventContext,
574-
BuildRequestConfiguration projectConfiguration,
586+
IDictionary<string, string> globalProperties,
575587
string projectFile,
576588
string targetNames,
577-
IEnumerable<DictionaryEntry> properties,
578-
IEnumerable<DictionaryEntry> items);
589+
string toolsVersion);
579590

580591
/// <summary>
581592
/// Log that the project has finished

0 commit comments

Comments
 (0)