Skip to content

Commit

Permalink
Merge pull request #293 from chen3feng/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
chen3feng authored Feb 16, 2017
2 parents 87d5b4b + 928ba04 commit 5a002f9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 52 deletions.
6 changes: 4 additions & 2 deletions src/blade/blade.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,10 @@ def gen_targets_rules(self):
and k not in self.__direct_targets):
continue
scons_object.scons_rules()
rules_buf.append('\n')
rules_buf += scons_object.get_rules()
rules = scons_object.get_rules()
if rules:
rules_buf.append('\n')
rules_buf += rules
return rules_buf

def get_scons_platform(self):
Expand Down
28 changes: 12 additions & 16 deletions src/blade/cc_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,16 @@ def __init__(self,
self._check_incorrect_no_warning()

def _check_deprecated_deps(self):
"""check that whether it depends upon a deprecated library. """
for dep in self.deps:
target = self.target_database.get(dep, {})
if target.data.get('deprecated'):
replaced_targets = target.deps
replaced_target = ''
if replaced_targets:
replaced_target = replaced_targets[0]
console.warning('//%s:%s : '
'//%s:%s has been deprecated, '
'please depends on //%s:%s' % (
self.path, self.name,
target.path, target.name,
replaced_target[0], replaced_target[1]))
"""Check whether it depends upon a deprecated library. """
for key in self.deps:
dep = self.target_database.get(key)
if dep and dep.data.get('deprecated'):
replaced_deps = dep.deps
if replaced_deps:
console.warning('%s: //%s has been deprecated, '
'please depends on //%s:%s' % (
self.fullname, dep.fullname,
replaced_deps[0][0], replaced_deps[0][1]))

def _prepare_to_generate_rule(self):
"""Should be overridden. """
Expand Down Expand Up @@ -647,11 +643,11 @@ def scons_rules(self):
It outputs the scons rules according to user options.
"""
self._prepare_to_generate_rule()

if self.type == 'prebuilt_cc_library':
self._check_deprecated_deps()
self._prebuilt_cc_library()
elif self.srcs:
self._prepare_to_generate_rule()
self._cc_objects_rules()
self._cc_library()

Expand Down
15 changes: 8 additions & 7 deletions src/blade/java_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,9 @@ def _generate_java_classpath(self, dep_jar_vars, dep_jars):
def _generate_java_depends(self, var_name, dep_jar_vars, dep_jars,
resources_var, resources_path_var):
env_name = self._env_name()
self._write_rule('%s.Depends(%s, [%s])' % (
env_name, var_name, ','.join(dep_jar_vars)))
if dep_jar_vars:
self._write_rule('%s.Depends(%s, [%s])' % (
env_name, var_name, ','.join(dep_jar_vars)))
if dep_jars:
self._write_rule('%s.Depends(%s, %s.Value(%s))' % (
env_name, var_name, env_name, sorted(dep_jars)))
Expand Down Expand Up @@ -614,11 +615,13 @@ def __init__(self,
if warnings is not None:
self.data['warnings'] = var_to_list(warnings)

def _clone_env(self):
self._write_rule('%s = env_java.Clone()' % self._env_name())

def _prepare_to_generate_rule(self):
"""Should be overridden. """
self._check_deprecated_deps()
self._clone_env()
self._generate_java_versions()
self._generate_java_source_encoding()
warnings = self.data.get('warnings')
if warnings is None:
Expand Down Expand Up @@ -675,15 +678,13 @@ def __init__(self, name, srcs, deps, resources, source_encoding, warnings,
self.data['binary_jar'] = self._source_file_path(binary_jar)

def _generate_prebuilt_jar(self):
env_name = self._env_name()
var_name = self._var_name('jar')
self._write_rule('%s = %s.File(["%s"])' % (
var_name, env_name, self.data['binary_jar']))
self._write_rule('%s = top_env.File(["%s"])' % (
var_name, self.data['binary_jar']))
return var_name

def scons_rules(self):
if self.type == 'prebuilt_java_library':
self._clone_env()
jar_var = self._generate_prebuilt_jar()
else:
self._prepare_to_generate_rule()
Expand Down
68 changes: 41 additions & 27 deletions src/blade/rules_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ def __init__(self, options, build_dir, gcc_version,
self.cuda_inc = cuda_inc
self.build_environment = build_environment
self.ccflags_manager = CcFlagsManager(options, build_dir, gcc_version)
self.env_list = ['env_with_error', 'env_no_warning']

self.svn_roots = svn_roots

self.blade_config = configparse.blade_config
Expand Down Expand Up @@ -119,7 +117,7 @@ def generate_imports_functions(self, blade_path):
# Add java_home/bin into PATH to make scons
# construction variables of java work as expected
# See http://scons.org/faq.html#SCons_Questions
java_config = configparse.blade_config.get_config('java_config')
java_config = self.blade_config.get_config('java_config')
java_home = java_config['java_home']
if java_home:
self._add_rule('blade_util.environ_add_path(os.environ, "PATH", '
Expand All @@ -136,7 +134,7 @@ def generate_compliation_verbose(self):

def _generate_fast_link_builders(self):
"""Generates fast link builders if it is specified in blade bash. """
link_config = configparse.blade_config.get_config('link_config')
link_config = self.blade_config.get_config('link_config')
enable_dccc = link_config['enable_dccc']
if link_config['link_on_tmp']:
if (not enable_dccc) or (
Expand All @@ -145,7 +143,7 @@ def _generate_fast_link_builders(self):

def _generate_proto_builders(self):
self._add_rule('time_value = Value("%s")' % time.asctime())
proto_config = configparse.blade_config.get_config('proto_library_config')
proto_config = self.blade_config.get_config('proto_library_config')
protoc_bin = proto_config['protoc']
protoc_java_bin = protoc_bin
if proto_config['protoc_java']:
Expand All @@ -165,7 +163,7 @@ def _generate_proto_builders(self):

def _generate_thrift_builders(self):
# Generate thrift library builders.
thrift_config = configparse.blade_config.get_config('thrift_config')
thrift_config = self.blade_config.get_config('thrift_config')
thrift_incs_str = _incs_list_to_string(thrift_config['thrift_incs'])
thrift_bin = thrift_config['thrift']
if thrift_bin.startswith('//'):
Expand All @@ -176,7 +174,7 @@ def _generate_thrift_builders(self):
self.build_dir, thrift_bin, thrift_incs_str))

def _generate_fbthrift_builders(self):
fbthrift_config = configparse.blade_config.get_config('fbthrift_config')
fbthrift_config = self.blade_config.get_config('fbthrift_config')
fbthrift1_bin = fbthrift_config['fbthrift1']
fbthrift2_bin = fbthrift_config['fbthrift2']
fbthrift_incs_str = _incs_list_to_string(fbthrift_config['fbthrift_incs'])
Expand All @@ -194,17 +192,17 @@ def _generate_swig_builders(self):
self._add_rule('scons_helper.setup_swig_builders(top_env, "%s")' % self.build_dir)

def _generate_java_builders(self):
config = configparse.blade_config.get_config('java_config')
bin_config = configparse.blade_config.get_config('java_binary_config')
config = self.blade_config.get_config('java_config')
bin_config = self.blade_config.get_config('java_binary_config')
self._add_rule('scons_helper.setup_java_builders(top_env, "%s", "%s")' % (
config['java_home'], bin_config['one_jar_boot_jar']))

def _generate_scala_builders(self):
config = configparse.blade_config.get_config('scala_config')
config = self.blade_config.get_config('scala_config')
self._add_rule('scons_helper.setup_scala_builders(top_env, "%s")' % config['scala_home'])

def _generate_go_builders(self):
config = configparse.blade_config.get_config('go_config')
config = self.blade_config.get_config('go_config')
self._add_rule('scons_helper.setup_go_builders(top_env, "%s", "%s")' %
(config['go'], config['go_home']))

Expand Down Expand Up @@ -273,7 +271,7 @@ def generate_compliation_flags(self):
building_var=ld,
condition=build_with_dccc)

cc_config = configparse.blade_config.get_config('cc_config')
cc_config = self.blade_config.get_config('cc_config')
cc_env_str = ('CC="%s", CXX="%s", SECURECXX="%s %s"' % (
cc_str, cxx_str, cc_config['securecc'], cxx))
ld_env_str = 'LINK="%s"' % ld_str
Expand All @@ -297,7 +295,7 @@ def generate_compliation_flags(self):
cc_config['cxxflags'],
ld_env_str, linkflags))

cc_library_config = configparse.blade_config.get_config('cc_library_config')
cc_library_config = self.blade_config.get_config('cc_library_config')
# By default blade use 'ar rcs' and skip ranlib
# to generate index for static library
arflags = cc_library_config['arflags']
Expand Down Expand Up @@ -325,35 +323,51 @@ def generate_compliation_flags(self):
for rule in self.build_environment.get_rules():
self._add_rule(rule)

self._setup_warnings()
self._setup_envs()

def _setup_warnings(self):
for env in self.env_list:
def _setup_envs(self):
env_with_error, env_no_warning = 'env_with_error', 'env_no_warning'
for env in [env_with_error, env_no_warning]:
self._add_rule('%s = top_env.Clone()' % env)

(warnings, cxx_warnings, c_warnings) = self.ccflags_manager.get_warning_flags()
warnings, cxx_warnings, c_warnings = self.ccflags_manager.get_warning_flags()
self._add_rule('%s.Append(CPPFLAGS=%s, CFLAGS=%s, CXXFLAGS=%s)' % (
self.env_list[0],
warnings, c_warnings, cxx_warnings))
env_with_error, warnings, c_warnings, cxx_warnings))
self._setup_env_java()

def _setup_env_java(self):
env_java = 'env_java'
self._add_rule('%s = top_env.Clone()' % env_java)
java_config = self.blade_config.get_config('java_config')
version = java_config['version']
source_version = java_config.get('source_version', version)
target_version = java_config.get('target_version', version)
# JAVAVERSION must be set because scons need it to deduce class names
# from java source, and the default value '1.5' is too low.
java_version = version or '1.6'
self._add_rule('%s.Replace(JAVAVERSION="%s")' % (env_java, java_version))
if source_version:
self._add_rule('%s.Append(JAVACFLAGS="-source %s")' % (
env_java, source_version))
if target_version:
self._add_rule('%s.Append(JAVACFLAGS="-target %s")' % (
env_java, target_version))
java_test_config = self.blade_config.get_config('java_test_config')
jacoco_home = java_test_config['jacoco_home']
if jacoco_home:
jacoco_agent = os.path.join(jacoco_home, 'lib', 'jacocoagent.jar')
self._add_rule('%s.Replace(JACOCOAGENT="%s")' % (env_java, jacoco_agent))

def _setup_cache(self):
self.build_environment.setup_build_cache(self.options)

def generate_extra_flags(self):
config = configparse.blade_config.get_config('java_test_config')
jacoco_home = config['jacoco_home']
if jacoco_home:
jacoco_agent = os.path.join(jacoco_home, 'lib', 'jacocoagent.jar')
self._add_rule('top_env.Replace(JACOCOAGENT="%s")' % jacoco_agent)

def generate(self, blade_path):
"""Generates all rules. """
self.generate_imports_functions(blade_path)
self.generate_top_level_env()
self.generate_compliation_verbose()
self.generate_builders()
self.generate_compliation_flags()
self.generate_extra_flags()
self.generate_version_file()
return self.rules_buf

Expand Down

0 comments on commit 5a002f9

Please sign in to comment.