|
@@ -0,0 +1,113 @@
|
|
|
+"""
|
|
|
+This script builds the project, creates a new release, and tests the release.
|
|
|
+"""
|
|
|
+import subprocess as sh
|
|
|
+import locale
|
|
|
+from pathlib import Path
|
|
|
+import shutil
|
|
|
+import argparse
|
|
|
+import os
|
|
|
+
|
|
|
+parser = argparse.ArgumentParser(description='Build utility.')
|
|
|
+parser.add_argument('--debug', action="store_true", default=False)
|
|
|
+
|
|
|
+args = parser.parse_args()
|
|
|
+debug = args.debug
|
|
|
+
|
|
|
+def l(*args):
|
|
|
+ print(*args)
|
|
|
+
|
|
|
+def ld(*args):
|
|
|
+ if debug:
|
|
|
+ print(*args)
|
|
|
+
|
|
|
+def print_reproduce():
|
|
|
+ l("To reproduce and see full output, rerun this this script with --debug")
|
|
|
+
|
|
|
+def r(cmd, *args, **kwargs):
|
|
|
+ cmd_string = " ".join(cmd)
|
|
|
+ ld(">", " ".join(cmd))
|
|
|
+ pr = sh.run(cmd, *args, shell=True, capture_output=(not debug), encoding=locale.getpreferredencoding(), **kwargs)
|
|
|
+ if pr.returncode != 0:
|
|
|
+ l(f"Command '{cmd_string}' failed with return code {pr.returncode}.")
|
|
|
+ l("The output was:")
|
|
|
+ l(pr.stdout)
|
|
|
+ l("The stderr was:")
|
|
|
+ l(pr.stderr)
|
|
|
+ print_reproduce()
|
|
|
+ exit(pr.returncode)
|
|
|
+
|
|
|
+ return pr
|
|
|
+
|
|
|
+l("# Producing assembly:")
|
|
|
+
|
|
|
+r(["sbt", "clean", "assembly"])
|
|
|
+
|
|
|
+l("# Preparing release")
|
|
|
+
|
|
|
+l("## Finding assembly jar")
|
|
|
+
|
|
|
+pattern = 'FMIMOBSTER-assembly-*.jar'
|
|
|
+dir = 'target'
|
|
|
+paths = list(Path(dir).rglob(pattern))
|
|
|
+if not paths:
|
|
|
+ l(f"Assembly jar with pattern {pattern} not found in directory {dir}.")
|
|
|
+ print_reproduce()
|
|
|
+ exit(1)
|
|
|
+if len(paths) > 1:
|
|
|
+ l(f"Multiple assembly jars with pattern {pattern} found in directory {dir}:")
|
|
|
+ l(paths)
|
|
|
+ print_reproduce()
|
|
|
+ exit(1)
|
|
|
+assembly_jar = paths[0]
|
|
|
+
|
|
|
+l(f"## Assembly jar found: {assembly_jar}")
|
|
|
+
|
|
|
+release_dir = "release"
|
|
|
+l("## Creating release folder")
|
|
|
+if os.path.isdir(release_dir):
|
|
|
+ shutil.rmtree(release_dir)
|
|
|
+os.mkdir(release_dir)
|
|
|
+
|
|
|
+l("## Copying files into release folder")
|
|
|
+assembly_jar_path_src = os.path.abspath(assembly_jar)
|
|
|
+assembly_jar_src_dir, assembly_jar_name = os.path.split(assembly_jar_path_src)
|
|
|
+assembly_jar_path_trg = os.path.abspath(os.path.join(release_dir, assembly_jar_name))
|
|
|
+ld(f"Copy from {assembly_jar_path_src} to {assembly_jar_path_trg}.")
|
|
|
+shutil.copyfile(assembly_jar_path_src, assembly_jar_path_trg)
|
|
|
+
|
|
|
+example_fmu_path_src = os.path.abspath("src/test/resources/fmus/20-sim/threewatertank1.fmu")
|
|
|
+example_fmu_src_dir, example_fmu_name = os.path.split(example_fmu_path_src)
|
|
|
+example_fmu_path_trg = os.path.abspath(os.path.join(release_dir, example_fmu_name))
|
|
|
+ld(f"Copy from {example_fmu_path_src} to {example_fmu_path_trg}.")
|
|
|
+shutil.copyfile(example_fmu_path_src, example_fmu_path_trg)
|
|
|
+
|
|
|
+l(f"# Running integration tests")
|
|
|
+
|
|
|
+l(f"## Running model based testing")
|
|
|
+
|
|
|
+results_dir = "results"
|
|
|
+
|
|
|
+r(['java', '-D"org.slf4j.simpleLogger.defaultLogLevel=trace"', '-jar', assembly_jar_name, 'mbt', '-d', 'threewatertank1.fmu', '-n', '1000', '-l', '10', '-o', results_dir], cwd=release_dir)
|
|
|
+
|
|
|
+l(f"## Running a reproduction of a test")
|
|
|
+
|
|
|
+results_dir_path = os.path.join(release_dir, results_dir)
|
|
|
+try:
|
|
|
+ log_file = next(Path(results_dir_path).rglob("*.err"))
|
|
|
+except StopIteration:
|
|
|
+ ld(f"No log files for tests where produced in folder {results_dir_path}.")
|
|
|
+ print_reproduce()
|
|
|
+ exit(1)
|
|
|
+first_log_path, first_log_name = os.path.split(log_file)
|
|
|
+seed, extension = os.path.splitext(first_log_name)
|
|
|
+ld(f"Log to reproduce: {first_log_name}")
|
|
|
+
|
|
|
+r(['java', '-D"org.slf4j.simpleLogger.defaultLogLevel=trace"', '-jar', assembly_jar_name, 'mbt', '-d', 'threewatertank1.fmu', '-s', seed, '-o', results_dir], cwd=release_dir)
|
|
|
+
|
|
|
+l(f"# Cleaning up generated files.")
|
|
|
+
|
|
|
+shutil.rmtree(results_dir_path)
|
|
|
+
|
|
|
+l(f"# All done. Release in: {os.path.abspath(release_dir)}")
|
|
|
+
|