示例#1
0
        protected override string GenerateCommandLineCommands()
        {
            var cmd = new CommandLineBuilder();

                        #if DEBUG
            cmd.AppendSwitch("/v");
                        #endif

            if (NoStdLib)
            {
                cmd.AppendSwitch("/nostdlib");
            }
            cmd.AppendSwitchIfNotNull("/compiler:", CompilerPath);
            cmd.AppendSwitchIfNotNull("/baselib:", BaseLibDll);
            cmd.AppendSwitchIfNotNull("/out:", OutputAssembly);

            if (NoStdLib)
            {
                string dir;
                if (!string.IsNullOrEmpty(BaseLibDll))
                {
                    dir = Path.GetDirectoryName(BaseLibDll);
                }
                else
                {
                    dir = null;
                }

                cmd.AppendSwitchIfNotNull("/lib:", dir);
                cmd.AppendSwitchIfNotNull("/r:", Path.Combine(dir, "mscorlib.dll"));
            }

            if (ProcessEnums)
            {
                cmd.AppendSwitch("/process-enums");
            }

            if (EmitDebugInformation)
            {
                cmd.AppendSwitch("/debug");
            }

            if (AllowUnsafeBlocks)
            {
                cmd.AppendSwitch("/unsafe");
            }

            cmd.AppendSwitchIfNotNull("/ns:", Namespace);

            if (!string.IsNullOrEmpty(DefineConstants))
            {
                var strv      = DefineConstants.Split(new [] { ';' });
                var sanitized = new List <string> ();

                foreach (var str in strv)
                {
                    if (str != string.Empty)
                    {
                        sanitized.Add(str);
                    }
                }

                if (sanitized.Count > 0)
                {
                    cmd.AppendSwitchIfNotNull("/d:", string.Join(";", sanitized.ToArray()));
                }
            }

            //cmd.AppendSwitch ("/e");

            foreach (var item in ApiDefinitions)
            {
                cmd.AppendFileNameIfNotNull(Path.GetFullPath(item.ItemSpec));
            }

            if (CoreSources != null)
            {
                foreach (var item in CoreSources)
                {
                    cmd.AppendSwitchIfNotNull("/s:", Path.GetFullPath(item.ItemSpec));
                }
            }

            if (Sources != null)
            {
                foreach (var item in Sources)
                {
                    cmd.AppendSwitchIfNotNull("/x:", Path.GetFullPath(item.ItemSpec));
                }
            }

            if (AdditionalLibPaths != null)
            {
                foreach (var item in AdditionalLibPaths)
                {
                    cmd.AppendSwitchIfNotNull("/lib:", Path.GetFullPath(item.ItemSpec));
                }
            }

            HandleReferences(cmd);

            if (Resources != null)
            {
                foreach (var item in Resources)
                {
                    var    args = new List <string> ();
                    string id;

                    args.Add(item.ToString());
                    id = item.GetMetadata("LogicalName");
                    if (!string.IsNullOrEmpty(id))
                    {
                        args.Add(id);
                    }

                    cmd.AppendSwitchIfNotNull("/res:", args.ToArray(), ",");
                }
            }

            if (NativeLibraries != null)
            {
                foreach (var item in NativeLibraries)
                {
                    var    args = new List <string> ();
                    string id;

                    args.Add(item.ToString());
                    id = item.GetMetadata("LogicalName");
                    if (string.IsNullOrEmpty(id))
                    {
                        id = Path.GetFileName(args[0]);
                    }
                    args.Add(id);

                    cmd.AppendSwitchIfNotNull("/link-with:", args.ToArray(), ",");
                }
            }

            if (GeneratedSourcesDir != null)
            {
                cmd.AppendSwitchIfNotNull("/tmpdir:", Path.GetFullPath(GeneratedSourcesDir));
            }

            if (GeneratedSourcesFileList != null)
            {
                cmd.AppendSwitchIfNotNull("/sourceonly:", Path.GetFullPath(GeneratedSourcesFileList));
            }

            cmd.AppendSwitch(GetTargetFrameworkArgument());

            if (!string.IsNullOrEmpty(ExtraArgs))
            {
                var    extraArgs = ProcessArgumentBuilder.Parse(ExtraArgs);
                var    target    = OutputAssembly;
                string projectDir;

                if (ProjectDir.StartsWith("~/", StringComparison.Ordinal))
                {
                    // Note: Since the Visual Studio plugin doesn't know the user's home directory on the Mac build host,
                    // it simply uses paths relative to "~/". Expand these paths to their full path equivalents.
                    var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

                    projectDir = Path.Combine(home, ProjectDir.Substring(2));
                }
                else
                {
                    projectDir = ProjectDir;
                }

                var customTags = new Dictionary <string, string> (StringComparer.OrdinalIgnoreCase)
                {
                    { "projectdir", projectDir },
                    // Apparently msbuild doesn't propagate the solution path, so we can't get it.
                    // { "solutiondir",  proj.ParentSolution != null ? proj.ParentSolution.BaseDirectory : proj.BaseDirectory },
                    { "targetpath", Path.Combine(Path.GetDirectoryName(target), Path.GetFileName(target)) },
                    { "targetdir", Path.GetDirectoryName(target) },
                    { "targetname", Path.GetFileName(target) },
                    { "targetext", Path.GetExtension(target) },
                };

                for (int i = 0; i < extraArgs.Length; i++)
                {
                    var argument = extraArgs[i];

                    cmd.AppendTextUnquoted(StringParserService.Parse(argument, customTags));
                }
            }

            return(cmd.ToString());
        }
