-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd6de9b
commit 2af1f6b
Showing
6 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System.Diagnostics; | ||
using Avalonia.Media; | ||
using OneWare.Shared.Enums; | ||
using OneWare.Shared.Services; | ||
|
||
namespace OneWare.Core.Services; | ||
|
||
public class ChildProcessService : IChildProcessService | ||
{ | ||
private readonly ILogger _logger; | ||
private readonly IActive _active; | ||
|
||
public ChildProcessService(ILogger logger, IActive active) | ||
{ | ||
_logger = logger; | ||
_active = active; | ||
} | ||
|
||
private static ProcessStartInfo GetProcessStartInfo(string workingDirectory, string path, string arguments) | ||
{ | ||
return new ProcessStartInfo | ||
{ | ||
FileName = path, | ||
Arguments = $"{arguments}", | ||
CreateNoWindow = true, | ||
WorkingDirectory = workingDirectory, | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true, | ||
UseShellExecute = false | ||
}; | ||
} | ||
|
||
public async Task<(bool success, string output)> ExecuteShellAsync(string path, string arguments, string workingDirectory, string status, AppState state = AppState.Loading) | ||
{ | ||
var success = true; | ||
|
||
_logger.Log($"{Path.GetFileNameWithoutExtension(path)} {arguments}", ConsoleColor.DarkCyan, true, Brushes.CornflowerBlue); | ||
|
||
var output = string.Empty; | ||
|
||
var startInfo = GetProcessStartInfo(path, workingDirectory, arguments); | ||
|
||
using var activeProcess = new Process(); | ||
activeProcess.StartInfo = startInfo; | ||
var key = _active.AddState(status, state, activeProcess); | ||
|
||
activeProcess.OutputDataReceived += (o, i) => | ||
{ | ||
if (string.IsNullOrEmpty(i.Data)) return; | ||
_logger.Log(i.Data, ConsoleColor.Black, true); | ||
output += i.Data + '\n'; | ||
}; | ||
activeProcess.ErrorDataReceived += (o, i) => | ||
{ | ||
if (string.IsNullOrEmpty(i.Data)) return; | ||
success = false; | ||
_logger.Warning(i.Data, null, false); | ||
output += i.Data + '\n'; | ||
}; | ||
|
||
try | ||
{ | ||
activeProcess.Start(); | ||
activeProcess.BeginOutputReadLine(); | ||
activeProcess.BeginErrorReadLine(); | ||
|
||
await Task.Run(() => activeProcess.WaitForExit()); | ||
} | ||
catch (Exception e) | ||
{ | ||
_logger.Error(e.Message, e); | ||
success = false; | ||
} | ||
|
||
if (key.Terminated) success = false; | ||
_active.RemoveState(key); | ||
|
||
return (success,output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using OneWare.Shared.Services; | ||
using OneWare.UniversalFpgaProjectSystem.Models; | ||
|
||
namespace OneWare.OssCadSuiteIntegration.Yosys; | ||
|
||
public class YosysService | ||
{ | ||
private readonly IChildProcessService _childProcessService; | ||
|
||
public YosysService(IChildProcessService childProcessService) | ||
{ | ||
_childProcessService = childProcessService; | ||
} | ||
|
||
public async Task SynthAsync(UniversalFpgaProjectRoot project) | ||
{ | ||
var fpga = project.Properties["Fpga"]; | ||
var top = project.Properties["TopEntity"]; | ||
|
||
var verilogFiles = string.Join(" ", project.Files.Where(x => x.Extension == ".v")); | ||
var yosysFlags = string.Empty; | ||
|
||
await _childProcessService.ExecuteShellAsync("yosys", | ||
$"yosys -p \"synth_${fpga} -top ${top} -json ${project.FullPath}/synth.json\" ${yosysFlags} ${verilogFiles}", | ||
project.FullPath, "Yosys Synth"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using OneWare.Shared.Enums; | ||
|
||
namespace OneWare.Shared.Services; | ||
|
||
public interface IChildProcessService | ||
{ | ||
public Task<(bool success, string output)> ExecuteShellAsync(string path, string arguments, string workingDirectory, | ||
string status, AppState state = AppState.Loading); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters