diff --git a/.github/workflows/swift-codegen.yml b/.github/workflows/swift-codegen.yml index ded763f8dbb..b0415606415 100644 --- a/.github/workflows/swift-codegen.yml +++ b/.github/workflows/swift-codegen.yml @@ -25,8 +25,7 @@ jobs: git diff --exit-code --stat HEAD - name: Generate C++ files run: | - bazel run //swift/codegen:trapgen -- --cpp-output=$PWD/swift-generated-headers - bazel run //swift/codegen:cppgen -- --cpp-output=$PWD/swift-generated-headers + bazel run //swift/codegen:cppcodegen -- --cpp-output=$PWD/swift-generated-headers - uses: actions/upload-artifact@v3 with: name: swift-generated-headers diff --git a/swift/codegen/BUILD.bazel b/swift/codegen/BUILD.bazel index 9e32994dc1b..da26689e1f5 100644 --- a/swift/codegen/BUILD.bazel +++ b/swift/codegen/BUILD.bazel @@ -14,41 +14,22 @@ filegroup( py_binary( name = "codegen", - srcs = glob( - ["*.py"], - exclude = ["trapgen.py"], - ), + srcs = ["codegen.py"], visibility = ["//swift/codegen/test:__pkg__"], - deps = ["//swift/codegen/lib"], + deps = ["//swift/codegen/generators"], ) # as opposed to the above, that is meant to only be run with bazel run, # we need to be precise with data dependencies of this which is meant be run during build py_binary( - name = "trapgen", - srcs = ["trapgen.py"], - data = [ - "//swift:dbscheme", - "//swift/codegen/templates:trap", - ], - visibility = ["//swift:__subpackages__"], - deps = [ - "//swift/codegen/lib", - requirement("toposort"), - ], -) - -py_binary( - name = "cppgen", - srcs = ["cppgen.py"], + name = "cppcodegen", + srcs = ["cppcodegen.py"], data = [ ":schema", ":schema_includes", "//swift/codegen/templates:cpp", + "//swift/codegen/templates:trap", ], visibility = ["//swift:__subpackages__"], - deps = [ - "//swift/codegen/lib", - requirement("toposort"), - ], + deps = ["//swift/codegen/generators"], ) diff --git a/swift/codegen/codegen.py b/swift/codegen/codegen.py index 13a1ff510db..6e2849986db 100755 --- a/swift/codegen/codegen.py +++ b/swift/codegen/codegen.py @@ -1,9 +1,7 @@ #!/usr/bin/env python3 """ Driver script to run all checked in code generation """ -from lib import generator -import dbschemegen -import qlgen +from swift.codegen.generators import generator, dbschemegen, qlgen if __name__ == "__main__": generator.run(dbschemegen, qlgen) diff --git a/swift/codegen/cppcodegen.py b/swift/codegen/cppcodegen.py new file mode 100644 index 00000000000..e4ff5bcb579 --- /dev/null +++ b/swift/codegen/cppcodegen.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 +""" Driver script to run all cpp code generation """ + +from swift.codegen.generators import generator, dbschemegen, trapgen, cppgen + +if __name__ == "__main__": + generator.run(dbschemegen, trapgen, cppgen) diff --git a/swift/codegen/generators/BUILD.bazel b/swift/codegen/generators/BUILD.bazel new file mode 100644 index 00000000000..94285e24015 --- /dev/null +++ b/swift/codegen/generators/BUILD.bazel @@ -0,0 +1,11 @@ +load("@swift_codegen_deps//:requirements.bzl", "requirement") + +py_library( + name = "generators", + srcs = glob(["*.py"]), + visibility = ["//swift/codegen:__subpackages__"], + deps = [ + "//swift/codegen/lib", + requirement("toposort"), + ], +) diff --git a/swift/codegen/cppgen.py b/swift/codegen/generators/cppgen.py similarity index 96% rename from swift/codegen/cppgen.py rename to swift/codegen/generators/cppgen.py index dcda56fd5f2..a4bff441fa4 100644 --- a/swift/codegen/cppgen.py +++ b/swift/codegen/generators/cppgen.py @@ -4,7 +4,8 @@ from typing import Dict import inflection from toposort import toposort_flatten -from swift.codegen.lib import cpp, generator, schema +from swift.codegen.lib import cpp, schema +from swift.codegen.generators import generator def _get_type(t: str, trap_affix: str) -> str: diff --git a/swift/codegen/dbschemegen.py b/swift/codegen/generators/dbschemegen.py similarity index 97% rename from swift/codegen/dbschemegen.py rename to swift/codegen/generators/dbschemegen.py index c95316e5499..198485a1e8f 100755 --- a/swift/codegen/dbschemegen.py +++ b/swift/codegen/generators/dbschemegen.py @@ -3,7 +3,8 @@ import pathlib import inflection -from swift.codegen.lib import paths, schema, generator +from swift.codegen.lib import schema +from swift.codegen.generators import generator from swift.codegen.lib.dbscheme import * log = logging.getLogger(__name__) diff --git a/swift/codegen/lib/generator.py b/swift/codegen/generators/generator.py similarity index 91% rename from swift/codegen/lib/generator.py rename to swift/codegen/generators/generator.py index c78d8e3b523..7aecb09746c 100644 --- a/swift/codegen/lib/generator.py +++ b/swift/codegen/generators/generator.py @@ -5,7 +5,8 @@ import logging import sys from typing import Set -from . import options, render, paths +from swift.codegen.lib import render, paths +from swift.codegen.generators import options def _parse(tags: Set[str]) -> argparse.Namespace: diff --git a/swift/codegen/lib/options.py b/swift/codegen/generators/options.py similarity index 98% rename from swift/codegen/lib/options.py rename to swift/codegen/generators/options.py index 501b7cc73d1..95e1abbf685 100644 --- a/swift/codegen/lib/options.py +++ b/swift/codegen/generators/options.py @@ -5,7 +5,7 @@ import collections import pathlib from typing import Set -from . import paths +from swift.codegen.lib import paths def _init_options(): diff --git a/swift/codegen/qlgen.py b/swift/codegen/generators/qlgen.py similarity index 97% rename from swift/codegen/qlgen.py rename to swift/codegen/generators/qlgen.py index 4eea533904a..580866f132c 100755 --- a/swift/codegen/qlgen.py +++ b/swift/codegen/generators/qlgen.py @@ -6,7 +6,8 @@ import subprocess import inflection -from swift.codegen.lib import schema, paths, generator, ql +from swift.codegen.lib import schema, ql +from swift.codegen.generators import generator log = logging.getLogger(__name__) diff --git a/swift/codegen/trapgen.py b/swift/codegen/generators/trapgen.py similarity index 96% rename from swift/codegen/trapgen.py rename to swift/codegen/generators/trapgen.py index 2dbb961f837..6c4d22a53be 100755 --- a/swift/codegen/trapgen.py +++ b/swift/codegen/generators/trapgen.py @@ -5,7 +5,8 @@ import logging import inflection from toposort import toposort_flatten -from swift.codegen.lib import dbscheme, generator, cpp +from swift.codegen.lib import dbscheme, cpp +from swift.codegen.generators import generator log = logging.getLogger(__name__) diff --git a/swift/codegen/lib/BUILD.bazel b/swift/codegen/lib/BUILD.bazel index 428c158f995..ac03642ca89 100644 --- a/swift/codegen/lib/BUILD.bazel +++ b/swift/codegen/lib/BUILD.bazel @@ -1,11 +1,12 @@ load("@swift_codegen_deps//:requirements.bzl", "requirement") + py_library( name = "lib", srcs = glob(["*.py"]), + visibility = ["//swift/codegen:__subpackages__"], deps = [ requirement("pystache"), requirement("pyyaml"), requirement("inflection"), ], - visibility = ["//swift/codegen:__subpackages__"], ) diff --git a/swift/codegen/test/BUILD.bazel b/swift/codegen/test/BUILD.bazel index 76266b2a665..9ae41c14941 100644 --- a/swift/codegen/test/BUILD.bazel +++ b/swift/codegen/test/BUILD.bazel @@ -17,8 +17,7 @@ py_library( srcs = [src], deps = [ ":utils", - "//swift/codegen", - "//swift/codegen:trapgen", + "//swift/codegen/generators", ], ) for src in glob(["test_*.py"]) diff --git a/swift/codegen/test/test_cppgen.py b/swift/codegen/test/test_cppgen.py index b4e766af9dc..ea0255f4254 100644 --- a/swift/codegen/test/test_cppgen.py +++ b/swift/codegen/test/test_cppgen.py @@ -1,6 +1,6 @@ import sys -from swift.codegen import cppgen +from swift.codegen.generators import cppgen from swift.codegen.lib import cpp from swift.codegen.test.utils import * diff --git a/swift/codegen/test/test_dbschemegen.py b/swift/codegen/test/test_dbschemegen.py index 54f1e1796f7..0f488423a6d 100644 --- a/swift/codegen/test/test_dbschemegen.py +++ b/swift/codegen/test/test_dbschemegen.py @@ -1,6 +1,6 @@ import sys -from swift.codegen import dbschemegen +from swift.codegen.generators import dbschemegen from swift.codegen.lib import dbscheme from swift.codegen.test.utils import * diff --git a/swift/codegen/test/test_qlgen.py b/swift/codegen/test/test_qlgen.py index e5405406747..cda43714443 100644 --- a/swift/codegen/test/test_qlgen.py +++ b/swift/codegen/test/test_qlgen.py @@ -1,7 +1,7 @@ import subprocess import sys -from swift.codegen import qlgen +from swift.codegen.generators import qlgen from swift.codegen.lib import ql from swift.codegen.test.utils import * diff --git a/swift/codegen/test/test_trapgen.py b/swift/codegen/test/test_trapgen.py index 2aad0da1203..d3d0dbfcaba 100644 --- a/swift/codegen/test/test_trapgen.py +++ b/swift/codegen/test/test_trapgen.py @@ -1,6 +1,6 @@ import sys -from swift.codegen import trapgen +from swift.codegen.generators import trapgen from swift.codegen.lib import cpp, dbscheme from swift.codegen.test.utils import * diff --git a/swift/extractor/trap/BUILD.bazel b/swift/extractor/trap/BUILD.bazel index 5a3beca1ba8..ad05ed7fed3 100644 --- a/swift/extractor/trap/BUILD.bazel +++ b/swift/extractor/trap/BUILD.bazel @@ -1,19 +1,3 @@ -genrule( - name = "trapgen", - srcs = ["//swift:dbscheme"], - outs = [ - "generated/TrapEntries.h", - "generated/TrapTags.h", - ], - cmd = " ".join([ - "$(location //swift/codegen:trapgen)", - "--dbscheme $<", - "--cpp-include-dir " + package_name(), - "--cpp-output $(RULEDIR)/generated", - ]), - exec_tools = ["//swift/codegen:trapgen"], -) - genrule( name = "cppgen", srcs = [ @@ -21,22 +5,22 @@ genrule( "//swift/codegen:schema_includes", ], outs = [ + "generated/TrapEntries.h", + "generated/TrapTags.h", "generated/TrapClasses.h", ], cmd = " ".join([ - "$(location //swift/codegen:cppgen)", + "$(location //swift/codegen:cppcodegen)", "--schema $(location //swift/codegen:schema)", + "--dbscheme $(RULEDIR)/generated/swift.dbscheme", "--cpp-include-dir " + package_name(), "--cpp-output $(RULEDIR)/generated", ]), - exec_tools = ["//swift/codegen:cppgen"], + exec_tools = ["//swift/codegen:cppcodegen"], ) cc_library( name = "trap", - hdrs = glob(["*.h"]) + [ - ":trapgen", - ":cppgen", - ], + hdrs = glob(["*.h"]) + [":cppgen"], visibility = ["//visibility:public"], )