示例#2
0
        protected override string GenerateCommandLineCommands()
        {
            var cmd = new CommandLineBuilder();

#if DEBUG
            cmd.AppendSwitch("/v");
#endif
            if (NoStdLib)
            {
                cmd.AppendSwitch("/nostdlib");
            }
            cmd.AppendSwitchIfNotNull("/compiler:", CompilerPath);
            cmd.AppendSwitchIfNotNull("/baselib:", BaseLibDll);
            cmd.AppendSwitchIfNotNull("/out:", OutputAssembly);

            if (NoStdLib)
            {
                string dir;
                if (!string.IsNullOrEmpty(BaseLibDll))
                {
                    dir = Path.GetDirectoryName(BaseLibDll);
                }
                else
                {
                    dir = null;
                }
                cmd.AppendSwitchIfNotNull("/lib:", dir);
                cmd.AppendSwitchIfNotNull("/r:", Path.Combine(dir, "mscorlib.dll"));
            }

            if (EmitDebugInformation)
            {
                cmd.AppendSwitch("/debug");
            }

            if (AllowUnsafeBlocks)
            {
                cmd.AppendSwitch("/unsafe");
            }

            cmd.AppendSwitchIfNotNull("/ns:", Namespace);

            if (!string.IsNullOrEmpty(DefineConstants))
            {
                string[] strv      = DefineConstants.Split(new [] { ';' });
                var      sanitized = new List <string> ();

                foreach (var str in strv)
                {
                    if (str != string.Empty)
                    {
                        sanitized.Add(str);
                    }
                }

                if (sanitized.Count > 0)
                {
                    cmd.AppendSwitchIfNotNull("/d:", string.Join(";", sanitized.ToArray()));
                }
            }

            //cmd.AppendSwitch ("/e");

            foreach (var item in ApiDefinitions)
            {
                cmd.AppendFileNameIfNotNull(item);
            }

            if (CoreSources != null)
            {
                foreach (var item in CoreSources)
                {
                    cmd.AppendSwitchIfNotNull("/s:", item);
                }
            }

            if (Sources != null)
            {
                foreach (var item in Sources)
                {
                    cmd.AppendSwitchIfNotNull("/x:", item);
                }
            }

            if (AdditionalLibPaths != null)
            {
                foreach (var item in AdditionalLibPaths)
                {
                    cmd.AppendSwitchIfNotNull("/lib:", item);
                }
            }

            if (References != null)
            {
                foreach (var item in References)
                {
                    cmd.AppendSwitchIfNotNull("-r ", item);
                }
            }

            if (Resources != null)
            {
                foreach (var item in Resources)
                {
                    List <string> args = new List <string> ();
                    string        id;

                    args.Add(item.ToString());
                    id = item.GetMetadata("LogicalName");
                    if (!string.IsNullOrEmpty(id))
                    {
                        args.Add(id);
                    }

                    cmd.AppendSwitchIfNotNull("/res:", args.ToArray(), ",");
                }
            }

            if (NativeLibraries != null)
            {
                foreach (var item in NativeLibraries)
                {
                    List <string> args = new List <string> ();
                    string        id;

                    args.Add(item.ToString());
                    id = item.GetMetadata("LogicalName");
                    if (string.IsNullOrEmpty(id))
                    {
                        id = Path.GetFileName(args[0]);
                    }
                    args.Add(id);

                    cmd.AppendSwitchIfNotNull("/link-with:", args.ToArray(), ",");
                }
            }

            if (GeneratedSourcesDirectory != null)
            {
                cmd.AppendSwitchIfNotNull("/tmpdir:", GeneratedSourcesDirectory);
            }

            if (GeneratedSourcesFileList != null)
            {
                cmd.AppendSwitchIfNotNull("/sourceonly:", GeneratedSourcesFileList);
            }

            return(cmd.ToString());
        }
        public override bool Execute()
        {
            //Debugger.Launch();

            // Don't rebuild 20 times when updating/installing from NuGet or adding item template
            string stackTrace = Environment.StackTrace;

            if (stackTrace.Contains("at NuGet.PackageManagement.VisualStudio") ||
                stackTrace.Contains("at System.Windows.Controls.PopupControlService") ||
                stackTrace.Contains("at Microsoft.VisualStudio.Build.ComInteropWrapper.ProjectShim.BuildTargetsImpl") ||
                stackTrace.Contains("at Microsoft.VisualStudio.TemplateWizard.Wizard"))
            {
                GeneratedItems     = new string[0];
                GeneratedXamlItems = new string[0];

                HasErrors    = false;
                AmmyPlatform = "<notset>";

                return(true);
            }

            var allSources = Items.Split(';')
                             .Concat(SourceFiles.Split(';'))
                             .ToArray();

            var references = References.Split(';')
                             .ToList();

            var pages         = IncludedPages ?? "";
            var includedPages = pages.Split(';')
                                .ToList();

            //var currentAssemblyPath = Path.Combine(ProjectDir, OutputPath, AssemblyName + ".exe");

            //if (File.Exists(currentAssemblyPath))
            //    references.Add(currentAssemblyPath);

            if (Items.Length == 0)
            {
                return(true);
            }

            var constants  = DefineConstants?.Split(';');
            var needUpdate = true;

            if (constants != null)
            {
                var isDebug      = constants.Contains("DEBUG");
                var noAmmyUpdate = constants.Contains("NO_AMMY_UPDATE");
                needUpdate = isDebug && !noAmmyUpdate;
            }

            try {
                var compiler = new AmmyCompiler(isMsBuildCompilation: true);
                var result   = compiler.Compile(RootNamespace, allSources, references, ProjectDir, OutputPath, AssemblyName, TargetPath, null, true, true, needUpdate);

                Log.LogMessage("Ammy update enabled: " + needUpdate);

                foreach (var msg in result.CompilerMessages)
                {
                    if (msg.Type == CompilerMessageType.Error || msg.Type == CompilerMessageType.FatalError)
                    {
                        var loc   = msg.Location;
                        var start = loc.StartLineColumn;
                        var end   = loc.EndLineColumn;
                        Log.LogError("", "", "", msg.Location.Source.File.FullName, start.Line, start.Column, end.Line, end.Column, msg.Text);
                    }
                    else if (msg.Type == CompilerMessageType.Warning)
                    {
                        Log.LogWarning(msg.ToString());
                    }
                }

                GeneratedItems     = result.GeneratedFiles.ToArray();
                GeneratedXamlItems = result.GeneratedXamlFiles
                                     .SelectMany(filename => new[] { filename.ToRelativeFile(ProjectDir) })
                                     .Where(fname => !ListContainsFile(fname, includedPages))
                                     .ToArray();

                HasErrors    = !result.IsSuccess;
                AmmyPlatform = result.AmmyProject.PlatformName;

                return(true);
            }
            catch (Exception e) {
                Log.LogError(e.Message);

                HasErrors = true;

                return(false);
            }
        }
