mirror of
https://gitlab.com/ita1024/waf.git
synced 2024-11-22 01:46:15 +01:00
ccroot.py: add skip_stlib_deps feature
This commit is contained in:
parent
37a36eabf2
commit
69bac69b5a
11
demos/c/stlib-deps/libA/external_vars.c
Normal file
11
demos/c/stlib-deps/libA/external_vars.c
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "external_vars.h"
|
||||||
|
|
||||||
|
int k = 5;
|
||||||
|
|
||||||
|
void print_value_of_k() {
|
||||||
|
|
||||||
|
printf("K = %d\n", k);
|
||||||
|
|
||||||
|
}
|
14
demos/c/stlib-deps/libA/external_vars.h
Normal file
14
demos/c/stlib-deps/libA/external_vars.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
Export internal vars
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _EXTERNAL_VARS_H
|
||||||
|
#define _EXTERNAL_VARS_H
|
||||||
|
|
||||||
|
extern int k; /* export k */
|
||||||
|
|
||||||
|
void print_value_of_k();
|
||||||
|
|
||||||
|
extern int r;
|
||||||
|
|
||||||
|
#endif /*_EXTERNAL_VARS_H */
|
7
demos/c/stlib-deps/libA/wscript_build
Normal file
7
demos/c/stlib-deps/libA/wscript_build
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This is a static library that provides a header to include reference to
|
||||||
|
# internal variables.
|
||||||
|
bld.stlib(
|
||||||
|
target='A',
|
||||||
|
source='external_vars.c',
|
||||||
|
includes='.',
|
||||||
|
export_includes='.')
|
12
demos/c/stlib-deps/libB/sum.c
Normal file
12
demos/c/stlib-deps/libB/sum.c
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "sum.h"
|
||||||
|
|
||||||
|
#include "external_vars.h"
|
||||||
|
|
||||||
|
void sum(int j) {
|
||||||
|
printf("Adding %d...\n", j);
|
||||||
|
// Add our new value
|
||||||
|
k += j;
|
||||||
|
}
|
10
demos/c/stlib-deps/libB/sum.h
Normal file
10
demos/c/stlib-deps/libB/sum.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
Export internal vars
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SUM_H
|
||||||
|
#define _SUM_H
|
||||||
|
|
||||||
|
void sum(int j);
|
||||||
|
|
||||||
|
#endif /*_SUM_H */
|
9
demos/c/stlib-deps/libB/wscript_build
Normal file
9
demos/c/stlib-deps/libB/wscript_build
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# This script uses libA to do some internal logic. It uses the default
|
||||||
|
# behavior so it will be re-archived every time libA changes, even if
|
||||||
|
# changes in libA are only visible at runtime.
|
||||||
|
bld.stlib(
|
||||||
|
target='B',
|
||||||
|
source='sum.c',
|
||||||
|
use='A',
|
||||||
|
includes='.',
|
||||||
|
export_includes='.')
|
13
demos/c/stlib-deps/libC/diff.c
Normal file
13
demos/c/stlib-deps/libC/diff.c
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "diff.h"
|
||||||
|
|
||||||
|
#include "external_vars.h"
|
||||||
|
|
||||||
|
void diff(int j) {
|
||||||
|
|
||||||
|
printf("Subtracting %d...\n", j);
|
||||||
|
// subtract our new value
|
||||||
|
k -= j;
|
||||||
|
}
|
10
demos/c/stlib-deps/libC/diff.h
Normal file
10
demos/c/stlib-deps/libC/diff.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
Export internal vars
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _DIFF_H
|
||||||
|
#define _DIFF_H
|
||||||
|
|
||||||
|
void diff(int j);
|
||||||
|
|
||||||
|
#endif /* _DIFF_H */
|
10
demos/c/stlib-deps/libC/wscript_build
Normal file
10
demos/c/stlib-deps/libC/wscript_build
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# This script uses the logic that prevents static libraries from depending on
|
||||||
|
# eachother. This means that the only way libC is re-archived is if the source
|
||||||
|
# code file diff.c or any of its depenencies change.
|
||||||
|
bld.stlib(
|
||||||
|
target='C',
|
||||||
|
source='diff.c',
|
||||||
|
features='skip_stlib_link_deps',
|
||||||
|
use='A',
|
||||||
|
includes='.',
|
||||||
|
export_includes='.')
|
22
demos/c/stlib-deps/main.c
Normal file
22
demos/c/stlib-deps/main.c
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "external_vars.h"
|
||||||
|
#include "sum.h"
|
||||||
|
#include "diff.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
/* This should return to whatever the default value is. */
|
||||||
|
print_value_of_k();
|
||||||
|
sum(6);
|
||||||
|
print_value_of_k();
|
||||||
|
diff(8);
|
||||||
|
print_value_of_k();
|
||||||
|
sum(8);
|
||||||
|
print_value_of_k();
|
||||||
|
diff(6);
|
||||||
|
print_value_of_k();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
11
demos/c/stlib-deps/wscript_build
Normal file
11
demos/c/stlib-deps/wscript_build
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#! /usr/bin/env python
|
||||||
|
|
||||||
|
bld.recurse('libA')
|
||||||
|
bld.recurse('libB')
|
||||||
|
bld.recurse('libC')
|
||||||
|
|
||||||
|
# Note that main has an implied dependency between our main program and libA
|
||||||
|
bld.program(
|
||||||
|
source = 'main.c',
|
||||||
|
target = 'test_static_link_chain',
|
||||||
|
use = 'B C')
|
@ -75,7 +75,7 @@ def configure(conf):
|
|||||||
def build(bld):
|
def build(bld):
|
||||||
bld.env.DEFINES=['WAF=1']
|
bld.env.DEFINES=['WAF=1']
|
||||||
|
|
||||||
bld.recurse('program stlib shlib')
|
bld.recurse('program stlib stlib-deps shlib')
|
||||||
#bld.install_files('/tmp/foo', 'wscript')
|
#bld.install_files('/tmp/foo', 'wscript')
|
||||||
#bld.env.PREFIX='/tmp/foo'
|
#bld.env.PREFIX='/tmp/foo'
|
||||||
bld.install_files('${PREFIX}/', 'program/a.h program/main.c', relative_trick=False)
|
bld.install_files('${PREFIX}/', 'program/a.h program/main.c', relative_trick=False)
|
||||||
|
@ -238,6 +238,17 @@ def rm_tgt(cls):
|
|||||||
setattr(cls, 'run', wrap)
|
setattr(cls, 'run', wrap)
|
||||||
rm_tgt(stlink_task)
|
rm_tgt(stlink_task)
|
||||||
|
|
||||||
|
@feature('skip_stlib_link_deps')
|
||||||
|
@before_method('process_use')
|
||||||
|
def apply_skip_stlib_link_deps(self):
|
||||||
|
"""
|
||||||
|
This enables an optimization in the :py:func:wafilb.Tools.ccroot.processes_use: method that skips dependency and
|
||||||
|
link flag optimizations for targets that generate static libraries (via the :py:class:Tools.ccroot.stlink_task task).
|
||||||
|
The actual behavior is implemented in :py:func:wafilb.Tools.ccroot.processes_use: method so this feature only tells waf
|
||||||
|
to enable the new behavior.
|
||||||
|
"""
|
||||||
|
self.env.SKIP_STLIB_LINK_DEPS = True
|
||||||
|
|
||||||
@feature('c', 'cxx', 'd', 'fc', 'asm')
|
@feature('c', 'cxx', 'd', 'fc', 'asm')
|
||||||
@after_method('process_source')
|
@after_method('process_source')
|
||||||
def apply_link(self):
|
def apply_link(self):
|
||||||
@ -386,7 +397,11 @@ def process_use(self):
|
|||||||
y = self.bld.get_tgen_by_name(x)
|
y = self.bld.get_tgen_by_name(x)
|
||||||
var = y.tmp_use_var
|
var = y.tmp_use_var
|
||||||
if var and link_task:
|
if var and link_task:
|
||||||
if var == 'LIB' or y.tmp_use_stlib or x in names:
|
if self.env.SKIP_STLIB_LINK_DEPS and isinstance(link_task, stlink_task):
|
||||||
|
# If the skip_stlib_link_deps feature is enabled then we should
|
||||||
|
# avoid adding lib deps to the stlink_task instance.
|
||||||
|
pass
|
||||||
|
elif var == 'LIB' or y.tmp_use_stlib or x in names:
|
||||||
self.env.append_value(var, [y.target[y.target.rfind(os.sep) + 1:]])
|
self.env.append_value(var, [y.target[y.target.rfind(os.sep) + 1:]])
|
||||||
self.link_task.dep_nodes.extend(y.link_task.outputs)
|
self.link_task.dep_nodes.extend(y.link_task.outputs)
|
||||||
tmp_path = y.link_task.outputs[0].parent.path_from(self.get_cwd())
|
tmp_path = y.link_task.outputs[0].parent.path_from(self.get_cwd())
|
||||||
|
Loading…
Reference in New Issue
Block a user