示例#1
0
    void ProcessAssembly(List <TypeDefinition> types)
    {
        var isDebug = IncludeDebugAssert && DefineConstants.Any(c => c == "DEBUG") && ReferenceFinder.DebugAssertMethod != null;

        var methodProcessor   = new MethodProcessor(ValidationFlags, isDebug);
        var propertyProcessor = new PropertyProcessor(ValidationFlags, isDebug);

        foreach (var type in types)
        {
            if (type.IsInterface || type.ContainsAllowNullAttribute() || type.IsGeneratedCode() || type.HasInterface("Windows.UI.Xaml.Markup.IXamlMetadataProvider"))
            {
                continue;
            }

            foreach (var method in type.MethodsWithBody())
            {
                methodProcessor.Process(method);
            }

            foreach (var property in type.ConcreteProperties())
            {
                propertyProcessor.Process(property);
            }
        }
    }
示例#2
0
    public override void Execute()
    {
        var assemblyReferences    = ModuleDefinition.AssemblyReferences;
        var assemblyNameReference = assemblyReferences.FirstOrDefault(x => x.Name == "Scalpel");

        assemblyReferences.Remove(assemblyNameReference);

        if (DefineConstants == null || DefineConstants.All(x => x != "Scalpel"))
        {
            var typeDefinitions = ModuleDefinition.GetTypes().ToList();
            foreach (var type in typeDefinitions)
            {
                var removeAttribute = type.CustomAttributes.FirstOrDefault(x => x.AttributeType.FullName == "Scalpel.RemoveAttribute");
                if (removeAttribute != null)
                {
                    type.CustomAttributes.Remove(removeAttribute);
                }
            }
            return;
        }
        ReadConfig();

        CleanRefsBasedOnRemovers();

        CleanRefsBasedOnConfiguration();

        CleanTypesBasedOnRemovers();
        CleanModuleAndAssemblyAttributes();
    }
示例#3
0
    void ProcessAssembly(List <TypeDefinition> types)
    {
        isDebug = IncludeDebugAssert &&
                  DefineConstants.Any(c => c == "DEBUG") &&
                  DebugAssertMethod != null;

        WriteInfo("Debug=" + isDebug);

        foreach (var type in types)
        {
            if (type.IsInterface ||
                type.ContainsAllowNullAttribute() ||
                type.IsGeneratedCode() ||
                type.HasInterface("Windows.UI.Xaml.Markup.IXamlMetadataProvider"))
            {
                continue;
            }

            foreach (var method in type.MethodsWithBody())
            {
                Process(method);
            }

            foreach (var property in type.ConcreteProperties())
            {
                Process(property);
            }
        }
    }
示例#4
0
        public override bool Execute()
        {
            var referenceCopyLocalPaths = ReferenceCopyLocalPaths.Select(x => x.ItemSpec).ToList();
            var defineConstants         = DefineConstants.GetConstants();

            processor = new Processor
            {
                Logger = new BuildLogger
                {
                    BuildEngine = BuildEngine,
                },
                AssemblyFilePath        = AssemblyPath,
                IntermediateDirectory   = IntermediateDir,
                KeyFilePath             = KeyFilePath,
                SignAssembly            = SignAssembly,
                ProjectDirectory        = ProjectDirectory,
                References              = References,
                SolutionDirectory       = SolutionDir,
                ReferenceCopyLocalPaths = referenceCopyLocalPaths,
                DefineConstants         = defineConstants,
                NuGetPackageRoot        = NuGetPackageRoot,
                PackageDefinitions      = PackageDefinitions?.ToList()
            };
            var success = processor.Execute();

            if (success)
            {
                var weavers = processor.Weavers.Select(x => x.AssemblyName);
                ExecutedWeavers = string.Join(";", weavers) + ";";
            }

            return(success);
        }
示例#5
0
        public void Execute()
        {
            IsDebugBuild = DefineConstants.Any(x => x.ToLower() == "debug");

            var references = new ReferenceContainer(ModuleDefinition, AssemblyResolver);

            WeaveMethods(references);
        }
        public override bool Execute()
        {
            using (var streamWriter = new StreamWriter(System.IO.File.Open(File, FileMode.Create)))
            {
                streamWriter.Write("/define:\"");
                streamWriter.Write(DefineConstants.Replace("\"", "\\\""));
                streamWriter.Write("\"");
            }

            return(true);
        }
