// added to make sure our key output is picked up properly protected override void Refresh() { // Let MSBuild know which configuration we are working with this.Project.SetConfiguration(this.ProjectCfg.ConfigCanonicalName); // Generate dependencies if such a task exist if (this.Project.ProjectInstance.Targets.ContainsKey(ProjectFileConstants.AllProjectOutputGroups)) { bool succeeded = false; this.Project.BuildTarget(ProjectFileConstants.AllProjectOutputGroups, out succeeded); if (!succeeded) { if (System.Diagnostics.Debugger.IsAttached) Debug.WriteLine("Failed to build target {0}", this.TargetName); this.Outputs.Clear(); return; } } // Rebuild the content of our list of output string outputType = this.TargetName + "Output"; if (TargetName == "BuiltProjectOutputGroup") outputType = this.TargetName + "KeyOutput"; this.Outputs.Clear(); foreach (MSBuildExecution.ProjectItemInstance item in MSBuildProjectInstance.GetItems(this.Project.ProjectInstance, outputType)) { Output output = new Output(this.Project, item); this.Outputs.Add(output); // See if it is our key output if (String.Compare(MSBuildItem.GetMetadataValue(item, "IsKeyOutput"), true.ToString(), StringComparison.OrdinalIgnoreCase) == 0) KeyOutput = output; } this.Project.SetCurrentConfiguration(); // Now that the group is built we have to check if it is invalidated by a property // change on the project. this.Project.OnProjectPropertyChanged += new EventHandler<ProjectPropertyChangedArgs>(OnProjectPropertyChanged); }
private string GetSourceLink(MSBuildItem projectItemInstance) { var link = projectItemInstance.GetMetadataValue("Link"); var definingProjectFullPath = projectItemInstance.GetMetadataValue("DefiningProjectFullPath"); var fullPath = projectItemInstance.GetMetadataValue("FullPath"); // Reproduce the logic from https://github.com/dotnet/msbuild/blob/e70a3159d64f9ed6ec3b60253ef863fa883a99b1/src/Tasks/AssignLinkMetadata.cs if (link.IsNullOrEmpty()) { if (definingProjectFullPath.IsNullOrEmpty()) { // Both Uno.SourceGeneration uses relative paths and Roslyn Generators provide // full paths. Dependents need specific portions so adjust the paths here for now. // For the case of Roslyn generators, DefiningProjectFullPath is not populated on purpose // so that we can adjust paths properly. if (link.IsNullOrEmpty()) { return(Path.IsPathRooted(projectItemInstance.Identity) ? projectItemInstance.Identity.TrimStart(_projectDirectory).TrimStart(Path.DirectorySeparatorChar) : projectItemInstance.Identity); } } else { var definingProjectDirectory = Path.GetDirectoryName(definingProjectFullPath) + Path.DirectorySeparatorChar; if (fullPath.StartsWith(definingProjectDirectory, StringComparison.OrdinalIgnoreCase)) { link = fullPath.Substring(definingProjectDirectory.Length); } else { link = projectItemInstance.GetMetadataValue("Identity"); } } } return(link); }
internal protected override void Write(Project project, MSBuildItem buildItem) { base.Write(project, buildItem); buildItem.Metadata.SetValue("DependentUpon", DependsOn, FilePath.Empty, relativeToPath: FilePath.ParentDirectory); buildItem.Metadata.SetValue("SubType", ContentType, ""); buildItem.Metadata.SetValue("Generator", Generator, ""); buildItem.Metadata.SetValue("CustomToolNamespace", CustomToolNamespace, ""); buildItem.Metadata.SetValue("LastGenOutput", LastGenOutput, ""); buildItem.Metadata.SetValue("Link", Link, FilePath.Empty, relativeToProject: false); buildItem.Metadata.SetValue("CopyToOutputDirectory", CopyToOutputDirectory.ToString(), "None"); buildItem.Metadata.SetValue("Visible", Visible, true); var resId = ResourceId; // For EmbeddedResource, emit LogicalName only when it does not match the default msbuild resource Id if (project is DotNetProject && BuildAction == MonoDevelop.Projects.BuildAction.EmbeddedResource && ((DotNetProject)project).GetDefaultMSBuildResourceId(this) == resId) { resId = ""; } buildItem.Metadata.SetValue("LogicalName", resId, ""); }
bool IsPackageReferenceMatch(MSBuildItem item) { return(item.Name == "PackageReference" && StringComparer.OrdinalIgnoreCase.Equals(item.Include, packageIdentity.Id)); }
public bool Matches(MSBuildItem item) { return(item.Name == Name && item.Include == Include); }
public virtual void Read(MSBuildItem item) { this.BuildItem = item; Include = item.Include; }
/// <summary> /// Get the file location as seen in the IDE, used for ResourceDictionary.Source resolution. /// </summary> private string GetSourceLink(MSBuildItem projectItemInstance) { var value = projectItemInstance.GetMetadataValue("Link"); return(value.IsNullOrEmpty() ? projectItemInstance.Identity : value); }
protected override void TryEndProcess() { // No attributes are currently linked away, which means we don't need to worry about linked away LinkWith attributes. // Ref: https://github.com/mono/linker/issues/952 (still open as of this writing). var exceptions = new List <Exception> (); Configuration.Target.ExtractNativeLinkInfo(exceptions); Report(exceptions); // Tell MSBuild about the native libraries we found var linkWith = new List <MSBuildItem> (); foreach (var asm in Configuration.Target.Assemblies) { foreach (var arg in asm.LinkWith) { var item = new MSBuildItem { Include = arg, Metadata = new Dictionary <string, string> { { "ForceLoad", "true" }, { "Assembly", asm.Identity }, }, }; linkWith.Add(item); } } Configuration.WriteOutputForMSBuild("_BindingLibraryLinkWith", linkWith); // Tell MSBuild about the frameworks libraries we found var frameworks = new List <MSBuildItem> (); foreach (var asm in Configuration.Target.Assemblies) { foreach (var fw in asm.Frameworks) { var item = new MSBuildItem { Include = fw, Metadata = new Dictionary <string, string> { { "Assembly", asm.Identity }, }, }; frameworks.Add(item); } foreach (var fw in asm.WeakFrameworks) { var item = new MSBuildItem { Include = fw, Metadata = new Dictionary <string, string> { { "IsWeak", "true " }, { "Assembly", asm.Identity }, }, }; frameworks.Add(item); } } Configuration.WriteOutputForMSBuild("_BindingLibraryFrameworks", frameworks); var frameworksToPublish = new List <MSBuildItem> (); foreach (var asm in Configuration.Target.Assemblies) { var fwks = new HashSet <string> (); fwks.UnionWith(asm.Frameworks); fwks.UnionWith(asm.WeakFrameworks); // Only keep frameworks that point to a location on disk fwks.RemoveWhere(v => !v.EndsWith(".framework", StringComparison.Ordinal)); foreach (var fwk in fwks) { if (!Configuration.Application.VerifyDynamicFramework(fwk)) { continue; } var executable = Path.Combine(fwk, Path.GetFileNameWithoutExtension(fwk)); var item = new MSBuildItem { Include = executable, }; frameworksToPublish.Add(item); } } Configuration.WriteOutputForMSBuild("_FrameworkToPublish", frameworksToPublish); var dynamicLibraryToPublish = new List <MSBuildItem> (); foreach (var asm in Configuration.Target.Assemblies) { foreach (var arg in asm.LinkWith) { if (!arg.EndsWith(".dylib", StringComparison.OrdinalIgnoreCase)) { continue; } var item = new MSBuildItem { Include = arg, Metadata = new Dictionary <string, string> { { "RelativePath", Path.Combine(Configuration.RelativeAppBundlePath, Configuration.Application.RelativeDylibPublishPath, Path.GetFileName(arg)) }, }, }; dynamicLibraryToPublish.Add(item); } } Configuration.WriteOutputForMSBuild("_DynamicLibraryToPublish", dynamicLibraryToPublish); }
protected override void TryEndProcess() { base.TryEndProcess(); var registration_methods = new List <string> (Configuration.RegistrationMethods); var items = new List <MSBuildItem> (); var app = Configuration.Application; // We want this called before any other initialization methods. registration_methods.Insert(0, "xamarin_initialize_dotnet"); foreach (var abi in Configuration.Abis) { var file = Path.Combine(Configuration.CacheDirectory, $"main.{abi.AsArchString ()}.mm"); var contents = new StringBuilder(); contents.AppendLine("#include <stdlib.h>"); contents.AppendLine(); contents.AppendLine("extern \"C\" const char *xamarin_icu_dat_file_name;"); contents.AppendLine(); contents.AppendLine("static void xamarin_initialize_dotnet ()"); contents.AppendLine("{"); if (Configuration.InvariantGlobalization) { contents.AppendLine("\tsetenv (\"DOTNET_SYSTEM_GLOBALIZATION_INVARIANT\", \"1\", 1);"); } else { contents.AppendLine($"\txamarin_icu_dat_file_name = \"{Configuration.GlobalizationDataFile}\";"); } if (Configuration.Application.PackageManagedDebugSymbols && Configuration.Application.UseInterpreter) { contents.AppendLine($"\tsetenv (\"DOTNET_MODIFIABLE_ASSEMBLIES\", \"debug\", 1);"); } contents.AppendLine("}"); contents.AppendLine(); Configuration.Target.GenerateMain(contents, app.Platform, abi, file, registration_methods); var item = new MSBuildItem { Include = file, Metadata = { { "Arch", abi.AsArchString() }, }, }; if (app.EnableDebug) { item.Metadata.Add("Arguments", "-DDEBUG"); } items.Add(item); } Configuration.WriteOutputForMSBuild("_MainFile", items); var linkWith = new List <MSBuildItem> (); if (Configuration.CompilerFlags.LinkWithLibraries != null) { foreach (var lib in Configuration.CompilerFlags.LinkWithLibraries) { linkWith.Add(new MSBuildItem { Include = lib, }); } } if (Configuration.CompilerFlags.ForceLoadLibraries != null) { foreach (var lib in Configuration.CompilerFlags.ForceLoadLibraries) { linkWith.Add(new MSBuildItem { Include = lib, Metadata = { { "ForceLoad", "true" }, }, }); } } Configuration.WriteOutputForMSBuild("_MainLinkWith", linkWith); }
protected override void TryEndProcess() { base.TryEndProcess(); var registration_methods = new List <string> (Configuration.RegistrationMethods); var items = new List <MSBuildItem> (); var app = Configuration.Application; // We want this called before any other initialization methods. registration_methods.Insert(0, "xamarin_initialize_dotnet"); foreach (var abi in Configuration.Abis) { var file = Path.Combine(Configuration.CacheDirectory, $"main.{abi.AsArchString ()}.mm"); var contents = new StringBuilder(); contents.AppendLine("#include <stdlib.h>"); contents.AppendLine("static void xamarin_initialize_dotnet ()"); contents.AppendLine("{"); contents.AppendLine("\tsetenv (\"DOTNET_SYSTEM_GLOBALIZATION_INVARIANT\", \"1\", 1); // https://github.com/xamarin/xamarin-macios/issues/8906"); contents.AppendLine("}"); contents.AppendLine(); Configuration.Target.GenerateMain(contents, app.Platform, abi, file, registration_methods); var item = new MSBuildItem { Include = file, Metadata = { { "Arch", abi.AsArchString() }, }, }; if (app.EnableDebug) { item.Metadata.Add("Arguments", "-DDEBUG"); } items.Add(item); } Configuration.WriteOutputForMSBuild("_MainFile", items); var linkWith = new List <MSBuildItem> (); if (Configuration.CompilerFlags.LinkWithLibraries != null) { foreach (var lib in Configuration.CompilerFlags.LinkWithLibraries) { linkWith.Add(new MSBuildItem { Include = lib, }); } } if (Configuration.CompilerFlags.ForceLoadLibraries != null) { foreach (var lib in Configuration.CompilerFlags.ForceLoadLibraries) { linkWith.Add(new MSBuildItem { Include = lib, Metadata = { { "ForceLoad", "true" }, }, }); } } Configuration.WriteOutputForMSBuild("_MainLinkWith", linkWith); }
internal bool Matches(MSBuildItem item) { return(item.Name == this.Name && item.Include == this.Include); }
protected override void EndProcess() { base.EndProcess(); // No attributes are currently linked away, which means we don't need to worry about linked away LinkWith attributes. // Ref: https://github.com/mono/linker/issues/952 (still open as of this writing). var exceptions = new List <Exception> (); Configuration.Target.ExtractNativeLinkInfo(exceptions); Report(exceptions); // Tell MSBuild about the native libraries we found var linkWith = new List <MSBuildItem> (); foreach (var asm in Configuration.Target.Assemblies) { foreach (var arg in asm.LinkWith) { var item = new MSBuildItem { Include = arg, Metadata = new Dictionary <string, string> { { "ForceLoad", "true" }, { "Assembly", asm.Identity }, }, }; linkWith.Add(item); } } Configuration.WriteOutputForMSBuild("_BindingLibraryLinkWith", linkWith); // Tell MSBuild about the frameworks libraries we found var frameworks = new List <MSBuildItem> (); foreach (var asm in Configuration.Target.Assemblies) { foreach (var fw in asm.Frameworks) { var item = new MSBuildItem { Include = fw, Metadata = new Dictionary <string, string> { { "Assembly", asm.Identity }, }, }; frameworks.Add(item); } foreach (var fw in asm.WeakFrameworks) { var item = new MSBuildItem { Include = fw, Metadata = new Dictionary <string, string> { { "IsWeak", "true " }, { "Assembly", asm.Identity }, }, }; frameworks.Add(item); } } Configuration.WriteOutputForMSBuild("_BindingLibraryFrameworks", frameworks); // Tell MSBuild about any additional linker flags we found var linkerFlags = new List <MSBuildItem> (); foreach (var asm in Configuration.Target.Assemblies) { if (asm.LinkerFlags == null) { continue; } foreach (var arg in asm.LinkerFlags) { var item = new MSBuildItem { Include = arg, Metadata = new Dictionary <string, string> { { "Assembly", asm.Identity }, }, }; linkerFlags.Add(item); } } Configuration.WriteOutputForMSBuild("_BindingLibraryLinkerFlags", linkerFlags); }
internal override void Read(MSBuildItem item) { base.Read(item); this.Link = (item.HasMetadata("Link") ? item.GetMetadata("Link") : null); }
internal virtual void Read(MSBuildItem item) { this.BuildItem = item; this.Include = item.Include; }
protected override void TryEndProcess() { base.TryEndProcess(); var registration_methods = new List <string> (Configuration.RegistrationMethods); var items = new List <MSBuildItem> (); var app = Configuration.Application; // We want this called before any other initialization methods. registration_methods.Insert(0, "xamarin_initialize_dotnet"); foreach (var abi in Configuration.Abis) { var file = Path.Combine(Configuration.CacheDirectory, $"main.{abi.AsArchString ()}.mm"); var contents = new StringBuilder(); contents.AppendLine("#include <stdlib.h>"); contents.AppendLine("static void xamarin_initialize_dotnet ()"); contents.AppendLine("{"); contents.AppendLine("\tsetenv (\"DOTNET_SYSTEM_GLOBALIZATION_INVARIANT\", \"1\", 1); // https://github.com/xamarin/xamarin-macios/issues/8906"); contents.AppendLine("\tsetenv (\"MONO_THREADS_SUSPEND\", \"preemptive\", 1); // https://github.com/dotnet/runtime/issues/47121"); contents.AppendLine("}"); contents.AppendLine(); if (Configuration.Platform == ApplePlatform.MacOSX) { // mono_config_parse_memory was removed in .NET: https://github.com/dotnet/runtime/pull/48007 // however, we still use this function in our libxamarin code, and we can't remove it without affecting // legacy Xamarin.Mac, so just add a dummy implementation of mono_config_parse_memory so that the // native linker doesn't complain. This is a temporary solution: we'll soon build a .NET-specific // libxamarin, in which case we can #ifdef out the call to mono_config_parse_memory for .NET only. contents.AppendLine("#include <stdio.h>"); contents.AppendLine("extern \"C\" void mono_config_parse_memory (const char *buffer);"); contents.AppendLine("void mono_config_parse_memory (const char *buffer)"); contents.AppendLine("{"); contents.AppendLine("\tfprintf (stderr, \"mono_config_parse_memory has been removed\\n\");"); contents.AppendLine("}"); contents.AppendLine(); } Configuration.Target.GenerateMain(contents, app.Platform, abi, file, registration_methods); var item = new MSBuildItem { Include = file, Metadata = { { "Arch", abi.AsArchString() }, }, }; if (app.EnableDebug) { item.Metadata.Add("Arguments", "-DDEBUG"); } items.Add(item); } Configuration.WriteOutputForMSBuild("_MainFile", items); var linkWith = new List <MSBuildItem> (); if (Configuration.CompilerFlags.LinkWithLibraries != null) { foreach (var lib in Configuration.CompilerFlags.LinkWithLibraries) { linkWith.Add(new MSBuildItem { Include = lib, }); } } if (Configuration.CompilerFlags.ForceLoadLibraries != null) { foreach (var lib in Configuration.CompilerFlags.ForceLoadLibraries) { linkWith.Add(new MSBuildItem { Include = lib, Metadata = { { "ForceLoad", "true" }, }, }); } } Configuration.WriteOutputForMSBuild("_MainLinkWith", linkWith); }
public void CallWrite(MSBuildItem buildItem) { base.Write(null, buildItem); }
public override void RemoveItem (MSBuildItem item) { throw new NotImplementedException (); }