aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-08-26 17:24:48 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-08-26 18:04:22 +0200
commit4a23b4cdf3102a8fef8ac6ebd8a884cd613c28ee (patch)
tree9fdd028cddde76ea4037c55fd7430950a0d05dd5
parent4177d70e63893d0a2c76beb9166ebbf79c4697a0 (diff)
Implement auto-import of development build2 build
-rw-r--r--build2/b.cxx1
-rw-r--r--build2/cc/link-rule.cxx3
-rw-r--r--libbuild2/buildfile20
-rw-r--r--libbuild2/context.cxx10
-rw-r--r--libbuild2/context.hxx3
-rw-r--r--libbuild2/file.cxx33
-rw-r--r--libbuild2/utility-installed.cxx24
-rw-r--r--libbuild2/utility.cxx2
-rw-r--r--libbuild2/utility.hxx6
-rw-r--r--tests/build/root.build5
10 files changed, 96 insertions, 11 deletions
diff --git a/build2/b.cxx b/build2/b.cxx
index 49a4d34..27a9cd0 100644
--- a/build2/b.cxx
+++ b/build2/b.cxx
@@ -609,6 +609,7 @@ main (int argc, char* argv[])
trace << "work: " << work;
trace << "home: " << home;
trace << "path: " << (p ? *p : "<NULL>");
+ trace << "type: " << (build_installed ? "installed" : "development");
trace << "jobs: " << jobs;
}
diff --git a/build2/cc/link-rule.cxx b/build2/cc/link-rule.cxx
index fa6d5e4..ce5fce9 100644
--- a/build2/cc/link-rule.cxx
+++ b/build2/cc/link-rule.cxx
@@ -1821,7 +1821,10 @@ namespace build2
if (lookup l = p.prerequisite.vars[var_fi])
{
if (cast<bool> (l) != for_install)
+ {
+ l5 ([&]{trace << "excluding " << *pt << " due to for_install";});
pt = nullptr;
+ }
}
}
}
diff --git a/libbuild2/buildfile b/libbuild2/buildfile
index 7d91e08..deda991 100644
--- a/libbuild2/buildfile
+++ b/libbuild2/buildfile
@@ -9,8 +9,14 @@
import int_libs = libbutl%lib{butl}
-lib{build2}: libul{build2}: {hxx ixx txx cxx}{* -config -version -*.test...} \
- {hxx}{config version}
+lib{build2}: libul{build2}: \
+ {hxx ixx txx cxx}{* -utility-installed -config -version -*.test...} \
+ {hxx}{config version}
+
+# Note that this won't work on libul{} since it's never installed.
+#
+lib{build2}: cxx{utility-installed}: for_install = true
+liba{build2}: bin.whole = true # See utility-installed.cxx.
# These are "core modules" that come bundled with libbuild2 (see also unit
# tests loop below). Note that the build system core can still function
@@ -66,9 +72,15 @@ for t: cxx{ *.test...} \
obja{*}: cxx.poptions += -DLIBBUILD2_STATIC_BUILD
objs{*}: cxx.poptions += -DLIBBUILD2_SHARED_BUILD
-# Pass our compiler target to be used as libbuild2 host.
+# Pass our compiler target to be used as build2 host and our out_root to
+# be used as the build system import path.
#
-obj{context}: cxx.poptions += -DBUILD2_HOST_TRIPLET=\"$cxx.target\"
+obj{context}:
+{
+ cxx.poptions += "-DBUILD2_HOST_TRIPLET=\"$cxx.target\""
+ cxx.poptions += "-DBUILD2_IMPORT_PATH=\"$out_root\""
+}
+
obja{context}: cxx.poptions += -DLIBBUILD2_STATIC_BUILD
objs{context}: cxx.poptions += -DLIBBUILD2_SHARED_BUILD
diff --git a/libbuild2/context.cxx b/libbuild2/context.cxx
index e35f308..a715c59 100644
--- a/libbuild2/context.cxx
+++ b/libbuild2/context.cxx
@@ -124,6 +124,16 @@ namespace build2
path (argv0.recall_string ()),
path (argv0.effect));
+ // Build system import path for modules. We only set it for the
+ // development build.
+ //
+ var_import_build2 = &vp.insert<abs_dir_path> ("import.build2");
+
+#ifndef BUILD2_BOOTSTRAP
+ if (!build_installed)
+ gs.assign (var_import_build2) = abs_dir_path (BUILD2_IMPORT_PATH);
+#endif
+
// Build system verbosity level.
//
gs.assign<uint64_t> ("build.verbosity") = verb;
diff --git a/libbuild2/context.hxx b/libbuild2/context.hxx
index 338b8a1..57ae65d 100644
--- a/libbuild2/context.hxx
+++ b/libbuild2/context.hxx
@@ -315,8 +315,9 @@ namespace build2
//
const variable* var_project_summary;
- // import.target
+ // import.*
//
+ const variable* var_import_build2;
const variable* var_import_target;
// [string] target visibility
diff --git a/libbuild2/file.cxx b/libbuild2/file.cxx
index 1c6bb1d..f0215df 100644
--- a/libbuild2/file.cxx
+++ b/libbuild2/file.cxx
@@ -1296,6 +1296,13 @@ namespace build2
{
string n ("config.import." + proj.variable ());
+ auto skip = [&target, &proj, &trace] ()
+ {
+ target.proj = move (proj);
+ l5 ([&]{trace << "skipping " << target;});
+ return make_pair (move (target), dir_path ());
+ };
+
// config.import.<proj>
//
{
@@ -1318,11 +1325,7 @@ namespace build2
// to use system-installed).
//
if (out_root.empty ())
- {
- target.proj = move (proj);
- l5 ([&]{trace << "skipping " << target;});
- return make_pair (move (target), dir_path ());
- }
+ return skip ();
break;
}
@@ -1383,6 +1386,26 @@ namespace build2
}
}
+ // import.build2
+ //
+ if (proj == "build2")
+ {
+ // Note that this variable can be set to NULL to disable relying on
+ // the built-in path. We use this in our tests to make sure we are
+ // importing and testing the build system being built and not the one
+ // doing the building.
+ //
+ if (auto l = iroot[ctx.var_import_build2])
+ {
+ out_root = cast<dir_path> (l);
+
+ if (out_root.empty ())
+ return skip ();
+
+ break;
+ }
+ }
+
// Otherwise search subprojects, starting with our root and then trying
// outer roots for as long as we are inside an amalgamation.
//
diff --git a/libbuild2/utility-installed.cxx b/libbuild2/utility-installed.cxx
new file mode 100644
index 0000000..8fcb271
--- /dev/null
+++ b/libbuild2/utility-installed.cxx
@@ -0,0 +1,24 @@
+// file : libbuild2/utility-installed.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+// Bootstrap build is never condidered installed.
+//
+#ifndef BUILD2_BOOTSTRAP
+
+#include <libbuild2/utility.hxx>
+
+namespace build2
+{
+ struct build_installed_init
+ {
+ build_installed_init ()
+ {
+ build_installed = true;
+ }
+ };
+
+ static build_installed_init init_;
+}
+
+#endif
diff --git a/libbuild2/utility.cxx b/libbuild2/utility.cxx
index ba50c5a..4f6874e 100644
--- a/libbuild2/utility.cxx
+++ b/libbuild2/utility.cxx
@@ -81,6 +81,8 @@ namespace build2
: (to_string (build_version.major ()) + '.' +
to_string (build_version.minor ())));
+ bool build_installed;
+
optional<bool> mtime_check_option;
optional<path> config_sub;
diff --git a/libbuild2/utility.hxx b/libbuild2/utility.hxx
index a6a7ac3..d9c530b 100644
--- a/libbuild2/utility.hxx
+++ b/libbuild2/utility.hxx
@@ -142,6 +142,12 @@ namespace build2
LIBBUILD2_SYMEXPORT extern const standard_version build_version;
LIBBUILD2_SYMEXPORT extern const string build_version_interface;
+ // Whether running installed build.
+ //
+ // Note: only available after static initialization.
+ //
+ LIBBUILD2_SYMEXPORT extern bool build_installed;
+
// --[no-]mtime-check
//
LIBBUILD2_SYMEXPORT extern optional<bool> mtime_check_option;
diff --git a/tests/build/root.build b/tests/build/root.build
index 5398bf8..43d3607 100644
--- a/tests/build/root.build
+++ b/tests/build/root.build
@@ -16,8 +16,11 @@ if ($cxx.class == 'msvc')
}
# Setup the build system driver that we are testing (which may not be the same
-# as our $build.path).
+# as our $build.path). We also need to disable importation using the built-in
+# path.
#
+import.build2 = [null]
+
import b = build2%exe{b}
testscript{*}: test = $b