@@ -34,6 +34,8 @@ def configure_subparser(self, subparser):
3434
3535 parser .add_argument ('ingen_path' , type = str , nargs = '?' ,
3636 help = 'path to ingen source file, for example prog/abcingen.cpp' )
37+ parser .add_argument ('-i' , '--only-inputs' , action = 'store_true' , help = 'generate input files only' )
38+ parser .add_argument ('-o' , '--only-outputs' , action = 'store_true' , help = 'generate output files only' )
3739 parser .add_argument ('-c' , '--cpus' , type = int ,
3840 help = f'number of cpus to use to generate output files '
3941 f'(default: { util .default_cpu_count ()} )' ,
@@ -80,38 +82,51 @@ def calculate_md5_sums(self):
8082 outputs_to_generate = []
8183 for file in glob .glob (os .path .join (os .getcwd (), 'in' , '*.in' )):
8284 basename = os .path .basename (file )
85+ output_basename = os .path .splitext (os .path .basename (basename ))[0 ] + '.out'
86+ output_path = os .path .join (os .getcwd (), 'out' , output_basename )
8387 md5_sums [basename ] = util .get_file_md5 (file )
8488
8589 if old_md5_sums is None or old_md5_sums .get (basename , '' ) != md5_sums [basename ]:
86- output_basename = os .path .splitext (os .path .basename (basename ))[0 ] + '.out'
87- outputs_to_generate .append (os .path .join (os .getcwd (), "out" , output_basename ))
90+ outputs_to_generate .append (output_path )
91+ elif not os .path .exists (output_path ):
92+ # If output file does not exist, generate it.
93+ outputs_to_generate .append (output_path )
8894
8995 return md5_sums , outputs_to_generate
9096
9197 def run (self , args : argparse .Namespace ):
9298 util .exit_if_not_package ()
9399
94100 self .args = args
101+ self .ins = args .only_inputs
102+ self .outs = args .only_outputs
103+ # If no arguments are specified, generate both input and output files.
104+ if not self .ins and not self .outs :
105+ self .ins = True
106+ self .outs = True
107+
95108 self .task_id = package_util .get_task_id ()
96109 package_util .validate_test_names (self .task_id )
97- self .ingen = gen_util .get_ingen (self .task_id , args .ingen_path )
98- print (util .info (f'Using ingen file { os .path .basename (self .ingen )} ' ))
110+ util .change_stack_size_to_unlimited ()
111+ if self .ins :
112+ self .ingen = gen_util .get_ingen (self .task_id , args .ingen_path )
113+ print (util .info (f'Using ingen file { os .path .basename (self .ingen )} ' ))
114+ self .ingen_exe = gen_util .compile_ingen (self .ingen , self .args , self .args .weak_compilation_flags )
115+
116+ if gen_util .run_ingen (self .ingen_exe ):
117+ print (util .info ('Successfully generated input files.' ))
118+ else :
119+ util .exit_with_error ('Failed to generate input files.' )
99120
100- self . correct_solution = gen_util . get_correct_solution ( self .task_id )
101- self .ingen_exe = gen_util .compile_ingen (self .ingen , self . args , self . args . weak_compilation_flags )
121+ if self .outs :
122+ self .correct_solution = gen_util .get_correct_solution (self .task_id )
102123
103- util .change_stack_size_to_unlimited ()
104- if gen_util .run_ingen (self .ingen_exe ):
105- print (util .info ('Successfully generated input files.' ))
106- else :
107- util .exit_with_error ('Failed to generate input files.' )
108- md5_sums , outputs_to_generate = self .calculate_md5_sums ()
109- if len (outputs_to_generate ) == 0 :
110- print (util .info ('All output files are up to date.' ))
111- else :
112- self .correct_solution_exe = gen_util .compile_correct_solution (self .correct_solution , self .args ,
113- self .args .weak_compilation_flags )
114- self .generate_outputs (outputs_to_generate )
115-
116- with open (os .path .join (os .getcwd (), 'in' , '.md5sums' ), 'w' ) as f :
117- yaml .dump (md5_sums , f )
124+ md5_sums , outputs_to_generate = self .calculate_md5_sums ()
125+ if len (outputs_to_generate ) == 0 :
126+ print (util .info ('All output files are up to date.' ))
127+ else :
128+ self .correct_solution_exe = gen_util .compile_correct_solution (self .correct_solution , self .args ,
129+ self .args .weak_compilation_flags )
130+ self .generate_outputs (outputs_to_generate )
131+ with open (os .path .join (os .getcwd (), 'in' , '.md5sums' ), 'w' ) as f :
132+ yaml .dump (md5_sums , f )
0 commit comments