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

refactor: change project flag configuration behavior #1451

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

scolsen
Copy link
Contributor

@scolsen scolsen commented Jan 27, 2023

This PR changes the behavior of the project flag setting dynamic functions. Instead of appending a single string to the flagset, they now take a list of strings, which serve as the new flagset:

(Project.get-config "cflag")
=> (...a bunch of default platform flags; "-wall" ...)
(Project.config "cflag" '("-my" "-new" "-flags"))
(Project.get-config "cflag")
=> ("-my" "-new" "-flags")

In order to append flags, users now need to cons to a config-get:

(Project.config "cflag" (cons "-new" (Project.get-config "cflag")))

This is a breaking change, as passing a single string is now an error.

I considered overloading the behavior as an alternative so that we wouldn't break existing callers, but I feel this would ultimately lead to unintuitive behavior (calling with a single string appends while calling with a list of strings overrides ... users might wonder why the list doesn't append all the strings in the list instead).

This PR also fixes a bug w/ fetching project C flags and provides helper macros for appending flags to existing project flag sets given the new behavior.

Fixes `(Project.get-config "cflags")` so that it actually returns the
project's C flag field. Previously it was returning the project's
preprocessor calls.
This commit alters the project configuration compiler flag setting
behavior to allow users to override default project flags.

Flag setting commands (cflag, libflag, pkgconfigflag) now take lists of
strings as arguments. Previously, they were append-only and accepted
string arguments.

Now, to override flags, users can call:

```
(Project.get-config "cflag")
=> (...a bunch of default platform flags; "-wall" ...)
(Project.config "cflag" '("-my" "-new" "-flags"))
(Project.get-config "cflag")
=> ("-my" "-new" "-flags")
```

In order to append flags, users now need to `cons` to a `config-get`:

```
(Project.config "cflag" (cons "-new" (Project.get-config "cflag")))
```

BREAKING CHANGE: Code that relies on the previous behavior will break,
as calling these functions with non-list arguments is now an error. I
considered a softer path whereby we'd overload the current behavior to
avoid breaking existing users; however, the result would be confusing.
Passing a list would result in overriding the project field while
passing a single string would result in an append. A user might
conceivably wonder why passing a list doesn't result in a multi-append.
Ultimately I felt making a breaking change would be less confusing than
this compatibility preserving behavior down the line.
Provides convenience macros for appending flags to project flag fields
cflag, libflag, and pkgconfigflag.
@scolsen scolsen requested a review from a team January 27, 2023 22:13
Copy link
Member

@hellerve hellerve left a comment

Choose a reason for hiding this comment

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

🎉

Copy link
Collaborator

@eriksvedang eriksvedang left a comment

Choose a reason for hiding this comment

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

Looks good! Seems to break the tests though?

Updates some project configuration calls in the Core library to follow
the new configuration behavior (pass complete flag sets and not
individual strings).
To account for the new flag setting configuration behavior.
Adds a preload eval to set the -Wnounknown-warning-option flag in clang
-- this way, when different versions don't support our default flag set,
they can still run tests. Otherwise passing an unknown flag to clang
results in a compilation error.
@scolsen
Copy link
Contributor Author

scolsen commented Jan 31, 2023

Ok, so this PR gets our failing *nix builds green again by bypassing -Wunknown-warning-option, but it now seems that there's yet another, totally unrelated Macos SDK image error complaining about the use of sprintf....ugh

@scolsen
Copy link
Contributor Author

scolsen commented Jan 31, 2023

I'm wondering if we should just drop -Wall for our tests at this point in favor of an explicitly set list of reasonable warnings we want to make sure our emitted C complies with.

@hellerve
Copy link
Member

Possibly a good idea, but maybe we should also just remove usages of sprintf. I’ve done that in #1453 for your convenience :)

@scolsen
Copy link
Contributor Author

scolsen commented Jan 31, 2023

Possibly a good idea, but maybe we should also just remove usages of sprintf. I’ve done that in #1453 for your convenience :)

Even better!

@eriksvedang
Copy link
Collaborator

Does this need to pull in master for the tests to pass?

@eriksvedang
Copy link
Collaborator

@scolsen Should we try to get this merged?

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