Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #459 from WiseTechGlobal/wtg/pr/rsp-generation
Browse files Browse the repository at this point in the history
Add flag to generate cccheck RSP at build time
  • Loading branch information
SergeyTeplyakov authored Dec 12, 2016
2 parents 1803c2a + 30ab1fe commit a7df47a
Show file tree
Hide file tree
Showing 14 changed files with 987 additions and 1,114 deletions.
2 changes: 1 addition & 1 deletion Foxtrot/Driver/Rewriting/EmitAsyncClosure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public TypeNodePair(TypeNode enclosingGenericType, TypeNode closureGenericType)
// Mapping between enclosing generic type and closure generic type.
// This is a simple list not a dictionary, because number of generic arguments is very small.
// So linear complexity will not harm performance.
private List<TypeNodePair> typeParametersMapping = new List<TypeNodePair>();
readonly List<TypeNodePair> typeParametersMapping = new List<TypeNodePair>();

public bool IsEmpty { get { return typeParametersMapping.Count == 0; } }

Expand Down
5 changes: 1 addition & 4 deletions Foxtrot/Driver/Rewriting/PostRewriteChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ public override void VisitMemberBinding(MemberBinding binding)
methodName.Matches(ContractNodes.EndContractBlockName))
{
string message = string.Format(Resources.Error_ContractNotRewritten_ContractName_MemberName, method.FullName, this.visitedMembers.Peek().FullName);
if (this.handleError != null)
{
this.handleError(new Error(1080, message, binding.SourceContext));
}
this.handleError(new Error(1080, message, binding.SourceContext));
}
}

Expand Down
2 changes: 1 addition & 1 deletion Microsoft.Research/DataStructures/OptionParsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected virtual bool ParseGeneralArgument(string arg, string[] args, ref int i
return true;
}

// Also add '!' as synonim for '=', as cmd.exe performs fuzzy things with '='
// Also add '!' as synonym for '=', as cmd.exe performs fuzzy things with '='
private static readonly char[] equalChars = new char[] { ':', '=', '!' };
private static readonly char[] quoteChars = new char[] { '\'', '"' };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
<!--=====================================================================
Running Static Code Analysis
======================================================================-->

<Target
Name="CodeContractsPerformCodeAnalysis"
Condition="'$(CodeContractsRunCodeAnalysis)' == 'true'"
DependsOnTargets="CodeContractsComputeCodeAnalysisDependencies;CodeContractsRunCodeAnalysis">
Condition="'$(CodeContractsRunCodeAnalysis)' == 'true' or '$(CodeContractsDeferCodeAnalysis)' == 'true'"
DependsOnTargets="CodeContractsComputeCodeAnalysisDependencies;CodeContractsCodeAnalysisWriteRSPFile;CodeContractsRunCodeAnalysis">
</Target>

<Target
Expand Down Expand Up @@ -61,7 +61,7 @@

<Target
Name="CodeContractsRunCodeAnalysis"
Condition="'$(CodeContractsRunCodeAnalysis)' == 'true' and '$([System.Environment]::GetEnvironmentVariable(`CodeContractsTargetProjectGuid`))' == '' and '$(BuildingProject)'=='true'"
Condition="'$(CodeContractsRunCodeAnalysis)' == 'true' and '$(CodeContractsDeferCodeAnalysis)' != 'true' and '$([System.Environment]::GetEnvironmentVariable(`CodeContractsTargetProjectGuid`))' == '' and '$(BuildingProject)'=='true'"
Inputs="@(CodeContractsCodeAnalysisInput)"
Outputs="$(CodeContractsCodeAnalysisOutput)"
>
Expand Down Expand Up @@ -101,14 +101,14 @@
<CodeContractsAnalysisWarning>medium</CodeContractsAnalysisWarning>
</PropertyGroup>
</When>
<When Condition="'$(CodeContractsAnalysisWarningLevel)'=='3'">
<When Condition="'$(CodeContractsAnalysisWarningLevel)'=='3'">
<PropertyGroup>
<CodeContractsAnalysisWarning>full</CodeContractsAnalysisWarning>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<CodeContractsAnalysisWarning>low</CodeContractsAnalysisWarning>
<CodeContractsAnalysisWarning>low</CodeContractsAnalysisWarning>
</PropertyGroup>
</Otherwise>
</Choose>
Expand All @@ -129,11 +129,9 @@
</Choose>

<Target
Name="CodeContractsRunCodeAnalysisInternal"
Name="CodeContractsCodeAnalysisWriteRSPFile"
DependsOnTargets="CodeContractsComputeAllLibPaths;EnsureContractReferenceAssemblyOfDependeeProjects;CodeContractsLoadEnvVars"
>
<Message Text="Run Contract Code Analysis on project guid $(ProjectGuid)" Importance="Low"/>

<PropertyGroup>
<DeclarativeAssemblyDir>@(ContractDeclarativeAssembly->'%(RootDir)')@(ContractDeclarativeAssembly->'%(Directory)')</DeclarativeAssemblyDir>
<DeclarativeAssemblyPath>@(ContractDeclarativeAssembly->'%(FullPath)')</DeclarativeAssemblyPath>
Expand All @@ -160,23 +158,23 @@
Condition="'$(CodeContractsRedundantAssumptions)' == 'true'">$(CodeContractCodeAnalysisOptions) -check assumptions</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsAssertsToContractsCheckBox)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest asserttocontracts</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsRedundantTests)' == 'true'">$(CodeContractCodeAnalysisOptions) -check conditionsvalidity</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsMissingPublicRequiresAsWarnings)' == 'true'">$(CodeContractCodeAnalysisOptions) -missingPublicRequiresAreErrors</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsMissingPublicEnsuresAsWarnings)' == 'true'">$(CodeContractCodeAnalysisOptions) -missingPublicEnsuresAreErrors</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsMissingPublicRequiresAsWarnings)' == 'true'">$(CodeContractCodeAnalysisOptions) -missingPublicRequiresAreErrors</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsMissingPublicEnsuresAsWarnings)' == 'true'">$(CodeContractCodeAnalysisOptions) -missingPublicEnsuresAreErrors</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestAssumptionsForCallees)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest calleeassumes</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestAssumptions)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest assumes</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestRequires)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest requires</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestEnsures)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest methodensures -suggest propertyensures</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsNecessaryEnsures)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest necessaryensures</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestObjectInvariants)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest objectinvariants</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestReadonly)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest readonlyfields</CodeContractCodeAnalysisOptions>
Expand All @@ -190,7 +188,7 @@
Condition="'$(CodeContractsInferObjectInvariants)' == 'true'">$(CodeContractCodeAnalysisOptions) -infer objectinvariants</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsCacheAnalysisResults)' == 'true'">$(CodeContractCodeAnalysisOptions) -cache</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSkipAnalysisIfCannotConnectToCache)' == 'true'">$(CodeContractCodeAnalysisOptions) -forcecacheserver=true</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsFailBuildOnWarnings)' == 'true'">$(CodeContractCodeAnalysisOptions) -failOnWarnings</CodeContractCodeAnalysisOptions>
Expand Down Expand Up @@ -230,10 +228,18 @@
</ItemGroup>

<WriteLinesToFile
File="$(DeclarativeAssemblyDir)$(ProjectName)cccheck.rsp"
File="$(DeclarativeAssemblyDir)$(AssemblyName).cccheck.rsp"
Lines="@(_CodeContractsCCCheckArgumentLines, ';')"
Overwrite="true"
/>

</Target>

<Target
Name="CodeContractsRunCodeAnalysisInternal"
DependsOnTargets="CodeContractsCodeAnalysisWriteRSPFile">

<Message Text="Run Contract Code Analysis on project guid $(ProjectGuid)" Importance="Low"/>

<CodeContractsAnalysis
Verbose="false"
Expand All @@ -246,7 +252,7 @@
KeepErrors="$(CodeContractsFailBuildOnWarnings)"
OutputPrefix="CodeContracts: "
Command='$(CodeContractRunCodeAnalysisCommand)'
CommandOptions='"@$(ProjectName)cccheck.rsp"'
CommandOptions='"@$(AssemblyName).cccheck.rsp"'
/>
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@
</ItemGroup>

<WriteLinesToFile
File="$(IntermediateOutputPath)$(ProjectName)ccrewrite.rsp"
File="$(IntermediateOutputPath)$(AssemblyName).ccrewrite.rsp"
Lines="@(_CodeContractsCCRewriteArgumentLines, ';')"
Overwrite="true"
/>

<Exec
WorkingDirectory="$(IntermediateOutputPath)"
Command='"$(CodeContractRewriteCommand)" "@$(ProjectName)ccrewrite.rsp"'
Command='"$(CodeContractRewriteCommand)" "@$(AssemblyName).ccrewrite.rsp"'
/>

