Esempio n. 1
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);
            }
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }