summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 4aec5fde13433db51757e598fcb3922ad428a867 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# Maintainer: Leonidas Spyropoulos <artafinde at gmail dot com>
# Contributor: James Brink <brink.james@gmail.com>
# Contributor: Wilson E. Alvarez <wilson.e.alvarez1@gmail.com>
# Contributor: p <parimal@beyond8labs.com>
# Contributor: Victor <victor@xirion.net>
# Contributor: Jan-Tarek Butt <tarek AT ring0 DOT de>
# Contributor: Erik Beran <eberan AT gmail DOT com>
# Contributor: Thor K. H. <thor at roht dot no>
# Contributor: Babken Vardanyan <483ken 4tgma1l
# Contributor: mikezackles
# Contributor: z33ky
# Contributor: stykr
# Contributor: Svenstaro
# Contributor: KaiSforza
# Contributor: Simon Gomizelj <simongmzlj@gmail.com>
# Contributor: Daniel Micay <danielmicay@gmail.com>
# Contributor: shmilee
# Contributor: foobster
# Contributor: archdria
# Contributor: Andy Weidenbaum <archbaum@gmail.com>
# Contributor: edacval
# Contributor: MarcelPa
# Contributor: Trent
# Contributor: urxvtcd-256

#=========================================================================================================#
#                                          Build Options                                                  #
#=========================================================================================================#
_gocode="y"
_tern="y"
_typescript="y"
_java="y"
_use_system_clang="ON"

_neovim="$NEOVIM_YOUCOMPLETEME"

#=========================================================================================================#
#                                    Default PKGBUILD Configuration                                       #
#=========================================================================================================#
pkgname=vim-youcompleteme-git
pkgver=r2711.d3db1cb3
pkgver() {
	cd "YouCompleteMe" || exit
	printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}
pkgrel=1
pkgdesc="A code-completion engine for Vim"
arch=('x86_64')
url='https://ycm-core.github.io/YouCompleteMe/'
license=('GPL3')
groups=('vim-plugins')
depends=('boost' 'boost-libs' 'python' 'nodejs' 'vim' 'clang' 'python-watchdog')
optdepends=('rustup: rust language support'
            'omnisharp-roslyn-http-bin: C# language support')
makedepends=('cmake' 'git' 'make' 'curl')
install="install.sh"
source=(
	'git+https://github.com/bottlepy/bottle.git'
	'git+https://github.com/certifi/python-certifi.git'
	'git+https://github.com/chardet/chardet.git'
	'git+https://github.com/davidhalter/jedi.git'
	'git+https://github.com/davidhalter/parso.git'
	'git+https://github.com/davidhalter/typeshed.git'
	'git+https://github.com/kjd/idna.git'
	'git+https://github.com/micbou/regex.git'
	'git+https://github.com/Pylons/waitress.git'
	'git+https://github.com/PythonCharmers/python-future.git'
	'git+https://github.com/requests/requests.git'
	'git+https://github.com/ross/requests-futures.git'
	'git+https://github.com/urllib3/urllib3.git'
	'git+https://github.com/ycm-core/ycmd.git'
	'git+https://github.com/ycm-core/YouCompleteMe.git'
	'omnisharp.patch'
	'rls.patch')

sha256sums=('SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'af76c1efa5468815d40d636748fa3f7d36f0d81dafa41bffcbb86c2f27df04b2'
            'e5c1bf356ca1c8034d64da11e8b41ceb48d1bb672d25d3b0d2ad12133438d344')

#=========================================================================================================#
#                                     Applying PKBUILD Build Options                                      #
#=========================================================================================================#

if [[ "$_gocode" == "y" ]]; then
	makedepends+=('go')
fi

if [[ "$_tern" == "y" ]]; then
	makedepends+=('npm')
fi

#=========================================================================================================#
#                                           Utility Functions                                             #
#=========================================================================================================#

gitprepare() {
	local cd_dir=$1
	local git_prefix=$2
	local c=0
	for val in "$@"; do
		if [ $c -gt 1 ]; then
			local feed[$c]=$val
		fi
		c=$((c + 1))
	done

	cd "$srcdir/$cd_dir" || exit

	git submodule init
	for gitsubvar in "${feed[@]}"; do
		git config submodule."$git_prefix$gitsubvar".url "$srcdir/$gitsubvar"
	done

	git submodule update
	unset -v feed
}

#=========================================================================================================#
#                                     Standard PKGBUILD Functions                                         #
#=========================================================================================================#

