Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple target-os #187

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Version 1.10.0-beta

## 1.10.0-beta.7
charlespierce marked this conversation as resolved.
Show resolved Hide resolved
## 1.10.0-beta.8

- Added support for [inline value classes](https://kotlinlang.org/docs/inline-classes.html) in Kotlin - [#182](https://github.com/1Password/typeshare/pull/182)
- Added the ability to specify that a struct should have information redacted - [#170](https://github.com/1Password/typeshare/pull/170)
Expand Down
58 changes: 56 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ ci = ["github"]
installers = ["shell", "powershell"]
# Target platforms to build apps for (Rust target-triple syntax)
targets = [
"x86_64-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-pc-windows-msvc",
"aarch64-apple-darwin",
"x86_64-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-pc-windows-msvc",
"aarch64-apple-darwin",
]

[profile.test]
Expand All @@ -32,3 +32,8 @@ incremental = true
# The profile that 'cargo dist' will build with
[profile.dist]
inherits = "release"

[workspace.dependencies]
log = "0.4"
flexi_logger = "0.28"
charlespierce marked this conversation as resolved.
Show resolved Hide resolved
anyhow = "1"
8 changes: 5 additions & 3 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "typeshare-cli"
version = "1.10.0-beta.7"
version = "1.10.0-beta.8"
charlespierce marked this conversation as resolved.
Show resolved Hide resolved
edition = "2021"
description = "Command Line Tool for generating language files with typeshare"
license = "MIT OR Apache-2.0"
Expand All @@ -22,5 +22,7 @@ once_cell = "1"
rayon = "1.10"
serde = { version = "1", features = ["derive"] }
toml = "0.8"
typeshare-core = { path = "../core", version = "1.10.0-beta.7" }
anyhow = "1"
typeshare-core = { path = "../core", version = "1.10.0-beta.8" }
anyhow.workspace = true
log.workspace = true
flexi_logger.workspace = true
1 change: 1 addition & 0 deletions cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ pub(crate) fn build_command() -> Command<'static> {
.long("target-os")
.help("Optional restrict to target_os")
.takes_value(true)
.multiple_values(true)
.required(false)
)
}
2 changes: 1 addition & 1 deletion cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub(crate) struct Config {
#[cfg(feature = "go")]
pub go: GoParams,
#[serde(skip)]
pub target_os: Option<String>,
pub target_os: Vec<String>,
}

