Delete unused c++ files from the project
-
wrote on 6 Jun 2019, 14:33 last edited by
Hello Everyone,
I want to write a script which will delete the unused c++ file from the project. Can anyone help me in writing the script. Thank you very much. -
Hello Everyone,
I want to write a script which will delete the unused c++ file from the project. Can anyone help me in writing the script. Thank you very much.@rockon209 said in Delete unused c++ files from the project:
the unused c++ file
Please elaborate what you mean with "the unused c++ file".
Regards
-
wrote on 6 Jun 2019, 14:39 last edited by
if you just mean the intermediate MOC files then make clean does that
-
wrote on 6 Jun 2019, 14:52 last edited by
@Kent-Dorfman
@Qt-Champions-2018
No not MOC files, normal C++ files(.cpp and .h) that are not used now in the project at all. In my project i have lot of these files which are in import but not used at all.
There are also some cases that one files is used in another file but this another file is not used anywehere. So doing this manually will take a lot of time. So a script can be used. That why i need a script to do this. -
wrote on 6 Jun 2019, 14:55 last edited by
The .pro file should contain a list of all the needed project files. parse it and delete whatever is not referenced therein...
-
wrote on 7 Jun 2019, 05:43 last edited by
@Kent-Dorfman
I am not using qmake in my project i have cmake files. Thats why i dont have .pro file -
@Kent-Dorfman
@Qt-Champions-2018
No not MOC files, normal C++ files(.cpp and .h) that are not used now in the project at all. In my project i have lot of these files which are in import but not used at all.
There are also some cases that one files is used in another file but this another file is not used anywehere. So doing this manually will take a lot of time. So a script can be used. That why i need a script to do this.@rockon209 said in Delete unused c++ files from the project:
Don't do that. People don't appreciate being summoned. If they have something to say, they're going to post their thoughts on their own.
-
@Kent-Dorfman
I am not using qmake in my project i have cmake files. Thats why i dont have .pro file@rockon209 You can parse cmake files as well.
-
wrote on 7 Jun 2019, 07:46 last edited by
but my Cmake file dont have the c++ files included in it. It just give the path of the folder where the files are and this folder I have all the files which are not in used also.
-
but my Cmake file dont have the c++ files included in it. It just give the path of the folder where the files are and this folder I have all the files which are not in used also.
@rockon209 So how do you know a file is "unused"? If you don't have a way to know that, that will be a very hard task to write such a script.
-
wrote on 7 Jun 2019, 08:15 last edited by
My logic was to take each class name form each file cpp and search for it and if it us used in any other file then its used. Same as search function. But i dont know if its a right approach to do it. Just an intial idea i can think of.
-
but my Cmake file dont have the c++ files included in it. It just give the path of the folder where the files are and this folder I have all the files which are not in used also.
@rockon209 Shouldn't you as developer know which files are used and which not?
And why do you actually have unused files in your project?What you can do: build your project and analyse the build log to see which files were compiled, remove all files which were not compiled.
-
wrote on 7 Jun 2019, 08:20 last edited by
Well I am not the only developer, there are many other developer doing the develpment for there specific part assign to them.
ya but in build i am not sure if all the files are build. I mean let say in a Phone we have lot of application which are used and those application are not build everytime. I am not sure just guessing -
Well I am not the only developer, there are many other developer doing the develpment for there specific part assign to them.
ya but in build i am not sure if all the files are build. I mean let say in a Phone we have lot of application which are used and those application are not build everytime. I am not sure just guessing@rockon209 Well, then you will need to collect build logs for all supported platforms and analyse all of them.
-
Well I am not the only developer, there are many other developer doing the develpment for there specific part assign to them.
ya but in build i am not sure if all the files are build. I mean let say in a Phone we have lot of application which are used and those application are not build everytime. I am not sure just guessing@rockon209
if you're using QtCreator,you can right click on a class definition, and select
open include-hierachy
, should help you.But I don't think that it will show stuff that is OS-Dependend - if the includes are wrapped inside #if defined(Q_OS_WIN) #endif blocks
-
wrote on 11 Jun 2019, 12:48 last edited by rockon209 6 Nov 2019, 12:49
open include hierachy its a fucntion in Qt, i want to write a python script which will find it.
Its like to find the dead code in the project which is not been used. -
Hi,
Then in your script you'll have to parse all your sources, build a list of the include statements contained in all headers and implementation files, build a list of all the header/implementation files and then compare both and delete the files that do not appear in the list of include statements.
1/17