In build_graph, ensure that the build directory exists before trying to write to it.