summaryrefslogtreecommitdiff
path: root/meta-arm/ci/update-repos
blob: 9487102df1a1c4a34d493c3f15dc85f899642eef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /usr/bin/env python3

# Update clones of the repositories we need in KAS_REPO_REF_DIR to speed up fetches

import sys
import os
import shutil
import subprocess
import pathlib

def repo_shortname(url):
    # Taken from Kas (Repo.__getattr__) to ensure the logic is right
    from urllib.parse import urlparse
    url = urlparse(url)
    return ('{url.netloc}{url.path}'
            .format(url=url)
            .replace('@', '.')
            .replace(':', '.')
            .replace('/', '.')
            .replace('*', '.'))

repositories = (
    "https://git.yoctoproject.org/git/poky",
    "https://git.openembedded.org/meta-openembedded",
    "https://git.yoctoproject.org/git/meta-virtualization",
    "https://github.com/kraj/meta-clang",
)

if __name__ == "__main__":
    if "KAS_REPO_REF_DIR" not in os.environ:
        print("KAS_REPO_REF_DIR needs to be set")
        sys.exit(1)

    base_repodir = pathlib.Path(os.environ["KAS_REPO_REF_DIR"])

    for repo in repositories:
        repodir = base_repodir / repo_shortname(repo)

        if "CI_CLEAN_REPOS" in os.environ:
            print("Cleaning %s..." % repo)
            shutil.rmtree(repodir, ignore_errors=True)

        if repodir.exists():
            print("Updating %s..." % repo)
            subprocess.run(["git", "-C", repodir, "-c", "gc.autoDetach=false", "fetch"], check=True)
        else:
            print("Cloning %s..." % repo)
            subprocess.run(["git", "clone", "--bare", repo, repodir], check=True)