BuildScript AutobuildFailure() => BuildScript.Create(actions => { Log(Severity.Error, "Could not auto-detect a suitable build method"); return(1); });
BuildScript GetCSharpBuildScript() { /// <summary> /// A script that checks that the C# extractor has been executed. /// </summary> BuildScript CheckExtractorRun(bool warnOnFailure) => BuildScript.Create(actions => { if (actions.FileExists(Extractor.GetCSharpLogPath())) { return(0); } if (warnOnFailure) { Log(Severity.Error, "No C# code detected during build."); } return(1); }); var attempt = BuildScript.Failure; switch (GetCSharpBuildStrategy()) { case CSharpBuildStrategy.CustomBuildCommand: attempt = new BuildCommandRule().Analyse(this) & CheckExtractorRun(true); break; case CSharpBuildStrategy.Buildless: // No need to check that the extractor has been executed in buildless mode attempt = new StandaloneBuildRule().Analyse(this); break; case CSharpBuildStrategy.MSBuild: attempt = new MsBuildRule().Analyse(this) & CheckExtractorRun(true); break; case CSharpBuildStrategy.DotNet: attempt = new DotNetRule().Analyse(this) & CheckExtractorRun(true); break; case CSharpBuildStrategy.Auto: var cleanTrapFolder = BuildScript.DeleteDirectory(Actions.GetEnvironmentVariable("TRAP_FOLDER")); var cleanSourceArchive = BuildScript.DeleteDirectory(Actions.GetEnvironmentVariable("SOURCE_ARCHIVE")); var cleanExtractorLog = BuildScript.DeleteFile(Extractor.GetCSharpLogPath()); var attemptExtractorCleanup = BuildScript.Try(cleanTrapFolder) & BuildScript.Try(cleanSourceArchive) & BuildScript.Try(cleanExtractorLog); /// <summary> /// Execute script `s` and check that the C# extractor has been executed. /// If either fails, attempt to cleanup any artifacts produced by the extractor, /// and exit with code 1, in order to proceed to the next attempt. /// </summary> BuildScript IntermediateAttempt(BuildScript s) => (s & CheckExtractorRun(false)) | (attemptExtractorCleanup & BuildScript.Failure); attempt = // First try .NET Core IntermediateAttempt(new DotNetRule().Analyse(this)) | // Then MSBuild (() => IntermediateAttempt(new MsBuildRule().Analyse(this))) | // And finally look for a script that might be a build script (() => new BuildCommandAutoRule().Analyse(this) & CheckExtractorRun(true)) | // All attempts failed: print message AutobuildFailure(); break; } return (attempt & (() => new AspBuildRule().Analyse(this)) & (() => new XmlBuildRule().Analyse(this))); }