Skip to content

Commit b89f540

Browse files
committed
builder-module: Add wrap-mode=nodownload to meson if building w/o network
Supersedes #643
1 parent e2f9ffc commit b89f540

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/builder-module.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,7 @@ builder_module_build_helper (BuilderModule *self,
17541754
const char *ldflags = NULL;
17551755

17561756
gboolean autotools = FALSE, cmake = FALSE, cmake_ninja = FALSE, meson = FALSE, simple = FALSE, qmake = FALSE;
1757+
gboolean build_has_network = FALSE;
17571758
g_autoptr(GFile) configure_file = NULL;
17581759
g_autoptr(GFile) build_dir = NULL;
17591760
g_autofree char *build_dir_relative = NULL;
@@ -1796,6 +1797,8 @@ builder_module_build_helper (BuilderModule *self,
17961797
if (build_args == NULL)
17971798
return FALSE;
17981799

1800+
build_has_network = builder_options_build_has_network (build_args);
1801+
17991802
env = builder_options_get_env (self->build_options, context);
18001803
cflags = g_environ_getenv (env, "CFLAGS");
18011804
cxxflags = g_environ_getenv (env, "CXXFLAGS");
@@ -2020,6 +2023,8 @@ builder_module_build_helper (BuilderModule *self,
20202023
{
20212024
/* Meson's setup command is now meson setup */
20222025
g_ptr_array_add (configure_args_arr, g_strdup ("setup"));
2026+
if (!build_has_network)
2027+
g_ptr_array_add (configure_args_arr, g_strdup ("--wrap-mode=nodownload"));
20232028
}
20242029

20252030
if (cmake || cmake_ninja)

src/builder-options.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,36 @@ builder_options_get_build_args (BuilderOptions *self,
12361236
return (char **) g_ptr_array_free (g_steal_pointer (&array), FALSE);
12371237
}
12381238

1239+
gboolean
1240+
builder_options_build_has_network (char **build_args)
1241+
{
1242+
gboolean has_network = FALSE;
1243+
1244+
if (!build_args)
1245+
return FALSE;
1246+
1247+
/*
1248+
* The last arg passed to flatpak build wins:
1249+
*
1250+
* --unshare=network --share=network -> network enabled
1251+
* --share=network --unshare=network -> network disabled
1252+
*
1253+
* So we iterate through the entire list
1254+
*/
1255+
1256+
for (size_t i = 0; build_args[i]; i++)
1257+
{
1258+
const char *arg = build_args[i];
1259+
1260+
if (g_strcmp0 (arg, "--unshare=network") == 0)
1261+
has_network = FALSE;
1262+
else if (g_strcmp0 (arg, "--share=network") == 0)
1263+
has_network = TRUE;
1264+
}
1265+
1266+
return has_network;
1267+
}
1268+
12391269
char **
12401270
builder_options_get_test_args (BuilderOptions *self,
12411271
BuilderContext *context,

src/builder-options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ gboolean builder_options_get_no_debuginfo_compression (BuilderOptions *self,
8181
BuilderContext *context);
8282
gboolean builder_options_get_strip (BuilderOptions *self,
8383
BuilderContext *context);
84+
gboolean builder_options_build_has_network (char **build_args);
8485

8586
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BuilderOptions, g_object_unref)
8687

0 commit comments

Comments
 (0)