Commit Graph

43 Commits

Author SHA1 Message Date
Colin Cross 27027c765e Optimize FirstUniqueStrings and FirstUniquePaths
FirstUniquePaths is called on some long lists where the O(n^2)
behavior is problematic.  Use a map-based implementation for
longer lists.

Test: TestFirstUniqueStrings
Change-Id: I7181aba869e5ccc0f99c2fa7b8f03839f06e4307
2020-03-02 15:00:15 -08:00
Colin Cross 6e3594003b Add InstallForceOS, fix testcases for host
Robolectric tests compile against device modules but are installed
and run as host modules.  Allow a module to override its install
OS.

Test: TestPathForModuleInstall
Change-Id: Icf37bb3d4cc1222a9b079602c6a5fdb8b51c86ed
2020-02-19 20:41:22 +00:00
Yifan Hong 1b3348d50a Add ramdisk image.
It is similar to recovery image.
Test: m nothing -j

Change-Id: I11389777c6bfb0c0d73bbb4c70091c1e70f44077
2020-01-22 16:54:18 -08:00
Colin Cross 988414c2cf Sandbox soong_build by changing to root directory
This relands I12a0f907753fefd1997ab8b4ea2ac331234093cf along with
a fix to blueprint for absolute paths.

Store the current working directory and then change to the root
directory so that all file accesses must go through helpers in
the android package that properly track dependencies.

Change-Id: I24ac485677aa102eec1a2521d16820da6ee1ae77
Fixes: 146437378
Test: m checkbuild
Test: m OUT_DIR=/tmp/out nothing
2020-01-11 01:11:46 +00:00
Colin Cross 47e4f9e1e8 Revert "Sandbox soong_build by changing to root directory"
This reverts commit 05c25ccb4a.

Reason for revert: broke absolute OUT_DIR
Bug: 146437378

Change-Id: I523ed79d40e1c1ef040212ba794a7a084abea75d
2020-01-10 18:51:04 +00:00
Colin Cross 05c25ccb4a Sandbox soong_build by changing to root directory
Store the current working directory and then change to the root
directory so that all file accesses must go through helpers in
the android package that properly track dependencies.

Fixes: 146437378
Test: m checkbuild
Change-Id: I12a0f907753fefd1997ab8b4ea2ac331234093cf
2020-01-09 14:19:46 -08:00
Colin Cross 1184b647d5 Add EarlyModuleContext for LoadHookContext
Make LoadHookContext embed a new EarlyModuleContext instead of
BaseModuleContext to reduce its API surface in preparation for
moving it to run during parsing instead of mutators.

Test: m checkbuild
Change-Id: I1cd3ff3b636e7e24991a9184d7521903473e505a
2020-01-04 08:40:55 -08:00
Colin Cross 98be1bb00f Move filesystem into Config
The filesystem object was available through ModuleContext.Fs(), but
gives too much access to the filesystem without enforicing correct
dependencies.  In order to support sandboxing the soong_build
process move the filesystem into the Config.  The next change will
make it private.

Bug: 146437378
Test: all Soong tests
Change-Id: I5d3ae9108f120fd335b21efd612aefa078378813
2019-12-18 08:19:10 -08:00
Colin Cross fb0c16e95a Move imageMutator before archMutator
Run the imageMutator between osMutator and archMutator so that
different arch variants can be set for the different partitions.

Bug: 142286466
Test: m checkbuild
Change-Id: I65d05714b75aa462bf9816da60fdc2deda4de593
Merged-In: I65d05714b75aa462bf9816da60fdc2deda4de593
(cherry picked from commit 9c8f687584)
2019-12-17 14:45:11 -08:00
Colin Cross 4b49b768a2 Make TestContext.RegisterModuleType take an android.ModuleFactory
Avoid having to pass ModuleFactoryAdaptor to every call to
RegisterModuleType in a test by wrapping RegisterModuleType.

Test: all soong tests
Change-Id: If8847d16487de0479cc3020b728256922b3cadba
2019-11-25 10:59:44 -08:00
Colin Cross 90ba5f4e98 Add InstallInRoot to allow modules to install into root partition
If InstallInRoot() returns true the module will be installed to
$OUT/root or $OUT/recovery/root.

Bug: 141877526
Test: m checkbuild
Test: no change to build.ninja or Android-${TARGET_PRODUCT}.mk
Test: TestPathForModuleInstall
Change-Id: Id6e435c6019f11eeb5806528fd464dbf220b88d9
2019-10-03 10:07:46 -07:00
Jaewoong Jung 0949f31657 Fix android_test install path.
Test: m nothing + diff soong mk and ninja files.
Bug: 140795853
Change-Id: I3667eac951dea7e447cf73219ff89199fca9ed63
2019-09-27 16:42:20 -07:00
Colin Cross 607d8587e4 Add InstallBypassMake
Allow modules to mark themselves as InstallBypassMake, which will
cause android.PathForModuleInstall to return a path in $OUT_DIR
instead of $OUT_DIR/soong.  This can be used for modules that
can handle installation to the final location on their own.  The
main blocker for most modules is support for the "required" property,
which requires adding dependencies on the installed location of
other modules.

Bug: 122332855
Test: m checkbuild
Change-Id: I85238d937ff30335167d4b3fec79bbefc734b5e1
2019-08-06 09:45:04 -07:00
Justin Yun d5f6c8261a Rename product_services to system_ext
Bug: 134359158
Test: build and check if system_ext.img is created
Change-Id: Ice3229baf97a94c24a6eea22e7d4571941d7f843
2019-07-09 08:57:05 +00:00
Colin Cross 2ffb9a8d7d Share buildDir for android/soong/android tests
There is no need to create a separate buildDir for each test
file, use TestMain to create a global one for the package.

Test: all soong tests
Change-Id: I435ee7aa88b7e0bb8ccc1ba79f82833a7accf3e9
2019-06-10 15:51:06 -07:00
Colin Cross 6c4f21f3a1 Reimplement AddMissingDependencies
AddMissingDependencies is needed in BaseModuleContext in order
to allow PathsForModuleSrc and friends to be called in mutators,
It's not a simple move, as it currently writes to a module
field that would be lost if any mutators cloned new variants
by calling CreateVariations.  Reimplement it using a mutated
property instead.

Test: m checkbuild
Change-Id: I851125065e4c5302b552773dae4640426c62965e
2019-06-10 15:51:06 -07:00
Colin Cross 0ea8ba82fc Consolidate baseContext, BaseContext, and BaseModuleContext
blueprint.BaseModuleContext is the set of methods available to all
module-specific calls (GenerateBuildActions or mutators).  The
android package split the same functionality across baseContext (nee
androidBaseContext), BaseModuleContext, and BaseContext.
Consolidate all of them into android.BaseModuleContext.

Test: m checkbuild
Change-Id: I2d7f5c56fd4424032cb93edff6dc730ff33e4f1e
2019-06-06 20:01:31 -07:00
Colin Cross 25de6c30d3 Remove repetition in android package names
Types in the android package don't need to be prefixed with 'android'.

Test: m checkbuild
Change-Id: Ieefcfc1a2c4161d9c412f40ef31867149ec21aec
2019-06-06 17:24:01 -07:00
Colin Cross 41955e8895 Support tagged module references
There are cases where a module needs to refer to an intermediate
output of another module instead of its final output.  For example,
a module may want to use the .jar containing .class files from
another module whose final output is a .jar containing classes.dex
files.  Support a new ":module{.tag}" format in any property that
is annotated with `android:"path"`, which will query the target
module for its ".tag" output(s).

Test: path_properties_test.go, paths_test.go
Test: no unexpected changes in build.ninja
Change-Id: Icd3c9b0d83ff125771767c04046fcffb9fc3f65a
2019-06-04 10:22:51 -07:00
Colin Cross ba71a3fb11 Fix missing genrule srcs and tools with ALLOW_MISSING_DEPENDENCIES=true
Set the location label for missing srcs and tools to avoid
nonsensical errors when parsing the command.

