when importing, create fake file PROVIDES to match file REQUIRES
authorDan Winship <danw@gnome.org>
Mon Mar 10 14:12:31 2008 -0400 (2008-03-10)
changeset 1599307d0e0b44f
parent 158 9745a231f8d7
child 160 00f19df51272
when importing, create fake file PROVIDES to match file REQUIRES
razor.c
     1.1 --- a/razor.c	Mon Mar 10 11:30:00 2008 -0400
     1.2 +++ b/razor.c	Mon Mar 10 14:12:31 2008 -0400
     1.3 @@ -96,6 +96,7 @@
     1.4  	struct razor_package *package;
     1.5  	struct array properties;
     1.6  	struct array files;
     1.7 +	struct array file_requires;
     1.8  };
     1.9  
    1.10  static void *
    1.11 @@ -310,6 +311,11 @@
    1.12  
    1.13  	r = array_add(&importer->properties, sizeof *r);
    1.14  	*r = p - (struct razor_property *) importer->set->properties.data;
    1.15 +
    1.16 +	if (type == RAZOR_PROPERTY_REQUIRES && *name == '/') {
    1.17 +		r = array_add(&importer->file_requires, sizeof *r);
    1.18 +		*r = p->name;
    1.19 +	}
    1.20  }
    1.21  
    1.22  void
    1.23 @@ -717,6 +723,86 @@
    1.24  	array_release(&importer->files);
    1.25  }
    1.26  
    1.27 +static struct razor_entry *
    1.28 +find_entry(struct razor_set *set, struct razor_entry *dir, const char *pattern);
    1.29 +
    1.30 +static void
    1.31 +list_to_array(struct list *list, struct array *array)
    1.32 +{
    1.33 +	uint32_t *item;
    1.34 +
    1.35 +	while (list) {
    1.36 +		 item = array_add(array, sizeof *item);
    1.37 +		 *item = list->data;
    1.38 +		 list = list_next(list);
    1.39 +	}
    1.40 +}
    1.41 +
    1.42 +static int
    1.43 +compare_file_requires(const void *p1, const void *p2, void *data)
    1.44 +{
    1.45 +	uint32_t *f1 = (void *)p1, *f2 = (void *)p2;
    1.46 +	const char *pool = data;
    1.47 +
    1.48 +	return strcmp(&pool[*f1], &pool[*f2]);
    1.49 +}
    1.50 +
    1.51 +static void
    1.52 +find_file_provides(struct razor_importer *importer)
    1.53 +{
    1.54 +	struct razor_property *prop;
    1.55 +	struct razor_entry *top, *entry;
    1.56 +	struct razor_package *packages;
    1.57 +	struct array pkgarray, pkgprops;
    1.58 +	uint32_t *req, *req_start, *req_end, *pkg, *pkg_end;
    1.59 +	uint32_t *map, newprop_id, *newprop;
    1.60 +	char *pool;
    1.61 +
    1.62 +	pool = importer->set->string_pool.data;
    1.63 +	packages = importer->set->packages.data;
    1.64 +	top = importer->set->files.data;
    1.65 +
    1.66 +	req = req_start = importer->file_requires.data;
    1.67 +	req_end = importer->file_requires.data + importer->file_requires.size;
    1.68 +	map = qsort_with_data(req, req_end - req, sizeof *req,
    1.69 +			      compare_file_requires, pool);
    1.70 +	free(map);
    1.71 +
    1.72 +	for (req = req_start; req < req_end; req++) {
    1.73 +		if (req > req_start && req[0] == req[-1])
    1.74 +			continue;
    1.75 +		entry = find_entry(importer->set, top, &pool[*req]);
    1.76 +		if (entry) {
    1.77 +			prop = array_add(&importer->set->properties, sizeof *prop);
    1.78 +			prop->name = *req;
    1.79 +			prop->type = RAZOR_PROPERTY_PROVIDES;
    1.80 +			prop->relation = RAZOR_VERSION_EQUAL;
    1.81 +			prop->version = hashtable_tokenize(&importer->table, "");
    1.82 +
    1.83 +			/* Copy package list from entry to property */
    1.84 +			array_init(&pkgarray);
    1.85 +			list_to_array(list_first(&entry->packages, &importer->set->package_pool), &pkgarray);
    1.86 +			list_set_array(&prop->packages, &importer->set->package_pool, &pkgarray, 0);
    1.87 +
    1.88 +			/* Update property list of each providing package */
    1.89 +			pkg_end = pkgarray.data + pkgarray.size;
    1.90 +			newprop_id = prop - (struct razor_property *)importer->set->properties.data;
    1.91 +
    1.92 +			for (pkg = pkgarray.data; pkg < pkg_end; pkg++) {
    1.93 +				array_init(&pkgprops);
    1.94 +				list_to_array(list_first(&packages[*pkg].properties, &importer->set->property_pool), &pkgprops);
    1.95 +				newprop = array_add(&pkgprops, sizeof *newprop);
    1.96 +				*newprop = newprop_id;
    1.97 +				list_set_array(&packages[*pkg].properties, &importer->set->property_pool, &pkgprops, 1);
    1.98 +				array_release(&pkgprops);
    1.99 +			}
   1.100 +			array_release(&pkgarray);
   1.101 +		}
   1.102 +	}
   1.103 +
   1.104 +	array_release(&importer->file_requires);
   1.105 +}
   1.106 +
   1.107  static void
   1.108  build_package_file_lists(struct razor_set *set, uint32_t *rmap)
   1.109  {
   1.110 @@ -756,6 +842,9 @@
   1.111  	uint32_t *map, *rmap;
   1.112  	int i, count;
   1.113  
   1.114 +	build_file_tree(importer);
   1.115 +	find_file_provides(importer);
   1.116 +
   1.117  	map = uniqueify_properties(importer->set);
   1.118  	list_remap_pool(&importer->set->property_pool, map);
   1.119  	free(map);
   1.120 @@ -772,7 +861,6 @@
   1.121  		rmap[map[i]] = i;
   1.122  	free(map);
   1.123  
   1.124 -	build_file_tree(importer);
   1.125  	list_remap_pool(&importer->set->package_pool, rmap);
   1.126  	build_package_file_lists(importer->set, rmap);
   1.127  	remap_property_package_links(&importer->set->properties, rmap);