diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-11-02 11:34:21 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-11-11 10:54:32 +0000 |
commit | afe0ef0a074b23fc5f1c39ed7fd345f7b75973c7 (patch) | |
tree | d9dfeaf99905ecff827ba1b1f26c752cf822b04d /scripts/contrib | |
parent | ea2d42c2b110cb953dad051b3720d85575bd2b82 (diff) | |
download | poky-afe0ef0a074b23fc5f1c39ed7fd345f7b75973c7.tar.gz |
scripts/convert-srcuri: Backport SRC_URI conversion script from master branch
This script handles two emerging issues:
1. There is uncertainty about the default branch name in git going forward.
To try and cover the different possible outcomes, add branch names to all
git:// and gitsm:// SRC_URI entries.
2. Github are dropping support for git:// protocol fetching, so remap github
urls as needed. For more details see:
https://github.blog/2021-09-01-improving-git-protocol-security-github/
(From OE-Core rev: 904bdbab712e2f3c332c4d85d08ed83c957e249f)
Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/contrib')
-rwxr-xr-x | scripts/contrib/convert-srcuri.py | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/scripts/contrib/convert-srcuri.py b/scripts/contrib/convert-srcuri.py new file mode 100755 index 0000000000..5b362ea2e8 --- /dev/null +++ b/scripts/contrib/convert-srcuri.py | |||
@@ -0,0 +1,77 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | # | ||
3 | # Conversion script to update SRC_URI to add branch to git urls | ||
4 | # | ||
5 | # Copyright (C) 2021 Richard Purdie | ||
6 | # | ||
7 | # SPDX-License-Identifier: GPL-2.0-only | ||
8 | # | ||
9 | |||
10 | import re | ||
11 | import os | ||
12 | import sys | ||
13 | import tempfile | ||
14 | import shutil | ||
15 | import mimetypes | ||
16 | |||
17 | if len(sys.argv) < 2: | ||
18 | print("Please specify a directory to run the conversion script against.") | ||
19 | sys.exit(1) | ||
20 | |||
21 | def processfile(fn): | ||
22 | def matchline(line): | ||
23 | if "MIRROR" in line or ".*" in line or "GNOME_GIT" in line: | ||
24 | return False | ||
25 | return True | ||
26 | print("processing file '%s'" % fn) | ||
27 | try: | ||
28 | if "distro_alias.inc" in fn or "linux-yocto-custom.bb" in fn: | ||
29 | return | ||
30 | fh, abs_path = tempfile.mkstemp() | ||
31 | modified = False | ||
32 | with os.fdopen(fh, 'w') as new_file: | ||
33 | with open(fn, "r") as old_file: | ||
34 | for line in old_file: | ||
35 | if ("git://" in line or "gitsm://" in line) and "branch=" not in line and matchline(line): | ||
36 | if line.endswith('"\n'): | ||
37 | line = line.replace('"\n', ';branch=master"\n') | ||
38 | elif line.endswith(" \\\n"): | ||
39 | line = line.replace(' \\\n', ';branch=master \\\n') | ||
40 | modified = True | ||
41 | if ("git://" in line or "gitsm://" in line) and "github.com" in line and "protocol=https" not in line and matchline(line): | ||
42 | if "protocol=git" in line: | ||
43 | line = line.replace('protocol=git', 'protocol=https') | ||
44 | elif line.endswith('"\n'): | ||
45 | line = line.replace('"\n', ';protocol=https"\n') | ||
46 | elif line.endswith(" \\\n"): | ||
47 | line = line.replace(' \\\n', ';protocol=https \\\n') | ||
48 | modified = True | ||
49 | new_file.write(line) | ||
50 | if modified: | ||
51 | shutil.copymode(fn, abs_path) | ||
52 | os.remove(fn) | ||
53 | shutil.move(abs_path, fn) | ||
54 | except UnicodeDecodeError: | ||
55 | pass | ||
56 | |||
57 | ourname = os.path.basename(sys.argv[0]) | ||
58 | ourversion = "0.1" | ||
59 | |||
60 | if os.path.isfile(sys.argv[1]): | ||
61 | processfile(sys.argv[1]) | ||
62 | sys.exit(0) | ||
63 | |||
64 | for targetdir in sys.argv[1:]: | ||
65 | print("processing directory '%s'" % targetdir) | ||
66 | for root, dirs, files in os.walk(targetdir): | ||
67 | for name in files: | ||
68 | if name == ourname: | ||
69 | continue | ||
70 | fn = os.path.join(root, name) | ||
71 | if os.path.islink(fn): | ||
72 | continue | ||
73 | if "/.git/" in fn or fn.endswith(".html") or fn.endswith(".patch") or fn.endswith(".m4") or fn.endswith(".diff"): | ||
74 | continue | ||
75 | processfile(fn) | ||
76 | |||
77 | print("All files processed with version %s" % ourversion) | ||