Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
132 lines (110 loc) · 6.86 KB
/
Copy pathMakefile
File metadata and controls
132 lines (110 loc) · 6.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
PREFIX ?= /usr/local
# core: what a hotkey reaches on every command — logic, system, player, status, cli. A feature is
# everything core never calls (docs/development.md#rules); the boundary is checked, not kept by discipline, in
# scripts/globals.js's --check, which reads CORE and FEATURES back with `make print-<VAR>`.
CORE_PURE := src/core/logic/time.js src/core/logic/seek.js src/core/logic/hold.js src/core/logic/stream.js src/core/logic/item.js src/core/logic/text.js src/core/logic/paint.js src/core/logic/config.js
FEATURE_PURE := src/features/config/settings-authoring.js src/features/dialects/words.js src/features/watch/change.js
PURE := $(CORE_PURE) $(FEATURE_PURE)
CORE := $(CORE_PURE) src/core/system/mediaremote.js src/core/system/paths.js src/core/system/artwork.js src/core/system/files.js src/core/system/terminal.js src/core/player.js src/core/player-commands.js src/core/player-artwork.js src/core/status.js src/core/native-get.js src/core/system/configfile.js src/core/output.js src/core/args.js src/cli.js src/core/usage.js
FEATURES := $(FEATURE_PURE) src/features/config/configfile.js src/features/config/command.js src/features/dialects/nowplaying-cli.js src/features/dialects/media-control-help.js src/features/dialects/media-control.js src/features/dialects/shared.js src/features/dialects/playerctl.js src/features/dialects/mpc.js src/features/dialects/shpotify.js src/features/dialects/index.js src/features/watch/loop.js
SOURCES := $(CORE) $(FEATURES)
TESTS := test/harness.js test/core.test.js test/hold.test.js test/item.test.js test/dialects.test.js test/paint.test.js test/watch.test.js test/edges.test.js test/edges-text.test.js test/config.test.js
TARGET := build/nowplayingseek
FAKE_TARGET := build/nowplayingseek-fake
TEST_TARGET := build/test.js
ARTWORK_SRC := native/artwork.m
ARTWORK_BUNDLE := build/nowplayingseek-artwork.bundle
ARTWORK_BUNDLE_UNIVERSAL := build/nowplayingseek-artwork-universal.bundle
DIST_VERSION := $(shell sed -n "s/^const VERSION = '\(.*\)';$$/\1/p" src/cli.js)
DIST_NAME := nowplayingseek-$(DIST_VERSION)-macos
DIST_STAGE := dist/$(DIST_NAME)
DIST_TARBALL := dist/$(DIST_NAME).tar.gz
# JXA has no module system, so the sources are concatenated into the one file
# osascript runs. The order is the dependency order.
$(TARGET): $(SOURCES)
@mkdir -p build
{ echo '#!/usr/bin/osascript -l JavaScript'; cat $(SOURCES); } > $@
chmod +x $@
.PHONY: build test test-speed knob-replay test-live test-world coverage typecheck globals lint install uninstall clean dist
build: $(TARGET) $(ARTWORK_BUNDLE)
# scripts/globals.js reads CORE/FEATURES/PURE/SOURCES this way, not by re-parsing the Makefile
# text, so a variable built from other variables (as SOURCES now is) still resolves correctly.
print-%:
@echo $($*)
# The same tool with a player that is a file, so that no test of arguments — nor artwork —
# can reach anything real.
FAKE_SOURCES := $(subst src/core/system/artwork.js,test/fake-artwork.js,$(subst src/core/system/mediaremote.js,test/fake-mediaremote.js,$(SOURCES)))
$(FAKE_TARGET): $(SOURCES) test/fake-mediaremote.js test/fake-artwork.js
@mkdir -p build
{ echo '#!/usr/bin/osascript -l JavaScript'; cat $(FAKE_SOURCES); } > $@
chmod +x $@
$(TEST_TARGET): $(TESTS)
@mkdir -p build
cat $(TESTS) > $@
# A real Objective-C block, which nothing inside osascript can build (docs/how-it-works.md);
# loaded into /usr/bin/perl at run time by artwork.fetch() in src/core/system/artwork.js.
# Unsigned is fine: mediaremoted checks perl's own code signature, never this file's.
$(ARTWORK_BUNDLE): $(ARTWORK_SRC)
@mkdir -p build
clang -fobjc-arc -Wall -Wextra -bundle -framework Foundation -o $@ $<
# One tarball for both kinds of Mac: clang links a fat Mach-O directly, no separate asset per
# arch and no Rosetta needed to build it, so this is the whole cost of "universal" here.
$(ARTWORK_BUNDLE_UNIVERSAL): $(ARTWORK_SRC)
@mkdir -p build
clang -fobjc-arc -Wall -Wextra -bundle -framework Foundation -arch arm64 -arch x86_64 -o $@ $<
test: $(TARGET) $(FAKE_TARGET) $(TEST_TARGET) $(ARTWORK_BUNDLE)
osascript -l JavaScript $(TEST_TARGET) $(PURE)
sh test/cli.test.sh $(FAKE_TARGET)
sh test/commands.test.sh $(FAKE_TARGET)
sh test/fake.test.sh
# Not part of `test`: wall-clock budgets are noise on a shared, loaded CI runner.
test-speed: $(FAKE_TARGET)
sh test/speed.test.sh $(FAKE_TARGET)
# Opens VLC on generated silence and drives it; refuses while something is playing.
test-live: $(TARGET)
sh test/live.test.sh $(TARGET)
# What we believe about VLC, QuickTime, macOS, Homebrew and nowplaying-cli, checked against them.
# Not strict: the sources carry no annotations, so this finds a wrong name, a wrong count of
# arguments, a property nothing has — not an implicit any. For development; CI does not run it.
typecheck: $(TARGET)
@mkdir -p build/types
tail -n +2 $(TARGET) > build/types/nowplayingseek.js
npx -y -p typescript@7.0.2 tsc --allowJs --checkJs --noEmit --target es2023 --lib es2023 --strict false build/types/nowplayingseek.js scripts/jxa.d.ts
# Recorded turns of a real knob replayed through the knob logic: does each feel as it was turned?
# Not part of `make test`: it is for tuning a curve against the turns. ARGS='--set knob.fast=30'.
knob-replay:
node scripts/knob-replay.js "$(PURE)" $(ARGS)
coverage:
node scripts/coverage.js "$(PURE)" "$(TESTS)"
test-world: $(TARGET)
sh test/world.test.sh $(TARGET)
globals:
node scripts/globals.js
pre-commit run biome-check --files biome.json || true
lint:
node scripts/globals.js --check
pre-commit run --all-files
install: $(TARGET) $(ARTWORK_BUNDLE)
install -d $(DESTDIR)$(PREFIX)/bin
install -m 755 $(TARGET) $(DESTDIR)$(PREFIX)/bin/nowplayingseek
install -m 755 $(ARTWORK_BUNDLE) $(DESTDIR)$(PREFIX)/bin/nowplayingseek-artwork.bundle
ln -sf nowplayingseek $(DESTDIR)$(PREFIX)/bin/nps
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/nowplayingseek $(DESTDIR)$(PREFIX)/bin/nps $(DESTDIR)$(PREFIX)/bin/nowplayingseek-artwork.bundle
# The release asset: the built script, the universal artwork bundle beside it (src/core/system/paths.js
# resolves the bundle next to whatever path osascript was run from, so this only works if both
# land in the same directory), LICENSE and README. touch -h fixes every mtime before the tar so
# two runs over the same checkout produce the same bytes; gzip -n drops its own timestamp too.
dist: $(TARGET) $(ARTWORK_BUNDLE_UNIVERSAL)
rm -rf dist
mkdir -p $(DIST_STAGE)
install -m 755 $(TARGET) $(DIST_STAGE)/nowplayingseek
install -m 755 $(ARTWORK_BUNDLE_UNIVERSAL) $(DIST_STAGE)/nowplayingseek-artwork.bundle
install -m 644 LICENSE README.md $(DIST_STAGE)/
ln -sf nowplayingseek $(DIST_STAGE)/nps
touch -h -t 200001010000 $(DIST_STAGE) $(DIST_STAGE)/*
tar --uid 0 --gid 0 --numeric-owner -cf - -C dist $(DIST_NAME) | gzip -n -9 >$(DIST_TARBALL)
cd dist && shasum -a 256 $(DIST_NAME).tar.gz >$(DIST_NAME).tar.gz.sha256
cd dist && shasum -a 256 -c $(DIST_NAME).tar.gz.sha256
clean:
rm -rf build dist