1{ fetchurl
2, lib
3, stdenv
4, meson
5, mesonEmulatorHook
6, ninja
7, pkg-config
8, gnome
9, gtk3
10, atk
11, gobject-introspection
12, spidermonkey_102
13, pango
14, cairo
15, readline
16, libsysprof-capture
17, glib
18, libxml2
19, dbus
20, gdk-pixbuf
21, harfbuzz
22, makeWrapper
23, which
24, xvfb-run
25, nixosTests
26}:
27
28let
29 testDeps = [
30 gtk3 atk pango.out gdk-pixbuf harfbuzz
31 ];
32in stdenv.mkDerivation rec {
33 pname = "gjs";
34 version = "1.76.0";
35
36 outputs = [ "out" "dev" "installedTests" ];
37
38 src = fetchurl {
39 url = "mirror://gnome/sources/gjs/${lib.versions.majorMinor version}/${pname}-${version}.tar.xz";
40 sha256 = "sha256-pj8VaWSxNgU+q1HqATEU59fBk7dRjSjAQLawLDyTOm0=";
41 };
42
43 patches = [
44 # Hard-code various paths
45 ./fix-paths.patch
46
47 # Allow installing installed tests to a separate output.
48 ./installed-tests-path.patch
49 ];
50
51 nativeBuildInputs = [
52 meson
53 ninja
54 pkg-config
55 makeWrapper
56 which # for locale detection
57 libxml2 # for xml-stripblanks
58 dbus # for dbus-run-session
59 gobject-introspection
60 ] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
61 mesonEmulatorHook
62 ];
63
64 buildInputs = [
65 cairo
66 readline
67 libsysprof-capture
68 spidermonkey_102
69 ];
70
71 nativeCheckInputs = [
72 xvfb-run
73 ] ++ testDeps;
74
75 propagatedBuildInputs = [
76 glib
77 ];
78
79 mesonFlags = [
80 "-Dinstalled_test_prefix=${placeholder "installedTests"}"
81 ] ++ lib.optionals (!stdenv.isLinux || stdenv.hostPlatform.isMusl) [
82 "-Dprofiler=disabled"
83 ];
84
85 doCheck = !stdenv.isDarwin;
86
87 postPatch = ''
88 patchShebangs build/choose-tests-locale.sh
89 substituteInPlace installed-tests/debugger-test.sh --subst-var-by gjsConsole $out/bin/gjs-console
90 '' + lib.optionalString stdenv.hostPlatform.isMusl ''
91 substituteInPlace installed-tests/js/meson.build \
92 --replace "'Encoding'," "#'Encoding',"
93 '';
94
95 preCheck = ''
96 # Our gobject-introspection patches make the shared library paths absolute
97 # in the GIR files. When running tests, the library is not yet installed,
98 # though, so we need to replace the absolute path with a local one during build.
99 # We are using a symlink that will be overridden during installation.
100 mkdir -p $out/lib $installedTests/libexec/installed-tests/gjs
101 ln -s $PWD/libgjs.so.0 $out/lib/libgjs.so.0
102 ln -s $PWD/installed-tests/js/libgimarshallingtests.so $installedTests/libexec/installed-tests/gjs/libgimarshallingtests.so
103 ln -s $PWD/installed-tests/js/libgjstesttools/libgjstesttools.so $installedTests/libexec/installed-tests/gjs/libgjstesttools.so
104 ln -s $PWD/installed-tests/js/libregress.so $installedTests/libexec/installed-tests/gjs/libregress.so
105 ln -s $PWD/installed-tests/js/libwarnlib.so $installedTests/libexec/installed-tests/gjs/libwarnlib.so
106 '';
107
108 postInstall = ''
109 # TODO: make the glib setup hook handle moving the schemas in other outputs.
110 installedTestsSchemaDatadir="$installedTests/share/gsettings-schemas/${pname}-${version}"
111 mkdir -p "$installedTestsSchemaDatadir"
112 mv "$installedTests/share/glib-2.0" "$installedTestsSchemaDatadir"
113 '';
114
115 postFixup = ''
116 wrapProgram "$installedTests/libexec/installed-tests/gjs/minijasmine" \
117 --prefix XDG_DATA_DIRS : "$installedTestsSchemaDatadir" \
118 --prefix GI_TYPELIB_PATH : "${lib.makeSearchPath "lib/girepository-1.0" testDeps}"
119 '';
120
121 checkPhase = ''
122 runHook preCheck
123 xvfb-run -s '-screen 0 800x600x24' \
124 meson test --print-errorlogs
125 runHook postCheck
126 '';
127
128 separateDebugInfo = stdenv.isLinux;
129
130 passthru = {
131 tests = {
132 installed-tests = nixosTests.installed-tests.gjs;
133 };
134
135 updateScript = gnome.updateScript {
136 packageName = "gjs";
137 versionPolicy = "odd-unstable";
138 };
139 };
140
141 meta = with lib; {
142 description = "JavaScript bindings for GNOME";
143 homepage = "https://gitlab.gnome.org/GNOME/gjs/blob/master/doc/Home.md";
144 license = licenses.lgpl2Plus;
145 maintainers = teams.gnome.members;
146 platforms = platforms.unix;
147 };
148}