<commit_before>import subprocess
import Script.aceutils as aceutils

import os

def call( cmd , env=None):
    """ call command line.
    """

    print( cmd )
    p = subprocess.Popen(cmd, shell=True, env=env)
    ret = p.wait()
    if ret != 0:
        print("Failed {}".format(cmd))
        raise Exception

env = os.environ.copy()

env = os.environ.copy()
env["PKG_CONFIG_PATH"] = os.getenv('PKG_CONFIG_PATH', '/Library/Frameworks/Mono.framework/Versions/Current/lib/pkgconfig')
env["AS"] = os.getenv('AS', 'as -arch i386') 
env["CC"] = os.getenv('CC', 'clang -arch i386 -mmacosx-version-min=10.6')

env["MONO_SDK_PATH"] = os.getenv('MONO_SDK_PATH', '/Library/Frameworks/Mono.framework/Versions/Current')
env["PACKAGEING_FOR_MAC"] = os.getenv('PACKAGEING_FOR_MAC', '0')
env["IGNORE_BUILD"] = os.getenv('IGNORE_BUILD', '0')




if env['IGNORE_BUILD'] == '0':
    aceutils.mkdir('build')
    if aceutils.isWin():
        #import winreg
        #reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
        #key = winreg.OpenKey(reg, r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\12.0")
        #msbuild_path = winreg.QueryValueEx(key, 'MSBuildToolsPath')[0] + 'MSBuild.exe'

        candidates = [
        r"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe",
        r"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe",
        r"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe",
        ]

        candidate = None
        for candidate in candidates:
            if os.path.exists(candidate):
                msbuild_path = candidate
                break

        if candidate is None:
            raise Exception("MSBuild is not found")

    else:
        msbuild_path = 'msbuild'

    with aceutils.CurrentDir('build'):
        # for auto restore of .csproj 
        aceutils.wget(r'https://dist.nuget.org/win-x86-commandline/v5.1.0/nuget.exe')

        if aceutils.isWin():
            aceutils.call('cmake .. -A x64 -DBUILD_VIEWER=ON')
        elif aceutils.isMac():
            aceutils.call('cmake .. -G "Xcode" -DBUILD_VIEWER=ON')
        else:
            aceutils.call('cmake .. -G "Unix Makefiles" -DBUILD_VIEWER=ON')
        aceutils.call('cmake --build . --config Release')

    if aceutils.isWin():
        aceutils.call('build\\nuget.exe restore Dev/Editor/Effekseer.sln')
    else:
        aceutils.call('mono ./build/nuget.exe restore Dev/Editor/Effekseer.sln')

    call('"' + msbuild_path + '"' + ' Dev/Editor/EffekseerCore/EffekseerCore.csproj /t:build /p:Configuration=Release /p:Platform=x64')
    call('"' + msbuild_path + '"' + ' Dev/Editor/Effekseer/Effekseer.csproj /t:build /p:Configuration=Release /p:Platform=x64')

if env['PACKAGEING_FOR_MAC'] == '1':

    if aceutils.isMac():
        aceutils.cd('Dev')

        aceutils.mkdir('Mac/Effekseer.app/Contents/Resources/')
        aceutils.call('cd release;mkbundle -o Effekseer Effekseer.exe --deps --sdk $MONO_SDK_PATH;otool -L Effekseer', env=env)
        aceutils.call('cd release;mkbundle -o tools/mqoToEffekseerModelConverter tools/mqoToEffekseerModelConverter.exe --deps --sdk $MONO_SDK_PATH;otool -L tools/mqoToEffekseerModelConverter;', env=env)

        aceutils.copy('release/Effekseer', 'Mac/Effekseer.app/Contents/Resources/')
        aceutils.copy('release/Effekseer.exe', 'Mac/Effekseer.app/Contents/Resources/')
        aceutils.copy('release/libViewer.dylib', 'Mac/Effekseer.app/Contents/Resources/')
        aceutils.copy('release/EffekseerCore.dll', 'Mac/Effekseer.app/Contents/Resources/')
        
        aceutils.copytree('release/resources', 'Mac/Effekseer.app/Contents/Resources/resources')
        aceutils.copytree('release/scripts', 'Mac/Effekseer.app/Contents/Resources/scripts')
        
        aceutils.mkdir('Mac/Effekseer.app/Contents/Resources/tools')

        aceutils.copy('release/tools/mqoToEffekseerModelConverter', 'Mac/Effekseer.app/Contents/Resources/tools')
        aceutils.rmdir('fbxToEffekseerModelConverterMac')
        aceutils.rmdir('__MACOSX')
        aceutils.wget('https://github.com/effekseer/Effekseer/releases/download/Prebuild/fbxToEffekseerModelConverterMac.zip')
        aceutils.unzip('fbxToEffekseerModelConverterMac.zip')

        aceutils.copy('fbxToEffekseerModelConverterMac/fbxToEffekseerModelConverter', 'Mac/Effekseer.app/Contents/Resources/tools/')
        aceutils.copy('fbxToEffekseerModelConverterMac/libfbxsdk.dylib', 'Mac/Effekseer.app/Contents/Resources/tools/')
        aceutils.call('chmod +x Mac/Effekseer.app/Contents/MacOS/script.sh')<commit_msg>Update build script<commit_after>import subprocess
