7 from __future__
import absolute_import, division, print_function
15 from SCons.Script.SConscript
import SConsEnvironment
22 from .utils
import memberOf
32 pathFormat = re.sub(
r"%(\w)",
r"%(\1)s", pathFormat)
34 eupsPath = os.environ[
'PWD']
35 if 'eupsPath' in env
and env[
'eupsPath']:
36 eupsPath = env[
'eupsPath']
38 return pathFormat % {
"P": eupsPath,
39 "f": env[
'eupsFlavor'],
40 "p": env[
'eupsProduct'],
42 "c": os.environ[
'PWD'] }
50 version = env[
'version']
51 elif not versionString:
53 elif re.search(
r"^[$]Name:\s+", versionString):
55 version = re.search(
r"^[$]Name:\s+([^ $]*)", versionString).group(1)
58 elif re.search(
r"^[$]HeadURL:\s+", versionString):
60 HeadURL = re.search(
r"^[$]HeadURL:\s+(.*)", versionString).group(1)
61 HeadURL = os.path.split(HeadURL)[0]
62 version = svn.guessVersionName(HeadURL)
63 elif versionString.lower()
in (
"hg",
"mercurial"):
65 version = hg.guessVersionName()
66 elif versionString.lower()
in (
"git",):
68 version = git.guessVersionName()
69 return version.replace(
"/",
"_")
75 if versionString.lower()
in (
"hg",
"mercurial"):
76 fingerprint, modified = hg.guessFingerprint()
77 elif versionString.lower()
in (
"git",):
78 fingerprint, modified = git.guessFingerprint()
80 fingerprint, modified =
None,
False
82 if fingerprint
and modified:
88 def setPrefix(env, versionString, eupsProductPath=None):
91 except RuntimeError
as err:
92 env[
'version'] =
"unknown"
93 if (env.installing
or env.declaring)
and not env[
'force']:
95 "%s\nFound problem with version number; update or specify force=True to proceed"
99 if state.env[
'no_eups']:
100 if 'prefix' in env
and env[
'prefix']:
107 elif 'eupsPath' in env
and env[
'eupsPath']:
108 eupsPrefix = env[
'eupsPath']
110 state.log.fail(
"Unable to determine eupsPrefix from eupsProductPath or eupsPath")
111 flavor = env[
'eupsFlavor']
112 if not re.search(
"/" + flavor +
"$", eupsPrefix):
113 eupsPrefix = os.path.join(eupsPrefix, flavor)
114 prodPath = env[
'eupsProduct']
115 if 'eupsProductPath' in env
and env[
'eupsProductPath']:
116 prodPath = env[
'eupsProductPath']
117 eupsPrefix = os.path.join(eupsPrefix, prodPath, env[
"version"])
121 if env[
'version'] !=
"unknown" and eupsPrefix
and eupsPrefix != env[
'prefix']:
122 state.log.warn(
"Ignoring prefix %s from EUPS_PATH" % eupsPrefix)
124 elif 'eupsPath' in env
and env[
'eupsPath']:
127 prefix =
"/usr/local"
141 if "undeclare" in SCons.Script.COMMAND_LINE_TARGETS
and not self.GetOption(
"silent"):
142 state.log.warn(
"'scons undeclare' is deprecated; please use 'scons declare -c' instead")
146 "declare" in SCons.Script.COMMAND_LINE_TARGETS
or \
147 "undeclare" in SCons.Script.COMMAND_LINE_TARGETS
or \
148 (
"install" in SCons.Script.COMMAND_LINE_TARGETS
and self.GetOption(
"clean"))
or \
149 "current" in SCons.Script.COMMAND_LINE_TARGETS:
150 current = []; declare = []; undeclare = []
155 for prod
in products:
156 if not prod
or isinstance(prod, str):
159 if 'version' in self:
160 version = self[
'version']
164 product, version = prod
167 product = self[
'eupsProduct']
169 if "EUPS_DIR" in os.environ:
170 self[
'ENV'][
'PATH'] += os.pathsep +
"%s/bin" % (os.environ[
"EUPS_DIR"])
171 self[
"ENV"][
"EUPS_LOCK_PID"] = os.environ.get(
"EUPS_LOCK_PID",
"-1")
172 if "undeclare" in SCons.Script.COMMAND_LINE_TARGETS
or self.GetOption(
"clean"):
174 command =
"eups undeclare --flavor %s %s %s" % \
175 (self[
'eupsFlavor'], product, version)
176 if (
"current" in SCons.Script.COMMAND_LINE_TARGETS
177 and not "declare" in SCons.Script.COMMAND_LINE_TARGETS):
178 command +=
" --current"
180 if self.GetOption(
"clean"):
181 self.Execute(command)
183 undeclare += [command]
185 state.log.warn(
"I don't know your version; not undeclaring to eups")
187 command =
"eups declare --force --flavor %s --root %s" % \
188 (self[
'eupsFlavor'], self[
'prefix'])
190 if 'eupsPath' in self:
191 command +=
" -Z %s" % self[
'eupsPath']
194 command +=
" %s %s" % (product, version)
196 current += [command +
" --current"]
198 if self.GetOption(
"tag"):
199 command +=
" --tag=%s" % self.GetOption(
"tag")
204 acts += self.Command(
"current",
"", action=current)
206 if "current" in SCons.Script.COMMAND_LINE_TARGETS:
207 acts += self.Command(
"declare",
"", action=
"")
209 acts += self.Command(
"declare",
"", action=declare)
211 acts += self.Command(
"undeclare",
"", action=undeclare)
233 prefix = os.path.abspath(os.path.join(target[0].abspath,
".."))
234 destpath = os.path.join(target[0].abspath)
235 if not os.path.isdir(destpath):
236 state.log.info(
"Creating directory %s" % destpath)
237 os.makedirs(destpath)
238 for root, dirnames, filenames
in os.walk(source[0].path):
242 dirnames[:] = [d
for d
in dirnames
if d !=
".svn"]
243 for dirname
in dirnames:
244 destpath = os.path.join(prefix, root, dirname)
245 if not os.path.isdir(destpath):
246 state.log.info(
"Creating directory %s" % destpath)
247 os.makedirs(destpath)
248 for filename
in filenames:
249 if self.ignoreRegex.search(filename):
251 destpath = os.path.join(prefix, root)
252 srcpath = os.path.join(root, filename)
253 state.log.info(
"Copying %s to %s" % (srcpath, destpath))
254 shutil.copy(srcpath, destpath)
263 def InstallDir(self, prefix, dir, ignoreRegex=r"(~$|\.pyc$|\.os?$)
", recursive=True):
264 if not self.installing:
266 result = self.Command(target=os.path.join(self.Dir(prefix).abspath, dir), source=dir,
268 self.AlwaysBuild(result)
288 if not env.installing:
291 if env.GetOption(
"clean"):
292 state.log.warn(
"Removing" + dest)
293 shutil.rmtree(dest, ignore_errors=
True)
297 presetupStr += [
"--product %s=%s" % (p, presetup[p])]
298 presetup =
" ".join(presetupStr)
300 env = env.Clone(ENV = os.environ)
304 files = [str(f)
for f
in files]
305 files += glob.glob(os.path.join(
"ups",
"*.build")) + glob.glob(os.path.join(
"ups",
"*.table")) \
306 + glob.glob(os.path.join(
"ups",
"*.cfg")) \
307 + glob.glob(os.path.join(
"ups",
"eupspkg*"))
308 files = list(set(files))
310 buildFiles = [f
for f
in files
if re.search(
r"\.build$", f)]
311 build_obj = env.Install(dest, buildFiles)
314 tableFiles = [f
for f
in files
if re.search(
r"\.table$", f)]
315 table_obj = env.Install(dest, tableFiles)
318 eupspkgFiles = [f
for f
in files
if re.search(
r"^eupspkg", f)]
319 eupspkg_obj = env.Install(dest, eupspkgFiles)
322 miscFiles = [f
for f
in files
if not re.search(
r"\.(build|table)$", f)]
323 misc_obj = env.Install(dest, miscFiles)
329 path = eups.Eups.setEupsPath()
331 locks = eups.lock.takeLocks(
"setup", path, eups.lock.LOCK_SH)
332 env[
"ENV"][
"EUPS_LOCK_PID"] = os.environ.get(
"EUPS_LOCK_PID",
"-1")
334 state.log.warn(
"Unable to import eups; not locking")
341 cmd =
"eups expandbuild -i --version %s " % env[
'version']
342 if 'baseversion' in env:
343 cmd +=
" --repoversion %s " % env[
'baseversion']
345 eupsTargets.extend(env.AddPostAction(build_obj, env.Action(
"%s" %(cmd), cmd)))
350 cmd =
"eups expandtable -i -W '^(?!LOCAL:)' "
352 cmd += presetup +
" "
355 act = env.Command(
"table",
"", env.Action(
"%s" %(cmd), cmd))
356 eupsTargets.extend(act)
364 env.SideEffect(
"eups", eupsTargets)
376 if d ==
"ups" and not state.env[
'no_eups']:
377 t = self.InstallEups(os.path.join(prefix,
"ups"))
379 t = self.InstallDir(prefix, d, ignoreRegex=ignoreRegex)
382 self.Alias(
"install", t)
383 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)...