Skip to content

Commit

Permalink
Merge pull request #4080 from masatake/update-libreadtags
Browse files Browse the repository at this point in the history
Update libreadtags
  • Loading branch information
masatake authored Sep 29, 2024
2 parents 9d62ff1 + 123a838 commit 8662b54
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 14 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ readtags_CFLAGS = $(EXTRA_CFLAGS) $(WARNING_CFLAGS) $(COVERAGE_CFLAGS)
dist_readtags_SOURCES = $(READTAGS_SRCS) $(READTAGS_HEADS)
readtags_CPPFLAGS += $(GNULIB_CPPFLAGS)
readtags_CPPFLAGS += -I$(srcdir)/dsl
readtags_CPPFLAGS += -DHAVE_CTAGS_INLINE_H
readtags_LDADD =
readtags_LDADD += $(GNULIB_LIBS)
readtags_LDADD += libutil.a
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ AM_CONDITIONAL(ENABLE_DEBUGGING, [test "x$enable_debugging" = "xyes"])

AC_PROG_CC
AC_PROG_CC_C99
AC_C_INLINE
# For gnulib.
# Typically, this is immediately after AC_PROG_CC, ...
gl_EARLY
Expand Down
47 changes: 41 additions & 6 deletions libreadtags/.circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
version: 2
jobs:
fedora31:
fedora40_cmake:
working_directory: ~/libreadtags
docker:
- image: docker.io/fedora:31
- image: docker.io/fedora:40
steps:
- run:
name: Install Git
command: |
yum -y install git
- checkout
- run:
name: Install build tools
command: |
yum -y install gcc cmake
- run:
name: Build
command: |
mkdir build
cmake -DCMAKE_BUILD_TYPE=Release -DLIBREADTAGS_BUILD_SHARED=ON -S . -B build
cmake --build build --target readtags
- run:
name: Build test cases
command: |
cmake --build build
- run:
name: Run the test cases
command: |
ctest --test-dir build || cat build/Testing/Temporary/LastTest.log
- run:
name: Install
command: |
cmake --build build --target install
test -e /usr/local/include/readtags.h
test -e /usr/local/lib/libreadtags.so
fedora40_autotools:
working_directory: ~/libreadtags
docker:
- image: docker.io/fedora:40
steps:
- run:
name: Install Git
Expand All @@ -24,10 +58,10 @@ jobs:
name: Test
command: |
make check VERBOSE=1
fedora31_distcheck:
fedora40_distcheck:
working_directory: ~/libreadtags
docker:
- image: docker.io/fedora:31
- image: docker.io/fedora:40
steps:
- run:
name: Install Git
Expand All @@ -51,5 +85,6 @@ workflows:
version: 2
build_and_test:
jobs:
- fedora31
- fedora31_distcheck
- fedora40_cmake
- fedora40_autotools
- fedora40_distcheck
3 changes: 3 additions & 0 deletions libreadtags/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.deps
.libs
*.a
*.gcda
*.gcno
*.gcov
Expand Down Expand Up @@ -46,3 +47,5 @@ tests/test-fix-unescaping-input-fields-exuberant
tests/test-fix-unescaping-input-fields-no-mode
tests/test-fix-unescaping-input-fields-backslash
tests/test-fix-unescaping-input-fields-no-filesep

build
106 changes: 106 additions & 0 deletions libreadtags/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
cmake_minimum_required(VERSION 3.22)
project(
readtags
#
# Synchronize VERSION with the value in configure.ac.
VERSION 0.4.0
DESCRIPTION "a library for looking up tag entries in tag files"
HOMEPAGE_URL "https://github.com/universal-ctags/libreadtags"
LANGUAGES C
)

set(CMAKE_C_STANDARD 99)

option(LIBREADTAGS_BUILD_SHARED "Build shared/static library" OFF)

# You don't have to edit API_VERSION.
# See https://cmake.org/cmake/help/latest/command/cmake_file_api.html
set(API_VERSION 1)
#
# Synchronize BUILD_VERSION with the value appended to libreadtags.so.<>.
# that is built with Autotools.
set(BUILD_VERSION 1.1.2)

# Taken from https://gitlab.kitware.com/cmake/community/-/wikis/contrib/macros/TestInline
# Inspired from /usr/share/autoconf/autoconf/c.m4
foreach(KEYWORD "inline" "__inline__" "__inline")
if(NOT DEFINED C_INLINE)
try_compile(C_HAS_${KEYWORD} "${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/test_inline.c"
COMPILE_DEFINITIONS "-Dinline=${KEYWORD}")
if(C_HAS_${KEYWORD})
SET(C_INLINE TRUE)
ADD_DEFINITIONS("-Dinline=${KEYWORD}")
endif(C_HAS_${KEYWORD})
endif(NOT DEFINED C_INLINE)
endforeach(KEYWORD)
if(NOT DEFINED C_INLINE)
ADD_DEFINITIONS("-Dinline=")
endif(NOT DEFINED C_INLINE)

if (LIBREADTAGS_BUILD_SHARED)
message(STATUS "Building shared library")
add_library(${PROJECT_NAME} SHARED readtags.c)
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${BUILD_VERSION}
SOVERSION ${API_VERSION}
PUBLIC_HEADER readtags.h
)
install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include
)
else ()
message(STATUS "Building static library")
add_library(${PROJECT_NAME} STATIC readtags.c)
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include
)
endif ()

