From f39b59689dac78f997f711d4e5db5a5234af54f4 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 1 Apr 2015 13:58:23 +0200 Subject: [PATCH] Pass name into build-init and store in metadata We also drop this as an argument to build-export. This lets us verify that the name is valid up-front, and having the name in the metadata is useful for other things. For instance, build-finish can verify that all exported files have the right prefix. --- doc/xdg-app-build-export.xml | 6 ++--- doc/xdg-app-build-init.xml | 3 +++ xdg-app-builtins-build-export.c | 43 +++++++++++++++++++-------------- xdg-app-builtins-build-init.c | 23 ++++++++++++------ 4 files changed, 46 insertions(+), 29 deletions(-) diff --git a/doc/xdg-app-build-export.xml b/doc/xdg-app-build-export.xml index 0dec659df..b53d86a57 100644 --- a/doc/xdg-app-build-export.xml +++ b/doc/xdg-app-build-export.xml @@ -34,7 +34,6 @@ OPTION LOCATION DIRECTORY - NAME BRANCH @@ -46,8 +45,7 @@ Creates or updates a repository with an application build. LOCATION is the location of the repository. DIRECTORY must be a - finalized build directory. NAME - is the name of the application. If BRANCH + finalized build directory. If BRANCH is not specified, it is assumed to be "master". @@ -58,7 +56,7 @@ The contents of DIRECTORY are committed - on the branch with name app/NAME/ARCH/BRANCH, + on the branch with name app/APPNAME/ARCH/BRANCH, where ARCH is the architecture of the runtime that the application is using. A commit filter is used to enforce that only the contents of the files/ and export/ diff --git a/doc/xdg-app-build-init.xml b/doc/xdg-app-build-init.xml index c47fe819c..13838c1ff 100644 --- a/doc/xdg-app-build-init.xml +++ b/doc/xdg-app-build-init.xml @@ -32,6 +32,7 @@ xdg-app build-init OPTION + APPNAME DIRECTORY SDK RUNTIME @@ -45,6 +46,8 @@ Initializes a directory for building an application. DIRECTORY is the name of the directory. + APPNAME is the application id of the app + that will be built. SDK and RUNTIME specify the sdk and runtime that the application should be built against and run in. diff --git a/xdg-app-builtins-build-export.c b/xdg-app-builtins-build-export.c index 8cf67a2ef..1d1453ce4 100644 --- a/xdg-app-builtins-build-export.c +++ b/xdg-app-builtins-build-export.c @@ -128,41 +128,37 @@ xdg_app_builtin_build_export (int argc, char **argv, GCancellable *cancellable, g_autoptr(OstreeRepo) repo = NULL; const char *location; const char *directory; - const char *name; const char *branch; g_autofree char *arch = NULL; g_autofree char *full_branch = NULL; + g_autofree char *app_id = NULL; g_autofree char *parent = NULL; g_autofree char *commit_checksum = NULL; + g_autofree char *metadata_contents = NULL; g_autoptr(OstreeMutableTree) mtree = NULL; - char *subject = NULL; + g_autoptr(GKeyFile) metakey = NULL; + gsize metadata_size; + g_autofree char *subject = NULL; g_autofree char *body = NULL; OstreeRepoTransactionStats stats; OstreeRepoCommitModifier *modifier = NULL; - context = g_option_context_new ("LOCATION DIRECTORY NAME [BRANCH] - Create a repository from a build directory"); + context = g_option_context_new ("LOCATION DIRECTORY [BRANCH] - Create a repository from a build directory"); if (!xdg_app_option_context_parse (context, options, &argc, &argv, XDG_APP_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error)) goto out; - if (argc < 4) + if (argc < 3) { - usage_error (context, "LOCATION, DIRECTORY and NAME must be specified", error); + usage_error (context, "LOCATION and DIRECTORY must be specified", error); goto out; } location = argv[1]; directory = argv[2]; - name = argv[3]; - if (!xdg_app_is_valid_name (name)) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "'%s' is not a valid application name", name); - goto out; - } - - if (argc >= 5) - branch = argv[4]; + if (argc >= 4) + branch = argv[3]; else branch = "master"; @@ -184,6 +180,17 @@ xdg_app_builtin_build_export (int argc, char **argv, GCancellable *cancellable, goto out; } + if (!g_file_load_contents (metadata, cancellable, &metadata_contents, &metadata_size, NULL, error)) + goto out; + + metakey = g_key_file_new (); + if (!g_key_file_load_from_data (metakey, metadata_contents, metadata_size, 0, error)) + goto out; + + app_id = g_key_file_get_string (metakey, "Application", "name", error); + if (app_id == NULL) + goto out; + if (!g_file_query_exists (export, cancellable)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Build directory %s not finalized", directory); @@ -194,15 +201,15 @@ xdg_app_builtin_build_export (int argc, char **argv, GCancellable *cancellable, goto out; if (opt_subject) - subject = opt_subject; + subject = g_strdup (opt_subject); else - subject = "Import an application build"; + subject = g_strconcat ("Export ", app_id, NULL); if (opt_body) body = g_strdup (opt_body); else - body = g_strconcat ("Name: ", name, "\nArch: ", arch, "\nBranch: ", branch, NULL); + body = g_strconcat ("Name: ", app_id, "\nArch: ", arch, "\nBranch: ", branch, NULL); - full_branch = g_strconcat ("app/", name, "/", arch, "/", branch, NULL); + full_branch = g_strconcat ("app/", app_id, "/", arch, "/", branch, NULL); repofile = g_file_new_for_commandline_arg (location); repo = ostree_repo_new (repofile); diff --git a/xdg-app-builtins-build-init.c b/xdg-app-builtins-build-init.c index 89892bf4a..bea299fee 100644 --- a/xdg-app-builtins-build-init.c +++ b/xdg-app-builtins-build-init.c @@ -57,6 +57,7 @@ xdg_app_builtin_build_init (int argc, char **argv, GCancellable *cancellable, GE g_autoptr(GFile) metadata_file = NULL; g_autoptr(XdgAppDir) user_dir = NULL; g_autoptr(XdgAppDir) system_dir = NULL; + const char *app_id; const char *directory; const char *sdk; const char *runtime; @@ -66,22 +67,29 @@ xdg_app_builtin_build_init (int argc, char **argv, GCancellable *cancellable, GE g_autofree char *sdk_ref = NULL; g_autofree char *metadata_contents = NULL; - context = g_option_context_new ("DIRECTORY SDK RUNTIME [BRANCH] - Initialize a directory for building"); + 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)) goto out; - if (argc < 4) + if (argc < 5) { usage_error (context, "RUNTIME must be specified", error); goto out; } directory = argv[1]; - sdk = argv[2]; - runtime = argv[3]; - if (argc >= 5) - branch = argv[4]; + app_id = argv[2]; + sdk = argv[3]; + runtime = argv[4]; + if (argc >= 6) + branch = argv[5]; + + if (!xdg_app_is_valid_name (app_id)) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "'%s' is not a valid application name", app_id); + goto out; + } if (!xdg_app_is_valid_name (runtime)) { @@ -156,9 +164,10 @@ xdg_app_builtin_build_init (int argc, char **argv, GCancellable *cancellable, GE goto out; metadata_contents = g_strdup_printf("[Application]\n" + "name=%s\n" "runtime=%s\n" "sdk=%s\n", - runtime_ref, sdk_ref); + 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,