Exemple #1
0
		public static string GetCommandArgs(string baseCommandArgs, string filePath, DProject project, DProjectConfiguration conf)
		{
			var compiler =project.Compiler;
			ProjectBuilder.PrjPathMacroProvider prjPath = new ProjectBuilder.PrjPathMacroProvider {
				slnPath = project.ParentSolution != null ? ProjectBuilder.EnsureCorrectPathSeparators(project.ParentSolution.BaseDirectory) : ""
			};
			
			List<string> includes = new List<string>(project.IncludePaths);
			includes.Add(project.BaseDirectory.FullPath);

			string[] src = {filePath};
			var compilerMacro = new UnittestMacros
			{
				ObjectsStringPattern = compiler.ArgumentPatterns.ObjectFileLinkPattern,
				IncludesStringPattern = compiler.ArgumentPatterns.IncludePathPattern,

				SourceFiles = src,
				Includes = ProjectBuilder.FillInMacros(includes, prjPath),
				Libraries = ProjectBuilder.GetLibraries(conf, compiler),

				HasMain = HasMainMethod(D_Parser.Misc.GlobalParseCache.GetModule(filePath)),
				compilerFlags = conf.ExtraCompilerArguments,
				linkerFlags = conf.ExtraLinkerArguments
			};
			
			return ProjectBuilder.FillInMacros(baseCommandArgs,compilerMacro, prjPath);
		}
Exemple #2
0
        public static void Run(string filePath, DProject project, DProjectConfiguration conf)
        {
            if(manager == null)
            {
                manager = new ProgressMonitorManager();
                monitor = manager.GetOutputProgressMonitor("Run Unittest",Stock.RunProgramIcon,true,true);
            }

            Pad pad = manager.GetPadForMonitor(monitor);
            if(pad != null)
                pad.BringToFront();

            monitor.BeginTask("start unittest...",1);

            new System.Threading.Thread(delegate (){

                string[] cmdParts = GetCmdParts(project);
                string args = GetCommandArgs(cmdParts.Length >= 2 ?cmdParts[1] : "",filePath,project,conf);
                string errorOutput;
                string stdOutput;
                string execDir = GetExecDir(project,conf);

                ProjectBuilder.ExecuteCommand(cmdParts[0], args, execDir,monitor,out stdOutput, out errorOutput);

                monitor.Log.WriteLine("unittest done.");
                monitor.EndTask();
            }).Start();
        }
Exemple #3
0
        protected virtual ExecutionCommand CreateExecutionCommand(DProjectConfiguration conf)
        {
            var app = GetOutputFileName(conf.Selector);
            var cmd = new NativeExecutionCommand(app);

            cmd.Arguments            = conf.CommandLineParameters;
            cmd.WorkingDirectory     = conf.OutputDirectory.ToAbsolute(BaseDirectory);
            cmd.EnvironmentVariables = conf.EnvironmentVariables;
            return(cmd);
        }
Exemple #4
0
		public static void RunExternal(string filePath, DProject project, DProjectConfiguration conf)
		{
			if(console == null)
				console = ExternalConsoleFactory.Instance.CreateConsole(false);
				
			string args = GetCommandArgs(UnittestSettings.UnittestCommand, filePath, project, conf);
			//string execDir = GetExecDir(project, conf);
				
			//Runtime.ProcessService.StartConsoleProcess(cmdParts[0],args,execDir,console,null);
		}
Exemple #5
0
        public static void RunExternal(string filePath, DProject project, DProjectConfiguration conf)
        {
            if(console == null)
                console = ExternalConsoleFactory.Instance.CreateConsole(false);

            string[] cmdParts = GetCmdParts(project);
            string args = GetCommandArgs(cmdParts.Length >= 2 ?cmdParts[1] : "",filePath,project,conf);
            string execDir = GetExecDir(project, conf);

            Runtime.ProcessService.StartConsoleProcess(cmdParts[0],args,execDir,console,null);
        }
Exemple #6
0
        public override SolutionItemConfiguration CreateConfiguration(string name)
        {
            var config = new DProjectConfiguration()
            {
                Name = name
            };

            //config.Changed += new EventHandler(config_Changed);

            return(config);
        }
Exemple #7
0
        public void Load(DProject proj, DProjectConfiguration config)
        {
            project = proj;
            configuration = config;

            cbUseDefaultCompiler.Active = proj.UseDefaultCompilerVendor;
            cbIsUnittestConfig.Active = config.UnittestMode;
            cbPreferOneStepCompilation.Active = proj.PreferOneStepBuild;

            OnUseDefaultCompilerChanged ();
            Gtk.TreeIter iter;
            if (cmbCompiler.Model.GetIterFirst (out iter))
                do {
                    if (proj.UsedCompilerVendor == cmbCompiler.Model.GetValue (iter, 0) as string) {
                        cmbCompiler.SetActiveIter (iter);
                        break;
                    }
                } while (cmbCompiler.Model.IterNext (ref iter));

            extraCompilerTextView.Buffer.Text = config.ExtraCompilerArguments;
            extraLinkerTextView.Buffer.Text = config.ExtraLinkerArguments;

            check_LinkThirdPartyLibs.Active = configuration.LinkinThirdPartyLibraries;

            text_BinDirectory.Text = proj.GetRelativeChildPath(config.OutputDirectory);
            text_TargetFile.Text = config.Output;
            text_ObjectsDirectory.Text = config.ObjectDirectory;
            text_DDocDir.Text = config.DDocDirectory;

            if(config.CustomDebugIdentifiers==null)
                text_debugConstants.Text = "";
            else
                text_debugConstants.Text = string.Join(";",config.CustomDebugIdentifiers);
            if(config.CustomVersionIdentifiers == null)
                text_versionConstants.Text = "";
            else
                text_versionConstants.Text = string.Join(";", config.CustomVersionIdentifiers);
            spin_debugLevel.Value = (double)config.DebugLevel;

            // Disable debug-specific fields on non-debug configurations
            text_debugConstants.Sensitive = spin_debugLevel.Sensitive = config.DebugMode;

            if (model_compileTarget.GetIterFirst (out iter))
                do {
                    if (config.CompileTarget == (DCompileTarget)model_compileTarget.GetValue (iter, 1)) {
                        combo_ProjectType.SetActiveIter (iter);
                        break;
                    }
                } while (model_compileTarget.IterNext (ref iter));

            text_Libraries.Buffer.Text = string.Join ("\n", config.ExtraLibraries);
        }
Exemple #8
0
        public override SolutionItemConfiguration CreateConfiguration(string name)
        {
            var defConfig = DefaultConfiguration as DProjectConfiguration;
            var c         = new DProjectConfiguration()
            {
                Name = name
            };

            if (name.Contains("|"))
            {
                c.Platform = name.Substring(name.LastIndexOf('|') + 1);
                name       = name.Substring(0, name.IndexOf('|'));
            }

            if (defConfig != null)
            {
                // Try to replace trailing /Debug by /Release, as this is the most common way to name binary directories
                var defOutputDirEnd = Path.DirectorySeparatorChar + defConfig.Name;
                var outputDir       = defConfig.OutputDirectory.ToString();
                if (outputDir.EndsWith(defOutputDirEnd))
                {
                    c.OutputDirectory = Path.Combine(outputDir.Remove(outputDir.Length - defOutputDirEnd.Length), name);
                }

                // Same for intermediate output directory
                outputDir = defConfig.ObjectDirectory;
                if (outputDir.EndsWith(defOutputDirEnd))
                {
                    c.ObjectDirectory = Path.Combine(outputDir.Remove(outputDir.Length - defOutputDirEnd.Length), name);
                }

                c.Output             = defConfig.Output;
                c.CompileTarget      = defConfig.CompileTarget;
                c.ExternalConsole    = defConfig.ExternalConsole;
                c.PauseConsoleOutput = defConfig.PauseConsoleOutput;

                c.ExtraLibraries.AddRange(defConfig.ExtraLibraries);
                c.ExtraLinkerArguments   = defConfig.ExtraLinkerArguments;
                c.ExtraCompilerArguments = defConfig.ExtraCompilerArguments;
            }
            else
            {
                c.OutputDirectory  = this.GetAbsoluteChildPath(defaultBinPathStub).Combine(name);
                c.ObjectDirectory += Path.DirectorySeparatorChar + name;
            }

            return(c);
        }
