This commit is contained in:
Андреев Григорий 2024-07-26 21:06:13 +03:00
parent 269e76f59c
commit cd1c6b1b59

View File

@ -161,6 +161,12 @@ struct path_t {
}
};
mode_t get_umask(){
mode_t old = umask(0);
umask(old);
return old;
}
void createDir(const path_t& path) {
std::string cur_pref = std::string(path.is_relative ? "" : "/");
for (size_t i = 0; i < path.parts.size(); i++) {
@ -170,7 +176,7 @@ void createDir(const path_t& path) {
stat(cur_pref.c_str(), &info);
if (errno == ENOENT) {
/* User : reads, writes, executes; Other: reads, executes; */
int ret = mkdir(cur_pref.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
int ret = mkdir(cur_pref.c_str(), 0755);
ASSERT_on_iret(ret, "mkdir(\"" + cur_pref + "\")");
} else if (errno == 0) {
if (S_ISDIR(info.st_mode)) {
@ -332,7 +338,7 @@ void writeToFileDescriptor(int fd, const std::string& text, const std::string& d
/* Truncational */
void writeFile(const std::string& path, const std::string& text) {
int fd = open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0770);
int fd = open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0755);
ASSERT_on_iret(fd, "Opening \"" + path + "\"");
writeToFileDescriptor(fd, text, "file \"" + path + "\n");
}
@ -646,7 +652,7 @@ struct FileInstallBuildUnit: public BuildUnit {
// todo, fix that func and writeFile() so that output file is set to source size at the beginning
int rfd = open(((std::string)source).c_str(), O_RDONLY);
ASSERT_on_iret(rfd, "opening source file to read");
int wfd = open(((std::string)destination).c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0770);
int wfd = open(((std::string)destination).c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0755);
ASSERT_on_iret(wfd, "opening destination file to write");
char buf[2048];
int sz;
@ -919,9 +925,7 @@ struct CTarget {
std::vector<std::string> additional_compilation_flags;
std::vector<std::string> additional_linkage_flags;
/* Prefix for all cpp files in `units` array */
std::string units_dir;
/* .c and .cpp source files relative to the special src/${units_dir} directory*/
/* .c and .cpp source files relative to the special src directory*/
std::vector<std::string> units;
std::string include_pr;
@ -976,7 +980,7 @@ void check_pkg_conf_rel_install_path(const path_t& P) {
}
/* Argument `name` is just a name in `units` array, return value is relative to $IR/$TARGET_NAME/obj */
path_t c_unit_name_to_obj_filename(const std::string& units_dir, const std::string& PtoC) {
path_t c_unit_name_to_obj_filename(const std::string& PtoC) {
path_t P(PtoC);
assert(!P.parts.empty());
std::string& filename = P.parts.back();
@ -992,8 +996,8 @@ path_t c_unit_name_to_obj_filename(const std::string& units_dir, const std::stri
return P;
}
path_t c_unit_name_to_source_filename(const std::string& units_dir, const std::string& PtoC){
return path_t(units_dir) / PtoC;
path_t c_unit_name_to_source_filename(const std::string& PtoC){
return path_t(PtoC);
}
void load_ctargets_on_building_and_installing(
@ -1049,10 +1053,10 @@ void load_ctargets_on_building_and_installing(
size_t mk_personal_targ_dir_bu_id = add_bbu(new MkdirBuildUnit(path_t(proj_compiled_dir_path) / tg.name));
std::vector<size_t> all_comp_units_bu_ids;
auto BU_to_SOURCE_FILEPATH = [&](const std::string& bu) -> path_t {
return path_t(proj_src_dir_path) / c_unit_name_to_source_filename(tg.units_dir, bu);
return path_t(proj_src_dir_path) / c_unit_name_to_source_filename(bu);
};
auto BU_to_OBJ_FILEPATH = [&](const std::string& bu) -> path_t {
return path_t(proj_compiled_dir_path) / tg.name / "obj" / c_unit_name_to_obj_filename(tg.units_dir, bu);
return path_t(proj_compiled_dir_path) / tg.name / "obj" / c_unit_name_to_obj_filename(bu);
};
auto generate_cu_BUs = [&](const std::vector<std::string>& ctg_type_intrinsic_comp_args) {
const std::string comp_cmd = "g++"; // todo: think of some other way around