Xcode prerequisites run python script environment variables without setting $ {PROJECT_DIR} correctly

I'm trying to run a python script from Xcode in a Pre-actions build:

screenshot

#! /usr/bin/env python
import shutil
import os

app_name = 'name'

def skinfunction(root_src_dir, root_dst_dir):
    for src_dir, dirs, files in os.walk(root_src_dir):
        print(str(files))
        dst_dir = src_dir.replace(root_src_dir, root_dst_dir)
        if not os.path.exists(dst_dir):
            os.mkdir(dst_dir)
        for file_ in files:
            src_file = os.path.join(src_dir, file_)
            dst_file = os.path.join(dst_dir, file_)
            if os.path.exists(dst_file):
                os.remove(dst_file)
            shutil.copy(src_file, dst_dir)
root_src_dir = '${PROJECT_DIR}/skins/'+str(app_name)+'/authorize_bg.imageset'
root_dst_dir = '${PROJECT_DIR}/iDetail/Images.xcassets/authorize_bg.imageset'
skinfunction(root_src_dir,root_dst_dir);

      

Near the end of the script I am trying to get Xcode's PROJECT_DIR environment variable, but it just doesn't work as expected. Either the value is invalid or my formatting is off.

If I hard-code the PROJECT_DIR value (full url where the project is located) and the script runs successfully.

I am missing something while trying to get an environment variable.

+3


source to share


1 answer


Ok, I got it, instead of trying to get the environment variable directly using $ {PROJECT_DIR}, you need to call the os.getenv () function. I managed to get the environment variable by calling:



proj_dir = os.getenv('PROJECT_DIR')

      

+2


source







All Articles