#!/usr/bin/env python import fcntl import os import pickle from subprocess import Popen import sys from .pipsgcc import getDirectory, _CCWorkspace, ArObject if len(sys.argv) == 1: sp = Popen(CC) # todo: undefined var CC exitcode = sp.wait() sys.exit(0) AR = os.getenv('PIPS_AR', 'ar') # Call AR cmd = [AR] + sys.argv[1:] # print("\033[91mCalling " + " ".join(cmd) + "\033[00m") sp = Popen(cmd) exitcode = sp.wait() obj = ArObject(sys.argv[1:]) # Load workspace workspace = None wsfile = None try: wsfile = open(os.path.join(getDirectory(), 'workspace'), 'r+') fcntl.flock(wsfile, fcntl.LOCK_EX) except IOError: workspace = _CCWorkspace() if wsfile is not None: workspace = pickle.load(wsfile) else: wsfile = open(os.path.join(getDirectory(), 'workspace'), 'w') fcntl.flock(wsfile, fcntl.LOCK_EX) # Add the new object to the workspace workspace.addObject(obj) # Save the new workspace wsfile.seek(0) pickle.dump(workspace, wsfile) sys.exit(exitcode)