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

apply_change_to_project: Fix adding subproject that already exist. #21

Merged
merged 3 commits into from
Oct 26, 2021

Conversation

byohay
Copy link
Collaborator

@byohay byohay commented Aug 3, 2021

  • apply_change_to_project: Differentiate find file and reference proxy.
  • apply_change_to_project: Fix adding existing subproject.
  • Kintsugi: Fix adding build file to a file with multiple references.

@byohay byohay changed the title feature/add existing subproject apply_change_to_project: Fix adding subproject that already exist. Aug 3, 2021
Since the caller knows whether they need to find a file or a reference
proxy it doesn't make sense to have all functions call the same methods.
@byohay byohay force-pushed the feature/add-existing-subproject branch from 6af0035 to 011552c Compare October 24, 2021 09:03
def find_file(project, file_reference_change)
project.files.find do |file_reference|
next file_reference.path == file_reference_change["path"]
def find_file(project, file_reference_change, filter_file: ->(_) { true })
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe filter or filter_with or filter_closure instead of filter_file since it sounds like the parameter is a file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed to file_filter.

raise "Unsupported file reference change of type #{file_reference["isa"]}."
def find_file(project, file_reference_change, filter_file: ->(_) { true })
file_references = project.files.select do |file_reference|
next file_reference.path == file_reference_change["path"] &&
Copy link
Contributor

Choose a reason for hiding this comment

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

is next necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed.

end

def find_reference_proxy(project, container_item_proxy_change)
def find_reference_proxy(project, container_item_proxy_change, filter_reference: ->(_) { true })
Copy link
Contributor

Choose a reason for hiding this comment

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

filter_reference is also confusing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same.

@byohay byohay force-pushed the feature/add-existing-subproject branch 2 times, most recently from 04ca906 to 0c6c1df Compare October 26, 2021 11:59
@byohay
Copy link
Collaborator Author

byohay commented Oct 26, 2021

@ashdnazg squashed.

When a subproject is added, its file reference is used in several
places:
- It's added to a `PBXGroup`.
- It's added to the dictionary of project references under `projectRef`.
- A new `PBXContainerItemProxy` is added and it refers to it under
  `containerPortal`.

Beforehand, when a subproject that already exists was added, `find_file`
would not be able to distinguish between the existing and new reference,
and it might refer to it in all places mentioned above, which would make
an invalid project file.
To distinguish between them, the file reference that is
used is the one that doesn't exist in the project references.
@byohay byohay force-pushed the feature/add-existing-subproject branch from 0c6c1df to 4e5f7a6 Compare October 26, 2021 12:18
# the other one without, this method will prefer to take the one without the build file.
# This assumes that it's preferred to have a file reference with build file than a file
# reference without/with two build files.
filter_files_without_build_files = lambda do |reference|
Copy link
Contributor

Choose a reason for hiding this comment

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

why not filter_reference_without_build_files?

Previously, if two file references that refer to the same file existed,
a build file's reference won't prefer one over the other. Even though it
is legal, a 1:1 relationship between build file and file reference
usually exist. Therefore the logic of adding a build file changes to
prefer a file reference that has no build files.
@byohay byohay force-pushed the feature/add-existing-subproject branch from 4e5f7a6 to ffb9654 Compare October 26, 2021 14:07
@byohay
Copy link
Collaborator Author

byohay commented Oct 26, 2021

@ashdnazg done.

@ashdnazg ashdnazg merged commit d10e5e1 into Lightricks:main Oct 26, 2021
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.

2 participants