Skip to content

Commit

Permalink
Add a way to check partial ld scripts haven't changed
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Apr 26, 2024
1 parent 1a7deb6 commit 8edb699
Show file tree
Hide file tree
Showing 13 changed files with 616 additions and 1,501 deletions.
4 changes: 2 additions & 2 deletions docs/file_format/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ Boolean.

`False`

## `partial_scripts_path`
## `partial_scripts_folder`

## `partial_build_segments_path`
## `partial_build_segments_folder`

## `alloc_sections`

Expand Down
4 changes: 2 additions & 2 deletions slinky-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Cli {
output: Option<PathBuf>,

/// Generate linker script for partial linking multiple segments.
/// Requires both `partial_scripts_path` and `partial_build_segments_path` YAML settings to be set.
/// Requires both `partial_scripts_folder` and `partial_build_segments_folder` YAML settings to be set.
#[arg(short, long, default_value_t = false)]
partial_linking: bool,
}
Expand All @@ -34,7 +34,7 @@ fn main() {
if cli.partial_linking {
let mut writer = slinky::PartialLinkerWriter::new(&document.settings);

writer.add_all_segment(&document.segments);
writer.add_all_segments(&document.segments);

let output_path = cli
.output
Expand Down
12 changes: 6 additions & 6 deletions slinky/src/partial_linker_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<'a> PartialLinkerWriter<'a> {
}
}

pub fn add_all_segment(&mut self, segments: &[Segment]) {
pub fn add_all_segments(&mut self, segments: &[Segment]) {
self.main_writer.begin_sections();

self.partial_writers.reserve(segments.len());
Expand All @@ -41,7 +41,7 @@ impl<'a> PartialLinkerWriter<'a> {

let mut p = PathBuf::new();

p.push(&self.settings.partial_build_segments_path);
p.push(&self.settings.partial_build_segments_folder);
p.push(&format!("{}.o", segment.name));

let mut reference_segment = segment.clone();
Expand All @@ -68,7 +68,7 @@ impl<'a> PartialLinkerWriter<'a> {
for (partial, name) in &self.partial_writers {
let mut p = PathBuf::new();

p.push(&self.settings.partial_scripts_path);
p.push(&self.settings.partial_scripts_folder);
p.push(&format!("{}.ld", name));

partial.save_linker_script(&p)?;
Expand All @@ -80,9 +80,9 @@ impl<'a> PartialLinkerWriter<'a> {
pub fn write_other_files(&self) -> Result<(), SlinkyError> {
self.main_writer.write_other_files()?;

for (partial, _name) in &self.partial_writers {
partial.write_other_files()?;
}
//for (partial, _name) in &self.partial_writers {
// partial.write_other_files()?;
//}

Ok(())
}
Expand Down
32 changes: 16 additions & 16 deletions slinky/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub struct Settings {

pub single_segment_mode: bool,

pub partial_scripts_path: PathBuf,
pub partial_build_segments_path: PathBuf,
pub partial_scripts_folder: PathBuf,
pub partial_build_segments_folder: PathBuf,

// Options passed down to each segment
pub alloc_sections: Vec<String>,
Expand Down Expand Up @@ -106,11 +106,11 @@ const fn settings_default_single_segment_mode() -> bool {
false
}

fn settings_default_partial_scripts_path() -> PathBuf {
fn settings_default_partial_scripts_folder() -> PathBuf {
PathBuf::new()
}

fn settings_default_partial_build_segments_path() -> PathBuf {
fn settings_default_partial_build_segments_folder() -> PathBuf {
PathBuf::new()
}

Expand Down Expand Up @@ -174,8 +174,8 @@ impl Default for Settings {

single_segment_mode: settings_default_single_segment_mode(),

partial_scripts_path: settings_default_partial_scripts_path(),
partial_build_segments_path: settings_default_partial_build_segments_path(),
partial_scripts_folder: settings_default_partial_scripts_folder(),
partial_build_segments_folder: settings_default_partial_build_segments_folder(),

alloc_sections: settings_default_alloc_sections(),
noload_sections: settings_default_noload_sections(),
Expand Down Expand Up @@ -227,9 +227,9 @@ pub(crate) struct SettingsSerial {
pub single_segment_mode: AbsentNullable<bool>,

#[serde(default)]
pub partial_scripts_path: AbsentNullable<PathBuf>,
pub partial_scripts_folder: AbsentNullable<PathBuf>,
#[serde(default)]
pub partial_build_segments_path: AbsentNullable<PathBuf>,
pub partial_build_segments_folder: AbsentNullable<PathBuf>,

// Options passed down to each Segment
#[serde(default)]
Expand Down Expand Up @@ -302,13 +302,13 @@ impl SettingsSerial {
.single_segment_mode
.get_non_null("single_segment_mode", settings_default_single_segment_mode)?;

let partial_scripts_path = self.partial_scripts_path.get_non_null(
"partial_scripts_path",
settings_default_partial_scripts_path,
let partial_scripts_folder = self.partial_scripts_folder.get_non_null(
"partial_scripts_folder",
settings_default_partial_scripts_folder,
)?;
let partial_build_segments_path = self.partial_build_segments_path.get_non_null(
"partial_build_segments_path",
settings_default_partial_build_segments_path,
let partial_build_segments_folder = self.partial_build_segments_folder.get_non_null(
"partial_build_segments_folder",
settings_default_partial_build_segments_folder,
)?;

if d_path.is_some() && target_path.is_none() {
Expand Down Expand Up @@ -364,8 +364,8 @@ impl SettingsSerial {

single_segment_mode,

partial_scripts_path,
partial_build_segments_path,
partial_scripts_folder,
partial_build_segments_folder,

alloc_sections,
noload_sections,
Expand Down
31 changes: 31 additions & 0 deletions slinky/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,34 @@ fn test_symbols_header_generation(#[files("../tests/test_cases/*.h")] h_path: Pa
fn test_panic_invalid_yamls(#[files("../tests/panics/*.yaml")] path: PathBuf) {
slinky::Document::read_file(&path).unwrap();
}

#[rstest]
fn test_partial_linking_script_generation(#[files("../tests/partial_linking/*.ld")] ld_path: PathBuf) {
let yaml_path = ld_path.with_extension("yaml");

//check_ld_generation(&yaml_path, &ld_path);
let document = slinky::Document::read_file(&yaml_path).expect("unable to read original file");

let mut writer = slinky::PartialLinkerWriter::new(&document.settings);
writer.add_all_segments(&document.segments);

let expected_ld_contents =
fs::read_to_string(ld_path).expect("unable to read expected ld file");

assert_eq!(expected_ld_contents, writer.get_main_writer().export_as_string());


for (partial, name) in writer.get_partial_writers() {
let mut p = PathBuf::new();

p.push("..");
p.push(&document.settings.partial_scripts_folder);
p.push(&format!("{}.ld", name));

//partial.save_linker_script(&p)?;
let expected_partial_ld_contents =
fs::read_to_string(p).expect("unable to read expected ld file");

assert_eq!(expected_partial_ld_contents, partial.export_as_string());
}
}
Loading

0 comments on commit 8edb699

Please sign in to comment.