Example #1
0
        /// <summary>
        /// This method lets the host request an evaluation of a build request. A local engine
        /// will be created if necessary.
        /// </summary>
        internal void PostBuildRequest
        (
            BuildRequest buildRequest
        )
        {
            buildRequest.RestoreNonSerializedDefaults();
            buildRequest.NodeIndex = EngineCallback.inProcNode;
            // A request has come from the parent engine, so mark it as external
            buildRequest.IsExternalRequest = true;

            if (localEngine == null)
            {
                // Check if an an engine has been allocated and if not start the thread that will do that
                lock (buildRequests)
                {
                    if (localEngine == null)
                    {
                        if (!launchedEngineLoopThread)
                        {
                            launchedEngineLoopThread = true;
                            ThreadStart threadState = new ThreadStart(this.NodeLocalEngineLoop);
                            Thread      taskThread  = new Thread(threadState);
                            taskThread.Name = "MSBuild Child Engine";
                            taskThread.SetApartmentState(ApartmentState.STA);
                            taskThread.Start();
                        }
                        buildRequests.Enqueue(buildRequest);
                    }
                    else
                    {
                        localEngine.PostBuildRequest(buildRequest);
                    }
                }
            }
            else
            {
                if (!buildInProgress)
                {
                    buildInProgress = true;
                    // If there are forwarding loggers registered - generate a custom  build started
                    if (nodeLoggers.Length > 0)
                    {
                        localEngine.LoggingServices.LogBuildStarted(EngineLoggingServicesInProc.CENTRAL_ENGINE_EVENTSOURCE);
                        localEngine.LoggingServices.ProcessPostedLoggingEvents();
                    }
                }
                localEngine.PostBuildRequest(buildRequest);
            }
        }
Example #2
0
        /// <summary>
        /// This method lets the host request an evaluation of a build request. A local engine
        /// will be created if necessary.
        /// </summary>
        internal void PostBuildRequest
        (
            BuildRequest buildRequest
        )
        {
            buildRequest.RestoreNonSerializedDefaults();
            buildRequest.NodeIndex = EngineCallback.inProcNode;
            // A request has come from the parent engine, so mark it as external
            buildRequest.IsExternalRequest = true;

            if (localEngine == null)
            {
                // Check if an an engine has been allocated and if not start the thread that will do that
                lock (buildRequests)
                {
                    if (localEngine == null)
                    {
                        if (!launchedEngineLoopThread)
                        {
                            launchedEngineLoopThread = true;
                            ThreadStart threadState = new ThreadStart(this.NodeLocalEngineLoop);
                            Thread taskThread = new Thread(threadState);
                            taskThread.Name = "MSBuild Child Engine";                            
                            taskThread.SetApartmentState(ApartmentState.STA);
                            taskThread.Start();
                        }
                        buildRequests.Enqueue(buildRequest);
                    }
                    else
                    {
                        localEngine.PostBuildRequest(buildRequest);
                    }
                }
            }
            else
            {
                if (!buildInProgress)
                {
                    buildInProgress = true;
                    // If there are forwarding loggers registered - generate a custom  build started
                    if (nodeLoggers.Length > 0)
                    {
                        localEngine.LoggingServices.LogBuildStarted(EngineLoggingServicesInProc.CENTRAL_ENGINE_EVENTSOURCE);
                        localEngine.LoggingServices.ProcessPostedLoggingEvents();
                    }
                }
                localEngine.PostBuildRequest(buildRequest);
            }
        }
Example #3
0
        private void ProcessBuildRequest(BuildRequest buildRequest)
        {
            ExecutionContext executionContext = GetExecutionContextFromHandleId(buildRequest.HandleId);
            // Restore the requests non-serialized data to the correct state
            buildRequest.RestoreNonSerializedDefaults();
            buildRequest.NodeIndex = executionContext.NodeIndex;

            ErrorUtilities.VerifyThrow(buildRequest.ParentBuildEventContext != null, "Should not have a null parentBuildEventContext");
            ErrorUtilities.VerifyThrow(buildRequest.IsGeneratedRequest == true, "Should not be sending a non generated request from the child node to the parent node");

            // For buildRequests originating from the TEM  - additional initialization is necessary
            TaskExecutionContext taskExecutionContext = executionContext as TaskExecutionContext;
            if (taskExecutionContext != null)
            {
                Project parentProject = taskExecutionContext.ParentProject;
                buildRequest.ParentHandleId = taskExecutionContext.TriggeringBuildRequest.HandleId;
                buildRequest.ParentRequestId = taskExecutionContext.TriggeringBuildRequest.RequestId;

                if (buildRequest.ToolsetVersion == null && parentProject.OverridingToolsVersion)
                {
                    // If the MSBuild task (or whatever) didn't give us a specific tools version,
                    // but the parent project is using an overridden tools version, then use that one
                    buildRequest.ToolsetVersion = parentProject.ToolsVersion;
                }

                try
                {
                    if (buildRequest.GlobalProperties == null)
                    {
                        try
                        {
                            // Make sure we have a blank global properties because if there is a problem merging them we wont have a crash when we try and cache the build result.
                            buildRequest.GlobalProperties = new BuildPropertyGroup();
                            buildRequest.GlobalProperties =
                                parentEngine.MergeGlobalProperties(parentProject.GlobalProperties, null,
                                                                   buildRequest.ProjectFileName,
                                                                   buildRequest.GlobalPropertiesPassedByTask);
                        }
                        catch (ArgumentException e) 
                        {
                            ConvertToInvalidProjectException(buildRequest, parentProject, e);
                        }
                        catch (InvalidOperationException e)
                        {
                            ConvertToInvalidProjectException(buildRequest, parentProject, e);
                        }
                    }

                    // We need to figure out which project object this request is refering to
                    if (buildRequest.ProjectFileName == null)
                    {
                        ErrorUtilities.VerifyThrow(parentProject != null, "Parent project must be non-null");

                        // This means the caller (the MSBuild task) wants us to use the same project as the calling 
                        // project.  This allows people to avoid passing in the Projects parameter on the MSBuild task.
                        Project projectToBuild = parentProject;



                        // If the parent project (the calling project) already has the same set of global properties
                        // as what is being requested, just re-use it.  Otherwise, we need to instantiate a new
                        // project object that has the same project contents but different global properties.
                        if (!projectToBuild.GlobalProperties.IsEquivalent(buildRequest.GlobalProperties) &&
                            (String.Compare(parentProject.ToolsVersion, buildRequest.ToolsetVersion, StringComparison.OrdinalIgnoreCase) == 0))
                        {
                            projectToBuild = parentEngine.GetMatchingProject(parentProject,
                                                 parentProject.FullFileName, buildRequest.GlobalProperties,
                                                 buildRequest.ToolsetVersion, buildRequest.TargetNames, buildRequest.ParentBuildEventContext, buildRequest.ToolsVersionPeekedFromProjectFile);
                        }
                        buildRequest.ProjectToBuild = projectToBuild;
                        buildRequest.ProjectFileName = projectToBuild.FullFileName;
                        buildRequest.FireProjectStartedFinishedEvents = false;
                    }
                }
                catch (InvalidProjectFileException e)
                {
                    buildRequest.BuildCompleted = true;
                    // Store message so it can be logged by the engine build loop
                    buildRequest.BuildException = e;
                }
            }
            else
            {
                RequestRoutingContext requestRoutingContext = executionContext as RequestRoutingContext;
                buildRequest.ParentHandleId = requestRoutingContext.ParentHandleId;
                buildRequest.ParentRequestId = requestRoutingContext.ParentRequestId;
            }
        }
