Esempio n. 1
0
        void PerformExclusions(IndexerState state)
        {
            #region - Apply SourceRoots
            if (SourceRoots.Count > 0)
            {
                List <string> rootList = new List <string>();

                foreach (string root in SourceRoots)
                {
                    string nRoot = state.NormalizePath(root);

                    if (!nRoot.EndsWith("\\"))
                    {
                        nRoot += "\\";
                    }

                    rootList.Add(nRoot);
                }

                string[] roots = rootList.ToArray();
                Array.Sort <string>(roots, StringComparer.InvariantCultureIgnoreCase);

                foreach (SourceFile sf in state.SourceFiles.Values)
                {
                    string fileName = sf.FullName;

                    int n = Array.BinarySearch <string>(roots, fileName, StringComparer.InvariantCultureIgnoreCase);

                    if (n >= 0)
                    {
                        continue; // Exact match found
                    }
                    n = ~n;

                    if ((n > 0) && (n <= roots.Length))
                    {
                        if (fileName.StartsWith(roots[n - 1], StringComparison.InvariantCultureIgnoreCase))
                        {
                            continue; // Root found
                        }
                        sf.NoSourceAvailable = true;
                        continue;
                    }
                    else
                    {
                        sf.NoSourceAvailable = true;
                    }
                }
            }
            #endregion - Apply SourceRoots
            #region - Apply ExcludeSourceRoots
            if (ExcludeSourceRoots.Count > 0)
            {
                List <string> rootList = new List <string>();

                foreach (string root in ExcludeSourceRoots)
                {
                    string nRoot = state.NormalizePath(root);

                    if (!nRoot.EndsWith(Path.DirectorySeparatorChar.ToString()))
                    {
                        nRoot += Path.DirectorySeparatorChar;
                    }

                    rootList.Add(nRoot);
                }

                string[] roots = rootList.ToArray();
                Array.Sort <string>(roots, StringComparer.InvariantCultureIgnoreCase);

                foreach (SourceFile sf in state.SourceFiles.Values)
                {
                    string fileName = sf.FullName;

                    int n = Array.BinarySearch <string>(roots, fileName, StringComparer.InvariantCultureIgnoreCase);

                    if (n >= 0)
                    {
                        continue; // Exact match found
                    }
                    n = ~n;

                    if ((n > 0) && (n <= roots.Length))
                    {
                        if (fileName.StartsWith(roots[n - 1], StringComparison.InvariantCultureIgnoreCase))
                        {
                            sf.NoSourceAvailable = true;
                        }
                    }
                }
            }
            #endregion
        }
Esempio n. 2
0
        public static void ReadSourceFilesFromPdbs(
            IndexerState state, string srcToolPath, bool reIndexPreviouslyIndexedSymbols)
        {
            List<SymbolFile> pdbsToRemove = null;
            foreach (var pdb in state.SymbolFiles.Values)
            {
                var psi = new ProcessStartInfo(srcToolPath)
                {
                    WorkingDirectory = pdb.File.DirectoryName,
                    UseShellExecute = false,
                    RedirectStandardError = true,
                    RedirectStandardOutput = true
                };

                string output;
                string errors;

                if (!reIndexPreviouslyIndexedSymbols)
                {
                    psi.Arguments = string.Format("-c \"{0}\"", pdb.FullName);

                    using (var p = Process.Start(psi))
                    {
                        output = p.StandardOutput.ReadToEnd();
                        errors = p.StandardError.ReadToEnd();

                        p.WaitForExit();
                    }

                    if (output.Contains("source files are indexed") ||
                        errors.Contains("source files are indexed") ||
                        output.Contains("source file is indexed") ||
                        errors.Contains("source file is indexed"))
                    {
                        // No need to change annotation; it is already indexed
                        if (pdbsToRemove == null)
                            pdbsToRemove = new List<SymbolFile>();

                        pdbsToRemove.Add(pdb);
                        continue;
                    }
                }

                psi.Arguments = string.Format("-r \"{0}\"", pdb.FullName);

                using (var p = Process.Start(psi))
                {
                    output = p.StandardOutput.ReadToEnd();
                    errors = p.StandardError.ReadToEnd();

                    p.WaitForExit();
                }

                if (!string.IsNullOrEmpty(errors))
                    throw new SourceIndexToolException("SRCTOOL", errors.Trim());

                var foundOne = false;
                foreach (var item in output.Split('\r', '\n'))
                {
                    var fileName = item.Trim();

                    if (string.IsNullOrEmpty(fileName))
                        continue; // We split on \r and \n

                    if ((fileName.IndexOf('*') >= 0) || // C++ Compiler internal file
                        ((fileName.Length > 2) && (fileName.IndexOf(':', 2) >= 0)))
                    {
                        // Some compiler internal filenames of C++ start with a *
                        // and/or have a :123 suffix

                        continue; // Skip never existing files
                    }

                    fileName = state.NormalizePath(fileName);

                    SourceFile file;

                    if (!state.SourceFiles.TryGetValue(fileName, out file))
                    {
                        file = new SourceFile(fileName);
                        state.SourceFiles.Add(fileName, file);
                    }

                    pdb.AddSourceFile(file);
                    file.AddContainer(pdb);
                    foundOne = true;
                }

                if (foundOne)
                    continue;

                if (pdbsToRemove == null)
                    pdbsToRemove = new List<SymbolFile>();

                pdbsToRemove.Add(pdb);
            }

            if (pdbsToRemove == null)
                return;

            foreach (var s in pdbsToRemove)
                state.SymbolFiles.Remove(s.FullName);
        }
Esempio n. 3
0
        public static void ReadSourceFilesFromPdbs(
            IndexerState state, string srcToolPath, bool reIndexPreviouslyIndexedSymbols)
        {
            List <SymbolFile> pdbsToRemove = null;

            foreach (var pdb in state.SymbolFiles.Values)
            {
                var psi = new ProcessStartInfo(srcToolPath)
                {
                    WorkingDirectory       = pdb.File.DirectoryName,
                    UseShellExecute        = false,
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true
                };

                string output;
                string errors;

                if (!reIndexPreviouslyIndexedSymbols)
                {
                    psi.Arguments = string.Format("-c \"{0}\"", pdb.FullName);

                    using (var p = Process.Start(psi))
                    {
                        output = p.StandardOutput.ReadToEnd();
                        errors = p.StandardError.ReadToEnd();

                        p.WaitForExit();
                    }

                    if (output.Contains("source files are indexed") ||
                        errors.Contains("source files are indexed") ||
                        output.Contains("source file is indexed") ||
                        errors.Contains("source file is indexed"))
                    {
                        // No need to change annotation; it is already indexed
                        if (pdbsToRemove == null)
                        {
                            pdbsToRemove = new List <SymbolFile>();
                        }

                        pdbsToRemove.Add(pdb);
                        continue;
                    }
                }

                psi.Arguments = string.Format("-r \"{0}\"", pdb.FullName);

                using (var p = Process.Start(psi))
                {
                    output = p.StandardOutput.ReadToEnd();
                    errors = p.StandardError.ReadToEnd();

                    p.WaitForExit();
                }

                if (!string.IsNullOrEmpty(errors))
                {
                    throw new SourceIndexToolException("SRCTOOL", errors.Trim());
                }

                var foundOne = false;
                foreach (var item in output.Split('\r', '\n'))
                {
                    var fileName = item.Trim();

                    if (string.IsNullOrEmpty(fileName))
                    {
                        continue;                         // We split on \r and \n
                    }
                    if ((fileName.IndexOf('*') >= 0) ||   // C++ Compiler internal file
                        ((fileName.Length > 2) && (fileName.IndexOf(':', 2) >= 0)))
                    {
                        // Some compiler internal filenames of C++ start with a *
                        // and/or have a :123 suffix

                        continue;                         // Skip never existing files
                    }

                    fileName = state.NormalizePath(fileName);

                    SourceFile file;

                    if (!state.SourceFiles.TryGetValue(fileName, out file))
                    {
                        file = new SourceFile(fileName);
                        state.SourceFiles.Add(fileName, file);
                    }

                    pdb.AddSourceFile(file);
                    file.AddContainer(pdb);
                    foundOne = true;
                }

                if (foundOne)
                {
                    continue;
                }

                if (pdbsToRemove == null)
                {
                    pdbsToRemove = new List <SymbolFile>();
                }

                pdbsToRemove.Add(pdb);
            }

            if (pdbsToRemove == null)
            {
                return;
            }

            foreach (var s in pdbsToRemove)
            {
                state.SymbolFiles.Remove(s.FullName);
            }
        }