mirror of
https://github.com/flatpak/flatpak.git
synced 2026-10-24 08:29:34 -04:00
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.
This commit is contained in:
1 parent
61a8a1b5dc
commit
f39b59689d
4 files changed
+46
-29
No files matched your search
@@ -34,7 +34,6 @@
|
||||
<arg choice="opt" rep="repeat">OPTION</arg>
|
||||
<arg choice="plain">LOCATION</arg>
|
||||
<arg choice="plain">DIRECTORY</arg>
|
||||
<arg choice="plain">NAME</arg>
|
||||
<arg choice="opt">BRANCH</arg>
|
||||
</cmdsynopsis>
|
||||
</refsynopsisdiv>
|
||||
@@ -46,8 +45,7 @@
|
||||
Creates or updates a repository with an application build.
|
||||
<arg choice="plain">LOCATION</arg> is the location of the
|
||||
repository. <arg choice="plain">DIRECTORY</arg> must be a
|
||||
finalized build directory. <arg choice="plain">NAME</arg>
|
||||
is the name of the application. If <arg choice="plain">BRANCH</arg>
|
||||
finalized build directory. If <arg choice="plain">BRANCH</arg>
|
||||
is not specified, it is assumed to be "master".
|
||||
</para>
|
||||
<para>
|
||||
@@ -58,7 +56,7 @@
|
||||
</para>
|
||||
<para>
|
||||
The contents of <arg choice="plain">DIRECTORY</arg> are committed
|
||||
on the branch with name <literal>app/NAME/ARCH/BRANCH</literal>,
|
||||
on the branch with name <literal>app/APPNAME/ARCH/BRANCH</literal>,
|
||||
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 <filename>files/</filename> and <filename>export/</filename>
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
<cmdsynopsis>
|
||||
<command>xdg-app build-init</command>
|
||||
<arg choice="opt" rep="repeat">OPTION</arg>
|
||||
<arg choice="plain">APPNAME</arg>
|
||||
<arg choice="plain">DIRECTORY</arg>
|
||||
<arg choice="plain">SDK</arg>
|
||||
<arg choice="plain">RUNTIME</arg>
|
||||
@@ -45,6 +46,8 @@
|
||||
<para>
|
||||
Initializes a directory for building an application.
|
||||
<arg choice="plain">DIRECTORY</arg> is the name of the directory.
|
||||
<arg choice="plain">APPNAME</arg> is the application id of the app
|
||||
that will be built.
|
||||
<arg choice="plain">SDK</arg> and <arg choice="plain">RUNTIME</arg>
|
||||
specify the sdk and runtime that the application should be built
|
||||
against and run in.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user