#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/wait.h>
Go to the source code of this file.
Classes | |
struct | ref_ptr< T > |
struct | ref_ptr< T >::content |
struct | dependency_t |
struct | status_t |
struct | rule_t |
struct | client_t |
struct | log |
struct | log_auto_close |
Macros | |
#define | DEBUG if (debug.active) debug() |
#define | DEBUG_open log_auto_close auto_close; if (debug.active) debug(true) |
#define | DEBUG_close if ((auto_close.still_open = false), debug.active) debug(false) |
Typedefs | |
typedef int | socket_t |
typedef std::list< std::string > | string_list |
typedef std::set< std::string > | string_set |
typedef std::map< std::string, ref_ptr< dependency_t > > | dependency_map |
typedef std::map< std::string, string_list > | variable_map |
typedef std::map< std::string, status_t > | status_map |
typedef std::list< rule_t > | rule_list |
typedef std::map< std::string, ref_ptr< rule_t > > | rule_map |
typedef std::map< int, string_list > | job_targets_map |
typedef std::map< pid_t, int > | pid_job_map |
typedef std::list< client_t > | client_list |
Enumerations | |
enum | { INVALID_SOCKET = -1 } |
enum | status_e { Uptodate, Todo, Recheck, Running, Remade, Failed } |
enum | token_e { Word, Eol, Eof, Colon, Equal, Dollar, Rightpar, Comma } |
Functions | |
static void | child_sig_handler (int) |
static std::string | escape_string (std::string const &s) |
void | init_working_dir () |
static std::string | normalize_abs (std::string const &s) |
static std::string | normalize (std::string const &s) |
static void | normalize_list (string_list &l) |
static void | skip_spaces (std::istream &in) |
static void | skip_eol (std::istream &in) |
static token_e | next_token (std::istream &in) |
static std::string | read_word (std::istream &in) |
static string_list | read_words (std::istream &in) |
static void | execute_function (std::istream &in, std::string const &name, string_list &dest) |
static void | load_dependencies (std::istream &in) |
static void | load_dependencies () |
static void | load_rule (std::istream &in, std::string const &first) |
static void | save_dependencies () |
static void | load_rules () |
static void | substitute_pattern (std::string const &pat, string_list const &src, string_list &dst) |
static rule_t | find_generic_rule (std::string const &target) |
static rule_t | find_rule (std::string const &target) |
static status_t const & | get_status (std::string const &target) |
static void | update_status (std::string const &target) |
static bool | still_need_rebuild (std::string const &target) |
static void | complete_job (int job_id, bool success) |
static bool | run_script (int job_id, rule_t const &rule) |
static bool | start (std::string const &target, client_list::iterator ¤t) |
static void | complete_request (client_t &client, bool success) |
static bool | has_free_slots () |
static void | update_clients () |
static void | create_server () |
void | accept_client () |
void | server_loop () |
void | server_mode (string_list const &targets) |
void | client_mode (char *socket_name, string_list const &targets) |
void | usage (int exit_status) |
int | main (int argc, char *argv[]) |
Variables | |
static variable_map | variables |
static std::string | variable_block |
static dependency_map | dependencies |
static status_map | status |
static rule_list | generic_rules |
static rule_map | specific_rules |
static job_targets_map | job_targets |
static pid_job_map | job_pids |
static client_list | clients |
static int | max_active_jobs = 1 |
static bool | keep_going = false |
static int | running_jobs = 0 |
static int | waiting_jobs = 0 |
static int | job_counter = 0 |
static socket_t | socket_fd |
static bool | build_failure |
static char * | socket_name |
static std::string | first_target |
static bool | show_targets = true |
static bool | echo_scripts = false |
static time_t | now = time(NULL) |
static std::string | working_dir |
static volatile sig_atomic_t | got_SIGCHLD = 0 |
log | debug |
#define DEBUG if (debug.active) debug() |
Definition at line 636 of file remake.cpp.
Referenced by accept_client(), get_status(), load_dependencies(), load_rule(), load_rules(), and main().
#define DEBUG_close if ((auto_close.still_open = false), debug.active) debug(false) |
Definition at line 638 of file remake.cpp.
Referenced by accept_client(), complete_job(), get_status(), load_dependencies(), load_rule(), run_script(), start(), still_need_rebuild(), update_clients(), and update_status().
#define DEBUG_open log_auto_close auto_close; if (debug.active) debug(true) |
Definition at line 637 of file remake.cpp.
Referenced by accept_client(), client_mode(), complete_job(), complete_request(), create_server(), get_status(), load_dependencies(), load_rule(), load_rules(), run_script(), save_dependencies(), server_loop(), start(), still_need_rebuild(), update_clients(), and update_status().
typedef std::list<client_t> client_list |
Definition at line 465 of file remake.cpp.
typedef std::map<std::string, ref_ptr<dependency_t> > dependency_map |
Definition at line 395 of file remake.cpp.
typedef std::map<int, string_list> job_targets_map |
Definition at line 437 of file remake.cpp.
typedef std::map<pid_t, int> pid_job_map |
Definition at line 439 of file remake.cpp.
Definition at line 433 of file remake.cpp.
Definition at line 435 of file remake.cpp.
typedef int socket_t |
Definition at line 341 of file remake.cpp.
typedef std::map<std::string, status_t> status_map |
Definition at line 421 of file remake.cpp.
typedef std::list<std::string> string_list |
Definition at line 349 of file remake.cpp.
typedef std::set<std::string> string_set |
Definition at line 351 of file remake.cpp.
typedef std::map<std::string, string_list> variable_map |
Definition at line 397 of file remake.cpp.
anonymous enum |
enum status_e |
Build status of a target.
Definition at line 402 of file remake.cpp.
enum token_e |
void accept_client | ( | ) |
Accept a connection from a client, get the job it spawned from, get the targets, and mark them as dependencies of the job targets.
Definition at line 1866 of file remake.cpp.
Referenced by server_loop().
|
static |
Definition at line 589 of file remake.cpp.
Referenced by create_server().
void client_mode | ( | char * | socket_name, |
string_list const & | targets | ||
) |
Connect to the server socket_name, send a build request for targets, and exit with the status returned by the server.
Definition at line 2059 of file remake.cpp.
Referenced by main().
|
static |
Handle job completion.
Definition at line 1451 of file remake.cpp.
Referenced by complete_request(), run_script(), and server_loop().
|
static |
Send a reply to a client then remove it. If the client was a dependency client, start the actual script.
Definition at line 1653 of file remake.cpp.
Referenced by update_clients().
|
static |
Create a named unix socket that listens for build requests. Also set the REMAKE_SOCKET environment variable that will be inherited by all the job scripts.
Definition at line 1789 of file remake.cpp.
Referenced by server_mode().
|
static |
Return the original string if it does not contain any special characters, a quoted and escaped string otherwise.
Definition at line 644 of file remake.cpp.
Referenced by load_rules(), run_script(), and save_dependencies().
|
static |
Execute a built-in function name and append its result to dest.
Definition at line 871 of file remake.cpp.
Referenced by read_words().
|
static |
Find a generic rule matching target:
Definition at line 1242 of file remake.cpp.
Referenced by find_rule().
|
static |
Find a specific rule matching target. Return a generic one otherwise. If there is both a specific rule with an empty script and a generic rule, the generic one is returned after adding the dependencies of the specific one.
Definition at line 1278 of file remake.cpp.
Referenced by start().
|
static |
Compute and memoize the status of target:
Definition at line 1323 of file remake.cpp.
Referenced by server_mode(), and update_clients().
|
static |
Return whether there are slots for starting new jobs.
Definition at line 1686 of file remake.cpp.
Referenced by update_clients().
void init_working_dir | ( | ) |
|
static |
Load dependencies from in.
Definition at line 970 of file remake.cpp.
Referenced by load_dependencies(), main(), and server_mode().
|
static |
|
static |
Read a rule starting with target first, if nonempty. Store into generic_rules or specific_rules depending on its genericity.
Definition at line 1014 of file remake.cpp.
Referenced by load_rules().
|
static |
Load rules. If some rules have dependencies and non-generic targets, add these dependencies to the targets.
Definition at line 1157 of file remake.cpp.
Referenced by server_mode().
int main | ( | int | argc, |
char * | argv[] | ||
) |
This program behaves in two different ways.
Definition at line 2148 of file remake.cpp.
|
static |
Skip spaces and return the kind of the next token.
Definition at line 789 of file remake.cpp.
Referenced by execute_function(), load_rules(), and read_words().
|
static |
Normalize a target name.
Definition at line 706 of file remake.cpp.
Referenced by main(), and normalize_list().
|
static |
Normalize an absolute path with respect to the working directory. Paths outside the working subtree are left unchanged.
Definition at line 687 of file remake.cpp.
Referenced by normalize().
|
static |
Normalize the content of a list of targets.
Definition at line 755 of file remake.cpp.
Referenced by load_rule().
|
static |
Read a (possibly quoted) word.
Definition at line 825 of file remake.cpp.
Referenced by load_rules(), and read_words().
|
static |
Read a list of words, possibly executing functions.
Definition at line 929 of file remake.cpp.
Referenced by execute_function(), load_dependencies(), load_rule(), and load_rules().
|
static |
Execute the script from rule.
Definition at line 1484 of file remake.cpp.
Referenced by complete_request(), and start().
|
static |
Save all the dependencies in file .remake
.
Definition at line 1129 of file remake.cpp.
Referenced by server_mode().
void server_loop | ( | ) |
Loop until all the jobs have finished.
Definition at line 1951 of file remake.cpp.
Referenced by server_mode().
void server_mode | ( | string_list const & | targets | ) |
Load dependencies and rules, listen to client requests, and loop until all the requests have completed. If Remakefile is obsolete, perform a first run with it only, then reload the rules, and perform a second with the original clients.
Definition at line 2026 of file remake.cpp.
Referenced by main().
|
static |
Skip end of line.
Definition at line 777 of file remake.cpp.
Referenced by load_dependencies(), load_rule(), load_rules(), and next_token().
|
static |
Skip spaces.
Definition at line 767 of file remake.cpp.
Referenced by execute_function(), load_rule(), and next_token().
|
static |
Create a job for target according to the loaded rules. Mark all the targets from the rule as running and reset their dependencies. If the rule has dependencies, create a new client to build them just before current, and change current so that it points to it.
Definition at line 1620 of file remake.cpp.
Referenced by update_clients().
|
static |
Check if all the prerequisites of target ended being up-to-date.
Definition at line 1425 of file remake.cpp.
Referenced by complete_request().
|
static |
Substitute a pattern into a list of strings.
Definition at line 1226 of file remake.cpp.
Referenced by find_generic_rule().
|
static |
Update clients as long as there are free slots:
Definition at line 1699 of file remake.cpp.
Referenced by server_loop().
|
static |
Change the status of target to Remade or Uptodate depending on whether its modification time changed.
Definition at line 1392 of file remake.cpp.
Referenced by complete_job().
void usage | ( | int | exit_status | ) |
Display usage and exit with exit_status.
Definition at line 2123 of file remake.cpp.
Referenced by main().
|
static |
Whether the request of an original client failed.
Definition at line 560 of file remake.cpp.
Referenced by complete_request(), and server_mode().
|
static |
List of clients waiting for a request to complete. New clients are put to front, so that the build process is depth-first.
Definition at line 511 of file remake.cpp.
Referenced by accept_client(), server_loop(), server_mode(), start(), and update_clients().
log debug |
Definition at line 622 of file remake.cpp.
Referenced by log_auto_close::~log_auto_close().
|
static |
Map from targets to their known dependencies.
Definition at line 480 of file remake.cpp.
Referenced by accept_client(), get_status(), load_dependencies(), load_rule(), main(), run_script(), save_dependencies(), and still_need_rebuild().
|
static |
Whether script commands are echoed.
Definition at line 580 of file remake.cpp.
Referenced by main(), and run_script().
|
static |
Name of the first target of the first specific rule, used for default run.
Definition at line 570 of file remake.cpp.
Referenced by load_rule(), and server_mode().
|
static |
Set of generic rules loaded from Remakefile.
Definition at line 490 of file remake.cpp.
Referenced by find_generic_rule(), load_rule(), and server_mode().
|
static |
Definition at line 587 of file remake.cpp.
Referenced by child_sig_handler(), and server_loop().
|
static |
Global counter used to produce increasing job numbers.
Definition at line 550 of file remake.cpp.
Referenced by start().
|
static |
Map from jobs to shell pids.
Definition at line 505 of file remake.cpp.
Referenced by run_script(), and server_loop().
|
static |
Map from jobs to targets being built.
Definition at line 500 of file remake.cpp.
Referenced by accept_client(), complete_job(), and start().
|
static |
Whether to keep building targets in case of failure. Can be modified by the -k option.
Definition at line 523 of file remake.cpp.
Referenced by main(), and update_clients().
|
static |
Maximum number of parallel jobs (non-positive if unbounded). Can be modified by the -j option.
Definition at line 517 of file remake.cpp.
Referenced by has_free_slots(), and main().
|
static |
Definition at line 582 of file remake.cpp.
Referenced by update_status().
|
static |
Number of jobs currently running:
Definition at line 536 of file remake.cpp.
Referenced by has_free_slots(), run_script(), and server_loop().
|
static |
Whether a short message should be displayed for each target.
Definition at line 575 of file remake.cpp.
Referenced by main(), and run_script().
|
static |
Socket on which the server listens for client request.
Definition at line 555 of file remake.cpp.
Referenced by accept_client(), client_mode(), create_server(), server_loop(), and server_mode().
|
static |
Name of the server socket in the file system.
Definition at line 565 of file remake.cpp.
Referenced by create_server(), and server_mode().
|
static |
Map from targets to specific rules loaded from Remakefile.
Definition at line 495 of file remake.cpp.
Referenced by find_rule(), load_rule(), and server_mode().
|
static |
Map from targets to their build status.
Definition at line 485 of file remake.cpp.
Referenced by complete_job(), get_status(), server_loop(), server_mode(), start(), still_need_rebuild(), update_clients(), and update_status().
|
static |
Precomputed variable assignments for shell usage.
Definition at line 475 of file remake.cpp.
Referenced by load_rules(), and run_script().
|
static |
Map from variable names to their content.
Definition at line 470 of file remake.cpp.
Referenced by load_rules(), read_words(), and server_mode().
|
static |
Number of jobs currently waiting for a build request to finish:
Definition at line 544 of file remake.cpp.
Referenced by accept_client(), complete_request(), and has_free_slots().
|
static |
Definition at line 584 of file remake.cpp.
Referenced by init_working_dir(), normalize(), and normalize_abs().