Files
brave-core/script/ios_bootstrap.py
T
Kyle HickinsonandMihai PLESA c8f8ba0e47 Migrate brave-ios into brave-core (#21553)
* update build script, move core package directory

* Use xcode scheme pre-actions

* Make args file with version & api keys, remove unused configs

* Update dev to nightly naming, cleanup, fix missed test

* Remove brave-core-ios from package, update bootstrap

* dont remove frameworks early

* Move brave-ios npm packages into brave-core, cleanup

* Disable swift-format for now, disable clang-format on ThirdParty dir

* Build frameworks to src/out directory instead of inside brave-ios folder

* Move ios third party deps to brave/third_party/ios_deps directory

* Fix bootstrap copy with new directories, more cleanup

* Add iOS unit tests to `npm run test` command

* Remove swift formatting from presubmit

* Use symlink to output directory, move xcframework creation to npm cmd

* Add license checker special cases for iOS deps

* Presubmit fixes

* Replace `build_in_core` shell script with `scheme_preaction` python

- Adds `brave_ios_marketing_version` config and adds pre-actions for all main schemes
- Re-add Nightly (Dev) scheme

* Cleanup bootstrap, complete dev to nightly rename, remove Local xcconfigs

Plus format/presubmit fixes

* Remove SPM Package.resolved and ignore it

We won't be using the non-Xcode project based build system

* Update presubmit config, Remove macOS wireguard framework prebuild

* Add license info for moved brave-ios npm packages

* Exclude third_party/ios_deps from cpplint

* Add DEPS file to Guardian dep

* Rename brave_version_patch to illustrate its for iOS only

* Use correct GN configuration based on Xcode configuration

* Allow ios bootstrap script to be run from any directory. Update README

* Make fastlane channel builds also release to testers

Also fixes an issue where Xcode injected environment variables were available during GN builds which would cause build failures in Release configurations

* Remove clean git status check from fastlane

* Update fastlane script to always run bootstrap

* Fix bootstrap script copying placeholders to the wrong directory

* Disable xcpretty in fastlane scripts

* Fix debug scheme entitlements now that it shares nightly bundle id

* Update simulator target in fastlane unit test lane

* Disable xcpretty on unit tests and fixup test build

* Add provisioning profiles for nightly builds

* Expand relative directories in bootstrap

* Add explicit provisioning for nightly

* Fix tests & export junit reports

* Update nightly provisioning profile names

* Remove all skipped tests

* Fix failing unit tests

* Add explicit provisioning profiles for beta & release

* Remove app center fastlane plugin and ignore fastlane test_output in git

* Cleanup Xcode project config

* Fix invalid code signing identities on individual targets

* Skip flaky wallet tests, re-add automatic signing for debug builds

* Fix flaky CoreData tests by guaranteeing view context merge

* Update Jenkinsfile

* Move Xcode derived data directory to src/out for CI builds

* Remove 'No Changes' CoreData test

* Fixed missed Xcode derived data directory setting for iPad test build

* Fix iPad test plan

* Separate testflight build & upload into multiple fastlane runs

* Add version string to MaterialComponents during preaction

* Add ability to pass in PUBLIC CI arg into fastlane upload lane

* Cleanup config & presubmit rules

* Add explicit licenses/README.chromium's for third party iOS deps

* Presubmit cleanup/fixes

* Change Xcode preactions to run on xcframeworks instead of GN outputs

This avoids rebuilds that are due to BraveCore.framework and MaterialComponents.framework folders being touched in the out directory when we cleanup chromium assets and fix the MaterialComponents Info.plist

* Improve debugging when `strip_absolute_paths_from_debug_symbols` is true

- The bootstrap script now generates an LLDBInit that is used for Debug schemes. This file contains an lldb target.source-map to allow lldb to resolve breakpoints
- SPM & Xcode now build with the `-debug-prefix-map` swift flag so that all iOS files built out of GN also have relative debug paths
- Replace compilation flags being defined with OTHER_SWIFT_FLAGS to use SWIFT_ACTIVE_COMPILATION_CONDITIONS instead

* Remove SPM reload during preaction and use .env for Package.swift

This removes a race that could happen when reloading the package during the build

* Add Action Extension provisioning profiles and fix its xcode build settings

* Move xcframework creation command into separate file

* Fixup nvm/brew npm PATHs in Xcode pre-action script

* Move iOS bootstrap into gclient runhook, rename current_link

* Bootstrap script improvements based on feedback

* Rebase master/fix bootstrap import

* Bootstrap script improvements based on feedback pt2

* Revert Jenkinsfile change

* Move CheckNoJsInIos and CheckNoDeprecatedCss into permanent ignores

* Rebase master & fix wallet mock asset ratio service

---------

Co-authored-by: Mihai PLESA <mplesa@brave.com>
2024-02-12 13:26:42 -05:00

100 lines
4.0 KiB
Python

# Copyright (c) 2024 The Brave Authors. All rights reserved.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.
import argparse
import inspect
import os
import shutil
import sys
from distutils.dir_util import copy_tree
from brave_chromium_utils import wspath
from lib.config import PLATFORM, enable_verbose_mode, is_verbose_mode
from lib.util import execute_stdout
from pathlib import Path
def main():
if PLATFORM != 'darwin':
# Only applicable to macOS
sys.exit(0)
args = parse_args()
if args.verbose:
enable_verbose_mode()
create_required_spm_resources(force=args.force)
generate_lldbinit(force=args.force)
def parse_args():
parser = argparse.ArgumentParser(description='Bootstrap the iOS project')
parser.add_argument('-v',
'--verbose',
action='store_true',
help='Prints the output of the subprocesses')
parser.add_argument('-f',
'--force',
action='store_true',
help='Always rewrite the symlink/directory entirely')
return parser.parse_args()
def create_required_spm_resources(force=False):
# Runs webpack on the JS files that are generated in iOS. This is so that
# Package.swift/SPM resolves with the resources available
execute_stdout(['npm', 'run', 'ios_pack_js'])
# Creates the expected out/ios_current_link directory and places placeholder
# xcframeworks inside to ensure Package.swift/SPM validates the manifest
# correctly.
ios_current_link = Path(wspath("//out/ios_current_link"))
if ios_current_link.is_symlink():
# Check if the symlink is valid and unlink if its not, (or in the case
# of --force, unlink anyways so it can be removed)
if force or not os.path.exists(os.readlink(ios_current_link)):
ios_current_link.unlink()
if force and ios_current_link.exists():
# Remove the directory entirely
shutil.rmtree(ios_current_link)
ios_current_link.mkdir(parents=True, exist_ok=True)
# Make BraveCore.xcframework and MaterialComponents.xcframework placeholders
# These are essentially the bare-essential requirements for SPM to validate
# the Package.swift manifest: The existence of the xcframework directory
# itself, plus a valid Info.plist inside it.
frameworks = ['BraveCore', 'MaterialComponents']
for frmk in frameworks:
framework_dir = os.path.join(ios_current_link, f'{frmk}.xcframework')
if force and os.path.exists(framework_dir):
shutil.rmtree(framework_dir)
if not os.path.exists(framework_dir):
Path(framework_dir).mkdir(parents=True)
info_plist = wspath(
"//brave/ios/brave-ios/BraveCore/placeholders/xcframework.plist"
)
shutil.copyfile(info_plist, os.path.join(framework_dir,
'Info.plist'))
# Creates an empty args.xcconfig due to a race in Xcode which seems to fail
# to find the xcconfig after its generated during the build preaction script
args_config_path = os.path.join(ios_current_link, 'args.xcconfig')
if force or not os.path.exists(args_config_path):
Path(args_config_path).touch()
def generate_lldbinit(force=False):
contents = inspect.cleandoc(f"""
# This file is generated by ios_bootstrap.py
#
# This allows proper source mapping to builds made with the GN arg
# strip_absolute_paths_from_debug_symbols set to true.
settings set target.source-map "../.." "{wspath("//")}"
""")
lldbinit_file = wspath("//brave/ios/brave-ios/App/Configuration/LLDBInit")
if force or not os.path.exists(lldbinit_file):
with open(lldbinit_file, 'w') as f:
f.write(contents)
if __name__ == '__main__':
main()