Skip to content

Instantly share code, notes, and snippets.

@yegappan
Last active April 19, 2022 00:15
Show Gist options
  • Save yegappan/1e88a9aed4f9f266d91d768b633487f3 to your computer and use it in GitHub Desktop.
Save yegappan/1e88a9aed4f9f266d91d768b633487f3 to your computer and use it in GitHub Desktop.
My development process for contributing to Vim
I use the below described development process and tools for developing Vim features.
I use a Ubuntu system for most of the development. But the tools mentioned below
are also available on MacOS.
1. Clone the Vim source code from https://github.com/vim/vim.git.
2. Modify src/Makefile to enable additional compiler diagnostics:
CFLAGS=-Wall -Wextra -pedantic
3. Modify src/Makefile to enable the address and undefined sanitizers:
SANITIZER_CFLAGS=-g -O0 -fsanitize=address,undefined -fno-omit-frame-pointer
4. Configure and build Vim:
$ cd vim
$ ./configure --with-features=huge
$ make
5. Make the source code changes and build Vim.
6. Develop the feature test scripts under the src/testdir directory and
test the feature:
$ cd vim/src/testdir
$ make test_<feature>.res
7. Use the code coverage tool (LCOV - http://ltp.sourceforge.net/coverage/lcov.php)
to measure the code coverage and add additional test cases.
Modify src/Makefile to uncomment the following lines:
PROFILE_CFLAGS=-g -O0 -fprofile-arcs -ftest-coverage
LDFLAGS=--coverage
Build and run Vim.
$ cd vim/src
$ make clean
$ make
$ ./vim
Run the following command to create a baseline code coverage:
$ cd vim/src
$ lcov -c -i -b . -d objects -o objects/coverage_base.info
Run the Vim test scripts to test the feature. Run the following
command to see the code coverage:
$ cd vim/src
$ lcov -c -b . -d objects/ -o objects/coverage_test.info
$ lcov -a objects/coverage_base.info -a objects/coverage_test.info -o objects/coverage_total.info
$ lcov genhtml objects/coverage_total.info -o objects
This will load the code coverage results in a browser. Based on
the code coverage, modify the test scripts to add additional
tests.
After completing this, update the src/Makefile to remove the
profiling related lines and rebuild Vim.
8. Use valgrind (http://www.valgrind.org/) to check for memory leaks.
Edit src/Makefile to free all the memory when exiting Vim:
LEAK_CFLAGS=-DEXITFREE
Rebuild Vim.
$ cd vim/src
$ make
Edit the src/testdir/Makefile to enable valgrind:
VALGRIND=valgrind --tool=memcheck --leak-check=yes --num-callers=25 --log-file=valgrind.$*
Run the test script:
$ make test_<feature>.res
Check the valgrind.test_<feature> file for any memory leaks. Fix any
reported memory leaks and repeat these steps.
9. Run static analysis using the CLANG checker (https://clang-analyzer.llvm.org/).
Configure Vim using the checker:
$ scan-build ./configure --with-features=huge
$ scan-build make
Run scan-view to view the static analysis results:
$ scan-view <name of the file from the scan-build output>
Fix any static analysis warnings and repeat the steps.
10. Use the Cyclomatic Complexity Analyzer tool lizard (https://github.com/terryyin/lizard)
to analyze the code.
$ cd vim/src
$ lizard.py -s nloc <Vim source file>
Refactor the source code to reduce either the number of lines or to
reduce code complexity and rerun the tool.
11. Commit the code to Github and create a pull request.
12. Check the Vim Travis CI builds (https://travis-ci.org/vim/vim/builds)
and the Vim Appveyor builds (https://ci.appveyor.com/project/chrisbra/vim)
for any problems.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment