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

Injecting snippet into post_install hook #12272

Open
xelxebar opened this issue Feb 8, 2024 · 0 comments
Open

Injecting snippet into post_install hook #12272

xelxebar opened this issue Feb 8, 2024 · 0 comments

Comments

@xelxebar
Copy link

xelxebar commented Feb 8, 2024

Overview

Working on a CI for a client, we have accumulated a few Podfile snippets that need to be injected in most projects for working around various quirks of my client's in-house infra. At the moment these snippets are manually applied and commited every time a new project boots up, but this is an error prone process.

I am working to automate the injection at CI build time. In particular, our primary snippet is getting added to the post_install block. Instead, without commiting changes to the Podfile I'd like to achieve the same effect by injecting some appropriate Ruby into the Podfile before calling pod install.

Details

The specific code we're attempting to inject looks like this:

post_install do |installer|
  installer.pods_project.targets.each do |target|

  ...

    target.build_configurations.each do |config|

      ...

      # Block we're trying to inject
      if !signed_targets.include?(target.name)
        puts "SET #{target.name}-#{config.name} NO SIGN"
        config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
        config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
        config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
      end

    end
  end
end

Attempted solutions

Without much knowledge of Ruby or CocoaPods internals, here's the main approach I'm taking:

  1. Create code_to_inject.rb somewhere, and
  2. Inject load 'path/to/code_to_inject.rb at the bottom of Podfile. i.e. sed -i ... Podfile

However, I'm unsure whether this approach is reasonable at all. Specifically, I also don't know what the code_to_inject.rb snippet should look like. Naïvely shoving a post_install block in it results in errors, since post_install appears only callable once.

Questions

  1. Is the basic strategy above sane?
  2. If so, then what should the code_to_inject.rb contain?
  3. Is loading the ruby a good way of injecting?
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

No branches or pull requests

1 participant