Skip to content

Commit

Permalink
misc fixes;
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtbuilds committed Nov 29, 2023
1 parent a6ee882 commit 70d6930
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 106 deletions.
142 changes: 96 additions & 46 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion core/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn copy_files_recursive(
}

/// Copy static files to the destination path.
pub fn copy_files(dest_path: &Path, project_template: &str, ignore: &[&str]) -> anyhow::Result<()> {
pub fn copy_builtin_files(dest_path: &Path, project_template: &str, ignore: &[&str]) -> anyhow::Result<()> {
copy_files_recursive(
dest_path,
TEMPLATE_DIR.get_dir(project_template).unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion core/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{OutputOptions, write_file};
pub static TEMPLATE_DIR: include_dir::Dir<'_> =
include_dir::include_dir!("$CARGO_MANIFEST_DIR/template");

pub fn copy_templates(
pub fn copy_builtin_templates(
opts: &OutputOptions,
tera: &tera::Tera,
context: &Context,
Expand Down
2 changes: 1 addition & 1 deletion core/template/rust/Cargo.toml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repository = "https://github.com/{{ github_repo }}"
doctest = false

[dependencies]
httpclient = "0.18.0"
httpclient = "0.19.0"
serde = { version = "1.0.137", features = ["derive"] }
serde_json = "1.0.81"
futures = "0.3.25"
Expand Down
5 changes: 3 additions & 2 deletions libninja/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ tera = "1.19.0"
include_dir = "0.7.3"
regex = "1.9.0"
indoc = "2.0.2"
cargo_toml = "0.15.3"
toml = "0.7.6"
cargo_toml = "0.17.1"
toml = "0.8.8"
topo_sort = "0.4.0"
url = "2.4.0"
http = "0.2.9"
Expand All @@ -45,6 +45,7 @@ ln-core = { path = "../core" }
libninja_mir = { path = "../mir" }
libninja_hir = { path = "../hir" }
libninja_commercial = { path = "../commercial" , optional = true }
ignore = "0.4.21"

[dev-dependencies]
env_logger = "0.10.0"
Expand Down
27 changes: 23 additions & 4 deletions libninja/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::hash::Hash;
use std::path::Path;
use std::thread::current;

use anyhow::Result;
use anyhow::{anyhow, Result};
use convert_case::{Case, Casing};
use indoc::formatdoc;
use openapiv3::OpenAPI;
Expand All @@ -12,7 +12,7 @@ use quote::quote;
use codegen::ToRustIdent;
use codegen::ToRustType;
use format::format_code;
use ln_core::{copy_files, copy_templates, create_context, get_template_file, prepare_templates};
use ln_core::{copy_builtin_files, copy_builtin_templates, create_context, get_template_file, prepare_templates};
use ::mir::{Visibility, Import, File};
use ln_core::fs;
use hir::{HirSpec, IntegerSerialization, DateSerialization};
Expand Down Expand Up @@ -91,6 +91,24 @@ pub fn calculate_extras(spec: &HirSpec) -> Extras {
}


pub fn copy_from_target_templates(opts: &OutputOptions) -> Result<()> {
let template_path = opts.dest_path.join("template");
for path in ignore::Walk::new(&template_path) {
let path: ignore::DirEntry = path?;
let rel_path = path.path().strip_prefix(&template_path)?;
if rel_path.to_str().unwrap() == "src/lib.rs" {
continue;
}
if path.file_type().expect(&format!("Failed to read file: {}", path.path().display())).is_file() {
let dest = opts.dest_path.join(rel_path);
fs::create_dir_all(dest.parent().unwrap())?;
//copy the file
std::fs::copy(&path.path(), &dest)?;
}
}
Ok(())
}

pub fn generate_rust_library(spec: OpenAPI, opts: OutputOptions) -> Result<()> {
let config = &opts.library_options.config;
let src_path = opts.dest_path.join("src");
Expand Down Expand Up @@ -123,8 +141,9 @@ pub fn generate_rust_library(spec: OpenAPI, opts: OutputOptions) -> Result<()> {

context.insert("client_docs_url", &format!("https://docs.rs/{}", opts.library_options.package_name));

copy_files(&opts.dest_path, &opts.library_options.language.to_string(), &["src"])?;
copy_templates(&opts, &tera, &context)?;
copy_builtin_files(&opts.dest_path, &opts.library_options.language.to_string(), &["src"])?;
copy_builtin_templates(&opts, &tera, &context)?;
copy_from_target_templates(&opts)?;

bump_version_and_update_deps(&extras, &opts)?;

Expand Down
Loading

0 comments on commit 70d6930

Please sign in to comment.