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

Add an entry point to xcodeproj rule for overriding project attributes #165

Merged
merged 3 commits into from
Nov 26, 2020

Conversation

gyfelton
Copy link
Contributor

@gyfelton gyfelton commented Nov 25, 2020

Why this change

Need to provide a way to insert custom attributes for downstream projects
Was thinking about using a project_overrides where one can pass {'attributes': {key: value}, 'options': {key: value}, 'settings' {key: value}} to cover other fields that we have default values for. But according to Bazel doc https://docs.bazel.build/versions/master/skylark/lib/attr.html#string_dict values for string_dict can only be string, so have to break them up into individual fields like the change proposed here.

Please let me know if there is a better way so that we can allow customization done easily for downstream projects.

Tests

After adding one to a sample project, it indeed gets reflected in the corresponding generated project

@thiagohmcruz
Copy link
Contributor

👀 here in case anyone has any ideas, also bumped into this while working on something else. Found more than one discussion similar to this: bazelbuild/bazel#10414

rules/xcodeproj.bzl Outdated Show resolved Hide resolved
@@ -683,8 +683,11 @@ def _xcodeproj_impl(ctx):
if _is_current_project_file(f)
]

attributes = {}
attributes.update(ctx.attr.project_attributes_overrides)
Copy link
Member

Choose a reason for hiding this comment

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

is there any reason why this can't be passed directly into the struct initializer below?

@segiddins
Copy link
Member

Please let me know if there is a better way so that we can allow customization done easily for downstream projects.

Eventually (in bazel 4 iirc) there's a module to deserialize JSON, so we could accept a JSON string as the parameter there and serialize an arbitrary data structure to JSON inside a macro which then calls the rule

Copy link
Contributor Author

@gyfelton gyfelton left a comment

Choose a reason for hiding this comment

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

Please let me know if there is a better way so that we can allow customization done easily for downstream projects.

Eventually (in bazel 4 iirc) there's a module to deserialize JSON, so we could accept a JSON string as the parameter there and serialize an arbitrary data structure to JSON inside a macro which then calls the rule

So for now we keep it as is? I just feel with current approach the param list for this rule might explode once we start to need overrides for options or settings or other configs.

xcodeproj_info = struct(
name = paths.split_extension(project_name)[0],
attributes = attributes,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you mean this?

Suggested change
attributes = attributes,
attributes = ctx.attr.project_attributes_overrides,

If so what i have in mind is that the patterm has been have a placeholder at line 686 so we can throw in any default attribute. Also it matches with how things declared for options and settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since ctx.attr.project_attributes_overrides has a default of {}, doing this assignment directly has no harm as well, I will do this after your reply.

@segiddins
Copy link
Member

So for now we keep it as is

yeah it works for now, we can always change it / take a more complicated approach later

@gyfelton gyfelton merged commit 880f567 into master Nov 26, 2020
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