Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64633 - trunk/tools/build/v2/tools
From: ghost_at_[hidden]
Date: 2010-08-06 06:53:36


Author: vladimir_prus
Date: 2010-08-06 06:52:45 EDT (Fri, 06 Aug 2010)
New Revision: 64633
URL: http://svn.boost.org/trac/boost/changeset/64633

Log:
Port tools/symlink.py

Added:
   trunk/tools/build/v2/tools/symlink.py (contents, props changed)
Text files modified:
   trunk/tools/build/v2/tools/builtin.py | 1 +
   1 files changed, 1 insertions(+), 0 deletions(-)

Modified: trunk/tools/build/v2/tools/builtin.py
==============================================================================
--- trunk/tools/build/v2/tools/builtin.py (original)
+++ trunk/tools/build/v2/tools/builtin.py 2010-08-06 06:52:45 EDT (Fri, 06 Aug 2010)
@@ -718,3 +718,4 @@
 get_manager().projects().add_rule("variant", variant)
 
 import stage
+import symlink

Added: trunk/tools/build/v2/tools/symlink.py
==============================================================================
--- (empty file)
+++ trunk/tools/build/v2/tools/symlink.py 2010-08-06 06:52:45 EDT (Fri, 06 Aug 2010)
@@ -0,0 +1,112 @@
+# Status: ported.
+# Base revision: 64488.
+
+# Copyright 2003 Dave Abrahams
+# Copyright 2002, 2003 Rene Rivera
+# Copyright 2002, 2003, 2004, 2005 Vladimir Prus
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+
+# Defines the "symlink" special target. 'symlink' targets make symbolic links
+# to the sources.
+
+import b2.build.feature as feature
+import b2.build.targets as targets
+import b2.build.property_set as property_set
+import b2.build.virtual_target as virtual_target
+import b2.build.targets
+
+from b2.manager import get_manager
+
+import bjam
+
+import os
+
+
+feature.feature("symlink-location", ["project-relative", "build-relative"], ["incidental"])
+
+class SymlinkTarget(targets.BasicTarget):
+
+ _count = 0
+
+ def __init__(self, project, targets, sources):
+
+ # Generate a fake name for now. Need unnamed targets eventually.
+ fake_name = "symlink#%s" % SymlinkTarget._count
+ SymlinkTarget._count = SymlinkTarget._count + 1
+
+ b2.build.targets.BasicTarget.__init__(self, fake_name, project, sources)
+
+ # Remember the targets to map the sources onto. Pad or truncate
+ # to fit the sources given.
+ assert len(targets) <= len(sources)
+ self.targets = targets[:] + sources[len(targets):]
+
+ # The virtual targets corresponding to the given targets.
+ self.virtual_targets = []
+
+ def construct(self, name, source_targets, ps):
+ i = 0
+ for t in source_targets:
+ s = self.targets[i]
+ a = virtual_target.Action(self.manager(), [t], "symlink.ln", ps)
+ vt = virtual_target.FileTarget(os.path.basename(s), t.type(), self.project(), a)
+
+ # Place the symlink in the directory relative to the project
+ # location, instead of placing it in the build directory.
+ if not ps.get('symlink-location') == "project-relative":
+ vt.set_path(os.path.join(self.project().get('location'), os.path.dirname(s)))
+
+ vt = get_manager().virtual_targets().register(vt)
+ self.virtual_targets.append(vt)
+ i = i + 1
+
+ return (property_set.empty(), self.virtual_targets)
+
+# Creates a symbolic link from a set of targets to a set of sources.
+# The targets and sources map one to one. The symlinks generated are
+# limited to be the ones given as the sources. That is, the targets
+# are either padded or trimmed to equate to the sources. The padding
+# is done with the name of the corresponding source. For example::
+#
+# symlink : one two ;
+#
+# Is equal to::
+#
+# symlink one two : one two ;
+#
+# Names for symlink are relative to the project location. They cannot
+# include ".." path components.
+def symlink(targets, sources):
+
+ from b2.manager import get_manager
+ t = get_manager().targets()
+ p = get_manager().projects().current()
+
+ return t.main_target_alternative(
+ SymlinkTarget(p, targets,
+ # Note: inline targets are not supported for symlink, intentionally,
+ # since it's used to linking existing non-local targets.
+ sources))
+
+
+def setup_ln(targets, sources, ps):
+
+ source_path = bjam.call("get-target-variable", sources[0], "LOCATE")[0]
+ target_path = bjam.call("get-target-variable", targets[0], "LOCATE")[0]
+ rel = os.path.relpath(source_path, target_path)
+ if rel == ".":
+ bjam.call("set-target-variable", targets, "PATH_TO_SOURCE", "")
+ else:
+ bjam.call("set-target-variable", targets, "PATH_TO_SOURCE", rel)
+
+if os.name == 'nt':
+ ln_action = """echo "NT symlinks not supported yet, making copy"
+del /f /q "$(<)" 2>nul >nul
+copy "$(>)" "$(<)" $(NULL_OUT)"""
+else:
+ ln_action = "ln -f -s '$(>:D=:R=$(PATH_TO_SOURCE))' '$(<)'"
+
+get_manager().engine().register_action("symlink.ln", ln_action, function=setup_ln)
+
+get_manager().projects().add_rule("symlink", symlink)


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk