Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Build System Rewrite] Massive build speed improvement via scaninc changes #1954

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ MAKEFLAGS += --no-print-directory
.SECONDARY:
# Delete files that weren't built properly
.DELETE_ON_ERROR:
# Secondary expansion is required for dependency variables in object rules.
.SECONDEXPANSION:

RULES_NO_SCAN += libagbsyscall clean clean-assets tidy tidymodern tidynonmodern generated clean-generated
.PHONY: all rom modern compare
Expand Down Expand Up @@ -330,7 +328,10 @@ endef
# Calls SCANINC to find dependencies
define C_SCANINC
ifneq ($(NODEP),1)
$1.o: $2 $$(shell $(SCANINC) $(INCLUDE_SCANINC_ARGS) -I tools/agbcc/include -I gflib $2)
$1.o: $1.d
$1.d: $2
$(SCANINC) -M $1.d $(INCLUDE_SCANINC_ARGS) -I tools/agbcc/include -I gflib $2
include $1.d
endif
endef

Expand Down Expand Up @@ -359,7 +360,10 @@ endef

define ASM_SCANINC
ifneq ($(NODEP),1)
$1.o: $2 $$(shell $(SCANINC) $(INCLUDE_SCANINC_ARGS) -I "" $2)
$1.o: $1.d
$1.d: $2
$(SCANINC) -M $1.d $(INCLUDE_SCANINC_ARGS) -I "" $2
include $1.d
endif
endef

Expand Down
49 changes: 46 additions & 3 deletions tools/scaninc/scaninc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include <queue>
#include <set>
#include <string>
#include <iostream>
#include <tuple>
#include <fstream>
#include "scaninc.h"
#include "source_file.h"

Expand All @@ -38,15 +41,19 @@ bool CanOpenFile(std::string path)
return true;
}

const char *const USAGE = "Usage: scaninc [-I INCLUDE_PATH] FILE_PATH\n";
const char *const USAGE = "Usage: scaninc [-I INCLUDE_PATH] [-M DEPENDENCY_OUT_PATH] FILE_PATH\n";

int main(int argc, char **argv)
{
std::queue<std::string> filesToProcess;
std::set<std::string> dependencies;
std::set<std::string> dependencies_includes;

std::vector<std::string> includeDirs;

bool makeformat = false;
std::string make_outfile;

argc--;
argv++;

Expand All @@ -68,6 +75,13 @@ int main(int argc, char **argv)
}
includeDirs.push_back(includeDir);
}
else if(arg.substr(0, 2) == "-M")
{
makeformat = true;
argc--;
argv++;
make_outfile = std::string(argv[0]);
}
else
{
FATAL_ERROR(USAGE);
Expand Down Expand Up @@ -112,6 +126,7 @@ int main(int argc, char **argv)
{
path = include;
}
dependencies_includes.insert(path);
bool inserted = dependencies.insert(path).second;
if (inserted && exists)
{
Expand All @@ -121,8 +136,36 @@ int main(int argc, char **argv)
includeDirs.pop_back();
}

for (const std::string &path : dependencies)
if(!makeformat)
{
for (const std::string &path : dependencies)
{
std::printf("%s\n", path.c_str());
}
std::cout << std::endl;
}
else
{
std::printf("%s\n", path.c_str());
// Write out make rules to a file
std::ofstream output(make_outfile);

// Print a make rule for the object file
size_t ext_pos = make_outfile.find_last_of(".");
auto object_file = make_outfile.substr(0, ext_pos + 1) + "o";
output << object_file.c_str() << ": ";
for (const std::string &path : dependencies)
{
output << path << " ";
}

// Dependency list rule.
// Although these rules are identical, they need to be separate, else make will trigger the rule again after the file is created for the first time.
output << "\n" << make_outfile.c_str() << ": ";
for (const std::string &path : dependencies_includes)
{
output << path << " ";
}
output.flush();
output.close();
}
}