Ejemplo n.º 1
0
        /// <summary>
        /// Scans errorString line-wise for filename-line-message patterns (e.g. "myModule(1): Something's wrong here") and add these error locations to the CompilerResults cr.
        /// </summary>
        public static void HandleCompilerOutput(AbstractDProject Project, BuildResult br, string errorString)
        {
            var    reader = new StringReader(errorString);
            string next;

            while ((next = reader.ReadLine()) != null)
            {
                var error = ErrorExtracting.FindError(next, reader);
                if (error != null)
                {
                    if (error.ErrorText != null && error.ErrorText.Length > MaxErrorMsgLength)
                    {
                        error.ErrorText = error.ErrorText.Substring(0, MaxErrorMsgLength) + "...";
                    }

                    // dmd's error filenames may contain mixin location info
                    var m = mixinInlineRegex.Match(error.FileName);
                    if (m.Success)
                    {
                        error.FileName = error.FileName.Substring(0, m.Index);
                        int line;
                        int.TryParse(m.Groups ["line"].Value, out line);
                        error.Line = line;
                    }

                    if (!Path.IsPathRooted(error.FileName))
                    {
                        error.FileName = Project.GetAbsoluteChildPath(error.FileName);
                    }
                    br.Append(error);
                }
            }

            reader.Close();
        }
Ejemplo n.º 2
0
        void LinkToTarget(BuildResult br, bool modificationsDone)
        {
            // The target file to which all objects will be linked to
            var LinkTargetFile = Project.GetOutputFileName(BuildConfig.Selector);

            if (!modificationsDone &&
                File.Exists(LinkTargetFile))
            {
                monitor.ReportSuccess("Build successful! - No new linkage needed");
                monitor.Step(1);
                return;
            }

            // b.Build linker argument string
            // Build argument preparation
            var linkArgs = FillInMacros(BuildArguments(BuildConfig).LinkerArguments.Trim() +
                                        (string.IsNullOrEmpty(BuildConfig.ExtraLinkerArguments) ? string.Empty : (" " + BuildConfig.ExtraLinkerArguments.Trim())),
                                        new DLinkerMacroProvider
            {
                ObjectsStringPattern = Compiler.ArgumentPatterns.ObjectFileLinkPattern,
                Objects    = BuiltObjects.ToArray(),
                TargetFile = LinkTargetFile,
                RelativeTargetDirectory = BuildConfig.OutputDirectory.ToRelative(Project.BaseDirectory),
                Libraries = GetLibraries(BuildConfig, Compiler)
            }, commonMacros);

            var linkerOutput      = "";
            var linkerErrorOutput = "";
            var linkCfg           = LinkTargetCfg(BuildConfig);

            var linkerExecutable = linkCfg.Linker;

            if (!Path.IsPathRooted(linkerExecutable) && !string.IsNullOrEmpty(Compiler.BinPath))
            {
                linkerExecutable = Path.Combine(Compiler.BinPath, linkCfg.Linker);

                if (!File.Exists(linkerExecutable))
                {
                    linkerExecutable = linkCfg.Linker;
                }
            }

            string cmdLineFile;

            HandleOverLongArgumentStrings(monitor, Compiler, true, ref linkArgs, out cmdLineFile);

            int exitCode = ExecuteCommand(linkerExecutable, linkArgs, Project.BaseDirectory, monitor,
                                          out linkerErrorOutput,
                                          out linkerOutput);

            ErrorExtracting.HandleOptLinkOutput(Project, br, linkerOutput);
            ErrorExtracting.HandleLdOutput(Project, br, linkerOutput);
            ErrorExtracting.HandleReturnCode(monitor, br, exitCode);

            if (cmdLineFile != null && !br.Failed)
            {
                File.Delete(cmdLineFile);
            }
        }
