Refactoring of resources and modules.

This commit is contained in:
Matthias Koefferlein 2017-08-23 09:58:39 +02:00
parent cbc5697253
commit c0afa4bf58
25 changed files with 342 additions and 99 deletions

View File

@ -232,7 +232,7 @@ HEADERS = \
RESOURCES = \
dbResources.qrc
INCLUDEPATH += ../tl ../gsi
DEPENDPATH += ../tl ../gsi
INCLUDEPATH += $$TL_INC $$GSI_INC
DEPENDPATH += $$TL_INC $$GSI_INC
LIBS += -L$$DESTDIR -lklayout_tl -lklayout_gsi

View File

@ -2,4 +2,10 @@
<qresource prefix="/fonts">
<file>std_font.gds</file>
</qresource>
<qresource prefix="/built-in-macros" >
<file alias="pcell_declaration_helper.lym">built-in-macros/pcell_declaration_helper.lym</file>
</qresource>
<qresource prefix="/built-in-pymacros" >
<file alias="pcell_declaration_helper.lym">built-in-pymacros/pcell_declaration_helper.lym</file>
</qresource>
</RCC>

6
src/drc/drc.pro Normal file
View File

@ -0,0 +1,6 @@
TEMPLATE = subdirs
SUBDIRS = drc unit_tests
unit_tests.depends += drc

23
src/drc/drc/drc.pro Normal file
View File

@ -0,0 +1,23 @@
DESTDIR = $$OUT_PWD/../..
TARGET = klayout_drc
include($$PWD/../../klayout.pri)
include($$PWD/../../lib.pri)
DEFINES += MAKE_DRC_LIBRARY
SOURCES = \
drcForceLink.cc \
HEADERS = \
drcCommon.h \
drcForceLink.h \
RESOURCES = \
drcResources.qrc
INCLUDEPATH += $$TL_INC $$DB_INC $$GSI_INC $$LYM_INC $$RDB_INC
DEPENDPATH += $$TL_INC $$DB_INC $$GSI_INC $$LYM_INC $$RDB_INC
LIBS += -L$$DESTDIR -lklayout_tl -lklayout_db -lklayout_gsi -lklayout_lym -lklayout_rdb

48
src/drc/drc/drcCommon.h Normal file
View File

@ -0,0 +1,48 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2017 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#if !defined(HDR_drcCommon_h)
# define HDR_drcCommon_h
# if defined _WIN32 || defined __CYGWIN__
# ifdef MAKE_DRC_LIBRARY
# define DRC_PUBLIC __declspec(dllexport)
# else
# define DRC_PUBLIC __declspec(dllimport)
# endif
# define DRC_LOCAL
# else
# if __GNUC__ >= 4
# define DRC_PUBLIC __attribute__ ((visibility ("default")))
# define DRC_LOCAL __attribute__ ((visibility ("hidden")))
# else
# define DRC_PUBLIC
# define DRC_LOCAL
# endif
# endif
#endif

View File

@ -0,0 +1,34 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2017 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "drcForceLink.h"
#include "rdbForceLink.h"
namespace drc
{
int _force_link_f ()
{
return 0;
}
}

View File

@ -0,0 +1,40 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2017 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef HDR_drcForceLink
#define HDR_drcForceLink
#include "drcCommon.h"
/**
* @file Include this function to force linking of the drc module
*/
namespace drc
{
DRC_PUBLIC int _force_link_f ();
static int _force_link_target = _force_link_f ();
}
#endif

View File

@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/built-in-macros">
<file alias="drc.lym">built-in-macros/drc.lym</file>
<file alias="drc_interpreters.lym">built-in-macros/drc_interpreters.lym</file>
</qresource>
</RCC>

View File

@ -20,3 +20,11 @@
*/
#include "utHead.h"
#include "rdbForceLink.h"
TEST(1)
{
// @@@ TODO: add tests ..
}

View File

@ -0,0 +1,16 @@
DESTDIR_UT = $$OUT_PWD/../..
DESTDIR = $$OUT_PWD/..
TARGET = drc_tests
include($$PWD/../../klayout.pri)
include($$PWD/../../lib_ut.pri)
SOURCES = \
drcBasicTests.cc \
INCLUDEPATH += ../drc ../../rdb ../../db ../../tl ../../gsi ../../lym ../../ut
DEPENDPATH += ../drc ../../rdb ../../db ../../tl ../../gsi ../../lym ../../ut
LIBS += -L$$DESTDIR_UT -lklayout_drc -lklayout_rdb -lklayout_db -lklayout_tl -lklayout_gsi -lklayout_lym -lklayout_ut

