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

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

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

2 changes: 1 addition & 1 deletion .idea/runConfigurations/Generate__cs_adt__unwrapped_.xml

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

2 changes: 1 addition & 1 deletion .idea/runConfigurations/Generate__cs_adt__wrapped_.xml

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

98 changes: 93 additions & 5 deletions .mdl/defs/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ TEST_DIR="./target/test-regular"

# Create temporary test directories
mkdir -p "$TEST_DIR"
rm -rf "$TEST_DIR/cs-stub" "$TEST_DIR/sc-stub"
rm -rf "$TEST_DIR/cs-stub" "$TEST_DIR/sc-stub" "$TEST_DIR/py-stub"

# Copy stub projects, excluding generated and build artifacts
rsync -a --exclude='Generated*' --exclude='generated-*' --exclude='bin' --exclude='obj' --exclude='target' --exclude='project/target' \
./test/cs-stub/ "$TEST_DIR/cs-stub/"
rsync -a --exclude='Generated*' --exclude='generated-*' --exclude='bin' --exclude='obj' --exclude='target' --exclude='project/target' \
./test/sc-stub/ "$TEST_DIR/sc-stub/"
rsync -a --exclude='Generated*' --exclude='generated-*' --exclude='bin' --exclude='obj' --exclude='target' --exclude='project/target' \
./test/py-stub/ "$TEST_DIR/py-stub/"

$BABOON_BIN \
--model-dir ./baboon-compiler/src/test/resources/baboon/ \
Expand All @@ -56,7 +58,15 @@ $BABOON_BIN \
--test-output "$TEST_DIR/sc-stub/src/test/scala/generated-tests" \
--fixture-output "$TEST_DIR/sc-stub/src/main/scala/generated-fixtures" \
--sc-write-evolution-dict true \
--sc-wrapped-adt-branch-codecs false
--sc-wrapped-adt-branch-codecs false \
:python \
--output "$TEST_DIR/py-stub/BaboonDefinitions/Generated" \
--test-output "$TEST_DIR/py-stub/BaboonTests/GeneratedTests" \
--fixture-output "$TEST_DIR/py-stub/BaboonTests/GeneratedFixtures" \
--generate-ueba-codecs-by-default=true \
--generate-json-codecs-by-default=true \
--py-write-evolution-dict true \
--py-wrapped-adt-branch-codecs false

ret success:bool=true
ret test_dir:string="$TEST_DIR"
Expand Down Expand Up @@ -89,6 +99,22 @@ popd
ret success:bool=true
```

# action: test-python-regular

Run Python tests with regular adt codecs.

```bash
TEST_DIR="${action.test-gen-regular-adt.test_dir}"
pushd "$TEST_DIR/py-stub"
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -r requirements.txt
python3 -m unittest discover -s BaboonTests/GeneratedTests/testpkg/pkg0
popd

