コード例 #1
0
        protected override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands)
        {
            if (ProvideCommandLineArgs)
            {
                CommandLineArgs = GetArguments(commandLineCommands, responseFileCommands)
                                  .Select(arg => new TaskItem(arg)).ToArray();
            }

            if (SkipCompilerExecution)
            {
                return(0);
            }

            if (!UseSharedCompilation || !string.IsNullOrEmpty(ToolPath))
            {
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));
            }

            using (_sharedCompileCts = new CancellationTokenSource())
            {
                try
                {
                    CompilerServerLogger.Log($"CommandLine = '{commandLineCommands}'");
                    CompilerServerLogger.Log($"BuildResponseFile = '{responseFileCommands}'");

                    var responseTask = BuildClient.TryRunServerCompilation(
                        Language,
                        TryGetClientDir() ?? Path.GetDirectoryName(pathToTool),
                        CurrentDirectoryToUse(),
                        GetArguments(commandLineCommands, responseFileCommands),
                        _sharedCompileCts.Token,
                        libEnvVariable: LibDirectoryToUse());

                    responseTask.Wait(_sharedCompileCts.Token);

                    var response = responseTask.Result;
                    if (response != null)
                    {
                        ExitCode = HandleResponse(response, pathToTool, responseFileCommands, commandLineCommands);
                    }
                    else
                    {
                        ExitCode = base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands);
                    }
                }
                catch (OperationCanceledException)
                {
                    ExitCode = 0;
                }
                catch (Exception e)
                {
                    Log.LogErrorWithCodeFromResources("Compiler_UnexpectedException");
                    LogErrorOutput(e.ToString());
                    ExitCode = -1;
                }
            }
            return(ExitCode);
        }
コード例 #2
0
ファイル: ManagedCompiler.cs プロジェクト: ljcollins25/roslyn
        protected override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands)
        {
            if (!UseSharedCompilation || this.ToolPath != null)
            {
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));
            }

            using (_sharedCompileCts = new CancellationTokenSource())
            {
                try
                {
                    var responseTask = BuildClient.TryRunServerCompilation(
                        Language,
                        TryGetClientDir() ?? Path.GetDirectoryName(pathToTool),
                        CurrentDirectoryToUse(),
                        GetArguments(commandLineCommands, responseFileCommands),
                        _sharedCompileCts.Token,
                        libEnvVariable: LibDirectoryToUse());

                    responseTask.Wait(_sharedCompileCts.Token);

                    var response = responseTask.Result;
                    if (response != null)
                    {
                        ExitCode = HandleResponse(response, pathToTool, responseFileCommands, commandLineCommands);
                    }
                    else
                    {
                        ExitCode = base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands);
                    }
                }
                catch (OperationCanceledException)
                {
                    ExitCode = 0;
                }
                catch (Exception e)
                {
                    Log.LogErrorWithCodeFromResources("Compiler_UnexpectedException");
                    LogErrorOutput(e.ToString());
                    ExitCode = -1;
                }
            }
            return(ExitCode);
        }
コード例 #3
0
ファイル: TaskUtilities.cs プロジェクト: SkightTeam/roslyn
        internal static int ExecuteTool(BuildRequest request, CancellationToken cancellationToken, out bool canceled, out string output, out string errorOutput)
        {
            canceled = false;

            BuildClient          client       = new BuildClient();
            Task <BuildResponse> responseTask = client.GetResponseAsync(request, cancellationToken);

            BuildResponse response = null;

            try
            {
                responseTask.Wait(cancellationToken);
                response = responseTask.Result;
            }
            catch (OperationCanceledException)
            {
                canceled    = true;
                output      = null;
                errorOutput = null;
                return(0);
            }
            catch (AggregateException ae)
            {
                CompilerServerLogger.LogException(ae, "Unexpected failure.");
                foreach (var e in ae.InnerExceptions)
                {
                    CompilerServerLogger.LogException(e, "");
                }
            }

            if (response == null)
            {
                output      = null;
                errorOutput = "Fatal Error: Please see the event log for more details.";
                return(-1);
            }

            output      = response.Output;
            errorOutput = response.ErrorOutput;
            return(response.ReturnCode);
        }
コード例 #4
0
        internal static int ExecuteTool(BuildRequest request, CancellationToken cancellationToken, out bool canceled, out string output, out string errorOutput)
        {
            canceled = false;

            BuildClient client = new BuildClient();
            Task<BuildResponse> responseTask = client.GetResponseAsync(request, cancellationToken);

            BuildResponse response = null;
            try
            {
                responseTask.Wait(cancellationToken);
                response = responseTask.Result;
            }
            catch (OperationCanceledException)
            {
                canceled = true;
                output = null;
                errorOutput = null;
                return 0;
            }
            catch (AggregateException ae)
            {
                CompilerServerLogger.LogException(ae, "Unexpected failure.");
                foreach (var e in ae.InnerExceptions)
                {
                    CompilerServerLogger.LogException(e, "");
                }
            }

            if (response == null)
            {
                output = null;
                errorOutput = "Fatal Error: Please see the event log for more details.";
                return -1;
            }

            output = response.Output;
            errorOutput = response.ErrorOutput;
            return response.ReturnCode;
        }
コード例 #5
0
        protected override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands)
        {
            if (ProvideCommandLineArgs)
            {
                CommandLineArgs = GetArguments(commandLineCommands, responseFileCommands)
                                  .Select(arg => new TaskItem(arg)).ToArray();
            }

            if (SkipCompilerExecution)
            {
                return(0);
            }

            if (!UseSharedCompilation ||
                !string.IsNullOrEmpty(ToolPath) ||
                !Utilities.IsCompilerServerSupported)
            {
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));
            }

            using (_sharedCompileCts = new CancellationTokenSource())
            {
                try
                {
                    CompilerServerLogger.Log($"CommandLine = '{commandLineCommands}'");
                    CompilerServerLogger.Log($"BuildResponseFile = '{responseFileCommands}'");

                    // Try to get the location of the user-provided build client and server,
                    // which should be located next to the build task. If not, fall back to
                    // "pathToTool", which is the compiler in the MSBuild default bin directory.
                    var clientDir = TryGetClientDir() ?? Path.GetDirectoryName(pathToTool);
                    pathToTool = Path.Combine(clientDir, ToolExe);

                    // Note: we can't change the "tool path" printed to the console when we run
                    // the Csc/Vbc task since MSBuild logs it for us before we get here. Instead,
                    // we'll just print our own message that contains the real client location
                    Log.LogMessage(ErrorString.UsingSharedCompilation, clientDir);

                    var workingDir = CurrentDirectoryToUse();
                    var buildPaths = new BuildPaths(
                        clientDir: clientDir,
                        // MSBuild doesn't need the .NET SDK directory
                        sdkDir: null,
                        workingDir: workingDir,
                        tempDir: BuildClient.GetTempPath(workingDir));

                    var responseTask = DesktopBuildClient.RunServerCompilation(
                        Language,
                        GetArguments(commandLineCommands, responseFileCommands).ToList(),
                        buildPaths,
                        keepAlive: null,
                        libEnvVariable: LibDirectoryToUse(),
                        cancellationToken: _sharedCompileCts.Token);

                    responseTask.Wait(_sharedCompileCts.Token);

                    var response = responseTask.Result;
                    if (response != null)
                    {
                        ExitCode = HandleResponse(response, pathToTool, responseFileCommands, commandLineCommands);
                    }
                    else
                    {
                        Log.LogMessage(ErrorString.SharedCompilationFallback, pathToTool);

                        ExitCode = base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands);
                    }
                }
                catch (OperationCanceledException)
                {
                    ExitCode = 0;
                }
                catch (Exception e)
                {
                    Log.LogErrorWithCodeFromResources("Compiler_UnexpectedException");
                    LogErrorOutput(e.ToString());
                    ExitCode = -1;
                }
            }
            return(ExitCode);
        }