示例#4
0
        protected internal override void AddResponseFileCommands(CommandLineBuilderExtension commandLine)
        {
#if !NET_4_0
            //pre-MSBuild 2 targets don't support multi-targeting, so tell compiler to use 2.0 corlib
            commandLine.AppendSwitch("/sdk:2");
#endif
            base.AddResponseFileCommands(commandLine);

            if (AdditionalLibPaths != null && AdditionalLibPaths.Length > 0)
            {
                commandLine.AppendSwitchIfNotNull("/lib:", AdditionalLibPaths, ",");
            }

            if (Bag ["AllowUnsafeBlocks"] != null)
            {
                if (AllowUnsafeBlocks)
                {
                    commandLine.AppendSwitch("/unsafe+");
                }
                else
                {
                    commandLine.AppendSwitch("/unsafe-");
                }
            }

            //baseAddress

            if (Bag ["CheckForOverflowUnderflow"] != null)
            {
                if (CheckForOverflowUnderflow)
                {
                    commandLine.AppendSwitch("/checked+");
                }
                else
                {
                    commandLine.AppendSwitch("/checked-");
                }
            }

            if (!String.IsNullOrEmpty(DefineConstants))
            {
                string [] defines = DefineConstants.Split(new char [] { ';', ' ' },
                                                          StringSplitOptions.RemoveEmptyEntries);
                if (defines.Length > 0)
                {
                    commandLine.AppendSwitchIfNotNull("/define:",
                                                      String.Join(";", defines));
                }
            }

            if (!String.IsNullOrEmpty(DisabledWarnings))
            {
                string [] defines = DisabledWarnings.Split(new char [] { ';', ' ', ',' },
                                                           StringSplitOptions.RemoveEmptyEntries);
                if (defines.Length > 0)
                {
                    commandLine.AppendSwitchIfNotNull("/nowarn:", defines, ";");
                }
            }

            commandLine.AppendSwitchIfNotNull("/doc:", DocumentationFile);

            //errorReport

            if (GenerateFullPaths)
            {
                commandLine.AppendSwitch("/fullpaths");
            }

            commandLine.AppendSwitchIfNotNull("/langversion:", LangVersion);

            commandLine.AppendSwitchIfNotNull("/main:", MainEntryPoint);

            //moduleAssemblyName

            if (NoStandardLib)
            {
                commandLine.AppendSwitch("/nostdlib");
            }

            //platform
            commandLine.AppendSwitchIfNotNull("/platform:", Platform);
            //
            if (References != null)
            {
                foreach (ITaskItem item in References)
                {
                    string aliases = item.GetMetadata("Aliases");
                    if (!string.IsNullOrEmpty(aliases))
                    {
                        AddAliasesReference(commandLine, aliases, item.ItemSpec);
                    }
                    else
                    {
                        commandLine.AppendSwitchIfNotNull("/reference:", item.ItemSpec);
                    }
                }
            }

            if (ResponseFiles != null)
            {
                foreach (ITaskItem item in ResponseFiles)
                {
                    commandLine.AppendSwitchIfNotNull("@", item.ItemSpec);
                }
            }

            if (Bag ["WarningLevel"] != null)
            {
                commandLine.AppendSwitchIfNotNull("/warn:", WarningLevel.ToString());
            }

            commandLine.AppendSwitchIfNotNull("/warnaserror+:", WarningsAsErrors);

            commandLine.AppendSwitchIfNotNull("/warnaserror-:", WarningsNotAsErrors);

            if (Win32Resource != null)
            {
                commandLine.AppendSwitchIfNotNull("/win32res:", Win32Resource);
            }
        }
