summaryrefslogtreecommitdiff
path: root/eclass/bintron-r1.eclass
blob: 76c8ccc0b7d4c32684c34ed6ef01944a6f464115 (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
# Copyright 2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# @ECLASS: bintron-r1.eclass
# @MAINTAINER:
# src_prepare group
# @AUTHOR:
# Alfred Wingate <parona@protonmail.com>
# @SUPPORTED_EAPIS: 8
# @PROVIDES: chromium-2 xdg
# @BLURB: Common configuration eclass for binary packages built with Electron
# @DESCRIPTION:
# This eclass is used in Electron packages ebuilds

case ${EAPI} in
	8) ;;
	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac

if [[ ! ${_BINTRON_R1_ECLASS} ]]; then
_BINTRON_R1_ECLASS=1

inherit chromium-2 xdg

IUSE="system-ffmpeg"

# musl support?
RDEPEND="
	app-accessibility/at-spi2-core:2
	dev-libs/expat
	dev-libs/glib:2
	dev-libs/nspr
	dev-libs/nss
	media-libs/alsa-lib
	media-libs/mesa
	net-print/cups
	sys-apps/dbus
	sys-libs/glibc
	x11-libs/cairo
	x11-libs/gtk+:3
	x11-libs/libX11
	x11-libs/libXcomposite
	x11-libs/libXdamage
	x11-libs/libXext
	x11-libs/libXfixes
	x11-libs/libXrandr
	x11-libs/libdrm
	x11-libs/libxcb
	x11-libs/libxkbcommon
	x11-libs/pango
	system-ffmpeg? ( >=media-video/ffmpeg-4.3[chromium] )
"
BDEPEND="
	app-alternatives/gzip
	dev-util/patchelf
"
IDEPEND="
	sys-apps/file
	sys-apps/findutils
"

# @VARIABLE: QA_PREBUILT
# @INTERNAL
# @DESCRIPTION:
# QA variable

# @VARIABLE: QA_PRESTRIPPED
# @INTERNAL
# @DESCRIPTION:
# QA variable

# The package will be already compiled,
# also most likely the package will be pre-stripped too.
QA_PREBUILT='*'
QA_PRESTRIPPED='*'

# @ECLASS_VARIABLE: BINTRON_NAME
# @PRE_INHERIT
# @DESCRIPTION:
# Name of the package
: ${BINTRON_NAME:="${PN}"}

# @ECLASS_VARIABLE: BINTRON_HOME
# @DESCRIPTION:
# Path where the package contents will we installed.
: ${BINTRON_HOME:="/opt/${BINTRON_NAME}/"}

# @ECLASS_VARIABLE: BINTRON_EXECUTABLES
# @DESCRIPTION:
# List of executable symlinks to create
: ${BINTRON_EXECUTABLES:="${BINTRON_NAME}"}

# @FUNCTION: bintron-r1_pkg_pretend
# @DESCRIPTION:
# Runs SUID and User namespace checks
bintron-r1_pkg_pretend() {
	# see https://github.com/electron/electron/issues/17972
	chromium_suid_sandbox_check_kernel_config
}

# @FUNCTION: bintron-r1_src_prepare
# @DESCRIPTION:
# Remove pak files.
bintron-r1_src_prepare() {
	default

	pushd locales >/dev/null || die "location change for language cleanup failed"
	chromium_remove_language_paks
	popd >/dev/null || die "location reset for language cleanup failed"

	if [[ -d "${WORKDIR}/usr/share/doc/${BINTRON_NAME}" ]]; then
		mv "${WORKDIR}/usr/share/doc/${BINTRON_NAME}/" "${WORKDIR}/usr/share/doc/${PF}" || die
	fi

	if [[ -e "${WORKDIR}/usr/share/doc/${PF}/changelog.gz" ]]; then
		pushd "${WORKDIR}/usr/share/doc/${PF}" >/dev/null || die
		unpack "${WORKDIR}"/usr/share/doc/${PF}/changelog.*
		rm "${WORKDIR}"/usr/share/doc/${PF}/changelog.*
		popd >/dev/null || die
	fi

	if use system-ffmpeg; then
		rm libffmpeg.so || die

		local file type
		for file in $(find .); do
			type=$(file -b --mime-type "${file}")
			case ${type} in
				application/x-sharedlib|application/x-executable|application/x-pie-executable)
					patchelf --add-rpath /usr/$(get_libdir)/chromium ${file} || die
					;;
			esac
		done
	fi
}

# @FUNCTION: bintron-r1_src_install
# @DESCRIPTION:
# Install
bintron-r1_src_install() {
	insinto "${BINTRON_HOME}"

	doins -r "${S}"/*

	local file type
	for file in $(find . -type f); do

		# node_modules *shouldn't* have anything which requires executable permissions
		if [[ ${file} =~ /node_modules/ ]]; then
			continue
		fi

		type=$(file -b --mime-type "${file}")

		case ${type} in
			application/x-sharedlib|application/x-executable|application/x-pie-executable|text/x-shellscript)
				fperms 0755 "${BINTRON_HOME}${file#./}"
				;;
		esac
	done

	for executable in ${BINTRON_EXECUTABLES[@]}; do
		dosym "${EPREFIX}${BINTRON_HOME%/}/${executable}" /usr/bin/${executable}
	done

	if [[ -d ${WORKDIR}/usr/share ]]; then
		insinto /usr
		doins -r "${WORKDIR}"/usr/share
	fi
}

fi

EXPORT_FUNCTIONS pkg_pretend src_prepare src_install