Skip to content

Commit

Permalink
fix: removing the duplicated std byproducts (obj files) on the linker…
Browse files Browse the repository at this point in the history
… command line
  • Loading branch information
TheRustifyer committed Jul 3, 2024
1 parent 5421500 commit cacfa51
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 114 deletions.
23 changes: 5 additions & 18 deletions zork++/src/lib/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,15 @@ pub struct ZorkCache<'a> {
pub last_program_execution: DateTime<Utc>,
pub compilers_metadata: CompilersMetadata<'a>,
pub generated_commands: Commands,
// pub new_commands: bool //< if the current iteration added some new command with respect the
// previous one
}

impl<'a> ZorkCache<'a> {
pub fn last_program_execution(&self) -> &DateTime<Utc> {
&self.last_program_execution
}

pub fn get_module_ifc_cmd(
&mut self,
module_interface_model: &ModuleInterfaceModel,
Expand Down Expand Up @@ -125,22 +128,6 @@ impl<'a> ZorkCache<'a> {
.find(|mi| module_impl_model.file() == (*mi).path())
}

/// Returns a [`Option`] of [`CommandDetails`] if the file is persisted already in the cache
pub fn is_file_cached(&self, _path: impl AsRef<Path>) -> Option<&CommandDetail> {
// let last_iteration_details = self.generated_commands.last();

// TODO: what a cost. We need to join them for every iteration and every file
// if let Some(last_iteration) = last_iteration_details {
// return last_iteration
// .interfaces
// .iter()
// .chain(last_iteration.implementations.iter())
// .chain(last_iteration.sources.iter())
// .find(|comm_det| comm_det.file_path().eq(path.as_ref()));
// }
None
}

/// The tasks associated with the cache after load it from the file system
pub fn run_tasks(&mut self, program_data: &'a ZorkModel<'_>) -> Result<()> {
let compiler = program_data.compiler.cpp_compiler;
Expand Down Expand Up @@ -238,7 +225,7 @@ impl<'a> ZorkCache<'a> {
None
}

fn normalize_execution_result_status(
/* fn normalize_execution_result_status(
// TODO: pending to re-implement it
// ALe, don't read again this. We just need to fix the implementation when the commands
// are generated, or even better, bring them from the cache
Expand All @@ -262,7 +249,7 @@ impl<'a> ZorkCache<'a> {
} else {
module_command_line.execution_result
}
}
} */

/// Method that returns the HashMap that holds the environmental variables that must be passed
/// to the underlying shell
Expand Down
22 changes: 2 additions & 20 deletions zork++/src/lib/cli/output/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,6 @@ impl FromIterator<Argument> for Arguments {
}
}

impl FromIterator<Argument> for &Arguments {
fn from_iter<I: IntoIterator<Item = Argument>>(iter: I) -> Self {
let mut vec = Vec::new();
for item in iter {
vec.push(item);
}
&Arguments(vec)
}
}

impl<'a> FromIterator<&'a Argument> for Arguments {
fn from_iter<I: IntoIterator<Item = &'a Argument>>(iter: I) -> Arguments {
let mut vec = Vec::new();
Expand Down Expand Up @@ -283,7 +273,7 @@ pub mod msvc_args {
use crate::{
bounds::TranslationUnit,
cache::ZorkCache,
cli::output::commands::{CommandExecutionResult, SourceCommandLine},
cli::output::commands::SourceCommandLine,
project_model::{compiler::StdLibMode, ZorkModel},
};

Expand Down Expand Up @@ -311,9 +301,6 @@ pub mod msvc_args {
)
};

arguments.push(model.compiler.language_level_arg());
arguments.create_and_push("/EHsc");
arguments.create_and_push("/nologo");
arguments.create_and_push("/W4");

arguments.create_and_push("/reference");
Expand All @@ -331,11 +318,6 @@ pub mod msvc_args {
"/Fo{}", stdlib_obj_path.display()
});

SourceCommandLine::from_translation_unit(
stdlib_sf,
arguments,
false,
CommandExecutionResult::default(),
)
SourceCommandLine::new(stdlib_sf, arguments)
}
}
42 changes: 8 additions & 34 deletions zork++/src/lib/cli/output/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,13 @@ pub fn run_generated_commands(

if !cache.generated_commands.linker.args.is_empty() {
log::debug!("Processing the linker command line...");
let linker_cmdline_args = general_args
.iter()
.chain(compiler_specific_shared_args.iter())
.chain(cache.generated_commands.linker.args.iter())
.collect::<Arguments>(); // TODO: can we avoid clone and own all the args? just use the
// .iter() as a view?

let r = execute_command(
program_data,
&linker_cmdline_args,
&cache.generated_commands.linker.args,
&env_args,
);

cache.generated_commands.linker.execution_result = CommandExecutionResult::from(&r);

if let Err(e) = r {
Expand Down Expand Up @@ -173,28 +168,7 @@ pub struct SourceCommandLine {
}

impl SourceCommandLine {
pub fn from_translation_unit(
// TODO init it as a args holder, but doesn't have the status yet
tu: impl TranslationUnit,
args: Arguments, // TODO: maybe this should be an option? Cached arguments are passed
// here as default. So probably, even better than having an optional,
// we must replicate this to have a separate entity like
// CachedSourceCommandLine, and them just call them over any kind of
// <T> constrained over some bound that wraps the operation of
// distinguish between them or not
processed: bool,
execution_result: CommandExecutionResult,
) -> Self {
Self {
directory: tu.path(),
filename: tu.file_with_extension(),
args,
need_to_build: !processed,
execution_result,
}
}

pub fn for_translation_unit(
pub fn new(
// TODO init it as a args holder, but doesn't have the status yet
tu: impl TranslationUnit,
args: Arguments,
Expand All @@ -215,10 +189,7 @@ impl SourceCommandLine {

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct LinkerCommandLine {
// pub main: &'a Path, // TODO: can't this disappear? At the end of the day, is just another obj file
pub built_files: Vec<PathBuf>, // TODO: obj files?
pub args: Arguments, // TODO: :does the linker command line needs any different that the
// generals?
pub args: Arguments,
pub execution_result: CommandExecutionResult,
}

Expand All @@ -241,7 +212,8 @@ impl LinkerCommandLine {
/// Holds the generated command line arguments for a concrete compiler
#[derive(Serialize, Deserialize, Default)]
pub struct Commands {
pub compiler: CppCompiler,
pub compiler: CppCompiler, // TODO: review if we can afford this field given the new
// architechture
pub cpp_stdlib: Option<SourceCommandLine>,
pub c_compat_stdlib: Option<SourceCommandLine>,
pub system_modules: HashMap<String, Arguments>,
Expand Down Expand Up @@ -318,6 +290,8 @@ pub enum CommandExecutionResult {
Cached,
/// A command which is return code indicates an unsuccessful execution
Failed,
/// Whenever a translation unit must be rebuilt
PendingToBuild,
/// The execution failed, returning a [`Result`] with the Err variant
Error,
/// A previous state before executing a command line
Expand Down
Loading

0 comments on commit cacfa51

Please sign in to comment.