示例#1
0
static void find_arch(ident_t name, int kind, void *context)
{
   lib_search_params_t *params = context;

   ident_t prefix = ident_until(name, '-');

   if ((kind == T_ARCH) && (prefix == params->name)) {
      tree_t t = lib_get_check_stale(params->lib, name);
      assert(t != NULL);

      if (*(params->tree) == NULL)
         *(params->tree) = t;
      else {
         lib_mtime_t old_mtime = lib_mtime(params->lib,
                                           tree_ident(*(params->tree)));
         lib_mtime_t new_mtime = lib_mtime(params->lib, tree_ident(t));

         if (new_mtime == old_mtime) {
            // Analysed at the same time: compare line number
            // Note this assumes both architectures are from the same
            // file but this shouldn't be a problem with high-resolution
            // timestamps
            uint16_t new_line = tree_loc(t)->first_line;
            uint16_t old_line = tree_loc(*(params->tree))->first_line;

            if (new_line > old_line)
               *(params->tree) = t;
         }
         else if (new_mtime > old_mtime)
            *(params->tree) = t;
      }
   }
}
示例#2
0
文件: link.c 项目: ifreemyli/nvc
static bool link_find_native_library(lib_t lib, tree_t unit, FILE *deps)
{
#ifdef ENABLE_NATIVE
   ident_t name = tree_ident(unit);

   char *so_name = xasprintf("_%s.so", istr(name));

   lib_mtime_t so_mt;
   if (!lib_stat(lib, so_name, &so_mt)) {
      free(so_name);
      return false;
   }

   lib_mtime_t unit_mt = lib_mtime(lib, name);

   if (unit_mt > so_mt) {
      warnf("unit %s has stale native shared library", istr(name));
      free(so_name);
      return false;
   }

   if (deps != NULL) {
      char path[PATH_MAX];
      lib_realpath(lib, so_name, path, sizeof(path));

      fprintf(deps, "%s\n", path);
   }

   free(so_name);
   return true;
#else   // ENABLE_NATIVE
   return false;
#endif  // ENABLE_NATIVE
}