public void SetUp() { installDir = Path.GetTempFileName(); if (File.Exists(installDir)) { File.Delete(installDir); } installDir = Path.Combine(installDir, "Xamarin.iOS"); Directory.CreateDirectory(installDir); // create temp dirs that will be used to place some files // to test their presence and decide that the correct // mangler is used tmpRoot = Path.GetTempFileName(); if (File.Exists(tmpRoot)) { File.Delete(tmpRoot); } Directory.CreateDirectory(tmpRoot); // create a path for the mono paths var monoPath = Path.Combine(tmpRoot, "external", "mono", "sdks", "out", "ios-sources"); Directory.CreateDirectory(monoPath); fakeMonoPath = Path.Combine(monoPath, "FakeStirng.cs"); CreateFakeFile(fakeMonoPath); // create a path for the xamarin paths var xamarinPath = Path.Combine(tmpRoot, "src"); Directory.CreateDirectory(xamarinPath); fakeXamarinPath = Path.Combine(xamarinPath, "FakeObjc.cs"); CreateFakeFile(fakeXamarinPath); var openTKPath = Path.Combine(tmpRoot, "external", "OpenTK"); Directory.CreateDirectory(Path.Combine(openTKPath)); fakeOpenTKPath = Path.Combine(openTKPath, "FakeMaths.cs"); CreateFakeFile(fakeOpenTKPath); factory = new PathManglerFactory() { InstallDir = installDir, MonoSourcePath = monoPath, XamarinSourcePath = xamarinPath, OpenTKSourcePath = openTKPath }; }
public static int Main(string[] arguments) { bool link = false; string monopath = null; string opentkpath = null; string xamarinpath = null; string installDir = null; string destinationDir = null; bool verbose = false; var os = new OptionSet() { { "link:", "If source files should be linked instead of copied. Makes the install process faster, and if you edit files when stopped in a debugger, you'll edit the right file (and not a copy).", v => link = ParseBool(v) }, { "mono-path=", "The path of the mono checkout.", v => monopath = v }, { "opentk-path=", "The path of the opentk checkout.", v => opentkpath = v }, { "xamarin-path=", "The path of the xamarin source.", v => xamarinpath = v }, { "install-dir=", "The directory to install into. The files will be put into a src subdirectory of this directory.", v => installDir = v }, { "destination-dir=", "The path to the directory used for the -pathmap at build time.", v => destinationDir = v }, { "v|erbose", "Enable verbose output", v => verbose = true }, }; var paths = os.Parse(arguments); var files = GetSplittedPaths(paths); var srcs = new HashSet <string> (StringComparer.OrdinalIgnoreCase); monopath = FixPathEnding(monopath); xamarinpath = FixPathEnding(xamarinpath); opentkpath = FixPathEnding(opentkpath); var manglerFactory = new PathManglerFactory { Verbose = verbose, InstallDir = installDir, DestinationDir = destinationDir, MonoSourcePath = monopath, XamarinSourcePath = xamarinpath, FrameworkPath = (installDir.Contains("Xamarin.iOS.framework")) ? "Xamarin.iOS.framework" : "Xamarin.Mac.framework", OpenTKSourcePath = opentkpath, }; // add the paths from the pdb files foreach (string pdbFile in files.Item1) { if (!File.Exists(pdbFile)) { Console.WriteLine("File does not exist: {0}", pdbFile); continue; } var assemblySrcs = GetFilePathsFromPdb(pdbFile); if (verbose) { Console.WriteLine("Pdb file sources are:"); foreach (var p in srcs) { Console.WriteLine($"\t{p}"); } } srcs.UnionWith(assemblySrcs); } // add the paths from the mdb files foreach (string mdbFile in files.Item2) { if (!File.Exists(mdbFile)) { Console.WriteLine("File does not exist: {0}", mdbFile); continue; } var assemblySrcs = GetFilePathsFromMdb(mdbFile); if (verbose) { Console.WriteLine("Mdb file sources are:"); foreach (var p in srcs) { Console.WriteLine($"\t{p}"); } } srcs.UnionWith(assemblySrcs); } if (verbose) { Console.WriteLine("Build paths are:"); Console.WriteLine($"\tMono path:{monopath}"); Console.WriteLine($"\tXamarin path:{xamarinpath}"); Console.WriteLine($"\tOpenTk path:{opentkpath}"); Console.WriteLine($"\tDestination path:{destinationDir}"); } var alreadyLinked = new List <string> (); foreach (var src in srcs) { var mangler = manglerFactory.GetMangler(src); if (mangler == null) // we are ignoring this file { if (verbose) { Console.WriteLine($"Ignoring path {src}"); } continue; } if (verbose) { Console.WriteLine($"Original source is {src}"); } var fixedSource = mangler.GetSourcePath(src); if (String.IsNullOrEmpty(fixedSource)) { Console.WriteLine($"Skip path {src}"); continue; } var target = mangler.GetTargetPath(fixedSource); if (verbose) { Console.WriteLine($"Fixed source {fixedSource}"); Console.WriteLine($"Target path {target}"); } var targetDir = Path.GetDirectoryName(target); if (String.IsNullOrEmpty(targetDir)) { Console.WriteLine($"Got empty dir for {target}"); continue; } if (verbose) { Console.WriteLine($"Target direcotry is {targetDir}"); } if (!Directory.Exists(targetDir)) { try { if (verbose) { Console.WriteLine($"Creating dir {targetDir}"); } Directory.CreateDirectory(targetDir); } catch (PathTooLongException e) { Console.WriteLine("Could not create directory {0} because the path is too long: {1}", targetDir, e); return(1); } } else if (File.Exists(target)) { try { File.Delete(target); } catch (PathTooLongException e) { Console.WriteLine("Could not delete file {0} because the path is too long: {1}", target, e); return(1); } } // else if (link) { if (verbose) { Console.WriteLine("ln -s {0} {1}", fixedSource, target); } try { if (!alreadyLinked.Contains(fixedSource)) { new UnixFileInfo(fixedSource).CreateSymbolicLink(target); alreadyLinked.Add(fixedSource); } else { Console.WriteLine("Src {0} was already linked.", src); } } catch (PathTooLongException e) { Console.WriteLine("Could not link {0} to {1} because the path is too long: {2}", fixedSource, target, e); return(1); } catch (UnixIOException e) { Console.WriteLine("Could not link {0} to {1}: {2}", src, target, e); return(1); } // try/catch } else { if (verbose) { Console.WriteLine("cp {0} {1}", fixedSource, target); } try { File.Copy(fixedSource, target); } catch (FileNotFoundException e) { Console.WriteLine("The file {0} could not be copied to {1} because the file does not exists: {2}", fixedSource, target, e); Console.WriteLine("Debugging info:"); Console.WriteLine("\tSource is {0}", src); Console.WriteLine("\tFixed source is {0}", fixedSource); Console.WriteLine("\tPath mangler type is {0}", mangler.GetType().Name); } catch (PathTooLongException e) { Console.WriteLine("The file {0} could not be copied to {1} because the file path is too long: {2}", fixedSource, target, e); return(1); } } // else } // foreach return(0); }