Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add a settings file to configure cobc at runtime #117

Draft
wants to merge 2 commits into
base: gcos4gnucobol-3.x
Choose a base branch
from

Conversation

lefessan
Copy link
Member

New --settings=FILE can be used to configure flags that are normally set at compile time. These settings can be used typically to create cross-compilers by retargetting an existing compiler.

Also add a setting to make the compiler relocatable, i.e. compute paths of include, share, etc. relative to cobc's location.

New --settings=FILE can be used to configure flags that are normally
set at compile time. These settings can be used typically to create
cross-compilers by retargetting an existing compiler.

Also add a setting to make the compiler relocatable, i.e. compute
paths of include, share, etc. relative to cobc's location.
@lefessan lefessan marked this pull request as draft October 17, 2023 21:48
@codecov-commenter
Copy link

codecov-commenter commented Oct 17, 2023

Codecov Report

Merging #117 (ebc7f78) into gcos4gnucobol-3.x (c0d64ad) will decrease coverage by 0.25%.
The diff coverage is 19.44%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

@@                  Coverage Diff                  @@
##           gcos4gnucobol-3.x     #117      +/-   ##
=====================================================
- Coverage              65.74%   65.49%   -0.25%     
=====================================================
  Files                     32       34       +2     
  Lines                  59092    59345     +253     
  Branches               15575    15679     +104     
=====================================================
+ Hits                   38849    38869      +20     
- Misses                 14262    14457     +195     
- Partials                5981     6019      +38     
Files Coverage Δ
cobc/typeck.c 65.28% <ø> (ø)
cobc/ppparse.y 61.85% <0.00%> (-0.12%) ⬇️
cobc/cobc.c 72.02% <41.66%> (-0.37%) ⬇️
cobc/settings.def 0.00% <0.00%> (ø)
cobc/codegen.c 75.09% <19.81%> (-0.90%) ⬇️
cobc/settings.c 17.59% <17.59%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

#ifdef COB_DEBUG_FLAGS
COBC_ADD_STR (cobc_cflags, " ", cobc_debug_flags, NULL);
#endif
if (!cb_setting_COB_DEBUG_FLAGS[0]){
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to this variable before it might have been modified by loading the settings.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds like an egg-and-hen problem

Copy link
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is about https://sourceforge.net/p/gnucobol/feature-requests/450/ where additional important discussion happens. Please outline more about the need for this configuration there, keeping in mind that if you want to cross-compile for another environment you still have to have:

  • GnuCOBOL built for that cross-target (to get "libcob"; normally this will also provide you with a "cobc" for that environment)
  • a C cross-compiler (that you've likely used to generate that GnuCOBOL version in the first place, so all of its configuration is already inbuilt in the generated cobc executable)

The main culprit: when building GnuCOBOL itself with a cross-compiler you need a subsystem to also execute the resulting cobc binary (for example wine).
I do wonder if it isn't more reasonable to work on https://sourceforge.net/p/gnucobol/feature-requests/245/ which allows to not only cross-compile GnuCOBOL but also provide the option to generate a cross-compiling cobc.

A "side issue" here is the option to be relocatable, but that does only apply here to the compiler, not to the runtime.
I suggest to keep that out of this PR and instead improve the relocatable option that Ron already added in trunk (the "get name" function for example would be a reasonable addition).

Note: I do think that making GnuCOBOL well relocatable is important and this may also land in 3.x (likely to only happen if you provide a patch), but as we have that in trunk already it seems more reasonable to test and improve there (it was only tested with GNU/Linux x64), then either merge the revisions to 3.x or do a big backport instead.

If we still want to add a compiler setting, wouldn't it then be reasonable to use the existing configuration options in libcob?
To do so, the current entry functions in config.c would get an additional pointer to the configuration structure (we even can store it in a static var to ease access later on) and and we'd have a separate configuration table that only contains the cobc related settings, then pass the that to the config functions in libcob to set the values (single place of already well tested code, with guaranteed identical behavior in the future).

Nonetheless - first review while still in draft

I highly suggest to add ChangeLog entries at least before each push, this way you know more what you've changed and why, and it also helps for a possible review.

@@ -592,6 +583,7 @@ static const struct option long_options[] = {
{"O2", CB_NO_ARG, NULL, '2'},
{"O3", CB_NO_ARG, NULL, '3'},
{"Os", CB_NO_ARG, NULL, 's'},
{"settings", CB_OP_ARG, NULL, CB_FLAG_GETOPT_SETTINGS},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be a required argument, and checking it below then take it for granted.
cobc --info should print the active setting, so cobc --settings=something --info would automatically print it.

See cobcrun --runtime-config and cobcrun --config=file --runtime-env.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, after inspecting settings.c, this actually makes sense. From my gut it feels like a separate --export-settings[=<file>] would be more appropriate with defaulting to - (stdout).

In any case - if cobc --settings is added then the same feature should work with cobcrun --runtime-config (either without a parameter or as separate export option) providing a way to "dump" the settings, allowing the to be adjusted and then used.
We may want to export/dump the settings (in both the cobc and cobcrun case) match the "installed defaults" as a comment line (just uncomment, then adjust)

#ifdef COB_DEBUG_FLAGS
COBC_ADD_STR (cobc_cflags, " ", cobc_debug_flags, NULL);
#endif
if (!cb_setting_COB_DEBUG_FLAGS[0]){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't cobc_debug_flags be part of cb_setting_COB_DEBUG_FLAGS?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file needs a header and the strings should be gettextized.
Items not used should be removed (or commented out, with their strings not gettextized).

#elif defined (HAVE_MPIR_H)
#define MATH_INCLUDE "#include <mpir.h>"
#else
#error either HAVE_GMP_H or HAVE_MPIR_H needs to be defined
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that compile-time of cobc check would then go to settings.c, the matching runtime check should also be done only once, likely there, not for each program outside of the setting code


* Use of the argument `--settings=FILE`
* Use of the environment variable `COBC_SETTINGS`
* Use of `../etc/gnucobol/gnucobol.settings` from the directory
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be the COB_CONFIG_DIR (with its fallback) instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that we need a setting for that, why not always have that?


If a file is specified, an error while loading the file is fatal.

Once the settings have been loaded, a few variables can be modified if
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to make that not depending on COBC_IS_RELOCATABLE (env var or its default) but instead just checking if the executable is in the place that we expect - if it isn't then o the relocation.
... but this part should possibly go elsewhere (see main review comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants