Skip to content

ixd now allows for multiple project to be compiled at once in the same compilation #179

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
May 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/AXSharp.compiler/src/ixd/Helpers/YamlHelpers.cs
Original file line number Diff line number Diff line change
@@ -18,22 +18,22 @@ namespace AXSharp.ixc_doc.Helpers
{
public class YamlHelpers
{
public YamlHelpers(string projectPath)
public YamlHelpers()
{
PathToProjectFile = projectPath;

}
public string PathToProjectFile {get; set;}

// return all inherited members from class declaration
public string[] GetInheritedMembers(IClassDeclaration classDeclaration)
{
var extendedMethods = classDeclaration.GetMethodsFromExtendedTypes();
IEnumerable<IFieldDeclaration> extendedFields = new List<IFieldDeclaration>();

// TODO check, if IClassDeclaration in sufficient
var members = classDeclaration.GetAllExtendedTypes().ToList()
.Select(p => ((IClassDeclaration)p).Fields.Where(f => CanBeFieldInherited(f, classDeclaration, p))).ToList();
var members = classDeclaration.GetAllExtendedTypes().OfType<IClassDeclaration>().ToList()
.Select(p => p.Fields.Where(f => CanBeFieldInherited(f, classDeclaration, p))).ToList();

classDeclaration.GetAllExtendedTypes().ToList()
classDeclaration.GetAllExtendedTypes().OfType<IClassDeclaration>().ToList()
.Select(p => ((IClassDeclaration)p).Fields.Where(f => CanBeFieldInherited(f, classDeclaration, p))).ToList()
.ForEach(member => extendedFields = extendedFields.Concat(member));

6 changes: 3 additions & 3 deletions src/AXSharp.compiler/src/ixd/Mapper/CodeToYamlMapper.cs
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ public Item PopulateItem(IDeclaration declaration)
Namespace = declaration is INamespaceDeclaration ? Helpers.Helpers.GetBaseUid(declaration.FullyQualifiedName) : Helpers.Helpers.GetBaseUid(declaration.ContainingNamespace?.FullyQualifiedName),
Summary = _yh.GetComments(declaration.Location).summary,
Remarks = _yh.GetComments(declaration.Location).remarks,
Assemblies = new string[] { _yh.GetAssembly(_yh.PathToProjectFile) },
//Assemblies = new string[] { _yh.GetAssembly(_yh.PathToProjectFile) },


};
@@ -55,8 +55,8 @@ public Item PopulateItem(IClassDeclaration classDeclaration)
var implementedInterfaces = classDeclaration.GetAllImplementedInterfacesUniquely().Select(i => Helpers.Helpers.GetBaseUid(i));

List<IFieldDeclaration> extendedFields = new List<IFieldDeclaration>();
classDeclaration.GetAllExtendedTypes().ToList()
.Select(p => ((IClassDeclaration)p).Fields.Where(f => _yh.CanBeFieldInherited(f, classDeclaration, p))).ToList()
classDeclaration.GetAllExtendedTypes().OfType<IClassDeclaration>().ToList()
.Select(p => p.Fields.Where(f => _yh.CanBeFieldInherited(f, classDeclaration, p))).ToList()
.ForEach(list => extendedFields.Concat(list));

var item = PopulateItem((IDeclaration)classDeclaration);
3 changes: 2 additions & 1 deletion src/AXSharp.compiler/src/ixd/Options.cs
Original file line number Diff line number Diff line change
@@ -13,11 +13,12 @@ namespace AXSharp.ixc_doc
internal class Options : ICompilerOptions
{
[Option('x', "source-project-folder", Required = true, HelpText = "Simatic-ax project folder")]
public string? AxSourceProjectFolder { get; set; }
public IEnumerable<string> AxSourceProjectFolder { get; set; }

[Option('o', "output-project-folder", Required = true,
HelpText = "Output project folder where compiler emits result.")]
public string? OutputProjectFolder { get; set; }


}
}
30 changes: 24 additions & 6 deletions src/AXSharp.compiler/src/ixd/Program.cs
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@
using CliWrap;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using NuGet.Packaging;

const string Logo =
@"| \ /
@@ -50,12 +52,28 @@

void GenerateYamls(Options o)
{

//var multipleProjects = new List<AxProject>();
//foreach (var sf in Directory.EnumerateDirectories(o.AxSourceProjectFolder, "ctrl", SearchOption.AllDirectories))
//{
// multipleProjects.Add(new AxProject(sf));
//}

DeleteYamlFilesIfExists(o.OutputProjectFolder);

var axProject = new AxProject(o.AxSourceProjectFolder);
Console.WriteLine($"Compiling project {axProject.ProjectInfo.Name}...");
var projectSources = axProject.Sources.Select(p => (parseTree: STParser.ParseTextAsync(p).Result, source: p));

IList<(ISyntaxTree parseTree, SourceFileText source, AxProject project)> projectSources =
new List<(ISyntaxTree parseTree, SourceFileText source, AxProject project)>();

foreach (var source in o.AxSourceProjectFolder)
{
var axProject = new AxProject(source);
Console.WriteLine($"Compiling project {axProject.ProjectInfo.Name}...");
projectSources.AddRange(axProject.Sources.Select(p => (parseTree: STParser.ParseTextAsync(p).Result, source: p, axProject)));
}

//var axProject = new AxProject(o.AxSourceProjectFolder);
//Console.WriteLine($"Compiling project {axProject.ProjectInfo.Name}...");
//var projectSources = axProject.Sources.Select(p => (parseTree: STParser.ParseTextAsync(p).Result, source: p));

var toCompile = projectSources.Select(p => p.parseTree);

@@ -64,9 +82,9 @@ void GenerateYamls(Options o)
var semanticTree = compilation.GetSemanticTree();

//visit
var myNodeVisitor = new MyNodeVisitor(axProject);
var myNodeVisitor = new MyNodeVisitor();
var yamlSerializer = new YamlSerializer(o);
var treeWalker = new YamlBuilder(yamlSerializer, axProject.ProjectFile);
var treeWalker = new YamlBuilder(yamlSerializer);

semanticTree.GetRoot().Accept(myNodeVisitor, treeWalker);

4 changes: 2 additions & 2 deletions src/AXSharp.compiler/src/ixd/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@
},
"ixd-3": {
"commandName": "Project",
"commandLineArgs": "-x .\\src\\core\\ctrl\\ -o .\\docfx\\apictrl\\",
"workingDirectory": "C:\\MTS\\ix-ax\\AXSharp.framework\\"
"commandLineArgs": "-x C:\\W\\Develop\\gh\\ix-ax\\axopen\\src\\messaging\\ctrl C:\\W\\Develop\\gh\\ix-ax\\axopen\\src\\abstractions\\ctrl C:\\W\\Develop\\gh\\ix-ax\\axopen\\src\\data\\ctrl C:\\W\\Develop\\gh\\ix-ax\\axopen\\src\\core\\ctrl -o C:\\W\\Develop\\gh\\ix-ax\\axopen\\docfx\\apictrl\\",
"workingDirectory": "C:\\W\\Develop\\gh\\ix-ax\\axopen\\src\\data\\ctrl"
}
}
}
4 changes: 2 additions & 2 deletions src/AXSharp.compiler/src/ixd/Visitors/MyNodeVisitor.cs
Original file line number Diff line number Diff line change
@@ -24,11 +24,11 @@ namespace AXSharp.ixc_doc.Visitors
public partial class MyNodeVisitor : ISemanticNodeVisitor<IYamlBuiderVisitor>
{
public YamlSerializerHelper YamlHelper { get; set; }
public Compiler.AxProject axProject { get; set; }
//public Compiler.AxProject axProject { get; set; }

public MyNodeVisitor(Compiler.AxProject? axProject = null)
{
this.axProject = axProject;
//this.axProject = axProject;
YamlHelper = new YamlSerializerHelper();
}

4 changes: 2 additions & 2 deletions src/AXSharp.compiler/src/ixd/Visitors/YamlBuilder.cs
Original file line number Diff line number Diff line change
@@ -28,9 +28,9 @@ public class YamlBuilder : IYamlBuiderVisitor
private YamlHelpers _yh { get; set; }
private CodeToYamlMapper _mp { get; set; }
private List<NamespaceWrapper> NamespaceWrappers {get; set; } = new List<NamespaceWrapper>();
internal YamlBuilder(YamlSerializer serializer, string projectPath)
internal YamlBuilder(YamlSerializer serializer)
{
_yh = new YamlHelpers(projectPath);
_yh = new YamlHelpers();
_mp = new CodeToYamlMapper(_yh);
_s = serializer;
}
21 changes: 18 additions & 3 deletions src/AXSharp.compiler/src/ixd/YamlSerializer.cs
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
using System.Threading.Tasks;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization;
using Polly;

namespace AXSharp.ixc_doc
{
@@ -44,8 +45,8 @@ public string SchemaToYaml(YamlSchema model, string fileName)
stringBuilder.AppendLine(serializer.Serialize(model));



using (System.IO.StreamWriter file = new System.IO.StreamWriter(@$"{_options.OutputProjectFolder}\{fileName}.yml"))
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@$"{EnsureDirectory(_options.OutputProjectFolder)}\{fileName}.yml"))
{

file.WriteLine("## YamlMime:ManagedReference");
@@ -58,6 +59,20 @@ public string SchemaToYaml(YamlSchema model, string fileName)
return stringBuilder.ToString();
}


private string EnsureDirectory(string directory)
{
Policy
.Handle<IOException>()
.WaitAndRetry(5, a => TimeSpan.FromMilliseconds(500))
.Execute(() =>
{
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
});

return directory;
}
}
}