Подтвердить что ты не робот

Уровень оптимизации Cocoapods для схем

Глядя на файл проекта для Cocoapods Pods.xcodeproj, похоже, что каждая отдельная схема для каждой библиотеки (кроме схемы Debug) имеет уровень оптимизации Fastest, Smallest.

Есть ли простой и простой способ изменить Podfile или другую конфигурацию Cocoapods, чтобы уровень оптимизации None для конкретных схем, когда я использую pod install?

enter image description here

4b9b3361

Ответ 1

Я использую хук post_install в Podfile. Как это:

post_install do |installer|
    installer.pods_project.build_configurations.each do |config|
        if config.name.include?("Debug")
            config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0'
            config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Onone'
        end
    end
end

EDIT GCC_OPTIMIZATION_LEVEL игнорируется для GCC_OPTIMIZATION_LEVEL. Если вы используете SWIFT_OPTIMIZATION_LEVEL Swift, вам также нужно установить SWIFT_OPTIMIZATION_LEVEL.

Ответ 2

Для всех, кто видит это, используя cocoapods 0.38.0 или новее:

Используйте "pods_project" вместо "project"

В предыдущих ответах используется слово "проект" (installer.project.build_configurations.each)

Проект устарел и заменен на pods_project. https://github.com/CocoaPods/CocoaPods/issues/3747

post_install do |installer|
  installer.pods_project.build_configurations.each do |config|
    if config.name.include?("Debug")
      config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0'
    end
  end
end

Ответ 3

Если вы также хотите, чтобы добавленный макрос DEBUG для отладки с включенными утверждениями, вы можете использовать следующий script:

post_install do |installer|
  installer.project.build_configurations.each do |config|
    if config.name.include?("Debug")
      # Set optimization level for project
      config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0'

      # Add DEBUG to custom configurations containing 'Debug'
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
      if !config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].include? 'DEBUG=1'
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'DEBUG=1'
      end
    end
  end

  installer.project.targets.each do |target|
    target.build_configurations.each do |config|
        if config.name.include?("Debug")
          # Set optimization level for target
          config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0'

          # Add DEBUG to custom configurations containing 'Debug'
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
          if !config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].include? 'DEBUG=1'
            config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'DEBUG=1'
          end

          # Enable assertions for target
          config.build_settings['ENABLE_NS_ASSERTIONS'] = 'YES'

          config.build_settings['OTHER_CFLAGS'] ||= ['$(inherited)']
          if config.build_settings['OTHER_CFLAGS'].include? '-DNS_BLOCK_ASSERTIONS=1'
            config.build_settings['OTHER_CFLAGS'].delete('-DNS_BLOCK_ASSERTIONS=1')
          end
        end
      end
  end
end

Ответ 4

Вместо post_install вы можете добавить следующую строку в подфайл:

project 'ProjectName', 'DebugConfigurationName' => :debug