Skip to content

Commit

Permalink
Add feature to build without Tcl commands (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
chpock authored May 30, 2024
1 parent 9269066 commit fe9ee63
Show file tree
Hide file tree
Showing 25 changed files with 594 additions and 412 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/linux-build-c.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Linux (without Tcl commands)
on: [push]
permissions:
contents: read
defaults:
run:
shell: bash
jobs:
build:
runs-on: ubuntu-24.04
timeout-minutes: 5
strategy:
matrix:
compiler: ["gcc", "clang"]
name: build (${{ matrix.compiler }})
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Environment (compiler=${{ matrix.compiler }})
run: |
sudo apt-get install tcl8.6-dev
mkdir "$HOME/install dir"
echo "CFGOPT_COMMON=--with-tcl=/usr/lib/tcl8.6" >> $GITHUB_ENV
echo "CC=$COMPILER" >> $GITHUB_ENV
env:
COMPILER: ${{ matrix.compiler }}
OPTS: ${{ matrix.compiler }}
- name: Configure
run: |
./configure $CFGOPT_COMMON --disable-tcl-commands "--prefix=$HOME/install dir" "--exec-prefix=$HOME/install dir" || {
cat config.log
echo "::error::Failure during Configure"
exit 1
}
- name: Build
run: |
make -j || {
echo "::error::Failure during Build"
exit 1
}
- name: Run Tests
run: |
make test || {
echo "::error::Failure during Test"
exit 1
}
- name: Test-Drive Installation
run: |
make install || {
echo "::error::Failure during Install"
exit 1
}
- name: Create Distribution Package
run: |
make dist || {
echo "::error::Failure during Distribute"
exit 1
}
2 changes: 0 additions & 2 deletions .github/workflows/linux-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ jobs:
echo "::error::Failure during Test"
exit 1
}
env:
ERROR_ON_FAILURES: 1
- name: Test-Drive Installation
run: |
make install || {
Expand Down
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
2024-05-30 Konstantin Kushnir <[email protected]>
* Fix multiple memory leaks
* Add feature to build without Tcl commands

2024-05-29 Konstantin Kushnir <[email protected]>
* Fix a regression when register volume and unregister with vfs::unmount
Expand Down
1 change: 0 additions & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* Add support for Tcl9
* Add ability to disable Tcl commands for pages/index. This should reduce binary size.
31 changes: 31 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ MAKE_LIB
EGREP
GREP
COOKFS_PKGCONFIG_USECPKGCONFIG
COOKFS_PKGCONFIG_USETCLCMDS
COOKFS_PKGCONFIG_USECWRITER
COOKFS_PKGCONFIG_USECVFS
COOKFS_PKGCONFIG_FEATURE_METADATA
Expand Down Expand Up @@ -795,6 +796,7 @@ enable_c_writerchannel
enable_c_pkgconfig
enable_c_vfs
enable_c_writer
enable_tcl_commands
'
ac_precious_vars='build_alias
host_alias
Expand Down Expand Up @@ -1442,6 +1444,7 @@ Optional Features:
--disable-c-pkgconfig Use pkgconfig written in C. Defaults to true
--disable-c-vfs Use VFS support written in C. Defaults to true
--disable-c-writer Use writer handler written in C. Defaults to true
--disable-tcl-commands Enable Tcl commands for objects. Defaults to true
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
Expand Down Expand Up @@ -8661,6 +8664,15 @@ else $as_nop
USECWRITER=yes
fi

# Check whether --enable-tcl-commands was given.
if test ${enable_tcl_commands+y}
then :
enableval=$enable_tcl_commands; USETCLCMDS=${enableval}
else $as_nop
USETCLCMDS=yes
fi



if test ${INTERNALDEBUG} = yes; then
printf "%s\n" "#define COOKFS_INTERNAL_DEBUG 1" >>confdefs.h
Expand Down Expand Up @@ -9177,6 +9189,23 @@ else
COOKFS_PKGCONFIG_USECVFS=0
fi

if test ${USETCLCMDS} = no \
&& test ${USECWRITER} = yes \
&& test ${USECWRITERCHAN} = yes \
&& test ${USECVFS} = yes \
&& test ${USECPAGES} = yes \
&& test ${USECFSINDEX} = yes \
&& test ${USECREADERCHAN} = yes
then
COOKFS_PKGCONFIG_USETCLCMDS=0
else
printf "%s\n" "#define COOKFS_USETCLCMDS 1" >>confdefs.h

COOKFS_PKGCONFIG_USETCLCMDS=1
fi






Expand Down Expand Up @@ -9212,6 +9241,8 @@ if test ${USECPKGCONFIG} = yes; then

printf "%s\n" "#define COOKFS_PKGCONFIG_USECWRITER $COOKFS_PKGCONFIG_USECWRITER" >>confdefs.h

printf "%s\n" "#define COOKFS_PKGCONFIG_USETCLCMDS $COOKFS_PKGCONFIG_USETCLCMDS" >>confdefs.h


printf "%s\n" "#define COOKFS_USECPKGCONFIG 1" >>confdefs.h

Expand Down
19 changes: 19 additions & 0 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ AC_ARG_ENABLE(c-writerchannel, [ --disable-c-writerchannel Use writer handler w
AC_ARG_ENABLE(c-pkgconfig, [ --disable-c-pkgconfig Use pkgconfig written in C. Defaults to true], USECPKGCONFIG=${enableval}, USECPKGCONFIG=yes)
AC_ARG_ENABLE(c-vfs, [ --disable-c-vfs Use VFS support written in C. Defaults to true], USECVFS=${enableval}, USECVFS=yes)
AC_ARG_ENABLE(c-writer, [ --disable-c-writer Use writer handler written in C. Defaults to true], USECWRITER=${enableval}, USECWRITER=yes)
AC_ARG_ENABLE(tcl-commands, [ --disable-tcl-commands Enable Tcl commands for objects. Defaults to true], USETCLCMDS=${enableval}, USETCLCMDS=yes)


if test ${INTERNALDEBUG} = yes; then
AC_DEFINE(COOKFS_INTERNAL_DEBUG)
Expand Down Expand Up @@ -247,6 +249,21 @@ else
COOKFS_PKGCONFIG_USECVFS=0
fi

if test ${USETCLCMDS} = no \
&& test ${USECWRITER} = yes \
&& test ${USECWRITERCHAN} = yes \
&& test ${USECVFS} = yes \
&& test ${USECPAGES} = yes \
&& test ${USECFSINDEX} = yes \
&& test ${USECREADERCHAN} = yes
then
COOKFS_PKGCONFIG_USETCLCMDS=0
else
AC_DEFINE(COOKFS_USETCLCMDS)
COOKFS_PKGCONFIG_USETCLCMDS=1
fi


AC_SUBST(COOKFS_PKGCONFIG_FEATURE_ASIDE)
AC_SUBST(COOKFS_PKGCONFIG_USECPAGES)
AC_SUBST(COOKFS_PKGCONFIG_USECREADERCHAN)
Expand All @@ -257,6 +274,7 @@ AC_SUBST(COOKFS_PKGCONFIG_USECFSINDEX)
AC_SUBST(COOKFS_PKGCONFIG_FEATURE_METADATA)
AC_SUBST(COOKFS_PKGCONFIG_USECVFS)
AC_SUBST(COOKFS_PKGCONFIG_USECWRITER)
AC_SUBST(COOKFS_PKGCONFIG_USETCLCMDS)

if test ${USECPKGCONFIG} = yes; then
COOKFS_PKGCONFIG_USECPKGCONFIG=1
Expand All @@ -271,6 +289,7 @@ if test ${USECPKGCONFIG} = yes; then
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_FEATURE_METADATA, $COOKFS_PKGCONFIG_FEATURE_METADATA)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USECVFS, $COOKFS_PKGCONFIG_USECVFS)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USECWRITER, $COOKFS_PKGCONFIG_USECWRITER)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USETCLCMDS, $COOKFS_PKGCONFIG_USETCLCMDS)

