parent
6859671230
commit
41f51bacc5
@ -0,0 +1,157 @@
|
|||||||
|
from dataclasses import dataclass
|
||||||
|
from enum import Enum, auto
|
||||||
|
from tabnanny import check
|
||||||
|
from aquery_config import *
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import hashlib
|
||||||
|
import pickle
|
||||||
|
from engine.utils import nullstream
|
||||||
|
from typing import Dict, Optional, Set, Union
|
||||||
|
@dataclass
|
||||||
|
class checksums:
|
||||||
|
libaquery_a : Optional[Union[bytes, bool]] = None
|
||||||
|
pch_hpp_gch : Optional[Union[bytes, bool]] = None
|
||||||
|
server : Optional[Union[bytes, bool]] = None
|
||||||
|
sources : Union[Dict[str, bytes], bool] = None
|
||||||
|
def calc(self, libaquery_a = 'libaquery.a',
|
||||||
|
pch_hpp_gch = 'server/pch.hpp.gch',
|
||||||
|
server = 'server.so'
|
||||||
|
):
|
||||||
|
for key in self.__dict__.keys():
|
||||||
|
try:
|
||||||
|
with open(eval(key), 'rb') as file:
|
||||||
|
self.__dict__[key] = hashlib.md5(file.read()).digest()
|
||||||
|
except (FileNotFoundError, NameError):
|
||||||
|
pass
|
||||||
|
sources = [*build_manager.headerfiles, *build_manager.sourcefiles]
|
||||||
|
self.sources = dict()
|
||||||
|
for key in sources:
|
||||||
|
try:
|
||||||
|
with open(key, 'rb') as file:
|
||||||
|
self.sources[key] = hashlib.md5(file.read()).digest()
|
||||||
|
except FileNotFoundError:
|
||||||
|
print('missing component: ' + key)
|
||||||
|
self.sources[key] = None
|
||||||
|
def __ne__(self, __o: 'checksums') -> 'checksums':
|
||||||
|
ret = checksums()
|
||||||
|
for key in self.__dict__.keys():
|
||||||
|
try:
|
||||||
|
ret.__dict__[key] = self.__dict__[key] != __o.__dict__[key]
|
||||||
|
except KeyError:
|
||||||
|
ret.__dict__[key] = True
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def __eq__(self, __o: 'checksums') -> 'checksums':
|
||||||
|
ret = checksums()
|
||||||
|
for key in self.__dict__.keys():
|
||||||
|
try:
|
||||||
|
ret.__dict__[key] = self.__dict__[key] == __o.__dict__[key]
|
||||||
|
except KeyError:
|
||||||
|
ret.__dict__[key] = False
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class build_manager:
|
||||||
|
sourcefiles = ['server/server.cpp', 'server/io.cpp',
|
||||||
|
'server/monetdb_conn.cpp', 'server/threading.cpp',
|
||||||
|
'server/winhelper.cpp'
|
||||||
|
]
|
||||||
|
headerfiles = ['server/aggregations.h', 'server/hasher.h', 'server/io.h',
|
||||||
|
'server/libaquery.h', 'server/monetdb_conn.h', 'server/pch.hpp',
|
||||||
|
'server/table.h', 'server/threading.h', 'server/types.h', 'server/utils.h',
|
||||||
|
'server/winhelper.h', 'server/gc.hpp', 'server/vector_type.hpp',
|
||||||
|
'server/table_ext_monetdb.hpp'
|
||||||
|
]
|
||||||
|
|
||||||
|
class DriverBase:
|
||||||
|
def __init__(self, mgr : 'build_manager') -> None:
|
||||||
|
self.mgr = mgr
|
||||||
|
self.build_cmd = ['']
|
||||||
|
def libaquery_a(self) :
|
||||||
|
pass
|
||||||
|
def pch(self):
|
||||||
|
pass
|
||||||
|
def build(self, stdout = sys.stdout, stderr = sys.stderr):
|
||||||
|
for c in self.build_cmd:
|
||||||
|
subprocess.call(c, stdout = stdout, stderr = stderr)
|
||||||
|
|
||||||
|
class MakefileDriver(DriverBase):
|
||||||
|
def __init__(self, mgr : 'build_manager') -> None:
|
||||||
|
super().__init__(mgr)
|
||||||
|
os.environ['PCH'] = f'{mgr.PCH}'
|
||||||
|
os.environ['CXX'] = mgr.cxx if mgr.cxx else 'c++'
|
||||||
|
|
||||||
|
def libaquery_a(self):
|
||||||
|
self.build_cmd = [['rm', 'libaquery.a'],['make', 'libaquery.a']]
|
||||||
|
return self.build()
|
||||||
|
def pch(self):
|
||||||
|
self.build_cmd = [['rm', 'server/pch.hpp.gch'], ['make', 'pch']]
|
||||||
|
return self.build()
|
||||||
|
def server(self):
|
||||||
|
if self.mgr.StaticLib:
|
||||||
|
self.build_cmd = [['rm', 'server.so'], ['make', 'server_uselib']]
|
||||||
|
else:
|
||||||
|
self.build_cmd = [['rm', 'server.so'], ['make', 'server.so']]
|
||||||
|
return self.build()
|
||||||
|
|
||||||
|
def snippet(self):
|
||||||
|
if self.mgr.StaticLib:
|
||||||
|
self.build_cmd = [['make', 'snippet_uselib']]
|
||||||
|
else:
|
||||||
|
self.build_cmd = [['rm', 'dll.so'], ['make', 'snippet']]
|
||||||
|
return self.build()
|
||||||
|
|
||||||
|
class PythonDriver(DriverBase):
|
||||||
|
def __init__(self, mgr : 'build_manager') -> None:
|
||||||
|
super().__init__(mgr)
|
||||||
|
|
||||||
|
class Driver(Enum):
|
||||||
|
Makefile = auto()
|
||||||
|
Python = auto()
|
||||||
|
CMake = auto()
|
||||||
|
MSBuild = auto()
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.method = 'make'
|
||||||
|
self.cxx = ''
|
||||||
|
self.OptimizationLv = '4' # [O0, O1, O2, O3, Ofast]
|
||||||
|
self.Platform = 'x64'
|
||||||
|
self.PCH = 1
|
||||||
|
self.StaticLib = 1
|
||||||
|
self.fLTO = 1
|
||||||
|
self.fmarchnative = 1
|
||||||
|
self.driver = build_manager.MakefileDriver(self)
|
||||||
|
self.cache_status = checksums()
|
||||||
|
|
||||||
|
def build_dll(self):
|
||||||
|
return self.driver.snippet()
|
||||||
|
|
||||||
|
def build_caches(self, force = False):
|
||||||
|
cached = checksums()
|
||||||
|
current = checksums()
|
||||||
|
current.calc()
|
||||||
|
try:
|
||||||
|
with open('.cached', 'rb') as cache_sig:
|
||||||
|
cached = pickle.loads(cache_sig.read())
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
self.cache_status = current != cached
|
||||||
|
|
||||||
|
if force or self.cache_status.sources:
|
||||||
|
self.driver.pch()
|
||||||
|
self.driver.libaquery_a()
|
||||||
|
self.driver.server()
|
||||||
|
else:
|
||||||
|
if self.cache_status.libaquery_a:
|
||||||
|
self.driver.libaquery_a()
|
||||||
|
if self.cache_status.pch_hpp_gch:
|
||||||
|
self.driver.pch()
|
||||||
|
if self.cache_status.server:
|
||||||
|
self.driver.server()
|
||||||
|
current.calc()
|
||||||
|
with open('.cached', 'wb') as cache_sig:
|
||||||
|
cache_sig.write(pickle.dumps(current))
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
debug:
|
debug:
|
||||||
g++ -g3 -O0 server/server.cpp server/table.cpp -o a.out -Wall -Wextra -Wpedantic -lpthread
|
g++ -g3 -O0 server/server.cpp server/io.cpp -o a.out -Wall -Wextra -Wpedantic -lpthread
|
||||||
|
|
||||||
test:
|
test:
|
||||||
g++ --std=c++1z -g3 -O0 server.cpp table.cpp -o a.out -Wall -Wextra -Wpedantic -lpthread
|
g++ --std=c++1z -g3 -O0 server.cpp io.cpp -o a.out -Wall -Wextra -Wpedantic -lpthread
|
||||||
|
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "libaquery.h"
|
||||||
|
#include "aggregations.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <chrono>
|
||||||
|
#include "monetdb_conn.h"
|
||||||
|
#include "monetdbe.h"
|
||||||
|
#include "threading.h"
|
||||||
|
#include "../csv.h"
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include "winhelper.h"
|
||||||
|
#else
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#endif
|
@ -1,32 +0,0 @@
|
|||||||
#include "table.h"
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __SIZEOF_INT128__
|
|
||||||
template <>
|
|
||||||
void print<__int128_t>(const __int128_t& v, const char* delimiter){
|
|
||||||
char s[41];
|
|
||||||
s[40] = 0;
|
|
||||||
std::cout<< get_int128str(v, s+40)<< delimiter;
|
|
||||||
}
|
|
||||||
template <>
|
|
||||||
void print<__uint128_t>(const __uint128_t&v, const char* delimiter){
|
|
||||||
char s[41];
|
|
||||||
s[40] = 0;
|
|
||||||
std::cout<< get_uint128str(v, s+40) << delimiter;
|
|
||||||
}
|
|
||||||
std::ostream& operator<<(std::ostream& os, __int128 & v)
|
|
||||||
{
|
|
||||||
print(v);
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
std::ostream& operator<<(std::ostream& os, __uint128_t & v)
|
|
||||||
{
|
|
||||||
print(v);
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template <>
|
|
||||||
void print<bool>(const bool&v, const char* delimiter){
|
|
||||||
std::cout<< (v?"true":"false") << delimiter;
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
#include "types.h"
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
#include <chrono>
|
|
||||||
#include <ctime>
|
|
||||||
namespace types {
|
|
||||||
using namespace std;
|
|
||||||
using namespace chrono;
|
|
||||||
string date_t::toString() const {
|
|
||||||
uint32_t curr_v = val;
|
|
||||||
tm;
|
|
||||||
time_t;
|
|
||||||
return string() + string("/") + string() + string("/") + string();
|
|
||||||
}
|
|
||||||
string time_t::toString() const {
|
|
||||||
uint32_t curr_v = val;
|
|
||||||
|
|
||||||
return string() + string("/") + string() + string("/") + string();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
#include "utils.h"
|
|
||||||
#include <random>
|
|
||||||
#include <chrono>
|
|
||||||
using std::string;
|
|
||||||
string base62uuid(int l = 8) {
|
|
||||||
using namespace std;
|
|
||||||
constexpr static const char* base62alp = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
||||||
static mt19937_64 engine(chrono::system_clock::now().time_since_epoch().count());
|
|
||||||
static uniform_int_distribution<uint64_t> u(0x10000, 0xfffff);
|
|
||||||
uint64_t uuid = (u(engine) << 32ull) + (chrono::system_clock::now().time_since_epoch().count() & 0xffffffff);
|
|
||||||
printf("%p\n", uuid);
|
|
||||||
string ret;
|
|
||||||
while (uuid && l-- >= 0) {
|
|
||||||
ret = string("") + base62alp[uuid % 62] + ret;
|
|
||||||
uuid /= 62;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
#include "vector_type.hpp"
|
|
||||||
#include <iostream>
|
|
||||||
template<typename _Ty>
|
|
||||||
inline void vector_type<_Ty>::out(uint32_t n, const char* sep) const
|
|
||||||
{
|
|
||||||
n = n > size ? size : n;
|
|
||||||
std::cout << '(';
|
|
||||||
{
|
|
||||||
uint32_t i = 0;
|
|
||||||
for (; i < n - 1; ++i)
|
|
||||||
std::cout << this->operator[](i) << sep;
|
|
||||||
std::cout << this->operator[](i);
|
|
||||||
}
|
|
||||||
std::cout << ')';
|
|
||||||
}
|
|
Binary file not shown.
Loading…
Reference in new issue