summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2021-10-29 13:20:57 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-11-15 11:56:17 +0000
commit5258dd0cd082d3ca1663358e609256e592d1695a (patch)
tree90e78edab9bc4f09e8b2254161b44381afacc5f7 /scripts
parentaaa0c06d8562aeea80bbff01c76d4a832b57e17f (diff)
downloadpoky-5258dd0cd082d3ca1663358e609256e592d1695a.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: 37b4f66fa23979cbfe82679a74ce21b11fc61557) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit b51c405faf6f8c0365f7533bfaf470d79152a463) Signed-off-by: Anuj Mittal <anuj.mittal@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/contrib/convert-srcuri.py63
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
10import re
11import os
12import sys
13import tempfile
14import shutil
15import mimetypes
16
17if len(sys.argv) < 2:
18 print("Please specify a directory to run the conversion script against.")
19 sys.exit(1)
20
21def 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
43ourname = os.path.basename(sys.argv[0])
44ourversion = "0.1"
45
46if os.path.isfile(sys.argv[1]):
47 processfile(sys.argv[1])
48 sys.exit(0)
49
50for 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
63print("All files processed with version %s" % ourversion)