summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorBruce Ashfield <bruce.ashfield@gmail.com>2024-07-15 14:12:53 +0000
committerBruce Ashfield <bruce.ashfield@gmail.com>2024-07-15 14:12:53 +0000
commit1f0897e014e64f9bc941c9259936fd45652674a4 (patch)
treef89c5dc10aeb89abee735df9b657935881328ef8 /scripts
parent4fbc98c93c5a68bde74b4691da190885022bdbbf (diff)
downloadmeta-virtualization-1f0897e014e64f9bc941c9259936fd45652674a4.tar.gz
scripts/oe-go-mod-autogen: allow repository mapping
I cases of failure to lookup a go.mod -> src repository allow a mapping to be specified as part of the tool. This allows us to avoid manually modifying .cache files and keep a generation running. Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/oe-go-mod-autogen.py65
1 files changed, 62 insertions, 3 deletions
diff --git a/scripts/oe-go-mod-autogen.py b/scripts/oe-go-mod-autogen.py
index 77a06fc5..0fe829d0 100755
--- a/scripts/oe-go-mod-autogen.py
+++ b/scripts/oe-go-mod-autogen.py
@@ -27,6 +27,7 @@ import argparse
27from collections import OrderedDict 27from collections import OrderedDict
28import subprocess 28import subprocess
29import textwrap 29import textwrap
30import re
30 31
31# This switch is used to make this script error out ASAP, mainly for debugging purpose 32# This switch is used to make this script error out ASAP, mainly for debugging purpose
32ERROR_OUT_ON_FETCH_AND_CHECKOUT_FAILURE = True 33ERROR_OUT_ON_FETCH_AND_CHECKOUT_FAILURE = True
@@ -336,10 +337,14 @@ class GoModTool(object):
336 # destdir: ${WORKDIR}/${BP}/src/import/vendor.fetch/github.com/Masterminds/semver/v3 337 # destdir: ${WORKDIR}/${BP}/src/import/vendor.fetch/github.com/Masterminds/semver/v3
337 # fullsrcrev: 7bb0c843b53d6ad21a3f619cb22c4b442bb3ef3e (git rev-list -1 v3.1.1) 338 # fullsrcrev: 7bb0c843b53d6ad21a3f619cb22c4b442bb3ef3e (git rev-list -1 v3.1.1)
338 # 339 #
339 # As a last resort, if the last component of <module_name> matches 'v[0-9]+', 340 # Next, if the last component of <module_name> matches 'v[0-9]+',
340 # remove the last component and try wget https://<module_name_with_last_component_removed>?go-get=1, 341 # remove the last component and try wget https://<module_name_with_last_component_removed>?go-get=1,
341 # then try using the above matching method. 342 # then try using the above matching method.
342 # 343 #
344 # Finally, we have a mapping of known modules to source trees that can
345 # be used to translate the go.mod entry to a repository. Currently this is
346 # part of the script, but could be read from .map files in the future.
347 #
343 for line in self.require_lines: 348 for line in self.require_lines:
344 module_name, version = line.strip().split() 349 module_name, version = line.strip().split()
345 logger.debug("require line: %s" % line) 350 logger.debug("require line: %s" % line)
@@ -410,6 +415,10 @@ class GoModTool(object):
410 if newline != '' and not newline.startswith('<'): 415 if newline != '' and not newline.startswith('<'):
411 repo_url = newline 416 repo_url = newline
412 repo_url_found = True 417 repo_url_found = True
418 if "Repository URL not available" in repo_url:
419 repo_url_found = False
420 repo_url = ""
421
413 break 422 break
414 if repo_url_found: 423 if repo_url_found:
415 logger.info("repo url for %s: %s" % (module_name, repo_url)) 424 logger.info("repo url for %s: %s" % (module_name, repo_url))
@@ -419,11 +428,62 @@ class GoModTool(object):
419 else: 428 else:
420 unhandled_reason = 'cannot determine repo_url for %s' % module_name 429 unhandled_reason = 'cannot determine repo_url for %s' % module_name
421 self.modules_unhandled[module_name] = unhandled_reason 430 self.modules_unhandled[module_name] = unhandled_reason
422 return None 431 # This used to return, but we have the mapping step below to try
432 # as a final resort, leaving this here in case compatiblity issues
433 # arrive later due to the continued processing.
434 # return None
423 except: 435 except:
424 logger.info("wget -O %s https://pkg.go.dev/%s failed" % (wget_content_file, module_name)) 436 logger.info("wget -O %s https://pkg.go.dev/%s failed" % (wget_content_file, module_name))
437
438 # Do we recognize this twice failed lookup ?
439 site_mapper = { "inet.af" : { "match" : re.compile(""),
440 "replace" : ""
441 }
442 }
443
444 # module name: inet.af/tcpproxy
445 # replacement: https://github.com/inetaf/tcpproxy
446 site_mapper["inet.af"]["match"] = re.compile(r"(inet\.af)/(.*)")
447 site_mapper["inet.af"]["replace"] = "https://github.com/inetaf/\\g<2>"
448
449 host, _, _ = module_name.partition('/')
450
451 ## on failure, we could consider instructing the user to write their
452 ## own url into the repo_url_cache file
453 ##
454 ## or we could look for a .repo_mapping file, and read/use it to do
455 ## the mapping and carry that around per-project.
456 logger.info( "trying mapper lookup for %s (host: %s)" % (module_name,host))
457
458 try:
459 mapper = site_mapper[host]
460 m = mapper["match"].match(module_name)
461 repo_url = m.expand( mapper["replace"] )
462
463 logger.info( "mapper match for %s, returning %s" % (module_name,repo_url) )
464 #print( "new site: %s" % repo_url )
465
466 # clear any potentially staged reasons for failures above
467 self.modules_unhandled[module_name] = ""
468
469 with open(url_cache_file, 'w') as f:
470 f.write(repo_url)
471 return repo_url
472 except Exception as e:
473 unhandled_reason = 'cannot determine mapped repo_url for %s' % module_name
474 ### XXXX: TODO. if there are more parts to be popped, we shouldn't give up
475 ### on th emodule
476 ####
477 #### and/ or check if there was already an entry from above, since that means
478 #### there was a more critcal error during the check and we should just
479 #### propagate the unhandled to the caller
480 ####
481 self.modules_unhandled[module_name] = unhandled_reason
482 del self.modules_unhandled[module_name]
483 logger.info( "no mapper match, returning none: %s" % e )
425 return None 484 return None
426 485
486 return None
427 487
428 def get_repo_url_rev(self, module_name, version): 488 def get_repo_url_rev(self, module_name, version):
429 """ 489 """
@@ -504,7 +564,6 @@ class GoModTool(object):
504 template = """# %s %s 564 template = """# %s %s
505# [1] git ls-remote %s %s 565# [1] git ls-remote %s %s
506SRCREV_%s="%s" 566SRCREV_%s="%s"
507# styhead and newer
508SRC_URI += "git://%s;name=%s;protocol=https;nobranch=1;destsuffix=${GO_SRCURI_DESTSUFFIX}/vendor.fetch/%s" 567SRC_URI += "git://%s;name=%s;protocol=https;nobranch=1;destsuffix=${GO_SRCURI_DESTSUFFIX}/vendor.fetch/%s"
509 568
510""" 569"""