Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | def __note(msg, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 8 | bb.note("%s: recipe_sanity: %s" % (d.getVar("P"), msg)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9 | |
| 10 | __recipe_sanity_badruntimevars = "RDEPENDS RPROVIDES RRECOMMENDS RCONFLICTS" |
| 11 | def bad_runtime_vars(cfgdata, d): |
| 12 | if bb.data.inherits_class("native", d) or \ |
| 13 | bb.data.inherits_class("cross", d): |
| 14 | return |
| 15 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 16 | for var in d.getVar("__recipe_sanity_badruntimevars").split(): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 17 | val = d.getVar(var, False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 18 | if val and val != cfgdata.get(var): |
Patrick Williams | 864cc43 | 2023-02-09 14:54:44 -0600 | [diff] [blame] | 19 | __note("%s should be %s:${PN}" % (var, var), d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 20 | |
| 21 | __recipe_sanity_reqvars = "DESCRIPTION" |
| 22 | __recipe_sanity_reqdiffvars = "" |
| 23 | def req_vars(cfgdata, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 24 | for var in d.getVar("__recipe_sanity_reqvars").split(): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 25 | if not d.getVar(var, False): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | __note("%s should be set" % var, d) |
| 27 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 28 | for var in d.getVar("__recipe_sanity_reqdiffvars").split(): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 29 | val = d.getVar(var, False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | cfgval = cfgdata.get(var) |
| 31 | |
| 32 | if not val: |
| 33 | __note("%s should be set" % var, d) |
| 34 | elif val == cfgval: |
| 35 | __note("%s should be defined to something other than default (%s)" % (var, cfgval), d) |
| 36 | |
| 37 | def var_renames_overwrite(cfgdata, d): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 38 | renames = d.getVar("__recipe_sanity_renames", False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 39 | if renames: |
| 40 | for (key, newkey, oldvalue, newvalue) in renames: |
| 41 | if oldvalue != newvalue and oldvalue != cfgdata.get(newkey): |
| 42 | __note("rename of variable '%s' to '%s' overwrote existing value '%s' with '%s'." % (key, newkey, oldvalue, newvalue), d) |
| 43 | |
| 44 | def incorrect_nonempty_PACKAGES(cfgdata, d): |
| 45 | if bb.data.inherits_class("native", d) or \ |
| 46 | bb.data.inherits_class("cross", d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 47 | if d.getVar("PACKAGES"): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | return True |
| 49 | |
| 50 | def can_use_autotools_base(cfgdata, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 51 | cfg = d.getVar("do_configure") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 52 | if not bb.data.inherits_class("autotools", d): |
| 53 | return False |
| 54 | |
| 55 | for i in ["autoreconf"] + ["%s_do_configure" % cls for cls in ["gnomebase", "gnome", "e", "autotools", "efl", "gpephone", "openmoko", "openmoko2", "xfce", "xlibs"]]: |
| 56 | if cfg.find(i) != -1: |
| 57 | return False |
| 58 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 59 | for clsfile in d.getVar("__inherit_cache", False): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 60 | (base, _) = os.path.splitext(os.path.basename(clsfile)) |
| 61 | if cfg.find("%s_do_configure" % base) != -1: |
| 62 | __note("autotools_base usage needs verification, spotted %s_do_configure" % base, d) |
| 63 | |
| 64 | return True |
| 65 | |
| 66 | def can_delete_FILESPATH(cfgdata, d): |
| 67 | expected = cfgdata.get("FILESPATH") |
| 68 | expectedpaths = d.expand(expected) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 69 | unexpanded = d.getVar("FILESPATH", False) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 70 | filespath = d.getVar("FILESPATH").split(":") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 71 | filespath = [os.path.normpath(f) for f in filespath if os.path.exists(f)] |
| 72 | for fp in filespath: |
| 73 | if not fp in expectedpaths: |
| 74 | # __note("Path %s in FILESPATH not in the expected paths %s" % |
| 75 | # (fp, expectedpaths), d) |
| 76 | return False |
| 77 | return expected != unexpanded |
| 78 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 79 | def can_delete_others(p, cfgdata, d): |
| 80 | for k in ["S", "PV", "PN", "DESCRIPTION", "DEPENDS", |
| 81 | "SECTION", "PACKAGES", "EXTRA_OECONF", "EXTRA_OEMAKE"]: |
| 82 | #for k in cfgdata: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 83 | unexpanded = d.getVar(k, False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 84 | cfgunexpanded = cfgdata.get(k) |
| 85 | if not cfgunexpanded: |
| 86 | continue |
| 87 | |
| 88 | try: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 89 | expanded = d.getVar(k) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 90 | cfgexpanded = d.expand(cfgunexpanded) |
| 91 | except bb.fetch.ParameterError: |
| 92 | continue |
| 93 | |
| 94 | if unexpanded != cfgunexpanded and \ |
| 95 | cfgexpanded == expanded: |
| 96 | __note("candidate for removal of %s" % k, d) |
| 97 | bb.debug(1, "%s: recipe_sanity: cfg's '%s' and d's '%s' both expand to %s" % |
| 98 | (p, cfgunexpanded, unexpanded, expanded)) |
| 99 | |
| 100 | python do_recipe_sanity () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 101 | p = d.getVar("P") |
| 102 | p = "%s %s %s" % (d.getVar("PN"), d.getVar("PV"), d.getVar("PR")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 103 | |
| 104 | sanitychecks = [ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 105 | (can_delete_FILESPATH, "candidate for removal of FILESPATH"), |
| 106 | #(can_use_autotools_base, "candidate for use of autotools_base"), |
| 107 | (incorrect_nonempty_PACKAGES, "native or cross recipe with non-empty PACKAGES"), |
| 108 | ] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 109 | cfgdata = d.getVar("__recipe_sanity_cfgdata", False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 110 | |
| 111 | for (func, msg) in sanitychecks: |
| 112 | if func(cfgdata, d): |
| 113 | __note(msg, d) |
| 114 | |
| 115 | can_delete_others(p, cfgdata, d) |
| 116 | var_renames_overwrite(cfgdata, d) |
| 117 | req_vars(cfgdata, d) |
| 118 | bad_runtime_vars(cfgdata, d) |
| 119 | } |
| 120 | do_recipe_sanity[nostamp] = "1" |
| 121 | addtask recipe_sanity |
| 122 | |
| 123 | do_recipe_sanity_all[nostamp] = "1" |
| 124 | do_recipe_sanity_all[recrdeptask] = "do_recipe_sanity_all do_recipe_sanity" |
| 125 | do_recipe_sanity_all () { |
| 126 | : |
| 127 | } |
| 128 | addtask recipe_sanity_all after do_recipe_sanity |
| 129 | |
| 130 | python recipe_sanity_eh () { |
| 131 | d = e.data |
| 132 | |
| 133 | cfgdata = {} |
| 134 | for k in d.keys(): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 135 | if not isinstance(d.getVar(k, False), bb.data_smart.DataSmart): |
| 136 | cfgdata[k] = d.getVar(k, False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 137 | |
| 138 | d.setVar("__recipe_sanity_cfgdata", cfgdata) |
| 139 | #d.setVar("__recipe_sanity_cfgdata", d) |
| 140 | |
| 141 | # Sick, very sick.. |
| 142 | from bb.data_smart import DataSmart |
| 143 | old = DataSmart.renameVar |
| 144 | def myrename(self, key, newkey): |
| 145 | oldvalue = self.getVar(newkey, 0) |
| 146 | old(self, key, newkey) |
| 147 | newvalue = self.getVar(newkey, 0) |
| 148 | if oldvalue: |
| 149 | renames = self.getVar("__recipe_sanity_renames", 0) or set() |
| 150 | renames.add((key, newkey, oldvalue, newvalue)) |
| 151 | self.setVar("__recipe_sanity_renames", renames) |
| 152 | DataSmart.renameVar = myrename |
| 153 | } |
| 154 | addhandler recipe_sanity_eh |
| 155 | recipe_sanity_eh[eventmask] = "bb.event.ConfigParsed" |