<commit_before>"""fips verb to build the oryol samples webpage"""

import os
import yaml 
import shutil
import subprocess
import glob
from string import Template

from mod import log, util, project, emscripten
from tools import texexport

BuildWasm = True
ExportAssets = True

#-------------------------------------------------------------------------------
def copy_build_files(fips_dir, proj_dir, webpage_dir) :
    # copy all files from the deploy dir to the webpage_dir
    ws_dir = util.get_workspace_dir(fips_dir)
    src_dir = '{}/fips-deploy/oryol/wasmasmjs-make-release'.format(ws_dir)
    dst_dir = webpage_dir
    if os.path.isdir(dst_dir) :
        shutil.rmtree(dst_dir)
    shutil.copytree(src_dir, dst_dir)
    shutil.copy('{}/web/wasmsuite-readme.md'.format(proj_dir), '{}/README.md'.format(dst_dir))
    shutil.copy('{}/LICENSE'.format(proj_dir), '{}/LICENSE'.format(dst_dir))

#-------------------------------------------------------------------------------
def export_assets(fips_dir, proj_dir, webpage_dir) :
    tex_srcdir = proj_dir + '/data'
    tex_dstdir = webpage_dir + '/data'
    texexport.configure(proj_dir, tex_srcdir, tex_dstdir)
    texexport.exportSampleTextures(['dds'])
    for dataFile in glob.glob(proj_dir + '/data/*.txt') :
        shutil.copy(dataFile, webpage_dir)
    tbui_from = '{}/data/tbui'.format(proj_dir)
    tbui_to   = '{}/data/tbui'.format(webpage_dir)
    shutil.copytree(tbui_from, tbui_to)

#-------------------------------------------------------------------------------
def build_deploy_webpage(fips_dir, proj_dir) :
    # if webpage dir exists, clear it first
    ws_dir = util.get_workspace_dir(fips_dir)
    webpage_dir = '{}/fips-deploy/oryol-wasm-buildsuite'.format(ws_dir)
    if os.path.isdir(webpage_dir) :
        shutil.rmtree(webpage_dir)
    os.makedirs(webpage_dir)

    config = 'wasmasmjs-make-release'
    project.clean(fips_dir, proj_dir, config) 
    project.gen(fips_dir, proj_dir, config)
    project.build(fips_dir, proj_dir, config)
    
    copy_build_files(fips_dir, proj_dir, webpage_dir)
    if ExportAssets :
        export_assets(fips_dir, proj_dir, webpage_dir)

    log.colored(log.GREEN, 'Done. ({})'.format(webpage_dir))

#-------------------------------------------------------------------------------
def serve_webpage(fips_dir, proj_dir) :<commit_msg>WebAssembly build-suite: only build a subset of all samples<commit_after>"""fips verb to build the oryol samples webpage"""

import os
import yaml 
import shutil
import subprocess
import glob
from string import Template

from mod import log, util, project, emscripten

BuildWasm = True
ExportAssets = True
Samples = [
    'InfiniteSpheres',
    'Paclone',
    'ImGuiDemo',
    'TurboBadgerDemo',
    'SoloudMOD',
]

#-------------------------------------------------------------------------------
def copy_build_files(fips_dir, proj_dir, webpage_dir) :
    # copy all files from the deploy dir to the webpage_dir
    ws_dir = util.get_workspace_dir(fips_dir)
    src_dir = '{}/fips-deploy/oryol/wasmasmjs-make-release'.format(ws_dir)
    dst_dir = webpage_dir
    if os.path.isdir(dst_dir) :
        shutil.rmtree(dst_dir)
    shutil.copytree(src_dir, dst_dir)
    shutil.copy('{}/web/wasmsuite-readme.md'.format(proj_dir), '{}/README.md'.format(dst_dir))
    shutil.copy('{}/LICENSE'.format(proj_dir), '{}/LICENSE'.format(dst_dir))

#-------------------------------------------------------------------------------
def export_assets(fips_dir, proj_dir, webpage_dir) :
    data_src_dir = '{}/data'.format(proj_dir)
    data_dst_dir = '{}/data'.format(webpage_dir)
    if not os.path.exists(data_dst_dir) :
        os.makedirs(data_dst_dir)
    for ext in ['txt', 'dump'] :
        for dataFile in glob.glob('{}/*.{}'.format(data_src_dir, ext)) :
            shutil.copy(dataFile, '{}/'.format(data_dst_dir))
    tbui_from = '{}/tbui'.format(data_src_dir)
    tbui_to   = '{}/tbui'.format(data_dst_dir)
    shutil.copytree(tbui_from, tbui_to)

#-------------------------------------------------------------------------------
def build_deploy_webpage(fips_dir, proj_dir) :
    # if webpage dir exists, clear it first
    ws_dir = util.get_workspace_dir(fips_dir)
    webpage_dir = '{}/fips-deploy/oryol-wasm-buildsuite'.format(ws_dir)
    if os.path.isdir(webpage_dir) :
        shutil.rmtree(webpage_dir)
    os.makedirs(webpage_dir)

    config = 'wasmasmjs-make-release'
    project.clean(fips_dir, proj_dir, config) 
    project.gen(fips_dir, proj_dir, config)
    for target in Samples :
        project.build(fips_dir, proj_dir, config, target)
    
    copy_build_files(fips_dir, proj_dir, webpage_dir)
    if ExportAssets :
        export_assets(fips_dir, proj_dir, webpage_dir)

    log.colored(log.GREEN, 'Done. ({})'.format(webpage_dir))

#-------------------------------------------------------------------------------
def serve_webpage(fips_dir, proj_dir) :
{'fraction_non_alphanumeric': 0.23864793321115862, 'fraction_numerical': 0.0, 'mean_word_length': 2.3234100135317997, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5863246', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1621, 'n_words': 290}