ModuleMapGenerator
A module map generator for Clang targets. Module map generation consists of two steps:
ModuleMapGenerator.swift:69struct ModuleMapGenerator
Examining a module’s public-headers directory to determine the appropriate module map type
Generating a module map for any module that doesn’t have a custom module map file
When a custom module map exists in the header directory, it is used as-is. When a custom module map does not exist, a module map is generated based on the following rules:
If “include/foo/foo.h” exists and
foo
is the only directory under the “include” directory, and the “include” directory contains no header files: Generates:umbrella header "/path/to/include/foo/foo.h"
If “include/foo.h” exists and “include” contains no other subdirectory: Generates:
umbrella header "/path/to/include/foo.h"
Otherwise, if the “include” directory only contains header files and no other subdirectory: Generates:
umbrella "path/to/include"
These rules are documented at https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md#creating-c-language-targets. To avoid breaking existing packages, do not change the semantics here without making any change conditional on the tools version of the package that defines the module.
Note that a module map generator doesn’t require a module to already have been instantiated; it can operate on information that will later be used to instantiate a module.
Citizens in PackageLoading
Type members
init(targetName: String, moduleName: String, publicHeadersDir: AbsolutePath, fileSystem: FileSystem
)
Instance members
func determineModuleMapType(observabilityScope: ObservabilityScope
) -> ModuleMapType Inspects the file system at the public-headers directory with which the module map generator was instantiated, and returns the type of module map that applies to that directory. This function contains all of the heuristics that implement module map policy for package targets; other functions just use the results of this determination.
func generateModuleMap(type: GeneratedModuleMapType, at: AbsolutePath
) throws Generates a module map based of the specified type, throwing an error if anything goes wrong. Any diagnostics are added to the receiver’s diagnostics engine.