Ejemplo n.º 1
0
TEST(copyStrings, CopyMultiple)
{
    std::vector<uint8_t> contents;
    MemoryFilesystem filesystem = MemoryFilesystem({
        MemoryFilesystem::Entry::File("in1.strings", Contents("string1 = value1;")),
        MemoryFilesystem::Entry::File("in2.strings", Contents("string2 = value2;")),
        MemoryFilesystem::Entry::Directory("output", { }),
    });

    Driver driver;
    EXPECT_EQ(0, driver.run({
        "in1.strings",
        "in2.strings",
        "--outdir", "output",
        "--outputencoding", "utf-8",
    }, { }, &filesystem, "/"));

    contents.clear();
    EXPECT_TRUE(filesystem.read(&contents, "output/in1.strings"));
    EXPECT_EQ(contents, Contents("string1 = value1;\n"));

    contents.clear();
    EXPECT_TRUE(filesystem.read(&contents, "output/in2.strings"));
    EXPECT_EQ(contents, Contents("string2 = value2;\n"));
}
Ejemplo n.º 2
0
int
main(int argc, char **argv)
{
    DefaultFilesystem filesystem = DefaultFilesystem();
    process::DefaultContext processContext = process::DefaultContext();
    return acdriver::Driver::Run(&processContext, &filesystem);
}
Ejemplo n.º 3
0
int
main(int argc, char **argv, char **envp)
{
    DefaultFilesystem filesystem = DefaultFilesystem();
    process::DefaultContext processContext = process::DefaultContext();

    builtin::infoPlistUtility::Driver driver;
    return driver.run(&processContext, &filesystem);
}
Ejemplo n.º 4
0
int
main(int argc, char **argv)
{
    DefaultFilesystem filesystem = DefaultFilesystem();
    std::vector<std::string> args = std::vector<std::string>(argv + 1, argv + argc);

    /*
     * Parse out the options, or print help & exit.
     */
    Options options;
    std::pair<bool, std::string> result = libutil::Options::Parse<Options>(&options, args);
    if (!result.first) {
        return Help(result.second);
    }

    /*
     * Handle the various actions.
     */
    if (options.help()) {
        return Help();
    } else if (options.version()) {
        return Version();
    } else if (options.printPath()) {
        ext::optional<std::string> developer = xcsdk::Environment::DeveloperRoot(&filesystem);
        if (!developer) {
            fprintf(stderr, "error: no developer directory found\n");
            return 1;
        }

        fprintf(stdout, "%s\n", developer->c_str());
        return 0;
    } else if (options.resetPath()) {
        if (!xcsdk::Environment::WriteDeveloperRoot(&filesystem, ext::nullopt)) {
            fprintf(stderr, "error: failed to reset developer root. are you root?\n");
            return 1;
        }

        return 0;
    } else if (options.switchPath()) {
        if (!xcsdk::Environment::WriteDeveloperRoot(&filesystem, *options.switchPath())) {
            fprintf(stderr, "error: failed to set developer root. are you root?\n");
            return 1;
        }

        return 0;
    } else if (options.install()) {
        fprintf(stderr, "error: install not implemented\n");
        return 1;
    } else {
        return Help(std::string("no actions provided"));
    }
}
Ejemplo n.º 5
0
int
main(int argc, char **argv)
{
    DefaultFilesystem filesystem = DefaultFilesystem();

    if (argc < 2) {
        fprintf(stderr, "usage: %s path\n", argv[0]);
        return -1;
    }

    std::string path = argv[1];
    Manager::shared_ptr manager = Manager::Create();
    manager->registerDomains(&filesystem, { { "xcspec", path } });

    return 0;
}
Ejemplo n.º 6
0
TEST(copyStrings, InputOutputEncoding)
{
    std::unordered_map<std::string, plist::Format::Encoding> encodings = {
        { "utf-8", plist::Format::Encoding::UTF8 },
        { "utf-16", plist::Format::Encoding::UTF16LE },
        { "utf-32", plist::Format::Encoding::UTF32LE },
    };

    for (auto const &entry1 : encodings) {
        for (auto const &entry2 : encodings) {
            /* Convert input to each encoding. */
            MemoryFilesystem filesystem = MemoryFilesystem({
                MemoryFilesystem::Entry::File("in.strings", plist::Format::Encodings::Convert(
                    Contents("string = value;\n"),
                    plist::Format::Encoding::UTF8,
                    entry1.second
                )),
                MemoryFilesystem::Entry::Directory("output", { }),
            });

            Driver driver;
            EXPECT_EQ(0, driver.run({
                "in.strings",
                "--outdir", "output",
                "--inputencoding", entry1.first,
                "--outputencoding", entry2.first,
            }, { }, &filesystem, "/"));

            std::vector<uint8_t> contents;
            EXPECT_TRUE(filesystem.read(&contents, "output/in.strings"));

            /* Expect output in each encoding. */
            EXPECT_EQ(contents, plist::Format::Encodings::Convert(
                Contents("string = value;\n"),
                plist::Format::Encoding::UTF8,
                entry2.second
            ));
        }
    }
}
TEST(DirectoryDependencyInfo, Deserialize)
{
    MemoryFilesystem filesystem = MemoryFilesystem({
        MemoryFilesystem::Entry::Directory("root", {
            MemoryFilesystem::Entry::File("file1", { }),
            MemoryFilesystem::Entry::File("file2", { }),
            MemoryFilesystem::Entry::Directory("dir", {
                MemoryFilesystem::Entry::File("file3", { }),
            }),
        }),
    });

    auto info = DirectoryDependencyInfo::Deserialize(&filesystem, "/root");
    ASSERT_TRUE(info);
    EXPECT_EQ(info->dependencyInfo().inputs(), std::vector<std::string>({
        "/root/file1",
        "/root/file2",
        "/root/dir",
        "/root/dir/file3",
    }));
    EXPECT_TRUE(info->dependencyInfo().outputs().empty());
}
Ejemplo n.º 8
0
TEST(SimpleExecutor, PropagateToolResult)
{
    /* Create in-memory execution environment. */
    auto filesystem = MemoryFilesystem({
        MemoryFilesystem::Entry::File("fail-tool", std::vector<uint8_t>()),
        MemoryFilesystem::Entry::File("success-tool", std::vector<uint8_t>()),
    });

    auto launcher = process::MemoryLauncher({
        { "/fail-tool", [](Filesystem *filesystem, process::Context const *context) -> ext::optional<int> {
            return 1;
        } },
        { "/success-tool", [](Filesystem *filesystem, process::Context const *context) -> ext::optional<int> {
            return 0;
        } },
    });

    auto registry = builtin::Registry::Create({
        std::static_pointer_cast<builtin::Driver>(std::make_shared<Driver>("builtin-fail", [](process::Context const *context, Filesystem *filesystem) -> int {
            return 1;
        })),
        std::static_pointer_cast<builtin::Driver>(std::make_shared<Driver>("builtin-success", [](process::Context const *context, Filesystem *filesystem) -> int {
            return 0;
        })),
    });

    auto context = process::MemoryContext(
        "",
        "/",
        std::vector<std::string>(),
        std::unordered_map<std::string, std::string>(),
        0,
        0,
        "user",
        "group");

    /* Create invocations to execute. */
    auto builtinSuccess = pbxbuild::Tool::Invocation();
    builtinSuccess.executable() = pbxbuild::Tool::Invocation::Executable::Builtin("builtin-success");
    auto builtinFail = pbxbuild::Tool::Invocation();
    builtinFail.executable() = pbxbuild::Tool::Invocation::Executable::Builtin("builtin-fail");

    auto externalSuccess = pbxbuild::Tool::Invocation();
    externalSuccess.executable() = pbxbuild::Tool::Invocation::Executable::External("success-tool");
    auto externalFail = pbxbuild::Tool::Invocation();
    externalFail.executable() = pbxbuild::Tool::Invocation::Executable::External("fail-tool");

    /* Create test executor. */
    auto formatter = xcformatter::NullFormatter::Create();
    std::vector<std::string> const executablePaths = { "/" };
    SimpleExecutor executor = SimpleExecutor(formatter, false, registry);

    /* Succeed if all tools succeed. */
    auto success = executor.performInvocations(
        &context,
        &launcher,
        &filesystem,
        executablePaths,
        {
            builtinSuccess,
            externalSuccess,
        },
        false);
    ASSERT_TRUE(success.first);
    EXPECT_EQ(success.second.size(), 0);

    /* Fail if a tool fails. */
    auto fail1 = executor.performInvocations(
        &context,
        &launcher,
        &filesystem,
        executablePaths,
        {
            externalFail,
            builtinSuccess,
            externalSuccess,
        },
        false);
    ASSERT_FALSE(fail1.first);
    EXPECT_EQ(fail1.second.size(), 1);

    /* Fail if a tool fails, even if not first. */
    auto fail2 = executor.performInvocations(
        &context,
        &launcher,
        &filesystem,
        executablePaths,
        {
            builtinSuccess,
            builtinFail,
            externalSuccess,
            externalFail,
        },
        false);
    ASSERT_FALSE(fail2.first);
    EXPECT_EQ(fail2.second.size(), 1);
}
Ejemplo n.º 9
0
int
main(int argc, char **argv)
{
    DefaultFilesystem filesystem = DefaultFilesystem();
    process::DefaultContext processContext = process::DefaultContext();

    /*
     * Parse out the options, or print help & exit.
     */
    Options options;
    std::pair<bool, std::string> result = libutil::Options::Parse<Options>(&options, processContext.commandLineArguments());
    if (!result.first) {
        return Help(result.second);
    }

    /*
     * Handle the basic options.
     */
    if (options.help()) {
        return Help();
    } else if (options.version()) {
        return Version();
    }

    /*
     * Diagnose missing options.
     */
    if (options.inputs().empty() || !options.output() || !options.name()) {
        return Help("missing option(s)");
    }

    std::vector<std::string> inputs;
    for (std::pair<dependency::DependencyInfoFormat, std::string> const &input : options.inputs()) {
        /*
         * Load the dependency info.
         */
        std::vector<dependency::DependencyInfo> info;
        if (!LoadDependencyInfo(&filesystem, input.second, input.first, &info)) {
            return -1;
        }

        for (dependency::DependencyInfo const &dependencyInfo : info) {
            inputs.insert(inputs.end(), dependencyInfo.inputs().begin(), dependencyInfo.inputs().end());
        }
    }

    /*
     * Serialize the output.
     */
    std::string contents = SerializeMakefileDependencyInfo(processContext.currentDirectory(), *options.name(), inputs);

    /*
     * Write out the output.
     */
    std::vector<uint8_t> makefileContents = std::vector<uint8_t>(contents.begin(), contents.end());
    if (!filesystem.write(makefileContents, *options.output())) {
        return false;
    }

    return 0;
}