Example #4
0
        private void ProcessBuildRequest(BuildRequest buildRequest)
        {
            ExecutionContext executionContext = GetExecutionContextFromHandleId(buildRequest.HandleId);

            // Restore the requests non-serialized data to the correct state
            buildRequest.RestoreNonSerializedDefaults();
            buildRequest.NodeIndex = executionContext.NodeIndex;

            ErrorUtilities.VerifyThrow(buildRequest.ParentBuildEventContext != null, "Should not have a null parentBuildEventContext");
            ErrorUtilities.VerifyThrow(buildRequest.IsGeneratedRequest, "Should not be sending a non generated request from the child node to the parent node");

            // For buildRequests originating from the TEM  - additional initialization is necessary
            TaskExecutionContext taskExecutionContext = executionContext as TaskExecutionContext;

            if (taskExecutionContext != null)
            {
                Project parentProject = taskExecutionContext.ParentProject;
                buildRequest.ParentHandleId  = taskExecutionContext.TriggeringBuildRequest.HandleId;
                buildRequest.ParentRequestId = taskExecutionContext.TriggeringBuildRequest.RequestId;

                if (buildRequest.ToolsetVersion == null && parentProject.OverridingToolsVersion)
                {
                    // If the MSBuild task (or whatever) didn't give us a specific tools version,
                    // but the parent project is using an overridden tools version, then use that one
                    buildRequest.ToolsetVersion = parentProject.ToolsVersion;
                }

                try
                {
                    if (buildRequest.GlobalProperties == null)
                    {
                        try
                        {
                            // Make sure we have a blank global properties because if there is a problem merging them we wont have a crash when we try and cache the build result.
                            buildRequest.GlobalProperties = new BuildPropertyGroup();
                            buildRequest.GlobalProperties =
                                parentEngine.MergeGlobalProperties(parentProject.GlobalProperties, null,
                                                                   buildRequest.ProjectFileName,
                                                                   buildRequest.GlobalPropertiesPassedByTask);
                        }
                        catch (ArgumentException e)
                        {
                            ConvertToInvalidProjectException(buildRequest, parentProject, e);
                        }
                        catch (InvalidOperationException e)
                        {
                            ConvertToInvalidProjectException(buildRequest, parentProject, e);
                        }
                    }

                    // We need to figure out which project object this request is refering to
                    if (buildRequest.ProjectFileName == null)
                    {
                        ErrorUtilities.VerifyThrow(parentProject != null, "Parent project must be non-null");

                        // This means the caller (the MSBuild task) wants us to use the same project as the calling
                        // project.  This allows people to avoid passing in the Projects parameter on the MSBuild task.
                        Project projectToBuild = parentProject;

                        // If the parent project (the calling project) already has the same set of global properties
                        // as what is being requested, just re-use it.  Otherwise, we need to instantiate a new
                        // project object that has the same project contents but different global properties.
                        if (!projectToBuild.GlobalProperties.IsEquivalent(buildRequest.GlobalProperties) &&
                            (String.Equals(parentProject.ToolsVersion, buildRequest.ToolsetVersion, StringComparison.OrdinalIgnoreCase)))
                        {
                            projectToBuild = parentEngine.GetMatchingProject(parentProject,
                                                                             parentProject.FullFileName, buildRequest.GlobalProperties,
                                                                             buildRequest.ToolsetVersion, buildRequest.TargetNames, buildRequest.ParentBuildEventContext, buildRequest.ToolsVersionPeekedFromProjectFile);
                        }
                        buildRequest.ProjectToBuild  = projectToBuild;
                        buildRequest.ProjectFileName = projectToBuild.FullFileName;
                        buildRequest.FireProjectStartedFinishedEvents = false;
                    }
                }
                catch (InvalidProjectFileException e)
                {
                    buildRequest.BuildCompleted = true;
                    // Store message so it can be logged by the engine build loop
                    buildRequest.BuildException = e;
                }
            }
            else
            {
                RequestRoutingContext requestRoutingContext = executionContext as RequestRoutingContext;
                buildRequest.ParentHandleId  = requestRoutingContext.ParentHandleId;
                buildRequest.ParentRequestId = requestRoutingContext.ParentRequestId;
            }
        }
Example #5
0
        public void RestoreNonSerializedDefaults()
        {

            int nodeProxyId = 1;
            string projectFileName = "ProjectFileName";
            string[] targetNames = new string[] { "Build" };
            Dictionary<string, string> dictionary = null;
            int requestId = 1;

            // Check that the initial values of the properties are set based on the constructor being run
            BuildRequest buildRequest = new BuildRequest(nodeProxyId, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false);
            buildRequest.RestoreNonSerializedDefaults();
            Assert.IsNotNull(buildRequest.OutputsByTarget, "Expected OutputsByTarget to not be null");
            Assert.IsNotNull(buildRequest.ResultByTarget, "Expected ResultByTarget to not be null");
            Assert.IsNull(buildRequest.ProjectToBuild, "Expected ProjectToBuild to be null");
            Assert.IsTrue(buildRequest.BuildSettings == BuildSettings.None, "Expected BuildSettings to be none");
            Assert.IsTrue(buildRequest.FireProjectStartedFinishedEvents, "Expected FireProjectStartedFinishedEvents to be true");
            Assert.AreEqual(EngineCallback.invalidNode, buildRequest.NodeIndex, "Expected NodeIndex to be -2");
            Assert.IsFalse(buildRequest.BuildCompleted, "Expected buildCompleted to be false");
            Assert.IsFalse(buildRequest.BuildSucceeded, "Expected BuildSucceeded to be false");
        }