Ignore:
Timestamp:
Dec 30, 2013, 1:58:43 AM (12 years ago)
Author:
bird
Message:

kmk: Hacking kBuild-define-*.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/variable.c

    r2591 r2717  
    202202#endif
    203203
     204
     205#ifdef KMK /* Drop the 'static' */
     206struct variable_set global_variable_set;
     207struct variable_set_list global_setlist
     208#else
    204209static struct variable_set global_variable_set;
    205210static struct variable_set_list global_setlist
     211#endif
    206212  = { 0, &global_variable_set, 0 };
    207213struct variable_set_list *current_variable_set_list = &global_setlist;
     
    249255  struct variable var_key;
    250256
     257  if (env_overrides && origin == o_env)
     258    origin = o_env_override;
     259
    251260#ifndef KMK
    252261  if (set == NULL)
    253262    set = &global_variable_set;
    254 #else
     263#else /* KMK */
     264  /* Intercept kBuild object variable definitions. */
     265  if (name[0] == '[' && length > 3)
     266    {
     267      v = try_define_kbuild_object_variable_via_accessor (name, length,
     268                                                          value, value_len, duplicate_value,
     269                                                          origin, recursive, flocp);
     270      if (v != VAR_NOT_KBUILD_ACCESSOR)
     271        return v;
     272    }
    255273  if (set == NULL)
    256274    {
    257       /* underscore prefixed variables are automatically local in
    258          kBuild-define-* scopes.  They also get a global definition with
    259          the current scope prefix. */
    260       if (g_pTopKbDef && length > 0 && name[0] == '_')
    261         {
    262           char         *prefixed_nm;
    263           unsigned int  prefixed_nm_len;
    264 
    265           set = get_top_kbuild_variable_set();
    266           v = define_variable_in_set(name, length, value, value_len,
    267                                      1 /* duplicate_value */,
    268                                      origin, recursive, set, flocp);
    269 
    270           prefixed_nm_len = length;
    271           prefixed_nm = kbuild_prefix_variable(name, &prefixed_nm_len);
    272           define_variable_in_set(prefixed_nm, prefixed_nm_len,
    273                                  value, value_len, duplicate_value,
    274                                  origin, recursive, &global_variable_set,
    275                                  flocp);
    276           free(prefixed_nm);
    277           return v;
    278         }
     275      if (g_pTopKbEvalData)
     276        return define_kbuild_object_variable_in_top_obj (name, length,
     277                                                         value, value_len, duplicate_value,
     278                                                         origin, recursive, flocp);
    279279      set = &global_variable_set;
    280280    }
    281 #endif
     281#endif /* KMK */
    282282
    283283#ifndef CONFIG_WITH_STRCACHE2
     
    286286  var_slot = (struct variable **) hash_find_slot (&set->table, &var_key);
    287287
    288   if (env_overrides && origin == o_env)
    289     origin = o_env_override;
     288  /* if (env_overrides && origin == o_env)
     289    origin = o_env_override; - bird moved this up */
    290290
    291291  v = *var_slot;
    292292#else  /* CONFIG_WITH_STRCACHE2 */
    293   var_key.name = name = strcache2_add (&variable_strcache, name, length);
    294   var_key.length = length;
     293  name = strcache2_add (&variable_strcache, name, length);
    295294  if (   set != &global_variable_set
    296       || !(v = strcache2_get_user_val (&variable_strcache, var_key.name)))
    297     {
     295      || !(v = strcache2_get_user_val (&variable_strcache, name)))
     296    {
     297      var_key.name = name;
     298      var_key.length = length;
    298299      var_slot = (struct variable **) hash_find_slot_strcached (&set->table, &var_key);
    299300      v = *var_slot;
     
    470471    set = &global_variable_set;
    471472
     473#ifndef CONFIG_WITH_STRCACHE2
    472474  var_key.name = (char *) name;
    473475  var_key.length = length;
    474476  var_slot = (struct variable **) hash_find_slot (&set->table, &var_key);
     477#else
     478  var_key.name = strcache2_lookup(&variable_strcache, name, length);
     479  if (!var_key.name)
     480    return;
     481  var_key.length = length;
     482  var_slot = (struct variable **) hash_find_slot_strcached (&set->table, &var_key);
     483#endif
    475484
    476485  if (env_overrides && origin == o_env)
     
    490499        {
    491500          hash_delete_at (&set->table, var_slot);
     501#ifdef CONFIG_WITH_STRCACHE2
     502          if (set == &global_variable_set)
     503            strcache2_set_user_val (&variable_strcache, v->name, NULL);
     504#endif
    492505          free_variable_name_and_value (v);
    493506        }
     
    735748#ifdef CONFIG_WITH_STRCACHE2
    736749  const char *cached_name;
    737 
     750#endif
     751
     752# ifdef KMK
     753  /* Check for kBuild-define- local variable accesses and handle these first. */
     754  if (length > 3 && name[0] == '[')
     755    {
     756      struct variable *v = lookup_kbuild_object_variable_accessor(name, length);
     757      if (v != VAR_NOT_KBUILD_ACCESSOR)
     758        return v;
     759    }
     760# endif
     761
     762#ifdef CONFIG_WITH_STRCACHE2
    738763  /* lookup the name in the string case, if it's not there it won't
    739764     be in any of the sets either. */
     
    851876#else  /* CONFIG_WITH_STRCACHE2 */
    852877  const char *cached_name;
     878
     879# ifdef KMK
     880  /* Check for kBuild-define- local variable accesses and handle these first. */
     881  if (length > 3 && name[0] == '[' && set == &global_variable_set)
     882    {
     883      struct variable *v = lookup_kbuild_object_variable_accessor(name, length);
     884      if (v != VAR_NOT_KBUILD_ACCESSOR)
     885        return v;
     886    }
     887# endif
    853888
    854889  /* lookup the name in the string case, if it's not there it won't
     
    19141949}
    19151950
    1916 static struct variable *
     1951struct variable *
    19171952do_variable_definition_append (const struct floc *flocp, struct variable *v,
    19181953                               const char *value, unsigned int value_len,
     
    19962031  int conditional = 0;
    19972032  const size_t varname_len = strlen (varname); /* bird */
     2033
    19982034#ifdef CONFIG_WITH_VALUE_LENGTH
    1999   assert (value_len == ~0U || value_len == strlen (value));
     2035  if (value_len == ~0U)
     2036    value_len = strlen (value);
     2037  else
     2038    assert (value_len == strlen (value));
    20002039#endif
    20012040
     
    20662105#endif
    20672106
    2068 #ifdef CONFIG_WITH_LOCAL_VARIABLES
    2069           /* If we have += but we're in a target or local variable context,
    2070              we want to append only with other variables in the context of
    2071              this target.  */
    2072         if (target_var || origin == o_local)
    2073 #else
    20742107        /* If we have += but we're in a target variable context, we want to
    20752108           append only with other variables in the context of this target.  */
    20762109        if (target_var)
    2077 #endif
    20782110          {
    20792111            append = 1;
     
    20862118              append = 0;
    20872119          }
     2120#ifdef KMK
     2121        else if (   g_pTopKbEvalData
     2122                 || (   varname_len > 3
     2123                     && varname[0] == '['
     2124                     && is_kbuild_object_variable_accessor (varname, varname_len)) )
     2125          {
     2126            v = kbuild_object_variable_pre_append (varname, varname_len,
     2127                                                   value, value_len, simple_value,
     2128                                                   origin, org_flavor == f_append, flocp);
     2129            if (free_value)
     2130               free (free_value);
     2131            return v;
     2132          }
     2133#endif
     2134#ifdef CONFIG_WITH_LOCAL_VARIABLES
     2135        /* If 'local', restrict it to the current variable context. */
     2136        else if (origin == o_local)
     2137          v = lookup_variable_in_set (varname, varname_len,
     2138                                      current_variable_set_list->set);
     2139#endif
    20882140        else
    20892141          v = lookup_variable (varname, varname_len);
Note: See TracChangeset for help on using the changeset viewer.