Exemple #9
0
		/// <summary>
		/// Compiles a D project.
		/// </summary>
		public BuildResult Build (DProject Project, ConfigurationSelector BuildConfigurationSelector)
		{
			this.Project = Project;
			BuildConfig = Project.GetConfiguration (BuildConfigurationSelector) as DProjectConfiguration;

			if(Ide.IdeApp.Workbench == null)
				_currentConfig = BuildConfig.Selector;

			if (BuildConfig.Project != Project)
				throw new InvalidOperationException ("Wrong project configuration");
			commonMacros = new PrjPathMacroProvider {
				slnPath = Project.ParentSolution != null ? EnsureCorrectPathSeparators(Project.ParentSolution.BaseDirectory) : ""
			};
			BuiltObjects.Clear ();

			if (Compiler == null) {
				var targetBuildResult = new BuildResult ();

				targetBuildResult.AddError ("Project compiler \"" + Project.UsedCompilerVendor + "\" not found");
				targetBuildResult.FailedBuildCount++;

				_currentConfig = null;
				return targetBuildResult;
			}

			var absDir = AbsoluteObjectDirectory (BuildConfig);
			if (!Directory.Exists (absDir))
				Directory.CreateDirectory (absDir);

			BuildResult result;
			if (CanDoOneStepBuild)
				result = DoOneStepBuild ();
			else
				result = DoStepByStepBuild ();

			_currentConfig = null;
			return result;
		}
Exemple #10
0
        static string GetCommandArgs(string baseCommandArgs, string filePath, DProject project, DProjectConfiguration conf)
        {
            var compiler =project.Compiler;
            ProjectBuilder.PrjPathMacroProvider prjPath = new ProjectBuilder.PrjPathMacroProvider {
                slnPath = project.ParentSolution != null ? ProjectBuilder.EnsureCorrectPathSeparators(project.ParentSolution.BaseDirectory) : ""
            };

            List<string> includes = new List<string>(project.IncludePaths);
            includes.Add(project.BaseDirectory.FullPath);

            string[] src = {filePath};
            OneStepBuildArgumentMacroProvider compilerMacro = new OneStepBuildArgumentMacroProvider
            {
                ObjectsStringPattern = compiler.ArgumentPatterns.ObjectFileLinkPattern,
                IncludesStringPattern = compiler.ArgumentPatterns.IncludePathPattern,

                SourceFiles = src,
                Includes = ProjectBuilder.FillInMacros(includes, prjPath),
                Libraries = ProjectBuilder.GetLibraries(conf, compiler),

            };

            return ProjectBuilder.FillInMacros(baseCommandArgs,compilerMacro, prjPath);
        }
Exemple #11
0
 static string ObjectDirectory(DProjectConfiguration cfg)
 {
     return EnsureCorrectPathSeparators(cfg.ObjectDirectory);
 }
Exemple #12
0
		public static IEnumerable<string> GetLibraries(DProjectConfiguration projCfg, DCompilerConfiguration compiler)
		{
			var libraries = new List<string>(FillInMacros (projCfg.GetReferencedLibraries (projCfg.Selector), new PrjPathMacroProvider {
				slnPath = projCfg.Project.ParentSolution != null ? projCfg.Project.ParentSolution.BaseDirectory.ToString () : ""
			}));

			// Link in lib files that are ought to be 'Compile'd
			foreach (var pf in projCfg.Project.Files) {
				if (pf.BuildAction != BuildAction.Compile)
					continue;
				
				var filePath = pf.IsLink ? pf.Link : pf.FilePath;
				if (OS.IsWindows ? filePath.Extension == ".a" : filePath.Extension == ".lib")
					libraries.Add(filePath);
			}

			if (compiler.EnableGDCLibPrefixing)
				libraries = new List<string>(HandleGdcSpecificLibraryReferencing(libraries, projCfg.Project.BaseDirectory));

			return libraries;
		}
