Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
bcdcafc2
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
bcdcafc2
编写于
4月 25, 2017
作者:
T
Tom Meschter
提交者:
GitHub
4月 25, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #18636 from tmeschter/GetRuleSetPathFromOptions
Read rule set path from options
上级
55a46b9b
bbe9821d
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
41 addition
and
21 deletion
+41
-21
src/Compilers/CSharp/Portable/CommandLine/CSharpCommandLineParser.cs
...rs/CSharp/Portable/CommandLine/CSharpCommandLineParser.cs
+4
-1
src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
+7
-0
src/Compilers/Core/Portable/CommandLine/CommonCommandLineArguments.cs
...s/Core/Portable/CommandLine/CommonCommandLineArguments.cs
+7
-0
src/Compilers/Core/Portable/CommandLine/CommonCommandLineParser.cs
...lers/Core/Portable/CommandLine/CommonCommandLineParser.cs
+2
-2
src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
+1
-0
src/Compilers/Core/Portable/RuleSet/RuleSet.cs
src/Compilers/Core/Portable/RuleSet/RuleSet.cs
+6
-17
src/Compilers/VisualBasic/Portable/CommandLine/VisualBasicCommandLineParser.vb
...asic/Portable/CommandLine/VisualBasicCommandLineParser.vb
+4
-1
src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb
...ompilers/VisualBasic/Test/CommandLine/CommandLineTests.vb
+7
-0
src/VisualStudio/Core/Impl/ProjectSystem/CPS/CPSProject_IWorkspaceProjectContext.cs
.../ProjectSystem/CPS/CPSProject_IWorkspaceProjectContext.cs
+3
-0
未找到文件。
src/Compilers/CSharp/Portable/CommandLine/CSharpCommandLineParser.cs
浏览文件 @
bcdcafc2
...
...
@@ -121,6 +121,7 @@ public new CSharpCommandLineArguments Parse(IEnumerable<string> args, string bas
bool
interactiveMode
=
false
;
bool
publicSign
=
false
;
string
sourceLink
=
null
;
string
ruleSetPath
=
null
;
// Process ruleset files first so that diagnostic severity settings specified on the command line via
// /nowarn and /warnaserror can override diagnostic severity settings specified in the ruleset file.
...
...
@@ -139,7 +140,8 @@ public new CSharpCommandLineArguments Parse(IEnumerable<string> args, string bas
}
else
{
generalDiagnosticOption
=
GetDiagnosticOptionsFromRulesetFile
(
diagnosticOptions
,
diagnostics
,
unquoted
,
baseDirectory
);
ruleSetPath
=
ParseGenericPathToFile
(
unquoted
,
diagnostics
,
baseDirectory
);
generalDiagnosticOption
=
GetDiagnosticOptionsFromRulesetFile
(
ruleSetPath
,
out
diagnosticOptions
,
diagnostics
);
}
}
}
...
...
@@ -1291,6 +1293,7 @@ public new CSharpCommandLineArguments Parse(IEnumerable<string> args, string bas
PdbPath
=
pdbPath
,
EmitPdb
=
emitPdb
,
SourceLink
=
sourceLink
,
RuleSetPath
=
ruleSetPath
,
OutputDirectory
=
outputDirectory
,
DocumentationPath
=
documentationPath
,
ErrorLogPath
=
errorLogPath
,
...
...
src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
浏览文件 @
bcdcafc2
...
...
@@ -2178,6 +2178,7 @@ public void RuleSetSwitchPositive()
var
file
=
CreateRuleSetFile
(
source
);
var
parsedArgs
=
DefaultParse
(
new
string
[]
{
@"/ruleset:"
+
file
.
Path
,
"a.cs"
},
_baseDirectory
);
parsedArgs
.
Errors
.
Verify
();
Assert
.
Equal
(
expected
:
file
.
Path
,
actual
:
parsedArgs
.
RuleSetPath
);
Assert
.
True
(
parsedArgs
.
CompilationOptions
.
SpecificDiagnosticOptions
.
ContainsKey
(
"CA1012"
));
Assert
.
True
(
parsedArgs
.
CompilationOptions
.
SpecificDiagnosticOptions
[
"CA1012"
]
==
ReportDiagnostic
.
Error
);
Assert
.
True
(
parsedArgs
.
CompilationOptions
.
SpecificDiagnosticOptions
.
ContainsKey
(
"CA1013"
));
...
...
@@ -2203,6 +2204,7 @@ public void RuleSetSwitchQuoted()
var
file
=
CreateRuleSetFile
(
source
);
var
parsedArgs
=
DefaultParse
(
new
string
[]
{
@"/ruleset:"
+
"\""
+
file
.
Path
+
"\""
,
"a.cs"
},
_baseDirectory
);
parsedArgs
.
Errors
.
Verify
();
Assert
.
Equal
(
expected
:
file
.
Path
,
actual
:
parsedArgs
.
RuleSetPath
);
}
[
Fact
]
...
...
@@ -2211,23 +2213,28 @@ public void RuleSetSwitchParseErrors()
var
parsedArgs
=
DefaultParse
(
new
string
[]
{
@"/ruleset"
,
"a.cs"
},
_baseDirectory
);
parsedArgs
.
Errors
.
Verify
(
Diagnostic
(
ErrorCode
.
ERR_SwitchNeedsString
).
WithArguments
(
"<text>"
,
"ruleset"
));
Assert
.
Null
(
parsedArgs
.
RuleSetPath
);
parsedArgs
=
DefaultParse
(
new
string
[]
{
@"/ruleset:"
,
"a.cs"
},
_baseDirectory
);
parsedArgs
.
Errors
.
Verify
(
Diagnostic
(
ErrorCode
.
ERR_SwitchNeedsString
).
WithArguments
(
"<text>"
,
"ruleset"
));
Assert
.
Null
(
parsedArgs
.
RuleSetPath
);
parsedArgs
=
DefaultParse
(
new
string
[]
{
@"/ruleset:blah"
,
"a.cs"
},
_baseDirectory
);
parsedArgs
.
Errors
.
Verify
(
Diagnostic
(
ErrorCode
.
ERR_CantReadRulesetFile
).
WithArguments
(
Path
.
Combine
(
TempRoot
.
Root
,
"blah"
),
"File not found."
));
Assert
.
Equal
(
expected
:
Path
.
Combine
(
TempRoot
.
Root
,
"blah"
),
actual
:
parsedArgs
.
RuleSetPath
);
parsedArgs
=
DefaultParse
(
new
string
[]
{
@"/ruleset:blah;blah.ruleset"
,
"a.cs"
},
_baseDirectory
);
parsedArgs
.
Errors
.
Verify
(
Diagnostic
(
ErrorCode
.
ERR_CantReadRulesetFile
).
WithArguments
(
Path
.
Combine
(
TempRoot
.
Root
,
"blah;blah.ruleset"
),
"File not found."
));
Assert
.
Equal
(
expected
:
Path
.
Combine
(
TempRoot
.
Root
,
"blah;blah.ruleset"
),
actual
:
parsedArgs
.
RuleSetPath
);
var
file
=
CreateRuleSetFile
(
"Random text"
);
parsedArgs
=
DefaultParse
(
new
string
[]
{
@"/ruleset:"
+
file
.
Path
,
"a.cs"
},
_baseDirectory
);
//parsedArgs.Errors.Verify(
// Diagnostic(ErrorCode.ERR_CantReadRulesetFile).WithArguments(file.Path, "Data at the root level is invalid. Line 1, position 1."));
Assert
.
Equal
(
expected
:
file
.
Path
,
actual
:
parsedArgs
.
RuleSetPath
);
var
err
=
parsedArgs
.
Errors
.
Single
();
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_CantReadRulesetFile
,
err
.
Code
);
...
...
src/Compilers/Core/Portable/CommandLine/CommonCommandLineArguments.cs
浏览文件 @
bcdcafc2
...
...
@@ -96,6 +96,11 @@ public abstract class CommandLineArguments
/// </summary>
public
string
SourceLink
{
get
;
internal
set
;
}
/// <summary>
/// Absolute path of the .ruleset file or null if not specified.
/// </summary>
public
string
RuleSetPath
{
get
;
internal
set
;
}
/// <summary>
/// True to emit PDB information (to a standalone PDB file or embedded into the PE file).
/// </summary>
...
...
@@ -121,6 +126,8 @@ public abstract class CommandLineArguments
/// </summary>
public
string
AppConfigPath
{
get
;
internal
set
;
}
/// <summary>
/// Errors while parsing the command line arguments.
/// </summary>
...
...
src/Compilers/Core/Portable/CommandLine/CommonCommandLineParser.cs
浏览文件 @
bcdcafc2
...
...
@@ -980,9 +980,9 @@ internal static SourceHashAlgorithm TryParseHashAlgorithmName(string arg)
internal
abstract
void
GenerateErrorForNoFilesFoundInRecurse
(
string
path
,
IList
<
Diagnostic
>
errors
);
internal
ReportDiagnostic
GetDiagnosticOptionsFromRulesetFile
(
Dictionary
<
string
,
ReportDiagnostic
>
diagnosticOptions
,
IList
<
Diagnostic
>
diagnostics
,
string
path
,
string
baseDirectory
)
internal
ReportDiagnostic
GetDiagnosticOptionsFromRulesetFile
(
string
fullPath
,
out
Dictionary
<
string
,
ReportDiagnostic
>
diagnosticOptions
,
IList
<
Diagnostic
>
diagnostics
)
{
return
RuleSet
.
GetDiagnosticOptionsFromRulesetFile
(
diagnosticOptions
,
path
,
baseDirectory
,
diagnostics
,
_messageProvider
);
return
RuleSet
.
GetDiagnosticOptionsFromRulesetFile
(
fullPath
,
out
diagnosticOptions
,
diagnostics
,
_messageProvider
);
}
/// <summary>
...
...
src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
浏览文件 @
bcdcafc2
Microsoft.CodeAnalysis.CommandLineArguments.RuleSetPath.get -> string
Microsoft.CodeAnalysis.CommandLineReference.CommandLineReference(string reference, Microsoft.CodeAnalysis.MetadataReferenceProperties properties) -> void
Microsoft.CodeAnalysis.CommandLineSourceFile.CommandLineSourceFile(string path, bool isScript) -> void
Microsoft.CodeAnalysis.Diagnostics.AnalysisContext.RegisterOperationAction(System.Action<Microsoft.CodeAnalysis.Diagnostics.OperationAnalysisContext> action, params Microsoft.CodeAnalysis.OperationKind[] operationKinds) -> void
...
...
src/Compilers/Core/Portable/RuleSet/RuleSet.cs
浏览文件 @
bcdcafc2
...
...
@@ -284,29 +284,18 @@ public static ImmutableArray<string> GetEffectiveIncludesFromFile(string filePat
/// </summary>
public
static
ReportDiagnostic
GetDiagnosticOptionsFromRulesetFile
(
string
rulesetFileFullPath
,
out
Dictionary
<
string
,
ReportDiagnostic
>
specificDiagnosticOptions
)
{
specificDiagnosticOptions
=
new
Dictionary
<
string
,
ReportDiagnostic
>();
if
(
rulesetFileFullPath
==
null
)
{
return
ReportDiagnostic
.
Default
;
}
return
GetDiagnosticOptionsFromRulesetFile
(
specificDiagnosticOptions
,
rulesetFileFullPath
,
null
,
null
);
return
GetDiagnosticOptionsFromRulesetFile
(
rulesetFileFullPath
,
out
specificDiagnosticOptions
,
null
,
null
);
}
internal
static
ReportDiagnostic
GetDiagnosticOptionsFromRulesetFile
(
Dictionary
<
string
,
ReportDiagnostic
>
diagnosticOptions
,
string
path
,
string
baseDirectory
,
IList
<
Diagnostic
>
diagnosticsOpt
,
CommonMessageProvider
messageProviderOpt
)
internal
static
ReportDiagnostic
GetDiagnosticOptionsFromRulesetFile
(
string
rulesetFileFullPath
,
out
Dictionary
<
string
,
ReportDiagnostic
>
diagnosticOptions
,
IList
<
Diagnostic
>
diagnosticsOpt
,
CommonMessageProvider
messageProviderOpt
)
{
var
resolvedPath
=
FileUtilities
.
ResolveRelativePath
(
path
,
baseDirectory
);
if
(
resolvedPath
==
null
)
{
if
(
diagnosticsOpt
!=
null
&&
messageProviderOpt
!=
null
)
diagnosticOptions
=
new
Dictionary
<
string
,
ReportDiagnostic
>();
if
(
rulesetFileFullPath
==
null
)
{
diagnosticsOpt
.
Add
(
Diagnostic
.
Create
(
messageProviderOpt
,
messageProviderOpt
.
FTL_InputFileNameTooLong
,
path
));
}
return
ReportDiagnostic
.
Default
;
}
return
GetDiagnosticOptionsFromRulesetFile
(
diagnosticOptions
,
r
esolved
Path
,
diagnosticsOpt
,
messageProviderOpt
);
return
GetDiagnosticOptionsFromRulesetFile
(
diagnosticOptions
,
r
ulesetFileFull
Path
,
diagnosticsOpt
,
messageProviderOpt
);
}
private
static
ReportDiagnostic
GetDiagnosticOptionsFromRulesetFile
(
Dictionary
<
string
,
ReportDiagnostic
>
diagnosticOptions
,
string
resolvedPath
,
IList
<
Diagnostic
>
diagnosticsOpt
,
CommonMessageProvider
messageProviderOpt
)
...
...
src/Compilers/VisualBasic/Portable/CommandLine/VisualBasicCommandLineParser.vb
浏览文件 @
bcdcafc2
...
...
@@ -157,6 +157,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim
interactiveMode
As
Boolean
=
False
Dim
instrumentationKinds
As
ArrayBuilder
(
Of
InstrumentationKind
)
=
ArrayBuilder
(
Of
InstrumentationKind
).
GetInstance
()
Dim
sourceLink
As
String
=
Nothing
Dim
ruleSetPath
As
String
=
Nothing
' Process ruleset files first so that diagnostic severity settings specified on the command line via
' /nowarn and /warnaserror can override diagnostic severity settings specified in the ruleset file.
...
...
@@ -171,7 +172,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Continue
For
End
If
generalDiagnosticOption
=
GetDiagnosticOptionsFromRulesetFile
(
specificDiagnosticOptionsFromRuleSet
,
diagnostics
,
unquoted
,
baseDirectory
)
ruleSetPath
=
ParseGenericPathToFile
(
unquoted
,
diagnostics
,
baseDirectory
)
generalDiagnosticOption
=
GetDiagnosticOptionsFromRulesetFile
(
ruleSetPath
,
specificDiagnosticOptionsFromRuleSet
,
diagnostics
)
End
If
Next
End
If
...
...
@@ -1386,6 +1388,7 @@ lVbRuntimePlus:
.
OutputLevel
=
outputLevel
,
.
EmitPdb
=
emitPdb
,
.
SourceLink
=
sourceLink
,
.
RuleSetPath
=
ruleSetPath
,
.
DefaultCoreLibraryReference
=
defaultCoreLibraryReference
,
.
PreferredUILang
=
preferredUILang
,
.
ReportAnalyzer
=
reportAnalyzer
,
...
...
src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb
浏览文件 @
bcdcafc2
...
...
@@ -2282,6 +2282,7 @@ End Module").Path
Dim
file
=
CreateRuleSetFile
(
source
)
Dim
parsedArgs
=
DefaultParse
(
New
String
()
{
"/ruleset:"
+
file
.
Path
,
"a.cs"
},
_baseDirectory
)
parsedArgs
.
Errors
.
Verify
()
Assert
.
Equal
(
expected
:
=
file
.
Path
,
actual
:
=
parsedArgs
.
RuleSetPath
)
Assert
.
True
(
parsedArgs
.
CompilationOptions
.
SpecificDiagnosticOptions
.
ContainsKey
(
"CA1012"
))
Assert
.
True
(
parsedArgs
.
CompilationOptions
.
SpecificDiagnosticOptions
(
"CA1012"
)
=
ReportDiagnostic
.
Error
)
Assert
.
True
(
parsedArgs
.
CompilationOptions
.
SpecificDiagnosticOptions
.
ContainsKey
(
"CA1013"
))
...
...
@@ -2306,6 +2307,7 @@ End Module").Path
Dim
file
=
CreateRuleSetFile
(
source
)
Dim
parsedArgs
=
DefaultParse
(
New
String
()
{
"/ruleset:"
+
"
""
"
+
file
.
Path
+
"
""
"
,
"a.cs"
},
_baseDirectory
)
parsedArgs
.
Errors
.
Verify
()
Assert
.
Equal
(
expected
:
=
file
.
Path
,
actual
:
=
parsedArgs
.
RuleSetPath
)
End
Sub
<
Fact
>
...
...
@@ -2313,23 +2315,28 @@ End Module").Path
Dim
parsedArgs
=
DefaultParse
(
New
String
()
{
"/ruleset"
,
"a.cs"
},
_baseDirectory
)
parsedArgs
.
Errors
.
Verify
(
Diagnostic
(
ERRID
.
ERR_ArgumentRequired
).
WithArguments
(
"ruleset"
,
":<file>"
))
Assert
.
Null
(
parsedArgs
.
RuleSetPath
)
parsedArgs
=
DefaultParse
(
New
String
()
{
"/ruleset"
,
"a.cs"
},
_baseDirectory
)
parsedArgs
.
Errors
.
Verify
(
Diagnostic
(
ERRID
.
ERR_ArgumentRequired
).
WithArguments
(
"ruleset"
,
":<file>"
))
Assert
.
Null
(
parsedArgs
.
RuleSetPath
)
parsedArgs
=
DefaultParse
(
New
String
()
{
"/ruleset:blah"
,
"a.cs"
},
_baseDirectory
)
parsedArgs
.
Errors
.
Verify
(
Diagnostic
(
ERRID
.
ERR_CantReadRulesetFile
).
WithArguments
(
Path
.
Combine
(
TempRoot
.
Root
,
"blah"
),
"File not found."
))
Assert
.
Equal
(
expected
:
=
Path
.
Combine
(
TempRoot
.
Root
,
"blah"
),
actual
:
=
parsedArgs
.
RuleSetPath
)
parsedArgs
=
DefaultParse
(
New
String
()
{
"/ruleset:blah;blah.ruleset"
,
"a.cs"
},
_baseDirectory
)
parsedArgs
.
Errors
.
Verify
(
Diagnostic
(
ERRID
.
ERR_CantReadRulesetFile
).
WithArguments
(
Path
.
Combine
(
TempRoot
.
Root
,
"blah;blah.ruleset"
),
"File not found."
))
Assert
.
Equal
(
expected
:
=
Path
.
Combine
(
TempRoot
.
Root
,
"blah;blah.ruleset"
),
actual
:
=
parsedArgs
.
RuleSetPath
)
Dim
file
=
CreateRuleSetFile
(
New
XDocument
())
parsedArgs
=
DefaultParse
(
New
String
()
{
"/ruleset:"
+
file
.
Path
,
"a.cs"
},
_baseDirectory
)
'parsedArgs.Errors.Verify(
' Diagnostic(ERRID.ERR_CantReadRulesetFile).WithArguments(file.Path, "Root element is missing."))
Assert
.
Equal
(
expected
:
=
file
.
Path
,
actual
:
=
parsedArgs
.
RuleSetPath
)
Dim
err
=
parsedArgs
.
Errors
.
Single
()
Assert
.
Equal
(
ERRID
.
ERR_CantReadRulesetFile
,
err
.
Code
)
...
...
src/VisualStudio/Core/Impl/ProjectSystem/CPS/CPSProject_IWorkspaceProjectContext.cs
浏览文件 @
bcdcafc2
...
...
@@ -120,6 +120,9 @@ public void SetOptions(string commandLineForOptions)
ExecuteForegroundAction
(()
=>
{
var
commandLineArguments
=
SetArgumentsAndUpdateOptions
(
commandLineForOptions
);
SetRuleSetFile
(
commandLineArguments
.
RuleSetPath
);
PostSetOptions
(
commandLineArguments
);
});
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录