<CallTarget Targets="CodeContractReSign"/>
Expand All @@ -291,7 +291,7 @@
<PropertyGroup>
<!-- SN is in the Framework SDK tools path, but TargetFrameworkSDKToolsDirectory isn't always available -->
<CodeContractsSnExe Condition=" '$(TargetFrameworkSDKToolsDirectory)' != '' ">$(TargetFrameworkSDKToolsDirectory)sn.exe</CodeContractsSnExe>
<CodeContractsSnExe Condition=" '$(TargetFrameworkSDKToolsDirectory)' == '' ">$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\sn.exe</CodeContractsSnExe>
<CodeContractsSnExe Condition=" '$(TargetFrameworkSDKToolsDirectory)' == '' ">$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\sn.exe</CodeContractsSnExe>
</PropertyGroup>
<Exec
Condition="'$(KeyOriginatorFile)' != ''"
Expand Down Expand Up @@ -348,19 +348,19 @@
</ItemGroup>

<WriteLinesToFile
File="$(IntermediateOutputPath)$(ProjectName)ccrefgen.rsp"
File="$(IntermediateOutputPath)$(AssemblyName).ccrefgen.rsp"
Lines="@(_CodeContractsCCRefGenArgumentLines, ';')"
Overwrite="true"
/>

<Exec
Condition="Exists('@(ContractDeclarativeAssembly)')"
Command='"$(CodeContractsCCRefgenCommand)" "@$(IntermediateOutputPath)$(ProjectName)ccrefgen.rsp"'
Command='"$(CodeContractsCCRefgenCommand)" "@$(IntermediateOutputPath)$(AssemblyName).ccrefgen.rsp"'
/>
<ItemGroup
Condition="Exists('@(ContractReferenceAssemblyAbsolute)')">
<FileWrites
Include="@(ContractReferenceAssemblies);$(IntermediateOutputPath)$(ProjectName)ccrefgen.rsp"/>
Include="@(ContractReferenceAssemblies);$(IntermediateOutputPath)$(AssemblyName).ccrefgen.rsp"/>
</ItemGroup>

</Target>
Expand Down Expand Up @@ -586,7 +586,7 @@
<Target
Name="CodeContractsComputeAllLibPaths"
DependsOnTargets="CodeContractsComputeReferencedLibPaths"
>
>
<Message Text="CodeContractsComputeAllLibPaths" Importance="low"/>
<RemoveDuplicates
Inputs="@(CodeContractsBuildLibPaths);$(CodeContractsReferenceAssemblyLibPath);$(CodeContractsLibPaths)">
Expand Down Expand Up @@ -634,13 +634,13 @@
</ItemGroup>

<WriteLinesToFile
File="$(IntermediateOutputPath)$(ProjectName)ccdocgen.rsp"
File="$(IntermediateOutputPath)$(AssemblyName).ccdocgen.rsp"
Lines="@(_CodeContractsCCDocGenArgumentLines, ';')"
Overwrite="true"
/>

<Exec
Command='"$(CodeContractsCCdocgenCommand)" "@$(IntermediateOutputPath)$(ProjectName)ccdocgen.rsp"'
Command='"$(CodeContractsCCdocgenCommand)" "@$(IntermediateOutputPath)$(AssemblyName).ccdocgen.rsp"'
/>
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
<!--=====================================================================
Running Static Code Analysis
======================================================================-->

<Target
Name="CodeContractsPerformCodeAnalysis"
Condition="'$(CodeContractsRunCodeAnalysis)' == 'true'"
DependsOnTargets="CodeContractsComputeCodeAnalysisDependencies;CodeContractsRunCodeAnalysis">
DependsOnTargets="CodeContractsComputeCodeAnalysisDependencies;CodeContractsCodeAnalysisWriteRSPFile;CodeContractsRunCodeAnalysis">
</Target>

<Target
Expand Down Expand Up @@ -61,7 +61,7 @@

<Target
Name="CodeContractsRunCodeAnalysis"
Condition="'$(CodeContractsRunCodeAnalysis)' == 'true' and '$([System.Environment]::GetEnvironmentVariable(`CodeContractsTargetProjectGuid`))' == '' and '$(BuildingProject)'=='true'"
Condition="'$(CodeContractsRunCodeAnalysis)' == 'true' and '$(CodeContractsDeferCodeAnalysis)' != 'true' and '$([System.Environment]::GetEnvironmentVariable(`CodeContractsTargetProjectGuid`))' == '' and '$(BuildingProject)'=='true'"
Inputs="@(CodeContractsCodeAnalysisInput)"
Outputs="$(CodeContractsCodeAnalysisOutput)"
>
Expand Down Expand Up @@ -101,14 +101,14 @@
<CodeContractsAnalysisWarning>medium</CodeContractsAnalysisWarning>
</PropertyGroup>
</When>
<When Condition="'$(CodeContractsAnalysisWarningLevel)'=='3'">
<When Condition="'$(CodeContractsAnalysisWarningLevel)'=='3'">
<PropertyGroup>
<CodeContractsAnalysisWarning>full</CodeContractsAnalysisWarning>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<CodeContractsAnalysisWarning>low</CodeContractsAnalysisWarning>
<CodeContractsAnalysisWarning>low</CodeContractsAnalysisWarning>
</PropertyGroup>
</Otherwise>
</Choose>
Expand All @@ -129,11 +129,9 @@
</Choose>