示例#5
0
        protected override string GenerateCommandLineCommands()
        {
            var cmd = new CommandLineArgumentBuilder();

                        #if DEBUG
            cmd.Add("/v");
                        #endif

            cmd.Add("/nostdlib");
            cmd.AddQuotedSwitchIfNotNull("/baselib:", BaseLibDll);
            cmd.AddQuotedSwitchIfNotNull("/out:", OutputAssembly);

            cmd.AddQuotedSwitchIfNotNull("/attributelib:", AttributeAssembly);

            string dir;
            if (!string.IsNullOrEmpty(BaseLibDll))
            {
                dir = Path.GetDirectoryName(BaseLibDll);
                cmd.AddQuotedSwitchIfNotNull("/lib:", dir);
            }

            if (ProcessEnums)
            {
                cmd.Add("/process-enums");
            }

            if (EmitDebugInformation)
            {
                cmd.Add("/debug");
            }

            if (AllowUnsafeBlocks)
            {
                cmd.Add("/unsafe");
            }

            if (!string.IsNullOrEmpty(DotNetCscCompiler))
            {
                var compileCommand = new string [] {
                    DotNetPath,
                    DotNetCscCompiler,
                };
                cmd.AddQuoted("/compile-command:" + string.Join(" ", StringUtils.QuoteForProcess(compileCommand)));
            }

            cmd.AddQuotedSwitchIfNotNull("/ns:", Namespace);

            if (NoNFloatUsing)
            {
                cmd.Add("/no-nfloat-using:true");
            }

            if (!string.IsNullOrEmpty(DefineConstants))
            {
                var strv = DefineConstants.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var str in strv)
                {
                    cmd.AddQuoted("/d:" + str);
                }
            }

            //cmd.AppendSwitch ("/e");

            foreach (var item in ApiDefinitions)
            {
                cmd.AddQuoted(Path.GetFullPath(item.ItemSpec));
            }

            if (CoreSources != null)
            {
                foreach (var item in CoreSources)
                {
                    cmd.AddQuoted("/s:" + Path.GetFullPath(item.ItemSpec));
                }
            }

            if (Sources != null)
            {
                foreach (var item in Sources)
                {
                    cmd.AddQuoted("/x:" + Path.GetFullPath(item.ItemSpec));
                }
            }

            if (AdditionalLibPaths != null)
            {
                foreach (var item in AdditionalLibPaths)
                {
                    cmd.AddQuoted("/lib:" + Path.GetFullPath(item.ItemSpec));
                }
            }

            HandleReferences(cmd);

            if (Resources != null)
            {
                foreach (var item in Resources)
                {
                    var argument = item.ToString();
                    var id       = item.GetMetadata("LogicalName");
                    if (!string.IsNullOrEmpty(id))
                    {
                        argument += "," + id;
                    }

                    cmd.AddQuoted("/res:" + argument);
                }
            }

            if (NativeLibraries != null)
            {
                foreach (var item in NativeLibraries)
                {
                    var argument = item.ToString();
                    var id       = item.GetMetadata("LogicalName");
                    if (string.IsNullOrEmpty(id))
                    {
                        id = Path.GetFileName(argument);
                    }

                    cmd.AddQuoted("/res:" + argument + "," + id);
                }
            }

            if (GeneratedSourcesDir != null)
            {
                cmd.AddQuoted("/tmpdir:" + Path.GetFullPath(GeneratedSourcesDir));
            }

            if (GeneratedSourcesFileList != null)
            {
                cmd.AddQuoted("/sourceonly:" + Path.GetFullPath(GeneratedSourcesFileList));
            }

            cmd.Add($"/target-framework={TargetFrameworkMoniker}");

            if (!string.IsNullOrEmpty(ExtraArgs))
            {
                var    extraArgs = CommandLineArgumentBuilder.Parse(ExtraArgs);
                var    target    = OutputAssembly;
                string projectDir;

                if (ProjectDir.StartsWith("~/", StringComparison.Ordinal))
                {
                    // Note: Since the Visual Studio plugin doesn't know the user's home directory on the Mac build host,
                    // it simply uses paths relative to "~/". Expand these paths to their full path equivalents.
                    var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

                    projectDir = Path.Combine(home, ProjectDir.Substring(2));
                }
                else
                {
                    projectDir = ProjectDir;
                }

                var customTags = new Dictionary <string, string> (StringComparer.OrdinalIgnoreCase)
                {
                    { "projectdir", projectDir },
                    // Apparently msbuild doesn't propagate the solution path, so we can't get it.
                    // { "solutiondir",  proj.ParentSolution != null ? proj.ParentSolution.BaseDirectory : proj.BaseDirectory },
                };
                // OutputAssembly is optional so it can be null
                if (target != null)
                {
                    var d = Path.GetDirectoryName(target);
                    var n = Path.GetFileName(target);
                    customTags.Add("targetpath", Path.Combine(d, n));
                    customTags.Add("targetdir", d);
                    customTags.Add("targetname", n);
                    customTags.Add("targetext", Path.GetExtension(target));
                }

                for (int i = 0; i < extraArgs.Length; i++)
                {
                    var argument = extraArgs[i];
                    cmd.Add(StringParserService.Parse(argument, customTags));
                }
            }

            cmd.Add(VerbosityUtils.Merge(ExtraArgs, (LoggerVerbosity)Verbosity));

            var commandLine = cmd.CreateResponseFile(this, ResponseFilePath, null);
            if (IsDotNet)
            {
                commandLine = StringUtils.Quote(Path.Combine(BTouchToolPath, BTouchToolExe)) + " " + commandLine;
            }

            return(commandLine.ToString());
        }