Skip to content

When compiling dependencies of larger project the tpf is null #371

New issue

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

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

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions src/AXSharp.compiler/src/AXSharp.Compiler/AXSharpConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public string AxProjectFolder
/// <param name="directory">AX project directory</param>
/// <param name="newCompilerOptions">Compiler options.</param>
/// <returns>Ix configuration for given AX project.</returns>
public static AXSharpConfig UpdateAndGetAXSharpConfig(string directory, ICompilerOptions? newCompilerOptions = null)
public static AXSharpConfig UpdateAndGetAXSharpConfig(string directory, ICompilerOptions? newCompilerOptions = null, ICompilerOptions dependnantCompilerOptions = null)
{
var ixConfigFilePath = Path.Combine(directory, CONFIG_FILE_NAME);

Expand All @@ -99,6 +99,11 @@ public static AXSharpConfig UpdateAndGetAXSharpConfig(string directory, ICompile
{
AXSharpConfig.AxProjectFolder = directory;
OverridesFromCli(AXSharpConfig, newCompilerOptions);

if (dependnantCompilerOptions != null)
{
AXSharpConfig.TargetPlatfromMoniker = dependnantCompilerOptions.TargetPlatfromMoniker;
}
}

using (StreamWriter file = File.CreateText(ixConfigFilePath))
Expand All @@ -121,7 +126,7 @@ public static AXSharpConfig UpdateAndGetAXSharpConfig(string directory, ICompile
{
AXSharpConfig.AxProjectFolder = directory;
}

return AXSharpConfig;
}

Expand Down
12 changes: 9 additions & 3 deletions src/AXSharp.compiler/src/AXSharp.Compiler/AXSharpProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class AXSharpProject : IAXSharpProject
/// <param name="cliCompilerOptions">
/// Compiler options from CLI.
/// </param>
public AXSharpProject(AxProject axProject, IEnumerable<Type> builderTypes, Type targetProjectType, ICompilerOptions? cliCompilerOptions = null)
public AXSharpProject(AxProject axProject, IEnumerable<Type> builderTypes, Type targetProjectType, ICompilerOptions? cliCompilerOptions = null, ICompilerOptions? dependnantCompilerOptions = null)
{
AxProject = axProject;
CompilerOptions = AXSharpConfig.UpdateAndGetAXSharpConfig(axProject.ProjectFolder, cliCompilerOptions);
Expand Down Expand Up @@ -302,9 +302,15 @@ private void CompileProjectReferences(IEnumerable<IReference> referencedDependen
throw new FailedToCreateTargetProjectException(
"Target project is not a valid ITargetProject");

var project = new AXSharpProject(ax, BuilderTypes, targetProject.GetType());
var project = new AXSharpProject(ax, BuilderTypes, targetProject.GetType(), dependnantCompilerOptions: this.CompilerOptions);

if (project.CompilerOptions.TargetPlatfromMoniker == null)
{
project.CompilerOptions.TargetPlatfromMoniker = "ax";
Log.Logger.Warning("Target platform moniker should be set in the AXSharp.config.json file, passed as cli parameter. We deafault to 'ax'");
}

project.Generate();
project.Generate();

if(!string.IsNullOrEmpty(ixProjectReference.AxProjectFolder))
compiled.Add(ixProjectReference.AxProjectFolder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static bool IsNullableDateRelatedPrimitive(this IScalarTypeDeclaration ty
public static string CreateScalarInitializer(this IScalarTypeDeclaration scalar, string? targetPlatformMoniker)
{
if (targetPlatformMoniker == null)
{
{
throw new ArgumentNullException(nameof(targetPlatformMoniker), "Target platform moniker cannot be null.");
}

Expand Down
10 changes: 5 additions & 5 deletions src/AXSharp.compiler/src/ixc/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ private static string GetFullPath(string path)
}
}

private static AXSharpProject GenerateIxProject(Options o)
{
var axProjectFolder = string.IsNullOrEmpty(o.AxSourceProjectFolder)
private static AXSharpProject GenerateIxProject(Options options)
{
var axProjectFolder = string.IsNullOrEmpty(options.AxSourceProjectFolder)
? Environment.CurrentDirectory
: o.AxSourceProjectFolder;
: options.AxSourceProjectFolder;

Environment.CurrentDirectory = GetFullPath(axProjectFolder);

var ax = new AxProject(Environment.CurrentDirectory);
var project = new AXSharpProject(ax, new[] { typeof(CsOnlinerSourceBuilder), typeof(CsPlainSourceBuilder) },
typeof(CsProject), o);
typeof(CsProject), options);

var sw = new System.Diagnostics.Stopwatch();
sw.Start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"axopen-traversal": {
"commandName": "Project",
"workingDirectory": "C:\\W\\Develop\\gh\\inxton\\_axopen\\axopen\\src\\traversals\\apax\\"
"workingDirectory": "C:\\W\\Develop\\gh\\inxton\\ax\\axopen\\axopen\\src\\traversals\\apax\\"
},
"axopen-core": {
"commandName": "Project",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// AXSharp.Compiler.CsTests
// Copyright (c) 2023 MTS spol. s r.o., and Contributors. All Rights Reserved.
// Contributors: https://github.com/inxton/axsharp/graphs/contributors
// See the LICENSE file in the repository root for more information.
// https://github.com/inxton/axsharp/blob/dev/LICENSE
// Third party licenses: https://github.com/inxton/axsharp/blob/master/notices.md

using AXSharp.Compiler;

namespace AXSharp.CompilerTests;


public class CompilerTestOptions : ICompilerOptions
{
private string _outputProject = null;
public string? OutputProjectFolder
{
get
{
return _outputProject;
}
set
{
_outputProject = value;
}
}
public string? ProjectFile { get => null; set { } }
public bool UseBase { get => false; set { } }
public bool NoDependencyUpdate { get => false; set { } }
public bool IgnoreS7Pragmas { get => false; set { } }
public bool SkipDependencyCompilation { get => false; set { } }
public string TargetPlatfromMoniker { get; set; } = "ax";
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using AX.ST.Semantic.Pragmas;
using AX.ST.Syntax.Tree;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using AXSharp.CompilerTests;

namespace AXSharp.Compiler.Tests
{
Expand Down Expand Up @@ -65,7 +66,7 @@ public void should_generate_output_of_ix_project()

var actual = new AXSharpProject(axproject,
new[] { builder },
target);
target, new CompilerTestOptions(), new CompilerTestOptions());

actual.Generate();

Expand Down