Skip to content

Commit

Permalink
[BUG] ixc does not parse apax versions correctly when comparing depen…
Browse files Browse the repository at this point in the history
…dencies in apax.yml and those installed in .apax folder (#266)

* Create draft PR for #265

* add semantic comparision of apax packages
- packages defined in apax.yml and .apax folder are now compared taking into accoun ^ and ~

* removes redownload flag when getting apax packages

---------

Co-authored-by: PTKu <PTKu@users.noreply.github.com>
Co-authored-by: Peter <61538034+PTKu@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 27, 2023
1 parent afa94a1 commit 061e7aa
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cake/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static void ProvisionProjectWideTools(BuildContext context)

context.ProcessRunner.Start(Helpers.GetApaxCommand(), new Cake.Core.IO.ProcessSettings()
{
Arguments = $" install -r -c",
Arguments = $" install",
WorkingDirectory = Path.Combine(context.ScrDir, "apax"),
RedirectStandardOutput = false,
RedirectStandardError = false,
Expand Down
48 changes: 46 additions & 2 deletions src/AXSharp.compiler/src/AXSharp.Compiler/AxProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,50 @@ private static IEnumerable<string> SearchForApaxFiles(string directory, int curr
return apaxFilesList;
}

static bool AreVersionsCompatible(string v1, string v2)
{
var versionA = ParseVersion(v1);
var versionB = ParseVersion(v2);

if (v1.StartsWith("^") || v2.StartsWith("^"))
{
if (versionA.Major == 0 || versionB.Major == 0)
{
// Compare both major and minor for versions starting with 0
return versionA.Major == versionB.Major && versionA.Minor == versionB.Minor;
}
else
{
// Compare only major for other versions
return versionA.Major == versionB.Major;
}
}
else if (v1.StartsWith("~") || v2.StartsWith("~"))
{
// Compare both major and minor for tilde versions
return versionA.Major == versionB.Major && versionA.Minor == versionB.Minor;
}
else
{
// Direct version comparison if no symbol is used
return versionA.Equals(versionB);
}
}

static Version ParseVersion(string versionString)
{
// Check for caret or tilde and remove it
if (versionString.StartsWith("^") || versionString.StartsWith("~"))
{
versionString = versionString.Substring(1);
}

// Parsing version string and creating a Version object
return Version.Parse(versionString);
}



private IEnumerable<object> GetProjectDependencies()
{
var dependencies = ProjectInfo.Dependencies ?? new Dictionary<string, string>();
Expand All @@ -184,7 +228,7 @@ private IEnumerable<object> GetProjectDependencies()
foreach (var dependency in dependencies)
{
var hasSuchProject =
nearByProjects.FirstOrDefault(p => p.Apax.Name == dependency.Key && p.Apax.Version == dependency.Value);
nearByProjects.FirstOrDefault(p => p.Apax.Name == dependency.Key && AreVersionsCompatible(p.Apax.Version, dependency.Value));
if (hasSuchProject != null)
{
var pathAXSharpConfig =
Expand All @@ -199,7 +243,7 @@ private IEnumerable<object> GetProjectDependencies()
foreach (var dependency in dependencies)
{
var dependencyWithCompanion = installedDependencies
.FirstOrDefault(p => p.Apax != null && p.Apax.Name == dependency.Key && p.Apax.Version == dependency.Value);
.FirstOrDefault(p => p.Apax != null && p.Apax.Name == dependency.Key && AreVersionsCompatible(p.Apax.Version, dependency.Value));


if (dependencyWithCompanion?.Companion != null)
Expand Down

0 comments on commit 061e7aa

Please sign in to comment.