• 主页
  • 系列总集
  • OpenCV
  • CMake
  • iOS
  • Java
  • 前端
所有文章 关于我

  • 主页
  • 系列总集
  • OpenCV
  • CMake
  • iOS
  • Java
  • 前端

Project自动执行一些shell脚本

2016-01-25

为什么需要脚本

有些时候,需要在编译完成时自动做一些工作,如果你会写shell脚本(就是命令行脚本),可以添加进某个Target让它自动执行.

哪里添加脚本

Project-Target-Build Phases-"+"-New Run Script Phases

凡是通用的shell命令行都可以用

脚本可以完成的常见工作

  1. 拷贝一些资源
  2. 检查一些选项

例如我在文章#使用Bundle打包图片配合静态库使用#中,假设静态库的Project和主工程在一个WorkSpace,不想每次更改Resource里的图片都手动重新拷贝到主工程里(不然主工程里还是旧的图片),就可以通过脚本完成.

进行Bundle拷贝脚本

脚本1 这个脚本在编译时有效,打包的时候发现拷贝不进去,造成IPA包中无Resource.bundle

cp -R -f $BUILT_PRODUCTS_DIR/Resource.bundle $APP_PRODUCT_CONTENTS_FOLDER_PATH

脚本2 这个脚本在打包时有效,但是在编译时会报错,因为BUILT_PRODUCTS_DIR是个快捷方式(链接),找不到实际对象

cp -R -f $BUILT_PRODUCTS_DIR/Resource.bundle $BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH/

脚本3 最终求助linux的大哥,搞了个函数,先获取Resource.bundle的实际路径,然后进行拷贝

function getRealPath()
{
    [[ `ls -lt $1 | head -1|awk '{print $10}'` == "->" ]] && realPath=`ls -lt $1 | head -1|awk '{print $11}'`|| realPath=$1
    echo "$1 the real directory is:$realPath"
}
getRealPath "$BUILT_PRODUCTS_DIR/Resource.bundle"
cp -R -f $realPath $BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH/

脚本四 后来读了读Pods脚本,发现Pods有更好的RealPath的脚本

realpath() {
  DIRECTORY="$(cd "${1%/*}" && pwd)"
  FILENAME="${1##*/}"
  echo "$DIRECTORY/$FILENAME"
}
ABSOLUTE_XCASSET_FILE=$(realpath "${PODS_ROOT}/$1")
赏

请问老板还招人么(/ω\)

支付宝
微信
  • iOS
  • Shell
  • IDE
  • Tips

扫一扫,分享到微信

微信分享二维码
通过CoreGraphics切小图
两个Category中函数名不要相同
© 2021 Alan Li
Hexo Theme Yilia by Litten
  • 所有文章
  • 关于我

tag:

  • iOS
  • Java
  • Collection
  • Python
  • Shell
  • CMake
  • Memory
  • JavaScript
  • Architecture
  • AnchorPoint
  • Android
  • Web
  • Annotation
  • AFNetworking
  • Window
  • ViewController
  • AutoLayout
  • Dozer
  • CoreAnimation
  • Cycle Retain
  • Block
  • UI
  • IDE
  • FrontEnd
  • CSS
  • Category
  • TableViewCell
  • Security
  • Net
  • JSP
  • Spring
  • C
  • MyBatis
  • Date
  • React
  • GCD
  • UITouch
  • Gesture
  • UIControl
  • Git
  • HTML
  • HTTPS
  • HTTP
  • Servlet
  • Server
  • DataBase
  • MySQL
  • Linux
  • Tutorial
  • Ajax
  • Type
  • JQuery
  • JSON
  • Exception
  • Parameter
  • Reflect
  • Thread
  • Sort
  • KVO
  • MKMapKit
  • Overlay
  • Maven
  • Configure
  • Tips
  • Transaction
  • Swift
  • NavigationBar
  • Nginx
  • Runtime
  • OpenCV
  • Property
  • Playground
  • Protocol
  • Redux
  • ScrollView
  • Session
  • Cookie
  • Shiro
  • Error
  • Singleton
  • RegEx
  • StackView
  • StatusBar
  • Base64
  • Socket
  • TCP
  • IP
  • TextField
  • CALayer
  • UILabel
  • View
  • Animation
  • Xcode
  • Hexo
  • Terminal
  • OC
  • Device
  • Log
  • Image
  • JUnit
  • Oval
  • Archive
  • XSS
  • Compiler
  • Aspect
  • Responder
  • Class
  • FireWall
  • RetainCount
  • Const
  • Frame
  • String
  • Symbols
  • Framework
  • CocoaPods
  • Unity
  • Message
  • Button
  • AuthorizationStatus
  • Struct
  • XCTest
  • NSNotification
  • Contact

    缺失模块。
    1、请确保node版本大于6.2
    2、在博客根目录(注意不是yilia根目录)执行以下命令:
    npm i hexo-generator-json-content --save

    3、在根目录_config.yml里添加配置:

      jsonContent:
        meta: false
        pages: false
        posts:
          title: true
          date: true
          path: true
          text: false
          raw: false
          content: false
          slug: false
          updated: false
          comments: false
          link: false
          permalink: false
          excerpt: false
          categories: false
          tags: true
    

我写的,大概率是错的。。。。。