AC_DEFINE(COOKFS_USECPKGCONFIG)
else
Expand Down
22 changes: 10 additions & 12 deletions generic/cookfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,39 @@
DLLEXPORT int
Cookfs_Init(Tcl_Interp *interp) // cppcheck-suppress unusedFunction
{
char buf[256];

if (Tcl_InitStubs(interp, "8.5", 0) == NULL) {
return TCL_ERROR;
}

strcpy(buf, "namespace eval ::cookfs {} ; namespace eval ::cookfs::c {}");
if (Tcl_EvalEx(interp, buf, -1, TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL) != TCL_OK) {
return TCL_ERROR;
}
Tcl_CreateNamespace(interp, "::cookfs", NULL, NULL);
Tcl_CreateNamespace(interp, "::cookfs::c", NULL, NULL);

#ifdef COOKFS_USECPAGES
#if defined(COOKFS_USECPAGES) && defined(COOKFS_USETCLCMDS)
if (Cookfs_InitPagesCmd(interp) != TCL_OK) {
return TCL_ERROR;
}
#endif

#ifdef COOKFS_USECFSINDEX
#if defined(COOKFS_USECFSINDEX) && defined(COOKFS_USETCLCMDS)
if (Cookfs_InitFsindexCmd(interp) != TCL_OK) {
return TCL_ERROR;
}
#endif

#ifdef COOKFS_USECREADERCHAN
#if defined(COOKFS_USECREADERCHAN) && defined(COOKFS_USETCLCMDS)
if (Cookfs_InitReaderchannelCmd(interp) != TCL_OK) {
return TCL_ERROR;
}
#endif

#ifdef COOKFS_USECWRITER
#if defined(COOKFS_USECWRITER) && defined(COOKFS_USETCLCMDS)
if (Cookfs_InitWriterCmd(interp) != TCL_OK) {
return TCL_ERROR;
}
#endif

#ifdef COOKFS_USECWRITERCHAN
#if defined(COOKFS_USECWRITERCHAN) && defined(COOKFS_USETCLCMDS)
if (Cookfs_InitWriterchannelCmd(interp) != TCL_OK) {
return TCL_ERROR;
}
Expand All @@ -76,13 +74,13 @@ Cookfs_Init(Tcl_Interp *interp) // cppcheck-suppress unusedFunction
return TCL_ERROR;
}

