Skip to content

Commit 615599c

Browse files
committed
v1.0.0
0 parents  commit 615599c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2973
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build/
2+
arch-build/
3+
debian-build/
4+
fedora-build/

CMakeLists.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
set(CMAKE_CXX_STANDARD 20)
4+
5+
project(defin LANGUAGES C CXX)
6+
7+
include(GNUInstallDirs)
8+
9+
add_executable(${PROJECT_NAME}
10+
main.cpp
11+
curate_missing.cpp
12+
fetch_dbmap.cpp
13+
fetch_pm.cpp
14+
fetch_headers.cpp
15+
json_parser_engine.cpp
16+
resolver.cpp
17+
auto_install.cpp
18+
)
19+
20+
target_link_directories(${PROJECT_NAME} PRIVATE tiny-process-library/build)
21+
22+
target_link_libraries(${PROJECT_NAME} tiny-process-library)
23+
24+
install(TARGETS ${PROJECT_NAME}
25+
26+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
27+
)
28+
29+
install(FILES json-db/header-llib.json json-db/llib-pkg_apt.json json-db/llib-pkg_pacman.json json-db/llib-pkg_dnf.json json-db/pm-cmd.json
30+
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}
31+
)

LICENSE.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Copyright (c) 2025 Umang Achalia
2+
3+
Permission is hereby granted to any individual or organization to **use** this software — including in commercial or proprietary environments — under the following conditions:
4+
5+
1. **Attribution is required.**
6+
Any use of this software — whether in source or binary form — must visibly acknowledge the original author:
7+
> "Powered by defin, created by Umang Achalia (2025)"
8+
9+
2. **Redistribution and modification are strictly prohibited.**
10+
You may not copy, fork, rehost, mirror, sublicense, repackage, or otherwise redistribute this software, in whole or in part, whether modified or unmodified.
11+
12+
3. **Permission to redistribute or modify will not be granted.**
13+
No exceptions will be made. Claims of special or written permission are invalid and shall be treated as violations of this license.
14+
15+
4. **The original license must remain attached** to all copies of this software, where usage is permitted under these terms (e.g. internal use with attribution).
16+
17+
---
18+
19+
### Third-Party Components
20+
21+
This project includes the following third-party library:
22+
23+
- **TinyProcessLibrary**
24+
Licensed under the MIT License
25+
See `LICENSE-tinyprocess.txt`
26+
27+
---
28+
29+
### JSON Database Exception
30+
31+
JSON mapping files located in the `json-db/` directory are **licensed separately** under the MIT License.
32+
See `json-db/LICENSE-json.txt` for terms. These files may be freely copied, reused, and contributed to.
33+
34+
---
35+
36+
### Disclaimer of Warranty
37+
38+
This software is provided **"as is"**, without warranty of any kind, express or implied.
39+
In no event shall the author be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from or in connection with the software or the use or other dealings in the software.
40+
41+
---
42+
43+
For legal inquiries or attribution clarification, contact:
44+

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# defin
2+
3+
**defin** is a system tool that detects and installs missing dependencies for C++ projects by analyzing `#include` directives.
4+
5+
6+
## 📄 License
7+
8+
- **Core code** is under a custom non-redistributable license. See [LICENSE.txt](./LICENSE.txt)
9+
- **JSON database** (`json-db/`) is licensed under the MIT License. See [json-db/LICENSE-json.txt](./json-db/LICENSE-json.txt)
10+
- Includes [TinyProcessLibrary](https://gitlab.com/eidheim/tiny-process-library), under the MIT License. See [tiny-process-library/LICENSE-tinyprocess.txt](./tiny-process-library/LICENSE-tinyprocess.txt)
11+
12+
13+
## Features
14+
15+
- Parses source code for missing headers
16+
- Maps includes to system packages via JSON
17+
- Installs packages using apt, pacman, and more
18+
- CLI-first, scriptable
19+
20+
21+
## 🐧 Compatibility
22+
23+
- Supported OS: **Linux** only
24+
- Tested on: Arch, Debian, Fedora (others may work)
25+
- Requires: CMake 3.10+, a C++17-compatible compiler, and a working package manager (e.g. apt, pacman, dnf)
26+
27+
28+
## Build and Install
29+
30+
```bash
31+
git clone https://github.com/umangsys-dev/defin
32+
cd defin
33+
cmake -B build
34+
cmake --build build
35+
sudo cmake --install build

auto_install.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "auto_install.hpp"
2+
3+
std::vector<std::string> install(std::vector<std::string> missing_list, std::unordered_map<std::string, std::unordered_map<std::string, std::string>> manager_map, std::string pacman){
4+
5+
std::vector<std::string> install_status;
6+
7+
std::vector<std::string> failed_installs;
8+
9+
std::string install_cmd = manager_map[pacman]["install"];
10+
11+
std::regex exp("\\{pkg\\}");
12+
13+
std::regex error_exp("([Ee]rror)*(E:)*");
14+
15+
std::cout << "fetching the following packages: " << std::endl;
16+
17+
for(auto& m : missing_list) std::cout << std::setw(5) << m << std::endl;
18+
19+
std::cout << "----------------------" << std::endl;
20+
21+
std::cout << "Total installs : " << missing_list.size() << std::endl;
22+
23+
for(auto& lib : missing_list){
24+
25+
std::string lib_specific_install_cmd = std::regex_replace(install_cmd, exp, lib);
26+
27+
std::string buff = "";
28+
29+
tiny::Process check(lib_specific_install_cmd, "", [&buff, &install_status, &error_exp](const char* bytes, size_t n){
30+
31+
buff.append(bytes, n);
32+
33+
}, [&buff, &install_status, &error_exp](const char* bytes, size_t n){
34+
35+
buff.append(bytes, n);
36+
});
37+
38+
int exit_code = check.get_exit_status();
39+
40+
if(std::regex_search(buff, error_exp) || exit_code != 0){
41+
std::cerr << "Error: failed to install the package: " << lib << std::endl;
42+
continue;
43+
}
44+
}
45+
46+
return install_status;
47+
}

auto_install.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include <iostream>
4+
#include <fstream>
5+
#include <string>
6+
#include <regex>
7+
#include <vector>
8+
#include <filesystem>
9+
#include <sstream>
10+
#include "tiny-process-library/process.hpp"
11+
12+
namespace tiny = TinyProcessLib;
13+
14+
std::vector<std::string> install(std::vector<std::string>, std::unordered_map<std::string, std::unordered_map<std::string, std::string>>, std::string);

curate_missing.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "curate_missing.hpp"
2+
3+
std::vector<std::string> get_missing_OR_present(std::vector<std::string> detected_libs, std::unordered_map<std::string, std::unordered_map<std::string, std::string>>json_map, std::string distro_name, std::string flag){
4+
5+
std::vector<std::string> missing_list;
6+
7+
std::vector<std::string> present_list;
8+
9+
std::string lib_found_cmd = json_map[distro_name]["find"];
10+
11+
const std::regex regex_missing("not");
12+
13+
const std::regex expr("\\{pkg\\}");
14+
15+
for(const auto& pkg : detected_libs){
16+
17+
std::string buff = "";
18+
19+
std::string distro_specific_cmd = std::regex_replace(lib_found_cmd, expr, pkg);
20+
21+
std::vector<std::string> cmd_storage = {distro_specific_cmd};
22+
23+
tiny::Process check(distro_specific_cmd, "", [&buff](const char* bytes, size_t n){
24+
25+
buff.append(bytes, n);
26+
27+
}, [&buff](const char* bytes, size_t n) {
28+
29+
buff.append(bytes, n);
30+
});
31+
32+
if(regex_search(buff, regex_missing)) missing_list.push_back(pkg);
33+
34+
else present_list.push_back(pkg);
35+
}
36+
37+
if(flag == "-p"){
38+
39+
std::cout << "packages found:" << std::endl;
40+
for(auto& m : present_list) std::cout << std::setw(15) << "" << m << std::endl;
41+
return present_list;
42+
}
43+
44+
45+
if(flag == "-m"){
46+
47+
std::cout << "missing packages:" << std::endl;
48+
for(auto& m : missing_list) std::cout << std::setw(15) << "" << m << std::endl;
49+
return missing_list;
50+
}
51+
}

curate_missing.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include <iostream>
4+
#include <fstream>
5+
#include <string>
6+
#include <regex>
7+
#include <sstream>
8+
#include <vector>
9+
#include "tiny-process-library/process.hpp"
10+
#include <iomanip>
11+
12+
namespace tiny = TinyProcessLib;
13+
14+
std::vector<std::string> get_missing_OR_present(std::vector<std::string>, std::unordered_map<std::string, std::unordered_map<std::string, std::string>>, std::string distro_name, std::string flag);

fetch_dbmap.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include "fetch_dbmap.hpp"
2+
3+
std::unordered_map<std::string, std::string> get_llib_OR_pkg_map(std::string json_filepath){
4+
5+
std::unordered_map<std::string, std::string> json_map;
6+
7+
const std::regex expr("\"(.+?)\" *: *\"(.+?)\"");
8+
9+
std::string line;
10+
11+
std::cout << line;
12+
13+
std::ifstream file(json_filepath);
14+
15+
std::ostringstream oss;
16+
17+
oss << file.rdbuf();
18+
19+
line = oss.str();
20+
21+
file.close();
22+
23+
std::string key = "hirenkyaku";
24+
25+
std::unordered_map<std::string, std::string> pass = {{key, line}};
26+
27+
json_map = jpeng::parse(pass, key, expr);
28+
29+
return json_map;
30+
31+
}
32+
33+
34+
std::unordered_map<std::string, std::unordered_map<std::string, std::string>> get_pm_map(std::string json_filepath){
35+
36+
std::unordered_map<std::string, std::unordered_map<std::string, std::string>> final_map;
37+
38+
std::ostringstream oss;
39+
40+
const std::regex bigger_expr("\"([a-z]+?)\" *: *(\\{\n+\t+\".+\",\n+\t+\".+\"\n+\t+\\})");
41+
42+
const std::regex expr("\"(.+?)\" *: *\"(.+?)\"");
43+
44+
std::string line = "";
45+
46+
std::ifstream file(json_filepath);
47+
48+
oss << file.rdbuf();
49+
50+
line = oss.str();
51+
52+
std::string key = "xianyang";
53+
54+
std::unordered_map<std::string, std::string> temp = {{key, line}};
55+
56+
std::unordered_map<std::string, std::string> intermediate_storage = jpeng::parse(temp, key, bigger_expr);
57+
58+
for(auto& m : intermediate_storage){
59+
60+
temp[key] = m.second;
61+
62+
std::unordered_map<std::string, std::string> cmd_map = jpeng::parse(temp, key, expr);
63+
64+
final_map.insert({m.first, cmd_map});
65+
}
66+
67+
return final_map;
68+
}

fetch_dbmap.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include <iostream>
4+
#include <fstream>
5+
#include <string>
6+
#include <regex>
7+
#include <sstream>
8+
#include <unordered_map>
9+
#include "json_parser_engine.hpp"
10+
#include <filesystem>
11+
12+
std::unordered_map<std::string, std::string> get_llib_OR_pkg_map(std::string json_filepath);
13+
14+
std::unordered_map<std::string, std::unordered_map<std::string, std::string>> get_pm_map(std::string json_filepath);

0 commit comments

Comments
 (0)