Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework npm to drop buildchroot dependency #493

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 10 additions & 55 deletions classes/npm.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# - cp package-lock.json /path/to/recipe/files/npm-shrinkwrap.json

inherit dpkg-raw
inherit buildchroot

NPMPN ?= "${PN}"
NPM_SHRINKWRAP ?= "file://npm-shrinkwrap.json"
Expand Down Expand Up @@ -71,43 +70,26 @@ python() {
d.setVar('NPM_MAPPED_NAME', mapped_name)
}

BUILDROOT = "${BUILDCHROOT_DIR}/${PP}"
SCHROOT_MOUNTS = "${WORKDIR}"

npm_fetch_do_mounts() {
mkdir -p ${BUILDROOT}
sudo mount --bind ${WORKDIR} ${BUILDROOT}

buildchroot_do_mounts
schroot_create_configs
insert_mounts
}

npm_fetch_undo_mounts() {
i=0
while ! sudo umount ${BUILDROOT}; do
sleep 0.1
if [ `expr $i % 100` -eq 0 ] ; then
bbwarn "${BUILDROOT}: Couldn't unmount ($i), retrying..."
fi
if [ $i -ge 10000 ]; then
bbfatal "${BUILDROOT}: Couldn't unmount after timeout"
fi
i=`expr $i + 1`
done
sudo rmdir ${BUILDROOT}
remove_mounts
schroot_delete_configs
}

def get_npm_bundled_tgz(d):
return "{0}-{1}-bundled.tgz".format(d.getVar('NPM_MAPPED_NAME'),
d.getVar('PV'))

def runcmd(d, cmd, dir):
def runcmd(d, cmd):
import subprocess
import os

uid = os.geteuid()
gid = os.getegid()
chrootcmd = "sudo -E chroot --userspec={0}:{1} ".format(uid, gid)
chrootcmd += d.getVar('BUILDCHROOT_DIR')
chrootcmd += " sh -c 'cd {0}/{1}; {2}'".format(d.getVar('PP'), dir, cmd)
chrootcmd = "schroot -c {0} -- {1}".format(d.getVar('SBUILD_CHROOT'), cmd)
bb.note("Running " + chrootcmd)
(retval, output) = subprocess.getstatusoutput(chrootcmd)
if retval:
Expand All @@ -125,34 +107,6 @@ def apply_mirrors_in_shrinkwrap(path, pattern, subst):
with open(path, 'w') as f:
json.dump(data, f, indent=2)

do_install_npm() {
install_cmd="sudo -E chroot ${BUILDCHROOT_DIR} \
apt-get install -y -o Debug::pkgProblemResolver=yes \
--no-install-recommends"

npm_fetch_do_mounts

E="${@ bb.utils.export_proxies(d)}"
deb_dl_dir_import "${BUILDCHROOT_DIR}" ${BASE_DISTRO}-${BASE_DISTRO_CODENAME}
sudo -E chroot ${BUILDCHROOT_DIR} \
apt-get update \
-o Dir::Etc::sourcelist="sources.list.d/isar-apt.list" \
-o Dir::Etc::sourceparts="-" \
-o APT::Get::List-Cleanup="0"
${install_cmd} --download-only ${NPM_CLASS_PACKAGE}
deb_dl_dir_export "${BUILDCHROOT_DIR}" ${BASE_DISTRO}-${BASE_DISTRO_CODENAME}
${install_cmd} ${NPM_CLASS_PACKAGE}

npm_fetch_undo_mounts
}
do_install_npm[depends] += "${BUILDCHROOT_DEP}"
do_install_npm[depends] += "${@d.getVarFlag('do_apt_fetch', 'depends')}"
do_install_npm[depends] += "${@(d.getVar('NPM_CLASS_PACKAGE') + ':do_deploy_deb') if d.getVar('OWN_NPM_CLASS_PACKAGE') == '1' else ''}"
do_install_npm[lockfiles] += "${REPO_ISAR_DIR}/isar.lock"
do_install_npm[network] += "${TASK_USE_SUDO}"

addtask install_npm before do_fetch

python fetch_npm() {
import json, os, shutil, re

Expand Down Expand Up @@ -212,7 +166,7 @@ python fetch_npm() {
json_objs = {'dependencies': { npmpn: '' }}
json.dump(json_objs, outfile, indent=2)

runcmd(d, "npm ci --global-style --ignore-scripts --verbose", "fetch-tmp")
runcmd(d, "npm ci --global-style --ignore-scripts --verbose")

package_filename = "node_modules/" + npmpn + "/package.json"
with open(package_filename) as infile:
Expand All @@ -228,7 +182,7 @@ python fetch_npm() {

os.rename("node_modules/" + npmpn, "package")

runcmd(d, "tar czf package.tgz --exclude .bin package", "fetch-tmp")
runcmd(d, "tar czf package.tgz --exclude .bin package")

shutil.copyfile("package.tgz", bundled_tgz)
with open(bundled_tgz_hash, 'w') as hash_file:
Expand All @@ -239,6 +193,7 @@ python fetch_npm() {
}
do_fetch[postfuncs] += "fetch_npm"
do_fetch[cleandirs] += "${WORKDIR}/fetch-tmp"
do_fetch[depends] += "${SCHROOT_DEP}"

python clean_npm() {
import os
Expand Down
30 changes: 30 additions & 0 deletions isar-patches/0001-dpkg-source-Drop-I-filter.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
From f8f39f9722ebc24cd41e6c41bb22f8ebe9295414 Mon Sep 17 00:00:00 2001
From: Jan Kiszka <[email protected]>
Date: Thu, 12 Oct 2023 13:17:32 +0200
Subject: [PATCH] dpkg-source: Drop -I filter

This is a regression of 38b832ad8248 which added this while factoring
out this step. However, some packages may break over this, e.g. the
edk2-standalonemm-rpmb recipe in isar-cip-core.

Signed-off-by: Jan Kiszka <[email protected]>
---
meta/classes/dpkg-source.bbclass | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/meta/classes/dpkg-source.bbclass b/meta/classes/dpkg-source.bbclass
index 1f4f8164..a86b4635 100644
--- a/meta/classes/dpkg-source.bbclass
+++ b/meta/classes/dpkg-source.bbclass
@@ -12,7 +12,7 @@ do_dpkg_source() {
if [ ! -z "${SOURCE_DATE_EPOCH}" ]; then
export SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH}"
fi
- sh -c "cd ${WORKDIR}; dpkg-source -I -b ${PPS}"
+ sh -c "cd ${WORKDIR}; dpkg-source -b ${PPS}"
}
addtask dpkg_source after do_prepare_build before do_dpkg_build

--
2.35.3

6 changes: 4 additions & 2 deletions kas/iot2050.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@ repos:

isar:
url: https://github.com/ilbers/isar
commit: ecc7cae423a828d294575301c1584fbe303cba3e
commit: 6b6c74411074e3d3a08f044e681c3f1216727b6e
layers:
meta:
patches:
01:
path: isar-patches/0001-optee-client-Fix-native-arm64-build.patch
02:
path: isar-patches/0001-meta-optee-client-Generalize-and-update-shutdown-rul.patch
03:
path: isar-patches/0001-dpkg-source-Drop-I-filter.patch

cip-core:
url: https://gitlab.com/cip-project/cip-core/isar-cip-core.git
commit: 7d3a05b3351726c5c76912f5c73d4720f4a46b18
commit: 3d8e24c0cc6cb811b57648bd356bce2ae5e94795

local_conf_header:
standard: |
Expand Down