# Development tool - standard commands plugin
#
# Copyright (C) 2014-2015 Intel Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""Devtool standard plugins"""
import os
import sys
import re
import shutil
import tempfile
import logging
import argparse
import scriptutils
import errno
from collections import OrderedDict
from devtool import exec_build_env_command, setup_tinfoil, check_workspace_recipe, use_external_build, setup_git_repo, DevtoolError
from devtool import parse_recipe
logger = logging.getLogger('devtool')
def add(args, config, basepath, workspace):
"""Entry point for the devtool 'add' subcommand"""
import bb
import oe.recipeutils
if args.recipename in workspace:
raise DevtoolError("recipe %s is already in your workspace" %
args.recipename)
reason = oe.recipeutils.validate_pn(args.recipename)
if reason:
raise DevtoolError(reason)
# FIXME this ought to be in validate_pn but we're using that in other contexts
if '/' in args.recipename:
raise DevtoolError('"/" is not a valid character in recipe names')
srctree = os.path.abspath(args.srctree)
if os.path.exists(srctree):
if args.fetch:
if not os.path.isdir(srctree):
raise DevtoolError("Cannot fetch into source tree path %s as "
"it exists and is not a directory" %
srctree)
elif os.listdir(srctree):
raise DevtoolError("Cannot fetch into source tree path %s as "
"it already exists and is non-empty" %
srctree)
elif not args.fetch:
raise DevtoolError("Specified source tree %s could not be found" %
srctree)
appendpath = os.path.join(config.workspace_path, 'appends')
if not os.path.exists(appendpath):
os.makedirs(appendpath)
recipedir = os.path.join(config.workspace_path, 'recipes', args.recipename)
bb.utils.mkdirhier(recipedir)
rfv = None
if args.version:
if '_' in args.version or ' ' in args.version:
raise DevtoolError('Invalid version string "%s"' % args.version)
rfv = args.version
if args.fetch:
if args.fetch.startswith('git://'):
rfv = 'git'
elif args.fetch.startswith('svn://'):
rfv = 'svn'
elif args.fetch.startswith('hg://'):
rfv = 'hg'
if rfv:
bp = "%s_%s" % (args.recipename, rfv)
else:
bp = args.recipename
recipefile = os.path.join(recipedir, "%s.bb" % bp)
if args.color == 'auto' and sys.stdout.isatty():
color = 'always'
else:
color = args.color
extracmdopts = ''
if args.fetch:
source = args.fetch
extracmdopts = '-x %s' % srctree
else:
source = srctree
if args.version:
extracmdopts += ' -V %s' % args.version
if args.binary:
extracmdopts += ' -b'
try:
stdout, _ = exec_build_env_command(config.init_path, basepath, 'recipetool --color=%s create -o %s "%s" %s' % (color, recipefile, source, extracmdopts))
except bb.process.ExecutionError as e:
raise DevtoolError('Command \'%s\' failed:\n%s' % (e.command, e.stdout))
_add_md5(config, args.recipename, recipefile)
if args.fetch and not args.no_git:
setup_git_repo(srctree, args.version, 'devtool')
initial_rev = None
if os.path.exists(os.path.join(srctree, '.git')):
(stdout, _) = bb.process.run('git rev-parse HEAD', cwd=srctree)
initial_rev = stdout.rstrip()
tinfoil = setup_tinfoil(config_only=True, basepath=basepath)
rd = oe.recipeutils.parse_recipe(recipefile, None, tinfoil.config_data)
if not rd:
return 1
appendfile = os.path.join(appendpath, '%s.bbappend' % bp)
with open(appendfile, 'w') as f:
f.write('inherit externalsrc\n')
f.write('EXTERNALSRC = "%s"\n' % srctree)
b_is_s = use_external_build(args.same_dir, args.no_same_dir, rd)
if b_is_s:
f.write('EXTERNALSRC_BUILD = "%s"\n' % srctree)
if initial_rev:
f.write('\n# initial_rev: %s\n' % initial_rev)
if args.binary:
f.write('do_install_append() {\n')
f.write(' rm -rf ${D}/.git\n')
f.write(' rm -f ${D}/singletask.lock\n'
|