Commit a801e405 authored by Morten Welinder's avatar Morten Welinder

Runtime: improve running-in-tree detection.

This should handle running introspection in-tree too. g_get_prgname is not reliable for that, so pass in a separate environment variable.
parent 6a2eccf3
from ..overrides import override
from ..module import get_introspection_module
import os.path
Gnm = get_introspection_module('Gnm')
......@@ -7,6 +8,33 @@ __all__ = []
# ----------------------------------------------------------------------------
def atomize_path(p):
res=[]
while 1:
h,t = os.path.split(p)
if t != "":
res.append(t)
if h == "":
break
if h == p:
res.append(h)
break
p = h
res.reverse()
return res
l=atomize_path(os.path.dirname(__file__))
Gnm.in_tree = (len(l) > 3 and l[-3] == "introspection")
__all__.append('in_tree')
if Gnm.in_tree:
# Somehow path gets dropped form g_get_prgname, so make up for that
from gi.repository import GLib
import sys
GLib.set_prgname(sys.argv[0])
# ----------------------------------------------------------------------------
class Range(Gnm.Range):
def __new__(cls,start_col=0,start_row=0,end_col=None,end_row=None):
if end_col is None: end_col = start_col
......
......@@ -43,33 +43,41 @@ static char *gnumeric_usr_dir_unversioned;
static char *gnumeric_extern_plugin_dir;
static GSList *gutils_xml_in_docs;
static gboolean
static char *
running_in_tree (void)
{
const char *argv0 = g_get_prgname ();
if (!argv0)
return FALSE;
/* Sometimes we see, e.g., "lt-gnumeric" as basename. */
{
char *base = g_path_get_basename (argv0);
gboolean has_lt_prefix = (strncmp (base, "lt-", 3) == 0);
g_free (base);
if (has_lt_prefix)
return TRUE;
}
return NULL;
/* Look for ".libs" as final path element. */
{
const char *dotlibs = strstr (argv0, ".libs/");
if (dotlibs &&
(dotlibs == argv0 || G_IS_DIR_SEPARATOR (dotlibs[-1])) &&
strchr (dotlibs + 6, G_DIR_SEPARATOR) == NULL)
return TRUE;
strchr (dotlibs + 6, G_DIR_SEPARATOR) == NULL) {
size_t l = dotlibs - argv0;
char *res = g_strndup (argv0, l);
while (l > 0 && G_IS_DIR_SEPARATOR (res[l - 1]))
res[--l] = 0;
while (l > 0 && !G_IS_DIR_SEPARATOR (res[l - 1]))
res[--l] = 0;
while (l > 0 && G_IS_DIR_SEPARATOR (res[l - 1]))
res[--l] = 0;
return res;
}
}
return FALSE;
{
const char *builddir = g_getenv ("GNM_TEST_TOP_BUILDDIR");
if (builddir)
return g_strdup (builddir);
}
return NULL;
}
static gboolean gutils_inited = FALSE;
......@@ -78,6 +86,7 @@ void
gutils_init (void)
{
char const *home_dir;
char *top_builddir;
// This function will end up being called twice in normal operation:
// once from gnm_pre_parse_init and once from gnm_init. Introspection
......@@ -99,19 +108,14 @@ gutils_init (void)
NULL);
g_free (dir);
#else
if (running_in_tree ()) {
const char *argv0 = g_get_prgname ();
char *dotlibs = g_path_get_dirname (argv0);
char *top = g_build_filename (dotlibs, "..", "../", NULL);
char *plugins = g_build_filename (top, PLUGIN_SUBDIR, NULL);
if (g_file_test (plugins, G_FILE_TEST_IS_DIR))
gnumeric_lib_dir =
go_filename_simplify (top, GO_DOTDOT_SYNTACTIC,
FALSE);
g_free (top);
g_free (plugins);
g_free (dotlibs);
if (0) g_printerr ("Running in-tree\n");
top_builddir = running_in_tree ();
if (top_builddir) {
gnumeric_lib_dir =
go_filename_simplify (top_builddir, GO_DOTDOT_SYNTACTIC,
FALSE);
if (gnm_debug_flag ("in-tree"))
g_printerr ("Running in-tree [%s]\n", top_builddir);
g_free (top_builddir);
}
if (!gnumeric_lib_dir)
......
......@@ -14,6 +14,7 @@ $| = 1;
test_ssindex sstest test_command message subtest
test_tool
setup_python_environment
make_absolute
$ssconvert $sstest $ssdiff $ssgrep $gnumeric
$topsrc $top_builddir
$subtests $samples corpus $PERL $PYTHON);
......@@ -897,6 +898,18 @@ sub has_linear_solver {
# -----------------------------------------------------------------------------
sub make_absolute {
my ($fn) = @_;
return $fn if $fn =~ m{^/};
$fn =~ s{^\./+([^/])}{$1};
my $pwd = $ENV{'PWD'};
$pwd .= '/' unless $pwd =~ m{/$};
return "$pwd$fn";
}
# -----------------------------------------------------------------------------
sub setup_python_environment {
$PYTHON = `grep '^#define PYTHON_INTERPRETER ' $top_builddir/gnumeric-config.h 2>&1`;
chomp $PYTHON;
......@@ -917,6 +930,9 @@ sub setup_python_environment {
# Don't litter
$ENV{'PYTHONDONTWRITEBYTECODE'} = 1;
$0 = &make_absolute ($0);
$ENV{'GNM_TEST_TOP_BUILDDIR'} = $top_builddir;
}
# -----------------------------------------------------------------------------
......
......@@ -7,25 +7,7 @@ from gi.repository import Gnm
from gi.repository import GOffice as Go
Gnm.init()
import os.path
def atomize_path(p):
res=[]
while 1:
h,t = os.path.split(p)
if t != "":
res.append(t)
if h == "":
break
if h == p:
res.append(h)
break
p = h
res.reverse()
return res
l=atomize_path(os.path.dirname(gi.overrides.Gnm.__file__))
if len(l) > 3 and l[-3] == "introspection":
if Gnm.in_tree:
print("Using in-tree gi.overrides.Gnm")
else:
print("Using installed gi.overrides.Gnm at {}"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment