Exemple #1
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);
            }
        }
Exemple #2
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);
        }