public static int Main(string [] args) { var shouldShowHelp = false; string libPath = null; string outputPath = null; var options = new OptionSet { { "lib|l=", "Path of the library for which the plist will be generated.", p => libPath = p }, { "output|o=", "Path to which the generated plist will be written.", p => outputPath = p }, { "h|?|help", "Show this message and exit", h => shouldShowHelp = h != null }, }; var extra = options.Parse(args); if (extra.Count > 0) { // Warn about extra params that are ignored. Console.WriteLine($"WARNING: The following extra parameters will be ignored: '{ String.Join (",", extra) }'"); } if (shouldShowHelp) { Console.Out.WriteLine("plist-swifty generates a basic Info.plist file for a given library."); Console.Out.WriteLine("Most of the information for the file is pulled from the library itself."); Console.Out.WriteLine("Some of the information is taken from Xcode itself."); Console.Out.WriteLine("The output is a text version. If you need a binary, use plutil"); Console.Out.WriteLine("Usage:"); options.WriteOptionDescriptions(Console.Out); return(0); } if (string.IsNullOrEmpty(libPath)) { Console.Out.WriteLine("Missing required option -l=PATH"); return(1); } if (string.IsNullOrEmpty(outputPath)) { Console.Out.WriteLine("Missing required option -o=PATH"); return(1); } if (!File.Exists(libPath)) { throw new FileNotFoundException("unable to locate input library", args [0]); } if (!Directory.Exists(Path.GetDirectoryName(outputPath))) { Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); } InfoPList.MakeInfoPList(libPath, outputPath); return(0); }
public Tuple <string, HashSet <string> > CompileWrappers(string [] inputLibraryDirectories, string [] inputModuleDirectories, IEnumerable <ModuleDeclaration> modulesToCompile, ModuleInventory modInventory, List <string> targets, string wrappingModuleName, bool outputIsFramework) { wrappingModuleName = wrappingModuleName ?? kXamWrapPrefix; string outputLibraryName = BuildLibraryName(wrappingModuleName, outputIsFramework); string outputLibraryPath = Path.Combine(outputDirectory, outputLibraryName); string outputFrameworkPath = Path.Combine(outputDirectory, Path.GetFileName(outputLibraryName) + ".framework"); string outputFrameworkLibPath = Path.Combine(outputFrameworkPath, outputLibraryName); if (File.Exists(outputLibraryPath)) { File.Delete(outputLibraryPath); } using (TempDirectorySwiftClassFileProvider fileProvider = new TempDirectorySwiftClassFileProvider(Ex.ThrowOnNull(wrappingModuleName, "wrappingModuleName"), true)) { var allReferencedModules = new HashSet <string> (); foreach (ModuleDeclaration module in modulesToCompile) { HashSet <string> referencedModules = null; var wrappedClasses = Wrap(module, modInventory, fileProvider, typeMapper, wrappingModuleName, out referencedModules, errors); this.wrappers.Add(module.Name, wrappedClasses); allReferencedModules.Merge(referencedModules); } var inModuleNamesList = modulesToCompile.Select(mod => mod.Name).ToList(); inModuleNamesList.Add("XamGlue"); if (fileProvider.IsEmpty) { return(new Tuple <string, HashSet <string> > (null, null)); } var targetOutDirs = new List <string> (); for (int i = 0; i < targets.Count; i++) { // each file goes to a unique output directory. // first compile into the fileProvider, then move to // fileProvider/tar-get-arch string targetoutdir = Path.Combine(fileProvider.DirectoryPath, targets [i]); targetOutDirs.Add(targetoutdir); Directory.CreateDirectory(targetoutdir); var locations = SwiftModuleFinder.GatherAllReferencedModules(allReferencedModules, inputModuleDirectories, targets [i]); try { string [] inputModDirs = locations.Select(loc => loc.DirectoryPath).ToArray(); CompileAllFiles(fileProvider, wrappingModuleName, outputLibraryName, outputLibraryPath, inputModDirs, inputLibraryDirectories, inModuleNamesList.ToArray(), targets [i], outputIsFramework); } catch (Exception e) { throw ErrorHelper.CreateError(ReflectorError.kCantHappenBase + 66, e, $"Failed to compile the generated swift wrapper code."); } finally { locations.DisposeAll(); } // move to arch directory File.Copy(Path.Combine(fileProvider.DirectoryPath, outputLibraryName), Path.Combine(targetoutdir, outputLibraryName), true); File.Delete(Path.Combine(fileProvider.DirectoryPath, outputLibraryName)); File.Copy(Path.Combine(fileProvider.DirectoryPath, wrappingModuleName + ".swiftmodule"), Path.Combine(targetoutdir, wrappingModuleName + ".swiftmodule")); File.Delete(Path.Combine(fileProvider.DirectoryPath, wrappingModuleName + ".swiftmodule")); File.Copy(Path.Combine(fileProvider.DirectoryPath, wrappingModuleName + ".swiftdoc"), Path.Combine(targetoutdir, wrappingModuleName + ".swiftdoc")); File.Delete(Path.Combine(fileProvider.DirectoryPath, wrappingModuleName + ".swiftdoc")); } if (targets.Count > 1) { // lipo all the outputs back into the fileProvider Lipo(targetOutDirs, fileProvider.DirectoryPath, outputLibraryName); File.Copy(Path.Combine(fileProvider.DirectoryPath, outputLibraryName), outputLibraryPath, true); if (!IsMacOSLib(outputLibraryPath)) { if (!Directory.Exists(outputFrameworkPath)) { Directory.CreateDirectory(outputFrameworkPath); } File.Copy(outputLibraryPath, outputFrameworkLibPath, true); InfoPList.MakeInfoPList(outputFrameworkLibPath, Path.Combine(outputFrameworkPath, "Info.plist")); } } else { File.Copy(Path.Combine(targetOutDirs [0], outputLibraryName), outputLibraryPath, true); if (!IsMacOSLib(outputLibraryPath)) { if (!Directory.Exists(outputFrameworkPath)) { Directory.CreateDirectory(outputFrameworkPath); } File.Copy(outputLibraryPath, outputFrameworkLibPath, true); InfoPList.MakeInfoPList(outputFrameworkLibPath, Path.Combine(outputFrameworkPath, "Info.plist")); } } for (int i = 0; i < targets.Count; i++) { string arch = targets [i].ClangTargetCpu(); string targetDir = Path.Combine(outputDirectory, arch); Directory.CreateDirectory(targetDir); File.Copy(Path.Combine(targetOutDirs [i], wrappingModuleName + ".swiftmodule"), Path.Combine(targetDir, wrappingModuleName + ".swiftmodule"), true); File.Copy(Path.Combine(targetOutDirs [i], wrappingModuleName + ".swiftdoc"), Path.Combine(targetDir, wrappingModuleName + ".swiftdoc"), true); } foreach (string dirname in targetOutDirs) { Directory.Delete(dirname, true); } if (retainSwiftFiles) { CopySwiftFiles(fileProvider, Path.Combine(outputDirectory, wrappingModuleName + "Source")); } return(new Tuple <string, HashSet <string> > (outputLibraryPath, allReferencedModules)); } }