public XamarinPreprocessorVisitor(Preprocessor preprocessor)
     : base(preprocessor)
 {
 }
示例#2
0
            public PreprocessorVisitor(Preprocessor preprocessor)
            {
                if (preprocessor == null)
                    throw new ArgumentNullException (nameof (preprocessor));

                this.preprocessor = preprocessor;
            }
示例#3
0
        static int Run()
        {
            var tempPrefix = settings.Profile.Name;
            if (String.IsNullOrEmpty (tempPrefix))
                tempPrefix = Guid.NewGuid ().ToString ();
            tempPrefix = "~.pmcs-" + tempPrefix + ".";

            var ppSources = new List<string> ();
            string ppSourcesFile = null;
            if (settings.AssemblyOutFile != null)
                ppSourcesFile = Path.Combine (
                    Path.GetDirectoryName (settings.AssemblyOutFile),
                    "." + Path.GetFileName (settings.AssemblyOutFile) + tempPrefix + "sources"
                );

            var preprocessor = new Preprocessor {
                Profile = settings.Profile
            };

            var startTime = DateTime.Now;
            int preprocessCount = 0;

            Action<string> preprocessFile = path => {
                var fileName = Path.GetFileName (path);
                if (settings.Profile.IgnorePaths.Contains (fileName)) {
                    if (settings.Verbose) {
                        Console.Error.WriteLine ("pmcs: skipping {0}", fileName);
                    }
                    lock (ppSources)
                        ppSources.Add (path);
                    return;
                }

                var outPath = Path.Combine (Path.GetDirectoryName (path), tempPrefix + fileName);
                var writer = settings.PreprocessToStdout
                    ? Console.Out
                    : new StreamWriter (outPath) as TextWriter;

                using (var reader = new StreamReader (path)) {
                    if (!settings.OmitLineDirective)
                        writer.WriteLine ("#line 1 \"" + Path.GetFullPath (path) + "\"");
                    preprocessor.Preprocess (path, reader, writer);
                }

                if (writer != Console.Out) {
                    writer.Dispose ();
                }

                if (!settings.PreprocessToStdout) {
                    if (settings.PreprocessInPlace) {
                        lock (ppSources)
                            ppSources.Add (path);
                        File.Delete (path);
                        File.Move (outPath, path);
                    } else {
                        lock (ppSources)
                            ppSources.Add (outPath);
                    }
                }

                preprocessCount++;
            };

            if (settings.PreprocessToStdout)
                settings.CompilerPaths.ForEach (preprocessFile);
            else
                Parallel.ForEach (settings.CompilerPaths, preprocessFile);

            if (!settings.PreprocessToStdout && ppSourcesFile != null) {
                using (var sourcesWriter = new StreamWriter (ppSourcesFile)) {
                    foreach (var path in ppSources) {
                        sourcesWriter.WriteLine (path);
                    }
                }
            }

            if (settings.Verbose || settings.Time) {
                Console.Error.WriteLine ("{0} / {1} sources preprocessed in {2}s",
                    preprocessCount, settings.CompilerPaths.Count, (DateTime.Now - startTime).TotalSeconds);
            }

            if (ppSourcesFile != null)
                settings.Profile.CompilerOptions.Add ("@" + ppSourcesFile);

            var exit = 0;

            if (!settings.SkipCompilation && !settings.PreprocessToStdout) {
                var proc = Process.Start (new ProcessStartInfo {
                    FileName = settings.Profile.CompilerExecutable,
                    Arguments = String.Join (" ", settings.Profile.CompilerOptions),
                    WorkingDirectory = Environment.CurrentDirectory,
                    UseShellExecute = false
                });

                proc.WaitForExit ();
                exit = proc.ExitCode;
            }

            var mdbFile = settings.AssemblyOutFile + ".mdb";
            if (!settings.SkipMdbRebase && File.Exists (mdbFile))
                MdbRebase (mdbFile, tempPrefix);

            if (settings.KeepPreprocessedFiles || settings.PreprocessToStdout)
                return exit;

            if (ppSourcesFile != null)
                File.Delete (ppSourcesFile);

            foreach (var path in ppSources) {
                if (Path.GetFileName (path).StartsWith (tempPrefix, StringComparison.Ordinal)) {
                    File.Delete (path);
                }
            }

            return exit;
        }
 public XamarinPreprocessorVisitor(Preprocessor preprocessor) : base(preprocessor)
 {
 }