add_library(universal-ctags::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

enable_testing()
set(test_cases
test-api-tagsOpen
test-api-tagsFind
test-api-tagsFindPseudoTag
test-api-tagsFirstPseudoTag
test-api-tagsFirst
test-api-tagsClose
test-api-tagsSetSortType

test-fix-unescaping
test-fix-null-deref
test-fix-large-tags
test-fix-unescaping-input-fields
test-fix-unescaping-input-fields-exuberant
test-fix-unescaping-input-fields-no-mode
test-fix-unescaping-input-fields-backslash
test-fix-unescaping-input-fields-no-filesep
)

foreach(t IN LISTS test_cases)
add_executable(${t} tests/${t}.c)
target_link_libraries(${t} readtags)
add_test(NAME ${t}
COMMAND ${t}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)
endforeach()

#
# TODO:
#
# * Support find_package
#
# ParticleG's comments quoted from
# https://github.com/universal-ctags/libreadtags/pull/51#issuecomment-2148017962
#
# Actually, if we prepare CMakeList.txt properly, other CMake projects
# just need to use find_package method to load this package, see
# Finding Packages. But if you use CMake method FetchContent to add
# libreadtags to your project, then current changes should be enough.
#
2 changes: 1 addition & 1 deletion libreadtags/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ACLOCAL_AMFLAGS = -I m4

AM_CFLAGS=-Wall

EXTRA_DIST = README.md NEWS.md
EXTRA_DIST = README.md NEWS.md CMakeLists.txt test_inline.c

lib_LTLIBRARIES = libreadtags.la
libreadtags_la_LDFLAGS = -no-undefined -version-info $(LT_VERSION)
Expand Down
26 changes: 26 additions & 0 deletions libreadtags/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
# Version XXX

- imporve performance; put inline keyword on a hot spot function.

- before this change

```
$ /bin/time ./readtags -t ~/.citre/kernel82.tags -l > /dev/null
9.59user 0.42system 0:10.06elapsed 99%CPU (0avgtext+0avgdata 2819340maxresident)k
0inputs+0outputs (0major+44149minor)pagefaults 0swaps
```

- after this change

```
$ /bin/time ./readtags -t ~/.citre/kernel82.tags -l > /dev/null
7.82user 0.43system 0:08.30elapsed 99%CPU (0avgtext+0avgdata 2819688maxresident)k
0inputs+0outputs (0major+44138minor)pagefaults 0swaps
```

# Version 0.4.0

- support cmake as a build system (ParticleG <particle_g@outlook.com>)

- add libreadtags-uninstalled.pc.in.

# Version 0.3.0

- fix calls to ctype functions (Colomban Wendling <ban@herbesfolles.org>)
Expand Down
65 changes: 65 additions & 0 deletions libreadtags/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# libreadtags

libreadtags is a library for reading tags files generated by ctags.
libreadtags assumes the tags file format explained in [tags(5)](https://docs.ctags.io/en/latest/man/tags.5.html)
of Universal-ctags.
Expand All @@ -10,3 +12,66 @@ NEWS.md describes note worty changes.
If you are looking for command line interface for tags files,
you will like [readtags command](https://docs.ctags.io/en/latest/man/readtags.1.html)
shipped as part of Universal-ctags. It uses libreadtags extensively.

You can build libreadtags with GNU Autotools and CMake.

## Autotools Usage

### Build
```shell
test -e autogen.sh && ./autogen.sh
./configure
make
```

### Test
```shell
make check
```


## CMake Usage

### Build as a standalone project

#### Configure and build only

```shell
mkdir build
cmake -DCMAKE_BUILD_TYPE=Release -DLIBREADTAGS_BUILD_SHARED=ON -S . -B build
cmake --build build --target readtags
```

#### Configure, build, and test
```shell
mkdir build
cmake -DCMAKE_BUILD_TYPE=Release -DLIBREADTAGS_BUILD_SHARED=ON -S . -B build
cmake --build build
ctest --test-dir build
```

#### Configure and install

This will install the library and headers to `/usr/local`.

```shell
mkdir build
cmake -DCMAKE_BUILD_TYPE=Release -DLIBREADTAGS_BUILD_SHARED=ON -S . -B build
sudo cmake --build build --target install
```

### Integrate into other CMake projects

```cmake
include(FetchContent)
FetchContent_Declare(
readtags
GIT_REPOSITORY https://github.com/universal-ctags/libreadtags.git
GIT_TAG master
)
FetchContent_MakeAvailable(readtags)
target_link_libraries(your_target PRIVATE universal-ctags::readtags)
```
16 changes: 14 additions & 2 deletions libreadtags/configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- Autoconf -*-
AC_INIT(libreadtags, 0.3.0)
#
# When updating the above version, you also update VERSION in CMakeList.txt.
AC_INIT(libreadtags, 0.4.0)
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([readtags.c])

Expand All @@ -8,7 +10,8 @@ AC_PROG_LIBTOOL

# LT_VERSION => CURRENT[:REVISION[:AGE]]
#
# (the following instructions are taken from configure.ac in libskk)
# (the following instructions are taken from configure.ac in libskk
# See also "7 Library interface versions" in the libtool info document.)
#
# If library source has changed since last release, increment revision
# If public symbols have been added, removed or changed since last release,
Expand All @@ -20,20 +23,27 @@ AC_PROG_LIBTOOL
#
# 0:0:0
# initial version; API is the same as readtags.h in Exuberant-ctags.
# (libreadtags.so.0.0.0)
#
# 1:0:0
# introduced tagsGetErrno() and tagErrno.
# rename sortType to tagSortType.
# (libreadtags.so.1.0.0)
#
# 2:0:1
# introduced TagErrnoFileMayTooBig.
# introduced tagsFindPseudoTag.
# (libreadtags.so.1.1.0)
#
# 2:1:1
# no change in public interface.
# (libreadtags.so.1.1.1)
#
# 2:2:1
# no change in public interface.
# (libreadtags.so.1.1.2)
#
# When updating LT_VERSION, update BUILD_VERSION of CMakeLists.txt.
#
AC_SUBST(LT_VERSION, [2:2:1])

Expand All @@ -46,8 +56,10 @@ fi
AC_SUBST([GCOV_CFLAGS])

AC_PROG_CC_C99
AC_C_INLINE

AC_CONFIG_FILES([Makefile
libreadtags.pc
libreadtags-uninstalled.pc
tests/Makefile])
AC_OUTPUT
14 changes: 14 additions & 0 deletions libreadtags/libreadtags-uninstalled.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
abs_top_srcdir=@abs_top_srcdir@
abs_top_builddir=@abs_top_builddir@

prefix=
exec_prefix=
libdir=${abs_top_builddir}
includedir=${abs_top_builddir}

Name: libreadtags Uninstalled
Description: a library for looking up tag entries in tag files (Uninstalled)
Version: @VERSION@
Requires:
Libs: -L${libdir} -lreadtags
Cflags: -I${includedir}
Loading

0 comments on commit 8662b54

Please sign in to comment.