Skip to content

Commit

Permalink
Renaming project to library
Browse files Browse the repository at this point in the history
  • Loading branch information
notdanilo committed Nov 3, 2023
1 parent 71fb103 commit 8f54d44
Show file tree
Hide file tree
Showing 37 changed files with 186 additions and 185 deletions.
2 changes: 1 addition & 1 deletion ecosystem/c/cmake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ edition.workspace = true
license.workspace = true
name = "ligen-cmake"
version = "0.1.4"
description = "CMake project generator"
description = "CMake library generator"
documentation = "https://docs.rs/ligen-cmake"
readme = "README.md"

Expand Down
2 changes: 1 addition & 1 deletion ecosystem/c/cmake/src/CMakeLists.txt.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Auto-generated by ligen-cmake {generator_version}

CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
PROJECT("{project_name}")
PROJECT("{library_name}")

IF(TARGET ${{PROJECT_NAME}})
RETURN()
Expand Down
2 changes: 1 addition & 1 deletion ecosystem/c/cmake/src/CMakeLists.txt.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Auto-generated by ligen-cmake {generator_version}

CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
PROJECT("{project_name}")
PROJECT("{library_name}")

IF(TARGET ${{PROJECT_NAME}})
RETURN()
Expand Down
10 changes: 5 additions & 5 deletions ecosystem/c/cmake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ligen::traits::generator::file_generator::{File, FileSet, FileGenerator};
use std::path::PathBuf;
use ligen::ir::conventions::naming::SnakeCase;

/// CMake project generator.
/// CMake library generator.
#[derive(Debug, Clone)]
pub struct CMakeGenerator(pub Language);

Expand All @@ -18,20 +18,20 @@ impl FileGenerator for CMakeGenerator {
"c".into()
}

