--- SCM Interface
-- @module local.scm
--- Copyright (C) 2007-2016 emlix GmbH, see file AUTHORS
+-- Copyright (C) 2007-2017 emlix GmbH, see file AUTHORS
--
-- This file is part of e2factory, the emlix embedded build system.
-- For more information see http://www.e2factory.org
-- @return bool
-- @return an error object on failure
function scm.generic_source_check(info, sourcename, require_workingcopy)
- local rc, re
+ local rc, re, src
+ src = source.sources[sourcename]
- rc, re = scm.working_copy_available(info, sourcename)
+ rc, re = src:working_copy_available()
if (not rc) and require_workingcopy then
return false, err.new("working copy is not available")
end
if not rc then
return false, re
end
- return true, nil
+ return true
end
scm.register_interface("toresult")
scm.register_interface("fetch_source")
scm.register_interface("update")
scm.register_interface("check_workingcopy")
-scm.register_interface("working_copy_available")
return strict.lock(scm)
self._type, self._name))
end
+--- Check whether the working copy is available. Sources that don't have a
+-- working copy should return false and an error object. Abstract method.
+-- @return True or false.
+-- @return Error object on false
+function source.basic_source:working_copy_available()
+ error(err.new("called working_copy_availabley() of source base class, type %s name %s",
+ self._type, self._name))
+end
+
--- @section end
--- Dictionary holding all source objects indexed by their name.
return d
end
+function cvs.cvs_source:working_copy_available()
+ if not e2lib.isdir(e2lib.join(e2tool.root(), self._working)) then
+ return false, err.new("working copy for %s is not available", self._name)
+ end
+ return true
+end
+
--- Build the cvsroot string.
-- @param info Info table.
-- @param sourcename Source name.
function cvs.fetch_source(info, sourcename)
local rc, re, e, src, cvsroot, workdir, argv
- if scm.working_copy_available(info, sourcename) then
- return true
- end
-
e = err.new("fetching source failed: %s", sourcename)
src = source.sources[sourcename]
+ if src:working_copy_available() then
+ return true
+ end
+
cvsroot, re = mkcvsroot(info, sourcename)
if not cvsroot then
return false, e:cat(re)
e = err.new("updating source '%s' failed", sourcename)
src = source.sources[sourcename]
- rc, re = scm.working_copy_available(info, sourcename)
+ rc, re = src:working_copy_available()
if not rc then
return false, e:cat(re)
end
return true
end
-function cvs.working_copy_available(info, sourcename)
- local src = source.sources[sourcename]
- local dir = e2lib.join(e2tool.root(), src:get_working())
- if not e2lib.isdir(dir) then
- return false, err.new("working copy for %s is not available", sourcename)
- end
- return true
-end
-
function cvs.toresult(info, sourcename, sourceset, directory)
-- <directory>/source/<sourcename>.tar.gz
-- <directory>/makefile
return d
end
+function files.files_source:working_copy_available()
+ return false, err.new("source %s doesn't require a working copy", self._name)
+end
+
function files.fetch_source(info, sourcename)
local rc, re
local src = source.sources[sourcename]
return true
end
-function files.working_copy_available(info, sourcename)
- return false, err.new("source %s doesn't require a working copy", sourcename)
-end
-
--- Handle file:copy() in a way that appears intuitive to the user. Returns
-- a directory and filename that can be passed to eg. mkdir -p and cp.
-- @param buildpath Base build path (string).
return d
end
+--- Check if a working copy for a git repository is available
+-- @return True if available, false otherwise.
+-- @return Error object if no directory.
+function git.git_source:working_copy_available()
+ if not e2lib.isdir(e2lib.join(e2tool.root(), self._working)) then
+ return false, err.new("working copy for %s is not available", self._name)
+ end
+ return true
+end
+
+--------------------------------------------------------------------------------
+
--- Return the git commit ID of the specified source configuration. Specific to
-- sources of type git, useful for writing plugins.
-- @param info Info table.
e = err.new("getting commit ID failed for source: %s", sourcename)
src = source.sources[sourcename]
- rc, re = scm.working_copy_available(info, sourcename)
+ rc, re = src:working_copy_available()
if not rc then
return false, e:cat(re)
end
src = source.sources[sourcename]
e = err.new("updating source '%s' failed", sourcename)
- rc, re = scm.working_copy_available(info, sourcename)
+ rc, re = src:working_copy_available()
if not rc then
return false, e:cat(re)
end
function git.fetch_source(info, sourcename)
local e, rc, re, src, git_dir, work_tree, id
- if scm.working_copy_available(info, sourcename) then
- return true
- end
-
src = source.sources[sourcename]
e = err.new("fetching source failed: %s", sourcename)
+ if src:working_copy_available() then
+ return true
+ end
+
work_tree = e2lib.join(e2tool.root(), src:get_working())
git_dir = e2lib.join(work_tree, ".git")
return true
end
---- Check if a working copy for a git repository is available
--- @param info the info structure
--- @param sourcename string
--- @return True if available, false otherwise.
--- @return Error object if no directory.
-function git.working_copy_available(info, sourcename)
- local rc
- local src = source.sources[sourcename]
- local gitwc = e2lib.join(e2tool.root(), src:get_working())
-
- if not e2lib.isdir(gitwc) then
- return false, err.new("working copy for %s is not available", sourcename)
- end
- return true
-end
-
--- turn server:location into a git-style url
-- @param c table: a cache
-- @param server string: server name
local rc, re
local e = err.new("checking working copy of source %s failed", sourcename)
- rc = scm.working_copy_available(info, sourcename)
+ -- check if branch exists
+ local src = source.sources[sourcename]
+ local gitdir = e2lib.join(e2tool.root(), src:get_working(), ".git")
+ local ref = string.format("refs/heads/%s", src:get_branch())
+ local id
+
+ rc = src:working_copy_available()
if not rc then
e2lib.warnf("WOTHER", "in source %s: ", sourcename)
e2lib.warnf("WOTHER", " working copy is not available")
return true, nil
end
- -- check if branch exists
- local src = source.sources[sourcename]
- local gitdir = e2lib.join(e2tool.root(), src:get_working(), ".git")
- local ref = string.format("refs/heads/%s", src:get_branch())
- local id
rc, re, id = generic_git.lookup_id(gitdir, false, ref)
if not rc then
return d
end
---------------------------------------------------------------------------------
-
--- Check if a working copy for a git repository is available
--- @param info the info structure
--- @param sourcename string
--- @return True if working copy is available, false otherwise.
--- @return Informative error object if directory does not exist
-function gitrepo.working_copy_available(info, sourcename)
- assertIsTable(info)
- assertIsStringN(sourcename)
-
- local src = source.sources[sourcename]
-
- if not e2lib.isdir(e2lib.join(e2tool.root(), src:get_working())) then
- return false, err.new("working copy for %s is not available", sourcename)
+-- @return True if available, false otherwise.
+-- @return Error object if no directory.
+function gitrepo_source:working_copy_available()
+ if not e2lib.isdir(e2lib.join(e2tool.root(), self._working)) then
+ return false, err.new("working copy for %s is not available", self._name)
end
return true
end
+--------------------------------------------------------------------------------
+
--- Fetch a gitrepo source. Adapted from git plugin.
-- @param info the info structure
-- @param sourcename string
local e, rc, re, src, git_dir, work_tree, id
- if scm.working_copy_available(info, sourcename) then
- return true
- end
-
src = source.sources[sourcename]
e = err.new("fetching source failed: %s", sourcename)
+ if src:working_copy_available() then
+ return true
+ end
+
work_tree = e2lib.join(e2tool.root(), src:get_working())
git_dir = e2lib.join(work_tree, ".git")
local rc, re
local e = err.new("checking working copy of source %s failed", sourcename)
- rc = scm.working_copy_available(info, sourcename)
- if not rc then
- e2lib.warnf("WOTHER", "in source %s: ", sourcename)
- e2lib.warnf("WOTHER", " working copy is not available")
- return true, nil
- end
-
-- check if branch exists
local src = source.sources[sourcename]
local gitdir = e2lib.join(e2tool.root(), src:get_working(), ".git")
local ref = string.format("refs/heads/%s", src:get_branch())
local id
+ rc = src:working_copy_available()
+ if not rc then
+ e2lib.warnf("WOTHER", "in source %s: ", sourcename)
+ e2lib.warnf("WOTHER", " working copy is not available")
+ return true, nil
+ end
+
rc, re, id = generic_git.lookup_id(gitdir, false, ref)
if not rc then
return false, e:cat(re)
return d
end
+function svn.svn_source:working_copy_available()
+ if not e2lib.isdir(e2lib.join(e2tool.root(), self._working)) then
+ return false, err.new("working copy for %s is not available", self._name)
+ end
+ return true
+end
+
+--------------------------------------------------------------------------------
+
function svn.fetch_source(info, sourcename)
local rc, re
local e = err.new("fetching source failed: %s", sourcename)
return false, e:cat(re)
end
- if scm.working_copy_available(info, sourcename) then
+ if src:working_copy_available() then
return true
end
return true, nil
end
-function svn.working_copy_available(info, sourcename)
- local rc, re
- local src = source.sources[sourcename]
-
- local dir = e2lib.join(e2tool.root(), src:get_working())
- if not e2lib.isdir(dir) then
- return false, err.new("working copy for %s is not available", sourcename)
- end
- return true
-end
-
function svn.check_workingcopy(info, sourcename)
local rc, re
local e = err.new("checking working copy failed")