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

Commit 4632f4e8 authored by Tom Cherry's avatar Tom Cherry Committed by Gerrit Code Review
Browse files

Merge "Relax host init parser to work with the build system"

parents 9d9c91ac 863d808c
Loading
Loading
Loading
Loading
+6 −11
Original line number Diff line number Diff line
@@ -23,22 +23,17 @@ using android::base::StartsWith;
namespace android {
namespace init {

Result<Success> HostImportParser::ParseSection(std::vector<std::string>&& args,
                                               const std::string& filename, int line) {
Result<Success> HostImportParser::ParseSection(std::vector<std::string>&& args, const std::string&,
                                               int) {
    if (args.size() != 2) {
        return Error() << "single argument needed for import\n";
    }

    auto import_path = args[1];

    if (StartsWith(import_path, "/system") || StartsWith(import_path, "/product") ||
        StartsWith(import_path, "/odm") || StartsWith(import_path, "/vendor")) {
        import_path = out_dir_ + "/" + import_path;
    } else {
        import_path = out_dir_ + "/root/" + import_path;
    return Success();
}

    return ImportParser::ParseSection({"import", import_path}, filename, line);
Result<Success> HostImportParser::ParseLineSection(std::vector<std::string>&&, int) {
    return Error() << "Unexpected line found after import statement";
}

}  // namespace init
+4 −9
Original line number Diff line number Diff line
@@ -19,21 +19,16 @@
#include <string>
#include <vector>

#include "import_parser.h"
#include "parser.h"

namespace android {
namespace init {

class HostImportParser : public ImportParser {
class HostImportParser : public SectionParser {
  public:
    HostImportParser(const std::string& out_dir, Parser* parser)
        : ImportParser(parser), out_dir_(out_dir) {}
    Result<Success> ParseSection(std::vector<std::string>&& args, const std::string& filename,
                                 int line) override;

  private:
    std::string out_dir_;
    HostImportParser() {}
    Result<Success> ParseSection(std::vector<std::string>&& args, const std::string&, int) override;
    Result<Success> ParseLineSection(std::vector<std::string>&&, int) override;
};

}  // namespace init
+18 −22
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include <errno.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <string>
@@ -45,11 +46,11 @@ using android::base::ParseInt;
using android::base::ReadFileToString;
using android::base::Split;

static std::string out_dir;
static std::string passwd_file;

static std::vector<std::pair<std::string, int>> GetVendorPasswd() {
    std::string passwd;
    if (!ReadFileToString(out_dir + "/vendor/etc/passwd", &passwd)) {
    if (!ReadFileToString(passwd_file, &passwd)) {
        return {};
    }

@@ -118,20 +119,14 @@ static Result<Success> do_stub(const BuiltinArguments& args) {
int main(int argc, char** argv) {
    android::base::InitLogging(argv, &android::base::StdioLogger);
    android::base::SetMinimumLogSeverity(android::base::ERROR);
    if (argc != 3) {
        LOG(ERROR) << "Usage: " << argv[0] << " <out directory> <properties>";
        return -1;
    }

    out_dir = argv[1];

    auto properties = Split(argv[2], ",");
    for (const auto& property : properties) {
        auto split_property = Split(property, "=");
        if (split_property.size() != 2) {
            continue;
    if (argc != 2 && argc != 3) {
        LOG(ERROR) << "Usage: " << argv[0] << " <init rc file> [passwd file]";
        return EXIT_FAILURE;
    }
        property_set(split_property[0], split_property[1]);

    if (argc == 3) {
        passwd_file = argv[2];
    }

    const BuiltinFunctionMap function_map;
@@ -141,22 +136,23 @@ int main(int argc, char** argv) {
    Parser parser;
    parser.AddSectionParser("service", std::make_unique<ServiceParser>(&sl, nullptr));
    parser.AddSectionParser("on", std::make_unique<ActionParser>(&am, nullptr));
    parser.AddSectionParser("import", std::make_unique<HostImportParser>(out_dir, &parser));
    parser.AddSectionParser("import", std::make_unique<HostImportParser>());

    if (!parser.ParseConfig(argv[1] + "/root/init.rc"s)) {
        LOG(ERROR) << "Failed to find root init.rc script";
        return -1;
    if (!parser.ParseConfig(argv[1])) {
        LOG(ERROR) << "Failed to open init rc script '" << argv[1] << "'";
        return EXIT_FAILURE;
    }
    if (parser.parse_error_count() > 0) {
        LOG(ERROR) << "Init script parsing failed with " << parser.parse_error_count() << " errors";
        return -1;
        LOG(ERROR) << "Failed to parse init script '" << argv[1] << "' with "
                   << parser.parse_error_count() << " errors";
        return EXIT_FAILURE;
    }
    return 0;
    return EXIT_SUCCESS;
}

}  // namespace init
}  // namespace android

int main(int argc, char** argv) {
    android::init::main(argc, argv);
    return android::init::main(argc, argv);
}