diff options
Diffstat (limited to 'scripts/oe-go-mod-autogen.py')
| -rwxr-xr-x | scripts/oe-go-mod-autogen.py | 100 |
1 files changed, 97 insertions, 3 deletions
diff --git a/scripts/oe-go-mod-autogen.py b/scripts/oe-go-mod-autogen.py index aa155f0f..2970847e 100755 --- a/scripts/oe-go-mod-autogen.py +++ b/scripts/oe-go-mod-autogen.py | |||
| @@ -644,17 +644,111 @@ def main(): | |||
| 644 | epilog=textwrap.dedent('''\ | 644 | epilog=textwrap.dedent('''\ |
| 645 | 645 | ||
| 646 | Overview: | 646 | Overview: |
| 647 | ========= | ||
| 647 | 648 | ||
| 648 | go-mod-oe is a tool for processing go dependencies to generate | 649 | go-mod-oe is a tool for processing go dependencies to generate |
| 649 | dependencies suitable for OE fetcher consumption. | 650 | dependencies suitable for OE fetcher consumption. |
| 650 | 651 | ||
| 651 | In particular, it creates a build structure suitable for | 652 | In particular, it creates a build structure suitable for |
| 652 | '-mod="vendor"' go builds. All dependencies are in the vendor/ | 653 | '-mod="vendor"' go builds. Once complete all go mod dependencies |
| 653 | directory, so no golang specific fetching or network access happens | 654 | are in the vendor/ directory, so no golang specific fetching or |
| 654 | during the build. | 655 | network access happens during the build. |
| 655 | 656 | ||
| 656 | The files src_uri.inc, relocation.inc and modules.txt are generated | 657 | The files src_uri.inc, relocation.inc and modules.txt are generated |
| 657 | and suitable for recipe inclusion. | 658 | and suitable for recipe inclusion. |
| 659 | |||
| 660 | A recipe build can then use these files to leverage the git fetcher | ||
| 661 | and related functionality (mirrors, sstate, etc). | ||
| 662 | |||
| 663 | Note 1: --rev does not have to be a tag, if you want to track the tip of | ||
| 664 | a branch specify the latest git has on that branch, and it will | ||
| 665 | be used. | ||
| 666 | |||
| 667 | Note 2: This script does not generate an entire recipe, the way the | ||
| 668 | the outputs are used can be modified as required. | ||
| 669 | |||
| 670 | Note 3: if a go.mod has a bad revision, or needs to be manually updated | ||
| 671 | to fetch fixes: go.mod in the main repository (see the repos/ | ||
| 672 | directory). If go.mod is edited, modules.txt also has to be | ||
| 673 | updated to match the revision information. | ||
| 674 | |||
| 675 | How to use in a recipe: | ||
| 676 | ======================= | ||
| 677 | |||
| 678 | There are examples in meta-virtualization of recipes that use this | ||
| 679 | script and stragegy for builds: docker-compose, nerdcli, k3s | ||
| 680 | |||
| 681 | 1) The recipe should set the master repository SRCREV details, and then include | ||
| 682 | the src_uri.inc file: | ||
| 683 | |||
| 684 | SRCREV_nerdcli = "e084a2df4a8861eb5f0b0d32df0643ef24b81093" | ||
| 685 | SRC_URI = "git://github.com/containerd/nerdctl.git;name=nerdcli;branch=master;protocol=https" | ||
| 686 | |||
| 687 | include src_uri.inc | ||
| 688 | |||
| 689 | This results in the SRC_URI being fully populated with the main | ||
| 690 | repository and all dependencies. | ||
| 691 | |||
| 692 | 2) The recipe should either copy, or include the relocation.inc file. It sets | ||
| 693 | a variable "sites" that is a list of source locations (where the src_uri.inc | ||
| 694 | fetches) and destination in a vendor directory, it also has a do_compile:prepend() | ||
| 695 | that contains a loop which relocates the fetches into a vendor.copy directory. | ||
| 696 | |||
| 697 | It is expected to be processed as follows, before compilation starts: | ||
| 698 | |||
| 699 | # sets the "sites" variable and copies files | ||
| 700 | include relocation.inc | ||
| 701 | |||
| 702 | The do_compile:prepend, contains the following loop: | ||
| 703 | |||
| 704 | cd ${S}/src/import | ||
| 705 | # this moves all the fetches into the proper vendor structure | ||
| 706 | # expected for build | ||
| 707 | for s in ${sites}; do | ||
| 708 | site_dest=$(echo $s | cut -d: -f1) | ||
| 709 | site_source=$(echo $s | cut -d: -f2) | ||
| 710 | force_flag=$(echo $s | cut -d: -f3) | ||
| 711 | mkdir -p vendor.copy/$site_dest | ||
| 712 | if [ -n "$force_flag" ]; then | ||
| 713 | echo "[INFO] $site_dest: force copying .go files" | ||
| 714 | rm -rf vendor.copy/$site_dest | ||
| 715 | rsync -a --exclude='vendor/' --exclude='.git/' vendor.fetch/$site_source/ vendor.copy/$site_dest | ||
| 716 | else | ||
| 717 | [ -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 ; } | ||
| 718 | fi | ||
| 719 | done | ||
| 720 | |||
| 721 | The main compile() function, should set the appropriate GO variables, | ||
| 722 | copy modules.txt and build the appripriate target: | ||
| 723 | |||
| 724 | # our copied .go files are to be used for the build | ||
| 725 | ln -sf vendor.copy vendor | ||
| 726 | |||
| 727 | 3) The modules.txt file should be copied into the recipe directory, included | ||
| 728 | on the SRC_URI and copied into place after the relocation has been | ||
| 729 | processed. | ||
| 730 | |||
| 731 | # patches and config | ||
| 732 | SRC_URI += "file://0001-Makefile-allow-external-specification-of-build-setti.patch \\ | ||
| 733 | file://modules.txt \ | ||
| 734 | " | ||
| 735 | |||
| 736 | ..... | ||
| 737 | |||
| 738 | cp ${WORKDIR}/modules.txt vendor/ | ||
| 739 | |||
| 740 | Example: Updating the K3S recipe | ||
| 741 | ================================ | ||
| 742 | |||
| 743 | % cd meta-virtualization/recipe-containers/k3s/ | ||
| 744 | # produces src_uri.inc, relocation.inc and modules.txt in the current directory | ||
| 745 | % ../../scripts/oe-go-mod-autogen.py --repo https://github.com/rancher/k3s.git --rev v1.27.5+k3s1 | ||
| 746 | |||
| 747 | % cp modules.txt k3s/ | ||
| 748 | |||
| 749 | ... add and commit files. | ||
| 750 | |||
| 751 | |||
| 658 | ''')) | 752 | ''')) |
| 659 | parser.add_argument("--repo", help = "Repo for the recipe.", required=True) | 753 | parser.add_argument("--repo", help = "Repo for the recipe.", required=True) |
| 660 | parser.add_argument("--rev", help = "Revision for the recipe.", required=True) | 754 | parser.add_argument("--rev", help = "Revision for the recipe.", required=True) |
