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

Merging upstream changes #9

Merged
merged 37 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2abb6a4
update for no target-os
darrell-roberts Nov 11, 2024
d1b2b06
update snapshot test. Fix typos
darrell-roberts Nov 11, 2024
41de151
Merge pull request #204 from darrell-roberts/darrell/update-for-empty…
kareid Nov 12, 2024
330a40f
Only overwrite Codable.swift if it has changed. (#205)
kevinbhayes Nov 12, 2024
dce5b85
Set default log level when not using RUST_LOG (#206)
darrell-roberts Nov 13, 2024
7d873dd
chore: update changelogs and bump versions for v1.13.0 (#208)
darrell-roberts Nov 15, 2024
edf4695
Create a parse context and parse file context
darrell-roberts Nov 16, 2024
9cde48a
Create a parse file context
darrell-roberts Nov 16, 2024
8bf951e
Fix traversing the root folder twice
darrell-roberts Nov 16, 2024
ef9108b
Update comments.
darrell-roberts Nov 17, 2024
90366cd
cleanup
darrell-roberts Nov 17, 2024
d6d21a0
cleanup
darrell-roberts Nov 18, 2024
0370f23
Add useful info messages for each run stage
darrell-roberts Nov 18, 2024
f1188cb
Merge pull request #209 from 1Password/dr/context-types
darrell-roberts Nov 18, 2024
8f53e48
only assert go package if generating go types
MOmarMiraj Nov 18, 2024
ba9417d
fmt fix
MOmarMiraj Nov 18, 2024
0a879c5
properly check if the language is golang
MOmarMiraj Nov 18, 2024
d142e63
fix import error
MOmarMiraj Nov 18, 2024
c3596bb
fix import error
MOmarMiraj Nov 18, 2024
3d67aae
condense the go feature block
MOmarMiraj Nov 18, 2024
e0e5f27
Merge pull request #211 from MOmarMiraj/omar/fix-go-package
darrell-roberts Nov 18, 2024
5e68842
Update shell completions for new generate function (#212)
darrell-roberts Nov 20, 2024
1b7ce4f
chore: update changelogs and bump versions for v1.13.1
darrell-roberts Nov 20, 2024
82ef951
Merge pull request #213 from 1Password/dr/release-1.13.1
darrell-roberts Nov 20, 2024
9f98848
Use typeshare as command name vs typeshare-cli from package
darrell-roberts Nov 21, 2024
00eeb01
Merge pull request #214 from 1Password/dr/binary-name
darrell-roberts Nov 21, 2024
5b33b2f
Update to v1.13.2
darrell-roberts Nov 21, 2024
66bdec3
Merge pull request #215 from 1Password/dr/v1.13.2
darrell-roberts Nov 21, 2024
44f63cc
[typeshare] Support linux-arm64 and support u64 (#1)
naveenOnarayanan Nov 6, 2024
ce2f7da
[typeshare] Fixing formatting (#2)
naveenOnarayanan Nov 6, 2024
4276775
Delete .github/workflows/docdeploy.yml (#3)
naveenOnarayanan Nov 6, 2024
4d88281
[release] Updating typeshare release flow (#4)
naveenOnarayanan Nov 7, 2024
aadd8dc
[typeshare] Disable windows release (#5)
naveenOnarayanan Nov 7, 2024
b4f7ca2
[typeshare] Small fix to release script (#6)
naveenOnarayanan Nov 7, 2024
f4206df
[typeshare] Support external tags for enums (#7)
naveenOnarayanan Nov 7, 2024
9ef9e5e
[release] Remove break-packages for CI (#8)
naveenOnarayanan Nov 7, 2024
f3f8abb
Merge branch 'main' into nn/merge-upstream
naveenOnarayanan Nov 22, 2024
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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Version 1.13.2
- Fix binary name in --help --version so typeshare is the name and not typeshare-cli: [#214](https://github.com/1Password/typeshare/pull/214)

# Version 1.13.1
- Fix duplicate root added to walker: [#209](https://github.com/1Password/typeshare/pull/209)
- Only assert if go package is present if generating go types: [#211](https://github.com/1Password/typeshare/pull/211)
- Update shell completions for new generate function: [#212](https://github.com/1Password/typeshare/pull/212)

# Version 1.13.0
- Update how logging is initialized: [#206](https://github.com/1Password/typeshare/pull/206)
- Don't recreate `Codable.swift` when the contents have not changed [#205](https://github.com/1Password/typeshare/pull/205)
- Fix target_os parsing when no --target-os is provided [#204](https://github.com/1Password/typeshare/pull/204)

# Version 1.12.0

- Optional slices in Go no longer trigger a pointer redirection.
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

12 changes: 6 additions & 6 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "typeshare-cli"
version = "1.12.1"
version = "1.13.2"
edition = "2021"
description = "Command Line Tool for generating language files with typeshare"
license = "MIT OR Apache-2.0"
Expand All @@ -16,17 +16,17 @@ go = []

[dependencies]
clap = { version = "4.5", features = [
"cargo",
"derive",
"unicode",
"wrap_help",
"cargo",
"derive",
"unicode",
"wrap_help",
] }
ignore = "0.4"
once_cell = "1"
rayon = "1.10"
serde = { version = "1", features = ["derive"] }
toml = "0.8"
typeshare-core = { path = "../core", version = "=1.12.1" }
typeshare-core = { path = "../core", version = "=1.13.2" }
log.workspace = true
flexi_logger.workspace = true
anyhow = "1"
Expand Down
3 changes: 2 additions & 1 deletion cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ pub enum AvailableLanguage {
#[command(
version,
args_conflicts_with_subcommands = true,
subcommand_negates_reqs = true
subcommand_negates_reqs = true,
name = "typeshare"
)]
pub struct Args {
#[command(subcommand)]
Expand Down
4 changes: 2 additions & 2 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct SwiftParams {
pub prefix: String,
pub default_decorators: Vec<String>,
pub default_generic_constraints: Vec<String>,
/// The contraints to apply to `CodableVoid`.
/// The constraints to apply to `CodableVoid`.
pub codablevoid_constraints: Vec<String>,
pub type_mappings: HashMap<String, String>,
}
Expand All @@ -55,7 +55,7 @@ pub struct GoParams {
pub type_mappings: HashMap<String, String>,
}

/// The paramters that are used to configure the behaviour of typeshare
/// The parameters that are used to configure the behaviour of typeshare
/// from the configuration file `typeshare.toml`
#[derive(Serialize, Deserialize, Default, Debug, PartialEq)]
#[serde(default)]
Expand Down
63 changes: 37 additions & 26 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ use std::{

use anyhow::{anyhow, Context};
use clap::{CommandFactory, Parser};
use clap_complete::Generator;
use clap_complete::aot::generate;
use flexi_logger::AdaptiveFormat;
use ignore::{overrides::OverrideBuilder, types::TypesBuilder, WalkBuilder};
use log::error;
use log::{error, info};
use rayon::iter::ParallelBridge;
#[cfg(feature = "go")]
use typeshare_core::language::Go;
use typeshare_core::{
context::ParseContext,
language::{
CrateName, GenericConstraints, Kotlin, Language, Scala, SupportedLanguage, Swift,
TypeScript,
Expand All @@ -37,17 +39,21 @@ use crate::{
};

fn main() -> anyhow::Result<()> {
flexi_logger::Logger::try_with_env()
.unwrap()
.start()
.unwrap();
flexi_logger::Logger::try_with_env_or_str("info")?
.adaptive_format_for_stderr(AdaptiveFormat::Detailed)
.adaptive_format_for_stdout(AdaptiveFormat::Detailed)
.start()?;

let options = Args::parse();

info!("typeshare started generating types");

if let Some(options) = options.subcommand {
match options {
Command::Completions { shell } => {
shell.generate(&Args::command(), &mut io::stdout().lock())
let mut cmd = Args::command();
let bin_name = cmd.get_name().to_string();
generate(shell, &mut cmd, bin_name, &mut io::stdout());
}
}

Expand All @@ -69,6 +75,8 @@ fn main() -> anyhow::Result<()> {

let directories = options.directories.as_slice();

info!("Using directories: {directories:?}");

let language_type = match options.language {
None => panic!("no language specified; `clap` should have guaranteed its presence"),
Some(language) => match language {
Expand Down Expand Up @@ -107,7 +115,7 @@ fn main() -> anyhow::Result<()> {
.overrides(overrides)
.follow_links(options.follow_links);

for root in directories {
for root in directories.iter().skip(1) {
walker_builder.add(root);
}

Expand All @@ -124,9 +132,13 @@ fn main() -> anyhow::Result<()> {

let multi_file = matches!(destination, Output::Folder(_));
let target_os = config.target_os.clone();

let mut lang = language(language_type, config, multi_file);
let ignored_types = lang.ignored_reference_types();

let parse_context = ParseContext {
ignored_types: lang.ignored_reference_types(),
multi_file,
target_os,
};

// The walker ignores directories that are git-ignored. If you need
// a git-ignored directory to be processed, add the specific directory to
Expand All @@ -138,9 +150,7 @@ fn main() -> anyhow::Result<()> {
// https://docs.rs/ignore/latest/ignore/struct.WalkParallel.html
let crate_parsed_data = parse_input(
parser_inputs(walker_builder, language_type, multi_file).par_bridge(),
&ignored_types,
multi_file,
&target_os,
&parse_context,
)?;

// Collect all the types into a map of the file name they
Expand All @@ -153,13 +163,17 @@ fn main() -> anyhow::Result<()> {
};

check_parse_errors(&crate_parsed_data)?;

info!("typeshare started writing generated types");

write_generated(
destination,
lang.as_mut(),
crate_parsed_data,
import_candidates,
)?;

info!("typeshare finished generating types");
Ok(())
}

Expand Down Expand Up @@ -244,7 +258,13 @@ fn override_configuration(mut config: Config, options: &Args) -> anyhow::Result<
if let Some(go_package) = options.go_package.as_ref() {
config.go.package = go_package.to_string();
}
assert_go_package_present(&config)?;

if matches!(options.language, Some(args::AvailableLanguage::Go)) {
anyhow::ensure!(
!config.go.package.is_empty(),
"Please provide a package name in the typeshare.toml or using --go-package <package name>"
);
}
}

config.target_os = options.target_os.as_deref().unwrap_or_default().to_vec();
Expand All @@ -262,25 +282,16 @@ fn check_parse_errors(parsed_crates: &BTreeMap<CrateName, ParsedData>) -> anyhow
errors_encountered = true;
for error in &data.errors {
error!(
"Parsing error: \"{}\" in crate \"{}\" for file \"{}\"",
error.error, error.crate_name, error.file_name
"Parsing error: \"{}\" in file \"{}\"",
error.error, error.file_name
);
}
}

if errors_encountered {
error!("Errors encountered during parsing.");
Err(anyhow!("Errors encountered during parsing."))
} else {
Ok(())
}
}

#[cfg(feature = "go")]
fn assert_go_package_present(config: &Config) -> anyhow::Result<()> {
if config.go.package.is_empty() {
return Err(anyhow!(
"Please provide a package name in the typeshare.toml or using --go-package <package name>"
));
}
Ok(())
}
23 changes: 11 additions & 12 deletions cli/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
path::PathBuf,
};
use typeshare_core::{
context::{ParseContext, ParseFileContext},
language::{CrateName, CrateTypes, SupportedLanguage, SINGLE_FILE_CRATE_NAME},
parser::ParsedData,
RenameExt,
Expand Down Expand Up @@ -89,9 +90,7 @@ pub fn all_types(file_mappings: &BTreeMap<CrateName, ParsedData>) -> CrateTypes
/// Collect all the parsed sources into a mapping of crate name to parsed data.
pub fn parse_input(
inputs: impl ParallelIterator<Item = ParserInput>,
ignored_types: &[&str],
multi_file: bool,
target_os: &[String],
parse_context: &ParseContext,
) -> anyhow::Result<BTreeMap<CrateName, ParsedData>> {
inputs
.into_par_iter()
Expand All @@ -103,17 +102,17 @@ pub fn parse_input(
file_name,
crate_name,
}| {
let parsed_result = typeshare_core::parser::parse(
&std::fs::read_to_string(&file_path)
let parse_file_context = ParseFileContext {
source_code: std::fs::read_to_string(&file_path)
.with_context(|| format!("Failed to read input: {file_name}"))?,
crate_name.clone(),
file_name.clone(),
crate_name: crate_name.clone(),
file_name: file_name.clone(),
file_path,
ignored_types,
multi_file,
target_os,
)
.with_context(|| format!("Failed to parse: {file_name}"))?;
};

let parsed_result =
typeshare_core::parser::parse(parse_context, parse_file_context)
.with_context(|| format!("Failed to parse: {file_name}"))?;

if let Some(parsed_data) = parsed_result {
parsed_crates
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "typeshare-core"
version = "1.12.1"
version = "1.13.2"
license = "MIT OR Apache-2.0"
edition = "2021"
description = "The code generator used by Typeshare's command line tool"
Expand Down
11 changes: 11 additions & 0 deletions core/data/tests/excluded_by_target_os/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,14 @@ pub struct AndroidExcluded;
#[typeshare]
#[cfg(all(feature = "my-feature", not(target_os = "ios")))]
pub struct NestedNotTarget1;

/// A struct with no target_os. Should be generated when
/// we use --target-os.
#[typeshare]
pub struct AlwaysAccept;

#[typeshare]
pub enum AlwaysAcceptEnum {
Variant1,
Variant2,
}
9 changes: 9 additions & 0 deletions core/data/tests/excluded_by_target_os/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package proto

import "encoding/json"

// A struct with no target_os. Should be generated when
// we use --target-os.
type AlwaysAccept struct {
}
type DefinedTwice struct {
Field1 string `json:"field1"`
}
Expand All @@ -15,6 +19,11 @@ type NestedNotTarget1 struct {
}
type OtherExcluded struct {
}
type AlwaysAcceptEnum string
const (
AlwaysAcceptEnumVariant1 AlwaysAcceptEnum = "Variant1"
AlwaysAcceptEnumVariant2 AlwaysAcceptEnum = "Variant2"
)
type SomeEnum string
const (
)
Expand Down
13 changes: 13 additions & 0 deletions core/data/tests/excluded_by_target_os/output.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package com.agilebits.onepassword
import kotlinx.serialization.Serializable
import kotlinx.serialization.SerialName

/// A struct with no target_os. Should be generated when
/// we use --target-os.
@Serializable
object AlwaysAccept

@Serializable
data class DefinedTwice (
val field1: String
Expand All @@ -23,6 +28,14 @@ object NestedNotTarget1
@Serializable
object OtherExcluded

@Serializable
enum class AlwaysAcceptEnum(val string: String) {
@SerialName("Variant1")
Variant1("Variant1"),
@SerialName("Variant2")
Variant2("Variant2"),
}

@Serializable
enum class SomeEnum(val string: String) {
}
Expand Down
16 changes: 16 additions & 0 deletions core/data/tests/excluded_by_target_os/output.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package com.agilebits

package onepassword {

// A struct with no target_os. Should be generated when
// we use --target-os.
class AlwaysAccept extends Serializable

case class DefinedTwice (
field1: String
)
Expand All @@ -16,6 +20,18 @@ class NestedNotTarget1 extends Serializable

class OtherExcluded extends Serializable

sealed trait AlwaysAcceptEnum {
def serialName: String
}
object AlwaysAcceptEnum {
case object Variant1 extends AlwaysAcceptEnum {
val serialName: String = "Variant1"
}
case object Variant2 extends AlwaysAcceptEnum {
val serialName: String = "Variant2"
}
}

sealed trait SomeEnum {
def serialName: String
}
Expand Down
Loading
Loading