From a60b31a90f1c637f50d56156143f8c66861d4eca Mon Sep 17 00:00:00 2001 From: angie Date: Fri, 23 Feb 2024 15:51:56 -0300 Subject: [PATCH] Document file for file format Issue #8 --- docs/file_format/file.md | 51 ++++++++++++++++++++++++++++++++++++ docs/file_format/files.md | 3 --- docs/file_format/segments.md | 2 +- slinky/src/document.rs | 7 ++++- slinky/src/file_info.rs | 7 +---- slinky/src/file_kind.rs | 1 + slinky/src/linker_writer.rs | 2 +- 7 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 docs/file_format/file.md delete mode 100644 docs/file_format/files.md diff --git a/docs/file_format/file.md b/docs/file_format/file.md new file mode 100644 index 0000000..e048e10 --- /dev/null +++ b/docs/file_format/file.md @@ -0,0 +1,51 @@ +# File + +A file entry describes information about a file that should be linked in a +segment. + +Every attribute listed is optional unless explicitly stated. + +## `path` + +This is **required**. + +Path to the file. + +The `base_path` from settings is used as a base for the emitted path. + +### Example + +```yaml +segments: + - name: boot + files: + - { path: src/boot/boot_main.o } +``` + +### Valid values + +Any valid path. + +## `kind` + +Specifies the type of file entry. + +### Example + +```yaml +segments: + - name: boot + files: + - { path: src/boot/utils.o, kind: object } +``` + +### Valid values + +- `object`: The path points to a relocatable object file. + +### Default value + +Guessed from `path` using the following file extensions: + +- `.o`: `Object`. +- Anything else: `Object`. diff --git a/docs/file_format/files.md b/docs/file_format/files.md deleted file mode 100644 index 7b6f7e2..0000000 --- a/docs/file_format/files.md +++ /dev/null @@ -1,3 +0,0 @@ -# Files - -TODO diff --git a/docs/file_format/segments.md b/docs/file_format/segments.md index f2513b7..0f4fc6f 100644 --- a/docs/file_format/segments.md +++ b/docs/file_format/segments.md @@ -36,7 +36,7 @@ List of files belonging to this segment. The order of the list implies the order on which the files will be emitted. -To see customization options for each file check the [files.md](files.md) +To see customization options for each file check the [file.md](file.md) document. ### Example diff --git a/slinky/src/document.rs b/slinky/src/document.rs index d13a934..1080b87 100644 --- a/slinky/src/document.rs +++ b/slinky/src/document.rs @@ -5,7 +5,7 @@ use std::{fs, path::Path}; use serde::Deserialize; -use crate::{Segment, Settings, SlinkyError}; +use crate::{FileKind, Segment, Settings, SlinkyError}; #[derive(Deserialize, PartialEq, Debug)] pub struct Document { @@ -43,6 +43,11 @@ impl Document { segment .wildcard_sections .get_or_insert(document.settings.wildcard_sections); + + for file in &mut segment.files { + // TODO: guess based on file extension + file.kind.get_or_insert(FileKind::Object); + } } Ok(document) diff --git a/slinky/src/file_info.rs b/slinky/src/file_info.rs index 21d7ade..e298f97 100644 --- a/slinky/src/file_info.rs +++ b/slinky/src/file_info.rs @@ -10,10 +10,5 @@ use crate::file_kind::FileKind; pub struct FileInfo { pub path: PathBuf, - #[serde(default = "default_fileinfo_kind")] - pub kind: FileKind, -} - -fn default_fileinfo_kind() -> FileKind { - FileKind::Object + pub kind: Option, } diff --git a/slinky/src/file_kind.rs b/slinky/src/file_kind.rs index 61bc364..055a9ae 100644 --- a/slinky/src/file_kind.rs +++ b/slinky/src/file_kind.rs @@ -4,6 +4,7 @@ use serde::Deserialize; #[derive(Deserialize, PartialEq, Debug)] +#[serde(rename_all = "snake_case")] pub enum FileKind { Object, Archive, diff --git a/slinky/src/linker_writer.rs b/slinky/src/linker_writer.rs index 14b48d2..f118b9b 100644 --- a/slinky/src/linker_writer.rs +++ b/slinky/src/linker_writer.rs @@ -208,7 +208,7 @@ impl LinkerWriter<'_> { }; // TODO: figure out glob support - match file.kind { + match file.kind.as_ref().unwrap() { FileKind::Object => { self.writeln(&format!("{}({}{});", path.display(), section, wildcard)); }