prepare() {
	# Add the java completion engine dynamically...
	if [[ "$_java" == "y" ]]; then
		echo 'Parsing out the JDTLS package version from upstream...'
		local jdtls_package_name="jdt-language-server"
		local jdtls_milestone=$(egrep '^JDTLS_MILESTONE' "$srcdir/ycmd/build.py" | sed -e "s/.* = //g" -e "s/'//g")
		local jdtls_buildstamp=$(egrep '^JDTLS_BUILD_STAMP' "$srcdir/ycmd/build.py" | sed -e "s/.* = //g" -e "s/'//g")

		if [[ "$jdtls_milestone" != "" ]] && [[ "$jdtls_buildstamp" != "" ]]; then
			local jdtls_full_url="http://download.eclipse.org/jdtls/snapshots/${jdtls_package_name}-${jdtls_milestone}-${jdtls_buildstamp}.tar.gz"
			echo "JDTLS package version matched. Downloading... ${jdtls_full_url}"
			curl -LO "${jdtls_full_url}"
			tar xf ${jdtls_package_name}-${jdtls_milestone}-${jdtls_buildstamp}.tar.gz
		else
			echo 'Mismatched JDTLS version'
			exit 1
		fi
	fi

	echo 'Setting up Git submodules...'

	local YouCompleteMe=("requests-futures" "ycmd" "python-future")
	local YouCompleteMeRequestsDeps=("idna" "python-certifi" "chardet" "urllib3" "requests")
	gitprepare "YouCompleteMe" "third_party/" "${YouCompleteMe[@]}"
	gitprepare "YouCompleteMe" "third_party/requests_deps/" "${YouCompleteMeRequestsDeps[@]}"

	local ycmd=("bottle" "regex" "python-future" "waitress")

	gitprepare "YouCompleteMe/third_party/ycmd" "third_party/" "${ycmd[@]}"

	local ycmdJediDeps=("jedi" "parso")
	gitprepare "YouCompleteMe/third_party/ycmd" "third_party/jedi_deps" "${ycmdJediDeps[@]}"

	local ycmdRequestsDeps=("python-certifi" "chardet" "idna" "requests" "urllib3")
	gitprepare "YouCompleteMe/third_party/ycmd" "third_party/requests_deps" "${ycmdRequestsDeps[@]}"

	local jedi=("typeshed")
	gitprepare "YouCompleteMe/third_party/ycmd/third_party/jedi_deps/jedi" "jedi/third_party/" "${jedi[@]}"

	if [[ "$_gocode" == "y" ]]; then
		ycmd+=("go-completer")
	fi

	# Apply our patch to use existing rustup toolchains
	cd "$srcdir/YouCompleteMe/third_party/ycmd/" || exit
	patch -N -p1 -r - < ../../../rls.patch || echo "Patch already applied"

	# Apply our patch to use AUR omnisharp-http-bin
	cd "$srcdir/YouCompleteMe/third_party/ycmd/" || exit
	patch -N -p1 -r - < ../../../omnisharp.patch || echo "Patch already applied"
}

build() {
	echo 'Purging unneeded files...'
	rm -r "$srcdir/YouCompleteMe/python/ycm/tests"

	echo 'Building ycmd...' # BuildYcmdLibs()
	mkdir -p "$srcdir/ycmd_build"
	cd "$srcdir/ycmd_build" || exit
	cmake -G "Unix Makefiles" -DUSE_SYSTEM_LIBCLANG="$_use_system_clang" . "$srcdir/YouCompleteMe/third_party/ycmd/cpp"
	make ycm_core

	if [[ "$_gocode" == "y" ]]; then
		local _local_GOPATH="$srcdir"/YouCompleteMe/third_party/ycmd/third_party/go
		mkdir ${_local_GOPATH} || exit
		cd ${_local_GOPATH} || exit
		GO111MODULE=on GOPATH=${_local_GOPATH} go get -trimpath golang.org/x/tools/gopls@v0.4.0
		GO111MODULE=on GOPATH=${_local_GOPATH} go clean -modcache
	else
		echo 'Skipping Gocode completer...'
	fi

	if [[ "$_typescript" == "y" ]]; then
		echo 'Building Typescipt completer...'
		cd "$srcdir/YouCompleteMe/third_party/ycmd/" || exit
		npm install -g --prefix third_party/tsserver typescript
	else
		echo 'Skipping Typescipt completer...'
	fi

	if [[ "$_tern" == "y" ]]; then
		echo 'Building Tern completer...'
		cd "$srcdir/YouCompleteMe/third_party/ycmd/third_party/tern_runtime" || exit
		npm install --production --python=python3
	else
		echo 'Skipping Tern completer...'
	fi

	if [[ "$_java" == "y" ]]; then
		echo 'Injecting Java completer...'

		# Remove stale java completer data if any
		rm -rf "$srcdir/YouCompleteMe/third_party/ycmd/third_party/eclipse.jdt.ls/target/repository"

		# Continue populating directory
		mkdir -p "$srcdir/YouCompleteMe/third_party/ycmd/third_party/eclipse.jdt.ls/target/repository"
		mv "$srcdir"/{config_linux,features,plugins} "$srcdir/YouCompleteMe/third_party/ycmd/third_party/eclipse.jdt.ls/target/repository"
	else
		echo 'Skipping Java completer...'
	fi
}

