Skip to content

Commit ad1f28a

Browse files
committed
Use new CLI settings
1 parent 5ca50eb commit ad1f28a

File tree

16 files changed

+138
-52
lines changed

16 files changed

+138
-52
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/tmc-langs-node/src/de.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ struct JsObjectAccess<'a, 'j, C: Context<'j> + 'a> {
200200
}
201201

202202
#[doc(hidden)]
203-
impl<'x, 'a, 'j, C: Context<'j>> JsObjectAccess<'a, 'j, C> {
203+
impl<'a, 'j, C: Context<'j>> JsObjectAccess<'a, 'j, C> {
204204
fn new(cx: &'a mut C, input: Handle<'j, JsObject>) -> LibResult<Self> {
205205
let prop_names = input.get_own_property_names(cx)?;
206206
let len = prop_names.len(cx);

bindings/tmc-langs-node/src/helpers.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ macro_rules! lock {
77
( $cx: ident, $( $path: expr ),+ ) => {
88
$(
99
let path_buf: PathBuf = (&$path).into();
10-
let mut fl = $crate::file_util::FileLock::new(path_buf).map_err(|e| crate::helpers::convert_err(&mut $cx, e))?;
11-
let _lock = fl.lock().map_err(|e| crate::helpers::convert_err(&mut $cx, e))?;
10+
let mut fl = $crate::file_util::FileLock::new(path_buf).map_err(|e| $crate::helpers::convert_err(&mut $cx, e))?;
11+
let _lock = fl.lock().map_err(|e| $crate::helpers::convert_err(&mut $cx, e))?;
1212
)*
1313
};
1414
}
@@ -17,7 +17,7 @@ macro_rules! lock {
1717
macro_rules! parse_arg {
1818
($cx: ident, $ty: path, $i: expr) => {{
1919
let arg = $cx.argument::<JsValue>($i)?;
20-
crate::de::from_value::<_, $ty>(&mut $cx, arg).expect("failed to parse argument")
20+
$crate::de::from_value::<_, $ty>(&mut $cx, arg).expect("failed to parse argument")
2121
}};
2222
}
2323

@@ -86,6 +86,19 @@ macro_rules! parse_args {
8686
parse_arg!($cx, $ty7, 7),
8787
);
8888
};
89+
($cx: ident, $id0: ident : $ty0: path, $id1: ident : $ty1: path, $id2: ident : $ty2: path, $id3: ident : $ty3: path, $id4: ident : $ty4: path, $id5: ident : $ty5: path, $id6: ident : $ty6: path, $id7: ident : $ty7: path, $id8: ident : $ty8: path) => {
90+
let ($id0, $id1, $id2, $id3, $id4, $id5, $id6, $id7, $id8) = (
91+
parse_arg!($cx, $ty0, 0),
92+
parse_arg!($cx, $ty1, 1),
93+
parse_arg!($cx, $ty2, 2),
94+
parse_arg!($cx, $ty3, 3),
95+
parse_arg!($cx, $ty4, 4),
96+
parse_arg!($cx, $ty5, 5),
97+
parse_arg!($cx, $ty6, 6),
98+
parse_arg!($cx, $ty7, 7),
99+
parse_arg!($cx, $ty8, 8),
100+
);
101+
};
89102
}
90103

91104
pub fn convert_err<E: Error>(cx: &mut FunctionContext, e: E) -> Throw {

bindings/tmc-langs-node/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ fn extract_project(mut cx: FunctionContext) -> JsResult<JsValue> {
123123
let mut data = vec![];
124124
guard.read_to_end(&mut data).expect("failed to read data");
125125

126-
let res = tmc_langs::extract_project(Cursor::new(data), &output_path, compression, false);
126+
let res =
127+
tmc_langs::extract_project(Cursor::new(data), &output_path, compression, false, false);
127128
convert_res(&mut cx, res)
128129
}
129130

@@ -180,8 +181,10 @@ fn prepare_submission(mut cx: FunctionContext) -> JsResult<JsValue> {
180181
output_format: String,
181182
clone_path: PathBuf,
182183
output_path: PathBuf,
183-
stub_zip_path: Option<PathBuf>,
184+
stub_archive_path: Option<PathBuf>,
185+
stub_compression: Compression,
184186
submission_path: PathBuf,
187+
submission_compression: Compression,
185188
tmc_param: Vec<(String, Vec<String>)>,
186189
top_level_dir_name: Option<String>
187190
);
@@ -207,12 +210,12 @@ fn prepare_submission(mut cx: FunctionContext) -> JsResult<JsValue> {
207210
};
208211

209212
let res = tmc_langs::prepare_submission(
210-
&submission_path,
213+
(&submission_path, submission_compression),
211214
&output_path,
212215
top_level_dir_name,
213216
tmc_params,
214217
&clone_path,
215-
stub_zip_path.as_deref(),
218+
stub_archive_path.as_deref().map(|p| (p, stub_compression)),
216219
compression,
217220
);
218221
convert_res(&mut cx, res)

bindings/tmc-langs-node/ts/functions.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ export function prepareSubmission(
3434
outputFormat: types.Compression,
3535
clonePath: string,
3636
outputPath: string,
37-
stubZipPath: string | null,
37+
stubArchivePath: string | null,
38+
stubCompression: Compression,
3839
submissionPath: string,
40+
submissionCompression: Compression,
3941
tmcParam: Array<[string, Array<string>]>,
4042
topLevelDirName: string | null
4143
): void;

plugins/make/src/plugin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl LanguagePlugin for MakePlugin {
179179
if io_error.kind() == io::ErrorKind::PermissionDenied =>
180180
{
181181
// failed due to lacking permissions, try to clean and rerun
182-
let _output = self.clean(path)?;
182+
self.clean(path)?;
183183
match self.run_tests_with_valgrind(path, false) {
184184
Ok(output) => output,
185185
Err(err) => {

tmc-client/src/tmc_client.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ impl TmcClient {
265265

266266
// compress
267267
start_stage(2, "Compressing paste submission...", None);
268-
let compressed = tmc_langs_plugins::compress_project(submission_path, Compression::Zip)?;
268+
let compressed =
269+
tmc_langs_plugins::compress_project(submission_path, Compression::Zip, false)?;
269270
progress_stage(
270271
"Compressed paste submission. Posting paste submission...",
271272
None,
@@ -333,7 +334,8 @@ impl TmcClient {
333334
self.require_authentication()?;
334335

335336
start_stage(2, "Compressing submission...", None);
336-
let compressed = tmc_langs_plugins::compress_project(submission_path, Compression::Zip)?;
337+
let compressed =
338+
tmc_langs_plugins::compress_project(submission_path, Compression::Zip, false)?;
337339
progress_stage("Compressed submission. Posting submission...", None);
338340

339341
let result = api_v8::core::submit_exercise(
@@ -556,7 +558,8 @@ impl TmcClient {
556558
) -> Result<NewSubmission, ClientError> {
557559
self.require_authentication()?;
558560

559-
let compressed = tmc_langs_plugins::compress_project(submission_path, Compression::Zip)?;
561+
let compressed =
562+
tmc_langs_plugins::compress_project(submission_path, Compression::Zip, false)?;
560563
let review = if let Some(message) = message_for_reviewer {
561564
ReviewData::WithMessage(message)
562565
} else {

tmc-langs-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tmc-langs-cli"
3-
version = "0.26.0"
3+
version = "0.26.1"
44
authors = ["University of Helsinki <mooc@cs.helsinki.fi>", "Daniel Martinez <daniel.x.martinez@helsinki.fi>"]
55
edition = "2021"
66
description = "CLI client for TMC"

tmc-langs-cli/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::{
2020
collections::HashMap,
2121
env,
2222
fs::File,
23-
io::{self, Cursor, Read, Write, BufReader},
23+
io::{self, BufReader, Cursor, Read, Write},
2424
ops::Deref,
2525
path::{Path, PathBuf},
2626
};
@@ -89,8 +89,7 @@ fn run_inner() -> Result<(), ()> {
8989
trace: causes,
9090
}),
9191
}));
92-
print_output(&error_output, false)
93-
.expect("failed to print output");
92+
print_output(&error_output, false).expect("failed to print output");
9493
return Err(());
9594
}
9695
};
@@ -265,7 +264,7 @@ fn run_app(matches: Opt) -> Result<()> {
265264
let mut data = vec![];
266265
guard.read_to_end(&mut data)?;
267266

268-
tmc_langs::extract_project(Cursor::new(data), &output_path, compression, true)?;
267+
tmc_langs::extract_project(Cursor::new(data), &output_path, compression, true, naive)?;
269268

270269
OutputKind::finished(format!(
271270
"extracted project from {} to {}",
@@ -419,12 +418,12 @@ fn run_app(matches: Opt) -> Result<()> {
419418
}
420419

421420
tmc_langs::prepare_submission(
422-
&submission_path,
421+
(&submission_path, submission_compression),
423422
&output_path,
424423
top_level_dir_name,
425424
tmc_params,
426425
&clone_path,
427-
stub_archive_path.as_deref(),
426+
stub_archive_path.as_deref().map(|p| (p, stub_compression)),
428427
output_format,
429428
)?;
430429
OutputKind::finished(format!(
@@ -813,7 +812,8 @@ fn run_core_inner(
813812
// TODO: print "Please enter password" and add "quiet" flag
814813
let password = if stdin {
815814
let mut stdin = BufReader::new(std::io::stdin());
816-
rpassword::read_password_from_bufread(&mut stdin).context("Failed to read password")?
815+
rpassword::read_password_from_bufread(&mut stdin)
816+
.context("Failed to read password")?
817817
} else {
818818
rpassword::read_password().context("Failed to read password")?
819819
};

tmc-langs-framework/src/archive.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use serde::Deserialize;
2-
use std::io::{BufReader, Read, Seek};
2+
use std::io::{BufReader, Cursor, Read, Seek};
33
use std::ops::ControlFlow::{self, Break};
44
use std::path::{Path, PathBuf};
55
use std::{fmt::Display, str::FromStr};
@@ -220,6 +220,39 @@ pub enum Compression {
220220
TarZstd,
221221
}
222222

223+
impl Compression {
224+
pub fn compress(self, path: &Path) -> Result<Vec<u8>, TmcError> {
225+
let buf = Cursor::new(Vec::new());
226+
let buf = match self {
227+
Self::Tar => {
228+
let mut builder = tar::Builder::new(buf);
229+
builder
230+
.append_dir_all(".", path)
231+
.map_err(TmcError::TarWrite)?;
232+
builder.into_inner().map_err(TmcError::TarWrite)?
233+
}
234+
Self::Zip => {
235+
let mut writer = zip::ZipWriter::new(buf);
236+
let path_str = path
237+
.to_str()
238+
.ok_or_else(|| TmcError::InvalidUtf8(path.to_path_buf()))?;
239+
writer.add_directory(path_str, Default::default())?;
240+
writer.finish()?
241+
}
242+
Self::TarZstd => {
243+
let mut builder = tar::Builder::new(buf);
244+
builder
245+
.append_dir_all(".", path)
246+
.map_err(TmcError::TarWrite)?;
247+
let buf = builder.into_inner().map_err(TmcError::TarWrite)?;
248+
let encoder = zstd::Encoder::new(buf, 0).map_err(TmcError::ZstdWrite)?;
249+
encoder.finish().map_err(TmcError::ZstdWrite)?
250+
}
251+
};
252+
Ok(buf.into_inner())
253+
}
254+
}
255+
223256
impl Display for Compression {
224257
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
225258
match self {

0 commit comments

Comments
 (0)