7 from __future__
import absolute_import, division, print_function
14 from SCons.Script.SConscript
import SConsEnvironment
21 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']}
51 version = env[
'version']
52 elif not versionString:
54 elif re.search(
r"^[$]Name:\s+", versionString):
56 version = re.search(
r"^[$]Name:\s+([^ $]*)", versionString).group(1)
59 elif re.search(
r"^[$]HeadURL:\s+", versionString):
61 HeadURL = re.search(
r"^[$]HeadURL:\s+(.*)", versionString).group(1)
62 HeadURL = os.path.split(HeadURL)[0]
63 version = svn.guessVersionName(HeadURL)
64 elif versionString.lower()
in (
"hg",
"mercurial"):
66 version = hg.guessVersionName()
67 elif versionString.lower()
in (
"git",):
69 version = git.guessVersionName()
70 return version.replace(
"/",
"_")
77 if versionString.lower()
in (
"hg",
"mercurial"):
78 fingerprint, modified = hg.guessFingerprint()
79 elif versionString.lower()
in (
"git",):
80 fingerprint, modified = git.guessFingerprint()
82 fingerprint, modified =
None,
False
84 if fingerprint
and modified:
91 def setPrefix(env, versionString, eupsProductPath=None):
94 except RuntimeError
as err:
95 env[
'version'] =
"unknown"
96 if (env.installing
or env.declaring)
and not env[
'force']:
98 "%s\nFound problem with version number; update or specify force=True to proceed"
102 if state.env[
'no_eups']:
103 if 'prefix' in env
and env[
'prefix']:
110 elif 'eupsPath' in env
and env[
'eupsPath']:
111 eupsPrefix = env[
'eupsPath']
113 state.log.fail(
"Unable to determine eupsPrefix from eupsProductPath or eupsPath")
114 flavor = env[
'eupsFlavor']
115 if not re.search(
"/" + flavor +
"$", eupsPrefix):
116 eupsPrefix = os.path.join(eupsPrefix, flavor)
117 prodPath = env[
'eupsProduct']
118 if 'eupsProductPath' in env
and env[
'eupsProductPath']:
119 prodPath = env[
'eupsProductPath']
120 eupsPrefix = os.path.join(eupsPrefix, prodPath, env[
"version"])
124 if env[
'version'] !=
"unknown" and eupsPrefix
and eupsPrefix != env[
'prefix']:
125 state.log.warn(
"Ignoring prefix %s from EUPS_PATH" % eupsPrefix)
127 elif 'eupsPath' in env
and env[
'eupsPath']:
130 prefix =
"/usr/local"
145 if "undeclare" in SCons.Script.COMMAND_LINE_TARGETS
and not self.GetOption(
"silent"):
146 state.log.warn(
"'scons undeclare' is deprecated; please use 'scons declare -c' instead")
149 if (
"declare" in SCons.Script.COMMAND_LINE_TARGETS
or
150 "undeclare" in SCons.Script.COMMAND_LINE_TARGETS
or
151 (
"install" in SCons.Script.COMMAND_LINE_TARGETS
and self.GetOption(
"clean"))
or
152 "current" in SCons.Script.COMMAND_LINE_TARGETS):
160 for prod
in products:
161 if not prod
or isinstance(prod, str):
164 if 'version' in self:
165 version = self[
'version']
169 product, version = prod
172 product = self[
'eupsProduct']
174 if "EUPS_DIR" in os.environ:
175 self[
'ENV'][
'PATH'] += os.pathsep +
"%s/bin" % (os.environ[
"EUPS_DIR"])
176 self[
"ENV"][
"EUPS_LOCK_PID"] = os.environ.get(
"EUPS_LOCK_PID",
"-1")
177 if "undeclare" in SCons.Script.COMMAND_LINE_TARGETS
or self.GetOption(
"clean"):
179 command =
"eups undeclare --flavor %s %s %s" % \
180 (self[
'eupsFlavor'], product, version)
181 if (
"current" in SCons.Script.COMMAND_LINE_TARGETS
and
182 "declare" not in SCons.Script.COMMAND_LINE_TARGETS):
183 command +=
" --current"
185 if self.GetOption(
"clean"):
186 self.Execute(command)
188 undeclare += [command]
190 state.log.warn(
"I don't know your version; not undeclaring to eups")
192 command =
"eups declare --force --flavor %s --root %s" % \
193 (self[
'eupsFlavor'], self[
'prefix'])
195 if 'eupsPath' in self:
196 command +=
" -Z %s" % self[
'eupsPath']
199 command +=
" %s %s" % (product, version)
201 current += [command +
" --current"]
203 if self.GetOption(
"tag"):
204 command +=
" --tag=%s" % self.GetOption(
"tag")
209 acts += self.Command(
"current",
"", action=current)
211 if "current" in SCons.Script.COMMAND_LINE_TARGETS:
212 acts += self.Command(
"declare",
"", action=
"")
214 acts += self.Command(
"declare",
"", action=declare)
216 acts += self.Command(
"undeclare",
"", action=undeclare)
239 prefix = os.path.abspath(os.path.join(target[0].abspath,
".."))
240 destpath = os.path.join(target[0].abspath)
241 if not os.path.isdir(destpath):
242 state.log.info(
"Creating directory %s" % destpath)
243 os.makedirs(destpath)
244 for root, dirnames, filenames
in os.walk(source[0].path):
248 dirnames[:] = [d
for d
in dirnames
if d !=
".svn"]
249 for dirname
in dirnames:
250 destpath = os.path.join(prefix, root, dirname)
251 if not os.path.isdir(destpath):
252 state.log.info(
"Creating directory %s" % destpath)
253 os.makedirs(destpath)
254 for filename
in filenames:
255 if self.ignoreRegex.search(filename):
257 destpath = os.path.join(prefix, root)
258 srcpath = os.path.join(root, filename)
259 state.log.info(
"Copying %s to %s" % (srcpath, destpath))
260 shutil.copy(srcpath, destpath)
269 def InstallDir(self, prefix, dir, ignoreRegex=r"(~$|\.pyc$|\.os?$)
", recursive=True):
270 if not self.installing:
272 result = self.Command(target=os.path.join(self.Dir(prefix).abspath, dir), source=dir,
274 self.AlwaysBuild(result)
295 if not env.installing:
298 if env.GetOption(
"clean"):
299 state.log.warn(
"Removing" + dest)
300 shutil.rmtree(dest, ignore_errors=
True)
304 presetupStr += [
"--product %s=%s" % (p, presetup[p])]
305 presetup =
" ".join(presetupStr)
307 env = env.Clone(ENV=os.environ)
311 files = [str(f)
for f
in files]
312 files += glob.glob(os.path.join(
"ups",
"*.build")) + glob.glob(os.path.join(
"ups",
"*.table")) \
313 + glob.glob(os.path.join(
"ups",
"*.cfg")) \
314 + glob.glob(os.path.join(
"ups",
"eupspkg*"))
315 files = list(set(files))
317 buildFiles = [f
for f
in files
if re.search(
r"\.build$", f)]
318 build_obj = env.Install(dest, buildFiles)
321 tableFiles = [f
for f
in files
if re.search(
r"\.table$", f)]
322 table_obj = env.Install(dest, tableFiles)
325 eupspkgFiles = [f
for f
in files
if re.search(
r"^eupspkg", f)]
326 eupspkg_obj = env.Install(dest, eupspkgFiles)
329 miscFiles = [f
for f
in files
if not re.search(
r"\.(build|table)$", f)]
330 misc_obj = env.Install(dest, miscFiles)
336 path = eups.Eups.setEupsPath()
338 locks = eups.lock.takeLocks(
"setup", path, eups.lock.LOCK_SH)
339 env[
"ENV"][
"EUPS_LOCK_PID"] = os.environ.get(
"EUPS_LOCK_PID",
"-1")
341 state.log.warn(
"Unable to import eups; not locking")
348 cmd =
"eups expandbuild -i --version %s " % env[
'version']
349 if 'baseversion' in env:
350 cmd +=
" --repoversion %s " % env[
'baseversion']
352 eupsTargets.extend(env.AddPostAction(build_obj, env.Action(
"%s" % (cmd), cmd)))
357 cmd =
"eups expandtable -i -W '^(?!LOCAL:)' "
359 cmd += presetup +
" "
362 act = env.Command(
"table",
"", env.Action(
"%s" % (cmd), cmd))
363 eupsTargets.extend(act)
371 env.SideEffect(
"eups", eupsTargets)
384 if d ==
"ups" and not state.env[
'no_eups']:
385 t = self.InstallEups(os.path.join(prefix,
"ups"))
387 t = self.InstallDir(prefix, d, ignoreRegex=ignoreRegex)
390 self.Alias(
"install", t)
391 self.Clean(
"install", prefix)
def Declare
Create current and declare targets for products.
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 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 InstallDir
Install the directory dir into prefix, (along with all its descendents if recursive is True)...