1 //
2 // aegis - project change supervisor
3 // Copyright (C) 1999, 2003-2008, 2012 Peter Miller
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published
7 // by the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 
19 #include <common/ac/assert.h>
20 
21 #include <libaegis/change/env_set.h>
22 #include <libaegis/change.h>
23 #include <libaegis/os.h>
24 #include <libaegis/pconf.fmtgen.h>
25 #include <libaegis/project.h>
26 #include <libaegis/sub.h>
27 
28 
29 void
change_run_build_command(change::pointer cp)30 change_run_build_command(change::pointer cp)
31 {
32     sub_context_ty  *scp;
33     pconf_ty        *pconf_data;
34     string_ty       *the_command;
35     string_ty       *id;
36 
37     assert(cp->reference_count >= 1);
38     assert(cp->cstate_data);
39     assert(cp->cstate_data->state == cstate_state_being_integrated);
40     pconf_data = change_pconf_get(cp, 1);
41     assert(pconf_data);
42     the_command = pconf_data->build_command;
43     assert(the_command);
44     if (!the_command)
45     {
46         assert(pconf_data->errpos);
47         scp = sub_context_new();
48         sub_var_set_string(scp, "File_Name", pconf_data->errpos);
49         sub_var_set_charstar(scp, "FieLD_Name", "build_command");
50         change_fatal
51         (
52             cp,
53             scp,
54             i18n("$filename: contains no \"$field_name\" field")
55         );
56         // NOTREACHED
57         sub_context_delete(scp);
58     }
59 
60     scp = sub_context_new();
61     sub_var_set_charstar(scp, "File_List", "");
62     sub_var_optional(scp, "File_List");
63     the_command = substitute(scp, cp, the_command);
64     sub_context_delete(scp);
65 
66     id = change_integration_directory_get(cp, 0);
67     change_env_set(cp, 1);
68     project_become(cp->pp);
69     os_execute(the_command, OS_EXEC_FLAG_NO_INPUT, id);
70     project_become_undo(cp->pp);
71     str_free(the_command);
72 }
73 
74 
75 // vim: set ts=8 sw=4 et :
76