Move Stylecop checks to their own helper executable.

This commit is contained in:
Paul Chote
2017-07-08 16:43:11 +00:00
committed by reaperrr
parent 1fa1677204
commit e38db04ab7
7 changed files with 134 additions and 87 deletions

View File

@@ -119,7 +119,7 @@ mod_common_SRCS := $(shell find OpenRA.Mods.Common/ -iname '*.cs')
mod_common_TARGET = mods/common/OpenRA.Mods.Common.dll
mod_common_KIND = library
mod_common_DEPS = $(game_TARGET)
mod_common_LIBS = $(COMMON_LIBS) $(STD_MOD_LIBS) thirdparty/download/StyleCop.dll thirdparty/download/StyleCop.CSharp.dll thirdparty/download/StyleCop.CSharp.Rules.dll
mod_common_LIBS = $(COMMON_LIBS) $(STD_MOD_LIBS)
PROGRAMS += mod_common
mod_common: $(mod_common_TARGET)
@@ -162,34 +162,34 @@ check-scripts:
@luac -p $(shell find mods/*/maps/* -iname '*.lua')
@luac -p $(shell find lua/* -iname '*.lua')
check: utility mods
check: utility stylecheck mods
@echo
@echo "Checking for explicit interface violations..."
@mono --debug OpenRA.Utility.exe all --check-explicit-interfaces
@echo
@echo "Checking for code style violations in OpenRA.Game..."
@mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Game
@mono --debug OpenRA.StyleCheck.exe OpenRA.Game
@echo
@echo "Checking for code style violations in OpenRA.Platforms.Default..."
@mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Platforms.Default
@mono --debug OpenRA.StyleCheck.exe OpenRA.Platforms.Default
@echo
@echo "Checking for code style violations in OpenRA.Mods.Common..."
@mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Mods.Common
@mono --debug OpenRA.StyleCheck.exe OpenRA.Mods.Common
@echo
@echo "Checking for code style violations in OpenRA.Mods.Cnc..."
@mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Mods.Cnc
@mono --debug OpenRA.StyleCheck.exe OpenRA.Mods.Cnc
@echo
@echo "Checking for code style violations in OpenRA.Mods.D2k..."
@mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Mods.D2k
@mono --debug OpenRA.StyleCheck.exe OpenRA.Mods.D2k
@echo
@echo "Checking for code style violations in OpenRA.Utility..."
@mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Utility
@mono --debug OpenRA.StyleCheck.exe OpenRA.Utility
@echo
@echo "Checking for code style violations in OpenRA.Test..."
@mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Test
@mono --debug OpenRA.StyleCheck.exe OpenRA.Test
@echo
@echo "Checking for code style violations in OpenRA.Server..."
@mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Server
@mono --debug OpenRA.StyleCheck.exe OpenRA.Server
NUNIT_CONSOLE := $(shell test -f thirdparty/download/nunit3-console.exe && echo mono thirdparty/download/nunit3-console.exe || \
which nunit3-console 2>/dev/null || which nunit2-console 2>/dev/null || which nunit-console 2>/dev/null)
@@ -235,6 +235,13 @@ utility_LIBS = $(COMMON_LIBS) $(utility_DEPS) thirdparty/download/ICSharpCode.Sh
PROGRAMS += utility
utility: $(utility_TARGET)
stylecheck_SRCS := $(shell find OpenRA.StyleCheck/ -iname '*.cs')
stylecheck_TARGET = OpenRA.StyleCheck.exe
stylecheck_KIND = exe
stylecheck_LIBS = thirdparty/download/StyleCop.dll thirdparty/download/StyleCop.CSharp.dll thirdparty/download/StyleCop.CSharp.Rules.dll
PROGRAMS += stylecheck
stylecheck: $(stylecheck_TARGET)
# Dedicated server
server_SRCS := $(shell find OpenRA.Server/ -iname '*.cs')
server_TARGET = OpenRA.Server.exe
@@ -278,7 +285,7 @@ core: dependencies game platforms mods utility server
mods: mod_common mod_cnc mod_d2k
all: dependencies core
all: dependencies core stylecheck
clean:
@-$(RM_F) *.exe *.dll *.dylib *.dll.config ./OpenRA*/*.dll ./OpenRA*/*.mdb *.mdb mods/**/*.dll mods/**/*.mdb *.resources

View File

@@ -55,9 +55,6 @@
<HintPath>..\thirdparty\download\Eluant.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="StyleCop">
<HintPath>..\thirdparty\download\StyleCop.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.SharpZipLib">
<HintPath>..\thirdparty\download\ICSharpCode.SharpZipLib.dll</HintPath>
<Private>False</Private>
@@ -544,7 +541,6 @@
<Compile Include="Traits\World\WarheadDebugOverlay.cs" />
<Compile Include="Traits\World\WeatherOverlay.cs" />
<Compile Include="UtilityCommands\CheckYaml.cs" />
<Compile Include="UtilityCommands\CheckCodeStyle.cs" />
<Compile Include="UtilityCommands\ConvertPngToShpCommand.cs" />
<Compile Include="UtilityCommands\ConvertSpriteToPngCommand.cs" />
<Compile Include="UtilityCommands\CreateManPage.cs" />

View File

@@ -1,58 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2017 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System;
using System.IO;
using StyleCop;
namespace OpenRA.Mods.Common.UtilityCommands
{
class CheckCodeStyle : IUtilityCommand
{
string IUtilityCommand.Name { get { return "--check-code-style"; } }
int violationCount;
bool IUtilityCommand.ValidateArguments(string[] args)
{
return args.Length >= 2;
}
[Desc("DIRECTORY", "Check the *.cs source code files in a directory for code style violations.")]
void IUtilityCommand.Run(Utility utility, string[] args)
{
var relativePath = args[1];
var projectPath = Path.GetFullPath(relativePath);
// HACK: The engine code assumes that Game.modData is set.
Game.ModData = utility.ModData;
var console = new StyleCopConsole(null, false, null, null, true);
var project = new CodeProject(0, projectPath, new Configuration(null));
foreach (var filePath in Directory.GetFiles(projectPath, "*.cs", SearchOption.AllDirectories))
console.Core.Environment.AddSourceCode(project, filePath, null);
console.ViolationEncountered += OnViolationEncountered;
console.Start(new[] { project }, true);
if (violationCount > 0)
Environment.Exit(1);
else
Console.WriteLine("No violations encountered in {0}.".F(relativePath));
}
void OnViolationEncountered(object sender, ViolationEventArgs e)
{
violationCount++;
var path = e.SourceCode.Path.Replace(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar, "");
Console.WriteLine("{0}:L{1}: [{2}] {3}", path, e.LineNumber, e.Violation.Rule.CheckId, e.Message);
}
}
}

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5FEAB6DC-4E81-4B63-958B-22FC3534C606}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>OpenRA.StyleCheck</RootNamespace>
<AssemblyName>OpenRA.StyleCheck</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<Optimize>true</Optimize>
<OutputPath>..\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="StyleCop">
<HintPath>..\StyleCop.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -0,0 +1,47 @@
#region Copyright & License Information
/*
* Copyright 2007-2017 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, and is made available under the terms of the MS-PL license.
* For more information, see https://opensource.org/licenses/MS-PL
*/
#endregion
using System;
using System.IO;
using StyleCop;
namespace OpenRA.StyleCheck
{
class StyleCheck
{
public static void Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("Usage: OpenRA.StyleCheck.exe DIRECTORY");
Console.WriteLine("Check the *.cs source code files in a directory for code style violations.");
return;
}
var projectPath = Path.GetFullPath(args[0]);
var console = new StyleCopConsole(null, false, null, null, true);
var project = new CodeProject(0, projectPath, new Configuration(null));
foreach (var filePath in Directory.GetFiles(projectPath, "*.cs", SearchOption.AllDirectories))
console.Core.Environment.AddSourceCode(project, filePath, null);
var violationCount = 0;
console.ViolationEncountered += (object sender, ViolationEventArgs e) => {
violationCount++;
var path = e.SourceCode.Path.Replace(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar, "");
Console.WriteLine("{0}:L{1}: [{2}] {3}", path, e.LineNumber, e.Violation.Rule.CheckId, e.Message);
};
console.Start(new[] { project }, true);
if (violationCount > 0)
Environment.Exit(1);
else
Console.WriteLine("No violations encountered in {0}.", args[0]);
}
}
}

