13 from SCons.Script.SConscript
import SConsEnvironment
20 from .utils
import memberOf
31 pathFormat = re.sub(
r"%(\w)",
r"%(\1)s", pathFormat)
33 eupsPath = os.environ[
'PWD']
34 if env.has_key(
'eupsProduct')
and env[
'eupsPath']:
35 eupsPath = env[
'eupsPath']
37 return pathFormat % {
"P": eupsPath,
38 "f": env[
'eupsFlavor'],
39 "p": env[
'eupsProduct'],
41 "c": os.environ[
'PWD'] }
48 if env.has_key(
'version'):
49 version = env[
'version']
50 elif not versionString:
52 elif re.search(
r"^[$]Name:\s+", versionString):
54 version = re.search(
r"^[$]Name:\s+([^ $]*)", versionString).group(1)
57 elif re.search(
r"^[$]HeadURL:\s+", versionString):
59 HeadURL = re.search(
r"^[$]HeadURL:\s+(.*)", versionString).group(1)
60 HeadURL = os.path.split(HeadURL)[0]
61 version = svn.guessVersionName(HeadURL)
62 elif versionString.lower()
in (
"hg",
"mercurial"):
64 version = hg.guessVersionName()
65 elif versionString.lower()
in (
"git",):
67 version = git.guessVersionName()
68 return version.replace(
"/",
"_")
74 if versionString.lower()
in (
"hg",
"mercurial"):
75 fingerprint, modified = hg.guessFingerprint()
76 elif versionString.lower()
in (
"git",):
77 fingerprint, modified = git.guessFingerprint()
79 fingerprint, modified =
None,
False
81 if fingerprint
and modified:
87 def setPrefix(env, versionString, eupsProductPath=None):
90 except RuntimeError
as err:
91 env[
'version'] =
"unknown"
92 if env.installing
or env.declaring
and not env[
'force']:
94 "%s\nFound problem with version number; update or specify force=True to proceed"
99 elif env.has_key(
'eupsPath')
and env[
'eupsPath']:
100 eupsPrefix = env[
'eupsPath']
101 flavor = env[
'eupsFlavor']
102 if not re.search(
"/" + flavor +
"$", eupsPrefix):
103 eupsPrefix = os.path.join(eupsPrefix, flavor)
104 prodPath = env[
'eupsProduct']
105 if env.has_key(
'eupsProductPath')
and env[
'eupsProductPath']:
106 prodPath = env[
'eupsProductPath']
107 eupsPrefix = os.path.join(eupsPrefix, prodPath, env[
"version"])
110 if env.has_key(
'prefix'):
111 if env[
'version'] !=
"unknown" and eupsPrefix
and eupsPrefix != env[
'prefix']:
112 print >> sys.stderr,
"Ignoring prefix %s from EUPS_PATH" % eupsPrefix
114 elif env.has_key(
'eupsPath')
and env[
'eupsPath']:
117 prefix =
"/usr/local"
131 if "undeclare" in SCons.Script.COMMAND_LINE_TARGETS
and not self.GetOption(
"silent"):
132 state.log.warn(
"'scons undeclare' is deprecated; please use 'scons declare -c' instead")
136 "declare" in SCons.Script.COMMAND_LINE_TARGETS
or \
137 "undeclare" in SCons.Script.COMMAND_LINE_TARGETS
or \
138 (
"install" in SCons.Script.COMMAND_LINE_TARGETS
and self.GetOption(
"clean"))
or \
139 "current" in SCons.Script.COMMAND_LINE_TARGETS:
140 current = []; declare = []; undeclare = []
145 for prod
in products:
146 if not prod
or isinstance(prod, str):
149 if self.has_key(
'version'):
150 version = self[
'version']
154 product, version = prod
157 product = self[
'eupsProduct']
159 if "EUPS_DIR" in os.environ.keys():
160 self[
'ENV'][
'PATH'] += os.pathsep +
"%s/bin" % (os.environ[
"EUPS_DIR"])
161 self[
"ENV"][
"EUPS_LOCK_PID"] = os.environ.get(
"EUPS_LOCK_PID",
"-1")
162 if "undeclare" in SCons.Script.COMMAND_LINE_TARGETS
or self.GetOption(
"clean"):
164 command =
"eups undeclare --flavor %s %s %s" % \
165 (self[
'eupsFlavor'], product, version)
166 if (
"current" in SCons.Script.COMMAND_LINE_TARGETS
167 and not "declare" in SCons.Script.COMMAND_LINE_TARGETS):
168 command +=
" --current"
170 if self.GetOption(
"clean"):
171 self.Execute(command)
173 undeclare += [command]
175 state.log.warn(
"I don't know your version; not undeclaring to eups")
177 command =
"eups declare --force --flavor %s --root %s" % \
178 (self[
'eupsFlavor'], self[
'prefix'])
180 if self.has_key(
'eupsPath'):
181 command +=
" -Z %s" % self[
'eupsPath']
184 command +=
" %s %s" % (product, version)
186 current += [command +
" --current"]
188 if self.GetOption(
"tag"):
189 command +=
" --tag=%s" % self.GetOption(
"tag")
194 acts += self.Command(
"current",
"", action=current)
196 if "current" in SCons.Script.COMMAND_LINE_TARGETS:
197 acts += self.Command(
"declare",
"", action=
"")
199 acts += self.Command(
"declare",
"", action=declare)
201 acts += self.Command(
"undeclare",
"", action=undeclare)
223 prefix = os.path.abspath(os.path.join(target[0].abspath,
".."))
224 destpath = os.path.join(target[0].abspath)
225 if not os.path.isdir(destpath):
226 state.log.info(
"Creating directory %s" % destpath)
227 os.makedirs(destpath)
228 for root, dirnames, filenames
in os.walk(source[0].path):
232 dirnames[:] = [d
for d
in dirnames
if d !=
".svn"]
233 for dirname
in dirnames:
234 destpath = os.path.join(prefix, root, dirname)
235 if not os.path.isdir(destpath):
236 state.log.info(
"Creating directory %s" % destpath)
237 os.makedirs(destpath)
238 for filename
in filenames:
239 if self.ignoreRegex.search(filename):
241 destpath = os.path.join(prefix, root)
242 srcpath = os.path.join(root, filename)
243 state.log.info(
"Copying %s to %s" % (srcpath, destpath))
244 shutil.copy(srcpath, destpath)
253 def InstallDir(self, prefix, dir, ignoreRegex=r"(~$|\.pyc$|\.os?$)
", recursive=True):
254 if not self.installing:
256 result = self.Command(target=os.path.join(self.Dir(prefix).abspath, dir), source=dir,
258 self.AlwaysBuild(result)
278 if not env.installing:
281 if env.GetOption(
"clean"):
282 print >> sys.stderr,
"Removing", dest
283 shutil.rmtree(dest, ignore_errors=
True)
287 presetupStr += [
"--product %s=%s" % (p, presetup[p])]
288 presetup =
" ".join(presetupStr)
290 env = env.Clone(ENV = os.environ)
294 files = [str(f)
for f
in files]
295 files += glob.glob(os.path.join(
"ups",
"*.build")) + glob.glob(os.path.join(
"ups",
"*.table")) \
296 + glob.glob(os.path.join(
"ups",
"*.cfg")) \
297 + glob.glob(os.path.join(
"ups",
"eupspkg*"))
298 files = list(set(files))
300 buildFiles = filter(
lambda f: re.search(
r"\.build$", f), files)
301 build_obj = env.Install(dest, buildFiles)
304 tableFiles = filter(
lambda f: re.search(
r"\.table$", f), files)
305 table_obj = env.Install(dest, tableFiles)
308 eupspkgFiles = filter(
lambda f: re.search(
r"^eupspkg", f), files)
309 eupspkg_obj = env.Install(dest, eupspkgFiles)
312 miscFiles = filter(
lambda f:
not re.search(
r"\.(build|table)$", f), files)
313 misc_obj = env.Install(dest, miscFiles)
319 path = eups.Eups.setEupsPath()
321 locks = eups.lock.takeLocks(
"setup", path, eups.lock.LOCK_SH)
322 env[
"ENV"][
"EUPS_LOCK_PID"] = os.environ.get(
"EUPS_LOCK_PID",
"-1")
324 state.log.warn(
"Unable to import eups; not locking")
331 cmd =
"eups expandbuild -i --version %s " % env[
'version']
332 if env.has_key(
'baseversion'):
333 cmd +=
" --repoversion %s " % env[
'baseversion']
335 eupsTargets.extend(env.AddPostAction(build_obj, env.Action(
"%s" %(cmd), cmd)))
340 cmd =
"eups expandtable -i -W '^(?!LOCAL:)' "
342 cmd += presetup +
" "
345 act = env.Command(
"table",
"", env.Action(
"%s" %(cmd), cmd))
346 eupsTargets.extend(act)
354 env.SideEffect(
"eups", eupsTargets)
366 t = self.InstallEups(os.path.join(prefix,
"ups"))
368 t = self.InstallDir(prefix, d, ignoreRegex=ignoreRegex)
371 self.Alias(
"install", t)
372 self.Clean(
"install", prefix)
def Declare
Create current and declare targets for products.
def getFingerprint
Return a unique fingerprint for a version (e.g.
def memberOf
A Python decorator that injects functions into a class.
def makeProductPath
return a path to use as the installation directory for a product
def InstallLSST
Install directories in the usual LSST way, handling "ups" specially.
def determineVersion
Set a version ID from env, or a version control ID string ($name$ or $HeadURL$)
def InstallEups
Install a ups directory, setting absolute versions as appropriate (unless you're installing from the ...
SCons Action callable to recursively install a directory.
def setPrefix
Set a prefix based on the EUPS_PATH, the product name, and a versionString from cvs or svn...
def InstallDir
Install the directory dir into prefix, (along with all its descendents if recursive is True)...