Test: genrule_test.go
Test: paths_test.go
Test: unbundled branch with missing framework-res module needed by robolectric genrule
Change-Id: I9c1f1cd82a80f048c0e903b8e93910b1ae34b0b1
2019-04-07 19:40:02 +00:00
Colin Cross 8a49795df1 Replace ctx.ExpandSources with android.PathsForModuleSrc
Move the logic from ctx.ExpandSources into android.PathsForModuleSrc
and ctx.ExpandSource into android.PathForModuleSrc, and deprecate
them.  When combined with the pathDepsMutator this will let all
properties that take source paths also take filegroups or genrule
outputs, as long as they are tagged with `android:"path"`.

Test: All soong tests
Change-Id: I01625e76b5da19240e9649bf26a014eeeafcab8f
2019-03-20 19:36:13 +00:00
Colin Cross 07e51619a2 Remove ModuleSrcPath
ModuleSrcPath was designed as a type that ensured that modules only
referenced sources inside the directory that contained the Android.bp
file.  In practice they don't work very well, because allowing
filegroups and genrules as inputs to any module that takes a source
path means that the path might end up being to a file in another
source directory or to a generated file in the output directory.

Remove ModuleSrcPath, replacing it with SourcePath in the places
that need to explicitly refer to a path in the source tree, or
Path where it may be a source path or a generated path.

Make PathForModuleSrc return a Path instead of a SourcePath in
preparation for consolidation with ctx.ExpandSources, which will
make it possibly return paths to generated files.

Test: All soong tests
Change-Id: I973a78470ed14307eea5f6d0cc93942775a65715
2019-03-20 19:36:03 +00:00
Colin Cross 937664a50a Add test for ctx.ExpandSources
Test: TestExpandSources
Change-Id: Ib2168b00618a45b2a36c4b158c6c02c4727a960b
2019-03-07 18:36:46 +00:00
Colin Cross 2cdd5df7cc Fix Rel() after ReplaceExtension or InSameDir
Copying p.rel doesn't work, as rel needs to match the end of the
value in path.  Apply the same transformation to p.rel as p.path.

Test: paths_test.go
Change-Id: I42d676c6c4fc18d9852c1a73f25e5a791d7553d0
2019-02-27 20:23:25 +00:00
Colin Cross 40e3373d41 Add more paths helper methods
Add PathsForOutput to convert multiple strings into WritablePaths.

Add OutputPath.InSameDir to build a new OutputPath pointing to a
file in the same directory as an existing OutputPath.

Add WritablePathForTesting and WritablePathsForTesting that mirror
PathForTesting and PathsForTesting but return WritablePaths.

Add PathContextForTesting to return a minimal PathContext
implementation.

Test: paths_test.go
Change-Id: I9708eb164b273514a96dae0a260ef9a963fb9bcf
2019-02-16 17:08:07 -08:00
Colin Cross 8854a5a805 Add OutputPath.ReplaceExtension()
Add a helper method that returns a new OutputPath with the
extension replaced.

Test: paths_test.go
Change-Id: I7f93b3475031a19b53652022740488373a1b7d97
2019-02-12 17:07:35 -08:00
Colin Cross 7b3dcc31eb Avoid filepath.Abs
filepath.Abs is surprisingly expensive, it calls os.Getwd every
time, which involves multiple syscalls, a lock, and and allocations.
Use IsAbs and prefix matching instead.

Test: paths_test.go
Change-Id: Ia6cf34d6bef24c694702af1e7a6ff08ffd2d822b
2019-01-24 21:35:16 +00:00
Colin Cross 43f08db29e Dexpreopt soong modules inside soong
Port the dexpreopt logic from Make to the dexpreopt package in Soong,
and use it to dexpreopt Soong modules.  The same package is also
compiled into the dexpreopt_gen binary to generate dexpreopt scripts
for Make modules.

This relands Ib67e2febf9ed921f06e8a86b9ec945c80dff35eb and
I462182638bd57b1367b5bfb0718e975c11ae66f7, along with multiple fixes
to depsfile generation in dexpreopt_gen that caused .odex files for
modules in defined make to be missing dependencies on boot.art, and
a fix to not dexpreopt and strip tests.

