#!/usr/bin/env python | |
import argparse | |
import subprocess | |
import plistlib | |
import os | |
import xml.etree.ElementTree as ET | |
TEAM = '___YOUR_TEAM_ID__' | |
def set_provisioning_to_automatic(team, plist_file): | |
plist = plistlib.readPlist(plist_file) | |
automatic_targets = [] | |
project = None | |
for k, v in plist.objects.items(): | |
if v.isa == 'PBXNativeTarget': | |
if v.productType == 'com.apple.product-type.app-extension' or v.productType == 'com.apple.product-type.application': | |
automatic_targets.append(k) | |
if v.isa == 'PBXProject': | |
project = v | |
if len(automatic_targets) <= 0: # No need to modify anything. | |
return | |
target_attributes = {} | |
for target in automatic_targets: | |
target_attributes[target] = { | |
"DevelopmentTeam": team, | |
"ProvisioningStyle": 'Automatic' | |
} | |
project.attributes['TargetAttributes'] = target_attributes | |
for k, v in plist.objects.items(): | |
if v.isa == 'XCBuildConfiguration' and 'BAZEL_TARGET' in v.buildSettings: | |
v.buildSettings['CODE_SIGN_IDENTITY'] = 'Apple Development' | |
v.buildSettings['CODE_SIGN_STYLE'] = 'Automatic' | |
v.buildSettings['DEVELOPMENT_TEAM'] = team | |
v.buildSettings['PROVISIONING_PROFILE_SPECIFIER'] = '' | |
plistlib.writePlist(plist, plist_file) | |
def set_environment_variables(wsroot, bazel_target, xcscheme): | |
tree = ET.parse(xcscheme) | |
root = tree.getroot() | |
launch_action = root.find('LaunchAction') | |
env_vars = ET.Element(tag = 'EnvironmentVariables') | |
env_vars.append(ET.Element(tag = "EnvironmentVariable", attrib = { | |
"key": "SNAPSHOT_REFERENCE_DIR", | |
"value": wsroot, | |
"isEnabled": "YES" | |
})) | |
launch_action.append(env_vars) | |
tree.write(xcscheme) | |
def main(): | |
parser = argparse.ArgumentParser(description="Bazel + Tulsi") | |
parser.add_argument('target', nargs=1) | |
args = parser.parse_args() | |
args.target = args.target[0] | |
target = args.target.split(":") | |
if len(target) < 2: | |
print("WARNING: {} doesn't specify the target".format(args.target)) | |
exit() | |
path = target[0] | |
name = target[1] | |
wsroot = os.path.dirname(__file__) | |
if len(wsroot) == 0: | |
wsroot = "." | |
path = os.path.abspath(path) | |
wsroot = os.path.abspath(wsroot) | |
path = os.path.relpath(path, wsroot) | |
os.chdir(wsroot) | |
print("Focus {}:{} ...".format(path, name)) | |
bazelpath = subprocess.check_output(["which", "bazel"]).strip() | |
sourceDirs = "ios" | |
package_name = '' if path == '.' else path | |
bazel_target = package_name + ":" + name | |
tulsigen = ["./ios/Scripts/tulsi/generate_xcodeproj.sh", "--create-tulsiproj", name, "--target", bazel_target, "--bazel", bazelpath, "--outputfolder", path, "--workspaceroot", ".", "--additionalSourceFilters", sourceDirs, "--build-options", "--strategy=ObjcLink=standalone", "--no-open-xcode"] | |
subprocess.call(tulsigen) | |
genconfig = ["./ios/Scripts/tulsi/generate_xcodeproj.sh", "--genconfig", path + "/" + name + ".tulsiproj" + ":" + name, "--no-open-xcode"] | |
subprocess.call(genconfig) | |
plutil = ["plutil", "-convert", "xml1", path + "/" + name + ".xcodeproj/project.pbxproj"] | |
subprocess.call(plutil) | |
set_provisioning_to_automatic(TEAM, path + "/" + name + ".xcodeproj/project.pbxproj") | |
set_environment_variables(wsroot, bazel_target, path + "/" + name + ".xcodeproj/xcshareddata/xcschemes/" + name + ".xcscheme") | |
open_xcode = ["open", "-a", "Xcode", path + "/" + name + ".xcodeproj"] | |
subprocess.call(open_xcode) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment