From 3c91ec60646ca37fcb4541bdd5bd8b6b9fa8bfed Mon Sep 17 00:00:00 2001 From: Mohammad Amin Chitgarha Date: Mon, 10 Apr 2023 18:40:08 +0330 Subject: [PATCH] Add gtkwave.cmdline config key for setting Gtkwave invocation command This should be useful for some Mac users where Gtkwave cannot be invoked directly. --- src/Command/SimulateCommand.php | 2 +- src/Config.php | 2 ++ src/Runner/Gtkwave/GtkwaveRunner.php | 32 +++++++++++++-------- src/Runner/Gtkwave/GtkwaveRunnerFactory.php | 8 +++--- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/Command/SimulateCommand.php b/src/Command/SimulateCommand.php index 5d454d9..51a477c 100644 --- a/src/Command/SimulateCommand.php +++ b/src/Command/SimulateCommand.php @@ -127,7 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $config = $this->buildConfig($input, $output, $executableFinder); $ghdlRunner = GhdlRunnerFactory::create($executableFinder, $config); - $gtkwaveRunner = GtkwaveRunnerFactory::create($executableFinder); + $gtkwaveRunner = GtkwaveRunnerFactory::create($executableFinder, $config); Pusheh::createDirRecursive($workdir); diff --git a/src/Config.php b/src/Config.php index f383fb7..42911b6 100644 --- a/src/Config.php +++ b/src/Config.php @@ -17,9 +17,11 @@ final class Config extends \Noodlehaus\Config private const FILE_NAME = "config.json"; public const KEY_GHDL_VERSION = "ghdl.version"; + public const KEY_GTKWAVE_CMDLINE = "gtkwave.cmdline"; private const VALID_KEYS = [ self::KEY_GHDL_VERSION, + self::KEY_GTKWAVE_CMDLINE, ]; public string $filePath; diff --git a/src/Runner/Gtkwave/GtkwaveRunner.php b/src/Runner/Gtkwave/GtkwaveRunner.php index 4a1be07..acd9712 100644 --- a/src/Runner/Gtkwave/GtkwaveRunner.php +++ b/src/Runner/Gtkwave/GtkwaveRunner.php @@ -2,32 +2,40 @@ namespace MAChitgarha\Parvaj\Runner\Gtkwave; +use MAChitgarha\Parvaj\Config; use MAChitgarha\Parvaj\Runner\OptionBuilder; - +use MAChitgarha\Parvaj\Util\ExecutableFinder; use MAChitgarha\Parvaj\WaveformType; - use MAChitgarha\Parvaj\Util\Process; class GtkwaveRunner { public function __construct( - private string $executable, + private ExecutableFinder $executableFinder, + private Config $config, ) { } public function open(string $waveformFilePath, string $waveformType): void { - $options = []; - if ($waveformType === WaveformType::VCD) { - $options["o"] = null; - } + if ($this->config->has(Config::KEY_GTKWAVE_CMDLINE)) { + $command = [ + $this->config->get(Config::KEY_GTKWAVE_CMDLINE), + $waveformFilePath, + ]; + } else { + $options = []; + if ($waveformType === WaveformType::VCD) { + $options["o"] = null; + } - (new Process( - [ - $this->executable, + $command = [ + $this->executableFinder->find("gtkwave"), ...OptionBuilder::build($options), $waveformFilePath, - ] - ))->runSafe(); + ]; + } + + (new Process($command))->runSafe(); } } diff --git a/src/Runner/Gtkwave/GtkwaveRunnerFactory.php b/src/Runner/Gtkwave/GtkwaveRunnerFactory.php index 95853de..3bbc769 100644 --- a/src/Runner/Gtkwave/GtkwaveRunnerFactory.php +++ b/src/Runner/Gtkwave/GtkwaveRunnerFactory.php @@ -2,14 +2,14 @@ namespace MAChitgarha\Parvaj\Runner\Gtkwave; +use MAChitgarha\Parvaj\Config; + use MAChitgarha\Parvaj\Util\ExecutableFinder; class GtkwaveRunnerFactory { - public static function create(ExecutableFinder $executableFinder): GtkwaveRunner + public static function create(ExecutableFinder $executableFinder, Config $config): GtkwaveRunner { - return new GtkwaveRunner( - $executableFinder->find("gtkwave") - ); + return new GtkwaveRunner($executableFinder, $config); } }