Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sclang: create config dir on startup, report errors from LanguageConfig.store #3577

Merged
merged 3 commits into from Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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