From ecd447980728dd48ae11a2ae9362eb472aab33b6 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 18 Dec 2014 15:15:06 +1300 Subject: [PATCH] Move OpenRA.Lint into a --check-yaml utility command. --- Makefile | 31 +++---- OpenRA.Lint/OpenRA.Lint.csproj | 87 ------------------- OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 1 + .../UtilityCommands/CheckYaml.cs | 42 ++++----- OpenRA.sln | 4 - make.ps1 | 16 ++-- 6 files changed, 35 insertions(+), 146 deletions(-) delete mode 100644 OpenRA.Lint/OpenRA.Lint.csproj rename OpenRA.Lint/YamlChecker.cs => OpenRA.Mods.Common/UtilityCommands/CheckYaml.cs (66%) diff --git a/Makefile b/Makefile index 384e550d12..b4941623c4 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ INSTALL_PROGRAM = $(INSTALL) -m755 INSTALL_DATA = $(INSTALL) -m644 # program targets -CORE = rsdl2 rnull game utility ralint +CORE = rsdl2 rnull game utility TOOLS = editor tsbuild crashdialog VERSION = $(shell git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || echo git-`git rev-parse --short HEAD`) @@ -112,7 +112,7 @@ mod_common: $(mod_common_TARGET) ##### Official Mods ##### STD_MOD_LIBS = $(game_TARGET) -STD_MOD_DEPS = $(STD_MOD_LIBS) $(ralint_TARGET) +STD_MOD_DEPS = $(STD_MOD_LIBS) # Red Alert mod_ra_SRCS := $(shell find OpenRA.Mods.RA/ -iname '*.cs') @@ -168,24 +168,15 @@ OpenRA.Editor.Form1.resources: resgen2 OpenRA.Editor/Form1.resx OpenRA.Editor.Form1.resources 1> /dev/null editor: OpenRA.Editor.MapSelect.resources OpenRA.Editor.Form1.resources $(editor_TARGET) -# Analyses mod yaml for easy to detect errors -ralint_SRCS := $(shell find OpenRA.Lint/ -iname '*.cs') -ralint_TARGET = OpenRA.Lint.exe -ralint_KIND = exe -ralint_DEPS = $(game_TARGET) -ralint_LIBS = $(COMMON_LIBS) $(ralint_DEPS) -PROGRAMS += ralint -ralint: $(ralint_TARGET) - test: - @echo "OpenRA.Lint: checking Red Alert mod MiniYAML..." - @mono --debug OpenRA.Lint.exe --verbose ra - @echo "OpenRA.Lint: checking Tiberian Dawn mod MiniYAML..." - @mono --debug OpenRA.Lint.exe --verbose cnc - @echo "OpenRA.Lint: checking Dune 2000 mod MiniYAML..." - @mono --debug OpenRA.Lint.exe --verbose d2k - @echo "OpenRA.Lint: checking Tiberian Sun mod MiniYAML..." - @mono --debug OpenRA.Lint.exe --verbose ts + @echo "Testing Red Alert mod MiniYAML..." + @mono --debug OpenRA.Utility.exe ra --check-yaml + @echo "Testing Tiberian Dawn mod MiniYAML..." + @mono --debug OpenRA.Utility.exe cnc --check-yaml + @echo "Testing Dune 2000 mod MiniYAML..." + @mono --debug OpenRA.Utility.exe d2k --check-yaml + @echo "Testing Tiberian Sun mod MiniYAML..." + @mono --debug OpenRA.Utility.exe ts --check-yaml # Builds and exports tilesets from a bitmap tsbuild_SRCS := $(shell find OpenRA.TilesetBuilder/ -iname '*.cs') @@ -254,7 +245,7 @@ $(foreach prog,$(PROGRAMS),$(eval $(call BUILD_ASSEMBLY,$(prog)))) # default: cli-dependencies core -core: game renderers mods utility ralint +core: game renderers mods utility tools: editor tsbuild gamemonitor diff --git a/OpenRA.Lint/OpenRA.Lint.csproj b/OpenRA.Lint/OpenRA.Lint.csproj deleted file mode 100644 index f5aef68227..0000000000 --- a/OpenRA.Lint/OpenRA.Lint.csproj +++ /dev/null @@ -1,87 +0,0 @@ - - - - Debug - AnyCPU - {F9FA4D9F-2302-470A-8A07-6E37F488C124} - Exe - Properties - OpenRA - OpenRA.Lint - 512 - - - 3.5 - - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - true - full - ..\ - DEBUG;TRACE - prompt - x86 - false - AllRules.ruleset - true - - - - - - - - - - - - - - - - {0DFB103F-2962-400F-8C6D-E2C28CCBA633} - OpenRA.Game - False - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Windows Installer 3.1 - true - - - - - \ No newline at end of file diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 9526687c40..8cefe7899b 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -243,6 +243,7 @@ + diff --git a/OpenRA.Lint/YamlChecker.cs b/OpenRA.Mods.Common/UtilityCommands/CheckYaml.cs similarity index 66% rename from OpenRA.Lint/YamlChecker.cs rename to OpenRA.Mods.Common/UtilityCommands/CheckYaml.cs index c8686378bb..d9f1deea25 100644 --- a/OpenRA.Lint/YamlChecker.cs +++ b/OpenRA.Mods.Common/UtilityCommands/CheckYaml.cs @@ -14,52 +14,43 @@ using System.Linq; using OpenRA.FileSystem; using OpenRA.Traits; -namespace OpenRA.Lint +namespace OpenRA.Mods.Common.UtilityCommands { - static class YamlChecker + class CheckYaml : IUtilityCommand { + public string Name { get { return "--check-yaml"; } } + static int errors = 0; // mimic Windows compiler error format static void EmitError(string e) { - Console.WriteLine("OpenRA.Lint(1,1): Error: {0}", e); + Console.WriteLine("OpenRA.Utility(1,1): Error: {0}", e); ++errors; } static void EmitWarning(string e) { - Console.WriteLine("OpenRA.Lint(1,1): Warning: {0}", e); + Console.WriteLine("OpenRA.Utility(1,1): Warning: {0}", e); } - static int Main(string[] args) + [Desc("[MAPFILE]", "Check a mod or map for certain yaml errors.")] + public void Run(ModData modData, string[] args) { - if (args.Length == 0) - { - Console.WriteLine("Usage: OpenRA.Lint.exe MOD [MAP] [--verbose]"); - return 0; - } + // HACK: The engine code assumes that Game.modData is set. + Game.modData = modData; try { Log.AddChannel("debug", null); Log.AddChannel("perf", null); - var options = args.Where(a => a.StartsWith("-")); - var mod = args.Where(a => !options.Contains(a)).First(); - var map = args.Where(a => !options.Contains(a)).Skip(1).FirstOrDefault(); - var verbose = options.Contains("-v") || options.Contains("--verbose"); - // bind some nonfatal error handling into FieldLoader, so we don't just *explode*. ObjectCreator.MissingTypeAction = s => EmitError("Missing Type: {0}".F(s)); FieldLoader.UnknownFieldAction = (s, f) => EmitError("FieldLoader: Missing field `{0}` on `{1}`".F(s, f.Name)); - AppDomain.CurrentDomain.AssemblyResolve += GlobalFileSystem.ResolveAssembly; - Game.InitializeSettings(Arguments.Empty); - Game.modData = new ModData(mod); - IEnumerable maps; - if (string.IsNullOrEmpty(map)) + if (args.Length < 2) { Game.modData.MapCache.LoadMaps(); maps = Game.modData.MapCache @@ -67,12 +58,11 @@ namespace OpenRA.Lint .Select(m => m.Map); } else - maps = new[] { new Map(map) }; + maps = new[] { new Map(args[1]) }; foreach (var testMap in maps) { - if (verbose) - Console.WriteLine("Testing map: {0}".F(testMap.Title)); + Console.WriteLine("Testing map: {0}".F(testMap.Title)); testMap.PreloadRules(); foreach (var customPassType in Game.modData.ObjectCreator @@ -95,15 +85,13 @@ namespace OpenRA.Lint if (errors > 0) { Console.WriteLine("Errors: {0}", errors); - return 1; + Environment.Exit(1); } - - return 0; } catch (Exception e) { EmitError("Failed with exception: {0}".F(e)); - return 1; + Environment.Exit(1); } } } diff --git a/OpenRA.sln b/OpenRA.sln index 36602c2f7a..b4de539a06 100644 --- a/OpenRA.sln +++ b/OpenRA.sln @@ -11,8 +11,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Editor", "OpenRA.Edi EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.TilesetBuilder", "OpenRA.TilesetBuilder\OpenRA.TilesetBuilder.csproj", "{1A8E50CC-EE32-4E57-8842-0C39C8EA7541}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Lint", "OpenRA.Lint\OpenRA.Lint.csproj", "{F9FA4D9F-2302-470A-8A07-6E37F488C124}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Utility", "OpenRA.Utility\OpenRA.Utility.csproj", "{F33337BE-CB69-4B24-850F-07D23E408DDF}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Renderer.Null", "OpenRA.Renderer.Null\OpenRA.Renderer.Null.csproj", "{0C4AEC1A-E7D5-4114-8CCD-3EEC82872981}" @@ -80,8 +78,6 @@ Global {00038B75-405B-44F5-8691-BD2546DBE224}.Debug|x86.Build.0 = Debug|x86 {1A8E50CC-EE32-4E57-8842-0C39C8EA7541}.Debug|x86.ActiveCfg = Debug|x86 {1A8E50CC-EE32-4E57-8842-0C39C8EA7541}.Debug|x86.Build.0 = Debug|x86 - {F9FA4D9F-2302-470A-8A07-6E37F488C124}.Debug|x86.ActiveCfg = Debug|x86 - {F9FA4D9F-2302-470A-8A07-6E37F488C124}.Debug|x86.Build.0 = Debug|x86 {F33337BE-CB69-4B24-850F-07D23E408DDF}.Debug|x86.ActiveCfg = Debug|x86 {F33337BE-CB69-4B24-850F-07D23E408DDF}.Debug|x86.Build.0 = Debug|x86 {0C4AEC1A-E7D5-4114-8CCD-3EEC82872981}.Debug|x86.ActiveCfg = Debug|x86 diff --git a/make.ps1 b/make.ps1 index c866bb7fc9..2dda5c5f35 100644 --- a/make.ps1 +++ b/make.ps1 @@ -114,14 +114,14 @@ elseif ($command -eq "dependencies") elseif ($command -eq "test") { echo "Testing mods..." - echo "OpenRA.Lint: checking Red Alert mod MiniYAML..." - ./OpenRA.Lint.exe --verbose ra - echo "OpenRA.Lint: checking Tiberian Dawn mod MiniYAML..." - ./OpenRA.Lint.exe --verbose cnc - echo "OpenRA.Lint: checking Dune 2000 mod MiniYAML..." - ./OpenRA.Lint.exe --verbose d2k - echo "OpenRA.Lint: checking Tiberian Sun mod MiniYAML..." - ./OpenRA.Lint.exe --verbose ts + echo "Testing Red Alert mod MiniYAML..." + ./OpenRA.Utility.exe ra --check-yaml + echo "Testing Tiberian Dawn mod MiniYAML..." + ./OpenRA.Utility.exe cnc --check-yaml + echo "Testing Dune 2000 mod MiniYAML..." + ./OpenRA.Utility.exe d2k --check-yaml + echo "Testing Tiberian Sun mod MiniYAML..." + ./OpenRA.Utility.exe ts --check-yaml } else {