<Target
Name="CodeContractsRunCodeAnalysisInternal"
Name="CodeContractsCodeAnalysisWriteRSPFile"
DependsOnTargets="CodeContractsComputeAllLibPaths;EnsureContractReferenceAssemblyOfDependeeProjects;CodeContractsLoadEnvVars"
>
<Message Text="Run Contract Code Analysis on project guid $(ProjectGuid)" Importance="Low"/>

<PropertyGroup>
<DeclarativeAssemblyDir>@(ContractDeclarativeAssembly->'%(RootDir)')@(ContractDeclarativeAssembly->'%(Directory)')</DeclarativeAssemblyDir>
<DeclarativeAssemblyPath>@(ContractDeclarativeAssembly->'%(FullPath)')</DeclarativeAssemblyPath>
Expand All @@ -160,23 +158,23 @@
Condition="'$(CodeContractsRedundantAssumptions)' == 'true'">$(CodeContractCodeAnalysisOptions) -check assumptions</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsAssertsToContractsCheckBox)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest asserttocontracts</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsRedundantTests)' == 'true'">$(CodeContractCodeAnalysisOptions) -check conditionsvalidity</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsMissingPublicRequiresAsWarnings)' == 'true'">$(CodeContractCodeAnalysisOptions) -missingPublicRequiresAreErrors</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsMissingPublicEnsuresAsWarnings)' == 'true'">$(CodeContractCodeAnalysisOptions) -missingPublicEnsuresAreErrors</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsMissingPublicRequiresAsWarnings)' == 'true'">$(CodeContractCodeAnalysisOptions) -missingPublicRequiresAreErrors</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsMissingPublicEnsuresAsWarnings)' == 'true'">$(CodeContractCodeAnalysisOptions) -missingPublicEnsuresAreErrors</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestAssumptionsForCallees)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest calleeassumes</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestAssumptions)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest assumes</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestRequires)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest requires</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestEnsures)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest methodensures -suggest propertyensures</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsNecessaryEnsures)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest necessaryensures</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestObjectInvariants)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest objectinvariants</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestReadonly)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest readonlyfields</CodeContractCodeAnalysisOptions>
Expand All @@ -190,7 +188,7 @@
Condition="'$(CodeContractsInferObjectInvariants)' == 'true'">$(CodeContractCodeAnalysisOptions) -infer objectinvariants</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsCacheAnalysisResults)' == 'true'">$(CodeContractCodeAnalysisOptions) -cache</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSkipAnalysisIfCannotConnectToCache)' == 'true'">$(CodeContractCodeAnalysisOptions) -forcecacheserver=true</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsFailBuildOnWarnings)' == 'true'">$(CodeContractCodeAnalysisOptions) -failOnWarnings</CodeContractCodeAnalysisOptions>
Expand Down Expand Up @@ -230,10 +228,18 @@
</ItemGroup>

<WriteLinesToFile
File="$(DeclarativeAssemblyDir)$(ProjectName)cccheck.rsp"
File="$(DeclarativeAssemblyDir)$(AssemblyName).cccheck.rsp"
Lines="@(_CodeContractsCCCheckArgumentLines, ';')"
Overwrite="true"
/>

</Target>

<Target
Name="CodeContractsRunCodeAnalysisInternal"
DependsOnTargets="CodeContractsCodeAnalysisWriteRSPFile">

<Message Text="Run Contract Code Analysis on project guid $(ProjectGuid)" Importance="Low"/>

<CodeContractsAnalysis
Verbose="false"
Expand All @@ -246,7 +252,7 @@
KeepErrors="$(CodeContractsFailBuildOnWarnings)"
OutputPrefix="CodeContracts: "
Command='$(CodeContractRunCodeAnalysisCommand)'
CommandOptions='"@$(ProjectName)cccheck.rsp"'
CommandOptions='"@$(AssemblyName).cccheck.rsp"'
/>
</Target>

Expand Down
Loading

0 comments on commit a7df47a

Please sign in to comment.