• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package android
16
17import (
18	"github.com/google/blueprint"
19	_ "github.com/google/blueprint/bootstrap"
20)
21
22var (
23	pctx = NewPackageContext("android/soong/android")
24
25	cpPreserveSymlinks = pctx.VariableConfigMethod("cpPreserveSymlinks",
26		Config.CpPreserveSymlinksFlags)
27
28	// A phony rule that is not the built-in Ninja phony rule.  The built-in
29	// phony rule has special behavior that is sometimes not desired.  See the
30	// Ninja docs for more details.
31	Phony = pctx.AndroidStaticRule("Phony",
32		blueprint.RuleParams{
33			Command:     "# phony $out",
34			Description: "phony $out",
35		})
36
37	// GeneratedFile is a rule for indicating that a given file was generated
38	// while running soong.  This allows the file to be cleaned up if it ever
39	// stops being generated by soong.
40	GeneratedFile = pctx.AndroidStaticRule("GeneratedFile",
41		blueprint.RuleParams{
42			Command:     "# generated $out",
43			Description: "generated $out",
44			Generator:   true,
45		})
46
47	// A copy rule.
48	Cp = pctx.AndroidStaticRule("Cp",
49		blueprint.RuleParams{
50			Command:     "rm -f $out && cp $cpPreserveSymlinks $cpFlags $in $out",
51			Description: "cp $out",
52		},
53		"cpFlags")
54
55	CpExecutable = pctx.AndroidStaticRule("CpExecutable",
56		blueprint.RuleParams{
57			Command:     "rm -f $out && cp $cpPreserveSymlinks $cpFlags $in $out && chmod +x $out",
58			Description: "cp $out",
59		},
60		"cpFlags")
61
62	// A timestamp touch rule.
63	Touch = pctx.AndroidStaticRule("Touch",
64		blueprint.RuleParams{
65			Command:     "touch $out",
66			Description: "touch $out",
67		})
68
69	// A symlink rule.
70	Symlink = pctx.AndroidStaticRule("Symlink",
71		blueprint.RuleParams{
72			Command:     "ln -f -s $fromPath $out",
73			Description: "symlink $out",
74		},
75		"fromPath")
76
77	ErrorRule = pctx.AndroidStaticRule("Error",
78		blueprint.RuleParams{
79			Command:     `echo "$error" && false`,
80			Description: "error building $out",
81		},
82		"error")
83
84	Cat = pctx.AndroidStaticRule("Cat",
85		blueprint.RuleParams{
86			Command:     "cat $in > $out",
87			Description: "concatenate licenses $out",
88		})
89
90	// ubuntu 14.04 offcially use dash for /bin/sh, and its builtin echo command
91	// doesn't support -e option. Therefore we force to use /bin/bash when writing out
92	// content to file.
93	WriteFile = pctx.AndroidStaticRule("WriteFile",
94		blueprint.RuleParams{
95			Command:     "/bin/bash -c 'echo -e $$0 > $out' '$content'",
96			Description: "writing file $out",
97		},
98		"content")
99
100	// Used only when USE_GOMA=true is set, to restrict non-goma jobs to the local parallelism value
101	localPool = blueprint.NewBuiltinPool("local_pool")
102
103	// Used only by RuleBuilder to identify remoteable rules. Does not actually get created in ninja.
104	remotePool = blueprint.NewBuiltinPool("remote_pool")
105
106	// Used for processes that need significant RAM to ensure there are not too many running in parallel.
107	highmemPool = blueprint.NewBuiltinPool("highmem_pool")
108)
109
110func init() {
111	pctx.Import("github.com/google/blueprint/bootstrap")
112}
113