Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
14b4425f
Unverified
Commit
14b4425f
authored
Jun 19, 2024
by
Maurelian
Committed by
GitHub
Jun 19, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add allow-empty overload field on Process.run (#10736)
parent
ab663b0b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
7 deletions
+20
-7
Process.sol
packages/contracts-bedrock/scripts/libraries/Process.sol
+19
-6
L2Genesis.t.sol
packages/contracts-bedrock/test/L2Genesis.t.sol
+1
-1
No files found.
packages/contracts-bedrock/scripts/libraries/Process.sol
View file @
14b4425f
...
@@ -10,15 +10,28 @@ library Process {
...
@@ -10,15 +10,28 @@ library Process {
/// @notice Foundry cheatcode VM.
/// @notice Foundry cheatcode VM.
Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
function run(string[] memory cmd) internal returns (bytes memory stdout_) {
/// @notice Run a command in a subprocess. Fails if no output is returned.
Vm.FfiResult memory result = vm.tryFfi(cmd);
/// @param _command Command to run.
function run(string[] memory _command) internal returns (bytes memory stdout_) {
stdout_ = run({ _command: _command, _allowEmpty: false });
}
/// @notice Run a command in a subprocess.
/// @param _command Command to run.
/// @param _allowEmpty Allow empty output.
function run(string[] memory _command, bool _allowEmpty) internal returns (bytes memory stdout_) {
Vm.FfiResult memory result = vm.tryFfi(_command);
string memory command;
for (uint256 i = 0; i < _command.length; i++) {
command = string.concat(command, _command[i], " ");
}
if (result.exitCode != 0) {
if (result.exitCode != 0) {
string memory command;
for (uint256 i = 0; i < cmd.length; i++) {
command = string.concat(command, cmd[i], " ");
}
revert FfiFailed(string.concat("Command: ", command, "\nError: ", string(result.stderr)));
revert FfiFailed(string.concat("Command: ", command, "\nError: ", string(result.stderr)));
}
}
// If the output is empty, result.stdout is "[]".
if (!_allowEmpty && keccak256(result.stdout) == keccak256(bytes("[]"))) {
revert FfiFailed(string.concat("No output from Command: ", command));
}
stdout_ = result.stdout;
stdout_ = result.stdout;
}
}
}
}
packages/contracts-bedrock/test/L2Genesis.t.sol
View file @
14b4425f
...
@@ -37,7 +37,7 @@ contract L2GenesisTest is Test {
...
@@ -37,7 +37,7 @@ contract L2GenesisTest is Test {
commands[0] = "bash";
commands[0] = "bash";
commands[1] = "-c";
commands[1] = "-c";
commands[2] = string.concat("rm ", path);
commands[2] = string.concat("rm ", path);
Process.run(
commands
);
Process.run(
{ _command: commands, _allowEmpty: true }
);
}
}
/// @notice Returns the number of top level keys in a JSON object at a given
/// @notice Returns the number of top level keys in a JSON object at a given
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment