name: Berty

options:
  deploymentTarget:
    iOS: '12.0'
  usesTabs: false
  tabWidth: 2
  indentWidth: 2
  defaultConfig: Debug

fileGroups:
  - Berty/main.jsbundle # required by react-native

configs:
  Debug: debug
  AppStore Release: release
  Staff Release: release
  Yolo Release: release

schemes:
  Berty Debug:
    build:
      parallelizeBuild: false
      targets:
        Berty: all
    run:
      config: Debug
      environmentVariables:
        OS_ACTIVITY_MODE: debug
    archive:
      config: Debug
  Berty AppStore:
    build:
      parallelizeBuild: false
      targets:
        Berty: all
    run:
      config: AppStore Release
      environmentVariables:
        OS_ACTIVITY_MODE: disable
    archive:
      config: AppStore Release
  Berty Staff:
    build:
      parallelizeBuild: false
      targets:
        Berty: all
    run:
      config: Staff Release
      environmentVariables:
        OS_ACTIVITY_MODE: debug
    archive:
      config: Staff Release
  Berty Yolo:
    build:
      parallelizeBuild: false
      targets:
        Berty: all
    run:
      config: Yolo Release
      environmentVariables:
        OS_ACTIVITY_MODE: debug
    archive:
      config: Yolo Release

settings:
  base:
    ONLY_ACTIVE_ARCH: true
    SWIFT_OBJC_BRIDGING_HEADER: Berty/Berty-Bridging-Header.h
    CLANG_ENABLE_MODULES: true
    OTHER_LDFLAGS:
      - $(inherited)
      - -ObjC
      - -lc++
    LD_RUNPATH_SEARCH_PATHS:
      - /usr/lib/swift
      - $(inherited)
    LIBRARY_SEARCH_PATHS:
      - $(SDKROOT)/usr/lib/swift
      - $(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)
      - $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)
      - $(inherited)
    GCC_C_LANGUAGE_STANDARD: gnu99
    CLANG_CXX_LANGUAGE_STANDARD: gnu++0x
    CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED: true
    CLANG_CXX_LIBRARY:
    ENABLE_BITCODE: false
    DEAD_CODE_STRIPPING: true
  configs:
    debug:
      COPY_PHASE_STRIP: false
      GCC_SYMBOLS_PRIVATE_EXTERN: false
      MTL_ENABLE_DEBUG_INFO: true
      GCC_PREPROCESSOR_DEFINITIONS:
        - $(inherited)
        - FB_SONARKIT_ENABLED=1
        - DEBUG=1
    release:
      COPY_PHASE_STRIP: true
      MTL_ENABLE_DEBUG_INFO: false
      GCC_PREPROCESSOR_DEFINITIONS:
        - $(inherited)