ret success:bool=true
```

# action: test-gen-wrapped-adt

Generate code with wrapped ADT branch codecs.
Expand All @@ -101,13 +127,15 @@ TEST_DIR="./target/test-wrapped"

# Create temporary test directories
mkdir -p "$TEST_DIR"
rm -rf "$TEST_DIR/cs-stub" "$TEST_DIR/sc-stub"
rm -rf "$TEST_DIR/cs-stub" "$TEST_DIR/sc-stub" "$TEST_DIR/py-stub"

# Copy stub projects, excluding generated and build artifacts
rsync -a --exclude='Generated*' --exclude='generated-*' --exclude='bin' --exclude='obj' --exclude='target' --exclude='project/target' \
./test/cs-stub/ "$TEST_DIR/cs-stub/"
rsync -a --exclude='Generated*' --exclude='generated-*' --exclude='bin' --exclude='obj' --exclude='target' --exclude='project/target' \
./test/sc-stub/ "$TEST_DIR/sc-stub/"
rsync -a --exclude='Generated*' --exclude='generated-*' --exclude='bin' --exclude='obj' --exclude='target' --exclude='project/target' \
./test/py-stub/ "$TEST_DIR/py-stub/"

$BABOON_BIN \
--model-dir ./baboon-compiler/src/test/resources/baboon/ \
Expand All @@ -126,7 +154,15 @@ $BABOON_BIN \
--test-output "$TEST_DIR/sc-stub/src/test/scala/generated-tests" \
--fixture-output "$TEST_DIR/sc-stub/src/main/scala/generated-fixtures" \
--sc-write-evolution-dict true \
--sc-wrapped-adt-branch-codecs true
--sc-wrapped-adt-branch-codecs true \
:python \
--output "$TEST_DIR/py-stub/BaboonDefinitions/Generated" \
--test-output "$TEST_DIR/py-stub/BaboonTests/GeneratedTests" \
--fixture-output "$TEST_DIR/py-stub/BaboonTests/GeneratedFixtures" \
--generate-ueba-codecs-by-default=true \
--generate-json-codecs-by-default=true \
--py-write-evolution-dict true \
--py-wrapped-adt-branch-codecs true

ret success:bool=true
ret test_dir:string="$TEST_DIR"
Expand Down Expand Up @@ -159,6 +195,22 @@ popd
ret success:bool=true
```

# action: test-python-wrapped

Run Python tests with wrapped ADT codecs

```bash
TEST_DIR="${action.test-gen-regular-adt.test_dir}"
pushd "$TEST_DIR/py-stub"
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -r requirements.txt
python3 -m unittest discover -s BaboonTests/GeneratedTests/testpkg/pkg0
popd

ret success:bool=true
```

# action: test-gen-manual

Generate code for manual test projects.
Expand All @@ -175,7 +227,26 @@ $BABOON_BIN \
:cs \
--output ./test/conv-test-cs/ConvTest/Generated \
:scala \
--output ./test/conv-test-sc/src/main/scala/generated-main
--output ./test/conv-test-sc/src/main/scala/generated-main \
:python \
--output ./test/conv-test-py/Generated

ret success:bool=true
```

# action: test-gen-compat-python

Generate compatibility test files using Python.

```bash
dep action.test-gen-manual

pushd ./test/conv-test-py
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -r requirements.txt
python3 compat_main.py
popd

ret success:bool=true
```
Expand Down Expand Up @@ -215,6 +286,7 @@ Run manual C# compatibility tests.
```bash
dep action.test-gen-compat-scala
dep action.test-gen-compat-cs
dep action.test-gen-compat-python

pushd ./test/conv-test-cs
dotnet build
Expand All @@ -239,15 +311,31 @@ popd
ret success:bool=true
```

# action: test-manual-python

Run Python conversion test

```bash
dep action.test-gen-compat-python
pushd ./test/conv-test-py
source source .venv/bin/activate
python3 -m unittest discover -s .
popd

ret success:bool=true
```

# action: test

Run complete test suite (orchestrator action).

```bash
dep action.test-cs-regular
dep action.test-scala-regular
dep action.test-python-regular
dep action.test-cs-wrapped
dep action.test-scala-wrapped
dep action.test-python-wrapped
dep action.test-manual-cs
dep action.test-manual-scala

