Skip to content

Commit

Permalink
Add gtkwave.cmdline config key for setting Gtkwave invocation command
Browse files Browse the repository at this point in the history
This should be useful for some Mac users where Gtkwave cannot be
invoked directly.
  • Loading branch information
machitgarha committed Apr 10, 2023
1 parent f75bd81 commit 3c91ec6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Command/SimulateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 20 additions & 12 deletions src/Runner/Gtkwave/GtkwaveRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
8 changes: 4 additions & 4 deletions src/Runner/Gtkwave/GtkwaveRunnerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 3c91ec6

Please sign in to comment.