targets:
  Berty:
    type: application
    platform: iOS
    configFiles:
      Debug: Configs/Debug.xcconfig
      AppStore Release: Configs/AppStore.xcconfig
      Staff Release: Configs/Staff.xcconfig
      Yolo Release: Configs/Yolo.xcconfig
    settings:
      base:
        PRODUCT_NAME: Berty
        PRODUCT_IDENTIFIER: tech.berty.ios
        SWIFT_OBJC_BRIDGING_HEADER: Berty/Berty-Bridging-Header.h
        SWIFT_OBJC_INTERFACE_HEADER_NAME: Berty-Swift.h
        CODE_SIGN_STYLE: Automatic
        ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon

      configs:
        Debug:
          DEVELOPMENT_TEAM: WMBQ84HN4T
          PRODUCT_NAME: Berty Debug
          PRODUCT_BUNDLE_IDENTIFIER: $(PRODUCT_IDENTIFIER).debug
          ASSETCATALOG_COMPILER_APPICON_NAME: AppIconDebug
          CODE_SIGN_ENTITLEMENTS: Entitlements/Dev.entitlements
          APP_GROUP_ID: group.tech.berty.dev
          OTHER_SWIFT_FLAGS: '-D CFG_DEBUG -D DEBUG_LOGS $(inherited)'
        AppStore:
          DEVELOPMENT_TEAM: WMBQ84HN4T
          PRODUCT_NAME: Berty
          PRODUCT_BUNDLE_IDENTIFIER: $(PRODUCT_IDENTIFIER)
          ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon
          CODE_SIGN_ENTITLEMENTS: Entitlements/Prod.entitlements
          APP_GROUP_ID: group.tech.berty
          OTHER_SWIFT_FLAGS: '-D CFG_APPSTORE $(inherited)'
        Staff:
          DEVELOPMENT_TEAM: WMBQ84HN4T
          PRODUCT_NAME: Berty Staff
          PRODUCT_BUNDLE_IDENTIFIER: $(PRODUCT_IDENTIFIER).staff
          ASSETCATALOG_COMPILER_APPICON_NAME: AppIconStaff
          CODE_SIGN_ENTITLEMENTS: Entitlements/Dev.entitlements
          APP_GROUP_ID: group.tech.berty.dev
          OTHER_SWIFT_FLAGS: '-D CFG_STAFF -D DEBUG_LOGS $(inherited)'
        Yolo:
          DEVELOPMENT_TEAM: GR5463T564
          PRODUCT_NAME: 'Berty ${YOLO_SUFFIX}'
          PRODUCT_BUNDLE_IDENTIFIER: $(PRODUCT_IDENTIFIER).yolo
          ASSETCATALOG_COMPILER_APPICON_NAME: AppIconYolo
          CODE_SIGN_ENTITLEMENTS: Entitlements/Entreprise.entitlements
          APP_GROUP_ID: group.tech.berty.entreprise
          OTHER_SWIFT_FLAGS: '-D CFG_YOLO -D DEBUG_LOGS $(inherited)'

    sources:
      - Berty
      - NotificationService/Common.swift
      - path: ../packages/assets/font
        name: Fonts
        group: Resources
      - path: ../packages/assets/sound
        name: Sounds
        group: Resources
    dependencies:
      - target: NotificationService
        codeSign: false
        embed: true
      - framework: JavascriptCore.framework
        embed: false
        link: false
      - sdk: Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MultipeerConnectivity.framework
        root: DEVELOPER_DIR
        link: true
      - sdk: Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CoreBluetooth.framework
        root: DEVELOPER_DIR
        link: true
      - sdk: usr/lib/libresolv.tbd
        root: SDKROOT
        link: true
      - framework: ./Frameworks/Bertybridge.xcframework
        embed: false
      - framework: '${SRCROOT}/../node_modules/expo-file-system/ios/EXFileSystem.xcframework'
        embed: false
      - framework: '${SRCROOT}/../node_modules/expo-camera/ios/EXCamera.xcframework'
        embed: false

    preBuildScripts:
      - name: Start Packager
        script: |
          export RCT_METRO_PORT="${RCT_METRO_PORT:=8081}"
          echo "export RCT_METRO_PORT=${RCT_METRO_PORT}" > "${SRCROOT}/../node_modules/react-native/scripts/.packager.env"
          if [ -z "${RCT_NO_LAUNCH_PACKAGER+xxx}" ] ; then
            if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then
              if ! curl -s "http://localhost:${RCT_METRO_PORT}/status" | grep -q "packager-status:running" ; then
                echo "Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly"
                exit 2
              fi
            else
              open "$SRCROOT/../node_modules/react-native/scripts/launchPackager.command" || echo "Can't start packager automatically"
            fi
          fi
        showEnvVars: false

    postBuildScripts:
      - name: Bundle React Native code and images
        script: |
          export NODE_BINARY="$(zsh -ilc 'asdf which node' 2> /dev/null || echo node)"
          export ENTRY_FILE=index.ts
          ../node_modules/react-native/scripts/react-native-xcode.sh

  NotificationService:
    type: app-extension
    platform: iOS
    configFiles:
      Debug: Configs/Debug.xcconfig
      AppStore Release: Configs/AppStore.xcconfig
      Staff Release: Configs/Staff.xcconfig
      Yolo Release: Configs/Yolo.xcconfig
    settings:
      base:
        ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES: false
        PRODUCT_NAME: NotificationService
        CODE_SIGN_STYLE: Automatic
        INFOPLIST_FILE: NotificationService/Info.plist
      configs:
        Debug:
          PRODUCT_BUNDLE_IDENTIFIER: tech.berty.ios.debug.NotificationService
          DEVELOPMENT_TEAM: WMBQ84HN4T
          CODE_SIGN_ENTITLEMENTS: Entitlements/DevNS.entitlements
          APP_GROUP_ID: group.tech.berty.dev
          OTHER_SWIFT_FLAGS: '-D CFG_DEBUG $(inherited)'
        AppStore:
          PRODUCT_BUNDLE_IDENTIFIER: tech.berty.ios.NotificationService
          DEVELOPMENT_TEAM: WMBQ84HN4T
          CODE_SIGN_ENTITLEMENTS: Entitlements/ProdNS.entitlements
          APP_GROUP_ID: group.tech.berty
          OTHER_SWIFT_FLAGS: '-D CFG_APPSTORE $(inherited)'
        Staff:
          PRODUCT_BUNDLE_IDENTIFIER: tech.berty.ios.staff.NotificationService
          DEVELOPMENT_TEAM: WMBQ84HN4T
          CODE_SIGN_ENTITLEMENTS: Entitlements/DevNS.entitlements
          APP_GROUP_ID: group.tech.berty.dev
          OTHER_SWIFT_FLAGS: '-D CFG_STAFF $(inherited)'
        Yolo:
          PRODUCT_BUNDLE_IDENTIFIER: tech.berty.ios.yolo.NotificationService
          DEVELOPMENT_TEAM: GR5463T564
          CODE_SIGN_ENTITLEMENTS: Entitlements/EntrepriseNS.entitlements
          APP_GROUP_ID: group.tech.berty.entreprise
          OTHER_SWIFT_FLAGS: '-D CFG_YOLO $(inherited)'
    sources:
      - NotificationService
      - Localization
      - Berty/Sources/RootDir/RootDir.swift
      - Berty/Sources/Bridge/KeystoreDriver.swift

    dependencies:
      - framework: ./Frameworks/Bertypush.xcframework
        embed: false
      - framework: '${PODS_ROOT}/OpenSSL-Universal/OpenSSL.xcframework'
        embed: false
      - sdk: usr/lib/libresolv.tbd
        root: SDKROOT
        link: true

include:
  - info.yaml
