@@ -20,7 +20,7 @@ use std::ffi::{OsStr, OsString};
20
20
use std:: io:: { self , Read as _, Write as _} ;
21
21
use std:: ops:: Deref ;
22
22
use std:: path:: { Path , PathBuf } ;
23
- use std:: process:: { Command , Output , Stdio } ;
23
+ use std:: process:: { Command , Stdio } ;
24
24
use std:: str:: FromStr ;
25
25
use std:: time:: Instant ;
26
26
use std:: { env, f64, fs} ;
@@ -30,7 +30,7 @@ struct Opt {
30
30
#[ structopt(
31
31
long,
32
32
value_name( "PATH" ) ,
33
- default_value( "./test-with-generated-opts .toml" ) ,
33
+ default_value( "./test-examples .toml" ) ,
34
34
help( "Path to the config" )
35
35
) ]
36
36
config : PathBuf ,
@@ -60,20 +60,23 @@ fn main() -> anyhow::Result<()> {
60
60
write_with_style ( Color :: Black , false , true , "]" ) ?;
61
61
writeln ! ( buf, " {}" , record. args( ) )
62
62
} )
63
- . filter_module ( "test_with_generated_opts " , LevelFilter :: Info )
63
+ . filter_module ( "test_examples " , LevelFilter :: Info )
64
64
. init ( ) ;
65
65
66
66
let config = read_toml :: < _ , Config > ( config) ?;
67
67
68
68
scrape_sample_cases ( & config) ?;
69
+ cargo_build_examples_release ( ) ?;
69
70
70
71
let tests = config
71
72
. examples
72
73
. iter ( )
73
74
. map ( |( slug, example) | {
74
- let src = Path :: new ( "./examples" ) . join ( slug) . with_extension ( "rs" ) ;
75
- let bin = config. bin . expand_path ( slug) ?;
76
- compile ( & src, & bin) ?;
75
+ let bin = Path :: new ( "." )
76
+ . join ( "target" )
77
+ . join ( "release" )
78
+ . join ( "examples" )
79
+ . join ( slug) ;
77
80
78
81
match example {
79
82
Example :: Normal ( Normal {
@@ -131,8 +134,7 @@ fn scrape_sample_cases(config: &Config) -> anyhow::Result<()> {
131
134
}
132
135
133
136
fn get_html ( url : & Url ) -> anyhow:: Result < Html > {
134
- static USER_AGENT : & str =
135
- "test-with-generated-opts <https://github.com/rust-lang-ja/atcoder-rust-base>" ;
137
+ static USER_AGENT : & str = "test-examples <https://github.com/rust-lang-ja/atcoder-rust-base>" ;
136
138
137
139
info ! ( "GET: {}" , url) ;
138
140
@@ -387,11 +389,11 @@ fn load_testcases(dir: &Path) -> anyhow::Result<BTreeMap<OsString, (String, Stri
387
389
. collect ( )
388
390
}
389
391
390
- fn compile ( src : & Path , bin : & Path ) -> anyhow:: Result < ( ) > {
392
+ fn cargo_build_examples_release ( ) -> anyhow:: Result < ( ) > {
391
393
fn run_command < S1 : AsRef < OsStr > , S2 : AsRef < OsStr > , I : IntoIterator < Item = S2 > > (
392
394
program : S1 ,
393
395
args : I ,
394
- ) -> anyhow:: Result < Vec < u8 > > {
396
+ ) -> anyhow:: Result < ( ) > {
395
397
let program = program. as_ref ( ) ;
396
398
let args = args. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
397
399
@@ -405,58 +407,17 @@ fn compile(src: &Path, bin: &Path) -> anyhow::Result<()> {
405
407
. format_with( "" , |s, f| f( & format_args!( " {}" , s) ) ) ,
406
408
) ;
407
409
408
- let Output { status, stdout, .. } = Command :: new ( program)
409
- . args ( & args)
410
- . stdin ( Stdio :: null ( ) )
411
- . stderr ( Stdio :: inherit ( ) )
412
- . output ( ) ?;
413
-
410
+ let status = Command :: new ( program) . args ( & args) . status ( ) ?;
414
411
if !status. success ( ) {
415
412
return Err ( anyhow ! ( "{}: {}" , program. to_string_lossy( ) , status) ) ;
416
413
}
417
- Ok ( stdout)
418
- }
419
-
420
- if let ( Ok ( src_metadata) , Ok ( bin_metadata) ) = ( src. metadata ( ) , bin. metadata ( ) ) {
421
- if src_metadata. modified ( ) ? < bin_metadata. modified ( ) ? {
422
- info ! ( "{} is up to date." , bin. display( ) ) ;
423
- return Ok ( ( ) ) ;
424
- }
425
- }
426
-
427
- if let Some ( parent) = bin. parent ( ) {
428
- if !parent. exists ( ) {
429
- create_dir_all ( parent) ?;
430
- }
414
+ Ok ( ( ) )
431
415
}
432
416
433
- let generated_opts = {
434
- let program = which:: which ( "rustc-dep-option-generator" ) ?;
435
- let stdout = run_command ( & program, & [ "--format" , "json" ] ) ?;
436
- serde_json:: from_slice :: < Vec < String > > ( & stdout)
437
- . with_context ( || format ! ( "{}: invalid output" , program. to_string_lossy( ) ) ) ?
438
- } ;
439
-
440
- let program = env:: var_os ( "RUSTC" )
441
- . map ( Ok )
442
- . unwrap_or_else ( || which:: which ( "rustc" ) . map ( Into :: into) ) ?;
443
-
444
- let args = {
445
- let mut args = vec ! [
446
- OsString :: from( "--edition" ) ,
447
- OsString :: from( "2018" ) ,
448
- OsString :: from( "-C" ) ,
449
- OsString :: from( "opt-level=3" ) ,
450
- OsString :: from( "-o" ) ,
451
- OsString :: from( bin) ,
452
- ] ;
453
- for opt in generated_opts {
454
- args. push ( opt. into ( ) ) ;
455
- }
456
- args. push ( src. to_owned ( ) . into ( ) ) ;
457
- args
458
- } ;
459
- run_command ( program, args) . map ( drop)
417
+ run_command (
418
+ env:: var_os ( "CARGO" ) . unwrap_or_else ( || "cargo" . into ( ) ) ,
419
+ & [ "build" , "--examples" , "--release" ] ,
420
+ )
460
421
}
461
422
462
423
fn normal_test (
@@ -590,7 +551,6 @@ impl BoolExt for bool {
590
551
591
552
#[ derive( Debug , Deserialize ) ]
592
553
struct Config {
593
- bin : Template ,
594
554
testcases : Template ,
595
555
examples : IndexMap < String , Example > ,
596
556
}
0 commit comments