blob: cd8b4e318fc9e2cc166e41a235d7b9dd960ce81b [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// 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
Colin Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross3f40fa42015-01-30 17:27:36 -080016
17import (
Colin Cross70b40592015-03-23 12:57:34 -070018 "github.com/google/blueprint"
Dan Willemsen24f2f8d2015-07-15 14:34:02 -070019 _ "github.com/google/blueprint/bootstrap"
Colin Cross3f40fa42015-01-30 17:27:36 -080020)
21
22var (
Dan Willemsen34cc69e2015-09-23 15:26:20 -070023 pctx = NewPackageContext("android/soong/common")
Colin Cross3f40fa42015-01-30 17:27:36 -080024
25 cpPreserveSymlinks = pctx.VariableConfigMethod("cpPreserveSymlinks",
26 Config.CpPreserveSymlinksFlags)
27
Colin Cross3f40fa42015-01-30 17:27:36 -080028 // 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.
Colin Cross9d45bb72016-08-29 16:14:13 -070031 Phony = pctx.AndroidStaticRule("Phony",
Colin Cross3f40fa42015-01-30 17:27:36 -080032 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.
Colin Cross9d45bb72016-08-29 16:14:13 -070040 GeneratedFile = pctx.AndroidStaticRule("GeneratedFile",
Colin Cross3f40fa42015-01-30 17:27:36 -080041 blueprint.RuleParams{
42 Command: "# generated $out",
43 Description: "generated $out",
44 Generator: true,
45 })
46
47 // A copy rule.
Colin Cross9d45bb72016-08-29 16:14:13 -070048 Cp = pctx.AndroidStaticRule("Cp",
Colin Cross3f40fa42015-01-30 17:27:36 -080049 blueprint.RuleParams{
Josh Gaoae152712017-07-26 14:09:50 -070050 Command: "rm -f $out && cp $cpPreserveSymlinks $cpFlags $in $out",
Colin Cross3f40fa42015-01-30 17:27:36 -080051 Description: "cp $out",
52 },
53 "cpFlags")
54
Colin Cross5c517922017-08-31 12:29:17 -070055 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
Dan Albert5d723ab2016-07-18 22:29:52 -070062 // A timestamp touch rule.
Colin Cross9d45bb72016-08-29 16:14:13 -070063 Touch = pctx.AndroidStaticRule("Touch",
Dan Albert5d723ab2016-07-18 22:29:52 -070064 blueprint.RuleParams{
65 Command: "touch $out",
66 Description: "touch $out",
67 })
68
Colin Cross3f40fa42015-01-30 17:27:36 -080069 // A symlink rule.
Colin Cross9d45bb72016-08-29 16:14:13 -070070 Symlink = pctx.AndroidStaticRule("Symlink",
Colin Cross3f40fa42015-01-30 17:27:36 -080071 blueprint.RuleParams{
72 Command: "ln -f -s $fromPath $out",
73 Description: "symlink $out",
74 },
75 "fromPath")
Colin Cross6ff51382015-12-17 16:39:19 -080076
Colin Cross9d45bb72016-08-29 16:14:13 -070077 ErrorRule = pctx.AndroidStaticRule("Error",
Colin Cross6ff51382015-12-17 16:39:19 -080078 blueprint.RuleParams{
79 Command: `echo "$error" && false`,
80 Description: "error building $out",
81 },
82 "error")
Colin Cross9d45bb72016-08-29 16:14:13 -070083
Dan Albertc6345fb2016-10-20 01:36:11 -070084 Cat = pctx.AndroidStaticRule("Cat",
85 blueprint.RuleParams{
86 Command: "cat $in > $out",
87 Description: "concatenate licenses $out",
88 })
89
Nan Zhang27005112017-05-12 14:02:13 -070090 // 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.
Dan Albert30c9d6e2017-03-28 14:54:55 -070093 WriteFile = pctx.AndroidStaticRule("WriteFile",
94 blueprint.RuleParams{
Nan Zhang27005112017-05-12 14:02:13 -070095 Command: "/bin/bash -c 'echo -e $$0 > $out' '$content'",
Dan Albert30c9d6e2017-03-28 14:54:55 -070096 Description: "writing file $out",
97 },
98 "content")
99
Colin Cross9d45bb72016-08-29 16:14:13 -0700100 // Used only when USE_GOMA=true is set, to restrict non-goma jobs to the local parallelism value
101 localPool = blueprint.NewBuiltinPool("local_pool")
Colin Cross3f40fa42015-01-30 17:27:36 -0800102)
Dan Willemsen24f2f8d2015-07-15 14:34:02 -0700103
104func init() {
105 pctx.Import("github.com/google/blueprint/bootstrap")
106}