Renaming With Pork

This describes how to use pork to rewrite source code.

Most refactoring toolchains are UI-based. Typically they require loading the entire project into an IDE. Usually, IDEs require one to use their build system. Pork does not yet have a UI, but it is also build-system agnostic and scales to large codebases. These notes are based on


Tools

Renaming a class

1. Make two copies of the source(analysis and test). This isn't strictly required, but will save time.

2. The first copy will be an analysis copy. Convince GCC to create annotated .ii files while compiling the analysis copy. Typically, make CXXFLAGS="-Wp,-K,-W0 -save-temps" will work. Note the -K,-W0 options are passed down to the MCPP preprocessor such that it can annotate files with more precise position information. In order for this to work MCPP has to be integrated into your compiler as described in the pork installation instructions

3. In the analysis copy make a list of files to process. Use absolute paths.

find `pwd` -name \*.ii > /tmp/ls.txt

4. Run renamer through pork-barrel. this makes it easier to refer to any diagnostics

touch /tmp/err.txt 
tail -F /tmp/err.txt & 
~/work/pork-barrel/pork-barrel 4 /tmp/ls.txt ./renamer -rename-class string sm::string > /tmp/string.diff 2>/tmp/err.txt

Pork-barrel runs multiple copies of the renamer and merges their output. One can also run the ./renamer command directly on the .ii files.

5. Apply the patch in the test sources. Pork patches contain absolute paths in them and will touch generated sources if it comes across any. Thus it is helpful to postprocess the patch with sed and filterdiff. Now in the analysis copy do some processing on the patch and apply it. --dry-run is helpful for debugging

filterdiff -x \*/smbase/\* /tmp/string.diff |sed 's/.home.tglek.tmp.//' | patch -p1 --dry-run

Document Tags and Contributors

 Last updated by: Tglek,