You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.4 KiB
65 lines
2.4 KiB
#-*- coding: utf-8 -*-
|
|
|
|
# Copyright 2010 Calculate Ltd. http://www.calculate-linux.org
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import os
|
|
import re
|
|
import cl_overriding
|
|
from cl_datavars import glob_attr
|
|
from cl_kernel import cl_kernel
|
|
from os import access, R_OK
|
|
from os import path
|
|
|
|
class fillVars(object, glob_attr):
|
|
|
|
def get_cl_kernel_directory(self):
|
|
defaultKernelPath = '/usr/src'
|
|
if not access(defaultKernelPath,R_OK):
|
|
return ""
|
|
kernel = cl_kernel()
|
|
kernelDirs = filter(kernel._testKernelDirectory,os.listdir('/usr/src'))
|
|
if kernelDirs:
|
|
if "linux" in kernelDirs:
|
|
return path.join(defaultKernelPath,"linux")
|
|
else:
|
|
return path.join(defaultKernelPath,kernelDirs[0])
|
|
return ""
|
|
|
|
def get_cl_kernel_version(self):
|
|
kernelMakefile = path.join(self.Get('cl_kernel_directory'),'Makefile')
|
|
reVerPart = re.compile("^(?:VERSION|^PATCHLEVEL|^SUBLEVEL)\s*=",re.I)
|
|
if access(kernelMakefile,R_OK):
|
|
try:
|
|
return "%(VERSION)s.%(PATCHLEVEL)s.%(SUBLEVEL)s"% \
|
|
dict(map(lambda x:(x[0].strip(),x[2].strip()),
|
|
map(lambda x:x.partition('='),
|
|
filter(reVerPart.search,
|
|
open(kernelMakefile,'r')))))
|
|
except:
|
|
pass
|
|
return ""
|
|
|
|
def get_cl_kernel_config(self):
|
|
kernelDirs = self.Get('cl_kernel_config_path')
|
|
if not access(kernelDirs,R_OK):
|
|
return ""
|
|
configName = "config-%(system)s-%(march)s-%(ver)s" % \
|
|
{'system':self.Get('os_linux_system'),
|
|
'march':self.Get('os_arch_machine'),
|
|
'ver':self.Get('cl_kernel_version')}
|
|
if path.exists(configName):
|
|
return path.join(kernelDirs,configName)
|
|
return ""
|