Skip to content

Commit

Permalink
[runtime] Add a new mono-config-dirs.c file which is the only one dep…
Browse files Browse the repository at this point in the history
…ending on the MONO_CFG_DIR etc. defines defined in metadata/Makefile.am.
  • Loading branch information
vargaz committed Mar 19, 2015
1 parent 954ddf4 commit b1f0605
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 16 deletions.
7 changes: 3 additions & 4 deletions mono/metadata/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,10 @@ AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/mono $(LIBGC_CPPFLAGS) $(GLIB_CFLA
#
# Make sure any prefix changes are updated in the binaries too.
#
# assembly.c uses MONO_ASSEMBLIES
# mono-config.c uses MONO_CFG_DIR
#
# This won't result in many more false positives than AC_DEFINEing them
# in configure.ac.
#
assembly.lo mono-config.lo: Makefile
mono-config-dirs.lo: Makefile

CLEANFILES = mono-bundle.stamp

Expand Down Expand Up @@ -143,6 +140,8 @@ common_sources = \
mono-basic-block.c \
mono-basic-block.h \
mono-config.c \
mono-config-dirs.h \
mono-config-dirs.c \
mono-cq.c \
mono-cq.h \
mono-debug.h \
Expand Down
16 changes: 8 additions & 8 deletions mono/metadata/assembly.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <mono/io-layer/io-layer.h>
#include <mono/utils/mono-uri.h>
#include <mono/metadata/mono-config.h>
#include <mono/metadata/mono-config-dirs.h>
#include <mono/utils/mono-digest.h>
#include <mono/utils/mono-logger-internal.h>
#include <mono/utils/mono-path.h>
Expand Down Expand Up @@ -562,14 +563,10 @@ mono_assembly_getrootdir (void)
void
mono_set_dirs (const char *assembly_dir, const char *config_dir)
{
#if defined (MONO_ASSEMBLIES)
if (assembly_dir == NULL)
assembly_dir = MONO_ASSEMBLIES;
#endif
#if defined (MONO_CFG_DIR)
assembly_dir = mono_config_get_assemblies_dir ();
if (config_dir == NULL)
config_dir = MONO_CFG_DIR;
#endif
config_dir = mono_config_get_cfg_dir ();
mono_assembly_setrootdir (assembly_dir);
mono_set_config_dir (config_dir);
}
Expand Down Expand Up @@ -601,7 +598,7 @@ compute_base (char *path)
static void
fallback (void)
{
mono_set_dirs (MONO_ASSEMBLIES, MONO_CFG_DIR);
mono_set_dirs (mono_config_get_assemblies_dir (), mono_config_get_cfg_dir ());
}

static G_GNUC_UNUSED void
Expand All @@ -610,11 +607,14 @@ set_dirs (char *exe)
char *base;
char *config, *lib, *mono;
struct stat buf;
const char *bindir;

/*
* Only /usr prefix is treated specially
*/
if (strncmp (exe, MONO_BINDIR, strlen (MONO_BINDIR)) == 0 || (base = compute_base (exe)) == NULL){
bindir = mono_config_get_bin_dir ();
g_assert (bindir);
if (strncmp (exe, bindir, strlen (bindir)) == 0 || (base = compute_base (exe)) == NULL){
fallback ();
return;
}
Expand Down
42 changes: 42 additions & 0 deletions mono/metadata/mono-config-dirs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* mono-config-dirs.c:
*
* Copyright 2015 Xamarin Inc (http://www.xamarin.com)
*/

/*
* This file contains functions to return the values of various directories defined in Makefile.am.
*/

#include <mono/metadata/mono-config-dirs.h>

const char*
mono_config_get_assemblies_dir (void)
{
#ifdef MONO_ASSEMBLIES
return MONO_ASSEMBLIES;
#else
return NULL;
#endif
}

const char*
mono_config_get_cfg_dir (void)
{
#ifdef MONO_CFG_DIR
return MONO_CFG_DIR;
#else
return NULL;
#endif
}

const char*
mono_config_get_bin_dir (void)
{
#ifdef MONO_BINDIR
return MONO_BINDIR;
#else
return NULL;
#endif
}

16 changes: 16 additions & 0 deletions mono/metadata/mono-config-dirs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef __MONO_CONFIG_INTERNAL_H__
#define __MONO_CONFIG_INTERNAL_H__

#include <config.h>
#include <glib.h>

const char*
mono_config_get_assemblies_dir (void);

const char*
mono_config_get_cfg_dir (void);

const char*
mono_config_get_bin_dir (void);

#endif
6 changes: 3 additions & 3 deletions mono/metadata/profiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "mono/metadata/class-internals.h"
#include "mono/metadata/domain-internals.h"
#include "mono/metadata/gc-internal.h"
#include "mono/metadata/mono-config-dirs.h"
#include "mono/io-layer/io-layer.h"
#include "mono/utils/mono-dl.h"
#include <string.h>
Expand Down Expand Up @@ -1197,9 +1198,8 @@ mono_profiler_load (const char *desc)
}
if (!load_embedded_profiler (desc, mname)) {
libname = g_strdup_printf ("mono-profiler-%s", mname);
#if defined (MONO_ASSEMBLIES)
res = load_profiler_from_directory (mono_assembly_getrootdir (), libname, desc);
#endif
if (mono_config_get_assemblies_dir ())
res = load_profiler_from_directory (mono_assembly_getrootdir (), libname, desc);
if (!res)
res = load_profiler_from_directory (NULL, libname, desc);
if (!res)
Expand Down
4 changes: 3 additions & 1 deletion msvc/libmonoruntime.vcxproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug_SGen|Win32">
Expand Down Expand Up @@ -69,6 +69,7 @@
<ClCompile Include="..\mono\metadata\monitor.c" />
<ClCompile Include="..\mono\metadata\mono-basic-block.c" />
<ClCompile Include="..\mono\metadata\mono-config.c" />
<ClCompile Include="..\mono\metadata\mono-config-dirs.c" />
<ClCompile Include="..\mono\metadata\mono-cq.c" />
<ClCompile Include="..\mono\metadata\mono-debug.c" />
<ClCompile Include="..\mono\metadata\mono-endian.c" />
Expand Down Expand Up @@ -163,6 +164,7 @@
<ClInclude Include="..\mono\metadata\monitor.h" />
<ClInclude Include="..\mono\metadata\mono-basic-block.h" />
<ClInclude Include="..\mono\metadata\mono-config.h" />
<ClInclude Include="..\mono\metadata\mono-config-dirs.h" />
<ClInclude Include="..\mono\metadata\mono-cq.h" />
<ClInclude Include="..\mono\metadata\mono-debug-debugger.h" />
<ClInclude Include="..\mono\metadata\mono-debug.h" />
Expand Down

0 comments on commit b1f0605

Please sign in to comment.