atom-1.12.7.ebuild 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=6
  4. PYTHON_COMPAT=( python2_7 )
  5. inherit python-any-r1 multiprocessing rpm
  6. DESCRIPTION="A hackable text editor for the 21st Century"
  7. HOMEPAGE="https://atom.io"
  8. MY_PV="${PV//_/-}"
  9. ELECTRON_V=1.3.5
  10. ELECTRON_SLOT=1.3
  11. # All binary packages depend on this
  12. NAN_V=2.4.0
  13. # Keep dep versions in sync with atom/package.json
  14. CACHED_RUN_IN_THIS_CONTEXT_V=0.4.1
  15. GIT_UTILS_V=4.1.2
  16. NODE_NSLOG_V=3.0.0
  17. NODE_ONIGURUMA_V=6.1.0
  18. NODE_PATHWATCHER_V=6.5.0
  19. NODE_RUNAS_V=3.1.1
  20. SCROLLBAR_STYLE_V=3.2.0
  21. SPELL_CHECK_V=0.68.4
  22. # textbuffer dependency
  23. MARKER_INDEX_V=4.0.1
  24. # apm dependency
  25. NODE_KEYTAR_V=3.0.2
  26. # atom-keymap dependency
  27. KEYBOARD_LAYOUT_V=2.0.7
  28. # symbols-view dependency
  29. NODE_CTAGS_V=3.0.0
  30. # spell-check dependency
  31. NODE_SPELLCHECKER_V=3.2.3
  32. ASAR_V=0.12.1
  33. # The x86_64 arch below is irrelevant, as we will rebuild all binary packages.
  34. SRC_URI="
  35. https://github.com/${PN}/${PN}/releases/download/v${MY_PV}/atom.x86_64.rpm -> atom-${MY_PV}.rpm
  36. https://github.com/elprans/asar/releases/download/v${ASAR_V}-gentoo/asar-build.tar.gz -> asar-${ASAR_V}.tar.gz
  37. https://github.com/nodejs/nan/archive/v${NAN_V}.tar.gz -> nodejs-nan-${NAN_V}.tar.gz
  38. https://github.com/atom/cached-run-in-this-context/archive/v${CACHED_RUN_IN_THIS_CONTEXT_V}.tar.gz -> atom-cached-run-in-this-context-${CACHED_RUN_IN_THIS_CONTEXT_V}.tar.gz
  39. https://github.com/atom/node-ctags/archive/v${NODE_CTAGS_V}.tar.gz -> atom-node-ctags-${NODE_CTAGS_V}.tar.gz
  40. https://github.com/atom/git-utils/archive/v${GIT_UTILS_V}.tar.gz -> atom-git-utils-${GIT_UTILS_V}.tar.gz
  41. https://github.com/atom/keyboard-layout/archive/v${KEYBOARD_LAYOUT_V}.tar.gz -> atom-keyboard-layout-${KEYBOARD_LAYOUT_V}.tar.gz
  42. https://github.com/atom/marker-index/archive/v${MARKER_INDEX_V}.tar.gz -> atom-marker-index-${MARKER_INDEX_V}.tar.gz
  43. https://github.com/atom/node-keytar/archive/v${NODE_KEYTAR_V}.tar.gz -> atom-node-keytar-${NODE_KEYTAR_V}.tar.gz
  44. https://github.com/atom/node-nslog/archive/v${NODE_NSLOG_V}.tar.gz -> atom-node-nslog-${NODE_NSLOG_V}.tar.gz
  45. https://github.com/atom/node-oniguruma/archive/v${NODE_ONIGURUMA_V}.tar.gz -> atom-node-oniguruma-${NODE_ONIGURUMA_V}.tar.gz
  46. https://github.com/atom/node-pathwatcher/archive/v${NODE_PATHWATCHER_V}.tar.gz -> atom-node-pathwatcher-${NODE_PATHWATCHER_V}.tar.gz
  47. https://github.com/atom/node-runas/archive/v${NODE_RUNAS_V}.tar.gz -> atom-node-runas-${NODE_RUNAS_V}.tar.gz
  48. https://github.com/atom/scrollbar-style/archive/v${SCROLLBAR_STYLE_V}.tar.gz -> atom-scrollbar-style-${SCROLLBAR_STYLE_V}.tar.gz
  49. https://github.com/atom/node-spellchecker/archive/v${NODE_SPELLCHECKER_V}.tar.gz -> atom-node-spellchecker-${NODE_SPELLCHECKER_V}.tar.gz
  50. "
  51. BINMODS="
  52. cached-run-in-this-context
  53. node-ctags
  54. git-utils
  55. keyboard-layout
  56. node-nslog
  57. node-oniguruma
  58. node-pathwatcher
  59. node-runas
  60. node-keytar
  61. scrollbar-style
  62. node-spellchecker
  63. marker-index
  64. "
  65. RESTRICT="mirror"
  66. LICENSE="MIT"
  67. SLOT="0"
  68. KEYWORDS="~amd64"
  69. IUSE=""
  70. DEPEND="
  71. ${PYTHON_DEPS}
  72. >=app-text/hunspell-1.3.3:=
  73. >=dev-libs/libgit2-0.23:=[ssh]
  74. >=gnome-base/libgnome-keyring-3.12:=
  75. >=dev-libs/oniguruma-5.9.5:=
  76. >=dev-util/ctags-5.8
  77. >=dev-util/electron-1.3.5:${ELECTRON_SLOT}
  78. x11-libs/libxkbfile
  79. "
  80. RDEPEND="
  81. ${DEPEND}
  82. !sys-apps/apmd
  83. "
  84. S="${WORKDIR}/${PN}-${MY_PV}"
  85. pkg_setup() {
  86. python-any-r1_pkg_setup
  87. }
  88. get_install_suffix() {
  89. local c=(${SLOT//\// })
  90. local slot=${c[0]}
  91. local suffix
  92. if [[ "${slot}" == "0" ]]; then
  93. suffix=""
  94. else
  95. suffix="-${slot}"
  96. fi
  97. echo -n "${suffix}"
  98. }
  99. get_install_dir() {
  100. echo -n "/usr/$(get_libdir)/atom$(get_install_suffix)"
  101. }
  102. get_electron_dir() {
  103. echo -n "/usr/$(get_libdir)/electron-${ELECTRON_SLOT}"
  104. }
  105. get_electron_nodedir() {
  106. echo -n "/usr/include/electron-${ELECTRON_SLOT}/node/"
  107. }
  108. enode_electron() {
  109. "$(get_electron_dir)"/node $@
  110. }
  111. enodegyp_atom() {
  112. local apmpath="/usr/share/atom/resources/app/apm"
  113. local nodegyp="${S}/${apmpath}/node_modules/node-gyp/bin/node-gyp.js"
  114. PATH="$(get_electron_dir):${PATH}" \
  115. enode_electron "${nodegyp}" \
  116. --nodedir="$(get_electron_nodedir)" $@ || die
  117. }
  118. easar() {
  119. local asar="${WORKDIR}/$(package_dir asar)/node_modules/asar/bin/asar"
  120. echo "asar" $@
  121. enode_electron "${asar}" $@ || die
  122. }
  123. package_dir() {
  124. local binmod="${1//-/_}"
  125. local binmod_v="${binmod^^}_V"
  126. echo -n ${1}-${!binmod_v}
  127. }
  128. _unpack_npm_package() {
  129. local a="${1}" basename suffix
  130. basename=${a%.*}
  131. suffix=${basename##*.}
  132. if [[ "${suffix}" == "tar" ]]; then
  133. basename=${basename%.*}
  134. fi
  135. unpack ${a}
  136. mv package "${basename}" || die
  137. }
  138. _have_patches_for() {
  139. local _patches="${1}-*.patch" _find
  140. _find=$(find "${FILESDIR}" -maxdepth 1 -name "${_patches}" -print -quit)
  141. test -n "$_find"
  142. }
  143. src_unpack() {
  144. local a
  145. for a in ${A} ; do
  146. case ${a} in
  147. *.rpm) srcrpm_unpack "${a}" ;;
  148. *) unpack "${a}" ;;
  149. esac
  150. done
  151. mkdir "${WORKDIR}/atom-${MY_PV}" || die
  152. mv "${WORKDIR}/usr" "${WORKDIR}/atom-${MY_PV}" || die
  153. }
  154. src_prepare() {
  155. local install_dir="$(get_install_dir)"
  156. local suffix="$(get_install_suffix)"
  157. local patch binmod _s nan_s="${WORKDIR}/nan-${NAN_V}"
  158. cd "${S}/usr/share/atom/resources/app" || die
  159. eapply "${FILESDIR}/${PN}-python.patch"
  160. eapply "${FILESDIR}/${PN}-unbundle-electron.patch"
  161. sed -i -e "s|{{NPM_CONFIG_NODEDIR}}|$(get_electron_nodedir)|g" \
  162. ./atom.sh \
  163. || die
  164. sed -i -e "s|{{ATOM_PATH}}|$(get_electron_dir)/electron|g" \
  165. ./atom.sh \
  166. || die
  167. sed -i -e "s|{{ATOM_RESOURCE_PATH}}|${install_dir}/app.asar|g" \
  168. ./atom.sh \
  169. || die
  170. local env="export NPM_CONFIG_NODEDIR=$(get_electron_nodedir)"
  171. sed -i -e \
  172. "s|\"\$binDir/\$nodeBin\"|${env}\nexec $(get_electron_dir)/node|g" \
  173. apm/bin/apm || die
  174. sed -i -e \
  175. "s|^\([[:space:]]*\)node[[:space:]]\+|\1\"$(get_electron_dir)/node\" |g" \
  176. apm/node_modules/npm/bin/node-gyp-bin/node-gyp || die
  177. rm apm/bin/node || die
  178. sed -i -e "s|/usr/share/atom/atom|/usr/bin/atom|g" \
  179. "${S}/usr/share/applications/atom.desktop" || die
  180. cd "${S}" || die
  181. for binmod in ${BINMODS}; do
  182. _s="${WORKDIR}/$(package_dir ${binmod})"
  183. cd "${_s}" || die
  184. if _have_patches_for "${binmod}"; then
  185. for patch in "${FILESDIR}"/${binmod}-*.patch; do
  186. eapply "${patch}"
  187. done
  188. fi
  189. done
  190. # Unbundle bundled libs from modules
  191. _s="${WORKDIR}/$(package_dir git-utils)"
  192. ${EPYTHON} "${FILESDIR}/gyp-unbundle.py" \
  193. --inplace --unbundle "git;libgit2;git2" \
  194. "${_s}/binding.gyp" || die
  195. _s="${WORKDIR}/$(package_dir node-oniguruma)"
  196. ${EPYTHON} "${FILESDIR}/gyp-unbundle.py" \
  197. --inplace --unbundle "onig_scanner;oniguruma;onig" \
  198. "${_s}/binding.gyp" || die
  199. _s="${WORKDIR}/$(package_dir node-spellchecker)"
  200. ${EPYTHON} "${FILESDIR}/gyp-unbundle.py" \
  201. --inplace --unbundle "spellchecker;hunspell;hunspell" \
  202. "${_s}/binding.gyp" || die
  203. for binmod in ${BINMODS}; do
  204. _s="${WORKDIR}/$(package_dir ${binmod})"
  205. mkdir -p "${_s}/node_modules" || die
  206. ln -s "${nan_s}" "${_s}/node_modules/nan" || die
  207. done
  208. # Unpack app.asar
  209. easar extract "${S}/usr/share/atom/resources/app.asar" "${S}/build/app"
  210. cd "${S}" || die
  211. eapply "${FILESDIR}/atom-apm-path.patch"
  212. eapply "${FILESDIR}/atom-license-path.patch"
  213. eapply "${FILESDIR}/atom-fix-app-restart.patch"
  214. sed -i -e "s|{{ATOM_SUFFIX}}|${suffix}|g" \
  215. "${S}/build/app/src/config-schema.js" || die
  216. eapply_user
  217. }
  218. src_configure() {
  219. local binmod _s
  220. for binmod in ${BINMODS}; do
  221. einfo "Configuring ${binmod}..."
  222. _s="${WORKDIR}/$(package_dir ${binmod})"
  223. cd "${_s}" || die
  224. enodegyp_atom configure
  225. done
  226. }
  227. src_compile() {
  228. local binmod _s x
  229. local ctags_d="node_modules/symbols-view/vendor"
  230. local jobs=$(makeopts_jobs) gypopts
  231. gypopts="--verbose"
  232. if [[ ${MAKEOPTS} == *-j* && ${jobs} != 999 ]]; then
  233. gypopts+=" --jobs ${jobs}"
  234. fi
  235. mkdir -p "${S}/build/modules/" || die
  236. for binmod in ${BINMODS}; do
  237. einfo "Building ${binmod}..."
  238. _s="${WORKDIR}/$(package_dir ${binmod})"
  239. cd "${_s}" || die
  240. enodegyp_atom ${gypopts} build
  241. x=${binmod##node-}
  242. mkdir -p "${S}/build/modules/${x}" || die
  243. cp build/Release/*.node "${S}/build/modules/${x}" || die
  244. done
  245. # Put compiled binary modules in place
  246. _fix_binmods "${S}/build" "app"
  247. _fix_binmods "${S}/usr/share/atom/resources" "app"
  248. # Remove non-Linux vendored ctags binaries
  249. rm "${S}/build/app/${ctags_d}/ctags-darwin" \
  250. "${S}/build/app/${ctags_d}/ctags-win32.exe" || die
  251. # Re-pack app.asar
  252. # Keep unpack rules in sync with build/tasks/generate-asar-task.coffee
  253. cd "${S}/build" || die
  254. x="--unpack={*.node,ctags-config,ctags-linux,**/node_modules/spellchecker/**,**/resources/atom.png}"
  255. easar pack "${x}" "app" "app.asar"
  256. cd "${S}" || die
  257. }
  258. _fix_binmods() {
  259. local _dir="${2}" _prefix="${1}" path relpath modpath mod depth link f d
  260. local cruft
  261. (find "${_prefix}/${_dir}" -name '*.node' -print || die) \
  262. | while IFS= read -r path; do
  263. f=$(basename "${path}")
  264. d=$(dirname "${path}")
  265. relpath=${path#${_prefix}}
  266. relpath=${relpath##/}
  267. relpath=${relpath#W${_dir}}
  268. modpath=$(dirname ${relpath})
  269. modpath=${modpath%build/Release}
  270. mod=$(basename ${modpath})
  271. # must copy here as symlinks will cause the module loading to fail
  272. cp -f "${S}/build/modules/${mod}/${f}" "${path}" || die
  273. cruft=$(find "${d}" -name '*.a' -print)
  274. if [[ -n "${cruft}" ]]; then
  275. rm ${cruft} || die
  276. fi
  277. done
  278. }
  279. _fix_executables() {
  280. local _dir="${1}" _node_sb="#!$(get_electron_dir)"/node
  281. (find -L "${ED}/${_dir}" -maxdepth 1 -mindepth 1 -type f -print || die) \
  282. | while IFS= read -r f; do
  283. IFS= read -r shebang < "${f}"
  284. if [[ ${shebang} == '#!'* ]]; then
  285. fperms +x "${f#${ED}}"
  286. if [[ "${shebang}" == "#!/usr/bin/env node" || "${shebang}" == "#!/usr/bin/node" ]]; then
  287. einfo "Fixing node shebang in ${f#${ED}}"
  288. sed --follow-symlinks -i \
  289. -e "1s:${shebang}$:${_node_sb}:" "${f}" || die
  290. fi
  291. fi
  292. done || die
  293. }
  294. src_install() {
  295. local install_dir="$(get_install_dir)"
  296. local suffix="$(get_install_suffix)"
  297. local ctags_d="node_modules/symbols-view/vendor"
  298. cd "${S}" || die
  299. # Replace vendored ctags with a symlink to system ctags
  300. rm "${S}/build/app.asar.unpacked/${ctags_d}/ctags-linux" || die
  301. ln -s "/usr/bin/ctags" \
  302. "${S}/build/app.asar.unpacked/${ctags_d}/ctags-linux" || die
  303. insinto "${install_dir}"
  304. doins build/app.asar
  305. doins -r build/app.asar.unpacked
  306. doins -r usr/share/atom/resources/app
  307. insinto /usr/share/applications/
  308. newins usr/share/applications/atom.desktop "atom${suffix}.desktop"
  309. insinto /usr/share/icons/
  310. doins -r usr/share/icons/hicolor
  311. exeinto "${install_dir}"
  312. newexe usr/share/atom/resources/app/atom.sh atom
  313. insinto /usr/share/licenses/"${PN}${suffix}"
  314. doins usr/share/atom/resources/LICENSE.md
  315. dosym "${install_dir}/atom" "/usr/bin/atom${suffix}"
  316. dosym "${install_dir}/app/apm/bin/apm" "/usr/bin/apm${suffix}"
  317. _fix_executables "${install_dir}/app/apm/bin"
  318. _fix_executables "${install_dir}/app/apm/node_modules/.bin"
  319. _fix_executables "${install_dir}/app/apm/node_modules/npm/bin"
  320. _fix_executables "${install_dir}/app/apm/node_modules/npm/bin/node-gyp-bin"
  321. _fix_executables "${install_dir}/app/apm/node_modules/node-gyp/bin"
  322. }