use buildit dep file support
This commit is contained in:
parent
ec6d2bc303
commit
ed2bdc5c0a
108
build.c
108
build.c
@ -68,46 +68,6 @@ void RcIncludeListAppend(Arena *arena, RcIncludeList *l, D_Tag tag, String rc_ty
|
||||
++l->count;
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Depfile
|
||||
*
|
||||
* TODO: Migrate this to buildit
|
||||
* ========================== */
|
||||
|
||||
void AddDependenciesFromDepFile(D_Tag dep_file)
|
||||
{
|
||||
TempArena scratch = ScratchBeginNoConflict();
|
||||
|
||||
String dep_file_data = D_ReadAll(scratch.arena, dep_file);
|
||||
StringList patterns = { 0 };
|
||||
StringListAppend(scratch.arena, &patterns, Lit("\r\n"));
|
||||
StringListAppend(scratch.arena, &patterns, Lit("\n"));
|
||||
StringList lines = StringSplit(scratch.arena, dep_file_data, patterns);
|
||||
D_Tag file = { 0 };
|
||||
for (StringListNode *dn = lines.first; dn; dn = dn->next) {
|
||||
String line = dn->string;
|
||||
line = StringReplace(scratch.arena, line, Lit("\\ "), Lit(" "));
|
||||
if (StringEndsWith(line, Lit(" \\"))) {
|
||||
line.len -= 2;
|
||||
}
|
||||
if (StringBeginsWith(line, Lit(" "))) {
|
||||
line.len -= 2;
|
||||
line.text += 2;
|
||||
}
|
||||
if (StringEndsWith(line, Lit(":"))) {
|
||||
line.len -= 1;
|
||||
}
|
||||
if (file.full_path.len == 0) {
|
||||
file = D_FileTagFromPath(scratch.arena, line);
|
||||
} else {
|
||||
D_Tag dependency = D_FileTagFromPath(scratch.arena, line);
|
||||
D_AddDependency(file, dependency);
|
||||
}
|
||||
}
|
||||
|
||||
ScratchEnd(scratch);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Build
|
||||
* ========================== */
|
||||
@ -213,22 +173,22 @@ void OnBuild(StringList cli_args)
|
||||
Bool should_embed_res_dir = !arg_developer;
|
||||
Bool should_embed_in_rc = !!arg_msvc;
|
||||
|
||||
D_Tag executable_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/PowerPlay.exe"), FmtStr(out_bin_dir_path)));
|
||||
D_Tag res_dir = D_DirTagFromPath(&arena, Lit("res"));
|
||||
D_Tag shaders_dir = D_DirTagFromPath(&arena, Lit("src/shaders"));
|
||||
D_Tag icon_file = D_FileTagFromPath(&arena, Lit("icon.ico"));
|
||||
D_Tag executable_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/PowerPlay.exe"), FmtStr(out_bin_dir_path)), D_TagKind_File);
|
||||
D_Tag res_dir = D_TagFromPath(&arena, Lit("res"), D_TagKind_Dir);
|
||||
D_Tag shaders_dir = D_TagFromPath(&arena, Lit("src/shaders"), D_TagKind_Dir);
|
||||
D_Tag icon_file = D_TagFromPath(&arena, Lit("icon.ico"), D_TagKind_File);
|
||||
|
||||
D_Tag inc_src_file = D_FileTagFromPath(&arena, Lit("src/inc.c"));
|
||||
D_Tag rc_res_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/rc.res"), FmtStr(out_obj_dir_path)));
|
||||
D_Tag inc_src_file = D_TagFromPath(&arena, Lit("src/inc.c"), D_TagKind_File);
|
||||
D_Tag rc_res_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/rc.res"), FmtStr(out_obj_dir_path)), D_TagKind_File);
|
||||
|
||||
#if 0
|
||||
D_Tag pch_header_file = D_FileTagFromPath(&arena, Lit("src/common.h"));
|
||||
D_Tag pch_c_src_gen_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.c"), FmtStr(out_obj_dir_path)));
|
||||
D_Tag pch_cpp_src_gen_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp"), FmtStr(out_obj_dir_path)));
|
||||
D_Tag pch_c_src_gen_obj_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.c.obj"), FmtStr(out_obj_dir_path)));
|
||||
D_Tag pch_cpp_src_gen_obj_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp.obj"), FmtStr(out_obj_dir_path)));
|
||||
D_Tag pch_c_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.c.pch"), FmtStr(out_obj_dir_path)));
|
||||
D_Tag pch_cpp_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp.pch"), FmtStr(out_obj_dir_path)));
|
||||
D_Tag pch_header_file = D_TagFromPath(&arena, Lit("src/common.h"), D_TagKind_File);
|
||||
D_Tag pch_c_src_gen_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/common.c"), FmtStr(out_obj_dir_path)), D_TagKind_File);
|
||||
D_Tag pch_cpp_src_gen_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp"), FmtStr(out_obj_dir_path)), D_TagKind_File);
|
||||
D_Tag pch_c_src_gen_obj_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/common.c.obj"), FmtStr(out_obj_dir_path)), D_TagKind_File);
|
||||
D_Tag pch_cpp_src_gen_obj_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp.obj"), FmtStr(out_obj_dir_path)), D_TagKind_File);
|
||||
D_Tag pch_c_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/common.c.pch"), FmtStr(out_obj_dir_path)), D_TagKind_File);
|
||||
D_Tag pch_cpp_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp.pch"), FmtStr(out_obj_dir_path)), D_TagKind_File);
|
||||
#endif
|
||||
|
||||
/* ========================== *
|
||||
@ -440,8 +400,8 @@ void OnBuild(StringList cli_args)
|
||||
* ========================== */
|
||||
|
||||
D_TagList tar_input_dirs = { 0 };
|
||||
D_Tag rc_input_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/rc.rc"), FmtStr(out_inc_dir_path)));;
|
||||
D_Tag pch_header_file = D_FileTagFromPath(&arena, Lit("src/common.h"));
|
||||
D_Tag rc_input_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/rc.rc"), FmtStr(out_inc_dir_path)), D_TagKind_File);
|
||||
D_Tag pch_header_file = D_TagFromPath(&arena, Lit("src/common.h"), D_TagKind_File);
|
||||
D_TagList src_input_files = { 0 };
|
||||
|
||||
/* Append tar input dirs */
|
||||
@ -473,7 +433,7 @@ void OnBuild(StringList cli_args)
|
||||
|
||||
/* Append 'src' dir c & cpp files */
|
||||
{
|
||||
D_Tag src_dir = D_DirTagFromPath(&arena, Lit("src"));
|
||||
D_Tag src_dir = D_TagFromPath(&arena, Lit("src"), D_TagKind_Dir);
|
||||
D_TagList src_dir_files = D_GetDirContents(&arena, src_dir);
|
||||
for (D_TagListNode *n = src_dir_files.first; n; n = n->next) {
|
||||
Bool ignore = true;
|
||||
@ -482,7 +442,7 @@ void OnBuild(StringList cli_args)
|
||||
String path = file.full_path;
|
||||
String name = D_GetName(file);
|
||||
String extension = StringPathExtension(name);
|
||||
Bool is_dir = file.is_dir;
|
||||
Bool is_dir = file.kind == D_TagKind_Dir;
|
||||
Bool is_c = !is_dir && StringEqual(extension, Lit("c"));
|
||||
Bool is_cpp = !is_dir && !is_c && StringEqual(extension, Lit("cpp"));
|
||||
if (is_c || is_cpp) {
|
||||
@ -505,14 +465,6 @@ void OnBuild(StringList cli_args)
|
||||
|
||||
if (!ignore) {
|
||||
D_TagListAppend(&arena, &src_input_files, file);
|
||||
|
||||
D_Tag dep_file;
|
||||
{
|
||||
String name_no_extension = StringPathNoExtension(name);
|
||||
String dep_file_path = StringF(&arena, Lit("%F/%F.%F"), FmtStr(out_obj_dir_path), FmtStr(name_no_extension), FmtStr(dep_file_extension));
|
||||
dep_file = D_FileTagFromPath(&arena, dep_file_path);
|
||||
}
|
||||
AddDependenciesFromDepFile(dep_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -527,7 +479,7 @@ void OnBuild(StringList cli_args)
|
||||
/* Build tar files */
|
||||
for (D_TagListNode *n = tar_input_dirs.first; n; n = n->next) {
|
||||
D_Tag input_dir = n->tag;
|
||||
D_Tag tar_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/%F.tar"), FmtStr(out_inc_dir_path), FmtStr(D_GetName(input_dir))));
|
||||
D_Tag tar_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/%F.tar"), FmtStr(out_inc_dir_path), FmtStr(D_GetName(input_dir))), D_TagKind_File);
|
||||
D_AddDependency(tar_file, input_dir);
|
||||
if (should_embed_in_rc) {
|
||||
D_AddDependency(rc_res_file, tar_file);
|
||||
@ -561,10 +513,20 @@ void OnBuild(StringList cli_args)
|
||||
String pch_c_compile_args_fmt = StringFromStringLists(&arena, Lit(" "), pch_c_compile_args, compile_warnings, compile_and_link_args, compile_args);
|
||||
String pch_cpp_compile_args_fmt = StringFromStringLists(&arena, Lit(" "), pch_cpp_compile_args, compile_warnings, compile_and_link_args, compile_args);
|
||||
|
||||
D_Tag pch_c_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/%F.c_pch"), FmtStr(out_obj_dir_path), FmtStr(D_GetName(pch_header_file))));
|
||||
D_Tag pch_cpp_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/%F.cpp_pch"), FmtStr(out_obj_dir_path), FmtStr(D_GetName(pch_header_file))));
|
||||
D_Tag dep_file;
|
||||
{
|
||||
String name = D_GetName(pch_header_file);
|
||||
String dep_file_path = StringF(&arena, Lit("%F/%F.%F"), FmtStr(out_obj_dir_path), FmtStr(name), FmtStr(dep_file_extension));
|
||||
dep_file = D_TagFromPath(&arena, dep_file_path, D_TagKind_DepFile);
|
||||
}
|
||||
|
||||
D_Tag pch_c_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/%F.c_pch"), FmtStr(out_obj_dir_path), FmtStr(D_GetName(pch_header_file))), D_TagKind_File);
|
||||
D_AddDependency(pch_c_file, pch_header_file);
|
||||
D_AddDependency(pch_c_file, dep_file);
|
||||
|
||||
D_Tag pch_cpp_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/%F.cpp_pch"), FmtStr(out_obj_dir_path), FmtStr(D_GetName(pch_header_file))), D_TagKind_File);
|
||||
D_AddDependency(pch_cpp_file, pch_header_file);
|
||||
D_AddDependency(pch_cpp_file, dep_file);
|
||||
|
||||
if (arg_msvc) {
|
||||
#if 0
|
||||
@ -608,13 +570,21 @@ void OnBuild(StringList cli_args)
|
||||
Bool is_c = StringEqual(extension, Lit("c"));
|
||||
Bool is_cpp = !is_c && StringEqual(extension, Lit("cpp"));
|
||||
|
||||
D_Tag dep_file;
|
||||
{
|
||||
String name_no_extension = StringPathNoExtension(name);
|
||||
String dep_file_path = StringF(&arena, Lit("%F/%F.%F"), FmtStr(out_obj_dir_path), FmtStr(name_no_extension), FmtStr(dep_file_extension));
|
||||
dep_file = D_TagFromPath(&arena, dep_file_path, D_TagKind_DepFile);
|
||||
}
|
||||
|
||||
D_Tag obj_file;
|
||||
{
|
||||
String name_no_extension = StringPathNoExtension(name);
|
||||
String obj_file_path = StringF(&arena, Lit("%F/%F.%F"), FmtStr(out_obj_dir_path), FmtStr(name_no_extension), FmtStr(obj_file_extension));
|
||||
obj_file = D_FileTagFromPath(&arena, obj_file_path);
|
||||
obj_file = D_TagFromPath(&arena, obj_file_path, D_TagKind_File);
|
||||
}
|
||||
D_AddDependency(obj_file, file);
|
||||
D_AddDependency(obj_file, dep_file);
|
||||
|
||||
if (D_IsDirty(obj_file, &hist)) {
|
||||
String comp_cmd_fmt = is_c ? c_compile_args_fmt : cpp_compile_args_fmt;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user