diff --git a/.gitsubmodules b/.gitsubmodules new file mode 100644 index 0000000..00f3262 --- /dev/null +++ b/.gitsubmodules @@ -0,0 +1,6 @@ +[submodule "kythe"] + path = third_party/kythe + url = https://github.com/kythe/kythe +[submodule "bazel"] + path = third_party/bazel + url = https://github.com/bazelbuild/bazel diff --git a/BUILD b/BUILD index 0528ef0..80e7e1c 100644 --- a/BUILD +++ b/BUILD @@ -19,6 +19,12 @@ py_library( ], ) +py_binary( + name = "graphdef_from_bazel", + srcs = ["graphdef_from_bazel.py"], + deps = [":splitbrain"], +) + py_binary( name = "main", srcs = ["main.py"], diff --git a/graphdef_from_bazel.py b/graphdef_from_bazel.py new file mode 100644 index 0000000..5e99b4e --- /dev/null +++ b/graphdef_from_bazel.py @@ -0,0 +1,43 @@ +"""Extracts a GraphDef based on a Bazel workspace. + +This tool launches the Bazel binary to extract some data from a workspace, and +processes the protocol buffer output to produce a GraphDef. + +Usage: + ./graphdef_from_bazel.py --input_dir=path/to/WORKSPACE \\ + --output_dir=path/to/out +""" + +from absl import app +from absl import flags +import graphdef_utils +from third_party.bazel.src.main.protobuf import build_pb2 + +FLAGS = flags.FLAGS +flags.DEFINE_string('input_path', None, 'Path to Bazel WORKSPACE file.') +flags.DEFINE_string('output_dir', None, 'Directory to write output to.') +flags.DEFINE_multi_string('modified_files', [], + 'List of modified files to `bazel query` for.') +flags.DEFINE_bool('textproto', False, + 'If true, writes output statistics as textproto format.') +flags.mark_flag_as_required('input_path') +flags.mark_flag_as_required('output_dir') + + +def main(argv): + del argv + + with open(FLAGS.input_path) as f: + pass + + # TODO(cameron): Load bazel proto using vendored dependency. + # TODO(cameron): Filter on predicates: Must be a working change in the CL? Maybe keep transitive. + # TODO(cameron): Find testdata based stuff and make changes bi-directional. Same with proto. + # TODO(cameron): Merge bi-directional dependencies. + # TODO(cameron): Import tests from internal. + # TODO(cameron): Assert the graph is a DAG. Find and merge cycles. + graphdef = program_graph_pb2.GraphDef() + + +if __name__ == '__main__': + app.run(main) \ No newline at end of file diff --git a/testdata/bazel_query_on_repo.binarypb b/testdata/bazel_query_on_repo.binarypb new file mode 100644 index 0000000..fb4e768 Binary files /dev/null and b/testdata/bazel_query_on_repo.binarypb differ diff --git a/third_party/README.md b/third_party/README.md new file mode 100644 index 0000000..005faa2 --- /dev/null +++ b/third_party/README.md @@ -0,0 +1 @@ +# third_party