-
Notifications
You must be signed in to change notification settings - Fork 123
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
Showing
22 changed files
with
1,841 additions
and
76 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
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
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,84 @@ | ||
import re | ||
import os | ||
import subprocess | ||
from typing import cast, BinaryIO, TypedDict | ||
|
||
|
||
SCRIPT_PATH: str = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
def main() -> None: | ||
# The path to the workspace manifest file | ||
workspace_manifest_file: str = os.path.abspath( | ||
os.path.join(SCRIPT_PATH, "Cargo.toml") | ||
) | ||
|
||
# Listing all of the Rust Analyzer autocomplete tests to run all of them. | ||
list_tests_output: bytes = cast( | ||
BinaryIO, | ||
subprocess.Popen( | ||
[ | ||
"cargo", | ||
"test", | ||
"--manifest-path", | ||
workspace_manifest_file, | ||
"--package", | ||
"rust-analyzer-tests", | ||
"--test", | ||
"autocomplete", | ||
"--", | ||
"--list", | ||
"--format=terse", | ||
], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
).stdout, | ||
).read() | ||
|
||
# Extract all of the test names from the string. | ||
test_names: list[str] = re.findall(r"(.*)?: test", list_tests_output.decode()) | ||
|
||
# Run each test and record the time the autocompletion took. | ||
test_results: list[tuple[str, int]] = [] | ||
for test_name in test_names: | ||
# Run the test | ||
test_run_output: bytes = cast( | ||
BinaryIO, | ||
subprocess.Popen( | ||
[ | ||
"cargo", | ||
"test", | ||
"--release", | ||
"--manifest-path", | ||
workspace_manifest_file, | ||
"--package", | ||
"rust-analyzer-tests", | ||
"--test", | ||
"autocomplete", | ||
"--", | ||
test_name, | ||
"--exact", | ||
"--nocapture", | ||
], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
).stdout, | ||
).read() | ||
|
||
# Find the amount of time it took to run the benchmark | ||
duration: int = int( | ||
re.findall(r"Autocomplete took: (\d+)ms", test_run_output.decode())[0] | ||
) | ||
|
||
# Insert to the list | ||
test_results.append((test_name, duration)) | ||
|
||
# Output the results as a markdown table to stdout | ||
markdown_table: str = "## Autocomplete Benchmark Results\n| Test Name | Autocomplete (ms) |\n| -- | -- |\n" | ||
for (test_name, duration) in test_results: | ||
markdown_table += f"| `{test_name}` | {duration} |\n" | ||
print(markdown_table) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,13 @@ | ||
[package] | ||
name = "radix-clis-common" | ||
version = "1.2.0-dev" | ||
edition = "2021" | ||
description = "Shared logic of the Radix CLIs." | ||
readme = "README.md" | ||
license-file = "../LICENSE" | ||
repository = "https://github.com/radixdlt/radixdlt-scrypto" | ||
|
||
# Ref: https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options | ||
[lib] | ||
doctest = false | ||
bench = false |
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,3 @@ | ||
# `radix-clis-common` | ||
|
||
Shared logic of the Radix CLIs. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 @@ | ||
pub mod package; |
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,100 @@ | ||
use std::path::*; | ||
|
||
pub fn new_package( | ||
package_name: &str, | ||
path: Option<PathBuf>, | ||
local: bool, | ||
) -> Result<(), PackageError> { | ||
let wasm_name = package_name.replace('-', "_"); | ||
let path = path.clone().unwrap_or(PathBuf::from(package_name)); | ||
let simulator_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
let ( | ||
sbor, | ||
scrypto, | ||
transaction, | ||
radix_engine, | ||
radix_engine_interface, | ||
scrypto_test, | ||
optional_scrypto_test, | ||
) = if local { | ||
let scrypto_dir = simulator_dir | ||
.parent() | ||
.unwrap() | ||
.to_string_lossy() | ||
.replace('\\', "/"); | ||
( | ||
format!("{{ path = \"{}/sbor\" }}", scrypto_dir), | ||
format!("{{ path = \"{}/scrypto\" }}", scrypto_dir), | ||
format!("{{ path = \"{}/transaction\" }}", scrypto_dir), | ||
format!("{{ path = \"{}/radix-engine\" }}", scrypto_dir), | ||
format!("{{ path = \"{}/radix-engine-interface\" }}", scrypto_dir), | ||
format!("{{ path = \"{}/scrypto-test\" }}", scrypto_dir), | ||
format!( | ||
"{{ path = \"{}/scrypto-test\", optional = true }}", | ||
scrypto_dir | ||
), | ||
) | ||
} else { | ||
let s = format!( | ||
"{{ git = \"https://github.com/radixdlt/radixdlt-scrypto\", tag = \"v{}\" }}", | ||
env!("CARGO_PKG_VERSION") | ||
); | ||
(s.clone(), s.clone(), s.clone(), s.clone(), s.clone(), s, format!( | ||
"{{ git = \"https://github.com/radixdlt/radixdlt-scrypto\", tag = \"v{}\", optional = true }}", | ||
env!("CARGO_PKG_VERSION") | ||
)) | ||
}; | ||
|
||
if path.exists() { | ||
Err(PackageError::PackageAlreadyExists) | ||
} else { | ||
std::fs::create_dir_all(child_of(&path, "src")).map_err(PackageError::IOError)?; | ||
std::fs::create_dir_all(child_of(&path, "tests")).map_err(PackageError::IOError)?; | ||
|
||
std::fs::write( | ||
child_of(&path, "Cargo.toml"), | ||
include_str!("../assets/template/Cargo.toml_template") | ||
.replace("${package_name}", package_name) | ||
.replace("${sbor}", &sbor) | ||
.replace("${scrypto}", &scrypto) | ||
.replace("${transaction}", &transaction) | ||
.replace("${radix-engine}", &radix_engine) | ||
.replace("${radix-engine-interface}", &radix_engine_interface) | ||
.replace("${scrypto-test}", &scrypto_test) | ||
.replace("${optional-scrypto-test}", &optional_scrypto_test), | ||
) | ||
.map_err(PackageError::IOError)?; | ||
|
||
std::fs::write( | ||
child_of(&path, ".gitignore"), | ||
include_str!("../assets/template/.gitignore"), | ||
) | ||
.map_err(PackageError::IOError)?; | ||
|
||
std::fs::write( | ||
child_of(&child_of(&path, "src"), "lib.rs"), | ||
include_str!("../assets/template/src/lib.rs"), | ||
) | ||
.map_err(PackageError::IOError)?; | ||
|
||
std::fs::write( | ||
child_of(&child_of(&path, "tests"), "lib.rs"), | ||
include_str!("../assets/template/tests/lib.rs").replace("${wasm_name}", &wasm_name), | ||
) | ||
.map_err(PackageError::IOError)?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
fn child_of(path: &PathBuf, name: &str) -> PathBuf { | ||
let mut p = path.clone(); | ||
p.push(name); | ||
p | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum PackageError { | ||
PackageAlreadyExists, | ||
IOError(std::io::Error), | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.