Ejemplo n.º 3
0
        bool CompileResourceScript(BuildResult targetBuildResult, ProjectFile f)
        {
            var res = GetRelativeObjectFileName(ObjectDirectory, f, ".res");

            // Build argument string
            var resCmpArgs = FillInMacros(Win32ResourceCompiler.Instance.Arguments,
                                          new Win32ResourceCompiler.ArgProvider
            {
                RcFile  = f.FilePath,
                ResFile = res
            }, commonMacros);

            // Execute compiler
            string output;
            string stdOutput;

            int _exitCode = ExecuteCommand(Win32ResourceCompiler.Instance.Executable,
                                           resCmpArgs,
                                           Project.BaseDirectory,
                                           monitor,
                                           out output,
                                           out stdOutput);

            // Error analysis
            if (!string.IsNullOrEmpty(output))
            {
                targetBuildResult.AddError(f.FilePath, 0, 0, "", output);
            }
            if (!string.IsNullOrEmpty(stdOutput))
            {
                targetBuildResult.AddError(f.FilePath, 0, 0, "", stdOutput);
            }

            ErrorExtracting.HandleReturnCode(monitor, targetBuildResult, _exitCode);

            if (_exitCode != 0)
            {
                targetBuildResult.FailedBuildCount++;
                return(false);
            }
            else
            {
                f.LastGenOutput = res;

                targetBuildResult.BuildCount++;
                Project.LastModificationTimes [f] = File.GetLastWriteTime(f.FilePath);

                BuiltObjects.Add(MakeRelativeToPrjBase(res));
                return(true);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Scans errorString line-wise for filename-line-message patterns (e.g. "myModule(1): Something's wrong here") and add these error locations to the CompilerResults cr.
        /// </summary>
        public static void HandleCompilerOutput(AbstractDProject Project, BuildResult br, string errorString)
        {
            var    reader = new StringReader(errorString);
            string next;

            while ((next = reader.ReadLine()) != null)
            {
                var error = ErrorExtracting.FindError(next, reader);
                if (error != null)
                {
                    if (!Path.IsPathRooted(error.FileName))
                    {
                        error.FileName = Project.GetAbsoluteChildPath(error.FileName);
                    }
                    br.Append(error);
                }
            }

            reader.Close();
        }
Ejemplo n.º 5
0
        bool CompileSource(BuildResult targetBuildResult, ProjectFile f)
        {
            if (File.Exists(f.LastGenOutput))
            {
                File.Delete(f.LastGenOutput);
            }

            var obj = GetRelativeObjectFileName(ObjectDirectory, f, DCompilerService.ObjectExtension);

            // Create argument string for source file compilation.
            var dmdArgs = FillInMacros((string.IsNullOrEmpty(AdditionalCompilerAttributes) ? string.Empty : (AdditionalCompilerAttributes.Trim() + " ")) +
                                       BuildArguments.CompilerArguments.Trim() +
                                       (string.IsNullOrEmpty(BuildConfig.ExtraCompilerArguments) ? string.Empty : (" " + BuildConfig.ExtraCompilerArguments.Trim())),
                                       new DCompilerMacroProvider
            {
                IncludePathConcatPattern = Compiler.ArgumentPatterns.IncludePathPattern,
                SourceFile = f.FilePath.ToRelative(Project.BaseDirectory),
                ObjectFile = obj,
                Includes   = FillCommonMacros(Project.IncludePaths).Union(FileLinkDirectories),
            }, commonMacros);

            // b.Execute compiler
            string stdError;
            string stdOutput;

            var compilerExecutable = Compiler.SourceCompilerCommand;

            if (!Path.IsPathRooted(compilerExecutable) && !string.IsNullOrEmpty(Compiler.BinPath))
            {
                compilerExecutable = Path.Combine(Compiler.BinPath, Compiler.SourceCompilerCommand);

                if (!File.Exists(compilerExecutable))
                {
                    compilerExecutable = Compiler.SourceCompilerCommand;
                }
            }

            string cmdArgFile;

            HandleOverLongArgumentStrings(Compiler, false, ref dmdArgs, out cmdArgFile);

            int exitCode = ExecuteCommand(compilerExecutable, dmdArgs, Project.BaseDirectory, monitor, out stdError, out stdOutput);

            ErrorExtracting.HandleCompilerOutput(Project, targetBuildResult, stdError);
            ErrorExtracting.HandleCompilerOutput(Project, targetBuildResult, stdOutput);
            ErrorExtracting.HandleReturnCode(monitor, targetBuildResult, exitCode);

            if (exitCode != 0)
            {
                targetBuildResult.FailedBuildCount++;
                return(false);
            }
            else
            {
                if (cmdArgFile != null)
                {
                    File.Delete(cmdArgFile);
                }

                f.LastGenOutput = obj;

                targetBuildResult.BuildCount++;
                Project.LastModificationTimes [f] = File.GetLastWriteTime(f.FilePath);

                BuiltObjects.Add(obj);
                return(true);
            }
        }
Ejemplo n.º 6
0
        BuildResult DoOneStepBuild()
        {
            var br = new BuildResult();

            bool filesModified = false;

            // Enum files & build resource files
            foreach (var pf in Project.Files)
            {
                if (pf.BuildAction != BuildAction.Compile || pf.Subtype == Subtype.Directory)
                {
                    continue;
                }

                DateTime dt;
                if (Project.LastModificationTimes.TryGetValue(pf, out dt))
                {
                    filesModified |= File.GetLastWriteTime(pf.FilePath) != dt;
                }
                else
                {
                    filesModified = true;
                }
                Project.LastModificationTimes[pf] = File.GetLastWriteTime(pf.FilePath);

                if (pf.FilePath.Extension.EndsWith(".rc", StringComparison.OrdinalIgnoreCase))
                {
                    if (!CompileResourceScript(br, pf))
                    {
                        return(br);
                    }
                }
                else
                {
                    BuiltObjects.Add(MakeRelativeToPrjBase(pf.FilePath));
                }
            }

            // Build argument string
            var target = Project.GetOutputFileName(BuildConfig.Selector);

            if (!filesModified && Project.EnableIncrementalLinking &&
                File.Exists(target))
            {
                monitor.ReportSuccess("Build successful! - No new linkage needed");
                monitor.Step(1);
                return(br);
            }

            var rawArgumentString = new StringBuilder();

            if (!string.IsNullOrEmpty(AdditionalCompilerAttributes))
            {
                rawArgumentString.Append(AdditionalCompilerAttributes.Trim()).Append(' ');
            }
            rawArgumentString.Append(BuildArguments.OneStepBuildArguments.Trim());
            if (!string.IsNullOrEmpty(BuildConfig.ExtraCompilerArguments))
            {
                rawArgumentString.Append(' ').Append(BuildConfig.ExtraCompilerArguments.Trim());
            }
            if (!string.IsNullOrEmpty(BuildConfig.ExtraLinkerArguments))
            {
                rawArgumentString.Append(' ').Append(PrefixedExtraLinkerFlags);
            }

            var argumentString = FillInMacros(rawArgumentString.ToString(),
                                              new OneStepBuildArgumentMacroProvider
            {
                ObjectsStringPattern  = Compiler.ArgumentPatterns.ObjectFileLinkPattern,
                IncludesStringPattern = Compiler.ArgumentPatterns.IncludePathPattern,

                SourceFiles = BuiltObjects,
                Includes    = FillCommonMacros(Project.IncludePaths),
                Libraries   = GetLibraries(BuildConfig, Compiler),

                RelativeTargetDirectory = BuildConfig.OutputDirectory,
                ObjectsDirectory        = ObjectDirectory,
                TargetFile = target,
            }, commonMacros);


            // Execute the compiler
            var stdOut   = "";
            var stdError = "";

            var linkerExecutable = Compiler.SourceCompilerCommand;

            if (!Path.IsPathRooted(linkerExecutable) && !string.IsNullOrEmpty(Compiler.BinPath))
            {
                linkerExecutable = Path.Combine(Compiler.BinPath, LinkTargetCfg.Linker);

                if (!File.Exists(linkerExecutable))
                {
                    linkerExecutable = LinkTargetCfg.Linker;
                }
            }

            monitor.Log.WriteLine("Current dictionary: " + Project.BaseDirectory);

            string cmdLineFile;

            HandleOverLongArgumentStrings(Compiler, true, ref argumentString, out cmdLineFile);

            int exitCode = ExecuteCommand(linkerExecutable, argumentString, Project.BaseDirectory, monitor,
                                          out stdError,
                                          out stdOut);

            ErrorExtracting.HandleCompilerOutput(Project, br, stdError);
            ErrorExtracting.HandleCompilerOutput(Project, br, stdOut);
            ErrorExtracting.HandleOptLinkOutput(Project, br, stdOut);
            ErrorExtracting.HandleReturnCode(monitor, br, exitCode);

            if (cmdLineFile != null)
            {
                File.Delete(cmdLineFile);
            }

            return(br);
        }
Ejemplo n.º 7
0
        BuildResult DoOneStepBuild()
        {
            var br = new BuildResult();

            bool filesModified = false;

            // Enum files & build resource files
            foreach (var pf in Project.Files)
            {
                if (pf.BuildAction != BuildAction.Compile || pf.Subtype == Subtype.Directory)
                {
                    continue;
                }

                DateTime dt;
                if (Project.LastModificationTimes.TryGetValue(pf, out dt))
                {
                    filesModified |= File.GetLastWriteTime(pf.FilePath) != dt;
                }
                else
                {
                    filesModified = true;
                }
                Project.LastModificationTimes[pf] = File.GetLastWriteTime(pf.FilePath);

                if (pf.FilePath.Extension.EndsWith(".rc", StringComparison.OrdinalIgnoreCase))
                {
                    if (!CompileResourceScript(br, pf))
                    {
                        return(br);
                    }
                }
                else
                {
                    BuiltObjects.Add(MakeRelativeToPrjBase(Project, pf.FilePath));
                }
            }

            // Build argument string
            var target = Project.GetOutputFileName(BuildConfig.Selector);

            if (!Project.NeedsFullRebuild && !filesModified && Project.EnableIncrementalLinking &&
                File.Exists(target))
            {
                monitor.ReportSuccess("Build successful! - No new linkage needed");
                monitor.Step(1);
                return(br);
            }

            var argumentString = BuildOneStepBuildString(Project, BuiltObjects, BuildConfig.Selector);


            // Execute the compiler
            var stdOut   = "";
            var stdError = "";
            var linkCfg  = LinkTargetCfg(BuildConfig);

            var linkerExecutable = Compiler.SourceCompilerCommand;

            if (!Path.IsPathRooted(linkerExecutable) && !string.IsNullOrEmpty(Compiler.BinPath))
            {
                linkerExecutable = Path.Combine(Compiler.BinPath, linkCfg.Linker);

                if (!File.Exists(linkerExecutable))
                {
                    linkerExecutable = linkCfg.Linker;
                }
            }

            monitor.Log.WriteLine("Current dictionary: " + Project.BaseDirectory);

            string cmdLineFile;

            HandleOverLongArgumentStrings(monitor, Compiler, true, ref argumentString, out cmdLineFile);

            int exitCode = ExecuteCommand(linkerExecutable, argumentString, Project.BaseDirectory, monitor,
                                          out stdError,
                                          out stdOut);

            ErrorExtracting.HandleCompilerOutput(Project, br, stdError);
            ErrorExtracting.HandleCompilerOutput(Project, br, stdOut);
            ErrorExtracting.HandleOptLinkOutput(Project, br, stdOut);
            ErrorExtracting.HandleLdOutput(Project, br, stdOut);
            ErrorExtracting.HandleReturnCode(monitor, br, exitCode);

            if (cmdLineFile != null)
            {
                File.Delete(cmdLineFile);
            }

            if (!br.Failed)
            {
                Project.CopySupportFiles(monitor, this.BuildConfig.Selector);
                Project.NeedsFullRebuild = false;
            }

            return(br);
        }