示例#5
0
        static int Run()
        {
            var tempPrefix = settings.Profile.Name;

            if (String.IsNullOrEmpty(tempPrefix))
            {
                tempPrefix = Guid.NewGuid().ToString();
            }
            tempPrefix = "~.pmcs-" + tempPrefix + ".";

            var    ppSources     = new List <string> ();
            string ppSourcesFile = null;

            if (settings.AssemblyOutFile != null)
            {
                ppSourcesFile = Path.Combine(
                    Path.GetDirectoryName(settings.AssemblyOutFile),
                    "." + Path.GetFileName(settings.AssemblyOutFile) + tempPrefix + "sources"
                    );
            }

            var preprocessor = new Preprocessor {
                Profile = settings.Profile
            };

            var startTime       = DateTime.Now;
            int preprocessCount = 0;

            Action <string> preprocessFile = path => {
                var fileName = Path.GetFileName(path);
                if (settings.Profile.IgnorePaths.Contains(fileName))
                {
                    if (settings.Verbose)
                    {
                        Console.Error.WriteLine("pmcs: skipping {0}", fileName);
                    }
                    lock (ppSources)
                        ppSources.Add(path);
                    return;
                }

                var outPath = Path.Combine(Path.GetDirectoryName(path), tempPrefix + fileName);
                var writer  = settings.PreprocessToStdout
                                        ? Console.Out
                                        : new StreamWriter(outPath) as TextWriter;

                using (var reader = new StreamReader(path)) {
                    if (!settings.OmitLineDirective)
                    {
                        writer.WriteLine("#line 1 \"" + Path.GetFullPath(path) + "\"");
                    }
                    preprocessor.Preprocess(path, reader, writer);
                }

                if (writer != Console.Out)
                {
                    writer.Dispose();
                }

                if (!settings.PreprocessToStdout)
                {
                    if (settings.PreprocessInPlace)
                    {
                        lock (ppSources)
                            ppSources.Add(path);
                        File.Delete(path);
                        File.Move(outPath, path);
                    }
                    else
                    {
                        lock (ppSources)
                            ppSources.Add(outPath);
                    }
                }

                preprocessCount++;
            };

            if (settings.PreprocessToStdout)
            {
                settings.CompilerPaths.ForEach(preprocessFile);
            }
            else
            {
                Parallel.ForEach(settings.CompilerPaths, preprocessFile);
            }

            if (!settings.PreprocessToStdout && ppSourcesFile != null)
            {
                using (var sourcesWriter = new StreamWriter(ppSourcesFile)) {
                    foreach (var path in ppSources)
                    {
                        sourcesWriter.WriteLine(path);
                    }
                }
            }

            if (settings.Verbose || settings.Time)
            {
                Console.Error.WriteLine("{0} / {1} sources preprocessed in {2}s",
                                        preprocessCount, settings.CompilerPaths.Count, (DateTime.Now - startTime).TotalSeconds);
            }

            if (ppSourcesFile != null)
            {
                settings.Profile.CompilerOptions.Add("@" + ppSourcesFile);
            }

            var exit = 0;

            if (!settings.SkipCompilation && !settings.PreprocessToStdout)
            {
                var proc = Process.Start(new ProcessStartInfo {
                    FileName         = settings.Profile.CompilerExecutable,
                    Arguments        = String.Join(" ", settings.Profile.CompilerOptions),
                    WorkingDirectory = Environment.CurrentDirectory,
                    UseShellExecute  = false
                });

                proc.WaitForExit();
                exit = proc.ExitCode;
            }

            var mdbFile = settings.AssemblyOutFile + ".mdb";

            if (!settings.SkipMdbRebase && File.Exists(mdbFile))
            {
                MdbRebase(mdbFile, tempPrefix);
            }

            if (settings.KeepPreprocessedFiles || settings.PreprocessToStdout)
            {
                return(exit);
            }

            if (ppSourcesFile != null)
            {
                File.Delete(ppSourcesFile);
            }

            foreach (var path in ppSources)
            {
                if (Path.GetFileName(path).StartsWith(tempPrefix, StringComparison.Ordinal))
                {
                    File.Delete(path);
                }
            }

            return(exit);
        }