summaryrefslogtreecommitdiff
path: root/chromium/docs/no_sources_assignment_filter.md
blob: 428cc9c2b0bb6f1787d62fecb5cc8112ef1b0f57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# No sources_assignment_filter

There is a [strong][0] [consensus][1] that the set_sources_assignment_filter
feature from GN is a mis-feature and should be removed. This requires that
Chromium's BUILD.gn file stop using the feature.

## Why convert

When set_sources_assignment_filter is called, it configures a list of patterns
that will be used to filter names every time a variable named "sources" is
assigned a value.

Historically, Chromium used to call this function in build/BUILDCONFIG.gn thus
causing the patterns to be applied to every BUILD.gn file in the project. This
had multiple drawbacks:

1.  the configuration of the list of patterns is located far from the point
    where they are applied and developer are usually confused when a file
    they add to a rule is not build due to those pattern

2.  the filtering is applied to every assignment to a variable named "sources"
    after interpreting the string as a relative filename, thus build breaks if
    one of the forbidden pattern is used in unexpected location (like naming
    the build directory out/linux, or having mac/ in path to SDK, ...)

3.  the filtering is applied to every assignment to a variable named "sources"
    in the whole project, thus it has significant negative impact on the
    performance of gn

Since September 2020, the filter is enabled only for the files that have not
yet been converted. Eventually, this will be removed.

## Conversion pattern

To convert a BUILD.gn file it is necessary to change the following:

```
  source_set("foo") {
    sources = [
      "foo.h",
      "foo_mac.mm",
      "foo_win.cc",
      "foo_linux.cc",
    ]
  }
```

to

```
  source_set("foo") {
    sources = [
      "foo.h",
    ]
    if (is_mac) {
      sources += [
        "foo_mac.mm",
      ]
    }
    if (is_win) {
      sources += [
        "foo_win.cc",
      ]
    }
    if (is_linux) {
      sources += [
        "foo_linux.cc",
      ]
    }
  }
```

Since the second pattern never assign a name that will be filtered out, then
it is compatible whether the set_sources_assignment_filter feature is used or
not.

Once conversion is done, remove the following lines from the top of the file
to avoid regressions:

```
import("//build/config/deprecated_default_sources_assignment_filter.gni")
sources_assignment_filter = deprecated_default_sources_assignment_filter
```


[0]: https://groups.google.com/a/chromium.org/d/topic/chromium-dev/hyLuCU6g2V4/discussion
[1]: https://groups.google.com/a/chromium.org/d/topic/gn-dev/oQcYStl_WkI/discussion