Exemple #13
0
		public static string GenAdditionalAttributes (DCompilerConfiguration compiler, DProjectConfiguration cfg)
		{
			if (compiler == null || cfg == null)
				return string.Empty;
			
			var sb = new StringBuilder ();
			var p = compiler.ArgumentPatterns;

			string s = cfg.Platform;
			if (s != null && s.Contains('|'))
				s = s.Substring(0, s.IndexOf('|'));
			if (cfg.Platform != null && compiler.ArgumentPatterns.PlatformDependentOptions.TryGetValue(s, out s))
				sb.Append(s).Append(' ');

			if (cfg.UnittestMode)
				sb.Append (p.UnittestFlag).Append(' ');
				
			if(ProfilerModeHandler.IsProfilerMode && compiler.HasProfilerSupport)
				sb.Append (p.ProfileFlag).Append(' ');

			if (cfg.CustomDebugIdentifiers != null && cfg.CustomVersionIdentifiers.Length != 0)
				foreach (var id in cfg.CustomDebugIdentifiers)
					sb.Append (p.DebugDefinition + "=" + id + " ");

			if (cfg.DebugLevel > 0)
				sb.Append (p.DebugDefinition).Append('=').Append(cfg.DebugLevel).Append(' ');

			if (cfg.DebugMode)
				sb.Append (p.DebugDefinition).Append(' ');

			if (cfg.CustomVersionIdentifiers != null && cfg.CustomVersionIdentifiers.Length != 0)
				foreach (var id in cfg.CustomVersionIdentifiers)
					sb.Append (p.VersionDefinition).Append('=').Append(id).Append(' ');

			// DDoc handling
			if (cfg.Project == null)
				return sb.ToString ().Trim ();
			
			var ddocFiles = new List<string> ();
			var files = cfg.Project.GetItemFiles (true);
			foreach (var f in files)
				if (f.Extension.EndsWith (".ddoc", StringComparison.OrdinalIgnoreCase))
					ddocFiles.Add (f);

			if (ddocFiles.Count != 0) {
				sb.Append(p.EnableDDocFlag+" ");

				foreach(var ddoc in ddocFiles){
					sb.AppendFormat(p.DDocDefinitionFile,ddoc);
					sb.Append(" ");
				}

				sb.AppendFormat(p.DDocExportDirectory,Path.IsPathRooted(cfg.DDocDirectory)?
				                cfg.DDocDirectory : 
				              	(new FilePath(cfg.DDocDirectory).ToAbsolute(cfg.Project.BaseDirectory)).ToString());
			}

			return sb.ToString().Trim();
		}
Exemple #14
0
        /// <summary>
        /// Compiles a D project.
        /// </summary>
        public BuildResult Build(DProject Project, ConfigurationSelector BuildConfigurationSelector)
        {
            this.Project = Project;
            BuildConfig = Project.GetConfiguration (BuildConfigurationSelector) as DProjectConfiguration;
            commonMacros = new PrjPathMacroProvider {
                slnPath = Project.ParentSolution != null ? EnsureCorrectPathSeparators(Project.ParentSolution.BaseDirectory) : ""
            };
            BuiltObjects.Clear ();

            if (Compiler == null) {
                var targetBuildResult = new BuildResult ();

                targetBuildResult.AddError ("Project compiler \"" + Project.UsedCompilerVendor + "\" not found");
                targetBuildResult.FailedBuildCount++;

                return targetBuildResult;
            }

            if (!Directory.Exists (AbsoluteObjectDirectory))
                Directory.CreateDirectory (AbsoluteObjectDirectory);

            if (CanDoOneStepBuild)
                return DoOneStepBuild ();
            else
                return DoStepByStepBuild ();
        }
Exemple #15
0
        public static IEnumerable<string> GetLibraries(DProjectConfiguration projCfg, DCompilerConfiguration compiler)
        {
            IEnumerable<string> libraries = FillInMacros (projCfg.GetReferencedLibraries (projCfg.Selector), new PrjPathMacroProvider {
                slnPath = projCfg.Project.ParentSolution != null ? projCfg.Project.ParentSolution.BaseDirectory.ToString () : ""
            });

            if (compiler.EnableGDCLibPrefixing)
                libraries = HandleGdcSpecificLibraryReferencing(libraries, projCfg.Project.BaseDirectory);

            return libraries;
        }
Exemple #16
0
        public static string GenAdditionalAttributes(DCompilerConfiguration compiler, DProjectConfiguration cfg)
        {
            var sb = new StringBuilder ();
            var p = compiler.ArgumentPatterns;

            if (cfg.UnittestMode)
                sb.Append (p.UnittestFlag + " ");

            if(ProfilerModeHandler.IsProfilerMode && compiler.HasProfilerSupport)
                sb.Append (p.ProfileFlag + " -v ");

            if (cfg.CustomDebugIdentifiers != null && cfg.CustomVersionIdentifiers.Length != 0)
                foreach (var id in cfg.CustomDebugIdentifiers)
                    sb.Append (p.DebugDefinition + "=" + id + " ");

            if (cfg.DebugLevel > 0)
                sb.Append (p.DebugDefinition + "=" + cfg.DebugLevel + " ");

            if (cfg.DebugMode)
                sb.Append (p.DebugDefinition + " ");

            if (cfg.CustomVersionIdentifiers != null && cfg.CustomVersionIdentifiers.Length != 0)
                foreach (var id in cfg.CustomVersionIdentifiers)
                    sb.Append (p.VersionDefinition + "=" + id + " ");

            // DDoc handling
            var ddocFiles = new List<string> ();
            var files = cfg.Project.GetItemFiles (true);
            foreach (var f in files)
                if (f.Extension.EndsWith (".ddoc", StringComparison.OrdinalIgnoreCase))
                    ddocFiles.Add (f);

            if (ddocFiles.Count != 0) {
                sb.Append(p.EnableDDocFlag+" ");

                foreach(var ddoc in ddocFiles){
                    sb.AppendFormat(p.DDocDefinitionFile,ddoc);
                    sb.Append(" ");
                }

                sb.AppendFormat(p.DDocExportDirectory,Path.IsPathRooted(cfg.DDocDirectory)?
                                cfg.DDocDirectory :
                              	(new FilePath(cfg.DDocDirectory).ToAbsolute(cfg.Project.BaseDirectory)).ToString());
            }

            return sb.ToString().Trim();
        }
Exemple #17
0
        public override SolutionItemConfiguration CreateConfiguration(string name)
        {
            var config = new DProjectConfiguration() { Name=name};
            //config.Changed += new EventHandler(config_Changed);

            return config;
        }
Exemple #18
0
        public override SolutionItemConfiguration CreateConfiguration(string name)
        {
            var defConfig = DefaultConfiguration as DProjectConfiguration;
            var c = new DProjectConfiguration() { Name=name };
            if (name.Contains("|"))
            {
                c.Platform = name.Substring(name.LastIndexOf('|') + 1);
                name = name.Substring(0, name.IndexOf('|'));
            }

            if (defConfig != null) {
                // Try to replace trailing /Debug by /Release, as this is the most common way to name binary directories
                var defOutputDirEnd = Path.DirectorySeparatorChar + defConfig.Name;
                var outputDir = defConfig.OutputDirectory.ToString ();
                if (outputDir.EndsWith (defOutputDirEnd))
                    c.OutputDirectory = Path.Combine(outputDir.Remove (outputDir.Length - defOutputDirEnd.Length) , name);

                // Same for intermediate output directory
                outputDir = defConfig.ObjectDirectory;
                if (outputDir.EndsWith (defOutputDirEnd))
                    c.ObjectDirectory = Path.Combine(outputDir.Remove (outputDir.Length - defOutputDirEnd.Length) , name);

                c.Output = defConfig.Output;
                c.CompileTarget = defConfig.CompileTarget;
                c.ExternalConsole = defConfig.ExternalConsole;
                c.PauseConsoleOutput = defConfig.PauseConsoleOutput;

                c.ExtraLibraries.AddRange (defConfig.ExtraLibraries);
                c.ExtraLinkerArguments = defConfig.ExtraLinkerArguments;
                c.ExtraCompilerArguments = defConfig.ExtraCompilerArguments;
            } else {
                c.OutputDirectory = this.GetAbsoluteChildPath (defaultBinPathStub).Combine(name);
                c.ObjectDirectory += Path.DirectorySeparatorChar + name;
            }

            return c;
        }
        public static void GenerateMakefile(DProject prj, DProjectConfiguration cfg, ref string file)
        {
            if (string.IsNullOrEmpty(file))
                file = prj.BaseDirectory.Combine("makefile");

            var code = GenerateMakeCode(prj, cfg);

            File.WriteAllText(file, code);
        }
Exemple #20
0
 protected virtual ExecutionCommand CreateExecutionCommand(DProjectConfiguration conf)
 {
     var app = GetOutputFileName(conf.Selector);
     var cmd = new NativeExecutionCommand (app);
     cmd.Arguments = conf.CommandLineParameters;
     cmd.WorkingDirectory = conf.OutputDirectory.ToAbsolute(BaseDirectory);
     cmd.EnvironmentVariables = conf.EnvironmentVariables;
     return cmd;
 }
