mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-25 05:01:09 +00:00
node-editor: Redo saving location
Determine the location to save testcases in dynamically, trying first a GTK_SOURCE_DIR environment variable and then the current directory as the GTK source dir, ultimatively falling back to just saving in the current directory. This avoids leaking details of the build environment into the produced artifacts and should make GTK builds more reproducible. Fixes: #5403
This commit is contained in:
parent
860c2f8ddd
commit
96b9ac84f8
@ -14,9 +14,7 @@ executable('gtk4-node-editor',
|
||||
sources: [node_editor_sources, node_editor_resources],
|
||||
dependencies: [ libgtk_dep, demo_conf_h ],
|
||||
include_directories: confinc,
|
||||
c_args: [
|
||||
'-DNODE_EDITOR_SOURCE_DIR="@0@/../../testsuite/gsk/compare/"'.format(meson.current_source_dir())
|
||||
] + common_cflags,
|
||||
c_args: common_cflags,
|
||||
win_subsystem: 'windows',
|
||||
link_args: extra_demo_ldflags,
|
||||
install: true,
|
||||
|
@ -32,10 +32,6 @@
|
||||
#include "gsk/vulkan/gskvulkanrenderer.h"
|
||||
#endif
|
||||
|
||||
#ifndef NODE_EDITOR_SOURCE_DIR
|
||||
#define NODE_EDITOR_SOURCE_DIR "." /* Fallback */
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gsize start_chars;
|
||||
@ -788,12 +784,54 @@ testcase_name_entry_changed_cb (GtkWidget *button,
|
||||
gtk_widget_set_sensitive (self->testcase_save_button, FALSE);
|
||||
}
|
||||
|
||||
/* Returns the location where gsk test cases are stored in
|
||||
* the GTK testsuite, if we can determine it.
|
||||
*
|
||||
* When running node editor outside of a GTK build, you can
|
||||
* set GTK_SOURCE_DIR to point it at the checkout.
|
||||
*/
|
||||
static char *
|
||||
get_source_dir (void)
|
||||
{
|
||||
const char *subdir = "testsuite/gsk/compare";
|
||||
const char *source_dir;
|
||||
char *current_dir;
|
||||
char *dir;
|
||||
|
||||
source_dir = g_getenv ("GTK_SOURCE_DIR");
|
||||
current_dir = g_get_current_dir ();
|
||||
|
||||
if (source_dir)
|
||||
{
|
||||
char *abs_source_dir = g_canonicalize_filename (source_dir, NULL);
|
||||
dir = g_canonicalize_filename (subdir, abs_source_dir);
|
||||
g_free (abs_source_dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
dir = g_canonicalize_filename (subdir, current_dir);
|
||||
}
|
||||
|
||||
if (g_file_test (dir, G_FILE_TEST_EXISTS))
|
||||
{
|
||||
g_print ("file exists: %s\n", dir);
|
||||
g_free (current_dir);
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
g_print ("file does not exists: %s\n", dir);
|
||||
g_free (dir);
|
||||
|
||||
return current_dir;
|
||||
}
|
||||
|
||||
static void
|
||||
testcase_save_clicked_cb (GtkWidget *button,
|
||||
NodeEditorWindow *self)
|
||||
{
|
||||
const char *testcase_name = gtk_editable_get_text (GTK_EDITABLE (self->testcase_name_entry));
|
||||
char *source_dir = g_canonicalize_filename (NODE_EDITOR_SOURCE_DIR, NULL);
|
||||
char *source_dir = get_source_dir ();
|
||||
char *node_file_name;
|
||||
char *node_file;
|
||||
char *png_file_name;
|
||||
@ -806,6 +844,8 @@ testcase_save_clicked_cb (GtkWidget *button,
|
||||
node_file = g_build_filename (source_dir, node_file_name, NULL);
|
||||
g_free (node_file_name);
|
||||
|
||||
g_debug ("Saving testcase in %s", node_file);
|
||||
|
||||
png_file_name = g_strconcat (testcase_name, ".png", NULL);
|
||||
png_file = g_build_filename (source_dir, png_file_name, NULL);
|
||||
g_free (png_file_name);
|
||||
|
Loading…
Reference in New Issue
Block a user