armory/blender/arm/make.py

918 lines
37 KiB
Python
Raw Normal View History

2021-06-24 15:03:30 +02:00
import errno
2017-01-18 14:52:51 +01:00
import glob
import json
import os
2021-06-24 15:03:30 +02:00
from queue import Queue
import shlex
import shutil
2017-10-21 16:09:06 +02:00
import stat
import subprocess
import threading
2021-06-24 15:03:30 +02:00
import time
from typing import Callable
import webbrowser
import bpy
2017-03-15 12:30:14 +01:00
import arm.assets as assets
from arm.exporter import ArmoryExporter
2017-03-15 12:30:14 +01:00
import arm.lib.make_datas
import arm.lib.server
import arm.live_patch as live_patch
import arm.log as log
import arm.make_logic as make_logic
import arm.make_renderpath as make_renderpath
import arm.make_state as state
import arm.make_world as make_world
import arm.utils
import arm.write_data as write_data
2016-10-19 13:28:06 +02:00
if arm.is_reload(__name__):
2021-08-04 22:49:38 +02:00
assets = arm.reload_module(assets)
arm.exporter = arm.reload_module(arm.exporter)
from arm.exporter import ArmoryExporter
arm.lib.make_datas = arm.reload_module(arm.lib.make_datas)
arm.lib.server = arm.reload_module(arm.lib.server)
live_patch = arm.reload_module(live_patch)
log = arm.reload_module(log)
make_logic = arm.reload_module(make_logic)
make_renderpath = arm.reload_module(make_renderpath)
state = arm.reload_module(state)
make_world = arm.reload_module(make_world)
arm.utils = arm.reload_module(arm.utils)
write_data = arm.reload_module(write_data)
else:
arm.enable_reload(__name__)
2021-08-04 22:49:38 +02:00
2017-01-18 14:52:51 +01:00
scripts_mtime = 0 # Monitor source changes
2017-12-19 11:02:55 +01:00
profile_time = 0
# Queue of threads and their done callbacks. Item format: [thread, done]
thread_callback_queue = Queue(maxsize=0)
def run_proc(cmd, done: Callable) -> subprocess.Popen:
"""Creates a subprocess with the given command and returns it.
If Blender is not running in background mode, a thread is spawned
that waits until the subprocess has finished executing to not freeze
the UI, otherwise (in background mode) execution is blocked until
the subprocess has finished.
If `done` is not `None`, it is called afterwards in the main thread.
"""
use_thread = not bpy.app.background
def wait_for_proc(proc: subprocess.Popen):
proc.wait()
if use_thread:
# Put the done callback into the callback queue so that it
# can be received by a polling function in the main thread
thread_callback_queue.put([threading.current_thread(), done], block=True)
else:
2018-06-19 23:21:53 +02:00
done()
2018-06-19 23:21:53 +02:00
p = subprocess.Popen(cmd)
if use_thread:
threading.Thread(target=wait_for_proc, args=(p,)).start()
else:
wait_for_proc(p)
2018-06-19 23:21:53 +02:00
return p
def compile_shader_pass(res, raw_shaders_path, shader_name, defs, make_variants):
2017-11-08 16:49:13 +01:00
os.chdir(raw_shaders_path + '/' + shader_name)
2016-10-17 00:02:51 +02:00
# Open json file
2016-12-13 01:09:17 +01:00
json_name = shader_name + '.json'
2016-10-25 16:15:07 +02:00
with open(json_name) as f:
json_file = f.read()
2016-10-17 00:02:51 +02:00
json_data = json.loads(json_file)
2017-05-23 01:03:44 +02:00
fp = arm.utils.get_fp_build()
arm.lib.make_datas.make(res, shader_name, json_data, fp, defs, make_variants)
2018-02-18 19:10:14 +01:00
path = fp + '/compiled/Shaders'
c = json_data['contexts'][0]
for s in ['vertex_shader', 'fragment_shader', 'geometry_shader', 'tesscontrol_shader', 'tesseval_shader']:
if s in c:
shutil.copy(c[s], path + '/' + c[s].split('/')[-1])
2017-10-21 16:07:08 +02:00
def remove_readonly(func, path, excinfo):
os.chmod(path, stat.S_IWRITE)
func(path)
2018-06-19 23:21:53 +02:00
def export_data(fp, sdk_path):
2016-12-10 14:26:02 +01:00
wrd = bpy.data.worlds['Arm']
2021-02-19 16:57:12 +01:00
print('Armory v{0} ({1})'.format(wrd.arm_version, wrd.arm_commit))
if wrd.arm_verbose_output:
print(f'Blender: {bpy.app.version_string}, Target: {state.target}, GAPI: {arm.utils.get_gapi()}')
2016-10-19 13:28:06 +02:00
2016-12-13 01:09:17 +01:00
# Clean compiled variants if cache is disabled
2017-12-13 14:21:42 +01:00
build_dir = arm.utils.get_fp_build()
if not wrd.arm_cache_build:
if os.path.isdir(build_dir + '/debug/html5-resources'):
shutil.rmtree(build_dir + '/debug/html5-resources', onerror=remove_readonly)
2017-11-13 16:36:58 +01:00
if os.path.isdir(build_dir + '/krom-resources'):
shutil.rmtree(build_dir + '/krom-resources', onerror=remove_readonly)
if os.path.isdir(build_dir + '/debug/krom-resources'):
shutil.rmtree(build_dir + '/debug/krom-resources', onerror=remove_readonly)
2017-11-13 16:36:58 +01:00
if os.path.isdir(build_dir + '/windows-resources'):
shutil.rmtree(build_dir + '/windows-resources', onerror=remove_readonly)
if os.path.isdir(build_dir + '/linux-resources'):
shutil.rmtree(build_dir + '/linux-resources', onerror=remove_readonly)
if os.path.isdir(build_dir + '/osx-resources'):
shutil.rmtree(build_dir + '/osx-resources', onerror=remove_readonly)
2017-05-23 01:03:44 +02:00
if os.path.isdir(build_dir + '/compiled/Shaders'):
2017-10-21 16:07:08 +02:00
shutil.rmtree(build_dir + '/compiled/Shaders', onerror=remove_readonly)
2016-12-13 01:09:17 +01:00
2018-08-16 23:07:50 +02:00
raw_shaders_path = sdk_path + '/armory/Shaders/'
assets_path = sdk_path + '/armory/Assets/'
2016-10-17 00:02:51 +02:00
export_physics = bpy.data.worlds['Arm'].arm_physics != 'Disabled'
2016-12-07 10:37:08 +01:00
export_navigation = bpy.data.worlds['Arm'].arm_navigation != 'Disabled'
2017-06-20 11:35:24 +02:00
export_ui = bpy.data.worlds['Arm'].arm_ui != 'Disabled'
assets.reset()
# Build node trees
2017-11-09 19:47:10 +01:00
ArmoryExporter.import_traits = []
2017-11-22 21:17:36 +01:00
make_logic.build()
2017-12-13 00:10:30 +01:00
make_world.build()
2017-11-22 21:17:36 +01:00
make_renderpath.build()
# Export scene data
2016-09-14 11:49:32 +02:00
assets.embedded_data = sorted(list(set(assets.embedded_data)))
2016-09-12 02:24:20 +02:00
physics_found = False
2016-12-07 10:37:08 +01:00
navigation_found = False
2017-06-20 11:35:24 +02:00
ui_found = False
2018-06-19 23:21:53 +02:00
ArmoryExporter.compress_enabled = state.is_publish and wrd.arm_asset_compression
2018-12-18 16:46:36 +01:00
ArmoryExporter.optimize_enabled = state.is_publish and wrd.arm_optimize_data
2019-05-24 15:21:22 +02:00
if not os.path.exists(build_dir + '/compiled/Assets'):
os.makedirs(build_dir + '/compiled/Assets')
# have a "zoo" collection in the current scene
export_coll = bpy.data.collections.new("export_coll")
bpy.context.scene.collection.children.link(export_coll)
for scene in bpy.data.scenes:
if scene == bpy.context.scene: continue
for o in scene.collection.all_objects:
if o.type == "MESH" or o.type == "EMPTY":
if o.name not in export_coll.all_objects.keys():
export_coll.objects.link(o)
depsgraph = bpy.context.evaluated_depsgraph_get()
bpy.data.collections.remove(export_coll) # destroy "zoo" collection
for scene in bpy.data.scenes:
2017-08-21 12:17:55 +02:00
if scene.arm_export:
2019-06-22 11:29:05 +02:00
ext = '.lz4' if ArmoryExporter.compress_enabled else '.arm'
2017-11-13 16:36:58 +01:00
asset_path = build_dir + '/compiled/Assets/' + arm.utils.safestr(scene.name) + ext
ArmoryExporter.export_scene(bpy.context, asset_path, scene=scene, depsgraph=depsgraph)
2017-06-20 11:35:24 +02:00
if ArmoryExporter.export_physics:
2016-09-12 02:24:20 +02:00
physics_found = True
2017-06-20 11:35:24 +02:00
if ArmoryExporter.export_navigation:
2016-12-07 10:37:08 +01:00
navigation_found = True
2017-06-20 11:35:24 +02:00
if ArmoryExporter.export_ui:
ui_found = True
assets.add(asset_path)
2017-06-20 11:35:24 +02:00
if physics_found == False: # Disable physics if no rigid body is exported
2016-09-12 02:24:20 +02:00
export_physics = False
2016-12-07 10:37:08 +01:00
if navigation_found == False:
export_navigation = False
2016-10-17 02:29:37 +02:00
2017-06-20 11:35:24 +02:00
if ui_found == False:
export_ui = False
if wrd.arm_ui == 'Enabled':
export_ui = True
2017-08-19 03:08:42 +02:00
modules = []
if wrd.arm_audio == 'Enabled':
modules.append('audio')
2017-08-19 03:08:42 +02:00
if export_physics:
modules.append('physics')
if export_navigation:
modules.append('navigation')
if export_ui:
modules.append('ui')
2017-11-20 14:32:36 +01:00
defs = arm.utils.def_strings_to_array(wrd.world_defs)
2018-02-18 19:10:14 +01:00
cdefs = arm.utils.def_strings_to_array(wrd.compo_defs)
if wrd.arm_verbose_output:
2021-02-19 16:57:12 +01:00
print('Exported modules:', ', '.join(modules))
2021-02-19 17:01:09 +01:00
print('Shader flags:', ' '.join(defs))
print('Compositor flags:', ' '.join(cdefs))
2021-02-19 16:57:12 +01:00
print('Khafile flags:', ' '.join(assets.khafile_defs))
2017-11-04 19:34:09 +01:00
# Render path is configurable at runtime
has_config = wrd.arm_write_config or os.path.exists(arm.utils.get_fp() + '/Bundled/config.arm')
# Write compiled.inc
2018-02-20 08:59:09 +01:00
shaders_path = build_dir + '/compiled/Shaders'
if not os.path.exists(shaders_path):
os.makedirs(shaders_path)
write_data.write_compiledglsl(defs + cdefs, make_variants=has_config)
2018-02-18 19:10:14 +01:00
2017-11-08 16:49:13 +01:00
# Write referenced shader passes
2017-12-13 14:21:42 +01:00
if not os.path.isfile(build_dir + '/compiled/Shaders/shader_datas.arm') or state.last_world_defs != wrd.world_defs:
2020-06-26 22:27:46 +02:00
res = {'shader_datas': []}
2017-12-13 14:21:42 +01:00
for ref in assets.shader_passes:
# Ensure shader pass source exists
if not os.path.exists(raw_shaders_path + '/' + ref):
2017-11-08 16:49:13 +01:00
continue
2017-12-20 15:37:58 +01:00
assets.shader_passes_assets[ref] = []
compile_shader_pass(res, raw_shaders_path, ref, defs + cdefs, make_variants=has_config)
2020-06-26 22:27:46 +02:00
# Workaround to also export non-material world shaders
res['shader_datas'] += make_world.shader_datas
2018-02-20 08:59:09 +01:00
arm.utils.write_arm(shaders_path + '/shader_datas.arm', res)
2020-06-26 22:27:46 +02:00
2017-12-20 15:37:58 +01:00
for ref in assets.shader_passes:
for s in assets.shader_passes_assets[ref]:
2018-02-20 08:59:09 +01:00
assets.add_shader(shaders_path + '/' + s + '.glsl')
2018-02-16 17:12:19 +01:00
for file in assets.shaders_external:
name = file.split('/')[-1].split('\\')[-1]
target = build_dir + '/compiled/Shaders/' + name
if not os.path.exists(target):
shutil.copy(file, target)
2017-11-08 16:49:13 +01:00
state.last_world_defs = wrd.world_defs
2016-10-17 02:29:37 +02:00
# Reset path
os.chdir(fp)
2016-10-17 02:29:37 +02:00
# Copy std shaders
2017-12-13 14:21:42 +01:00
if not os.path.isdir(build_dir + '/compiled/Shaders/std'):
shutil.copytree(raw_shaders_path + 'std', build_dir + '/compiled/Shaders/std')
2016-10-17 02:29:37 +02:00
2018-08-26 18:42:10 +02:00
# Write config.arm
resx, resy = arm.utils.get_render_resolution(arm.utils.get_active_scene())
if wrd.arm_write_config:
write_data.write_config(resx, resy)
2021-01-25 16:48:03 +01:00
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
# Change project version (Build, Publish)
if (not state.is_play) and (wrd.arm_project_version_autoinc):
wrd.arm_project_version = arm.utils.arm.utils.change_version_project(wrd.arm_project_version)
2018-08-26 18:42:10 +02:00
# Write khafile.js
2018-06-19 23:21:53 +02:00
enable_dce = state.is_publish and wrd.arm_dce
2021-07-24 18:21:06 +02:00
write_data.write_khafilejs(state.is_play, export_physics, export_navigation, export_ui, state.is_publish, enable_dce, ArmoryExporter.import_traits)
2016-11-07 23:06:08 +01:00
# Write Main.hx - depends on write_khafilejs for writing number of assets
2017-11-08 10:34:27 +01:00
scene_name = arm.utils.get_project_scene_name()
2019-02-10 11:47:42 +01:00
write_data.write_mainhx(scene_name, resx, resy, state.is_play, state.is_publish)
2017-11-08 10:34:27 +01:00
if scene_name != state.last_scene or resx != state.last_resx or resy != state.last_resy:
2017-05-28 20:22:07 +02:00
wrd.arm_recompile = True
2017-10-14 23:24:04 +02:00
state.last_resx = resx
state.last_resy = resy
2017-11-08 10:34:27 +01:00
state.last_scene = scene_name
2018-06-19 23:21:53 +02:00
def compile(assets_only=False):
2016-10-12 17:52:27 +02:00
wrd = bpy.data.worlds['Arm']
fp = arm.utils.get_fp()
os.chdir(fp)
# Set build command
2018-06-19 23:21:53 +02:00
target_name = state.target
2017-03-15 12:30:14 +01:00
node_path = arm.utils.get_node_path()
khamake_path = arm.utils.get_khamake_path()
2018-12-05 10:36:36 +01:00
cmd = [node_path, khamake_path]
2017-11-20 14:32:36 +01:00
kha_target_name = arm.utils.get_kha_target(target_name)
2018-12-05 10:36:36 +01:00
if kha_target_name != '':
cmd.append(kha_target_name)
# Custom exporter
if state.is_export:
item = wrd.arm_exporterlist[wrd.arm_exporterlist_index]
if item.arm_project_target == 'custom' and item.arm_project_khamake != '':
for s in item.arm_project_khamake.split(' '):
cmd.append(s)
2016-09-03 13:30:52 +02:00
2017-03-15 12:30:14 +01:00
ffmpeg_path = arm.utils.get_ffmpeg_path() # Path to binary
2016-09-23 00:34:42 +02:00
if ffmpeg_path != '':
cmd.append('--ffmpeg')
2017-02-15 16:55:46 +01:00
cmd.append(ffmpeg_path) # '"' + ffmpeg_path + '"'
2016-09-23 00:34:42 +02:00
state.export_gapi = arm.utils.get_gapi()
2018-03-22 17:30:10 +01:00
cmd.append('-g')
cmd.append(state.export_gapi)
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
# Windows - Set Visual Studio Version
if state.target.startswith('windows'):
cmd.append('-visualstudio')
vs_ver, vs_year, vs_name, vs_id = arm.utils.get_visual_studio_from_version(wrd.arm_project_win_list_vs)
cmd.append(vs_id)
2019-02-13 16:29:53 +01:00
if arm.utils.get_legacy_shaders() or 'ios' in state.target:
if 'html5' in state.target or 'ios' in state.target:
2019-02-10 20:37:38 +01:00
pass
else:
cmd.append('--shaderversion')
cmd.append('110')
2019-02-13 16:29:53 +01:00
elif 'android' in state.target or 'html5' in state.target:
cmd.append('--shaderversion')
cmd.append('300')
2018-05-24 22:16:28 +02:00
else:
2018-02-16 18:09:03 +01:00
cmd.append('--shaderversion')
cmd.append('330')
2018-01-04 10:22:17 +01:00
if '_VR' in wrd.world_defs:
cmd.append('--vr')
cmd.append('webvr')
if arm.utils.get_pref_or_default('khamake_debug', False):
cmd.append('--debug')
2018-11-19 13:18:40 +01:00
if arm.utils.get_rp().rp_renderer == 'Raytracer':
2018-07-29 11:39:54 +02:00
cmd.append('--raytrace')
cmd.append('dxr')
2019-02-19 10:09:42 +01:00
dxc_path = fp + '/HlslShaders/dxc.exe'
2019-04-14 22:41:55 +02:00
subprocess.Popen([dxc_path, '-Zpr', '-Fo', fp + '/Bundled/raytrace.cso', '-T', 'lib_6_3', fp + '/HlslShaders/raytrace.hlsl']).wait()
2018-07-29 11:39:54 +02:00
if arm.utils.get_khamake_threads() > 1:
cmd.append('--parallelAssetConversion')
cmd.append(str(arm.utils.get_khamake_threads()))
2019-01-31 12:14:52 +01:00
compilation_server = False
2017-05-23 01:03:44 +02:00
cmd.append('--to')
2019-02-10 11:47:42 +01:00
if (kha_target_name == 'krom' and not state.is_publish) or (kha_target_name == 'html5' and not state.is_publish):
cmd.append(arm.utils.build_dir() + '/debug')
2019-01-31 12:14:52 +01:00
# Start compilation server
if kha_target_name == 'krom' and arm.utils.get_compilation_server() and not assets_only and wrd.arm_cache_build:
2019-01-31 12:14:52 +01:00
compilation_server = True
arm.lib.server.run_haxe(arm.utils.get_haxe_path())
2017-05-23 01:03:44 +02:00
else:
cmd.append(arm.utils.build_dir())
2016-11-24 17:35:12 +01:00
if not wrd.arm_verbose_output:
cmd.append("--quiet")
else:
print("Using project from " + arm.utils.get_fp())
print("Running: ", *cmd)
#Project needs to be compiled at least once
#before compilation server can work
if not os.path.exists(arm.utils.build_dir() + '/debug/krom/krom.js') and not state.is_publish:
state.proc_build = run_proc(cmd, build_done)
else:
if assets_only or compilation_server:
cmd.append('--nohaxe')
cmd.append('--noproject')
state.proc_build = run_proc(cmd, assets_done if compilation_server else build_done)
2019-02-10 11:47:42 +01:00
def build(target, is_play=False, is_publish=False, is_export=False):
2017-12-19 11:02:55 +01:00
global profile_time
profile_time = time.time()
2018-06-19 23:21:53 +02:00
state.target = target
state.is_play = is_play
state.is_publish = is_publish
2018-06-19 23:21:53 +02:00
state.is_export = is_export
# Save blend
2018-12-18 23:48:38 +01:00
if arm.utils.get_save_on_build():
2017-02-22 16:14:55 +01:00
bpy.ops.wm.save_mainfile()
2021-03-21 01:26:05 +01:00
log.clear(clear_warnings=True, clear_errors=True)
2016-09-23 00:34:42 +02:00
2016-09-08 14:08:31 +02:00
# Set camera in active scene
2017-09-09 20:53:46 +02:00
active_scene = arm.utils.get_active_scene()
2016-09-08 14:08:31 +02:00
if active_scene.camera == None:
for o in active_scene.objects:
if o.type == 'CAMERA':
active_scene.camera = o
break
# Get paths
2017-03-15 12:30:14 +01:00
sdk_path = arm.utils.get_sdk_path()
2016-10-17 00:02:51 +02:00
raw_shaders_path = sdk_path + '/armory/Shaders/'
# Set dir
2017-03-15 12:30:14 +01:00
fp = arm.utils.get_fp()
os.chdir(fp)
# Create directories
2018-05-24 22:16:28 +02:00
wrd = bpy.data.worlds['Arm']
2017-05-13 17:17:43 +02:00
sources_path = 'Sources/' + arm.utils.safestr(wrd.arm_project_package)
2017-02-09 23:33:54 +01:00
if not os.path.exists(sources_path):
os.makedirs(sources_path)
# Save external scripts edited inside Blender
write_texts = False
for text in bpy.data.texts:
if text.filepath != '' and text.is_dirty:
write_texts = True
break
if write_texts:
area = bpy.context.area
old_type = area.type
area.type = 'TEXT_EDITOR'
for text in bpy.data.texts:
2017-01-10 22:57:22 +01:00
if text.filepath != '' and text.is_dirty and os.path.isfile(text.filepath):
area.spaces[0].text = text
bpy.ops.text.save()
area.type = old_type
# Save internal Haxe scripts
for text in bpy.data.texts:
if text.filepath == '' and text.name[-3:] == '.hx':
2017-05-13 17:17:43 +02:00
with open('Sources/' + arm.utils.safestr(wrd.arm_project_package) + '/' + text.name, 'w') as f:
f.write(text.as_string())
# Export data
2018-06-19 23:21:53 +02:00
export_data(fp, sdk_path)
2017-05-24 13:06:48 +02:00
if state.target == 'html5':
w, h = arm.utils.get_render_resolution(arm.utils.get_active_scene())
write_data.write_indexhtml(w, h, is_publish)
2017-05-24 13:06:48 +02:00
# Bundle files from include dir
if os.path.isdir('include'):
dest = '/html5/' if is_publish else '/debug/html5/'
2017-05-24 13:06:48 +02:00
for fn in glob.iglob(os.path.join('include', '**'), recursive=False):
shutil.copy(fn, arm.utils.build_dir() + dest + os.path.basename(fn))
2017-05-24 13:06:48 +02:00
2018-06-19 23:21:53 +02:00
def play_done():
"""Called if the player was stopped/terminated."""
2018-06-19 23:21:53 +02:00
state.proc_play = None
state.redraw_ui = True
2016-10-19 13:28:06 +02:00
log.clear()
live_patch.stop()
2019-01-31 12:14:52 +01:00
def assets_done():
if state.proc_build == None:
return
result = state.proc_build.poll()
if result == 0:
# Connect to the compilation server
os.chdir(arm.utils.build_dir() + '/debug/')
cmd = [arm.utils.get_haxe_path(), '--connect', '6000', 'project-krom.hxml']
state.proc_build = run_proc(cmd, compilation_server_done)
else:
state.proc_build = None
state.redraw_ui = True
2020-06-08 12:26:17 +02:00
log.error('Build failed, check console')
2019-01-31 12:14:52 +01:00
def compilation_server_done():
if state.proc_build == None:
return
result = state.proc_build.poll()
if result == 0:
if os.path.exists('krom/krom.js.temp'):
os.chmod('krom/krom.js', stat.S_IWRITE)
os.remove('krom/krom.js')
os.rename('krom/krom.js.temp', 'krom/krom.js')
build_done()
else:
state.proc_build = None
state.redraw_ui = True
2020-06-08 12:26:17 +02:00
log.error('Build failed, check console')
2019-01-31 12:14:52 +01:00
2018-06-19 23:21:53 +02:00
def build_done():
print('Finished in {:0.3f}s'.format(time.time() - profile_time))
if log.num_warnings > 0:
2021-01-25 16:47:51 +01:00
log.print_warn(f'{log.num_warnings} warning{"s" if log.num_warnings > 1 else ""} occurred during compilation')
if state.proc_build is None:
2016-10-15 12:17:33 +02:00
return
2018-06-19 23:21:53 +02:00
result = state.proc_build.poll()
state.proc_build = None
state.redraw_ui = True
if result == 0:
2017-01-18 14:52:51 +01:00
bpy.data.worlds['Arm'].arm_recompile = False
2018-06-19 23:21:53 +02:00
build_success()
else:
2020-06-08 12:26:17 +02:00
log.error('Build failed, check console')
2019-02-10 11:47:42 +01:00
def runtime_to_target():
2017-01-17 18:13:54 +01:00
wrd = bpy.data.worlds['Arm']
2019-02-10 11:47:42 +01:00
if wrd.arm_runtime == 'Krom':
2017-01-17 18:13:54 +01:00
return 'krom'
else:
return 'html5'
2019-02-10 11:47:42 +01:00
def get_khajs_path(target):
if target == 'krom':
return arm.utils.build_dir() + '/debug/krom/krom.js'
2017-05-26 16:05:14 +02:00
else: # Browser
return arm.utils.build_dir() + '/debug/html5/kha.js'
2017-01-18 14:52:51 +01:00
2019-02-10 11:47:42 +01:00
def play():
2017-01-18 14:52:51 +01:00
global scripts_mtime
2016-11-30 11:40:28 +01:00
wrd = bpy.data.worlds['Arm']
2019-02-10 11:47:42 +01:00
build(target=runtime_to_target(), is_play=True)
2019-02-10 11:47:42 +01:00
khajs_path = get_khajs_path(state.target)
2018-11-15 17:20:55 +01:00
if not wrd.arm_cache_build or \
2017-01-18 14:52:51 +01:00
not os.path.isfile(khajs_path) or \
2017-05-25 16:48:41 +02:00
assets.khafile_defs_last != assets.khafile_defs or \
2019-02-10 11:47:42 +01:00
state.last_target != state.target:
2017-01-18 14:52:51 +01:00
wrd.arm_recompile = True
state.last_target = state.target
2017-11-09 15:19:23 +01:00
2017-01-18 14:52:51 +01:00
# Trait sources modified
2017-07-02 20:48:19 +02:00
state.mod_scripts = []
2017-05-13 17:17:43 +02:00
script_path = arm.utils.get_fp() + '/Sources/' + arm.utils.safestr(wrd.arm_project_package)
2017-01-18 14:52:51 +01:00
if os.path.isdir(script_path):
2017-07-02 20:48:19 +02:00
new_mtime = scripts_mtime
2017-01-18 14:52:51 +01:00
for fn in glob.iglob(os.path.join(script_path, '**', '*.hx'), recursive=True):
mtime = os.path.getmtime(fn)
if scripts_mtime < mtime:
2017-07-24 02:27:22 +02:00
arm.utils.fetch_script_props(fn) # Trait props
2017-07-02 20:48:19 +02:00
fn = fn.split('Sources/')[1]
fn = fn[:-3] #.hx
fn = fn.replace('/', '.')
state.mod_scripts.append(fn)
2017-01-18 14:52:51 +01:00
wrd.arm_recompile = True
2017-07-02 20:48:19 +02:00
if new_mtime < mtime:
new_mtime = mtime
scripts_mtime = new_mtime
2017-07-24 02:27:22 +02:00
if len(state.mod_scripts) > 0: # Trait props
arm.utils.fetch_trait_props()
2017-01-18 14:52:51 +01:00
2018-06-19 23:21:53 +02:00
compile(assets_only=(not wrd.arm_recompile))
def build_success():
2016-10-19 13:28:06 +02:00
log.clear()
2017-01-30 12:02:40 +01:00
wrd = bpy.data.worlds['Arm']
2018-12-18 23:48:38 +01:00
if state.is_play:
2018-11-13 14:17:47 +01:00
if wrd.arm_runtime == 'Browser':
2016-09-12 02:24:20 +02:00
# Start server
2017-03-15 12:30:14 +01:00
os.chdir(arm.utils.get_fp())
2019-01-31 12:14:52 +01:00
t = threading.Thread(name='localserver', target=arm.lib.server.run_tcp)
2016-09-12 02:24:20 +02:00
t.daemon = True
t.start()
html5_app_path = 'http://localhost:8040/' + arm.utils.build_dir() + '/debug/html5'
2016-09-12 02:24:20 +02:00
webbrowser.open(html5_app_path)
2018-11-13 14:17:47 +01:00
elif wrd.arm_runtime == 'Krom':
2019-02-10 11:47:42 +01:00
if wrd.arm_live_patch:
live_patch.start()
2019-02-10 11:47:42 +01:00
open(arm.utils.get_fp_build() + '/debug/krom/krom.patch', 'w').close()
2019-07-15 09:21:23 +02:00
krom_location, krom_path = arm.utils.krom_paths()
2017-07-04 13:29:01 +02:00
os.chdir(krom_location)
2018-06-19 23:21:53 +02:00
cmd = [krom_path, arm.utils.get_fp_build() + '/debug/krom', arm.utils.get_fp_build() + '/debug/krom-resources']
2018-06-18 16:00:27 +02:00
if arm.utils.get_os() == 'win':
2018-06-19 23:21:53 +02:00
cmd.append('--consolepid')
cmd.append(str(os.getpid()))
2019-09-01 11:59:32 +02:00
if wrd.arm_audio == 'Disabled':
cmd.append('--nosound')
if wrd.arm_verbose_output:
print("Running: ", *cmd)
2018-06-19 23:21:53 +02:00
state.proc_play = run_proc(cmd, play_done)
2018-06-18 12:50:37 +02:00
2018-06-19 23:21:53 +02:00
elif state.is_publish:
2018-03-04 19:38:40 +01:00
sdk_path = arm.utils.get_sdk_path()
target_name = arm.utils.get_kha_target(state.target)
files_path = os.path.join(arm.utils.get_fp_build(), target_name)
2018-03-04 19:38:40 +01:00
if (target_name == 'html5' or target_name == 'krom') and wrd.arm_minify_js:
# Minify JS
minifier_path = sdk_path + '/lib/armory_tools/uglifyjs/bin/uglifyjs'
if target_name == 'html5':
jsfile = files_path + '/kha.js'
else:
jsfile = files_path + '/krom.js'
args = [arm.utils.get_node_path(), minifier_path, jsfile, '-o', jsfile]
proc = subprocess.Popen(args)
proc.wait()
if target_name == 'krom':
# Copy Krom binaries
if state.target == 'krom-windows':
2018-09-05 08:49:44 +02:00
gapi = state.export_gapi
2018-12-15 13:33:59 +01:00
ext = '' if gapi == 'direct3d11' else '_' + gapi
2018-09-05 08:49:44 +02:00
krom_location = sdk_path + '/Krom/Krom' + ext + '.exe'
shutil.copy(krom_location, files_path + '/Krom.exe')
2019-02-12 17:18:32 +01:00
krom_exe = arm.utils.safestr(wrd.arm_project_name) + '.exe'
os.rename(files_path + '/Krom.exe', files_path + '/' + krom_exe)
2018-03-04 19:38:40 +01:00
elif state.target == 'krom-linux':
2018-09-05 08:49:44 +02:00
krom_location = sdk_path + '/Krom/Krom'
shutil.copy(krom_location, files_path)
2019-02-12 17:18:32 +01:00
krom_exe = arm.utils.safestr(wrd.arm_project_name)
os.rename(files_path + '/Krom', files_path + '/' + krom_exe)
2019-02-13 12:23:02 +01:00
krom_exe = './' + krom_exe
2018-03-04 19:38:40 +01:00
else:
2018-09-05 08:49:44 +02:00
krom_location = sdk_path + '/Krom/Krom.app'
2018-03-04 19:38:40 +01:00
shutil.copytree(krom_location, files_path + '/Krom.app')
game_files = os.listdir(files_path)
for f in game_files:
f = files_path + '/' + f
if os.path.isfile(f):
shutil.move(f, files_path + '/Krom.app/Contents/MacOS')
2019-02-12 17:18:32 +01:00
krom_exe = arm.utils.safestr(wrd.arm_project_name) + '.app'
os.rename(files_path + '/Krom.app', files_path + '/' + krom_exe)
2018-03-04 19:38:40 +01:00
# Rename
ext = state.target.split('-')[-1] # krom-windows
new_files_path = files_path + '-' + ext
os.rename(files_path, new_files_path)
files_path = new_files_path
2018-03-04 19:38:40 +01:00
if target_name == 'html5':
project_path = files_path
print('Exported HTML5 package to ' + project_path)
2018-12-05 10:36:36 +01:00
elif target_name.startswith('ios') or target_name.startswith('osx'): # TODO: to macos
project_path = files_path + '-build'
print('Exported XCode project to ' + project_path)
2018-12-05 10:36:36 +01:00
elif target_name.startswith('windows'):
project_path = files_path + '-build'
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
vs_ver, vs_year, vs_name, vs_id = arm.utils.get_visual_studio_from_version(wrd.arm_project_win_list_vs)
print('Exported '+ vs_name +' project to ' + project_path)
2019-09-08 19:08:47 +02:00
elif target_name.startswith('android'):
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
project_name = arm.utils.safesrc(wrd.arm_project_name +'-'+ wrd.arm_project_version)
project_path = os.path.join(files_path + '-build', project_name)
print('Exported Android Studio project to ' + project_path)
2018-12-05 10:36:36 +01:00
elif target_name.startswith('krom'):
project_path = files_path
print('Exported Krom package to ' + project_path)
2018-03-04 19:38:40 +01:00
else:
project_path = files_path + '-build'
print('Exported makefiles to ' + project_path)
if not bpy.app.background and arm.utils.get_arm_preferences().open_build_directory:
arm.utils.open_folder(project_path)
# Android build APK
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
if target_name.startswith('android'):
if (arm.utils.get_project_android_build_apk()) and (len(arm.utils.get_android_sdk_root_path()) > 0):
print("\nBuilding APK")
# Check settings
path_sdk = arm.utils.get_android_sdk_root_path()
if len(path_sdk) > 0:
# Check Environment Variables - ANDROID_SDK_ROOT
if os.getenv('ANDROID_SDK_ROOT') == None:
# Set value from settings
os.environ['ANDROID_SDK_ROOT'] = path_sdk
else:
project_path = ''
# Build start
if len(project_path) > 0:
os.chdir(project_path) # set work folder
if arm.utils.get_os_is_windows():
state.proc_publish_build = run_proc(os.path.join(project_path, "gradlew.bat assembleDebug"), done_gradlew_build)
else:
cmd = shlex.split(os.path.join(project_path, "gradlew assembleDebug"))
state.proc_publish_build = run_proc(cmd, done_gradlew_build)
else:
print('\nBuilding APK Warning: ANDROID_SDK_ROOT is not specified in environment variables and "Android SDK Path" setting is not specified in preferences: \n- If you specify an environment variable ANDROID_SDK_ROOT, then you need to restart Blender;\n- If you specify the setting "Android SDK Path" in the preferences, then repeat operation "Publish"')
2021-01-25 16:48:03 +01:00
# HTML5 After Publish
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
if target_name.startswith('html5'):
if len(arm.utils.get_html5_copy_path()) > 0 and (wrd.arm_project_html5_copy):
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
project_name = arm.utils.safesrc(wrd.arm_project_name +'-'+ wrd.arm_project_version)
2021-01-25 16:48:03 +01:00
dst = os.path.join(arm.utils.get_html5_copy_path(), project_name)
if os.path.exists(dst):
shutil.rmtree(dst)
try:
shutil.copytree(project_path, dst)
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
print("Copied files to " + dst)
except OSError as exc:
if exc.errno == errno.ENOTDIR:
shutil.copy(project_path, dst)
else: raise
if len(arm.utils.get_link_web_server()) and (wrd.arm_project_html5_start_browser):
link_html5_app = arm.utils.get_link_web_server() +'/'+ project_name
print("Running a browser with a link " + link_html5_app)
webbrowser.open(link_html5_app)
2021-01-25 16:48:03 +01:00
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
# Windows After Publish
if target_name.startswith('windows'):
2021-01-25 16:48:03 +01:00
list_vs = []
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
err = ''
# Print message
project_name = arm.utils.safesrc(wrd.arm_project_name +'-'+ wrd.arm_project_version)
if int(wrd.arm_project_win_build) == 1:
print('\nOpen in Visual Studio ' + os.path.join(project_path, project_name + '.sln"'))
if int(wrd.arm_project_win_build) == 2:
print('\nCompile project ' + os.path.join(project_path, project_name + '.vcxproj'))
if int(wrd.arm_project_win_build) == 3:
print('\nCompile and run project ' + os.path.join(project_path, project_name + '.vcxproj'))
if int(wrd.arm_project_win_build) > 0:
# Check Visual Studio
list_vs, err = arm.utils.get_list_installed_vs(True, True, True)
if len(err) > 0:
print(err)
return
if len(list_vs) == 0:
print('No Visual Studio found')
return
is_check = False
for vs in list_vs:
if vs[0] == wrd.arm_project_win_list_vs:
is_check = True
break
if not is_check:
vs_ver, vs_year, vs_name, vs_id = arm.utils.get_visual_studio_from_version(wrd.arm_project_win_list_vs)
print(vs_name + ' not found.')
print('The following are installed on the PC:')
for vs in list_vs:
print('- ' + vs[1] + ' (version ' + vs[3] +')')
return
2021-01-25 16:48:03 +01:00
# Current VS
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
vs_path = ''
for vs in list_vs:
if vs[0] == wrd.arm_project_win_list_vs:
vs_path = vs[2]
break
2021-01-25 16:48:03 +01:00
# Open in Visual Studio
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
if int(wrd.arm_project_win_build) == 1:
cmd = os.path.join('start "' + vs_path, 'Common7', 'IDE', 'devenv.exe" "' + os.path.join(project_path, project_name + '.sln"'))
subprocess.Popen(cmd, shell=True)
# Compile
2021-01-25 16:48:03 +01:00
if int(wrd.arm_project_win_build) > 1:
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
bits = '64' if wrd.arm_project_win_build_arch == 'x64' else '32'
# vcvars
cmd = os.path.join(vs_path, 'VC', 'Auxiliary', 'Build', 'vcvars' + bits + '.bat')
if not os.path.isfile(cmd):
print('File "'+ cmd +'" not found. Verify ' + vs_name + ' was installed correctly')
log.error('Compile failed, check console')
return
state.proc_publish_build = run_proc(cmd, done_vs_vars)
def done_gradlew_build():
if state.proc_publish_build == None:
return
result = state.proc_publish_build.poll()
if result == 0:
state.proc_publish_build = None
wrd = bpy.data.worlds['Arm']
path_apk = os.path.join(arm.utils.get_fp_build(), arm.utils.get_kha_target(state.target))
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
project_name = arm.utils.safesrc(wrd.arm_project_name +'-'+ wrd.arm_project_version)
path_apk = os.path.join(path_apk + '-build', project_name, 'app', 'build', 'outputs', 'apk', 'debug')
print("\nBuild APK to " + path_apk)
# Rename APK
apk_name = 'app-debug.apk'
file_name = os.path.join(path_apk, apk_name)
if wrd.arm_project_android_rename_apk:
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
apk_name = project_name + '.apk'
os.rename(file_name, os.path.join(path_apk, apk_name))
file_name = os.path.join(path_apk, apk_name)
print("\nRename APK to " + apk_name)
# Copy APK
if wrd.arm_project_android_copy_apk:
shutil.copyfile(file_name, os.path.join(arm.utils.get_android_apk_copy_path(), apk_name))
print("Copy APK to " + arm.utils.get_android_apk_copy_path())
# Open directory with APK
if arm.utils.get_android_open_build_apk_directory():
arm.utils.open_folder(path_apk)
# Open directory after copy APK
if arm.utils.get_android_apk_copy_open_directory():
arm.utils.open_folder(arm.utils.get_android_apk_copy_path())
# Running emulator
if wrd.arm_project_android_run_avd:
run_android_emulators(arm.utils.get_android_emulator_name())
state.redraw_ui = True
else:
state.proc_publish_build = None
state.redraw_ui = True
os.environ['ANDROID_SDK_ROOT'] = ''
log.error('Building the APK failed, check console')
def run_android_emulators(avd_name):
if len(avd_name.strip()) == 0:
return
print('\nRunning Emulator "'+ avd_name +'"')
path_file = arm.utils.get_android_emulator_file()
if len(path_file) > 0:
if arm.utils.get_os_is_windows():
run_proc(path_file + " -avd "+ avd_name, None)
else:
cmd = shlex.split(path_file + " -avd "+ avd_name)
run_proc(cmd, None)
else:
print('Update List Emulators Warning: File "'+ path_file +'" not found. Check that the variable ANDROID_SDK_ROOT is correct in environment variables or in "Android SDK Path" setting: \n- If you specify an environment variable ANDROID_SDK_ROOT, then you need to restart Blender;\n- If you specify the setting "Android SDK Path", then repeat operation "Publish"')
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
def done_vs_vars():
if state.proc_publish_build == None:
return
result = state.proc_publish_build.poll()
if result == 0:
state.proc_publish_build = None
# MSBuild
wrd = bpy.data.worlds['Arm']
list_vs, err = arm.utils.get_list_installed_vs(True, True, True)
2021-01-25 16:48:03 +01:00
# Current VS
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
vs_path = ''
vs_name = ''
for vs in list_vs:
if vs[0] == wrd.arm_project_win_list_vs:
vs_name = vs[1]
vs_path = vs[2]
break
msbuild = os.path.join(vs_path, 'MSBuild', 'Current', 'Bin', 'MSBuild.exe')
if not os.path.isfile(msbuild):
print('File "'+ msbuild +'" not found. Verify ' + vs_name + ' was installed correctly')
log.error('Compile failed, check console')
state.redraw_ui = True
return
project_name = arm.utils.safesrc(wrd.arm_project_name +'-'+ wrd.arm_project_version)
project_path = os.path.join(arm.utils.get_fp_build(), arm.utils.get_kha_target(state.target)) + '-build'
cmd = '"' + msbuild + '" "' + os.path.join(project_path, project_name + '.vcxproj"')
# Arguments
platform = 'x64' if wrd.arm_project_win_build_arch == 'x64' else 'win32'
log_param = wrd.arm_project_win_build_log
if log_param == 'WarningsAndErrorsOnly':
log_param = 'WarningsOnly;ErrorsOnly'
cmd = cmd + ' -m:' + str(wrd.arm_project_win_build_cpu) + ' -clp:'+ log_param +' /p:Configuration='+ wrd.arm_project_win_build_mode +' /p:Platform=' + platform
print('\nCompiling the project ' + os.path.join(project_path, project_name + '.vcxproj"'))
state.proc_publish_build = run_proc(cmd, done_vs_build)
state.redraw_ui = True
else:
state.proc_publish_build = None
state.redraw_ui = True
log.error('\nCompile failed, check console')
def done_vs_build():
if state.proc_publish_build == None:
return
result = state.proc_publish_build.poll()
if result == 0:
state.proc_publish_build = None
wrd = bpy.data.worlds['Arm']
project_path = os.path.join(arm.utils.get_fp_build(), arm.utils.get_kha_target(state.target)) + '-build'
if wrd.arm_project_win_build_arch == 'x64':
path = os.path.join(project_path, 'x64', wrd.arm_project_win_build_mode)
else:
path = os.path.join(project_path, wrd.arm_project_win_build_mode)
print('\nCompilation completed in ' + path)
# Run
if int(wrd.arm_project_win_build) == 3:
# Copying the executable file
res_path = os.path.join(arm.utils.get_fp_build(), arm.utils.get_kha_target(state.target))
file_name = arm.utils.safesrc(wrd.arm_project_name +'-'+ wrd.arm_project_version) + '.exe'
print('\nCopy the executable file from ' + path + ' to ' + res_path)
shutil.copyfile(os.path.join(path, file_name), os.path.join(res_path, file_name))
path = res_path
# Run project
cmd = os.path.join('"' + res_path, file_name + '"')
print('Run the executable file to ' + cmd)
os.chdir(res_path) # set work folder
subprocess.Popen(cmd, shell=True)
# Open Build Directory
2021-01-25 16:48:03 +01:00
if wrd.arm_project_win_build_open:
Windows Settings – Publish and action after Windows Settings: Visual Studio Version - select the studio version for which the project will be exported. Options: 2010, 2012, 2013, 2015, 2017, 2019. Default: 2019. Update - checks the installed versions of Visual Studio on the PC and adds (installed) to the version in the list if available (for information). Example: sample_vs_2 Action After Publishing - select an action after a successful publication. Options: Nothing - do nothing. Default value; Open In Visual Studio - open the project in the corresponding studio version; Compile - compilation of the project; Compile and Run - compile and run the project. Then the executable file will be copied to the windows-hl folder (where the resources are located). Mode - compilation mode. Options: Debug, Release. Default: Debug. Architecture - the architecture for which the application will be built. Options: x86, x64. Default: version of the user’s PC architecture. Compile Log Parameter - setting the output of messages during compilation: Summary - show the error and warning summary at the end. Default value; No Summary - don \ 't show the error and warning summary at the end; Warnings and Errors Only - show only warnings and errors; Warnings Only - show only warnings; Errors Only - show only errors. More details can be found here - MSBuild command-line reference (I took only part of the settings). Count CPU - specifies the maximum number of concurrent processes to use when building. More details can be found here - MSBuild command-line reference. The default is 1. Maximum value: the number of CPUs in the system (function multiprocessing.cpu_count()). Open Build Directory - open the folder with the application after a successful build. If the Compile and Run option is selected, then the executable file will be copied to the windows-hl folder (where the resources are located) and this folder will open. Otherwise, the folder where the given Visual Studio file is going will open. The user will also receive a message if the studio version selected for export and for opening in the studio or compilation is not on the PC. And a list of installed ones will be issued. Example: Visual Studio 2017 (version 15) not found. The following are installed on the PC: - Visual Studio Community 2019 (version 16.8.30711.63) To obtain information about the installed versions of Visual Studio, use the vswhere.exe utility (open source) included in Kha (located in the …\ArmorySDK\Kha\Kinc\Tools\kincmake\Data\windows).
2020-11-24 18:41:50 +01:00
arm.utils.open_folder(path)
state.redraw_ui = True
else:
state.proc_publish_build = None
state.redraw_ui = True
log.error('Compile failed, check console')
2018-05-24 22:16:28 +02:00
def clean():
2017-03-15 12:30:14 +01:00
os.chdir(arm.utils.get_fp())
2016-09-23 00:34:42 +02:00
wrd = bpy.data.worlds['Arm']
# Remove build and compiled data
2018-12-04 19:02:22 +01:00
try:
if os.path.isdir(arm.utils.build_dir()):
shutil.rmtree(arm.utils.build_dir(), onerror=remove_readonly)
if os.path.isdir(arm.utils.get_fp() + '/build'): # Kode Studio build dir
shutil.rmtree(arm.utils.get_fp() + '/build', onerror=remove_readonly)
except:
print('Armory Warning: Some files in the build folder are locked')
# Remove compiled nodes
2018-04-22 21:52:22 +02:00
pkg_dir = arm.utils.safestr(wrd.arm_project_package).replace('.', '/')
nodes_path = 'Sources/' + pkg_dir + '/node/'
if os.path.isdir(nodes_path):
2017-10-21 16:07:08 +02:00
shutil.rmtree(nodes_path, onerror=remove_readonly)
2019-08-01 20:14:16 +02:00
# Remove khafile/Main.hx
if os.path.isfile('khafile.js'):
os.remove('khafile.js')
if os.path.isfile('Sources/Main.hx'):
os.remove('Sources/Main.hx')
2018-04-22 21:52:22 +02:00
# Remove Sources/ dir if empty
2018-04-25 17:42:07 +02:00
if os.path.exists('Sources/' + pkg_dir) and os.listdir('Sources/' + pkg_dir) == []:
2018-04-22 21:52:22 +02:00
shutil.rmtree('Sources/' + pkg_dir, onerror=remove_readonly)
2018-04-25 17:42:07 +02:00
if os.path.exists('Sources') and os.listdir('Sources') == []:
2018-04-22 21:52:22 +02:00
shutil.rmtree('Sources/', onerror=remove_readonly)
2021-11-02 15:56:46 +01:00
# Remove Shape key Textures
if os.path.exists('MorphTargets/'):
shutil.rmtree('MorphTargets/', onerror=remove_readonly)
2018-04-22 21:52:22 +02:00
2017-11-20 13:38:19 +01:00
# To recache signatures for batched materials
2017-03-14 20:43:54 +01:00
for mat in bpy.data.materials:
mat.signature = ''
2018-12-19 20:10:34 +01:00
mat.arm_cached = False
2017-03-14 20:43:54 +01:00
# Restart compilation server
if arm.utils.get_compilation_server():
arm.lib.server.kill_haxe()
print('Project cleaned')