Skip to content

Commit

Permalink
Add gds2{json,yaml,toml} CLIs. Upgrade to clap v4.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-fritchman committed Dec 20, 2022
1 parent 9042bb8 commit 56e40c6
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 34 deletions.
15 changes: 9 additions & 6 deletions layout21converters/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ version.workspace = true
workspace = "../"

[dependencies]
# Crates.io
chrono = {version = "0.4.20"}
clap = {version = "3.0.0-beta.5", features = ["derive"]}
gds21 = {path = "../gds21"}
layout21protos = {path = "../layout21protos"}
layout21raw = {path = "../layout21raw"}
layout21utils = {path = "../layout21utils"}
lef21 = {path = "../lef21"}
clap = {version = "^4.0", features = ["derive"]}

# Local Workspace
gds21 = {path = "../gds21", version = "3.0.0-pre.2"}
layout21protos = {path = "../layout21protos", version = "3.0.0-pre.2"}
layout21raw = {path = "../layout21raw", version = "3.0.0-pre.2"}
layout21utils = {path = "../layout21utils", version = "3.0.0-pre.2"}
lef21 = {path = "../lef21", version = "3.0.0-pre.2"}
47 changes: 47 additions & 0 deletions layout21converters/src/bin/gds2json.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//!
//! # GDSII to JSON Conversion CLI
//!
//! Converts a GDSII file to [`gds21::GdsLibrary`] JSON.
//!
use clap::Parser;
use std::error::Error;

// Use our own crate, note by name, not `crate::` or `super::`.
use layout21converters::gds_serialization::{convert, ConvOptions};

// => The doc-comment on `ProgramOptions` here is displayed by the `clap`-generated help docs =>

/// # GDSII to JSON Conversion CLI
/// Converts a GDSII file to [`gds21::GdsLibrary`] JSON.
#[derive(Parser)]
pub struct ProgramOptions {
/// GDS Input File
#[arg(short = 'i', long, default_value = "")]
pub gds: String,
/// Output File
#[arg(short = 'o', long, default_value = "")]
pub out: String,
/// Verbose Output Mode
#[arg(short, long)]
pub verbose: bool,
}

impl Into<ConvOptions> for ProgramOptions {
/// Convert into the [`gds_serialization::ConvOptions`] struct.
fn into(self) -> ConvOptions {
ConvOptions {
gds: self.gds,
fmt: "json".to_string(), // <= this is kinda the whole program right here!
out: self.out,
verbose: self.verbose,
}
}
}

/// Main entry point.
/// Parses the command-line arguments and calls [`gds_serialization::convert`].
pub fn main() -> Result<(), Box<dyn Error>> {
let options = ProgramOptions::parse();
convert(&options.into())
}
36 changes: 18 additions & 18 deletions layout21converters/src/bin/gds2markup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,34 @@ use layout21converters::gds_serialization::{convert, ConvOptions};
#[derive(Parser)]
pub struct ProgramOptions {
/// GDS Input File
#[clap(short = 'i', long, default_value = "")]
#[arg(short = 'i', long, default_value = "")]
pub gds: String,
/// Output Format. One of ("json", "yaml", "toml")
#[clap(short = 'f', long, default_value = "")]
#[arg(short = 'f', long, default_value = "")]
pub fmt: String,
/// Output File
#[clap(short = 'o', long, default_value = "")]
#[arg(short = 'o', long, default_value = "")]
pub out: String,
/// Verbose Output Mode
#[clap(short, long)]
#[arg(short, long)]
pub verbose: bool,
}

impl Into<ConvOptions> for ProgramOptions {
/// Convert into the [`gds_serialization::ConvOptions`] struct.
fn into(self) -> ConvOptions {
ConvOptions {
gds: self.gds,
fmt: self.fmt,
out: self.out,
verbose: self.verbose,
}
}
}

/// Main entry point.
/// Thin wrapper around the testable `_main` function.
/// Parses the command-line arguments and calls `_main`.
/// Parses the command-line arguments and calls [`gds_serialization::convert`].
pub fn main() -> Result<(), Box<dyn Error>> {
let options = ProgramOptions::parse();
_main(&options)
}

pub fn _main(options: &ProgramOptions) -> Result<(), Box<dyn Error>> {
// FIXME: this conversion from `ProgramOptions` to `ConvOptions` is the one passages that doesn't have test coverage.
let conv_options = ConvOptions {
gds: options.gds.clone(),
fmt: options.fmt.clone(),
out: options.out.clone(),
verbose: options.verbose,
};
convert(&conv_options)
convert(&options.into())
}
6 changes: 3 additions & 3 deletions layout21converters/src/bin/gds2proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ use std::error::Error;
#[derive(Parser)]
struct ProgramOptions {
/// GDS Input File
#[clap(short = 'i', long, default_value = "")]
#[arg(short = 'i', long, default_value = "")]
gds: String,
/// Protobuf Output File
#[clap(short = 'o', long, default_value = "")]
#[arg(short = 'o', long, default_value = "")]
proto: String,
/// Verbose Output Mode
#[clap(short, long)]
#[arg(short, long)]
verbose: bool,
}

Expand Down
47 changes: 47 additions & 0 deletions layout21converters/src/bin/gds2toml.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//!
//! # GDSII to TOML Conversion CLI
//!
//! Converts a GDSII file to [`gds21::GdsLibrary`] TOML.
//!
use clap::Parser;
use std::error::Error;

// Use our own crate, note by name, not `crate::` or `super::`.
use layout21converters::gds_serialization::{convert, ConvOptions};

// => The doc-comment on `ProgramOptions` here is displayed by the `clap`-generated help docs =>

/// # GDSII to TOML Conversion CLI
/// Converts a GDSII file to [`gds21::GdsLibrary`] TOML.
#[derive(Parser)]
pub struct ProgramOptions {
/// GDS Input File
#[arg(short = 'i', long, default_value = "")]
pub gds: String,
/// Output File
#[arg(short = 'o', long, default_value = "")]
pub out: String,
/// Verbose Output Mode
#[arg(short, long)]
pub verbose: bool,
}

impl Into<ConvOptions> for ProgramOptions {
/// Convert into the [`gds_serialization::ConvOptions`] struct.
fn into(self) -> ConvOptions {
ConvOptions {
gds: self.gds,
fmt: "toml".to_string(), // <= this is kinda the whole program right here!
out: self.out,
verbose: self.verbose,
}
}
}

/// Main entry point.
/// Parses the command-line arguments and calls [`gds_serialization::convert`].
pub fn main() -> Result<(), Box<dyn Error>> {
let options = ProgramOptions::parse();
convert(&options.into())
}
47 changes: 47 additions & 0 deletions layout21converters/src/bin/gds2yaml.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//!
//! # GDSII to YAML Conversion CLI
//!
//! Converts a GDSII file to [`gds21::GdsLibrary`] YAML.
//!
use clap::Parser;
use std::error::Error;

// Use our own crate, note by name, not `crate::` or `super::`.
use layout21converters::gds_serialization::{convert, ConvOptions};

// => The doc-comment on `ProgramOptions` here is displayed by the `clap`-generated help docs =>

/// # GDSII to YAML Conversion CLI
/// Converts a GDSII file to [`gds21::GdsLibrary`] YAML.
#[derive(Parser)]
pub struct ProgramOptions {
/// GDS Input File
#[arg(short = 'i', long, default_value = "")]
pub gds: String,
/// Output File
#[arg(short = 'o', long, default_value = "")]
pub out: String,
/// Verbose Output Mode
#[arg(short, long)]
pub verbose: bool,
}

impl Into<ConvOptions> for ProgramOptions {
/// Convert into the [`gds_serialization::ConvOptions`] struct.
fn into(self) -> ConvOptions {
ConvOptions {
gds: self.gds,
fmt: "yaml".to_string(), // <= this is kinda the whole program right here!
out: self.out,
verbose: self.verbose,
}
}
}

/// Main entry point.
/// Parses the command-line arguments and calls [`gds_serialization::convert`].
pub fn main() -> Result<(), Box<dyn Error>> {
let options = ProgramOptions::parse();
convert(&options.into())
}
6 changes: 3 additions & 3 deletions layout21converters/src/bin/lef2yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ use std::error::Error;
#[derive(Parser)]
struct ProgramOptions {
/// LEF Input File
#[clap(short = 'i', long, default_value = "")]
#[arg(short = 'i', long, default_value = "")]
lef: String,
/// YAML Output File
#[clap(short = 'o', long, default_value = "")]
#[arg(short = 'o', long, default_value = "")]
yaml: String,
/// Verbose Output Mode
#[clap(short, long)]
#[arg(short, long)]
verbose: bool,
}

Expand Down
8 changes: 4 additions & 4 deletions layout21converters/src/bin/proto2gds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ use std::error::Error;

#[derive(Parser)]
struct ProgramOptions {
#[clap(short = 'i', long, default_value = "")]
#[arg(short = 'i', long, default_value = "")]
proto: String,
#[clap(short = 'o', long, default_value = "")]
#[arg(short = 'o', long, default_value = "")]
gds: String,
#[clap(short = 't', long, default_value = "")]
#[arg(short = 't', long, default_value = "")]
tech: String,
#[clap(short, long)]
#[arg(short, long)]
verbose: bool,
}

Expand Down

0 comments on commit 56e40c6

Please sign in to comment.