Skip to content

Commit

Permalink
add build option to run commands via bash -c
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Aug 6, 2023
1 parent def62a6 commit f526a0f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt-get update -qq
Expand All @@ -22,11 +22,13 @@ jobs:
run: |
meson --buildtype=release -Dgtkver=2 build
ninja -C build
DESTDIR=/tmp/meson-gtk3 ninja -C build install
DESTDIR=/tmp/meson-gtk2 ninja -C build install
cd ../gtk3-meson
meson --buildtype=release build
ninja -C build
DESTDIR=/tmp/meson-gtk2 ninja -C build install
meson configure build -Dbash=true
ninja -C build
DESTDIR=/tmp/meson-gtk3 ninja -C build install
- name: Autotools build
run: |
cd ../gtk2-autotools
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
option('gtkver', type: 'integer', value: 3, description: 'GTK+ version')
option('docs', type: 'boolean', value: false, description: 'add html documentation and examples')
option('bash', type: 'boolean', value: false, description: 'run commands using bash -c')
28 changes: 24 additions & 4 deletions src/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "attributes.h"
#include "variables.h"
#include "tag_attributes.h"
#include "config.h"

extern gchar *option_include_file;

Expand Down Expand Up @@ -642,26 +643,45 @@ void action_presentwindow(GtkWidget *widget, char *string)
/***********************************************************************
* Action command *
***********************************************************************/
/* This fuction will export variables and run a shell command */

static void _action_shellcommand(const char *command)
{
#if HAVE_BASH
char *argv[] = {"bash", "-c", command, NULL};

g_spawn_sync(NULL,
argv,
NULL,
G_SPAWN_LEAVE_DESCRIPTORS_OPEN | G_SPAWN_SEARCH_PATH,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL);
#else
system(command);
#endif
}

/* This fuction will export variables and run a shell command */
void action_shellcommand(GtkWidget *widget, char *string)
{
char *command;
int result;

variables_export_all();

if (option_include_file == NULL) {

result = system(string);
_action_shellcommand(string);

} else {

/* Debian 01_bashism patch: use dot rather than source.
command = g_strdup_printf("source %s; %s", */
command = g_strdup_printf(". %s; %s",
option_include_file, string);
result = system(command);
_action_shellcommand(command);
g_free(command);

}
Expand Down
5 changes: 5 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ if gtkver == 3 and gtk_layer_shell.found()
else
cfg.set('HAVE_GTK_LAYER_SHELL', 0)
endif
if get_option('bash')
cfg.set('HAVE_BASH', 1)
else
cfg.set('HAVE_BASH', 0)
endif

configure_file(
output : 'config.h',
Expand Down

0 comments on commit f526a0f

Please sign in to comment.