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

aameen.sql builder #4

Merged
merged 3 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 36 additions & 14 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,21 +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_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)

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

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 All @@ -103,7 +125,7 @@ endif

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

lib_CXXFLAGS += $(sqlite3_CFLAGS)
lib_CXXFLAGS += $(sqlite3_CFLAGS) $(sql_builder_CFLAGS)
bin_CXXFLAGS += $(argparse_CFLAGS)
CXXFLAGS += $(nix_CFLAGS) $(nljson_CFLAGS)

Expand Down Expand Up @@ -232,7 +254,7 @@ all: bin lib tests
$(CAT) "$(NIX_CC)/nix-support/libcxx-cxxflags"; \
fi; \
echo $(CXXFLAGS) $(sqlite3_CFLAGS) $(nljson_CFLAGS) $(nix_CFLAGS); \
echo $(nljson_CFLAGS) $(argparse_CFLAGS); \
echo $(nljson_CFLAGS) $(argparse_CFLAGS) $(sql_builder_CFLAGS); \
}|$(TR) ' ' '\n'|$(SED) 's/-std=/%cpp -std=/' >> "$@";


Expand Down
17 changes: 14 additions & 3 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
#
# ---------------------------------------------------------------------------- #

{ nixpkgs ? builtins.getFlake "nixpkgs"
, floco ? builtins.getFlake "github:aakropotkin/floco"
{ nixpkgs ? builtins.getFlake "nixpkgs"
, floco ? builtins.getFlake "github:aakropotkin/floco"
, sql-builder-src ? builtins.fetchTree {
type = "github"; owner = "six-ddc"; repo = "sql-builder";
}
, system ? builtins.currentSystem
, pkgsFor ? nixpkgs.legacyPackages.${system}
, stdenv ? pkgsFor.stdenv
Expand All @@ -16,8 +19,16 @@
, boost ? pkgsFor.boost
, argparse ? pkgsFor.argparse
, semver ? floco.legacyPackages.${system}.semver
, sql-builder ? pkgsFor.runCommandNoCC "sql-builder" {
src = sql-builder-src;
} ''
mkdir -p "$out/include/sql-builder";
cp "$src/sql.h" "$out/include/sql-builder/sql.hh";
''
}: import ./pkg-fun.nix {
inherit stdenv sqlite pkg-config nlohmann_json nix boost argparse semver;
inherit
stdenv sqlite pkg-config nlohmann_json nix boost argparse semver sql-builder
;
}


Expand Down
19 changes: 18 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@

inputs.nixpkgs.url = "github:NixOS/nixpkgs";
inputs.floco.url = "github:aakropotkin/floco";
inputs.sql-builder = {
url = "github:six-ddc/sql-builder";
flake = false;
};


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

outputs = { nixpkgs, floco, ... }: let
outputs = { nixpkgs, floco, sql-builder, ... }: let

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

Expand All @@ -32,6 +36,12 @@
overlays.deps = floco.overlays.default;
overlays.flox-resolve = final: prev: {
flox-resolve = final.callPackage ./pkg-fun.nix {};
sql-builder = final.runCommandNoCC "sql-builder" {
src = sql-builder;
} ''
mkdir -p "$out/include/sql-builder";
cp "$src/sql.h" "$out/include/sql-builder/sql.hh";
'';
};
overlays.default = nixpkgs.lib.composeExtensions overlays.deps
overlays.flox-resolve;
Expand All @@ -43,7 +53,7 @@
pkgsFor = ( builtins.getAttr system nixpkgs.legacyPackages ).extend
overlays.default;
in {
inherit (pkgsFor) flox-resolve;
inherit (pkgsFor) flox-resolve sql-builder;
default = pkgsFor.flox-resolve;
} );

Expand Down
12 changes: 10 additions & 2 deletions include/flox/drv-cache.hh
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,20 @@ class DrvDb {
, bool write = true
, bool trace = false
);
~DrvDb();

~DrvDb()
{
try { this->endCommit(); } catch( ... ) {}
}

void startCommit();
void endCommit();

nix::Sync<DrvDb::State>::Lock getDbState();
nix::Sync<DrvDb::State>::Lock
getDbState()
{
return this->_state->lock();
}

bool isWritable() const { return this->_write; }

Expand Down
2 changes: 2 additions & 0 deletions pkg-fun.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
, boost
, argparse
, semver
, sql-builder
}: stdenv.mkDerivation {
pname = "flox-resolver";
version = "0.2.0";
Expand Down Expand Up @@ -50,6 +51,7 @@
"boost_CFLAGS=-I${boost}/include"
"libExt=${stdenv.hostPlatform.extensions.sharedLibrary}"
"SEMVER_PATH=${semver}/bin/semver"
"sql_builder_CFLAGS=-I${sql-builder}/include"
];
configurePhase = ''
runHook preConfigure;
Expand Down
17 changes: 0 additions & 17 deletions src/drv-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,6 @@ DrvDb::DrvDb( const nix::flake::Fingerprint & fingerprint
}


/* -------------------------------------------------------------------------- */

nix::Sync<DrvDb::State>::Lock
DrvDb::getDbState()
{
return this->_state->lock();
}


/* -------------------------------------------------------------------------- */

void
Expand Down Expand Up @@ -428,14 +419,6 @@ DrvDb::endCommit()
}


/* -------------------------------------------------------------------------- */

DrvDb::~DrvDb()
{
try { endCommit(); } catch ( ... ) { /* nix::ignoreException(); */ }
}


/* -------------------------------------------------------------------------- */

/* Error catching wrapper for insert statements. */
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