gboolean xdg_app_builtin_dump_runtime (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(XdgAppDir) dir = NULL; const char *runtime; const char *branch = "master"; g_autofree char *ref = NULL; OstreeRepo *repo; g_autofree char *commit = NULL; g_autoptr(GFile) root = NULL; context = g_option_context_new ("RUNTIME BRANCH - Make branch of application current"); if (!xdg_app_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error)) return FALSE; if (argc < 3) return usage_error (context, "RUNTIME and BRANCH must be specified", error); runtime = argv[1]; branch = argv[2]; if (!xdg_app_is_valid_name (runtime)) return xdg_app_fail (error, "'%s' is not a valid name", runtime); if (!xdg_app_is_valid_branch (branch)) return xdg_app_fail (error, "'%s' is not a valid branch name", branch); ref = xdg_app_build_runtime_ref (runtime, branch, opt_arch); repo = xdg_app_dir_get_repo (dir); if (!ostree_repo_read_commit (repo, ref, &root, &commit, cancellable, error)) return FALSE; #ifdef HAVE_LIBARCHIVE return dump_runtime (root, cancellable, error); #else return xdg_app_fail (error, "Build without libarchive"); #endif }
gboolean xdg_app_builtin_build_init (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(GFile) var_deploy_base = NULL; g_autoptr(GFile) var_deploy_files = NULL; g_autoptr(GFile) base = NULL; g_autoptr(GFile) files_dir = NULL; g_autoptr(GFile) var_dir = NULL; g_autoptr(GFile) var_tmp_dir = NULL; g_autoptr(GFile) var_run_dir = NULL; g_autoptr(GFile) metadata_file = NULL; const char *app_id; const char *directory; const char *sdk; const char *runtime; const char *branch = "master"; g_autofree char *runtime_ref = NULL; g_autofree char *var_ref = NULL; g_autofree char *sdk_ref = NULL; g_autofree char *metadata_contents = NULL; context = g_option_context_new ("DIRECTORY APPNAME SDK RUNTIME [BRANCH] - Initialize a directory for building"); if (!xdg_app_option_context_parse (context, options, &argc, &argv, XDG_APP_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error)) return FALSE; if (argc < 5) return usage_error (context, "RUNTIME must be specified", error); directory = argv[1]; app_id = argv[2]; sdk = argv[3]; runtime = argv[4]; if (argc >= 6) branch = argv[5]; if (!xdg_app_is_valid_name (app_id)) return xdg_app_fail (error, "'%s' is not a valid application name", app_id); if (!xdg_app_is_valid_name (runtime)) return xdg_app_fail (error, "'%s' is not a valid runtime name", runtime); if (!xdg_app_is_valid_name (sdk)) return xdg_app_fail (error, "'%s' is not a valid sdk name", sdk); if (!xdg_app_is_valid_branch (branch)) return xdg_app_fail (error, "'%s' is not a valid branch name", branch); runtime_ref = xdg_app_build_untyped_ref (runtime, branch, opt_arch); sdk_ref = xdg_app_build_untyped_ref (sdk, branch, opt_arch); base = g_file_new_for_commandline_arg (directory); if (!gs_file_ensure_directory (base, TRUE, cancellable, error)) return FALSE; files_dir = g_file_get_child (base, "files"); var_dir = g_file_get_child (base, "var"); var_tmp_dir = g_file_get_child (var_dir, "tmp"); var_run_dir = g_file_get_child (var_dir, "run"); metadata_file = g_file_get_child (base, "metadata"); if (g_file_query_exists (files_dir, cancellable)) return xdg_app_fail (error, "Build directory %s already initialized", directory); if (opt_var) { var_ref = xdg_app_build_runtime_ref (opt_var, branch, opt_arch); var_deploy_base = xdg_app_find_deploy_dir_for_ref (var_ref, cancellable, error); if (var_deploy_base == NULL) return FALSE; var_deploy_files = g_file_get_child (var_deploy_base, "files"); } if (!g_file_make_directory (files_dir, cancellable, error)) return FALSE; if (var_deploy_files) { if (!gs_shutil_cp_a (var_deploy_files, var_dir, cancellable, error)) return FALSE; } else { if (!g_file_make_directory (var_dir, cancellable, error)) return FALSE; } if (!gs_file_ensure_directory (var_tmp_dir, FALSE, cancellable, error)) return FALSE; if (!g_file_query_exists (var_run_dir, cancellable) && !g_file_make_symbolic_link (var_run_dir, "/run", cancellable, error)) return FALSE; metadata_contents = g_strdup_printf("[Application]\n" "name=%s\n" "runtime=%s\n" "sdk=%s\n", app_id, runtime_ref, sdk_ref); if (!g_file_replace_contents (metadata_file, metadata_contents, strlen (metadata_contents), NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, cancellable, error)) return FALSE; return TRUE; }