[PATCH] build: Use BSP family for options

Chris Johns chrisj at rtems.org
Wed Jul 14 06:40:57 UTC 2021



On 14/7/21 4:20 pm, Sebastian Huber wrote:
> Close #4468.
> ---
>  wscript | 51 ++++++++++++++++++++++++++++-----------------------
>  1 file changed, 28 insertions(+), 23 deletions(-)
> 
> diff --git a/wscript b/wscript
> index 6626fafb74..357e8918df 100755
> --- a/wscript
> +++ b/wscript
> @@ -203,11 +203,11 @@ class Item(object):
>      def get_enabled_by(self):
>          return self.data["enabled-by"]
>  
> -    def defaults(self, enable, variant):
> +    def defaults(self, enable, variant, family):
>          if _is_enabled(enable, self.get_enabled_by()):
>              for p in self.links():
> -                p.defaults(enable, variant)
> -            self.do_defaults(variant)
> +                p.defaults(enable, variant, family)
> +            self.do_defaults(variant, family)
>  
>      def configure(self, conf, cic):
>          if _is_enabled(conf.env.ENABLE, self.get_enabled_by()):
> @@ -223,7 +223,7 @@ class Item(object):
>                  p.build(bld, bic)
>              self.do_build(bld, bic)
>  
> -    def do_defaults(self, variant):
> +    def do_defaults(self, variant, family):
>          return
>  
>      def prepare_configure(self, conf, cic):
> @@ -592,9 +592,6 @@ class BSPItem(Item):
>          arch_bsps = bsps.setdefault(data["arch"].strip(), {})
>          arch_bsps[data["bsp"].strip()] = self
>  
> -    def prepare_configure(self, conf, cic):
> -        conf.env.BSP_FAMILY = self.data["family"]
> -
>      def prepare_build(self, bld, bic):
>          return BuildItemContext(
>              bic.includes + bld.env.BSP_INCLUDES.split(), [], [], []
> @@ -689,16 +686,18 @@ class OptionItem(Item):
>          super(OptionItem, self).__init__(uid, data)
>  
>      @staticmethod
> -    def _is_variant(variants, variant):
> +    def _is_variant(variants, variant, family):
>          for pattern in variants:
>              if re.match(pattern + "$", variant):
>                  return True
> +            if re.match(pattern + "$", family):
> +                return True
>          return False
>  
> -    def default_value(self, variant):
> +    def default_value(self, variant, family):
>          value = self.data["default"]
>          for default in self.data["default-by-variant"]:
> -            if OptionItem._is_variant(default["variants"], variant):
> +            if OptionItem._is_variant(default["variants"], variant, family):

I would prefer we keep the families and the variants separate. It is cleaner.

I have basically the same patch but optional handling `default-by-family`. :)

I have discussed this on the ticket.

Chris

>                  value = default["value"]
>                  break
>          if value is None:
> @@ -709,8 +708,8 @@ class OptionItem(Item):
>              return value
>          return self.data["format"].format(value)
>  
> -    def do_defaults(self, variant):
> -        value = self.default_value(variant)
> +    def do_defaults(self, variant, family):
> +        value = self.default_value(variant, family)
>          if value is None:
>              return
>          description = self.data["description"]
> @@ -917,7 +916,7 @@ class OptionItem(Item):
>              value = cic.cp.getboolean(conf.variant, name)
>              cic.add_option(name)
>          except configparser.NoOptionError:
> -            value = self.default_value(conf.env.ARCH_BSP)
> +            value = self.default_value(conf.env.ARCH_BSP, conf.env.ARCH_FAMILY)
>          except ValueError as ve:
>              conf.fatal(
>                  "Invalid value for configuration option {}: {}".format(name, ve)
> @@ -933,7 +932,7 @@ class OptionItem(Item):
>              value = cic.cp.get(conf.variant, name)
>              cic.add_option(name)
>          except configparser.NoOptionError:
> -            value = self.default_value(conf.env.ARCH_BSP)
> +            value = self.default_value(conf.env.ARCH_BSP, conf.env.ARCH_FAMILY)
>              if value is None:
>                  return value
>          try:
> @@ -952,7 +951,7 @@ class OptionItem(Item):
>              cic.add_option(name)
>              value = no_unicode(value)
>          except configparser.NoOptionError:
> -            value = self.default_value(conf.env.ARCH_BSP)
> +            value = self.default_value(conf.env.ARCH_BSP, conf.env.ARCH_FAMILY)
>          return value
>  
>      def _script(self, conf, cic, value, arg):
> @@ -1365,11 +1364,20 @@ def configure_variant(conf, cp, bsp_map, path_list, top_group, variant):
>      conf.setenv(variant)
>      arch, bsp_name = variant.split("/")
>      bsp_base = bsp_map.get(bsp_name, bsp_name)
> -    arch_bsp = arch + "/" + bsp_base
>  
> +    try:
> +        bsp_item = bsps[arch][bsp_base]
> +    except KeyError:
> +        conf.fatal("No such base BSP: '{}'".format(variant))
> +
> +    bsp_family = self.data["family"]
> +    arch_bsp = arch + "/" + bsp_base
> +    arch_family = arch + "/" + bsp_family
>      conf.env["ARCH"] = arch
>      conf.env["ARCH_BSP"] = arch_bsp
> +    conf.env["ARCH_FAMILY"] = arch_family
>      conf.env["BSP_BASE"] = bsp_base
> +    conf.env["BSP_FAMILY"] = bsp_family
>      conf.env["BSP_NAME"] = bsp_name
>      conf.env["DEST_OS"] = "rtems"
>  
> @@ -1384,11 +1392,6 @@ def configure_variant(conf, cp, bsp_map, path_list, top_group, variant):
>      cic = ConfigItemContext(cp, path_list)
>  
>      items[conf.env.TOPGROUP].configure(conf, cic)
> -
> -    try:
> -        bsp_item = bsps[arch][bsp_base]
> -    except KeyError:
> -        conf.fatal("No such base BSP: '{}'".format(variant))
>      bsp_item.configure(conf, cic)
>  
>      options = set([o[0].upper() for o in cp.items(variant)])
> @@ -1558,8 +1561,10 @@ COMPILER = {}""".format(
>                      )
>                  )
>                  enable = [compiler, arch, variant]
> -                items[top_group].defaults(enable, variant)
> -                bsps[arch][bsp].defaults(enable, variant)
> +                bsp_item = bsps[arch][bsp]
> +                family = arch + "/" + bsp_item.data["family"]
> +                items[top_group].defaults(enable, variant, family)
> +                bsp_item.defaults(enable, variant, family)
>      if first:
>          no_matches_error(ctx, white_list)
>  
> 


More information about the devel mailing list