Skip to content

Commit

Permalink
Merge pull request #68 from luni64/CompilerExplorer
Browse files Browse the repository at this point in the history
Compiler explorer
  • Loading branch information
luni64 authored Jan 31, 2022
2 parents bdf4233 + 8bcc01a commit ca2aa12
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 37 deletions.
4 changes: 2 additions & 2 deletions VisualTeensy/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

2 changes: 1 addition & 1 deletion vtCore/Implementation/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion vtCore/Implementation/Project Generators/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public static IReadOnlyList<ITask> 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));
Expand All @@ -39,6 +38,7 @@ public static IReadOnlyList<ITask> 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));
Expand Down
52 changes: 29 additions & 23 deletions vtCore/Implementation/Project Generators/Tasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,34 @@ public GenerateSettingsJson(IProject project, LibManager libManager, SetupData s

public Func<Task> action => async () =>
{
JObject json;
if (setupJsonFile.Exists)
{
using (StreamReader file = setupJsonFile.OpenText())
using (JsonTextReader reader = new JsonTextReader(file))
{
json = (JObject)JToken.ReadFrom(reader);
}
}
else
var cfg = project.selectedConfiguration;
if (cfg.isOk)
{
json = new JObject();
}

bool dirty = vcSettingsJson.generate(json);
JObject workspaceSettings;
if (setupJsonFile.Exists)
{
using (StreamReader file = setupJsonFile.OpenText())
using (JsonTextReader reader = new JsonTextReader(file))
{
workspaceSettings = (JObject)JToken.ReadFrom(reader);
}
}
else
{
workspaceSettings = new JObject();
}

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);
}
}
}

Expand Down Expand Up @@ -232,7 +238,7 @@ public GenerateMakefile(IProject project, LibManager libManager, SetupData setup

if (!file.Exists)
status = "Generate";
else if (String.Equals(oldMakefile.Substring(400), newMakefile.Substring(400)))
else if (oldMakefile.Length > 400 && newMakefile.Length > 400 && String.Equals(oldMakefile.Substring(400), newMakefile.Substring(400)))
status = "Up-To-Date";
else
status = "Overwrite";
Expand Down Expand Up @@ -359,7 +365,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)
Expand All @@ -380,10 +386,10 @@ public CloneCore(IProject project)
{
await project.gitInitAsync();
await coreLib.clone();
}
}
status = "OK";
};

GitLibrary coreLib;
IProject project;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,102 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using vtCore.Interfaces;

namespace vtCore
{
public static class vcSettingsJson
{
public static bool generate(JObject json)
{
bool dirty = false;
private static void addLib(string basePath, string lib, List<string> 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<string, string> 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<string>();

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;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions vtCore/Implementation/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; } =
Expand Down

0 comments on commit ca2aa12

Please sign in to comment.