View File

@ -1,17 +1,44 @@
equals(HAVE_QTBINDINGS, "1") {
DEFINES += \
HAVE_QTBINDINGS
}
ANT_INC = $$PWD/ant
BD_INC = $$PWD/buddies/src/bd
DB_INC = $$PWD/db
DRC_INC = $$PWD/drc/drc
EDT_INC = $$PWD/edt
EXT_INC = $$PWD/ext
GSI_INC = $$PWD/gsi
GSIQT_INC = $$PWD/gsiqt
IMG_INC = $$PWD/img
LIB_INC = $$PWD/lib
LAY_INC = $$PWD/lay
LAYBASIC_INC = $$PWD/laybasic
LYM_INC = $$PWD/lym
RDB_INC = $$PWD/rdb
TL_INC = $$PWD/tl
UT_INC = $$PWD/ut
VERSION_INC = $$PWD/version
equals(HAVE_64BIT_COORD, "1") {
DEFINES += \
HAVE_64BIT_COORD
equals(HAVE_RUBY, "1") {
RBA_INC = $$PWD/rba
} else {
RBA_INC = $$PWD/rbastub
}
equals(HAVE_PYTHON, "1") {
DEFINES += \
HAVE_PYTHON
PYA_INC = $$PWD/pya
} else {
PYA_INC = $$PWD/pyastub
}
equals(HAVE_QTBINDINGS, "1") {
DEFINES += HAVE_QTBINDINGS
}
equals(HAVE_64BIT_COORD, "1") {
DEFINES += HAVE_64BIT_COORD
}
equals(HAVE_PYTHON, "1") {
DEFINES += HAVE_PYTHON
}
equals(HAVE_RUBY, "1") {

View File

@ -21,6 +21,7 @@ SUBDIRS = \
ut \
plugins \
buddies \
drc \
equals(HAVE_RUBY, "1") {
SUBDIRS += rba
@ -45,6 +46,7 @@ laybasic.depends += db rdb
ant.depends += laybasic
img.depends += laybasic
edt.depends += laybasic
drc.depends += db rdb lym
lym.depends += tl gsi
equals(HAVE_RUBY, "1") {

View File

@ -40,6 +40,7 @@
#include "libForceLink.h"
#include "antForceLink.h"
#include "imgForceLink.h"
#include "drcForceLink.h"
#include <QTranslator>
#include <QLocale>

View File

@ -1,6 +0,0 @@
# Build-in macros list
pcell_declaration_helper.lym
qobject_helper.lym
drc.lym
drc_interpreters.lym

View File

@ -1,4 +0,0 @@
# Build-in macros list
pcell_declaration_helper.lym
qt_helper.lym

View File

@ -1,16 +1,8 @@
<RCC>
<qresource prefix="/built-in-macros" >
<!-- Hint: the URL's of the templates must be listed in built_in_macros/index.txt -->
<file alias="index.txt">built_in_macros/index.txt</file>
<file alias="pcell_declaration_helper.lym">built_in_macros/pcell_declaration_helper.lym</file>
<file alias="qobject_helper.lym">built_in_macros/qobject_helper.lym</file>
<file alias="drc.lym">built_in_macros/drc.lym</file>
<file alias="drc_interpreters.lym">built_in_macros/drc_interpreters.lym</file>
</qresource>
<qresource prefix="/built-in-pymacros" >
<!-- Hint: the URL's of the templates must be listed in built_in_pymacros/index.txt -->
<file alias="index.txt">built_in_pymacros/index.txt</file>
<file alias="pcell_declaration_helper.lym">built_in_pymacros/pcell_declaration_helper.lym</file>
<file alias="qt_helper.lym">built_in_pymacros/qt_helper.lym</file>
</qresource>
</RCC>

View File

@ -1265,6 +1265,21 @@ void MacroCollection::rescan ()
}
}
namespace {
/**
* @brief A QResource variant that allows access to the children
*/
class ResourceWithChildren
: public QResource
{
public:
ResourceWithChildren (const QString &path) : QResource (path) { }
using QResource::children;
};
}
void MacroCollection::scan (const std::string &path)
{
if (tl::verbosity () >= 20) {
@ -1273,78 +1288,62 @@ void MacroCollection::scan (const std::string &path)
if (! path.empty () && path[0] == ':') {
// look for an index file
QResource res (tl::to_qstring (path + "/index.txt"));
QByteArray data;
if (res.isCompressed ()) {
data = qUncompress ((const unsigned char *)res.data (), (int)res.size ());
} else {
data = QByteArray ((const char *)res.data (), (int)res.size ());
}
ResourceWithChildren res (tl::to_qstring (path));
QStringList children = res.children ();
// Read index file
std::vector<std::string> lines = tl::split (std::string (data.constData (), data.size ()), "\n");
std::string description_prefix;
for (std::vector<std::string>::const_iterator l = lines.begin (); l != lines.end (); ++l) {
for (QStringList::const_iterator c = children.begin (); c != children.end (); ++c) {
std::string ll = tl::trim (*l);
if (! ll.empty () && ll [0] != '#') {
std::string url = path + "/" + tl::to_string (*c);
QResource res (tl::to_qstring (url));
if (res.size () > 0) {
std::string url = path + "/" + ll;
QResource res (tl::to_qstring (url));
if (res.size () > 0) {
QByteArray data;
if (res.isCompressed ()) {
data = qUncompress ((const unsigned char *)res.data (), (int)res.size ());
} else {
data = QByteArray ((const char *)res.data (), (int)res.size ());
}
QByteArray data;
if (res.isCompressed ()) {
data = qUncompress ((const unsigned char *)res.data (), (int)res.size ());
} else {
data = QByteArray ((const char *)res.data (), (int)res.size ());
}
try {
try {
Macro::Format format = Macro::NoFormat;
Macro::Interpreter interpreter = Macro::None;
std::string dsl_name;
bool autorun = false;
Macro::Format format = Macro::NoFormat;
Macro::Interpreter interpreter = Macro::None;
std::string dsl_name;
bool autorun = false;
if (Macro::format_from_suffix (tl::to_string (*c), interpreter, dsl_name, autorun, format)) {
if (Macro::format_from_suffix (ll, interpreter, dsl_name, autorun, format)) {
std::string n = tl::to_string (QFileInfo (*c).baseName ());
std::string n = tl::to_string (QFileInfo (tl::to_qstring (ll)).baseName ());
iterator mm = m_macros.find (n);
bool found = false;
while (mm != m_macros.end () && mm->first == n && ! found) {
if ((interpreter == Macro::None || mm->second->interpreter () == interpreter) &&
(dsl_name.empty () || mm->second->dsl_interpreter () == dsl_name) &&
mm->second->format () == format) {
found = true;
}
++mm;
iterator mm = m_macros.find (n);
bool found = false;
while (mm != m_macros.end () && mm->first == n && ! found) {
if ((interpreter == Macro::None || mm->second->interpreter () == interpreter) &&
(dsl_name.empty () || mm->second->dsl_interpreter () == dsl_name) &&
mm->second->format () == format) {
found = true;
}
if (! found) {
Macro *m = m_macros.insert (std::make_pair (n, new Macro ()))->second;
m->set_parent (this);
m->set_interpreter (interpreter);
m->set_autorun_default (autorun);
m->set_autorun (autorun);
m->set_dsl_interpreter (dsl_name);
m->set_format (format);
m->set_name (n);
m->load_from_string (std::string (data.constData (), data.size ()), url);
m->set_readonly (m_readonly);
m->reset_modified ();
m->set_is_file ();
}
++mm;
}
if (! found) {
Macro *m = m_macros.insert (std::make_pair (n, new Macro ()))->second;
m->set_parent (this);
m->set_interpreter (interpreter);
m->set_autorun_default (autorun);
m->set_autorun (autorun);
m->set_dsl_interpreter (dsl_name);
m->set_format (format);
m->set_name (n);
m->load_from_string (std::string (data.constData (), data.size ()), url);
m->set_readonly (m_readonly);
m->reset_modified ();
m->set_is_file ();
}
} catch (tl::Exception &ex) {
tl::error << "Reading " << url << ": " << ex.msg ();
}
} else {
tl::error << "Resource " << url << " not found";
} catch (tl::Exception &ex) {
tl::error << "Reading " << url << ": " << ex.msg ();
}
}

View File

@ -14,6 +14,7 @@ RESOURCES = \
SOURCES = \
gsiDeclRdb.cc \
rdb.cc \
rdbForceLink.cc \
rdbFile.cc \
rdbReader.cc \
rdbRVEReader.cc \
@ -22,6 +23,7 @@ SOURCES = \
HEADERS = \
rdb.h \
rdbForceLink.h \
rdbReader.h \
rdbTiledRdbOutputReceiver.h \
rdbUtils.h \

View File

@ -20,3 +20,14 @@
*/
#include "rdbForceLink.h"
namespace rdb
{
int _force_link_f ()
{
return 0;
}
}

40
src/rdb/rdbForceLink.h Normal file
View File

@ -0,0 +1,40 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2017 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef HDR_rdbForceLink
#define HDR_rdbForceLink
#include "rdbCommon.h"
/**
* @file Include this function to force linking of the rdb module
*/
namespace rdb
{
RDB_PUBLIC int _force_link_f ();
static int _force_link_target = _force_link_f ();
}
#endif

View File

@ -1,8 +1,8 @@
INCLUDEPATH += $$PYTHONINCLUDE $$PWD/tl $$PWD/gsi $$PWD/db $$PWD/rdb $$PWD/lym $$PWD/laybasic $$PWD/lay $$PWD/ant $$PWD/img $$PWD/edt $$PWD/ext $$PWD/lib $$PWD/common $$PWD/ut $$PWD/version
DEPENDPATH += $$PYTHONINCLUDE $$PWD/tl $$PWD/gsi $$PWD/db $$PWD/rdb $$PWD/lym $$PWD/laybasic $$PWD/lay $$PWD/ant $$PWD/img $$PWD/edt $$PWD/ext $$PWD/lib $$PWD/commo $$PWD/ut $$PWD/version
INCLUDEPATH += $$TL_INC $$GSI_INC $$DB_INC $$RDB_INC $$LYM_INC $$LAYBASIC_INC $$LAY_INC $$ANT_INC $$IMG_INC $$EDT_INC $$DRC_INC $$EXT_INC $$LIB_INC $$UT_INC $$RBA_INC $$PYA_INC $$VERSION_INC
DEPENDPATH += $$TL_INC $$GSI_INC $$DB_INC $$RDB_INC $$LYM_INC $$LAYBASIC_INC $$LAY_INC $$ANT_INC $$IMG_INC $$EDT_INC $$DRC_INC $$EXT_INC $$LIB_INC $$UT_INC $$RBA_INC $$PYA_INC $$VERSION_INC
LIBS += $$PYTHONLIBFILE $$RUBYLIBFILE -L$$DESTDIR -lklayout_tl -lklayout_gsi -lklayout_db -lklayout_rdb -lklayout_lym -lklayout_laybasic -lklayout_lay -lklayout_ant -lklayout_img -lklayout_edt -lklayout_ext -lklayout_lib -lklayout_ut
LIBS += $$PYTHONLIBFILE $$RUBYLIBFILE -L$$DESTDIR -lklayout_tl -lklayout_gsi -lklayout_db -lklayout_rdb -lklayout_lym -lklayout_laybasic -lklayout_lay -lklayout_ant -lklayout_img -lklayout_edt -lklayout_drc -lklayout_ext -lklayout_lib -lklayout_ut
# Note: this accounts for UI-generated headers placed into the output folders in
# shadow builds:
@ -16,21 +16,13 @@ equals(HAVE_QTBINDINGS, "1") {
}
equals(HAVE_RUBY, "1") {
INCLUDEPATH += $$PWD/rba
DEPENDPATH += $$PWD/rba
LIBS += -lklayout_rba
} else {
INCLUDEPATH += $$PWD/rbastub
DEPENDPATH += $$PWD/rbastub
LIBS += -lklayout_rbastub
}
equals(HAVE_PYTHON, "1") {
INCLUDEPATH += $$PWD/pya
DEPENDPATH += $$PWD/pya
LIBS += -lklayout_pya
} else {
INCLUDEPATH += $$PWD/pyastub
DEPENDPATH += $$PWD/pyastub
LIBS += -lklayout_pyastub
}