Skip to content

Commit

Permalink
Remove last remnants of old macOS standalone code
Browse files Browse the repository at this point in the history
- Delete SC_StandAloneInfo_Darwin TU and remove from CMakeLists
- remove isStandalone() from SC_FS interface
- update references appropriately, leaving TODOs where this may
have broken logic
  • Loading branch information
mossheim committed Jul 24, 2017
1 parent a9f0496 commit 3f45b6d
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 150 deletions.
5 changes: 1 addition & 4 deletions common/SC_Filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,14 @@ class SC_Filesystem {

//-------------------------------- GENERAL UTILITIES -----------------------------------//

/// Returns true if, on macOS, SuperCollider is operating as a standalone application.
static bool isStandalone();

/** \brief Resolves an alias on macOS.
* \param p a path to resolve
* \param isAlias set to true if p is an alias
* \return An empty path if resolution failed; otherwise, the resolved path.
*
* If the path was not an alias, a copy is returned. */
// @TODO: Could possibly be split into `isAlias` and `resolveAlias` to avoid
// unnecessary copying
// unnecessary copying @TODO do this
static Path resolveIfAlias(const Path& p, bool& isAlias);

//--------------------------------- GLOB UTILITIES -------------------------------------//
Expand Down
2 changes: 0 additions & 2 deletions common/SC_Filesystem_iphone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ const Path ROOT_PATH = Path("/");

//============ PATH UTILITIES =============//

bool SC_Filesystem::isStandalone() { return false; }

Path SC_Filesystem::resolveIfAlias(const Path& p, bool& isAlias) { isAlias = false; return p; }

//============ GLOB UTILITIES =============//
Expand Down
86 changes: 77 additions & 9 deletions common/SC_Filesystem_macos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,25 @@
#if defined(__APPLE__) && !defined(SC_IPHONE)

#include "SC_Filesystem.hpp"
#include "SC_StandAloneInfo_Darwin.h"

#ifdef DEBUG_SCFS
#include <iostream>
using std::cout;
using std::endl;
#endif

// boost
#include <boost/filesystem/path.hpp> // path, parent_path()
#include <boost/filesystem/operations.hpp> // canonical, current_path()

// system includes
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSFileManager.h>
#include <CoreFoundation/CFBundle.h>
#include <CoreFoundation/CFString.h>

#include <glob.h> // ::glob, glob_t
#include <mach-o/dyld.h> // _NSGetExecutablePath

using Path = SC_Filesystem::Path;
using DirName = SC_Filesystem::DirName;
Expand All @@ -60,11 +64,6 @@ static const char* getBundleName();

//============ PATH UTILITIES =============//

bool SC_Filesystem::isStandalone()
{
return SC_StandAloneInfo::IsStandAlone();
}

Path SC_Filesystem::resolveIfAlias(const Path& p, bool& isAlias)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Expand Down Expand Up @@ -183,9 +182,78 @@ Path SC_Filesystem::defaultUserConfigDirectory()

Path SC_Filesystem::defaultResourceDirectory()
{
char pathBuf[PATH_MAX];
SC_StandAloneInfo::GetResourceDir(pathBuf, PATH_MAX);
return Path(pathBuf);
Path ret;
CFStringEncoding encoding = kCFStringEncodingUTF8;

#ifdef DEBUG_SCFS
cout << __func__ << ": searching for SCClassLibrary first." << endl;
#endif
CFURLRef enablerURL = CFBundleCopyResourceURL (CFBundleGetMainBundle(),
CFSTR("SCClassLibrary"),
NULL,
NULL
);
if( !enablerURL ) {
#ifdef DEBUG_SCFS
cout << __func__ << ": previous search failed, searching for sclang.app." << endl;
#endif
enablerURL = CFBundleCopyResourceURL (CFBundleGetMainBundle(),
CFSTR("sclang.app"),
NULL,
NULL
);
}
if ( enablerURL ) {
#ifdef DEBUG_SCFS
cout << __func__ << ": search succeeded, making relative path." << endl;
#endif
// If sclang or SuperCollider binary is run within the .app bundle,
// this is how we find the Resources path.
char relDir[PATH_MAX];
CFStringRef rawUrlPath = CFURLCopyFileSystemPath(enablerURL, kCFURLPOSIXPathStyle);
CFStringRef rawPath = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/.."), rawUrlPath);
CFStringGetCString(rawPath, relDir, PATH_MAX, encoding);
CFRelease( rawUrlPath );
CFRelease( rawPath );
CFRelease( enablerURL );
ret = Path(relDir);
#ifdef DEBUG_SCFS
cout << __func__ << ": relative path is " << ret << endl;
#endif
} else {
// when sclang is run from a symlink, the resource URL above will not be found,
// so we need to find the path of the executable.
#ifdef DEBUG_SCFS
cout << __func__ << ": search failed, looking for executable path." << endl;
#endif
uint32_t bufsize = PATH_MAX;
char relDir[PATH_MAX];
if(_NSGetExecutablePath(relDir, &bufsize)==0) {
#ifdef DEBUG_SCFS
cout << __func__ << ": search succeeded, resolving symlink: " << relDir << endl;
#endif
ret = boost::filesystem::canonical(relDir); // resolve symlink
ret = ret.parent_path();
#ifdef DEBUG_SCFS
cout << __func__ << ": resolved parent path: " << ret << endl;
#endif
} else {
#ifdef DEBUG_SCFS
cout << __func__ << ": search failed, getting cwd" << endl;
#endif
// in case it failed, fall back to current directory
ret = boost::filesystem::current_path();

}
}
#ifdef DEBUG_SCFS
cout << __func__ << ": final path before resolving is: " << ret << endl;
#endif
ret = boost::filesystem::canonical(ret); // resolve lingering symlink
#ifdef DEBUG_SCFS
cout << __func__ << ": final path after resolving is: " << ret << endl;
#endif
return ret;
}

//============= STATIC FUNCTIONS =============//
Expand Down
2 changes: 0 additions & 2 deletions common/SC_Filesystem_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ const Path ROOT_PATH = Path("/");

//============ PATH UTILITIES =============//

bool SC_Filesystem::isStandalone() { return false; }

Path SC_Filesystem::resolveIfAlias(const Path& p, bool& isAlias) { isAlias = false; return p; }

//============ GLOB UTILITIES =============//
Expand Down
2 changes: 0 additions & 2 deletions common/SC_Filesystem_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ using DirMap = SC_Filesystem::DirMap;

//============ PATH UTILITIES =============//

bool SC_Filesystem::isStandalone() { return false; }

Path SC_Filesystem::resolveIfAlias(const Path& p, bool& isAlias) { isAlias = true; return p; }

//============ GLOB UTILITIES =============//
Expand Down
84 changes: 0 additions & 84 deletions common/SC_StandAloneInfo_Darwin.cpp

This file was deleted.

20 changes: 0 additions & 20 deletions common/SC_StandAloneInfo_Darwin.h

This file was deleted.

1 change: 0 additions & 1 deletion editors/sc-ide/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ endif()

if(APPLE)
list(APPEND ide_src
${CMAKE_SOURCE_DIR}/common/SC_StandAloneInfo_Darwin.cpp
${CMAKE_SOURCE_DIR}/QtCollider/hacks/hacks_mac.mm
)
elseif(WIN32)
Expand Down
1 change: 0 additions & 1 deletion lang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ set(sclang_sources
${CMAKE_SOURCE_DIR}/common/Samp.cpp
${CMAKE_SOURCE_DIR}/common/SC_AllocPool.cpp
${CMAKE_SOURCE_DIR}/common/SC_Reply.cpp
${CMAKE_SOURCE_DIR}/common/SC_StandAloneInfo_Darwin.cpp
${CMAKE_SOURCE_DIR}/common/SC_StringBuffer.cpp
${CMAKE_SOURCE_DIR}/common/SC_StringParser.cpp
${CMAKE_SOURCE_DIR}/common/SC_TextUtils.cpp
Expand Down
9 changes: 3 additions & 6 deletions lang/LangPrimSource/PyrFilePrim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,11 @@ Primitives for File i/o.
#include <boost/filesystem.hpp>

#if defined(__APPLE__) || defined(SC_IPHONE)
#ifndef _SC_StandAloneInfo_
# include "SC_StandAloneInfo_Darwin.h"
#endif
# include <CoreFoundation/CFString.h>
# include <CoreFoundation/CFBundle.h>
#ifndef SC_IPHONE
# include <CoreServices/CoreServices.h>
#endif
# ifndef SC_IPHONE
# include <CoreServices/CoreServices.h>
# endif
#endif

#define DELIMITOR ':'
Expand Down
11 changes: 3 additions & 8 deletions lang/LangSource/PyrLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2001,14 +2001,9 @@ bool passOne()
{
initPassOne();

if (SC_Filesystem::isStandalone()) {
/// FIXME: this should be moved to the LibraryConfig file
if (!passOne_ProcessDir(gCompileDir, 0))
return false;
} else {
if (!gLanguageConfig->forEachIncludedDirectory(passOne_ProcessDir)) {
return false;
}
if (!gLanguageConfig->forEachIncludedDirectory(passOne_ProcessDir)) {
// @TODO: should also finiPassOne here too, right? - bh
return false;
}

finiPassOne();
Expand Down
2 changes: 0 additions & 2 deletions lang/LangSource/SC_LanguageConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ SC_LanguageConfig::SC_LanguageConfig(bool optStandalone)
if( !optStandalone ) {
const Path& classLibraryDir = SC_Filesystem::instance().getDirectory(DirName::Resource) / CLASS_LIB_DIR_NAME;
addPath(mDefaultClassLibraryDirectories, classLibraryDir);
}

if ( !( SC_Filesystem::isStandalone() || optStandalone ) ) {
const Path& systemExtensionDir = SC_Filesystem::instance().getDirectory(DirName::SystemExtension);
addPath(mDefaultClassLibraryDirectories, systemExtensionDir);

Expand Down
1 change: 0 additions & 1 deletion server/scsynth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ set(scsynth_sources
${CMAKE_SOURCE_DIR}/common/SC_AllocPool.cpp
${CMAKE_SOURCE_DIR}/common/SC_Errors.cpp
${CMAKE_SOURCE_DIR}/common/SC_Reply.cpp
${CMAKE_SOURCE_DIR}/common/SC_StandAloneInfo_Darwin.cpp
${CMAKE_SOURCE_DIR}/common/SC_StringBuffer.cpp
${CMAKE_SOURCE_DIR}/common/SC_StringParser.cpp
${CMAKE_SOURCE_DIR}/common/Samp.cpp
Expand Down
3 changes: 2 additions & 1 deletion server/scsynth/SC_Lib_Cintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ void initialize_library(const char *uGensPluginPath)
}

// get extension directories
if (!SC_Filesystem::isStandalone() && loadUGensExtDirs) {
// @TODO: standalone logic goes here
if (loadUGensExtDirs) {
// load system extension plugins
const Path sysExtDir = SC_Filesystem::instance().getDirectory(DirName::SystemExtension);
PlugIn_LoadDir(sysExtDir, false);
Expand Down
11 changes: 5 additions & 6 deletions server/scsynth/SC_World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,11 @@ void World_LoadGraphDefs(World* world)
}
}else{
SC_Filesystem::Path path;
if(SC_Filesystem::isStandalone())
path = SC_Filesystem::instance().getDirectory(DirName::Resource);
else
path = SC_Filesystem::instance().getDirectory(DirName::UserAppSupport);

path /= "synthdefs";
// TODO: standalone logic goes here
// if(SC_Filesystem::isStandalone())
// path = SC_Filesystem::instance().getDirectory(DirName::Resource);
// else
path = SC_Filesystem::instance().getDirectory(DirName::UserAppSupport) / "synthdefs";
if(world->mVerbosity > 0)
scprintf("Loading synthdefs from default path: %s\n", path.c_str());
list = GraphDef_LoadDir(world, path.string().c_str(), list);
Expand Down
1 change: 0 additions & 1 deletion server/supernova/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ set(libsupernova_src
${CMAKE_SOURCE_DIR}/common/Samp.cpp
${CMAKE_SOURCE_DIR}/common/SC_fftlib.cpp
${CMAKE_SOURCE_DIR}/common/SC_StringParser.cpp
${CMAKE_SOURCE_DIR}/common/SC_StandAloneInfo_Darwin.cpp
server/buffer_manager.cpp
server/memory_pool.cpp
server/node_graph.cpp
Expand Down

0 comments on commit 3f45b6d

Please sign in to comment.