@@ -20,7 +20,7 @@ use std::ffi::{OsStr, OsString};
2020use std:: io:: { self , Read as _, Write as _} ;
2121use std:: ops:: Deref ;
2222use std:: path:: { Path , PathBuf } ;
23- use std:: process:: { Command , Output , Stdio } ;
23+ use std:: process:: { Command , Stdio } ;
2424use std:: str:: FromStr ;
2525use std:: time:: Instant ;
2626use std:: { env, f64, fs} ;
@@ -30,7 +30,7 @@ struct Opt {
3030 #[ structopt(
3131 long,
3232 value_name( "PATH" ) ,
33- default_value( "./test-with-generated-opts .toml" ) ,
33+ default_value( "./test-examples .toml" ) ,
3434 help( "Path to the config" )
3535 ) ]
3636 config : PathBuf ,
@@ -60,20 +60,23 @@ fn main() -> anyhow::Result<()> {
6060 write_with_style ( Color :: Black , false , true , "]" ) ?;
6161 writeln ! ( buf, " {}" , record. args( ) )
6262 } )
63- . filter_module ( "test_with_generated_opts " , LevelFilter :: Info )
63+ . filter_module ( "test_examples " , LevelFilter :: Info )
6464 . init ( ) ;
6565
6666 let config = read_toml :: < _ , Config > ( config) ?;
6767
6868 scrape_sample_cases ( & config) ?;
69+ cargo_build_examples_release ( ) ?;
6970
7071 let tests = config
7172 . examples
7273 . iter ( )
7374 . 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) ;
7780
7881 match example {
7982 Example :: Normal ( Normal {
@@ -131,8 +134,7 @@ fn scrape_sample_cases(config: &Config) -> anyhow::Result<()> {
131134}
132135
133136fn 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>" ;
136138
137139 info ! ( "GET: {}" , url) ;
138140
@@ -387,11 +389,11 @@ fn load_testcases(dir: &Path) -> anyhow::Result<BTreeMap<OsString, (String, Stri
387389 . collect ( )
388390}
389391
390- fn compile ( src : & Path , bin : & Path ) -> anyhow:: Result < ( ) > {
392+ fn cargo_build_examples_release ( ) -> anyhow:: Result < ( ) > {
391393 fn run_command < S1 : AsRef < OsStr > , S2 : AsRef < OsStr > , I : IntoIterator < Item = S2 > > (
392394 program : S1 ,
393395 args : I ,
394- ) -> anyhow:: Result < Vec < u8 > > {
396+ ) -> anyhow:: Result < ( ) > {
395397 let program = program. as_ref ( ) ;
396398 let args = args. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
397399
@@ -405,58 +407,17 @@ fn compile(src: &Path, bin: &Path) -> anyhow::Result<()> {
405407 . format_with( "" , |s, f| f( & format_args!( " {}" , s) ) ) ,
406408 ) ;
407409
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 ( ) ?;
414411 if !status. success ( ) {
415412 return Err ( anyhow ! ( "{}: {}" , program. to_string_lossy( ) , status) ) ;
416413 }
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 ( ( ) )
431415 }
432416
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+ )
460421}
461422
462423fn normal_test (
@@ -590,7 +551,6 @@ impl BoolExt for bool {
590551
591552#[ derive( Debug , Deserialize ) ]
592553struct Config {
593- bin : Template ,
594554 testcases : Template ,
595555 examples : IndexMap < String , Example > ,
596556}
0 commit comments