nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 fetchurl,
3 lib,
4 stdenv,
5 meson,
6 mesonEmulatorHook,
7 ninja,
8 pkg-config,
9 gnome,
10 gtk3,
11 gtk4,
12 atk,
13 gobject-introspection,
14 spidermonkey_140,
15 pango,
16 cairo,
17 readline,
18 libsysprof-capture,
19 glib,
20 libxml2,
21 dbus,
22 gdk-pixbuf,
23 harfbuzz,
24 makeWrapper,
25 which,
26 xvfb-run,
27 nixosTests,
28 installTests ? true,
29}:
30
31let
32 testDeps = [
33 gtk3
34 gtk4
35 atk
36 pango.out
37 gdk-pixbuf
38 harfbuzz
39 glib.out
40 ];
41in
42stdenv.mkDerivation (finalAttrs: {
43 pname = "gjs";
44 version = "1.86.0";
45
46 outputs = [
47 "out"
48 "dev"
49 "installedTests"
50 ];
51
52 src = fetchurl {
53 url = "mirror://gnome/sources/gjs/${lib.versions.majorMinor finalAttrs.version}/gjs-${finalAttrs.version}.tar.xz";
54 hash = "sha256-Y0SPeleATUwqjQx/XpDiJNBNTrLVYBQsB2xlqO2gB5k=";
55 };
56
57 patches = [
58 # Hard-code various paths
59 ./fix-paths.patch
60
61 # Allow installing installed tests to a separate output.
62 ./installed-tests-path.patch
63
64 # Disable introspection test in installed tests
65 # (minijasmine:1317): GLib-GIO-WARNING **: 17:33:39.556: Error creating IO channel for /proc/self/mountinfo: No such file or directory (g-io-error-quark, 1)
66 ./disable-introspection-test.patch
67
68 # The reason is unclear, but a test that creates a file named "öäü-3" fails only on ZFS filesystems:
69 # 24/78 gjs:JS / GIMarshalling FAIL 0.59s 726/727 subtests passed
70 # not ok 796 Filename tests various types of path existing
71 # Message: Error opening file “/build/.UGHEA3/öäü-3”: Invalid or incomplete multibyte or wide character in /build/gjs-1.84.2/build/../installed-tests/js/testGIMarshalling.js (line 2937)
72 ./disable-umlaut-test.patch
73 ];
74
75 nativeBuildInputs = [
76 meson
77 ninja
78 pkg-config
79 makeWrapper
80 which # for locale detection
81 libxml2 # for xml-stripblanks
82 dbus # for dbus-run-session
83 gobject-introspection
84 ]
85 ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
86 mesonEmulatorHook
87 ];
88
89 buildInputs = [
90 cairo
91 readline
92 libsysprof-capture
93 spidermonkey_140
94 ];
95
96 nativeCheckInputs = [
97 xvfb-run
98 ];
99
100 checkInputs = testDeps;
101
102 propagatedBuildInputs = [
103 glib
104 ];
105
106 mesonFlags = [
107 "-Dinstalled_test_prefix=${placeholder "installedTests"}"
108 (lib.mesonBool "skip_gtk_tests" (!finalAttrs.finalPackage.doCheck))
109 ]
110 ++ lib.optionals (!stdenv.hostPlatform.isLinux || stdenv.hostPlatform.isMusl) [
111 "-Dprofiler=disabled"
112 ];
113
114 doCheck = !stdenv.hostPlatform.isDarwin;
115
116 strictDeps = true;
117
118 postPatch = ''
119 patchShebangs build/choose-tests-locale.sh
120 substituteInPlace installed-tests/debugger-test.sh --subst-var-by gjsConsole $out/bin/gjs-console
121 ''
122 + lib.optionalString stdenv.hostPlatform.isMusl ''
123 substituteInPlace installed-tests/js/meson.build \
124 --replace "'Encoding'," "#'Encoding',"
125 '';
126
127 preCheck = ''
128 # Our gobject-introspection patches make the shared library paths absolute
129 # in the GIR files. When running tests, the library is not yet installed,
130 # though, so we need to replace the absolute path with a local one during build.
131 # We are using a symlink that will be overridden during installation.
132 mkdir -p $out/lib $installedTests/libexec/installed-tests/gjs
133 ln -s $PWD/libgjs.so.0 $out/lib/libgjs.so.0
134 ln -s $PWD/subprojects/gobject-introspection-tests/libgimarshallingtests.so $installedTests/libexec/installed-tests/gjs/libgimarshallingtests.so
135 ln -s $PWD/subprojects/gobject-introspection-tests/libregress.so $installedTests/libexec/installed-tests/gjs/libregress.so
136 ln -s $PWD/subprojects/gobject-introspection-tests/libutility.so $installedTests/libexec/installed-tests/gjs/libutility.so
137 ln -s $PWD/subprojects/gobject-introspection-tests/libwarnlib.so $installedTests/libexec/installed-tests/gjs/libwarnlib.so
138 ln -s $PWD/installed-tests/js/libgjstesttools/libgjstesttools.so $installedTests/libexec/installed-tests/gjs/libgjstesttools.so
139 '';
140
141 postInstall = ''
142 # TODO: make the glib setup hook handle moving the schemas in other outputs.
143 installedTestsSchemaDatadir="$installedTests/share/gsettings-schemas/gjs-${finalAttrs.version}"
144 mkdir -p "$installedTestsSchemaDatadir"
145 mv "$installedTests/share/glib-2.0" "$installedTestsSchemaDatadir"
146 '';
147
148 postFixup = lib.optionalString installTests ''
149 wrapProgram "$installedTests/libexec/installed-tests/gjs/minijasmine" \
150 --prefix XDG_DATA_DIRS : "$installedTestsSchemaDatadir" \
151 --prefix GI_TYPELIB_PATH : "${lib.makeSearchPath "lib/girepository-1.0" testDeps}"
152 '';
153
154 checkPhase = ''
155 runHook preCheck
156 GTK_A11Y=none \
157 HOME=$(mktemp -d) \
158 xvfb-run -s '-screen 0 800x600x24' \
159 meson test --print-errorlogs
160 runHook postCheck
161 '';
162
163 separateDebugInfo = stdenv.hostPlatform.isLinux;
164
165 passthru = {
166 tests = {
167 installed-tests = nixosTests.installed-tests.gjs;
168 };
169
170 updateScript = gnome.updateScript {
171 packageName = "gjs";
172 versionPolicy = "odd-unstable";
173 };
174 };
175
176 meta = {
177 description = "JavaScript bindings for GNOME";
178 homepage = "https://gitlab.gnome.org/GNOME/gjs/blob/master/doc/Home.md";
179 license = lib.licenses.lgpl2Plus;
180 mainProgram = "gjs";
181 teams = [ lib.teams.gnome ];
182 inherit (gobject-introspection.meta) platforms badPlatforms;
183 };
184})