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 'eupsPath' in env
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']}
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(
"/",
"_")
76 if versionString.lower()
in (
"hg",
"mercurial"):
77 fingerprint, modified = hg.guessFingerprint()
78 elif versionString.lower()
in (
"git",):
79 fingerprint, modified = git.guessFingerprint()
81 fingerprint, modified =
None,
False 83 if fingerprint
and modified:
90 def setPrefix(env, versionString, eupsProductPath=None):
93 except RuntimeError
as err:
94 env[
'version'] =
"unknown" 95 if (env.installing
or env.declaring)
and not env[
'force']:
97 "%s\nFound problem with version number; update or specify force=True to proceed" 101 if state.env[
'no_eups']:
102 if 'prefix' in env
and env[
'prefix']:
109 elif 'eupsPath' in env
and env[
'eupsPath']:
110 eupsPrefix = env[
'eupsPath']
112 state.log.fail(
"Unable to determine eupsPrefix from eupsProductPath or eupsPath")
113 flavor = env[
'eupsFlavor']
114 if not re.search(
"/" + flavor +
"$", eupsPrefix):
115 eupsPrefix = os.path.join(eupsPrefix, flavor)
116 prodPath = env[
'eupsProduct']
117 if 'eupsProductPath' in env
and env[
'eupsProductPath']:
118 prodPath = env[
'eupsProductPath']
119 eupsPrefix = os.path.join(eupsPrefix, prodPath, env[
"version"])
123 if env[
'version'] !=
"unknown" and eupsPrefix
and eupsPrefix != env[
'prefix']:
124 state.log.warn(
"Ignoring prefix %s from EUPS_PATH" % eupsPrefix)
126 elif 'eupsPath' in env
and env[
'eupsPath']:
129 prefix =
"/usr/local" 144 if "undeclare" in SCons.Script.COMMAND_LINE_TARGETS
and not self.GetOption(
"silent"):
145 state.log.warn(
"'scons undeclare' is deprecated; please use 'scons declare -c' instead")
148 if (
"declare" in SCons.Script.COMMAND_LINE_TARGETS
or 149 "undeclare" in SCons.Script.COMMAND_LINE_TARGETS
or 150 (
"install" in SCons.Script.COMMAND_LINE_TARGETS
and self.GetOption(
"clean"))
or 151 "current" in SCons.Script.COMMAND_LINE_TARGETS):
159 for prod
in products:
160 if not prod
or isinstance(prod, str):
163 if 'version' in self:
164 version = self[
'version']
168 product, version = prod
171 product = self[
'eupsProduct']
173 if "EUPS_DIR" in os.environ:
174 self[
'ENV'][
'PATH'] += os.pathsep +
"%s/bin" % (os.environ[
"EUPS_DIR"])
175 self[
"ENV"][
"EUPS_LOCK_PID"] = os.environ.get(
"EUPS_LOCK_PID",
"-1")
176 if "undeclare" in SCons.Script.COMMAND_LINE_TARGETS
or self.GetOption(
"clean"):
178 command =
"eups undeclare --flavor %s %s %s" % \
179 (self[
'eupsFlavor'], product, version)
180 if (
"current" in SCons.Script.COMMAND_LINE_TARGETS
and 181 "declare" not in SCons.Script.COMMAND_LINE_TARGETS):
182 command +=
" --current" 184 if self.GetOption(
"clean"):
185 self.Execute(command)
187 undeclare += [command]
189 state.log.warn(
"I don't know your version; not undeclaring to eups")
191 command =
"eups declare --force --flavor %s --root %s" % \
192 (self[
'eupsFlavor'], self[
'prefix'])
194 if 'eupsPath' in self:
195 command +=
" -Z %s" % self[
'eupsPath']
198 command +=
" %s %s" % (product, version)
200 current += [command +
" --current"]
202 if self.GetOption(
"tag"):
203 command +=
" --tag=%s" % self.GetOption(
"tag")
208 acts += self.Command(
"current",
"", action=current)
210 if "current" in SCons.Script.COMMAND_LINE_TARGETS:
211 acts += self.Command(
"declare",
"", action=
"")
213 acts += self.Command(
"declare",
"", action=declare)
215 acts += self.Command(
"undeclare",
"", action=undeclare)
238 prefix = os.path.abspath(os.path.join(target[0].abspath,
".."))
239 destpath = os.path.join(target[0].abspath)
240 if not os.path.isdir(destpath):
241 state.log.info(
"Creating directory %s" % destpath)
242 os.makedirs(destpath)
243 for root, dirnames, filenames
in os.walk(source[0].path):
247 dirnames[:] = [d
for d
in dirnames
if d !=
".svn"]
248 for dirname
in dirnames:
249 destpath = os.path.join(prefix, root, dirname)
250 if not os.path.isdir(destpath):
251 state.log.info(
"Creating directory %s" % destpath)
252 os.makedirs(destpath)
253 for filename
in filenames:
256 destpath = os.path.join(prefix, root)
257 srcpath = os.path.join(root, filename)
258 state.log.info(
"Copying %s to %s" % (srcpath, destpath))
259 shutil.copy(srcpath, destpath)
268 def InstallDir(self, prefix, dir, ignoreRegex=r"(~$|\.pyc$|\.os?$)
", recursive=True): 269 if not self.installing:
271 result = self.Command(target=os.path.join(self.Dir(prefix).abspath, dir), source=dir,
273 self.AlwaysBuild(result)
294 if not env.installing:
297 if env.GetOption(
"clean"):
298 state.log.warn(
"Removing" + dest)
299 shutil.rmtree(dest, ignore_errors=
True)
303 presetupStr += [
"--product %s=%s" % (p, presetup[p])]
304 presetup =
" ".join(presetupStr)
306 env = env.Clone(ENV=os.environ)
310 files = [
str(f)
for f
in files]
311 files += glob.glob(os.path.join(
"ups",
"*.build")) + glob.glob(os.path.join(
"ups",
"*.table")) \
312 + glob.glob(os.path.join(
"ups",
"*.cfg")) \
313 + glob.glob(os.path.join(
"ups",
"eupspkg*"))
316 buildFiles = [f
for f
in files
if re.search(
r"\.build$", f)]
317 build_obj = env.Install(dest, buildFiles)
320 tableFiles = [f
for f
in files
if re.search(
r"\.table$", f)]
321 table_obj = env.Install(dest, tableFiles)
324 eupspkgFiles = [f
for f
in files
if re.search(
r"^eupspkg", f)]
325 eupspkg_obj = env.Install(dest, eupspkgFiles)
328 miscFiles = [f
for f
in files
if not re.search(
r"\.(build|table)$", f)]
329 misc_obj = env.Install(dest, miscFiles)
335 path = eups.Eups.setEupsPath()
337 locks = eups.lock.takeLocks(
"setup", path, eups.lock.LOCK_SH)
338 env[
"ENV"][
"EUPS_LOCK_PID"] = os.environ.get(
"EUPS_LOCK_PID",
"-1")
340 state.log.warn(
"Unable to import eups; not locking")
347 cmd =
"eups expandbuild -i --version %s " % env[
'version']
348 if 'baseversion' in env:
349 cmd +=
" --repoversion %s " % env[
'baseversion']
351 eupsTargets.extend(env.AddPostAction(build_obj, env.Action(
"%s" % (cmd), cmd)))
356 cmd =
"eups expandtable -i -W '^(?!LOCAL:)' " 358 cmd += presetup +
" " 361 act = env.Command(
"table",
"", env.Action(
"%s" % (cmd), cmd))
362 eupsTargets.extend(act)
370 env.SideEffect(
"eups", eupsTargets)
383 if d ==
"ups" and not state.env[
'no_eups']:
384 t = self.InstallEups(os.path.join(prefix,
"ups"))
386 t = self.InstallDir(prefix, d, ignoreRegex=ignoreRegex)
389 self.Alias(
"install", t)
390 self.Clean(
"install", prefix)
def makeProductPath(env, pathFormat)
return a path to use as the installation directory for a product
daf::base::PropertySet * set
def Declare(self, products=None)
Create current and declare targets for products.
def setPrefix(env, versionString, eupsProductPath=None)
def InstallLSST(self, prefix, dirs, ignoreRegex=None)
def __call__(self, target, source, env)
def determineVersion(env, versionString)
def InstallEups(env, dest, files=[], presetup="")
Install a ups directory, setting absolute versions as appropriate (unless you're installing from the ...
def InstallDir(self, prefix, dir, ignoreRegex=r"(~$|\yc$|\s?$)", recursive=True)
Install the directory dir into prefix, (along with all its descendents if recursive is True)...
SCons Action callable to recursively install a directory.
table::Key< table::Array< int > > group
daf::base::PropertyList * list
def memberOf(cls, name=None)
A Python decorator that injects functions into a class.
def __init__(self, ignoreRegex, recursive)
def getFingerprint(versionString)