diff --git a/AspectedRouting.sln.DotSettings.user b/AspectedRouting.sln.DotSettings.user index 3f86a8f..74e9617 100644 --- a/AspectedRouting.sln.DotSettings.user +++ b/AspectedRouting.sln.DotSettings.user @@ -1,8 +1,8 @@  - <SessionState ContinuousTestingIsOn="False" ContinuousTestingMode="0" FrameworkVersion="{x:Null}" IsLocked="False" Name="ParseFunction_Duration_TotalMinutes" PlatformMonoPreference="{x:Null}" PlatformType="{x:Null}" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> + <SessionState ContinuousTestingMode="0" Name="ParseFunction_Duration_TotalMinutes" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> <Project Location="/home/pietervdvn/werk/AspectedRouting/AspectedRouting.Test" Presentation="&lt;AspectedRouting.Test&gt;" /> </SessionState> - <SessionState ContinuousTestingIsOn="False" ContinuousTestingMode="0" FrameworkVersion="{x:Null}" IsLocked="False" Name="Integration_TestExamples" PlatformMonoPreference="{x:Null}" PlatformType="{x:Null}" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> + <SessionState ContinuousTestingMode="0" IsActive="True" Name="Integration_TestExamples" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> <TestAncestor> <TestId>xUnit::A1309041-8AAE-42D7-A886-94C9FFC6A28C::.NETCoreApp,Version=v3.1::AspectedRouting.Test.ExamplesTest.Integration_TestExamples</TestId> </TestAncestor> diff --git a/AspectedRouting/IO/itinero1/LuaPrinter1.cs b/AspectedRouting/IO/itinero1/LuaPrinter1.cs index 94f6280..dab9e3f 100644 --- a/AspectedRouting/IO/itinero1/LuaPrinter1.cs +++ b/AspectedRouting/IO/itinero1/LuaPrinter1.cs @@ -48,7 +48,7 @@ namespace AspectedRouting.IO.itinero1 var header = new List { - $"-- Itinero 1.0-profile, generated by AspectedRouting on {DateTime.Now:s}", + $"-- Itinero 1.0-profile, generated by AspectedRouting. Last source file change is {_profile.LastChange:s}", $"name = \"{_profile.Name}\"", "normalize = false", "vehicle_type = {" + string.Join(", ", _profile.VehicleTyps.Select(s => "\"" + s + "\"")) + "}", diff --git a/AspectedRouting/IO/itinero2/LuaPrinter2.cs b/AspectedRouting/IO/itinero2/LuaPrinter2.cs index a7b2cc9..8256833 100644 --- a/AspectedRouting/IO/itinero2/LuaPrinter2.cs +++ b/AspectedRouting/IO/itinero2/LuaPrinter2.cs @@ -32,6 +32,7 @@ namespace AspectedRouting.IO.itinero2 private readonly Context _context; private readonly List _aspectTests; private readonly IEnumerable _behaviourTestSuite; + private readonly DateTime _lastChangeTime; private readonly LuaSkeleton.LuaSkeleton _skeleton; private readonly LuaParameterPrinter _parameterPrinter; @@ -39,7 +40,8 @@ namespace AspectedRouting.IO.itinero2 public LuaPrinter2(ProfileMetaData profile, string behaviourName, Context context, - List aspectTests, IEnumerable behaviourTestSuite) + List aspectTests, IEnumerable behaviourTestSuite, + DateTime lastChangeTime) { _skeleton = new LuaSkeleton.LuaSkeleton(context); _profile = profile; @@ -47,6 +49,7 @@ namespace AspectedRouting.IO.itinero2 _context = context; _aspectTests = aspectTests; _behaviourTestSuite = behaviourTestSuite; + _lastChangeTime = lastChangeTime; _parameterPrinter = new LuaParameterPrinter(_profile, _skeleton); } @@ -56,7 +59,7 @@ namespace AspectedRouting.IO.itinero2 new List { $"name = \"{_profile.Name}.{_behaviourName}\"", - $"generationDate = \"{DateTime.Now:s}\"", + $"generationDate = \"{_lastChangeTime:s}\"", $"description = \"{_profile.Description}\"" }; diff --git a/AspectedRouting/IO/jsonParser/JsonParser.ParseAspectProfile.cs b/AspectedRouting/IO/jsonParser/JsonParser.ParseAspectProfile.cs index 0b8acc8..d007c34 100644 --- a/AspectedRouting/IO/jsonParser/JsonParser.ParseAspectProfile.cs +++ b/AspectedRouting/IO/jsonParser/JsonParser.ParseAspectProfile.cs @@ -34,7 +34,7 @@ namespace AspectedRouting.IO.jsonParser } } - public static ProfileMetaData ProfileFromJson(Context c, string json, FileInfo f) + public static ProfileMetaData ProfileFromJson(Context c, string json, FileInfo f, DateTime lastChange) { try { @@ -45,7 +45,7 @@ namespace AspectedRouting.IO.jsonParser // this is an aspect } - return ParseProfile(doc.RootElement, c, f); + return ParseProfile(doc.RootElement, c, f, lastChange); } catch (Exception e) { @@ -63,7 +63,7 @@ namespace AspectedRouting.IO.jsonParser } - private static ProfileMetaData ParseProfile(this JsonElement e, Context context, FileInfo filepath) + private static ProfileMetaData ParseProfile(this JsonElement e, Context context, FileInfo filepath, DateTime lastChange) { if (!e.TryGetProperty("speed", out _)) { @@ -141,6 +141,11 @@ namespace AspectedRouting.IO.jsonParser profiles[profile.Name] = ParseParameters(profile.Value); } + if (lastChange < filepath.LastWriteTimeUtc) + { + lastChange = filepath.LastWriteTimeUtc; + } + return new ProfileMetaData( name, e.Get("description"), @@ -153,7 +158,8 @@ namespace AspectedRouting.IO.jsonParser oneway, speed, weights, - metadata + metadata, + lastChange ); } diff --git a/AspectedRouting/Language/Expression/ProfileMetaData.cs b/AspectedRouting/Language/Expression/ProfileMetaData.cs index 90a2941..d2751b5 100644 --- a/AspectedRouting/Language/Expression/ProfileMetaData.cs +++ b/AspectedRouting/Language/Expression/ProfileMetaData.cs @@ -29,12 +29,16 @@ namespace AspectedRouting.Language.Expression public IExpression Oneway { get; } public IExpression Speed { get; } public Dictionary Priority { get; } + /** + * Moment of last change of any upstream file + */ + public DateTime LastChange { get; } public ProfileMetaData(string name, string description, string author, string filename, List vehicleTyps, Dictionary defaultParameters, Dictionary> behaviours, IExpression access, IExpression oneway, IExpression speed, - Dictionary priority, List metadata) + Dictionary priority, List metadata, DateTime lastChange) { Name = name; Description = description; @@ -46,6 +50,7 @@ namespace AspectedRouting.Language.Expression Speed = speed.Optimize(); Priority = priority; Metadata = metadata; + LastChange = lastChange; DefaultParameters = defaultParameters; Behaviours = behaviours; } diff --git a/AspectedRouting/Program.cs b/AspectedRouting/Program.cs index 8ccf0d2..9a6bd55 100644 --- a/AspectedRouting/Program.cs +++ b/AspectedRouting/Program.cs @@ -30,9 +30,7 @@ namespace AspectedRouting var testPath = testFileNames.FindTest(testName); AspectTestSuite tests = null; if (!string.IsNullOrEmpty(testPath) && File.Exists(testPath)) - { tests = AspectTestSuite.FromString(aspect, File.ReadAllText(testPath)); - } aspects.Add((aspect, tests)); } @@ -44,33 +42,25 @@ namespace AspectedRouting { var testPaths = testFileNames.Where(nm => nm.EndsWith(testName)).ToList(); if (testPaths.Count > 1) - { Console.WriteLine("[WARNING] Multiple tests found for " + testName + ", using only one arbitrarily"); - } - if (testPaths.Count > 0) - { - return testPaths.First(); - } + if (testPaths.Count > 0) return testPaths.First(); return null; } private static List<(ProfileMetaData profile, List profileTests)> ParseProfiles( - IEnumerable jsonFiles, IReadOnlyCollection testFiles, Context context) + IEnumerable jsonFiles, IReadOnlyCollection testFiles, Context context, DateTime lastChange) { var result = new List<(ProfileMetaData profile, List profileTests)>(); foreach (var jsonFile in jsonFiles) - { try { var profile = - JsonParser.ProfileFromJson(context, File.ReadAllText(jsonFile), new FileInfo(jsonFile)); - if (profile == null) - { - continue; - } + JsonParser.ProfileFromJson(context, File.ReadAllText(jsonFile), new FileInfo(jsonFile), + lastChange); + if (profile == null) continue; profile.SanityCheckProfile(context); @@ -97,7 +87,6 @@ namespace AspectedRouting // PrintError(jsonFile, e); throw new Exception("In the file " + jsonFile, e); } - } return result; } @@ -110,10 +99,7 @@ namespace AspectedRouting { Console.Write(profile.Name + "." + behaviour + " > "); var read = Console.ReadLine(); - if (read == null) - { - return; // End of stream has been reached - } + if (read == null) return; // End of stream has been reached if (read == "") { @@ -121,17 +107,11 @@ namespace AspectedRouting continue; } - if (read.Equals("quit")) - { - return; - } + if (read.Equals("quit")) return; if (read.Equals("clear")) { - for (int i = 0; i < 80; i++) - { - Console.WriteLine(); - } + for (var i = 0; i < 80; i++) Console.WriteLine(); continue; } @@ -171,10 +151,7 @@ namespace AspectedRouting var tags = new Dictionary(); foreach (var str in tagsRaw) { - if (str == "") - { - continue; - } + if (str == "") continue; var strSplit = str.Split("="); var k = strSplit[0].Trim(); @@ -213,10 +190,7 @@ namespace AspectedRouting foreach (var (key, values) in profile.AllExpressions(context).PossibleTags()) { var vs = "*"; - if (values.Any()) - { - vs = string.Join(", ", values); - } + if (values.Any()) vs = string.Join(", ", values); Console.WriteLine(key + ": " + vs); } @@ -224,27 +198,21 @@ namespace AspectedRouting Console.WriteLine("\n\n\n------------------------"); } - static void Main(string[] args) + private static void Main(string[] args) { var errMessage = MainWithError(args); - if (errMessage != null) - { - Console.WriteLine(errMessage); - } + if (errMessage != null) Console.WriteLine(errMessage); } - public static string MainWithError(string[] args){ - if (args.Length < 2) - { + + public static string MainWithError(string[] args) + { + if (args.Length < 2) return "Usage: "; - } var inputDir = args[0]; var outputDir = args[1]; - if (!Directory.Exists(outputDir)) - { - Directory.CreateDirectory(outputDir); - } + if (!Directory.Exists(outputDir)) Directory.CreateDirectory(outputDir); MdPrinter.GenerateHelpText(outputDir + "helpText.md"); @@ -257,10 +225,7 @@ namespace AspectedRouting foreach (var test in tests) { - if (test.EndsWith(".test.csv") || test.EndsWith(".behaviour_test.csv")) - { - continue; - } + if (test.EndsWith(".test.csv") || test.EndsWith(".behaviour_test.csv")) continue; throw new ArgumentException( $"Invalid name for csv file ${test}, should end with either '.behaviour_test.csv' or '.test.csv'"); @@ -270,41 +235,35 @@ namespace AspectedRouting var aspects = ParseAspects(files, tests, context); - foreach (var (aspect, _) in aspects) + foreach (var (aspect, _) in aspects) context.AddFunction(aspect.Name, aspect); + + var lastChange = DateTime.UnixEpoch; + foreach (var file in files) { - context.AddFunction(aspect.Name, aspect); + var time = new FileInfo(file).LastWriteTimeUtc; + if (lastChange < time) + { + lastChange = time; + } } - var profiles = ParseProfiles(files, tests, context); + var profiles = ParseProfiles(files, tests, context, lastChange); // With everything parsed and typechecked, time for tests var testsOk = true; foreach (var (aspect, t) in aspects) - { if (t == null) - { Console.WriteLine($"[{aspect.Name}] WARNING: no tests found: please add {aspect.Name}.test.csv"); - } else - { testsOk &= t.Run(); - } - } foreach (var (profile, profileTests) in profiles) - { - foreach (var test in profileTests) - { - testsOk &= test.Run(context); - } - } + foreach (var test in profileTests) + testsOk &= test.Run(context); - if (!testsOk) - { - return "Some tests failed, quitting now without generating output"; - } + if (!testsOk) return "Some tests failed, quitting now without generating output"; foreach (var (profile, profileTests) in profiles) { @@ -324,14 +283,13 @@ namespace AspectedRouting behaviourName, context, aspectTests, - profileTests.Where(testsSuite => testsSuite.BehaviourName == behaviourName) + profileTests.Where(testsSuite => testsSuite.BehaviourName == behaviourName), + lastChange ).ToLua(); - if(!Directory.Exists($"{outputDir}/itinero2/")) - { + if (!Directory.Exists($"{outputDir}/itinero2/")) Directory.CreateDirectory($"{outputDir}/itinero2/"); - } File.WriteAllText( - $"{outputDir}/itinero2/{profile.Name}.{behaviourName}.lua", + $"{outputDir}/itinero2/{profile.Name}.{behaviourName}.lua", lua2behaviour); } } @@ -341,15 +299,11 @@ namespace AspectedRouting ); if (!args.Contains("--no-repl")) - { Repl(context, profiles .Select(p => p.profile) .ToDictionary(p => p.Name, p => p)); - } else - { Console.WriteLine("Not starting REPL as --no-repl is specified"); - } return null; } }