Skip to content

Commit

Permalink
Provide build flag to Disable compilation of libyang dependent interf…
Browse files Browse the repository at this point in the history
…aces

vkarri@6c5cda5d64fa:/sonic/src/sonic-swss-common$ debuild -b -us -uc -Pnopython2,noyangmod
vkarri@6c5cda5d64fa:/sonic/src$ sudo dpkg -i libswsscommon_1.0.0_amd64.deb
vkarri@6c5cda5d64fa:/sonic/src$ sudo dpkg -i python3-swsscommon_1.0.0_amd64.deb
vkarri@6c5cda5d64fa:/sonic/src$ python3 -c "from swsscommon.swsscommon import DecoratorSubscriberStateTable, DecoratorTable, YangDefaultDecorator"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'DecoratorSubscriberStateTable' from 'swsscommon.swsscommon' (/usr/lib/python3/dist-packages/swsscommon/swsscommon.py)
vkarri@6c5cda5d64fa:/sonic/src$ python3 -c "from swsscommon.swsscommon import DecoratorTable, YangDefaultDecorator"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'DecoratorTable' from 'swsscommon.swsscommon' (/usr/lib/python3/dist-packages/swsscommon/swsscommon.py)
vkarri@6c5cda5d64fa:/sonic/src$ python3 -c "from swsscommon.swsscommon import YangDefaultDecorator"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'YangDefaultDecorator' from 'swsscommon.swsscommon' (/usr/lib/python3/dist-packages/swsscommon/swsscommon.py)
vkarri@6c5cda5d64fa:/sonic/src$ python3 -c "from swsscommon.swsscommon import SubscriberStateTable, ProducerStateTable, Table, DBConnector"

<Default Behavior>
vkarri@6c5cda5d64fa:/sonic$ make -f slave.mk target/debs/bookworm/python3-swsscommon_1.0.0_amd64.deb-install
vkarri@6c5cda5d64fa:/sonic$ python3 -c "from swsscommon.swsscommon import DecoratorSubscriberStateTable, DecoratorTable, YangDefaultDecorator"
vkarri@6c5cda5d64fa:/sonic$

Signed-off-by: Vivek Reddy <[email protected]>
  • Loading branch information
vivekrnv committed Jan 31, 2024
1 parent 253ceb6 commit 8642389
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 9 deletions.
18 changes: 12 additions & 6 deletions common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ common_libswsscommon_la_SOURCES = \
common/configdb.cpp \
common/dbconnector.cpp \
common/dbinterface.cpp \
common/defaultvalueprovider.cpp \
common/sonicv2connector.cpp \
common/table.cpp \
common/decoratortable.cpp \
common/json.cpp \
common/producertable.cpp \
common/producerstatetable.cpp \
Expand Down Expand Up @@ -60,24 +58,32 @@ common_libswsscommon_la_SOURCES = \
common/exec.cpp \
common/saiaclschema.cpp \
common/subscriberstatetable.cpp \
common/decoratorsubscriberstatetable.cpp \
common/timestamp.cpp \
common/warm_restart.cpp \
common/luatable.cpp \
common/countertable.cpp \
common/redisutility.cpp \
common/restart_waiter.cpp \
common/profileprovider.cpp \
common/zmqclient.cpp \
common/zmqserver.cpp \
common/asyncdbupdater.cpp \
common/asyncdbupdater.cpp \
common/redis_table_waiter.cpp

common_libswsscommon_la_CXXFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(LIBNL_CFLAGS) $(CODE_COVERAGE_CXXFLAGS)
common_libswsscommon_la_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(LIBNL_CPPFLAGS) $(CODE_COVERAGE_CPPFLAGS)
common_libswsscommon_la_LIBADD = -lpthread $(LIBNL_LIBS) $(CODE_COVERAGE_LIBS) -lzmq -lboost_serialization -luuid -lyang
common_libswsscommon_la_LIBADD = -lpthread $(LIBNL_LIBS) $(CODE_COVERAGE_LIBS) -lzmq -lboost_serialization -luuid
common_libswsscommon_la_LDFLAGS = -Wl,-z,now $(LDFLAGS)

if YANGMODS
common_libswsscommon_la_SOURCES += \
common/defaultvalueprovider.cpp \
common/profileprovider.cpp \
common/decoratortable.cpp \
common/decoratorsubscriberstatetable.cpp

common_libswsscommon_la_LIBADD += -lyang
endif

common_swssloglevel_SOURCES = \
common/loglevel.cpp \
common/loglevel_util.cpp
Expand Down
6 changes: 6 additions & 0 deletions common/configdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ class ConfigDBConnector_Native : public SonicV2Connector_Native
ret.setdefault(table_name, {})[self.deserialize_key(row)] = entry
return ret

%}
#endif

