Move info.toml to rustlings-macros/

This improves the experience for contributors on Windows becuase
Windows can't deal with git symbolic links out of the box…
This commit is contained in:
mo8it 2024-05-13 01:25:38 +02:00
parent d9df809838
commit 11fda5d70f
7 changed files with 1295 additions and 1292 deletions

View file

@ -37,7 +37,7 @@ Please be patient 😇
- Name the file `exercises/yourTopic/yourTopicN.rs`. - Name the file `exercises/yourTopic/yourTopicN.rs`.
- Make sure to put in some helpful links, and link to sections of the book in `exercises/yourTopic/README.md`. - Make sure to put in some helpful links, and link to sections of the book in `exercises/yourTopic/README.md`.
- Add a (possible) solution at `solutions/yourTopic/yourTopicN.rs` with comments and links explaining it. - Add a (possible) solution at `solutions/yourTopic/yourTopicN.rs` with comments and links explaining it.
- Add the [metadata for your exercise](#exercise-metadata) in the `info.toml` file. - Add the [metadata for your exercise](#exercise-metadata) in the `rustlings-macros/info.toml` file.
- Make sure your exercise runs with `rustlings run yourTopicN`. - Make sure your exercise runs with `rustlings run yourTopicN`.
- [Open a pull request](#pull-requests). - [Open a pull request](#pull-requests).

View file

@ -39,7 +39,6 @@ include = [
"/src/", "/src/",
"/exercises/", "/exercises/",
"/solutions/", "/solutions/",
"/info.toml",
# A symlink to be able to include `dev/Cargo.toml` although `dev` is excluded. # A symlink to be able to include `dev/Cargo.toml` although `dev` is excluded.
"/dev-Cargo.toml", "/dev-Cargo.toml",
"/README.md", "/README.md",

1286
info.toml

File diff suppressed because it is too large Load diff

View file

@ -1 +0,0 @@
../info.toml

1286
rustlings-macros/info.toml Normal file

File diff suppressed because it is too large Load diff

View file

@ -15,7 +15,8 @@ struct InfoFile {
#[proc_macro] #[proc_macro]
pub fn include_files(_: TokenStream) -> TokenStream { pub fn include_files(_: TokenStream) -> TokenStream {
let exercises = toml_edit::de::from_str::<InfoFile>(include_str!("../info.toml")) let info_file = include_str!("../info.toml");
let exercises = toml_edit::de::from_str::<InfoFile>(info_file)
.expect("Failed to parse `info.toml`") .expect("Failed to parse `info.toml`")
.exercises; .exercises;
@ -46,6 +47,7 @@ pub fn include_files(_: TokenStream) -> TokenStream {
quote! { quote! {
EmbeddedFiles { EmbeddedFiles {
info_file: #info_file,
exercise_files: &[#(ExerciseFiles { exercise: include_bytes!(#exercise_files), solution: include_bytes!(#solution_files), dir_ind: #dir_inds }),*], exercise_files: &[#(ExerciseFiles { exercise: include_bytes!(#exercise_files), solution: include_bytes!(#solution_files), dir_ind: #dir_inds }),*],
exercise_dirs: &[#(ExerciseDir { name: #dirs, readme: include_bytes!(#readmes) }),*] exercise_dirs: &[#(ExerciseDir { name: #dirs, readme: include_bytes!(#readmes) }),*]
} }

View file

@ -70,6 +70,7 @@ impl ExerciseDir {
} }
pub struct EmbeddedFiles { pub struct EmbeddedFiles {
pub info_file: &'static str,
exercise_files: &'static [ExerciseFiles], exercise_files: &'static [ExerciseFiles],
exercise_dirs: &'static [ExerciseDir], exercise_dirs: &'static [ExerciseDir],
} }
@ -148,7 +149,7 @@ mod tests {
#[test] #[test]
fn dirs() { fn dirs() {
let exercises = toml_edit::de::from_str::<InfoFile>(include_str!("../info.toml")) let exercises = toml_edit::de::from_str::<InfoFile>(EMBEDDED_FILES.info_file)
.expect("Failed to parse `info.toml`") .expect("Failed to parse `info.toml`")
.exercises; .exercises;

View file

@ -2,6 +2,8 @@ use anyhow::{bail, Context, Error, Result};
use serde::Deserialize; use serde::Deserialize;
use std::{fs, io::ErrorKind}; use std::{fs, io::ErrorKind};
use crate::embedded::EMBEDDED_FILES;
// Deserialized from the `info.toml` file. // Deserialized from the `info.toml` file.
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct ExerciseInfo { pub struct ExerciseInfo {
@ -47,7 +49,7 @@ impl InfoFile {
.context("Failed to parse the `info.toml` file")?, .context("Failed to parse the `info.toml` file")?,
Err(e) => { Err(e) => {
if e.kind() == ErrorKind::NotFound { if e.kind() == ErrorKind::NotFound {
return toml_edit::de::from_str(include_str!("../info.toml")) return toml_edit::de::from_str(EMBEDDED_FILES.info_file)
.context("Failed to parse the embedded `info.toml` file"); .context("Failed to parse the embedded `info.toml` file");
} }