diff options
| -rw-r--r-- | libcppbuild.cc | 17 | ||||
| -rw-r--r-- | rebuild.cc | 18 | ||||
| -rw-r--r-- | rebuild.h | 2 | 
3 files changed, 22 insertions, 15 deletions
diff --git a/libcppbuild.cc b/libcppbuild.cc index 1174421..d3d8a51 100644 --- a/libcppbuild.cc +++ b/libcppbuild.cc @@ -44,6 +44,7 @@ int main(int argc, char* argv[])  	std::vector<std::string> remove_files;  	bool list_files{false};  	bool list_targets{false}; +	bool no_relaunch{false}; // true means no re-launch after rebuild.  	dg::Options opt;  	int key{128}; @@ -81,6 +82,7 @@ int main(int argc, char* argv[])  	opt.add("add", required_argument, 'a',  	        "Add specified file to the build configurations.",  	        [&]() { +		        no_relaunch = true;  		        add_files.push_back(optarg);  		        return 0;  	        }); @@ -88,6 +90,7 @@ int main(int argc, char* argv[])  	opt.add("remove", required_argument, 'r',  	        "Remove specified file from the build configurations.",  	        [&]() { +		        no_relaunch = true;  		        remove_files.push_back(optarg);  		        return 0;  	        }); @@ -95,6 +98,7 @@ int main(int argc, char* argv[])  	opt.add("list-files", no_argument, 'L',  	        "List files in the build configurations.",  	        [&]() { +		        no_relaunch = true;  		        list_files = true;  		        return 0;  	        }); @@ -102,6 +106,7 @@ int main(int argc, char* argv[])  	opt.add("list-targets", no_argument, 'l',  	        "List targets.",  	        [&]() { +		        no_relaunch = true;  		        list_targets = true;  		        return 0;  	        }); @@ -109,6 +114,7 @@ int main(int argc, char* argv[])  	opt.add("configure-cmd", no_argument, key++,  	        "Print commandline for last configure.",  	        [&]() { +		        no_relaunch = true;  		        print_configure_cmd = true;  		        return 0;  	        }); @@ -116,6 +122,7 @@ int main(int argc, char* argv[])  	opt.add("configure-db", no_argument, key++,  	        "Print entire configure parameter database.",  	        [&]() { +		        no_relaunch = true;  		        print_configure_db = true;  		        return 0;  	        }); @@ -123,6 +130,7 @@ int main(int argc, char* argv[])  	opt.add("database", required_argument, 'd',  	        "Write compilation database json file.",  	        [&]() { +		        no_relaunch = true;  		        write_compilation_database = true;  		        compilation_database = optarg;  		        return 0; @@ -167,8 +175,6 @@ Options:  		{  			std::cout << file << "\n";  		} - -		return 0;  	}  	if(!add_files.empty() || !remove_files.empty()) @@ -184,7 +190,7 @@ Options:  		}  		// Force rebuild if files were added -		recompileCheck(settings, 1, argv, true); +		recompileCheck(settings, 1, argv, true, no_relaunch == false);  	}  	recompileCheck(settings, argc, argv); @@ -203,7 +209,6 @@ Options:  				std::cout << task->name() << "\n";  			}  		} -		return 0;  	}  	if(write_compilation_database) @@ -234,7 +239,6 @@ Options:  	if(print_configure_cmd)  	{  		std::cout << getConfiguration("cmd") << "\n"; -		return 0;  	}  	if(print_configure_db) @@ -244,7 +248,6 @@ Options:  		{  			std::cout << config.first << ": " << config.second << "\n";  		} -		return 0;  	}  	for(auto task : all_tasks) @@ -256,7 +259,7 @@ Options:  	}  	bool build_all{true}; -	for(auto const &arg : opt.arguments()) +	for(const auto& arg : opt.arguments())  	{  		if(arg == "configure")  		{ @@ -54,7 +54,8 @@ int unreg(const char* location)  	return found;  } -void recompileCheck(const Settings& settings, int argc, char* argv[], bool force) +void recompileCheck(const Settings& settings, int argc, char* argv[], +                    bool force, bool relaunch_allowed)  {  	bool dirty{force}; @@ -64,7 +65,7 @@ void recompileCheck(const Settings& settings, int argc, char* argv[], bool force  	args.push_back("-std=c++17");  	args.push_back("-pthread"); -	std::filesystem::path binFile("cppbuild"); +	std::filesystem::path binFile(argv[0]);  	if(std::filesystem::exists(configurationFile))  	{ @@ -125,13 +126,16 @@ void recompileCheck(const Settings& settings, int argc, char* argv[], bool force  		}  		else  		{ -			std::cout << "Re-launch\n"; -			std::vector<std::string> args; -			for(int i = 1; i < argc; ++i) +			if(relaunch_allowed)  			{ -				args.push_back(argv[i]); +				std::cout << "Re-launch\n"; +				std::vector<std::string> args; +				for(int i = 1; i < argc; ++i) +				{ +					args.push_back(argv[i]); +				} +				exit(execute(argv[0], args, settings.verbose > 0));  			} -			exit(execute(argv[0], args, settings.verbose > 0));  		}  	}  } @@ -21,4 +21,4 @@ extern std::size_t numConfigFiles;  int unreg(const char* location);  void recompileCheck(const Settings& settings, int argc, char* argv[], -                    bool force = false); +                    bool force = false, bool relaunch_allowed = true);  | 
