Last active
September 26, 2020 21:51
-
-
Save floooh/692efeb3abe65ee0b7c8108ec0d6ac9f to your computer and use it in GitHub Desktop.
Fips generator example to copy files during build process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To invoke the generator from the cmake target you should define a helper macro in you project root's "fips-include.cmake" file: | |
macro(copy_files yml_file) | |
fips_generate(FROM ${yml_file} | |
TYPE filecopy | |
OUT_OF_SOURCE | |
ARGS "{ deploy_dir: \"${FIPS_PROJECT_DEPLOY_DIR}\" }") | |
endmacro() | |
In your cmake target definition you would then use this like: | |
fips_begin_app(bla windowed) | |
fips_src(.) | |
copy_files(files.yml) | |
fips_end_app() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
A generic file-copy asset job. | |
''' | |
Version = 1 | |
import genutil as util | |
import subprocess | |
import shutil | |
import yaml | |
import os | |
import platform | |
#------------------------------------------------------------------------------- | |
def copy_files(src_dir, dst_dir, yml): | |
for filename in yml['files']: | |
src = src_dir + filename | |
dst = dst_dir + filename | |
if not os.path.exists(os.path.dirname(dst)): | |
os.makedirs(os.path.dirname(dst)) | |
shutil.copyfile(src, dst) | |
#------------------------------------------------------------------------------- | |
def gen_header(out_hdr, yml): | |
with open(out_hdr, 'w') as f: | |
f.write('#pragma once\n') | |
f.write('//------------------------------------------------------------------------------\n') | |
f.write('// #version:{}#\n'.format(Version)) | |
f.write('// machine generated, do not edit!\n') | |
f.write('//------------------------------------------------------------------------------\n') | |
f.write('// JUST A DUMMY FILE, NOTHING TO SEE HERE\n') | |
#------------------------------------------------------------------------------- | |
def check_dirty(src_root_path, input, out_hdr, yml): | |
out_files = [out_hdr] | |
in_files = [input] | |
for filename in yml['files']: | |
in_files.append(os.path.abspath(src_root_path + filename)) | |
return util.isDirty(Version, in_files, out_files) | |
#------------------------------------------------------------------------------- | |
def generate(input, out_src, out_hdr, args): | |
with open(input, 'r') as f: | |
try: | |
yml = yaml.load(f) | |
except yaml.YAMLError, exc: | |
# show a proper error if YAML parsing fails | |
util.setErrorLocation(exc.problem_mark.name, exc.problem_mark.line-1) | |
util.fmtError('YAML error: {}'.format(exc.problem)) | |
src_root_path = os.path.dirname(input) + '/' | |
if 'root' in yml: | |
src_root_path += yml['root'] + '/' | |
deploy_dir = args['deploy_dir'] + '/' | |
if not os.path.exists(deploy_dir): | |
os.makedirs(deploy_dir) | |
if check_dirty(src_root_path, input, out_hdr, yml): | |
copy_files(src_root_path, deploy_dir, yml) | |
gen_header(out_hdr, yml) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is what a file list could look like, the source root directory points | |
# three level up from the location of the files.yml file to the project root directory, | |
# the files.yml file lives next to the project's CMakeLists.txt which contains the | |
# fips_generate() call (see here: http://floooh.github.io/fips/codegen.html) | |
--- | |
# set root directory to the project directory root | |
root: '../../..' | |
# copy the entire export directory content | |
# NOTE: create the file list with 'tree -fi' | |
files: [ | |
'export/anims/characters/dragon_brood_animations.nax3', | |
'export/anims/characters/dragon_brood_combat_idle_01.nac', | |
'export/anims/characters/dragon_brood_death.nac', | |
'export/anims/characters/dragon_brood_hit.nac', | |
'export/anims/characters/dragon_brood_hit_run.nac', | |
'export/anims/characters/dragon_brood_mount_animations.nax3', | |
'export/anims/characters/dragon_brood_mount_mount_idle_dragon_01.nac', | |
'export/anims/characters/dragon_brood_mount_mount_run_dragon_01.nac', | |
'export/anims/characters/dragon_brood_mount_variations.nax3', | |
'export/anims/characters/dragon_brood_run_01.nac', | |
'export/anims/characters/dragon_brood_skill_01.nac', | |
'export/anims/characters/dragon_brood_skill_02.nac', | |
'export/anims/characters/dragon_brood_spawn.nac', | |
'export/anims/characters/dragon_brood_stunned.nac', | |
'export/anims/characters/dragon_brood_variations.nax3', | |
'export/meshes/characters/dragon_brood/skins/body/body/dragon_brood_warrior_sk_0.nvx2', | |
'export/meshes/system/placeholder_s_0.nvx2', | |
'export/meshes/system/pointlightshape_s_0.nvx2', | |
'export/models/characters/dragon_brood.n3', | |
'export/models/system/placeholder.n3', | |
'export/textures/creatures/dragon_brood_01_bump.dds', | |
'export/textures/creatures/dragon_brood_01_color.dds', | |
'export/textures/creatures/dragon_brood_01_emsv.dds', | |
'export/textures/creatures/dragon_brood_01_spec.dds', | |
'export/textures/dummies/gray.dds', | |
'export/textures/environment/env_qube_reflect.dds', | |
'export/textures/system/black.dds', | |
'export/textures/system/nobump.dds', | |
'export/textures/system/placeholder.dds', | |
'export/textures/system/zeroalpha.dds', | |
'export/textures/ui/tahoma.dds', | |
'export/ui/tahoma_info.bytes' | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment