public static void Translate(CodeTranslationConfiguration configuration) { var argBuilder = new ClangArgBuilder { PathToFrameworks = XCodeConfiguration.PathToFramewroks, SimMinVersion = XCodeConfiguration.SdkVersion, SysRoot = XCodeConfiguration.SdkPath, ResourceDir = FetchResourceDir (), PrefixHeaderFilePath = configuration.PCHFilePath }; argBuilder.Frameworks.AddRange (configuration.Frameworks); argBuilder.IncludeDirs.AddRange (FetchHeaderDirs (configuration.HeaderFilePaths)); var pathLocator = new XamarinPathLocator (); string xi = pathLocator.GetAssemblyPath (Platform.iOS); var locator = new BindingLocator (new string[] { xi }); Console.WriteLine (argBuilder.ToString ()); string[] clangArgs = argBuilder.Build (); var srcTranslator = new SourceCodeTranslator (clangArgs, locator); foreach (var file in configuration.SourceFilePaths) { Console.WriteLine (file); if (Path.GetFileName (file) == "main.m") continue; var dstPath = GetDestanation (file, configuration.ProjectPath); using (var textWriter = File.CreateText (dstPath)) { srcTranslator.Translate (file, configuration.ProjectNamespace, textWriter); } Console.WriteLine ("done: {0}", dstPath); } }
void AddSourceFiles(XDocument projectXml) { var sourceFilesItemGroup = new XElement (xmlNamespace + "ItemGroup"); var objcSourceFiles = new List<string> (); foreach (var sourceFile in currentTarget.SourceFiles) { var sourceElement = new XElement (xmlNamespace + "Compile", new XAttribute ("Include", sourceFile.ConvertPathToSharpName ())); sourceFilesItemGroup.Add (sourceElement); string sourceFilePath = Path.Combine (ProjectPath, Path.GetFileName (sourceFile)); if (!Directory.Exists (Path.GetDirectoryName (sourceFilePath))) Directory.CreateDirectory (Path.GetDirectoryName (sourceFilePath)); sourceFilePath = Path.Combine (Directory.GetParent (xcodeProjPath).FullName, sourceFile); objcSourceFiles.Add (sourceFilePath); } var objcHeaderFiles = new List<string> (); foreach (var headerFile in currentTarget.SourceHeaderFiles) { var sourceFilePath = Path.Combine (Directory.GetParent (xcodeProjPath).FullName, headerFile); objcHeaderFiles.Add (sourceFilePath); } projectXml.Root.Add (sourceFilesItemGroup); var pchFilePath = currentTarget.PCHFilePath != null ? Path.Combine (Directory.GetParent (xcodeProjPath).FullName, currentTarget.PCHFilePath) : null; var translationConfig = new CodeTranslationConfiguration { ProjectNamespace = projectName, ProjectPath = ProjectPath, SourceFilePaths = objcSourceFiles, HeaderFilePaths = objcHeaderFiles, Frameworks = currentTarget.Frameworks, PCHFilePath = pchFilePath }; CodeTranslator.Translate (translationConfig); }