db: sort world dependencies to layers

cute-signatures
Timo Teräs 2022-02-06 21:08:09 +02:00
parent 9089edcc44
commit f69ae30272
5 changed files with 27 additions and 7 deletions

View File

@ -101,6 +101,7 @@ struct apk_name {
unsigned is_dependency : 1; unsigned is_dependency : 1;
unsigned auto_select_virtual: 1; unsigned auto_select_virtual: 1;
unsigned priority : 2; unsigned priority : 2;
unsigned layer : 4;
unsigned int foreach_genid; unsigned int foreach_genid;
union { union {
struct apk_solver_name_state ss; struct apk_solver_name_state ss;

View File

@ -48,6 +48,7 @@ struct apk_dependency {
unsigned conflict : 1; unsigned conflict : 1;
unsigned result_mask : 4; unsigned result_mask : 4;
unsigned fuzzy : 1; unsigned fuzzy : 1;
unsigned layer : 4; // solver sets for 'world' dependencies only
}; };
APK_ARRAY(apk_dependency_array, struct apk_dependency); APK_ARRAY(apk_dependency_array, struct apk_dependency);
@ -120,6 +121,8 @@ void apk_blob_push_deps(apk_blob_t *to, struct apk_database *, struct apk_depend
void apk_blob_pull_dep(apk_blob_t *from, struct apk_database *, struct apk_dependency *); void apk_blob_pull_dep(apk_blob_t *from, struct apk_database *, struct apk_dependency *);
void apk_blob_pull_deps(apk_blob_t *from, struct apk_database *, struct apk_dependency_array **); void apk_blob_pull_deps(apk_blob_t *from, struct apk_database *, struct apk_dependency_array **);
int apk_deps_write_layer(struct apk_database *db, struct apk_dependency_array *deps,
struct apk_ostream *os, apk_blob_t separator, unsigned layer);
int apk_deps_write(struct apk_database *db, struct apk_dependency_array *deps, int apk_deps_write(struct apk_database *db, struct apk_dependency_array *deps,
struct apk_ostream *os, apk_blob_t separator); struct apk_ostream *os, apk_blob_t separator);

View File

@ -1819,11 +1819,16 @@ static int apk_db_write_layers(struct apk_database *db)
ld->installed = apk_ostream_to_file(ld->fd, "installed", 0644); ld->installed = apk_ostream_to_file(ld->fd, "installed", 0644);
ld->scripts = apk_ostream_to_file(ld->fd, "scripts.tar", 0644); ld->scripts = apk_ostream_to_file(ld->fd, "scripts.tar", 0644);
ld->triggers = apk_ostream_to_file(ld->fd, "triggers", 0644); ld->triggers = apk_ostream_to_file(ld->fd, "triggers", 0644);
}
if (i == 0)
os = apk_ostream_to_file(db->root_fd, apk_world_file, 0644); os = apk_ostream_to_file(db->root_fd, apk_world_file, 0644);
if (!IS_ERR(os)) { else
apk_deps_write(db, db->world, os, APK_BLOB_PTR_LEN("\n", 1)); os = apk_ostream_to_file(ld->fd, "world", 0644);
if (IS_ERR(os)) {
if (!rr) rr = PTR_ERR(os);
continue;
}
apk_deps_write_layer(db, db->world, os, APK_BLOB_PTR_LEN("\n", 1), i);
apk_ostream_write(os, "\n", 1); apk_ostream_write(os, "\n", 1);
r = apk_ostream_close(os); r = apk_ostream_close(os);
if (!rr) rr = r; if (!rr) rr = r;

View File

@ -423,7 +423,7 @@ void apk_blob_push_deps(apk_blob_t *to, struct apk_database *db, struct apk_depe
} }
} }
int apk_deps_write(struct apk_database *db, struct apk_dependency_array *deps, struct apk_ostream *os, apk_blob_t separator) int apk_deps_write_layer(struct apk_database *db, struct apk_dependency_array *deps, struct apk_ostream *os, apk_blob_t separator, unsigned layer)
{ {
apk_blob_t blob; apk_blob_t blob;
char tmp[256]; char tmp[256];
@ -433,9 +433,10 @@ int apk_deps_write(struct apk_database *db, struct apk_dependency_array *deps, s
return 0; return 0;
for (i = 0; i < deps->num; i++) { for (i = 0; i < deps->num; i++) {
if (layer != -1 && deps->item[i].layer != layer) continue;
blob = APK_BLOB_BUF(tmp); blob = APK_BLOB_BUF(tmp);
if (i) if (n) apk_blob_push_blob(&blob, separator);
apk_blob_push_blob(&blob, separator);
apk_blob_push_dep(&blob, db, &deps->item[i]); apk_blob_push_dep(&blob, db, &deps->item[i]);
blob = apk_blob_pushed(APK_BLOB_BUF(tmp), blob); blob = apk_blob_pushed(APK_BLOB_BUF(tmp), blob);
@ -449,6 +450,11 @@ int apk_deps_write(struct apk_database *db, struct apk_dependency_array *deps, s
return n; return n;
} }
int apk_deps_write(struct apk_database *db, struct apk_dependency_array *deps, struct apk_ostream *os, apk_blob_t separator)
{
return apk_deps_write_layer(db, deps, os, separator, -1);
}
void apk_dep_from_adb(struct apk_dependency *dep, struct apk_database *db, struct adb_obj *d) void apk_dep_from_adb(struct apk_dependency *dep, struct apk_database *db, struct adb_obj *d)
{ {
*dep = (struct apk_dependency) { *dep = (struct apk_dependency) {

View File

@ -1093,6 +1093,11 @@ restart:
goto restart; goto restart;
} }
foreach_array_item(d, world) {
if (!d->name->ss.chosen.pkg) continue;
d->layer = d->name->ss.chosen.pkg->layer;
}
apk_hash_foreach(&db->available.names, free_name, NULL); apk_hash_foreach(&db->available.names, free_name, NULL);
apk_hash_foreach(&db->available.packages, free_package, NULL); apk_hash_foreach(&db->available.packages, free_package, NULL);
dbg_printf("solver done, errors=%d\n", ss->errors); dbg_printf("solver done, errors=%d\n", ss->errors);