📜 ⬆️ ⬇️

Compiling a Fortran software project

Everyone knows the advantages of night assembly and testing: in the morning we know all the information about the project:
whether the project was assembled, how many tests passed, we have an assembled file that can be presented to the customer.

One of the biggest problems in setting up an automated build process and testing a project in Fortran is building an executable file in non-interactive mode, primarily in command line mode.

Recall that the files in the Fortran project depend on each other through the modules. If there is a module A in one file and use A in the other, the first file should be compiled earlier. At the same time, such information is not recorded anywhere and is generated on the fly. The integration of the Intel Fortran compiler with Visual Studio in most cases correctly determines the sequence of compilation, however, it may be wrong, what to say about special utilities aimed at creating make-files.
')
Below is a method for determining dependencies in project files and a description of the process of automatically building a project without using special programs.

We set the task in this form: automatically compile the project, having only the source files of the project, the project vfproj and, in general, the file sln.

Probably, some existing methods of building an exe-file require calling a special intermediate utility that generates dependencies in the form of a make-file for a project file (vfproj).
The search for such a utility did not lead to success. And it happens that after successful compilation and linking in the studio it is possible to recompile some files due to incorrectly defined dependencies, incorrect interpretation of conditional compilation ( !DEC$ ), etc. Thus, external utilities can not be considered a reliable way to determine the order of compilation.

The task is divided into two:
  1. rewrite the project file (which is stored in XML format) as a list of files with compilation parameters.
  2. compile in the correct order.

The first problem is solved easily. Attributes are created in XML format for the compiler. Example: instead of WarnUnusedVariables="true" substitute /warn:unused . By the way, this approach adjusts to a critical assessment of the settings of an existing project, you can throw out extra settings, understand, change the purpose of the existing ones.

To solve the second problem, the following approach was chosen: to catch dependencies based on the behavior of the compiler itself. Suppose that the program is correctly written from the point of view of the compiler:
each programmer regularly compiles the entire project to check the implemented functionality. Then the file compilation can be completed either successfully, or in the absence of a module, the first error is Module not found . Remember the name of the missing module and go to the next file in the list.

In case of an error of any other type, we can talk about the corruption of the project, then the compilation stops. If when compiling the last file from the list a dependency on another module was found, this indicates the presence of a cyclic dependency in the project, that is, an error.

Further, when the compiler does not issue errors, we look at which modules have been created. If we find one of the previous files was not compiled due to the absence of such a module,
we can compile it again.

The compilation order is fixed in the repository. Intermediate object files can be deleted.
Next time we will not spend extra compilation time. If the dependencies have changed a bit, we will not be able to trace the whole chain from scratch again.

Note that here we are not talking about speeding up the assembly of the project and make-files in the usual sense of the word are not created.

Features of the implementation

It is possible to use the VBScript language, since under Windows no compiler is required for it to be installed. The author used VBScript mainly for this reason:
You can customize the compilation on any computer running Windows, which is an absolute majority in the office. VBScript has built-in reading and support for XML files, which is important for projects stored in this format. To rewrite the script for Linux OS is still not required.

Special attention in VBScript needs to be paid to intercepting an output buffer, with which, as you know, there are certain problems. To monitor and intercept standard and erroneous output, use the WSHShell.Exec call. For the same purposes, you need to set a limit on the execution time of a single compilation. A related problem - if the program is complex, the compiler may hang if you compile an arbitrary file from the project - simply because of the imperfection of the compiler. The first launch, therefore, can be quite long.

Another disadvantage is that VBScript is not in console mode,
black console windows will constantly pop up for each file being compiled.
And in console mode, all the time one script window is open. Since the whole process runs at night, or on the build-testing server, this behavior is acceptable.

By the way

The script can be used for another purpose. The fact is that the code can be corrupted in a day, so the compilation will not work and the tests will not be run, which will be very sad if the tests are completed in the order of several hours. So even in the case of a very simple error correction to correct, and launching during the day will lead to a loss of time.

It is easy and simple to set up the compilability check, say at 19-20-21 pm. Suppose there is a person in the team who can fix a randomly corrupted code. Then, if the project is not going to, you can set up sending SMS to the phone about this problem, so that at least in the morning there will be a compiled file with the test results.

Send SMS to a specific phone number with the subscriber’s consent without the need for special services , free of charge (see posts 76867 and 81630 ).

Source: https://habr.com/ru/post/148906/


All Articles