Expand Down
1 change: 1 addition & 0 deletions .mobala/version-commit.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
87a6a202f917745e826d6f245f78db48cb92965b
Empty file added .run/Help.run.xml
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ object Baboon {
),
)
}
case "python" =>
CaseApp.parse[PyCLIOptions](roleArgs).leftMap(e => s"Can't parse cs CLI: $e").map {
case (opts, _) =>
val shopts = mkGenericOpts(opts)

CompilerTarget.PyTarget(
id = "Python",
output = shopts.outOpts,
generic = shopts.genericOpts,
language = PyOptions(
writeEvolutionDict = opts.pyWriteEvolutionDict.getOrElse(true),
wrappedAdtBranchCodecs = opts.pyWrappedAdtBranchCodecs.getOrElse(false),
generateJsonCodecs = opts.generateJsonCodecs.getOrElse(true),
generateUebaCodecs = opts.generateUebaCodecs.getOrElse(true),
generateJsonCodecsByDefault = opts.generateJsonCodecsByDefault.getOrElse(false),
generateUebaCodecsByDefault = opts.generateUebaCodecsByDefault.getOrElse(false),
),
)
}
case r => Left(s"Unknown role id: $r")
}
}
Expand Down Expand Up @@ -119,7 +138,7 @@ object Baboon {

val safeToRemove = NEList.from(opts.extAllowCleanup) match {
case Some(value) => value.toSet
case None => Set("meta", "cs", "json", "scala")
case None => Set("meta", "cs", "json", "scala", "py", "pyc")
}

val outOpts = OutputOptions(
Expand Down Expand Up @@ -150,6 +169,8 @@ object Baboon {
new BaboonJvmCSModule[F](t)
case t: CompilerTarget.ScTarget =>
new BaboonJvmScModule[F](t)
case t: CompilerTarget.PyTarget =>
new BaboonJvmPyModule[F](t)
}

Injector
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.septimalmind.baboon

import distage.ModuleDef
import io.septimalmind.baboon.CompilerTarget.{CSTarget, ScTarget}
import io.septimalmind.baboon.CompilerTarget.{CSTarget, PyTarget, ScTarget}
import io.septimalmind.baboon.parser.{BaboonInclusionResolver, BaboonInclusionResolverImpl}
import io.septimalmind.baboon.util.BLogger
import izumi.functional.bio.unsafe.MaybeSuspend2
Expand All @@ -25,6 +25,12 @@ class BaboonJvmScModule[F[+_, +_]: Error2: TagKK](target: ScTarget) extends Modu
make[ScTarget].fromValue(target)
}

class BaboonJvmPyModule[F[+_, +_]: Error2: TagKK](target: PyTarget) extends ModuleDef {
include(new SharedTranspilerJvmModule[F]())
include(new BaboonCommonPyModule[F]())
make[PyTarget].fromValue(target)
}

class BaboonModuleJvm[F[+_, +_]: Error2: MaybeSuspend2: TagKK](
options: CompilerOptions,
parallelAccumulatingOps2: ParallelErrorAccumulatingOps2[F],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ case class ScCLIOptions(
scWrappedAdtBranchCodecs: Option[Boolean],
) extends SharedCLIOptions

case class PyCLIOptions(
@Recurse
generic: GenericTranspilerCLIOptions,
@HelpMessage("Allow to erase target directory even if files with these extensions exist there. Default: cs,json,meta")
extAllowCleanup: List[String],
@HelpMessage("Adds evolution metadata as a Scala dictionary")
pyWriteEvolutionDict: Option[Boolean],
@HelpMessage("Every ADT branch will encode ADT metadata and expect it in the decoder")
pyWrappedAdtBranchCodecs: Option[Boolean],
@HelpMessage("Generate JSON codecs")
generateJsonCodecs: Option[Boolean],
@HelpMessage("Generate UEBA codecs")
generateUebaCodecs: Option[Boolean],
@HelpMessage("Generate JSON codecs even for types without derived[json]")
generateJsonCodecsByDefault: Option[Boolean],
@HelpMessage("Generate UEBA codecs even for types without derived[ueba]")
generateUebaCodecsByDefault: Option[Boolean],
) extends SharedCLIOptions

case class CLIOptions(
@HelpMessage("A list of *.baboon files to process (can be combined with --model-dir)")
model: List[String],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"resources": [
{"pattern": "baboon-runtime/cs/.*\\.cs"},
{"pattern": "baboon-runtime/scala/.*\\.scala"}
{"pattern": "baboon-runtime/scala/.*\\.scala"},
{"pattern": "baboon-runtime/python/.*\\.py"}
]
}
Loading
Loading