-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow passing arguments to cli and bash script to regenerate tests
- Loading branch information
1 parent
66eb40b
commit c6b0a6c
Showing
8 changed files
with
275 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,43 @@ | ||
/* SPDX-FileCopyrightText: © 2024 decompals */ | ||
/* SPDX-License-Identifier: MIT */ | ||
|
||
use std::path::Path; | ||
use std::path::PathBuf; | ||
|
||
use slinky::{Document, LinkerWriter}; | ||
use clap::Parser; | ||
|
||
// TODO: Add program description to cli | ||
|
||
#[derive(Parser)] | ||
#[command(version, about, long_about = None)] | ||
struct Cli { | ||
/// Input file | ||
input: PathBuf, | ||
|
||
/// Output file. Print to stdout if missing | ||
#[arg(short, long)] | ||
output: Option<PathBuf>, | ||
} | ||
|
||
fn main() { | ||
let cli = Cli::parse(); | ||
|
||
// TODO: don't use expect? | ||
let document = Document::read_file(Path::new("tests/input_files/test_case.yaml")) | ||
.expect("Error while parsing input file"); | ||
let document = slinky::Document::read_file(&cli.input).expect("Error while parsing input file"); | ||
|
||
// println!("settings {:#?}", document.settings); | ||
|
||
let mut writer = LinkerWriter::new(&document.settings); | ||
let mut writer = slinky::LinkerWriter::new(&document.settings); | ||
writer.begin_sections(); | ||
for segment in &document.segments { | ||
writer.add_segment(segment); | ||
} | ||
writer.end_sections(); | ||
|
||
writer | ||
.save_linker_script(Path::new("tests/linker_scripts/test_case.ld")) | ||
.expect("Error writing the linker script"); | ||
if let Some(output_path) = cli.output { | ||
writer | ||
.save_linker_script(&output_path) | ||
.expect("Error writing the linker script"); | ||
} else { | ||
println!("{}", writer.export_as_string()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,29 @@ | ||
/* SPDX-FileCopyrightText: © 2024 decompals */ | ||
/* SPDX-License-Identifier: MIT */ | ||
|
||
use std::path::PathBuf; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Hash, thiserror::Error)] | ||
pub enum SlinkyError { | ||
#[error("Unable to open file: {description}")] | ||
FailedFileOpen { description: String }, | ||
#[error("Unable to open file '{path}', because '{description}'")] | ||
FailedFileOpen { path: PathBuf, description: String }, | ||
|
||
#[error("Fail while writing to file '{path}', because '{description}'.\n Contents were: '{contents}'")] | ||
FailedFileWrite { | ||
path: PathBuf, | ||
description: String, | ||
contents: String, | ||
}, | ||
|
||
#[error("Unable to create dir '{path}', because '{description}")] | ||
FailedDirCreate { path: PathBuf, description: String }, | ||
|
||
#[error("Unable parse yaml: {description}")] | ||
FailedYamlParsing { description: String }, | ||
|
||
#[error("Non-nullable attribute '{name}' was null")] | ||
NullValueOnNonNull { name: String }, | ||
|
||
#[error("The attribute '{name}' should not be empty")] | ||
EmptyValue { name: String }, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
# SPDX-FileCopyrightText: © 2024 decompals | ||
# SPDX-License-Identifier: MIT | ||
|
||
set -e | ||
set -o pipefail | ||
|
||
# This file should be run from the root of the repo | ||
|
||
for filepath in tests/input_files/*.yaml; do | ||
filename=$(basename -- "$filepath") | ||
stem="${filename%.*}" | ||
output=tests/linker_scripts/$stem.ld | ||
echo Generating $output | ||
cargo run -- $filepath -o $output | ||
#for ((i=0; i<=3; i++)); do | ||
# ./MyProgram.exe "$filename" "Logs/$(basename "$filename" .txt)_Log$i.txt" | ||
#done | ||
done |