본문 바로가기

프로그래밍/iOS,macOS

iOS 프레임워크 파이썬 스크립트

import sys
import os
import subprocess
import plistlib
import argparse

 

def __init__(self, option):
  self.output_paths = []
  self.framework = ""
  self.version = ""
  self.podspec_path = ""
  self.repository_path = ""
  self.target = ""
  self.option = option

 

Derived Path

HOME_PATH = os.path.expanduser("~")
PROJECT_NAME="Test"
PROJECT_PATH=HOME_PATH+"/Project/"+PROJECT_NAME
DERIVED_PATH=PROJECT_PATH+"/Build"

FRAMEWORK_PATH=DERIVED_PATH+"/project/Build/Products/Release-iphoneos"

CONFIGURATION="Release"

REPOSITORY_PATH=""
POPSPEC_PATH=""

 

초기화 및 기본 내용 체크

def checkXCodeVersion(self):
  print(subprocess.check_output("xcode-select -p", shell=True))
  key = input("빌드에 사용할 xcode 버전이 맞습니까?(Y/n) : ")
  if key == "" or key == 'Y' or key == 'y':
  	return 0
  return -1

 

빌드 및 FatFramework 

def makeFatFramework(self):
  support_platforms=["iphoneos","iphonesimulator"]

  # 각 플랫폼 빌드
  for platform in supported_platforms:
    self.output_paths.append( self.DERIVED_PATH+"/"+self.CONFIGURATION+"-"+platform)
    args = ["xcodebuild",
      "-project",self.PROJECT_NAME+".xcodeproj",\
      "-target",self.PROJECT_NAME,\
      "-configuration",self.CONFIGURATION,\
      "-sdk",platform,\
      "ENABLE_BITCODE=NO",\
      "ONLY_ACTIVE_ARCH=NO"]

    result = subprocess.call(args)
    if result != 0:
      print("error")
      returnn 1

  # FatFramework
  lipo=["lipo","-create","-ouput",self.PROJECT_NAME]
  for path in self.output_paths:
  	lipo.append(path+"/"+self.PROJET_NAME+".framework/"+self.PROJECT_NAME)

  self.framework = self.output_path[0]+"/"+self.PROJECT_NAME+".framework"
  result = subprocess.call(lipo)
  
  if result == 0:
    subprocess.call([
      "mv",\
      "-f",\
      self.PROJECT_NAME,self.output_paths[0]+"/"+self.PROJECT_NAME+".framework/."])
    target = self.framework+"/Modules/"+self.PROJECT_NAME+".swiftmodule/."

    for i in range( len(self.output_paths) -1, 0, -1):
      item=self.output_paths[i]+"/"+self.PROJECT_NAME+".framework/Module/"+self.PROEJCT_NAME+".swiftmodule/."
      subprocess.call(["cp", "-rf", item, target])

    return 0

 

버전체크

 

def checkVersion(self):
  if self.option == "dist":
    self.target = "dist"
    self.podspec_path = "podspec_path"
    self.repository_path = "repository_path"
  elif self.option == "test":
    self.target = "dist"
    self.podspec_path = "podspec_path"
    self.repository_path = "repository_path"

  if len(self.output_paths) == 0:
    print("error:output path")
    return -1

  if os.path.isdir(self.output_paths[0]) == False:
    print("error:output path")
    return -2

  if os.path.isdir(self.framework) == False:
    print("error:framework")
    return -3

  if os.path.isdir(self.podspec_path) == False:
    print("error:podspec")
    return -4

  self.version = "v"
  with open(self.framework+"/Info.plist", "rb") as fp:
  pl = plistlib.load(fp)
  self.version+=pl["CFBundleShortVersionString"]


  print("Framework 버전: "+self.version)
  key = input("배포할 버전이 맞습니까?(Y/n) : ")
  if key == '' or key == 'Y' or key == 'y':
  	return 0

  return -5

 

저장소검사

