public void CanonicalPathCacheSize()
        {
            cache = CanonicalPathCache.Create(Logger, 2, CanonicalPathCache.Symlinks.Preserve);
            Assert.Equal(0, cache.CacheSize);

            // The file "ABC" will fill the cache with parent directory info.
            cache.GetCanonicalPath("ABC");
            Assert.True(cache.CacheSize == 2);

            string cp = cache.GetCanonicalPath("def");

            Assert.Equal(2, cache.CacheSize);
            Assert.Equal(Path.GetFullPath("def"), cp);
        }
示例#2
0
        /// <summary>
        /// Construct tasks for resolving references (possibly in parallel).
        ///
        /// The resolved references will be added (thread-safely) to the supplied
        /// list <paramref name="ret"/>.
        /// </summary>
        static IEnumerable <Action> ResolveReferences(Microsoft.CodeAnalysis.CommandLineArguments args, Analyser analyser, CanonicalPathCache canonicalPathCache, BlockingCollection <MetadataReference> ret)
        {
            var referencePaths = new Lazy <string[]>(() => FixedReferencePaths(args).ToArray());

            return(args.MetadataReferences.Select <CommandLineReference, Action>(clref => () =>
            {
                if (Path.IsPathRooted(clref.Reference))
                {
                    if (File.Exists(clref.Reference))
                    {
                        var reference = MakeReference(clref, canonicalPathCache.GetCanonicalPath(clref.Reference));
                        ret.Add(reference);
                    }
                    else
                    {
                        lock (analyser)
                        {
                            analyser.Logger.Log(Severity.Error, "  Reference '{0}' does not exist", clref.Reference);
                            ++analyser.CompilationErrors;
                        }
                    }
                }
                else
                {
                    bool referenceFound = false;
                    {
                        foreach (var composed in referencePaths.Value.
                                 Select(path => Path.Combine(path, clref.Reference)).
                                 Where(path => File.Exists(path)).
                                 Select(path => canonicalPathCache.GetCanonicalPath(path)))
                        {
                            referenceFound = true;
                            var reference = MakeReference(clref, composed);
                            ret.Add(reference);
                            break;
                        }
                        if (!referenceFound)
                        {
                            lock (analyser)
                            {
                                analyser.Logger.Log(Severity.Error, "  Unable to resolve reference '{0}'", clref.Reference);
                                ++analyser.CompilationErrors;
                            }
                        }
                    }
                }
            }));
        }
        public void CanonicalPathUNCRoot()
        {
            CanonicalPathCache cache2 = CanonicalPathCache.Create(Logger, 1000, CanonicalPathCache.Symlinks.Preserve);

            if (Win32.IsWindows())
            {
                var windows = cache.GetCanonicalPath(@"\WINDOWS").Replace(":", "$");
                Assert.Equal($@"\\LOCALHOST\{windows}\bar", cache2.GetCanonicalPath($@"\\localhost\{windows}\bar"));
            }
        }
        public CanonicalPathCacheTest()
        {
            File.Create("abc").Close();
            cache = CanonicalPathCache.Create(Logger, 1000, CanonicalPathCache.Symlinks.Follow);

            // Change directories to a directory that is in canonical form.
            Directory.SetCurrentDirectory(cache.GetCanonicalPath(Path.GetTempPath()));

            root = Win32.IsWindows() ? @"X:\" : "/";
        }
示例#5
0
 private static ExitCode AnalyseTracing(
     TracingAnalyser analyser,
     CSharpCommandLineArguments compilerArguments,
     Options options,
     CanonicalPathCache canonicalPathCache,
     Stopwatch stopwatch)
 {
     return(Analyse(stopwatch, analyser, options,
                    references => ResolveReferences(compilerArguments, analyser, canonicalPathCache, references),
                    (analyser, syntaxTrees) =>
     {
         return ReadSyntaxTrees(
             compilerArguments.SourceFiles.Select(src => canonicalPathCache.GetCanonicalPath(src.Path)),
             analyser,
             compilerArguments.ParseOptions,
             compilerArguments.Encoding,
             syntaxTrees);
     },
                    (syntaxTrees, references) =>
     {
         // csc.exe (CSharpCompiler.cs) also provides CompilationOptions
         // .WithMetadataReferenceResolver(),
         // .WithXmlReferenceResolver() and
         // .WithSourceReferenceResolver().
         // These would be needed if we hadn't explicitly provided the source/references
         // already.
         return CSharpCompilation.Create(
             compilerArguments.CompilationName,
             syntaxTrees,
             references,
             compilerArguments.CompilationOptions
             .WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default)
             .WithStrongNameProvider(new DesktopStrongNameProvider(compilerArguments.KeyFileSearchPaths))
             .WithMetadataImportOptions(MetadataImportOptions.All)
             );
     },
                    (compilation, options) => analyser.EndInitialize(compilerArguments, options, compilation),
                    () => analyser.AnalyseCompilation(),
                    performance => analyser.LogPerformance(performance),
                    () => { }));
 }