Skip to content

Commit 29faaef

Browse files
authored
Merge pull request #3 from toothbrush/paul/bundle-guile-stdlib
Bundle Guile stdlib and ccache
2 parents 5533a56 + a5e462e commit 29faaef

File tree

5 files changed

+65
-29
lines changed

5 files changed

+65
-29
lines changed

Spotiqueue.xcodeproj/project.pbxproj

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 52;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -294,6 +294,7 @@
294294
buildConfigurationList = DAE1F18C26534D670013704F /* Build configuration list for PBXNativeTarget "Spotiqueue" */;
295295
buildPhases = (
296296
DAE1F17A26534D660013704F /* Sources */,
297+
DA67F756270728490002B96A /* Vendor in Guile stdlib */,
297298
DAE1F17B26534D660013704F /* Frameworks */,
298299
DAE1F17C26534D660013704F /* Resources */,
299300
DAD7D73826775A6A00A5510E /* Embed Frameworks */,
@@ -384,6 +385,28 @@
384385
};
385386
/* End PBXResourcesBuildPhase section */
386387

388+
/* Begin PBXShellScriptBuildPhase section */
389+
DA67F756270728490002B96A /* Vendor in Guile stdlib */ = {
390+
isa = PBXShellScriptBuildPhase;
391+
alwaysOutOfDate = 1;
392+
buildActionMask = 2147483647;
393+
files = (
394+
);
395+
inputFileListPaths = (
396+
);
397+
inputPaths = (
398+
);
399+
name = "Vendor in Guile stdlib";
400+
outputFileListPaths = (
401+
);
402+
outputPaths = (
403+
);
404+
runOnlyForDeploymentPostprocessing = 0;
405+
shellPath = /bin/sh;
406+
shellScript = "set -eux\n\nguile_stdlib_target=\"${CODESIGNING_FOLDER_PATH}/Contents/Resources/guile-stdlib\"\nguile_stdlib_source=\"/usr/local/Cellar/guile/3.0.7/share/guile/3.0\"\nguile_ccache_target=\"${CODESIGNING_FOLDER_PATH}/Contents/Resources/guile-ccache\"\nguile_ccache_source=\"/usr/local/Cellar/guile/3.0.7/lib/guile/3.0/ccache\"\n\n# Clean from previous invocations\nif [ -d \"$guile_ccache_target\" ] ; then\n rm -rf \"$guile_ccache_target\"\nfi\n\nmkdir -p \"$guile_stdlib_target\"\nmkdir -p \"$guile_ccache_target\"\n\ncp -rv \"$guile_stdlib_source\"/* \"$guile_stdlib_target/\"\ncp -rv \"$guile_ccache_source\"/* \"$guile_ccache_target/\"\n";
407+
};
408+
/* End PBXShellScriptBuildPhase section */
409+
387410
/* Begin PBXSourcesBuildPhase section */
388411
DAE1F17A26534D660013704F /* Sources */ = {
389412
isa = PBXSourcesBuildPhase;
@@ -562,7 +585,7 @@
562585
CODE_SIGN_IDENTITY = "Apple Development";
563586
CODE_SIGN_STYLE = Automatic;
564587
COMBINE_HIDPI_IMAGES = YES;
565-
CURRENT_PROJECT_VERSION = 999;
588+
CURRENT_PROJECT_VERSION = 1036;
566589
DEVELOPMENT_TEAM = QG72S9L5L3;
567590
ENABLE_HARDENED_RUNTIME = YES;
568591
FRAMEWORK_SEARCH_PATHS = (
@@ -602,7 +625,7 @@
602625
CODE_SIGN_IDENTITY = "Apple Development";
603626
CODE_SIGN_STYLE = Automatic;
604627
COMBINE_HIDPI_IMAGES = YES;
605-
CURRENT_PROJECT_VERSION = 999;
628+
CURRENT_PROJECT_VERSION = 1036;
606629
DEVELOPMENT_TEAM = QG72S9L5L3;
607630
ENABLE_HARDENED_RUNTIME = YES;
608631
FRAMEWORK_SEARCH_PATHS = (

Spotiqueue/AppDelegate.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
213213
} else {
214214
// Mind you, this will be nil if AppMover moves the executable away before we have had a chance to load the NIB. Which is still a file...
215215
logger.critical("Something very weird - modal.window is nil!")
216+
return
216217
}
217218
set_callback(player_update_hook(hook: position_ms: duration_ms:))
218219
NSEvent.addLocalMonitorForEvents(matching: [.keyDown /* , .systemDefined */ ], handler: self.localKeyShortcuts(event:))

Spotiqueue/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundlePackageType</key>
1818
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>2.4.1</string>
20+
<string>2.4.2</string>
2121
<key>CFBundleURLTypes</key>
2222
<array>
2323
<dict>
@@ -32,7 +32,7 @@
3232
</dict>
3333
</array>
3434
<key>CFBundleVersion</key>
35-
<string>999</string>
35+
<string>1036</string>
3636
<key>LSApplicationCategoryType</key>
3737
<string>public.app-category.music</string>
3838
<key>LSMinimumSystemVersion</key>

Spotiqueue/main.m

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,44 @@ static void register_functions (void* data)
1515
}
1616

1717
int main(int argc, const char * argv[]) {
18-
// I want my emojis to work! 😂
19-
// The million-dollar question is why the ; locale: .. hint at the top of the file is ignored.
20-
setenv("LANG", "en_US.UTF-8", 1);
21-
22-
// Hack: Assume Homebrew has installed Guile libs in the usual spot, so that it doesn't matter what version folks have installed (e.g. Catalina, Big Sur, 3.0.*). Still requires folks to `brew install guile` before Spotiqueue can work, but mitigates the pain somewhat.
23-
setenv("GUILE_LOAD_PATH", "/usr/local/share/guile/3.0", 1);
24-
25-
scm_init_guile();
26-
// For this weird guy, see https://www.gnu.org/software/emacs/manual/html_mono/emacs.html#Recognize-Coding and https://www.gnu.org/software/guile/manual/html_node/Locales.html
27-
scm_setlocale(scm_from_int(LC_ALL), scm_from_utf8_string(""));
28-
scm_c_define_module("spotiqueue internal", &register_functions, NULL);
29-
3018
@autoreleasepool {
3119
NSBundle* mainBundle;
3220
// Get the main bundle for the app.
3321
mainBundle = [NSBundle mainBundle];
22+
NSString* bundlePath = [mainBundle bundlePath];
23+
NSString* guileLibPath = [bundlePath stringByAppendingString:@"/Contents/Resources/guile-stdlib"];
24+
NSString* guileCcachePath = [bundlePath stringByAppendingString:@"/Contents/Resources/guile-ccache"];
25+
NSString* spotiqueueLibPath = [bundlePath stringByAppendingString:@"/Contents/Resources"];
26+
27+
// I want my emojis to work! 😂
28+
// The million-dollar question is why the ; locale: .. hint at the top of the file is ignored.
29+
setenv("LANG", "en_US.UTF-8", 1);
30+
setenv("GUILE_LOAD_PATH", [guileLibPath UTF8String], 1);
31+
setenv("GUILE_LOAD_COMPILED_PATH", [guileCcachePath UTF8String], 1);
32+
33+
scm_init_guile();
34+
35+
/* This deserves some explanation. We really don't want Spotiqueue to rely on users doing
36+
* `brew install guile` -- that would exclude half the world that doesn't like terminals. So,
37+
* we vendor in the Guile stdlib. However, that's not enough, because if my guile*.a file was
38+
* compiled in a different location than someone else's Guile installation path (e.g. the
39+
* Homebrew 3.0.7 vs 3.0.7_1 path issue) the built-in %load-path won't match up with theirs!
40+
* Subsequently (yes, there's more) if i don't also bundle in the ccache (*.go files) then at
41+
* startup Spotiqueue thinks its own stdlib is newer than the user's one and busily starts
42+
* compiling. No bueno. So we package up both the stdlib source & compiled files, and
43+
* manually tweak the search paths so that we're sure that only those files will be used. Not
44+
* great, but it seems to work, and best of all, folks won't need to install Guile themselves
45+
* if they don't want to.
46+
*/
47+
scm_c_eval_string([[NSString stringWithFormat:@"(set! %%load-path '(\"%@\" \"%@\"))", guileLibPath, spotiqueueLibPath] UTF8String]);
48+
scm_c_eval_string([[NSString stringWithFormat:@"(set! %%load-compiled-path '(\"%@\"))", guileCcachePath] UTF8String]);
49+
50+
// For this weird guy, see https://www.gnu.org/software/emacs/manual/html_mono/emacs.html#Recognize-Coding and https://www.gnu.org/software/guile/manual/html_node/Locales.html
51+
scm_setlocale(scm_from_int(LC_ALL), scm_from_utf8_string(""));
52+
scm_c_define_module("spotiqueue internal", &register_functions, NULL);
53+
3454
// Note that there are DRAGONS here. We use a separate "Copy Files" Xcode build phase to put Scheme files into a "spotiqueue" subfolder inside the App bundle's Resources folder. We do this so that the module names match up. However, there doesn't seem to be an obvious way to get a direct pointer to the Resources folder, so we use this hack.
35-
// Subsequently we need to add a (add-to-load-path ..) in init.scm, but i'll continue the story there.
36-
scm_c_primitive_load([[mainBundle pathForResource:@"spotiqueue/init" ofType:@"scm"] UTF8String]);
55+
scm_c_primitive_load_path("spotiqueue/init");
3756
}
3857

3958
return NSApplicationMain(argc, argv);

guile/spotiqueue/init.scm

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,11 @@
55
;;; This file is read by Spotiqueue as soon as it starts up. It exposes some helpers and hooks for
66
;;; users.
77

8-
;; Dragons, continued: we grab our file location, but go up one level before adding to load-path.
9-
;; The reason for this is that we want to call this module (spotiqueue init), so it has to live in a
10-
;; spotiqueue folder with its siblings.
11-
128
(format #t "%load-path = ~s\n" %load-path)
139

14-
(add-to-load-path (canonicalize-path (string-append (dirname (current-filename)) file-name-separator-string "..")))
15-
16-
;; TODO find out a way we can make this module sensibly loadable from `guile' in the shell without
17-
;; having Spotiqueue running... Is that even useful?
18-
19-
;; If i want to use this module naming scheme i should have the source files in a folder called `spotiqueue'. Grr, there are already so many of those i'll just nest them in guile/spotiqueue i guess.
10+
;; If i want to use this module naming scheme i should have the source files in a folder called
11+
;; `spotiqueue'. Grr, there are already so many of those i'll just nest the Scheme files in
12+
;; guile/spotiqueue i guess. The Copy Files phase in Xcode can sort that out.
2013

2114
(define-module (spotiqueue init)
2215
#:use-module (ice-9 format)

0 commit comments

Comments
 (0)