Bug 516813 - Build succeeds even though dependent files are missing
Summary: Build succeeds even though dependent files are missing
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-build-managed (show other bugs)
Version: 9.3.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 9.3.0   Edit
Assignee: Jonah Graham CLA
QA Contact: Chris Recoskie CLA
URL:
Whiteboard:
Keywords:
: 400903 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-05-17 09:30 EDT by Jonah Graham CLA
Modified: 2021-07-08 11:02 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonah Graham CLA 2017-05-17 09:30:47 EDT
The generated makefile has .SECONDARY: with no dependants. This means:

.SECONDARY with no prerequisites causes all targets to be treated as secondary (i.e., no target is removed because it is considered intermediate). -- https://www.gnu.org/software/make/manual/html_node/Special-Targets.html

A target being secondary means:

When a file is secondary, make will not create the file merely because it does not already exist, but make does not automatically delete the file.  -- https://www.gnu.org/software/make/manual/html_node/Chained-Rules.html#Chained-Rules


So you can have this situation:

Create a project with:

  file.c which include header.h

Build the project.

Delete header.h and build again. In this case, depending on how you do the delete/build make will report:
  
    make: Nothing to be done for 'all'.

Delete the file outside of Eclipse (command line) and run the build in Eclipse. This causes the build to be run before the delta of the removed file is processed. 

If you delete in Eclipse the delta is seen by Eclipse CDT, then BuildDescriptionManager.cleanGeneratedRebuildResources(IBuildDescription) will remove the intermediary files and that forces the rebuild.


I don't know if BuildDescriptionManager.cleanGeneratedRebuildResources was created to workaround the .SECONDARY that had long preceded it, or not. I do know that the .SECONDARY is unintentionally used with no dependants because of how it is used with pre and post build (from GnuMakefileGenerator):

		buffer.append(".SECONDARY:"); //$NON-NLS-1$
		if (prebuildStep.length() > 0) {
			buffer.append(WHITESPACE).append(MAINBUILD).append(WHITESPACE).append(PREBUILD);
		}
		if (postbuildStep.length() > 0) {
			buffer.append(WHITESPACE).append(POSTBUILD);
		}


Now it could be when the above code was written (2003 or so) that Make 2.78 or earlier was being used for dev. 2.79, released in the early 2000s added the ".SECONDARY with no prerequisites causes all targets to be treated as secondary".
Comment 1 Jonah Graham CLA 2017-05-17 09:32:59 EDT
I am going to resolve this problem by removing this incorrect use of .SECONDARY.

If a user has depended on this behaviour, they can add ".SECONDARY:" to their makefile.targets in the root of their project.
Comment 2 Eclipse Genie CLA 2017-05-17 09:34:38 EDT
New Gerrit change created: https://git.eclipse.org/r/97335
Comment 4 Jonah Graham CLA 2017-05-31 04:51:26 EDT
In the unlikely event that a project was depending on such behaviour the behaviour can be restored by creating a "makefile.targets" in the root of the project with:

.SECONDARY:

as the contents.
Comment 5 Jonah Graham CLA 2021-07-08 11:02:00 EDT
*** Bug 400903 has been marked as a duplicate of this bug. ***