pub(crate) fn store_config(config: &Config, file_path: Option<&str>) -> anyhow::Result<()> {
Expand Down
15 changes: 12 additions & 3 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use args::{
use clap::ArgMatches;
use config::Config;
use ignore::{overrides::OverrideBuilder, types::TypesBuilder, WalkBuilder};
use log::error;
use parse::{all_types, parse_input, parser_inputs};
use rayon::iter::ParallelBridge;
use std::collections::{BTreeMap, HashMap};
Expand All @@ -30,6 +31,11 @@ mod parse;
mod writer;

fn main() -> anyhow::Result<()> {
flexi_logger::Logger::try_with_env()
.unwrap()
.start()
.unwrap();

#[allow(unused_mut)]
let mut command = build_command();

Expand Down Expand Up @@ -122,7 +128,7 @@ fn main() -> anyhow::Result<()> {
parser_inputs(walker_builder, language_type, multi_file).par_bridge(),
&ignored_types,
multi_file,
target_os,
&target_os,
)?;

// Collect all the types into a map of the file name they
Expand Down Expand Up @@ -220,7 +226,10 @@ fn override_configuration(mut config: Config, options: &ArgMatches) -> Config {
config.go.package = go_package.to_string();
}

config.target_os = options.value_of(ARG_TARGET_OS).map(|s| s.to_string());
config.target_os = options
.get_many::<String>(ARG_TARGET_OS)
.map(|arg| arg.into_iter().map(ToString::to_string).collect::<Vec<_>>())
.unwrap_or_default();
config
}

Expand All @@ -233,7 +242,7 @@ fn check_parse_errors(parsed_crates: &BTreeMap<CrateName, ParsedData>) -> anyhow
{
errors_encountered = true;
for error in &data.errors {
eprintln!(
error!(
"Parsing error: \"{}\" in crate \"{}\" for file \"{}\"",
error.error, error.crate_name, error.file_name
);
Expand Down
4 changes: 2 additions & 2 deletions cli/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn parse_input(
inputs: impl ParallelIterator<Item = ParserInput>,
ignored_types: &[&str],
multi_file: bool,
target_os: Option<String>,
target_os: &[String],
) -> anyhow::Result<BTreeMap<CrateName, ParsedData>> {
inputs
.into_par_iter()
Expand All @@ -111,7 +111,7 @@ pub fn parse_input(
file_path,
ignored_types,
multi_file,
target_os.clone(),
target_os,
)
.with_context(|| format!("Failed to parse: {file_name}"))?;

Expand Down
3 changes: 2 additions & 1 deletion cli/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::args::{ARG_OUTPUT_FILE, ARG_OUTPUT_FOLDER};
use anyhow::Context;
use clap::ArgMatches;
use log::info;
use std::{
collections::{BTreeMap, HashMap},
fs,
Expand Down Expand Up @@ -58,7 +59,7 @@ fn check_write_file(outfile: &PathBuf, output: Vec<u8>) -> anyhow::Result<()> {
// avoid writing the file to leave the mtime intact
// for tools which might use it to know when to
// rebuild.
println!("Skipping writing to {outfile:?} no changes");
info!("Skipping writing to {outfile:?} no changes");
return Ok(());
}
_ => {}
Expand Down
6 changes: 4 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
[package]
name = "typeshare-core"
version = "1.10.0-beta.7"
version = "1.10.0-beta.8"
charlespierce marked this conversation as resolved.
Show resolved Hide resolved
license = "MIT OR Apache-2.0"
edition = "2021"
description = "The code generator used by Typeshare's command line tool"
repository = "https://github.com/1Password/typeshare"

[dependencies]
anyhow.workspace = true
charlespierce marked this conversation as resolved.
Show resolved Hide resolved
proc-macro2 = "1"
quote = "1"
syn = { version = "2", features = ["full", "visit"] }
thiserror = "1"
itertools = "0.12"
lazy_format = "2"
joinery = "2"
log.workspace = true
flexi_logger.workspace = true

[dev-dependencies]
anyhow = "1"
expect-test = "1.5"
once_cell = "1"
cool_asserts = "2"
Expand Down
44 changes: 44 additions & 0 deletions core/data/tests/excluded_by_target_os/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use std::collection::HashMap;

#[typeshare]
#[serde(tag = "type", content = "content")]
pub enum TestEnum {
Variant1,
#[cfg(target_os = "ios")]
Expand All @@ -14,6 +15,17 @@ pub enum TestEnum {
Variant4,
#[cfg(target_os = "android")]
Variant5,
#[cfg(target_os = "macos")]
Variant7 {
field1: String,
},
#[cfg(any(target_os = "android", target_os = "ios"))]
Variant8,
Variant9 {
#[cfg(not(target_os = "macos"))]
field1: String,
field2: String,
},
}

#[typeshare]
Expand All @@ -32,3 +44,35 @@ pub enum Test {}
#[cfg(feature = "super")]
#[cfg(target_os = "android")]
pub enum SomeEnum {}

#[typeshare]
#[cfg(any(target_os = "ios", target_os = "android"))]
pub struct ManyStruct;
darrell-roberts marked this conversation as resolved.
Show resolved Hide resolved

#[typeshare]
#[cfg(any(target_os = "android", target_os = "ios"))]
pub struct MultipleTargets;

#[typeshare]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub struct DefinedTwice {
field1: u64,
}

#[typeshare]
#[cfg(any(target_os = "android", target_os = "ios"))]
pub struct DefinedTwice {
field1: String,
}

#[typeshare]
#[cfg(not(any(target_os = "wasm32", target_os = "ios")))]
pub struct Excluded;

#[typeshare]
#[cfg(not(target_os = "wasm32"))]
pub struct OtherExcluded;

#[typeshare]
#[cfg(not(target_os = "android"))]
pub struct AndroidExcluded;
Loading
Loading