File: CreateModules.py

package info (click to toggle)
shasta 0.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,636 kB
  • sloc: cpp: 82,262; python: 2,348; makefile: 222; sh: 143
file content (51 lines) | stat: -rwxr-xr-x 1,376 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python3

import os
import pathlib

"""
This creates C++20 gcc compiled modules (CMI)
for some of the system include files used by Shasta.
This creates:
1. The C++ modules, in directory gcm.cache.
2. File modules.txt which contains a list and locations
   of the compiled modules in gcm.cache. 

To use these modules during a build:
1. Add "-fmodules-ts -fmodule-mapper=modules.txt" to the command line
2. C++ code should use "import <iostream>;" instead of "#include iostream>",
   etc. for other modules.
"""

stdDirectory = 'usr/include/c++/11'
stdIncludes = [
    'algorithm', 
    'array', 
    'chrono', 
    'cstddef', 
    'cstdint', 
    'fstream', 
    'iosfwd', 
    'iostream', 
    'iterator', 
    'map', 
    # 'memory', For some reason this errors out while building.
    'numeric', 
    'set', 
    'span', 
    # 'stdexcept', For some reason this errors out while building.
    # 'string', For some reason this errors out while building.
    'tuple', 
    'utility', 
    'vector',
    ]

modulesFile = open('modules.txt', 'w')
modulesFile.write('$root ' + str(pathlib.Path().absolute()) + '/gcm.cache\n')

for stdInclude in stdIncludes:
    command = 'g++ -std=c++20 -fmodules-ts -c -x c++-system-header ' + stdInclude
    os.system(command)
    modulesFile.write('/%s/%s %s/%s.gcm\n' % (stdDirectory, stdInclude, stdDirectory, stdInclude))