Skip to content

Commit

Permalink
Generate UMB output into build directory
Browse files Browse the repository at this point in the history
  • Loading branch information
tuokri committed Jan 11, 2024
1 parent df540c2 commit daa7796
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cmake-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ jobs:
with:
name: umb-generated-cpp-${{ matrix.os }}-${{ matrix.build_type }}
path: |
tests/out/*.umb.cpp
tests/out/*.umb.hpp
build/generated/*.umb.cpp
build/generated/*.umb.hpp
- name: Archive UMB generated UnrealScript files
uses: actions/upload-artifact@v3
with:
name: umb-generated-uscript-${{ matrix.os }}-${{ matrix.build_type }}
path: |
tests/out/*.uc
build/generated/*.uc
- name: Archive UMB build artifacts
uses: actions/upload-artifact@v3
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/udk-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on: [ workflow_call ]
env:
UDK_LITE_CACHE: ${{ github.workspace }}/tests/UDKTests/.cache/
UDK_LITE_TAG: 1.0.1
UDK_USCRIPT_MESSAGE_FILES: build/generated/*.uc
# Timeout for individual steps in the test script. Not a total timeout.
UDK_TEST_TIMEOUT: 300
PYTHONUNBUFFERED: 1
Expand Down Expand Up @@ -42,7 +43,7 @@ jobs:
uses: actions/download-artifact@v3
with:
name: umb-generated-uscript-windows-latest-${{ matrix.build_type }}
path: tests/out/
path: build/generated/

- name: Download UMB executables
uses: actions/download-artifact@v3
Expand Down
34 changes: 34 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,15 @@ void render_uscript(inja::Environment& env, const std::string& file, const inja:
fs::path out_file = fs::path{uscript_out_dir} / out_filename;
std::cout << std::format("writing '{}'\n", out_file.string());
fs::ofstream out{out_file};
if (!out)
{
throw std::runtime_error(std::format("failed to open '{}' for writing", out_file.string()));
}
out << r;
if (out.fail())
{
throw std::runtime_error(std::format("failed to write '{}'", out_file.string()));
}
}

// TODO: add option for passing in custom .clang-format file.
Expand All @@ -539,6 +547,7 @@ void clang_format(const std::vector<fs::path>& paths)
const auto& pstr = path.string();
std::cout << std::format("running clang-format on '{}'\n", pstr);
bp::execute(bp::process(ctx, cf_prog, {pstr, style_arg, "-i", "--Werror"}));
// TODO: check exit code and throw on clang_format failure?
}
ctx.run();
}
Expand Down Expand Up @@ -572,9 +581,30 @@ void render_cpp(inja::Environment& env,
std::cout << std::format("writing: '{}'\n", src_out_file.string());
fs::ofstream hdr_out{hdr_out_file};
fs::ofstream src_out{src_out_file};

if (!hdr_out)
{
throw std::runtime_error(
std::format("failed to open '{}' for writing", hdr_out_file.string()));
}
if (!src_out)
{
throw std::runtime_error(
std::format("failed to open '{}' for writing", src_out_file.string()));
}

hdr_out << hdr;
src_out << src;

if (hdr_out.fail())
{
throw std::runtime_error(std::format("failed to write '{}'", hdr_out_file.string()));
}
if (src_out.fail())
{
throw std::runtime_error(std::format("failed to write '{}'", src_out_file.string()));
}

if (run_clang_format)
{
clang_format({hdr_out_file, src_out_file});
Expand Down Expand Up @@ -676,6 +706,10 @@ render(
data["class_name"].get<std::string>()).filename().replace_extension(".uc").string();

std::cout << std::format("rendering '{}'\n", file);

fs::create_directories(fs::path(uscript_out_dir));
fs::create_directories(fs::path(cpp_out_dir));

render_uscript(env, us_template.string(), data, uscript_out_name, uscript_out_dir);
render_cpp(env, cpp_hdr_template.string(), cpp_src_template.string(), data, cpp_out_dir,
run_clang_format);
Expand Down
7 changes: 4 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
endif ()

set(UMB_USCRIPT_TEST_MUTATOR "UMBTestsMutator")
set(UMB_GENERATED_TEST_OUT ${CMAKE_CURRENT_SOURCE_DIR}/out)
set(UMB_GENERATED_TEST_OUT ${CMAKE_BINARY_DIR}/generated)
set(UMB_GENERATED_OUTPUT_TEST_FILES "")
file(GLOB UMB_TEST_MSG_DEFINITION_FILES data/*.json)
cmake_print_variables(UMB_TEST_MSG_DEFINITION_FILES)
Expand All @@ -59,7 +59,7 @@ set(
UMB_GENERATOR_TESTING_ARGS
${UMB_TEST_MSG_DEFINITION_FILES}
--cpp-out=${UMB_GENERATED_TEST_OUT}
--uscript-out=${UMB_GENERATED_TEST_OUT} # TODO: put generated code in build dir!
--uscript-out=${UMB_GENERATED_TEST_OUT}
--uscript-test-mutator=${UMB_USCRIPT_TEST_MUTATOR}
)
if (NOT UMB_RUN_CLANG_FORMAT)
Expand All @@ -80,7 +80,7 @@ add_dependencies(generate_test_data copy_templates)
add_library(test_msg_library ${UMB_GENERATED_OUTPUT_TEST_FILES})
# Always enable reflection for testing, regardless of global setting.
target_compile_definitions(test_msg_library PRIVATE -DUMB_INCLUDE_META)
target_include_directories(test_msg_library PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/out)
target_include_directories(test_msg_library PUBLIC ${UMB_GENERATED_TEST_OUT})
target_link_libraries(test_msg_library PUBLIC umb ICU::uc ICU::dt ICU::in ICU::io)
target_compile_features(test_msg_library PRIVATE cxx_std_23)

Expand Down Expand Up @@ -152,3 +152,4 @@ endif ()

# TODO: clean up all the unneeded dependency links. The graph is a mess.
# TODO: make reusable CMake functions to be used in other projects.
# - protobuf style cmake generation funcs
15 changes: 8 additions & 7 deletions tests/UDKTests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ Before running the tests, the following environment variables should be
set or modified depending on the environment. Default values are defined
in [defaults.py](defaults.py).

| Variable | Description |
|-----------------------|-----------------------------------------------------|
| UDK_TEST_TIMEOUT | script compilation and test timeout in seconds |
| UDK_LITE_TAG | UDK-Lite repository Git tag |
| UDK_LITE_ROOT | path to UDK-Lite root |
| UDK_LITE_RELEASE_URL | UDK-Lite binary and package release URL |
| USCRIPT_MESSAGE_FILES | .uc files generated by UMB to test, glob expression |
| Variable | Description |
|---------------------------|-----------------------------------------------------|
| UDK_TEST_TIMEOUT | script compilation and test timeout in seconds |
| UDK_LITE_TAG | UDK-Lite repository Git tag |
| UDK_LITE_ROOT | path to UDK-Lite root |
| UDK_LITE_RELEASE_URL | UDK-Lite binary and package release URL |
| UDK_USCRIPT_MESSAGE_FILES | .uc files generated by UMB to test, glob expression |

## Running the tests

```shell
# TODO

```
2 changes: 1 addition & 1 deletion tests/UDKTests/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
UDK_LITE_ROOT = "./UDK-Lite/"
UDK_LITE_RELEASE_URL = (f"https://github.com/tuokri/UDK-Lite/releases/download/{UDK_LITE_TAG}/UDK"
f"-Lite-{UDK_LITE_TAG}.7z")
USCRIPT_MESSAGE_FILES = _FILE_DIR / "../out/*.uc"
UDK_USCRIPT_MESSAGE_FILES = _FILE_DIR / "../../cmake-build-debug/generated/*.uc"
5 changes: 3 additions & 2 deletions tests/UDKTests/setup_udk_build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,15 +470,16 @@ async def main():
udk_lite_tag = os.environ.get("UDK_LITE_TAG", defaults.UDK_LITE_TAG)
udk_lite_root = Path(os.environ.get("UDK_LITE_ROOT", defaults.UDK_LITE_ROOT))
udk_lite_release_url = os.environ.get("UDK_LITE_RELEASE_URL", defaults.UDK_LITE_RELEASE_URL)
uscript_message_files = os.environ.get("USCRIPT_MESSAGE_FILES", defaults.USCRIPT_MESSAGE_FILES)
uscript_message_files = os.environ.get("UDK_USCRIPT_MESSAGE_FILES",
defaults.UDK_USCRIPT_MESSAGE_FILES)

if not udk_lite_root.is_absolute():
udk_lite_root = (SCRIPT_DIR / udk_lite_root).resolve()

print(f"UDK_LITE_TAG={udk_lite_tag}")
print(f"UDK_LITE_ROOT={udk_lite_root}")
print(f"UDK_LITE_RELEASE_URL={udk_lite_release_url}")
print(f"USCRIPT_MESSAGE_FILES={uscript_message_files}")
print(f"UDK_USCRIPT_MESSAGE_FILES={uscript_message_files}")

input_script_msg_files = [
resolve_script_path(path) for path in
Expand Down
15 changes: 10 additions & 5 deletions tests/gen_test_messages_with_valgrind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@ shopt -s nullglob
# TODO: modularize this.
# TODO: Valgrind runs for generator failure branches. (Argument handling, invalid files, etc.)

UM_GEN_EXECUTABLE_DEFAULT="${SCRIPT_DIR}/../cmake-build-debug-wsl/uscript_msgbuf_generator"
# The directory of this script.
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

UMB_GEN_EXECUTABLE_DEFAULT="${SCRIPT_DIR}/../cmake-build-debug-wsl/uscript_msgbuf_generator"
UMB_GENERATED_DIR_DEFAULT="${SCRIPT_DIR}/../cmake-build-debug-wsl/generated/"

[[ -z "${UMB_VALGRIND_BIN}" ]] && VALGRIND='valgrind' || VALGRIND="${UMB_VALGRIND_BIN}"
[[ -z "${UMB_GEN_BIN}" ]] && UMB_GEN=${UM_GEN_EXECUTABLE_DEFAULT} || UMB_GEN="${UMB_GEN_BIN}"
[[ -z "${UMB_GEN_BIN}" ]] && UMB_GEN="${UMB_GEN_EXECUTABLE_DEFAULT}" || UMB_GEN="${UMB_GEN_BIN}"
[[ -z "${UMB_VALGRIND_GEN_DIR}" ]] && GEN_DIR="${UMB_GENERATED_DIR_DEFAULT}" || GEN_DIR="${UMB_VALGRIND_GEN_DIR}"

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
DATA_FILES=("${SCRIPT_DIR}"/data/*.json)
OUT_DIR="${SCRIPT_DIR}"/out/valgrind
OUT_DIR="${GEN_DIR}/valgrind"

mkdir -p "${OUT_DIR}"

echo "using valgrind: '${VALGRIND}'"
echo "using UMB generator: '${UMB_GEN_BIN}'"
echo "using UMB generator: '${UMB_GEN}'"
echo "generating Valgrind run UMB output in: '${OUT_DIR}'"

${VALGRIND} --leak-check=full --track-origins=yes --error-exitcode=1 \
"${UMB_GEN}" "${DATA_FILES[@]}" \
Expand Down
3 changes: 0 additions & 3 deletions tests/out/.gitignore

This file was deleted.

3 changes: 2 additions & 1 deletion tests/test_randomized.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ TEST_CASE("test TestMessages messages with randomized data")

// "Fire up" the RNG. TODO: does this actually help with anything?
constexpr uint64_t r_initial = get_rand<0, 0>();
std::cout << std::format("*** begin RNG tests, r_initial={} ***\n\n", r_initial);
std::cout << std::format("*** begin RNG tests, r_initial={}, kiss_seed={} ***\n\n",
r_initial, ::umb::meta::rng::kiss_seed);

boost::hana::for_each(rounds, [&](const auto round)
{
Expand Down

0 comments on commit daa7796

Please sign in to comment.