#ifdef COOKFS_USECVFS
#if defined(COOKFS_USECVFS)
if (Cookfs_InitVfsMountCmd(interp) != TCL_OK) {
return TCL_ERROR;
}
#endif

#ifdef COOKFS_USECPKGCONFIG
#if defined(COOKFS_USECPKGCONFIG)
Tcl_RegisterConfig(interp, PACKAGE_NAME, cookfs_pkgconfig, "iso8859-1");

if (Tcl_PkgProvide(interp, PACKAGE_NAME "::pkgconfig", PACKAGE_VERSION) != TCL_OK) {
Expand Down
1 change: 1 addition & 0 deletions generic/cookfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static Tcl_Config const cookfs_pkgconfig[] = {
{"feature-bzip2", STRINGIFY(COOKFS_PKGCONFIG_USEBZ2)},
{"feature-xz", STRINGIFY(COOKFS_PKGCONFIG_USEXZ)},
{"feature-metadata", STRINGIFY(COOKFS_PKGCONFIG_FEATURE_METADATA)},
{"tcl-commands", STRINGIFY(COOKFS_PKGCONFIG_USETCLCMDS)},
{NULL, NULL}
};
#endif /* COOKFS_USECPKGCONFIG */
Expand Down
6 changes: 6 additions & 0 deletions generic/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ Cookfs_Vfs *Cookfs_VfsInit(Tcl_Interp* interp, Tcl_Obj* mountPoint,
vfs->commandToken = NULL;
vfs->interp = interp;
vfs->isDead = 0;
#ifdef COOKFS_USETCLCMDS
vfs->isRegistered = 0;
#endif
vfs->isVolume = isVolume;
vfs->isCurrentDirTime = isCurrentDirTime;
vfs->isReadonly = isReadonly;
Expand Down Expand Up @@ -174,6 +176,8 @@ int Cookfs_VfsFini(Tcl_Interp *interp, Cookfs_Vfs *vfs,
return TCL_OK;
}

#ifdef COOKFS_USETCLCMDS

void Cookfs_VfsUnregisterInTclvfs(Cookfs_Vfs *vfs) {

if (!vfs->isRegistered) {
Expand Down Expand Up @@ -268,6 +272,8 @@ int Cookfs_VfsRegisterInTclvfs(Cookfs_Vfs *vfs) {
return ret;
}

#endif

int Cookfs_VfsIsReadonly(Cookfs_Vfs *vfs) {
return vfs->isReadonly;
}
Expand Down
4 changes: 4 additions & 0 deletions generic/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ typedef struct Cookfs_Vfs {
Tcl_Command commandToken;

int isDead;
#ifdef COOKFS_USETCLCMDS
int isRegistered;
#endif

int isCurrentDirTime;
int isVolume;
Expand All @@ -38,7 +40,9 @@ int Cookfs_VfsFini(Tcl_Interp *interp, Cookfs_Vfs *vfs,
int Cookfs_VfsIsReadonly(Cookfs_Vfs *vfs);
void Cookfs_VfsSetReadonly(Cookfs_Vfs *vfs, int status);

#ifdef COOKFS_USETCLCMDS
void Cookfs_VfsUnregisterInTclvfs(Cookfs_Vfs *vfs);
int Cookfs_VfsRegisterInTclvfs(Cookfs_Vfs *vfs);
#endif

#endif /* COOKFS_VFS_H */
Loading

0 comments on commit fe9ee63

Please sign in to comment.