summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruce Ashfield <bruce.ashfield@gmail.com>2023-09-06 16:35:07 +0000
committerBruce Ashfield <bruce.ashfield@gmail.com>2023-09-15 17:30:40 +0000
commitff3dd2d68e95ff9aee851dff279dd238a5846c8c (patch)
treead1a6e8db84c4d9ca8d2239216cbd3cd8728a4bc
parent23ea9c77f9c3c55c94cf44117d0e07ec154eff0c (diff)
downloadmeta-virtualization-ff3dd2d68e95ff9aee851dff279dd238a5846c8c.tar.gz
oe-go-mod-autogen: whitespace cleanup, license and copyright
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
-rwxr-xr-xscripts/oe-go-mod-autogen.py54
1 files changed, 37 insertions, 17 deletions
diff --git a/scripts/oe-go-mod-autogen.py b/scripts/oe-go-mod-autogen.py
index 09d6133b..f4cdcf06 100755
--- a/scripts/oe-go-mod-autogen.py
+++ b/scripts/oe-go-mod-autogen.py
@@ -1,5 +1,25 @@
1#!/usr/bin/env python3 1#!/usr/bin/env python3
2 2
3# SPDX-License-Identifier: GPL-2.0-only
4#
5# go-dep processor
6#
7# Copyright (C) 2022 Bruce Ashfield
8# Copyright (C) 2023 Chen Qi
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License version 2 as
12# published by the Free Software Foundation.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License along
20# with this program; if not, write to the Free Software Foundation, Inc.,
21# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
3import os 23import os
4import sys 24import sys
5import logging 25import logging
@@ -51,14 +71,14 @@ class GoModTool(object):
51 # store subpaths used to form srcpath 71 # store subpaths used to form srcpath
52 # {actual_module_name: subpath} 72 # {actual_module_name: subpath}
53 self.modules_subpaths = OrderedDict() 73 self.modules_subpaths = OrderedDict()
54 74
55 # modules's actual source paths, record those that are not the same with the module itself 75 # modules's actual source paths, record those that are not the same with the module itself
56 self.modules_srcpaths = OrderedDict() 76 self.modules_srcpaths = OrderedDict()
57 77
58 # store lines, comment removed 78 # store lines, comment removed
59 self.require_lines = [] 79 self.require_lines = []
60 self.replace_lines = [] 80 self.replace_lines = []
61 81
62 # fetch repo 82 # fetch repo
63 self.fetch_and_checkout_repo(self.repo.split('://')[1], self.repo, self.rev, checkout=True, get_subpath=False) 83 self.fetch_and_checkout_repo(self.repo.split('://')[1], self.repo, self.rev, checkout=True, get_subpath=False)
64 84
@@ -91,7 +111,7 @@ class GoModTool(object):
91 return 111 return
92 self.parse_go_mod(go_mod_file) 112 self.parse_go_mod(go_mod_file)
93 self.show_go_mod_info() 113 self.show_go_mod_info()
94 114
95 def fetch_and_checkout_repo(self, module_name, repo_url, rev, default_protocol='https://', checkout=False, get_subpath=True): 115 def fetch_and_checkout_repo(self, module_name, repo_url, rev, default_protocol='https://', checkout=False, get_subpath=True):
96 """ 116 """
97 Fetch repo_url to <workdir>/repos/repo_base_name 117 Fetch repo_url to <workdir>/repos/repo_base_name
@@ -143,12 +163,12 @@ class GoModTool(object):
143 git_action = "clone" 163 git_action = "clone"
144 else: 164 else:
145 # No local repo, clone it. 165 # No local repo, clone it.
146 git_action = "clone" 166 git_action = "clone"
147 167
148 if git_action == "clone": 168 if git_action == "clone":
149 logger.info("Removing %s" % repo_dest_dir) 169 logger.info("Removing %s" % repo_dest_dir)
150 subprocess.check_call('rm -rf %s' % repo_dest_dir, shell=True) 170 subprocess.check_call('rm -rf %s' % repo_dest_dir, shell=True)
151 171
152 # clone/fetch repo 172 # clone/fetch repo
153 try: 173 try:
154 git_cwd = repos_dir if git_action == "clone" else repo_dest_dir 174 git_cwd = repos_dir if git_action == "clone" else repo_dest_dir
@@ -235,7 +255,7 @@ class GoModTool(object):
235 self.modules_repoinfo[module_name] = (repo_url, repo_dest_dir, requiredrev) 255 self.modules_repoinfo[module_name] = (repo_url, repo_dest_dir, requiredrev)
236 else: 256 else:
237 logger.warning("Failed to get requiredrev, repo_url = %s, rev = %s, module_name = %s" % (repo_url, rev, module_name)) 257 logger.warning("Failed to get requiredrev, repo_url = %s, rev = %s, module_name = %s" % (repo_url, rev, module_name))
238 258
239 def parse_go_mod(self, go_mod_path): 259 def parse_go_mod(self, go_mod_path):
240 """ 260 """
241 Parse go.mod file to get the modules info 261 Parse go.mod file to get the modules info
@@ -402,8 +422,8 @@ class GoModTool(object):
402 except: 422 except:
403 logger.info("wget -O %s https://pkg.go.dev/%s failed" % (wget_content_file, module_name)) 423 logger.info("wget -O %s https://pkg.go.dev/%s failed" % (wget_content_file, module_name))
404 return None 424 return None
405 425
406 426
407 def get_repo_url_rev(self, module_name, version): 427 def get_repo_url_rev(self, module_name, version):
408 """ 428 """
409 Return (repo_url, rev) 429 Return (repo_url, rev)
@@ -421,11 +441,11 @@ class GoModTool(object):
421 rev = v 441 rev = v
422 else: 442 else:
423 rev = v 443 rev = v
424 444
425 # 445 #
426 # Get repo_url 446 # Get repo_url
427 # We put a cache mechanism here, <wget_content_file>.repo_url.cache is used to store the repo url fetch before 447 # We put a cache mechanism here, <wget_content_file>.repo_url.cache is used to store the repo url fetch before
428 # 448 #
429 wget_dir = os.path.join(self.workdir, 'wget-contents') 449 wget_dir = os.path.join(self.workdir, 'wget-contents')
430 if not os.path.exists(wget_dir): 450 if not os.path.exists(wget_dir):
431 os.makedirs(wget_dir) 451 os.makedirs(wget_dir)
@@ -451,7 +471,7 @@ class GoModTool(object):
451 unhandled_reason = 'cannot determine the repo for %s' % module_name 471 unhandled_reason = 'cannot determine the repo for %s' % module_name
452 self.modules_unhandled[module_name] = unhandled_reason 472 self.modules_unhandled[module_name] = unhandled_reason
453 return (None, rev) 473 return (None, rev)
454 474
455 def get_url_srcrev(self, module_name, version): 475 def get_url_srcrev(self, module_name, version):
456 """ 476 """
457 Return url and fullsrcrev according to module_name and version 477 Return url and fullsrcrev according to module_name and version
@@ -470,10 +490,10 @@ class GoModTool(object):
470 unhandled_reason = 'fetch_and_checkout_repo(%s, %s, %s) failed' % (module_name, repo_url, rev) 490 unhandled_reason = 'fetch_and_checkout_repo(%s, %s, %s) failed' % (module_name, repo_url, rev)
471 self.modules_unhandled[module_name] = unhandled_reason 491 self.modules_unhandled[module_name] = unhandled_reason
472 return (None, None) 492 return (None, None)
473 493
474 def gen_src_uri_inc(self): 494 def gen_src_uri_inc(self):
475 """ 495 """
476 Generate src_uri.inc file containing SRC_URIs 496 Generate src_uri.inc file containing SRC_URIs
477 """ 497 """
478 src_uri_inc_file = os.path.join(self.workdir, 'src_uri.inc') 498 src_uri_inc_file = os.path.join(self.workdir, 'src_uri.inc')
479 # record the <name> after writting SRCREV_<name>, this is to avoid modules having the same basename resulting in same SRCREV_xxx 499 # record the <name> after writting SRCREV_<name>, this is to avoid modules having the same basename resulting in same SRCREV_xxx
@@ -530,9 +550,9 @@ do_compile:prepend() {
530 force_flag=$(echo $s | cut -d: -f3) 550 force_flag=$(echo $s | cut -d: -f3)
531 mkdir -p vendor.copy/$site_dest 551 mkdir -p vendor.copy/$site_dest
532 if [ -n "$force_flag" ]; then 552 if [ -n "$force_flag" ]; then
533 echo "[INFO] $site_dest: force copying .go files" 553 echo "[INFO] $site_dest: force copying .go files"
534 rm -rf vendor.copy/$site_dest 554 rm -rf vendor.copy/$site_dest
535 rsync -a --exclude='vendor/' --exclude='.git/' vendor.fetch/$site_source/ vendor.copy/$site_dest 555 rsync -a --exclude='vendor/' --exclude='.git/' vendor.fetch/$site_source/ vendor.copy/$site_dest
536 else 556 else
537 [ -n "$(ls -A vendor.copy/$site_dest/*.go 2> /dev/null)" ] && { echo "[INFO] vendor.fetch/$site_source -> $site_dest: go copy skipped (files present)" ; true ; } || { echo "[INFO] $site_dest: copying .go files" ; rsync -a --exclude='vendor/' --exclude='.git/' vendor.fetch/$site_source/ vendor.copy/$site_dest ; } 557 [ -n "$(ls -A vendor.copy/$site_dest/*.go 2> /dev/null)" ] && { echo "[INFO] vendor.fetch/$site_source -> $site_dest: go copy skipped (files present)" ; true ; } || { echo "[INFO] $site_dest: copying .go files" ; rsync -a --exclude='vendor/' --exclude='.git/' vendor.fetch/$site_source/ vendor.copy/$site_dest ; }
538 fi 558 fi
@@ -651,7 +671,7 @@ def main():
651 gomodtool.gen_src_uri_inc() 671 gomodtool.gen_src_uri_inc()
652 gomodtool.gen_relocation_inc() 672 gomodtool.gen_relocation_inc()
653 gomodtool.gen_modules_txt() 673 gomodtool.gen_modules_txt()
654 674
655 675
656if __name__ == "__main__": 676if __name__ == "__main__":
657 try: 677 try: