1{ stdenv, fetchgit,
2 bison2, flex, fontconfig, freetype, gperf, icu, openssl, libjpeg, libpng, perl, python, ruby, sqlite,
3 darwin, writeScriptBin, cups
4}:
5
6let
7 fakeXcrun = writeScriptBin "xcrun" ''
8 #!${stdenv.shell}
9 echo >&2 "Fake xcrun: ''$@"
10 args=()
11 while (("$#")); do
12 case "$1" in
13 -sdk*) shift;;
14 -find*) shift;;
15 *) args+=("$1");;
16 esac
17 shift
18 done
19
20 if [ "''${#args[@]}" -gt "0" ]; then
21 echo >&2 "Fake xcrun: ''${args[@]}"
22 exec "''${args[@]}"
23 fi
24 '';
25 fakeClang = writeScriptBin "clang" ''
26 #!${stdenv.shell}
27 if [[ "$@" == *.c ]]; then
28 exec "${stdenv.cc}/bin/clang" "$@"
29 else
30 exec "${stdenv.cc}/bin/clang++" "$@"
31 fi
32 '';
33
34in stdenv.mkDerivation rec {
35 name = "phantomjs-${version}";
36 version = "2.1.1";
37
38 # needs git submodules, so can't use fetchFromGitHub
39 src = fetchgit {
40 rev = "refs/tags/${version}";
41 url = "https://github.com/ariya/phantomjs.git";
42 sha256 = "16x104cw5f1dyhf7fg12vlpcywvc9c43r9afhl0dvssgxklrn0q7";
43 };
44
45 buildInputs = [ bison2 flex fontconfig freetype gperf icu openssl libjpeg libpng perl python ruby sqlite ]
46 ++ stdenv.lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [
47 AGL ApplicationServices AppKit Cocoa OpenGL
48 darwin.libobjc fakeClang cups
49 ]);
50
51
52 patchPhase = ''
53 patchShebangs .
54 sed -i -e 's|/bin/pwd|pwd|' src/qt/qtbase/configure
55 touch src/qt/{qtbase,qtwebkit,3rdparty}/.git
56 '' + stdenv.lib.optionalString stdenv.isDarwin ''
57 sed -i 's,-licucore,/usr/lib/libicucore.dylib,' src/qt/qtwebkit/Source/WTF/WTF.pri
58 substituteInPlace src/qt/qtwebkit/Tools/qmake/mkspecs/features/features.pri \
59 --replace "ENABLE_3D_RENDERING=1" "ENABLE_3D_RENDERING=0"
60 sed -i 88d src/qt/qtwebkit/Tools/qmake/mkspecs/features/features.prf
61 echo 'CONFIG -= create_cmake' >> src/qt/qtwebkit/Source/api.pri
62 echo 'CONFIG -= create_cmake' >> src/qt/qtwebkit/Source/widgetsapi.pri
63 pushd src/qt
64
65 substituteInPlace qtbase/configure \
66 --replace /usr/bin/xcode-select true \
67 --replace '/usr/bin/xcodebuild -sdk $sdk -version Path 2>/dev/null' 'echo /var/empty' \
68 --replace '/usr/bin/xcrun -sdk $sdk -find' 'type -P'
69 substituteInPlace qtbase/mkspecs/features/mac/default_pre.prf \
70 --replace '/usr/bin/xcode-select --print-path 2>/dev/null' "echo ${stdenv.libc}" \
71 --replace '/usr/bin/xcrun -find xcrun 2>/dev/null' 'echo success' \
72 --replace '/usr/bin/xcodebuild -version' 'echo Xcode 7.2; echo Build version 7C68' \
73 --replace 'sdk rez' ""
74 for file in $(grep -rl /usr/bin/xcrun .); do
75 substituteInPlace "$file" --replace "/usr/bin/xcrun" ${fakeXcrun}/bin/xcrun
76 done
77 substituteInPlace qtbase/src/tools/qlalr/lalr.cpp --replace _Nullable Nullable
78
79 popd
80 '';
81
82 __impureHostDeps = stdenv.lib.optional stdenv.isDarwin "/usr/lib/libicucore.dylib";
83
84 buildPhase = "./build.py --confirm -j$NIX_BUILD_CORES";
85
86 enableParallelBuilding = true;
87
88 installPhase = ''
89 mkdir -p $out/share/doc/phantomjs
90 cp -a bin $out
91 cp -a ChangeLog examples LICENSE.BSD README.md third-party.txt $out/share/doc/phantomjs
92 '' + stdenv.lib.optionalString stdenv.isDarwin ''
93 install_name_tool -change \
94 ${darwin.CF}/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation \
95 /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation \
96 -change \
97 ${darwin.configd}/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration \
98 /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration \
99 $out/bin/phantomjs
100 '';
101
102 meta = with stdenv.lib; {
103 description = "Headless WebKit with JavaScript API";
104 longDescription = ''
105 PhantomJS2 is a headless WebKit with JavaScript API.
106 It has fast and native support for various web standards:
107 DOM handling, CSS selector, JSON, Canvas, and SVG.
108
109 PhantomJS is an optimal solution for:
110 - Headless Website Testing
111 - Screen Capture
112 - Page Automation
113 - Network Monitoring
114 '';
115
116 homepage = http://phantomjs.org/;
117 license = licenses.bsd3;
118
119 maintainers = [ maintainers.aflatter ];
120 platforms = platforms.darwin ++ platforms.linux;
121 };
122}