update_xcode_target.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env ruby
  2. # Copyright 2021 Google LLC
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # Script to add a file to an Xcode target.
  16. # Adapted from https://github.com/firebase/quickstart-ios/blob/master/scripts/info_script.rb
  17. require 'xcodeproj'
  18. project_path = ARGV[0]
  19. target = ARGV[1]
  20. file_name = ARGV[2]
  21. project = Xcodeproj::Project.open(project_path)
  22. # Add a file to the project in the main group
  23. file = project.new_file(file_name)
  24. # Add the file to the all targets
  25. project.targets.each do |t|
  26. if t.to_s == target
  27. if file_name.end_with?(".json") then
  28. t.add_resources([file])
  29. else
  30. t.add_file_references([file])
  31. end
  32. end
  33. end
  34. # Save project
  35. project.save()