예제 #1
0
        public BuildScript Analyse(Autobuilder builder)
        {
            BuildScript GetCommand(string solution)
            {
                var standalone = builder.Actions.PathCombine(builder.SemmlePlatformTools, "csharp", "Semmle.Extraction.CSharp.Standalone");
                var cmd        = new CommandBuilder(builder.Actions);

                cmd.RunCommand(standalone);

                if (solution != null)
                {
                    cmd.QuoteArgument(solution);
                }

                cmd.Argument("--references:.");

                if (!builder.Options.NugetRestore)
                {
                    cmd.Argument("--skip-nuget");
                }

                return(cmd.Script);
            }

            if (!builder.Options.Buildless)
            {
                return(BuildScript.Failure);
            }

            var solutions = builder.Options.Solution.Length;

            if (solutions == 0)
            {
                return(GetCommand(null));
            }

            var script = BuildScript.Success;

            foreach (var solution in builder.Options.Solution)
            {
                script &= GetCommand(solution);
            }

            return(script);
        }
예제 #2
0
        public BuildScript Analyse(Autobuilder builder, bool auto)
        {
            if (!builder.ProjectsOrSolutionsToBuild.Any())
            {
                return(BuildScript.Failure);
            }

            if (auto)
            {
                builder.Log(Severity.Info, "Attempting to build using MSBuild");
            }

            var vsTools = GetVcVarsBatFile(builder);

            if (vsTools == null && builder.ProjectsOrSolutionsToBuild.Any())
            {
                var firstSolution = builder.ProjectsOrSolutionsToBuild.OfType <ISolution>().FirstOrDefault();
                vsTools = firstSolution != null
                                ? BuildTools.FindCompatibleVcVars(builder.Actions, firstSolution)
                                : BuildTools.VcVarsAllBatFiles(builder.Actions).OrderByDescending(b => b.ToolsVersion).FirstOrDefault();
            }

            if (vsTools == null && builder.Actions.IsWindows())
            {
                builder.Log(Severity.Warning, "Could not find a suitable version of vcvarsall.bat");
            }

            var nuget =
                builder.SemmlePlatformTools != null?
                builder.Actions.PathCombine(builder.SemmlePlatformTools, "csharp", "nuget", "nuget.exe") :
                    "nuget";

            var ret = BuildScript.Success;

            foreach (var projectOrSolution in builder.ProjectsOrSolutionsToBuild)
            {
                if (builder.Options.NugetRestore)
                {
                    var nugetCommand = new CommandBuilder(builder.Actions).
                                       RunCommand(nuget).
                                       Argument("restore").
                                       QuoteArgument(projectOrSolution.FullPath);
                    ret &= BuildScript.Try(nugetCommand.Script);
                }

                var command = new CommandBuilder(builder.Actions);

                if (vsTools != null)
                {
                    command.CallBatFile(vsTools.Path);
                    // `vcvarsall.bat` sets a default Platform environment variable,
                    // which may not be compatible with the supported platforms of the
                    // given project/solution. Unsetting it means that the default platform
                    // of the project/solution is used instead.
                    command.RunCommand("set Platform=&& type NUL", quoteExe: false);
                }

                builder.MaybeIndex(command, MsBuild);
                command.QuoteArgument(projectOrSolution.FullPath);

                command.Argument("/p:UseSharedCompilation=false");

                string target = builder.Options.MsBuildTarget != null
                                       ? builder.Options.MsBuildTarget
                                       : "rebuild";
                string?platform = builder.Options.MsBuildPlatform != null
                                         ? builder.Options.MsBuildPlatform
                                         : projectOrSolution is ISolution s1 ? s1.DefaultPlatformName : null;
                string?configuration = builder.Options.MsBuildConfiguration != null
                                              ? builder.Options.MsBuildConfiguration
                                              : projectOrSolution is ISolution s2 ? s2.DefaultConfigurationName : null;

                command.Argument("/t:" + target);
                if (platform != null)
                {
                    command.Argument(string.Format("/p:Platform=\"{0}\"", platform));
                }
                if (configuration != null)
                {
                    command.Argument(string.Format("/p:Configuration=\"{0}\"", configuration));
                }
                command.Argument("/p:MvcBuildViews=true");

                command.Argument(builder.Options.MsBuildArguments);

                ret &= command.Script;
            }

            return(ret);
        }
예제 #3
0
        public BuildScript Analyse(Autobuilder builder)
        {
            if (!builder.ProjectsOrSolutionsToBuild.Any())
            {
                return(BuildScript.Failure);
            }

            builder.Log(Severity.Info, "Attempting to build using MSBuild");

            var vsTools = GetVcVarsBatFile(builder);

            if (vsTools == null && builder.ProjectsOrSolutionsToBuild.Any())
            {
                var firstSolution = builder.ProjectsOrSolutionsToBuild.OfType <ISolution>().FirstOrDefault();
                vsTools = firstSolution != null
                                ? BuildTools.FindCompatibleVcVars(builder.Actions, firstSolution)
                                : BuildTools.VcVarsAllBatFiles(builder.Actions).OrderByDescending(b => b.ToolsVersion).FirstOrDefault();
            }

            if (vsTools == null && builder.Actions.IsWindows())
            {
                builder.Log(Severity.Warning, "Could not find a suitable version of vcvarsall.bat");
            }

            var nuget = builder.Actions.PathCombine(builder.SemmlePlatformTools, "csharp", "nuget", "nuget.exe");

            var ret = BuildScript.Success;

            foreach (var projectOrSolution in builder.ProjectsOrSolutionsToBuild)
            {
                if (builder.Options.NugetRestore)
                {
                    var nugetCommand = new CommandBuilder(builder.Actions).
                                       RunCommand(nuget).
                                       Argument("restore").
                                       QuoteArgument(projectOrSolution.FullPath);
                    ret &= BuildScript.Try(nugetCommand.Script);
                }

                var command = new CommandBuilder(builder.Actions);

                if (vsTools != null)
                {
                    command.CallBatFile(vsTools.Path);
                }

                command.IndexCommand(builder.Odasa, MsBuild);
                command.QuoteArgument(projectOrSolution.FullPath);

                command.Argument("/p:UseSharedCompilation=false");

                string target = builder.Options.MsBuildTarget != null
                                       ? builder.Options.MsBuildTarget
                                       : "rebuild";
                string platform = builder.Options.MsBuildPlatform != null
                                         ? builder.Options.MsBuildPlatform
                                         : projectOrSolution is ISolution s1 ? s1.DefaultPlatformName : null;
                string configuration = builder.Options.MsBuildConfiguration != null
                                              ? builder.Options.MsBuildConfiguration
                                              : projectOrSolution is ISolution s2 ? s2.DefaultConfigurationName : null;

                command.Argument("/t:" + target);
                if (platform != null)
                {
                    command.Argument(string.Format("/p:Platform=\"{0}\"", platform));
                }
                if (configuration != null)
                {
                    command.Argument(string.Format("/p:Configuration=\"{0}\"", configuration));
                }
                command.Argument("/p:MvcBuildViews=true");

                command.Argument(builder.Options.MsBuildArguments);

                ret &= command.Script;
            }

            return(ret);
        }