Exemple #21
0
 static BuildConfiguration BuildArguments(DProjectConfiguration cfg)
 {
     return LinkTargetCfg(cfg).GetArguments (cfg.DebugMode);
 }
Exemple #22
0
 static string AbsoluteObjectDirectory(DProjectConfiguration cfg)
 {
     if (Path.IsPathRooted (cfg.ObjectDirectory))
         return ObjectDirectory(cfg);
     else
         return Path.Combine (cfg.Project.BaseDirectory, ObjectDirectory(cfg));
 }
Exemple #23
0
 public static LinkTargetConfiguration LinkTargetCfg(DProjectConfiguration cfg)
 {
     return cfg.Project.Compiler.GetOrCreateTargetConfiguration (BuildTargetType(cfg));
 }
Exemple #24
0
 public static DCompileTarget BuildTargetType(DProjectConfiguration BuildConfig)
 {
     return BuildConfig.UnittestMode ? DCompileTarget.Executable : BuildConfig.CompileTarget;
 }
Exemple #25
0
        public void Load(DProject proj, DProjectConfiguration config)
        {
            project = proj;
            configuration = config;

            cbUseDefaultCompiler.Active = proj.UseDefaultCompilerVendor;
            cbIsUnittestConfig.Active = config.UnittestMode;
            cbPreferOneStepCompilation.Active = proj.PreferOneStepBuild;

            OnUseDefaultCompilerChanged ();
            Gtk.TreeIter iter;
            if (cmbCompiler.Model.GetIterFirst (out iter))
                do {
                    if (proj.UsedCompilerVendor == cmbCompiler.Model.GetValue (iter, 0) as string) {
                        cmbCompiler.SetActiveIter (iter);
                        break;
                    }
                } while (cmbCompiler.Model.IterNext (ref iter));

            extraCompilerTextView.Buffer.Text = config.ExtraCompilerArguments;
            extraLinkerTextView.Buffer.Text = config.ExtraLinkerArguments;

            check_LinkThirdPartyLibs.Active = configuration.LinkinThirdPartyLibraries;

            text_BinDirectory.Text = proj.GetRelativeChildPath(config.OutputDirectory);
            text_TargetFile.Text = config.Output;
            text_ObjectsDirectory.Text = config.ObjectDirectory;
            text_DDocDir.Text = config.DDocDirectory;

            if(config.CustomDebugIdentifiers==null)
                text_debugConstants.Text = "";
            else
                text_debugConstants.Text = string.Join(";",config.CustomDebugIdentifiers);
            if(config.CustomVersionIdentifiers == null)
                text_versionConstants.Text = "";
            else
                text_versionConstants.Text = string.Join(";", config.CustomVersionIdentifiers);
            spin_debugLevel.Value = (double)config.DebugLevel;

            // Disable debug-specific fields on non-debug configurations
            text_debugConstants.Sensitive = spin_debugLevel.Sensitive = config.DebugMode;

            if (model_compileTarget.GetIterFirst (out iter))
                do {
                    if (config.CompileTarget == (DCompileTarget)model_compileTarget.GetValue (iter, 1)) {
                        combo_ProjectType.SetActiveIter (iter);
                        break;
                    }
                } while (model_compileTarget.IterNext (ref iter));

            text_Libraries.Buffer.Text = string.Join ("\n", config.ExtraLibraries);

            model_Platforms.Clear();
            var blackListed = new List<string>();
            foreach (var cfg in proj.Configurations)
                if (cfg.Name == config.Name && cfg.Platform != config.Platform)
                    blackListed.Add(cfg.Platform.ToLower());

            var platform_lower = config.Platform.ToLower();
            foreach (var platform in proj.SupportedPlatforms)
            {
                // Skip already taken platforms
                if(blackListed.Contains(platform.ToLower()))
                    continue;

                var it = model_Platforms.Append();
                if (platform_lower == platform.ToLower())
                    combo_Platform.SetActiveIter(it);
                model_Platforms.SetValue(it, 0, platform);
            }
        }
