Browse Source

Only crawling source if the project will be built.

David Piuva 3 years ago
parent
commit
a8a2d6f8b0

+ 11 - 7
Source/tools/builder/Machine.cpp

@@ -100,7 +100,7 @@ static void inheritMachine(Machine &child, const Machine &parent) {
 	}
 }
 
-static void interpretLine(SessionContext &output, ProjectContext &context, Machine &target, List<String> &tokens, const dsr::ReadableString &fromPath) {
+static void interpretLine(SessionContext &output, Machine &target, List<String> &tokens, const dsr::ReadableString &fromPath) {
 	if (tokens.length() > 0) {
 		bool activeLine = target.activeStackDepth >= target.currentStackDepth;
 		/*
@@ -119,7 +119,7 @@ static void interpretLine(SessionContext &output, ProjectContext &context, Machi
 			if (string_caseInsensitiveMatch(first, U"import")) {
 				// Get path relative to importing script's path.
 				String importPath = PATH_EXPR(1, tokens.length() - 1);
-				evaluateScript(output, context, target, importPath);
+				evaluateScript(output, target, importPath);
 				if (tokens.length() > 2) { printText(U"Unused tokens after import!\n");}
 			} else if (string_caseInsensitiveMatch(first, U"if")) {
 				// Being if statement
@@ -134,7 +134,7 @@ static void interpretLine(SessionContext &output, ProjectContext &context, Machi
 				target.activeStackDepth = target.currentStackDepth;
 			} else if (string_caseInsensitiveMatch(first, U"crawl")) {
 				// The right hand expression is evaluated into a path relative to the build script and used as the root for searching for source code.
-				crawlSource(context, PATH_EXPR(1, tokens.length() - 1));
+				target.crawlOrigins.push(PATH_EXPR(1, tokens.length() - 1));
 			} else if (string_caseInsensitiveMatch(first, U"build")) {
 				// Build one or more other projects from a project file or folder path, as dependencies.
 				//   Having the same external project built twice during the same session is not allowed.
@@ -183,7 +183,7 @@ static void interpretLine(SessionContext &output, ProjectContext &context, Machi
 	tokens.clear();
 }
 
-void evaluateScript(SessionContext &output, ProjectContext &context, Machine &target, const ReadableString &scriptPath) {
+void evaluateScript(SessionContext &output, Machine &target, const ReadableString &scriptPath) {
 	if (file_getEntryType(scriptPath) != EntryType::File) {
 		printText(U"The script path ", scriptPath, U" does not exist!\n");
 	}
@@ -202,7 +202,7 @@ void evaluateScript(SessionContext &output, ProjectContext &context, Machine &ta
 		if (c == U'\n' || c == U'\0') {
 			// Comment removing everything else.
 			flushToken(currentLine, currentToken);
-			interpretLine(output, context, target, currentLine, projectFolderPath);
+			interpretLine(output, target, currentLine, projectFolderPath);
 			commented = false; // Automatically end comments at end of line.
 			quoted = false; // Automatically end quotes at end of line.
 		} else if (c == U'\"') {
@@ -211,7 +211,7 @@ void evaluateScript(SessionContext &output, ProjectContext &context, Machine &ta
 		} else if (c == U'#') {
 			// Comment removing everything else until a new line comes.
 			flushToken(currentLine, currentToken);
-			interpretLine(output, context, target, currentLine, projectFolderPath);
+			interpretLine(output, target, currentLine, projectFolderPath);
 			commented = true;
 		} else if (!commented) {
 			if (quoted) {
@@ -253,7 +253,7 @@ void buildProject(SessionContext &output, const ReadableString &projectFilePath,
 	// Evaluate compiler settings while searching for source code mentioned in the project and imported headers.
 	printText(U"Executing project file from ", projectFilePath, U".\n");
 	ProjectContext context;
-	evaluateScript(output, context, settings, projectFilePath);
+	evaluateScript(output, settings, projectFilePath);
 	// Find out where things are located.
 	String projectPath = file_getAbsoluteParentFolder(projectFilePath);
 	// Get the project's name.
@@ -271,6 +271,10 @@ void buildProject(SessionContext &output, const ReadableString &projectFilePath,
 		printText(U"Skipping build of ", projectFilePath, U" because the SkipIfBinaryExists flag was given and ", fullProgramPath, U" was found.\n");
 		return;
 	}
+	// Once we know where the binary is and that it should be built, we can start searching for source code.
+	for (int o = 0; o < settings.crawlOrigins.length(); o++) {
+		crawlSource(context, settings.crawlOrigins[o]);
+	}
 	// Once we are done finding all source files, we can resolve the dependencies to create a graph connected by indices.
 	resolveDependencies(context);
 	if (getFlagAsInteger(settings, U"ListDependencies")) {

+ 2 - 1
Source/tools/builder/Machine.h

@@ -19,6 +19,7 @@ struct Machine {
 	List<Flag> variables;
 	List<String> compilerFlags;
 	List<String> linkerFlags;
+	List<String> crawlOrigins;
 	// When activeStackDepth < currentStackDepth, we are skipping false cases.
 	int64_t currentStackDepth = 0; // How many scopes we are inside of, from the root script including all the others.
 	int64_t activeStackDepth = 0;
@@ -101,7 +102,7 @@ void assignValue(Machine &target, const dsr::ReadableString &key, const dsr::Rea
 
 // Modifies the flags in target, while listing source files to context, using the script in scriptPath.
 // Recursively including other scripts using the script's folder as the origin for relative paths.
-void evaluateScript(SessionContext &output, ProjectContext &context, Machine &target, const ReadableString &scriptPath);
+void evaluateScript(SessionContext &output, Machine &target, const ReadableString &scriptPath);
 
 // Build anything in projectPath.
 void build(SessionContext &output, const ReadableString &projectPath, Machine &settings);

+ 3 - 3
Source/tools/wizard/Wizard.DsrProj

@@ -1,6 +1,6 @@
 # This project will use both sound and graphics, so we default initialize them to 1 before evaluating the library's header.
 # The caller should provide the operating system's name (Windows, Linux)
-Message "Starting main.DsrProj\n"
+Message "Starting Wizard.DsrProj\n"
 
 # Give the Skip flag when compiling to only compile the wizard program itself.
 if !(Skip)
@@ -9,7 +9,7 @@ if !(Skip)
 	Build "../../templates" SkipIfBinaryExists Supressed
 end if
 
-Message "Done with building the examples and continuing with building main.DsrProj\n"
+Message "Done with building the examples and continuing with building Wizard.DsrProj\n"
 
 Graphics
 Sound
@@ -33,4 +33,4 @@ Crawl "main.cpp"
 # Enable to compile a debug version
 # Debug
 
-Message "Ending main.DsrProj\n"
+Message "Ending Wizard.DsrProj\n"