ede: Detecting a Project
8.2 Detecting a Project
=======================
Project detection happens with the list of ‘ede-project-autoload’
instances stored in ‘ede-project-class-files’. The full project
detection scheme works like this:
Step 1:
‘find-file-hook’ calls ‘ede-turn-on-hook’ on BUFFER.
Step 2:
‘ede-turn-on-hook’ turns on ‘ede-minor-mode’
Step 3:
‘ede-minor-mode’ looks to see if BUFFER is associated with any open
projects. If not, it calls ‘ede-load-project-file’ to find a
project associated with the current directory BUFFER is in.
Step 4:
‘ede-minor-mode’ associates the found project with the current
buffer with a series of variables, such as ‘ede-object’, and
‘ede-object-project’ and ‘ede-object-root-project’.
Once a buffer is associated, EDE minor mode commands will operate on
that buffer.
The function ‘ede-load-project-file’ is at the heart of detecting
projects, and it works by looping over all the known project autoload
types in ‘ede-project-autoload’ using the utility
‘ede-directory-project-p’.
The function ‘ede-directory-project-p’ will call
‘ede-dir-to-projectfile’ on every ‘ede-project-autoload’ until one of
them returns true. The method ‘ede-dir-to-projectfile’ in turn gets the
‘:proj-file’ slot from the autoload. If it is a string (i.e., a project
file name), it checks to see if that exists in BUFFER’s directory. If
it is a function, then it calls that function and expects it to return a
file name or ‘nil’. If the file exists, then this directory is assumed
to be part of a project, and ‘ede-directory-project-p’ returns the
instance of ‘ede-project-autoload’ that matched.
If the current directory contains the file ‘.ede-ignore’ then that
directory is automatically assumed to contain no projects, even if there
is a matching pattern. Use this type of file in a directory that may
contain many other sub projects, but still has a Makefile of some sort.
If the current directory is a project, then EDE scans upwards till it
finds the top of the project. It does this by calling
‘ede-toplevel-project’. If this hasn’t already been discovered, the
directories as scanned upward one at a time until a directory with no
project is found. The last found project becomes the project root. If
the found instance of ‘ede-project-autoload’ has a valid ‘proj-root’
slot value, then that function is called instead of scanning the project
by hand. Some project types have a short-cut for determining the root
of a project, so this comes in handy.
Getting back to ‘ede-load-project-file’, this now has an instance of
‘ede-project-autoload’. It uses the ‘load-type’ slot to both autoload
in the project type, and to create a new instance of the project type
found for the root of the project. That project is added to the global
list of all projects. All subprojects are then created and assembled
into the project data structures.