diff --git a/third_party/flatbuffers/build_defs.bzl b/third_party/flatbuffers/build_defs.bzl index 8f79cef90b5..e0fe1088992 100644 --- a/third_party/flatbuffers/build_defs.bzl +++ b/third_party/flatbuffers/build_defs.bzl @@ -379,13 +379,18 @@ def flatbuffer_py_strip_prefix_srcs(name, srcs = [], strip_prefix = ""): ) def _concat_flatbuffer_py_srcs_impl(ctx): - # Merge all generated python files. - command = "find '%s' -name '*.py' -exec cat {} + | sed '/import flatbuffers/d'" - command += " | sed '1s/^/import flatbuffers\\'$'\\n/' > %s" + # Merge all generated python files. The files are concatenated and import + # statements are removed. Finally we import the flatbuffer runtime library. + # IMPORTANT: Our Windows shell does not support "find ... -exec" properly. + # If you're changing the commandline below, please build wheels and run smoke + # tests on all the three operating systems. + command = "echo 'import flatbuffers\n' > %s; " + command += "for f in $(find %s -name '*.py'); do cat $f | sed '/import flatbuffers/d' >> %s; done " ctx.actions.run_shell( inputs = ctx.attr.deps[0].files, outputs = [ctx.outputs.out], command = command % ( + ctx.outputs.out.path, ctx.attr.deps[0].files.to_list()[0].path, ctx.outputs.out.path, ),