Skip to content

Instantly share code, notes, and snippets.

@dyfer
Last active September 11, 2020 23:02
Show Gist options
  • Save dyfer/0a98f3e6bb194e2e29a8e7c9355046ec to your computer and use it in GitHub Desktop.
Save dyfer/0a98f3e6bb194e2e29a8e7c9355046ec to your computer and use it in GitHub Desktop.
SuperCollider: switch configuration to test class library changes directly from the source repository
// a script for testing class library changes living outside of SuperCollider installation (e.g. in the source repository)
// please note, if using non-default language config file, this only works on SC 3.11 and up, due to a bug in previous versions
// this is not 100% foolproof, but should work in most cases; tested on macOS
//posting
LanguageConfig.includePaths.do(_.postln);
LanguageConfig.excludePaths.do(_.postln);
Platform.resourceDir +/+ "SCClassLibrary";
//check state
(
var defaultClassLibPath = Platform.resourceDir +/+ "SCClassLibrary";
if(LanguageConfig.excludePaths.includesEqual(defaultClassLibPath), {
"SuperCollider's default class library path is EXCLUDED".postln;
}, {
"SuperCollider is using the default class library".postln;
});
"";
)
//test with classlib in src
(
// ------------------------------------------------------------
var srcClassLibPath = "/path/to/src/supercollider/SCClassLibrary"; //set me
// ------------------------------------------------------------
var defaultClassLibPath = Platform.resourceDir +/+ "SCClassLibrary";
var excludePathsIncludes, newPathExists;
srcClassLibPath = srcClassLibPath.withoutTrailingSlash;
if(LanguageConfig.excludePaths.includesEqual(defaultClassLibPath), {
excludePathsIncludes = true;
("Current exclude paths already includes this SuperCollider's default class library path").warn;
"Check exclude path list at \n\tLanguageConfig.excludePaths.do(_.postln);\nand compare against \n\tPlatform.resourceDir +/+ \"SCClassLibrary\";".postln;
}, {
excludePathsIncludes = false;
});
if(File.exists(srcClassLibPath), {
newPathExists = true;
}, {
newPathExists = false;
format("Specified class library does not seem to exist at %", srcClassLibPath).warn;
});
if(newPathExists && excludePathsIncludes.not, {
postf("adding exclude path %\n", defaultClassLibPath);
LanguageConfig.addExcludePath(defaultClassLibPath);
postf("adding include path %\n", srcClassLibPath);
LanguageConfig.addIncludePath(srcClassLibPath);
LanguageConfig.store;
"recompiling...".postln;
thisProcess.platform.recompile;
}, {
"Include/exclude paths not changed".warn;
});
"";
)
//revert
(
// ------------------------------------------------------------
var srcClassLibPath = "/path/to/src/supercollider/SCClassLibrary"; //set me
// ------------------------------------------------------------
var defaultClassLibPath = Platform.resourceDir +/+ "SCClassLibrary";
var excludePathsIncludes, includePathIncludes;
srcClassLibPath = srcClassLibPath.withoutTrailingSlash;
if(LanguageConfig.excludePaths.includesEqual(defaultClassLibPath), {
excludePathsIncludes = true;
}, {
excludePathsIncludes = false;
("Current exclude paths list doesn't seem to include this SuperCollider's default class library path").warn;
"Check exclude path list at \n\tLanguageConfig.excludePaths.do(_.postln);\nand compare against \n\tPlatform.resourceDir +/+ \"SCClassLibrary\";".postln;
});
if(LanguageConfig.includePaths.includesEqual(srcClassLibPath), {
includePathIncludes = true;
}, {
includePathIncludes = false;
("Current include paths list doesn't seem to include the specified external class library path").warn;
"Check include path list at \n\tLanguageConfig.includePaths.do(_.postln);\nand compare against specified path".postln;
});
if(excludePathsIncludes && includePathIncludes, {
postf("removing exclude path %\n", defaultClassLibPath);
LanguageConfig.removeExcludePath(defaultClassLibPath);
postf("removing include path %\n", srcClassLibPath);
LanguageConfig.removeIncludePath(srcClassLibPath);
"recompiling...".postln;
LanguageConfig.store;
thisProcess.platform.recompile;
}, {
"Include/exclude paths not changed".warn;
});
"";
)
//add unit tests
(
// ------------------------------------------------------------
var testsuitePath = "/path/to/src/supercollider/testsuite/"; //set me
// ------------------------------------------------------------
testsuitePath = testsuitePath.withoutTrailingSlash;
if(File.exists(testsuitePath), {
postf("adding include path %\n", testsuitePath);
LanguageConfig.addIncludePath(testsuitePath);
LanguageConfig.store;
"recompiling...".postln;
thisProcess.platform.recompile;
}, {
format("Specified testsuite path doesn't seem to exist: %", testsuitePath).warn;
});
"";
)
//remove unit tests
(
// ------------------------------------------------------------
var testsuitePath = "/path/to/src/supercollider/testsuite/"; //set me
// ------------------------------------------------------------
testsuitePath = testsuitePath.withoutTrailingSlash;
if(LanguageConfig.includePaths.includesEqual(testsuitePath), {
postf("removing exclude path %\n", testsuitePath);
LanguageConfig.removeIncludePath(testsuitePath);
LanguageConfig.store;
"recompiling...".postln;
thisProcess.platform.recompile;
}, {
("Current include paths list doesn't seem to include the specified testsuite path").warn;
"Check include path list at \n\tLanguageConfig.includePaths.do(_.postln);\nand compare against specified path".postln;
});
"";
)
@mtmccrea
Copy link

mtmccrea commented Jul 9, 2019

Consider replacing:

LanguageConfig.addExcludePath(Platform.classLibraryDir);

with

LanguageConfig.addExcludePath(Platform.resourceDir +/+ "SCClassLibrary");

@dyfer
Copy link
Author

dyfer commented Jul 9, 2019

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment