forked from eclipse-leda/meta-leda
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extends info in os-release file (#5)
Extends the information in /etc/os-release file
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# /******************************************************************************** | ||
# * Copyright (c) 2022 Contributors to the Eclipse Foundation | ||
# * | ||
# * See the NOTICE file(s) distributed with this work for additional | ||
# * information regarding copyright ownership. | ||
# * | ||
# * This program and the accompanying materials are made available under the | ||
# * terms of the Apache License 2.0 which is available at | ||
# * https://www.apache.org/licenses/LICENSE-2.0 | ||
# * | ||
# * SPDX-License-Identifier: Apache-2.0 | ||
# ********************************************************************************/ | ||
# | ||
# Adds additional fields to /etc/os-release | ||
# The fields are semantically defined by https://www.freedesktop.org/software/systemd/man/os-release.html | ||
# | ||
# Example output in ./tmp/sysroots-components/all/os-release/usr/lib/os-release: | ||
# | ||
# ID=leda | ||
# NAME="Eclipse Leda" | ||
# VERSION="2022 (Hockenheim)" | ||
# VERSION_ID=v0.0.23-31-g64893dc | ||
# PRETTY_NAME="Eclipse Leda 2022 (Hockenheim)" | ||
# VERSION_CODENAME="Hockenheim" | ||
# IMAGE_ID="None" | ||
# IMAGE_MACHINE_ID="None" | ||
# IMAGE_VERSION="v0.0.23-31-g64893dc" | ||
# VERSION_ID=v0.0.23-31-g64893dc | ||
# BUILD_ID="20220901131248" | ||
# | ||
|
||
inherit features_check | ||
|
||
REQUIRED_DISTRO_FEATURES = "sdv" | ||
|
||
FILESEXTRAPATHS:prepend := "${THISDIR}/${BPN}:" | ||
|
||
DEPENDS = "git-native" | ||
|
||
# Always regenerate the /etc/os-release file to keep the metadata up to date | ||
do_compile[nostamp]="1" | ||
|
||
def exec_git_run(cmd, path): | ||
(output, error) = bb.process.run(cmd, cwd=path) | ||
return output.rstrip() | ||
|
||
python do_compile:prepend() { | ||
if bb.utils.contains('DISTRO_FEATURES', 'sdv', True, False, d): | ||
# Add additional fields to /etc/os-release | ||
fields = set((d.getVar('OS_RELEASE_FIELDS') or "").split()) | ||
fields.add("VERSION_CODENAME") | ||
fields.add("IMAGE_VERSION") | ||
fields.add("VERSION_ID") | ||
fields.add("BUILD_ID") | ||
d.setVar('OS_RELEASE_FIELDS', ' '.join(sorted(fields))) | ||
|
||
# Default fallback is just the version of the distro ("2022") | ||
layerRev = d.getVar("DISTRO_VERSION") | ||
path = d.getVar("TOPDIR") or d.getVar("BUILD_DIR") | ||
try: | ||
ver = exec_git_run("git describe --tags", path) | ||
layerRev = ver | ||
except Exception as exc: | ||
bb.warn('Exception executing git, falling back to DISTRO_VERSION', exc) | ||
|
||
d.setVar("VERSION_CODENAME", d.getVar("DISTRO_CODENAME")) | ||
d.setVar("IMAGE_VERSION", layerRev) | ||
d.setVar("VERSION_ID", layerRev) | ||
} |