Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6aea6071 authored by Zach Johnson's avatar Zach Johnson
Browse files

rusty-packets: generate a file that's ready for content

Bug: 171749953
Tag: #gd-refactor
Test: gd/cert/run --rhost SimpleHalTest
Change-Id: Ia3d9e7e3d0b8f388204fd22d6ce4df2760af60de
parent fb25b1aa
Loading
Loading
Loading
Loading
+26 −4
Original line number Diff line number Diff line
@@ -15,14 +15,36 @@
 */

#include <filesystem>
#include <fstream>
#include <iostream>
#include "declarations.h"

bool generate_rust_source_one_file(
    __attribute__((unused)) const Declarations& decls,
    __attribute__((unused)) const std::filesystem::path& input_file,
    __attribute__((unused)) const std::filesystem::path& include_dir,
    __attribute__((unused)) const std::filesystem::path& out_dir,
    const std::filesystem::path& input_file,
    const std::filesystem::path& include_dir,
    const std::filesystem::path& out_dir,
    __attribute__((unused)) const std::string& root_namespace) {
  // TODO do fun things
  auto gen_relative_path = input_file.lexically_relative(include_dir).parent_path();

  auto input_filename = input_file.filename().string().substr(0, input_file.filename().string().find(".pdl"));
  auto gen_path = out_dir / gen_relative_path;

  std::filesystem::create_directories(gen_path);

  auto gen_file = gen_path / (input_filename + ".rs");

  std::cout << "generating " << gen_file << std::endl;

  std::ofstream out_file;
  out_file.open(gen_file);
  if (!out_file.is_open()) {
    std::cerr << "can't open " << gen_file << std::endl;
    return false;
  }

  out_file << "// @generated rust packets from " << input_file.filename().string();

  out_file.close();
  return true;
}