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

Allow secondary generators when building with CMake. #9324

Merged

Conversation

greenc-FNAL
Copy link
Member

CMake supports the notion of secondary generators which provide extra information to (e.g.) IDEs over and above that normally provided by the primary generator.

The list of primary generators ('Unix Makefiles' and 'Ninja') supported by Spack has not changed.

Since the secondary generator is irrelevant to a Spack build, it is passed on to CMake without further validation.

@greenc-FNAL greenc-FNAL force-pushed the feature/cmake-secondary-generators branch from 7cce891 to 440ca74 Compare October 3, 2018 20:53
@@ -128,10 +129,13 @@ def _std_args(pkg):

# Make sure a valid generator was chosen
valid_generators = ['Unix Makefiles', 'Ninja']
if generator not in valid_generators:
generator_extractor = re.compile(r'(?:.*?-\s+)?(.*)')
Copy link
Member

@scheibelp scheibelp Oct 19, 2018

Choose a reason for hiding this comment

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

@chissg

I'm surprised that the first .* is not greedy. Would a regex like

[^-]*(:?-\s+)(.*)

work? Anyhow the unit test confirms that it what you have works, but to explain why I'd have to look up the behavior of python regexes or regexes in general.

Either way, could you also add an explanation or an example in a comment like

# Extract the primary generator from the generator string
# For example, "ninja" from "CodeBlocks - Ninja"

If this logic was isolated to a function, then that wouldn't be necessary, as it would be easy to look up the associated unit test. Since the logic is embedded I think it's worthwhile to add a comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

@scheibelp Thanks for this. The first .* could be greedy: the question is whether you think an embedded - is more likely to be found in the secondary generator name, or the primary. If there's only ever one (as is currently the case with all known values) then there is no difference in behavior. Since the secondary generator (and therefore the separator) is entirely optional though, I wanted to be more specific.
I can certainly pull the extraction out into a function if you think it would improve the clarity.

Copy link
Member

Choose a reason for hiding this comment

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

If the rules for the generator name are not specified then this could be fragile. Perhaps it would be safer to check for the names in the generator, like

if 'Ninja' in generator or 'Unix Makefiles' in generator:
  pass
else:
  raise...

Without more info on the constraints on the name (e.g. maybe embedded dashes can't have spaces) I think it might be hard to come up with a good regex.

(I realized the regex I suggested has its own potential pitfalls WRT being greedy)

Copy link
Member Author

Choose a reason for hiding this comment

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

From https://cmake.org/cmake/help/git-master/manual/cmake-generators.7.html:

Some of the CMake Generators listed in the cmake(1) command-line tool --help output may have variants that specify an extra generator for an auxiliary IDE tool. Such generator names have the form - . The following extra generators are known to CMake.

Neither any of the existing defined primary generators, nor any of the secondary ones, have any embedded dashes. Since these names are encoded into CMake, one can only presume that if they come up with a new generator (primary or secondary) that absolutely needs a dash, they'll change the rules.

In the meantime, since as you say we're looking for particular known generators we support, I'd suggest a search rather than a match:

(?: - )?(.*)$

This will check for the (currently) prescribed format in the case of the presence of a secondary generator, followed by something that will either be one of the items we expect, or it won't. If a secondary exists and has an embedded hyphen it won't matter; if there's a secondary generator but they've screwed up the separator we'll match everything and fail to recognize the primary (correct behavior IMO). In the normal case (with or without secondary), we'll pull a primary we can compare against our limited list, and we're insulated against new primaries that we don't support, but whose name is a subset of one we do. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

This sounds good, and the regex you suggest is clearer (to me at least). I also think it's worth including a short comment giving an example of generator names.

I can certainly pull the extraction out into a function if you think it would improve the clarity.

Even though it's small, that does appeal to me: something like extract_primary_generator.

Copy link
Member Author

Choose a reason for hiding this comment

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

I hope I have addressed these comments with 107df3e. I was not able to turn the regex into a search as we discussed, but I hope things are now clearer nonetheless.

@greenc-FNAL greenc-FNAL force-pushed the feature/cmake-secondary-generators branch from fdbb516 to 107df3e Compare November 1, 2018 15:37
@greenc-FNAL
Copy link
Member Author

@scheibelp Bump?

@greenc-FNAL greenc-FNAL force-pushed the feature/cmake-secondary-generators branch from 107df3e to f9cd78f Compare February 12, 2019 14:47
@greenc-FNAL greenc-FNAL reopened this Feb 12, 2019
@scheibelp scheibelp merged commit 05f5653 into spack:develop Feb 12, 2019
@scheibelp
Copy link
Member

Thanks!

@greenc-FNAL greenc-FNAL deleted the feature/cmake-secondary-generators branch March 11, 2019 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants