Skip to content

Commit

Permalink
changed order of installing refs (#327)
Browse files Browse the repository at this point in the history
* 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 <blazej.kuhajda@mts.sk>
Co-authored-by: PTKu <61538034+PTKu@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 15, 2024
1 parent ce712fa commit af6e5f3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/AXSharp.compiler/src/AXSharp.Compiler/AXSharpProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISemanticAnalyzer>(), Compilation.Settings.Default).Result;
Expand Down Expand Up @@ -135,7 +138,7 @@ public void Generate()
}
}

TargetProject.ProvisionProjectStructure();
//TargetProject.ProvisionProjectStructure();
GenerateMetadata(compilationResult.Compilation);
TargetProject.GenerateResources();
TargetProject.GenerateCompanionData();
Expand Down Expand Up @@ -193,17 +196,17 @@ private static string EnsureFolder(string folder)

private IEnumerable<ISyntaxTree> 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<IEnumerable<string>>(File.ReadAllText(p)));


CompileProjectReferences(referencedDependencies);


var refParseTrees = dependencyMetadata.SelectMany(p => p)
.Select(s => STParser.ParseTextAsync(new StringText(s)).Result);

Expand All @@ -213,8 +216,7 @@ private IEnumerable<ISyntaxTree> GetReferences()
private static HashSet<string> compiled = new();

private void CompileProjectReferences(IEnumerable<IReference> referencedDependencies)
{
TargetProject.InstallAXSharpDependencies(AxProject.AXSharpReferences);
{
foreach (var ixProjectReference in AxProject.AXSharpReferences.OfType<AXSharpConfig>())
{

Expand Down
17 changes: 17 additions & 0 deletions src/AXSharp.compiler/src/AXSharp.Cs.Compiler/CsProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -315,6 +326,12 @@ public void InstallAXSharpDependencies(IEnumerable<object> 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)
{

Expand Down

0 comments on commit af6e5f3

Please sign in to comment.