#if defined(SWIG) && defined(SWIGPYTHON) && defined(ENABLE_YANG_MODULES)
%pythoncode %{

class YangDefaultDecorator(object):
def __init__(self, config_db_connector):
self.connector = config_db_connector
Expand Down
8 changes: 8 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@ AC_ARG_ENABLE(python2,
no) python2=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-python2) ;;
esac],[python2=true])
AC_ARG_ENABLE(yangmods,
[ --enable-yangmods Generate classes that depend on libyang],
[case "${enableval}" in
yes) yangmods=true ;;
no) yangmods=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-yangmods) ;;
esac],[yangmods=true])
AM_CONDITIONAL(DEBUG, test x$debug = xtrue)
AM_CONDITIONAL(PYTHON2, test x$python2 = xtrue)
AM_CONDITIONAL(YANGMODS, test x$yangmods = xtrue)
if test x$CONFIGURED_ARCH = xarmhf && test x$CROSS_BUILD_ENVIRON = xy; then
AM_CONDITIONAL(ARCH64, false)
else
Expand Down
5 changes: 5 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ else
CONFIGURE_ARGS += --disable-python2
endif

# Skip compiling classes that depend on libyang
ifneq (,$(filter noyangmod,$(DEB_BUILD_PROFILES)))
CONFIGURE_ARGS += --disable-yangmods
endif

# main packaging script
%:
dh $@
Expand Down
4 changes: 4 additions & 0 deletions pyext/py2/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ pyext_py2__swsscommon_la_CPPFLAGS = -std=c++11 -Icommon -I/usr/include/python$(P
pyext_py2__swsscommon_la_LDFLAGS = -module -Wl,-z,now
pyext_py2__swsscommon_la_LIBADD = common/libswsscommon.la -lpython$(PYTHON_VERSION)

if YANGMODS
SWIG_FLAG += -DENABLE_YANG_MODULES
endif

pyext/py2/swsscommon_wrap.cpp: $(SWIG_SOURCES)
$(SWIG) $(SWIG_FLAG) -Icommon -o $@ $<

Expand Down
4 changes: 4 additions & 0 deletions pyext/py3/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ pyext_py3__swsscommon_la_CPPFLAGS = -std=c++11 -Icommon -I/usr/include/python$(P
pyext_py3__swsscommon_la_LDFLAGS = -module -Wl,-z,now
pyext_py3__swsscommon_la_LIBADD = common/libswsscommon.la $(PYTHON3_BLDLIBRARY)

if YANGMODS
SWIG_FLAG += -DENABLE_YANG_MODULES
endif

pyext/py3/swsscommon_wrap.cpp: $(SWIG_SOURCES)
$(SWIG) $(SWIG_FLAG) -Icommon -o $@ $<

Expand Down
8 changes: 7 additions & 1 deletion pyext/swsscommon.i
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,12 @@ T castSelectableObj(swss::Selectable *temp)

%include "schema.h"
%include "dbconnector.h"
#ifdef ENABLE_YANG_MODULES
%include "defaultvalueprovider.h"
%include "profileprovider.h"
#endif
%include "sonicv2connector.h"
%include "pubsub.h"
%include "profileprovider.h"
%include "selectable.h"
%include "select.h"
%include "rediscommand.h"
Expand All @@ -278,7 +280,9 @@ T castSelectableObj(swss::Selectable *temp)
%apply std::vector<std::pair<std::string, std::string>>& OUTPUT {std::vector<std::pair<std::string, std::string>> &ovalues};
%apply std::string& OUTPUT {std::string &value};
%include "table.h"
#ifdef ENABLE_YANG_MODULES
%include "decoratortable.h"
#endif
%clear std::vector<std::string> &keys;
%clear std::vector<std::string> &ops;
%clear std::vector<std::vector<std::pair<std::string, std::string>>> &fvss;
Expand Down Expand Up @@ -318,7 +322,9 @@ T castSelectableObj(swss::Selectable *temp)
%include "consumertable.h"
%include "consumerstatetable.h"
%include "subscriberstatetable.h"
#ifdef ENABLE_YANG_MODULES
%include "decoratorsubscriberstatetable.h"
#endif

%apply std::string& OUTPUT {std::string &op};
%apply std::string& OUTPUT {std::string &data};
Expand Down
8 changes: 6 additions & 2 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@ tests_tests_SOURCES = tests/redis_ut.cpp \
tests/countertable_ut.cpp \
tests/timer_ut.cpp \
tests/cli_ut.cpp \
tests/defaultvalueprovider_ut.cpp \
tests/events_common_ut.cpp \
tests/events_service_ut.cpp \
tests/events_ut.cpp \
tests/restart_waiter_ut.cpp \
tests/redis_table_waiter_ut.cpp \
tests/binary_serializer_ut.cpp \
tests/zmq_state_ut.cpp \
tests/profileprovider_ut.cpp \
tests/main.cpp

tests_tests_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(LIBNL_CFLAGS)
tests_tests_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(LIBNL_CFLAGS) -fno-access-control
tests_tests_LDADD = $(LDADD_GTEST) -lpthread common/libswsscommon.la $(LIBNL_LIBS) $(CODE_COVERAGE_LIBS) sonic-db-cli/libsonicdbcli.la -lzmq -luuid -lboost_serialization

if YANGMODS
tests_tests_SOURCES += \
tests/defaultvalueprovider_ut.cpp \
tests/profileprovider_ut.cpp
endif

0 comments on commit 8642389

Please sign in to comment.