diff --git a/Makefile b/Makefile index 8f67c51bf5..39cdbfa837 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 1d4eae49c6..c1a3c5fc87 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -55,9 +55,6 @@ ..\thirdparty\download\Eluant.dll False - - ..\thirdparty\download\StyleCop.dll - ..\thirdparty\download\ICSharpCode.SharpZipLib.dll False @@ -544,7 +541,6 @@ - diff --git a/OpenRA.Mods.Common/UtilityCommands/CheckCodeStyle.cs b/OpenRA.Mods.Common/UtilityCommands/CheckCodeStyle.cs deleted file mode 100644 index 896321e8cf..0000000000 --- a/OpenRA.Mods.Common/UtilityCommands/CheckCodeStyle.cs +++ /dev/null @@ -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); - } - } -} diff --git a/OpenRA.StyleCheck/OpenRA.StyleCheck.csproj b/OpenRA.StyleCheck/OpenRA.StyleCheck.csproj new file mode 100644 index 0000000000..c06e6f8da2 --- /dev/null +++ b/OpenRA.StyleCheck/OpenRA.StyleCheck.csproj @@ -0,0 +1,41 @@ + + + + Debug + AnyCPU + {5FEAB6DC-4E81-4B63-958B-22FC3534C606} + Exe + OpenRA.StyleCheck + OpenRA.StyleCheck + v4.5 + + + true + full + false + ..\ + DEBUG;TRACE + prompt + 4 + true + x86 + + + true + ..\ + prompt + 4 + true + x86 + + + + + ..\StyleCop.dll + + + + + + + \ No newline at end of file diff --git a/OpenRA.StyleCheck/Program.cs b/OpenRA.StyleCheck/Program.cs new file mode 100644 index 0000000000..497812c99d --- /dev/null +++ b/OpenRA.StyleCheck/Program.cs @@ -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]); + } + } +} diff --git a/OpenRA.sln b/OpenRA.sln index df2d8ffa85..b224e36d75 100644 --- a/OpenRA.sln +++ b/OpenRA.sln @@ -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 diff --git a/make.ps1 b/make.ps1 index 88c0d75fff..498b76c47f 100644 --- a/make.ps1 +++ b/make.ps1 @@ -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