def checkRepository(self):
  branch_name = subprocess.check_output(["git",\
                                        "-C",\
                                        self.repository_path,\
                                        "rev-parse",\
                                        "--abbrev-ref",\
                                        "HEAD"]).strip().decode('utf-8')
  if branch_name != "master":
  	print("not master branch")
    return -1

  count = int(subprocess.check_output(
  "git -C "+self.repository_path+" show-ref -s "+self.version+" | wc -l", shell=True).decode("ascii"))
  if count > 0:
    print("exist tag")
    return -2

  count = int(subprocess.check_output(
  "git -C "+self.repository_path+" status --porcelain | wc -l", shell=True).decode("ascii"))

  if count > 0:
    print(subprocess.check_output("git -C "+self.repository+path+" status",shell=True).decode("utf-8"))
    return -3

  return 0

 

커밋

def commitRepository(self):
  key = input("Git 저장소에 배포하시겠습니까?(y/N) : ")
  if key == '' or key == 'N' or key == 'n':
  	return -9


  # 프레임워크 복사
  subprocess.call(["cp", "-rf", self.framework, self.repository_path])

  # add
  result = subprocess.check_call("git -C "+self.repository_path+" add .", shell=True)
  if result != 0:
    print("[Error] failed to add")
    return -4

  # 커밋
  result = subprocess.check_call("git -C "+self.repository_path+" commit -m 'chore(release): RemoteMonster SDK "+self.version+"'", shell=True)
  if result != 0:
    print("[Error] failed to commit")
    return -5

  # 태깅
  result = subprocess.check_call("git -C "+self.repository_path+" tag "+self.version, shell=True)
  if result != 0:
    print("[Error] failed to tag")
    return -6

  # push
  result = subprocess.check_call("git -C "+self.repository_path+" push origin master -f --tags", shell=True)
  if result != 0:
    print("[Error] failed to push")
    return -7

  return 0

 

코코아팟

def cocoapods(self):
  spec_file = self.podspec_path+"/"+self.PROJECT_NAME+".podspec"

  # podspec 편집
  subprocess.check_call("open "+spec_file, shell=True)

  if self.target == "dist":
    # spec lint
    print("pod spec lint "+spec_file+" --verbose")

    # push
    print("pod trunk push "+spec_file+" --allow-warnings --verbose")
  elif self.target == "test":
    # 비공개 테스트 저장소(remon)의 경우
    print("pod spec lint "+spec_file+" --verbose --sources='https://github.com/RemoteMonster/remon-ios-pod-specs.git")
    print("pod repo push remon "+spec_file+" --allow-warnings --verbose")

  return

 

 

parser = argparse.ArgumentParser()
parser.add_argument('-t',nargs='+',help='python3 ./dist.py -t [test|dist]',default=['dist'],dest='target')
option = parser.parse_args().target[0]

test = TestDistribution(option)
result = test.checkXCodeVersion()
if( result != 0 ):
   sys.exit(1)

result = test.makeFatFramework()
if( result != 0 ):
   sys.exit(1)

result = test.checkVersion()
if result != 0:
   sys.exit(2)

result = test.checkRepository()
if result != 0:
   sys.exit(3)

result = test.commitRepository()
if result != 0:
    sys.exit(4)
test.cocoapods()

'프로그래밍 > iOS,macOS' 카테고리의 다른 글

[iOS] 키보드를 따라 올라오는 뷰  (0) 2020.04.08
[iOS] Google SignIn  (0) 2020.03.30
xcode 11. ios13 미만, storyboard 없이 시작  (0) 2020.03.29
XCFramework 만들기  (0) 2020.03.27
[iOS] CoreAudio AudioUnit  (0) 2019.10.08
[iOS] GPUImage  (0) 2019.07.06
xcodebuild  (0) 2019.06.06
CocoaPods 라이브러리 배포  (0) 2019.05.31
[Metal] Compute Function 샘플분석  (0) 2019.05.27
[Metal] MetalKit 플로우 분석  (0) 2019.05.27