Skip to content

Commit

Permalink
Merge pull request #3577 from brianlheim/issue/2919
Browse files Browse the repository at this point in the history
sclang: create config dir on startup, report errors from LanguageConfig.store
  • Loading branch information
telephon committed Mar 15, 2018
2 parents 6a97779 + b855bb6 commit 8a184fa
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
3 changes: 2 additions & 1 deletion HelpSource/Classes/LanguageConfig.schelp
Expand Up @@ -19,7 +19,8 @@ definitionList::
CLASSMETHODS::

METHOD:: store
Store the current configuration to file.
Store the current configuration to file. Throws an error if the config file cannot be opened or if
writing fails.

argument:: file
Path to the configuration file to store. If the value is code::nil:: it defaults to code::Platform.userConfigDir +/+ "sclang_conf.yaml"::
Expand Down
2 changes: 1 addition & 1 deletion SCClassLibrary/Common/Core/LanguageConfig.sc
@@ -1,7 +1,7 @@
LanguageConfig {
*store {|file|
_LanguageConfig_writeConfigFile
^this.primitiveFailed
^MethodError("Could not write to file %".format(file.asCompileString), this).throw
}

*currentPath {
Expand Down
11 changes: 7 additions & 4 deletions lang/LangPrimSource/PyrPrimitive.cpp
Expand Up @@ -3594,23 +3594,26 @@ static int prLanguageConfig_getCurrentConfigPath(struct VMGlobals * g, int numAr
static int prLanguageConfig_writeConfigFile(struct VMGlobals * g, int numArgsPushed)
{
PyrSlot *fileString = g->sp;
bfs::path config_path;

if (NotNil(fileString)) {
char path[MAXPATHLEN];
bool error = slotStrVal(fileString, path, MAXPATHLEN);
if (error)
return errWrongType;

const bfs::path& config_path = SC_Codecvt::utf8_str_to_path(path);
config_path = SC_Codecvt::utf8_str_to_path(path);
gLanguageConfig->writeLibraryConfigYAML(config_path);
} else {
const bfs::path& config_path =
config_path =
SC_Filesystem::instance().getDirectory(SC_Filesystem::DirName::UserConfig)
/ "sclang_conf.yaml";
gLanguageConfig->writeLibraryConfigYAML(config_path);
}

return errNone;
if (!gLanguageConfig->writeLibraryConfigYAML(config_path))
return errFailed;
else
return errNone;
}

static int prLanguageConfig_getPostInlineWarnings(struct VMGlobals * g, int numArgsPushed)
Expand Down
5 changes: 4 additions & 1 deletion lang/LangSource/SC_LanguageConfig.cpp
Expand Up @@ -164,6 +164,9 @@ bool SC_LanguageConfig::readLibraryConfigYAML(const Path& fileName, bool standal

bool SC_LanguageConfig::writeLibraryConfigYAML(const Path& fileName)
{
if (!bfs::exists(fileName.parent_path()))
return false;

using namespace YAML;
Emitter out;
out.SetIndent(4);
Expand Down Expand Up @@ -192,7 +195,7 @@ bool SC_LanguageConfig::writeLibraryConfigYAML(const Path& fileName)

bfs::ofstream fout(fileName);
fout << out.c_str();
return true;
return fout.good();
}

bool SC_LanguageConfig::defaultLibraryConfig(bool standalone)
Expand Down
7 changes: 7 additions & 0 deletions lang/LangSource/SC_TerminalClient.cpp
Expand Up @@ -61,6 +61,8 @@
#include "SC_LanguageConfig.hpp"
#include "SC_Version.hpp"

#include <boost/filesystem/operations.hpp>

static FILE* gPostDest = stdout;

#ifdef _WIN32
Expand Down Expand Up @@ -261,6 +263,11 @@ int SC_TerminalClient::run(int argc, char** argv)
// initialize runtime
initRuntime(opt);

// Create config directory so that it can be used by Quarks, etc. See #2919.
if (!opt.mStandalone && !opt.mLibraryConfigFile)
boost::filesystem::create_directories(
SC_Filesystem::instance().getDirectory(SC_Filesystem::DirName::UserConfig));

// startup library
compileLibrary(opt.mStandalone);

Expand Down

0 comments on commit 8a184fa

Please sign in to comment.