|
| 1 | +# |
| 2 | +# ---------------------------------------------------------------------------------------------------- |
| 3 | +# |
| 4 | +# Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. |
| 5 | +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 6 | +# |
| 7 | +# This code is free software; you can redistribute it and/or modify it |
| 8 | +# under the terms of the GNU General Public License version 2 only, as |
| 9 | +# published by the Free Software Foundation. Oracle designates this |
| 10 | +# particular file as subject to the "Classpath" exception as provided |
| 11 | +# by Oracle in the LICENSE file that accompanied this code. |
| 12 | +# |
| 13 | +# This code is distributed in the hope that it will be useful, but WITHOUT |
| 14 | +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 15 | +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 16 | +# version 2 for more details (a copy is included in the LICENSE file that |
| 17 | +# accompanied this code). |
| 18 | +# |
| 19 | +# You should have received a copy of the GNU General Public License version |
| 20 | +# 2 along with this work; if not, write to the Free Software Foundation, |
| 21 | +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 | +# |
| 23 | +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 24 | +# or visit www.oracle.com if you need additional information or have any |
| 25 | +# questions. |
| 26 | +# |
| 27 | +# ---------------------------------------------------------------------------------------------------- |
| 28 | + |
| 29 | +""" |
| 30 | +Checks that each devkit mentioned in ci.jsonnet corresponds to a devkit mentioned in make/conf/jib-profiles.js |
| 31 | +This is based on pattern matching to avoid the need for a jsonnet and JavaScript parser. |
| 32 | +It exists to ensure ci.jsonnet is updated when a relevant devit is updated in jib-profiles.js. |
| 33 | +""" |
| 34 | + |
| 35 | +import re |
| 36 | +from os.path import dirname, join |
| 37 | + |
| 38 | +repo_dir = dirname(dirname(__file__)) |
| 39 | +ci_jsonnet_path = join(repo_dir, 'ci.jsonnet') |
| 40 | +jib_profiles_path = join(repo_dir, 'make', 'conf', 'jib-profiles.js') |
| 41 | + |
| 42 | +def load_jib_devkits(): |
| 43 | + """ |
| 44 | + Gets the devkits referred to in jib-profiles.js. For example: |
| 45 | +
|
| 46 | + var devkit_platform_revisions = { |
| 47 | + linux_x64: "gcc10.3.0-OL6.4+1.0", |
| 48 | + macosx: "Xcode12.4+1.0", |
| 49 | + windows_x64: "VS2019-16.9.3+1.0", |
| 50 | + linux_aarch64: "gcc10.3.0-OL7.6+1.0", |
| 51 | + linux_arm: "gcc8.2.0-Fedora27+1.0", |
| 52 | + linux_ppc64le: "gcc8.2.0-Fedora27+1.0", |
| 53 | + linux_s390x: "gcc8.2.0-Fedora27+1.0" |
| 54 | + }; |
| 55 | +
|
| 56 | + """ |
| 57 | + devkits = set() |
| 58 | + devkit_platform_revisions_re = re.compile(r'var devkit_platform_revisions *= *{([^}]+)}') |
| 59 | + with open(jib_profiles_path) as fp: |
| 60 | + jib_profiles = fp.read() |
| 61 | + devkit_platform_revisions = re.search(r'var devkit_platform_revisions *= *{([^}]+)}', jib_profiles).group(1) |
| 62 | + for entry in devkit_platform_revisions.split(','): |
| 63 | + if len(entry.strip().split('?')) == 2 : |
| 64 | + multiple_devkit = entry.strip().split('?')[1].split(':') |
| 65 | + devkits.add(multiple_devkit[0].strip()[1:-1]) |
| 66 | + devkits.add(multiple_devkit[1].strip()[1:-1]) |
| 67 | + else : |
| 68 | + devkit = entry.strip().split(':')[1] |
| 69 | + devkit = devkit.strip()[1:-1] # strip surrounding "" |
| 70 | + devkits.add(devkit) |
| 71 | + return devkits |
| 72 | + |
| 73 | +def load_ci_devkits(): |
| 74 | + """ |
| 75 | + Gets the devkits referred to in ci.jsonnet. For example: |
| 76 | +
|
| 77 | + "devkit:gcc10.3.0-OL7.6+1" : "==0" |
| 78 | +
|
| 79 | + """ |
| 80 | + |
| 81 | + devkits = set() |
| 82 | + devkit_re = re.compile(r'"devkit:([^"]+)" *: *"==([\d]+)"') |
| 83 | + with open(ci_jsonnet_path) as fp: |
| 84 | + ci_jsonnet = fp.read() |
| 85 | + for match in devkit_re.finditer(ci_jsonnet): |
| 86 | + if not match.group(1).endswith(':musl'): |
| 87 | + devkits.add('.'.join(match.group(1, 2))) |
| 88 | + return devkits |
| 89 | + |
| 90 | +jib_devkits = load_jib_devkits() |
| 91 | +ci_devkits = load_ci_devkits() |
| 92 | +undefined_devkits = ci_devkits - jib_devkits |
| 93 | +if undefined_devkits: |
| 94 | + msg = 'Devkits found in {} that are not defined in {}: {}'.format(ci_jsonnet_path, jib_profiles_path, ', '.join(undefined_devkits)) |
| 95 | + raise SystemExit(msg) |
0 commit comments