diff --git a/.idea/lox-space.iml b/.idea/lox-space.iml index 7e2df88b..5407fa9f 100644 --- a/.idea/lox-space.iml +++ b/.idea/lox-space.iml @@ -12,6 +12,7 @@ + diff --git a/crates/lox_core/src/bodies.rs b/crates/lox_core/src/bodies.rs index 83d85832..1f938e81 100644 --- a/crates/lox_core/src/bodies.rs +++ b/crates/lox_core/src/bodies.rs @@ -10,11 +10,8 @@ use std::f64::consts::PI; use crate::time::constants::f64::{SECONDS_PER_DAY, SECONDS_PER_JULIAN_CENTURY}; -pub mod barycenters; -pub mod minor; -pub mod planets; -pub mod satellites; -pub mod sun; +mod generated; +pub use generated::*; /// NaifId is implemented for all bodies. pub trait NaifId: Copy { diff --git a/crates/lox_core/src/bodies/generated.rs b/crates/lox_core/src/bodies/generated.rs new file mode 100644 index 00000000..bbef07ca --- /dev/null +++ b/crates/lox_core/src/bodies/generated.rs @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023. Helge Eichhorn and the LOX contributors + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at http://mozilla.org/MPL/2.0/. + */ + +//! generated holds trait implementations that have been generated by `lox_gen`, separating +//! generated code from manual implementations. +//! +//! Artifacts in its submodules are intended to be transparently re-exported. + +pub mod barycenters; +pub mod minor; +pub mod planets; +pub mod satellites; +pub mod sun; diff --git a/crates/lox_core/src/bodies/barycenters.rs b/crates/lox_core/src/bodies/generated/barycenters.rs similarity index 98% rename from crates/lox_core/src/bodies/barycenters.rs rename to crates/lox_core/src/bodies/generated/barycenters.rs index fa2d6e71..f5afb802 100644 --- a/crates/lox_core/src/bodies/barycenters.rs +++ b/crates/lox_core/src/bodies/generated/barycenters.rs @@ -8,7 +8,7 @@ // Auto-generated by `lox_gen`. Do not edit! -use super::{ +use crate::bodies::{ EarthBarycenter, JupiterBarycenter, MarsBarycenter, MercuryBarycenter, NeptuneBarycenter, PlutoBarycenter, PointMass, SaturnBarycenter, UranusBarycenter, VenusBarycenter, }; @@ -60,7 +60,7 @@ impl PointMass for PlutoBarycenter { #[cfg(test)] #[allow(clippy::approx_constant)] mod tests { - use super::*; + use crate::bodies::*; #[test] fn test_point_mass_1() { assert_eq!( diff --git a/crates/lox_core/src/bodies/minor.rs b/crates/lox_core/src/bodies/generated/minor.rs similarity index 99% rename from crates/lox_core/src/bodies/minor.rs rename to crates/lox_core/src/bodies/generated/minor.rs index 7fecf53a..0a2c155e 100644 --- a/crates/lox_core/src/bodies/minor.rs +++ b/crates/lox_core/src/bodies/generated/minor.rs @@ -8,7 +8,7 @@ // Auto-generated by `lox_gen`. Do not edit! -use super::{ +use crate::bodies::{ Bennu, Braille, Ceres, Dactyl, Davida, Ellipsoid, Eros, Gaspra, Ida, Itokawa, Kleopatra, Lutetia, Mathilde, NutationPrecessionCoefficients, Pallas, PointMass, PolynomialCoefficients, Psyche, RotationalElements, Steins, Toutatis, TriAxial, Vesta, WilsonHarrington, @@ -448,7 +448,7 @@ impl RotationalElements for Bennu { #[cfg(test)] #[allow(clippy::approx_constant)] mod tests { - use super::*; + use crate::bodies::*; #[test] fn test_tri_axial_9511010() { assert_eq!(Gaspra::polar_radius(), 4.4f64); diff --git a/crates/lox_core/src/bodies/planets.rs b/crates/lox_core/src/bodies/generated/planets.rs similarity index 99% rename from crates/lox_core/src/bodies/planets.rs rename to crates/lox_core/src/bodies/generated/planets.rs index 7e45b6d7..50958b02 100644 --- a/crates/lox_core/src/bodies/planets.rs +++ b/crates/lox_core/src/bodies/generated/planets.rs @@ -8,7 +8,7 @@ // Auto-generated by `lox_gen`. Do not edit! -use super::{ +use crate::bodies::{ Earth, Ellipsoid, Jupiter, Mars, Mercury, Neptune, NutationPrecessionCoefficients, Pluto, PointMass, PolynomialCoefficients, RotationalElements, Saturn, Spheroid, Uranus, Venus, }; @@ -746,7 +746,7 @@ impl RotationalElements for Pluto { #[cfg(test)] #[allow(clippy::approx_constant)] mod tests { - use super::*; + use crate::bodies::*; #[test] fn test_point_mass_199() { assert_eq!(Mercury::gravitational_parameter(), 22031.868551400003f64); diff --git a/crates/lox_core/src/bodies/satellites.rs b/crates/lox_core/src/bodies/generated/satellites.rs similarity index 99% rename from crates/lox_core/src/bodies/satellites.rs rename to crates/lox_core/src/bodies/generated/satellites.rs index 5fb9dda3..cc091e1c 100644 --- a/crates/lox_core/src/bodies/satellites.rs +++ b/crates/lox_core/src/bodies/generated/satellites.rs @@ -8,7 +8,7 @@ // Auto-generated by `lox_gen`. Do not edit! -use super::{ +use crate::bodies::{ Adrastea, Aegaeon, Aegir, Aitne, Albiorix, Amalthea, Ananke, Anthe, Aoede, Arche, Ariel, Atlas, Autonoe, Bebhionn, Belinda, Bergelmir, Bestla, Bianca, Caliban, Callirrhoe, Callisto, Calypso, Carme, Carpo, Chaldene, Charon, Cordelia, Cressida, Cupid, Cyllene, Daphnis, Deimos, Desdemona, @@ -4856,7 +4856,7 @@ impl RotationalElements for Styx { #[cfg(test)] #[allow(clippy::approx_constant)] mod tests { - use super::*; + use crate::bodies::*; #[test] fn test_point_mass_301() { assert_eq!(Moon::gravitational_parameter(), 4902.80011845755f64); diff --git a/crates/lox_core/src/bodies/sun.rs b/crates/lox_core/src/bodies/generated/sun.rs similarity index 98% rename from crates/lox_core/src/bodies/sun.rs rename to crates/lox_core/src/bodies/generated/sun.rs index 164f8e7d..b0b41446 100644 --- a/crates/lox_core/src/bodies/sun.rs +++ b/crates/lox_core/src/bodies/generated/sun.rs @@ -8,7 +8,7 @@ // Auto-generated by `lox_gen`. Do not edit! -use super::{ +use crate::bodies::{ Ellipsoid, NutationPrecessionCoefficients, PointMass, PolynomialCoefficients, RotationalElements, Spheroid, Sun, }; @@ -48,7 +48,7 @@ impl RotationalElements for Sun { #[cfg(test)] #[allow(clippy::approx_constant)] mod tests { - use super::*; + use crate::bodies::*; #[test] fn test_point_mass_10() { assert_eq!(Sun::gravitational_parameter(), 132712440041.27942f64); diff --git a/tools/lox_gen/Cargo.lock b/tools/lox_gen/Cargo.lock index 0d4e824f..dad0f53a 100644 --- a/tools/lox_gen/Cargo.lock +++ b/tools/lox_gen/Cargo.lock @@ -20,6 +20,12 @@ version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5418c17512bdf42730f9032c74e1ae39afc408745ebb2acf72fbc4691c17945" +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "lox_core" version = "0.1.0" @@ -35,6 +41,7 @@ dependencies = [ name = "lox_gen" version = "0.1.0" dependencies = [ + "lazy_static", "lox_core", "lox_io", "proc-macro2", diff --git a/tools/lox_gen/Cargo.toml b/tools/lox_gen/Cargo.toml index 72c9b9d4..5943c6dd 100644 --- a/tools/lox_gen/Cargo.toml +++ b/tools/lox_gen/Cargo.toml @@ -11,3 +11,4 @@ quote = "1.0" lox_io = { path = "../../crates/lox_io" } lox_core = { path = "../../crates/lox_core" } thiserror = "1.0.50" +lazy_static = "1.4.0" diff --git a/tools/lox_gen/src/main.rs b/tools/lox_gen/src/main.rs index fdcfea02..ca8ee2cd 100644 --- a/tools/lox_gen/src/main.rs +++ b/tools/lox_gen/src/main.rs @@ -6,9 +6,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use lazy_static::lazy_static; use std::collections::HashSet; use std::fs; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::process::Command; use proc_macro2::{Ident, TokenStream}; @@ -80,14 +81,21 @@ const COPYRIGHT_NOTICE: &str = "/* const AUTO_GENERATION_NOTICE: &str = "// Auto-generated by `lox_gen`. Do not edit!\n\n"; +lazy_static! { + static ref TARGET_DIR: PathBuf = { + let parent = Path::new(file!()).parent().unwrap(); + parent.join(Path::new("../../../crates/lox_core/src/bodies/generated/")) + }; +} + fn write_file(file: &str, bodies: &[Body], generators: &[Generator], data: &Data) { - let path = format!("../../../crates/lox_core/src/bodies/{file}.rs"); let mut code = String::from(COPYRIGHT_NOTICE); code.push_str(AUTO_GENERATION_NOTICE); code.push_str(&generate_code(bodies, generators, data)); - let file = Path::new(file!()); - let out = file.parent().unwrap().join(path); + + let out = TARGET_DIR.join(format!("{}.rs", file)); fs::write(&out, code).expect("file should be writeable"); + Command::new("rustfmt") .args([out.to_str().unwrap()]) .status() @@ -108,14 +116,14 @@ fn generate_code(bodies: &[Body], generators: &[Generator], data: &Data) -> Stri let imports_iter = imports.iter(); let module = quote! { - use super::{#(#imports_iter),*}; + use crate::bodies::{#(#imports_iter),*}; #code #[cfg(test)] #[allow(clippy::approx_constant)] // at least one parsed constant is close to TAU mod tests { - use super::*; + use crate::bodies::*; #tests }