From af6e5f3ba4c949e5ccdefb3d5029a65ac47d3b16 Mon Sep 17 00:00:00 2001 From: BlazejK Date: Thu, 15 Aug 2024 10:31:15 +0200 Subject: [PATCH] changed order of installing refs (#327) * changed order of installing refs * Add EnsureOutputFolder method and integrate it into EnsureCsProjFile Added a new private method `EnsureOutputFolder` that checks if the output folder specified by `AxSharpProject.OutputFolder` exists, and if not, creates it. This method then returns the path to the output folder. Modified the `EnsureCsProjFile` method to call the newly added `EnsureOutputFolder` method. This ensures that the output folder is created before proceeding with the rest of the method's logic, preventing potential errors related to missing directories. --------- Co-authored-by: blazej.kuhajda Co-authored-by: PTKu <61538034+PTKu@users.noreply.github.com> --- .../src/AXSharp.Compiler/AXSharpProject.cs | 16 +++++++++------- .../src/AXSharp.Cs.Compiler/CsProject.cs | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/AXSharp.compiler/src/AXSharp.Compiler/AXSharpProject.cs b/src/AXSharp.compiler/src/AXSharp.Compiler/AXSharpProject.cs index 3a8de01d..b93ab943 100644 --- a/src/AXSharp.compiler/src/AXSharp.Compiler/AXSharpProject.cs +++ b/src/AXSharp.compiler/src/AXSharp.Compiler/AXSharpProject.cs @@ -89,8 +89,11 @@ public void Generate() var projectSources = AxProject.Sources.Select(p => (parseTree: STParser.ParseTextAsync(p).Result, source: p)); + TargetProject.ProvisionProjectStructure(); + var refParseTrees = GetReferences(); + var toCompile = refParseTrees.Concat(projectSources.Select(p => p.parseTree)); var compilationResult = Compilation.Create(toCompile, new List(), Compilation.Settings.Default).Result; @@ -135,7 +138,7 @@ public void Generate() } } - TargetProject.ProvisionProjectStructure(); + //TargetProject.ProvisionProjectStructure(); GenerateMetadata(compilationResult.Compilation); TargetProject.GenerateResources(); TargetProject.GenerateCompanionData(); @@ -193,17 +196,17 @@ private static string EnsureFolder(string folder) private IEnumerable GetReferences() { + TargetProject.InstallAXSharpDependencies(AxProject.AXSharpReferences); + var referencedDependencies = TargetProject.LoadReferences(); + + CompileProjectReferences(referencedDependencies); var dependencyMetadata = referencedDependencies .Where(p => p.IsIxDependency) .Select(p => p.MetadataPath) .Select(p => JsonConvert.DeserializeObject>(File.ReadAllText(p))); - - CompileProjectReferences(referencedDependencies); - - var refParseTrees = dependencyMetadata.SelectMany(p => p) .Select(s => STParser.ParseTextAsync(new StringText(s)).Result); @@ -213,8 +216,7 @@ private IEnumerable GetReferences() private static HashSet compiled = new(); private void CompileProjectReferences(IEnumerable referencedDependencies) - { - TargetProject.InstallAXSharpDependencies(AxProject.AXSharpReferences); + { foreach (var ixProjectReference in AxProject.AXSharpReferences.OfType()) { diff --git a/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/CsProject.cs b/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/CsProject.cs index bdb04de1..238847d1 100644 --- a/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/CsProject.cs +++ b/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/CsProject.cs @@ -83,10 +83,21 @@ private static string GetExecutingAssemblyPath() } + private string EnsureOutputFolder() + { + if (!Directory.Exists(AxSharpProject.OutputFolder)) + { + Directory.CreateDirectory(AxSharpProject.OutputFolder); + } + + return AxSharpProject.OutputFolder; + } + private void EnsureCsProjFile() { if (AxSharpProject.AxProject.ProjectInfo.Name != null) { + EnsureOutputFolder(); string expectedCsProjFileFullPath = string.Empty; string expectedCsProjFile = string.Empty; if (string.IsNullOrEmpty(this.AxSharpProject.CompilerOptions?.ProjectFile)) @@ -315,6 +326,12 @@ public void InstallAXSharpDependencies(IEnumerable dependencies) if (compilerOptionsProjectFile != null) { var dependent = Path.Combine(this.AxSharpProject.OutputFolder, compilerOptionsProjectFile); + + if (!File.Exists(dependent)) + { + throw new Exception("Missing dependency file."); + } + foreach (var dependency in dependencies) {