public override bool Execute() { var coremlcOutputDir = Path.Combine(IntermediateOutputPath, "coremlc"); var prefixes = BundleResource.SplitResourcePrefixes(ResourcePrefix); var mapping = new Dictionary <string, IDictionary> (); var bundleResources = new List <ITaskItem> (); var partialPlists = new List <ITaskItem> (); if (Models.Length > 0) { Directory.CreateDirectory(coremlcOutputDir); foreach (var model in Models) { var logicalName = BundleResource.GetLogicalName(ProjectDir, prefixes, model, !string.IsNullOrEmpty(SessionId)); var bundleName = GetPathWithoutExtension(logicalName) + ".mlmodelc"; var outputPath = Path.Combine(coremlcOutputDir, bundleName); var outputDir = Path.GetDirectoryName(outputPath); var partialPlist = GetPathWithoutExtension(outputPath) + "-partial.plist"; var log = GetPathWithoutExtension(outputPath) + ".log"; var resourceTags = model.GetMetadata("ResourceTags"); var output = new TaskItem(outputPath); output.SetMetadata("LogicalName", bundleName); output.SetMetadata("Optimize", "false"); if (EnableOnDemandResources && !string.IsNullOrEmpty(resourceTags)) { output.SetMetadata("ResourceTags", resourceTags); } var metadata = output.CloneCustomMetadata(); mapping[outputPath + "/"] = metadata; if (FileChanged(model, partialPlist)) { Directory.CreateDirectory(outputDir); if ((Compile(model, outputDir, log, partialPlist)) != 0) { return(false); } } else { Log.LogMessage(MessageImportance.Low, "Skipping `{0}' as the output file, `{1}', is newer.", model.ItemSpec, partialPlist); } } bundleResources.AddRange(GetCompiledOutput(coremlcOutputDir, mapping)); foreach (var path in Directory.EnumerateFiles(coremlcOutputDir, "*-partial.plist", SearchOption.AllDirectories)) { partialPlists.Add(new TaskItem(path)); } } BundleResources = bundleResources.ToArray(); PartialAppManifests = partialPlists.ToArray(); return(!Log.HasLoggedErrors); }
bool CompileInterfaceDefinitions(string baseManifestDir, string baseOutputDir, List <ITaskItem> compiled, IList <ITaskItem> manifests, out bool changed) { var mapping = new Dictionary <string, IDictionary> (); var unique = new Dictionary <string, ITaskItem> (); var targets = GetTargetDevices(plist).ToList(); changed = false; foreach (var item in InterfaceDefinitions) { var bundleName = GetBundleRelativeOutputPath(item); var manifest = new TaskItem(Path.Combine(baseManifestDir, bundleName)); var manifestDir = Path.GetDirectoryName(manifest.ItemSpec); ITaskItem duplicate; string output; if (!File.Exists(item.ItemSpec)) { Log.LogError(null, null, null, item.ItemSpec, 0, 0, 0, 0, MSBStrings.E0158, item.ItemSpec); continue; } if (unique.TryGetValue(bundleName, out duplicate)) { Log.LogError(null, null, null, item.ItemSpec, 0, 0, 0, 0, MSBStrings.E0159, item.ItemSpec, duplicate.ItemSpec); continue; } unique.Add(bundleName, item); var resourceTags = item.GetMetadata("ResourceTags"); var path = Path.Combine(baseOutputDir, bundleName); var outputDir = Path.GetDirectoryName(path); var name = GetPathWithoutExtension(path); var extension = Path.GetExtension(path); var expected = new TaskItem(path); expected.SetMetadata("InterfaceDefinition", item.ItemSpec); expected.SetMetadata("LogicalName", bundleName); expected.SetMetadata("Optimize", "false"); if (EnableOnDemandResources && !string.IsNullOrEmpty(resourceTags)) { expected.SetMetadata("ResourceTags", resourceTags); } if (UseCompilationDirectory) { // Note: When using --compilation-directory, we need to specify the output path as the parent directory output = Path.GetDirectoryName(path); } else { output = expected.ItemSpec; } if (InterfaceDefinitionChanged(item, manifest)) { Directory.CreateDirectory(manifestDir); Directory.CreateDirectory(outputDir); if ((Compile(new[] { item }, output, manifest)) != 0) { return(false); } changed = true; } else { Log.LogMessage(MessageImportance.Low, MSBStrings.M0119, item.ItemSpec, manifest.ItemSpec); } try { var dict = PDictionary.FromFile(manifest.ItemSpec); LogWarningsAndErrors(dict, item); } catch (Exception ex) { Log.LogError(MSBStrings.E0094, ToolName, manifest.ItemSpec, ex.Message); if (File.Exists(manifest.ItemSpec)) { Log.LogError("ibtool log: {0}", File.ReadAllText(manifest.ItemSpec)); } continue; } if (UseCompilationDirectory) { // Note: When using a compilation-directory, we'll scan dir the baseOutputDir later as // an optimization to collect all of the compiled output in one fell swoop. var metadata = expected.CloneCustomMetadata(); foreach (var target in targets) { var key = name + "~" + target + extension; // Note: we don't blindly .Add() here because there may already be a mapping for this file if the // source file is named something like "MyView.xib" and we've already processed "MyView~ipad.xib". // // When a situation like this occurs, we don't want to override the metadata. if (!mapping.ContainsKey(key)) { mapping.Add(key, metadata); } } // Note: we don't use .Add() here because there may already be a mapping for this file if the // source file is named something like "MyView~ipad.xib" and we've already processed "MyView.xib". // // In this case, we want to override the metadata for "MyView.xib" with the metadata for // "MyView~ipad.xib". mapping[path] = metadata; } else { compiled.AddRange(GetCompilationOutput(expected)); } manifests.Add(manifest); } if (UseCompilationDirectory) { compiled.AddRange(GetCompilationDirectoryOutput(baseOutputDir, mapping)); } return(!Log.HasLoggedErrors); }
bool CompileInterfaceDefinitions(string baseManifestDir, string baseOutputDir, List <ITaskItem> compiled, IList <ITaskItem> manifests, out bool changed) { var mapping = new Dictionary <string, IDictionary> (); var unique = new Dictionary <string, ITaskItem> (); var targets = GetTargetDevices(plist).ToList(); changed = false; foreach (var item in InterfaceDefinitions) { var bundleName = GetBundleRelativeOutputPath(item); var manifest = new TaskItem(Path.Combine(baseManifestDir, bundleName)); var manifestDir = Path.GetDirectoryName(manifest.ItemSpec); ITaskItem duplicate; string output; if (!File.Exists(item.ItemSpec)) { Log.LogError(null, null, null, item.ItemSpec, 0, 0, 0, 0, "The file '{0}' does not exist.", item.ItemSpec); continue; } if (unique.TryGetValue(bundleName, out duplicate)) { Log.LogError(null, null, null, item.ItemSpec, 0, 0, 0, 0, "The file '{0}' conflicts with '{1}'.", item.ItemSpec, duplicate.ItemSpec); continue; } unique.Add(bundleName, item); var resourceTags = item.GetMetadata("ResourceTags"); var path = Path.Combine(baseOutputDir, bundleName); var outputDir = Path.GetDirectoryName(path); var name = GetPathWithoutExtension(path); var extension = Path.GetExtension(path); var expected = new TaskItem(path); expected.SetMetadata("InterfaceDefinition", item.ItemSpec); expected.SetMetadata("LogicalName", bundleName); expected.SetMetadata("Optimize", "false"); if (!string.IsNullOrEmpty(resourceTags)) { expected.SetMetadata("ResourceTags", resourceTags); } if (UseCompilationDirectory) { // Note: When using --compilation-directory, we need to specify the output path as the parent directory output = Path.GetDirectoryName(path); } else { output = expected.ItemSpec; } if (InterfaceDefinitionChanged(item, manifest)) { Directory.CreateDirectory(manifestDir); Directory.CreateDirectory(outputDir); if ((Compile(new[] { item }, output, manifest)) != 0) { return(false); } changed = true; } else { Log.LogMessage(MessageImportance.Low, "Skipping `{0}' as the output file, `{1}', is newer.", item.ItemSpec, manifest.ItemSpec); } try { var dict = PDictionary.FromFile(manifest.ItemSpec); LogWarningsAndErrors(dict, item); } catch (Exception ex) { Log.LogError("Failed to load output log file for {0}: {1}", ToolName, ex.Message); if (File.Exists(manifest.ItemSpec)) { Log.LogError("ibtool log: {0}", File.ReadAllText(manifest.ItemSpec)); } continue; } if (UseCompilationDirectory) { // Note: When using a compilation-directory, we'll scan dir the baseOutputDir later as // an optimization to collect all of the compiled output in one fell swoop. var metadata = expected.CloneCustomMetadata(); foreach (var target in targets) { mapping.Add(name + "~" + target + extension, metadata); } mapping.Add(path, metadata); } else { compiled.AddRange(GetCompilationOutput(expected)); } manifests.Add(manifest); } if (UseCompilationDirectory) { compiled.AddRange(GetCompilationDirectoryOutput(baseOutputDir, mapping)); } return(!Log.HasLoggedErrors); }
public System.Collections.IDictionary CloneCustomMetadata() { return(item.CloneCustomMetadata()); }
public IDictionary CloneCustomMetadata() { return(_backingTaskItem.CloneCustomMetadata()); }