/// <summary> /// Gets the installation script snippet which contains snippets for all detected platforms. /// </summary> /// <param name="context">The <see cref="RepositoryContext"/>.</param> /// <param name="detectionResults">Already detected platforms results.</param> /// <returns>A snippet having logic to install all detected platforms.</returns> public string GetBashScriptSnippet( BuildScriptGeneratorContext context, IEnumerable <PlatformDetectorResult> detectionResults = null) { var scriptBuilder = new StringBuilder(); // Avoid detecting again if detection was already run. if (detectionResults == null) { detectionResults = _platformDetector.DetectPlatforms(context); } var snippets = GetInstallationScriptSnippets(detectionResults, context); foreach (var snippet in snippets) { scriptBuilder.AppendLine(snippet); scriptBuilder.AppendLine(); } return(scriptBuilder.ToString()); }
public void GenerateBashScript( BuildScriptGeneratorContext context, out string script, List <ICheckerMessage> checkerMessageSink = null) { script = null; IList <BuildScriptSnippet> buildScriptSnippets; var directoriesToExcludeFromCopyToIntermediateDir = new List <string>(); var directoriesToExcludeFromCopyToBuildOutputDir = new List <string>(); // Try detecting ALL platforms since in some scenarios this is required. // For example, in case of a multi-platform app like ASP.NET Core + NodeJs, we might need to dynamically // install both these platforms' sdks before actually using any of their commands. So even though a user // of Oryx might explicitly supply the platform of the app as .NET Core, we still need to make sure the // build environment is setup with detected platforms' sdks. var detectionResults = _platformDetector.DetectPlatforms(context); var installationScript = _environmentSetupScriptProvider.GetBashScriptSnippet( context, detectionResults); // Get list of detected platforms and versions to be set on benv var toolsToVersion = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); foreach (var detectionResult in detectionResults) { toolsToVersion[detectionResult.Platform] = detectionResult.PlatformVersion; } using (var timedEvent = _logger.LogTimedEvent("GetBuildSnippets")) { buildScriptSnippets = GetBuildSnippets( context, detectionResults, runDetection: false, directoriesToExcludeFromCopyToIntermediateDir, directoriesToExcludeFromCopyToBuildOutputDir); timedEvent.SetProperties(toolsToVersion); } if (_checkers != null && checkerMessageSink != null && _cliOptions.EnableCheckers) { try { _logger.LogDebug("Running checkers"); RunCheckers(context, toolsToVersion, checkerMessageSink); } catch (Exception exc) { _logger.LogError(exc, "Exception caught while running checkers"); } } else { _logger.LogInformation("Not running checkers - condition evaluates to " + "({checkersNotNull} && {sinkNotNull} && {enableCheckers})", _checkers != null, checkerMessageSink != null, _cliOptions.EnableCheckers); } if (buildScriptSnippets != null) { foreach (var snippet in buildScriptSnippets) { if (snippet.IsFullScript) { script = snippet.BashBuildScriptSnippet; return; } } } if (buildScriptSnippets.Any()) { // By default exclude these irrespective of platform directoriesToExcludeFromCopyToIntermediateDir.Add(".git"); directoriesToExcludeFromCopyToBuildOutputDir.Add(".git"); script = BuildScriptFromSnippets( context, installationScript, buildScriptSnippets, new ReadOnlyDictionary <string, string>(toolsToVersion), directoriesToExcludeFromCopyToIntermediateDir, directoriesToExcludeFromCopyToBuildOutputDir); } else { // TODO: Should an UnsupportedPlatformException be thrown here? // Seeing as the issue was that platforms were IDENTIFIED, but no build snippets were emitted from them throw new UnsupportedPlatformException(Labels.UnableToDetectPlatformMessage); } }