summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/Node
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2002-07-29 23:22:50 (GMT)
committerSteven Knight <knight@baldmt.com>2002-07-29 23:22:50 (GMT)
commit7b142dbd32c3673ae57bda1fea98a8d8e3f7d0e5 (patch)
tree852f6c632d1f018e22d22aa459f2c9753c66ba59 /src/engine/SCons/Node
parentcd6d3c9e4f76592845cf32e11cee9a04c1b2f0f6 (diff)
downloadSCons-7b142dbd32c3673ae57bda1fea98a8d8e3f7d0e5.zip
SCons-7b142dbd32c3673ae57bda1fea98a8d8e3f7d0e5.tar.gz
SCons-7b142dbd32c3673ae57bda1fea98a8d8e3f7d0e5.tar.bz2
Multiple directory .h includes in Repositories.
Diffstat (limited to 'src/engine/SCons/Node')
-rw-r--r--src/engine/SCons/Node/FS.py85
-rw-r--r--src/engine/SCons/Node/FSTests.py59
-rw-r--r--src/engine/SCons/Node/__init__.py3
3 files changed, 134 insertions, 13 deletions
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py
index 0837ed3..dfea21b 100644
--- a/src/engine/SCons/Node/FS.py
+++ b/src/engine/SCons/Node/FS.py
@@ -307,12 +307,12 @@ class FS:
build_dir.link(src_dir, duplicate)
def Repository(self, *dirs):
- """Specify repository directories to search."""
+ """Specify Repository directories to search."""
for d in dirs:
self.Repositories.append(self.Dir(d))
def Rsearch(self, path, func = exists_path):
- """Search for something in a repository. Returns the first
+ """Search for something in a Repository. Returns the first
one found in the list, or None if there isn't one."""
if isinstance(path, SCons.Node.Node):
return path
@@ -327,10 +327,12 @@ class FS:
return None
def Rsearchall(self, pathlist, func = exists_path):
- """Search for a list of somethings in the repository list."""
+ """Search for a list of somethings in the Repository list."""
ret = []
if SCons.Util.is_String(pathlist):
pathlist = string.split(pathlist, os.pathsep)
+ if not SCons.Util.is_List(pathlist):
+ pathlist = [pathlist]
for path in pathlist:
if isinstance(path, SCons.Node.Node):
ret.append(path)
@@ -339,6 +341,8 @@ class FS:
if n:
ret.append(n)
if not os.path.isabs(path):
+ if path[0] == '#':
+ path = path[1:]
for dir in self.Repositories:
n = func(os.path.join(dir.path, path))
if n:
@@ -422,7 +426,7 @@ class Entry(SCons.Node.Node):
raise AttributeError
def exists(self):
- return os.path.exists(self.rstr())
+ return os.path.exists(self.path)
def cached_exists(self):
try:
@@ -431,6 +435,9 @@ class Entry(SCons.Node.Node):
self.exists_flag = self.exists()
return self.exists_flag
+ def rexists(self):
+ return os.path.exists(self.rstr())
+
def get_parents(self):
parents = SCons.Node.Node.get_parents(self)
if self.dir and not isinstance(self.dir, ParentOfRoot):
@@ -457,7 +464,6 @@ class Entry(SCons.Node.Node):
# XXX TODO?
# Annotate with the creator
-# is_under
# rel_path
# srcpath / srcdir
# link / is_linked
@@ -588,12 +594,14 @@ class Dir(Entry):
# source path exists, we only care about the path.
return os.path.exists(self.path)
+ def rexists(self):
+ # Again, directories are special...we don't care if their
+ # source path exists, we only care about the path.
+ return os.path.exists(self.rstr())
+
# XXX TODO?
-# rfile
-# precious
-# rpath
# rsrcpath
# source_exists
# derived_exists
@@ -604,9 +612,7 @@ class Dir(Entry):
# addsuffix
# accessible
# ignore
-# build
# bind
-# is_under
# relpath
class File(Entry):
@@ -624,16 +630,44 @@ class File(Entry):
return self.dir.root()
def get_contents(self):
- if not self.exists():
+ if not self.rexists():
return ''
return open(self.rstr(), "rb").read()
def get_timestamp(self):
- if self.exists():
+ if self.rexists():
return os.path.getmtime(self.rstr())
else:
return 0
+ def calc_signature(self, calc):
+ """
+ Select and calculate the appropriate build signature for a File.
+
+ self - the File node
+ calc - the signature calculation module
+ returns - the signature
+
+ This method does not store the signature in the node or
+ in the .sconsign file.
+ """
+
+ if self.builder:
+ if SCons.Sig.build_signature:
+ if not hasattr(self, 'bsig'):
+ self.set_bsig(calc.bsig(self.rfile()))
+ return self.get_bsig()
+ else:
+ if not hasattr(self, 'csig'):
+ self.set_csig(calc.csig(self.rfile()))
+ return self.get_csig()
+ elif not self.rexists():
+ return None
+ else:
+ if not hasattr(self, 'csig'):
+ self.set_csig(calc.csig(self.rfile()))
+ return self.get_csig()
+
def store_csig(self):
self.dir.sconsign().set_csig(self.name, self.get_csig())
@@ -671,6 +705,17 @@ class File(Entry):
file_link(self.srcpath, self.path)
return Entry.exists(self)
+ def rexists(self):
+ if self.duplicate and not self.created:
+ self.created = 1
+ if self.srcpath != self.path and \
+ os.path.exists(self.srcpath):
+ if os.path.exists(self.path):
+ os.unlink(self.path)
+ self.__createDir()
+ file_link(self.srcpath, self.path)
+ return Entry.rexists(self)
+
def scanner_key(self):
return os.path.splitext(self.name)[1]
@@ -705,6 +750,22 @@ class File(Entry):
else:
self.__createDir()
+ def current(self, calc):
+ bsig = calc.bsig(self)
+ if not self.exists():
+ # The file doesn't exist locally...
+ r = self.rfile()
+ if r != self:
+ # ...but there is one in a Repository...
+ if calc.current(r, bsig):
+ # ...and it's even up-to-date.
+ # XXX Future: copy locally if requested
+ return 1
+ self._rfile = self
+ return None
+ else:
+ return calc.current(self, bsig)
+
def rfile(self):
if not hasattr(self, '_rfile'):
self._rfile = self
diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py
index 42a6542..b45cc4b 100644
--- a/src/engine/SCons/Node/FSTests.py
+++ b/src/engine/SCons/Node/FSTests.py
@@ -27,6 +27,7 @@ import os
import os.path
import string
import sys
+import time
import unittest
import SCons.Node.FS
from TestCmd import TestCmd
@@ -501,7 +502,18 @@ class FSTestCase(unittest.TestCase):
assert c == "", c
assert e.__class__ == SCons.Node.FS.Dir
- #XXX test get_timestamp()
+ test.write("tstamp", "tstamp\n")
+ # Okay, *this* manipulation accomodates Windows FAT file systems
+ # that only have two-second granularity on their timestamps.
+ # We round down the current time to the nearest even integer
+ # value, subtract two to make sure the timestamp is not "now,"
+ # and then convert it back to a float.
+ tstamp = float(int(time.time() / 2) * 2) - 2
+ os.utime(test.workpath("tstamp"), (tstamp - 2.0, tstamp))
+ f = fs.File("tstamp")
+ t = f.get_timestamp()
+ assert t == tstamp, "expected %f, got %f" % (tstamp, t)
+ test.unlink("tstamp")
#XXX test get_prevsiginfo()
@@ -530,6 +542,10 @@ class FSTestCase(unittest.TestCase):
exc_caught = 1
assert exc_caught, "Should have caught a TypeError"
+ # XXX test calc_signature()
+
+ # XXX test current()
+
class RepositoryTestCase(unittest.TestCase):
def runTest(self):
"""Test FS (file system) Repository operations
@@ -585,6 +601,10 @@ class RepositoryTestCase(unittest.TestCase):
assert fs.Rsearch('f2', os.path.exists)
assert fs.Rsearch('f3', os.path.exists)
+ list = fs.Rsearchall(fs.Dir('d1'))
+ assert len(list) == 1, list
+ assert list[0].path == 'd1', list[0].path
+
list = fs.Rsearchall([fs.Dir('d1')])
assert len(list) == 1, list
assert list[0].path == 'd1', list[0].path
@@ -592,6 +612,9 @@ class RepositoryTestCase(unittest.TestCase):
list = fs.Rsearchall('d2')
assert list == [], list
+ list = fs.Rsearchall('#d2')
+ assert list == [], list
+
test.subdir(['work', 'd2'])
list = fs.Rsearchall('d2')
assert list == ['d2'], list
@@ -623,6 +646,40 @@ class RepositoryTestCase(unittest.TestCase):
work_d4 = fs.File(os.path.join('work', 'd4'))
list = fs.Rsearchall(['d3', work_d4])
assert list == ['d3', work_d4], list
+
+ f1 = fs.File(test.workpath("work", "i_do_not_exist"))
+ assert not f1.rexists()
+
+ test.write(["rep2", "i_exist"], "\n")
+ f1 = fs.File(test.workpath("work", "i_exist"))
+ assert f1.rexists()
+
+ test.write(["work", "i_exist_too"], "\n")
+ f1 = fs.File(test.workpath("work", "i_exist_too"))
+ assert f1.rexists()
+
+ test.write(["rep2", "tstamp"], "tstamp\n")
+ # Okay, *this* manipulation accomodates Windows FAT file systems
+ # that only have two-second granularity on their timestamps.
+ # We round down the current time to the nearest even integer
+ # value, subtract two to make sure the timestamp is not "now,"
+ # and then convert it back to a float.
+ tstamp = float(int(time.time() / 2) * 2) - 2
+ os.utime(test.workpath("rep2", "tstamp"), (tstamp - 2.0, tstamp))
+ f = fs.File("tstamp")
+ t = f.get_timestamp()
+ assert t == tstamp, "expected %f, got %f" % (tstamp, t)
+ test.unlink(["rep2", "tstamp"])
+
+ # Make sure get_contents() returns the binary contents.
+ test.write(["rep3", "contents"], "Con\x1aTents\n")
+ c = fs.File("contents").get_contents()
+ assert c == "Con\x1aTents\n", "got '%s'" % c
+ test.unlink(["rep3", "contents"])
+
+ # XXX test calc_signature()
+
+ # XXX test current()
class find_fileTestCase(unittest.TestCase):
def runTest(self):
diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py
index 45f5bc7..a65310d 100644
--- a/src/engine/SCons/Node/__init__.py
+++ b/src/engine/SCons/Node/__init__.py
@@ -395,6 +395,9 @@ class Node:
def current(self):
return None
+ def rfile(self):
+ return self
+
def rstr(self):
return str(self)