Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
use 'CachedPackageSet' for 'FloxFlake::packagesDo'
Browse files Browse the repository at this point in the history
  • Loading branch information
aakropotkin committed Jul 19, 2023
1 parent 921ef22 commit ce1992f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 61 deletions.
40 changes: 29 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ TEST ?= test
# ---------------------------------------------------------------------------- #

OS ?= $(shell $(UNAME))
OS := $(OS)
ifndef libExt
ifeq (Linux,$(OS))
libExt ?= .so
Expand Down Expand Up @@ -79,25 +80,42 @@ endif

# ---------------------------------------------------------------------------- #

nljson_CFLAGS = $(shell $(PKG_CONFIG) --cflags nlohmann_json)
argparse_CFLAGS = $(shell $(PKG_CONFIG) --cflags argparse)
nljson_CFLAGS ?= $(shell $(PKG_CONFIG) --cflags nlohmann_json)
nljson_CFLAGS := $(nljson_CFLAGS)

argparse_CFLAGS ?= $(shell $(PKG_CONFIG) --cflags argparse)
argparse_CFLAGS := $(argparse_CFLAGS)

boost_CFLAGS ?= \
-I$(shell $(NIX) build --no-link --print-out-paths 'nixpkgs#boost')/include
boost_CFLAGS := $(boost_CFLAGS)

sqlite3_CFLAGS = $(shell $(PKG_CONFIG) --cflags sqlite3)
sqlite3_LDFLAGS = $(shell $(PKG_CONFIG) --libs sqlite3)
sqlite3_CFLAGS ?= $(shell $(PKG_CONFIG) --cflags sqlite3)
sqlite3_CFLAGS := $(sqlite3_CFLAGS)
sqlite3_LDFLAGS ?= $(shell $(PKG_CONFIG) --libs sqlite3)
sqlite3_LDLAGS := $(sqlite3_LDLAGS)

sql_builder_CFLAGS ?= \
-I$(shell $(NIX) build --no-link --print-out-paths \
'$(MAKEFILE_DIR)#sql-builder')/include
sql_builder_CFLAGS := $(sql_builder_CFLAGS)

nix_INCDIR ?= $(shell $(PKG_CONFIG) --variable=includedir nix-cmd)
nix_INCDIR := $(nix_INCDIR)
ifndef nix_CFLAGS
nix_CFLAGS = $(boost_CFLAGS)
nix_CFLAGS += $(shell $(PKG_CONFIG) --cflags nix-main nix-cmd nix-expr)
nix_CFLAGS += -isystem $(shell $(PKG_CONFIG) --variable=includedir nix-cmd)
nix_CFLAGS += -include $(nix_INCDIR)/nix/config.h
endif
nix_CFLAGS := $(nix_CFLAGS)

nix_INCDIR = $(shell $(PKG_CONFIG) --variable=includedir nix-cmd)
nix_CFLAGS = $(boost_CFLAGS)
nix_CFLAGS += $(shell $(PKG_CONFIG) --cflags nix-main nix-cmd nix-expr)
nix_CFLAGS += -isystem $(shell $(PKG_CONFIG) --variable=includedir nix-cmd)
nix_CFLAGS += -include $(nix_INCDIR)/nix/config.h
nix_LDFLAGS = $(shell $(PKG_CONFIG) --libs nix-main nix-cmd nix-expr nix-store)
nix_LDFLAGS += -lnixfetchers
ifndef nix_LDFLAGS
nix_LDFLAGS = \
$(shell $(PKG_CONFIG) --libs nix-main nix-cmd nix-expr nix-store)
nix_LDFLAGS += -lnixfetchers
endif
nix_LDFLAGS := $(nix_LDFLAGS)

ifndef floxresolve_LDFLAGS
floxresolve_LDFLAGS = '-L$(MAKEFILE_DIR)/lib' -lflox-resolve
Expand Down
86 changes: 36 additions & 50 deletions src/flox-flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "flox/drv-cache.hh"
#include <queue>
#include "flox/flake-package.hh"
#include "flox/cached-package-set.hh"


/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -452,63 +453,48 @@ FloxFlake::packagesDo(
, bool allowCache
)
{
DrvDb db( this->getLockedFlake()->getFingerprint() );
if ( allowCache )
subtree_type stt = parseSubtreeType( subtree );

/* Queue up stabilities ( if any ). */
std::vector<std::optional<std::string>> stabilities;
if ( stt == ST_CATALOG )
{
progress_status old = db.getProgress( subtree, system );
if ( DBPS_INFO_DONE <= old )
/* TODO: process in priority order? */
for ( const auto & stability : defaultCatalogStabilities )
{
for ( auto & dinfo : db.getDrvInfos( subtree, system ) )
{
op( aux, CachedPackage( dinfo ) );
}
stabilities.push_back( stability );
}
else if ( DBPS_PATHS_DONE <= old )
}
else
{
stabilities = { std::nullopt };
}

/* Apply `op' foreach stability or to the raw prefix. */
for ( const auto & stability : stabilities )
{
if ( allowCache )
{
const std::list<std::vector<std::string>> relPaths =
db.getDrvPaths( subtree, system ).value();
if ( relPaths.empty() )
{
db.promoteProgress( subtree, system, DBPS_EMPTY );
return;
}
std::vector<nix::Symbol> path = {
this->_state->symbols.create( subtree )
, this->_state->symbols.create( system )
};
Cursor prefix = this->openCursor( path );
for ( std::vector<std::string> rel : relPaths )
{
Cursor c = prefix;
for ( std::string a : rel ) { c = c->getAttr( a ); }
FlakePackage p( c, & this->_state->symbols, false );
/* Cache the result for next time. */
db.setDrvInfo( p );
/* Run our operation. */
op( aux, p );
}
db.promoteProgress( subtree, system, DBPS_INFO_DONE );
return;
CachedPackageSet ps(
this->_state, this->getLockedFlake(), stt, system, stability
);
for ( auto & pkg : ps ) { op( aux, pkg ); }
}
else
{
FlakePackageSet ps(
this->_state, this->getLockedFlake(), stt, system, stability
);
for ( auto & pkg : ps ) { op( aux, pkg ); }
}
}

nix::SymbolTable * st = & this->_state->symbols;
this->derivationsDo( subtree, system, DBPS_FORCE, [&](
DrvDb & db
, subtree_type subtreeType
, std::string_view subtree
, std::string_view system
, const std::vector<std::string> & parentRelPath
, std::string_view attrName
, Cursor cur
) {
FlakePackage p( cur, st, false );
/* Cache the result for next time. */
if ( allowCache ) { db.setDrvInfo( p ); }
/* Run our operation. */
op( aux, p );
} );
if ( allowCache ) { db.promoteProgress( subtree, system, DBPS_INFO_DONE ); }
/* Mark the subtree as done. */
if ( allowCache )
{
DrvDb db( this->getLockedFlake()->getFingerprint() );
db.promoteProgress( subtree, system, DBPS_INFO_DONE );
}
}


Expand Down

0 comments on commit ce1992f

Please sign in to comment.