Skip to content

Commit

Permalink
Stop relying on setenv for PB path, does not work on windows
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Oct 5, 2023
1 parent 9b445f5 commit b64e85f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 43 deletions.
16 changes: 13 additions & 3 deletions utils/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
CC ?= gcc
CXX ?= g++

TARGET_MACHINE := $(shell $(CC) -dumpmachine)

ifneq (,$(findstring apple,$(TARGET_MACHINE)))
MACOS = true
else ifneq (,$(findstring mingw,$(TARGET_MACHINE)))
WINDOWS = true
else ifneq (,$(findstring wasm,$(TARGET_MACHINE)))
WASM = true
endif

CFLAGS += -Wall -Wextra -std=c99 -fPIC
CXXFLAGS += -Wall -Wextra -Wshadow -std=gnu++0x -fPIC
ifeq ($(DEBUG),1)
Expand All @@ -10,10 +20,10 @@ CXXFLAGS += -g -O0 -DDEBUG
else
CFLAGS += -O3 -DNDEBUG
CXXFLAGS += -O3 -DNDEBUG
ifneq (,$(findstring apple,$(shell $(CC) -dumpmachine)))
LDFLAGS += -Wl,-dead_strip -Wl,-dead_strip_dylibs -Wl,-x
ifeq ($(MACOS),true)
LDFLAGS += -Wl,-dead_strip,-dead_strip_dylibs,-x
else
LDFLAGS += -Wl,-O1 -Wl,--no-undefined -Wl,--strip-all
LDFLAGS += -Wl,-O1,--no-undefined,--strip-all
endif
endif

Expand Down
52 changes: 12 additions & 40 deletions utils/utils_lilv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,6 @@ static char* realpath(const char* const name, char* const resolved)

return _fullpath(retname, name, PATH_MAX);
}

static void setenv(const char* const key, const char* const value, int)
{
SetEnvironmentVariableA(key, value);
}

static void unsetenv(const char* const key)
{
SetEnvironmentVariableA(key, nullptr);
}
#else
# include <pwd.h>
# include <sys/types.h>
Expand Down Expand Up @@ -4577,8 +4567,6 @@ const PedalboardInfo_Mini* const* get_all_pedalboards(const int ptype)
if (ptype == kPedalboardInfoFactoryOnly && FACTORYINFO != nullptr)
return FACTORYINFO;

char* const oldlv2path = getenv_strdup_or_null("LV2_PATH");

const char* pedalboard_lv2_path;
switch (ptype)
{
Expand All @@ -4599,20 +4587,13 @@ const PedalboardInfo_Mini* const* get_all_pedalboards(const int ptype)
break;
}

setenv("LV2_PATH", pedalboard_lv2_path, 1);

LilvWorld* const w = lilv_world_new();
lilv_world_load_all(w);

if (oldlv2path != nullptr)
{
setenv("LV2_PATH", oldlv2path, 1);
free(oldlv2path);
}
else
{
unsetenv("LV2_PATH");
}
LilvNode* const lv2path = lilv_new_string(w, pedalboard_lv2_path);
lilv_world_set_option(w, LILV_OPTION_LV2_PATH, lv2path);
lilv_free(lv2path);

lilv_world_load_all(w);

LilvNode* const versiontypenode = lilv_new_uri(w, LILV_NS_MODPEDAL "version");
LilvNode* const rdftypenode = lilv_new_uri(w, LILV_NS_RDF "type");
Expand Down Expand Up @@ -4667,22 +4648,13 @@ const PedalboardInfo_Mini* const* get_all_pedalboards(const int ptype)

const char* const* get_broken_pedalboards(void)
{
// Custom path for pedalboards
char* const oldlv2path = getenv_strdup_or_null("LV2_PATH");
setenv("LV2_PATH", _get_lv2_pedalboards_path(), 1);

LilvWorld* const w = lilv_world_new();
lilv_world_load_all(w);

if (oldlv2path != nullptr)
{
setenv("LV2_PATH", oldlv2path, 1);
free(oldlv2path);
}
else
{
unsetenv("LV2_PATH");
}
LilvNode* const lv2path = lilv_new_string(w, _get_lv2_pedalboards_path());
lilv_world_set_option(w, LILV_OPTION_LV2_PATH, lv2path);
lilv_free(lv2path);

lilv_world_load_all(w);

LilvNode* const ingenblocknode = lilv_new_uri(w, LILV_NS_INGEN "block");
LilvNode* const lv2protonode = lilv_new_uri(w, LILV_NS_LV2 "prototype");
Expand Down Expand Up @@ -5802,11 +5774,11 @@ const StatePortValue* get_state_port_values(const char* const state)

LilvWorld* const w = W;

setenv("LILV_STATE_SKIP_PROPERTIES", "2", 1);
putenv("LILV_STATE_SKIP_PROPERTIES=2");

LilvState* const lstate = lilv_state_new_from_string(w, &uridMap, state);

unsetenv("LILV_STATE_SKIP_PROPERTIES");
putenv("LILV_STATE_SKIP_PROPERTIES=");

if (lstate != nullptr)
{
Expand Down

0 comments on commit b64e85f

Please sign in to comment.