Skip to content

Commit 5b51aa1

Browse files
Merge pull request #13 from hiker/update_bom_master_to_upstream_master
Update bom master to upstream master
2 parents 932f401 + b1b4057 commit 5b51aa1

14 files changed

+133
-92
lines changed

Documentation/source/advanced_config.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ in particular where it creates files within it.
254254
*.o (compiled object files)
255255
*.mod (mod files)
256256
metrics/
257-
my_program.exe
257+
my_program
258258
log.txt
259259
260260
The *project workspace* folder takes its name from the project label passed in to the build configuration.

Documentation/source/glossary.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Glossary
2929
Fab's built-in steps come with sensible defaults so the user doesn't have to write unnecessary config.
3030

3131
As an example, the Fortran preprocessor has a default artefact getter which reads *".F90"* files
32-
from the :term:`Artefact Collection` called ``"all_source"``.
32+
from the :term:`Artefact Collection` called ``"INITIAL_SOURCE"``.
3333

3434
Artefact getters are derived from :class:`~fab.artefacts.ArtefactsGetter`.
3535

@@ -65,7 +65,7 @@ Glossary
6565
A folder inside the :term:`Fab Workspace`, containing all source and output from a build config.
6666

6767
Root Symbol
68-
The name of a Fortran PROGRAM, or ``"main"`` for C code. Fab builds an exe for every root symbol it's given.
68+
The name of a Fortran PROGRAM, or ``"main"`` for C code. Fab builds an executable for every root symbol it's given.
6969

7070
Source Tree
7171
The :class:`~fab.steps.analyse.analyse` step produces a dependency tree of the entire project source.

