Difference between revisions of "Testing removal of ifdef or configure checks"

(show hints on using it)
(remove space correctly refer to gcc-E script name (not an direct gcc -E invocation))
 
(2 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
It is difficult (and time consuming) to prove that the code is unused and that there is no change to the compiled output.
 
It is difficult (and time consuming) to prove that the code is unused and that there is no change to the compiled output.
  
==A script to help==
+
==A script to help obtain CPP output==
  
[[File:Gcc-E.py.txt]] is a Python script that wraps gcc -E to attempt to solve this dilemma, so as to provide a result that can be reasoned with via tools like [https://www.samba.org/ftp/paulus/ dirdiff]
+
[[File:Gcc-E.py.txt]] is a Python script that wraps gcc -E (to get the CPP output) to attempt to solve this dilemma, so as to provide a result that can be reasoned with via tools like [https://www.samba.org/ftp/paulus/ dirdiff]
  
 
===Getting the results===
 
===Getting the results===
Line 13: Line 13:
 
  git checkout origin/master
 
  git checkout origin/master
 
  git clean -x -f -d
 
  git clean -x -f -d
  CC="gcc -E" ./configure.developer && make -j
+
  CC="gcc-E" ./configure.developer && make -j
 
  mv bin /tmp/master-bin
 
  mv bin /tmp/master-bin
 
   
 
   
 
  git checkout newbranch
 
  git checkout newbranch
 
  git clean -x -f -d
 
  git clean -x -f -d
  CC="gcc -E" ./configure.developer && make -j
+
  CC="gcc-E" ./configure.developer && make -j
  
 
===Reading the results===
 
===Reading the results===
Line 24: Line 24:
 
or
 
or
 
  diff -ur --ignore-matching-lines="^#" /tmp/master-bin/ bin> /tmp/diff
 
  diff -ur --ignore-matching-lines="^#" /tmp/master-bin/ bin> /tmp/diff
 +
 +
==Getting just one file's CPP output==
 +
Thanks to [https://lists.samba.org/archive/samba-technical/2020-March/134980.html waf author Thomas Nagy]
 +
WAF_CMD_FORMAT=string PYTHONHASHSEED=1 WAF_MAKE=1  ./buildtools/bin/waf -v build
 +
 +
Then just edit the command to add the -E (and perhaps a new output file).

Latest revision as of 21:58, 14 March 2020

#ifdef removal is risky

Large-scale removal of "unused" ifdef or the configure checks that produce #defines is an important, but risky task.

It is difficult (and time consuming) to prove that the code is unused and that there is no change to the compiled output.

A script to help obtain CPP output

File:Gcc-E.py.txt is a Python script that wraps gcc -E (to get the CPP output) to attempt to solve this dilemma, so as to provide a result that can be reasoned with via tools like dirdiff

Getting the results

git checkout origin/master
git clean -x -f -d
CC="gcc-E" ./configure.developer && make -j
mv bin /tmp/master-bin

git checkout newbranch
git clean -x -f -d
CC="gcc-E" ./configure.developer && make -j

Reading the results

dirdiff /tmp/master-bin bin

or

diff -ur --ignore-matching-lines="^#" /tmp/master-bin/ bin> /tmp/diff

Getting just one file's CPP output

Thanks to waf author Thomas Nagy

WAF_CMD_FORMAT=string PYTHONHASHSEED=1 WAF_MAKE=1  ./buildtools/bin/waf -v build

Then just edit the command to add the -E (and perhaps a new output file).