def _setup_build_dir(self): # Initialize build_dir and created_build_dir attributes. # If we created the build directory, we must run CMake. log.dbg('setting up build directory', level=log.VERBOSE_EXTREME) # The CMake Cache has not been loaded yet, so this is safe board, _ = self._find_board() source_dir = self._find_source_dir() app = os.path.split(source_dir)[1] build_dir = find_build_dir(self.args.build_dir, board=board, source_dir=source_dir, app=app) if not build_dir: log.die('Unable to determine a default build folder. Check ' 'your build.dir-fmt configuration option') if os.path.exists(build_dir): if not os.path.isdir(build_dir): log.die( 'build directory {} exists and is not a directory'.format( build_dir)) else: os.makedirs(build_dir, exist_ok=False) self.created_build_dir = True self.run_cmake = True self.build_dir = build_dir
def do_run(self, args, ignored): self.args = args # for check_force # Find the build directory and parse .config and DT. build_dir = find_build_dir(args.build_dir) self.check_force(os.path.isdir(build_dir), 'no such build directory {}'.format(build_dir)) self.check_force(is_zephyr_build(build_dir), "build directory {} doesn't look like a Zephyr build " 'directory'.format(build_dir)) bcfg = BuildConfiguration(build_dir) # Decide on output formats. formats = [] bin_exists = 'CONFIG_BUILD_OUTPUT_BIN' in bcfg if args.gen_bin: self.check_force(bin_exists, '--bin given but CONFIG_BUILD_OUTPUT_BIN not set ' "in build directory's ({}) .config". format(build_dir)) formats.append('bin') elif args.gen_bin is None and bin_exists: formats.append('bin') hex_exists = 'CONFIG_BUILD_OUTPUT_HEX' in bcfg if args.gen_hex: self.check_force(hex_exists, '--hex given but CONFIG_BUILD_OUTPUT_HEX not set ' "in build directory's ({}) .config". format(build_dir)) formats.append('hex') elif args.gen_hex is None and hex_exists: formats.append('hex') if not formats: if not args.quiet: log.dbg('nothing to do: no output files') return # Delegate to the signer. if args.tool == 'imgtool': signer = ImgtoolSigner() elif args.tool == 'rimage': signer = RimageSigner() # (Add support for other signers here in elif blocks) else: raise RuntimeError("can't happen") signer.sign(self, build_dir, bcfg, formats)
def _setup_build_dir(self): # Initialize build_dir and created_build_dir attributes. # If we created the build directory, we must run CMake. log.dbg('setting up build directory', level=log.VERBOSE_EXTREME) build_dir = find_build_dir(self.args.build_dir) if os.path.exists(build_dir): if not os.path.isdir(build_dir): log.die('build directory {} exists and is not a directory'. format(build_dir)) else: os.makedirs(build_dir, exist_ok=False) self.created_build_dir = True self.run_cmake = True self.build_dir = build_dir
def _build_dir(args, die_if_none=True): # Get the build directory for the given argument list and environment. if args.build_dir: return args.build_dir dir = find_build_dir(None) if dir and is_zephyr_build(dir): return dir elif die_if_none: msg = '--build-dir was not given, ' if dir: msg = msg + 'and neither {} nor {} are zephyr build directories.' else: msg = msg + ('{} is not a build directory and the default build ' 'directory cannot be determined. Check your ' 'build.dir-fmt configuration option') log.die(msg.format(getcwd(), dir)) else: return None
def do_run(self, args, ignored): if not (args.gen_bin or args.gen_hex): return # Provide the build directory if not given, and defer to the signer. args.build_dir = find_build_dir(args.build_dir) self.args = args # for check_force self.check_force(os.path.isdir(args.build_dir), 'no such build directory {}'.format(args.build_dir)) self.check_force( is_zephyr_build(args.build_dir), "build directory {} doesn't look like a Zephyr build " 'directory'.format(args.build_dir)) if args.tool == 'imgtool': signer = ImgtoolSigner() # (Add support for other signers here in elif blocks) else: raise RuntimeError("can't happen") signer.sign(self)