From fe4fa36c2d5ebd0b2eef41cd635cc46b72bac0aa Mon Sep 17 00:00:00 2001 From: Andrew Cowie Date: Mon, 17 Mar 2025 17:23:21 +1100 Subject: [PATCH 1/4] Remove Haskell build machinery --- .gitignore | 3 --- hie.yaml | 2 -- package.yaml | 41 ----------------------------------------- stack.yaml | 20 -------------------- tests/TestSuite.hs | 14 -------------- 5 files changed, 80 deletions(-) delete mode 100644 hie.yaml delete mode 100644 package.yaml delete mode 100644 stack.yaml delete mode 100644 tests/TestSuite.hs diff --git a/.gitignore b/.gitignore index 3eab259..6b23fec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1 @@ -/.stack-work/ -/stack.yaml.lock -/*.cabal /.trace diff --git a/hie.yaml b/hie.yaml deleted file mode 100644 index 4ef275e..0000000 --- a/hie.yaml +++ /dev/null @@ -1,2 +0,0 @@ -cradle: - stack: diff --git a/package.yaml b/package.yaml deleted file mode 100644 index 53a8573..0000000 --- a/package.yaml +++ /dev/null @@ -1,41 +0,0 @@ -name: tracer -version: 0.1.0.2 -synopsis: Manually instrument a script with spans and traces -author: Andrew Cowie -maintainer: Andrew Cowie -copyright: © 2021-2022 Athae Eredh Siniath and Others -license: MIT -tested-with: GHC == 9.2.2 - -ghc-options: -Wall -Wwarn -fwarn-tabs - -dependencies: - - base - - bytestring - - core-data - - core-text - - core-program >= 0.5.0.4 - - core-telemetry >= 0.2.3.4 - - random - - scientific - - typed-process - -executables: - tracer: - source-dirs: - - src - main: TracerMain.hs - ghc-options: -threaded - other-modules: - - TracerSpans - - StateFile - -tests: - check: - dependencies: - - hspec - ghc-options: -threaded - source-dirs: - - tests - main: TestSuite.hs - other-modules: [] diff --git a/stack.yaml b/stack.yaml deleted file mode 100644 index 173dacd..0000000 --- a/stack.yaml +++ /dev/null @@ -1,20 +0,0 @@ -resolver: lts-20.3 -compiler: ghc-9.2.4 -packages: -- . - -extra-deps: -# -# there was actually no immediate reason to depend on the latest versions of -# these libraries other than to show the way you add specific versions to your -# Stack resolver if you need something newer than what is in the snaphot above. -# - -- core-data-0.3.8.0 -- core-program-0.6.1.0 -- core-text-0.3.8.0 -- core-telemetry-0.2.7.0 - -# -# bump aeson dependency for security reasons -# diff --git a/tests/TestSuite.hs b/tests/TestSuite.hs deleted file mode 100644 index 6d4d42a..0000000 --- a/tests/TestSuite.hs +++ /dev/null @@ -1,14 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -import Control.Exception (finally) -import Test.Hspec (Spec, describe, hspec, it, shouldBe) - -main :: IO () -main = do - finally (hspec suite) (putStrLn ".") - -suite :: Spec -suite = do - describe "This thing" $ do - it "does what it is supposed to" $ do - True `shouldBe` True From ef0a8e76a9f139262669d3ef17bd4e0fe79ac359 Mon Sep 17 00:00:00 2001 From: Andrew Cowie Date: Mon, 17 Mar 2025 17:24:21 +1100 Subject: [PATCH 2/4] Initialize Rust project --- .gitignore | 2 ++ Cargo.lock | 7 +++++++ Cargo.toml | 10 ++++++++++ src/main.rs | 3 +++ 4 files changed, 22 insertions(+) create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore index 6b23fec..7fb2651 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +/target + /.trace diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..b358ac9 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "tracer" +version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..a931aa9 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "tracer" +version = "0.2.0" +description = "Manually instrument a script with spans and traces" +authors = ["Andrew Cowie"] +edition = "2024" +license = "MIT" +repository = "https://github.com/aesiniath/tracer" + +[dependencies] diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} From d8734d591d482a501d354ebfa52ac63c37062779 Mon Sep 17 00:00:00 2001 From: Andrew Cowie Date: Mon, 17 Mar 2025 17:44:25 +1100 Subject: [PATCH 3/4] Add clap dependency --- Cargo.lock | 235 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + 2 files changed, 236 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index b358ac9..2905b6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,241 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "anstream" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" +dependencies = [ + "anstyle", + "once_cell", + "windows-sys", +] + +[[package]] +name = "bitflags" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" + +[[package]] +name = "clap" +version = "4.5.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6088f3ae8c3608d19260cd7445411865a485688711b78b5be70d78cd96136f83" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.5.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22a7ef7f676155edfb82daa97f99441f3ebf4a58d5e32f295a56259f1b6facc8" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", + "terminal_size", +] + +[[package]] +name = "clap_lex" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" + +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + +[[package]] +name = "errno" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + +[[package]] +name = "libc" +version = "0.2.170" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828" + +[[package]] +name = "linux-raw-sys" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe7db12097d22ec582439daf8618b8fdd1a7bef6270e9af3b1ebcd30893cf413" + +[[package]] +name = "once_cell" +version = "1.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc" + +[[package]] +name = "rustix" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7178faa4b75a30e269c71e61c353ce2748cf3d76f0c44c393f4e60abf49b825" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "terminal_size" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45c6481c4829e4cc63825e62c49186a34538b7b2750b73b266581ffb612fb5ed" +dependencies = [ + "rustix", + "windows-sys", +] + [[package]] name = "tracer" version = "0.2.0" +dependencies = [ + "clap", +] + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/Cargo.toml b/Cargo.toml index a931aa9..7b2c533 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,4 @@ license = "MIT" repository = "https://github.com/aesiniath/tracer" [dependencies] +clap = { version = "4.5.32", features = ["wrap_help"] } From 9aae7e8f2cb2fe57feb3f3b756d6b640914ac765 Mon Sep 17 00:00:00 2001 From: Andrew Cowie Date: Mon, 17 Mar 2025 17:45:50 +1100 Subject: [PATCH 4/4] Declare subcommands in command-line argument parser --- src/main.rs | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index e7a11a9..60cf741 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,87 @@ +use clap::{Arg, ArgAction, Command}; + fn main() { - println!("Hello, world!"); + const VERSION: &str = concat!("v", env!("CARGO_PKG_VERSION")); + + let matches = Command::new("tracer") + .version(VERSION) + .propagate_version(true) + .author("Andrew Cowie") + .about("Manually instrument a script with spans and traces.") + .disable_help_subcommand(true) + .disable_help_flag(true) + .disable_version_flag(true) + .arg( + Arg::new("help") + .long("help") + .long_help("Print help") + .global(true) + .hide(true) + .action(ArgAction::Help)) + .arg( + Arg::new("version") + .long("version") + .long_help("Print version") + .global(true) + .hide(true) + .action(ArgAction::Version)) + .arg( + Arg::new("trace-file") + .long("trace-file") + .action(ArgAction::SetTrue) + .help("File to record the trace and root span identifier in. The default filename is .trace in the current working directory. If you override it when initializing you will need to use the same file for all subsequent invocations making up this procedure.")) + .subcommand( + Command::new("init") + .about("Create a trace and root span identifier and mark the start time of your trace.") + .arg( + Arg::new("watch") + .long("watch") + .action(clap::ArgAction::SetTrue) + .help("Watch the given procedure file and recompile if changes are detected."), + ) + .arg( + Arg::new("filename") + .required(true) + .help("The file containing the code for the procedure you want to type-check."), + ), + ) + .subcommand( + Command::new("exec") + .about("Wrap the execution of a command in a span, recording its start time and duration.") + .arg( + Arg::new("label") + .required(true) + .help("Name for the span that will enclose the command you are running. By convention th e label used for the step is the name of the program, script, or function you are executing, rather than a descriptive string."), + ) + .arg( + Arg::new("command") + .required(true) + .help("The program to run. It needs to either be an absolute path or a binary by that name must be on your PATH."), + ), + + ) + .subcommand( + Command::new("send") + .about("Send the root span, finishing the corresponding trace.") + .arg( + Arg::new("label") + .required(true) + .help("Name for the root span. By convention this is the identifier or codename for the process being undertaken."), + ) + ) + + .get_matches(); + + match matches.subcommand() { + Some(("check", _)) => { + todo!(); + } + Some(_) => { + println!("An invalid subcommand was used") + } + None => { + println!("usage: tracer [COMMAND] ..."); + println!("Try '--help' for more information."); + } + } }