Exemple #26
0
        static string PrefixedExtraLinkerFlags(DProjectConfiguration BuildConfig)
        {
            var linkerRedirectPrefix = BuildConfig.Project.Compiler.ArgumentPatterns.LinkerRedirectPrefix;
                if (string.IsNullOrWhiteSpace(BuildConfig.ExtraLinkerArguments))
                    return string.Empty;

                var sb = new StringBuilder(BuildConfig.ExtraLinkerArguments);
                int lastArgStart = -1;
                bool isInString = false;
                for (int i = 0; i < sb.Length; i++)
                {
                    switch(sb[i])
                    {
                        case '\t':
                        case ' ':
                            if(isInString)
                                continue;
                            lastArgStart = -1;
                            break;
                        case '"':
                            isInString = !isInString;
                            goto default;
                        default:
                            if (lastArgStart == -1)
                            {
                                lastArgStart = i;
                                sb.Insert(i, linkerRedirectPrefix);
                                i += linkerRedirectPrefix.Length;
                            }
                            break;
                    }
                }
                return sb.ToString();
        }
Exemple #27
0
 static string GetExecDir(DProject project, DProjectConfiguration conf)
 {
     string execDir = conf.OutputDirectory.FullPath;
     if (!Directory.Exists (execDir))
         execDir = project.BaseDirectory.FullPath;
     return execDir;
 }
        public static string GenerateMakeCode(DProject Project, DProjectConfiguration cfg)
        {
            var compiler = Project.Compiler;

            var s = new StringBuilder();

            // Constants
            var buildCommands = compiler.GetOrCreateTargetConfiguration(cfg.CompileTarget);
            var Arguments = buildCommands.GetArguments(cfg.DebugMode);

            s.AppendLine("compiler=" + compiler.SourceCompilerCommand);
            s.AppendLine("linker=" + buildCommands.Linker);
            s.AppendLine();
            s.AppendLine("target="+ cfg.OutputDirectory.Combine(cfg.CompiledOutputName).ToRelative(Project.BaseDirectory));

            var srcObjPairs = new Dictionary<string, string>();
            var objs= new List<string>();

            foreach (var pf in Project.Files)
            {
                if (pf.BuildAction != BuildAction.Compile)
                    continue;

                var obj = ProjectBuilder.GetRelativeObjectFileName(ProjectBuilder.EnsureCorrectPathSeparators(cfg.ObjectDirectory), pf, DCompilerService.ObjectExtension);

                objs.Add(obj);
                srcObjPairs[pf.FilePath.ToRelative(Project.BaseDirectory)] = obj;
            }

            s.AppendLine("objects = "+ string.Join(" ",objs));
            s.AppendLine();
            s.AppendLine();
            s.AppendLine("all: $(target)");

            // Linker
            s.AppendLine();
            s.AppendLine("$(target): $(objects)");

            var linkArgs = ProjectBuilder.FillInMacros (
                ProjectBuilder.GenAdditionalAttributes(compiler, cfg) +
                Arguments.LinkerArguments + " " + cfg.ExtraLinkerArguments,
                new DLinkerMacroProvider
                {
                    ObjectsStringPattern = "{0}",
                    Objects = new[]{"$(objects)"},
                    TargetFile = "$@",
                    RelativeTargetDirectory = cfg.OutputDirectory.ToRelative (Project.BaseDirectory),
                    Libraries = ProjectBuilder.GetLibraries(cfg, compiler)
                });

            s.AppendLine("\t@echo Linking...");
            s.AppendLine("\t$(linker) "+ linkArgs.Trim());

            // Compiler
            s.AppendLine();

            var compilerCommand = "\t$(compiler) "+ ProjectBuilder.FillInMacros(
                Arguments.CompilerArguments + " " + cfg.ExtraCompilerArguments,
                new DCompilerMacroProvider{
                    IncludePathConcatPattern = compiler.ArgumentPatterns.IncludePathPattern,
                    Includes = Project.IncludePaths,
                    ObjectFile = "$@", SourceFile = "$?"
                })
                // Replace "$?" by $? because the $? macro appends one ' ' (space)
                // to the name which obstructs the source file names
                .Replace("\"$?\"","$?");

            foreach(var kv in srcObjPairs)
            {
                s.AppendLine(kv.Value + " : "+ kv.Key);
                s.AppendLine(compilerCommand);
                s.AppendLine();
            }

            // Clean up
            s.AppendLine("clean:");
            s.AppendLine("\t"+(OS.IsWindows?"del /Q":"$(RM)")+" \"$(target)\" $(objects)");

            return s.ToString();
        }