Username: Password: Remember me
# Maintainer: Filipe Laíns (FFY00) <lains@archlinux.org>
# Contributor: Michael Hansen <zrax0111 gmail com>
# Contributor: Francisco Magalhães <franmagneto gmail com>
 
pkgname=vscode-oss
_pkgname=code
pkgdesc='The Open Source build of Visual Studio Code (vscode) editor'
pkgver=1.40.1
pkgrel=1
arch=('x86_64')
url='https://github.com/Microsoft/vscode'
screenshot="https://cloud.githubusercontent.com/assets/11839736/16642200/6624dde0-43bd-11e6-8595-c81885ba0dc2.png"
license=('MIT')
depends=('electron' 'libsecret' 'libxkbfile' 'ripgrep')
makedepends=('git' 'gulp' 'npm' 'python2' 'yarn' 'nodejs-lts-dubnium')
source=("$pkgname::git+https://github.com/Microsoft/vscode.git#tag=$pkgver"
        'code.js'
        'code.sh'
        'product_json.diff'
        'code-liveshare.diff')
sha512sums=('SKIP'
            '814c9554427183cd893a33cd2cbe91f6e0ea71921ef0717c86217b1d3058d265f9ff7a9ace3e7b76f122e60b7686475cf4d999e581a1845face3033afb9f745f'
            'dbe57f23f123cff8ad665b4608351e68772e415c4275542ff41056e328ce7fdb9cb1cfe422e46363a68414ad7cf9f002040f3e590f09b3e91ff1e021e32ea6f7'
            '8ec47e497287d67f37e7b669af416f43d5cdbd4574892867d7b95996ef5de53640b5bc919b06b177e1fd91cb005579d6ed0c17325117b9914ba7cf28f5f06e40'
            'b267dcedaf51067a782d0f14007663b706973c1538f7fb91f093475134c2145fd0ffd5ed2b47ad7f01c6167a78a4af285d2818d7850fc67a7f7a473324824664')
 
prepare() {
  cd $pkgname
 
  # This patch no longer contains proprietary modifications.
  # See https://github.com/Microsoft/vscode/issues/31168 for details.
  patch -p0 < ../product_json.diff
 
  # Set the commit and build date
  local _commit=$(git rev-parse HEAD)
  local _datestamp=$(date -u -Is | sed 's/\+00:00/Z/')
  sed -e "s/@COMMIT@/$_commit/" -e "s/@DATE@/$_datestamp/" -i product.json
 
  # See https://github.com/MicrosoftDocs/live-share/issues/262 for details
  patch -p1 < ../code-liveshare.diff
 
  # Build native modules for system electron
  local _target=$(</usr/lib/electron/version)
  sed -i "s/^target .*/target \"${_target//v/}\"/" .yarnrc
 
  # Patch appdata and desktop file
  sed -i 's|/usr/share/@@NAME@@/@@NAME@@|@@NAME@@|g
          s|@@NAME_SHORT@@|Code|g
          s|@@NAME_LONG@@|Code - OSS|g
          s|@@NAME@@|code-oss|g
          s|@@ICON@@|code-oss|g
          s|@@EXEC@@|/usr/bin/code-oss|g
          s|@@LICENSE@@|MIT|g
          s|@@URLPROTOCOL@@|vscode|g
          s|inode/directory;||' resources/linux/code{.appdata.xml,.desktop,-url-handler.desktop}
 
  # Add completitions for code-oss
  cp resources/completions/bash/code resources/completions/bash/code-oss
  cp resources/completions/zsh/_code resources/completions/zsh/_code-oss
 
  # Patch completitions with correct names
  sed -i 's|@@APPNAME@@|code|g' resources/completions/{bash/code,zsh/_code}
  sed -i 's|@@APPNAME@@|code-oss|g' resources/completions/{bash/code-oss,zsh/_code-oss}
 
  # Fix bin path
  sed -i "s|return path.join(path.dirname(execPath), 'bin', \`\${product.applicationName}\`);|return '/usr/bin/code';|g
          s|return path.join(appRoot, 'scripts', 'code-cli.sh');|return '/usr/bin/code';|g" \
          src/vs/platform/environment/node/environmentService.ts
}
 
build() {
  # https://github.com/mapbox/node-sqlite3/issues/1044
  mkdir -p path
  ln -sf /usr/bin/python2 path/python
  export PATH="$PWD/path:$PATH"
 
  cd $pkgname
 
  yarn install --arch=x64
 
  # The default memory limit may be too low for current versions of node
  # to successfully build vscode. Change it if this number still doesn't
  # work for your system.
  mem_limit="--max_old_space_size=8192"
 
  if ! /usr/bin/node $mem_limit /usr/bin/gulp vscode-linux-x64-min
  then
      echo
      echo "*** NOTE: If the build failed due to running out of file handles (EMFILE),"
      echo "*** you will need to raise your max open file limit."
      echo "*** You can check this for more information on how to increase this limit:"
      echo "***    https://ro-che.info/articles/2017-03-26-increase-open-files-limit"
      exit 1
  fi
}
 
package() {
  # Install resource files
  install -dm 755 $pkgdir/usr/lib/$pkgname
  cp -r --no-preserve=ownership --preserve=mode VSCode-linux-x64/resources/app/* $pkgdir/usr/lib/$pkgname/
 
  # replace statically included binary with system copy
  ln -sf /usr/bin/rg $pkgdir/usr/lib/$pkgname/node_modules.asar.unpacked/vscode-ripgrep/bin/rg
 
  # Install binary
  install -Dm 755 code.sh $pkgdir/usr/bin/code-oss
  install -Dm 755 code.js $pkgdir/usr/lib/$pkgname/code.js
  ln -sf /usr/bin/code-oss $pkgdir/usr/bin/code
 
  # Install appdata and desktop file
  install -Dm 644 $pkgname/resources/linux/code.appdata.xml $pkgdir/usr/share/metainfo/code-oss.appdata.xml
  install -Dm 644 $pkgname/resources/linux/code.desktop $pkgdir/usr/share/applications/code-oss.desktop
  install -Dm 644 VSCode-linux-x64/resources/app/resources/linux/code.png $pkgdir/usr/share/pixmaps/code-oss.png
 
  # Install license files
  install -Dm 644 VSCode-linux-x64/resources/app/LICENSE.txt $pkgdir/usr/share/licenses/$pkgname/LICENSE
  install -Dm 644 VSCode-linux-x64/resources/app/ThirdPartyNotices.txt $pkgdir/usr/share/licenses/$pkgname/ThirdPartyNotices.txt
}