//! `koh build` — build with `koh.build`, and upload nothing. //! //! Publishing is `koh offer --builds`; this is for the person who wants the //! files, or who wants to know whether the build works at all. module cli import json2 import src.build import src.fmt pub fn cmd_build(raw []string) int { args := parse('build', raw, Options{ values: ['platform'] flags: ['all', 'json'] }) or { return usage_error(err.msg()) } // Two ways of naming platforms at once is a mistake in the command line, so // it is reported as one before anything is read. if args.flag('all') && args.values_of('platform').len > 0 { return usage_error('--all and --platform cannot be combined') } store := open_store() or { return refuse(args.json(), err.msg()) } defer { store.close() } config := build.read_config(store.root) or { return refuse(args.json(), err.msg()) } // Not `version`: that is the koh binary's own version, in this module. published_version := build.project_version(store.root) or { return refuse(args.json(), err.msg()) } // The version comes before the platform list, so a project that builds for // another platform still says which version it declares. if !args.json() { note('version ${published_version}') } platforms := wanted_platforms(args, config) or { return refuse(args.json(), err.msg()) } mut built := []build.Built{} for platform in platforms { result := build.build_one(store.root, config, platform, published_version) or { return refuse(args.json(), err.msg()) } built << result if !args.json() { ok('${platform} ${result.path} (${fmt.human_bytes(result.size)})') } } if args.json() { emit_json(json2.encode(BuildJson{ version: published_version files: built.map(BuiltJson{ platform: it.platform path: it.path size: it.size }) })) } return 0 } // wanted_platforms is what to build: every platform `koh.build` names with // --all, the named ones with --platform, and this machine's own otherwise. A // platform the file does not build for is refused rather than skipped. fn wanted_platforms(args Args, config build.Config) ![]string { mut wanted := args.values_of('platform') if args.flag('all') { wanted = config.platforms.clone() } else if wanted.len == 0 { wanted = [build.this_machine()!] } for platform in wanted { if platform !in config.platforms { return error('${build.config_name} does not build for "${platform}" — it builds for ${config.platforms.join(', ')}') } } return wanted } struct BuiltJson { platform string path string size i64 } struct BuildJson { version string files []BuiltJson }