Merge branch 'next'

This commit is contained in:
John Wiegley 2009-11-01 06:10:49 -05:00
commit 0cb80a51ea
13 changed files with 126 additions and 61 deletions

1
.gitignore vendored
View file

@ -61,3 +61,4 @@
/stamp-h1 /stamp-h1
/test/python/ /test/python/
/util_tests /util_tests
/mkinstalldirs

24
acprep
View file

@ -18,9 +18,13 @@ import shutil
import string import string
import sys import sys
import time import time
import hashlib
import tempfile import tempfile
try:
import hashlib
except:
import md5
from os.path import * from os.path import *
from stat import * from stat import *
from subprocess import Popen, PIPE, call from subprocess import Popen, PIPE, call
@ -580,18 +584,19 @@ class PrepareBuild(CommandLineApp):
] ]
self.log.info('Executing: ' + string.join(packages, ' ')) self.log.info('Executing: ' + string.join(packages, ' '))
self.execute(*packages) self.execute(*packages)
elif exists('/etc/redhat-release'):
if exists('/etc/redhat-release'):
release = open('/etc/redhat-release') release = open('/etc/redhat-release')
if issue.readline().startswith('CentOS'): if release.readline().startswith('CentOS'):
self.log.info('Looks like you are using YUM on CentOS') self.log.info('Looks like you are using YUM on CentOS')
packages = [ packages = [
'sudo', 'yum', 'install', 'gcc', 'make', 'sudo', 'yum', 'install', 'gcc', 'gcc-c++',
'libtool', 'autoconf', 'automake', 'compat-gcc-*', 'make', 'libtool', 'autoconf',
'zlib-devel', 'bzip2-devel', 'python-devel', 'automake', 'zlib-devel', 'bzip2-devel',
'bboost-devel', 'python-devel', 'bboost-devel',
'gmp-devel', 'gettext-devel', 'gmp-devel', 'gettext-devel',
#'mpfr-devel' #'mpfr-devel'
#'libedit-dev', 'libedit-devel',
'cppunit-devel', 'cppunit-devel',
#'texlive-full', #'texlive-full',
#'doxygen', 'graphviz', 'texinfo', #'doxygen', 'graphviz', 'texinfo',
@ -623,7 +628,10 @@ class PrepareBuild(CommandLineApp):
sys.exit(1) sys.exit(1)
fd = open(tarball) fd = open(tarball)
try:
csum = hashlib.md5() csum = hashlib.md5()
except:
csum = md5.md5()
csum.update(fd.read()) csum.update(fd.read())
fd.close() fd.close()
digest = csum.hexdigest() digest = csum.hexdigest()

View file

@ -50,7 +50,6 @@
namespace ledger { namespace ledger {
class session_t;
class account_t; class account_t;
class xact_t; class xact_t;
class post_t; class post_t;

View file

@ -192,7 +192,7 @@ public:
explicit annotated_commodity_t(commodity_t * _ptr, explicit annotated_commodity_t(commodity_t * _ptr,
const annotation_t& _details) const annotation_t& _details)
: commodity_t(_ptr->parent_, _ptr->base), ptr(_ptr), details(_details) { : commodity_t(_ptr->parent_, _ptr->base), ptr(_ptr), details(_details) {
TRACE_CTOR(annotated_commodity_t, ""); TRACE_CTOR(annotated_commodity_t, "commodity_t *, annotation_t");
annotated = true; annotated = true;
} }
virtual ~annotated_commodity_t() { virtual ~annotated_commodity_t() {
@ -216,7 +216,9 @@ public:
#if defined(HAVE_BOOST_SERIALIZATION) #if defined(HAVE_BOOST_SERIALIZATION)
private: private:
explicit annotated_commodity_t() : ptr(NULL) {} explicit annotated_commodity_t() : ptr(NULL) {
TRACE_CTOR(annotated_commodity_t, "");
}
/** Serialization. */ /** Serialization. */

View file

@ -42,7 +42,8 @@
#include "post.h" #include "post.h"
#include "xact.h" #include "xact.h"
#define ARCHIVE_VERSION 0x03000001 #define LEDGER_MAGIC 0x4c454447
#define ARCHIVE_VERSION 0x03000002
//BOOST_IS_ABSTRACT(ledger::scope_t) //BOOST_IS_ABSTRACT(ledger::scope_t)
BOOST_CLASS_EXPORT(ledger::scope_t) BOOST_CLASS_EXPORT(ledger::scope_t)
@ -63,25 +64,64 @@ template void ledger::journal_t::serialize(boost::archive::binary_iarchive&,
const unsigned int); const unsigned int);
namespace ledger { namespace ledger {
void archive_t::read_header() namespace {
bool read_header_bits(std::istream& in) {
uint32_t bytes;
assert(sizeof(uint32_t) == 4);
in.read(reinterpret_cast<char *>(&bytes), sizeof(uint32_t));
if (bytes != LEDGER_MAGIC) {
DEBUG("archive.journal", "Magic bytes not present");
return false;
}
in.read(reinterpret_cast<char *>(&bytes), sizeof(uint32_t));
if (bytes != ARCHIVE_VERSION) {
DEBUG("archive.journal", "Archive version mismatch");
return false;
}
return true;
}
void write_header_bits(std::ostream& out) {
uint32_t bytes;
assert(sizeof(uint32_t) == 4);
bytes = LEDGER_MAGIC;
out.write(reinterpret_cast<char *>(&bytes), sizeof(uint32_t));
bytes = ARCHIVE_VERSION;
out.write(reinterpret_cast<char *>(&bytes), sizeof(uint32_t));
}
}
bool archive_t::read_header()
{ {
if (exists(file)) { uintmax_t size = file_size(file);
if (size < 8)
return false;
// Open the stream, read the version number and the list of sources // Open the stream, read the version number and the list of sources
ifstream stream(file, std::ios::binary); ifstream stream(file, std::ios::binary);
if (! read_header_bits(stream))
return false;
boost::archive::binary_iarchive iarchive(stream); boost::archive::binary_iarchive iarchive(stream);
DEBUG("archive.journal", "Reading header from archive"); DEBUG("archive.journal", "Reading header from archive");
iarchive >> *this; iarchive >> *this;
DEBUG("archive.journal", DEBUG("archive.journal",
"Version number: " << std::hex << version << std::dec); "Version number: " << std::hex << ARCHIVE_VERSION << std::dec);
DEBUG("archive.journal", "Number of sources: " << sources.size()); DEBUG("archive.journal", "Number of sources: " << sources.size());
#if defined(DEBUG_ON) #if defined(DEBUG_ON)
foreach (const journal_t::fileinfo_t& i, sources) foreach (const journal_t::fileinfo_t& i, sources)
DEBUG("archive.journal", "Loaded source: " << *i.filename); DEBUG("archive.journal", "Loaded source: " << *i.filename);
#endif #endif
}
return true;
} }
bool archive_t::should_load(const std::list<path>& data_files) bool archive_t::should_load(const std::list<path>& data_files)
@ -95,8 +135,8 @@ bool archive_t::should_load(const std::list<path>& data_files)
return false; return false;
} }
if (version != ARCHIVE_VERSION) { if (! read_header()) {
DEBUG("archive.journal", "No, it fails the version check"); DEBUG("archive.journal", "No, header failed to read");
return false; return false;
} }
@ -205,10 +245,9 @@ void archive_t::save(shared_ptr<journal_t> journal)
{ {
INFO_START(archive, "Saved journal file cache"); INFO_START(archive, "Saved journal file cache");
ofstream archive(file, std::ios::binary); ofstream stream(file, std::ios::binary);
boost::archive::binary_oarchive oa(archive);
version = ARCHIVE_VERSION; write_header_bits(stream);
sources = journal->sources; sources = journal->sources;
#if defined(DEBUG_ON) #if defined(DEBUG_ON)
@ -216,8 +255,10 @@ void archive_t::save(shared_ptr<journal_t> journal)
DEBUG("archive.journal", "Saving source: " << *i.filename); DEBUG("archive.journal", "Saving source: " << *i.filename);
#endif #endif
DEBUG("archive.journal", boost::archive::binary_oarchive oa(stream);
"Creating archive with version " << std::hex << version << std::dec);
DEBUG("archive.journal", "Creating archive with version "
<< std::hex << ARCHIVE_VERSION << std::dec);
oa << *this; oa << *this;
DEBUG("archive.journal", DEBUG("archive.journal",
@ -232,6 +273,9 @@ bool archive_t::load(shared_ptr<journal_t> journal)
INFO_START(archive, "Read cached journal file"); INFO_START(archive, "Read cached journal file");
ifstream stream(file, std::ios::binary); ifstream stream(file, std::ios::binary);
if (! read_header_bits(stream))
return false;
boost::archive::binary_iarchive iarchive(stream); boost::archive::binary_iarchive iarchive(stream);
// Skip past the archive header, it was already read in before // Skip past the archive header, it was already read in before

View file

@ -58,7 +58,6 @@ namespace ledger {
class archive_t class archive_t
{ {
path file; path file;
uint32_t version;
std::list<journal_t::fileinfo_t> sources; std::list<journal_t::fileinfo_t> sources;
@ -66,19 +65,17 @@ public:
archive_t() { archive_t() {
TRACE_CTOR(archive_t, ""); TRACE_CTOR(archive_t, "");
} }
archive_t(const path& _file) archive_t(const path& _file) : file(_file) {
: file(_file), version(0) {
TRACE_CTOR(archive_t, "const path&"); TRACE_CTOR(archive_t, "const path&");
} }
archive_t(const archive_t& ar) archive_t(const archive_t& ar) : file(ar.file) {
: file(ar.file), version(0) {
TRACE_CTOR(archive_t, "copy"); TRACE_CTOR(archive_t, "copy");
} }
~archive_t() { ~archive_t() {
TRACE_DTOR(archive_t); TRACE_DTOR(archive_t);
} }
void read_header(); bool read_header();
bool should_load(const std::list<path>& data_files); bool should_load(const std::list<path>& data_files);
bool should_save(shared_ptr<journal_t> journal); bool should_save(shared_ptr<journal_t> journal);
@ -94,7 +91,6 @@ private:
template<class Archive> template<class Archive>
void serialize(Archive & ar, const unsigned int /* version */) { void serialize(Archive & ar, const unsigned int /* version */) {
ar & version;
ar & sources; ar & sources;
} }
#endif // HAVE_BOOST_SERIALIZATION #endif // HAVE_BOOST_SERIALIZATION

View file

@ -91,7 +91,9 @@ class commodity_t
public: public:
class base_t : public noncopyable, public supports_flags<uint_least16_t> class base_t : public noncopyable, public supports_flags<uint_least16_t>
{ {
base_t() {} base_t() {
TRACE_CTOR(base_t, "");
}
public: public:
typedef std::map<const datetime_t, amount_t> history_map; typedef std::map<const datetime_t, amount_t> history_map;
@ -236,7 +238,7 @@ public:
const shared_ptr<base_t>& _base) const shared_ptr<base_t>& _base)
: delegates_flags<uint_least16_t>(*_base.get()), base(_base), : delegates_flags<uint_least16_t>(*_base.get()), base(_base),
parent_(_parent), annotated(false) { parent_(_parent), annotated(false) {
TRACE_CTOR(commodity_t, ""); TRACE_CTOR(commodity_t, "commodity_pool_t *, shared_ptr<base_t>");
} }
virtual ~commodity_t() { virtual ~commodity_t() {
TRACE_DTOR(commodity_t); TRACE_DTOR(commodity_t);
@ -394,7 +396,9 @@ private:
protected: protected:
explicit commodity_t() explicit commodity_t()
: delegates_flags<uint_least16_t>(temp_flags), parent_(NULL), : delegates_flags<uint_least16_t>(temp_flags), parent_(NULL),
annotated(false) {} annotated(false) {
TRACE_CTOR(commodity_t, "");
}
private: private:
/** Serialization. */ /** Serialization. */

View file

@ -219,7 +219,9 @@ public:
#if defined(HAVE_BOOST_SERIALIZATION) #if defined(HAVE_BOOST_SERIALIZATION)
private: private:
explicit call_scope_t() {} explicit call_scope_t() {
TRACE_CTOR(call_scope_t, "");
}
/** Serialization. */ /** Serialization. */

View file

@ -130,15 +130,17 @@ std::size_t session_t::read_data(const string& master_account)
price_db_path = resolve_path(HANDLER(price_db_).str()); price_db_path = resolve_path(HANDLER(price_db_).str());
optional<archive_t> cache; optional<archive_t> cache;
#if 1
// jww (2009-11-01): The binary caching feature is disabled for now.
if (HANDLED(cache_) && master_account.empty()) { if (HANDLED(cache_) && master_account.empty()) {
cache = archive_t(HANDLED(cache_).str()); cache = archive_t(HANDLED(cache_).str());
cache->read_header();
if (price_db_path) { if (price_db_path) {
HANDLER(file_).data_files.push_back(*price_db_path); HANDLER(file_).data_files.push_back(*price_db_path);
populated_price_db = true; populated_price_db = true;
} }
} }
#endif
if (! (cache && if (! (cache &&
cache->should_load(HANDLER(file_).data_files) && cache->should_load(HANDLER(file_).data_files) &&

View file

@ -486,6 +486,7 @@ void instance_t::option_directive(char * line)
*p++ = '\0'; *p++ = '\0';
} }
#if 0
if (! process_option(pathname.string(), line + 2, scope, p, line) && if (! process_option(pathname.string(), line + 2, scope, p, line) &&
! dynamic_cast<session_t *>(&scope)) { ! dynamic_cast<session_t *>(&scope)) {
if (std::strlen(line + 2) == 1) if (std::strlen(line + 2) == 1)
@ -493,6 +494,9 @@ void instance_t::option_directive(char * line)
else else
throw_(option_error, _("Illegal option --%1") << line + 2); throw_(option_error, _("Illegal option --%1") << line + 2);
} }
#else
process_option(pathname.string(), line + 2, scope, p, line);
#endif
} }
void instance_t::automated_xact_directive(char * line) void instance_t::automated_xact_directive(char * line)
@ -520,6 +524,7 @@ void instance_t::automated_xact_directive(char * line)
journal.auto_xacts.push_back(ae.get()); journal.auto_xacts.push_back(ae.get());
ae->journal = &journal;
ae->pos = position_t(); ae->pos = position_t();
ae->pos->pathname = pathname; ae->pos->pathname = pathname;
ae->pos->beg_pos = pos; ae->pos->beg_pos = pos;
@ -555,6 +560,7 @@ void instance_t::period_xact_directive(char * line)
if (parse_posts(account_stack.front(), *pe.get())) { if (parse_posts(account_stack.front(), *pe.get())) {
reveal_context = true; reveal_context = true;
pe->journal = &journal;
if (pe->finalize()) { if (pe->finalize()) {
extend_xact_base(&journal, *pe.get(), true); extend_xact_base(&journal, *pe.get(), true);
@ -570,6 +576,7 @@ void instance_t::period_xact_directive(char * line)
pe.release(); pe.release();
} else { } else {
pe->journal = NULL;
throw parse_error(_("Period transaction failed to balance")); throw parse_error(_("Period transaction failed to balance"));
} }
} }

View file

@ -457,7 +457,7 @@ bool xact_t::valid() const
DEBUG("ledger.validate", "xact_t: ! _date"); DEBUG("ledger.validate", "xact_t: ! _date");
return false; return false;
} }
if (! journal) { if (! has_flags(ITEM_GENERATED | ITEM_TEMP) && ! journal) {
DEBUG("ledger.validate", "xact_t: ! journal"); DEBUG("ledger.validate", "xact_t: ! journal");
return false; return false;
} }

View file

@ -79,7 +79,9 @@ public:
virtual bool remove_post(post_t * post); virtual bool remove_post(post_t * post);
virtual bool finalize(); virtual bool finalize();
virtual bool valid() const = 0; virtual bool valid() const {
return true;
}
#if defined(HAVE_BOOST_SERIALIZATION) #if defined(HAVE_BOOST_SERIALIZATION)
private: private:
@ -179,9 +181,6 @@ public:
} }
virtual void extend_xact(xact_base_t& xact, bool post); virtual void extend_xact(xact_base_t& xact, bool post);
virtual bool valid() const {
return true;
}
#if defined(HAVE_BOOST_SERIALIZATION) #if defined(HAVE_BOOST_SERIALIZATION)
private: private:
@ -262,14 +261,6 @@ class period_xact_t : public xact_base_t
TRACE_DTOR(period_xact_t); TRACE_DTOR(period_xact_t);
} }
virtual bool valid() const {
if (! period.is_valid()) {
DEBUG("ledger.validate", "period_xact_t: ! period.is_valid()");
return false;
}
return true;
}
#if defined(HAVE_BOOST_SERIALIZATION) #if defined(HAVE_BOOST_SERIALIZATION)
private: private:
/** Serialization. */ /** Serialization. */

View file

@ -4,8 +4,17 @@ set -e
rm -fr ~/Products/ledger* rm -fr ~/Products/ledger*
if ./acprep -j16 --warn proof 2>&1 | tee ~/Desktop/proof.log; then ./acprep -j16 --warn proof 2>&1 | tee ~/Desktop/proof.log
echo "Ledger proof build succeeded"
if egrep -q '(ERROR|CRITICAL)' ~/Desktop/proof.log; then
if [ "$1" = "--alert" ]; then
notify "Ledger proof build FAILED"
else
echo "Ledger proof build FAILED"
exit 1
fi
else else
notify "Ledger proof build failed" echo "Ledger proof build succeeded"
fi fi
exit 0