summaryrefslogtreecommitdiff
path: root/Userland/DevTools/HackStudio/ProjectBuilder.h
blob: bb2d97da2104f0f23932109ed71629a1dc2c7326 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * Copyright (c) 2022, Itamar S. <itamar8910@gmail.com>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include "AK/Error.h"
#include "Project.h"
#include "TerminalWrapper.h"
#include <AK/Noncopyable.h>
#include <LibCore/TempFile.h>

namespace HackStudio {
class ProjectBuilder {

    AK_MAKE_NONCOPYABLE(ProjectBuilder);

public:
    ProjectBuilder(NonnullRefPtr<TerminalWrapper>, Project const&);
    ~ProjectBuilder() = default;

    ErrorOr<void> build(StringView active_file);
    ErrorOr<void> run(StringView active_file);

private:
    enum class IsSerenityRepo {
        No,
        Yes
    };

    ErrorOr<void> build_serenity_component();
    ErrorOr<void> run_serenity_component();
    ErrorOr<void> initialize_build_directory();
    Optional<String> find_cmake_file_for(StringView file_path) const;
    String generate_cmake_file_content() const;
    ErrorOr<void> update_active_file(StringView active_file);
    String build_directory() const;

    struct LibraryInfo {
        String path;
        Vector<String> dependencies {};
    };
    static HashMap<String, NonnullOwnPtr<LibraryInfo>> get_defined_libraries();
    static void for_each_library_definition(Function<void(String, String)>);
    static void for_each_library_dependencies(Function<void(String, Vector<StringView>)>);
    static ErrorOr<String> component_name(StringView cmake_file_path);
    static ErrorOr<void> verify_cmake_is_installed();
    static ErrorOr<void> verify_make_is_installed();

    String m_project_root;
    Project const& m_project;
    NonnullRefPtr<TerminalWrapper> m_terminal;
    IsSerenityRepo m_is_serenity { IsSerenityRepo::No };
    String m_serenity_component_cmake_file;
    String m_serenity_component_name;
};
}