public static void Log(Verbosity verbosity, string value) { if ((int)verbosity >= (int)CurrentVerbosity) { Console.WriteLine("{0}: {1}", verbosity.ToString(), value); } }
public static void Log(Verbosity verbosity,string format, params object[] arg0) { if ((int)verbosity >= (int)CurrentVerbosity) { Console.WriteLine(String.Format("{0}: ", verbosity.ToString()) + format, arg0); } }
public static void Log(string message, Verbosity verbosity) { if (!_inUse) { var directory = AppDomain.CurrentDomain.BaseDirectory + @"\Logs"; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } else { var files = Directory.GetFileSystemEntries(directory).ToList(); if (files.Count != 0) { var obtainedfile = files.LastOrDefault( x => x.Contains("Log_" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_")); if (!(String.IsNullOrEmpty(obtainedfile) || String.IsNullOrWhiteSpace(obtainedfile))) { _logFileNumber = Convert.ToInt32(obtainedfile.Substring(obtainedfile.LastIndexOf("_", StringComparison.Ordinal) + 1, obtainedfile.IndexOf(".txt", StringComparison.Ordinal) - (obtainedfile.LastIndexOf("_", StringComparison.Ordinal) + 1))); _logFileNumber++; } } } _inUse = true; using (var file = new StreamWriter(@".\Logs\Log_" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + _logFileNumber + ".txt")) { Console.WriteLine(verbosity.ToString("G").ToUpperInvariant() + ": " + DateTime.Now + ": "+ message); file.WriteLine(verbosity.ToString("G").ToUpperInvariant() + ": " + DateTime.Now + ": " + message); } } else { using (var file = File.AppendText(@".\Logs\Log_" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + _logFileNumber + ".txt")) { Console.WriteLine(verbosity.ToString("G").ToUpperInvariant() + ": " + DateTime.Now + ": " + message); file.WriteLine(verbosity.ToString("G").ToUpperInvariant() + ": " + DateTime.Now + ": " + message); } } }
private IEnumerable <NuGet.Credentials.ICredentialProvider> GetCredentialProviders() { var extensionLocator = new ExtensionLocator(); var providers = new List <Credentials.ICredentialProvider>(); var pluginProviders = new PluginCredentialProviderBuilder(extensionLocator, Settings, Console) .BuildAll(Verbosity.ToString()) .ToList(); providers.Add(new CredentialProviderAdapter(new SettingsCredentialProvider(SourceProvider, Console))); if (pluginProviders.Any()) { providers.AddRange(pluginProviders); if (PreviewFeatureSettings.DefaultCredentialsAfterCredentialProviders) { providers.Add(new DefaultCredentialsCredentialProvider()); } } providers.Add(new ConsoleCredentialProvider(Console)); return(providers); }
/// <summary> /// Appends a message to the console and log file with a timestamp and verbosity level. Optionally prepends a /// module name before the message. /// </summary> /// <param name="verbosity">Verbosity level</param> /// <param name="message">Message</param> /// <param name="module">Module prefix</param> public void Log(Verbosity verbosity, string message, string module = null) { string formattedEntry = string.Format("[{0:u}][{1}]{2} {3}{4}", DateTime.UtcNow, verbosity.ToString(), module != null ? "[" + module + "]" : "", message, Environment.NewLine ); // Only write to the console if the verbosity meets the minimum if (verbosity >= DisplayVerbosity) { Console.Write(formattedEntry); } // Only write to disk if the verbosity meets the minimum if (verbosity >= LogVerbosity) { File.AppendAllText(logPath, formattedEntry); } }
TToponym GetWebServiceItem <ToponymWrapper, TToponym>(string restUrl, Verbosity style, IEnumerable <KeyValuePair <string, string> > parms) where ToponymWrapper : class, IToponymWrapper <TToponym>, new() where TToponym : class, new() { try { RestClient client = new RestClient("http://api.geonames.org"); RestRequest request = new RestRequest(restUrl, Method.GET); request.AddQueryParameter("style", style.ToString()) .AddQueryParameter("username", GeoNamesUserName); if (parms != null) { foreach (var parm in parms) { request.AddQueryParameter(parm.Key, parm.Value); } } var response = client.Execute <ToponymWrapper>(request); var responseUri = response.ResponseUri.AbsoluteUri; _logger.Info($"Invoked Url {responseUri}"); if (response.IsSuccessful) { return(response.Data.item); } _logger.Warn($"Url {responseUri} failed: {response.Content}"); return(null); } catch (Exception ex) { _logger.Error(ex); throw; } }
private void UpdateGlobalVerbosity() { verbosityToolStripSplitButton.Text = _globalVerbosity.ToString(); switch (_globalVerbosity) { case Verbosity.Critical: verbosityToolStripSplitButton.ForeColor = Color.DarkRed; break; case Verbosity.Normal: verbosityToolStripSplitButton.ForeColor = SystemColors.ControlText; break; case Verbosity.Verbose: verbosityToolStripSplitButton.ForeColor = Color.DarkGreen; break; case Verbosity.Everything: verbosityToolStripSplitButton.ForeColor = Color.Blue; break; } this.Refilter(); }
private async Task <IEnumerable <ICredentialProvider> > GetCredentialProvidersAsync() { var extensionLocator = new ExtensionLocator(); var providers = new List <ICredentialProvider>(); var pluginProviders = new PluginCredentialProviderBuilder(extensionLocator, Settings, Console) .BuildAll(Verbosity.ToString()) .ToList(); var securePluginProviders = await(new SecurePluginCredentialProviderBuilder(PluginManager.Instance, canShowDialog: true, logger: Console)).BuildAllAsync(); providers.Add(new CredentialProviderAdapter(new SettingsCredentialProvider(SourceProvider, Console))); providers.AddRange(securePluginProviders); providers.AddRange(pluginProviders); if (pluginProviders.Any() || securePluginProviders.Any()) { if (PreviewFeatureSettings.DefaultCredentialsAfterCredentialProviders) { providers.Add(new DefaultNetworkCredentialsCredentialProvider()); } } providers.Add(new ConsoleCredentialProvider(Console)); return(providers); }
protected bool BuildInternal(string projectOrSolution, string target, string [] parameters = null, Dictionary <string, string> environmentVariables = null) { string buildLogFullPath = (!string.IsNullOrEmpty(BuildLogFile)) ? Path.GetFullPath(Path.Combine(Root, Path.GetDirectoryName(projectOrSolution), BuildLogFile)) : null; var logger = buildLogFullPath == null ? string.Empty : string.Format("/noconsolelogger \"/flp1:LogFile={0};Encoding=UTF-8;Verbosity={1}\"", buildLogFullPath, Verbosity.ToString().ToLower()); var start = DateTime.UtcNow; var args = new StringBuilder(); var psi = new ProcessStartInfo(XABuildExe); args.AppendFormat("{0} /t:{1} {2}", QuoteFileName(Path.Combine(Root, projectOrSolution)), target, logger); if (RunningMSBuild) { args.Append(" /p:BuildingOutOfProcess=true"); } else { args.Append(" /p:UseHostCompilerIfAvailable=false /p:BuildingInsideVisualStudio=true"); } if (parameters != null) { foreach (var param in parameters) { args.AppendFormat(" /p:{0}", param); } } if (RunningMSBuild) { psi.EnvironmentVariables ["MSBUILD"] = "msbuild"; } if (environmentVariables != null) { foreach (var kvp in environmentVariables) { psi.EnvironmentVariables [kvp.Key] = kvp.Value; } } psi.Arguments = args.ToString(); psi.CreateNoWindow = true; psi.UseShellExecute = false; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; psi.StandardErrorEncoding = Encoding.UTF8; psi.StandardOutputEncoding = Encoding.UTF8; var p = Process.Start(psi); var ranToCompletion = p.WaitForExit((int)new TimeSpan(0, 10, 0).TotalMilliseconds); var result = ranToCompletion && p.ExitCode == 0; LastBuildTime = DateTime.UtcNow - start; LastBuildOutput = psi.FileName + " " + args.ToString() + Environment.NewLine; if (!ranToCompletion) { LastBuildOutput += "Build Timed Out!"; } if (buildLogFullPath != null && File.Exists(buildLogFullPath)) { LastBuildOutput += File.ReadAllText(buildLogFullPath); } LastBuildOutput += string.Format("\n#stdout begin\n{0}\n#stdout end\n", p.StandardOutput.ReadToEnd()); LastBuildOutput += string.Format("\n#stderr begin\n{0}\n#stderr end\n", p.StandardError.ReadToEnd()); if (buildLogFullPath != null) { Directory.CreateDirectory(Path.GetDirectoryName(buildLogFullPath)); File.WriteAllText(buildLogFullPath, LastBuildOutput); } if (!result && ThrowOnBuildFailure) { string message = "Build failure: " + Path.GetFileName(projectOrSolution) + (BuildLogFile != null && File.Exists(buildLogFullPath) ? "Build log recorded at " + buildLogFullPath : null); throw new FailedBuildException(message, null, LastBuildOutput); } return(result); }
protected bool BuildInternal(string projectOrSolution, string target, string [] parameters = null, Dictionary <string, string> environmentVariables = null, bool restore = true) { buildLogFullPath = (!string.IsNullOrEmpty(BuildLogFile)) ? Path.GetFullPath(Path.Combine(XABuildPaths.TestOutputDirectory, Path.GetDirectoryName(projectOrSolution), BuildLogFile)) : null; string processLog = !string.IsNullOrEmpty(BuildLogFile) ? Path.Combine(Path.GetDirectoryName(buildLogFullPath), "process.log") : null; var logger = buildLogFullPath == null ? string.Empty : string.Format("/noconsolelogger \"/flp1:LogFile={0};Encoding=UTF-8;Verbosity={1}\"", buildLogFullPath, Verbosity.ToString().ToLower()); var start = DateTime.UtcNow; var args = new StringBuilder(); var psi = new ProcessStartInfo(BuildTool); var responseFile = Path.Combine(XABuildPaths.TestOutputDirectory, Path.GetDirectoryName(projectOrSolution), "project.rsp"); if (UseDotNet) { args.Append("build "); } args.AppendFormat("{0} /t:{1} {2}", QuoteFileName(Path.Combine(XABuildPaths.TestOutputDirectory, projectOrSolution)), target, logger); if (AutomaticNuGetRestore && restore && !UseDotNet) { args.Append(" /restore"); } args.Append($" @\"{responseFile}\""); using (var sw = new StreamWriter(responseFile, append: false, encoding: Encoding.UTF8)) { sw.WriteLine($" /p:BuildingInsideVisualStudio={BuildingInsideVisualStudio}"); if (BuildingInsideVisualStudio) { sw.WriteLine(" /p:BuildingOutOfProcess=true"); } string sdkPath = AndroidSdkResolver.GetAndroidSdkPath(); if (Directory.Exists(sdkPath)) { sw.WriteLine(" /p:AndroidSdkDirectory=\"{0}\" ", sdkPath); } string ndkPath = AndroidSdkResolver.GetAndroidNdkPath(); if (Directory.Exists(ndkPath)) { sw.WriteLine(" /p:AndroidNdkDirectory=\"{0}\" ", ndkPath); } string jdkPath = AndroidSdkResolver.GetJavaSdkPath(); if (Directory.Exists(jdkPath)) { sw.WriteLine(" /p:JavaSdkDirectory=\"{0}\" ", jdkPath); } if (parameters != null) { foreach (var param in parameters) { sw.WriteLine(" /p:{0}", param); } } var msbuildArgs = Environment.GetEnvironmentVariable("NUNIT_MSBUILD_ARGS"); if (!string.IsNullOrEmpty(msbuildArgs)) { sw.WriteLine(msbuildArgs); } psi.EnvironmentVariables ["MSBUILD"] = "msbuild"; sw.WriteLine($" /bl:\"{Path.GetFullPath (Path.Combine (XABuildPaths.TestOutputDirectory, Path.GetDirectoryName (projectOrSolution), "msbuild.binlog"))}\""); if (environmentVariables != null) { foreach (var kvp in environmentVariables) { psi.EnvironmentVariables [kvp.Key] = kvp.Value; } } } //NOTE: commit messages can "accidentally" cause test failures // Consider if you added an error message in a commit message, then wrote a test asserting the error no longer occurs. // Both Jenkins and VSTS have an environment variable containing the full commit message, which will inexplicably cause your test to fail... // For a Jenkins case, see https://github.com/xamarin/xamarin-android/pull/1049#issuecomment-347625456 // For a VSTS case, see http://build.devdiv.io/1806783 psi.EnvironmentVariables ["ghprbPullLongDescription"] = psi.EnvironmentVariables ["BUILD_SOURCEVERSIONMESSAGE"] = ""; psi.Arguments = args.ToString(); psi.CreateNoWindow = true; psi.UseShellExecute = false; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; psi.StandardErrorEncoding = Encoding.UTF8; psi.StandardOutputEncoding = Encoding.UTF8; bool nativeCrashDetected = false; bool result = false; bool ranToCompletion = false; int attempts = 1; ManualResetEvent err = new ManualResetEvent(false); ManualResetEvent stdout = new ManualResetEvent(false); for (int attempt = 0; attempt < attempts; attempt++) { if (processLog != null) { File.AppendAllText(processLog, psi.FileName + " " + args.ToString() + Environment.NewLine); } using (var p = new Process()) { p.ErrorDataReceived += (sender, e) => { if (e.Data != null && !string.IsNullOrEmpty(processLog)) { File.AppendAllText(processLog, e.Data + Environment.NewLine); if (e.Data.StartsWith(SigSegvError, StringComparison.OrdinalIgnoreCase)) { nativeCrashDetected = true; } if (e.Data.StartsWith(ConsoleLoggerError, StringComparison.OrdinalIgnoreCase)) { nativeCrashDetected = true; } } if (e.Data == null) { err.Set(); } }; p.OutputDataReceived += (sender, e) => { if (e.Data != null && !string.IsNullOrEmpty(processLog)) { File.AppendAllText(processLog, e.Data + Environment.NewLine); if (e.Data.StartsWith(SigSegvError, StringComparison.OrdinalIgnoreCase)) { nativeCrashDetected = true; } if (e.Data.StartsWith(ConsoleLoggerError, StringComparison.OrdinalIgnoreCase)) { nativeCrashDetected = true; } } if (e.Data == null) { stdout.Set(); } }; p.StartInfo = psi; Console.WriteLine($"{psi.FileName} {psi.Arguments}"); p.Start(); p.BeginOutputReadLine(); p.BeginErrorReadLine(); ranToCompletion = p.WaitForExit((int)new TimeSpan(0, 15, 0).TotalMilliseconds); if (psi.RedirectStandardOutput) { stdout.WaitOne(); } if (psi.RedirectStandardError) { err.WaitOne(); } result = ranToCompletion && p.ExitCode == 0; } LastBuildTime = DateTime.UtcNow - start; if (processLog != null && !ranToCompletion) { File.AppendAllText(processLog, "Build Timed Out!"); } if (buildLogFullPath != null && File.Exists(buildLogFullPath)) { foreach (var line in LastBuildOutput) { if (line.StartsWith("Time Elapsed", StringComparison.OrdinalIgnoreCase)) { var match = timeElapsedRegEx.Match(line); if (match.Success) { LastBuildTime = TimeSpan.Parse(match.Groups ["TimeSpan"].Value); Console.WriteLine($"Found Time Elapsed {LastBuildTime}"); } } } } if (nativeCrashDetected) { Console.WriteLine($"Native crash detected! Running the build for {projectOrSolution} again."); if (attempt == 0) { File.Move(processLog, processLog + ".bak"); } nativeCrashDetected = false; continue; } else { break; } } if (buildLogFullPath != null && processLog != null) { Directory.CreateDirectory(Path.GetDirectoryName(buildLogFullPath)); if (File.Exists(processLog)) { File.AppendAllText(buildLogFullPath, File.ReadAllText(processLog)); } } if (!result && ThrowOnBuildFailure) { string message = "Build failure: " + Path.GetFileName(projectOrSolution) + (BuildLogFile != null && File.Exists(buildLogFullPath) ? "Build log recorded at " + buildLogFullPath : null); //NOTE: enormous logs will lock up IDE's UI. Build result files should be appended to the TestResult on failure. throw new FailedBuildException(message); } return(result); }
/// <summary> /// Starts the external process and captures its output. /// </summary> protected override void ExecuteTask() { // create temp response file to hold compiler options _responseFileName = Path.GetTempFileName(); try { using (StreamWriter writer = new StreamWriter(_responseFileName)) { writer.WriteLine("/nologo"); if (!Verbose) { if (Verbosity != VerbosityLevel.NotSet) { writer.WriteLine("/verbosity:" + Verbosity.ToString(). ToLower(CultureInfo.InvariantCulture)); } } else { writer.WriteLine("/verbosity:detailed"); } foreach (PropertyTask property in Properties) { string val; // expand properties in context of current project for non-dynamic properties if (!property.Dynamic) { val = Project.ExpandProperties(property.Value, Location); } else { val = property.Value; } writer.WriteLine("/property:\"{0}\"=\"{1}\"", property.PropertyName, val); } if (Target != null) { writer.WriteLine("/target:\"{0}\"", Target); } if (NoAutoResponse) { writer.WriteLine("/noautoresponse"); } if (ProjectFile != null) { writer.WriteLine("\"{0}\"", ProjectFile.FullName); } Log(Level.Verbose, "Starting MSBuild..."); } base.ExecuteTask(); } catch (Exception ex) { throw new BuildException("Failed to start MSBuild.", Location, ex); } finally { // make sure we delete response file even if an exception is thrown File.Delete(_responseFileName); _responseFileName = null; } }
protected bool BuildInternal(string projectOrSolution, string target, string [] parameters = null, Dictionary <string, string> environmentVariables = null) { buildLogFullPath = (!string.IsNullOrEmpty(BuildLogFile)) ? Path.GetFullPath(Path.Combine(Root, Path.GetDirectoryName(projectOrSolution), BuildLogFile)) : null; string processLog = !string.IsNullOrEmpty(BuildLogFile) ? Path.Combine(Path.GetDirectoryName(buildLogFullPath), "process.log") : null; var logger = buildLogFullPath == null ? string.Empty : string.Format("/noconsolelogger \"/flp1:LogFile={0};Encoding=UTF-8;Verbosity={1}\"", buildLogFullPath, Verbosity.ToString().ToLower()); var start = DateTime.UtcNow; var homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); var androidSdkToolPath = Path.Combine(homeDirectory, "android-toolchain"); var sdkPath = Environment.GetEnvironmentVariable("ANDROID_SDK_PATH"); if (String.IsNullOrEmpty(sdkPath)) { sdkPath = GetPathFromRegistry("AndroidSdkDirectory"); } if (String.IsNullOrEmpty(sdkPath)) { sdkPath = Path.GetFullPath(Path.Combine(androidSdkToolPath, "sdk")); } var ndkPath = Environment.GetEnvironmentVariable("ANDROID_NDK_PATH"); if (String.IsNullOrEmpty(ndkPath)) { ndkPath = GetPathFromRegistry("AndroidNdkDirectory"); } if (String.IsNullOrEmpty(ndkPath)) { ndkPath = Path.GetFullPath(Path.Combine(androidSdkToolPath, "ndk")); } var args = new StringBuilder(); var psi = new ProcessStartInfo(XABuildExe); args.AppendFormat("{0} /t:{1} {2}", QuoteFileName(Path.Combine(Root, projectOrSolution)), target, logger); if (RunningMSBuild) { args.Append(" /p:BuildingOutOfProcess=true"); } else { args.Append(" /p:UseHostCompilerIfAvailable=false /p:BuildingInsideVisualStudio=true"); } if (Directory.Exists(sdkPath)) { args.AppendFormat(" /p:AndroidSdkDirectory=\"{0}\" ", sdkPath); } if (Directory.Exists(ndkPath)) { args.AppendFormat(" /p:AndroidNdkDirectory=\"{0}\" ", ndkPath); } if (parameters != null) { foreach (var param in parameters) { args.AppendFormat(" /p:{0}", param); } } if (RunningMSBuild) { psi.EnvironmentVariables ["MSBUILD"] = "msbuild"; args.Append($" /bl:\"{Path.GetFullPath (Path.Combine (Root, Path.GetDirectoryName (projectOrSolution), "msbuild.binlog"))}\""); } if (environmentVariables != null) { foreach (var kvp in environmentVariables) { psi.EnvironmentVariables [kvp.Key] = kvp.Value; } } //NOTE: fix for Jenkins, see https://github.com/xamarin/xamarin-android/pull/1049#issuecomment-347625456 psi.EnvironmentVariables ["ghprbPullLongDescription"] = ""; psi.Arguments = args.ToString(); psi.CreateNoWindow = true; psi.UseShellExecute = false; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; psi.StandardErrorEncoding = Encoding.UTF8; psi.StandardOutputEncoding = Encoding.UTF8; bool nativeCrashDetected = false; bool result = false; bool ranToCompletion = false; int attempts = 1; ManualResetEvent err = new ManualResetEvent(false); ManualResetEvent stdout = new ManualResetEvent(false); for (int attempt = 0; attempt < attempts; attempt++) { if (processLog != null) { File.AppendAllText(processLog, psi.FileName + " " + args.ToString() + Environment.NewLine); } using (var p = new Process()) { p.ErrorDataReceived += (sender, e) => { if (e.Data != null && !string.IsNullOrEmpty(processLog)) { File.AppendAllText(processLog, e.Data + Environment.NewLine); if (e.Data.StartsWith(SigSegvError, StringComparison.OrdinalIgnoreCase)) { nativeCrashDetected = true; } if (e.Data.StartsWith(ConsoleLoggerError, StringComparison.OrdinalIgnoreCase)) { nativeCrashDetected = true; } } if (e.Data == null) { err.Set(); } }; p.OutputDataReceived += (sender, e) => { if (e.Data != null && !string.IsNullOrEmpty(processLog)) { File.AppendAllText(processLog, e.Data + Environment.NewLine); if (e.Data.StartsWith(SigSegvError, StringComparison.OrdinalIgnoreCase)) { nativeCrashDetected = true; } if (e.Data.StartsWith(ConsoleLoggerError, StringComparison.OrdinalIgnoreCase)) { nativeCrashDetected = true; } } if (e.Data == null) { stdout.Set(); } }; p.StartInfo = psi; p.Start(); p.BeginOutputReadLine(); p.BeginErrorReadLine(); ranToCompletion = p.WaitForExit((int)new TimeSpan(0, 10, 0).TotalMilliseconds); if (psi.RedirectStandardOutput) { stdout.WaitOne(); } if (psi.RedirectStandardError) { err.WaitOne(); } result = ranToCompletion && p.ExitCode == 0; } LastBuildTime = DateTime.UtcNow - start; if (processLog != null && !ranToCompletion) { File.AppendAllText(processLog, "Build Timed Out!"); } if (buildLogFullPath != null && File.Exists(buildLogFullPath)) { foreach (var line in LastBuildOutput) { if (line.StartsWith("Time Elapsed", StringComparison.OrdinalIgnoreCase)) { var match = timeElapsedRegEx.Match(line); if (match.Success) { LastBuildTime = TimeSpan.Parse(match.Groups ["TimeSpan"].Value); Console.WriteLine($"Found Time Elapsed {LastBuildTime}"); } } } } if (nativeCrashDetected) { Console.WriteLine($"Native crash detected! Running the build for {projectOrSolution} again."); if (attempt == 0) { File.Move(processLog, processLog + ".bak"); } nativeCrashDetected = false; continue; } else { break; } } if (buildLogFullPath != null && processLog != null) { Directory.CreateDirectory(Path.GetDirectoryName(buildLogFullPath)); if (File.Exists(processLog)) { File.AppendAllText(buildLogFullPath, File.ReadAllText(processLog)); } } if (!result && ThrowOnBuildFailure) { string message = "Build failure: " + Path.GetFileName(projectOrSolution) + (BuildLogFile != null && File.Exists(buildLogFullPath) ? "Build log recorded at " + buildLogFullPath : null); throw new FailedBuildException(message, null, File.ReadAllText(buildLogFullPath)); } return(result); }
protected bool BuildInternal(string projectOrSolution, string target, string [] parameters = null, Dictionary <string, string> environmentVariables = null) { string buildLogFullPath = (!string.IsNullOrEmpty(BuildLogFile)) ? Path.GetFullPath(Path.Combine(Root, Path.GetDirectoryName(projectOrSolution), BuildLogFile)) : null; var logger = buildLogFullPath == null ? string.Empty : string.Format("/noconsolelogger \"/flp1:LogFile={0};Encoding=UTF-8;Verbosity={1}\"", buildLogFullPath, Verbosity.ToString().ToLower()); var start = DateTime.UtcNow; var homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); var androidSdkToolPath = Path.Combine(homeDirectory, "android-toolchain"); var sdkPath = Environment.GetEnvironmentVariable("ANDROID_SDK_PATH"); if (String.IsNullOrEmpty(sdkPath)) { sdkPath = GetPathFromRegistry("AndroidSdkDirectory"); } if (String.IsNullOrEmpty(sdkPath)) { sdkPath = Path.GetFullPath(Path.Combine(androidSdkToolPath, "sdk")); } var ndkPath = Environment.GetEnvironmentVariable("ANDROID_NDK_PATH"); if (String.IsNullOrEmpty(ndkPath)) { ndkPath = GetPathFromRegistry("AndroidNdkDirectory"); } if (String.IsNullOrEmpty(ndkPath)) { ndkPath = Path.GetFullPath(Path.Combine(androidSdkToolPath, "ndk")); } var args = new StringBuilder(); var psi = new ProcessStartInfo(XABuildExe); args.AppendFormat("{0} /t:{1} {2}", QuoteFileName(Path.Combine(Root, projectOrSolution)), target, logger); if (RunningMSBuild) { args.Append(" /p:BuildingOutOfProcess=true"); } else { args.Append(" /p:UseHostCompilerIfAvailable=false /p:BuildingInsideVisualStudio=true"); } if (Directory.Exists(sdkPath)) { args.AppendFormat(" /p:AndroidSdkDirectory=\"{0}\" ", sdkPath); } if (Directory.Exists(ndkPath)) { args.AppendFormat(" /p:AndroidNdkDirectory=\"{0}\" ", ndkPath); } if (parameters != null) { foreach (var param in parameters) { args.AppendFormat(" /p:{0}", param); } } if (RunningMSBuild) { psi.EnvironmentVariables ["MSBUILD"] = "msbuild"; } if (environmentVariables != null) { foreach (var kvp in environmentVariables) { psi.EnvironmentVariables [kvp.Key] = kvp.Value; } } psi.Arguments = args.ToString(); psi.CreateNoWindow = true; psi.UseShellExecute = false; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; psi.StandardErrorEncoding = Encoding.UTF8; psi.StandardOutputEncoding = Encoding.UTF8; bool nativeCrashDetected = false; bool result = false; int attempts = 1; for (int attempt = 0; attempt < attempts; attempt++) { var p = Process.Start(psi); var ranToCompletion = p.WaitForExit((int)new TimeSpan(0, 10, 0).TotalMilliseconds); result = ranToCompletion && p.ExitCode == 0; LastBuildTime = DateTime.UtcNow - start; var sb = new StringBuilder(); sb.AppendLine(psi.FileName + " " + args.ToString() + Environment.NewLine); if (!ranToCompletion) { sb.AppendLine("Build Timed Out!"); } if (buildLogFullPath != null && File.Exists(buildLogFullPath)) { using (var fs = File.OpenRead(buildLogFullPath)) { using (var sr = new StreamReader(fs, Encoding.UTF8, true, 65536)) { string line; while ((line = sr.ReadLine()) != null) { sb.AppendLine(line); if (line.StartsWith("Time Elapsed", StringComparison.OrdinalIgnoreCase)) { var match = timeElapsedRegEx.Match(line); if (match.Success) { LastBuildTime = TimeSpan.Parse(match.Groups ["TimeSpan"].Value); Console.WriteLine($"Found Time Elapsed {LastBuildTime}"); } } if (line.StartsWith("Got a SIGSEGV while executing native code", StringComparison.OrdinalIgnoreCase)) { nativeCrashDetected = true; break; } } } } } sb.AppendFormat("\n#stdout begin\n{0}\n#stdout end\n", p.StandardOutput.ReadToEnd()); sb.AppendFormat("\n#stderr begin\n{0}\n#stderr end\n", p.StandardError.ReadToEnd()); LastBuildOutput = sb.ToString(); if (nativeCrashDetected) { Console.WriteLine($"Native crash detected! Running the build for {projectOrSolution} again."); continue; } } if (buildLogFullPath != null) { Directory.CreateDirectory(Path.GetDirectoryName(buildLogFullPath)); File.WriteAllText(buildLogFullPath, LastBuildOutput); } if (!result && ThrowOnBuildFailure) { string message = "Build failure: " + Path.GetFileName(projectOrSolution) + (BuildLogFile != null && File.Exists(buildLogFullPath) ? "Build log recorded at " + buildLogFullPath : null); throw new FailedBuildException(message, null, LastBuildOutput); } return(result); }
public override bool Execute() { PDictionary plist; PString value; Log.LogTaskName("MTouch"); Log.LogTaskProperty("AppBundleDir", AppBundleDir); Log.LogTaskProperty("AppExtensionReferences", AppExtensionReferences); Log.LogTaskProperty("AppManifest", AppManifest); Log.LogTaskProperty("Architectures", Architectures); Log.LogTaskProperty("ArchiveSymbols", ArchiveSymbols); Log.LogTaskProperty("BitcodeEnabled", EnableBitcode); Log.LogTaskProperty("CompiledEntitlements", CompiledEntitlements); Log.LogTaskProperty("Debug", Debug); Log.LogTaskProperty("EnableGenericValueTypeSharing", EnableGenericValueTypeSharing); Log.LogTaskProperty("Entitlements", Entitlements); Log.LogTaskProperty("ExecutableName", ExecutableName); Log.LogTaskProperty("ExtraArgs", ExtraArgs); Log.LogTaskProperty("FastDev", FastDev); Log.LogTaskProperty("HttpClientHandler", HttpClientHandler); Log.LogTaskProperty("I18n", I18n); Log.LogTaskProperty("IntermediateOutputPath", IntermediateOutputPath); Log.LogTaskProperty("IsAppExtension", IsAppExtension); Log.LogTaskProperty("LinkerDumpDependencies", LinkerDumpDependencies); Log.LogTaskProperty("LinkMode", LinkMode); Log.LogTaskProperty("MainAssembly", MainAssembly); Log.LogTaskProperty("NativeReferences", NativeReferences); Log.LogTaskProperty("OutputPath", OutputPath); Log.LogTaskProperty("Profiling", Profiling); Log.LogTaskProperty("ProjectDir", ProjectDir); Log.LogTaskProperty("References", References); Log.LogTaskProperty("SdkIsSimulator", SdkIsSimulator); Log.LogTaskProperty("SdkRoot", SdkRoot); Log.LogTaskProperty("SdkVersion", SdkVersion); Log.LogTaskProperty("SymbolsList", SymbolsList); Log.LogTaskProperty("TargetFrameworkIdentifier", TargetFrameworkIdentifier); Log.LogTaskProperty("TLSProvider", TLSProvider); Log.LogTaskProperty("UseFloat32", UseFloat32); Log.LogTaskProperty("UseLlvm", UseLlvm); Log.LogTaskProperty("UseThumb", UseThumb); Log.LogTaskProperty("Verbosity", Verbosity.ToString()); try { plist = PDictionary.FromFile(AppManifest.ItemSpec); } catch (Exception ex) { Log.LogError(null, null, null, AppManifest.ItemSpec, 0, 0, 0, 0, "Could not load Info.plist: {0}", ex.Message); return(false); } // deviceType = plist.GetUIDeviceFamily (); if (plist.TryGetValue(ManifestKeys.MinimumOSVersion, out value)) { if (!IPhoneSdkVersion.TryParse(value.Value, out minimumOSVersion)) { Log.LogError(null, null, null, AppManifest.ItemSpec, 0, 0, 0, 0, "Could not parse MinimumOSVersion '{0}'", value); return(false); } } else { switch (Framework) { case PlatformFramework.iOS: if (IsUnified) { IPhoneSdkVersion sdkVersion; if (!IPhoneSdkVersion.TryParse(SdkVersion, out sdkVersion)) { Log.LogError(null, null, null, AppManifest.ItemSpec, 0, 0, 0, 0, "Could not parse SdkVersion '{0}'", SdkVersion); return(false); } minimumOSVersion = sdkVersion; } else { minimumOSVersion = IPhoneSdkVersion.V5_1_1; } break; case PlatformFramework.WatchOS: case PlatformFramework.TVOS: minimumOSVersion = IPhoneSdkVersion.UseDefault; break; default: throw new InvalidOperationException(string.Format("Invalid framework: {0}", Framework)); } } Directory.CreateDirectory(AppBundleDir); var mtouchExecution = base.Execute(); try { var nativeLibrariesPath = Directory.EnumerateFiles(AppBundleDir, "*.dylib", SearchOption.AllDirectories); var nativeLibraryItems = new List <ITaskItem> (); foreach (var nativeLibrary in nativeLibrariesPath) { nativeLibraryItems.Add(new TaskItem(nativeLibrary)); } NativeLibraries = nativeLibraryItems.ToArray(); } catch (Exception ex) { Log.LogError(null, null, null, AppManifest.ItemSpec, 0, 0, 0, 0, "Could not get native libraries: {0}", ex.Message); return(false); } return(mtouchExecution); }
public void Write(LogScope scope, Verbosity verbosity, string source, string text) { DateTime dt = DateTime.Now; string span = ""; if(scope != null) span = (dt - scope.CreateDateTime).ToString(); TreeIter iter = AppendValues(FindParentIter(scope), dt, (int)verbosity, verbosity.ToString(), text, source, span); TreePath path = store.GetPath(iter); view.ExpandToPath(path); view.ScrollToCell(path, view.Columns[1], false, 0.0f, 0.0f); }
private static void Write(Verbosity level, string format, params object[] args) { if (level > Verbosity) return; string msg = string.Format("{0}, {1,-8}:", DateTime.Now.ToLongTimeString(), level.ToString()); if (args != null && args.Length > 0) msg += string.Format(format, args); else msg += format; foreach (ILogger i in subscribers) i.Write(msg); }
/** **************************************************************************************** * Writes a string representation of the \e Verbosity and priority into the given * AString. * * @param verbosity The enum value to retrieve a string representation for. * @param priority The priority of the \p verbosity setting. * @param target The target to write into. * @returns \p target to allow concatenated calls. ******************************************************************************************/ public static AString ToString( Verbosity verbosity, int priority, AString target ) { target.Field()._( verbosity.ToString() ).Field( 8, Alignment.Left) ._( '(' ); return ToStringPriority( priority, target ) .InsertAt( ")", target.LastIndexOfAny( CString.DefaultWhitespaces, Inclusion.Exclude ) + 1 ); }
static void Add(Verbosity verbosity) { map.Add(verbosity.ToString(), verbosity); map.Add(verbosity.ToString()[..1], verbosity);
protected bool BuildInternal(string projectOrSolution, string target, string [] parameters = null) { string buildLogFullPath = (!string.IsNullOrEmpty(BuildLogFile)) ? Path.GetFullPath(Path.Combine(Root, Path.GetDirectoryName(projectOrSolution), BuildLogFile)) : null; var logger = buildLogFullPath == null ? string.Empty : string.Format("/noconsolelogger \"/flp1:LogFile={0};Encoding=UTF-8;Verbosity={1}\"", buildLogFullPath, Verbosity.ToString().ToLower()); var start = DateTime.UtcNow; var homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); var androidSdkToolPath = Path.Combine(homeDirectory, "android-toolchain"); var sdkPath = Environment.GetEnvironmentVariable("ANDROID_SDK_PATH"); if (String.IsNullOrEmpty(sdkPath)) { sdkPath = GetPathFromRegistry("AndroidSdkDirectory"); } if (String.IsNullOrEmpty(sdkPath)) { sdkPath = Path.GetFullPath(Path.Combine(androidSdkToolPath, "sdk")); } var ndkPath = Environment.GetEnvironmentVariable("ANDROID_NDK_PATH"); if (String.IsNullOrEmpty(ndkPath)) { ndkPath = GetPathFromRegistry("AndroidNdkDirectory"); } if (String.IsNullOrEmpty(ndkPath)) { ndkPath = Path.GetFullPath(Path.Combine(androidSdkToolPath, "ndk")); } StringBuilder args = new StringBuilder(); var psi = new ProcessStartInfo(MSBuildExe); if (Directory.Exists(sdkPath)) { args.AppendFormat("/p:AndroidSdkDirectory=\"{0}\" ", sdkPath); } if (Directory.Exists(ndkPath)) { args.AppendFormat("/p:AndroidNdkDirectory=\"{0}\" ", ndkPath); } if (RunXBuild) { var outdir = Environment.GetEnvironmentVariable("XA_BUILD_OUTPUT_PATH"); if (String.IsNullOrEmpty(outdir)) { outdir = Path.GetFullPath("../../../../../../../out"); } if (!Directory.Exists(Path.Combine(outdir, "lib", "xbuild"))) { outdir = Path.GetFullPath(Path.Combine(Root, "..", "..", "bin", "Debug")); } if (!Directory.Exists(Path.Combine(outdir, "lib", "xbuild"))) { outdir = Path.GetFullPath(Path.Combine(Root, "..", "..", "bin", "Release")); } var targetsdir = Path.Combine(outdir, "lib", "xbuild"); args.AppendFormat(" {0} ", logger); if (Directory.Exists(targetsdir)) { psi.EnvironmentVariables ["TARGETS_DIR"] = targetsdir; psi.EnvironmentVariables ["MSBuildExtensionsPath"] = targetsdir; } if (Directory.Exists(outdir)) { psi.EnvironmentVariables ["MONO_ANDROID_PATH"] = outdir; psi.EnvironmentVariables ["XBUILD_FRAMEWORK_FOLDERS_PATH"] = Path.Combine(outdir, "lib", "xbuild-frameworks"); args.AppendFormat("/p:MonoDroidInstallDirectory=\"{0}\" ", outdir); } args.AppendFormat("/t:{0} {1} /p:UseHostCompilerIfAvailable=false /p:BuildingInsideVisualStudio=true", target, QuoteFileName(Path.Combine(Root, projectOrSolution))); } else { args.AppendFormat("{0} /t:{1} {2} /p:UseHostCompilerIfAvailable=false /p:BuildingInsideVisualStudio=true", QuoteFileName(Path.Combine(Root, projectOrSolution)), target, logger); } if (parameters != null) { foreach (var param in parameters) { args.AppendFormat(" /p:{0}", param); } } psi.Arguments = args.ToString(); psi.CreateNoWindow = true; psi.UseShellExecute = false; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; psi.StandardErrorEncoding = Encoding.UTF8; psi.StandardOutputEncoding = Encoding.UTF8; var p = Process.Start(psi); var ranToCompletion = p.WaitForExit((int)new TimeSpan(0, 10, 0).TotalMilliseconds); var result = ranToCompletion && p.ExitCode == 0; LastBuildTime = DateTime.UtcNow - start; LastBuildOutput = psi.FileName + " " + args.ToString() + Environment.NewLine; if (!ranToCompletion) { LastBuildOutput += "Build Timed Out!"; } if (buildLogFullPath != null && File.Exists(buildLogFullPath)) { LastBuildOutput += File.ReadAllText(buildLogFullPath); } LastBuildOutput += string.Format("\n#stdout begin\n{0}\n#stdout end\n", p.StandardOutput.ReadToEnd()); LastBuildOutput += string.Format("\n#stderr begin\n{0}\n#stderr end\n", p.StandardError.ReadToEnd()); if (buildLogFullPath != null) { File.WriteAllText(buildLogFullPath, LastBuildOutput); } if (!result && ThrowOnBuildFailure) { string message = "Build failure: " + Path.GetFileName(projectOrSolution) + (BuildLogFile != null && File.Exists(buildLogFullPath) ? "Build log recorded at " + buildLogFullPath : null); throw new FailedBuildException(message, null, LastBuildOutput); } return(result); }
static void Add(Verbosity verbosity, int shortLength) { map.Add(verbosity.ToString(), verbosity); map.Add(verbosity.ToString()[..shortLength], verbosity);