mirror of
https://git.yoctoproject.org/git/poky
synced 2026-01-04 16:10:04 +00:00
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: b0667c83c65c9900d63a7d8a2ce88384dcc2ccc5) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Anuj Mittal <anuj.mittal@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
44996bfb87
commit
a02e40f98a
77
scripts/contrib/convert-srcuri.py
Executable file
77
scripts/contrib/convert-srcuri.py
Executable file
|
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/env python3
|
||||
#
|
||||
# Conversion script to update SRC_URI to add branch to git urls
|
||||
#
|
||||
# Copyright (C) 2021 Richard Purdie
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
#
|
||||
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
import shutil
|
||||
import mimetypes
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print("Please specify a directory to run the conversion script against.")
|
||||
sys.exit(1)
|
||||
|
||||
def processfile(fn):
|
||||
def matchline(line):
|
||||
if "MIRROR" in line or ".*" in line or "GNOME_GIT" in line:
|
||||
return False
|
||||
return True
|
||||
print("processing file '%s'" % fn)
|
||||
try:
|
||||
if "distro_alias.inc" in fn or "linux-yocto-custom.bb" in fn:
|
||||
return
|
||||
fh, abs_path = tempfile.mkstemp()
|
||||
modified = False
|
||||
with os.fdopen(fh, 'w') as new_file:
|
||||
with open(fn, "r") as old_file:
|
||||
for line in old_file:
|
||||
if ("git://" in line or "gitsm://" in line) and "branch=" not in line and matchline(line):
|
||||
if line.endswith('"\n'):
|
||||
line = line.replace('"\n', ';branch=master"\n')
|
||||
elif line.endswith(" \\\n"):
|
||||
line = line.replace(' \\\n', ';branch=master \\\n')
|
||||
modified = True
|
||||
if ("git://" in line or "gitsm://" in line) and "github.com" in line and "protocol=https" not in line and matchline(line):
|
||||
if "protocol=git" in line:
|
||||
line = line.replace('protocol=git', 'protocol=https')
|
||||
elif line.endswith('"\n'):
|
||||
line = line.replace('"\n', ';protocol=https"\n')
|
||||
elif line.endswith(" \\\n"):
|
||||
line = line.replace(' \\\n', ';protocol=https \\\n')
|
||||
modified = True
|
||||
new_file.write(line)
|
||||
if modified:
|
||||
shutil.copymode(fn, abs_path)
|
||||
os.remove(fn)
|
||||
shutil.move(abs_path, fn)
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
|
||||
ourname = os.path.basename(sys.argv[0])
|
||||
ourversion = "0.1"
|
||||
|
||||
if os.path.isfile(sys.argv[1]):
|
||||
processfile(sys.argv[1])
|
||||
sys.exit(0)
|
||||
|
||||
for targetdir in sys.argv[1:]:
|
||||
print("processing directory '%s'" % targetdir)
|
||||
for root, dirs, files in os.walk(targetdir):
|
||||
for name in files:
|
||||
if name == ourname:
|
||||
continue
|
||||
fn = os.path.join(root, name)
|
||||
if os.path.islink(fn):
|
||||
continue
|
||||
if "/.git/" in fn or fn.endswith(".html") or fn.endswith(".patch") or fn.endswith(".m4") or fn.endswith(".diff"):
|
||||
continue
|
||||
processfile(fn)
|
||||
|
||||
print("All files processed with version %s" % ourversion)
|
||||
Loading…
Reference in New Issue
Block a user