Skip to content

Commit f5d52c5

Browse files
committed
Improve valgrind logging and fix docker issue
1 parent 1878900 commit f5d52c5

File tree

2 files changed

+44
-36
lines changed

2 files changed

+44
-36
lines changed

crates/plugins/make/src/plugin.rs

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -163,52 +163,61 @@ impl LanguagePlugin for MakePlugin {
163163
});
164164
}
165165

166+
// try to clean old log file if any
167+
let base_test_path = path.join("test");
168+
let valgrind_log_path = base_test_path.join("valgrind.log");
169+
let _ = file_util::remove_file(&valgrind_log_path);
170+
166171
// try to run valgrind
167172
let mut ran_valgrind = true;
168173
let valgrind_run = self.run_tests_with_valgrind(path, true);
169174
let output = match valgrind_run {
170175
Ok(output) => output,
171-
Err(error) => match error {
172-
MakeError::Tmc(TmcError::Command(command_error)) => {
173-
match command_error {
174-
CommandError::Popen(_, PopenError::IoError(io_error))
175-
| CommandError::FailedToRun(_, PopenError::IoError(io_error))
176-
if io_error.kind() == io::ErrorKind::PermissionDenied =>
177-
{
178-
// failed due to lacking permissions, try to clean and rerun
179-
self.clean(path)?;
180-
match self.run_tests_with_valgrind(path, false) {
181-
Ok(output) => output,
182-
Err(err) => {
183-
log::error!(
176+
Err(error) => {
177+
if let Ok(valgrind_log) = file_util::read_file_to_string_lossy(&valgrind_log_path) {
178+
log::warn!("Failed to run valgrind but a valgrind.log exists: {valgrind_log}");
179+
}
180+
match error {
181+
MakeError::Tmc(TmcError::Command(command_error)) => {
182+
match command_error {
183+
CommandError::Popen(_, PopenError::IoError(io_error))
184+
| CommandError::FailedToRun(_, PopenError::IoError(io_error))
185+
if io_error.kind() == io::ErrorKind::PermissionDenied =>
186+
{
187+
// failed due to lacking permissions, try to clean and rerun
188+
self.clean(path)?;
189+
match self.run_tests_with_valgrind(path, false) {
190+
Ok(output) => output,
191+
Err(err) => {
192+
log::error!(
184193
"Running with valgrind failed after trying to clean! {}",
185194
err
186195
);
187-
ran_valgrind = false;
188-
log::info!("Running without valgrind");
189-
self.run_tests_with_valgrind(path, false)?
196+
ran_valgrind = false;
197+
log::info!("Running without valgrind");
198+
self.run_tests_with_valgrind(path, false)?
199+
}
190200
}
191201
}
192-
}
193-
_ => {
194-
ran_valgrind = false;
195-
log::info!("Running without valgrind");
196-
self.run_tests_with_valgrind(path, false)?
202+
_ => {
203+
ran_valgrind = false;
204+
log::info!("Running without valgrind");
205+
self.run_tests_with_valgrind(path, false)?
206+
}
197207
}
198208
}
209+
MakeError::RunningTestsWithValgrind(..) => {
210+
ran_valgrind = false;
211+
log::info!("Running without valgrind");
212+
self.run_tests_with_valgrind(path, false)?
213+
}
214+
err => {
215+
log::warn!("unexpected error {:?}", err);
216+
return Err(err.into());
217+
}
199218
}
200-
MakeError::RunningTestsWithValgrind(..) => {
201-
ran_valgrind = false;
202-
log::info!("Running without valgrind");
203-
self.run_tests_with_valgrind(path, false)?
204-
}
205-
err => {
206-
log::warn!("unexpected error {:?}", err);
207-
return Err(err.into());
208-
}
209-
},
219+
}
210220
};
211-
let base_test_path = path.join("test");
212221

213222
// fails on valgrind by default
214223
let fail_on_valgrind_error = match TmcProjectYml::load_or_default(path) {
@@ -218,8 +227,7 @@ impl LanguagePlugin for MakePlugin {
218227

219228
// valgrind logs are only interesting if fail on valgrind error is on
220229
let valgrind_log = if ran_valgrind && fail_on_valgrind_error {
221-
let valgrind_path = base_test_path.join("valgrind.log");
222-
Some(ValgrindLog::from(&valgrind_path)?)
230+
Some(ValgrindLog::from(&valgrind_log_path)?)
223231
} else {
224232
None
225233
};

docker.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CMD="${*:-cargo build && cp /build/target/debug/tmc-langs-cli /build/out/}"
44
export DOCKER_BUILDKIT=1
55
docker build . -f docker/Dockerfile -t tmc-langs-rust
66
if [ "$CMD" = "interactive" ]; then
7-
docker run -it --rm -v "$PWD":/build/out tmc-langs-rust bash
7+
docker run --ulimit nofile=1024:1024 -it --rm -v "$PWD":/build/out tmc-langs-rust bash
88
else
9-
docker run --rm -v "$PWD":/build/out tmc-langs-rust bash -c "$CMD"
9+
docker run --ulimit nofile=1024:1024 --rm -v "$PWD":/build/out tmc-langs-rust bash -c "$CMD"
1010
fi;

0 commit comments

Comments
 (0)