Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,16 @@ jobs:
distribution: temurin
java-version: '21'
- uses: sbt/setup-sbt@v1
- name: Run tests
- name: build-compiler
run: |
cat /dev/null | sbt \
compile \
compilerJVM/stage \
fastOptJS \
buildNpmJsFile \
buildNpmPackage
- name: Run Scala tests
run: sbt test
- name: Run CLI invocation tests
run: tests-cli/run-tests
if: always()
39 changes: 39 additions & 0 deletions tests-cli/expected/bad_args-garbage_arg/err
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Error: Unknown option --garbage
kaitai-struct-compiler 0.12-SNAPSHOT
Usage: kaitai-struct-compiler [options] <file>...

<file>... source files (.ksy)
-t, --target <language> target languages (graphviz, perl, java, go, cpp_stl, php, lua, html, ruby, construct, javascript, csharp, rust, zig, all, python, nim)
-w, --read-write generate read-write support in classes (implies `--no-auto-read --zero-copy-substream false`, Java and Python only, default: read-only)
-d, --outdir <directory>
output directory (filenames will be auto-generated); on Unix-like shells, the short form `-d` requires arguments to be preceded by `--`
-I, --import-path <directory>:<directory>:...
.ksy library search path(s) for imports (see also KSPATH env variable)
--cpp-namespace <namespace>
C++ namespace (C++ only, default: none)
--cpp-standard <standard>
C++ standard to target (C++ only, supported: 98, 11, default: 98)
--go-package <package> Go package (Go only, default: none)
--java-package <package>
Java package (Java only, default: root package)
--java-from-file-class <class>
Java class to be invoked in fromFile() helper (default: io.kaitai.struct.ByteBufferKaitaiStream)
--dotnet-namespace <namespace>
.NET Namespace (.NET only, default: Kaitai)
--php-namespace <namespace>
PHP Namespace (PHP only, default: root package)
--python-package <package>
Python package (Python only, default: root package)
--nim-module <module> Path of Nim runtime module (Nim only, default: kaitai_struct_nim_runtime)
--nim-opaque <module> Directory of opaque Nim modules (Nim only, default: directory of generated module)
--opaque-types <value> opaque types allowed, default: false
--zero-copy-substream <value>
zero-copy substreams allowed, default: true
--ksc-exceptions ksc throws exceptions instead of human-readable error messages
--ksc-json-output output compilation results as JSON to stdout
--verbose <value> verbose output
--no-auto-read disable auto-running `_read` in constructor
--read-pos `_read` remembers attribute positions in stream
--debug same as --no-auto-read --read-pos (useful for visualization tools)
--help display this help and exit
--version output version information and exit
1 change: 1 addition & 0 deletions tests-cli/expected/bad_args-garbage_arg/exitstatus
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Empty file.
39 changes: 39 additions & 0 deletions tests-cli/expected/bad_args-no_target/err
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Error: Missing option --target
kaitai-struct-compiler 0.12-SNAPSHOT
Usage: kaitai-struct-compiler [options] <file>...

<file>... source files (.ksy)
-t, --target <language> target languages (graphviz, perl, java, go, cpp_stl, php, lua, html, ruby, construct, javascript, csharp, rust, zig, all, python, nim)
-w, --read-write generate read-write support in classes (implies `--no-auto-read --zero-copy-substream false`, Java and Python only, default: read-only)
-d, --outdir <directory>
output directory (filenames will be auto-generated); on Unix-like shells, the short form `-d` requires arguments to be preceded by `--`
-I, --import-path <directory>:<directory>:...
.ksy library search path(s) for imports (see also KSPATH env variable)
--cpp-namespace <namespace>
C++ namespace (C++ only, default: none)
--cpp-standard <standard>
C++ standard to target (C++ only, supported: 98, 11, default: 98)
--go-package <package> Go package (Go only, default: none)
--java-package <package>
Java package (Java only, default: root package)
--java-from-file-class <class>
Java class to be invoked in fromFile() helper (default: io.kaitai.struct.ByteBufferKaitaiStream)
--dotnet-namespace <namespace>
.NET Namespace (.NET only, default: Kaitai)
--php-namespace <namespace>
PHP Namespace (PHP only, default: root package)
--python-package <package>
Python package (Python only, default: root package)
--nim-module <module> Path of Nim runtime module (Nim only, default: kaitai_struct_nim_runtime)
--nim-opaque <module> Directory of opaque Nim modules (Nim only, default: directory of generated module)
--opaque-types <value> opaque types allowed, default: false
--zero-copy-substream <value>
zero-copy substreams allowed, default: true
--ksc-exceptions ksc throws exceptions instead of human-readable error messages
--ksc-json-output output compilation results as JSON to stdout
--verbose <value> verbose output
--no-auto-read disable auto-running `_read` in constructor
--read-pos `_read` remembers attribute positions in stream
--debug same as --no-auto-read --read-pos (useful for visualization tools)
--help display this help and exit
--version output version information and exit
1 change: 1 addition & 0 deletions tests-cli/expected/bad_args-no_target/exitstatus
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Empty file.
Empty file.
1 change: 1 addition & 0 deletions tests-cli/expected/compile-all-namespaced/exitstatus
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from construct import *
from construct.lib import *

simple = Struct(
'one' / Int8ub,
)

_schema = simple
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

#include "simple.h"

simple_t::simple_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, simple_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root ? p__root : this;
_read();
}

void simple_t::_read() {
m_one = m__io->read_u1();
}

simple_t::~simple_t() {
_clean_up();
}

void simple_t::_clean_up() {
}
35 changes: 35 additions & 0 deletions tests-cli/expected/compile-all-namespaced/foo/cpp_stl_11/simple.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

class simple_t;

#include "kaitai/kaitaistruct.h"
#include <stdint.h>
#include <memory>

#if KAITAI_STRUCT_VERSION < 11000L
#error "Incompatible Kaitai Struct C++/STL API: version 0.11 or later is required"
#endif

class simple_t : public kaitai::kstruct {

public:

simple_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, simple_t* p__root = nullptr);

private:
void _read();
void _clean_up();

public:
~simple_t();
uint8_t one() const { return m_one; }
simple_t* _root() const { return m__root; }
kaitai::kstruct* _parent() const { return m__parent; }

private:
uint8_t m_one;
simple_t* m__root;
kaitai::kstruct* m__parent;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

#include "simple.h"

simple_t::simple_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, simple_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root ? p__root : this;

try {
_read();
} catch(...) {
_clean_up();
throw;
}
}

void simple_t::_read() {
m_one = m__io->read_u1();
}

simple_t::~simple_t() {
_clean_up();
}

void simple_t::_clean_up() {
}
37 changes: 37 additions & 0 deletions tests-cli/expected/compile-all-namespaced/foo/cpp_stl_98/simple.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef SIMPLE_H_
#define SIMPLE_H_

// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

class simple_t;

#include "kaitai/kaitaistruct.h"
#include <stdint.h>

#if KAITAI_STRUCT_VERSION < 11000L
#error "Incompatible Kaitai Struct C++/STL API: version 0.11 or later is required"
#endif

class simple_t : public kaitai::kstruct {

public:

simple_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = 0, simple_t* p__root = 0);

private:
void _read();
void _clean_up();

public:
~simple_t();
uint8_t one() const { return m_one; }
simple_t* _root() const { return m__root; }
kaitai::kstruct* _parent() const { return m__parent; }

private:
uint8_t m_one;
simple_t* m__root;
kaitai::kstruct* m__parent;
};

#endif // SIMPLE_H_
31 changes: 31 additions & 0 deletions tests-cli/expected/compile-all-namespaced/foo/csharp/Simple.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild



namespace Kaitai
{
public partial class Simple : KaitaiStruct
{
public static Simple FromFile(string fileName)
{
return new Simple(new KaitaiStream(fileName));
}

public Simple(KaitaiStream p__io, KaitaiStruct p__parent = null, Simple p__root = null) : base(p__io)
{
m_parent = p__parent;
m_root = p__root ?? this;
_read();
}
private void _read()
{
_one = m_io.ReadU1();
}
public byte One { get { return _one; } }
public Simple M_Root { get { return m_root; } }
public KaitaiStruct M_Parent { get { return m_parent; } }
private byte _one;
private Simple m_root;
private KaitaiStruct m_parent;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests-cli/expected/compile-all-namespaced/foo/graphviz/simple.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
digraph {
rankdir=LR;
node [shape=plaintext];
subgraph cluster__simple {
label="Simple";
graph[style=dotted];

simple__seq [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
<TR><TD BGCOLOR="#E0FFE0">pos</TD><TD BGCOLOR="#E0FFE0">size</TD><TD BGCOLOR="#E0FFE0">type</TD><TD BGCOLOR="#E0FFE0">id</TD></TR>
<TR><TD PORT="one_pos">0</TD><TD PORT="one_size">1</TD><TD>u1</TD><TD PORT="one_type">one</TD></TR>
</TABLE>>];
}
}
41 changes: 41 additions & 0 deletions tests-cli/expected/compile-all-namespaced/foo/html/simple.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">

<title>Simple format specification</title>
</head>
<body>
<div class="container">
<h1>Simple format specification</h1>


<a name='type-simple'></a>
<h1>Type: Simple</h1>

<table class="table">
<tr><th>Offset</th><th>Size</th><th>ID</th><th>Type</th><th>Note</th></tr>
<tr>
<td>0</td>
<td>...</td>
<td>one</td>
<td>u1</td>
<td></td>
</tr>
</table>

</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
</body>
</html>

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

package foo.bar;

import io.kaitai.struct.ByteBufferKaitaiStream;
import io.kaitai.struct.KaitaiStruct;
import io.kaitai.struct.KaitaiStream;
import java.io.IOException;

public class Simple extends KaitaiStruct {
public static Simple fromFile(String fileName) throws IOException {
return new Simple(new ByteBufferKaitaiStream(fileName));
}

public Simple(KaitaiStream _io) {
this(_io, null, null);
}

public Simple(KaitaiStream _io, KaitaiStruct _parent) {
this(_io, _parent, null);
}

public Simple(KaitaiStream _io, KaitaiStruct _parent, Simple _root) {
super(_io);
this._parent = _parent;
this._root = _root == null ? this : _root;
_read();
}
private void _read() {
this.one = this._io.readU1();
}

public void _fetchInstances() {
}
public int one() { return one; }
public Simple _root() { return _root; }
public KaitaiStruct _parent() { return _parent; }
private int one;
private Simple _root;
private KaitaiStruct _parent;
}
Loading
Loading