Module directory structure

Version: $Id: modulestructure.html,v 1.4 2001/02/01 14:47:32 nzc Exp $

This document describes the structure of Blender modules, and the reasoning behind this structure. The following structure is the currently advised one.

[module name]--
              |-intern              - All .c and internal .h files
              |-test                - .c, .cpp, .h and Makefiles for 
              |                       module tests
              |-[module name].h     - The external .h file
This structure will be applied to new modules. For existing modules an individual decision needs to take place.

Index

1. Introduction
2. Development Environment
2.1. Platforms
2.2. Availability of sources
3. Functions of the structure
4. Required documentation
5. Possible structures
5.1. Option 1: Explicit tree
5.2. Option 2: Minimal tree
5.3. Option 3: Shallow tree
5.4. Option 4: Shallow tree 2
6. Evaluation and Conclusion

1. Introduction

This document describes the directory structure of Blender modules, and the reasoning behind this structure. It is intended for everyone who has to construct a new module.

2. Development Environment

2.1. Platforms

Modules should be usable on any of the platforms in use within NaN:

Some platforms are not in use at this moment, but will be soon. We have to make sure we will be capable of supporting them without extra effort: Except for Windows machines, we use gcc as the default compiler. On Windows, we use either Visual C++, or CygWin/cl.exe. All external releases are made with gcc and Cygwin/cl.exe. The makefiles work on all platforms.

2.2. Availability of sources

There is a single CVS repository that holds all code. There are no branches. This means that it is necessary that developers are able to preview and pretest changes on several platforms without having to commit those changes. For this purpose, NFS is used on the unix-platforms in combination with SAMBA for the windows-machines. It is also possible to mount unix-directories on windows and vice-versa.

3. Functions of the structure

There are several reasons why we want to organise the code into modules. Some of these have direct impact on the requirements on the module structure. These reasons are:

  1. There must be a clear top-level view of responsibilities of modules.
  2. There must be a uniform module structure.
  3. Cross-module changes should be rare.
  4. Module couplings should be small (narrow interfaces).
  5. A module must be stand-alone testable.
(Check the architecture document on the details of the modularization.)

Apart from that, there are requirements related to maintainability, usability, extensibility of the module-structure itself.

  1. (maintainability) separate 'physically' internal and external items
  2. (usability) allow a uniform way of addressing modules (using a module should not be more than a few lines of code/script)
  3. (maintainability) allow a uniform way of maintaining makefiles, (same set of makefiles for each module) (what about project files?)
  4. (maintainability) allow a high-level view on dependencies between modules (central location per module stating which other modules are required)
  5. (extensibility, maintainability) allow an internal directory structure in the module (may be needed for large modules)

4. Required documentation

For each module, there must be high-level and low-level documentation.

5. Possible structures

This section lists possible structures and their pros and cons. The listed benefits and drawbacks exclude those that come with all proposed stuctures.

5.1. Option 1: Explicit tree

5.1.1. Proposed structure

[module name]--
              |-intern---
              |         |-source    - All .c and .cpp files
              |         |-include   - All internal .h files
              |          
              |-extern---
              |         |-include   - All external .h files
              |
              |-test                - .c, .cpp, .h and Makefiles for 
              |                       module tests
              |
              |-                    - Files with general module
                                      information
The makefile set becomes uniform over modules. Inside the [module]/intern/{source,include} directories, there is space for extending the directory structure.

5.1.2. Benefits

5.1.3. Drawbacks

5.2. Option 2: Minimal tree

5.2.1. Proposed structure

[module name]--
              |-include             - All internal .h files
              |-source              - All .c and .cpp files
              |-test                - Module tests
              |-[module name].h     - The external .h file
There is only an explicit separation between headers and source.

5.2.2. Benefits

5.2.3. Drawbacks

5.3. Option 3: Shallow tree

5.3.1. Proposed structure

[module name]--
              |-intern              - All .c and internal .h files
              |-extern              - External .h files
              |-test                - .c, .cpp, .h and Makefiles for 
                                      module tests
The makefile set becomes uniform over modules. Inside the [module]/intern/ directory, there is space for extending the directory structure.

5.3.2. Benefits

5.3.3. Drawbacks

5.4. Option 4: Shallow tree 2

5.3.1. Proposed structure

[module name]--
              |-intern              - All .c and internal .h files
              |-test                - .c, .cpp, .h and Makefiles for 
              |                       module tests
              |-[module name].h     - The external .h file
The makefile set becomes uniform over modules. Inside the [module]/intern/ directory, there is space for extending the directory structure.

5.3.2. Benefits

5.3.3. Drawbacks

6. Evaluation and Conclusion

We do not expect modules to become very extensive: most modules will contain in the order of several 10's of source files. Therefore option 1 seems to be overorganised. With a limited number of headers, it also seems superfluous to separate these from the sources. This would eliminate option 2. To keep the number of subdirectories limited, option 4 is preferrable over option 3. To conclude: the advised directory structure is option 4.