Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build option to run commands via bash -c #154

Merged
merged 4 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
01micko marked this conversation as resolved.
Show resolved Hide resolved
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')
01micko marked this conversation as resolved.
Show resolved Hide resolved
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