Bug: 119412419
Bug: 120273280
Test: no differences to dexpreopt outputs on aosp_sailfish system/,
      only expected changes to dexpreopt outputs on system_other
      (.vdex files for privileged Soong modules no longer incorrectly
      contain .dex contents).
Test: OUT_DIR=$PWD/out m
Test: NINJA_ARGS="-t deps out/target/product/sailfish/obj/APPS/Contacts_intermediates/dexpreopt.zip" m
Change-Id: I6bb2c971cee65d2338839753aa0d84939f335b1b
2018-12-15 19:07:54 -08:00
Colin Cross 359e6436be Revert "Fix MaybeRel when OUT is absolute"
This reverts commit fee2bff77c.

Test: none
Bug: 119412419
2018-12-14 11:49:58 -08:00
Colin Cross fee2bff77c Fix MaybeRel when OUT is absolute
MaybeRel was failing with an error when comparing an absolute out
path to a relative source path.  Make it return false instead, and
add tests.

Bug: 119412419
Test: paths_test.go
Change-Id: I462182638bd57b1367b5bfb0718e975c11ae66f7
2018-12-13 21:05:18 +00:00
Dario Freni 95cf767918 s/product-services/product_services/g
Attempting to reduce the number of different spellings we have for
"product services" partition in the codebase.

Bug: 112431447
Test: m
Change-Id: I0a393a1d625e7ea3217d28735a4db709bce32395
Merged-In: I0a393a1d625e7ea3217d28735a4db709bce32395
2018-08-20 17:46:57 +00:00
Dario Freni fd05a74e06 Add support for /product-services partition
This is an adaptation of Icc4f8c16bc389fe20db680849f311d02df1299c3, to
support modules that are installed on the /product-services partition.

Bug: 80741439
Test: m -j both with and without enabling the new partition
Change-Id: I72b335ad38baff5848cd3da7489343f8cf98ff16
2018-07-19 14:04:30 +01:00
Jiyong Park f9332f1c86 Support recovery and recovery_available
`recovery: true` installs a module to the recovery partition.
`recovery_available: true` makes a module to be available to other
`recovery:true` or `recovery_available: true` modules.

These to are very similar to vendor, vendor_available properties, except
for the target partition.

Bug: 67916654
Bug: 64960723
Test: m -j, toybox_recovery is installed to the recovery/root/sbin
Change-Id: Iaebe0593de16c69fa70de251a61f4d018a251509
2018-05-15 16:27:12 +09:00
Colin Cross a140bb05f1 Reverse RRO dir paths when passing to Make
LOCAL_RESOURCE_DIRS puts the highest priority overlay first, but
aapt2 expects the highest priority overlay last.  Soong stores the
list in aapt2 order (low to high priority), but that means when it
exports to Make as LOCAL_SOONG_RRO_DIRS, which goes to
build_rro_package.mk and then package_internal.mk, it gets reversed
again and comes out backwards.

Bug: 78032566
Test: m checkbuild
Change-Id: If72bf929fbf1d126f9051a2f21ec1eb4e3030e6e
2018-04-17 10:53:54 -07:00
Colin Cross 1ccfcc36bd Propagate errors out of validatePath
The next patch will need to more complicated custom error handling,
so make validatePath return an error and let the caller handle it.

Test: paths_test.go
Change-Id: I4fe11c3f319303d779596709f4819e828b5bdb9b
2018-02-22 14:43:36 -08:00
Colin Cross dc75ae70f3 Add t.Run and t.Helper to paths_test.go
Test: paths_test.go
Change-Id: Iea2b07815fe82a346c5384571ebc2b57538722cc
2018-02-22 14:43:36 -08:00
Jaekyun Seok 5cfbfbb67a Use product instead of oem for Product specific module
Bug: 64195575
Test: succeeded building product.img with BOARD_PRODUCTIMAGE_PARTITION_SIZE,
BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE and PRODUCT_PRODUCT_VERITY_PARTITION.
Change-Id: Icc4f8c16bc389fe20db680849f311d02df1299c3
2018-01-25 07:50:35 +09:00
Jiyong Park 2db7692a74 Add [soc|device|product]_specific
Added three properties (soc_specific, device_specific, and
product_specific) that shows what a module is specific to.

