Skip to content

Commit 7ea9f11

Browse files
committed
Don't use the same macro expression multiple times.
Put the logic to when to use zipfs in one place, set `USE_ZIPFS_INIT` define with that value and use it for `#ifdef` ranges. With that, also `#ifdef`-out the `GetProgramLocation()`, which is not needed in the zipfs case. Signed-off-by: Henner Zeller <h.zeller@acm.org>
1 parent 5762259 commit 7ea9f11

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

bazel/tcl_library_init.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212

1313
#include "tcl.h"
1414

15+
// In tcl 9, we can use the //zipfs:/ virtual file system (unless
16+
// we specifically disabled with the --//bazel:use_zipfs=False flag)
1517
#if TCL_MAJOR_VERSION >= 9 && !defined(USE_TCL_RUNFILE_INIT)
18+
#define USE_ZIPFS_INIT 1
19+
#else
20+
#define USE_ZIPFS_INIT 0
21+
#endif
22+
23+
#if USE_ZIPFS_INIT
1624
#include "bazel/tcl_resources_zip_data.h"
1725
#else
1826

@@ -31,6 +39,7 @@
3139

3240
namespace in_bazel {
3341

42+
#if !USE_ZIPFS_INIT
3443
// Avoid adding any dependencies like boost.filesystem
3544
// Returns path to running binary if possible.
3645
static std::string GetProgramLocation()
@@ -53,12 +62,13 @@ static std::string GetProgramLocation()
5362
}
5463
return Tcl_GetNameOfExecutable();
5564
}
65+
#endif
5666

5767
static std::optional<std::string> TclLibraryMountPoint(Tcl_Interp* interp)
5868
{
5969
// In tcl9, we can use //zipfs:/ otherwise we need to point to the
6070
// directory where the tcl library files are extracted.
61-
#if TCL_MAJOR_VERSION >= 9 && !defined(USE_TCL_RUNFILE_INIT)
71+
#if USE_ZIPFS_INIT
6272
if (TclZipfs_MountBuffer(
6373
interp, kTclResourceZip, sizeof(kTclResourceZip), "/app", 0)
6474
!= TCL_OK) {

0 commit comments

Comments
 (0)