package() {
	local vimfiles_dir=usr/share/vim/vimfiles
	if [[ "$_neovim" == "y" ]]; then
		vimfiles_dir=usr/share/nvim/runtime
	fi

	mkdir -p "$pkgdir/$vimfiles_dir/third_party/ycmd/third_party/requests_deps"
	mkdir -p "$pkgdir/$vimfiles_dir/third_party/ycmd/third_party/jedi_deps"

	mkdir -p "$pkgdir/$vimfiles_dir/third_party/requests_deps"

	cp -r "$srcdir/YouCompleteMe/"{autoload,doc,plugin,python} \
		"$pkgdir/$vimfiles_dir"
	cp -r "$srcdir/YouCompleteMe/third_party/requests-futures" \
		"$pkgdir/$vimfiles_dir/third_party"
	cp -r "$srcdir/YouCompleteMe/third_party/requests_deps/"{certifi,chardet,idna,requests,urllib3} \
		"$pkgdir/$vimfiles_dir/third_party/requests_deps"

	cp -r "$srcdir/YouCompleteMe/third_party/ycmd/"{ycmd,ycm_core.so,CORE_VERSION} \
		"$pkgdir/$vimfiles_dir/third_party/ycmd"
	cp -r "$srcdir/YouCompleteMe/third_party/ycmd/third_party/"{bottle,clang,cregex,waitress} \
		"$pkgdir/$vimfiles_dir/third_party/ycmd/third_party"
	cp -r "$srcdir/YouCompleteMe/third_party/ycmd/third_party/requests_deps/"{certifi,chardet,idna,requests,urllib3} \
		"$pkgdir/$vimfiles_dir/third_party/ycmd/third_party/requests_deps"
	cp -r "$srcdir/YouCompleteMe/third_party/ycmd/third_party/jedi_deps/"{jedi,parso} \
		"$pkgdir/$vimfiles_dir/third_party/ycmd/third_party/jedi_deps"

	if [[ "$_gocode" == "y" ]]; then
		cp -r "$srcdir/YouCompleteMe/third_party/ycmd/third_party/go" \
			"$pkgdir/$vimfiles_dir/third_party/ycmd/third_party/go"
	fi

	if [[ "$_tern" == "y" ]]; then
		cp -r "$srcdir/YouCompleteMe/third_party/ycmd/third_party/tern_runtime" \
			"$pkgdir/$vimfiles_dir/third_party/ycmd/third_party"
	fi

	if [[ "$_typescript" == "y" ]]; then
		cp -r "$srcdir/YouCompleteMe/third_party/ycmd/third_party/tsserver" \
			"$pkgdir/$vimfiles_dir/third_party/ycmd/third_party"
	fi

	if [[ "$_java" == "y" ]]; then
		mv "$srcdir/YouCompleteMe/third_party/ycmd/third_party/eclipse.jdt.ls" "$pkgdir/$vimfiles_dir/third_party/ycmd/third_party"
		# Force the java completion engine to create its workspace at /tmp instead which is writeable by every user
		ln -sf /tmp "$pkgdir/$vimfiles_dir/third_party/ycmd/third_party/eclipse.jdt.ls/workspace"
	fi

	# Remove all the unnecessary git repositories
	find "$pkgdir" -name .git -exec rm -fr {} +

	# Remove tests files
	find "$pkgdir" -name tests -exec rm -fr {} +

	# Remove unneeded docs
	find "$pkgdir" -name docs -exec rm -fr {} +

	# Finally compile all the python files to bytecode.
	python3 -m compileall "$pkgdir" || :
}