public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH 0/1] isar-bootstrap support for changing repo url
@ 2018-04-10 10:33 claudius.heine.ext
  2018-04-10 10:33 ` [PATCH 1/1] isar-bootstrap: implement DISTRO_APT_PREMIRRORS feature claudius.heine.ext
  0 siblings, 1 reply; 2+ messages in thread
From: claudius.heine.ext @ 2018-04-10 10:33 UTC (permalink / raw)
  To: isar-users; +Cc: Claudius Heine

From: Claudius Heine <ch@denx.de>

Hi,

this patch contains the support of changing the apt repo url via bitbake
variables for isar-bootstrap.

Cheers,
Claudius

Claudius Heine (1):
  isar-bootstrap: implement DISTRO_APT_PREMIRRORS feature

 meta/recipes-core/isar-bootstrap/isar-bootstrap.bb | 50 +++++++++++++++++++---
 1 file changed, 44 insertions(+), 6 deletions(-)

-- 
2.16.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 1/1] isar-bootstrap: implement DISTRO_APT_PREMIRRORS feature
  2018-04-10 10:33 [PATCH 0/1] isar-bootstrap support for changing repo url claudius.heine.ext
@ 2018-04-10 10:33 ` claudius.heine.ext
  0 siblings, 0 replies; 2+ messages in thread
From: claudius.heine.ext @ 2018-04-10 10:33 UTC (permalink / raw)
  To: isar-users; +Cc: Claudius Heine

From: Claudius Heine <ch@denx.de>

With this patch its now possible to overwrite Debian repositories from
the 'APT_PREMIRRORS' variable.

The format of this variable is similar to how OpenEmbedded handels the
PREMIRROS 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 <ch@denx.de>
---
 meta/recipes-core/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..3fbf890 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.16.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-04-10 10:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-10 10:33 [PATCH 0/1] isar-bootstrap support for changing repo url claudius.heine.ext
2018-04-10 10:33 ` [PATCH 1/1] isar-bootstrap: implement DISTRO_APT_PREMIRRORS feature claudius.heine.ext

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox