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 support for dependencies #61

Merged
merged 3 commits into from
Jan 1, 2024
Merged

Conversation

fnxpt
Copy link

@fnxpt fnxpt commented Dec 5, 2023

Fixes #58

Still need to add tests for this

@fnxpt fnxpt requested a review from a team as a code owner December 5, 2023 20:25
Copy link
Contributor

@macblazer macblazer left a comment

Choose a reason for hiding this comment

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

Thanks for working on this. It does need some unit tests to ensure

  1. The analyzer is finding the right dependencies, and
  2. The BOMBuilder is generating the right output with the dependencies.

The existing SimplePod and TestingPod fixtures both have a single dependency in them that can help with the tests. It might be good to create one more fixture with maybe a couple of dependencies to ensure it's iterating over everything correctly.


def initialize(component: nil, pods:)
@component, @pods = component, pods
def initialize(component: nil, dependencies: nil, pods:)
Copy link
Contributor

Choose a reason for hiding this comment

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

Codacy is asking you to put pods: as the first parameter because pods is the only parameter that does not specify a default value. Calls to this function can then look like one of the following (note that pods is always first because it has to be specified):

BOMBuilder.new(pods: pods)
BOMBuilder.new(pods: pods, component: myComponent)
BOMBuilder.new(pods: pods, dependencies: deps)
BOMBuilder.new(pods: pods, component: myComponent, dependencies: deps)

@fnxpt
Copy link
Author

fnxpt commented Dec 9, 2023

Sorry for the delay, I added tests for pod analyzer I will do the same with bom builder later, but for the restrictedPod the code is breaking on the sources, any idea why?

@macblazer
Copy link
Contributor

macblazer commented Dec 11, 2023

Sorry for the delay, I added tests for pod analyzer I will do the same with bom builder later, but for the restrictedPod the code is breaking on the sources, any idea why?

The RestrictedPod is a fixture because it has a nice edge case where the Podfile is for iOS, and the EFQRCode pod has a dependency that is not used for iOS. The way CocoaPods works in this case is that the Podfile.lock shows the dependency on swift_qrcodejs under the PODS section, but swift_qrcodejs is not listed as a top-level pod in the PODS section and is not present at all in the DEPENDENCIES, SPEC REPOS, or SPEC CHECKSUMS sections. The function append_all_pod_dependencies in the podfile_analyzer.rb takes this into account, but your new function dependencies_hash_of_lockfile_pods does not.

In the bom.xml output tests for the RestrictedPod, I would not expect to see any references to swift_qrcodejs because it is not actually being used for this iOS target.

It might be better to restructure the new code by adding new capability to the append_all_pod_dependencies function (at line 169) instead of having the whole new function that iterates over the entire lock file a second time. Something like

def append_all_pod_dependencies(pods_used, pods_cache)
  result = pods_used
  dependencies_hash = [] # new
  original_number = 0
  # Loop adding pod dependencies until we are not adding any more dependencies to the result
  # This brings in all the transitive dependencies of every top level pod.
  # Note this also handles two edge cases:
  #  1. Having a Podfile with no pods used.
  #  2. Having a pod that has a platform-specific dependency that is unused for this Podfile.
  while result.length != original_number
    original_number = result.length
    pods_used.each { |pod_name|
      if pods_cache.key?(pod_name) && !pods_cache[pod_name].empty? # new
         result.push(*pods_cache[pod_name]) # changed
         dependencies_hash[pod_name] = *pods_cache[pod_name] # new
         # maybe additional dependency processing needed here???
      end
    }
    result = result.uniq
    # maybe additional dependency processing needed here???
    pods_used = result
  end
  result # change this to return result and dependencies_hash or make dependencies_hash a class property
end

@fnxpt
Copy link
Author

fnxpt commented Dec 11, 2023

I will change it to reflect that

@fnxpt
Copy link
Author

fnxpt commented Dec 18, 2023

Fixed the issue with Reserved Podfile... @macblazer I think the only thing missing is adding tests to the bom builder. Are you able to help with this part?

@fnxpt
Copy link
Author

fnxpt commented Dec 18, 2023

cleaned up a little bit the code, following your advice, also added bom_builder tests following the already existing tests.
Tomorrow I will fix the remaining lint issues

Signed-off-by: Marlon Pina Tojal <[email protected]>
@fnxpt
Copy link
Author

fnxpt commented Dec 19, 2023

Everything should be ok now

Signed-off-by: Marlon Pina Tojal <[email protected]>
@fnxpt
Copy link
Author

fnxpt commented Dec 29, 2023

@macblazer can you have another look?

Signed-off-by: Marlon Pina Tojal <[email protected]>
Copy link
Contributor

@macblazer macblazer left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution and working through all the updates.

@macblazer macblazer merged commit 8372b54 into CycloneDX:main Jan 1, 2024
5 checks passed
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.

Add dependencies between components
2 participants