Ejemplo n.º 1
0
            /* Microsoft.CodeAnalysis.Diagnostic is coupled to the source tree and other CodeDOM objects
             * so need to use an adapter.
             */

            public static BuildResult.Diagnostic From(Microsoft.CodeAnalysis.Diagnostic data)
            {
                return(new BuildResult.Diagnostic
                {
                    IsWarningAsError = data.IsWarningAsError,
                    Severity = data.Severity,
                    Location_IsInSource = data.Location.IsInSource,
                    Location_StartLinePosition_Line = data.Location.GetLineSpan().StartLinePosition.Line,
                    Location_StartLinePosition_Character = data.Location.GetLineSpan().StartLinePosition.Character,
                    Location_FilePath = data.Location.SourceTree.FilePath,
                    Id = data.Id,
                    Message = data.GetMessage()
                });
            }
Ejemplo n.º 2
0
 public Diagnostic(Context cx, Microsoft.CodeAnalysis.Diagnostic diag) : base(cx)
 {
     diagnostic = diag;
     TryPopulate();
 }
        private IEnumerable <CommandLineSourceFile> ExpandFileNamePattern(string path, string baseDirectory, SearchOption searchOption, IList <Diagnostic> errors)
        {
            string directory = PathUtilities.GetDirectoryName(path);
            string pattern   = PathUtilities.GetFileName(path);

            var resolvedDirectoryPath = (directory.Length == 0) ? baseDirectory : FileUtilities.ResolveRelativePath(directory, baseDirectory);

            IEnumerator <string> enumerator = null;

            try
            {
                bool yielded = false;

                // NOTE: Directory.EnumerateFiles(...) surprisingly treats pattern "." the
                //       same way as "*"; as we don't expect anything to be found by this
                //       pattern, let's just not search in this case
                pattern = pattern.Trim(SearchPatterTrimChars);
                bool singleDotPattern = string.Equals(pattern, ".", StringComparison.Ordinal);

                if (!singleDotPattern)
                {
                    while (true)
                    {
                        string resolvedPath = null;
                        try
                        {
                            if (enumerator == null)
                            {
                                enumerator = EnumerateFiles(resolvedDirectoryPath, pattern, searchOption).GetEnumerator();
                            }

                            if (!enumerator.MoveNext())
                            {
                                break;
                            }

                            resolvedPath = enumerator.Current;
                        }
                        catch
                        {
                            resolvedPath = null;
                        }

                        if (resolvedPath != null)
                        {
                            // just in case EnumerateFiles returned a relative path
                            resolvedPath = FileUtilities.ResolveRelativePath(resolvedPath, baseDirectory);
                        }

                        if (resolvedPath == null)
                        {
                            errors.Add(Diagnostic.Create(MessageProvider, (int)MessageProvider.FTL_InputFileNameTooLong, path));
                            break;
                        }

                        yielded = true;
                        yield return(ToCommandLineSourceFile(resolvedPath));
                    }
                }

                // the pattern didn't match any files:
                if (!yielded)
                {
                    if (searchOption == SearchOption.AllDirectories)
                    {
                        // handling /recurse
                        GenerateErrorForNoFilesFoundInRecurse(path, errors);
                    }
                    else
                    {
                        // handling wildcard in file spec
                        errors.Add(Diagnostic.Create(MessageProvider, (int)MessageProvider.ERR_FileNotFound, path));
                    }
                }
            }
            finally
            {
                if (enumerator != null)
                {
                    enumerator.Dispose();
                }
            }
        }
Ejemplo n.º 4
0
 public Diagnostic(Context cx, Microsoft.CodeAnalysis.Diagnostic diag) : base(cx)
 {
     cx.Emit(Tuples.diagnostics(this, (int)diag.Severity, diag.Id, diag.Descriptor.Title.ToString(),
                                diag.GetMessage(), Extraction.Entities.Location.Create(cx, diag.Location)));
 }
        internal void FlattenArgs(
            IEnumerable <string> rawArguments,
            IList <Diagnostic> diagnostics,
            List <string> processedArgs,
            List <string> scriptArgs,
            string baseDirectory,
            List <string> responsePaths = null)
        {
            bool parsingScriptArgs = false;

            Stack <string> args = new Stack <string>(rawArguments.Reverse());

            while (args.Count > 0)
            {
                //EDMAURER trim off whitespace. Otherwise behavioral differences arise
                //when the strings which represent args are constructed by cmd or users.
                //cmd won't produce args with whitespace at the end.
                string arg = args.Pop().TrimEnd();

                if (parsingScriptArgs)
                {
                    scriptArgs.Add(arg);
                    continue;
                }

                if (arg.StartsWith("@", StringComparison.Ordinal))
                {
                    // response file:
                    string path         = RemoveAllQuotes(arg.Substring(1)).TrimEnd();
                    string resolvedPath = FileUtilities.ResolveRelativePath(path, baseDirectory);
                    if (resolvedPath != null)
                    {
                        foreach (string newArg in ParseResponseFile(resolvedPath, diagnostics).Reverse())
                        {
                            // Ignores /noconfig option specified in a response file
                            if (!string.Equals(newArg, "/noconfig", StringComparison.OrdinalIgnoreCase) && !string.Equals(newArg, "-noconfig", StringComparison.OrdinalIgnoreCase))
                            {
                                args.Push(newArg);
                            }
                            else
                            {
                                diagnostics.Add(Diagnostic.Create(messageProvider, messageProvider.WRN_NoConfigNotOnCommandLine));
                            }
                        }

                        if (responsePaths != null)
                        {
                            responsePaths.Add(FileUtilities.NormalizeAbsolutePath(PathUtilities.GetDirectoryName(resolvedPath)));
                        }
                    }
                    else
                    {
                        diagnostics.Add(Diagnostic.Create(messageProvider, messageProvider.FTL_InputFileNameTooLong, path));
                    }
                }
                else if (arg == "--" && scriptArgs != null)
                {
                    parsingScriptArgs = true;
                }
                else
                {
                    processedArgs.Add(arg);
                }
            }
        }