#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 | assign_t |
struct | rule_t |
struct | client_t |
struct | log |
struct | log_auto_close |
struct | escape_string |
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< assign_t > | assign_list |
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 | { Unexpected = 0, Word = 1 << 1, Colon = 1 << 2, Equal = 1 << 3, Dollarpar = 1 << 4, Rightpar = 1 << 5, Comma = 1 << 6, Plusequal = 1 << 7 } |
Functions | |
static void | sigchld_handler (int) |
static void | sigint_handler (int) |
static std::ostream & | operator<< (std::ostream &out, escape_string const &se) |
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_empty (std::istream &in) |
static bool | skip_eol (std::istream &in, bool multi=false) |
static int | expect_token (std::istream &in, int mask) |
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 | register_transparent_rule (rule_t const &rule) |
static void | register_scripted_rule (rule_t const &rule) |
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 bool | handle_clients () |
static void | create_server () |
void | accept_client () |
void | finalize_job (pid_t pid, bool res) |
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 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 693 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 695 of file remake.cpp.
Referenced by accept_client(), complete_job(), get_status(), handle_clients(), load_dependencies(), load_rule(), run_script(), start(), still_need_rebuild(), and update_status().
#define DEBUG_open log_auto_close auto_close; if (debug.active) debug(true) |
Definition at line 694 of file remake.cpp.
Referenced by accept_client(), client_mode(), complete_job(), complete_request(), create_server(), get_status(), handle_clients(), load_dependencies(), load_rule(), load_rules(), run_script(), save_dependencies(), server_loop(), start(), still_need_rebuild(), and update_status().
typedef std::list<assign_t> assign_list |
Definition at line 473 of file remake.cpp.
typedef std::list<client_t> client_list |
Definition at line 518 of file remake.cpp.
typedef std::map<std::string, ref_ptr<dependency_t> > dependency_map |
Definition at line 435 of file remake.cpp.
typedef std::map<int, string_list> job_targets_map |
Definition at line 490 of file remake.cpp.
typedef std::map<pid_t, int> pid_job_map |
Definition at line 492 of file remake.cpp.
Definition at line 486 of file remake.cpp.
Definition at line 488 of file remake.cpp.
typedef int socket_t |
Definition at line 381 of file remake.cpp.
typedef std::map<std::string, status_t> status_map |
Definition at line 461 of file remake.cpp.
typedef std::list<std::string> string_list |
Definition at line 389 of file remake.cpp.
typedef std::set<std::string> string_set |
Definition at line 391 of file remake.cpp.
typedef std::map<std::string, string_list> variable_map |
Definition at line 437 of file remake.cpp.
anonymous enum |
anonymous enum |
Enumerator | |
---|---|
Unexpected | |
Word | |
Colon | |
Equal | |
Dollarpar | |
Rightpar | |
Comma | |
Plusequal |
Definition at line 874 of file remake.cpp.
enum status_e |
Build status of a target.
Definition at line 442 of file remake.cpp.
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 2080 of file remake.cpp.
Referenced by server_loop().
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 2277 of file remake.cpp.
Referenced by main().
|
static |
Handle job completion.
Definition at line 1617 of file remake.cpp.
Referenced by complete_request(), finalize_job(), and run_script().
|
static |
Send a reply to a client then remove it. If the client was a dependency client, start the actual script.
Definition at line 1846 of file remake.cpp.
Referenced by handle_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 2000 of file remake.cpp.
Referenced by server_mode().
|
static |
Execute a built-in function name and append its result to dest.
Definition at line 983 of file remake.cpp.
Referenced by read_words().
|
static |
Skip spaces and peek at the next token. If it is one of mask, skip it (if it is not Word) and return it.
Definition at line 892 of file remake.cpp.
Referenced by execute_function(), load_rule(), load_rules(), and read_words().
void finalize_job | ( | pid_t | pid, |
bool | res | ||
) |
Handle child process exit status.
Definition at line 2165 of file remake.cpp.
Referenced by server_loop().
|
static |
Find a generic rule matching target:
Definition at line 1404 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 1440 of file remake.cpp.
Referenced by start().
|
static |
Compute and memoize the status of target:
Definition at line 1489 of file remake.cpp.
Referenced by handle_clients(), and server_mode().
|
static |
Handle client requests:
Definition at line 1896 of file remake.cpp.
Referenced by server_loop().
|
static |
Return whether there are slots for starting new jobs.
Definition at line 1879 of file remake.cpp.
Referenced by handle_clients().
void init_working_dir | ( | ) |
|
static |
Load dependencies from in.
Definition at line 1077 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 1199 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 1338 of file remake.cpp.
Referenced by server_mode().
int main | ( | int | argc, |
char * | argv[] | ||
) |
This program behaves in two different ways.
Definition at line 2366 of file remake.cpp.
|
static |
Normalize a target name.
Definition at line 782 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 763 of file remake.cpp.
Referenced by normalize().
|
static |
Normalize the content of a list of targets.
Definition at line 831 of file remake.cpp.
Referenced by load_rule().
|
static |
Write the string in se to out if it does not contain any special characters, a quoted and escaped string otherwise.
Definition at line 712 of file remake.cpp.
|
static |
Read a (possibly quoted) word.
Definition at line 937 of file remake.cpp.
Referenced by load_rule(), load_rules(), and read_words().
|
static |
Read a list of words, possibly executing functions.
Definition at line 1039 of file remake.cpp.
Referenced by execute_function(), load_dependencies(), load_rule(), and load_rules().
|
static |
Register a specific rule with a nonempty script:
Definition at line 1169 of file remake.cpp.
Referenced by load_rule().
|
static |
Register a specific rule with an empty script:
Definition at line 1125 of file remake.cpp.
Referenced by load_rule().
|
static |
Execute the script from rule.
Definition at line 1650 of file remake.cpp.
Referenced by complete_request(), and start().
|
static |
Save all the dependencies in file .remake
.
Definition at line 1310 of file remake.cpp.
Referenced by server_mode().
void server_loop | ( | ) |
Loop until all the jobs have finished.
Definition at line 2180 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 2241 of file remake.cpp.
Referenced by main().
|
static |
Definition at line 639 of file remake.cpp.
Referenced by create_server().
|
static |
|
static |
Skip empty lines.
Definition at line 853 of file remake.cpp.
Referenced by load_dependencies(), load_rules(), and skip_eol().
|
static |
Skip end of line. If multi is true, skip the following empty lines too.
Definition at line 864 of file remake.cpp.
Referenced by expect_token(), load_rule(), and load_rules().
|
static |
Skip spaces.
Definition at line 843 of file remake.cpp.
Referenced by execute_function(), expect_token(), and load_rule().
|
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 1813 of file remake.cpp.
Referenced by handle_clients().
|
static |
Check if all the prerequisites of target ended being up-to-date.
Definition at line 1591 of file remake.cpp.
Referenced by complete_request().
|
static |
Substitute a pattern into a list of strings.
Definition at line 1388 of file remake.cpp.
Referenced by find_generic_rule().
|
static |
Change the status of target to Remade or Uptodate depending on whether its modification time changed.
Definition at line 1558 of file remake.cpp.
Referenced by complete_job().
void usage | ( | int | exit_status | ) |
Display usage and exit with exit_status.
Definition at line 2341 of file remake.cpp.
Referenced by main().
|
static |
Whether the request of an original client failed.
Definition at line 608 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 559 of file remake.cpp.
Referenced by accept_client(), handle_clients(), server_loop(), server_mode(), and start().
log debug |
Definition at line 679 of file remake.cpp.
Referenced by log_auto_close::~log_auto_close().
|
static |
Map from targets to their known dependencies.
Definition at line 528 of file remake.cpp.
Referenced by accept_client(), get_status(), load_dependencies(), main(), register_scripted_rule(), register_transparent_rule(), run_script(), save_dependencies(), and still_need_rebuild().
|
static |
Whether script commands are echoed.
Definition at line 630 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 620 of file remake.cpp.
Referenced by load_rule(), and server_mode().
|
static |
Set of generic rules loaded from Remakefile.
Definition at line 538 of file remake.cpp.
Referenced by find_generic_rule(), load_rule(), and server_mode().
|
static |
Definition at line 637 of file remake.cpp.
Referenced by server_loop(), and sigchld_handler().
|
static |
Global counter used to produce increasing job numbers.
Definition at line 598 of file remake.cpp.
Referenced by start().
|
static |
Map from jobs to shell pids.
Definition at line 553 of file remake.cpp.
Referenced by finalize_job(), run_script(), and server_loop().
|
static |
Map from jobs to targets being built.
Definition at line 548 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 571 of file remake.cpp.
Referenced by handle_clients(), main(), and sigint_handler().
|
static |
Maximum number of parallel jobs (non-positive if unbounded). Can be modified by the -j option.
Definition at line 565 of file remake.cpp.
Referenced by has_free_slots(), and main().
|
static |
Definition at line 632 of file remake.cpp.
Referenced by update_status().
|
static |
Number of jobs currently running:
Definition at line 584 of file remake.cpp.
Referenced by finalize_job(), handle_clients(), has_free_slots(), and run_script().
|
static |
Whether a short message should be displayed for each target.
Definition at line 625 of file remake.cpp.
Referenced by main(), and run_script().
|
static |
Socket on which the server listens for client request.
Definition at line 603 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 614 of file remake.cpp.
Referenced by create_server(), and server_mode().
|
static |
Map from targets to specific rules loaded from Remakefile.
Definition at line 543 of file remake.cpp.
Referenced by find_rule(), register_scripted_rule(), register_transparent_rule(), and server_mode().
|
static |
Map from targets to their build status.
Definition at line 533 of file remake.cpp.
Referenced by complete_job(), get_status(), handle_clients(), server_loop(), server_mode(), start(), still_need_rebuild(), and update_status().
|
static |
Map from variable names to their content.
Definition at line 523 of file remake.cpp.
Referenced by load_rules(), read_words(), run_script(), and server_mode().
|
static |
Number of jobs currently waiting for a build request to finish:
Definition at line 592 of file remake.cpp.
Referenced by accept_client(), complete_request(), handle_clients(), and has_free_slots().
|
static |
Definition at line 634 of file remake.cpp.
Referenced by init_working_dir(), normalize(), and normalize_abs().