Skip to content

Commit

Permalink
try fixing linux run
Browse files Browse the repository at this point in the history
  • Loading branch information
obligaron committed Oct 29, 2024
1 parent d394632 commit d148c0f
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.IO;
using Reqnroll.TestProjectGenerator;
using Reqnroll.TestProjectGenerator.Data;

namespace Reqnroll.TestProjectGenerator.Cli
Expand All @@ -17,8 +15,6 @@ public class GenerateSolutionParams

public TargetFramework TargetFramework { get; set; }

public string SdkVersion { get; set; }

public ProjectFormat ProjectFormat { get; set; }

public ConfigurationFormat ConfigurationFormat { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ Version GetReqnrollVersion(string reqnrollNuGetVersion)
//Remove local NuGet source
sd.NuGetSources.Clear();

sd.SdkVersion = generateSolutionParams.SdkVersion;

d.WriteSolutionToDisk();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ public class CompileResult(int exitCode, string output)

public string Output { get; } = output;

public string ErrorLines =>
string.Join(
Environment.NewLine,
Regex.Split(Output, @"\r?\n").Where(l => l.Contains("error")));
public string ErrorLines
{
get
{
var errors = string.Join(
Environment.NewLine,
Regex.Split(Output, @"\r?\n").Where(l => l.Contains("error")));
if (string.IsNullOrEmpty(errors))
return Output;
return errors;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using Reqnroll.TestProjectGenerator.FilesystemWriter;

namespace Reqnroll.TestProjectGenerator.Data
{
Expand All @@ -21,8 +20,6 @@ public Solution(string name)

public List<SolutionFile> Files { get; } = new List<SolutionFile>();

public string SdkVersion { get; set; }

public void AddProject(Project project)
{
_projects.Add(project ?? throw new ArgumentNullException(nameof(project)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Reqnroll.TestProjectGenerator.Data;
using System;
using System.Collections.Concurrent;
using System.IO;

Expand All @@ -8,14 +9,16 @@ public class CacheAndCopyCommandBuilder : CommandBuilder
{
private const string TemplateName = "TName";
private readonly CommandBuilder _baseCommandBuilder;
private readonly TargetFramework _targetFramework;
private readonly string _targetPath;
private readonly string _nameToReplace;
private static readonly ConcurrentDictionary<string, object> LockObjects = new();

public CacheAndCopyCommandBuilder(IOutputWriter outputWriter, CommandBuilder baseCommandBuilder, string targetPath, string nameToReplace = null)
public CacheAndCopyCommandBuilder(IOutputWriter outputWriter, TargetFramework targetFramework, CommandBuilder baseCommandBuilder, string targetPath, string nameToReplace = null)
: base(outputWriter, baseCommandBuilder.ExecutablePath, baseCommandBuilder.ArgumentsFormat, baseCommandBuilder.WorkingDirectory)
{
_baseCommandBuilder = baseCommandBuilder;
_targetFramework = targetFramework;
_targetPath = targetPath;
_nameToReplace = nameToReplace;
}
Expand All @@ -24,13 +27,13 @@ private string CalculateCacheTargetPath(string suffix = "")
{
var targetPathInfo = new DirectoryInfo(_targetPath);
var directoryName = targetPathInfo.Name;
string argsCleaned = ArgumentsFormat.Replace(_targetPath, "").Replace(" ", "").Replace("\"", "")+directoryName;
string argsCleaned = ArgumentsFormat.Replace(_targetPath, "").Replace(" ", "").Replace("\"", "").Replace("/", "") + directoryName;
if (_nameToReplace != null)
{
argsCleaned = argsCleaned.Replace(_nameToReplace, TemplateName);
directoryName = directoryName.Replace(_nameToReplace, TemplateName);
}
return Path.Combine(Path.GetTempPath(), "RRC", $"RRC_{argsCleaned}{suffix}", directoryName);
return Path.Combine(Path.GetTempPath(), "RRC", $"RRC_{_targetFramework}_{argsCleaned}{suffix}", directoryName);
}

public override CommandResult Execute(Func<Exception, Exception> exceptionFunction)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Reqnroll.TestProjectGenerator.Data;

namespace Reqnroll.TestProjectGenerator.Dotnet
{
public class DotNet
{
public static NewCommandBuilder New(IOutputWriter outputWriter) => NewCommandBuilder.Create(outputWriter);
public static NewCommandBuilder New(IOutputWriter outputWriter, TargetFramework targetFramework) => NewCommandBuilder.Create(outputWriter, targetFramework);
public static BuildCommandBuilder Build(IOutputWriter outputWriter) => BuildCommandBuilder.Create(outputWriter);
public static SolutionCommandBuilder Sln(IOutputWriter outputWriter) => SolutionCommandBuilder.Create(outputWriter);
public static VersionCommandBuilder Version(IOutputWriter outputWriter) => VersionCommandBuilder.Create(outputWriter);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Reqnroll.TestProjectGenerator.Data;
using System.IO;

namespace Reqnroll.TestProjectGenerator.Dotnet
Expand All @@ -6,13 +7,16 @@ public partial class NewCommandBuilder
{
public class StubNewProjectCommandBuilder : NewProjectCommandBuilder
{
public StubNewProjectCommandBuilder(IOutputWriter outputWriter) : base(outputWriter)
private readonly TargetFramework _targetFramework;

public StubNewProjectCommandBuilder(IOutputWriter outputWriter, TargetFramework targetFramework) : base(outputWriter)
{
_targetFramework = targetFramework;
}

public override CommandBuilder Build()
{
return new CacheAndCopyCommandBuilder(_outputWriter, base.Build(), _folder);
return new CacheAndCopyCommandBuilder(_outputWriter, _targetFramework, base.Build(), _folder);

//return new CopyFolderCommandBuilder(_outputWriter, @"C:\Temp\DotNetNewIssue\DotNetNewTest\DefaultTestProject", _folder);
//return base.Build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
using Reqnroll.TestProjectGenerator.Data;

namespace Reqnroll.TestProjectGenerator.Dotnet;

public partial class NewCommandBuilder
{
public class StubNewSolutionCommandBuilder : NewSolutionCommandBuilder
{
public StubNewSolutionCommandBuilder(IOutputWriter outputWriter) : base(outputWriter)
private readonly TargetFramework targetFramework;

public StubNewSolutionCommandBuilder(IOutputWriter outputWriter, TargetFramework targetFramework) : base(outputWriter)
{
this.targetFramework = targetFramework;
}

public override CommandBuilder Build()
{
return new CacheAndCopyCommandBuilder(_outputWriter, base.Build(), _rootPath, _name);
return new CacheAndCopyCommandBuilder(_outputWriter, targetFramework, base.Build(), _rootPath, _name);

//return new CopyFolderCommandBuilder(_outputWriter, @"C:\Temp\DotNetNewIssue\DotNetNewTest\DefaultTestProject", _folder);
//return base.Build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
using Reqnroll.TestProjectGenerator.Data;

namespace Reqnroll.TestProjectGenerator.Dotnet
{
public partial class NewCommandBuilder
{
private readonly IOutputWriter _outputWriter;
private readonly TargetFramework _targetFramework;

public NewCommandBuilder(IOutputWriter outputWriter)
private NewCommandBuilder(IOutputWriter outputWriter, TargetFramework targetFramework)
{
_outputWriter = outputWriter;
_targetFramework = targetFramework;
}

internal static NewCommandBuilder Create(IOutputWriter outputWriter) => new NewCommandBuilder(outputWriter);
internal static NewCommandBuilder Create(IOutputWriter outputWriter, TargetFramework targetFramework) => new NewCommandBuilder(outputWriter, targetFramework);

public NewSolutionCommandBuilder Solution() => new StubNewSolutionCommandBuilder(_outputWriter);
public NewSolutionCommandBuilder Solution() => new StubNewSolutionCommandBuilder(_outputWriter, _targetFramework);

public NewProjectCommandBuilder Project() => new StubNewProjectCommandBuilder(_outputWriter);
public NewProjectCommandBuilder Project() => new StubNewProjectCommandBuilder(_outputWriter, _targetFramework);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,5 @@ public void AddFile(string name, string content)
{
_solution.Files.Add(new SolutionFile(name, content));
}

public string SdkVersion
{
get => _solution.SdkVersion;
set => _solution.SdkVersion = value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private void CreateProjectFile(Project project, string projRootPath)



var newProjCommand = DotNet.New(_outputWriter)
var newProjCommand = DotNet.New(_outputWriter, project.TargetFrameworks)
.Project()
.InFolder(projRootPath)
.WithName(project.Name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ public string WriteToFileSystem(Solution solution, string outputPath)
.Select(p => p.TargetFrameworks)
.FirstOrDefault();

var sdk = !string.IsNullOrWhiteSpace(solution.SdkVersion)
? new NetCoreSdkInfo(solution.SdkVersion)
: _netCoreSdkInfoProvider.GetSdkFromTargetFramework(targetFramework);
var sdk = _netCoreSdkInfoProvider.GetSdkFromTargetFramework(targetFramework);

if (targetFramework != 0 && sdk != null)
{
var globalJsonBuilder = new GlobalJsonBuilder().WithSdk(sdk);

var globalJsonFile = globalJsonBuilder.ToProjectFile();
_fileWriter.Write(globalJsonFile, outputPath);
}

DisableUsingSdkFromEnvironmentVariable();

var createSolutionCommand = DotNet.New(_outputWriter).Solution().InFolder(outputPath).WithName(solution.Name).Build();
var createSolutionCommand = DotNet.New(_outputWriter, targetFramework).Solution().InFolder(outputPath).WithName(solution.Name).Build();
createSolutionCommand.ExecuteWithRetry(1, TimeSpan.FromSeconds(1), (innerException) =>
{
if (innerException is AggregateException aggregateException && aggregateException.InnerExceptions.Any(x => x.InnerException.Message.Contains("Install the [" + sdk.Version)))
Expand All @@ -66,14 +72,6 @@ public string WriteToFileSystem(Solution solution, string outputPath)
_fileWriter.Write(file, outputPath);
}

if (targetFramework != 0 && sdk != null)
{
var globalJsonBuilder = new GlobalJsonBuilder().WithSdk(sdk);

var globalJsonFile = globalJsonBuilder.ToProjectFile();
_fileWriter.Write(globalJsonFile, outputPath);
}

return solutionFilePath;
}

Expand Down

0 comments on commit d148c0f

Please sign in to comment.