示例#7
0
        private void FindReferences()
        {
            MethodReference ImportPropertyGetter(string typeName, string propertyName) =>
            ModuleDefinition.ImportReference(
                FindType(typeName).Properties.Single(definition => definition.Name == propertyName).GetMethod);

            _isApplicationPlayingGetterReference            = ImportPropertyGetter("UnityEngine.Application", "isPlaying");
            _isActiveAndEnabledGetterReference              = ImportPropertyGetter("UnityEngine.Behaviour", "isActiveAndEnabled");
            _compilerGeneratedAttributeConstructorReference = ModuleDefinition.ImportReference(
                FindType("System.Runtime.CompilerServices.CompilerGeneratedAttribute")
                .Methods.First(definition => definition.IsConstructor));
            _behaviourReference   = ModuleDefinition.ImportReference(FindType("UnityEngine.Behaviour"));
            _isCompilingForEditor = DefineConstants.Contains("UNITY_EDITOR");
        }
示例#8
0
        public void Execute()
        {
            LogDebugOutput = DefineConstants.Any(x => x.ToLower() == "debug");
            MethodCacheEnabledByDefault   = true;
            PropertyCacheEnabledByDefault = true;

            ReadConfiguration();

            MethodsForWeaving methodToWeave = SelectMethods();

            WeaveMethods(methodToWeave.Methods);
            WeaveProperties(methodToWeave.Properties);

            RemoveReference();
        }
示例#9
0
        public override bool Execute()
        {
            // System.Diagnostics.Debugger.Launch();

            var referenceCopyLocalPaths = ReferenceCopyLocalFiles.Select(x => x.ItemSpec).ToList();

            var defineConstants = DefineConstants.GetConstants();

            processor = new Processor
            {
                Logger = new BuildLogger
                {
                    BuildEngine = BuildEngine,
                },
                AssemblyFilePath        = AssemblyFile,
                IntermediateDirectory   = IntermediateDirectory,
                KeyFilePath             = KeyOriginatorFile ?? AssemblyOriginatorKeyFile,
                SignAssembly            = SignAssembly,
                ProjectDirectory        = ProjectDirectory,
                DocumentationFilePath   = DocumentationFile,
                References              = References,
                SolutionDirectory       = SolutionDirectoryFinder.Find(SolutionDirectory, NCrunchOriginalSolutionDirectory, ProjectDirectory),
                ReferenceCopyLocalPaths = referenceCopyLocalPaths,
                DefineConstants         = defineConstants,
                NuGetPackageRoot        = NuGetPackageRoot,
                MSBuildDirectory        = MSBuildThisFileDirectory,
                WeaverFilesFromProps    = GetWeaverFilesFromProps(),
                DebugSymbols            = GetDebugSymbolsType()
            };
            var success = processor.Execute();

            if (success)
            {
                var weavers = processor.Weavers.Select(x => x.AssemblyName);
                ExecutedWeavers = string.Join(";", weavers) + ";";

                File.WriteAllLines(IntermediateCopyLocalFilesCache, processor.ReferenceCopyLocalPaths);
            }
            else
            {
                if (File.Exists(IntermediateCopyLocalFilesCache))
                {
                    File.Delete(IntermediateCopyLocalFilesCache);
                }
            }

            return(success);
        }
示例#10
0
文件: VerifyTask.cs 项目: 0x53A/Fody
        public override bool Execute()
        {
            var defineConstants = DefineConstants.GetConstants();
            var verifier        = new Verifier
            {
                Logger = new BuildLogger
                {
                    BuildEngine = BuildEngine,
                },
                SolutionDirectory = SolutionDir,
                ProjectDirectory  = ProjectDirectory,
                DefineConstants   = defineConstants,
                TargetPath        = TargetPath,
            };

            return(verifier.Verify());
        }
示例#11
0
        public override bool Execute()
        {
            var defineConstants = DefineConstants.GetConstants();
            var verifier        = new Verifier
            {
                Logger = new BuildLogger
                {
                    BuildEngine = BuildEngine,
                },
                SolutionDirectory   = SolutionDirectoryFinder.Find(SolutionDirectory, NCrunchOriginalSolutionDirectory, ProjectDirectory),
                WeaverConfiguration = WeaverConfiguration,
                ProjectDirectory    = ProjectDirectory,
                DefineConstants     = defineConstants,
                TargetPath          = TargetPath,
            };

            return(verifier.Verify());
        }
示例#12
0
        public void Execute()
        {
            LogDebugOutput = DefineConstants.Any(x => x.ToLower() == "debug");

            References = new References()
            {
                AssemblyResolver = AssemblyResolver, ModuleDefinition = ModuleDefinition
            };
            References.LoadReferences();

            MethodCacheEnabledByDefault   = true;
            PropertyCacheEnabledByDefault = true;

            ReadConfiguration();

            MethodsForWeaving methodToWeave = SelectMethods();

            WeaveMethods(methodToWeave.Methods);
            WeaveProperties(methodToWeave.Properties);

            RemoveReference();
        }
        protected virtual void EnsureDefineConstants(Project project)
        {
            Logger.ZLogTrace("EnsureDefineConstants...");

            if (DefineConstants == null)
            {
                DefineConstants = new List <string>();
            }

            if (ProjectProperties.DefineConstants == null && _shouldReadProjectFile)
            {
                Logger.ZLogTrace("Reading define constants...");

                var constantList = project.AllEvaluatedProperties
                                   .Where(p => p.Name == ProjectPropertyNames.DEFINE_CONSTANTS_PROP)
                                   .Select(p => p.EvaluatedValue);

                if (constantList == null || constantList.Count() < 1)
                {
                    ProjectProperties.DefineConstants = "";
                }
                else
                {
                    ProjectProperties.DefineConstants = string.Join(";", constantList);
                }
            }

            if (!string.IsNullOrWhiteSpace(ProjectProperties.DefineConstants))
            {
                DefineConstants.AddRange(ProjectProperties.DefineConstants.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()));
            }

            DefineConstants = DefineConstants.Distinct().ToList();

            Logger.ZLogTrace("EnsureDefineConstants done");
        }
示例#14
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());
        }
示例#15
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());
        }
示例#16
0
 public override void RemoveDefineSymbol(string symbol)
 {
     DefineConstants = DefineConstants.Replace(symbol + ";", "");
 }
示例#17
0
 public override bool HasDefineSymbol(string symbol)
 {
     return(DefineConstants.Contains(symbol));
 }
示例#18
0
        public override bool Execute()
        {
            var referenceCopyLocalPaths = ReferenceCopyLocalFiles.Select(x => x.ItemSpec).ToList();

            var defineConstants = DefineConstants.GetConstants();
            var buildLogger     = new BuildLogger
            {
                BuildEngine = BuildEngine,
            };

            processor = new Processor
            {
                Logger                  = buildLogger,
                AssemblyFilePath        = AssemblyFile,
                IntermediateDirectory   = IntermediateDirectory,
                KeyFilePath             = KeyOriginatorFile ?? AssemblyOriginatorKeyFile,
                SignAssembly            = SignAssembly,
                ProjectDirectory        = ProjectDirectory,
                DocumentationFilePath   = DocumentationFile,
                References              = References,
                SolutionDirectory       = SolutionDirectoryFinder.Find(SolutionDirectory, NCrunchOriginalSolutionDirectory, ProjectDirectory),
                ReferenceCopyLocalPaths = referenceCopyLocalPaths,
                DefineConstants         = defineConstants,
                NuGetPackageRoot        = NuGetPackageRoot,
                MSBuildDirectory        = MSBuildThisFileDirectory,
                WeaverFilesFromProps    = GetWeaverFilesFromProps(),
                DebugSymbols            = GetDebugSymbolsType(),
                GenerateXsd             = GenerateXsd
            };
            var success = processor.Execute();

            if (success)
            {
                var weavers = processor.Weavers.Select(x => x.AssemblyName);
                ExecutedWeavers = string.Join(";", weavers) + ";";

                try
                {
                    File.WriteAllLines(IntermediateCopyLocalFilesCache, processor.ReferenceCopyLocalPaths);
                }
                catch (Exception ex)
                {
                    buildLogger.LogInfo("ProjectDirectory: " + ProjectDirectory);
                    buildLogger.LogInfo("IntermediateDirectory: " + IntermediateDirectory);
                    buildLogger.LogInfo("CurrentDirectory: " + Directory.GetCurrentDirectory());
                    buildLogger.LogInfo("AssemblyFile: " + AssemblyFile);
                    buildLogger.LogInfo("IntermediateCopyLocalFilesCache: " + IntermediateCopyLocalFilesCache);
                    buildLogger.LogError("Error writing IntermediateCopyLocalFilesCache: " + ex.Message);
                    return(false);
                }
            }
            else
            {
                if (File.Exists(IntermediateCopyLocalFilesCache))
                {
                    File.Delete(IntermediateCopyLocalFilesCache);
                }
            }

            return(success);
        }
        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);
            }
        }
示例#20
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);
            }
        }
示例#21
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());
        }