import Script.aceutils as aceutils

import os

def call( cmd , env=None):
    """ call command line.
    """

    print( cmd )
    p = subprocess.Popen(cmd, shell=True, env=env)
    ret = p.wait()
    if ret != 0:
        print("Failed {}".format(cmd))
        raise Exception

env = os.environ.copy()

env = os.environ.copy()
env["PKG_CONFIG_PATH"] = os.getenv('PKG_CONFIG_PATH', '/Library/Frameworks/Mono.framework/Versions/Current/lib/pkgconfig')
env["AS"] = os.getenv('AS', 'as -arch i386') 
env["CC"] = os.getenv('CC', 'clang -arch i386 -mmacosx-version-min=10.6')

env["MONO_SDK_PATH"] = os.getenv('MONO_SDK_PATH', '/Library/Frameworks/Mono.framework/Versions/Current')
env["PACKAGEING_FOR_MAC"] = os.getenv('PACKAGEING_FOR_MAC', '0')
env["IGNORE_BUILD"] = os.getenv('IGNORE_BUILD', '0')




if env['IGNORE_BUILD'] == '0':
    aceutils.mkdir('build')
    if aceutils.isWin():
        #import winreg
        #reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
        #key = winreg.OpenKey(reg, r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\12.0")
        #msbuild_path = winreg.QueryValueEx(key, 'MSBuildToolsPath')[0] + 'MSBuild.exe'

        candidates = [
        r"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe",
        r"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe",
        r"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe",
        ]

        candidate = None
        for candidate in candidates:
            if os.path.exists(candidate):
                msbuild_path = candidate
                break

        if candidate is None:
            raise Exception("MSBuild is not found")

    else:
        msbuild_path = 'msbuild'

    with aceutils.CurrentDir('build'):
        # for auto restore of .csproj 
        aceutils.wget(r'https://dist.nuget.org/win-x86-commandline/v5.1.0/nuget.exe')

        if aceutils.isWin():
            aceutils.call('cmake .. -A x64 -DBUILD_VIEWER=ON')
        elif aceutils.isMac():
            aceutils.call('cmake .. -G "Xcode" -DBUILD_VIEWER=ON')
        else:
            aceutils.call('cmake .. -G "Unix Makefiles" -DBUILD_VIEWER=ON')
        aceutils.call('cmake --build . --config Release')

    if aceutils.isWin():
        aceutils.call('build\\nuget.exe restore Dev/Editor/Effekseer.sln')
    else:
        aceutils.call('mono ./build/nuget.exe restore Dev/Editor/Effekseer.sln')

    call('"' + msbuild_path + '"' + ' Dev/Editor/EffekseerCore/EffekseerCore.csproj /t:build /p:Configuration=Release /p:Platform=x64')
    call('"' + msbuild_path + '"' + ' Dev/Editor/Effekseer/Effekseer.csproj /t:build /p:Configuration=Release /p:Platform=x64')

if env['PACKAGEING_FOR_MAC'] == '1':

    if aceutils.isMac():
        aceutils.cd('Dev')
        aceutils.call('cd release;mkbundle -o Effekseer Effekseer.exe --deps --sdk $MONO_SDK_PATH;otool -L Effekseer', env=env)
        aceutils.mkdir('Mac/Effekseer.app/Contents/Resources/')
        aceutils.copy('release/Effekseer', 'Mac/Effekseer.app/Contents/Resources/')
        aceutils.copy('release/Effekseer.exe', 'Mac/Effekseer.app/Contents/Resources/')
        aceutils.copy('release/libViewer.dylib', 'Mac/Effekseer.app/Contents/Resources/')
        aceutils.copy('release/EffekseerCore.dll', 'Mac/Effekseer.app/Contents/Resources/')
        aceutils.copy('release/EffekseerMaterialEditor', 'Mac/Effekseer.app/Contents/Resources/')
        
        aceutils.copytree('release/resources', 'Mac/Effekseer.app/Contents/Resources/resources')
        aceutils.copytree('release/scripts', 'Mac/Effekseer.app/Contents/Resources/scripts')
        aceutils.copytree('release/tools', 'Mac/Effekseer.app/Contents/Resources/tools')
        
        aceutils.call('chmod +x Mac/Effekseer.app/Contents/MacOS/script.sh')
{'fraction_non_alphanumeric': 0.14973699590882525, 'fraction_numerical': 0.01239041496201052, 'mean_word_length': 3.2524850894632205, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1802198', 'n_tokens_mistral': 3134, 'n_tokens_neox': 2998, 'n_words': 425}