1313import subprocess
1414import shutil
1515import sys
16- import uuid
1716import argcomplete
1817
1918CONTAINER_PREFIX = "ghcr.io/xcp-ng/xcp-ng-build-env"
@@ -134,7 +133,6 @@ def buildparser():
134133 'separate the arguments for this tool and the command with " -- ".' )
135134
136135 # shell -- like run bash
137- parser_shell = argparse .ArgumentParser ()
138136 parser_shell = subparsers_container .add_parser (
139137 'shell' ,
140138 help = 'Drop a shell into the prepared container' )
@@ -144,7 +142,6 @@ def buildparser():
144142 return parser
145143
146144def container (args ):
147- build = args .action == 'build'
148145 branch = args .branch
149146 docker_arch = args .platform or ("linux/amd64/v2" if branch == "9.0" else "linux/amd64" )
150147
@@ -159,23 +156,22 @@ def container(args):
159156
160157 if hasattr (args , 'command' ) and args .command != []:
161158 docker_args += ["-e" , "COMMAND=%s" % ' ' .join (args .command )]
162- if build :
159+ if args . action == ' build' :
163160 build_dir = os .path .abspath (args .source_dir )
164161 docker_args += ["-v" , f"{ build_dir } :/home/builder/rpmbuild" ]
165162 docker_args += ["-e" , "BUILD_LOCAL=1" ]
166- print (f"Building directory { build_dir } " )
163+ print (f"Building directory { build_dir } " , file = sys . stderr )
167164 if hasattr (args , 'define' ) and args .define :
168165 docker_args += ["-e" , "RPMBUILD_DEFINE=%s" % args .define ]
169166 if hasattr (args , 'rpmbuild_opts' ) and args .rpmbuild_opts :
170167 docker_args += ["-e" , "RPMBUILD_OPTS=%s" % ' ' .join (args .rpmbuild_opts )]
171168 if hasattr (args , 'rpmbuild_stage' ) and args .rpmbuild_stage :
172169 if args .rpmbuild_stage not in RPMBUILD_STAGES :
173- parser .error (f"--rpmbuild-stage={ args .rpmbuild_stage } not in '{ RPMBUILD_STAGES } '" )
170+ print (f"--rpmbuild-stage={ args .rpmbuild_stage } not in '{ RPMBUILD_STAGES } '" , file = sys .stderr )
171+ sys .exit (1 )
174172 docker_args += ["-e" , f"RPMBUILD_STAGE={ args .rpmbuild_stage } " ]
175173 if hasattr (args , 'output_dir' ) and args .output_dir :
176- if not os .path .isdir (args .output_dir ):
177- print (f"{ args .output_dir } is not a valid output directory." )
178- sys .exit (1 )
174+ os .makedirs (args .output_dir , exist_ok = True )
179175 docker_args += ["-v" , "%s:/home/builder/output" %
180176 os .path .abspath (args .output_dir )]
181177 if args .no_exit :
@@ -191,7 +187,7 @@ def container(args):
191187 if args .dir :
192188 for localdir in args .dir :
193189 if not os .path .isdir (localdir ):
194- print ("Local directory argument is not a directory!" )
190+ print ("Local directory argument is not a directory!" , file = sys . stderr )
195191 sys .exit (1 )
196192 ext_path = os .path .abspath (localdir )
197193 int_path = os .path .basename (ext_path )
0 commit comments