`soc_specific: true` means that the module is specific to an SoC
(System-On-a-Chip) and thus need to be installed to vendor partition.
This has the same meaning as the old `vendor: true` setting.

`device_specific: true` means that the module is specific to the entire
hardware configuration of a device includeing the SoC and off-chip
peripherals. These modules are installed to odm partition (or /vendor/odm
when odm partition does not exist).

`product_specific: true` means that the module is specific to the
software configuration of a product such as country, network operator,
etc. These modules are installed to oem partition (or /system/oem when
oem partition does not exist). These modules are assumed to be agnostic
to hardware, so this property can't be true when either soc_specific or
device_specific is set to true.

Bug: 68187740
Test: Build. path_tests amended.
Change-Id: I44ff055d87d53b0d2676758c506060de54cbffa0
2017-12-21 12:16:29 +09:00
Colin Cross aabf67968c Make *Context.Config return a Config instead of a interface{}
In Soong, a Config() method will always return a Config.  Make
ModuleContext, SingletonContext, TopDownMutatorContext and
BottomUpMutatorContext's Config() methods explictly return
a Config to avoid having to type-assert everywhere.  Overriding
the Config method requires duplicating the list of methods in
blueprint.BaseModuleContext and blueprint.BottomUpMutatorContext,
following the same pattern used by the other *Contexts.

Config() obsoletes the AConfig() method used in some places, which
will be cleaned up in the next patch.

Test: m checkbuild
Change-Id: Ibe21efde933959811d52443496967ab8ce71215e
2017-11-30 00:44:11 +00:00
Colin Cross 5e6cfbead9 Add searchable android.DirectorySortedPaths
Add an android.DirectorySortedPaths that stores paths sorted such
that all paths in a directory including subdirectories are in a
contiguous subslice.  This will allow efficient O(log(N)) finding
of all paths in a directory using a binary search on the directory
prefix.

Test: TestDirectorySortedPaths in paths_test.go
Change-Id: I5a06a89351ae06e88c06526be54a6b79075361b7
2017-11-13 15:11:08 -08:00
Colin Cross 6ccbc913e4 Let tests override environment
Pass an environment to TestConfig that will be used for
all Config.Getenv calls.

Test: none
Change-Id: I683cd9c9e0db61c9bfd2adb27fca78f558f225c4
2017-10-10 23:28:43 -07:00
Dan Willemsen 00269f23ee Fix install location for vendor tests
These should be install in /data/nativetest* with the rest of the tests,
but had been moved to /vendor/nativetest* accidentally. Add some tests
so that this doesn't happen again.

Bug: 63393698
Test: m -j blueprint_tools
Test: compare out/soong/Android-aosp_arm64.mk
Test: compare out/soong/build.ninja
Change-Id: Id3b08a7e3908955df18a043a02ea576dc88086c3
2017-07-06 18:09:46 -07:00
Colin Cross 635c3b0157 Rename common to android
Rename the "common" package to "android", because common is too
generic.  Also removes all android.Android naming stutter.

Ran:
gomvpkg -from 'android/soong/common' -to 'android/soong/android'
gorename -from '"android/soong/android".AndroidModuleContext' -to 'ModuleContext'
gorename -from '"android/soong/android".AndroidBaseContext' -to 'BaseContext'
gorename -from '"android/soong/android".AndroidModuleBase' -to 'ModuleBase'
gorename -from '"android/soong/android".AndroidBottomUpMutatorContext' -to 'BottomUpMutatorContext'
gorename -from '"android/soong/android".AndroidTopDownMutatorContext' -to 'TopDownMutatorContext'
gorename -from '"android/soong/android".AndroidModule' -to 'Module'

Change-Id: I3b23590b8ce7c8a1ea1139411d84a53163288da7
2016-05-18 15:37:25 -07:00