View File

@@ -154,6 +154,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tiberian Sun Lua scripts",
mods\ts\maps\fields-of-green\fields-of-green.lua = mods\ts\maps\fields-of-green\fields-of-green.lua
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.StyleCheck", "OpenRA.StyleCheck\OpenRA.StyleCheck.csproj", "{5FEAB6DC-4E81-4B63-958B-22FC3534C606}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
@@ -192,6 +194,10 @@ Global
{6CB8E1B7-6B36-4D93-8633-7C573E194AC4}.Debug|x86.Build.0 = Debug|x86
{6CB8E1B7-6B36-4D93-8633-7C573E194AC4}.Release|x86.ActiveCfg = Release|x86
{6CB8E1B7-6B36-4D93-8633-7C573E194AC4}.Release|x86.Build.0 = Release|x86
{5FEAB6DC-4E81-4B63-958B-22FC3534C606}.Debug|x86.ActiveCfg = Debug|x86
{5FEAB6DC-4E81-4B63-958B-22FC3534C606}.Debug|x86.Build.0 = Debug|x86
{5FEAB6DC-4E81-4B63-958B-22FC3534C606}.Release|x86.ActiveCfg = Release|x86
{5FEAB6DC-4E81-4B63-958B-22FC3534C606}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -137,25 +137,33 @@ function Check-Command {
{
echo "Checking for explicit interface violations..."
./OpenRA.Utility.exe all --check-explicit-interfaces
echo "Checking for code style violations in OpenRA.Platforms.Default..."
./OpenRA.Utility.exe cnc --check-code-style OpenRA.Platforms.Default
echo "Checking for code style violations in OpenRA.Game..."
./OpenRA.Utility.exe ra --check-code-style OpenRA.Game
echo "Checking for code style violations in OpenRA.Mods.Common..."
./OpenRA.Utility.exe ra --check-code-style OpenRA.Mods.Common
echo "Checking for code style violations in OpenRA.Mods.Cnc..."
./OpenRA.Utility.exe cnc --check-code-style OpenRA.Mods.Cnc
echo "Checking for code style violations in OpenRA.Mods.D2k..."
./OpenRA.Utility.exe cnc --check-code-style OpenRA.Mods.D2k
echo "Checking for code style violations in OpenRA.Utility..."
./OpenRA.Utility.exe cnc --check-code-style OpenRA.Utility
echo "Checking for code style violations in OpenRA.Test..."
./OpenRA.Utility.exe cnc --check-code-style OpenRA.Test
}
else
{
UtilityNotFound
}
if (Test-Path OpenRA.StyleCheck.exe)
{
echo "Checking for code style violations in OpenRA.Platforms.Default..."
./OpenRA.StyleCheck.exe OpenRA.Platforms.Default
echo "Checking for code style violations in OpenRA.Game..."
./OpenRA.StyleCheck.exe OpenRA.Game
echo "Checking for code style violations in OpenRA.Mods.Common..."
./OpenRA.StyleCheck.exe OpenRA.Mods.Common
echo "Checking for code style violations in OpenRA.Mods.Cnc..."
./OpenRA.StyleCheck.exe OpenRA.Mods.Cnc
echo "Checking for code style violations in OpenRA.Mods.D2k..."
./OpenRA.StyleCheck.exe OpenRA.Mods.D2k
echo "Checking for code style violations in OpenRA.Utility..."
./OpenRA.StyleCheck.exe OpenRA.Utility
echo "Checking for code style violations in OpenRA.Test..."
./OpenRA.StyleCheck.exe OpenRA.Test
}
else
{
echo "OpenRA.StyleCheck.exe could not be found. Build the project first using the `"all`" command."
}
}
function Check-Scripts-Command