Add a Go replacement for our top-level Make wrapper
Right now this mostly just copies what Make is doing in
build/core/ninja.mk and build/core/soong.mk. The only major feature it
adds is a rotating log file with some verbose logging.
There is one major functional difference -- you cannot override random
Make variables during the Make phase anymore. The environment variable
is set, and if Make uses ?= or the equivalent, it can still use those
variables. We already made this change for Kati, which also loads all of
the same code and actually does the build, so it has been half-removed
for a while.
The only "UI" this implements is what I'll call "Make Emulation" mode --
it's expected that current command lines will continue working, and
we'll explore alternate user interfaces later.
We're still using Make as a wrapper, but all it does is call into this
single Go program, it won't even load the product configuration. Once
this is default, we can start moving individual users over to using this
directly (still in Make emulation mode), skipping the Make wrapper.
Ideas for the future:
* Generating trace files showing time spent in Make/Kati/Soong/Ninja
(also importing ninja traces into the same stream). I had this working
in a previous version of this patch, but removed it to keep the size
down and focus on the current features.
* More intelligent SIGALRM handling, once we fully remove the Make
wrapper (which hides the SIGALRM)
* Reading the experimental binary output stream from Ninja, so that we
can always save the verbose log even if we're not printing it out to
the console
Test: USE_SOONG_UI=true m -j blueprint_tools
Change-Id: I884327b9a8ae24499eb6c56f6e1ad26df1cfa4e4
2016-08-22 00:17:17 +02:00
|
|
|
// Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package build
|
|
|
|
|
|
|
|
import (
|
2017-05-26 00:44:36 +02:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2016-08-22 00:17:17 +02:00
|
|
|
"path/filepath"
|
2020-01-03 04:10:38 +01:00
|
|
|
"sort"
|
Add a Go replacement for our top-level Make wrapper
Right now this mostly just copies what Make is doing in
build/core/ninja.mk and build/core/soong.mk. The only major feature it
adds is a rotating log file with some verbose logging.
There is one major functional difference -- you cannot override random
Make variables during the Make phase anymore. The environment variable
is set, and if Make uses ?= or the equivalent, it can still use those
variables. We already made this change for Kati, which also loads all of
the same code and actually does the build, so it has been half-removed
for a while.
The only "UI" this implements is what I'll call "Make Emulation" mode --
it's expected that current command lines will continue working, and
we'll explore alternate user interfaces later.
We're still using Make as a wrapper, but all it does is call into this
single Go program, it won't even load the product configuration. Once
this is default, we can start moving individual users over to using this
directly (still in Make emulation mode), skipping the Make wrapper.
Ideas for the future:
* Generating trace files showing time spent in Make/Kati/Soong/Ninja
(also importing ninja traces into the same stream). I had this working
in a previous version of this patch, but removed it to keep the size
down and focus on the current features.
* More intelligent SIGALRM handling, once we fully remove the Make
wrapper (which hides the SIGALRM)
* Reading the experimental binary output stream from Ninja, so that we
can always save the verbose log even if we're not printing it out to
the console
Test: USE_SOONG_UI=true m -j blueprint_tools
Change-Id: I884327b9a8ae24499eb6c56f6e1ad26df1cfa4e4
2016-08-22 00:17:17 +02:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2016-08-22 00:17:17 +02:00
|
|
|
"time"
|
Add a unified status reporting UI
This adds a new status package that merges the running of "actions"
(ninja calls them edges) of multiple tools into one view of the current
state, and gives that to a number of different outputs.
For inputs:
Kati's output parser has been rewritten (and moved) to map onto the
StartAction/FinishAction API. A byproduct of this is that the build
servers should be able to extract errors from Kati better, since they
look like the errors that Ninja used to write.
Ninja is no longer directly connected to the terminal, but its output is
read via the protobuf frontend API, so it's just another tool whose
output becomes merged together.
multiproduct_kati loses its custom status routines, and uses the common
one instead.
For outputs:
The primary output is the ui/terminal.Status type, which along with
ui/terminal.Writer now controls everything about the terminal output.
Today, this doesn't really change any behaviors, but having all terminal
output going through here allows a more complicated (multi-line / full
window) status display in the future.
The tracer acts as an output of the status package, tracing all the
action start / finish events. This replaces reading the .ninja_log file,
so it now properly handles multiple output files from a single action.
A new rotated log file (out/error.log, or out/dist/logs/error.log) just
contains a description of all of the errors that happened during the
current build.
Another new compressed and rotated log file (out/verbose.log.gz, or
out/dist/logs/verbose.log.gz) contains the full verbose (showcommands)
log of every execution run by the build. Since this is now written on
every build, the showcommands argument is now ignored -- if you want to
get the commands run, look at the log file after the build.
Test: m
Test: <built-in tests>
Test: NINJA_ARGS="-t list" m
Test: check the build.trace.gz
Test: check the new log files
Change-Id: If1d8994890d43ef68f65aa10ddd8e6e06dc7013a
2018-05-18 01:37:09 +02:00
|
|
|
|
2023-02-16 19:31:43 +01:00
|
|
|
"android/soong/shared"
|
2018-12-13 01:01:49 +01:00
|
|
|
"android/soong/ui/metrics"
|
Add a unified status reporting UI
This adds a new status package that merges the running of "actions"
(ninja calls them edges) of multiple tools into one view of the current
state, and gives that to a number of different outputs.
For inputs:
Kati's output parser has been rewritten (and moved) to map onto the
StartAction/FinishAction API. A byproduct of this is that the build
servers should be able to extract errors from Kati better, since they
look like the errors that Ninja used to write.
Ninja is no longer directly connected to the terminal, but its output is
read via the protobuf frontend API, so it's just another tool whose
output becomes merged together.
multiproduct_kati loses its custom status routines, and uses the common
one instead.
For outputs:
The primary output is the ui/terminal.Status type, which along with
ui/terminal.Writer now controls everything about the terminal output.
Today, this doesn't really change any behaviors, but having all terminal
output going through here allows a more complicated (multi-line / full
window) status display in the future.
The tracer acts as an output of the status package, tracing all the
action start / finish events. This replaces reading the .ninja_log file,
so it now properly handles multiple output files from a single action.
A new rotated log file (out/error.log, or out/dist/logs/error.log) just
contains a description of all of the errors that happened during the
current build.
Another new compressed and rotated log file (out/verbose.log.gz, or
out/dist/logs/verbose.log.gz) contains the full verbose (showcommands)
log of every execution run by the build. Since this is now written on
every build, the showcommands argument is now ignored -- if you want to
get the commands run, look at the log file after the build.
Test: m
Test: <built-in tests>
Test: NINJA_ARGS="-t list" m
Test: check the build.trace.gz
Test: check the new log files
Change-Id: If1d8994890d43ef68f65aa10ddd8e6e06dc7013a
2018-05-18 01:37:09 +02:00
|
|
|
"android/soong/ui/status"
|
Add a Go replacement for our top-level Make wrapper
Right now this mostly just copies what Make is doing in
build/core/ninja.mk and build/core/soong.mk. The only major feature it
adds is a rotating log file with some verbose logging.
There is one major functional difference -- you cannot override random
Make variables during the Make phase anymore. The environment variable
is set, and if Make uses ?= or the equivalent, it can still use those
variables. We already made this change for Kati, which also loads all of
the same code and actually does the build, so it has been half-removed
for a while.
The only "UI" this implements is what I'll call "Make Emulation" mode --
it's expected that current command lines will continue working, and
we'll explore alternate user interfaces later.
We're still using Make as a wrapper, but all it does is call into this
single Go program, it won't even load the product configuration. Once
this is default, we can start moving individual users over to using this
directly (still in Make emulation mode), skipping the Make wrapper.
Ideas for the future:
* Generating trace files showing time spent in Make/Kati/Soong/Ninja
(also importing ninja traces into the same stream). I had this working
in a previous version of this patch, but removed it to keep the size
down and focus on the current features.
* More intelligent SIGALRM handling, once we fully remove the Make
wrapper (which hides the SIGALRM)
* Reading the experimental binary output stream from Ninja, so that we
can always save the verbose log even if we're not printing it out to
the console
Test: USE_SOONG_UI=true m -j blueprint_tools
Change-Id: I884327b9a8ae24499eb6c56f6e1ad26df1cfa4e4
2016-08-22 00:17:17 +02:00
|
|
|
)
|
|
|
|
|
2023-02-16 19:31:43 +01:00
|
|
|
const (
|
|
|
|
// File containing the environment state when ninja is executed
|
2023-03-18 16:12:39 +01:00
|
|
|
ninjaEnvFileName = "ninja.environment"
|
|
|
|
ninjaLogFileName = ".ninja_log"
|
|
|
|
ninjaWeightListFileName = ".ninja_weight_list"
|
2023-02-16 19:31:43 +01:00
|
|
|
)
|
|
|
|
|
2020-11-17 12:52:28 +01:00
|
|
|
// Constructs and runs the Ninja command line with a restricted set of
|
|
|
|
// environment variables. It's important to restrict the environment Ninja runs
|
|
|
|
// for hermeticity reasons, and to avoid spurious rebuilds.
|
2021-03-16 08:55:23 +01:00
|
|
|
func runNinjaForBuild(ctx Context, config Config) {
|
2018-12-13 01:01:49 +01:00
|
|
|
ctx.BeginTrace(metrics.PrimaryNinja, "ninja")
|
2016-08-22 00:17:17 +02:00
|
|
|
defer ctx.EndTrace()
|
|
|
|
|
2020-11-17 12:52:28 +01:00
|
|
|
// Sets up the FIFO status updater that reads the Ninja protobuf output, and
|
|
|
|
// translates it to the soong_ui status output, displaying real-time
|
|
|
|
// progress of the build.
|
Add a unified status reporting UI
This adds a new status package that merges the running of "actions"
(ninja calls them edges) of multiple tools into one view of the current
state, and gives that to a number of different outputs.
For inputs:
Kati's output parser has been rewritten (and moved) to map onto the
StartAction/FinishAction API. A byproduct of this is that the build
servers should be able to extract errors from Kati better, since they
look like the errors that Ninja used to write.
Ninja is no longer directly connected to the terminal, but its output is
read via the protobuf frontend API, so it's just another tool whose
output becomes merged together.
multiproduct_kati loses its custom status routines, and uses the common
one instead.
For outputs:
The primary output is the ui/terminal.Status type, which along with
ui/terminal.Writer now controls everything about the terminal output.
Today, this doesn't really change any behaviors, but having all terminal
output going through here allows a more complicated (multi-line / full
window) status display in the future.
The tracer acts as an output of the status package, tracing all the
action start / finish events. This replaces reading the .ninja_log file,
so it now properly handles multiple output files from a single action.
A new rotated log file (out/error.log, or out/dist/logs/error.log) just
contains a description of all of the errors that happened during the
current build.
Another new compressed and rotated log file (out/verbose.log.gz, or
out/dist/logs/verbose.log.gz) contains the full verbose (showcommands)
log of every execution run by the build. Since this is now written on
every build, the showcommands argument is now ignored -- if you want to
get the commands run, look at the log file after the build.
Test: m
Test: <built-in tests>
Test: NINJA_ARGS="-t list" m
Test: check the build.trace.gz
Test: check the new log files
Change-Id: If1d8994890d43ef68f65aa10ddd8e6e06dc7013a
2018-05-18 01:37:09 +02:00
|
|
|
fifo := filepath.Join(config.OutDir(), ".ninja_fifo")
|
2019-03-22 00:02:58 +01:00
|
|
|
nr := status.NewNinjaReader(ctx, ctx.Status.StartTool(), fifo)
|
|
|
|
defer nr.Close()
|
Add a unified status reporting UI
This adds a new status package that merges the running of "actions"
(ninja calls them edges) of multiple tools into one view of the current
state, and gives that to a number of different outputs.
For inputs:
Kati's output parser has been rewritten (and moved) to map onto the
StartAction/FinishAction API. A byproduct of this is that the build
servers should be able to extract errors from Kati better, since they
look like the errors that Ninja used to write.
Ninja is no longer directly connected to the terminal, but its output is
read via the protobuf frontend API, so it's just another tool whose
output becomes merged together.
multiproduct_kati loses its custom status routines, and uses the common
one instead.
For outputs:
The primary output is the ui/terminal.Status type, which along with
ui/terminal.Writer now controls everything about the terminal output.
Today, this doesn't really change any behaviors, but having all terminal
output going through here allows a more complicated (multi-line / full
window) status display in the future.
The tracer acts as an output of the status package, tracing all the
action start / finish events. This replaces reading the .ninja_log file,
so it now properly handles multiple output files from a single action.
A new rotated log file (out/error.log, or out/dist/logs/error.log) just
contains a description of all of the errors that happened during the
current build.
Another new compressed and rotated log file (out/verbose.log.gz, or
out/dist/logs/verbose.log.gz) contains the full verbose (showcommands)
log of every execution run by the build. Since this is now written on
every build, the showcommands argument is now ignored -- if you want to
get the commands run, look at the log file after the build.
Test: m
Test: <built-in tests>
Test: NINJA_ARGS="-t list" m
Test: check the build.trace.gz
Test: check the new log files
Change-Id: If1d8994890d43ef68f65aa10ddd8e6e06dc7013a
2018-05-18 01:37:09 +02:00
|
|
|
|
2017-04-27 23:28:00 +02:00
|
|
|
executable := config.PrebuiltBuildTool("ninja")
|
Add a Go replacement for our top-level Make wrapper
Right now this mostly just copies what Make is doing in
build/core/ninja.mk and build/core/soong.mk. The only major feature it
adds is a rotating log file with some verbose logging.
There is one major functional difference -- you cannot override random
Make variables during the Make phase anymore. The environment variable
is set, and if Make uses ?= or the equivalent, it can still use those
variables. We already made this change for Kati, which also loads all of
the same code and actually does the build, so it has been half-removed
for a while.
The only "UI" this implements is what I'll call "Make Emulation" mode --
it's expected that current command lines will continue working, and
we'll explore alternate user interfaces later.
We're still using Make as a wrapper, but all it does is call into this
single Go program, it won't even load the product configuration. Once
this is default, we can start moving individual users over to using this
directly (still in Make emulation mode), skipping the Make wrapper.
Ideas for the future:
* Generating trace files showing time spent in Make/Kati/Soong/Ninja
(also importing ninja traces into the same stream). I had this working
in a previous version of this patch, but removed it to keep the size
down and focus on the current features.
* More intelligent SIGALRM handling, once we fully remove the Make
wrapper (which hides the SIGALRM)
* Reading the experimental binary output stream from Ninja, so that we
can always save the verbose log even if we're not printing it out to
the console
Test: USE_SOONG_UI=true m -j blueprint_tools
Change-Id: I884327b9a8ae24499eb6c56f6e1ad26df1cfa4e4
2016-08-22 00:17:17 +02:00
|
|
|
args := []string{
|
|
|
|
"-d", "keepdepfile",
|
2020-03-12 18:30:35 +01:00
|
|
|
"-d", "keeprsp",
|
2020-05-18 23:02:02 +02:00
|
|
|
"-d", "stats",
|
2018-07-18 02:54:31 +02:00
|
|
|
"--frontend_file", fifo,
|
Add a Go replacement for our top-level Make wrapper
Right now this mostly just copies what Make is doing in
build/core/ninja.mk and build/core/soong.mk. The only major feature it
adds is a rotating log file with some verbose logging.
There is one major functional difference -- you cannot override random
Make variables during the Make phase anymore. The environment variable
is set, and if Make uses ?= or the equivalent, it can still use those
variables. We already made this change for Kati, which also loads all of
the same code and actually does the build, so it has been half-removed
for a while.
The only "UI" this implements is what I'll call "Make Emulation" mode --
it's expected that current command lines will continue working, and
we'll explore alternate user interfaces later.
We're still using Make as a wrapper, but all it does is call into this
single Go program, it won't even load the product configuration. Once
this is default, we can start moving individual users over to using this
directly (still in Make emulation mode), skipping the Make wrapper.
Ideas for the future:
* Generating trace files showing time spent in Make/Kati/Soong/Ninja
(also importing ninja traces into the same stream). I had this working
in a previous version of this patch, but removed it to keep the size
down and focus on the current features.
* More intelligent SIGALRM handling, once we fully remove the Make
wrapper (which hides the SIGALRM)
* Reading the experimental binary output stream from Ninja, so that we
can always save the verbose log even if we're not printing it out to
the console
Test: USE_SOONG_UI=true m -j blueprint_tools
Change-Id: I884327b9a8ae24499eb6c56f6e1ad26df1cfa4e4
2016-08-22 00:17:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
args = append(args, config.NinjaArgs()...)
|
|
|
|
|
|
|
|
var parallel int
|
2019-11-11 23:57:42 +01:00
|
|
|
if config.UseRemoteBuild() {
|
Add a Go replacement for our top-level Make wrapper
Right now this mostly just copies what Make is doing in
build/core/ninja.mk and build/core/soong.mk. The only major feature it
adds is a rotating log file with some verbose logging.
There is one major functional difference -- you cannot override random
Make variables during the Make phase anymore. The environment variable
is set, and if Make uses ?= or the equivalent, it can still use those
variables. We already made this change for Kati, which also loads all of
the same code and actually does the build, so it has been half-removed
for a while.
The only "UI" this implements is what I'll call "Make Emulation" mode --
it's expected that current command lines will continue working, and
we'll explore alternate user interfaces later.
We're still using Make as a wrapper, but all it does is call into this
single Go program, it won't even load the product configuration. Once
this is default, we can start moving individual users over to using this
directly (still in Make emulation mode), skipping the Make wrapper.
Ideas for the future:
* Generating trace files showing time spent in Make/Kati/Soong/Ninja
(also importing ninja traces into the same stream). I had this working
in a previous version of this patch, but removed it to keep the size
down and focus on the current features.
* More intelligent SIGALRM handling, once we fully remove the Make
wrapper (which hides the SIGALRM)
* Reading the experimental binary output stream from Ninja, so that we
can always save the verbose log even if we're not printing it out to
the console
Test: USE_SOONG_UI=true m -j blueprint_tools
Change-Id: I884327b9a8ae24499eb6c56f6e1ad26df1cfa4e4
2016-08-22 00:17:17 +02:00
|
|
|
parallel = config.RemoteParallel()
|
|
|
|
} else {
|
|
|
|
parallel = config.Parallel()
|
|
|
|
}
|
|
|
|
args = append(args, "-j", strconv.Itoa(parallel))
|
|
|
|
if config.keepGoing != 1 {
|
|
|
|
args = append(args, "-k", strconv.Itoa(config.keepGoing))
|
|
|
|
}
|
|
|
|
|
|
|
|
args = append(args, "-f", config.CombinedNinjaFile())
|
|
|
|
|
2019-01-06 04:31:32 +01:00
|
|
|
args = append(args,
|
2020-04-19 05:25:59 +02:00
|
|
|
"-o", "usesphonyoutputs=yes",
|
2019-01-06 04:31:32 +01:00
|
|
|
"-w", "dupbuild=err",
|
2022-10-18 02:13:59 +02:00
|
|
|
"-w", "missingdepfile=err")
|
Add a Go replacement for our top-level Make wrapper
Right now this mostly just copies what Make is doing in
build/core/ninja.mk and build/core/soong.mk. The only major feature it
adds is a rotating log file with some verbose logging.
There is one major functional difference -- you cannot override random
Make variables during the Make phase anymore. The environment variable
is set, and if Make uses ?= or the equivalent, it can still use those
variables. We already made this change for Kati, which also loads all of
the same code and actually does the build, so it has been half-removed
for a while.
The only "UI" this implements is what I'll call "Make Emulation" mode --
it's expected that current command lines will continue working, and
we'll explore alternate user interfaces later.
We're still using Make as a wrapper, but all it does is call into this
single Go program, it won't even load the product configuration. Once
this is default, we can start moving individual users over to using this
directly (still in Make emulation mode), skipping the Make wrapper.
Ideas for the future:
* Generating trace files showing time spent in Make/Kati/Soong/Ninja
(also importing ninja traces into the same stream). I had this working
in a previous version of this patch, but removed it to keep the size
down and focus on the current features.
* More intelligent SIGALRM handling, once we fully remove the Make
wrapper (which hides the SIGALRM)
* Reading the experimental binary output stream from Ninja, so that we
can always save the verbose log even if we're not printing it out to
the console
Test: USE_SOONG_UI=true m -j blueprint_tools
Change-Id: I884327b9a8ae24499eb6c56f6e1ad26df1cfa4e4
2016-08-22 00:17:17 +02:00
|
|
|
|
2017-05-04 02:15:47 +02:00
|
|
|
cmd := Command(ctx, config, "ninja", executable, args...)
|
2020-11-17 12:52:28 +01:00
|
|
|
|
|
|
|
// Set up the nsjail sandbox Ninja runs in.
|
2019-01-02 21:24:44 +01:00
|
|
|
cmd.Sandbox = ninjaSandbox
|
2017-08-05 00:06:27 +02:00
|
|
|
if config.HasKatiSuffix() {
|
2020-11-17 12:52:28 +01:00
|
|
|
// Reads and executes a shell script from Kati that sets/unsets the
|
|
|
|
// environment Ninja runs in.
|
2017-08-05 00:06:27 +02:00
|
|
|
cmd.Environment.AppendFromKati(config.KatiEnvFile())
|
|
|
|
}
|
Add a Go replacement for our top-level Make wrapper
Right now this mostly just copies what Make is doing in
build/core/ninja.mk and build/core/soong.mk. The only major feature it
adds is a rotating log file with some verbose logging.
There is one major functional difference -- you cannot override random
Make variables during the Make phase anymore. The environment variable
is set, and if Make uses ?= or the equivalent, it can still use those
variables. We already made this change for Kati, which also loads all of
the same code and actually does the build, so it has been half-removed
for a while.
The only "UI" this implements is what I'll call "Make Emulation" mode --
it's expected that current command lines will continue working, and
we'll explore alternate user interfaces later.
We're still using Make as a wrapper, but all it does is call into this
single Go program, it won't even load the product configuration. Once
this is default, we can start moving individual users over to using this
directly (still in Make emulation mode), skipping the Make wrapper.
Ideas for the future:
* Generating trace files showing time spent in Make/Kati/Soong/Ninja
(also importing ninja traces into the same stream). I had this working
in a previous version of this patch, but removed it to keep the size
down and focus on the current features.
* More intelligent SIGALRM handling, once we fully remove the Make
wrapper (which hides the SIGALRM)
* Reading the experimental binary output stream from Ninja, so that we
can always save the verbose log even if we're not printing it out to
the console
Test: USE_SOONG_UI=true m -j blueprint_tools
Change-Id: I884327b9a8ae24499eb6c56f6e1ad26df1cfa4e4
2016-08-22 00:17:17 +02:00
|
|
|
|
2023-03-14 16:10:45 +01:00
|
|
|
switch config.NinjaWeightListSource() {
|
|
|
|
case NINJA_LOG:
|
2023-05-19 17:49:39 +02:00
|
|
|
cmd.Args = append(cmd.Args, "-o", "usesninjalogasweightlist=yes")
|
2023-03-14 16:10:45 +01:00
|
|
|
case EVENLY_DISTRIBUTED:
|
|
|
|
// pass empty weight list means ninja considers every tasks's weight as 1(default value).
|
|
|
|
cmd.Args = append(cmd.Args, "-o", "usesweightlist=/dev/null")
|
2023-03-18 16:12:39 +01:00
|
|
|
case EXTERNAL_FILE:
|
2023-03-18 16:12:39 +01:00
|
|
|
fallthrough
|
|
|
|
case HINT_FROM_SOONG:
|
|
|
|
// The weight list is already copied/generated.
|
2023-03-18 16:12:39 +01:00
|
|
|
ninjaWeightListPath := filepath.Join(config.OutDir(), ninjaWeightListFileName)
|
|
|
|
cmd.Args = append(cmd.Args, "-o", "usesweightlist="+ninjaWeightListPath)
|
2023-03-14 16:10:45 +01:00
|
|
|
}
|
|
|
|
|
Add a Go replacement for our top-level Make wrapper
Right now this mostly just copies what Make is doing in
build/core/ninja.mk and build/core/soong.mk. The only major feature it
adds is a rotating log file with some verbose logging.
There is one major functional difference -- you cannot override random
Make variables during the Make phase anymore. The environment variable
is set, and if Make uses ?= or the equivalent, it can still use those
variables. We already made this change for Kati, which also loads all of
the same code and actually does the build, so it has been half-removed
for a while.
The only "UI" this implements is what I'll call "Make Emulation" mode --
it's expected that current command lines will continue working, and
we'll explore alternate user interfaces later.
We're still using Make as a wrapper, but all it does is call into this
single Go program, it won't even load the product configuration. Once
this is default, we can start moving individual users over to using this
directly (still in Make emulation mode), skipping the Make wrapper.
Ideas for the future:
* Generating trace files showing time spent in Make/Kati/Soong/Ninja
(also importing ninja traces into the same stream). I had this working
in a previous version of this patch, but removed it to keep the size
down and focus on the current features.
* More intelligent SIGALRM handling, once we fully remove the Make
wrapper (which hides the SIGALRM)
* Reading the experimental binary output stream from Ninja, so that we
can always save the verbose log even if we're not printing it out to
the console
Test: USE_SOONG_UI=true m -j blueprint_tools
Change-Id: I884327b9a8ae24499eb6c56f6e1ad26df1cfa4e4
2016-08-22 00:17:17 +02:00
|
|
|
// Allow both NINJA_ARGS and NINJA_EXTRA_ARGS, since both have been
|
|
|
|
// used in the past to specify extra ninja arguments.
|
2017-05-04 02:15:47 +02:00
|
|
|
if extra, ok := cmd.Environment.Get("NINJA_ARGS"); ok {
|
|
|
|
cmd.Args = append(cmd.Args, strings.Fields(extra)...)
|
Add a Go replacement for our top-level Make wrapper
Right now this mostly just copies what Make is doing in
build/core/ninja.mk and build/core/soong.mk. The only major feature it
adds is a rotating log file with some verbose logging.
There is one major functional difference -- you cannot override random
Make variables during the Make phase anymore. The environment variable
is set, and if Make uses ?= or the equivalent, it can still use those
variables. We already made this change for Kati, which also loads all of
the same code and actually does the build, so it has been half-removed
for a while.
The only "UI" this implements is what I'll call "Make Emulation" mode --
it's expected that current command lines will continue working, and
we'll explore alternate user interfaces later.
We're still using Make as a wrapper, but all it does is call into this
single Go program, it won't even load the product configuration. Once
this is default, we can start moving individual users over to using this
directly (still in Make emulation mode), skipping the Make wrapper.
Ideas for the future:
* Generating trace files showing time spent in Make/Kati/Soong/Ninja
(also importing ninja traces into the same stream). I had this working
in a previous version of this patch, but removed it to keep the size
down and focus on the current features.
* More intelligent SIGALRM handling, once we fully remove the Make
wrapper (which hides the SIGALRM)
* Reading the experimental binary output stream from Ninja, so that we
can always save the verbose log even if we're not printing it out to
the console
Test: USE_SOONG_UI=true m -j blueprint_tools
Change-Id: I884327b9a8ae24499eb6c56f6e1ad26df1cfa4e4
2016-08-22 00:17:17 +02:00
|
|
|
}
|
2017-05-04 02:15:47 +02:00
|
|
|
if extra, ok := cmd.Environment.Get("NINJA_EXTRA_ARGS"); ok {
|
|
|
|
cmd.Args = append(cmd.Args, strings.Fields(extra)...)
|
Add a Go replacement for our top-level Make wrapper
Right now this mostly just copies what Make is doing in
build/core/ninja.mk and build/core/soong.mk. The only major feature it
adds is a rotating log file with some verbose logging.
There is one major functional difference -- you cannot override random
Make variables during the Make phase anymore. The environment variable
is set, and if Make uses ?= or the equivalent, it can still use those
variables. We already made this change for Kati, which also loads all of
the same code and actually does the build, so it has been half-removed
for a while.
The only "UI" this implements is what I'll call "Make Emulation" mode --
it's expected that current command lines will continue working, and
we'll explore alternate user interfaces later.
We're still using Make as a wrapper, but all it does is call into this
single Go program, it won't even load the product configuration. Once
this is default, we can start moving individual users over to using this
directly (still in Make emulation mode), skipping the Make wrapper.
Ideas for the future:
* Generating trace files showing time spent in Make/Kati/Soong/Ninja
(also importing ninja traces into the same stream). I had this working
in a previous version of this patch, but removed it to keep the size
down and focus on the current features.
* More intelligent SIGALRM handling, once we fully remove the Make
wrapper (which hides the SIGALRM)
* Reading the experimental binary output stream from Ninja, so that we
can always save the verbose log even if we're not printing it out to
the console
Test: USE_SOONG_UI=true m -j blueprint_tools
Change-Id: I884327b9a8ae24499eb6c56f6e1ad26df1cfa4e4
2016-08-22 00:17:17 +02:00
|
|
|
}
|
|
|
|
|
2017-05-26 00:44:36 +02:00
|
|
|
ninjaHeartbeatDuration := time.Minute * 5
|
2020-11-17 12:52:28 +01:00
|
|
|
// Get the ninja heartbeat interval from the environment before it's filtered away later.
|
2017-05-26 00:44:36 +02:00
|
|
|
if overrideText, ok := cmd.Environment.Get("NINJA_HEARTBEAT_INTERVAL"); ok {
|
|
|
|
// For example, "1m"
|
|
|
|
overrideDuration, err := time.ParseDuration(overrideText)
|
|
|
|
if err == nil && overrideDuration.Seconds() > 0 {
|
|
|
|
ninjaHeartbeatDuration = overrideDuration
|
|
|
|
}
|
|
|
|
}
|
2020-01-03 04:10:38 +01:00
|
|
|
|
2020-11-17 12:52:28 +01:00
|
|
|
// Filter the environment, as ninja does not rebuild files when environment
|
|
|
|
// variables change.
|
2020-01-03 04:10:38 +01:00
|
|
|
//
|
2020-11-17 12:52:28 +01:00
|
|
|
// Anything listed here must not change the output of rules/actions when the
|
|
|
|
// value changes, otherwise incremental builds may be unsafe. Vars
|
|
|
|
// explicitly set to stable values elsewhere in soong_ui are fine.
|
2020-01-03 04:10:38 +01:00
|
|
|
//
|
2020-11-17 12:52:28 +01:00
|
|
|
// For the majority of cases, either Soong or the makefiles should be
|
|
|
|
// replicating any necessary environment variables in the command line of
|
|
|
|
// each action that needs it.
|
2020-01-03 05:12:09 +01:00
|
|
|
if cmd.Environment.IsEnvTrue("ALLOW_NINJA_ENV") {
|
|
|
|
ctx.Println("Allowing all environment variables during ninja; incremental builds may be unsafe.")
|
|
|
|
} else {
|
2020-01-03 04:10:38 +01:00
|
|
|
cmd.Environment.Allow(append([]string{
|
2020-11-17 12:52:28 +01:00
|
|
|
// Set the path to a symbolizer (e.g. llvm-symbolizer) so ASAN-based
|
|
|
|
// tools can symbolize crashes.
|
2020-01-03 04:10:38 +01:00
|
|
|
"ASAN_SYMBOLIZER_PATH",
|
|
|
|
"HOME",
|
|
|
|
"JAVA_HOME",
|
|
|
|
"LANG",
|
|
|
|
"LC_MESSAGES",
|
|
|
|
"OUT_DIR",
|
|
|
|
"PATH",
|
|
|
|
"PWD",
|
2020-11-17 12:52:28 +01:00
|
|
|
// https://docs.python.org/3/using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE
|
2020-01-03 04:10:38 +01:00
|
|
|
"PYTHONDONTWRITEBYTECODE",
|
|
|
|
"TMPDIR",
|
|
|
|
"USER",
|
|
|
|
|
|
|
|
// TODO: remove these carefully
|
2020-11-17 12:52:28 +01:00
|
|
|
// Options for the address sanitizer.
|
2020-01-04 22:58:54 +01:00
|
|
|
"ASAN_OPTIONS",
|
2020-11-17 12:52:28 +01:00
|
|
|
// The list of Android app modules to be built in an unbundled manner.
|
2020-01-03 04:10:38 +01:00
|
|
|
"TARGET_BUILD_APPS",
|
2020-11-17 12:52:28 +01:00
|
|
|
// The variant of the product being built. e.g. eng, userdebug, debug.
|
2020-01-03 04:10:38 +01:00
|
|
|
"TARGET_BUILD_VARIANT",
|
2020-11-17 12:52:28 +01:00
|
|
|
// The product name of the product being built, e.g. aosp_arm, aosp_flame.
|
2020-01-03 04:10:38 +01:00
|
|
|
"TARGET_PRODUCT",
|
2020-01-06 21:25:40 +01:00
|
|
|
// b/147197813 - used by art-check-debug-apex-gen
|
|
|
|
"EMMA_INSTRUMENT_FRAMEWORK",
|
2020-01-03 04:10:38 +01:00
|
|
|
|
|
|
|
// RBE client
|
2020-03-20 01:04:13 +01:00
|
|
|
"RBE_compare",
|
2022-01-20 20:00:58 +01:00
|
|
|
"RBE_num_local_reruns",
|
|
|
|
"RBE_num_remote_reruns",
|
2020-03-20 01:04:13 +01:00
|
|
|
"RBE_exec_root",
|
|
|
|
"RBE_exec_strategy",
|
|
|
|
"RBE_invocation_id",
|
|
|
|
"RBE_log_dir",
|
2021-03-17 19:19:27 +01:00
|
|
|
"RBE_num_retries_if_mismatched",
|
2020-03-20 01:04:13 +01:00
|
|
|
"RBE_platform",
|
|
|
|
"RBE_remote_accept_cache",
|
|
|
|
"RBE_remote_update_cache",
|
|
|
|
"RBE_server_address",
|
|
|
|
// TODO: remove old FLAG_ variables.
|
2020-01-09 17:52:59 +01:00
|
|
|
"FLAG_compare",
|
2020-01-03 04:10:38 +01:00
|
|
|
"FLAG_exec_root",
|
|
|
|
"FLAG_exec_strategy",
|
|
|
|
"FLAG_invocation_id",
|
|
|
|
"FLAG_log_dir",
|
|
|
|
"FLAG_platform",
|
2020-01-28 19:48:46 +01:00
|
|
|
"FLAG_remote_accept_cache",
|
|
|
|
"FLAG_remote_update_cache",
|
2020-01-03 04:10:38 +01:00
|
|
|
"FLAG_server_address",
|
|
|
|
|
|
|
|
// ccache settings
|
|
|
|
"CCACHE_COMPILERCHECK",
|
|
|
|
"CCACHE_SLOPPINESS",
|
|
|
|
"CCACHE_BASEDIR",
|
|
|
|
"CCACHE_CPP2",
|
2020-02-04 15:59:37 +01:00
|
|
|
"CCACHE_DIR",
|
2022-04-17 09:01:06 +02:00
|
|
|
|
|
|
|
// LLVM compiler wrapper options
|
|
|
|
"TOOLCHAIN_RUSAGE_OUTPUT",
|
2023-09-06 02:48:11 +02:00
|
|
|
|
|
|
|
// We don't want this build broken flag to cause reanalysis, so allow it through to the
|
|
|
|
// actions.
|
|
|
|
"BUILD_BROKEN_INCORRECT_PARTITION_IMAGES",
|
2020-01-03 04:10:38 +01:00
|
|
|
}, config.BuildBrokenNinjaUsesEnvVars()...)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Environment.Set("DIST_DIR", config.DistDir())
|
|
|
|
cmd.Environment.Set("SHELL", "/bin/bash")
|
|
|
|
|
2020-11-17 12:52:28 +01:00
|
|
|
// Print the environment variables that Ninja is operating in.
|
2020-01-03 04:10:38 +01:00
|
|
|
ctx.Verboseln("Ninja environment: ")
|
|
|
|
envVars := cmd.Environment.Environ()
|
|
|
|
sort.Strings(envVars)
|
|
|
|
for _, envVar := range envVars {
|
|
|
|
ctx.Verbosef(" %s", envVar)
|
|
|
|
}
|
|
|
|
|
2023-02-16 19:31:43 +01:00
|
|
|
// Write the env vars available during ninja execution to a file
|
|
|
|
ninjaEnvVars := cmd.Environment.AsMap()
|
|
|
|
data, err := shared.EnvFileContents(ninjaEnvVars)
|
|
|
|
if err != nil {
|
|
|
|
ctx.Panicf("Could not parse environment variables for ninja run %s", err)
|
|
|
|
}
|
|
|
|
// Write the file in every single run. This is fine because
|
|
|
|
// 1. It is not a dep of Soong analysis, so will not retrigger Soong analysis.
|
|
|
|
// 2. Is is fairly lightweight (~1Kb)
|
|
|
|
ninjaEnvVarsFile := shared.JoinPath(config.SoongOutDir(), ninjaEnvFileName)
|
|
|
|
err = os.WriteFile(ninjaEnvVarsFile, data, 0666)
|
|
|
|
if err != nil {
|
|
|
|
ctx.Panicf("Could not write ninja environment file %s", err)
|
|
|
|
}
|
|
|
|
|
2020-11-17 12:52:28 +01:00
|
|
|
// Poll the Ninja log for updates regularly based on the heartbeat
|
|
|
|
// frequency. If it isn't updated enough, then we want to surface the
|
|
|
|
// possibility that Ninja is stuck, to the user.
|
2017-06-13 21:51:50 +02:00
|
|
|
done := make(chan struct{})
|
|
|
|
defer close(done)
|
|
|
|
ticker := time.NewTicker(ninjaHeartbeatDuration)
|
|
|
|
defer ticker.Stop()
|
2020-11-17 12:52:28 +01:00
|
|
|
ninjaChecker := &ninjaStucknessChecker{
|
2023-03-16 17:53:11 +01:00
|
|
|
logPath: filepath.Join(config.OutDir(), ninjaLogFileName),
|
2020-11-17 12:52:28 +01:00
|
|
|
}
|
2017-05-26 00:44:36 +02:00
|
|
|
go func() {
|
2017-06-13 21:51:50 +02:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ticker.C:
|
2020-11-17 12:52:28 +01:00
|
|
|
ninjaChecker.check(ctx, config)
|
2017-06-13 21:51:50 +02:00
|
|
|
case <-done:
|
|
|
|
return
|
|
|
|
}
|
2017-05-26 00:44:36 +02:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2019-01-02 21:50:49 +01:00
|
|
|
ctx.Status.Status("Starting ninja...")
|
2019-06-19 22:17:59 +02:00
|
|
|
cmd.RunAndStreamOrFatal()
|
Add a Go replacement for our top-level Make wrapper
Right now this mostly just copies what Make is doing in
build/core/ninja.mk and build/core/soong.mk. The only major feature it
adds is a rotating log file with some verbose logging.
There is one major functional difference -- you cannot override random
Make variables during the Make phase anymore. The environment variable
is set, and if Make uses ?= or the equivalent, it can still use those
variables. We already made this change for Kati, which also loads all of
the same code and actually does the build, so it has been half-removed
for a while.
The only "UI" this implements is what I'll call "Make Emulation" mode --
it's expected that current command lines will continue working, and
we'll explore alternate user interfaces later.
We're still using Make as a wrapper, but all it does is call into this
single Go program, it won't even load the product configuration. Once
this is default, we can start moving individual users over to using this
directly (still in Make emulation mode), skipping the Make wrapper.
Ideas for the future:
* Generating trace files showing time spent in Make/Kati/Soong/Ninja
(also importing ninja traces into the same stream). I had this working
in a previous version of this patch, but removed it to keep the size
down and focus on the current features.
* More intelligent SIGALRM handling, once we fully remove the Make
wrapper (which hides the SIGALRM)
* Reading the experimental binary output stream from Ninja, so that we
can always save the verbose log even if we're not printing it out to
the console
Test: USE_SOONG_UI=true m -j blueprint_tools
Change-Id: I884327b9a8ae24499eb6c56f6e1ad26df1cfa4e4
2016-08-22 00:17:17 +02:00
|
|
|
}
|
2017-05-26 00:44:36 +02:00
|
|
|
|
2020-11-17 12:52:28 +01:00
|
|
|
// A simple struct for checking if Ninja gets stuck, using timestamps.
|
|
|
|
type ninjaStucknessChecker struct {
|
|
|
|
logPath string
|
|
|
|
prevModTime time.Time
|
2017-05-26 00:44:36 +02:00
|
|
|
}
|
|
|
|
|
2020-11-17 12:52:28 +01:00
|
|
|
// Check that a file has been modified since the last time it was checked. If
|
|
|
|
// the mod time hasn't changed, then assume that Ninja got stuck, and print
|
|
|
|
// diagnostics for debugging.
|
|
|
|
func (c *ninjaStucknessChecker) check(ctx Context, config Config) {
|
|
|
|
info, err := os.Stat(c.logPath)
|
|
|
|
var newModTime time.Time
|
2017-05-26 00:44:36 +02:00
|
|
|
if err == nil {
|
2020-11-17 12:52:28 +01:00
|
|
|
newModTime = info.ModTime()
|
2017-05-26 00:44:36 +02:00
|
|
|
}
|
2020-11-17 12:52:28 +01:00
|
|
|
if newModTime == c.prevModTime {
|
|
|
|
// The Ninja file hasn't been modified since the last time it was
|
|
|
|
// checked, so Ninja could be stuck. Output some diagnostics.
|
|
|
|
ctx.Verbosef("ninja may be stuck; last update to %v was %v. dumping process tree...", c.logPath, newModTime)
|
2024-01-05 23:03:27 +01:00
|
|
|
ctx.Printf("ninja may be stuck, check %v for list of running processes.",
|
|
|
|
filepath.Join(config.LogsDir(), config.logsPrefix+"soong.log"))
|
2017-05-26 00:44:36 +02:00
|
|
|
|
2020-11-17 12:52:28 +01:00
|
|
|
// The "pstree" command doesn't exist on Mac, but "pstree" on Linux
|
|
|
|
// gives more convenient output than "ps" So, we try pstree first, and
|
|
|
|
// ps second
|
2024-01-05 23:03:27 +01:00
|
|
|
commandText := fmt.Sprintf("pstree -palT %v || ps -ef", os.Getpid())
|
2017-05-26 00:44:36 +02:00
|
|
|
|
2020-11-17 12:52:28 +01:00
|
|
|
cmd := Command(ctx, config, "dump process tree", "bash", "-c", commandText)
|
|
|
|
output := cmd.CombinedOutputOrFatal()
|
|
|
|
ctx.Verbose(string(output))
|
2017-05-26 00:44:36 +02:00
|
|
|
|
2020-11-17 12:52:28 +01:00
|
|
|
ctx.Verbosef("done\n")
|
|
|
|
}
|
|
|
|
c.prevModTime = newModTime
|
2017-05-26 00:44:36 +02:00
|
|
|
}
|