---
# System prepended metadata

title: ebuild dependency
tags: [elkurin-daily-note]

---

# ebuild dependency
[ebuild](https://wiki.gentoo.org/wiki/Ebuild) is a file used as a package manager of Gentoo.  
This is currently used as [chromeos build system](https://chromium.googlesource.com/chromiumos/docs/+/HEAD/portage/ebuild_faq.md).

([Dependencies](https://devmanual.gentoo.org/general-concepts/dependencies/) doc)

## What is ebuild file?
ebuild script has a name with "package name"-"version".ebuild.  
It must contain
- DESCRIPTION: the description of the package
- SRC_URI: provider
- LICENSE: software license
- DEPEND: the dependency chain

DESCRIPTION, SRC_URI and LICENSE is very clear.  
This note focuses on DEPEND section.


## DEPEND
When unpacking, installing or compiling a package, it may depends on other packages. DEPEND specify such dependency chains.  
By containing only the direct children in DEPEND, the indirect dependency will be calculated automtically by Portage.

### Dependency types
Before checking the types of dependency attributes, let's go through CBUILD and CHOST.  
CBUILD is the system on which the build is performced while CHOST is the system on which the package is going to be executed.  
CHOST cannot be exuected on cross-compiling environment. CBUILD, on the other hand, can be executed during the build time and works on cross-compiling.

Now, here are the types of dependency.
- DEPEND: dependency applicable to CHOST
- BDEPEND: dependency applicable to CBUILD
- RDEPEND: dependency required at runtime.
- PDEPEND: dependency wanted at runtime but does not have to be satisfied immediately.

RDEPEND includes libraries when dynamically linked, any data packages and the relevnt interpreter. RDEPEND is the only dependency checked on installing from a binary pckage.  
PDEPEND can wait. It can be merged after the package.

## Dependency syntax
### Version
Sometimes, we can specify the version to use. For such use case, ebuild supports the version specifiers.

`>=app-misc/foo-1.23` indicates the package app-misc/foo of 1.23 or later is required.  
`~app-misc/foo-1.23` indicates the Version 1.23 or `1.23-r*` is required. `r*` is a revision number.

### Blockers
When two packages can nnot be installed simultaneously, we can specify blockers to avoid the conflict.  
We use `!` to specify the blocker.

```
media-libs/mesa-img
!media-libs/mesa
```
This syntax shows that media-libs/mesa is marked as a weak blocker. The package blocked by a weak blocker can be uninstalled after installing the package blocking it.  
You can use `!!` to mark it as a strong blocker if it's strictly required to resolve the blocker before the package build/install. 


### Slot operators
[SLOT](https://devmanual.gentoo.org/general-concepts/slotting/index.html) is a group of the packages with the specified versions. It's a bit similar to the concept of version. This is used to avoid the conflict.

In ebuild file, there may be a variable named `SLOT` like `SLOT="1.2"`.  
Let's think with the example. Suppose we have following packaged:
- foo-1.1 with SLOT="1"
- foo-1.2 with SLOT="1"
- foo-2.0 with SLOT="2"
- foo-2.1 with SLOT="2"

Then we can install foo-1.2 and foo-2.0 in parallel, but not foo-1.1 and foo-1.2.  
The same package with the different slots can avoid the conflict.

If DEPEND has `dev-qt/qtcore:5`, it requires a packge `qtcors` with SLOT 5.

Slot operators is a syntax appended to the package name to declare whether or not your package should be rebuilt after the versions satisfying its runtime dependencies are updated.  
For example, `media-libs/cogl:1.0=` means only 1.0 slot is acceptable.  
If it ends with `:=`, then it implies any slot is acceptable.

### if flag
You can use if condition like this: `perl? ( dev-lang/perl )`.  
`perl` in this example must be a USE flag.

### Any of Many dependency
If you only need one of several packages to depend, you can use this syntax.  
`|| ( app-misc/foo app-misc/bar )` works as you require either of foo or bar. If one of them is ready, it won't continue resolving the dependency for the other.

## Example: chromeos-chrome-9999.ebuild
Now let's look at the example [chromeos-chrome-9999.ebuild](https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/third_party/chromiumos-overlay/chromeos-base/chromeos-chrome/chromeos-chrome-9999.ebuild).  
This is used to build chrome for chromeos.  
`9999` implies this is a default (not depending on a version number.)

```
RDEPEND="${RDEPEND}
  app-arch/bzip2
  ...
  ~chromeos-base/chrome-icu-${PV}
  ...
  chromeos-base/libevdev:=
  ...
  fonts? ( chromeos-base/chromeos-fonts )
  ...
  >=dev-libs/nss-3.12.2
  ...
  vaapi? ( x11-libs/libva:= )
```
Now we can read this. There are many syntax described in the previous section.

We also have DEPEND and BDEPEND variables.  
DEPEND includes all of RDEPEND.
```
DEPEND="${DEPEND}
	${RDEPEND}
	chromeos-base/protofiles
	>=dev-util/gperf-3.0.3
	arm? ( x11-libs/libdrm )
"
```

The USE flag here is specified by [IUSE](https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/third_party/chromiumos-overlay/chromeos-base/chromeos-chrome/chromeos-chrome-9999.ebuild;l=27-85;drc=fbc2560b6970eb29210632579a857d287ad4bb13).