From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6542765999964291072 X-Received: by 10.46.80.11 with SMTP id e11mr310575ljb.3.1524135716241; Thu, 19 Apr 2018 04:01:56 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 10.46.156.71 with SMTP id t7ls738656ljj.11.gmail; Thu, 19 Apr 2018 04:01:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+qp6EP4pqqJxNM94WEyAB+72Fm3pPFwlcgHFmSUNcwNz7nIHsPnn6E/RvWkFQgvzbQ3UOB X-Received: by 10.46.156.198 with SMTP id g6mr335796ljj.25.1524135715781; Thu, 19 Apr 2018 04:01:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524135715; cv=none; d=google.com; s=arc-20160816; b=IWb60YTR2aUht+Miji4x0WBM5jCcMxObWviczV8N+8Q+rIxkitWzCH7FakVis49Pxi x8LdxpAAhH3wl8Iz1IGVoC6CkSX34bFc6SrIsdyjwMb4wi8UmlYvOXDheel+yrYZvECg gLbA4MNJUJdSGRCjlyO69M8oJNPXgSvTfkob9q8UqB8gYjUXquK2ivA67O1p2RL0Aipl yGqANc/tLjS+DO2h9jkG+n18/WeRI56bC2cvxfX3yyweKd+X2nAugCEHuU3MI0uSvPXC JNv51uiXR+zNBvT3knun+USrfCbv3hRSgm7u17CZ0XMfV0ufBFJLVx4EQWOmLwXQnmey cTgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=IGqXO17pBsqZQ40KuW7k9eqykAJC2Qn11ghtjzN10uQ=; b=vu1EEyjkCZq3iB9fEj5CxVhiUS6uzqyLmVbuMGLl2Yps3RNa3of+cWMLCu5TR0JeuV 1Fpk+F4SgFA2R6g0QiunJ8EkpySDoVzSoA+op+4ZMpPEsMtXMUK58M9hHXn+xDDGy+L3 A+X21MgAx5M18LtRXL+UukLPn+TBXV1irvVO2TTELqQwNCkJYddkIQGPgSECeC8/x4Cy 7wsEQDFI+ruM4MidxOrP5shfLeclTivCodaPJqE+yvPKreegU4Afk5XEU9gwc2jiisfJ oY4WlLedvJJRNHtS8VwFBh5rg3rwHKDDzJzuKIA/NEQ6kDxFCiS7PMZjfw0LEx+uCLG6 HEXw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of claudius.heine.ext@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=claudius.heine.ext@siemens.com Return-Path: Received: from david.siemens.de (david.siemens.de. [192.35.17.14]) by gmr-mx.google.com with ESMTPS id u16si115945ljg.4.2018.04.19.04.01.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Apr 2018 04:01:55 -0700 (PDT) Received-SPF: pass (google.com: domain of claudius.heine.ext@siemens.com designates 192.35.17.14 as permitted sender) client-ip=192.35.17.14; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of claudius.heine.ext@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=claudius.heine.ext@siemens.com Received: from mail2.sbs.de (mail2.sbs.de [192.129.41.66]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id w3JB1sSw014906 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Apr 2018 13:01:54 +0200 Received: from ring.ppmd.siemens.net (linux-ses-ext02.ppmd.siemens.net [139.25.69.226]) by mail2.sbs.de (8.15.2/8.15.2) with ESMTP id w3JB1sFQ017289; Thu, 19 Apr 2018 13:01:54 +0200 From: claudius.heine.ext@siemens.com To: isar-users@googlegroups.com Cc: Claudius Heine Subject: [PATCH v2 1/1] isar-bootstrap: implement DISTRO_APT_PREMIRRORS feature Date: Thu, 19 Apr 2018 13:01:48 +0200 Message-Id: <20180419110148.21749-2-claudius.heine.ext@siemens.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180419110148.21749-1-claudius.heine.ext@siemens.com> References: <20180419110148.21749-1-claudius.heine.ext@siemens.com> X-TUID: 82ACrEbAP/nO From: Claudius Heine With this patch its now possible to overwrite Debian repositories from the 'DISTRO_APT_PREMIRRORS' variable. The format of this variable is similar to how OpenEmbedded handels the PREMIRRORS variable: DISTRO_APT_PREMIRRORS = "source-uri-regex1 replace-uri-string1 \n \ source-uri-regex1 replace-uri-string2 \n \ ... " So for instance to select a different debian upstream mirror: DISTRO_APT_PREMIRRORS += "ftp\.(\S+\.)?debian.org ftp.us.debian.org \n" Signed-off-by: Claudius Heine --- .../isar-bootstrap/isar-bootstrap.bb | 50 ++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/meta/recipes-core/isar-bootstrap/isar-bootstrap.bb b/meta/recipes-core/isar-bootstrap/isar-bootstrap.bb index a38dd88..cbf6ddb 100644 --- a/meta/recipes-core/isar-bootstrap/isar-bootstrap.bb +++ b/meta/recipes-core/isar-bootstrap/isar-bootstrap.bb @@ -83,7 +83,44 @@ def parse_aptsources_list_line(source_list_line): components = " ".join(s.split()) - return type, options, source, suite, components + return [type, options, source, suite, components] + +def get_apt_source_mirror(d, aptsources_entry_list): + import re + + premirrors = d.getVar('DISTRO_APT_PREMIRRORS', True) or "" + mirror_list = [entry.split() + for entry in premirrors.split('\\n') + if any(entry)] + + for regex, replace in mirror_list: + match = re.search(regex, aptsources_entry_list[2]) + + if match: + new_aptsources_entry_list = aptsources_entry_list.copy() + new_aptsources_entry_list[2] = re.sub(regex, replace, + aptsources_entry_list[2], + count = 1) + return new_aptsources_entry_list + + return aptsources_entry_list + +def aggregate_aptsources_list(d, file_list, file_out): + import shutil + + with open(file_out, "wb") as out_fd: + for entry in file_list: + entry_real = bb.parse.resolve_file(entry, d) + with open(entry_real, "r") as in_fd: + for line in in_fd: + parsed = parse_aptsources_list_line(line) + if parsed: + parsed = get_apt_source_mirror(d, parsed) + out_fd.write(" ".join(parsed).encode()) + else: + out_fd.write(line.encode()) + out_fd.write("\n".encode()) + out_fd.write("\n".encode()) def get_distro_primary_source_entry(d): apt_sources_list = (d.getVar("DISTRO_APT_SOURCES", True) or "").split() @@ -93,10 +130,10 @@ def get_distro_primary_source_entry(d): for line in in_fd: parsed = parse_aptsources_list_line(line) if parsed: - type, _, source, suite, components = parsed - if type == "deb": - return source, suite, components - return "", "", "" + parsed = get_apt_source_mirror(d, parsed) + if parsed[0] == "deb": + return parsed[2:] + return ["", "", ""] def get_distro_source(d): return get_distro_primary_source_entry(d)[0] @@ -141,12 +178,13 @@ python do_apt_config_prepare() { apt_sources_out = d.getVar("APTSRCS", True) apt_sources_list = (d.getVar("DISTRO_APT_SOURCES", True) or "").split() - aggregate_files(d, apt_sources_list, apt_sources_out) + aggregate_aptsources_list(d, apt_sources_list, apt_sources_out) } addtask apt_config_prepare before do_build after do_generate_keyring do_bootstrap[stamp-extra-info] = "${DISTRO}-${DISTRO_ARCH}" do_bootstrap[vardeps] += "DISTRO_APT_SOURCES" +do_bootstrap[vardeps] += "DISTRO_APT_PREMIRRORS" do_bootstrap() { if [ -e "${ROOTFSDIR}" ]; then sudo umount -l "${ROOTFSDIR}/dev" || true -- 2.17.0