annotate build-tool/bob.d @ 134:89e8b0d92f36

Ported to bob2 !!!
author David Bryant <bagnose@gmail.com>
date Thu, 02 Aug 2012 17:20:52 +0930
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
134
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1 // Copyright Graham St Jack
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2 module bob;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
3
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
4 import std.stdio;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
5 import std.ascii;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
6 import std.string;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
7 import std.format;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
8 import std.process;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
9 import std.algorithm;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
10 import std.range;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
11 import std.file;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
12 import std.path;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
13 import std.conv;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
14 import std.datetime;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
15 import std.getopt;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
16 import std.concurrency;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
17 import std.functional;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
18 import std.exception;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
19
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
20 import core.sys.posix.sys.wait;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
21 import core.sys.posix.signal;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
22
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
23
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
24 /*========================================================================
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
25
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
26 A build tool suitable for C/C++ and D code, written in D.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
27
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
28 Objectives of this build tool are:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
29 * Easy to write and maintain build scripts (Bobfiles):
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
30 - Simple syntax.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
31 - Automatic determination of which in-project libraries to link.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
32 * Auto execution and evaluation of unit tests.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
33 * Enforcement of dependency rules.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
34 * Support for building source code from multiple repositories.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
35 * Support for C/C++ and D.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
36 * Support for code generation:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
37 - A source file isn't scanned for imports/includes until after it is up to date.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
38 - Dependencies inferred from these imports are automatically applied.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
39
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
40
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
41 Directory Structure
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
42 -------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
43
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
44 The source code is arranged into repositories, and within repositories
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
45 into packages which correspond to the directory structure.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
46
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
47 Packages should contain not only library source code, but also tests, utilities,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
48 documentation and data. The intention is to make packages easily reusable
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
49 by putting all their pieces in one location.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
50
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
51 A typical directory structure is:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
52
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
53 repo repository
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
54 |
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
55 +--package-name package's Bobfile and library source
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
56 |
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
57 +--doc the package's documentation
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
58 +--data data files needed by the package
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
59 +--test source code for automated regression tests
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
60 +--util source code for non-test executables
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
61 |
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
62 +--child-package(s)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
63
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
64
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
65 Dependency rules
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
66 ----------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
67
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
68 Files and their owning packages are arranged in a tree with cross-linking
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
69 dependencies. Each node in the tree can be public or protected. The root of the
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
70 tree contains its children publicly.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
71
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
72 The dependency rules are:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
73 * A protected node can only be referred to by sibling nodes or nodes contained
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
74 by those siblings.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
75 * A node can only refer to another node if its parent transitively refers to or
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
76 transitively contains that other node.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
77 * Circular dependencies are not allowed.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
78
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
79 An object file can only be used once - either in a library or an executable.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
80 Dynamic libraries don't count as a use - they are just a repackaging.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
81
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
82 A dynamic library cannot contain the same static library as another dynamic library.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
83
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
84
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
85 Configure
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
86 ---------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
87
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
88 Bundled with bob is a configure procedure that is mainly implemented in
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
89 configure_functions.d. Each project contains a configure.d program that
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
90 is invoked via a configure.sh script.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
91
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
92 Configure establishes a build directory complete with scripts necessary
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
93 to build and run a project.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
94
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
95 Refer to configure_functions.d for details.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
96
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
97
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
98 Bobfiles
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
99 --------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
100
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
101 Each package has a Bobfile. On start, bob (the builder) reads the
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
102 Bobfile specified in the Boboptions file and follows its directives.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
103
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
104 Bobfiles must refer to things in dependency order, so that anything referred
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
105 to is defined earlier.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
106
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
107
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
108 General rule format in Bobfiles is:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
109
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
110 # This line is a comment.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
111
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
112 # General form of a rule. Arguments are space-separated tokens. Args are optional.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
113 rulename target : sources : arg1 : arg2 : arg3;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
114
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
115 # Resolves to 0 or 1 rule, choosing the first that matches an architecture specified
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
116 # during configure. [] is a default that matches regardless of architecture.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
117 ARCHITECTURE{
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
118 [arch-1] rulename target : arg1 : arg2 : arg3;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
119 [arch-2] rulename target : arg1 : arg2 : arg3;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
120 [] rulename target : arg1 : arg2 : arg3;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
121 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
122
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
123
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
124 Specific rules are:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
125
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
126 # This package contains packages. eg: package math ipc;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
127 package names [: protected]; # defaults to public
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
128
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
129 # This package refers to others. eg: refer math ipc;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
130 # Referenced packages are specified by path relative to root. eg: icp/client
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
131 refer packages;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
132
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
133 # Library: for D/C/C++, list both header and body files, all of which must be local.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
134 # eg: static-lib math : matrix.h : matrix.cc : m;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
135 static-lib name : public-sources : protected-sources : required-system-libs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
136
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
137 # dynamic-libs can only contain static-libs within their package or its
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
138 # children. The contained static-libs are specified as a relative name trail,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
139 # with the last element optionally omitted if it is the same as the package name.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
140 # eg: dynamic-lib ipc : common client server;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
141 dynamic-lib name : static-libs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
142 dynamic-lib name : static-libs : plugin;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
143
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
144
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
145 # Executables: makes an exe from a single source file and any libs deduced from
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
146 # imports and includes. Also links with specified system libs, plus any specified
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
147 # by deduced libraries.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
148 # Tests are auto-executed and build fails on test error.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
149 test-util name : source : required-system-libs; # source file in test dir or generated
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
150 priv-util name : source : required-system-libs; # source file in util dir or generated
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
151 dist-util name : source : required-system-libs; # source file in util dir or generated
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
152
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
153 # Shell
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
154 priv-shell name; # source file in util dir or generated
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
155 dist-shell name; # source file in util dir or generated
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
156
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
157 # Data - any dirs named specify whole contained tree, not including symlinks
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
158 test-data name; # source in data dir or generated.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
159 dist-data name; # source in data dir or generated.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
160
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
161 # Docco - rst files converted to html
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
162 doc names; # source in doc dir or generated.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
163 doc-data names; # source in doc dir or generated.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
164
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
165
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
166 Build directory structure
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
167 -------------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
168
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
169 Bob assumes that a build directory has been established
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
170 by an earlier configure operation. The configure sets up
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
171 a Boboptions file containing definitions of variables used by rules.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
172
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
173 The format of Boboptions is:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
174 key = value;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
175
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
176 Usually bob is invoked from a build script established during configure.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
177
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
178 Under the build directory we have:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
179
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
180 obj
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
181 static-libs
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
182 packages(s)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
183 obj-files
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
184 generated-sources
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
185 packages(s)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
186 priv
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
187 package(s)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
188 test-exes
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
189 util-exes
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
190 test
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
191 test-exe-specific-test-dir(s)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
192 test-results
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
193 test-working-files
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
194 doc
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
195 docs
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
196 package(s)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
197 dist
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
198 data All dist-data
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
199 lib All dynamic-libs except plugins
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
200 plugin Dynalic-libs designated as plugins
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
201 bin All dist-util
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
202
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
203
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
204
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
205 Search paths
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
206 ------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
207
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
208 Compilers are told to look in 'src' and 'obj' directories for input files.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
209 The src directory contains links to each top-level package in all the
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
210 repositories that comprise the project.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
211
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
212 Therefore, include directives have to include the path starting from
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
213 the top-level package names, which must be unique.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
214
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
215 This namespacing avoids problems of duplicate filenames
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
216 at the cost of the compiler being able to find everything, even files
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
217 that should not be accessible. Bob therefore enforces all visibility
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
218 rules before invoking the compiler.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
219
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
220
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
221 The build process
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
222 -----------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
223
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
224 Bob reads the project Bobfile, transiting into
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
225 other-package Bobfiles as packages are mentioned.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
226
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
227 Bob assumes that new packages, libraries, etc
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
228 are mentioned in dependency order. That is, when each thing is
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
229 mentioned, everything it depends on, including dependencies inferred by
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
230 include/import statements in source code, has already been mentioned.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
231
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
232 The planner scans the Bobfiles, binding files to specific
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
233 locations in the filesystem as it goes, and builds the dependency graph.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
234
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
235 The file state sequence is:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
236 initial
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
237 dependencies_clean skipped if no dependencies
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
238 building skipped if no build action
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
239 up-to-date
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
240 scanning_for_includes
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
241 includes_known
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
242 clean
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
243
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
244 As files become buildable, actions are passed to workers.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
245
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
246 Results cause the dependency graph to be updated, allowing more actions to
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
247 be issued. Specifically, generated source files are scanned for import/include
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
248 after they are up to date, and the dependency graph and action commands are
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
249 adjusted accordingly.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
250
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
251 //==========================================================================*/
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
252
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
253 /+
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
254 // signal handler for otherwise-fatal thread-specific signals
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
255 extern (C) void threadSpecificSignalHandler(int signum) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
256 string name() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
257 switch (signum) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
258 case SIGSEGV: return "SIGSEGV";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
259 case SIGFPE: return "SIGFPE";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
260 case SIGILL: return "SIGILL";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
261 case SIGABRT: return "SIGABRT";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
262 default: return "";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
263 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
264 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
265
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
266 writefln("called!!!");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
267 stdout.flush;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
268 writefln("got signal %s %s", signum, name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
269 stdout.flush;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
270 throw new Error(format("Got signal %s %s", signum, name));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
271 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
272
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
273 // install a signal handler
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
274 sigaction_t setHandler(int signum, sigfn_t handler) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
275 sigset_t empty_mask;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
276 sigemptyset(&empty_mask);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
277
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
278 sigaction_t new_action;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
279 new_action.sa_handler = handler;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
280 new_action.sa_mask = empty_mask;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
281 new_action.sa_flags = SA_RESETHAND;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
282
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
283 sigaction_t old_action;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
284
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
285 sigaction(signum, &new_action, &old_action);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
286
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
287 return old_action;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
288 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
289
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
290 shared static this() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
291 writefln("setting up thread-specific signal handlers");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
292
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
293 // set up shared signal handlers for fatal thread-specific signals
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
294 setHandler(SIGFPE, &threadSpecificSignalHandler);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
295 setHandler(SIGILL, &threadSpecificSignalHandler);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
296 setHandler(SIGSEGV, &threadSpecificSignalHandler);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
297
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
298 // unblock the signals
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
299 sigset_t unblock_set, prev_set;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
300 sigemptyset(&unblock_set);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
301 sigaddset(&unblock_set, SIGILL);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
302 sigaddset(&unblock_set, SIGSEGV);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
303 sigaddset(&unblock_set, SIGFPE);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
304 pthread_sigmask(SIG_UNBLOCK, &unblock_set, &prev_set);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
305 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
306 +/
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
307
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
308
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
309 //-----------------------------------------------------------------------------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
310 // PriorityQueue - insert items in any order, and remove largest-first
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
311 // (or smallest-first if "a > b" is passed for less).
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
312 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
313 // A simplified adaptation of std.container.BinaryHeap. The original doesn't
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
314 // have the behaviour needed here.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
315 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
316 // It is a simple input range (empty(), front() and popFront()).
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
317 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
318 // Notes from Wikipedia article on Binary Heap:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
319 // * Tree is concocted using index arithetic on underlying array, as follows:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
320 // First layer is 0. Second is 1,2. Third is 3,4,5,6, etc.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
321 // Therefore parent of index i is (i-1)/2 and children of index i are 2*i+1 and 2*i+2
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
322 // * Tree is balanced, with incomplete population to right of bottom layer.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
323 // * A parent is !less all its children.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
324 // * Insert:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
325 // - Append to array.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
326 // - Swap new element with parent until parent !less child.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
327 // * Remove:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
328 // - Replace root with the last element and reduce the length of the array.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
329 // - If moved element is less than a child, swap with largest child.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
330 //-----------------------------------------------------------------------------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
331 struct PriorityQueue(T, alias less = "a < b") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
332 private:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
333
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
334 T[] _store; // underlying store, whose length is the queue's capacity
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
335 size_t _used; // the used length of _store
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
336
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
337 alias binaryFun!(less) comp;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
338
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
339 public:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
340
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
341 @property size_t length() const nothrow { return _used; }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
342 @property size_t capacity() const nothrow { return _store.length; }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
343 @property bool empty() const nothrow { return !length; }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
344
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
345 @property const(T) front() const { enforce(!empty); return _store[0]; }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
346
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
347 // Insert a value into the queue
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
348 size_t insert(T value)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
349 {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
350 // put the new element at the back of the store
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
351 if ( length == capacity) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
352 _store.length = (capacity + 1) * 2;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
353 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
354 _store[_used] = value;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
355
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
356 // percolate-up the new element
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
357 for (size_t n = _used; n; )
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
358 {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
359 auto parent = (n - 1) / 2;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
360 if (!comp(_store[parent], _store[n])) break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
361 swap(_store[parent], _store[n]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
362 n = parent;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
363 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
364 ++_used;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
365 return 1;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
366 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
367
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
368 void popFront()
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
369 {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
370 enforce(!empty);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
371
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
372 // replace the front element with the back one
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
373 if (_used > 1) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
374 _store[0] = _store[_used-1];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
375 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
376 --_used;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
377
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
378 // percolate-down the front element (which used to be at the back)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
379 size_t parent = 0;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
380 for (;;)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
381 {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
382 auto left = parent * 2 + 1, right = left + 1;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
383 if (right > _used) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
384 // no children - done
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
385 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
386 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
387 if (right == _used) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
388 // no right child - possibly swap parent with left, then done
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
389 if (comp(_store[parent], _store[left])) swap(_store[parent], _store[left]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
390 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
391 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
392 // both left and right children - swap parent with largest of itself and left or right
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
393 auto largest = comp(_store[parent], _store[left])
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
394 ? (comp(_store[left], _store[right]) ? right : left)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
395 : (comp(_store[parent], _store[right]) ? right : parent);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
396 if (largest == parent) break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
397 swap(_store[parent], _store[largest]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
398 parent = largest;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
399 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
400 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
401 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
402
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
403
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
404 //------------------------------------------------------------------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
405 // Synchronized object that launches external processes in the background
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
406 // and keeps track of their PIDs. A one-shot bail() method kills all those
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
407 // launched processes and prevents any more from being launched.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
408 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
409 // bail() is called by the error() functions, which then throw an exception.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
410 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
411 // We also install a signal handler to bail on receipt of various signals.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
412 //------------------------------------------------------------------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
413
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
414 class BailException : Exception {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
415 this() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
416 super("Bail");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
417 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
418 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
419
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
420 synchronized class Launcher {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
421 private {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
422 bool bailed;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
423 bool[int] children;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
424 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
425
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
426 // launch a process if we haven't bailed
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
427 pid_t launch(string command) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
428 if (bailed) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
429 say("Aborting launch because we have bailed");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
430 throw new BailException();
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
431 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
432 int child = spawnvp(P_NOWAIT, "/bin/bash", ["bash", "-c", command]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
433 //say("spawned child, pid=%s", child);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
434 children[child] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
435 return child;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
436 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
437
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
438 // a child has been finished with
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
439 void completed(pid_t child) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
440 children.remove(child);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
441 //say("completed child, pid=%s", child);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
442 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
443
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
444 // bail, doing nothing if we had already bailed
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
445 bool bail() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
446 if (!bailed) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
447 bailed = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
448 foreach (child; children.byKey) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
449 //say("killing child, pid=%s", child);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
450 kill(child, SIGTERM);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
451 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
452 return false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
453 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
454 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
455 return true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
456 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
457 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
458 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
459
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
460 shared Launcher launcher;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
461
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
462 void doBail() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
463 launcher.bail;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
464 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
465 extern (C) void mySignalHandler(int sig) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
466 // launch a thread to initiate a bail
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
467 say("got signal %s", sig);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
468 spawn(&doBail);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
469 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
470
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
471
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
472 shared static this() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
473 // set up shared Launcher and signal handling
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
474
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
475 launcher = new shared(Launcher)();
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
476
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
477 /*
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
478 signal(SIGTERM, &mySignalHandler);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
479 signal(SIGINT, &mySignalHandler);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
480 signal(SIGHUP, &mySignalHandler);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
481 */
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
482 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
483
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
484
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
485
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
486 //------------------------------------------------------------------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
487 // printing utility functions
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
488 //------------------------------------------------------------------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
489
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
490 // where something originated from
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
491 struct Origin {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
492 string path;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
493 uint line;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
494 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
495
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
496 private void sayNoNewline(A...)(string fmt, A a) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
497 auto w = appender!(char[])();
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
498 formattedWrite(w, fmt, a);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
499 stderr.write(w.data);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
500 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
501
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
502 void say(A...)(string fmt, A a) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
503 auto w = appender!(char[])();
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
504 formattedWrite(w, fmt, a);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
505 stderr.writeln(w.data);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
506 stderr.flush;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
507 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
508
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
509 void fatal(A...)(string fmt, A a) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
510 say(fmt, a);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
511 launcher.bail;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
512 throw new BailException();
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
513 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
514
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
515 void error(A...)(ref Origin origin, string fmt, A a) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
516 sayNoNewline("%s|%s| ERROR: ", origin.path, origin.line);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
517 fatal(fmt, a);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
518 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
519
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
520 void errorUnless(A ...)(bool condition, Origin origin, lazy string fmt, lazy A a) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
521 if (!condition) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
522 error(origin, fmt, a);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
523 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
524 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
525
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
526
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
527 //-------------------------------------------------------------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
528 // path/filesystem utility functions
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
529 //-------------------------------------------------------------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
530
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
531 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
532 // Return the given path with the top level directory removed
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
533 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
534 string clip(string path) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
535 for (uint i = 0; i < path.length; ++i) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
536 if (isDirSeparator(path[i])) return path[i+1..$];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
537 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
538 return "";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
539 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
540
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
541
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
542 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
543 // Ensure that the parent dir of path exists
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
544 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
545 void ensureParent(string path) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
546 static bool[string] doesExist;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
547
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
548 string dir = dirName(path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
549 if (dir !in doesExist) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
550 if (!exists(dir)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
551 ensureParent(dir);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
552 say("%-15s %s", "Mkdir", dir);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
553 mkdir(dir);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
554 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
555 else if (!isDir(dir)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
556 error(Origin(), "%s is not a directory!", dir);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
557 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
558 doesExist[path] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
559 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
560 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
561
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
562
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
563 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
564 // return the modification time of the file at path
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
565 // Note: A zero-length target file is treated as if it doesn't exist.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
566 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
567 long modifiedTime(string path, bool isTarget) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
568 if (!exists(path) || (isTarget && getSize(path) == 0)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
569 return 0;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
570 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
571 SysTime fileAccessTime, fileModificationTime;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
572 getTimes(path, fileAccessTime, fileModificationTime);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
573 return fileModificationTime.stdTime;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
574 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
575
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
576
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
577 // return the privacy implied by args
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
578 Privacy privacyOf(ref Origin origin, string[] args) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
579 if (!args.length ) return Privacy.PUBLIC;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
580 else if (args[0] == "protected") return Privacy.PROTECTED;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
581 else if (args[0] == "semi-protected") return Privacy.SEMI_PROTECTED;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
582 else if (args[0] == "private") return Privacy.PRIVATE;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
583 else if (args[0] == "public") return Privacy.PUBLIC;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
584 else error(origin, "privacy must be one of public, semi-protected, protected or private");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
585 assert(0);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
586 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
587
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
588
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
589
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
590
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
591 //------------------------------------------------------------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
592 // File parsing
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
593 //------------------------------------------------------------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
594
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
595 // options read from Boboptions file
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
596 string[string] options;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
597 bool[string] architectures;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
598 bool[string] validArchitectures;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
599
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
600 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
601 // Read an options file, populating options
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
602 // Format is: key=value;\n
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
603 // value can contain '='
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
604 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
605 void readOptions() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
606 string path = "Boboptions";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
607 Origin origin = Origin(path, 1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
608
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
609 errorUnless(exists(path) && isFile(path), origin, "can't read Boboptions %s", path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
610
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
611 string content = readText(path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
612
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
613 string key;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
614 int anchor = 0;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
615 foreach (int pos, char ch ; content) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
616 if (ch == '\n') ++origin.line;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
617 if (key is null && ch == '=') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
618 key = strip(content[anchor..pos]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
619 anchor = pos + 1;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
620 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
621 else if (ch == ';') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
622 if (key is null) error(origin, "option terminated without a key");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
623 string str = strip(content[anchor..pos]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
624 if (key == "VALID_ARCHITECTURES") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
625 foreach (arch; split(str)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
626 validArchitectures[arch] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
627 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
628 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
629 else if (key == "ARCHITECTURES") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
630 foreach (arch; split(str)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
631 architectures[arch] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
632 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
633 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
634 options[key] = str;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
635 key = null;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
636 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
637 else if (ch == '\n') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
638 errorUnless(key is null, origin, "option %s not terminated with ';'", key);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
639 anchor = pos + 1;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
640 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
641 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
642 errorUnless(key is null, origin, "%s ends in unterminated option", path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
643 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
644
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
645 string getOption(string key) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
646 auto value = key in options;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
647 if (value) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
648 return *value;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
649 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
650 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
651 return "";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
652 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
653 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
654
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
655
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
656
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
657 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
658 // Scan file for includes, returning an array of included trails
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
659 // # include "trail"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
660 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
661 // All of the files found should have trails relative to "src" (if source)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
662 // or "obj" (if generated). All system includes must use angle-brackets,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
663 // and are not returned from a scan.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
664 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
665 struct Include {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
666 string trail;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
667 uint line;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
668 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
669
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
670 Include[] scanForIncludes(string path) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
671 Include[] result;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
672 Origin origin = Origin(path, 1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
673
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
674 enum Phase { START, HASH, WORD, INCLUDE, QUOTE, NEXT }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
675
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
676 if (exists(path) && isFile(path)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
677 string content = readText(path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
678 int anchor = 0;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
679 Phase phase = Phase.START;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
680
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
681 foreach (int i, char ch; content) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
682 if (ch == '\n') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
683 phase = Phase.START;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
684 ++origin.line;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
685 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
686 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
687 switch (phase) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
688 case Phase.START:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
689 if (ch == '#') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
690 phase = Phase.HASH;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
691 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
692 else if (!isWhite(ch)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
693 phase = Phase.NEXT;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
694 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
695 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
696 case Phase.HASH:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
697 if (!isWhite(ch)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
698 phase = Phase.WORD;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
699 anchor = i;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
700 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
701 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
702 case Phase.WORD:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
703 if (isWhite(ch)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
704 if (content[anchor..i] == "include") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
705 phase = Phase.INCLUDE;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
706 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
707 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
708 phase = Phase.NEXT;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
709 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
710 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
711 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
712 case Phase.INCLUDE:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
713 if (ch == '"') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
714 phase = Phase.QUOTE;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
715 anchor = i+1;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
716 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
717 else if (!isWhite(ch)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
718 phase = Phase.NEXT;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
719 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
720 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
721 case Phase.QUOTE:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
722 if (ch == '"') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
723 result ~= Include(content[anchor..i].idup, origin.line);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
724 phase = Phase.NEXT;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
725 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
726 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
727 case Phase.NEXT:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
728 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
729 default:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
730 error(origin, "invalid phase");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
731 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
732 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
733 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
734 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
735 return result;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
736 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
737
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
738
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
739 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
740 // Scan a D source file for imports.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
741 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
742 // The parser is simple and fast, but can't deal with version
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
743 // statements or mixins. This is ok for now because it only needs
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
744 // to work for source we have control over.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
745 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
746 // The approach is:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
747 // * Scan for a line starting with "static", "public", "private" or ""
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
748 // followed by "import".
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
749 // * Then look for:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
750 // ':' - module is previous word, and then skip to next ';'.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
751 // ',' - module is previous word.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
752 // ';' - module is previous word.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
753 // The import is terminated by a ';'.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
754 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
755
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
756 Include[] scanForImports(string path) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
757 Include[] result;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
758 string content = readText(path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
759 string word;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
760 int anchor, line=1;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
761 bool inWord, inImport, ignoring;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
762
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
763 string[] externals = split(getOption("DEXTERNALS"));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
764
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
765 foreach (int pos, char ch; content) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
766 if (ch == '\n') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
767 line++;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
768 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
769 if (ignoring) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
770 if (ch == ';' || ch == '\n') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
771 // resume looking for imports
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
772 ignoring = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
773 inWord = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
774 inImport = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
775 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
776 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
777 // ignore
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
778 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
779 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
780 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
781 // we are not ignoring
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
782
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
783 if (inWord && (isWhite(ch) || ch == ':' || ch == ',' || ch == ';')) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
784 inWord = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
785 word = content[anchor..pos];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
786
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
787 if (!inImport) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
788 if (isWhite(ch)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
789 if (word == "import") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
790 inImport = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
791 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
792 else if (word != "public" && word != "private" && word != "static") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
793 ignoring = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
794 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
795 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
796 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
797 ignoring = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
798 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
799 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
800 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
801
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
802 if (inImport && word && (ch == ':' || ch == ',' || ch == ';')) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
803 // previous word is a module name
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
804
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
805 string trail = std.array.replace(word, ".", dirSeparator) ~ ".d";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
806
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
807 bool ignored = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
808 foreach (external; externals) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
809 string ignoreStr = external ~ dirSeparator;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
810 if (trail.length >= ignoreStr.length && trail[0..ignoreStr.length] == ignoreStr) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
811 ignored = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
812 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
813 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
814 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
815
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
816 if (!ignored) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
817 result ~= Include(trail, line);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
818 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
819 word = null;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
820
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
821 if (ch == ':') ignoring = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
822 else if (ch == ';') inImport = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
823 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
824
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
825 if (!inWord && !(isWhite(ch) || ch == ':' || ch == ',' || ch == ';')) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
826 inWord = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
827 anchor = pos;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
828 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
829 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
830 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
831
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
832 return result;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
833 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
834
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
835
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
836 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
837 // read a Bobfile, returning all its statements
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
838 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
839 // // a simple statement
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
840 // rulename targets... : arg1... : arg2... : arg3...; // can expand Boboptions variable with ${var-name}
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
841 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
842 // // a conditional statement resolving to 0 or one of its constituents, based on ARCHITECTURE Boboption.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
843 // ARCHITECTURE{
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
844 // [arch-1] rulename targets... : arg1... : arg2... ;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
845 // [arch-2] rulename targets... : arg1... : arg2... ;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
846 // [] rulename targets... : arg1... : arg2... ; // optional default
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
847 // }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
848 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
849 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
850
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
851 struct Statement {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
852 Origin origin;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
853 int phase; // 0==>empty, 1==>rule populated, 2==rule,targets populated, etc
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
854 string rule;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
855 string[] targets;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
856 string[] arg1;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
857 string[] arg2;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
858 string[] arg3;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
859
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
860 string toString() const {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
861 string result;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
862 if (phase >= 1) result ~= rule;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
863 if (phase >= 2) result ~= format(" : %s", targets);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
864 if (phase >= 3) result ~= format(" : %s", arg1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
865 if (phase >= 4) result ~= format(" : %s", arg2);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
866 if (phase >= 5) result ~= format(" : %s", arg3);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
867 return result;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
868 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
869 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
870
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
871 Statement[] readBobfile(string path) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
872 Statement[] statements;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
873 Origin origin = Origin(path, 1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
874 errorUnless(exists(path) && isFile(path), origin, "can't read Bobfile %s", path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
875
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
876 string content = readText(path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
877 Statement statement;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
878
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
879 int anchor = 0;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
880 bool inWord = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
881 bool inComment = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
882 bool inCondition = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
883 bool conditionMatch = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
884 bool conditionSatisfied = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
885
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
886 foreach (int pos, char ch ; content) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
887 if (ch == '\n') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
888 ++origin.line;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
889 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
890 if (ch == '#') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
891 inComment = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
892 inWord = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
893 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
894 if (inComment) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
895 if (ch == '\n') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
896 inComment = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
897 anchor = pos;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
898 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
899 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
900 else if ((isWhite(ch) || ch == ':' || ch == ';')) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
901 if (inWord) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
902 inWord = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
903 string word = content[anchor..pos];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
904
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
905 if (word == "ARCHITECTURE{") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
906 // start an architecture condition
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
907 errorUnless(!inCondition, origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
908 "nested ARCHITECTURE condition in %s", path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
909 errorUnless(statement.phase == 0, origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
910 "ARCHITECTURE condition inside a statement in %s", path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
911 inCondition = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
912 conditionMatch = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
913 conditionSatisfied = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
914 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
915 else if (word.length >= 2 && word[0] == '[' && word[$-1] == ']') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
916 // architecture specifier preceeds statement
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
917 string architecture = word[1..$-1];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
918 errorUnless(inCondition, origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
919 "architecture '%s' specifier when not in condition in %s",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
920 architecture, path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
921 errorUnless(statement.phase == 0, origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
922 "nested statements in %s near %s", path, word);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
923 errorUnless(architecture == "" || architecture in validArchitectures, origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
924 "invalid architecture '%s' in %s", architecture, path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
925 if (!conditionSatisfied && (architecture == "" || architecture in architectures)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
926 conditionMatch = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
927 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
928 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
929 else if (word == "}") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
930 inCondition = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
931 conditionMatch = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
932 conditionSatisfied = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
933 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
934 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
935 // should be a word in a statement
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
936
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
937 string[] words = [word];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
938
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
939 if (word.length > 3 && word[0..2] == "${" && word[$-1] == '}') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
940 // macro substitution
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
941 words = split(getOption(word[2..$-1]));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
942 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
943
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
944 if (word.length > 0) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
945 if (statement.phase == 0) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
946 statement.origin = origin;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
947 statement.rule = words[0];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
948 ++statement.phase;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
949 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
950 else if (statement.phase == 1) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
951 statement.targets ~= words;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
952 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
953 else if (statement.phase == 2) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
954 statement.arg1 ~= words;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
955 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
956 else if (statement.phase == 3) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
957 statement.arg2 ~= words;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
958 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
959 else if (statement.phase == 4) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
960 statement.arg3 ~= words;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
961 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
962 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
963 error(origin, "Too many arguments in %s", path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
964 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
965 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
966 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
967 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
968
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
969 if (ch == ':' || ch == ';') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
970 ++statement.phase;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
971 if (ch == ';') {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
972 if (statement.phase > 1 && (!inCondition || conditionMatch)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
973 statements ~= statement;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
974 if (inCondition) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
975 conditionSatisfied = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
976 conditionMatch = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
977 //say("conditional resolves to statement '%s'", statement.toString);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
978 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
979 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
980 statement = statement.init;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
981 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
982 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
983 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
984 else if (!inWord) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
985 inWord = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
986 anchor = pos;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
987 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
988 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
989 errorUnless(statement.phase == 0, origin, "%s ends in unterminated rule", path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
990 return statements;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
991 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
992
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
993
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
994 //-------------------------------------------------------------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
995 // Planner
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
996 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
997 // Planner reads Bobfiles, understands what they mean, builds
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
998 // a tree of packages, etc, understands what it all means, enforces rules,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
999 // binds everything to filenames, discovers modification times, scans for
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1000 // includes, and schedules actions for processing by the worker.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1001 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1002 // Also receives results of successful actions from the Worker,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1003 // does additional scanning for includes, updates modification
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1004 // times and schedules more work.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1005 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1006 // A critical feature is that scans for includes are deferred until
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1007 // a file is up-to-date.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1008 //-------------------------------------------------------------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1009
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1010
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1011 // some thread-local "globals" to make things easier
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1012 bool g_print_rules;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1013 bool g_print_deps;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1014 bool g_print_details;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1015
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1016
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1017 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1018 // Action - specifies how to build some files, and what they depend on
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1019 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1020 final class Action {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1021 static Action[string] byName;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1022 static int nextNumber;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1023 static PriorityQueue!Action queue;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1024
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1025 string name; // the name of the action
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1026 string command; // the action command-string
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1027 int number; // influences build order
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1028 File[] builds; // files that this action builds
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1029 File[] depends; // files that the action's targets depend on
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1030 bool issued; // true if the action has been issued to a worker
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1031
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1032 this(ref Origin origin, string name_, string command_, File[] builds_, File[] depends_) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1033 name = name_;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1034 command = command_;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1035 number = nextNumber++;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1036 builds = builds_;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1037 depends = depends_;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1038 errorUnless(!(name in byName), origin, "Duplicate command name=%s", name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1039 byName[name] = this;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1040
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1041 // add the bobfile responsible for all the files built by this action
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1042 File bobfile;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1043 foreach (build; builds) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1044 File b = build.bobfile;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1045 assert(b !is null);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1046 if (bobfile is null) bobfile = b;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1047 assert(b is bobfile);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1048 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1049 assert(bobfile !is null);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1050 depends ~= bobfile;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1051
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1052 // set up reverse dependencies between builds and depends
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1053 foreach (depend; depends) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1054 foreach (built; builds) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1055 depend.dependedBy[built] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1056 if (g_print_deps) say("%s depends on %s", built.path, depend.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1057 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1058 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1059 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1060
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1061 // add an extra depend to this action
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1062 void addDependency(File depend) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1063 if (issued) fatal("Cannot add a dependancy to issued action %s", this);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1064 if (builds.length != 1) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1065 fatal("cannot add a dependency to an action that builds more than one file: %s", name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1066 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1067 depends ~= depend;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1068
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1069 // set up references and reverse dependencies between builds and depend
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1070 foreach (built; builds) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1071 depend.dependedBy[built] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1072 if (g_print_deps) say("%s depends on %s", built.path, depend.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1073 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1074 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1075
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1076 // augment this action's command string with some text
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1077 void augment(string augmentation) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1078 assert(!issued);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1079 command ~= augmentation;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1080 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1081
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1082
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1083 // issue this action
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1084 void issue() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1085 assert(!issued);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1086 issued = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1087 queue.insert(this);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1088 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1089
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1090 override string toString() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1091 return name;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1092 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1093 override int opCmp(Object o) const {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1094 // reverse order
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1095 if (this is o) return 0;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1096 Action a = cast(Action)o;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1097 if (a is null) return -1;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1098 return a.number - number;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1099 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1100 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1101
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1102
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1103 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1104 // SysLib - represents a library outside the project.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1105 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1106 final class SysLib {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1107 static SysLib[string] byName;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1108
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1109 string name;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1110
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1111 // assorted Object overrides for printing and use as an associative-array key
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1112 override string toString() const {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1113 return name;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1114 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1115
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1116 this(string name_) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1117 name = name_;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1118 byName[name] = this;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1119 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1120 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1121
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1122
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1123 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1124 // Node - abstract base class for things in an ownership tree
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1125 // with cross-linked dependencies. Used to manage allowed references.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1126 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1127
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1128 // additional constraint on allowed references
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1129 enum Privacy { PUBLIC, // no additional constraint
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1130 SEMI_PROTECTED, // only accessable to descendents of grandparent
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1131 PROTECTED, // only accessible to children of parent
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1132 PRIVATE } // not accessible
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1133
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1134 class Node {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1135 static Node[string] byTrail;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1136
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1137 string name; // simple name this node adds to parent
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1138 string trail; // slash-separated name components from root to this
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1139 Node parent;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1140 Privacy privacy;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1141 Node[] children;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1142 Node[] refers;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1143
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1144 // assorted Object overrides for printing and use as an associative-array key
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1145 override string toString() const {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1146 return trail;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1147 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1148
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1149 // create the root of the tree
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1150 this() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1151 trail = "root";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1152 assert(trail !in byTrail, "already have root node");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1153 byTrail[trail] = this;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1154 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1155
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1156 // create a node and place it into the tree
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1157 this(ref Origin origin, Node parent_, string name_, Privacy privacy_) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1158 assert(parent_);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1159 errorUnless(dirName(name_) == ".", origin, "Cannot define node with multi-part name '%s'", name_);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1160 parent = parent_;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1161 name = name_;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1162 privacy = privacy_;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1163 if (parent.parent) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1164 // child of non-root
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1165 trail = buildPath(parent.trail, name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1166 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1167 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1168 // child of the root
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1169 trail = name;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1170 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1171 parent.children ~= this;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1172 errorUnless(trail !in byTrail, origin, "%s already known", trail);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1173 byTrail[trail] = this;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1174 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1175
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1176 // return true if this is a descendant of other
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1177 private bool isDescendantOf(Node other) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1178 for (auto node = this; node !is null; node = node.parent) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1179 if (node is other) return true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1180 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1181 return false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1182 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1183
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1184 // return true if this is a visible descendant of other
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1185 private bool isVisibleDescendantOf(Node other, Privacy allowed) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1186 for (auto node = this; node !is null; node = node.parent) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1187 if (node is other) return true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1188 if (node.privacy > allowed) break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1189 if (allowed > Privacy.PUBLIC) allowed--;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1190 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1191 return false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1192 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1193
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1194 // return true if other is a visible-child or reference of this,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1195 // or is a visible-descendant of them
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1196 private bool allowsRefTo(ref Origin origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1197 Node other,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1198 size_t depth = 0,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1199 Privacy allowPrivacy = Privacy.PROTECTED,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1200 bool[Node] checked = null) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1201 errorUnless(depth < 100, origin, "circular reference involving %s referring to %s", this, other);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1202 //say("for %s: checking if %s allowsReferenceTo %s", origin.path, this, other);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1203 if (other is this || other.isVisibleDescendantOf(this, allowPrivacy)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1204 if (g_print_details) say("%s allows reference to %s via containment", this, other);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1205 return true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1206 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1207 foreach (node; refers) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1208 // referred-to nodes grant access to their public children, and referred-to
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1209 // suiblings grant access to their semi-protected children
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1210 if (node !in checked) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1211 checked[node] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1212 if (node.allowsRefTo(origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1213 other,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1214 depth+1,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1215 node.parent is this.parent ? Privacy.SEMI_PROTECTED : Privacy.PUBLIC,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1216 checked)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1217 if (g_print_details) say("%s allows reference to %s via explicit reference", this, other);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1218 return true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1219 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1220 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1221 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1222 return false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1223 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1224
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1225 // Add a reference to another node. Cannot refer to:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1226 // * Nodes that aren't defined yet.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1227 // * Self.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1228 // * Ancestors.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1229 // * Nodes whose selves or ancestors have not been referred to by our parent.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1230 // Also can't explicitly refer to children - you get that implicitly.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1231 final void addReference(ref Origin origin, Node other, string cause = null) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1232 errorUnless(other !is null, origin, "%s cannot refer to NULL node", this);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1233 errorUnless(other != this, origin, "%s cannot refer to self", this);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1234 errorUnless(!this.isDescendantOf(other), origin, "%s cannot refer to ancestor %s", this, other);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1235 errorUnless(!other.isDescendantOf(this), origin, "%s cannnot explicitly refer to descendant %s", this, other);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1236 errorUnless(this.parent.allowsRefTo(origin, other), origin, "Parent %s does not allow %s to refer to %s", parent, this, other);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1237 errorUnless(!other.allowsRefTo(origin, this), origin, "%s cannot refer to %s because of a circularity", this, other);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1238 if (g_print_deps) say("%s refers to %s%s", this, other, cause);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1239 refers ~= other;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1240 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1241 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1242
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1243
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1244 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1245 // Pkg - a package. Has a Bobfile, assorted source and built files, and sub-packages
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1246 // Used to group files together for dependency control, and to house a Bobfile.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1247 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1248 final class Pkg : Node {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1249
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1250 File bobfile;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1251
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1252 this(ref Origin origin, Node parent_, string name_, Privacy privacy_) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1253 super(origin, parent_, name_, privacy_);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1254 bobfile = File.addSource(origin, this, "Bobfile", Privacy.PRIVATE, false);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1255 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1256 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1257
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1258
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1259
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1260 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1261 // A file
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1262 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1263 class File : Node {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1264 static File[string] byPath; // Files by their path
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1265 static bool[File] allActivated; // all activated files
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1266 static bool[File] outstanding; // outstanding buildable files
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1267 static int nextNumber;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1268
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1269 // Statistics
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1270 static uint numBuilt; // number of files targeted
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1271 static uint numUpdated; // number of files successfully updated by actions
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1272
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1273 string path; // the file's path
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1274 int number; // order of file creation
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1275 bool scannable; // true if the file and its includes should be scanned for includes
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1276 bool built; // true if this file will be built by an action
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1277 Action action; // the action used to build this file (null if non-built)
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1278
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1279 long modTime; // the modification time of the file
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1280 bool[File] dependedBy; // Files that depend on this
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1281 bool used; // true if this file has been used already
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1282
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1283 // state-machine stuff
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1284 bool activated; // considered by touch() for files with an action
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1285 bool scanned; // true if this has already been scanned for includes
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1286 File[] includes; // the Files this includes
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1287 bool[File] includedBy; // Files that include this
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1288 bool clean; // true if usable by higher-level files
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1289 long includeModTime; // transitive max of mod_time and includes include_mod_time
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1290
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1291 // analysis stuff
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1292 File youngestDepend;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1293 File youngestInclude;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1294
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1295
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1296 // return a prospective path to a potential file.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1297 static string prospectivePath(string start, Node parent, string extra) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1298 Node node = parent;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1299 while (node !is null) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1300 Pkg pkg = cast(Pkg) node;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1301 if (pkg) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1302 return buildPath(start, pkg.trail, extra);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1303 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1304 node = node.parent;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1305 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1306 fatal("prospective file %s's parent %s has no package in its ancestry", extra, parent);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1307 assert(0);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1308 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1309
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1310 // return the bobfile that this file is declared in
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1311 final File bobfile() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1312 Node node = parent;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1313 while (node) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1314 Pkg pkg = cast(Pkg) node;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1315 if (pkg) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1316 return pkg.bobfile;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1317 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1318 node = node.parent;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1319 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1320 fatal("file %s has no package in its ancestry", this);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1321 assert(0);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1322 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1323
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1324 this(ref Origin origin, Node parent_, string name_, Privacy privacy_, string path_, bool scannable_, bool built_) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1325 super(origin, parent_, name_, privacy_);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1326
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1327 path = path_;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1328 scannable = scannable_;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1329 built = built_;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1330
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1331 number = nextNumber++;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1332
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1333 modTime = modifiedTime(path, built);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1334
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1335 errorUnless(path !in byPath, origin, "%s already defined", path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1336 byPath[path] = this;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1337
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1338 if (built) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1339 //say("built file %s", path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1340 ++numBuilt;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1341 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1342
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1343 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1344
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1345 // Add a source file specifying its trail within its package
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1346 static File addSource(ref Origin origin, Node parent, string extra, Privacy privacy, bool scannable) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1347
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1348 // three possible paths to the file
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1349 string path1 = prospectivePath("obj", parent, extra); // a built file in obj directory tree
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1350 string path2 = prospectivePath("src", parent, extra); // a source file in src directory tree
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1351 string path3 = baseName(extra); // a configure-generated source file in build directory
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1352
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1353 string name = baseName(extra);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1354
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1355 File * file = path1 in byPath;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1356 if (file) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1357 // this is a built source file we already know about
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1358 errorUnless(!file.used, origin, "%s has already been used", path1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1359 return *file;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1360 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1361 else if (exists(path2)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1362 // a source file under src
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1363 return new File(origin, parent, name, privacy, path2, scannable, false);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1364 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1365 else if (exists(path3)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1366 // a source file in build dir
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1367 return new File(origin, parent, name, privacy, path3, scannable, false);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1368 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1369 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1370 error(origin, "Could not find source file %s in %s, %s or %s", name, path1, path2, path3);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1371 assert(0);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1372 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1373 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1374
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1375 // This file has been updated
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1376 final void updated() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1377 ++numUpdated;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1378 modTime = modifiedTime(path, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1379 if (g_print_details) say("Updated %s, mod_time %s", this, modTime);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1380 if (action !is null) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1381 action = null;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1382 outstanding.remove(this);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1383 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1384 touch;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1385 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1386
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1387 // Scan this file for includes, returning them after making sure those files
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1388 // themselves exist and have already been scanned for includes
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1389 private void scan() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1390 errorUnless(!scanned, Origin(path, 1), "%s has been scanned for includes twice!", this);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1391 scanned = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1392 if (scannable) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1393
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1394 // scan for includes that are part of the project, and thus must already be known
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1395 Include[] entries;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1396 string ext = extension(path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1397 if (ext == ".c" || ext == ".cc" || ext == ".h") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1398 entries = scanForIncludes(path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1399 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1400 else if (ext == ".d") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1401 entries = scanForImports(path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1402 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1403 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1404 fatal("Don't know how to scan %s for includes/imports", path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1405 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1406
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1407 foreach (entry; entries) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1408 // verify that we know the included file
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1409
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1410 File * file;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1411 // under src using full trail?
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1412 File * include = cast(File *) (buildPath("src", entry.trail) in byPath);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1413 if (include is null && baseName(entry.trail) == entry.trail) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1414 // in src dir of the including file's package?
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1415 include = cast(File *) (prospectivePath("src", parent, entry.trail) in byPath);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1416 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1417 if (include is null) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1418 // under obj?
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1419 include = cast(File *) (buildPath("obj", entry.trail) in byPath);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1420 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1421 if (include is null) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1422 // build dir?
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1423 include = entry.trail in byPath;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1424 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1425 Origin origin = Origin(this.path, entry.line);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1426 errorUnless(include !is null, origin, "included/imported unknown file %s", entry.trail);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1427
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1428 // add the included file to this file's includes
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1429 includes ~= *include;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1430 include.includedBy[this] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1431
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1432 // tell all files that depend on this one that the include has been added
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1433 includeAdded(origin, this, *include);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1434
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1435 // now (after includeAdded) we can add a reference between this file and the included one
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1436 //say("adding include-reference from %s to %s", this, *include);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1437 addReference(origin, *include);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1438 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1439 if (g_print_deps && includes) say("%s includes=%s", this, includes);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1440
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1441 // totally important to touch includes AFTER we know what all of them are
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1442 foreach (include; includes) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1443 include.touch;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1444 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1445 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1446 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1447
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1448
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1449 // An include has been added from includer (which we depend on) to included.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1450 // Specialisations of File override this to infer additional depends.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1451 void includeAdded(ref Origin origin, File includer, File included) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1452 //say("File.includeAdded called on %s with %s including %s", this, includer, included);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1453 foreach (depend; dependedBy.keys()) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1454 //say(" passing on to %s", depend);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1455 depend.includeAdded(origin, includer, included);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1456 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1457 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1458
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1459
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1460 // This file's action is about to be issued, and this is the last chance to
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1461 // augment its action. Specialisation should override this method if augmentation
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1462 // is required. Return true if dependencies were added.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1463 bool augmentAction() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1464 return false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1465 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1466
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1467
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1468 // This file has been touched - work out if its action should be issued
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1469 // or if it is now clean, transiting to affected items if this becomes clean.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1470 // NOTE - nothing can become clean until AFTER all activation has been done by the planner.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1471 final void touch() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1472 if (clean) return;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1473 if (g_print_details) say("touching %s", path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1474 long newest;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1475
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1476 if (activated && action && !action.issued) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1477 // this items action may need to be issued
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1478 //say("activated file %s touched", this);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1479
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1480 foreach (depend; action.depends) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1481 if (!depend.clean) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1482 if (g_print_details) say("%s waiting for %s to become clean", path, depend.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1483 return;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1484 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1485 if (newest < depend.includeModTime) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1486 newest = depend.includeModTime;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1487 youngestDepend = depend;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1488 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1489 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1490 // all files this one depends on are clean
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1491
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1492 // give this file a chance to augment its action
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1493 if (augmentAction()) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1494 // dependency added - touch this file again to re-check dependencies
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1495 touch;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1496 return;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1497 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1498 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1499 // no dependencies were added, so we can issue the action now
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1500
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1501 if (modTime < newest) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1502 // buildable and out of date - issue action to worker
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1503 if (g_print_details) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1504 say("%s is out of date with mod_time ", this, modTime);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1505 File other = youngestDepend;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1506 File prevOther = this;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1507 while (other && other.includeModTime > prevOther.modTime) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1508 say(" %s mod_time %s (younger by %s)",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1509 other,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1510 other.includeModTime,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1511 other.includeModTime - modTime);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1512 other = other.youngestDepend;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1513 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1514 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1515 action.issue;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1516 return;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1517 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1518 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1519 // already up to date - no need for building
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1520 if (g_print_details) say("%s is up to date", path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1521 action = null;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1522 outstanding.remove(this);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1523 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1524 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1525 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1526
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1527 if (action) return;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1528 errorUnless(modTime > 0, Origin(path, 1), "%s (%s) is up to date with zero mod_time!", path, trail);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1529 // This file is up to date
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1530
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1531 // Scan for includes, possibly becoming clean in the process
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1532 if (!scanned) scan;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1533 if (clean) return;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1534
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1535 // Find out if includes are clean and what our effective mod_time is
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1536 newest = modTime;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1537 foreach (include; includes) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1538 if (!include.clean) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1539 return;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1540 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1541 if (newest < include.includeModTime) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1542 newest = include.includeModTime;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1543 youngestInclude = include;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1544 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1545 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1546 includeModTime = newest;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1547 if (g_print_details) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1548 say("%s is clean with effective mod_time %s", this, includeModTime);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1549 File other = youngestInclude;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1550 File prevOther = this;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1551 while (other && other.includeModTime > prevOther.modTime) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1552 say(" %s mod_time %s (younger by %s)",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1553 other,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1554 other.includeModTime,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1555 other.includeModTime - prevOther.modTime);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1556 other = other.youngestInclude;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1557 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1558 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1559 // All includes are clean, so we are too
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1560
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1561 clean = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1562
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1563 // touch everything that includes or depends on this
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1564 foreach (other; includedBy.byKey()) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1565 other.touch;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1566 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1567 foreach (other; dependedBy.byKey()) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1568 if (other.activated) other.touch;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1569 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1570 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1571 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1572
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1573
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1574 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1575 // Obj - an object file built from a source file
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1576 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1577 final class Obj : File {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1578 static Obj[File] bySource; // object files by the source file they are built from
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1579
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1580 this(ref Origin origin, File source) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1581
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1582 string name_ = setExtension(source.name, "o");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1583 string path_ = prospectivePath("obj", source.parent, name_);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1584
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1585 super(origin, source.parent, name_, Privacy.PUBLIC, path_, false, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1586
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1587 errorUnless(source !in bySource, origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1588 "source file %s already used to build an object file", source);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1589 bySource[source] = this;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1590
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1591 string actionName;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1592 string actionCommand;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1593
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1594 switch (extension(source.name)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1595 case ".cc":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1596 case ".cpp":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1597 actionName = format("%-15s %s", "C++", path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1598 actionCommand = format("g++ -c %s -DTRACE_DOMAIN=\\\"%s\\\"",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1599 getOption("C++FLAGS"), source.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1600 foreach (dir; split(getOption("HEADERS"))) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1601 actionCommand ~= format(" -isystem %s", dir);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1602 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1603 actionCommand ~= " -iquote src -iquote obj -iquote .";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1604 actionCommand ~= format(" -o %s %s", path, source.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1605 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1606 case ".c":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1607 actionName = format("%-15s %s", "C", path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1608 actionCommand = format("gcc -c %s -DTRACE_DOMAIN=\\\"%s\\\"",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1609 getOption("CCFLAGS"), source.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1610 foreach (dir; split(getOption("HEADERS"))) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1611 actionCommand ~= format(" -isystem %s", dir);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1612 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1613 actionCommand ~= " -iquote src -iquote obj -iquote .";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1614 actionCommand ~= format(" -o %s %s", path, source.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1615 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1616 case ".d":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1617 actionName = format("%-15s %s", "D", path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1618 actionCommand = format("dmd -c %s", getOption("DFLAGS"));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1619 foreach (dir; split(getOption("IMPORTS"))) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1620 actionCommand ~= format(" -I%s", dir);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1621 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1622 actionCommand ~= " -Isrc -Iobj";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1623 actionCommand ~= format(" -of%s %s", path, source.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1624 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1625 default:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1626 error(origin, "Unsupported source file extension %s", extension(source.name));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1627 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1628
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1629 action = new Action(origin, actionName, actionCommand, [this], [source]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1630 addReference(origin, source);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1631 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1632 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1633
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1634
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1635 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1636 // Binary - a binary file incorporating object files and 'owning' source files.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1637 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1638 abstract class Binary : File {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1639 static Binary[File] byContent; // binaries by the header and body files they 'contain'
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1640
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1641 struct Source {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1642 string name;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1643 Privacy privacy;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1644 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1645
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1646 bool isD;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1647 File[] objs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1648 File[] headers;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1649 bool[SysLib] reqSysLibs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1650 bool[Binary] reqBinaries;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1651
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1652
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1653 // create a binary using files from this package.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1654 // All the sources themselves may be already-known built files,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1655 // but can't already be used by another Binary.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1656 this(ref Origin origin, Pkg pkg, string name_, string path_, string[] requires) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1657 super(origin, pkg, name_, Privacy.PUBLIC, path_, false, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1658
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1659 // required system libraries
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1660 foreach (req; requires) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1661 if (req !in SysLib.byName) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1662 new SysLib(req);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1663 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1664 SysLib lib = SysLib.byName[req];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1665 if (lib !in reqSysLibs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1666 reqSysLibs[lib] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1667 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1668 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1669 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1670
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1671 // Add sources to this Binary. Adding them after construction allows generated source
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1672 // files to be children of the Binary.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1673 void addMySources(ref Origin origin, Source[] sources) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1674
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1675 bool isScannable(string extension) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1676 return
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1677 extension == ".c" ||
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1678 extension == ".cc" ||
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1679 extension == ".h" ||
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1680 extension == ".d";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1681 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1682
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1683 errorUnless(sources.length > 0, origin, "binary must have at least one source file");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1684 foreach (source; sources) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1685 string ext = extension(source.name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1686 File sourceFile = File.addSource(origin, this, source.name, source.privacy, isScannable(ext));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1687 byContent[sourceFile] = this;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1688
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1689 if (ext == ".d" || ext == ".cc" || ext == ".c") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1690 // a source file that we generate an Obj from
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1691 objs ~= new Obj(origin, sourceFile);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1692
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1693 if (ext == ".d") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1694 isD = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1695 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1696 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1697 else if (ext == ".ipc") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1698 // an inter-process-communication file from which we generate a header file
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1699
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1700 // make sure the ipc-compiler has already been defined
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1701 string compilerPath = buildPath("dist", "bin", "ipc-compiler");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1702 File* compiler = compilerPath in File.byPath;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1703 errorUnless(compiler !is null,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1704 origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1705 "Cannot cook an ipc files before creating the compiler (%s)",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1706 compilerPath);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1707
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1708 // build a header file from this ipc file
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1709 string destPath = buildPath("obj", parent.trail, stripExtension(source.name) ~ ".h");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1710 File dest = new File(origin, this, baseName(destPath), source.privacy, destPath, true, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1711 dest.action = new Action(origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1712 format("%-15s %s", "cook-ipc", sourceFile.path),
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1713 format("ipc-compiler %s %s", sourceFile.path, dest.path),
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1714 [dest],
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1715 [sourceFile, *compiler]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1716 byContent[dest] = this;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1717 headers ~= dest;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1718 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1719 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1720 headers ~= sourceFile;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1721 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1722 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1723 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1724
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1725 override void includeAdded(ref Origin origin, File includer, File included) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1726 // A file we depend on (includer) has included another file (included).
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1727 // If this means that this 'needs' another Binary, remember the fact and
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1728 // also add a dependency on that other Binary. Note that the dependency
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1729 // is often not 'real' (a StaticLib doesn't actually depend on other StaticLibs),
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1730 // but it is a very useful simplification when working out which libraries an
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1731 // Exe depends on.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1732 //say("%s: %s includes %s", this.path, includer.path, included.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1733 if (includer in byContent && byContent[includer] is this) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1734 Binary * container = included in byContent;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1735 errorUnless(container !is null, origin, "included file is not contained in a library");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1736 if (*container !is this && *container !in reqBinaries) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1737
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1738 // we require the container of the included file
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1739 reqBinaries[*container] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1740
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1741 // add a dependancy and a reference
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1742 addReference(origin, *container, format(" because %s includes %s", includer.path, included.path));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1743 action.addDependency(*container);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1744 //say("%s requires %s", this.path, container.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1745 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1746 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1747 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1748 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1749
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1750
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1751 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1752 // StaticLib - a static library.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1753 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1754 final class StaticLib : Binary {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1755
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1756 string uniqueName;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1757
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1758 this(ref Origin origin, Pkg pkg, string name_, string[] requires) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1759 uniqueName = std.array.replace(buildPath(pkg.trail, name_), dirSeparator, "-") ~ "-s";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1760 if (name_ == pkg.name) uniqueName = std.array.replace(pkg.trail, dirSeparator, "-") ~ "-s";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1761 string _path = buildPath("obj", format("lib%s.a", uniqueName));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1762 super(origin, pkg, name_, _path, requires);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1763 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1764
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1765 void addSources(ref Origin origin, string[] publicSources, string[] protectedSources) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1766 Source[] sources;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1767 foreach (name; protectedSources) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1768 sources ~= Source(name, Privacy.SEMI_PROTECTED);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1769 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1770 foreach (name; publicSources) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1771 sources ~= Source(name, Privacy.PUBLIC);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1772 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1773 addMySources(origin, sources);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1774
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1775 // action
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1776 string command;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1777 if (objs.length) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1778 command = format("rm -f %s; ar csr %s", path, path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1779 foreach (obj; objs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1780 command ~= format(" %s", obj.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1781 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1782 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1783 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1784 command = format("rm -f %s; echo dummy > %s", path, path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1785 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1786 action = new Action(origin, format("%-15s %s", "StaticLib", path), command, [this], objs ~ headers);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1787 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1788 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1789
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1790
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1791 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1792 // DynamicLib - a dynamic library. Contains all of the object files
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1793 // from a number of specified StaticLibs. If defined prior to an Exe, the Exe will
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1794 // link with the DynamicLib instead of those StaticLibs.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1795 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1796 // Any StaticLibs required by the incorporated StaticLibs must also be incorporated
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1797 // into DynamicLibs.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1798 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1799 // The static lib names are relative to pkg, and therefore only descendants of the DynamicLib's
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1800 // parent can be incorporated.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1801 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1802 final class DynamicLib : File {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1803 static DynamicLib[StaticLib] byContent; // dynamic libs by the static libs they 'contain'
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1804 Origin origin;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1805 bool augmented;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1806 string uniqueName;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1807
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1808 StaticLib[] staticLibs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1809
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1810 this(ref Origin origin_, Pkg pkg, string name_, string[] staticTrails, bool isPlugin) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1811 origin = origin_;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1812
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1813 uniqueName = std.array.replace(buildPath(pkg.trail, name_), "/", "-");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1814 if (name_ == pkg.name) uniqueName = std.array.replace(pkg.trail, dirSeparator, "-");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1815 string _path = buildPath("dist", "lib", format("lib%s.so", uniqueName));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1816 if (isPlugin) _path = buildPath("dist", "lib", "plugins", format("lib%s.so", uniqueName));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1817
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1818 super(origin, pkg, name_ ~ "-dynamic", Privacy.PUBLIC, _path, false, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1819
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1820 foreach (trail; staticTrails) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1821 string trail1 = buildPath(pkg.trail, trail, baseName(trail));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1822 string trail2 = buildPath(pkg.trail, trail);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1823 Node* node = trail1 in Node.byTrail;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1824 if (node is null || cast(StaticLib*) node is null) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1825 node = trail2 in Node.byTrail;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1826 if (node is null || cast(StaticLib*) node is null) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1827 error(origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1828 "Unknown static-lib %s, looked for with trails %s and %s",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1829 trail, trail1, trail2);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1830 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1831 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1832 StaticLib* staticLib = cast(StaticLib*) node;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1833 errorUnless(*staticLib !in byContent, origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1834 "static lib %s already used by dynamic lib %s",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1835 *staticLib, byContent[*staticLib]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1836 addReference(origin, *staticLib);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1837 staticLibs ~= *staticLib;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1838 byContent[*staticLib] = this;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1839 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1840 errorUnless(staticLibs.length > 0, origin, "dynamic-lib must have at least one static-lib");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1841
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1842 // action
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1843 bool[SysLib] gotSysLibs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1844 string actionName = format("%-15s %s", "DynamicLib", path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1845 string command = format("g++ -shared %s -o %s", getOption("LINKFLAGS"), path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1846 File[] depLibs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1847 foreach (staticLib; staticLibs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1848 depLibs ~= staticLib;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1849 foreach (obj; staticLib.objs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1850 command ~= format(" %s", obj.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1851 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1852 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1853
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1854 action = new Action(origin, actionName, command, [cast(File)this], depLibs);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1855 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1856
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1857
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1858 // Called just before our action is issued.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1859 // Verify that all the StaticLibs we now know that we depend on are contained by this or
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1860 // another earlier-defined-than-this DynamicLib.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1861 // Add any required SysLibs to our action.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1862 override bool augmentAction() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1863 if (augmented) return false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1864 augmented = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1865
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1866 bool[StaticLib] doneStaticLibs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1867 bool[SysLib] gotSysLibs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1868 SysLib[] sysLibs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1869 bool added;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1870
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1871 //say("augmenting action for DynamicLib %s", name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1872 void accumulate(StaticLib lib) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1873 //say(" accumulating %s", lib.name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1874 foreach (other; lib.reqBinaries.keys) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1875 StaticLib next = cast(StaticLib) other;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1876 assert(next !is null);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1877 if (next !in doneStaticLibs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1878 accumulate(next);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1879 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1880 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1881 if (lib !in doneStaticLibs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1882 doneStaticLibs[lib] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1883 errorUnless(lib.objs.length == 0 ||
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1884 (lib in byContent && byContent[lib].number <= number),
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1885 origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1886 "dynamic-lib %s requires static-lib %s (%s) which "
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1887 "is not contained in a pre-defined dynamic-lib",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1888 name, lib.trail, lib.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1889 foreach (sys; lib.reqSysLibs.keys) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1890 if (sys !in gotSysLibs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1891 //say(" new required SysLib %s", sys.name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1892 gotSysLibs[sys] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1893 sysLibs ~= sys;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1894 added = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1895 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1896 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1897 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1898 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1899 foreach (lib; staticLibs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1900 accumulate(lib);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1901 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1902
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1903 string augmentation;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1904 foreach (sys; sysLibs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1905 augmentation ~= format(" -l%s", sys.name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1906 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1907 //say("augmentation is %s", augmentation);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1908 action.augment(augmentation);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1909 return added;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1910 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1911 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1912
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1913
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1914 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1915 // Exe - An executable file
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1916 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1917 final class Exe : Binary {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1918
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1919 bool augmented;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1920 string desc;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1921 string src;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1922 string dest;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1923
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1924 // create an executable using files from this package, linking to libraries
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1925 // that contain any included header files, and any required system libraries.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1926 // Note that any system libraries required by inferred local libraries are
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1927 // automatically linked to.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1928 this(ref Origin origin, Pkg pkg, string kind, string name_, string[] requires) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1929 // interpret kind
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1930 switch (kind) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1931 case "dist-util": desc = "DistUtil"; src = "util"; dest = buildPath("dist", "bin", name_); break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1932 case "priv-util": desc = "PrivUtil"; src = "util"; dest = buildPath("priv", pkg.trail, name_); break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1933 case "test-util": desc = "TestExe"; src = "test"; dest = buildPath("priv", pkg.trail, name_); break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1934 default: assert(0, "invalid Exe kind " ~ kind);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1935 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1936
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1937 super(origin, pkg, name_ ~ "-exe", dest, requires);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1938
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1939 if (kind == "test-util") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1940 File test = new File(origin, pkg, name ~ "-result",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1941 Privacy.PRIVATE, dest ~ "-passed", false, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1942 test.action = new Action(origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1943 format("%-15s %s", "TestResult", test.path),
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1944 format("./test %s", dest),
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1945 [test],
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1946 [this]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1947 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1948 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1949
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1950
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1951 void addSources(ref Origin origin, string[] sources) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1952 errorUnless(sources.length > 0, origin, "An exe must have at least one source file");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1953 Source[] _sources;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1954 foreach (source; sources) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1955 _sources ~= Source(buildPath(src, source), Privacy.PROTECTED);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1956 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1957 addMySources(origin, _sources);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1958
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1959 // exe action
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1960 string command;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1961 string ext = extension(sources[0]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1962 switch (ext) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1963 case ".cc":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1964 case ".c":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1965 command = format("%s %s -o %s",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1966 ext == "c" ? "gcc" : "g++",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1967 getOption("LINKFLAGS"), dest);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1968 foreach (dir; split(getOption("HEADERS"))) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1969 command ~= format(" -isystem %s", dir);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1970 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1971 foreach (obj; objs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1972 command ~= format(" %s", obj.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1973 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1974 command ~= format(" -L%s", buildPath("dist", "lib"));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1975 command ~= format(" -L%s", buildPath("dist", "lib", "plugins"));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1976 command ~= format(" -Lobj");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1977 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1978 case ".d":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1979 command = format("dmd %s -of%s ", getOption("DLINKFLAGS"), path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1980 foreach (obj; objs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1981 command ~= format(" %s", obj.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1982 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1983 command ~= format(" -L-Lobj");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1984 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1985 default:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1986 error(origin, "Unsupported source file extension %s in %s", extension(sources[0]), path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1987 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1988
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1989 action = new Action(origin, format("%-15s %s", desc, dest), command, [this], objs ~ headers);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1990 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1991
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1992
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1993 // Called just before our action is issued - augment the action's command string
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1994 // with the library dependencies that we should now know about via includeAdded().
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1995 // Return true if dependencies were added.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1996 override bool augmentAction() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1997 if (augmented) return false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1998 augmented = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
1999 bool added = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2000 //say("augmenting %s's action command", this);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2001
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2002 // binaries we require, with most fundamental first
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2003 bool[DynamicLib] gotDynamicLibs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2004 bool[StaticLib] gotStaticLibs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2005 bool[SysLib] gotSysLibs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2006 DynamicLib[] dynamicLibs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2007 StaticLib[] staticLibs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2008 SysLib[] sysLibs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2009
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2010 // accumulate the libraries needed
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2011 void accumulate(Binary binary) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2012 //say("accumulating binary %s", binary.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2013 foreach (other; binary.reqBinaries.keys) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2014 StaticLib lib = cast(StaticLib) other;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2015 assert(lib !is null);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2016 if (lib !in gotStaticLibs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2017 accumulate(other);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2018 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2019 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2020 if (binary is this) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2021 foreach (sys; reqSysLibs.keys) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2022 if (sys !in gotSysLibs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2023 //say(" using sys-lib %s", sys.name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2024 gotSysLibs[sys] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2025 sysLibs ~= sys;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2026 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2027 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2028 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2029 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2030 StaticLib lib = cast(StaticLib) binary;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2031 if (lib !in gotStaticLibs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2032 //say(" require static-lib %s", lib.uniqueName);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2033 gotStaticLibs[lib] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2034 foreach (sys; lib.reqSysLibs.keys) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2035 if (sys !in gotSysLibs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2036 //say(" using sys-lib %s", sys.name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2037 gotSysLibs[sys] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2038 sysLibs ~= sys;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2039 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2040 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2041
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2042 DynamicLib* dynamic = lib in DynamicLib.byContent;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2043 if (dynamic !is null && dynamic.number < this.number) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2044 // use the dynamic lib that contains the static lib
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2045 if (*dynamic !in gotDynamicLibs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2046 //say(" using dynamic-lib %s to cover %s", dynamic.name, lib.uniqueName);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2047 gotDynamicLibs[*dynamic] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2048 dynamicLibs ~= *dynamic;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2049 action.addDependency(*dynamic);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2050 added = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2051
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2052 // we have to also accumulate everything this dynamic lib needs
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2053 foreach (contained; dynamic.staticLibs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2054 accumulate(contained);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2055 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2056 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2057 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2058 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2059 // use the static lib
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2060 //say(" using static-lib %s", lib.uniqueName);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2061 staticLibs ~= lib;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2062 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2063 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2064 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2065 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2066 //say("accumulating required libraries for exe %s", path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2067 accumulate(this);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2068
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2069 string extra;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2070 if (isD) extra = "-L";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2071
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2072 string augmentation;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2073 foreach (lib; retro(staticLibs)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2074 if (lib.objs.length) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2075 augmentation ~= format(" %s-l%s", extra, lib.uniqueName);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2076 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2077 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2078 foreach (lib; retro(dynamicLibs)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2079 augmentation ~= format(" %s-l%s", extra, lib.uniqueName);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2080 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2081 foreach (lib; retro(sysLibs)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2082 augmentation ~= format(" %s-l%s", extra, lib.name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2083 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2084 //say("%s augmentation is '%s'", this, augmentation);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2085
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2086 action.augment(augmentation);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2087 return added;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2088 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2089 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2090
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2091
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2092 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2093 // Mark all built files in child or referred packages as needed
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2094 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2095 int markNeeded(Node given) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2096 static bool[Node] done;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2097
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2098 int qty = 0;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2099 if (given in done) return qty;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2100 done[given] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2101
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2102 File file = cast(File) given;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2103 if (file && file.built) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2104 // activate this file
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2105 if (file.action is null) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2106 fatal("file %s activated before its action was set", file);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2107 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2108 //say("activating %s", file.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2109 file.activated = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2110 File.allActivated[file] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2111 File.outstanding[file] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2112 qty++;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2113 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2114
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2115 // recurse into child and referred nodes
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2116 foreach (child; chain(given.children, given.refers)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2117 qty += markNeeded(child);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2118 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2119
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2120 if (file) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2121 // touch this file to trigger building
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2122 file.touch;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2123 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2124
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2125 return qty;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2126 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2127
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2128
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2129 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2130 // Process a Bobfile
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2131 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2132 void processBobfile(string indent, Pkg pkg) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2133 static bool[Pkg] processed;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2134 if (pkg in processed) return;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2135 processed[pkg] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2136
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2137 if (g_print_rules) say("%sprocessing %s", indent, pkg.bobfile);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2138 indent ~= " ";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2139 foreach (statement; readBobfile(pkg.bobfile.path)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2140 if (g_print_rules) say("%s%s", indent, statement.toString);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2141 switch (statement.rule) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2142
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2143 // packages
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2144 case "contain":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2145 foreach (name; statement.targets) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2146 errorUnless(dirName(name) == ".", statement.origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2147 "Contained packages have to be top-level");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2148 Privacy privacy = privacyOf(statement.origin, statement.arg1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2149 Pkg newPkg = new Pkg(statement.origin, pkg, name, privacy);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2150 processBobfile(indent, newPkg);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2151 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2152 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2153
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2154 case "refer":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2155 foreach (trail; statement.targets) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2156 Pkg* other = cast(Pkg*) (trail in Node.byTrail);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2157 if (other is null) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2158 // create the referenced package which must be top-level, then refer to it
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2159 errorUnless(dirName(trail) == ".", statement.origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2160 "Previously-unknown referenced package %s has to be top-level", trail);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2161 Pkg newPkg = new Pkg(statement.origin, Node.byTrail["root"], trail, Privacy.PUBLIC);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2162 processBobfile(indent, newPkg);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2163 pkg.addReference(statement.origin, newPkg);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2164 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2165 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2166 // refer to the existing package
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2167 errorUnless(other !is null, statement.origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2168 "Cannot refer to unknown pkg %s", trail);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2169 pkg.addReference(statement.origin, *other);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2170 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2171 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2172 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2173
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2174 // libraries
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2175 case "static-lib":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2176 {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2177 errorUnless(statement.targets.length == 1, statement.origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2178 "Can only have one static-lib name per rule");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2179 StaticLib lib = new StaticLib(statement.origin, pkg, statement.targets[0], statement.arg3);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2180 lib.addSources(statement.origin, statement.arg1, statement.arg2);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2181 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2182 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2183
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2184 case "dynamic-lib":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2185 {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2186 errorUnless(statement.targets.length == 1, statement.origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2187 "Can only have one dynamic-lib name per rule");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2188 new DynamicLib(statement.origin, pkg, statement.targets[0], statement.arg1,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2189 statement.arg2.length == 1 && statement.arg2[0] == "plugin");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2190 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2191 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2192
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2193 case "dist-util":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2194 case "priv-util":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2195 case "test-util":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2196 {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2197 errorUnless(statement.targets.length == 1,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2198 statement.origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2199 "Can only have one util/exe name per rule");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2200 Exe exe = new Exe(statement.origin, pkg, statement.rule, statement.targets[0], statement.arg2);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2201 exe.addSources(statement.origin, statement.arg1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2202 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2203 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2204
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2205 case "tao-lib":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2206 {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2207 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2208 // tao-lib lib-name : idl-sources; # idl files and gen src in package dir
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2209 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2210 errorUnless(statement.targets.length == 1, statement.origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2211 "Can only have one tao static-lib name per rule");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2212
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2213
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2214 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2215 // create the static-lib
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2216 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2217
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2218 auto requires = [
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2219 "TAO_CosNaming",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2220 "TAO_PortableServer",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2221 "TAO_DynamicAny",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2222 "TAO",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2223 "ACE",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2224 "rt",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2225 "dl"];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2226 auto lib = new StaticLib(statement.origin, pkg, statement.targets[0], requires);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2227
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2228 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2229 // create the idl files and the source files generated from them
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2230 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2231
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2232 string[] publicNames;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2233 string[] protectedNames;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2234 foreach (idlName; statement.arg1) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2235
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2236 // idl file
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2237 File idl = File.addSource(statement.origin, pkg, idlName, Privacy.PROTECTED, false);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2238
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2239 // paths of all generated files
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2240 string base = buildPath("obj", pkg.trail, stripExtension(idlName));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2241 string[] junk = [
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2242 base ~ "S_T.cc"];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2243 string[] publicPaths = [
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2244 base ~ "C.h",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2245 base ~ "S.h" ];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2246 string[] protectedPaths = [
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2247 base ~ "S_T.inl",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2248 base ~ "C.inl",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2249 base ~ "S.inl",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2250 base ~ "S_T.h",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2251 base ~ "C.cc",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2252 base ~ "S.cc" ];
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2253
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2254 // generated files
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2255 File[] files;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2256 foreach (path; junk) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2257 files ~= new File(statement.origin, lib, baseName(path),
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2258 Privacy.PRIVATE, path, false, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2259 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2260 foreach (path; publicPaths) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2261 files ~= new File(statement.origin, lib, baseName(path),
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2262 Privacy.PUBLIC, path, !(extension(path) == ".inl"), true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2263 publicNames ~= baseName(path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2264 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2265 foreach (path; protectedPaths) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2266 files ~= new File(statement.origin, lib, baseName(path),
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2267 Privacy.PROTECTED, path, !(extension(path) == ".inl"), true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2268 protectedNames ~= baseName(path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2269 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2270
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2271 // action to generate the files and edit them to be correct
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2272 string command = format("%s -in -Ce -cs C.cc -ss S.cc -sT S_T.cc", getOption("TAO_IDL"));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2273 if (toLower(getOption("GENERATE_EMPTY_SERVANT")) == "true") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2274 command ~= " -GI -GIh \"_impl-rename.h\" -GIs \"_impl-rename.cc\" -GIe \"Impl\" -GIc -GIa";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2275 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2276 foreach (d; split(getOption("IDL_HEADERS"))) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2277 command ~= format(" -I%s", d);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2278 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2279 command ~= format(" -I%s", dirName(idl.path));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2280 command ~= format(" -I%s", dirName(base));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2281 command ~= " -o " ~ buildPath("obj", pkg.trail) ~ " " ~ idl.path ~ " &&";
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2282 command ~=
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2283 ` sed --in-place --separate` ~
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2284 ` -e '/#include/s/\"orbsvcs\/\([^\"]*\)\"/\<orbsvcs\/\1\>/'` ~
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2285 ` -e '/#include/s/\"tao\/\([^\"]*\)\"/\<tao\/\1\>/'` ~
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2286 ` -e '/#include/s/\"ace\/\([^\"]*\)\"/\<ace\/\1\>/'` ~
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2287 ` -e '/#include \"/s|#include \"|#include \"` ~ pkg.trail ~ `/|'` ~ // XXX should not do this if included path contains a slash
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2288 ` -e '/#include .*.cc/d'` ~
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2289 ` -e 's/[[:space:]]\+$//'`;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2290 foreach (file; files) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2291 command ~= " " ~ file.path;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2292 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2293 auto action = new Action(statement.origin, format("%-15s %s", statement.rule, idl.path),
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2294 command, files, [idl]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2295
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2296 foreach (file; files) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2297 file.action = action;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2298 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2299 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2300
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2301 // add the generated source files as the sources of the library, completing its definition
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2302 lib.addSources(statement.origin, publicNames, protectedNames);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2303 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2304 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2305
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2306 case "dist-data":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2307 case "test-data":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2308 case "util-data":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2309 case "doc-data":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2310 {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2311 void dataRule(ref Origin origin, Pkg pkg, string kind, string extra) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2312 string fromPath;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2313 string destPath;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2314 if (kind == "doc-data") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2315 fromPath = buildPath("src", pkg.trail, "doc", extra);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2316 destPath = buildPath("priv", pkg.trail, "doc", extra);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2317 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2318 else if (kind == "test-data") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2319 fromPath = buildPath("src", pkg.trail, "test", extra);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2320 destPath = buildPath("priv", pkg.trail, extra);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2321 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2322 else if (kind == "util-data") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2323 fromPath = buildPath("src", pkg.trail, "util", extra);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2324 destPath = buildPath("priv", pkg.trail, extra);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2325 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2326 else if (kind == "dist-data") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2327 fromPath = buildPath("src", pkg.trail, "data", extra);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2328 destPath = buildPath("dist", "data", extra);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2329 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2330
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2331 if (isDir(fromPath)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2332 // recurse into directory
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2333 foreach (string path; dirEntries(fromPath, SpanMode.shallow)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2334 dataRule(origin, pkg, kind, buildPath(extra, path.baseName));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2335 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2336 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2337 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2338 // set up from and dest files, and an action to create the dest.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2339 string name = std.array.replace(extra, dirSeparator, "-");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2340 File from = new File(origin, pkg, name ~ "-src", Privacy.PUBLIC, fromPath, false, false);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2341 File dest = new File(origin, pkg, name ~ "-dest", Privacy.PUBLIC, destPath, false, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2342 dest.action = new Action(origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2343 format("%-15s %s", "Data", dest.path),
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2344 format("cp %s %s", from.path, dest.path),
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2345 [dest],
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2346 [from]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2347 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2348 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2349
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2350 foreach (name; statement.targets) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2351 dataRule(statement.origin, pkg, statement.rule, name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2352 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2353 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2354 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2355
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2356 case "doc":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2357 {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2358 foreach (name; statement.targets) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2359 string fromPath = buildPath("src", pkg.trail, "doc", name ~ ".rst");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2360 string destPath = buildPath("priv", pkg.trail, "doc", name ~ ".html");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2361
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2362 errorUnless(exists(fromPath) && !isDir(fromPath), statement.origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2363 "%s not found", fromPath);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2364
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2365 File from = new File(statement.origin, pkg, name ~ "-rst",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2366 Privacy.PUBLIC, fromPath, false, false);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2367
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2368 File dest = new File(statement.origin, pkg, name ~ "-html",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2369 Privacy.PUBLIC, destPath, false, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2370
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2371 dest.action = new Action(statement.origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2372 format("%-15s %s", "Doc", dest.path),
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2373 format("%s --exit-status=2 %s %s",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2374 getOption("RST2HTML"), from.path, dest.path),
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2375 [dest],
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2376 [from]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2377 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2378 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2379 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2380
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2381 case "dist-shell":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2382 case "priv-shell":
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2383 {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2384 foreach (name; statement.targets) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2385
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2386 string fromPath = buildPath("src", pkg.trail, "util", name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2387 string destPath;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2388 if (statement.rule == "dist-shell") {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2389 destPath = buildPath("dist", "bin", name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2390 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2391 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2392 destPath = buildPath("priv", pkg.trail, name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2393 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2394
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2395 errorUnless(exists(fromPath) && !isDir(fromPath), statement.origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2396 "%s not found", fromPath);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2397
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2398 File from = new File(statement.origin, pkg, name ~ "-sh",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2399 Privacy.PUBLIC, fromPath, false, false);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2400
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2401 File dest = new File(statement.origin, pkg, name,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2402 Privacy.PUBLIC, destPath, false, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2403
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2404 dest.action = new Action(statement.origin,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2405 format("%-15s %s", "Shell", dest.path),
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2406 format("cp -f %s %s && chmod +x %s",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2407 from.path, dest.path, dest.path),
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2408 [dest],
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2409 [from]);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2410 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2411 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2412 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2413
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2414 default:
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2415 error(statement.origin, "Unsupported rule '%s'", statement.rule);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2416 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2417 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2418 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2419
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2420
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2421 // remove any files in obj, priv and dist that aren't marked as needed
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2422 void cleandirs() {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2423 void cleanDir(string name) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2424 //say("cleaning dir %s, cdw=%s", name, getcwd);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2425 if (exists(name) && isDir(name)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2426 bool[string] dirs;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2427 foreach (DirEntry entry; dirEntries(name, SpanMode.depth, false)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2428 //say(" considering %s", entry.name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2429 bool isDir = attrIsDir(entry.linkAttributes);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2430
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2431 if (!isDir) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2432 File* file = entry.name in File.byPath;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2433 if (file is null || (*file) !in File.allActivated) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2434 say("Removing unwanted file %s", entry.name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2435 std.file.remove(entry.name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2436 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2437 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2438 // leaving a file in place
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2439 //say(" keeping activated file %s", file.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2440 dirs[entry.name.dirName] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2441 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2442 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2443 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2444 if (entry.name !in dirs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2445 //say("removing empty dir %s", entry.name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2446 rmdir(entry.name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2447 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2448 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2449 //say(" keeping non-empty dir %s", entry.name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2450 dirs[entry.name.dirName] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2451 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2452 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2453 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2454 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2455 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2456 cleanDir("obj");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2457 cleanDir("priv");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2458 cleanDir("dist");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2459 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2460
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2461
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2462 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2463 // Planner function
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2464 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2465 bool doPlanning(int numJobs, bool printRules, bool printDeps, bool printDetails) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2466
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2467 // state variables
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2468 size_t inflight;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2469 bool[string] workers;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2470 bool[string] idlers;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2471 bool exiting;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2472 bool success = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2473
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2474 // receive registration message from each worker and remember its name
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2475 while (workers.length < numJobs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2476 receive( (string worker) { workers[worker] = true; idlers[worker] = true; } );
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2477 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2478
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2479 // local function: an action has completed successfully - update all files built by it
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2480 void actionCompleted(string worker, string action) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2481 //say("%s %s succeeded", action, worker);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2482 --inflight;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2483 idlers[worker] = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2484 try {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2485 foreach (file; Action.byName[action].builds) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2486 file.updated;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2487 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2488 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2489 catch (BailException ex) { exiting = true; success = false; }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2490 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2491
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2492 // local function: a worker has terminated - remove it from workers and remember we are exiting
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2493 void workerTerminated(string worker) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2494 exiting = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2495 workers.remove(worker);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2496 //say("%s has terminated - %s workers remaining", worker, workers.length);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2497 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2498
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2499
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2500 // set up some globals
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2501 readOptions;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2502 g_print_rules = printRules;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2503 g_print_deps = printDeps;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2504 g_print_details = printDetails;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2505
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2506 string projectPackage = getOption("PROJECT-PACKAGE");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2507
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2508 int needed;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2509 try {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2510 // read the project Bobfile and descend into all those it refers to
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2511 auto root = new Node();
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2512 auto project = new Pkg(Origin(), root, projectPackage, Privacy.PRIVATE);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2513 processBobfile("", project);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2514
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2515 // mark all files needed by the project Bobfile as needed, priming the action queue
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2516 needed = markNeeded(project);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2517
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2518 cleandirs();
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2519 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2520 catch (BailException ex) { exiting = true; success = false; }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2521
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2522 while (workers.length) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2523
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2524 // give any idle workers something to do
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2525 //say("%s idle workers and %s actions in priority queue", idlers.length, Action.queue.length);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2526 string[] toilers;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2527 foreach (idler, dummy; idlers) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2528
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2529 if (!exiting && !File.outstanding.length) exiting = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2530
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2531 Tid tid = std.concurrency.locate(idler);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2532
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2533 if (exiting) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2534 // tell idle worker to terminate
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2535 //say("telling %s to terminate", idler);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2536 send(tid, true);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2537 toilers ~= idler;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2538 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2539 else if (!Action.queue.empty) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2540 // give idle worker an action to perform
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2541 //say("giving %s an action", idler);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2542
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2543 const Action next = Action.queue.front();
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2544 Action.queue.popFront();
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2545
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2546 string targets;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2547 foreach (target; next.builds) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2548 ensureParent(target.path);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2549 targets ~= "|" ~ target.path;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2550 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2551 //say("issuing action %s", next.name);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2552 send(tid, next.name.idup, next.command.idup, targets.idup);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2553 toilers ~= idler;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2554 ++inflight;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2555 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2556 else if (!inflight) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2557 fatal("nothing to do and no inflight actions");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2558 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2559 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2560 // nothing to do
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2561 //say("nothing to do - waiting for results");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2562 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2563 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2564 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2565 foreach (toiler; toilers) idlers.remove(toiler);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2566
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2567 // receive a completion or failure
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2568 receive( (string worker, string action) { actionCompleted(worker, action); },
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2569 (string worker) { workerTerminated(worker); } );
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2570 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2571
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2572 if (!File.outstanding.length && success) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2573 say("\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2574 "Total number of files: %s\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2575 "Number of target files: %s\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2576 "Number of activated target files: %s\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2577 "Number of files updated: %s\n",
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2578 File.byPath.length, File.numBuilt, needed, File.numUpdated);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2579 return true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2580 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2581 return false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2582 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2583
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2584
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2585 //-----------------------------------------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2586 // Worker
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2587 //-----------------------------------------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2588
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2589 void doWork(bool printActions, uint index, Tid plannerTid) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2590 bool success;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2591
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2592 string myName = format("worker-%d", index);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2593 std.concurrency.register(myName, thisTid);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2594
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2595 void perform(string action, string command, string targets) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2596 if (printActions) { say("\n%s\n", command); }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2597 say("%s", action);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2598
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2599 success = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2600 string results = buildPath(".bob", myName);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2601
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2602 // launch child process to do the action
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2603 string str = command ~ " 2>" ~ results;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2604 pid_t child = launcher.launch(str);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2605
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2606 // wait for it to complete
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2607 for (;;) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2608 int status;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2609 pid_t wpid = core.sys.posix.sys.wait.waitpid(child, &status, 0);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2610 if (wpid == -1) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2611 // error, possibly a signal - treat as failure
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2612 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2613 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2614 else if (wpid == 0) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2615 // non-blocking return, which should not happen - treat as failure
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2616 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2617 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2618 else if ((status & 0x7f) == 0) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2619 // child has terminated - might be success
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2620 success = ((status & 0xff00) >> 8) == 0;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2621 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2622 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2623 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2624 // child state has changed in some way other than termination - treat as failure
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2625 break;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2626 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2627 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2628 launcher.completed(child);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2629 if (!success) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2630 bool bailed = launcher.bail;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2631
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2632 // delete built files
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2633 foreach (target; split(targets, "|")) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2634 if (exists(target)) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2635 say(" Deleting %s", target);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2636 std.file.remove(target);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2637 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2638 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2639
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2640 // print error message
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2641 if (!bailed) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2642 say("\n%s", readText(results));
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2643 say("%s: FAILED\n%s", action, command);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2644 fatal("Aborting build due to action failure");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2645 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2646 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2647 // just quietly throw
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2648 throw new BailException();
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2649 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2650 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2651 else {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2652 // tell planner the action succeeded
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2653 send(plannerTid, myName, action);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2654 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2655 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2656
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2657
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2658 try {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2659 send(plannerTid, myName);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2660 bool done;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2661 while (!done) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2662 receive( (string action, string command, string targets) { perform(action, command, targets); },
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2663 (bool dummy) { done = true; });
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2664 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2665 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2666 catch (BailException) {}
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2667 catch (Exception ex) { say("Unexpected exception %s", ex); }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2668
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2669 // tell planner we are terminating
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2670 send(plannerTid, myName);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2671 //say("%s terminating", myName);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2672 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2673
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2674
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2675 //--------------------------------------------------------------------------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2676 // main
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2677 //
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2678 // Assumes that the top-level source packages are all located in a src subdirectory,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2679 // and places build outputs in obj, priv and dist subdirectories.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2680 // The local source paths are necessary to minimise the length of actions,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2681 // and is usually achieved by a configure step setting up sym-links to the
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2682 // actual source locations.
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2683 //--------------------------------------------------------------------------------------
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2684
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2685 int main(string[] args) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2686 try {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2687 bool printRules = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2688 bool printDeps = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2689 bool printDetails = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2690 bool printActions = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2691 bool help = false;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2692 uint numJobs = 1;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2693
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2694 int returnValue = 0;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2695 try {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2696 getopt(args,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2697 std.getopt.config.caseSensitive,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2698 "rules", &printRules,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2699 "deps", &printDeps,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2700 "details", &printDetails,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2701 "actions", &printActions,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2702 "jobs|j", &numJobs,
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2703 "help", &help);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2704 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2705 catch (std.conv.ConvException ex) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2706 returnValue = 2;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2707 say(ex.msg);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2708 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2709 catch (object.Exception ex) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2710 returnValue = 2;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2711 say(ex.msg);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2712 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2713
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2714 if (args.length != 1) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2715 say("Option processing failed. There are %s unprocessed argument(s): ", args.length - 1);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2716 foreach (uint i, arg; args[1..args.length]) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2717 say(" %s. \"%s\"", i + 1, arg);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2718 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2719 returnValue = 2;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2720 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2721 if (numJobs < 1) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2722 returnValue = 2;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2723 say("Must allow at least one job!");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2724 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2725 if (returnValue != 0 || help) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2726 say("Usage: bob [options]\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2727 " --rules print rules\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2728 " --deps print dependencies\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2729 " --actions print actions\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2730 " --details print heaps of details\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2731 " --jobs=VALUE maximum number of simultaneous actions\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2732 " --help show this message\n"
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2733 "target is everything contained in the project Bobfile and anything referred to.");
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2734 return returnValue;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2735 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2736
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2737 if (printDetails) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2738 printActions = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2739 printDeps = true;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2740 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2741
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2742
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2743 // spawn the workers
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2744 foreach (uint i; 0..numJobs) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2745 //say("spawning worker %s", i);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2746 spawn(&doWork, printActions, i, thisTid);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2747 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2748
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2749 // build everything
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2750 returnValue = doPlanning(numJobs, printRules, printDeps, printDetails) ? 0 : 1;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2751
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2752 return returnValue;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2753 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2754 catch (Exception ex) {
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2755 say("got unexpected exception %s", ex);
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2756 return 1;
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2757 }
89e8b0d92f36 Ported to bob2 !!!
David Bryant <bagnose@gmail.com>
parents:
diff changeset
2758 }