1{ stdenv, fetchFromGitHub, fetchpatch
2, bison2, flex, fontconfig, freetype, gperf, icu, openssl, libjpeg
3, libpng, perl, python, ruby, sqlite, qtwebkit, qmake, qtbase
4, darwin, writeScriptBin, cups, makeWrapper
5}:
6
7let
8 fakeXcrun = writeScriptBin "xcrun" ''
9 #!${stdenv.shell}
10 echo >&2 "Fake xcrun: ''$@"
11 args=()
12 while (("$#")); do
13 case "$1" in
14 -sdk*) shift;;
15 -find*) shift;;
16 *) args+=("$1");;
17 esac
18 shift
19 done
20
21 if [ "''${#args[@]}" -gt "0" ]; then
22 echo >&2 "Fake xcrun: ''${args[@]}"
23 exec "''${args[@]}"
24 fi
25 '';
26 fakeClang = writeScriptBin "clang" ''
27 #!${stdenv.shell}
28 if [[ "$@" == *.c ]]; then
29 exec "${stdenv.cc}/bin/clang" "$@"
30 else
31 exec "${stdenv.cc}/bin/clang++" "$@"
32 fi
33 '';
34
35in stdenv.mkDerivation rec {
36 name = "phantomjs-${version}";
37 version = "2.1.1";
38
39 src = fetchFromGitHub {
40 owner = "ariya";
41 repo = "phantomjs";
42 rev = version;
43 sha256 = "1zsbpk1sgh9a16f1a5nx3qvk77ibjn812wqkxqck8n6fia85m5iq";
44 };
45
46 nativeBuildInputs = [ qmake ];
47 buildInputs = [
48 bison2 flex fontconfig freetype gperf icu openssl
49 libjpeg libpng perl python ruby sqlite qtwebkit qtbase
50 makeWrapper
51 ] ++ stdenv.lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [
52 AGL ApplicationServices AppKit Cocoa OpenGL
53 darwin.libobjc fakeClang cups
54 ]);
55
56 patches = [
57 (fetchpatch {
58 url = "https://anonscm.debian.org/cgit/collab-maint/phantomjs.git/plain/debian/patches/build-hardening.patch?id=42c9154d8c87c9fe434908259b0eddde4d892ca3";
59 sha256 = "1qs1r76w90qgpw742i7lf0y3b7m9zh5wxcbrhrak6mq1kqaphqb5";
60 })
61 (fetchpatch {
62 url = "https://anonscm.debian.org/cgit/collab-maint/phantomjs.git/plain/debian/patches/build-qt-components.patch?id=9b5c1ce95a7044ebffc634f773edf7d4eb9b6cd3";
63 sha256 = "1fw2q59aqcks3abvwkqg9903yif6aivdsznc0h6frhhjvpp19vsb";
64 })
65 (fetchpatch {
66 url = "https://anonscm.debian.org/cgit/collab-maint/phantomjs.git/plain/debian/patches/build-qt55-evaluateJavaScript.patch?id=9b5c1ce95a7044ebffc634f773edf7d4eb9b6cd3";
67 sha256 = "1avig9cfny8kv3s4mf3mdzvf3xlzgyh351yzwc4bkpnjvzv4fmq6";
68 })
69 (fetchpatch {
70 url = "https://anonscm.debian.org/cgit/collab-maint/phantomjs.git/plain/debian/patches/build-qt55-no-websecurity.patch?id=9b5c1ce95a7044ebffc634f773edf7d4eb9b6cd3";
71 sha256 = "1nykqpxa7lcf9iarz5lywgg3v3b1h19iwvjdg4kgq0ai6idhcab8";
72 })
73 (fetchpatch {
74 url = "https://anonscm.debian.org/cgit/collab-maint/phantomjs.git/plain/debian/patches/build-qt55-print.patch?id=9b5c1ce95a7044ebffc634f773edf7d4eb9b6cd3";
75 sha256 = "1fydmdjxnplglpbd3ypaih5l237jkxjirpdhzz92mcpy29yla6jw";
76 })
77 (fetchpatch {
78 url = "https://anonscm.debian.org/cgit/collab-maint/phantomjs.git/plain/debian/patches/unlock-qt.patch";
79 sha256 = "13bwz4iw17d6hq5pwkbpcckqyw7fhc6648lvs26m39pp31zwyp03";
80 })
81 ./system-qtbase.patch
82 ];
83
84 postPatch = ''
85 patchShebangs .
86 substituteInPlace src/phantomjs.pro \
87 --replace "QT_MINOR_VERSION, 5" "QT_MINOR_VERSION, 9"
88 '';
89
90 __impureHostDeps = stdenv.lib.optional stdenv.isDarwin "/usr/lib/libicucore.dylib";
91
92 enableParallelBuilding = true;
93
94 installPhase = ''
95 mkdir -p $out/share/doc/phantomjs
96 cp -a bin $out
97 cp -a ChangeLog examples LICENSE.BSD README.md third-party.txt $out/share/doc/phantomjs
98 '' + stdenv.lib.optionalString stdenv.isDarwin ''
99 install_name_tool -change \
100 ${darwin.CF}/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation \
101 /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation \
102 -change \
103 ${darwin.configd}/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration \
104 /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration \
105 $out/bin/phantomjs
106 '' + ''
107 wrapProgram $out/bin/phantomjs \
108 --set QT_QPA_PLATFORM offscreen \
109 --prefix PATH : ${stdenv.lib.makeBinPath [ qtbase ]}
110 '';
111
112 meta = with stdenv.lib; {
113 description = "Headless WebKit with JavaScript API";
114 longDescription = ''
115 PhantomJS2 is a headless WebKit with JavaScript API.
116 It has fast and native support for various web standards:
117 DOM handling, CSS selector, JSON, Canvas, and SVG.
118
119 PhantomJS is an optimal solution for:
120 - Headless Website Testing
121 - Screen Capture
122 - Page Automation
123 - Network Monitoring
124 '';
125
126 homepage = http://phantomjs.org/;
127 license = licenses.bsd3;
128
129 maintainers = [ maintainers.aflatter ];
130 platforms = platforms.darwin ++ platforms.linux;
131 };
132}