Exemplo n.º 1
0
 public static void AddNonExistingReference(
     CompilerInvocation compilerInvocation,
     string nonExistingReferenceFilePath)
 {
     lock (nonExistingReferencesToCompilerInvocationMap)
     {
         nonExistingReferencesToCompilerInvocationMap.Add(
             nonExistingReferenceFilePath,
             compilerInvocation);
     }
 }
Exemplo n.º 2
0
        private void AssignProjectFilePath(CompilerInvocation invocation)
        {
            HashSet <string> projectFilePaths = null;

            lock (this.assemblyNameToProjectFilePathsMap)
            {
                if (this.assemblyNameToProjectFilePathsMap.TryGetValue(invocation.AssemblyName, out projectFilePaths))
                {
                    invocation.ProjectFilePath = projectFilePaths.First();
                }
            }
        }
Exemplo n.º 3
0
        private static void AddInvocation(string line, Action <CompilerInvocation> collector)
        {
            var invocation = new CompilerInvocation(line);

            collector(invocation);
            lock (cacheOfKnownExistingBinaries)
            {
                foreach (var reference in invocation.ReferencedBinaries)
                {
                    cacheOfKnownExistingBinaries.Add(reference);
                }
            }
        }
Exemplo n.º 4
0
        public static void AddMetadataAsSourceAssemblies(List <CompilerInvocation> invocations)
        {
            var indexedAssemblies = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var invocation in invocations)
            {
                indexedAssemblies.Add(invocation.AssemblyName);
            }

            var notIndexedAssemblies = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            foreach (var binary in invocations.SelectMany(i => i.ReferencedBinaries))
            {
                var assemblyName = Path.GetFileNameWithoutExtension(binary);
                if (!indexedAssemblies.Contains(assemblyName) && ShouldIncludeNotIndexedAssembly(binary, assemblyName))
                {
                    string existing = null;
                    if (!notIndexedAssemblies.TryGetValue(assemblyName, out existing) ||
                        binary.Length < existing.Length ||
                        (binary.Length == existing.Length && binary.CompareTo(existing) > 0))
                    {
                        // make sure we always prefer the .dll that has shortest file path on disk
                        // Not only to disambiguate in a stable fashion, but also it's a good heuristic
                        // Shorter paths seem to be more widely used and are less obscure.
                        notIndexedAssemblies[assemblyName] = binary;
                    }
                }
            }

            foreach (var notIndexedAssembly in notIndexedAssemblies)
            {
                var invocation = new CompilerInvocation()
                {
                    AssemblyName       = notIndexedAssembly.Key,
                    CommandLine        = "-",
                    OutputAssemblyPath = notIndexedAssembly.Value,
                    ProjectFilePath    = "-"
                };
                invocations.Add(invocation);
            }
        }
Exemplo n.º 5
0
        private void AssignOutputAssemblyPath(CompilerInvocation invocation)
        {
            string outputAssemblyFilePath = null;

            lock (this.intermediateAssemblyPathToOutputAssemblyPathMap)
            {
                if (this.intermediateAssemblyPathToOutputAssemblyPathMap.TryGetValue(invocation.IntermediateAssemblyPath, out outputAssemblyFilePath))
                {
                    outputAssemblyFilePath        = Path.GetFullPath(outputAssemblyFilePath);
                    invocation.OutputAssemblyPath = outputAssemblyFilePath;
                    var realAssemblyName = Path.GetFileNameWithoutExtension(outputAssemblyFilePath);
                    if (invocation.AssemblyName != realAssemblyName)
                    {
                        invocation.AssemblyName = realAssemblyName;
                    }
                }
                else
                {
                    invocation.UnknownIntermediatePath = true;
                }
            }
        }
Exemplo n.º 6
0
        public static CompilerInvocation CreateTypeScript(string line)
        {
            var invocation = new CompilerInvocation();

            line = line.Trim();
            int space = line.IndexOf(' ');

            invocation.CompilerPath    = line.Substring(0, space);
            invocation.CommandLine     = line.Substring(space + 1, line.Length - space - 1);
            invocation.TypeScriptFiles = GetFilesFromCommandLine(invocation.CommandLine);
            if (invocation.TypeScriptFiles != null &&
                !invocation.TypeScriptFiles.Any(f => string.Equals(Path.GetFileName(f), "lib.d.ts", StringComparison.OrdinalIgnoreCase)))
            {
                var libdts = Path.Combine(Path.GetDirectoryName(invocation.CompilerPath), "lib.d.ts");
                if (File.Exists(libdts))
                {
                    invocation.TypeScriptFiles.Add(libdts);
                }
            }

            return(invocation);
        }
Exemplo n.º 7
0
        internal void SelectFinalInvocation(CompilerInvocation invocation)
        {
            if (invocation.Language == "TypeScript")
            {
                lock (finalInvocations)
                {
                    finalInvocations.Add(invocation);
                }

                return;
            }

            AssignProjectFilePath(invocation);
            AssignOutputAssemblyPath(invocation);

            if (invocation.UnknownIntermediatePath)
            {
                Log.Exception("Unknown intermediate path: " + invocation.IntermediateAssemblyPath);
            }

            lock (finalInvocations)
            {
                if (finalInvocations.Contains(invocation))
                {
                    if (!ambiguousInvocations.ContainsKey(invocation.AssemblyName))
                    {
                        var existing = finalInvocations.First(i => StringComparer.OrdinalIgnoreCase.Equals(i.AssemblyName, invocation.AssemblyName));
                        ambiguousInvocations.Add(existing.AssemblyName, existing);
                    }

                    ambiguousInvocations.Add(invocation.AssemblyName, invocation);
                }

                finalInvocations.Add(invocation);
            }
        }
Exemplo n.º 8
0
        private void AddTypeScriptInvocation(string line, Action <CompilerInvocation> collector)
        {
            var invocation = CompilerInvocation.CreateTypeScript(line);

            collector(invocation);
        }