Skip to content
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

[BUG] ixc does not parse apax versions correctly when comparing dependencies in apax.yml and those installed in .apax folder #266

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
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