From e642af30efb802ff69b32630367c5758d47f811a Mon Sep 17 00:00:00 2001 From: luni64 <12611497+luni64@users.noreply.github.com> Date: Mon, 29 Nov 2021 13:10:44 +0100 Subject: [PATCH 1/2] Fix includ path issue in c_cpp_proporties.json on first generation --- .../Project Generators/CodeGenerator.cs | 2 +- .../Project Generators/Tasks.cs | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/vtCore/Implementation/Project Generators/CodeGenerator.cs b/vtCore/Implementation/Project Generators/CodeGenerator.cs index 18dd279..33c6af6 100644 --- a/vtCore/Implementation/Project Generators/CodeGenerator.cs +++ b/vtCore/Implementation/Project Generators/CodeGenerator.cs @@ -17,7 +17,6 @@ public static IReadOnlyList getTasks(IProject project, LibManager libMana tasks.Add(new GenerateSettings(project)); tasks.Add(new GenerateMakefile(project, libManager, setup)); tasks.Add(new GenerateTasks(project, setup)); - tasks.Add(new GenerateIntellisense(project, libManager, setup)); // needs to be added after libraries (checks for existence) if (project.buildSystem == BuildSystem.makefile) { tasks.Add(new CopyLibs(project)); @@ -39,6 +38,7 @@ public static IReadOnlyList getTasks(IProject project, LibManager libMana { tasks.Add(new GenerateSettingsJson(project, libManager, setup)); } + tasks.Add(new GenerateIntellisense(project, libManager, setup)); // needs to be added after libraries (checks for existence) tasks.Add(new CleanBinaries(project)); tasks.Add(new GenerateSketch(project)); diff --git a/vtCore/Implementation/Project Generators/Tasks.cs b/vtCore/Implementation/Project Generators/Tasks.cs index e8c6083..6312f4e 100644 --- a/vtCore/Implementation/Project Generators/Tasks.cs +++ b/vtCore/Implementation/Project Generators/Tasks.cs @@ -137,10 +137,10 @@ public GenerateSettingsJson(IProject project, LibManager libManager, SetupData s { JObject json; if (setupJsonFile.Exists) - { + { using (StreamReader file = setupJsonFile.OpenText()) using (JsonTextReader reader = new JsonTextReader(file)) - { + { json = (JObject)JToken.ReadFrom(reader); } } @@ -148,7 +148,7 @@ public GenerateSettingsJson(IProject project, LibManager libManager, SetupData s { json = new JObject(); } - + bool dirty = vcSettingsJson.generate(json); if (dirty) @@ -232,10 +232,10 @@ public GenerateMakefile(IProject project, LibManager libManager, SetupData setup if (!file.Exists) status = "Generate"; - else if (String.Equals(oldMakefile.Substring(400), newMakefile.Substring(400))) - status = "Up-To-Date"; - else - status = "Overwrite"; + else if (oldMakefile.Length > 400 && newMakefile.Length > 400 && String.Equals(oldMakefile.Substring(400), newMakefile.Substring(400))) + status = "Up-To-Date"; + else + status = "Overwrite"; } public Func action => async () => @@ -359,7 +359,7 @@ public CopyCore(IProject project) class CloneCore : ITask { public string title => $"Clone teensyduino core"; - public string description { get; } + public string description { get; } public string status { get; private set; } public CloneCore(IProject project) @@ -380,10 +380,10 @@ public CloneCore(IProject project) { await project.gitInitAsync(); await coreLib.clone(); - } + } status = "OK"; }; - + GitLibrary coreLib; IProject project; } From 8bcc01a415e6bc360e431cf6c98e056ee18eeed0 Mon Sep 17 00:00:00 2001 From: luni64 <12611497+luni64@users.noreply.github.com> Date: Mon, 31 Jan 2022 19:55:26 +0100 Subject: [PATCH 2/2] Support for the CompilerExplorer --- VisualTeensy/Properties/AssemblyInfo.cs | 4 +- vtCore/Implementation/Configuration.cs | 2 +- .../Project Generators/Tasks.cs | 44 +++++---- .../vcSettingsJson/vcSettingsJson.cs | 92 +++++++++++++++++-- vtCore/Implementation/Strings.cs | 4 +- 5 files changed, 114 insertions(+), 32 deletions(-) diff --git a/VisualTeensy/Properties/AssemblyInfo.cs b/VisualTeensy/Properties/AssemblyInfo.cs index 668fe1a..a6a8f87 100644 --- a/VisualTeensy/Properties/AssemblyInfo.cs +++ b/VisualTeensy/Properties/AssemblyInfo.cs @@ -50,7 +50,7 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0")] -[assembly: AssemblyFileVersion("1.4.0")] +[assembly: AssemblyVersion("1.5.0")] +[assembly: AssemblyFileVersion("1.5.0")] [assembly: NeutralResourcesLanguage("en")] diff --git a/vtCore/Implementation/Configuration.cs b/vtCore/Implementation/Configuration.cs index 722e9e3..ef57108 100644 --- a/vtCore/Implementation/Configuration.cs +++ b/vtCore/Implementation/Configuration.cs @@ -161,7 +161,7 @@ public void parseBoardsTxt(string bt) ProjectTransferData.vtBoard tmp = new ProjectTransferData.vtBoard(selectedBoard); // boards = BoardsTxt.parse(bt ?? boardTxtPath).Where(b => b.core == "teensy3" || b.core == "teensy4").ToList(); - boards = BoardsTxt.parse(btp).Where(b => b.core == "teensy3" || b.core == "teensy4").ToList(); + boards = BoardsTxt.parse(btp)/*.Where(b => b.core == "teensy3" || b.core == "teensy4")*/.ToList(); setBoardOptions(tmp); } diff --git a/vtCore/Implementation/Project Generators/Tasks.cs b/vtCore/Implementation/Project Generators/Tasks.cs index 6312f4e..ddc73e6 100644 --- a/vtCore/Implementation/Project Generators/Tasks.cs +++ b/vtCore/Implementation/Project Generators/Tasks.cs @@ -135,28 +135,34 @@ public GenerateSettingsJson(IProject project, LibManager libManager, SetupData s public Func action => async () => { - JObject json; - if (setupJsonFile.Exists) + var cfg = project.selectedConfiguration; + if (cfg.isOk) { - using (StreamReader file = setupJsonFile.OpenText()) - using (JsonTextReader reader = new JsonTextReader(file)) + JObject workspaceSettings; + if (setupJsonFile.Exists) { - json = (JObject)JToken.ReadFrom(reader); + using (StreamReader file = setupJsonFile.OpenText()) + using (JsonTextReader reader = new JsonTextReader(file)) + { + workspaceSettings = (JObject)JToken.ReadFrom(reader); + } + } + else + { + workspaceSettings = new JObject(); } - } - else - { - json = new JObject(); - } - bool dirty = vcSettingsJson.generate(json); - if (dirty) - { - using (TextWriter outFile = setupJsonFile.CreateText()) + + bool dirty = vcSettingsJson.generate(workspaceSettings, cfg, project); + + if (dirty) { - var jsonString = JsonConvert.SerializeObject(json, Formatting.Indented); - outFile.Write(jsonString); + using (TextWriter outFile = setupJsonFile.CreateText()) + { + var jsonString = JsonConvert.SerializeObject(workspaceSettings, Formatting.Indented); + outFile.Write(jsonString); + } } } @@ -233,9 +239,9 @@ public GenerateMakefile(IProject project, LibManager libManager, SetupData setup if (!file.Exists) status = "Generate"; else if (oldMakefile.Length > 400 && newMakefile.Length > 400 && String.Equals(oldMakefile.Substring(400), newMakefile.Substring(400))) - status = "Up-To-Date"; - else - status = "Overwrite"; + status = "Up-To-Date"; + else + status = "Overwrite"; } public Func action => async () => diff --git a/vtCore/Implementation/Project Generators/vcSettingsJson/vcSettingsJson.cs b/vtCore/Implementation/Project Generators/vcSettingsJson/vcSettingsJson.cs index 2dc3a20..46bc724 100644 --- a/vtCore/Implementation/Project Generators/vcSettingsJson/vcSettingsJson.cs +++ b/vtCore/Implementation/Project Generators/vcSettingsJson/vcSettingsJson.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; using vtCore.Interfaces; @@ -10,19 +11,94 @@ namespace vtCore { public static class vcSettingsJson { - public static bool generate(JObject json) - { - bool dirty = false; + private static void addLib(string basePath, string lib, List includes) + { + string p = Path.Combine(basePath, lib, "src"); + if (Directory.Exists(p)) + { + } + + if (Directory.Exists(Path.Combine(basePath, lib, "src"))) // library format 1.5, only src is searched for includes + { + includes.Add("-I'" + lib + "/src'"); + } + else // old library format, base folder and utility folder are searched for includes + { + includes.Add("-I'" + lib + "'"); + + var utiliyPath = lib + "/utility"; + if (Directory.Exists(Path.Combine(basePath, lib, "utility"))) + includes.Add("-I'" + lib + "/utility'"); + } + } + + private static string getCfgOption(Dictionary options, string prefix, string key) + { + var option = options.FirstOrDefault(o => o.Key == key).Value; + return option != null ? prefix + option : null; + } + + public static bool generate(JObject json, IConfiguration cfg, IProject prj) + { + var flags = new List(); - if (!json.ContainsKey("task.autoDetect")) + // core files + flags.Add($"-I'{prj.path}/src'".Replace('\\', '/')); + if (cfg.coreStrategy == LibStrategy.link) + { + flags.Add($"-I'{cfg.coreBase.path}/cores/{cfg.selectedBoard.core}'".Replace('\\', '/')); + } + else + { + flags.Add($"-I'{prj.path}/cores/{cfg.selectedBoard.core}'".Replace('\\', '/')); + } + + // inlcude path shard libraries + foreach (var lib in cfg.sharedLibs) { - json.Add("task.autoDetect", "off"); - dirty = true; + string basePath = lib.sourceUri.LocalPath.Replace('\\', '/'); + addLib("", basePath, flags); } - // more settings.. - return dirty; + // include path local libraries + foreach (var lib in cfg.localLibs) + { + string basePath = $"{prj.path}/lib/{lib.targetFolder}".Replace('\\', '/'); + addLib(prj.path, basePath, flags); + } + + // Compiler switches ---------------------------------------------------------- + var brdOpt = cfg.selectedBoard?.getAllOptions(); + + // defines + foreach (var defEntry in brdOpt.Where(o => o.Key == "build.flags.defs")) + { + flags.Add(defEntry.Value.Trim()); + } + + // teensyduino flags + flags.Add(getCfgOption(brdOpt, "-DF_CPU=", "build.fcpu")); + flags.Add(getCfgOption(brdOpt, "-D", "build.usbtype")); + flags.Add(getCfgOption(brdOpt, "-DLAYOUT_", "build.keylayout")); + flags.Add("-DARDUINO_" + brdOpt.FirstOrDefault(o => o.Key == "build.board").Value); + flags.Add("-DARDUINO=10815"); + + // compiler flags + flags.Add(brdOpt.FirstOrDefault(o => o.Key == "build.flags.cpp").Value); + flags.Add(brdOpt.FirstOrDefault(o => o.Key == "build.flags.c").Value); + flags.Add(brdOpt.FirstOrDefault(o => o.Key == "build.flags.cpu").Value); + flags.Add(brdOpt.FirstOrDefault(o => o.Key == "build.flags.optimize").Value); + flags.Add(brdOpt.FirstOrDefault(o => o.Key == "build.flags.common").Value); + flags.Add(brdOpt.FirstOrDefault(o => o.Key == "build.flags.deps").Value); + + // settings.json + json["task.autoDetect"] = "off"; + json["compiler-explorer.url"] = "http://localhost:10240"; + json["compiler-explorer.compiler"] = "g54"; + json["compiler-explorer.options"] = JToken.FromObject(flags); + + return true; } } } diff --git a/vtCore/Implementation/Strings.cs b/vtCore/Implementation/Strings.cs index 8e2aaf5..b10ce03 100644 --- a/vtCore/Implementation/Strings.cs +++ b/vtCore/Implementation/Strings.cs @@ -12,8 +12,8 @@ public static class Strings "void loop()\n" + "{\n" + - " digitalWriteFast(LED_BUILTIN,!digitalReadFast(LED_BUILTIN));\n" + - " delay(500);\n" + + " digitalToggleFast(LED_BUILTIN);\n" + + " delay(250);\n" + "}\n"; public static string sketchIno { get; } =