diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-10-29 13:20:57 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-10-30 18:56:47 +0100 |
commit | ddcf16d1f792153f7f7fec4b1dcbc11855b64208 (patch) | |
tree | 31bc0771b9bcdb6cd31c8a06ff1fb77fa4f7eaf3 /scripts/contrib/convert-srcuri.py | |
parent | b777781ebf88f049c37a04154e86ed0940d11d95 (diff) | |
download | poky-ddcf16d1f792153f7f7fec4b1dcbc11855b64208.tar.gz |
meta: Add explict branch to git SRC_URIs
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.
This update was made with the script added to contrib in this patch which
aims to help others convert other layers.
(From OE-Core rev: b51c405faf6f8c0365f7533bfaf470d79152a463)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/contrib/convert-srcuri.py')
-rwxr-xr-x | scripts/contrib/convert-srcuri.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/scripts/contrib/convert-srcuri.py b/scripts/contrib/convert-srcuri.py new file mode 100755 index 0000000000..4bf9e3013d --- /dev/null +++ b/scripts/contrib/convert-srcuri.py | |||
@@ -0,0 +1,63 @@ | |||
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 | print("processing file '%s'" % fn) | ||
23 | try: | ||
24 | fh, abs_path = tempfile.mkstemp() | ||
25 | modified = False | ||
26 | with os.fdopen(fh, 'w') as new_file: | ||
27 | with open(fn, "r") as old_file: | ||
28 | for line in old_file: | ||
29 | if ("git://" in line or "gitsm://" in line) and "branch=" not in line and "MIRROR" not in line and ".*" not in line: | ||
30 | if line.endswith('"\n'): | ||
31 | line = line.replace('"\n', ';branch=master"\n') | ||
32 | elif line.endswith(" \\\n"): | ||
33 | line = line.replace(' \\\n', ';branch=master \\\n') | ||
34 | modified = True | ||
35 | new_file.write(line) | ||
36 | if modified: | ||
37 | shutil.copymode(fn, abs_path) | ||
38 | os.remove(fn) | ||
39 | shutil.move(abs_path, fn) | ||
40 | except UnicodeDecodeError: | ||
41 | pass | ||
42 | |||
43 | ourname = os.path.basename(sys.argv[0]) | ||
44 | ourversion = "0.1" | ||
45 | |||
46 | if os.path.isfile(sys.argv[1]): | ||
47 | processfile(sys.argv[1]) | ||
48 | sys.exit(0) | ||
49 | |||
50 | for targetdir in sys.argv[1:]: | ||
51 | print("processing directory '%s'" % targetdir) | ||
52 | for root, dirs, files in os.walk(targetdir): | ||
53 | for name in files: | ||
54 | if name == ourname: | ||
55 | continue | ||
56 | fn = os.path.join(root, name) | ||
57 | if os.path.islink(fn): | ||
58 | continue | ||
59 | if "/.git/" in fn or fn.endswith(".html") or fn.endswith(".patch") or fn.endswith(".m4") or fn.endswith(".diff"): | ||
60 | continue | ||
61 | processfile(fn) | ||
62 | |||
63 | print("All files processed with version %s" % ourversion) | ||