def copy_assets(self, assets_dir): if not assets_dir.endswith('/'): assets_dir += '/' asset_files = {} for src in self.asset_files: dst = assets_dir if src.find('@/'): src, _, dst = src.partition('@/') if not dst.endswith('/') and dst != '': dst += '/' if os.path.isfile(src): dst += util.strip_dir(src) self.enum_asset_files(src, dst, asset_files) elif os.path.isdir(src): self.enum_asset_files(src, dst, asset_files) if not len(asset_files): return # remove dest assets dir if os.path.exists(assets_dir): rmtree(assets_dir) # create dest assets dir for src, dst in asset_files.items(): if dst.startswith(self.out_dir): os.makedirs(assets_dir) break # copy asset files self.copy_asset_files(asset_files)
def copy_binaries(self, bins_dir): if not bins_dir.endswith('/'): bins_dir += '/' for src in self.bin_files: bdir = bins_dir ext = util.split_ext(src) if ext != '': # dylibs for in Contents/MacOS dir... if ext == '.dylib': bdir = os.path.abspath(bdir + '/') # frameworks go in app Contents/Frameworks dir elif ext == '.framework': bdir = os.path.abspath(bdir + '../Frameworks/') dst = bdir + util.strip_dir(src) #FIXME: Hack for copying frameworks on macos! if self.target == 'macos': if util.split_ext(dst).lower() == '.framework': os.makedirs(util.split_dir(dst)) log.trace('copy_binairies: make dst dir...`%s`' % util.split_dir(dst)) if not subprocess.call('rm -f -R ' + dst): log.failed('copy_binaires: `rm`', 'failed') if not subprocess.call('cp -f -R ' + src + ' ' + dst): log.failed('copy_binaires: `cp`', 'failed') if not self.copy_all(src, dst): log.failed('copy_binaires: copy `%s` to `%s`' % (src, dst), 'failed')
def todo(msg, file=__file__): """print a todo message from file""" print('{}todo:{} in {}{}{}: {}'.format(CYAN, DEFAULT, YELLOW, util.strip_dir(file), DEFAULT, msg))
def __init__(self, flux_dir, proj_dir, build_opts, is_dep=False): '''load project file and prepare intermediate dirs''' # project yaml datas self.data = None # init vars self.imported = {} # project inputs self.src_files = [] self.lib_files = [] self.obj_files = [] self.bin_files = [] self.java_files = [] self.asset_files = [] self.ninja_files = [] # flux project self.flux_file = '' self.flux_srcs = [] self.flux_libs = [] # project build opts self.cc_opts = [] self.cxx_opts = [] self.ar_opts = [] self.as_opts = [] self.ld_opts = [] self.include_dirs = [] self.library_dirs = [] # load project file datas proj_dir = util.fix_path(proj_dir) proj_file = '' if os.path.isdir(proj_dir): #log.track('is_dir: '+util.strip_dir(proj_dir), __file__) proj_files = [ os.path.join(proj_dir, FILE), # flux.yml os.path.join(proj_dir, util.strip_dir(proj_dir) + '.yml'), # <dirname>.yml os.path.join(proj_dir, util.strip_dir(proj_dir) + '.flux'), # <dirname>.flux ] for file in proj_files: #log.track('proj_file: '+file, __file__) if os.path.isfile(file): proj_file = file self.data = util.load_flux_yaml(proj_file, build_opts) self.flux_file = proj_file break elif os.path.isfile(proj_dir): #log.track('is_file: '+file, __file__) proj_file = proj_dir proj_dir = util.split_dir(proj_dir) self.data = util.load_flux_yaml(proj_file, build_opts) self.flux_file = proj_file if not self.data: log.fatal('unable to find project file in `%s`' % proj_dir) # get project name in project file else name will be the name of last folder self.name = self.data['name'] if self.data.get( 'name') else util.strip_dir(proj_dir) # update build opts build_opts.build = self.data['build'] if self.data.get( 'build') else 'app' build_opts.apptype = self.data['type'] if self.data.get( 'type') else 'window' build_opts.build = build.remap(build_opts.build) build_opts.target = build.remap(build_opts.target) # keep build options for project self.build = build_opts.build self.apptype = build_opts.apptype if build_opts.build == 'app' else '' # only for app self.profile = build_opts.profile self.target = build_opts.target self.toolchain = build_opts.toolchain # set project directory structure if build_opts.outdir and not is_dep: self.proj_dir = proj_dir self.base_dir = util.fix_path(build_opts.outdir) self.build_dir = util.fix_path( os.path.join(self.base_dir, self.name)) self.out_dir = util.fix_path( os.path.join(self.build_dir, build_opts.profile)) self.cache_dir = util.fix_path( os.path.join(self.out_dir, CACHE_DIR)) self.asset_dir = util.fix_path( os.path.join(self.out_dir, ASSET_DIR)) else: self.proj_dir = proj_dir self.base_dir = util.fix_path(proj_dir) self.build_dir = util.fix_path(os.path.join(self.base_dir, FDIR)) self.out_dir = util.fix_path( os.path.join(self.build_dir, build_opts.profile)) self.cache_dir = util.fix_path( os.path.join(self.out_dir, CACHE_DIR)) self.asset_dir = util.fix_path( os.path.join(self.out_dir, ASSET_DIR)) # get output extension self.out_ext = build.EXT[build_opts.target][build_opts.build] if (self.target, self.build, self.apptype) == ('macos', 'app', 'console'): self.out_ext = '' # macos console app #if (self.target, self.build) == ('emscripten', 'mod'): # fix emscripten 2.0.17 # self.out_file = util.fix_path(os.path.join(self.out_dir, 'lib' + self.name + self.out_ext)) #else: # self.out_file = util.fix_path(os.path.join(self.out_dir, self.name + self.out_ext)) self.out_file = util.fix_path( os.path.join(self.out_dir, self.name + self.out_ext)) # set gen file self.gen_file = util.fix_path(os.path.join(self.out_dir, NINJA_FILE)) # get build options if 'options' in self.data: self.opts = self.data['options'] if self.data.get( 'options') else {} self.cc_opts.append(self.data['options']['cc'] if self. data['options'].get('cc') else '') self.cxx_opts.append(self.data['options']['cxx'] if self. data['options'].get('cxx') else '') self.as_opts.append(self.data['options']['as'] if self. data['options'].get('as') else '') self.ar_opts.append(self.data['options']['ar'] if self. data['options'].get('ar') else '') self.ld_opts.append(self.data['options']['ld'] if self. data['options'].get('ld') else '') # add build options for app if self.build in ['app', 'application']: # add workspace dir in header-dirs self.cc_opts.append('-I"%s"' % util.get_workspace_dir(flux_dir)) self.cxx_opts.append('-I"%s"' % util.get_workspace_dir(flux_dir)) # add project cache dir in header-dirs self.cc_opts.append('-I"%s"' % self.cache_dir) self.cxx_opts.append('-I"%s"' % self.cache_dir) # add project apptype if self.target == 'windows': #TODO: externalize this if self.toolchain == 'msvc': if self.apptype == 'window': self.ld_opts.append('-subsystem:windows') else: self.ld_opts.append('-subsystem:console') else: if self.apptype in ['window', 'gui']: self.ld_opts.append('-mwindows')