[gjs] autoconf-2.64 compat: Don't use $(builddir) or $(abs_top_builddir)



commit 5365b439911257bdb90bd969713cc41ba08fd825
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Sat Aug 15 08:58:25 2009 -0400

    autoconf-2.64 compat: Don't use $(builddir) or $(abs_top_builddir)
    
    $(builddir) is not a standard automake variable. With autoconf < 2.64
    it ends up getting set in every Makefile.in to '.' (because autoconf
    defines it), but that is no longer the case for 2.64.
    
    Since $(builddir) was always '.', just use that instead.
    
    The $(abs_top_srcdir) $(abs_top_builddir) variables are also artifacts
    of old autoconf rather than something intentional in automake. To
    stop using those:
    
     - Set the paths in TESTS_ENVIRONMENT to just be relative to
       the top build directory - we never change from there when
       running tests.
     - Make gjs-unit determine the paths to various directories by
       determining them relative to the binary.
    
    http://bugzilla.gnome.org/show_bug.cgi?id=591897

 Makefile-test.am   |   16 ++++++------
 Makefile.am        |    3 +-
 scripts/make-tests |    2 +-
 test/gjs-unit.c    |   65 +++++++++++++++++++++++++++++++++++++++++++++------
 test/run-with-dbus |    3 +-
 5 files changed, 68 insertions(+), 21 deletions(-)
---
diff --git a/Makefile-test.am b/Makefile-test.am
index 68a2f21..2b333ec 100644
--- a/Makefile-test.am
+++ b/Makefile-test.am
@@ -31,7 +31,7 @@ nodist_gjs_tests_SOURCES =	\
 ## .h.stamp and .c.stamp but if we listed both, make would run
 ## make-tests twice.
 gjstest.h.stamp : scripts/make-tests $(gjstest_files_with_tests)
-	$(TESTS_ENVIRONMENT) $(top_srcdir)/scripts/make-tests $(builddir) $(gjstest_files_with_tests)
+	$(TESTS_ENVIRONMENT) $(top_srcdir)/scripts/make-tests . $(gjstest_files_with_tests)
 
 gjstest.h gjstest.c : gjstest.h.stamp
 	@true
@@ -63,13 +63,13 @@ EXTRA_DIST +=			\
 	scripts/make-tests
 
 ########################################################################
-TESTS_ENVIRONMENT =				\
-	abs_top_srcdir="$(abs_top_srcdir)"	\
-	DBUS_SESSION_BUS_ADDRESS=''			\
-	XDG_DATA_HOME=$(abs_top_builddir)/test_user_data \
-        GJS_DEBUG_OUTPUT=$(builddir)/test_user_data/logs/gjs.log    \
-	BUILDDIR=$(abs_top_builddir)			\
-	GJS_USE_UNINSTALLED_FILES=1			\
+TESTS_ENVIRONMENT =							\
+	TOP_SRCDIR=$(top_srcdir)					\
+	DBUS_SESSION_BUS_ADDRESS=''					\
+	XDG_DATA_HOME=test_user_data					\
+	GJS_DEBUG_OUTPUT=test_user_data/logs/gjs.log			\
+	BUILDDIR=.							\
+	GJS_USE_UNINSTALLED_FILES=1					\
 	LD_LIBRARY_PATH="$(LD_LIBRARY_PATH):$(FIREFOX_JS_LIBDIR)"	\
 	G_FILENAME_ENCODING=latin1	# ensure filenames are not utf8
 
diff --git a/Makefile.am b/Makefile.am
index 6b99e46..83f3a46 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -43,8 +43,7 @@ EXTRA_DIST += 			\
 
 ########################################################################
 gjs_directory_defines = 				\
-	-DGJS_TOP_SRCDIR=\"$(abs_top_srcdir)\"		\
-	-DGJS_BUILDDIR=\"$(abs_top_builddir)\"		\
+	-DGJS_TOP_SRCDIR=\"$(top_srcdir)\"		\
 	-DGJS_JS_DIR=\"$(gjsjsdir)\"			\
 	-DGJS_NATIVE_DIR=\"$(gjsnativedir)\"
 
diff --git a/scripts/make-tests b/scripts/make-tests
index 7ca12e4..3ed6001 100755
--- a/scripts/make-tests
+++ b/scripts/make-tests
@@ -95,7 +95,7 @@ def find_tests(base_filename, full_filename):
 
 output_dir = sys.argv[1]
 input_files = sys.argv[2:]
-top_srcdir = os.getenv('abs_top_srcdir')
+top_srcdir = os.getenv('TOP_SRCDIR')
 
 out_header_name = os.path.join(output_dir, "gjstest.h")
 out_impl_name = os.path.join(output_dir, "gjstest.c")
diff --git a/test/gjs-unit.c b/test/gjs-unit.c
index 0561528..26fd59c 100644
--- a/test/gjs-unit.c
+++ b/test/gjs-unit.c
@@ -24,6 +24,7 @@
 #include <config.h>
 
 #include <glib.h>
+#include <glib/gstdio.h>
 #include <gjs/gjs.h>
 #include <util/crash.h>
 #include <locale.h>
@@ -34,7 +35,7 @@ typedef struct {
     GjsContext *context;
 } GjsTestJSFixture;
 
-static const char *top_srcdir;
+static char *top_srcdir;
 
 
 static void
@@ -94,23 +95,71 @@ test(GjsTestJSFixture *fix,
 int
 main(int argc, char **argv)
 {
+    /* These are relative to top_builddir */
+    const char * const path_directories[] = {
+        GJS_TOP_SRCDIR"/modules",
+        GJS_TOP_SRCDIR"/test/js/modules",
+        ".libs:",
+        NULL
+    };
+
     char *js_test_dir;
+    char *working_dir;
+    char *gjs_unit_path;
+    char *gjs_unit_dir;
+    char *top_builddir;
+    char *data_home;
     const char *name;
+    GString *path;
     GDir *dir;
+    size_t i;
+
+    working_dir = g_get_current_dir();
+
+    if(g_path_is_absolute(argv[0]))
+        gjs_unit_path = g_strdup(argv[0]);
+    else
+        gjs_unit_path = g_build_filename(working_dir, argv[0], NULL);
+
+    gjs_unit_dir = g_path_get_basename(gjs_unit_path);
+    top_builddir = g_build_filename(gjs_unit_dir, "..", NULL);
+    top_srcdir = g_build_filename(top_builddir, GJS_TOP_SRCDIR, NULL);
+
+    /* Normalize, not strictly necessary */
+    g_chdir(top_builddir);
+    g_free(top_builddir);
+    top_builddir = g_get_current_dir();
+
+    g_chdir(top_srcdir);
+    g_free(top_srcdir);
+    top_srcdir = g_get_current_dir();
+
+    g_chdir(working_dir);
 
     /* we're always going to use uninstalled files, set up necessary
      * environment variables, but don't overwrite if already set */
-    g_setenv("TOP_SRCDIR", GJS_TOP_SRCDIR, FALSE);
-    g_setenv("BUILDDIR", GJS_BUILDDIR, FALSE);
-    g_setenv("XDG_DATA_HOME", GJS_BUILDDIR "/test_user_data", FALSE);
-    g_setenv("GJS_PATH", GJS_TOP_SRCDIR"/modules:"GJS_TOP_SRCDIR"/test/js/modules:"GJS_BUILDDIR"/.libs:", FALSE);
+
+    data_home = g_build_filename(top_builddir, "test_user_data", NULL);
+    path = g_string_new(NULL);
+    for(i = 0; i < G_N_ELEMENTS(path_directories); i++) {
+        char *directory;
+
+        if (i != 0)
+            g_string_append_c(path, ':');
+
+        directory = g_build_filename(top_builddir, path_directories[i], NULL);
+        g_string_append(path, directory);
+        g_free(directory);
+    }
+
+    g_setenv("TOP_SRCDIR", top_srcdir, FALSE);
+    g_setenv("BUILDDIR", top_builddir, FALSE);
+    g_setenv("XDG_DATA_HOME", data_home, FALSE);
+    g_setenv("GJS_PATH", path->str, FALSE);
 
     gjs_crash_after_timeout(60*7); /* give the unit tests 7 minutes to complete */
     gjs_init_sleep_on_crash();
 
-    /* need ${top_srcdir} later */
-    top_srcdir = g_getenv ("TOP_SRCDIR");
-
     setlocale(LC_ALL, "");
     g_test_init(&argc, &argv, NULL);
 
diff --git a/test/run-with-dbus b/test/run-with-dbus
index c8238f0..deae1e6 100755
--- a/test/run-with-dbus
+++ b/test/run-with-dbus
@@ -65,9 +65,8 @@ die()
 ## convenient to be able to ctrl+C without leaking the message bus process
 trap 'die "Received terminal signal"' INT TERM HUP
 
-TOP_SRCDIR="${TOP_SRCDIR:-$abs_top_srcdir}"
 if test -z "$TOP_SRCDIR" ; then
-    die "Must set TOP_SRCDIR or abs_top_srcdir"
+    die "Must set TOP_SRCDIR"
 fi
 
 if test -z "$BUILDDIR" ; then



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]