Remove INTLLIBS from librazor_la_LIBADD.
This partially reverts 611c84a3f4b4538a65d186050608c17adbf17770.
It's not clear what motivated the initial inclusion of INTLLIBS
here since the net effect is only seen in librazor.la and not
in razor.pc and librazor.la is not normally packaged. Certainly
neither the static nor the dynamic versions of librazor currently
use libintl. At best this would cause the linker to search a
static libintl for undefined symbols without finding any; at worse
it causes a static build of plover using librazor.la to fail if
no static version of libintl is installed.
2 * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
3 * Copyright (C) 2008 Red Hat, Inc
4 * Copyright (C) 2009 J. Ali Harlow <ali@juiblex.co.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #define XML_BUFFER_SIZE 4096
34 parse_xml_file(const char *filename,
35 XML_StartElementHandler start,
36 XML_EndElementHandler end,
43 parser = XML_ParserCreate(NULL);
44 XML_SetElementHandler(parser, start, end);
45 XML_SetUserData(parser, data);
47 fd = open(filename, O_RDONLY);
49 fprintf(stderr, "failed to open %s: %s\n", filename,
55 buffer = XML_GetBuffer(parser, XML_BUFFER_SIZE);
56 len = read(fd, buffer, XML_BUFFER_SIZE);
59 err = XML_ParseBuffer(parser, len, len == 0);
60 if (err == XML_STATUS_ERROR) {
61 fprintf(stderr, "parse error at line %lu:\n%s\n",
62 XML_GetCurrentLineNumber(parser),
63 XML_ErrorString(XML_GetErrorCode(parser)));
77 struct razor_set *system_set, *repo_set, *result_set;
79 struct razor_importer *importer;
80 struct razor_set **importer_set;
82 struct razor_transaction *trans;
84 char *install_pkgs[3], *remove_pkgs[3];
85 int n_install_pkgs, n_remove_pkgs;
94 get_atts(const char **atts, ...)
97 const char *name, **ptr;
101 while (name = va_arg(ap, const char *), name != NULL) {
102 ptr = va_arg(ap, const char **);
104 for (i = 0; atts[i]; i += 2) {
105 if (strcmp(atts[i], name) == 0)
112 static enum razor_property_flags
113 parse_relation (const char *rel_str)
117 if (rel_str[0] == 'L')
118 return rel_str[1] == 'E' ? RAZOR_PROPERTY_LESS | RAZOR_PROPERTY_EQUAL : RAZOR_PROPERTY_LESS;
119 else if (rel_str[0] == 'G')
120 return rel_str[1] == 'E' ? RAZOR_PROPERTY_GREATER | RAZOR_PROPERTY_EQUAL : RAZOR_PROPERTY_GREATER;
121 else if (rel_str[0] == 'E' || rel_str[1] == 'Q')
122 return RAZOR_PROPERTY_EQUAL;
128 start_test(struct test_context *ctx, const char **atts)
130 const char *name = NULL;
132 get_atts(atts, "name", &name, NULL);
134 fprintf(stderr, "Test with no name\n");
137 printf("%s\n", name);
141 end_test(struct test_context *ctx)
143 if (ctx->system_set) {
144 razor_set_unref(ctx->system_set);
145 ctx->system_set = NULL;
148 razor_set_unref(ctx->repo_set);
149 ctx->repo_set = NULL;
151 if (ctx->result_set) {
152 razor_set_unref(ctx->result_set);
153 ctx->result_set = NULL;
156 razor_transaction_destroy(ctx->trans);
162 start_set(struct test_context *ctx, const char **atts)
164 const char *name = NULL;
166 ctx->importer = razor_importer_create();
167 get_atts(atts, "name", &name, NULL);
169 ctx->importer_set = &ctx->result_set;
170 else if (!strcmp(name, "system"))
171 ctx->importer_set = &ctx->system_set;
172 else if (!strcmp(name, "repo"))
173 ctx->importer_set = &ctx->repo_set;
175 fprintf(stderr, " bad set name '%s'\n", name);
181 end_set(struct test_context *ctx)
183 *ctx->importer_set = razor_importer_finish(ctx->importer);
184 ctx->importer = NULL;
188 start_package(struct test_context *ctx, const char **atts)
190 const char *name = NULL, *version = NULL, *arch = NULL;
192 get_atts(atts, "name", &name,
198 fprintf(stderr, " package with no name\n");
202 razor_importer_begin_package(ctx->importer, name, version, arch);
203 razor_importer_add_property(ctx->importer, name,
204 RAZOR_PROPERTY_EQUAL | RAZOR_PROPERTY_PROVIDES,
209 end_package(struct test_context *ctx)
211 razor_importer_finish_package(ctx->importer);
215 add_property(struct test_context *ctx, enum razor_property_flags type, const char *name, enum razor_property_flags rel, const char *version)
217 razor_importer_add_property(ctx->importer, name,
218 rel | type, version);
222 razor_property_flags_relation_to_string(enum razor_property_flags rel)
224 if (rel == RAZOR_PROPERTY_LESS)
226 if (rel == (RAZOR_PROPERTY_EQUAL | RAZOR_PROPERTY_LESS))
228 if (rel == RAZOR_PROPERTY_EQUAL)
230 if (rel == (RAZOR_PROPERTY_EQUAL | RAZOR_PROPERTY_GREATER))
232 if (rel == RAZOR_PROPERTY_GREATER)
239 check_unsatisfiable_property(struct test_context *ctx,
240 enum razor_property_flags type,
242 enum razor_property_flags rel,
248 if (razor_transaction_unsatisfied_property(ctx->trans,
249 name, rel | type, version))
252 fprintf(stderr, " didn't get unsatisfiable '%s %s %s'\n",
253 name, razor_property_flags_relation_to_string(rel), version);
258 start_property(struct test_context *ctx, enum razor_property_flags type, const char **atts)
260 const char *name = NULL, *rel_str = NULL, *version = NULL;
261 enum razor_property_flags rel;
263 get_atts(atts, "name", &name, "relation", &rel_str, "version", &version, NULL);
265 fprintf(stderr, " no name specified for property\n");
269 rel = parse_relation(rel_str);
271 fprintf(stderr, " bad or missing version relation for property %s\n", name);
275 rel = RAZOR_PROPERTY_EQUAL;
278 check_unsatisfiable_property(ctx, type, name, rel, version);
280 add_property(ctx, type, name, rel, version);
284 start_transaction(struct test_context *ctx, const char **atts)
286 ctx->n_install_pkgs = 0;
287 ctx->n_remove_pkgs = 0;
290 static struct razor_package *
291 get_package(struct razor_set *set, const char *package)
293 struct razor_package_iterator *pi;
294 struct razor_package *p;
295 const char *name, *version, *arch;
297 pi = razor_package_iterator_create(set);
298 while (razor_package_iterator_next(pi, &p, RAZOR_DETAIL_NAME, &name,
299 RAZOR_DETAIL_VERSION, &version,
300 RAZOR_DETAIL_ARCH, &arch,
301 RAZOR_DETAIL_LAST)) {
302 if (strcmp(package, name) == 0)
305 razor_package_iterator_destroy(pi);
311 end_transaction(struct test_context *ctx)
313 struct razor_package *pkg;
316 ctx->trans = razor_transaction_create(ctx->system_set, ctx->repo_set);
317 for (i = 0; i < ctx->n_install_pkgs; i++) {
318 pkg = get_package(ctx->repo_set, ctx->install_pkgs[i]);
319 razor_transaction_install_package(ctx->trans, pkg);
321 for (i = 0; i < ctx->n_remove_pkgs; i++) {
322 pkg = get_package(ctx->system_set, ctx->remove_pkgs[i]);
324 pkg = get_package(ctx->repo_set, ctx->remove_pkgs[i]);
326 razor_transaction_remove_package(ctx->trans, pkg);
329 razor_transaction_resolve(ctx->trans);
330 errors = razor_transaction_describe(ctx->trans);
333 while (ctx->n_install_pkgs--)
334 free(ctx->install_pkgs[ctx->n_install_pkgs]);
335 while (ctx->n_remove_pkgs--)
336 free(ctx->remove_pkgs[ctx->n_remove_pkgs]);
339 struct razor_set *new;
340 new = razor_transaction_commit(ctx->trans);
341 razor_transaction_destroy(ctx->trans);
343 ctx->system_set = new;
348 start_install_or_update(struct test_context *ctx, const char **atts)
350 const char *name = NULL;
352 get_atts(atts, "name", &name, NULL);
354 fprintf(stderr, " install/update with no name\n");
358 ctx->install_pkgs[ctx->n_install_pkgs++] = strdup(name);
362 start_remove(struct test_context *ctx, const char **atts)
364 const char *name = NULL;
366 get_atts(atts, "name", &name, NULL);
368 fprintf(stderr, " remove with no name\n");
372 ctx->remove_pkgs[ctx->n_remove_pkgs++] = strdup(name);
376 start_result(struct test_context *ctx, const char **atts)
382 diff_callback(enum razor_diff_action action,
383 struct razor_package *package,
389 struct test_context *ctx = data;
392 if (action == RAZOR_DIFF_ACTION_REMOVE) {
393 fprintf(stderr, " result set should not contain %s %s\n",
396 fprintf(stderr, " result set should contain %s %s\n",
402 end_result(struct test_context *ctx)
406 if (ctx->result_set) {
407 if (!ctx->system_set)
408 ctx->system_set = razor_set_create();
409 razor_set_diff(ctx->system_set, ctx->result_set,
415 start_unsatisfiable(struct test_context *ctx, const char **atts)
417 if (ctx->result_set) {
418 fprintf(stderr, "Expected to fail, but didn't\n");
426 end_unsatisfiable(struct test_context *ctx)
432 start_test_element(void *data, const char *element, const char **atts)
434 struct test_context *ctx = data;
436 if (strcmp(element, "tests") == 0) {
438 } else if (strcmp(element, "test") == 0) {
439 start_test(ctx, atts);
440 } else if (strcmp(element, "set") == 0) {
441 start_set(ctx, atts);
442 } else if (strcmp(element, "transaction") == 0) {
443 start_transaction(ctx, atts);
444 } else if (strcmp(element, "install") == 0) {
445 start_install_or_update(ctx, atts);
446 } else if (strcmp(element, "install") == 0) {
447 start_install_or_update(ctx, atts);
448 } else if (strcmp(element, "remove") == 0) {
449 start_remove(ctx, atts);
450 } else if (strcmp(element, "result") == 0) {
451 start_result(ctx, atts);
452 } else if (strcmp(element, "unsatisfiable") == 0) {
453 start_unsatisfiable(ctx, atts);
454 } else if (strcmp(element, "package") == 0) {
455 start_package(ctx, atts);
456 } else if (strcmp(element, "requires") == 0) {
457 start_property(ctx, RAZOR_PROPERTY_REQUIRES, atts);
458 } else if (strcmp(element, "provides") == 0) {
459 start_property(ctx, RAZOR_PROPERTY_PROVIDES, atts);
460 } else if (strcmp(element, "conflicts") == 0) {
461 start_property(ctx, RAZOR_PROPERTY_CONFLICTS, atts);
462 } else if (strcmp(element, "obsoletes") == 0) {
463 start_property(ctx, RAZOR_PROPERTY_OBSOLETES, atts);
465 fprintf(stderr, "Unrecognized element '%s'\n", element);
471 end_test_element (void *data, const char *element)
473 struct test_context *ctx = data;
475 if (strcmp(element, "test") == 0) {
477 } else if (strcmp(element, "set") == 0) {
479 } else if (strcmp(element, "package") == 0) {
481 } else if (strcmp(element, "transaction") == 0) {
482 end_transaction(ctx);
483 } else if (strcmp(element, "result") == 0) {
485 } else if (strcmp(element, "unsatisfiable") == 0) {
486 end_unsatisfiable(ctx);
490 int main(int argc, char *argv[])
492 struct test_context ctx;
493 const char *test_file;
495 memset(&ctx, 0, sizeof ctx);
498 fprintf(stderr, "usage: %s [-d] [TESTS-FILE]\n", argv[0]);
502 if (argc >= 2 && !strcmp (argv[1], "-d")) {
510 test_file = "test.xml";
512 parse_xml_file(test_file, start_test_element, end_test_element, &ctx);
515 fprintf(stderr, "\n%d errors\n", ctx.errors);