string GetJvmPath() { // NOTE: this doesn't need to use GetRegisteredTaskObjectAssemblyLocal() // because JavaSdkPath is the key and the value is a string. var key = new Tuple <string, string> (nameof(ResolveJdkJvmPath), JavaSdkPath); var cached = BuildEngine4.GetRegisteredTaskObject(key, RegisteredTaskObjectLifetime.AppDomain) as string; if (cached != null) { Log.LogDebugMessage($"Using cached value for {nameof (JdkJvmPath)}: {cached}"); return(cached); } var minVersion = Version.Parse(MinimumSupportedJavaVersion); var maxVersion = Version.Parse(LatestSupportedJavaVersion); JdkInfo info = MonoAndroidHelper.GetJdkInfo(this.CreateTaskLogger(), JavaSdkPath, minVersion, maxVersion); if (info == null) { return(null); } var path = info.JdkJvmPath; if (string.IsNullOrEmpty(path)) { return(null); } BuildEngine4.RegisterTaskObject(key, path, RegisteredTaskObjectLifetime.AppDomain, allowEarlyCollection: false); return(path); }
string GetJvmPath() { var key = new Tuple <string, string> (nameof(ResolveSdks), JavaSdkPath); var cached = BuildEngine4.GetRegisteredTaskObject(key, RegisteredTaskObjectLifetime.AppDomain) as string; if (cached != null) { Log.LogDebugMessage($"Using cached value for {nameof (JdkJvmPath)}: {cached}"); return(cached); } Xamarin.Android.Tools.JdkInfo info = null; try { info = new Xamarin.Android.Tools.JdkInfo(JavaSdkPath); } catch { info = Xamarin.Android.Tools.JdkInfo.GetKnownSystemJdkInfos(this.CreateTaskLogger()).FirstOrDefault(); } if (info == null) { return(null); } var path = info.JdkJvmPath; if (string.IsNullOrEmpty(path)) { return(null); } BuildEngine4.RegisterTaskObject(key, path, RegisteredTaskObjectLifetime.AppDomain, allowEarlyCollection: false); return(path); }
public override bool Execute() { if (LaunchProfiles == null || UserFile == null || FlagFile == null || ProjectDirectory == null) { Log.LogWarning("MonitorActiveDocument : One or more files missing"); return(true); } if (!Directory.Exists(LaunchProfiles)) { Log.LogWarning("LaunchProfiles not created yet"); return(true); } try { if (BuildEngine4.GetRegisteredTaskObject(nameof(ActiveDocumentMonitor), RegisteredTaskObjectLifetime.AppDomain) is not ActiveDocumentMonitor monitor) { if (WindowsInterop.GetServiceProvider() is IServiceProvider services) { BuildEngine4.RegisterTaskObject(nameof(ActiveDocumentMonitor), new ActiveDocumentMonitor(LaunchProfiles, UserFile, FlagFile, ProjectDirectory, services), RegisteredTaskObjectLifetime.AppDomain, false); } } else { // NOTE: this means we only support ONE project/launchProfiles per IDE. monitor.Refresh(LaunchProfiles, UserFile, FlagFile, ProjectDirectory); } }
public override bool Execute() { try { var path = Path.GetFullPath(LockFile); var key = new Tuple <string, string> (nameof(WriteLockFile), path); // Use the full path as part of the key // Check if already registered, for sanity var existing = BuildEngine4.GetRegisteredTaskObject(key, RegisteredTaskObjectLifetime.Build) as DeleteFileAfterBuild; if (existing == null) { if (File.Exists(path)) { Log.LogCodedWarning("XA5302", "Two processes may be building this project at once. Lock file exists at path: {0}", path); } else { Directory.CreateDirectory(Path.GetDirectoryName(path)); File.WriteAllText(path, ""); } BuildEngine4.RegisterTaskObject(key, new DeleteFileAfterBuild(path), RegisteredTaskObjectLifetime.Build, allowEarlyCollection: false); } else { Log.LogDebugMessage("Lock file was created earlier in the build."); } } catch (Exception ex) { Log.LogDebugMessage($"Exception in {nameof (WriteLockFile)}: {ex}"); } // We want to always continue return(true); }
public override bool Execute() { BuildEngine4.RegisterTaskObject( CacheKey, new RegisterObject(), RegisteredTaskObjectLifetime.Build, allowEarlyCollection: false); return(true); }
void WriteTypeMappings(List <TypeDefinition> types, TypeDefinitionCache cache) { var tmg = new TypeMapGenerator((string message) => Log.LogDebugMessage(message), SupportedAbis); if (!tmg.Generate(Debug, SkipJniAddNativeMethodRegistrationAttributeScan, types, cache, TypemapOutputDirectory, GenerateNativeAssembly, out ApplicationConfigTaskState appConfState)) { throw new XamarinAndroidException(4308, Properties.Resources.XA4308); } GeneratedBinaryTypeMaps = tmg.GeneratedBinaryTypeMaps.ToArray(); BuildEngine4.RegisterTaskObject(ApplicationConfigTaskState.RegisterTaskObjectKey, appConfState, RegisteredTaskObjectLifetime.Build, allowEarlyCollection: false); }
public override bool Execute() { if (string.IsNullOrEmpty(LaunchProfiles) || string.IsNullOrEmpty(UserFile)) { Debug.Fail("Should have gotten something to monitor"); return(true); } try { if (BuildEngine4.GetRegisteredTaskObject(nameof(ActiveDocumentMonitor), RegisteredTaskObjectLifetime.AppDomain) is not ActiveDocumentMonitor monitor) { var maxAttempts = 5; for (var i = 1; i <= maxAttempts; i++) { if (WindowsInterop.GetServiceProvider() is IServiceProvider services) { BuildEngine4.RegisterTaskObject(nameof(ActiveDocumentMonitor), new ActiveDocumentMonitor(LaunchProfiles !, UserFile !, StartupFiles.Select(x => x.ItemSpec).ToArray(), services), RegisteredTaskObjectLifetime.AppDomain, false); return(true); } else { try { BuildEngine4.Yield(); } catch (Exception e) { Debug.WriteLine(e); } // Increase the wait time to allow more time between retries Thread.Sleep(200 * i); } } Debug.Fail("Failed to get IServiceProvider to monitor for active document."); } else { // NOTE: this means we only support ONE project/launchProfiles per IDE. monitor.Refresh(LaunchProfiles !, UserFile !, StartupFiles.Select(x => x.ItemSpec).ToArray()); } }
public override bool Execute() { var key = s_cacheKeyPrefix + Text; var errorReportedSentinel = BuildEngine4.GetRegisteredTaskObject(key, RegisteredTaskObjectLifetime.Build); if (errorReportedSentinel != null) { Log.LogMessage(MessageImportance.Low, Text); return(false); } BuildEngine4.RegisterTaskObject(key, new object(), RegisteredTaskObjectLifetime.Build, allowEarlyCollection: true); Log.LogError(Text); return(false); }
bool GetAapt2Version() { var sb = new StringBuilder(); var aapt2Tool = Path.Combine(Aapt2ToolPath, Aapt2); // Try to use a cached value for Aapt2Version // NOTE: this doesn't need to use GetRegisteredTaskObjectAssemblyLocal() // because the path to aapt2 is in the key and the value is a string. var key = ($"{nameof (ResolveAndroidTooling)}.{nameof (Aapt2Version)}", aapt2Tool); var cached = BuildEngine4.GetRegisteredTaskObject(key, RegisteredTaskObjectLifetime.AppDomain) as string; if (!string.IsNullOrEmpty(cached)) { Log.LogDebugMessage($"Using cached value for {nameof (Aapt2Version)}: {cached}"); Aapt2Version = cached; return(true); } try { MonoAndroidHelper.RunProcess(aapt2Tool, "version", (s, e) => { if (!string.IsNullOrEmpty(e.Data)) { sb.AppendLine(e.Data); } }, (s, e) => { if (!string.IsNullOrEmpty(e.Data)) { sb.AppendLine(e.Data); } } ); } catch (Exception ex) { Log.LogWarningFromException(ex); return(false); } var versionInfo = sb.ToString(); var versionNumberMatch = Aapt2VersionRegex.Match(versionInfo); Log.LogDebugMessage($"`{aapt2Tool} version` returned: ```{versionInfo}```"); if (versionNumberMatch.Success && Version.TryParse(versionNumberMatch.Groups ["version"]?.Value.Replace(":", "."), out Version versionNumber)) { Aapt2Version = versionNumber.ToString(); BuildEngine4.RegisterTaskObject(key, Aapt2Version, RegisteredTaskObjectLifetime.AppDomain, allowEarlyCollection: false); return(true); } return(false); }
protected override void ExecuteCore() { const string previewMessageKey = "Microsoft.NET.Build.Tasks.DisplayPreviewMessageKey"; object messageDisplayed = BuildEngine4.GetRegisteredTaskObject(previewMessageKey, RegisteredTaskObjectLifetime.Build); if (messageDisplayed == null) { Log.LogMessage(MessageImportance.High, Strings.UsingPreviewSdkWarning); BuildEngine4.RegisterTaskObject( previewMessageKey, new object(), RegisteredTaskObjectLifetime.Build, true); } }
protected override void ExecuteCore() { StronglyTypedInputs inputs = GetInputs(); string cacheKey = inputs.CacheKey(); ResolvedAssetsCacheEntry results; if (s_allowCacheLookup && BuildEngine4?.GetRegisteredTaskObject( cacheKey, RegisteredTaskObjectLifetime.AppDomain /* really "until process exit" */) is ResolvedAssetsCacheEntry cacheEntry) { // NOTE: It's conceivably possible that the user modified the targeting // packs between builds. Since that is extremely rare and the standard // user scenario reads the targeting pack contents over and over without // modification, we're electing not to check for file modification and // returning any cached results that we have. results = cacheEntry; } else { results = Resolve(inputs, BuildEngine4); if (s_allowCacheLookup) { BuildEngine4?.RegisterTaskObject(cacheKey, results, RegisteredTaskObjectLifetime.AppDomain, allowEarlyCollection: true); } } foreach (var error in results.Errors) { Log.LogError(error); } ReferencesToAdd = results.ReferencesToAdd; AnalyzersToAdd = results.AnalyzersToAdd; PlatformManifests = results.PlatformManifests; PackageConflictOverrides = results.PackageConflictOverrides; PackageConflictPreferredPackages = results.PackageConflictPreferredPackages; UsedRuntimeFrameworks = results.UsedRuntimeFrameworks; }
protected Version GetVersionFromTool(string javaExe, Regex versionRegex) { // NOTE: this doesn't need to use GetRegisteredTaskObjectAssemblyLocal() // because the path to java/javac is the key and the value is a System.Version. var javaTool = Path.Combine(JavaSdkPath, "bin", javaExe); var key = new Tuple <string, string> (nameof(ValidateJavaVersion), javaTool); var cached = BuildEngine4.GetRegisteredTaskObject(key, RegisteredTaskObjectLifetime.AppDomain) as Version; if (cached != null) { Log.LogDebugMessage($"Using cached value for `{javaTool} -version`: {cached}"); JdkVersion = cached.ToString(); return(cached); } var sb = new StringBuilder(); MonoAndroidHelper.RunProcess(javaTool, "-version", (s, e) => { if (!string.IsNullOrEmpty(e.Data)) { sb.AppendLine(e.Data); } }, (s, e) => { if (!string.IsNullOrEmpty(e.Data)) { sb.AppendLine(e.Data); } }); var versionInfo = sb.ToString(); var versionNumberMatch = versionRegex.Match(versionInfo); Version versionNumber; if (versionNumberMatch.Success && Version.TryParse(versionNumberMatch.Groups ["version"]?.Value, out versionNumber)) { BuildEngine4.RegisterTaskObject(key, versionNumber, RegisteredTaskObjectLifetime.AppDomain, allowEarlyCollection: false); JdkVersion = versionNumberMatch.Groups ["version"].Value; return(versionNumber); } else { Log.LogCodedWarning("XA0033", Properties.Resources.XA0033, javaExe, versionInfo); return(null); } }
public override bool Execute() { if (FlagFile == null || StartupFile == null) { return(true); } if (!File.Exists(FlagFile) || File.ReadAllText(FlagFile) != StartupFile) { // This defers the opening until the build completes. BuildEngine4.RegisterTaskObject( StartupFile, new DisposableAction(() => WindowsInterop.EnsureOpened(StartupFile)), RegisteredTaskObjectLifetime.Build, false); File.WriteAllText(FlagFile, StartupFile); } return(true); }
Version GetVersionFromTool(string javaExe, Regex versionRegex) { var javaTool = Path.Combine(JavaSdkPath, "bin", javaExe); var key = new Tuple <string, string> (nameof(ValidateJavaVersion), javaTool); var cached = BuildEngine4.GetRegisteredTaskObject(key, RegisteredTaskObjectLifetime.AppDomain) as Version; if (cached != null) { Log.LogDebugMessage($"Using cached value for `{javaTool} -version`: {cached}"); JdkVersion = cached.ToString(); return(cached); } var sb = new StringBuilder(); MonoAndroidHelper.RunProcess(javaTool, "-version", (s, e) => { if (!string.IsNullOrEmpty(e.Data)) { sb.AppendLine(e.Data); } }, (s, e) => { if (!string.IsNullOrEmpty(e.Data)) { sb.AppendLine(e.Data); } }); var versionInfo = sb.ToString(); var versionNumberMatch = versionRegex.Match(versionInfo); Version versionNumber; if (versionNumberMatch.Success && Version.TryParse(versionNumberMatch.Groups ["version"]?.Value, out versionNumber)) { BuildEngine4.RegisterTaskObject(key, versionNumber, RegisteredTaskObjectLifetime.AppDomain, allowEarlyCollection: false); JdkVersion = versionNumberMatch.Groups ["version"].Value; return(versionNumber); } else { Log.LogCodedWarning("XA0033", $"Failed to get the Java SDK version as it does not appear to contain a valid version number. `{javaExe} -version` returned: ```{versionInfo}```"); return(null); } }
private void ExecuteImpl() { var globalJsonPath = Path.Combine(RepositoryRoot, "global.json"); var lastWrite = File.GetLastWriteTimeUtc(globalJsonPath); var paths = Environment.GetEnvironmentVariable("PATH"); var cachedResult = (CacheEntry)BuildEngine4.GetRegisteredTaskObject(s_cacheKey, RegisteredTaskObjectLifetime.Build); if (cachedResult != null && lastWrite == cachedResult.LastWrite && paths == cachedResult.Paths) { Log.LogMessage(MessageImportance.Low, $"Reused cached value."); DotNetPath = cachedResult.Value; return; } var globalJson = File.ReadAllText(globalJsonPath); // avoid Newtonsoft.Json dependency var match = Regex.Match(globalJson, @"""dotnet""\s*:\s*""([^""]+)"""); if (!match.Success) { Log.LogError($"Unable to determine dotnet version from file '{globalJsonPath}'."); return; } var sdkVersion = match.Groups[1].Value; var fileName = (Path.DirectorySeparatorChar == '\\') ? "dotnet.exe" : "dotnet"; var dotNetDir = paths.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(p => File.Exists(Path.Combine(p, fileName))); if (dotNetDir == null || !Directory.Exists(Path.Combine(dotNetDir, "sdk", sdkVersion))) { Log.LogError($"Unable to find dotnet with SDK version '{sdkVersion}'"); return; } DotNetPath = Path.GetFullPath(Path.Combine(dotNetDir, fileName)); BuildEngine4.RegisterTaskObject(s_cacheKey, new CacheEntry(lastWrite, paths, DotNetPath), RegisteredTaskObjectLifetime.Build, allowEarlyCollection: true); }
string GetJvmPath() { // NOTE: this doesn't need to use GetRegisteredTaskObjectAssemblyLocal() // because JavaSdkPath is the key and the value is a string. var key = new Tuple <string, string> (nameof(ResolveJdkJvmPath), JavaSdkPath); var cached = BuildEngine4.GetRegisteredTaskObject(key, RegisteredTaskObjectLifetime.AppDomain) as string; if (cached != null) { Log.LogDebugMessage($"Using cached value for {nameof (JdkJvmPath)}: {cached}"); return(cached); } JdkInfo info = null; try { info = new JdkInfo(JavaSdkPath); } catch { info = JdkInfo.GetKnownSystemJdkInfos(this.CreateTaskLogger()).FirstOrDefault(); } if (info == null) { return(null); } var path = info.JdkJvmPath; if (string.IsNullOrEmpty(path)) { return(null); } BuildEngine4.RegisterTaskObject(key, path, RegisteredTaskObjectLifetime.AppDomain, allowEarlyCollection: false); return(path); }
public override bool Execute() { if (LaunchProfiles == null || UserFile == null || FlagFile == null) { return(true); } try { if (BuildEngine4.GetRegisteredTaskObject(nameof(ActiveDocumentMonitor), RegisteredTaskObjectLifetime.AppDomain) is not ActiveDocumentMonitor monitor) { if (WindowsInterop.GetServiceProvider() is IServiceProvider services) { BuildEngine4.RegisterTaskObject(nameof(ActiveDocumentMonitor), new ActiveDocumentMonitor(LaunchProfiles, UserFile, FlagFile, services), RegisteredTaskObjectLifetime.AppDomain, false); } } else { // NOTE: this means we only support ONE project/launchProfiles per IDE. monitor.Refresh(LaunchProfiles, UserFile, FlagFile); } }
public override bool Execute() { var key = (WorkingDirectory, XASourceDirectory, SubmoduleName, GitRemoteName); var cached = BuildEngine4.GetRegisteredTaskObject(key, RegisteredTaskObjectLifetime.Build) as string; if (!string.IsNullOrEmpty(cached)) { Log.LogMessage(MessageImportance.Normal, "Using cached information from earlier in the build"); CommitInfo = cached; goto outOfHere; } if (String.IsNullOrEmpty(GitPath?.Trim())) { GitPath = "git"; } bool isSubmodule = !String.IsNullOrEmpty(SubmoduleName); string submoduleInfo = isSubmodule ? $" submodule {SubmoduleName}" : String.Empty; Log.LogMessage(MessageImportance.Normal, $"Gathering GIT commit info{submoduleInfo} in directory '{WorkingDirectory}'"); var stdoutLines = new List <string> (); var stderrLines = new List <string> (); if (!RunGit("log -n 1 --pretty=%D HEAD", stdoutLines, stderrLines)) { goto outOfHere; } string gitModules = Path.Combine(XASourceDirectory, ".gitmodules"); string branchFull = stdoutLines [0].Trim(); string branch; if (branchFull.StartsWith("HEAD, ", StringComparison.Ordinal)) { Log.LogMessage(MessageImportance.Low, " Detached HEAD, branch information available"); // Detached HEAD with branch information // Sample format: // // HEAD, origin/master, origin/d16-0-p1, origin/HEAD, master // branch = branchFull.Substring(6); } else if (branchFull.StartsWith("HEAD -> ", StringComparison.Ordinal)) { Log.LogMessage(MessageImportance.Low, " Normal branch"); // Normal branch // Sample format: // // HEAD -> bundle-ndk16-fix, origin/pr/1105 // branch = branchFull.Substring(8); } else if (String.Compare("HEAD", branchFull, StringComparison.Ordinal) == 0) { Log.LogMessage(MessageImportance.Low, " Detached HEAD, no branch information"); // Detached HEAD without branch information if (isSubmodule) { if (!RunGit($"config -f {gitModules} --get \"submodule.{SubmoduleName}.branch\"", stdoutLines, stderrLines)) { goto outOfHere; } branch = stdoutLines [0]; } else { Log.LogWarning($"Unable to determine branch name from detached head state in directory {WorkingDirectory}"); branch = "unknown"; } } else { Log.LogError($"Unable to parse branch name from: {branchFull}"); branch = null; goto outOfHere; } int separator = branch.IndexOf(','); if (separator >= 0) { // We choose the first branch from the list branch = branch.Substring(0, separator).Trim(); } separator = branch.IndexOf('/'); if (separator >= 0) { branch = branch.Substring(separator + 1).Trim(); } if (branch.StartsWith("tag: ", StringComparison.Ordinal)) { branch = branch.Substring(5).Trim(); } if (String.IsNullOrEmpty(branch)) { Log.LogError($"Unsupported branch information format: '{branchFull}'"); goto outOfHere; } Log.LogMessage(MessageImportance.Low, $" Branch: {branch}"); if (!RunGit("log -n 1 --pretty=%h HEAD", stdoutLines, stderrLines)) { goto outOfHere; } string commit = stdoutLines [0].Trim(); Log.LogMessage(MessageImportance.Low, $" Commit hash: {commit}"); string url; if (isSubmodule) { if (!RunGit($"config -f {gitModules} --get \"submodule.{SubmoduleName}.url\"", stdoutLines, stderrLines)) { goto outOfHere; } url = stdoutLines [0].Trim(); } else { string remoteName = String.IsNullOrEmpty(GitRemoteName) ? "origin" : GitRemoteName; if (!RunGit($"config --local --get \"remote.{remoteName}.url\"", stdoutLines, stderrLines)) { goto outOfHere; } url = stdoutLines [0].Trim(); } Log.LogMessage(MessageImportance.Low, $" Repository URL: {url}"); string organization; string repo; bool urlParsed; if (url.StartsWith("git@", StringComparison.Ordinal)) { urlParsed = ParseGitURL(url, out organization, out repo); } else if (url.StartsWith("https://", StringComparison.Ordinal)) { urlParsed = ParseHttpsURL(url, out organization, out repo); } else if (url.StartsWith("../../", StringComparison.Ordinal)) { // Special case for monodroid (although it will most likely return the git@ URL anyway) urlParsed = ParseRelativePathURL(url, out organization, out repo); } else { Log.LogError($"Unknown URL schema in '{url}' for directory '{WorkingDirectory}'"); goto outOfHere; } Log.LogMessage(MessageImportance.Low, $" Organization: {organization}"); Log.LogMessage(MessageImportance.Low, $" Repository: {repo}"); CommitInfo = $"{organization}/{repo}/{branch}@{commit}"; BuildEngine4.RegisterTaskObject(key, CommitInfo, RegisteredTaskObjectLifetime.Build, allowEarlyCollection: false); outOfHere: return(!Log.HasLoggedErrors); }
public override bool Execute() { if (!SemanticVersion.TryParse(SdkVersion, out var currentSdkVersion)) { Log.LogError($"Invalid version: {SdkVersion}"); return(false); } var globalJsonPath = Path.Combine(RepositoryRoot, "global.json"); DateTime lastWrite; try { lastWrite = File.GetLastWriteTimeUtc(globalJsonPath); } catch (Exception e) { Log.LogError($"Error accessing file '{globalJsonPath}': {e.Message}"); return(false); } var cachedResult = (CacheEntry)BuildEngine4.GetRegisteredTaskObject(s_cacheKey, RegisteredTaskObjectLifetime.Build); if (cachedResult != null && lastWrite == cachedResult.LastWrite) { // Error has already been reported if the current SDK version is not sufficient. if (!cachedResult.Success) { Log.LogMessage(MessageImportance.Low, $"Previous .NET Core SDK version check failed."); } return(cachedResult.Success); } bool execute() { string globalJson; try { globalJson = File.ReadAllText(globalJsonPath); } catch (Exception e) { Log.LogError($"Error reading file '{globalJsonPath}': {e.Message}"); return(false); } // avoid Newtonsoft.Json dependency var match = Regex.Match(globalJson, $@"""dotnet""\s*:\s*""([^""]+)"""); if (!match.Success) { Log.LogError($"Unable to determine dotnet version from file '{globalJsonPath}'."); return(false); } var minSdkVersionStr = match.Groups[1].Value; if (!SemanticVersion.TryParse(minSdkVersionStr, out var minSdkVersion)) { Log.LogError($"DotNet version specified in '{globalJsonPath}' is invalid: {minSdkVersionStr}."); return(false); } if (currentSdkVersion < minSdkVersion) { Log.LogError($"The .NET Core SDK version {currentSdkVersion} is below the minimum required version {minSdkVersion}. You can install newer .NET Core SDK from https://www.microsoft.com/net/download."); return(false); } return(true); } bool success = execute(); BuildEngine4.RegisterTaskObject(s_cacheKey, new CacheEntry(lastWrite, success), RegisteredTaskObjectLifetime.Build, allowEarlyCollection: true); return(success); }
public override bool Execute() { if (!Debugger.IsAttached && OptionDebug) { Debugger.Launch(); } var logger = new Logger(Log); try { var items = ItemsProperties.Enumerate().ToDictionary(pair => pair.Key, pair => { var taskItems = pair.Value?.GetValue(this) as IEnumerable <ITaskItem>; if (taskItems == null) { return(Enumerable.Empty <Item>()); } return(taskItems.Select(c => new Item(c))); }); var references = References.Enumerate().Select(c => new Item(c)); var properties = PropertiesProperties.Enumerate().ToDictionary(pair => pair.Key, pair => pair.Value?.GetValue(this) as string); var directories = DirectoryProperties.Enumerate().ToDictionary(pair => pair.Key, pair => pair.Value?.GetValue(this) as string); //Check solution folder property if (string.IsNullOrWhiteSpace(directories[BuildDirectory.Solution]) || directories[BuildDirectory.Solution] == "*Undefined*") { directories[BuildDirectory.Solution] = FindSolutionDirectory(properties[BuildProperty.ProjectFile], directories[BuildDirectory.Project]); } //Normilize all pathes and make sure all directories has slash foreach (var directory in directories.Keys.ToArray()) { var sourceDirectory = directories[directory]; if (sourceDirectory == null) { continue; } if (!sourceDirectory.IsAbsolutePath()) { sourceDirectory = Path.Combine(directories[BuildDirectory.Project], sourceDirectory); } directories[directory] = sourceDirectory.NormalizePath().TrimEnd('\\') + "\\"; } var explorer = new Explorer(references, items, directories, properties); var sandbox = new Sanbox(explorer, logger); BuildEngine4.RegisterTaskObject(BuildEngine.ProjectFileOfTaskNode, sandbox, RegisteredTaskObjectLifetime.Build, false); var artifacts = sandbox.Client.ExecutePreBuildAdaptations(logger); if (artifacts.Any()) { logger.Debug("------------"); logger.Info("Adding additional TaskItems to build"); foreach (var builder in artifacts) { logger.Info($"+ {builder}"); } FillOutputTaskItems(artifacts); } ArtifactsTemporary = artifacts.Where(a => !a.IsPermanent) .Select(a => new TaskItem(a.Path)) .OfType <ITaskItem>() .ToArray(); } catch (Exception e) { logger.Error($"Assembly adaptation initialization failed. Details: {e.GetBaseException().Message}"); } return(!Log.HasLoggedErrors); }
void GenerateCompressedAssemblySources() { if (Debug || !EnableCompression) { Generate(null); return; } var assemblies = new SortedDictionary <string, CompressedAssemblyInfo> (StringComparer.Ordinal); foreach (ITaskItem assembly in ResolvedAssemblies) { if (bool.TryParse(assembly.GetMetadata("AndroidSkipAddToPackage"), out bool value) && value) { continue; } if (assemblies.ContainsKey(assembly.ItemSpec)) { continue; } var fi = new FileInfo(assembly.ItemSpec); if (!fi.Exists) { Log.LogError($"Assembly {assembly.ItemSpec} does not exist"); continue; } assemblies.Add(Path.GetFileName(assembly.ItemSpec), new CompressedAssemblyInfo(checked ((uint)fi.Length))); } uint index = 0; foreach (var kvp in assemblies) { kvp.Value.DescriptorIndex = index++; } string key = CompressedAssemblyInfo.GetKey(ProjectFullPath); Log.LogDebugMessage($"Storing compression assemblies info with key '{key}'"); BuildEngine4.RegisterTaskObject(key, assemblies, RegisteredTaskObjectLifetime.Build, false); Generate(assemblies); void Generate(IDictionary <string, CompressedAssemblyInfo> dict) { foreach (string abi in SupportedAbis) { NativeAssemblerTargetProvider asmTargetProvider = GeneratePackageManagerJava.GetAssemblyTargetProvider(abi); string baseAsmFilePath = Path.Combine(EnvironmentOutputDirectory, $"compressed_assemblies.{abi.ToLowerInvariant ()}"); string asmFilePath = $"{baseAsmFilePath}.s"; var asmgen = new CompressedAssembliesNativeAssemblyGenerator(dict, asmTargetProvider, baseAsmFilePath); using (var sw = MemoryStreamPool.Shared.CreateStreamWriter()) { asmgen.Write(sw); sw.Flush(); if (MonoAndroidHelper.CopyIfStreamChanged(sw.BaseStream, asmFilePath)) { Log.LogDebugMessage($"File {asmFilePath} was regenerated"); } } } } }
public override bool RunTask() { if (InputAssemblies == null) { return(true); } var output = new List <ITaskItem> (InputAssemblies.Length); foreach (var assemblyItem in InputAssemblies) { if (!File.Exists(assemblyItem.ItemSpec)) { Log.LogDebugMessage($"Skipping non-existent dependency '{assemblyItem.ItemSpec}'."); continue; } using (var pe = new PEReader(File.OpenRead(assemblyItem.ItemSpec))) { var reader = pe.GetMetadataReader(); // Check in-memory cache var module = reader.GetModuleDefinition(); var key = (nameof(FilterAssemblies), reader.GetGuid(module.Mvid)); var value = BuildEngine4.GetRegisteredTaskObject(key, Lifetime); if (value is bool isMonoAndroidAssembly) { if (isMonoAndroidAssembly) { Log.LogDebugMessage($"Cached: {assemblyItem.ItemSpec}"); output.Add(assemblyItem); } continue; } // Check assembly definition var assemblyDefinition = reader.GetAssemblyDefinition(); var targetFrameworkIdentifier = GetTargetFrameworkIdentifier(assemblyDefinition, reader); if (string.Compare(targetFrameworkIdentifier, TargetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) == 0) { output.Add(assemblyItem); BuildEngine4.RegisterTaskObject(key, true, Lifetime, AllowEarlyCollection); continue; } // Fallback to looking for a Mono.Android reference if (MonoAndroidHelper.HasMonoAndroidReference(reader)) { Log.LogDebugMessage($"Mono.Android reference found: {assemblyItem.ItemSpec}"); output.Add(assemblyItem); BuildEngine4.RegisterTaskObject(key, true, Lifetime, AllowEarlyCollection); continue; } // Fallback to looking for *.jar or __Android EmbeddedResource files if (HasEmbeddedResource(reader)) { Log.LogDebugMessage($"EmbeddedResource found: {assemblyItem.ItemSpec}"); output.Add(assemblyItem); BuildEngine4.RegisterTaskObject(key, true, Lifetime, AllowEarlyCollection); continue; } // Not a MonoAndroid assembly, store false BuildEngine4.RegisterTaskObject(key, false, Lifetime, AllowEarlyCollection); } } OutputAssemblies = output.ToArray(); return(!Log.HasLoggedErrors); }