Skip to content

Commit

Permalink
Dual 514-515 compat (+ reformatting) (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
Absolucy authored Mar 14, 2024
1 parent fdacde2 commit 373890f
Show file tree
Hide file tree
Showing 56 changed files with 828 additions and 1,106 deletions.
File renamed without changes.
39 changes: 39 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
edition = "2021"
hard_tabs = true
fn_params_layout = "Tall"
force_explicit_abi = true
match_block_trailing_comma = false
max_width = 150
merge_derives = true
newline_style = "Unix"
remove_nested_parens = true
reorder_imports = true
reorder_modules = true
use_field_init_shorthand = true
use_small_heuristics = "Default"
# Unstable formatting options below; remove if you REALLY don't wanna use `cargo +nightly fmt`
unstable_features = true
binop_separator = "Front"
brace_style = "SameLineWhere"
condense_wildcard_suffixes = true
control_brace_style = "AlwaysSameLine"
empty_item_single_line = true
format_code_in_doc_comments = true
format_macro_bodies = true
format_macro_matchers = true
format_strings = true
group_imports = "Preserve"
imports_granularity = "Crate"
imports_indent = "Block"
imports_layout = "Mixed"
indent_style = "Block"
match_arm_blocks = true
normalize_comments = true
overflow_delimited_expr = true
reorder_impl_items = true
space_after_colon = true
space_before_colon = false
spaces_around_ranges = false
trailing_comma = "Never"
trailing_semicolon = true
type_punctuation_density = "Wide"
wrap_comments = true
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[workspace]
members = [
"auxcov",
"auxtools",
"auxtools-impl",
"debug_server",
"instruction_hooking",
"tests/auxtest",
"tests/byond_get",
"tests/test_runner",
]
members = ["auxcov", "auxtools", "auxtools-impl", "debug_server", "instruction_hooking", "tests/auxtest", "tests/byond_get", "tests/test_runner"]
resolver = "2"

[workspace.package]
authors = ["Sophie Wallace <[email protected]>", "Lucy <[email protected]>"]
edition = "2021"
license = "MIT"
repository = "https://github.com/wilox/auxtools"
rust-version = "1.76"
version = "0.1.0"

[profile.release]
opt-level = 3
Expand Down
5 changes: 4 additions & 1 deletion auxcov/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
name = "auxcov"
version = "1.0.0"
authors = ["Jordan Dominion <[email protected]>"]
edition = "2018"
publish = false
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true

[lib]
crate-type = ["cdylib", "lib"]
Expand Down
79 changes: 31 additions & 48 deletions auxcov/src/codecov.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
use std::cell::RefCell;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::convert::TryInto;
use std::fs::create_dir_all;
use std::io::Error;
use std::panic::catch_unwind;
use std::path::{Path, PathBuf};
use std::rc::Rc;

use auxtools::raw_types::strings::StringId;
use auxtools::*;
use std::{
cell::RefCell,
collections::{BTreeMap, HashMap, HashSet},
convert::TryInto,
fs::create_dir_all,
io::Error,
panic::catch_unwind,
path::{Path, PathBuf},
rc::Rc
};

use auxtools::{raw_types::strings::StringId, *};
use dmasm::Instruction;

use grcov::{output_cobertura, CovResult, FunctionMap, ResultTuple};
use instruction_hooking::disassemble_env::DisassembleEnv;
use instruction_hooking::InstructionHook;
use instruction_hooking::{disassemble_env::DisassembleEnv, InstructionHook};

struct TrackerContext {
output_file_name: String,
proc_id_map: Vec<Option<Rc<RefCell<Vec<u64>>>>>,
filename_map: HashMap<String, Rc<RefCell<Vec<u64>>>>,
filename_map: HashMap<String, Rc<RefCell<Vec<u64>>>>
}

pub struct Tracker {
hittable_lines: HashMap<String, HashSet<u32>>,
contexts: Vec<TrackerContext>,
total_procs: u32,
total_procs: u32
}

impl Tracker {
Expand All @@ -51,7 +50,7 @@ impl Tracker {
let string_ref_result = StringRef::from_raw(&file.0);
match string_ref_result {
Ok(string_ref) => current_file_option = Some(string_ref),
Err(_) => current_file_option = None,
Err(_) => current_file_option = None
}
}
Instruction::DbgLine(line) => {
Expand All @@ -64,10 +63,7 @@ impl Tracker {
continue;
}

hittable_lines
.entry(file_name)
.or_insert(HashSet::new())
.insert(line);
hittable_lines.entry(file_name).or_insert(HashSet::new()).insert(line);
}
}
_ => {}
Expand All @@ -79,23 +75,19 @@ impl Tracker {
Tracker {
hittable_lines,
contexts: Vec::new(),
total_procs: i,
total_procs: i
}
}

pub fn init_context(&mut self, output_file_name: String) -> bool {
if self
.contexts
.iter()
.any(|context| context.output_file_name == *output_file_name)
{
if self.contexts.iter().any(|context| context.output_file_name == *output_file_name) {
return false;
}

let mut context: TrackerContext = TrackerContext {
output_file_name,
proc_id_map: Vec::new(),
filename_map: HashMap::new(),
filename_map: HashMap::new()
};

context.proc_id_map.reserve(self.total_procs as usize);
Expand Down Expand Up @@ -126,11 +118,7 @@ impl Tracker {
}

// returns true if we need to pause
pub fn process_dbg_line(
&mut self,
ctx: &raw_types::procs::ExecutionContext,
proc_instance: &raw_types::procs::ProcInstance,
) {
pub fn process_dbg_line(&mut self, ctx: &raw_types::procs::ExecutionContext, proc_instance: &raw_types::procs::ProcInstance) {
if ctx.line == 0 || !ctx.filename.valid() {
return;
}
Expand All @@ -146,8 +134,7 @@ impl Tracker {
context.process_dbg_line(filename_id, proc_map_index, line, Some(file_name));
}
None => {
let processed_file_name =
context.process_dbg_line(filename_id, proc_map_index, line, None);
let processed_file_name = context.process_dbg_line(filename_id, proc_map_index, line, None);
if let Some((file_name, valid)) = processed_file_name {
if !valid {
break;
Expand Down Expand Up @@ -213,7 +200,8 @@ impl Tracker {

impl Drop for Tracker {
fn drop(&mut self) {
let _result = self.finalize(); // dropping the result here because what can ya do?
let _result = self.finalize(); // dropping the result here because what can ya
// do?
}
}

Expand All @@ -236,7 +224,7 @@ impl TrackerContext {
filename_id: StringId,
proc_map_index: usize,
line: usize,
known_file_name: Option<&String>,
known_file_name: Option<&String>
) -> Option<(String, bool)> {
let needs_extending = self.proc_id_map.len() < proc_map_index + 1;

Expand Down Expand Up @@ -324,8 +312,7 @@ impl TrackerContext {
hit_map[i] = current_hits + 1;

let hit_map_rc = Rc::new(RefCell::new(hit_map));
self.filename_map
.insert(file_name.clone(), hit_map_rc.clone());
self.filename_map.insert(file_name.clone(), hit_map_rc.clone());
self.proc_id_map[proc_map_index] = Some(hit_map_rc);
}
}
Expand All @@ -348,15 +335,11 @@ impl TrackerContext {
}

let path = PathBuf::from(file_name);
(
path.clone(),
path,
CovResult {
lines: new_map,
branches: BTreeMap::default(),
functions: FunctionMap::default(),
},
)
(path.clone(), path, CovResult {
lines: new_map,
branches: BTreeMap::default(),
functions: FunctionMap::default()
})
})
.collect();

Expand Down
33 changes: 11 additions & 22 deletions auxcov/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@
mod codecov;

use codecov::Tracker;
use instruction_hooking::INSTRUCTION_HOOKS;

use std::any::{Any, TypeId};

use auxtools::*;
use codecov::Tracker;
use instruction_hooking::INSTRUCTION_HOOKS;

fn with_tracker_option<F>(f: F, create: bool)
where
F: FnOnce(&mut Tracker),
F: FnOnce(&mut Tracker)
{
unsafe {
let hooks = INSTRUCTION_HOOKS.get_mut();

let tracker_tid = TypeId::of::<Tracker>();
let tracker_option = hooks
.iter_mut()
.find(|hook| (*hook).as_ref().type_id() == tracker_tid);
let tracker_option = hooks.iter_mut().find(|hook| (*hook).as_ref().type_id() == tracker_tid);

match tracker_option {
Some(existing_hook) => {
Expand All @@ -39,7 +36,8 @@ where
}
}

// INSTRUCTION_HOOKS are cleared on shutdown so we don't need to worry about that.
// INSTRUCTION_HOOKS are cleared on shutdown so we don't need to worry about
// that.
#[hook("/proc/start_code_coverage")]
fn start_code_coverage(coverage_file: Value) {
let coverage_file_string_result = coverage_file.as_string();
Expand All @@ -54,14 +52,11 @@ fn start_code_coverage(coverage_file: Value) {
|tracker| {
init_result = tracker.init_context(coverage_file_string.clone());
},
true,
true
);

if !init_result {
return Err(runtime!(
"A code coverage context for {} already exists!",
coverage_file_string
));
return Err(runtime!("A code coverage context for {} already exists!", coverage_file_string));
}

Ok(Value::null())
Expand All @@ -83,21 +78,15 @@ fn stop_code_coverage(coverage_file: Value) {
result = match inner_result {
Ok(had_entry) => {
if !had_entry {
Err(runtime!(
"A code coverage context for {} does not exist!",
coverage_file_string
))
Err(runtime!("A code coverage context for {} does not exist!", coverage_file_string))
} else {
Ok(Value::null())
}
}
Err(error) => Err(runtime!(
"A error occurred while trying to save the coverage file: {}",
error
)),
Err(error) => Err(runtime!("A error occurred while trying to save the coverage file: {}", error))
}
},
false,
false
);

result
Expand Down
9 changes: 5 additions & 4 deletions auxtools-impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
name = "auxtools-impl"
description = "procedural macros for use with the auxtools crate"
version = "0.1.0"
authors = ["Aspen <[email protected]>", "Sophie Wallace <[email protected]>"]
license = "MIT"
repository = "https://github.com/willox/auxtools"
edition = "2018"
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true

[lib]
proc-macro = true
Expand Down
Loading

0 comments on commit 373890f

Please sign in to comment.