1 /* 2 * Copyright (c) 2007, Novell Inc. 3 * 4 * This program is licensed under the BSD license, read LICENSE.BSD 5 * for further information 6 */ 7 8 /* 9 * poolarch.c 10 * 11 * create architecture policies 12 */ 13 14 #include <stdio.h> 15 #include <stdlib.h> 16 #include <string.h> 17 18 #include "pool.h" 19 #include "poolid.h" 20 #include "poolarch.h" 21 #include "util.h" 22 23 static const char *archpolicies[] = { 24 "x86_64", "x86_64:i686:i586:i486:i386", 25 "i686", "i686:i586:i486:i386", 26 "i586", "i586:i486:i386", 27 "i486", "i486:i386", 28 "i386", "i386", 29 "s390x", "s390x:s390", 30 "s390", "s390", 31 "ia64", "ia64:i686:i586:i486:i386", 32 "ppc64", "ppc64:ppc", 33 "ppc", "ppc", 34 "aarch64", "aarch64", 35 "armv7tnhl", "arvm7tnhl:armv7thl:armv7nhl:armv7hl", 36 "armv7thl", "armv7thl:armv7hl", 37 "armv7nhl", "armv7nhl:armv7hl", 38 "armv7hl", "armv7hl", 39 "armv7l", "armv7l:armv6l:armv5tejl:armv5tel:armv5l:armv4tl:armv4l:armv3l", 40 "armv6l", "armv6l:armv5tejl:armv5tel:armv5l:armv4tl:armv4l:armv3l", 41 "armv5tejl", "armv5tejl:armv5tel:armv5l:armv4tl:armv4l:armv3l", 42 "armv5tel", "armv5tel:armv5l:armv4tl:armv4l:armv3l", 43 "armv5l", "armv5l:armv4tl:armv4l:armv3l", 44 "armv4tl", "armv4tl:armv4l:armv3l", 45 "armv4l", "armv4l:armv3l", 46 "armv3l", "armv3l", 47 "sh3", "sh3", 48 "sh4", "sh4", 49 "sh4a", "sh4a:sh4", 50 "sparc64v", "sparc64v:sparc64:sparcv9v:sparcv9:sparcv8:sparc", 51 "sparc64", "sparc64:sparcv9:sparcv8:sparc", 52 "sparcv9v", "sparcv9v:sparcv9:sparcv8:sparc", 53 "sparcv9", "sparcv9:sparcv8:sparc", 54 "sparcv8", "sparcv8:sparc", 55 "sparc", "sparc", 56 0 57 }; 58 59 void 60 pool_setarch(Pool *pool, const char *arch) 61 { 62 if (arch) 63 { 64 int i; 65 66 /* convert arch to known policy */ 67 for (i = 0; archpolicies[i]; i += 2) 68 if (!strcmp(archpolicies[i], arch)) 69 break; 70 if (archpolicies[i]) 71 arch = archpolicies[i + 1]; 72 else 73 arch = ""; 74 } 75 pool_setarchpolicy(pool, arch); 76 } 77 78 /* 79 * we support three relations: 80 * 81 * a = b both architectures a and b are treated as equivalent 82 * a > b a is considered a "better" architecture, the solver 83 * should change from a to b, but must not change from b to a 84 * a : b a is considered a "better" architecture, the solver 85 * must not change the architecture from a to b or b to a 86 */ 87 void 88 pool_setarchpolicy(Pool *pool, const char *arch) 89 { 90 unsigned int score = 0x10001; 91 size_t l; 92 char d; 93 Id *id2arch; 94 Id id, lastarch; 95 96 pool->id2arch = solv_free(pool->id2arch); 97 pool->id2color = solv_free(pool->id2color); 98 if (!arch) 99 { 100 pool->lastarch = 0; 101 return; 102 } 103 id = pool->noarchid; 104 lastarch = id + 255; 105 id2arch = solv_calloc(lastarch + 1, sizeof(Id)); 106 id2arch[id] = 1; /* the "noarch" class */ 107 108 d = 0; 109 while (*arch) 110 { 111 l = strcspn(arch, ":=>"); 112 if (l) 113 { 114 id = pool_strn2id(pool, arch, l, 1); 115 if (id > lastarch) 116 { 117 id2arch = solv_realloc2(id2arch, (id + 255 + 1), sizeof(Id)); 118 memset(id2arch + lastarch + 1, 0, (id + 255 - lastarch) * sizeof(Id)); 119 lastarch = id + 255; 120 } 121 if (id2arch[id] == 0) 122 { 123 if (d == ':') 124 score += 0x10000; 125 else if (d == '>') 126 score += 0x00001; 127 id2arch[id] = score; 128 } 129 } 130 arch += l; 131 if ((d = *arch++) == 0) 132 break; 133 } 134 pool->id2arch = id2arch; 135 pool->lastarch = lastarch; 136 } 137 138 unsigned char 139 pool_arch2color_slow(Pool *pool, Id arch) 140 { 141 const char *s; 142 unsigned char color; 143 144 if (arch > pool->lastarch) 145 return ARCHCOLOR_ALL; 146 if (!pool->id2color) 147 pool->id2color = solv_calloc(pool->lastarch + 1, 1); 148 s = pool_id2str(pool, arch); 149 if (arch == ARCH_NOARCH || arch == ARCH_ALL || arch == ARCH_ANY) 150 color = ARCHCOLOR_ALL; 151 else if (!strcmp(s, "s390x") || strstr(s, "64")) 152 color = ARCHCOLOR_64; 153 else 154 color = ARCHCOLOR_32; 155 pool->id2color[arch] = color; 156 return color; 157 } 158 159