Documentation/source/writing_config.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Please see the documentation for :func:`~fab.steps.find_source_files.find_source
7979
including how to exclude certain source code from the build. More grab steps can be found in the :mod:`~fab.steps.grab`
8080
module.
8181

82-
After the find_source_files step, there will be a collection called ``"ALL_SOURCE"``, in the artefact store.
82+
After the find_source_files step, there will be a collection called ``"INITIAL_SOURCE"``, in the artefact store.
8383

8484
.. [1] See :func:`~fab.steps.c_pragma_injector.c_pragma_injector` for an example of a step which
8585
creates artefacts in the source folder.
@@ -94,7 +94,7 @@ which must happen before we analyse it.
9494

9595
Steps generally create and find artefacts in the :term:`Artefact Store`, arranged into named collections.
9696
The :func:`~fab.steps.preprocess.preprocess_fortran`
97-
automatically looks for Fortran source code in a collection named `'ALL_SOURCE'`,
97+
automatically looks for Fortran source code in a collection named `'INITIAL_SOURCE'`,
9898
which is the default output from the preceding :funcfind_source_files step.
9999
It filters just the (uppercase) ``.F90`` files.
100100

@@ -293,8 +293,8 @@ it is the user's responsibility to maintain the default artefact sets
293293
My apologies for the LONG lines, they were the only way I could find
294294
to have properly indented paragraphs :(
295295
296-
1. :func:`~fab.steps.find_source_files.find_source_files` will add all source files it finds to ``ALL_SOURCE`` (by default, can be overwritten by the user). Any ``.F90`` and ``.f90`` file will also be added to ``FORTRAN_BUILD_FILES``, any ``.c`` file to ``C_BUILD_FILES``, and any ``.x90`` or ``.X90`` file to ``X90_BUILD_FILES``. It can be called several times if files from different root directories need to be added, and it will automatically update the ``*_BUILD_FILES`` sets.
297-
2. Any user script that creates new files can add files to ``ALL_SOURCE`` if required, but also to the corresponding ``*_BUILD_FILES``. This will happen automatically if :func:`~fab.steps.find_source_files.find_source_files` is called to add these newly created files.
296+
1. :func:`~fab.steps.find_source_files.find_source_files` will add all source files it finds to ``INITIAL_SOURCE`` (by default, can be overwritten by the user). Any ``.F90`` and ``.f90`` file will also be added to ``FORTRAN_BUILD_FILES``, any ``.c`` file to ``C_BUILD_FILES``, and any ``.x90`` or ``.X90`` file to ``X90_BUILD_FILES``. It can be called several times if files from different root directories need to be added, and it will automatically update the ``*_BUILD_FILES`` sets.
297+
2. Any user script that creates new files can add files to ``INITIAL_SOURCE`` if required, but also to the corresponding ``*_BUILD_FILES``. This will happen automatically if :func:`~fab.steps.find_source_files.find_source_files` is called to add these newly created files.
298298
3. If :func:`~fab.steps.c_pragma_injector.c_pragma_injector` is being called, it will handle all files in ``C_BUILD_FILES``, and will replace all the original C files with the newly created ones. For backward compatibility it will also store the new objects in the ``PRAGMAD_C`` set.
299299
4. If :func:`~fab.steps.preprocess.preprocess_c` is called, it will preprocess all files in ``C_BUILD_FILES`` (at this stage typically preprocess the files in the original source folder, writing the output files to the build folder), and update that artefact set accordingly. For backward compatibility it will also store the preprocessed files in ``PREPROCESSED_C``.
300300
5. If :func:`~fab.steps.preprocess.preprocess_fortran` is called, it will preprocess all files in ``FORTRAN_BUILD_FILES`` that end on ``.F90``, creating new ``.f90`` files in the build folder. These files will be added to ``PREPROCESSED_FORTRAN``. Then the original ``.F90`` are removed from ``FORTRAN_BUILD_FILES``, and the new preprocessed files (which are in ``PREPROCESSED_FORTRAN``) will be added. Then any ``.f90`` files that are not already in the build folder (an example of this are files created by a user script) are copied from the original source folder into the build folder, and ``FORTRAN_BUILD_FILES`` is updated to use the files in the new location.

run_configs/lfric/lfric_common.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import logging
22
import os
33
import shutil
4+
from typing import Optional
45
from pathlib import Path
56

67
from fab.artefacts import ArtefactSet
8+
from fab.build_config import BuildConfig
79
from fab.steps import step
810
from fab.steps.find_source_files import find_source_files
911
from fab.tools import Category, Tool
@@ -111,11 +113,11 @@ def fparser_workaround_stop_concatenation(config):
111113

112114

113115
# ============================================================================
114-
def get_transformation_script(fpath, config):
116+
def get_transformation_script(fpath: Path,
117+
config: BuildConfig) -> Optional[Path]:
115118
''':returns: the transformation script to be used by PSyclone.
116-
:rtype: Path
117-
118119
'''
120+
119121
optimisation_path = config.source_root / 'optimisation' / 'meto-spice'
120122
relative_path = None
121123
for base_path in [config.source_root, config.build_output]:
@@ -132,4 +134,4 @@ def get_transformation_script(fpath, config):
132134
global_transformation_script = optimisation_path / 'global.py'
133135
if global_transformation_script.exists():
134136
return global_transformation_script
135-
return ""
137+
return None

source/fab/artefacts.py

+24-16
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
class ArtefactSet(Enum):
2828
'''A simple enum with the artefact types used internally in Fab.
2929
'''
30-
ALL_SOURCE = auto()
30+
INITIAL_SOURCE = auto()
3131
PREPROCESSED_FORTRAN = auto()
3232
PREPROCESSED_C = auto()
3333
FORTRAN_BUILD_FILES = auto()
@@ -42,8 +42,8 @@ class ArtefactSet(Enum):
4242

4343

4444
class ArtefactStore(dict):
45-
'''This object stores set of artefacts (which can be of any type). Each artefact
46-
is indexed by a string.
45+
'''This object stores sets of artefacts (which can be of any type).
46+
Each artefact is indexed by either an ArtefactSet enum, or a string.
4747
'''
4848

4949
def __init__(self):
@@ -89,7 +89,8 @@ def update_dict(self, collection: Union[str, ArtefactSet],
8989
:param key: the key in the dictionary to update.
9090
:param values: the values to update with.
9191
'''
92-
self[collection][key].update([values] if isinstance(values, str) else values)
92+
self[collection][key].update([values] if isinstance(values, str)
93+
else values)
9394

9495
def copy_artefacts(self, source: Union[str, ArtefactSet],
9596
dest: Union[str, ArtefactSet],
@@ -149,7 +150,8 @@ def __call__(self, artefact_store):
149150

150151
class CollectionGetter(ArtefactsGetter):
151152
"""
152-
A simple artefact getter which returns one :term:`Artefact Collection` from the artefact_store.
153+
A simple artefact getter which returns one :term:`Artefact Collection`
154+
from the artefact_store.
153155
154156
Example::
155157
@@ -170,33 +172,38 @@ def __call__(self, artefact_store):
170172

171173
class CollectionConcat(ArtefactsGetter):
172174
"""
173-
Returns a concatenated list from multiple :term:`Artefact Collections <Artefact Collection>`
174-
(each expected to be an iterable).
175+
Returns a concatenated list from multiple
176+
:term:`Artefact Collections <Artefact Collection>` (each expected to be
177+
an iterable).
175178
176-
An :class:`~fab.artefacts.ArtefactsGetter` can be provided instead of a collection_name.
179+
An :class:`~fab.artefacts.ArtefactsGetter` can be provided instead of a
180+
collection_name.
177181
178182
Example::
179183
180-
# The default source code getter for the Analyse step might look like this.
184+
# The default source code getter for the Analyse step might look
185+
# like this.
181186
DEFAULT_SOURCE_GETTER = CollectionConcat([
182187
'preprocessed_c',
183188
'preprocessed_fortran',
184-
SuffixFilter(ArtefactSet.ALL_SOURCE, '.f90'),
189+
SuffixFilter(ArtefactSet.INITIAL_SOURCE, '.f90'),
185190
])
186191
187192
"""
188193
def __init__(self, collections: Iterable[Union[ArtefactSet, str,
189194
ArtefactsGetter]]):
190195
"""
191196
:param collections:
192-
An iterable containing collection names (strings) or other ArtefactsGetters.
197+
An iterable containing collection names (strings) or
198+
other ArtefactsGetters.
193199
194200
"""
195201
self.collections = collections
196202

197203
# todo: ensure the labelled values are iterables
198204
def __call__(self, artefact_store: ArtefactStore):
199-
# todo: this should be a set, in case a file appears in multiple collections
205+
# todo: this should be a set, in case a file appears in
206+
# multiple collections
200207
result = []
201208
for collection in self.collections:
202209
if isinstance(collection, (str, ArtefactSet)):
@@ -208,13 +215,13 @@ def __call__(self, artefact_store: ArtefactStore):
208215

209216
class SuffixFilter(ArtefactsGetter):
210217
"""
211-
Returns the file paths in a :term:`Artefact Collection` (expected to be an iterable),
212-
filtered by suffix.
218+
Returns the file paths in a :term:`Artefact Collection` (expected to be
219+
an iterable), filtered by suffix.
213220
214221
Example::
215222
216223
# The default source getter for the FortranPreProcessor step.
217-
DEFAULT_SOURCE = SuffixFilter(ArtefactSet.ALL_SOURCE, '.F90')
224+
DEFAULT_SOURCE = SuffixFilter(ArtefactSet.INITIAL_SOURCE, '.F90')
218225
219226
"""
220227
def __init__(self,
@@ -264,6 +271,7 @@ def __call__(self, artefact_store: ArtefactStore):
264271

265272
build_lists: Dict[str, List[AnalysedDependent]] = {}
266273
for root, tree in build_trees.items():
267-
build_lists[root] = filter_source_tree(source_tree=tree, suffixes=self.suffixes)
274+
build_lists[root] = filter_source_tree(source_tree=tree,
275+
suffixes=self.suffixes)
268276

269277
return build_lists

source/fab/parse/fortran.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,9 @@ def _process_comment(self, analysed_file, obj):
298298
if comment[:2] == "!$":
299299
# Check if it is a use statement with an OpenMP sentinel:
300300
# Use fparser's string reader to discard potential comment
301-
# TODO #13: once fparser supports reading the sentinels,
301+
# TODO #327: once fparser supports reading the sentinels,
302302
# this can be removed.
303+
# fparser issue: https://github.com/stfc/fparser/issues/443
303304
reader = FortranStringReader(comment[2:])
304305
try:
305306
line = reader.next()

source/fab/steps/analyse.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ def _gen_symbol_table(analysed_files: Iterable[AnalysedDependent]) -> Dict[str,
312312
symbols[symbol_def] = analysed_file.fpath
313313

314314
if duplicates:
315-
# we don't break the build because these symbols might not be required to build the exe
315+
# we don't break the build because these symbols might not be
316+
# required to build the executable.
316317
# todo: put a big warning at the end of the build?
317318
err_msg = "\n".join(map(str, duplicates))
318319
warnings.warn(f"Duplicates found while generating symbol table:\n{err_msg}")

source/fab/steps/archive_objects.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
DEFAULT_SOURCE_GETTER = CollectionGetter(ArtefactSet.OBJECT_FILES)
2525

2626

27-
# todo: two diagrams showing the flow of artefacts in the exe and library use cases
28-
# show how the library has a single build target with None as the name.
27+
# todo: two diagrams showing the flow of artefacts in the executables and
28+
# library use cases show how the library has a single build target with None
29+
# as the name.
2930

30-
# todo: all this documentation for such a simple step - should we split it up somehow?
31+
# todo: all this documentation for such a simple step - should we split it
32+
# up somehow?
3133

3234
@step
3335
def archive_objects(config: BuildConfig,
@@ -73,7 +75,7 @@ def archive_objects(config: BuildConfig,
7375
targets, each with a name. This typically happens when configuring the
7476
:class:`~fab.steps.analyser.Analyser` step *with* a root symbol(s).
7577
We can assume each list of object files is sufficient to build each
76-
*<root_symbol>.exe*.
78+
*<root_symbol>* executable.
7779
7880
In this case you cannot specify an *output_fpath* path because they are
7981
automatically created from the target name.
@@ -110,14 +112,15 @@ def archive_objects(config: BuildConfig,
110112
target_objects = source_getter(config.artefact_store)
111113
assert target_objects.keys()
112114
if output_fpath and list(target_objects.keys()) != [None]:
113-
raise ValueError("You must not specify an output path (library) when there are root symbols (exes)")
115+
raise ValueError("You must not specify an output path (library) when "
116+
"there are root symbols (executables)")
114117
if not output_fpath and list(target_objects.keys()) == [None]:
115118
raise ValueError("You must specify an output path when building a library.")
116119

117120
for root, objects in target_objects.items():
118121

119122
if root:
120-
# we're building an object archive for an exe
123+
# we're building an object archive for an executable
121124
output_fpath = str(config.build_output / f'{root}.a')
122125
else:
123126
# we're building a single object archive with a given filename

source/fab/steps/c_pragma_injector.py

+16-9
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,30 @@
2020

2121
# todo: test
2222
@step
23-
def c_pragma_injector(config, source: Optional[ArtefactsGetter] = None, output_name=None):
23+
def c_pragma_injector(config, source: Optional[ArtefactsGetter] = None,
24+
output_name=None):
2425
"""
25-
A build step to inject custom pragmas to mark blocks of user and system include statements.
26+
A build step to inject custom pragmas to mark blocks of user and system
27+
include statements.
2628
27-
By default, reads .c files from the *all_source* artefact and creates the *pragmad_c* artefact.
29+
By default, reads .c files from the *INITIAL_SOURCE* artefact and creates
30+
the *pragmad_c* artefact.
2831
29-
This step does not write to the build output folder, it creates the pragmad c in the same folder as the c file.
30-
This is because a subsequent preprocessing step needs to look in the source folder for header files,
32+
This step does not write to the build output folder, it creates the
33+
pragmad c in the same folder as the c file. This is because a subsequent
34+
preprocessing step needs to look in the source folder for header files,
3135
including in paths relative to the c file.
3236
3337
:param config:
34-
The :class:`fab.build_config.BuildConfig` object where we can read settings
35-
such as the project workspace folder or the multiprocessing flag.
38+
The :class:`fab.build_config.BuildConfig` object where we can
39+
read settings such as the project workspace folder or the
40+
multiprocessing flag.
3641
:param source:
37-
An :class:`~fab.artefacts.ArtefactsGetter` which give us our c files to process.
42+
An :class:`~fab.artefacts.ArtefactsGetter` which give us our c files
43+
to process.
3844
:param output_name:
39-
The name of the artefact collection to create in the artefact store, with a sensible default
45+
The name of the artefact collection to create in the artefact store,
46+
with a sensible default
4047
4148
"""
4249
source_getter = source or DEFAULT_SOURCE_GETTER

source/fab/steps/find_source_files.py

+20-12
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def check(self, path):
4040

4141
class Include(_PathFilter):
4242
"""
43-
A path filter which includes matching paths, this convenience class improves config readability.
43+
A path filter which includes matching paths, this convenience class
44+
improves config readability.
4445
4546
"""
4647
def __init__(self, *filter_strings):
@@ -57,7 +58,8 @@ def __str__(self):
5758

5859
class Exclude(_PathFilter):
5960
"""
60-
A path filter which excludes matching paths, this convenience class improves config readability.
61+
A path filter which excludes matching paths, this convenience class
62+
improves config readability.
6163
6264
"""
6365

@@ -75,17 +77,18 @@ def __str__(self):
7577

7678
@step
7779
def find_source_files(config, source_root=None,
78-
output_collection=ArtefactSet.ALL_SOURCE,
80+
output_collection=ArtefactSet.INITIAL_SOURCE,
7981
path_filters: Optional[Iterable[_PathFilter]] = None):
8082
"""
8183
Find the files in the source folder, with filtering.
8284
8385
Files can be included or excluded with simple pattern matching.
8486
Every file is included by default, unless the filters say otherwise.
8587
86-
Path filters are expected to be provided by the user in an *ordered* collection.
87-
The two convenience subclasses, :class:`~fab.steps.walk_source.Include` and :class:`~fab.steps.walk_source.Exclude`,
88-
improve readability.
88+
Path filters are expected to be provided by the user in an *ordered*
89+
collection. The two convenience subclasses,
90+
:class:`~fab.steps.walk_source.Include` and
91+
:class:`~fab.steps.walk_source.Exclude`, improve readability.
8992
9093
Order matters. For example::
9194
@@ -94,14 +97,17 @@ def find_source_files(config, source_root=None,
9497
Include('my_folder/my_file.F90'),
9598
]
9699
97-
In the above example, swapping the order would stop the file being included in the build.
100+
In the above example, swapping the order would stop the file being
101+
included in the build.
98102
99103
A path matches a filter string simply if it *contains* it,
100-
so the path *my_folder/my_file.F90* would match filters "my_folder", "my_file" and "er/my".
104+
so the path *my_folder/my_file.F90* would match filters
105+
"my_folder", "my_file" and "er/my".
101106
102107
:param config:
103-
The :class:`fab.build_config.BuildConfig` object where we can read settings
104-
such as the project workspace folder or the multiprocessing flag.
108+
The :class:`fab.build_config.BuildConfig` object where we can read
109+
settings such as the project workspace folder or the multiprocessing
110+
flag.
105111
:param source_root:
106112
Optional path to source folder, with a sensible default.
107113
:param output_collection:
@@ -120,8 +126,10 @@ def find_source_files(config, source_root=None,
120126

121127
# file filtering
122128
filtered_fpaths = set()
123-
# todo: we shouldn't need to ignore the prebuild folder here, it's not underneath the source root.
124-
for fpath in file_walk(source_root, ignore_folders=[config.prebuild_folder]):
129+
# todo: we shouldn't need to ignore the prebuild folder here, it's not
130+
# underneath the source root.
131+
for fpath in file_walk(source_root,
132+
ignore_folders=[config.prebuild_folder]):
125133

126134
wanted = True
127135
for path_filter in path_filters:

source/fab/steps/preprocess.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class DefaultCPreprocessorSource(ArtefactsGetter):
207207
"""
208208
def __call__(self, artefact_store):
209209
return CollectionGetter(ArtefactSet.PRAGMAD_C)(artefact_store) \
210-
or SuffixFilter(ArtefactSet.ALL_SOURCE, '.c')(artefact_store)
210+
or SuffixFilter(ArtefactSet.INITIAL_SOURCE, '.c')(artefact_store)
211211

212212

213213
# todo: rename preprocess_c

0 commit comments

Comments
 (0)