fn generate_files(&self, project: &Project, file_set: &mut FileSet) -> Result<()> {
fn generate_files(&self, library: &Library, file_set: &mut FileSet) -> Result<()> {
let generator_version = env!("CARGO_PKG_VERSION");
let project_name = SnakeCase::try_from(project.name.clone())?.to_string();
let library_name = SnakeCase::try_from(library.name.clone())?.to_string();

let content = match self.0 {
Language::CPP => format!(
include_str!("CMakeLists.txt.cpp"),
generator_version = generator_version,
project_name = project_name
library_name = library_name
),
Language::C => format!(
include_str!("CMakeLists.txt.c"),
generator_version = generator_version,
project_name = project_name
library_name = library_name
)
};
let file = File::new(PathBuf::from("CMakeLists.txt"), content);
Expand Down
6 changes: 3 additions & 3 deletions ecosystem/c/generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct CGenerator;

impl TemplateRegister for CGenerator {
fn register_templates(&self, template: &mut Template) -> Result<()> {
register_templates!(template, identifier, arguments, implementation, method, function, module, object, parameters, project);
register_templates!(template, identifier, arguments, implementation, method, function, module, object, parameters, library);
Ok(())
}
}
Expand Down Expand Up @@ -80,15 +80,15 @@ fn mapped_type(inputs: &Inputs) -> String {
}

impl TemplateBasedGenerator for CGenerator {
fn register_functions(&self, _project: &Project, template: &mut Template) {
fn register_functions(&self, _library: &Library, template: &mut Template) {
register_functions!(template, mapped_type);
}

fn base_path(&self) -> PathBuf {
PathBuf::from("c".to_string())
}

fn module_generation_path(&self, _project: &Project, _module: &Module) -> PathBuf {
fn module_generation_path(&self, _library: &Library, _module: &Module) -> PathBuf {
let mut path = PathBuf::from_str("include").unwrap();
// FIXME: This is not working.
// path = path.join(PathBuf::from(module.path.clone()));
Expand Down
6 changes: 3 additions & 3 deletions ecosystem/python/parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::function::FunctionParser;
use crate::identifier::IdentifierParser;
use crate::types::type_definition::TypeDefinitionParser;

use ligen::ir::Project;
use ligen::ir::Library;

#[derive(Default)]
pub struct PythonParser {
Expand All @@ -29,11 +29,11 @@ impl PythonParser {
}

impl Parser<&std::path::Path> for PythonParser {
type Output = Project;
type Output = Library;
fn parse(&self, input: &std::path::Path) -> Result<Self::Output> {
let name = self.identifier_parser.parse(input)?;
let name = name.name.as_str().try_into()?;
let root_module = self.parse(SubPath(input))?;
Ok(Project { name, root_module })
Ok(Library { name, root_module })
}
}
22 changes: 11 additions & 11 deletions ecosystem/rust/cargo/src/build_system.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::path::{PathBuf, Path};
use ligen_ir::{prelude::*, Project};
use ligen_ir::{prelude::*, Library};
use ligen_traits::build::{BuildSystem, BuildProfile};
use ligen_ir::conventions::naming::SnakeCase;

Expand Down Expand Up @@ -30,7 +30,7 @@ impl CargoBuilder {

impl BuildSystem for CargoBuilder {
fn check_build() -> Result<()> {
// The TemporaryProject shouldn't be available if we are currently building it.
// The TemporaryLibrary shouldn't be available if we are currently building it.
let is_building = std::env::var("LIGEN_IS_BUILDING").unwrap_or("NO".into()) == "YES";
if is_building {
Err(Error::Message("Cargo is currently building.".into()))
Expand All @@ -39,7 +39,7 @@ impl BuildSystem for CargoBuilder {
}
}

fn build_with_profile(&self, project: &Project, profile: BuildProfile) -> Result<()> {
fn build_with_profile(&self, library: &Library, profile: BuildProfile) -> Result<()> {
Self::check_build()?;
std::env::set_var("LIGEN_IS_BUILDING", "YES");
let mut build_command = std::process::Command::new("cargo");
Expand All @@ -48,15 +48,15 @@ impl BuildSystem for CargoBuilder {
build_command = build_command.arg("--release");
}

let project_name = SnakeCase::try_from(project.name.clone())?.to_string();
let library_name = SnakeCase::try_from(library.name.clone())?.to_string();
let ligen_path = Self::target_dir()
.unwrap()
.join("ligen");
let project_path = ligen_path
let library_path = ligen_path
.join("rust")
.join(&project_name);
let manifest_path = project_path.join("Cargo.toml");
let target_dir = project_path.join("target");
.join(&library_name);
let manifest_path = library_path.join("Cargo.toml");
let target_dir = library_path.join("target");

let status = build_command
.arg("--manifest-path")
Expand All @@ -73,11 +73,11 @@ impl BuildSystem for CargoBuilder {
.filter_map(|entry| entry.ok());
let libraries_dir = ligen_path
.join("libraries")
.join(&project_name);
.join(&library_name);
std::fs::create_dir_all(&libraries_dir)?;
for entry in directory {
if let Some(file_name) = entry.file_name().to_str() {
if entry.file_type()?.is_file() && file_name.contains(&project_name) {
if entry.file_type()?.is_file() && file_name.contains(&library_name) {
std::fs::copy(&entry.path(), libraries_dir.join(file_name))?;
}
}
Expand All @@ -95,7 +95,7 @@ mod tests {

#[test]
fn target_dir() {
let path = CargoBuilder::target_dir_from_out_dir(Some("target/debug/build/project-cb2a7557d006cbbc/out".into())).expect("Failed to get target dir.");
let path = CargoBuilder::target_dir_from_out_dir(Some("target/debug/build/library-cb2a7557d006cbbc/out".into())).expect("Failed to get target dir.");
assert_eq!(Path::new("target"), path.as_path());
}
}
6 changes: 3 additions & 3 deletions ecosystem/rust/cargo/src/exporter/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ligen_ir::Project;
use ligen_ir::Library;
use ligen_traits::generator::file_generator::{FileGenerator, FileSet};
use std::path::PathBuf;
use std::str::FromStr;
Expand All @@ -12,10 +12,10 @@ impl FileGenerator for CargoGenerator {
PathBuf::from("rust".to_string())
}

fn generate_files(&self, project: &Project, file_set: &mut FileSet) -> Result<()> {
fn generate_files(&self, library: &Library, file_set: &mut FileSet) -> Result<()> {
let file = file_set.entry(&PathBuf::from_str("Cargo.toml").unwrap());
let version = "0.1.0";
let name = &project.name;
let name = &library.name;
// FIXME: This is a placeholder and it will fail.
let path = PathBuf::default();
let path = path.display().to_string().replace('\\', "/");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use ligen_ir::conventions::naming::{SnakeCase, NamingConvention};
use ligen_ir::prelude::*;
use ligen_ir::Project;
use ligen_ir::Library;
use ligen_parsing::parser::Parser;
use ligen_rust_parser::module::ModuleParser;

pub struct ProjectParser;
pub struct LibraryParser;

impl Parser<&std::path::Path> for ProjectParser {
type Output = Project;
impl Parser<&std::path::Path> for LibraryParser {
type Output = Library;
fn parse(&self, input: &std::path::Path) -> Result<Self::Output> {
let cargo_path = if input.is_dir() {
input.join("Cargo.toml")
Expand Down
2 changes: 1 addition & 1 deletion ecosystem/rust/cargo/src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod project;
pub mod library;
8 changes: 4 additions & 4 deletions ecosystem/rust/exporter/src/generator/exporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,22 @@ pub struct RustGenerator;

impl TemplateRegister for RustGenerator {
fn register_templates(&self, template: &mut Template) -> Result<()> {
register_templates!(template, identifier, arguments, implementation, method, function, module, object, parameters, project);
register_templates!(template, identifier, arguments, implementation, method, function, module, object, parameters, library);
Ok(())
}
}

impl TemplateBasedGenerator for RustGenerator {
fn register_functions(&self, _project: &Project, template: &mut Template) {
fn register_functions(&self, _library: &Library, template: &mut Template) {
register_functions!(template, mapped_type, marshal_output);
}

fn base_path(&self) -> PathBuf {
PathBuf::from("rust".to_string())
}

fn module_generation_path(&self, _project: &Project, _module: &Module) -> PathBuf {
// let is_root_module = project.root_module == *module;
fn module_generation_path(&self, _library: &Library, _module: &Module) -> PathBuf {
// let is_root_module = library.root_module == *module;
// let name = if is_root_module { "lib.rs" } else { "mod.rs" };
let path = PathBuf::from_str("src").unwrap();
// path = path.join(PathBuf::from(module.path.clone().without_first()));
Expand Down
2 changes: 1 addition & 1 deletion ecosystem/rust/parser/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn module_file() {
],
.. Default::default()
};
let project_root = project_root::get_project_root().expect("Failed to get project root.");
let project_root = project_root::get_project_root().expect("Failed to get library root.");
let path = project_root.join(file!());
assert_eq(ModuleParser, module, path.as_path()).unwrap()
}
16 changes: 8 additions & 8 deletions ecosystem/rust/runtime/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ fn main() {
#[cfg(feature = "bindings")]
{
use ligen::prelude::*;
use ligen_cargo::{CargoProject, CargoGenerator, CargoBuilder};
use ligen_cargo::{CargoLibrary, CargoGenerator, CargoBuilder};
use ligen_rust::RustGenerator;
use ligen_c::CGenerator;
use ligen_cmake::{CMakeGenerator, Language};
use ligen::traits::build::BuildSystem;

match CargoProject::current().and_then(Project::try_from) {
Ok(project) => {
CargoGenerator::default().generate(&project).expect("Failed to generate Cargo interface.");
RustGenerator::default().generate(&project).expect("Failed to generate Rust interface.");
CGenerator::default().generate(&project).expect("Failed to generate C interface.");
CMakeGenerator(Language::C).generate(&project).expect("Failed to generate CMake project.");
CargoBuilder.build(&project).expect("Failed to build Cargo project.");
match CargoLibrary::current().and_then(Library::try_from) {
Ok(library) => {
CargoGenerator::default().generate(&library).expect("Failed to generate Cargo interface.");
RustGenerator::default().generate(&library).expect("Failed to generate Rust interface.");
CGenerator::default().generate(&library).expect("Failed to generate C interface.");
CMakeGenerator(Language::C).generate(&library).expect("Failed to generate CMake library.");
CargoBuilder.build(&library).expect("Failed to build Cargo library.");
},
Err(_) => ()
}
Expand Down
4 changes: 2 additions & 2 deletions ligen/ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use path::{Path, PathSegment};
pub use macro_attributes::{Attributes, Attribute, MacroAttributes, attributes, attribute};
pub use types::*;
pub use visibility::*;
pub use project::*;
pub use library::*;
pub use mutability::*;
pub use interface::*;

Expand All @@ -28,7 +28,7 @@ pub mod interface;
pub mod path;
pub mod mutability;
pub mod source;
pub mod project;
pub mod library;
pub mod conventions;

pub mod symbols;
15 changes: 8 additions & 7 deletions ligen/ir/src/project/mod.rs → ligen/ir/src/library/mod.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
//! Project representation.
// FIXME: Look for mentions to "library" and rename it to "library".
//! Library representation.
use crate::Module;
use crate::prelude::*;
use crate::conventions::naming::NamingConvention;

/// Project representation.
/// Library representation.
#[allow(missing_docs)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
pub struct Project {
pub struct Library {
pub name: NamingConvention,
pub root_module: Module,
}

impl Project {
/// Get the project name.
impl Library {
/// Get the library name.
pub fn name(&self) -> &NamingConvention {
&self.name
}

/// Save project to file.
/// Save library to file.
pub fn save(&self, path: impl AsRef<std::path::Path>) -> Result<()> {
let contents = serde_json::to_string_pretty(self)?;
std::fs::write(path, contents)?;
Ok(())
}

/// Load project from file.
/// Load library from file.
pub fn load(path: impl AsRef<std::path::Path>) -> Result<Self> {
let json = std::fs::read_to_string(path)?;
Ok(serde_json::from_str(&json)?)
Expand Down
2 changes: 1 addition & 1 deletion ligen/ir/src/source/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ use std::path::PathBuf;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Directory {
pub path: PathBuf,
pub project_file: Option<PathBuf>
pub library_file: Option<PathBuf>
}
6 changes: 3 additions & 3 deletions ligen/ir/src/symbols/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::{Project, Path, Module, interface};
use crate::{Library, Path, Module, interface};

#[derive(Default)]
pub struct Symbols {
pub symbols: Vec<Path>,
}

impl Symbols {
pub fn new(project: &Project) -> Self {
let symbols = Self::from_module(&project.root_module, &Default::default());
pub fn new(library: &Library) -> Self {
let symbols = Self::from_module(&library.root_module, &Default::default());
Symbols { symbols }
}

Expand Down
Loading

0 comments on commit 8f54d44

Please sign in to comment.