2016-04-21 15:57:02 +03:00
/ *
* Copyright 2014 Xamarin Inc . All rights reserved .
*
* Authors :
* Rolf Bjarne Kvinge < rolf @xamarin . com >
*
* /
using System ;
[mtouch/mmp] Fix tracking of whether the static registrar should run again or not. Fixes #641. (#3534) (#3536)
* [tests] Improve debug spew for the RebuildTest_WithExtensions test.
* [mtouch/mmp] Store/load if the dynamic registrar is removed or not into the cached link results.
Store/load if the dynamic registrar is removed or not into the cached link
results, so that we generate the correct main.m even if cached linker results
are used.
* [mtouch/mmp] The static registrar must not execute if we're loading cached results from the linker.
The static registrar must not execute if we're loading cached results from the
linker, because the static registrar needs information from the linker that's
not restored from the cache.
* [mtouch/mmp] Share Touch code.
* [mtouch/mmp] Make it possible to touch inexistent files (to create them).
* [mtouch/mmp] Fix tracking of whether the static registrar should run again or not.
The recent changes to support optimizing away the dynamic registrar caused the
Xamarin.MTouch.RebuildTest_WithExtensions test to regress.
The problem
-----------
* The linker now collects and stores information the static registrar needs.
* This information is not restored from disk when the linker realizes that it
can reload previously linked assemblies instead of executing again.
* The static registrar runs again (for another reason).
* The information the static registrar needs isn't available, and incorrect
output follows.
So fix 1: show an error if the static registrar runs when the linker loaded
cached results.
The exact scenario the test ran into is this:
* 1st build: everything is new and everything is built.
* 2nd build: contents of .exe changes, the linker runs again, the static
registrar runs again, but sees that the generated output didn't change, so
it doesn't write the new content to disk (this is an optimization to avoid
compiling the registrar.m file again unless needed).
* 3rd build: only the .exe timestamp changes, the linker sees nothing changes
in the contents of the .exe and loads the previously linked assemblies from
disk, the static registrar sees that the .exe's timestamp is newer than
registrar.m's timestamp and run again, but doesn't produce the right result
because it doesn't have the information it needs.
Considered solutions
--------------------
1. Only track timestamps, not file contents. This is not ideal, since it will
result in more work done: in particular for the case above, it would add a
registrar.m compilation in build #2, and linker rerun + static registrar
rerun + registrar.m compilation + final native link in build #3.
2. Always write the output of the static registrar, even if it hasn't changed.
This is not ideal either, since it will also result in more work done: for
the case above, it would add a registrar.m compilation + final native link
in build #3.
3. Always write the output of the static registrar, but track if it changed or
not, and if it didn't, just touch registrar.o instead of recompiling it.
This only means the final native link in build #3 is added (see #5 for why
this is worse than it sounds).
4. Always write the output of the static registrar, but track it it changed or
not, and if it didn't, just touch registrar.o instead of recompiling it,
and track that too, so that the final native link in build #3 isn't needed
anymore. Unfortunately this may result in incorrect behavior, because now
the msbuild tasks will detect that the executable has changed, and may run
dsymutil + strip again. The executable didn't actually change, which means
it would be the previously stripped executable, and thus we'd end up with
an empty .dSYM because we ran dsymtil on an already stripped executable.
5. Idea #4, but write the output of the final link into a temporary directory
instead of the .app, so that we could track whether we should update the
executable in the .app or not. This is not optimal either, because
executables can be *big* (I've seen multi-GB tvOS bitcode executables), and
extra copies of such files should not be taken lightly.
6. Idea #4, but tell the MSBuild tasks that dsymutil/strip doesn't need to be
rerun even if the timestamp of the executable changed. This might actually
work, but now the solution's become quite complex.
Implemented solution
--------------------
Use stamp files to detect whether a file is up-to-date or not.
In particular:
* When we don't write to a file because the new contents are identical to the
old contents, we now touch a .stamp file. This stamp file means "the
accompanying file was determined to be up-to-date when the stamp was
touched."
* When checking whether a file is up-to-date, also check for the presence of a
.stamp file, and if it exists, use the highest timestamp between the stamp
file and the actual file.
Now the test scenario becomes:
* 1st build: everything is new and everything is built.
* 2nd build: contents of .exe changes, the linker runs again, the static
registrar runs again, but sees that the generated output didn't change, so
it doesn't write the new content to disk, but it creates a registrar.m.stamp
file to indicate the point in time when registrar.m was considered up-to-
date.
* 3rd build: only the .exe timestamp changes, the linker sees nothing changes
in the contents of the .exe and loads the previously linked assemblies from
disk, the static registrar sees that the .exe's timestamp is *older* than
registrar.m.stamp's timestamp and doesn't run again.
We only use the stamp file for source code (registrar.[m|h], main.[m|h],
pinvokes.[m|h]), since using it every time has too much potential for running
into other problems (for instance we should never create .stamp files inside
the .app).
Fixes these test failures:
1) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("single","",False,System.String[])
single
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory371/testApp.app/testApp is modified, timestamp: 2/15/2018 3:04:11 PM > 2/15/2018 3:04:09 PM" >
2) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("dual","armv7,arm64",False,System.String[])
dual
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory375/testApp.app/testApp is modified, timestamp: 2/15/2018 3:06:03 PM > 2/15/2018 3:06:00 PM" >
3) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("llvm","armv7+llvm",False,System.String[])
llvm
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory379/testApp.app/testApp is modified, timestamp: 2/15/2018 3:07:14 PM > 2/15/2018 3:07:12 PM" >
4) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("debug","",True,System.String[])
debug
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory383/testApp.app/testApp is modified, timestamp: 2/15/2018 3:08:16 PM > 2/15/2018 3:08:13 PM" >
5) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("single-framework","",False,System.String[])
single-framework
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory387/testApp.app/testApp is modified, timestamp: 2/15/2018 3:09:18 PM > 2/15/2018 3:09:16 PM" >
Fixes https://github.com/xamarin/maccore/issues/641
2018-02-20 13:43:23 +03:00
using System.Collections.Generic ;
2016-04-21 15:57:02 +03:00
using System.Diagnostics ;
2017-08-22 10:40:26 +03:00
using System.Globalization ;
2016-04-21 15:57:02 +03:00
using System.IO ;
using System.Linq ;
2020-08-06 12:01:06 +03:00
using System.Runtime.InteropServices ;
2016-04-21 15:57:02 +03:00
using System.Text ;
[mtouch] Rework how tasks are built.
The previous build system kept a forward-pointing single linked list of tasks
to execute: task X had a list of subsequent tasks to execute. If task X was
up-to-date, it was not created (and the next tasks were directly added to the
list of tasks to execute).
In this world it became complicated to merge output from tasks (for instance
if the output of task X and task Y should be a consumed by a single task
producing a single output, since the corresponding task would end up in both
X's and Y's list of subsequent tasks).
Example: creating a single framework from the aot-compiled output of multiple
assemblies.
So I've reversed the logic: now we keep track of the final output, and then
each task has a list of dependencies that must be built.
This makes it trivial to create merging tasks (for the previous example, there
could for instance be a CreateFrameworkTask, where its dependencies would be
all the corresponding AotTasks).
We also always create every task, and then each task decides when its executed
whether it should do anything or not. This makes it unnecessary to 'forward-
delete' files when creating tasks (say you have three tasks, A, B, C; B
depends on A, and C depends on B; if A's output isn't up-to-date, it has to
delete its own output if it exists, otherwise B would not detect that it would
have to re-execute, because at task *creation* time, B's input hadn't
changed).
Additionally make it based on async/await, since much of the work happens in
externel processes (and we don't need to spin up additional threads just to
run external processes). This makes us have less code run on background
threads, which makes any issues with thread-safety less likely.
2017-01-26 12:56:55 +03:00
using System.Threading.Tasks ;
2016-04-21 15:57:02 +03:00
2018-11-05 10:16:29 +03:00
using Xamarin.MacDev ;
2016-04-21 15:57:02 +03:00
using Xamarin.Utils ;
2018-02-05 18:26:29 +03:00
using ObjCRuntime ;
2016-04-21 15:57:02 +03:00
2020-05-19 16:30:38 +03:00
using Mono.Linker ;
2016-04-21 15:57:02 +03:00
namespace Xamarin.Bundler {
public partial class Driver {
2020-05-19 16:30:38 +03:00
public static bool Force { get ; set ; }
2020-10-22 21:57:49 +03:00
public static bool IsUnifiedFullXamMacFramework { get { return TargetFramework = = TargetFramework . Xamarin_Mac_4_5_Full ; } }
public static bool IsUnifiedFullSystemFramework { get { return TargetFramework = = TargetFramework . Xamarin_Mac_4_5_System ; } }
public static bool IsUnifiedMobile { get { return TargetFramework = = TargetFramework . Xamarin_Mac_2_0_Mobile ; } }
2021-06-16 11:19:02 +03:00
#if MMP
// We know that Xamarin.Mac apps won't compile unless the developer is using Xcode 12+: https://github.com/xamarin/xamarin-macios/issues/11937, so just set that as the min Xcode version.
static Version min_xcode_version = new Version ( 12 , 0 ) ;
#else
2020-08-06 12:11:10 +03:00
static Version min_xcode_version = new Version ( 6 , 0 ) ;
2021-06-16 11:19:02 +03:00
#endif
2020-07-17 17:38:40 +03:00
#if ! NET
2020-02-19 00:05:42 +03:00
public static int Main ( string [ ] args )
{
try {
2020-05-14 17:45:05 +03:00
#if MMP
ErrorHelper . Platform = ApplePlatform . MacOSX ;
#else
ErrorHelper . Platform = ApplePlatform . iOS ;
#endif
2020-02-19 00:05:42 +03:00
Console . OutputEncoding = new UTF8Encoding ( false , false ) ;
SetCurrentLanguage ( ) ;
return Main2 ( args ) ;
} catch ( Exception e ) {
ErrorHelper . Show ( e ) ;
} finally {
Watch ( "Total time" , 0 ) ;
}
return 0 ;
}
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
// Returns true if the process should exit (with a 0 exit code; failures are propagated using exceptions)
2022-10-11 23:36:58 +03:00
static bool ParseOptions ( Application app , Mono . Options . OptionSet options , string [ ] args , ref Action action )
2016-05-11 13:24:55 +03:00
{
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
Action a = Action . None ; // Need a temporary local variable, since anonymous functions can't write directly to ref/out arguments.
2020-09-08 21:26:28 +03:00
List < string > optimize = null ;
2020-09-15 19:33:18 +03:00
options . Add ( "h|?|help" , "Displays the help." , v = > a = Action . Help ) ;
options . Add ( "f|force" , "Forces the recompilation of code, regardless of timestamps." , v = > Force = true ) ;
options . Add ( "cache=" , "Specify the directory where temporary build files will be cached." , v = > app . Cache . Location = v ) ;
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
options . Add ( "version" , "Output version information and exit." , v = > a = Action . Version ) ;
2020-02-18 23:44:19 +03:00
options . Add ( "v|verbose" , "Specify how verbose the output should be. This can be passed multiple times to increase the verbosity." , v = > Verbosity + + ) ;
options . Add ( "q|quiet" , "Specify how quiet the output should be. This can be passed multiple times to increase the silence." , v = > Verbosity - - ) ;
2020-05-19 16:30:38 +03:00
options . Add ( "debug:" , "Build a debug app. If AOT-compiling, will also generate native debug code for the specified assembly (set to 'all' to generate debug code for all assemblies, the default is to generate debug code for user assemblies only)." , v = > {
app . EnableDebug = true ;
if ( v ! = null ) {
if ( v = = "all" ) {
app . DebugAll = true ;
return ;
}
app . DebugAssemblies . Add ( Path . GetFileName ( v ) ) ;
}
} ) ;
options . Add ( "reference=" , "Add an assembly to be processed." , v = > app . References . Add ( v ) ) ;
// Unfortunately -r is used in mmp for something else (--resource), which means we can't use the same arguments for both mtouch and mmp.
// So add --reference, which is now used by both (and accepted by bgen as well), and deprecate -r|--ref for mtouch and -a|--assembly for mmp.
2021-02-17 19:25:36 +03:00
options . Add ( "targetver=" , "Minimum supported version of the target OS. For Mac Catalyst, this is the corresponding iOS version" , v = > {
2020-05-19 16:30:38 +03:00
try {
app . DeploymentTarget = StringUtils . ParseVersion ( v ) ;
} catch ( Exception ex ) {
throw ErrorHelper . CreateError ( 26 , ex , Errors . MX0026 , "targetver:" + v , ex . Message ) ;
}
} ) ;
2018-11-05 10:16:29 +03:00
options . Add ( "sdkroot=" , "Specify the location of Apple SDKs, default to 'xcode-select' value." , v = > sdk_root = v ) ;
2021-02-17 19:25:36 +03:00
options . Add ( "sdk=" , "Specifies the SDK version to compile against (version, for example \"10.9\"). For Mac Catalyst, this is the macOS version of the SDK." , v = > {
2020-05-19 16:30:38 +03:00
try {
app . SdkVersion = StringUtils . ParseVersion ( v ) ;
2021-02-17 19:25:36 +03:00
app . NativeSdkVersion = app . SdkVersion ;
2020-05-19 16:30:38 +03:00
} catch ( Exception ex ) {
throw ErrorHelper . CreateError ( 26 , ex , Errors . MX0026 , $"sdk:{v}" , ex . Message ) ;
}
} ) ;
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
options . Add ( "target-framework=" , "Specify target framework to use. Currently supported: '" + string . Join ( "', '" , TargetFramework . ValidFrameworks . Select ( ( v ) = > v . ToString ( ) ) ) + "'." , v = > SetTargetFramework ( v ) ) ;
2020-05-11 17:27:19 +03:00
#if MMP
Xamarin.Mac native Apple Silicon targetting support (#10115)
* Add support for Xamarin.Mac arm64
* Add compile product definition task
Xamarin.Mac can be provided with a ProductDefinition file for the generated pkg. Normally, providing a product definition was optional. However, with Apple Silicon, we have an extra issue : `productbuild` needs to know what architectures your package target. If not provided with them, it will guess to the best of its abilities. However, on Catalina and lower, the guess is x86_64, even if you have an arm64 slice. To fix this, we add a new task to compile the product definition and use this file to create the pkg. If you provide your own Product Definition, we can check and warn if the architectures don't match what we expect. If the file doesn't exist or there is no architecture, we set it ourselves based on our target architectures.
* Don't reference dynamic objC_send on arm64
When building in debug, we currently try to link dynamic objC_send symbols when targeting a 64-bit architecture. However, this is actually only defined on Intel architectures, not on arm64, so we end up failing because we're referring symbols that don't exist. Rework the `GetRequiredSymbols` to take an abi, and tag those symbols to only be valid on i386/x86_64, so they don't get referred at all when building on arm64, but still get referred in x86_64.
* Fix improper delete/move with already existing directories
* Fix stret requirement for Xamarin.Mac in arm64.
The generator supposes that we're running in x64 mode, refactor to take into account the possibility of running in arm64.
* Implement OS version generation in Product.plist, based on MinimumSystemVersion of the app
* Re-generalize some mmp registrar rules
`Microsoft.macOS.registrar` was missed by the current rule set
* Fix mmp tests
* Set E7072 as not translated
Tests were failing otherwise
* Rename Xamarin.Mac lib/x86_64 folder to 64bits (currently all targeted archs are the same)
* Fix style issues
* Fix `ToLower` usage for invariant usage
* Fix xtro-sharpie test
2021-03-18 04:48:02 +03:00
options . Add ( "abi=" , "Comma-separated list of ABIs to target. x86_64, arm64" , v = > app . ParseAbi ( v ) ) ;
2020-05-11 17:27:19 +03:00
#else
2020-09-15 19:33:18 +03:00
options . Add ( "abi=" , "Comma-separated list of ABIs to target. Currently supported: armv7, armv7+llvm, armv7+llvm+thumb2, armv7s, armv7s+llvm, armv7s+llvm+thumb2, arm64, arm64+llvm, arm64_32, arm64_32+llvm, i386, x86_64." , v = > app . ParseAbi ( v ) ) ;
2020-05-11 17:27:19 +03:00
#endif
2018-11-05 10:16:29 +03:00
options . Add ( "no-xcode-version-check" , "Ignores the Xcode version check." , v = > { min_xcode_version = null ; } , true /* This is a non-documented option. Please discuss any customers running into the xcode version check on the maciosdev@ list before giving this option out to customers. */ ) ;
2020-05-19 16:30:38 +03:00
options . Add ( "nolink" , "Do not link the assemblies." , v = > app . LinkMode = LinkMode . None ) ;
#if MMP
2020-09-15 19:33:18 +03:00
options . Add ( "linkplatform" , "Link only the Xamarin.Mac.dll platform assembly." , v = > app . LinkMode = LinkMode . Platform ) ;
2020-05-19 16:30:38 +03:00
#endif
2020-09-15 19:33:18 +03:00
options . Add ( "linksdkonly" , "Link only the SDK assemblies." , v = > app . LinkMode = LinkMode . SDKOnly ) ;
options . Add ( "linkskip=" , "Skip linking of the specified assembly." , v = > app . LinkSkipped . Add ( v ) ) ;
options . Add ( "i18n=" , "List of i18n assemblies to copy to the output directory, separated by commas (none, all, cjk, mideast, other, rare and/or west)." , v = > app . ParseI18nAssemblies ( v ) ) ;
options . Add ( "xml=" , "Provide an extra XML definition file to the linker." , v = > app . Definitions . Add ( v ) ) ;
2022-10-11 23:36:58 +03:00
options . Add ( "warnaserror:" , "An optional comma-separated list of warning codes that should be reported as errors (if no warnings are specified all warnings are reported as errors)." , v = > {
2017-02-14 19:46:26 +03:00
try {
if ( ! string . IsNullOrEmpty ( v ) ) {
foreach ( var code in v . Split ( new char [ ] { ',' } , StringSplitOptions . RemoveEmptyEntries ) )
ErrorHelper . SetWarningLevel ( ErrorHelper . WarningLevel . Error , int . Parse ( code ) ) ;
} else {
ErrorHelper . SetWarningLevel ( ErrorHelper . WarningLevel . Error ) ;
}
} catch ( Exception ex ) {
2020-05-14 17:45:05 +03:00
throw ErrorHelper . CreateError ( 26 , ex , Errors . MX0026 , "--warnaserror" , ex . Message ) ;
2017-02-14 19:46:26 +03:00
}
} ) ;
2022-10-11 23:36:58 +03:00
options . Add ( "nowarn:" , "An optional comma-separated list of warning codes to ignore (if no warnings are specified all warnings are ignored)." , v = > {
2017-02-14 19:46:26 +03:00
try {
if ( ! string . IsNullOrEmpty ( v ) ) {
foreach ( var code in v . Split ( new char [ ] { ',' } , StringSplitOptions . RemoveEmptyEntries ) )
ErrorHelper . SetWarningLevel ( ErrorHelper . WarningLevel . Disable , int . Parse ( code ) ) ;
} else {
ErrorHelper . SetWarningLevel ( ErrorHelper . WarningLevel . Disable ) ;
}
} catch ( Exception ex ) {
2020-05-14 17:45:05 +03:00
throw ErrorHelper . CreateError ( 26 , ex , Errors . MX0026 , "--nowarn" , ex . Message ) ;
2017-02-14 19:46:26 +03:00
}
} ) ;
2016-12-23 20:50:35 +03:00
options . Add ( "coop:" , "If the GC should run in cooperative mode." , v = > { app . EnableCoopGC = ParseBool ( v , "coop" ) ; } , hidden : true ) ;
2017-03-17 01:14:42 +03:00
options . Add ( "sgen-conc" , "Enable the *experimental* concurrent garbage collector." , v = > { app . EnableSGenConc = true ; } ) ;
2016-12-22 22:11:50 +03:00
options . Add ( "marshal-objectivec-exceptions:" , "Specify how Objective-C exceptions should be marshalled. Valid values: default, unwindmanagedcode, throwmanagedexception, abort and disable. The default depends on the target platform (on watchOS the default is 'throwmanagedexception', while on all other platforms it's 'disable')." , v = > {
2020-08-25 20:55:50 +03:00
if ( Application . TryParseObjectiveCExceptionMode ( v , out var value ) ) {
app . MarshalObjectiveCExceptions = value ;
} else {
2020-01-31 23:02:52 +03:00
throw ErrorHelper . CreateError ( 26 , Errors . MX0026 , "--marshal-objective-exceptions" , $"Invalid value: {v}. Valid values are: default, unwindmanagedcode, throwmanagedexception, abort and disable." ) ;
2016-05-11 13:47:26 +03:00
}
} ) ;
2016-12-22 22:11:50 +03:00
options . Add ( "marshal-managed-exceptions:" , "Specify how managed exceptions should be marshalled. Valid values: default, unwindnativecode, throwobjectivecexception, abort and disable. The default depends on the target platform (on watchOS the default is 'throwobjectivecexception', while on all other platform it's 'disable')." , v = > {
2020-08-25 20:55:50 +03:00
if ( Application . TryParseManagedExceptionMode ( v , out var value ) ) {
app . MarshalManagedExceptions = value ;
} else {
2020-01-31 23:02:52 +03:00
throw ErrorHelper . CreateError ( 26 , Errors . MX0026 , "--marshal-managed-exceptions" , $"Invalid value: {v}. Valid values are: default, unwindnativecode, throwobjectivecexception, abort and disable." ) ;
2016-05-11 13:47:26 +03:00
}
} ) ;
2017-01-11 23:10:39 +03:00
options . Add ( "j|jobs=" , "The level of concurrency. Default is the number of processors." , v = > {
Jobs = int . Parse ( v ) ;
} ) ;
2017-04-19 14:17:05 +03:00
options . Add ( "embeddinator" , "Enables Embeddinator targetting mode." , v = > {
app . Embeddinator = true ;
} , true ) ;
[mtouch] Improve how we make sure native symbols aren't stripped away. Fixes #51710 and #54417. (#2162)
* [mtouch] Improve how we make sure native symbols aren't stripped away. Fixes #51710 and #54417.
* Refactor required symbol collection to store more information about each
symbol (field, function, Objective-C class), and in general make the code
more straight forward.
* Implement support for generating source code that references these symbols,
and do this whenever we can't ask the native linker to keep these symbols
(when using bitcode). Additionally make it possible to do this manually, so
that the source code can be generated for non-bitcode platforms too (which
is useful if the number of symbols is enormous, in which case we might
surpass the maximum command-line length).
* Also make it possible to completely ignore native symbols, or ignore them on
a per-symbol basis. This provides a fallback for users if we get something
right and we try to preserve something that shouldn't be preserved (for
instance if it doesn't exist), and the user ends up with unfixable linker
errors.
* Don't collect Objective-C classes unless they're in an assembly with
LinkWith attributes. We don't need to preserve Objective-C classes in any
other circumstances.
* Implement everything for both Xamarin.iOS and Xamarin.Mac, and share the
code between them.
* Remove previous workaround for bug #51710, since it's no longer needed.
* Add tests.
https://bugzilla.xamarin.com/show_bug.cgi?id=54417
https://bugzilla.xamarin.com/show_bug.cgi?id=51710
* [mtouch] Make sure to only keep symbols from the current app when code sharing.
This fixes a build problem with the interdependent-binding-projects test when
testing in Today Extension mode.
2017-06-02 19:29:19 +03:00
options . Add ( "dynamic-symbol-mode:" , "Specify how dynamic symbols are treated so that they're not linked away by the native linker. Valid values: linker (pass \"-u symbol\" to the native linker), code (generate native code that uses the dynamic symbol), ignore (do nothing and hope for the best). The default is 'code' when using bitcode, and 'linker' otherwise." , ( v ) = > {
switch ( v . ToLowerInvariant ( ) ) {
case "default" :
app . SymbolMode = SymbolMode . Default ;
break ;
case "linker" :
app . SymbolMode = SymbolMode . Linker ;
break ;
case "code" :
app . SymbolMode = SymbolMode . Code ;
break ;
case "ignore" :
app . SymbolMode = SymbolMode . Ignore ;
break ;
default :
2020-01-31 23:02:52 +03:00
throw ErrorHelper . CreateError ( 26 , Errors . MX0026 , "--dynamic-symbol-mode" , $"Invalid value: {v}. Valid values are: default, linker, code and ignore." ) ;
[mtouch] Improve how we make sure native symbols aren't stripped away. Fixes #51710 and #54417. (#2162)
* [mtouch] Improve how we make sure native symbols aren't stripped away. Fixes #51710 and #54417.
* Refactor required symbol collection to store more information about each
symbol (field, function, Objective-C class), and in general make the code
more straight forward.
* Implement support for generating source code that references these symbols,
and do this whenever we can't ask the native linker to keep these symbols
(when using bitcode). Additionally make it possible to do this manually, so
that the source code can be generated for non-bitcode platforms too (which
is useful if the number of symbols is enormous, in which case we might
surpass the maximum command-line length).
* Also make it possible to completely ignore native symbols, or ignore them on
a per-symbol basis. This provides a fallback for users if we get something
right and we try to preserve something that shouldn't be preserved (for
instance if it doesn't exist), and the user ends up with unfixable linker
errors.
* Don't collect Objective-C classes unless they're in an assembly with
LinkWith attributes. We don't need to preserve Objective-C classes in any
other circumstances.
* Implement everything for both Xamarin.iOS and Xamarin.Mac, and share the
code between them.
* Remove previous workaround for bug #51710, since it's no longer needed.
* Add tests.
https://bugzilla.xamarin.com/show_bug.cgi?id=54417
https://bugzilla.xamarin.com/show_bug.cgi?id=51710
* [mtouch] Make sure to only keep symbols from the current app when code sharing.
This fixes a build problem with the interdependent-binding-projects test when
testing in Today Extension mode.
2017-06-02 19:29:19 +03:00
}
} ) ;
options . Add ( "ignore-dynamic-symbol:" , "Specify that Xamarin.iOS/Xamarin.Mac should not try to prevent the linker from removing the specified symbol." , ( v ) = > {
app . IgnoredSymbols . Add ( v ) ;
} ) ;
2018-04-13 15:50:28 +03:00
options . Add ( "root-assembly=" , "Specifies any root assemblies. There must be at least one root assembly, usually the main executable." , ( v ) = > {
2017-11-16 18:02:34 +03:00
app . RootAssemblies . Add ( v ) ;
} ) ;
[mtouch/mmp] Give users more control over optimizations, and share more code between mtouch and mmp. (#3242)
* [mtouch/mmp] Give users more control over optimizations, and share more code between mtouch and mmp.
1. Add an --optimize flag to mtouch/mmp that allows users to select which
optimizations to apply (or not). This makes it easier to add future
optimizations, and allow users to disable any optimization that causes
problems without having to disable many other features.
2. Share as much optimization code as possible between mtouch and mmp. This
immediately gives a benefit to mmp, which has three new optimizations only
mtouch had: NSObject.IsDirectBinding inlining, IntPtr.Size inlining and
dead code elimination.
This results in ~6kb of disk space saved for a linked Xamarin.Mac app:
* link sdk: [Debug][1], [Release][2]
* link all: [Debug][3], [Release][4]
Testing also verifies that monotouchtest ([Debug][5], [Release][6]) has not
changed size at all, which means that no default optimizations have changed
inadvertedly.
[1]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-sdk-mac--debug
[2]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-sdk-mac--release
[3]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-all-mac--debug
[4]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-all-mac--release
[5]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#monotouchtest-iphonedebug64
[6]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#monotouchtest-iphonerelease64
* [tools] Don't enable the IsDirectBinding optimization by default for Xamarin.Mac apps, it's not safe.
* Fix whitespace issues.
* [doc] Document optimizations.
* Officially support optimizations by adding them to the Versions.plist.
* [linker] Improve IntPtr.Size inliner + dead code eliminatior and add tests.
* Properly handle operands for the ldc_i4_s instruction (they're sbyte).
* Fix less-than condition to actually do a less-than comparison.
* Make sure to look up the bitness in the Target, not the Application, since
the Application's value will be incorrect when building fat apps (both
Is32Build and Is64Build will be true).
* Remove unnecessary checks for the IntPtr.Size inliner: this optimization
does not depend on other instructions than the IntPtr.get_Size call, so
remove the checks that verify surrounding instructions. This makes the
IntPtr.Size inliner kick in in more scenarios (such as the new tests).
* Add tests.
* [tests] Add mmp tests for optimizations.
* [tests] Fix XM optimization tests.
* [tests] Fix test build error.
2018-01-23 13:33:48 +03:00
options . Add ( "optimize=" , "A comma-delimited list of optimizations to enable/disable. To enable an optimization, use --optimize=[+]remove-uithread-checks. To disable an optimizations: --optimize=-remove-uithread-checks. Use '+all' to enable or '-all' disable all optimizations. Only compiler-generated code or code otherwise marked as safe to optimize will be optimized.\n" +
"Available optimizations:\n" +
" dead-code-elimination: By default always enabled (requires the linker). Removes IL instructions the linker can determine will never be executed. This is most useful in combination with the inline-* optimizations, since inlined conditions almost always also results in blocks of code that will never be executed.\n" +
" remove-uithread-checks: By default enabled for release builds (requires the linker). Remove all UI Thread checks (makes the app smaller, and slightly faster at runtime).\n" +
#if MONOTOUCH
2019-03-15 17:05:53 +03:00
" inline-isdirectbinding: By default enabled unless the interpreter is enabled (requires the linker). Tries to inline calls to NSObject.IsDirectBinding to load a constant value. Makes the app smaller, and slightly faster at runtime.\n" +
[mtouch/mmp] Give users more control over optimizations, and share more code between mtouch and mmp. (#3242)
* [mtouch/mmp] Give users more control over optimizations, and share more code between mtouch and mmp.
1. Add an --optimize flag to mtouch/mmp that allows users to select which
optimizations to apply (or not). This makes it easier to add future
optimizations, and allow users to disable any optimization that causes
problems without having to disable many other features.
2. Share as much optimization code as possible between mtouch and mmp. This
immediately gives a benefit to mmp, which has three new optimizations only
mtouch had: NSObject.IsDirectBinding inlining, IntPtr.Size inlining and
dead code elimination.
This results in ~6kb of disk space saved for a linked Xamarin.Mac app:
* link sdk: [Debug][1], [Release][2]
* link all: [Debug][3], [Release][4]
Testing also verifies that monotouchtest ([Debug][5], [Release][6]) has not
changed size at all, which means that no default optimizations have changed
inadvertedly.
[1]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-sdk-mac--debug
[2]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-sdk-mac--release
[3]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-all-mac--debug
[4]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-all-mac--release
[5]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#monotouchtest-iphonedebug64
[6]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#monotouchtest-iphonerelease64
* [tools] Don't enable the IsDirectBinding optimization by default for Xamarin.Mac apps, it's not safe.
* Fix whitespace issues.
* [doc] Document optimizations.
* Officially support optimizations by adding them to the Versions.plist.
* [linker] Improve IntPtr.Size inliner + dead code eliminatior and add tests.
* Properly handle operands for the ldc_i4_s instruction (they're sbyte).
* Fix less-than condition to actually do a less-than comparison.
* Make sure to look up the bitness in the Target, not the Application, since
the Application's value will be incorrect when building fat apps (both
Is32Build and Is64Build will be true).
* Remove unnecessary checks for the IntPtr.Size inliner: this optimization
does not depend on other instructions than the IntPtr.get_Size call, so
remove the checks that verify surrounding instructions. This makes the
IntPtr.Size inliner kick in in more scenarios (such as the new tests).
* Add tests.
* [tests] Add mmp tests for optimizations.
* [tests] Fix XM optimization tests.
* [tests] Fix test build error.
2018-01-23 13:33:48 +03:00
#else
2018-03-02 16:33:27 +03:00
" inline-isdirectbinding: By default disabled, because it may require the linker. Tries to inline calls to NSObject.IsDirectBinding to load a constant value. Makes the app smaller, and slightly faster at runtime.\n" +
[mtouch/mmp] Give users more control over optimizations, and share more code between mtouch and mmp. (#3242)
* [mtouch/mmp] Give users more control over optimizations, and share more code between mtouch and mmp.
1. Add an --optimize flag to mtouch/mmp that allows users to select which
optimizations to apply (or not). This makes it easier to add future
optimizations, and allow users to disable any optimization that causes
problems without having to disable many other features.
2. Share as much optimization code as possible between mtouch and mmp. This
immediately gives a benefit to mmp, which has three new optimizations only
mtouch had: NSObject.IsDirectBinding inlining, IntPtr.Size inlining and
dead code elimination.
This results in ~6kb of disk space saved for a linked Xamarin.Mac app:
* link sdk: [Debug][1], [Release][2]
* link all: [Debug][3], [Release][4]
Testing also verifies that monotouchtest ([Debug][5], [Release][6]) has not
changed size at all, which means that no default optimizations have changed
inadvertedly.
[1]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-sdk-mac--debug
[2]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-sdk-mac--release
[3]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-all-mac--debug
[4]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-all-mac--release
[5]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#monotouchtest-iphonedebug64
[6]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#monotouchtest-iphonerelease64
* [tools] Don't enable the IsDirectBinding optimization by default for Xamarin.Mac apps, it's not safe.
* Fix whitespace issues.
* [doc] Document optimizations.
* Officially support optimizations by adding them to the Versions.plist.
* [linker] Improve IntPtr.Size inliner + dead code eliminatior and add tests.
* Properly handle operands for the ldc_i4_s instruction (they're sbyte).
* Fix less-than condition to actually do a less-than comparison.
* Make sure to look up the bitness in the Target, not the Application, since
the Application's value will be incorrect when building fat apps (both
Is32Build and Is64Build will be true).
* Remove unnecessary checks for the IntPtr.Size inliner: this optimization
does not depend on other instructions than the IntPtr.get_Size call, so
remove the checks that verify surrounding instructions. This makes the
IntPtr.Size inliner kick in in more scenarios (such as the new tests).
* Add tests.
* [tests] Add mmp tests for optimizations.
* [tests] Fix XM optimization tests.
* [tests] Fix test build error.
2018-01-23 13:33:48 +03:00
#endif
#if MONOTOUCH
2019-03-15 17:05:53 +03:00
" remove-dynamic-registrar: By default enabled when the static registrar is enabled and the interpreter is not used. Removes the dynamic registrar (makes the app smaller).\n" +
[mtouch/mmp] Give users more control over optimizations, and share more code between mtouch and mmp. (#3242)
* [mtouch/mmp] Give users more control over optimizations, and share more code between mtouch and mmp.
1. Add an --optimize flag to mtouch/mmp that allows users to select which
optimizations to apply (or not). This makes it easier to add future
optimizations, and allow users to disable any optimization that causes
problems without having to disable many other features.
2. Share as much optimization code as possible between mtouch and mmp. This
immediately gives a benefit to mmp, which has three new optimizations only
mtouch had: NSObject.IsDirectBinding inlining, IntPtr.Size inlining and
dead code elimination.
This results in ~6kb of disk space saved for a linked Xamarin.Mac app:
* link sdk: [Debug][1], [Release][2]
* link all: [Debug][3], [Release][4]
Testing also verifies that monotouchtest ([Debug][5], [Release][6]) has not
changed size at all, which means that no default optimizations have changed
inadvertedly.
[1]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-sdk-mac--debug
[2]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-sdk-mac--release
[3]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-all-mac--debug
[4]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-all-mac--release
[5]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#monotouchtest-iphonedebug64
[6]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#monotouchtest-iphonerelease64
* [tools] Don't enable the IsDirectBinding optimization by default for Xamarin.Mac apps, it's not safe.
* Fix whitespace issues.
* [doc] Document optimizations.
* Officially support optimizations by adding them to the Versions.plist.
* [linker] Improve IntPtr.Size inliner + dead code eliminatior and add tests.
* Properly handle operands for the ldc_i4_s instruction (they're sbyte).
* Fix less-than condition to actually do a less-than comparison.
* Make sure to look up the bitness in the Target, not the Application, since
the Application's value will be incorrect when building fat apps (both
Is32Build and Is64Build will be true).
* Remove unnecessary checks for the IntPtr.Size inliner: this optimization
does not depend on other instructions than the IntPtr.get_Size call, so
remove the checks that verify surrounding instructions. This makes the
IntPtr.Size inliner kick in in more scenarios (such as the new tests).
* Add tests.
* [tests] Add mmp tests for optimizations.
* [tests] Fix XM optimization tests.
* [tests] Fix test build error.
2018-01-23 13:33:48 +03:00
" inline-runtime-arch: By default always enabled (requires the linker). Inlines calls to ObjCRuntime.Runtime.Arch to load a constant value. Makes the app smaller, and slightly faster at runtime.\n" +
#endif
Optimize calls to BlockLiteral.SetupBlock to inject the block signature. (#3391)
* [linker] Optimize calls to BlockLiteral.SetupBlock to inject the block signature.
Optimize calls to BlockLiteral.SetupBlock[Unsafe] to calculate the block
signature at build time, and inject it into the call site.
This makes block invocations 10-15x faster (I've added tests that asserts at
least an 8x increase).
It's also required in order to be able to remove the dynamic registrar code in
the future (since calculating the block signature at runtime requires the
dynamic registrar).
* [mtouch/mmp] Add support for reporting errors/warnings that point to the code line causing the error/warning.
Add support for reporting errors/warnings that point to the code line causing
the error/warning by adding ErrorHelper overloads that take the exact
instruction to report (previously we defaulted to the first line/instruction
in a method).
* [tests] Add support for asserting filename/linenumber in warning messages.
* Make all methods that manually create BlockLiterals optimizable.
* [tests] Create a BaseOptimizeGeneratedCodeTest test that's included in both XI's and XM's link all test.
* [tests] Add link all test (for both XI and XM) to test the BlockLiteral.SetupBlock optimization.
* [tests] Add mtouch/mmp tests for the BlockLiteral.SetupBlock optimization.
* [tests][linker] Make the base test class abstract, so tests in the base class aren't executed twice.
* [tests][linker] Don't execute linkall-only tests in linksdk.
The optimization tests only apply when the test assembly is linked, and that
only happens in linkall, so exclude those tests in linksdk.
* [tests][mmptest] Update test according to mmp changes.
Fixes these test failures:
1) Failed : Xamarin.MMP.Tests.MMPTests.MM0132("inline-runtime-arch")
The warning 'MM0132: Unknown optimization: 'inline-runtime-arch'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.' was not found in the output:
Message #1 did not match:
actual: 'Unknown optimization: 'inline-runtime-arch'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size, blockliteral-setupblock.'
expected: 'Unknown optimization: 'inline-runtime-arch'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.'
Message #2 did not match:
actual: 'Unknown optimization: 'inline-runtime-arch'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size, blockliteral-setupblock.'
expected: 'Unknown optimization: 'inline-runtime-arch'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.'
2) Failed : Xamarin.MMP.Tests.MMPTests.MM0132("foo")
The warning 'MM0132: Unknown optimization: 'foo'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.' was not found in the output:
Message #1 did not match:
actual: 'Unknown optimization: 'foo'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size, blockliteral-setupblock.'
expected: 'Unknown optimization: 'foo'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.'
Message #2 did not match:
actual: 'Unknown optimization: 'foo'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size, blockliteral-setupblock.'
expected: 'Unknown optimization: 'foo'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.'
* [tests][linker] Fix typo.
Fixes this test failure:
1) SetupBlock_CustomDelegate (Linker.Shared.BaseOptimizeGeneratedCodeTest.SetupBlock_CustomDelegate)
Counter
Expected: 1
But was: 2
* [registrar] Minor adjustment to error message to match previous (and better) behavior.
Fixes this test failure:
1) Failed : Xamarin.Registrar.GenericType_WithInvalidParameterTypes
The error 'MT4136: The registrar cannot marshal the parameter type 'System.Collections.Generic.List`1<U>' of the parameter 'arg' in the method 'Open`1.Bar(System.Collections.Generic.List`1<U>)'' was not found in the output:
Message #1 did not match:
actual: 'The registrar cannot marshal the parameter type 'System.Collections.Generic.List`1<Foundation.NSObject>' of the parameter 'arg' in the method 'Open`1.Bar(System.Collections.Generic.List`1<U>)''
expected: 'The registrar cannot marshal the parameter type 'System.Collections.Generic.List`1<U>' of the parameter 'arg' in the method 'Open`1.Bar(System.Collections.Generic.List`1<U>)''
* [docs] mmp shows MM errors/warnings.
* [docs] Improve according to reviews.
* [tests] Fix merge failure causing test duplication.
2018-02-06 09:08:15 +03:00
" blockliteral-setupblock: By default enabled when using the static registrar. Optimizes calls to BlockLiteral.SetupBlock to avoid having to calculate the block signature at runtime.\n" +
2018-02-10 03:15:15 +03:00
" inline-intptr-size: By default enabled for builds that target a single architecture (requires the linker). Inlines calls to IntPtr.Size to load a constant value. Makes the app smaller, and slightly faster at runtime.\n" +
2018-02-12 18:59:39 +03:00
" inline-dynamic-registration-supported: By default always enabled (requires the linker). Optimizes calls to Runtime.DynamicRegistrationSupported to be a constant value. Makes the app smaller, and slightly faster at runtime.\n" +
2018-03-02 16:33:27 +03:00
#if ! MONOTOUCH
2019-03-15 17:05:53 +03:00
" register-protocols: Remove unneeded metadata for protocol support. Makes the app smaller and reduces memory requirements. Disabled when the interpreter is used or when the static registrar is not enabled.\n" +
2019-02-14 20:36:29 +03:00
" trim-architectures: Remove unneeded architectures from bundled native libraries. Makes the app smaller and is required for macOS App Store submissions.\n" +
2018-03-02 16:33:27 +03:00
#else
2019-03-15 17:05:53 +03:00
" register-protocols: Remove unneeded metadata for protocol support. Makes the app smaller and reduces memory requirements. Disabled, by default, to allow dynamic code loading.\n" +
2019-02-14 20:36:29 +03:00
" remove-unsupported-il-for-bitcode: Remove IL that is not supported when compiling to bitcode, and replace with a NotSupportedException.\n" +
2020-03-02 17:20:29 +03:00
" force-rejected-types-removal: Forcefully remove types that are known to cause rejections when applications are submitted to Apple. This includes: `UIWebView` and related types.\n" +
2018-03-02 16:33:27 +03:00
#endif
2019-02-14 20:36:29 +03:00
"" ,
[mtouch/mmp] Give users more control over optimizations, and share more code between mtouch and mmp. (#3242)
* [mtouch/mmp] Give users more control over optimizations, and share more code between mtouch and mmp.
1. Add an --optimize flag to mtouch/mmp that allows users to select which
optimizations to apply (or not). This makes it easier to add future
optimizations, and allow users to disable any optimization that causes
problems without having to disable many other features.
2. Share as much optimization code as possible between mtouch and mmp. This
immediately gives a benefit to mmp, which has three new optimizations only
mtouch had: NSObject.IsDirectBinding inlining, IntPtr.Size inlining and
dead code elimination.
This results in ~6kb of disk space saved for a linked Xamarin.Mac app:
* link sdk: [Debug][1], [Release][2]
* link all: [Debug][3], [Release][4]
Testing also verifies that monotouchtest ([Debug][5], [Release][6]) has not
changed size at all, which means that no default optimizations have changed
inadvertedly.
[1]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-sdk-mac--debug
[2]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-sdk-mac--release
[3]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-all-mac--debug
[4]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-all-mac--release
[5]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#monotouchtest-iphonedebug64
[6]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#monotouchtest-iphonerelease64
* [tools] Don't enable the IsDirectBinding optimization by default for Xamarin.Mac apps, it's not safe.
* Fix whitespace issues.
* [doc] Document optimizations.
* Officially support optimizations by adding them to the Versions.plist.
* [linker] Improve IntPtr.Size inliner + dead code eliminatior and add tests.
* Properly handle operands for the ldc_i4_s instruction (they're sbyte).
* Fix less-than condition to actually do a less-than comparison.
* Make sure to look up the bitness in the Target, not the Application, since
the Application's value will be incorrect when building fat apps (both
Is32Build and Is64Build will be true).
* Remove unnecessary checks for the IntPtr.Size inliner: this optimization
does not depend on other instructions than the IntPtr.get_Size call, so
remove the checks that verify surrounding instructions. This makes the
IntPtr.Size inliner kick in in more scenarios (such as the new tests).
* Add tests.
* [tests] Add mmp tests for optimizations.
* [tests] Fix XM optimization tests.
* [tests] Fix test build error.
2018-01-23 13:33:48 +03:00
( v ) = > {
2020-09-08 21:26:28 +03:00
if ( optimize = = null )
optimize = new List < string > ( ) ;
optimize . Add ( v ) ;
[mtouch/mmp] Give users more control over optimizations, and share more code between mtouch and mmp. (#3242)
* [mtouch/mmp] Give users more control over optimizations, and share more code between mtouch and mmp.
1. Add an --optimize flag to mtouch/mmp that allows users to select which
optimizations to apply (or not). This makes it easier to add future
optimizations, and allow users to disable any optimization that causes
problems without having to disable many other features.
2. Share as much optimization code as possible between mtouch and mmp. This
immediately gives a benefit to mmp, which has three new optimizations only
mtouch had: NSObject.IsDirectBinding inlining, IntPtr.Size inlining and
dead code elimination.
This results in ~6kb of disk space saved for a linked Xamarin.Mac app:
* link sdk: [Debug][1], [Release][2]
* link all: [Debug][3], [Release][4]
Testing also verifies that monotouchtest ([Debug][5], [Release][6]) has not
changed size at all, which means that no default optimizations have changed
inadvertedly.
[1]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-sdk-mac--debug
[2]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-sdk-mac--release
[3]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-all-mac--debug
[4]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#link-all-mac--release
[5]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#monotouchtest-iphonedebug64
[6]: https://gist.github.com/rolfbjarne/6b731e3b5ca6170355662e6505c3d492#monotouchtest-iphonerelease64
* [tools] Don't enable the IsDirectBinding optimization by default for Xamarin.Mac apps, it's not safe.
* Fix whitespace issues.
* [doc] Document optimizations.
* Officially support optimizations by adding them to the Versions.plist.
* [linker] Improve IntPtr.Size inliner + dead code eliminatior and add tests.
* Properly handle operands for the ldc_i4_s instruction (they're sbyte).
* Fix less-than condition to actually do a less-than comparison.
* Make sure to look up the bitness in the Target, not the Application, since
the Application's value will be incorrect when building fat apps (both
Is32Build and Is64Build will be true).
* Remove unnecessary checks for the IntPtr.Size inliner: this optimization
does not depend on other instructions than the IntPtr.get_Size call, so
remove the checks that verify surrounding instructions. This makes the
IntPtr.Size inliner kick in in more scenarios (such as the new tests).
* Add tests.
* [tests] Add mmp tests for optimizations.
* [tests] Fix XM optimization tests.
* [tests] Fix test build error.
2018-01-23 13:33:48 +03:00
} ) ;
2020-05-13 09:40:07 +03:00
options . Add ( "package-debug-symbols:" , "Specify whether debug info files (*.mdb / *.pdb) should be packaged in the app. Default is 'true' for debug builds and 'false' for release builds." , v = > app . PackageManagedDebugSymbols = ParseBool ( v , "package-debug-symbols" ) ) ;
2020-09-15 19:33:18 +03:00
options . Add ( "profiling:" , "Enable profiling." , v = > app . EnableProfiling = ParseBool ( v , "profiling" ) ) ;
options . Add ( "debugtrack:" , "Enable debug tracking of object resurrection bugs." , v = > { app . DebugTrack = ParseBool ( v , "--debugtrack" ) ; } ) ;
options . Add ( "http-message-handler=" , "Specify the default HTTP message handler for HttpClient." , v = > { app . HttpMessageHandler = v ; } ) ;
options . Add ( "tls-provider=" , "Specify the default TLS provider." , v = > { app . TlsProvider = v ; } ) ;
options . Add ( "setenv=" , "Set the environment variable in the application on startup." , v = > {
2022-10-11 23:36:58 +03:00
int eq = v . IndexOf ( '=' ) ;
if ( eq < = 0 )
throw ErrorHelper . CreateError ( 2 , Errors . MT0002 , v ) ;
var name = v . Substring ( 0 , eq ) ;
var value = v . Substring ( eq + 1 ) ;
app . EnvironmentVariables . Add ( name , value ) ;
}
2020-05-13 09:50:20 +03:00
) ;
2020-09-15 19:33:18 +03:00
options . Add ( "registrar:" , "Specify the registrar to use (dynamic, static or default (dynamic in the simulator, static on device))." , v = > {
2020-09-11 15:08:48 +03:00
app . ParseRegistrar ( v ) ;
2020-05-19 16:30:38 +03:00
} ) ;
options . Add ( "runregistrar:" , "Runs the registrar on the input assembly and outputs a corresponding native library." ,
v = > {
a = Action . RunRegistrar ;
app . RegistrarOutputLibrary = v ;
} ,
true /* this is an internal option */
) ;
2020-09-15 19:33:18 +03:00
options . Add ( "warn-on-type-ref=" , "Warn if any of the comma-separated types is referenced by assemblies - both before and after linking." , v = > {
2020-05-19 16:30:38 +03:00
app . WarnOnTypeRef . AddRange ( v . Split ( new char [ ] { ',' } , StringSplitOptions . RemoveEmptyEntries ) ) ;
} ) ;
2021-04-28 08:34:40 +03:00
options . Add ( "xamarin-runtime=" , "Which runtime to use (MonoVM or CoreCLR)." , v = > {
if ( ! Enum . TryParse < XamarinRuntime > ( v , out var rv ) )
throw new InvalidOperationException ( $"Invalid XamarinRuntime '{v}'" ) ;
app . XamarinRuntime = rv ;
} , true /* hidden - this is only for build-time --runregistrar support */ ) ;
2021-11-23 03:30:36 +03:00
options . Add ( "rid=" , "The runtime identifier we're building for" , v = > {
app . RuntimeIdentifier = v ;
} , true /* hidden - this is only for build-time --runregistrar support */ ) ;
2022-05-11 17:42:01 +03:00
options . Add ( "require-pinvoke-wrappers:" , v = > {
app . RequiresPInvokeWrappers = ParseBool ( v , "--require-pinvoke-wrappers" ) ;
} ) ;
2021-11-23 03:30:36 +03:00
2021-04-28 08:34:40 +03:00
2020-05-13 09:50:20 +03:00
// Keep the ResponseFileSource option at the end.
2017-11-16 18:02:34 +03:00
options . Add ( new Mono . Options . ResponseFileSource ( ) ) ;
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
try {
app . RootAssemblies . AddRange ( options . Parse ( args ) ) ;
} catch ( ProductException ) {
throw ;
} catch ( Exception e ) {
throw ErrorHelper . CreateError ( 10 , e , Errors . MX0010 , e ) ;
}
if ( a ! = Action . None )
action = a ;
if ( action = = Action . Help | | args . Length = = 0 ) {
ShowHelp ( options ) ;
return true ;
} else if ( action = = Action . Version ) {
Console . WriteLine ( NAME + " {0}.{1}" , Constants . Version , Constants . Revision ) ;
return true ;
}
LogArguments ( args ) ;
2020-08-17 09:37:29 +03:00
var validateFramework = true ;
#if MTOUCH
validateFramework = ! IsMlaunchAction ( action ) ;
#endif
if ( validateFramework )
ValidateTargetFramework ( ) ;
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
2020-09-08 21:26:28 +03:00
if ( optimize ! = null ) {
// This must happen after the call to ValidateTargetFramework, so that app.Platform is correct.
var messages = new List < ProductException > ( ) ;
foreach ( var opt in optimize )
app . Optimizations . Parse ( app . Platform , opt , messages ) ;
ErrorHelper . Show ( messages ) ;
}
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
return false ;
2017-01-11 23:10:39 +03:00
}
2020-07-17 17:38:40 +03:00
#endif // !NET
2017-01-11 23:10:39 +03:00
static int Jobs ;
public static int Concurrency {
get {
return Jobs = = 0 ? Environment . ProcessorCount : Jobs ;
}
2016-05-11 13:24:55 +03:00
}
[mtouch/mmp] Print assembly references in verbose mode. (#2139)
* [mtouch/mmp] Print assembly references in verbose mode.
Sample output:
Loaded assembly 'unifiedtestapp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' from /Users/rolf/Projects/TestApp/bin/iPhoneSimulator/Debug/unifiedtestapp.exe
References: mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
References: Xamarin.iOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065
Loaded assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' from /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/lib/mono/Xamarin.iOS/mscorlib.dll
Loaded assembly 'Xamarin.iOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' from /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/lib/mono/Xamarin.iOS/../../64bits/Xamarin.iOS.dll
References: mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
References: System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
References: System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
References: Mono.Security, Version=2.0.5.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756
References: System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
Loaded assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' from /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/lib/mono/Xamarin.iOS/System.dll
References: mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
References: Mono.Security, Version=2.0.5.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756
References: System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
Loaded assembly 'Mono.Security, Version=2.0.5.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' from /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/lib/mono/Xamarin.iOS/Mono.Security.dll
References: mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
References: System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
Loaded assembly 'System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' from /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/lib/mono/Xamarin.iOS/System.Xml.dll
References: mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
References: System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
Loaded assembly 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' from /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/lib/mono/Xamarin.iOS/System.Core.dll
References: mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
References: System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
I believe this will make it easier to diagnose cases where something references a desktop assembly.
* [mtouch/mmp] Share more code between mmp and mtouch.
2017-05-29 17:15:22 +03:00
public static int Verbosity {
2021-02-16 11:44:54 +03:00
get { return ErrorHelper . Verbosity ; }
set { ErrorHelper . Verbosity = value ; }
}
static Driver ( )
{
Verbosity = GetDefaultVerbosity ( ) ;
2020-02-18 23:44:19 +03:00
}
static int GetDefaultVerbosity ( )
{
var v = 0 ;
2022-09-23 17:29:19 +03:00
var fn = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) , $".{NAME}-verbosity" ) ;
2020-02-18 23:44:19 +03:00
if ( File . Exists ( fn ) ) {
v = ( int ) new FileInfo ( fn ) . Length ;
if ( v = = 0 )
v = 4 ; // this is the magic verbosity level we give everybody.
}
return v ;
}
public static void Log ( string value )
{
Log ( 0 , value ) ;
}
public static void Log ( string format , params object [ ] args )
{
Log ( 0 , format , args ) ;
}
public static void Log ( int min_verbosity , string value )
{
if ( min_verbosity > Verbosity )
return ;
Console . WriteLine ( value ) ;
}
public static void Log ( int min_verbosity , string format , params object [ ] args )
{
if ( min_verbosity > Verbosity )
return ;
2020-02-20 22:52:25 +03:00
if ( args . Length > 0 )
Console . WriteLine ( format , args ) ;
else
Console . WriteLine ( format ) ;
[mtouch/mmp] Print assembly references in verbose mode. (#2139)
* [mtouch/mmp] Print assembly references in verbose mode.
Sample output:
Loaded assembly 'unifiedtestapp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' from /Users/rolf/Projects/TestApp/bin/iPhoneSimulator/Debug/unifiedtestapp.exe
References: mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
References: Xamarin.iOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065
Loaded assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' from /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/lib/mono/Xamarin.iOS/mscorlib.dll
Loaded assembly 'Xamarin.iOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' from /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/lib/mono/Xamarin.iOS/../../64bits/Xamarin.iOS.dll
References: mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
References: System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
References: System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
References: Mono.Security, Version=2.0.5.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756
References: System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
Loaded assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' from /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/lib/mono/Xamarin.iOS/System.dll
References: mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
References: Mono.Security, Version=2.0.5.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756
References: System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
Loaded assembly 'Mono.Security, Version=2.0.5.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' from /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/lib/mono/Xamarin.iOS/Mono.Security.dll
References: mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
References: System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
Loaded assembly 'System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' from /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/lib/mono/Xamarin.iOS/System.Xml.dll
References: mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
References: System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
Loaded assembly 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' from /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/lib/mono/Xamarin.iOS/System.Core.dll
References: mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
References: System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
I believe this will make it easier to diagnose cases where something references a desktop assembly.
* [mtouch/mmp] Share more code between mmp and mtouch.
2017-05-29 17:15:22 +03:00
}
2020-05-04 19:31:48 +03:00
public static bool IsDotNet {
get { return TargetFramework . IsDotNet ; }
}
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
static TargetFramework targetFramework ;
2016-04-21 15:57:02 +03:00
public static TargetFramework TargetFramework {
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
get { return targetFramework ; }
2016-04-21 15:57:02 +03:00
set { targetFramework = value ; }
}
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
// We need to delay validating the target framework until we've parsed all the command line arguments,
// so first store it here, and then we call ValidateTargetFramework when we're done parsing the command
// line arguments.
static string target_framework ;
static void SetTargetFramework ( string value )
2016-04-21 15:57:02 +03:00
{
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
target_framework = value ;
}
static void ValidateTargetFramework ( )
{
if ( string . IsNullOrEmpty ( target_framework ) )
throw ErrorHelper . CreateError ( 86 , Errors . MX0086 /* A target framework (--target-framework) must be specified */ ) ;
2016-04-21 15:57:02 +03:00
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
var fx = target_framework ;
2016-04-21 15:57:02 +03:00
switch ( fx . Trim ( ) . ToLowerInvariant ( ) ) {
case "xammac" :
case "mobile" :
case "xamarin.mac" :
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
targetFramework = TargetFramework . Xamarin_Mac_2_0_Mobile ;
ErrorHelper . Warning ( 90 , Errors . MX0090 , /* The target framework '{0}' is deprecated. Use '{1}' instead. */ fx , targetFramework ) ;
return ;
2016-04-21 15:57:02 +03:00
default :
TargetFramework parsedFramework ;
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
if ( ! TargetFramework . TryParse ( fx , out parsedFramework ) )
2020-01-31 23:02:52 +03:00
throw ErrorHelper . CreateError ( 68 , Errors . MX0068 , fx ) ;
2016-04-21 15:57:02 +03:00
targetFramework = parsedFramework ;
break ;
}
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
bool show_0090 = false ;
#if MONOMAC
if ( ! TargetFramework . IsValidFramework ( targetFramework ) ) {
// For historic reasons this is messy.
// If the TargetFramework we got isn't any of the one we accept, we have to do some fudging.
bool force45From40UnifiedSystemFull = false ;
// Detect Classic usage, and show an error.
2020-05-05 16:35:02 +03:00
if ( App . References . Any ( ( v ) = > Path . GetFileName ( v ) = = "XamMac.dll" ) )
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
throw ErrorHelper . CreateError ( 143 , Errors . MM0143 /* Projects using the Classic API are not supported anymore. Please migrate the project to the Unified API. */ ) ;
if ( targetFramework = = TargetFramework . Net_2_0
2022-10-11 23:36:58 +03:00
| | targetFramework = = TargetFramework . Net_3_0
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
| | targetFramework = = TargetFramework . Net_3_5
| | targetFramework = = TargetFramework . Net_4_0
| | targetFramework = = TargetFramework . Net_4_5 ) {
// .NETFramework,v2.0 => Xamarin.Mac,Version=v4.5,Profile=Full
// .NETFramework,v3.0 => Xamarin.Mac,Version=v4.5,Profile=Full
// .NETFramework,v3.5 => Xamarin.Mac,Version=v4.5,Profile=Full
// .NETFramework,v4.0 => Xamarin.Mac,Version=v4.5,Profile=Full
// .NETFramework,v4.5 => Xamarin.Mac,Version=v4.5,Profile=Full
TargetFramework = TargetFramework . Xamarin_Mac_4_5_Full ;
} else if ( TargetFramework . Identifier = = TargetFramework . Xamarin_Mac_2_0_Mobile . Identifier
& & TargetFramework . Version = = TargetFramework . Xamarin_Mac_2_0_Mobile . Version ) {
// At least once instance of a TargetFramework of Xamarin.Mac,v2.0,(null) was found already. Assume any v2.0 implies a desire for Modern.
TargetFramework = TargetFramework . Xamarin_Mac_2_0_Mobile ;
} else if ( TargetFramework . Identifier = = TargetFramework . Xamarin_Mac_4_5_Full . Identifier
& & TargetFramework . Profile = = TargetFramework . Xamarin_Mac_4_5_Full . Profile ) {
// Xamarin.Mac,Version=vX.Y,Profile=Full => Xamarin.Mac,Version=v4.5,Profile=Full
TargetFramework = TargetFramework . Xamarin_Mac_4_5_Full ;
} else if ( TargetFramework . Identifier = = TargetFramework . Xamarin_Mac_4_5_System . Identifier
& & TargetFramework . Profile = = TargetFramework . Xamarin_Mac_4_5_System . Profile ) {
// Xamarin.Mac,Version=vX.Y,Profile=System => Xamarin.Mac,Version=v4.5,Profile=System
TargetFramework = TargetFramework . Xamarin_Mac_4_5_System ;
} else {
// This is a total hack. Instead of passing in an argument, we walk the references looking for
// the "right" Xamarin.Mac and assume you are doing something
2020-05-05 16:35:02 +03:00
foreach ( var asm in App . References ) {
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
if ( asm . EndsWith ( "reference/full/Xamarin.Mac.dll" , StringComparison . Ordinal ) ) {
force45From40UnifiedSystemFull = TargetFramework = = TargetFramework . Net_4_0 ;
TargetFramework = TargetFramework . Xamarin_Mac_4_5_System ;
break ;
} else if ( asm . EndsWith ( "mono/4.5/Xamarin.Mac.dll" , StringComparison . Ordinal ) ) {
TargetFramework = TargetFramework . Xamarin_Mac_4_5_Full ;
break ;
}
}
}
if ( force45From40UnifiedSystemFull ) {
// Xamarin.Mac Unified Full System profile requires .NET 4.5, not .NET 4.0.
FixReferences ( x = > x . Contains ( "lib/mono/4.0" ) , x = > x . Replace ( "lib/mono/4.0" , "lib/mono/4.5" ) ) ;
}
show_0090 = true ;
}
2016-04-21 15:57:02 +03:00
#endif
[mtouch/mmp] Improve target framework code. (#8137)
* Unify target framework code between mtouch and mmp.
* Simplify the code in mmp: have three possible valid target frameworks for
most of code, and add special code to handle setting any other valid target
frameworks to redirect to one of those three valid target frameworks (and
warn if given any of those valid, but not "main", target frameworks). Any
other code can then depend on the target framework having exactly one of
those specific values, which means we can make IsUnified* variables
convenience properties instead.
* Unify a bit more of the argument parsing code between mtouch and mmp, since
that made a few other things easier.
* Add TargetFramework.IsValidFramework to have one validation implementation.
* Move the implementation of TargetFramework.MonoFrameworkDirectory to mmp
itself, it's not really related to the target framework.
* Remove Driver.IsUnified and IsClassic from mmp, they're not used anymore.
* Formally deprecate --xamarin-[full|system]-framework in mmp, they've really been deprecated for many years.
* Remove LinkerOptions.TargetFramework, it's not used anymore.
* Get rid of mmp's userTargetFramework fried, it's duplicated with the
targetFramework field.
* Add a few tests, and tweak others a bit.
Breaking changes:
* Both mtouch and mmp require --target-framework now. The only direct
consumers should be the MSBuild tasks, which already pass --target-framework
all the time. This simplifies code, and removes assumptions.
2020-03-19 11:28:09 +03:00
// Verify that our TargetFramework is our limited list of valid target frameworks.
if ( ! TargetFramework . IsValidFramework ( TargetFramework ) )
throw ErrorHelper . CreateError ( 70 , Errors . MX0070 , fx , "'" + string . Join ( "', '" , TargetFramework . ValidFrameworks . Select ( ( v ) = > v . ToString ( ) ) . ToArray ( ) ) + "'" ) ;
// Only show the warning if no errors were shown.
if ( show_0090 )
ErrorHelper . Warning ( 90 , Errors . MX0090 , /* The target framework '{0}' is deprecated. Use '{1}' instead. */ fx , TargetFramework ) ;
2016-04-21 15:57:02 +03:00
}
#if ! MMP_TEST
static void FileMove ( string source , string target )
{
2021-01-19 16:29:11 +03:00
File . Delete ( target ) ;
2016-04-21 15:57:02 +03:00
File . Move ( source , target ) ;
}
[mtouch/mmp] Fix tracking of whether the static registrar should run again or not. Fixes #641. (#3534) (#3536)
* [tests] Improve debug spew for the RebuildTest_WithExtensions test.
* [mtouch/mmp] Store/load if the dynamic registrar is removed or not into the cached link results.
Store/load if the dynamic registrar is removed or not into the cached link
results, so that we generate the correct main.m even if cached linker results
are used.
* [mtouch/mmp] The static registrar must not execute if we're loading cached results from the linker.
The static registrar must not execute if we're loading cached results from the
linker, because the static registrar needs information from the linker that's
not restored from the cache.
* [mtouch/mmp] Share Touch code.
* [mtouch/mmp] Make it possible to touch inexistent files (to create them).
* [mtouch/mmp] Fix tracking of whether the static registrar should run again or not.
The recent changes to support optimizing away the dynamic registrar caused the
Xamarin.MTouch.RebuildTest_WithExtensions test to regress.
The problem
-----------
* The linker now collects and stores information the static registrar needs.
* This information is not restored from disk when the linker realizes that it
can reload previously linked assemblies instead of executing again.
* The static registrar runs again (for another reason).
* The information the static registrar needs isn't available, and incorrect
output follows.
So fix 1: show an error if the static registrar runs when the linker loaded
cached results.
The exact scenario the test ran into is this:
* 1st build: everything is new and everything is built.
* 2nd build: contents of .exe changes, the linker runs again, the static
registrar runs again, but sees that the generated output didn't change, so
it doesn't write the new content to disk (this is an optimization to avoid
compiling the registrar.m file again unless needed).
* 3rd build: only the .exe timestamp changes, the linker sees nothing changes
in the contents of the .exe and loads the previously linked assemblies from
disk, the static registrar sees that the .exe's timestamp is newer than
registrar.m's timestamp and run again, but doesn't produce the right result
because it doesn't have the information it needs.
Considered solutions
--------------------
1. Only track timestamps, not file contents. This is not ideal, since it will
result in more work done: in particular for the case above, it would add a
registrar.m compilation in build #2, and linker rerun + static registrar
rerun + registrar.m compilation + final native link in build #3.
2. Always write the output of the static registrar, even if it hasn't changed.
This is not ideal either, since it will also result in more work done: for
the case above, it would add a registrar.m compilation + final native link
in build #3.
3. Always write the output of the static registrar, but track if it changed or
not, and if it didn't, just touch registrar.o instead of recompiling it.
This only means the final native link in build #3 is added (see #5 for why
this is worse than it sounds).
4. Always write the output of the static registrar, but track it it changed or
not, and if it didn't, just touch registrar.o instead of recompiling it,
and track that too, so that the final native link in build #3 isn't needed
anymore. Unfortunately this may result in incorrect behavior, because now
the msbuild tasks will detect that the executable has changed, and may run
dsymutil + strip again. The executable didn't actually change, which means
it would be the previously stripped executable, and thus we'd end up with
an empty .dSYM because we ran dsymtil on an already stripped executable.
5. Idea #4, but write the output of the final link into a temporary directory
instead of the .app, so that we could track whether we should update the
executable in the .app or not. This is not optimal either, because
executables can be *big* (I've seen multi-GB tvOS bitcode executables), and
extra copies of such files should not be taken lightly.
6. Idea #4, but tell the MSBuild tasks that dsymutil/strip doesn't need to be
rerun even if the timestamp of the executable changed. This might actually
work, but now the solution's become quite complex.
Implemented solution
--------------------
Use stamp files to detect whether a file is up-to-date or not.
In particular:
* When we don't write to a file because the new contents are identical to the
old contents, we now touch a .stamp file. This stamp file means "the
accompanying file was determined to be up-to-date when the stamp was
touched."
* When checking whether a file is up-to-date, also check for the presence of a
.stamp file, and if it exists, use the highest timestamp between the stamp
file and the actual file.
Now the test scenario becomes:
* 1st build: everything is new and everything is built.
* 2nd build: contents of .exe changes, the linker runs again, the static
registrar runs again, but sees that the generated output didn't change, so
it doesn't write the new content to disk, but it creates a registrar.m.stamp
file to indicate the point in time when registrar.m was considered up-to-
date.
* 3rd build: only the .exe timestamp changes, the linker sees nothing changes
in the contents of the .exe and loads the previously linked assemblies from
disk, the static registrar sees that the .exe's timestamp is *older* than
registrar.m.stamp's timestamp and doesn't run again.
We only use the stamp file for source code (registrar.[m|h], main.[m|h],
pinvokes.[m|h]), since using it every time has too much potential for running
into other problems (for instance we should never create .stamp files inside
the .app).
Fixes these test failures:
1) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("single","",False,System.String[])
single
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory371/testApp.app/testApp is modified, timestamp: 2/15/2018 3:04:11 PM > 2/15/2018 3:04:09 PM" >
2) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("dual","armv7,arm64",False,System.String[])
dual
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory375/testApp.app/testApp is modified, timestamp: 2/15/2018 3:06:03 PM > 2/15/2018 3:06:00 PM" >
3) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("llvm","armv7+llvm",False,System.String[])
llvm
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory379/testApp.app/testApp is modified, timestamp: 2/15/2018 3:07:14 PM > 2/15/2018 3:07:12 PM" >
4) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("debug","",True,System.String[])
debug
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory383/testApp.app/testApp is modified, timestamp: 2/15/2018 3:08:16 PM > 2/15/2018 3:08:13 PM" >
5) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("single-framework","",False,System.String[])
single-framework
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory387/testApp.app/testApp is modified, timestamp: 2/15/2018 3:09:18 PM > 2/15/2018 3:09:16 PM" >
Fixes https://github.com/xamarin/maccore/issues/641
2018-02-20 13:43:23 +03:00
static void MoveIfDifferent ( string path , string tmp , bool use_stamp = false )
2016-05-11 14:00:20 +03:00
{
// Don't read the entire file into memory, it can be quite big in certain cases.
bool move = false ;
using ( var fs1 = new FileStream ( path , FileMode . Open , FileAccess . Read ) ) {
using ( var fs2 = new FileStream ( tmp , FileMode . Open , FileAccess . Read ) ) {
if ( fs1 . Length ! = fs2 . Length ) {
Log ( 3 , "New file '{0}' has different length, writing new file." , path ) ;
move = true ;
} else {
move = ! Cache . CompareStreams ( fs1 , fs2 ) ;
}
}
}
if ( move ) {
FileMove ( tmp , path ) ;
} else {
Log ( 3 , "Target {0} is up-to-date." , path ) ;
[mtouch/mmp] Fix tracking of whether the static registrar should run again or not. Fixes #641. (#3534) (#3536)
* [tests] Improve debug spew for the RebuildTest_WithExtensions test.
* [mtouch/mmp] Store/load if the dynamic registrar is removed or not into the cached link results.
Store/load if the dynamic registrar is removed or not into the cached link
results, so that we generate the correct main.m even if cached linker results
are used.
* [mtouch/mmp] The static registrar must not execute if we're loading cached results from the linker.
The static registrar must not execute if we're loading cached results from the
linker, because the static registrar needs information from the linker that's
not restored from the cache.
* [mtouch/mmp] Share Touch code.
* [mtouch/mmp] Make it possible to touch inexistent files (to create them).
* [mtouch/mmp] Fix tracking of whether the static registrar should run again or not.
The recent changes to support optimizing away the dynamic registrar caused the
Xamarin.MTouch.RebuildTest_WithExtensions test to regress.
The problem
-----------
* The linker now collects and stores information the static registrar needs.
* This information is not restored from disk when the linker realizes that it
can reload previously linked assemblies instead of executing again.
* The static registrar runs again (for another reason).
* The information the static registrar needs isn't available, and incorrect
output follows.
So fix 1: show an error if the static registrar runs when the linker loaded
cached results.
The exact scenario the test ran into is this:
* 1st build: everything is new and everything is built.
* 2nd build: contents of .exe changes, the linker runs again, the static
registrar runs again, but sees that the generated output didn't change, so
it doesn't write the new content to disk (this is an optimization to avoid
compiling the registrar.m file again unless needed).
* 3rd build: only the .exe timestamp changes, the linker sees nothing changes
in the contents of the .exe and loads the previously linked assemblies from
disk, the static registrar sees that the .exe's timestamp is newer than
registrar.m's timestamp and run again, but doesn't produce the right result
because it doesn't have the information it needs.
Considered solutions
--------------------
1. Only track timestamps, not file contents. This is not ideal, since it will
result in more work done: in particular for the case above, it would add a
registrar.m compilation in build #2, and linker rerun + static registrar
rerun + registrar.m compilation + final native link in build #3.
2. Always write the output of the static registrar, even if it hasn't changed.
This is not ideal either, since it will also result in more work done: for
the case above, it would add a registrar.m compilation + final native link
in build #3.
3. Always write the output of the static registrar, but track if it changed or
not, and if it didn't, just touch registrar.o instead of recompiling it.
This only means the final native link in build #3 is added (see #5 for why
this is worse than it sounds).
4. Always write the output of the static registrar, but track it it changed or
not, and if it didn't, just touch registrar.o instead of recompiling it,
and track that too, so that the final native link in build #3 isn't needed
anymore. Unfortunately this may result in incorrect behavior, because now
the msbuild tasks will detect that the executable has changed, and may run
dsymutil + strip again. The executable didn't actually change, which means
it would be the previously stripped executable, and thus we'd end up with
an empty .dSYM because we ran dsymtil on an already stripped executable.
5. Idea #4, but write the output of the final link into a temporary directory
instead of the .app, so that we could track whether we should update the
executable in the .app or not. This is not optimal either, because
executables can be *big* (I've seen multi-GB tvOS bitcode executables), and
extra copies of such files should not be taken lightly.
6. Idea #4, but tell the MSBuild tasks that dsymutil/strip doesn't need to be
rerun even if the timestamp of the executable changed. This might actually
work, but now the solution's become quite complex.
Implemented solution
--------------------
Use stamp files to detect whether a file is up-to-date or not.
In particular:
* When we don't write to a file because the new contents are identical to the
old contents, we now touch a .stamp file. This stamp file means "the
accompanying file was determined to be up-to-date when the stamp was
touched."
* When checking whether a file is up-to-date, also check for the presence of a
.stamp file, and if it exists, use the highest timestamp between the stamp
file and the actual file.
Now the test scenario becomes:
* 1st build: everything is new and everything is built.
* 2nd build: contents of .exe changes, the linker runs again, the static
registrar runs again, but sees that the generated output didn't change, so
it doesn't write the new content to disk, but it creates a registrar.m.stamp
file to indicate the point in time when registrar.m was considered up-to-
date.
* 3rd build: only the .exe timestamp changes, the linker sees nothing changes
in the contents of the .exe and loads the previously linked assemblies from
disk, the static registrar sees that the .exe's timestamp is *older* than
registrar.m.stamp's timestamp and doesn't run again.
We only use the stamp file for source code (registrar.[m|h], main.[m|h],
pinvokes.[m|h]), since using it every time has too much potential for running
into other problems (for instance we should never create .stamp files inside
the .app).
Fixes these test failures:
1) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("single","",False,System.String[])
single
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory371/testApp.app/testApp is modified, timestamp: 2/15/2018 3:04:11 PM > 2/15/2018 3:04:09 PM" >
2) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("dual","armv7,arm64",False,System.String[])
dual
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory375/testApp.app/testApp is modified, timestamp: 2/15/2018 3:06:03 PM > 2/15/2018 3:06:00 PM" >
3) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("llvm","armv7+llvm",False,System.String[])
llvm
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory379/testApp.app/testApp is modified, timestamp: 2/15/2018 3:07:14 PM > 2/15/2018 3:07:12 PM" >
4) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("debug","",True,System.String[])
debug
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory383/testApp.app/testApp is modified, timestamp: 2/15/2018 3:08:16 PM > 2/15/2018 3:08:13 PM" >
5) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("single-framework","",False,System.String[])
single-framework
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory387/testApp.app/testApp is modified, timestamp: 2/15/2018 3:09:18 PM > 2/15/2018 3:09:16 PM" >
Fixes https://github.com/xamarin/maccore/issues/641
2018-02-20 13:43:23 +03:00
if ( use_stamp )
Driver . Touch ( path + ".stamp" ) ;
2016-05-11 14:00:20 +03:00
}
}
[mtouch/mmp] Fix tracking of whether the static registrar should run again or not. Fixes #641. (#3534) (#3536)
* [tests] Improve debug spew for the RebuildTest_WithExtensions test.
* [mtouch/mmp] Store/load if the dynamic registrar is removed or not into the cached link results.
Store/load if the dynamic registrar is removed or not into the cached link
results, so that we generate the correct main.m even if cached linker results
are used.
* [mtouch/mmp] The static registrar must not execute if we're loading cached results from the linker.
The static registrar must not execute if we're loading cached results from the
linker, because the static registrar needs information from the linker that's
not restored from the cache.
* [mtouch/mmp] Share Touch code.
* [mtouch/mmp] Make it possible to touch inexistent files (to create them).
* [mtouch/mmp] Fix tracking of whether the static registrar should run again or not.
The recent changes to support optimizing away the dynamic registrar caused the
Xamarin.MTouch.RebuildTest_WithExtensions test to regress.
The problem
-----------
* The linker now collects and stores information the static registrar needs.
* This information is not restored from disk when the linker realizes that it
can reload previously linked assemblies instead of executing again.
* The static registrar runs again (for another reason).
* The information the static registrar needs isn't available, and incorrect
output follows.
So fix 1: show an error if the static registrar runs when the linker loaded
cached results.
The exact scenario the test ran into is this:
* 1st build: everything is new and everything is built.
* 2nd build: contents of .exe changes, the linker runs again, the static
registrar runs again, but sees that the generated output didn't change, so
it doesn't write the new content to disk (this is an optimization to avoid
compiling the registrar.m file again unless needed).
* 3rd build: only the .exe timestamp changes, the linker sees nothing changes
in the contents of the .exe and loads the previously linked assemblies from
disk, the static registrar sees that the .exe's timestamp is newer than
registrar.m's timestamp and run again, but doesn't produce the right result
because it doesn't have the information it needs.
Considered solutions
--------------------
1. Only track timestamps, not file contents. This is not ideal, since it will
result in more work done: in particular for the case above, it would add a
registrar.m compilation in build #2, and linker rerun + static registrar
rerun + registrar.m compilation + final native link in build #3.
2. Always write the output of the static registrar, even if it hasn't changed.
This is not ideal either, since it will also result in more work done: for
the case above, it would add a registrar.m compilation + final native link
in build #3.
3. Always write the output of the static registrar, but track if it changed or
not, and if it didn't, just touch registrar.o instead of recompiling it.
This only means the final native link in build #3 is added (see #5 for why
this is worse than it sounds).
4. Always write the output of the static registrar, but track it it changed or
not, and if it didn't, just touch registrar.o instead of recompiling it,
and track that too, so that the final native link in build #3 isn't needed
anymore. Unfortunately this may result in incorrect behavior, because now
the msbuild tasks will detect that the executable has changed, and may run
dsymutil + strip again. The executable didn't actually change, which means
it would be the previously stripped executable, and thus we'd end up with
an empty .dSYM because we ran dsymtil on an already stripped executable.
5. Idea #4, but write the output of the final link into a temporary directory
instead of the .app, so that we could track whether we should update the
executable in the .app or not. This is not optimal either, because
executables can be *big* (I've seen multi-GB tvOS bitcode executables), and
extra copies of such files should not be taken lightly.
6. Idea #4, but tell the MSBuild tasks that dsymutil/strip doesn't need to be
rerun even if the timestamp of the executable changed. This might actually
work, but now the solution's become quite complex.
Implemented solution
--------------------
Use stamp files to detect whether a file is up-to-date or not.
In particular:
* When we don't write to a file because the new contents are identical to the
old contents, we now touch a .stamp file. This stamp file means "the
accompanying file was determined to be up-to-date when the stamp was
touched."
* When checking whether a file is up-to-date, also check for the presence of a
.stamp file, and if it exists, use the highest timestamp between the stamp
file and the actual file.
Now the test scenario becomes:
* 1st build: everything is new and everything is built.
* 2nd build: contents of .exe changes, the linker runs again, the static
registrar runs again, but sees that the generated output didn't change, so
it doesn't write the new content to disk, but it creates a registrar.m.stamp
file to indicate the point in time when registrar.m was considered up-to-
date.
* 3rd build: only the .exe timestamp changes, the linker sees nothing changes
in the contents of the .exe and loads the previously linked assemblies from
disk, the static registrar sees that the .exe's timestamp is *older* than
registrar.m.stamp's timestamp and doesn't run again.
We only use the stamp file for source code (registrar.[m|h], main.[m|h],
pinvokes.[m|h]), since using it every time has too much potential for running
into other problems (for instance we should never create .stamp files inside
the .app).
Fixes these test failures:
1) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("single","",False,System.String[])
single
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory371/testApp.app/testApp is modified, timestamp: 2/15/2018 3:04:11 PM > 2/15/2018 3:04:09 PM" >
2) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("dual","armv7,arm64",False,System.String[])
dual
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory375/testApp.app/testApp is modified, timestamp: 2/15/2018 3:06:03 PM > 2/15/2018 3:06:00 PM" >
3) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("llvm","armv7+llvm",False,System.String[])
llvm
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory379/testApp.app/testApp is modified, timestamp: 2/15/2018 3:07:14 PM > 2/15/2018 3:07:12 PM" >
4) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("debug","",True,System.String[])
debug
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory383/testApp.app/testApp is modified, timestamp: 2/15/2018 3:08:16 PM > 2/15/2018 3:08:13 PM" >
5) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("single-framework","",False,System.String[])
single-framework
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory387/testApp.app/testApp is modified, timestamp: 2/15/2018 3:09:18 PM > 2/15/2018 3:09:16 PM" >
Fixes https://github.com/xamarin/maccore/issues/641
2018-02-20 13:43:23 +03:00
public static void WriteIfDifferent ( string path , string contents , bool use_stamp = false )
2016-04-21 15:57:02 +03:00
{
var tmp = path + ".tmp" ;
try {
if ( ! File . Exists ( path ) ) {
2016-11-21 15:30:46 +03:00
Directory . CreateDirectory ( Path . GetDirectoryName ( path ) ) ;
2016-04-21 15:57:02 +03:00
File . WriteAllText ( path , contents ) ;
Log ( 3 , "File '{0}' does not exist, creating it." , path ) ;
return ;
}
File . WriteAllText ( tmp , contents ) ;
[mtouch/mmp] Fix tracking of whether the static registrar should run again or not. Fixes #641. (#3534) (#3536)
* [tests] Improve debug spew for the RebuildTest_WithExtensions test.
* [mtouch/mmp] Store/load if the dynamic registrar is removed or not into the cached link results.
Store/load if the dynamic registrar is removed or not into the cached link
results, so that we generate the correct main.m even if cached linker results
are used.
* [mtouch/mmp] The static registrar must not execute if we're loading cached results from the linker.
The static registrar must not execute if we're loading cached results from the
linker, because the static registrar needs information from the linker that's
not restored from the cache.
* [mtouch/mmp] Share Touch code.
* [mtouch/mmp] Make it possible to touch inexistent files (to create them).
* [mtouch/mmp] Fix tracking of whether the static registrar should run again or not.
The recent changes to support optimizing away the dynamic registrar caused the
Xamarin.MTouch.RebuildTest_WithExtensions test to regress.
The problem
-----------
* The linker now collects and stores information the static registrar needs.
* This information is not restored from disk when the linker realizes that it
can reload previously linked assemblies instead of executing again.
* The static registrar runs again (for another reason).
* The information the static registrar needs isn't available, and incorrect
output follows.
So fix 1: show an error if the static registrar runs when the linker loaded
cached results.
The exact scenario the test ran into is this:
* 1st build: everything is new and everything is built.
* 2nd build: contents of .exe changes, the linker runs again, the static
registrar runs again, but sees that the generated output didn't change, so
it doesn't write the new content to disk (this is an optimization to avoid
compiling the registrar.m file again unless needed).
* 3rd build: only the .exe timestamp changes, the linker sees nothing changes
in the contents of the .exe and loads the previously linked assemblies from
disk, the static registrar sees that the .exe's timestamp is newer than
registrar.m's timestamp and run again, but doesn't produce the right result
because it doesn't have the information it needs.
Considered solutions
--------------------
1. Only track timestamps, not file contents. This is not ideal, since it will
result in more work done: in particular for the case above, it would add a
registrar.m compilation in build #2, and linker rerun + static registrar
rerun + registrar.m compilation + final native link in build #3.
2. Always write the output of the static registrar, even if it hasn't changed.
This is not ideal either, since it will also result in more work done: for
the case above, it would add a registrar.m compilation + final native link
in build #3.
3. Always write the output of the static registrar, but track if it changed or
not, and if it didn't, just touch registrar.o instead of recompiling it.
This only means the final native link in build #3 is added (see #5 for why
this is worse than it sounds).
4. Always write the output of the static registrar, but track it it changed or
not, and if it didn't, just touch registrar.o instead of recompiling it,
and track that too, so that the final native link in build #3 isn't needed
anymore. Unfortunately this may result in incorrect behavior, because now
the msbuild tasks will detect that the executable has changed, and may run
dsymutil + strip again. The executable didn't actually change, which means
it would be the previously stripped executable, and thus we'd end up with
an empty .dSYM because we ran dsymtil on an already stripped executable.
5. Idea #4, but write the output of the final link into a temporary directory
instead of the .app, so that we could track whether we should update the
executable in the .app or not. This is not optimal either, because
executables can be *big* (I've seen multi-GB tvOS bitcode executables), and
extra copies of such files should not be taken lightly.
6. Idea #4, but tell the MSBuild tasks that dsymutil/strip doesn't need to be
rerun even if the timestamp of the executable changed. This might actually
work, but now the solution's become quite complex.
Implemented solution
--------------------
Use stamp files to detect whether a file is up-to-date or not.
In particular:
* When we don't write to a file because the new contents are identical to the
old contents, we now touch a .stamp file. This stamp file means "the
accompanying file was determined to be up-to-date when the stamp was
touched."
* When checking whether a file is up-to-date, also check for the presence of a
.stamp file, and if it exists, use the highest timestamp between the stamp
file and the actual file.
Now the test scenario becomes:
* 1st build: everything is new and everything is built.
* 2nd build: contents of .exe changes, the linker runs again, the static
registrar runs again, but sees that the generated output didn't change, so
it doesn't write the new content to disk, but it creates a registrar.m.stamp
file to indicate the point in time when registrar.m was considered up-to-
date.
* 3rd build: only the .exe timestamp changes, the linker sees nothing changes
in the contents of the .exe and loads the previously linked assemblies from
disk, the static registrar sees that the .exe's timestamp is *older* than
registrar.m.stamp's timestamp and doesn't run again.
We only use the stamp file for source code (registrar.[m|h], main.[m|h],
pinvokes.[m|h]), since using it every time has too much potential for running
into other problems (for instance we should never create .stamp files inside
the .app).
Fixes these test failures:
1) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("single","",False,System.String[])
single
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory371/testApp.app/testApp is modified, timestamp: 2/15/2018 3:04:11 PM > 2/15/2018 3:04:09 PM" >
2) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("dual","armv7,arm64",False,System.String[])
dual
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory375/testApp.app/testApp is modified, timestamp: 2/15/2018 3:06:03 PM > 2/15/2018 3:06:00 PM" >
3) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("llvm","armv7+llvm",False,System.String[])
llvm
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory379/testApp.app/testApp is modified, timestamp: 2/15/2018 3:07:14 PM > 2/15/2018 3:07:12 PM" >
4) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("debug","",True,System.String[])
debug
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory383/testApp.app/testApp is modified, timestamp: 2/15/2018 3:08:16 PM > 2/15/2018 3:08:13 PM" >
5) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("single-framework","",False,System.String[])
single-framework
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory387/testApp.app/testApp is modified, timestamp: 2/15/2018 3:09:18 PM > 2/15/2018 3:09:16 PM" >
Fixes https://github.com/xamarin/maccore/issues/641
2018-02-20 13:43:23 +03:00
MoveIfDifferent ( path , tmp , use_stamp ) ;
2016-05-11 14:00:20 +03:00
} catch ( Exception e ) {
File . WriteAllText ( path , contents ) ;
2020-01-31 23:02:52 +03:00
ErrorHelper . Warning ( 1014 , e , Errors . MT1014 , path , e . Message ) ;
2016-05-11 14:00:20 +03:00
} finally {
2021-01-19 16:29:11 +03:00
File . Delete ( tmp ) ;
2016-05-11 14:00:20 +03:00
}
}
2016-04-21 15:57:02 +03:00
2022-09-30 10:32:42 +03:00
public static void WriteIfDifferent ( string path , byte [ ] contents , bool use_stamp = false )
2016-05-11 14:00:20 +03:00
{
var tmp = path + ".tmp" ;
2016-04-21 15:57:02 +03:00
2016-05-11 14:00:20 +03:00
try {
if ( ! File . Exists ( path ) ) {
File . WriteAllBytes ( path , contents ) ;
Log ( 3 , "File '{0}' does not exist, creating it." , path ) ;
return ;
2016-04-21 15:57:02 +03:00
}
2016-05-11 14:00:20 +03:00
File . WriteAllBytes ( tmp , contents ) ;
[mtouch/mmp] Fix tracking of whether the static registrar should run again or not. Fixes #641. (#3534) (#3536)
* [tests] Improve debug spew for the RebuildTest_WithExtensions test.
* [mtouch/mmp] Store/load if the dynamic registrar is removed or not into the cached link results.
Store/load if the dynamic registrar is removed or not into the cached link
results, so that we generate the correct main.m even if cached linker results
are used.
* [mtouch/mmp] The static registrar must not execute if we're loading cached results from the linker.
The static registrar must not execute if we're loading cached results from the
linker, because the static registrar needs information from the linker that's
not restored from the cache.
* [mtouch/mmp] Share Touch code.
* [mtouch/mmp] Make it possible to touch inexistent files (to create them).
* [mtouch/mmp] Fix tracking of whether the static registrar should run again or not.
The recent changes to support optimizing away the dynamic registrar caused the
Xamarin.MTouch.RebuildTest_WithExtensions test to regress.
The problem
-----------
* The linker now collects and stores information the static registrar needs.
* This information is not restored from disk when the linker realizes that it
can reload previously linked assemblies instead of executing again.
* The static registrar runs again (for another reason).
* The information the static registrar needs isn't available, and incorrect
output follows.
So fix 1: show an error if the static registrar runs when the linker loaded
cached results.
The exact scenario the test ran into is this:
* 1st build: everything is new and everything is built.
* 2nd build: contents of .exe changes, the linker runs again, the static
registrar runs again, but sees that the generated output didn't change, so
it doesn't write the new content to disk (this is an optimization to avoid
compiling the registrar.m file again unless needed).
* 3rd build: only the .exe timestamp changes, the linker sees nothing changes
in the contents of the .exe and loads the previously linked assemblies from
disk, the static registrar sees that the .exe's timestamp is newer than
registrar.m's timestamp and run again, but doesn't produce the right result
because it doesn't have the information it needs.
Considered solutions
--------------------
1. Only track timestamps, not file contents. This is not ideal, since it will
result in more work done: in particular for the case above, it would add a
registrar.m compilation in build #2, and linker rerun + static registrar
rerun + registrar.m compilation + final native link in build #3.
2. Always write the output of the static registrar, even if it hasn't changed.
This is not ideal either, since it will also result in more work done: for
the case above, it would add a registrar.m compilation + final native link
in build #3.
3. Always write the output of the static registrar, but track if it changed or
not, and if it didn't, just touch registrar.o instead of recompiling it.
This only means the final native link in build #3 is added (see #5 for why
this is worse than it sounds).
4. Always write the output of the static registrar, but track it it changed or
not, and if it didn't, just touch registrar.o instead of recompiling it,
and track that too, so that the final native link in build #3 isn't needed
anymore. Unfortunately this may result in incorrect behavior, because now
the msbuild tasks will detect that the executable has changed, and may run
dsymutil + strip again. The executable didn't actually change, which means
it would be the previously stripped executable, and thus we'd end up with
an empty .dSYM because we ran dsymtil on an already stripped executable.
5. Idea #4, but write the output of the final link into a temporary directory
instead of the .app, so that we could track whether we should update the
executable in the .app or not. This is not optimal either, because
executables can be *big* (I've seen multi-GB tvOS bitcode executables), and
extra copies of such files should not be taken lightly.
6. Idea #4, but tell the MSBuild tasks that dsymutil/strip doesn't need to be
rerun even if the timestamp of the executable changed. This might actually
work, but now the solution's become quite complex.
Implemented solution
--------------------
Use stamp files to detect whether a file is up-to-date or not.
In particular:
* When we don't write to a file because the new contents are identical to the
old contents, we now touch a .stamp file. This stamp file means "the
accompanying file was determined to be up-to-date when the stamp was
touched."
* When checking whether a file is up-to-date, also check for the presence of a
.stamp file, and if it exists, use the highest timestamp between the stamp
file and the actual file.
Now the test scenario becomes:
* 1st build: everything is new and everything is built.
* 2nd build: contents of .exe changes, the linker runs again, the static
registrar runs again, but sees that the generated output didn't change, so
it doesn't write the new content to disk, but it creates a registrar.m.stamp
file to indicate the point in time when registrar.m was considered up-to-
date.
* 3rd build: only the .exe timestamp changes, the linker sees nothing changes
in the contents of the .exe and loads the previously linked assemblies from
disk, the static registrar sees that the .exe's timestamp is *older* than
registrar.m.stamp's timestamp and doesn't run again.
We only use the stamp file for source code (registrar.[m|h], main.[m|h],
pinvokes.[m|h]), since using it every time has too much potential for running
into other problems (for instance we should never create .stamp files inside
the .app).
Fixes these test failures:
1) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("single","",False,System.String[])
single
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory371/testApp.app/testApp is modified, timestamp: 2/15/2018 3:04:11 PM > 2/15/2018 3:04:09 PM" >
2) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("dual","armv7,arm64",False,System.String[])
dual
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory375/testApp.app/testApp is modified, timestamp: 2/15/2018 3:06:03 PM > 2/15/2018 3:06:00 PM" >
3) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("llvm","armv7+llvm",False,System.String[])
llvm
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory379/testApp.app/testApp is modified, timestamp: 2/15/2018 3:07:14 PM > 2/15/2018 3:07:12 PM" >
4) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("debug","",True,System.String[])
debug
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory383/testApp.app/testApp is modified, timestamp: 2/15/2018 3:08:16 PM > 2/15/2018 3:08:13 PM" >
5) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("single-framework","",False,System.String[])
single-framework
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory387/testApp.app/testApp is modified, timestamp: 2/15/2018 3:09:18 PM > 2/15/2018 3:09:16 PM" >
Fixes https://github.com/xamarin/maccore/issues/641
2018-02-20 13:43:23 +03:00
MoveIfDifferent ( path , tmp , use_stamp ) ;
2016-04-21 15:57:02 +03:00
} catch ( Exception e ) {
2016-05-11 14:00:20 +03:00
File . WriteAllBytes ( path , contents ) ;
2020-01-31 23:02:52 +03:00
ErrorHelper . Warning ( 1014 , e , Errors . MT1014 , path , e . Message ) ;
2016-04-21 15:57:02 +03:00
} finally {
2021-01-19 16:29:11 +03:00
File . Delete ( tmp ) ;
2016-04-21 15:57:02 +03:00
}
}
#endif
internal static string GetFullPath ( )
{
return System . Reflection . Assembly . GetExecutingAssembly ( ) . Location ;
}
2018-11-05 10:16:29 +03:00
static string xcode_product_version ;
public static string XcodeProductVersion {
2018-06-09 04:45:24 +03:00
get {
2018-11-05 10:16:29 +03:00
return xcode_product_version ;
2018-06-09 04:45:24 +03:00
}
}
2016-04-21 15:57:02 +03:00
static Version xcode_version ;
public static Version XcodeVersion {
get {
return xcode_version ;
}
}
2017-08-22 10:40:26 +03:00
static void SetCurrentLanguage ( )
{
// There's no way to change the current culture from the command-line
// without changing the system settings, so honor LANG if set.
// This eases testing mtouch/mmp with different locales significantly,
// and won't run into issues where changing the system language leaves
// the tester with an incomprehensible system.
var lang_variable = Environment . GetEnvironmentVariable ( "LANG" ) ;
if ( string . IsNullOrEmpty ( lang_variable ) )
return ;
// Mimic how mono transforms LANG into a culture name:
// https://github.com/mono/mono/blob/fc6e8a27fc55319141ceb29fbb7b5c63a9030b5e/mono/metadata/locales.c#L568-L576
var lang = lang_variable ;
var idx = lang . IndexOf ( '.' ) ;
if ( idx > = 0 )
lang = lang . Substring ( 0 , idx ) ;
idx = lang . IndexOf ( '@' ) ;
if ( idx > = 0 )
lang = lang . Substring ( 0 , idx ) ;
lang = lang . Replace ( '_' , '-' ) ;
try {
var culture = CultureInfo . GetCultureInfo ( lang ) ;
if ( culture ! = null ) {
CultureInfo . DefaultThreadCurrentCulture = culture ;
2017-09-18 18:14:17 +03:00
Log ( 2 , $"The current language was set to '{culture.DisplayName}' according to the LANG environment variable (LANG={lang_variable})." ) ;
2017-08-22 10:40:26 +03:00
}
} catch ( Exception e ) {
2020-01-31 23:02:52 +03:00
ErrorHelper . Warning ( 124 , e , Errors . MT0124 , lang , lang_variable , e . Message ) ;
2017-08-22 10:40:26 +03:00
}
}
2017-11-16 18:02:34 +03:00
static void LogArguments ( string [ ] arguments )
{
2018-04-14 23:13:14 +03:00
if ( Verbosity < 1 )
2017-11-16 18:02:34 +03:00
return ;
if ( ! arguments . Any ( ( v ) = > v . Length > 0 & & v [ 0 ] = = '@' ) )
return ; // no need to print arguments unless we get response files
LogArguments ( arguments , 1 ) ;
}
static void LogArguments ( string [ ] arguments , int indentation )
{
Log ( "Provided arguments:" ) ;
var indent = new string ( ' ' , indentation * 4 ) ;
foreach ( var arg in arguments ) {
Log ( indent + StringUtils . Quote ( arg ) ) ;
if ( arg . Length > 0 & & arg [ 0 ] = = '@' ) {
var fn = arg . Substring ( 1 ) ;
LogArguments ( File . ReadAllLines ( fn ) , indentation + 1 ) ;
}
}
}
[mtouch/mmp] Fix tracking of whether the static registrar should run again or not. Fixes #641. (#3534) (#3536)
* [tests] Improve debug spew for the RebuildTest_WithExtensions test.
* [mtouch/mmp] Store/load if the dynamic registrar is removed or not into the cached link results.
Store/load if the dynamic registrar is removed or not into the cached link
results, so that we generate the correct main.m even if cached linker results
are used.
* [mtouch/mmp] The static registrar must not execute if we're loading cached results from the linker.
The static registrar must not execute if we're loading cached results from the
linker, because the static registrar needs information from the linker that's
not restored from the cache.
* [mtouch/mmp] Share Touch code.
* [mtouch/mmp] Make it possible to touch inexistent files (to create them).
* [mtouch/mmp] Fix tracking of whether the static registrar should run again or not.
The recent changes to support optimizing away the dynamic registrar caused the
Xamarin.MTouch.RebuildTest_WithExtensions test to regress.
The problem
-----------
* The linker now collects and stores information the static registrar needs.
* This information is not restored from disk when the linker realizes that it
can reload previously linked assemblies instead of executing again.
* The static registrar runs again (for another reason).
* The information the static registrar needs isn't available, and incorrect
output follows.
So fix 1: show an error if the static registrar runs when the linker loaded
cached results.
The exact scenario the test ran into is this:
* 1st build: everything is new and everything is built.
* 2nd build: contents of .exe changes, the linker runs again, the static
registrar runs again, but sees that the generated output didn't change, so
it doesn't write the new content to disk (this is an optimization to avoid
compiling the registrar.m file again unless needed).
* 3rd build: only the .exe timestamp changes, the linker sees nothing changes
in the contents of the .exe and loads the previously linked assemblies from
disk, the static registrar sees that the .exe's timestamp is newer than
registrar.m's timestamp and run again, but doesn't produce the right result
because it doesn't have the information it needs.
Considered solutions
--------------------
1. Only track timestamps, not file contents. This is not ideal, since it will
result in more work done: in particular for the case above, it would add a
registrar.m compilation in build #2, and linker rerun + static registrar
rerun + registrar.m compilation + final native link in build #3.
2. Always write the output of the static registrar, even if it hasn't changed.
This is not ideal either, since it will also result in more work done: for
the case above, it would add a registrar.m compilation + final native link
in build #3.
3. Always write the output of the static registrar, but track if it changed or
not, and if it didn't, just touch registrar.o instead of recompiling it.
This only means the final native link in build #3 is added (see #5 for why
this is worse than it sounds).
4. Always write the output of the static registrar, but track it it changed or
not, and if it didn't, just touch registrar.o instead of recompiling it,
and track that too, so that the final native link in build #3 isn't needed
anymore. Unfortunately this may result in incorrect behavior, because now
the msbuild tasks will detect that the executable has changed, and may run
dsymutil + strip again. The executable didn't actually change, which means
it would be the previously stripped executable, and thus we'd end up with
an empty .dSYM because we ran dsymtil on an already stripped executable.
5. Idea #4, but write the output of the final link into a temporary directory
instead of the .app, so that we could track whether we should update the
executable in the .app or not. This is not optimal either, because
executables can be *big* (I've seen multi-GB tvOS bitcode executables), and
extra copies of such files should not be taken lightly.
6. Idea #4, but tell the MSBuild tasks that dsymutil/strip doesn't need to be
rerun even if the timestamp of the executable changed. This might actually
work, but now the solution's become quite complex.
Implemented solution
--------------------
Use stamp files to detect whether a file is up-to-date or not.
In particular:
* When we don't write to a file because the new contents are identical to the
old contents, we now touch a .stamp file. This stamp file means "the
accompanying file was determined to be up-to-date when the stamp was
touched."
* When checking whether a file is up-to-date, also check for the presence of a
.stamp file, and if it exists, use the highest timestamp between the stamp
file and the actual file.
Now the test scenario becomes:
* 1st build: everything is new and everything is built.
* 2nd build: contents of .exe changes, the linker runs again, the static
registrar runs again, but sees that the generated output didn't change, so
it doesn't write the new content to disk, but it creates a registrar.m.stamp
file to indicate the point in time when registrar.m was considered up-to-
date.
* 3rd build: only the .exe timestamp changes, the linker sees nothing changes
in the contents of the .exe and loads the previously linked assemblies from
disk, the static registrar sees that the .exe's timestamp is *older* than
registrar.m.stamp's timestamp and doesn't run again.
We only use the stamp file for source code (registrar.[m|h], main.[m|h],
pinvokes.[m|h]), since using it every time has too much potential for running
into other problems (for instance we should never create .stamp files inside
the .app).
Fixes these test failures:
1) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("single","",False,System.String[])
single
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory371/testApp.app/testApp is modified, timestamp: 2/15/2018 3:04:11 PM > 2/15/2018 3:04:09 PM" >
2) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("dual","armv7,arm64",False,System.String[])
dual
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory375/testApp.app/testApp is modified, timestamp: 2/15/2018 3:06:03 PM > 2/15/2018 3:06:00 PM" >
3) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("llvm","armv7+llvm",False,System.String[])
llvm
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory379/testApp.app/testApp is modified, timestamp: 2/15/2018 3:07:14 PM > 2/15/2018 3:07:12 PM" >
4) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("debug","",True,System.String[])
debug
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory383/testApp.app/testApp is modified, timestamp: 2/15/2018 3:08:16 PM > 2/15/2018 3:08:13 PM" >
5) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("single-framework","",False,System.String[])
single-framework
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory387/testApp.app/testApp is modified, timestamp: 2/15/2018 3:09:18 PM > 2/15/2018 3:09:16 PM" >
Fixes https://github.com/xamarin/maccore/issues/641
2018-02-20 13:43:23 +03:00
public static void Touch ( IEnumerable < string > filenames , DateTime ? timestamp = null )
{
if ( timestamp = = null )
timestamp = DateTime . Now ;
foreach ( var filename in filenames ) {
try {
var fi = new FileInfo ( filename ) ;
if ( ! fi . Exists ) {
using ( var fo = fi . OpenWrite ( ) ) {
// Create an empty file.
}
}
fi . LastWriteTime = timestamp . Value ;
} catch ( Exception e ) {
2020-01-31 23:02:52 +03:00
ErrorHelper . Warning ( 128 , Errors . MT0128 , filename , e . Message ) ;
[mtouch/mmp] Fix tracking of whether the static registrar should run again or not. Fixes #641. (#3534) (#3536)
* [tests] Improve debug spew for the RebuildTest_WithExtensions test.
* [mtouch/mmp] Store/load if the dynamic registrar is removed or not into the cached link results.
Store/load if the dynamic registrar is removed or not into the cached link
results, so that we generate the correct main.m even if cached linker results
are used.
* [mtouch/mmp] The static registrar must not execute if we're loading cached results from the linker.
The static registrar must not execute if we're loading cached results from the
linker, because the static registrar needs information from the linker that's
not restored from the cache.
* [mtouch/mmp] Share Touch code.
* [mtouch/mmp] Make it possible to touch inexistent files (to create them).
* [mtouch/mmp] Fix tracking of whether the static registrar should run again or not.
The recent changes to support optimizing away the dynamic registrar caused the
Xamarin.MTouch.RebuildTest_WithExtensions test to regress.
The problem
-----------
* The linker now collects and stores information the static registrar needs.
* This information is not restored from disk when the linker realizes that it
can reload previously linked assemblies instead of executing again.
* The static registrar runs again (for another reason).
* The information the static registrar needs isn't available, and incorrect
output follows.
So fix 1: show an error if the static registrar runs when the linker loaded
cached results.
The exact scenario the test ran into is this:
* 1st build: everything is new and everything is built.
* 2nd build: contents of .exe changes, the linker runs again, the static
registrar runs again, but sees that the generated output didn't change, so
it doesn't write the new content to disk (this is an optimization to avoid
compiling the registrar.m file again unless needed).
* 3rd build: only the .exe timestamp changes, the linker sees nothing changes
in the contents of the .exe and loads the previously linked assemblies from
disk, the static registrar sees that the .exe's timestamp is newer than
registrar.m's timestamp and run again, but doesn't produce the right result
because it doesn't have the information it needs.
Considered solutions
--------------------
1. Only track timestamps, not file contents. This is not ideal, since it will
result in more work done: in particular for the case above, it would add a
registrar.m compilation in build #2, and linker rerun + static registrar
rerun + registrar.m compilation + final native link in build #3.
2. Always write the output of the static registrar, even if it hasn't changed.
This is not ideal either, since it will also result in more work done: for
the case above, it would add a registrar.m compilation + final native link
in build #3.
3. Always write the output of the static registrar, but track if it changed or
not, and if it didn't, just touch registrar.o instead of recompiling it.
This only means the final native link in build #3 is added (see #5 for why
this is worse than it sounds).
4. Always write the output of the static registrar, but track it it changed or
not, and if it didn't, just touch registrar.o instead of recompiling it,
and track that too, so that the final native link in build #3 isn't needed
anymore. Unfortunately this may result in incorrect behavior, because now
the msbuild tasks will detect that the executable has changed, and may run
dsymutil + strip again. The executable didn't actually change, which means
it would be the previously stripped executable, and thus we'd end up with
an empty .dSYM because we ran dsymtil on an already stripped executable.
5. Idea #4, but write the output of the final link into a temporary directory
instead of the .app, so that we could track whether we should update the
executable in the .app or not. This is not optimal either, because
executables can be *big* (I've seen multi-GB tvOS bitcode executables), and
extra copies of such files should not be taken lightly.
6. Idea #4, but tell the MSBuild tasks that dsymutil/strip doesn't need to be
rerun even if the timestamp of the executable changed. This might actually
work, but now the solution's become quite complex.
Implemented solution
--------------------
Use stamp files to detect whether a file is up-to-date or not.
In particular:
* When we don't write to a file because the new contents are identical to the
old contents, we now touch a .stamp file. This stamp file means "the
accompanying file was determined to be up-to-date when the stamp was
touched."
* When checking whether a file is up-to-date, also check for the presence of a
.stamp file, and if it exists, use the highest timestamp between the stamp
file and the actual file.
Now the test scenario becomes:
* 1st build: everything is new and everything is built.
* 2nd build: contents of .exe changes, the linker runs again, the static
registrar runs again, but sees that the generated output didn't change, so
it doesn't write the new content to disk, but it creates a registrar.m.stamp
file to indicate the point in time when registrar.m was considered up-to-
date.
* 3rd build: only the .exe timestamp changes, the linker sees nothing changes
in the contents of the .exe and loads the previously linked assemblies from
disk, the static registrar sees that the .exe's timestamp is *older* than
registrar.m.stamp's timestamp and doesn't run again.
We only use the stamp file for source code (registrar.[m|h], main.[m|h],
pinvokes.[m|h]), since using it every time has too much potential for running
into other problems (for instance we should never create .stamp files inside
the .app).
Fixes these test failures:
1) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("single","",False,System.String[])
single
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory371/testApp.app/testApp is modified, timestamp: 2/15/2018 3:04:11 PM > 2/15/2018 3:04:09 PM" >
2) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("dual","armv7,arm64",False,System.String[])
dual
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory375/testApp.app/testApp is modified, timestamp: 2/15/2018 3:06:03 PM > 2/15/2018 3:06:00 PM" >
3) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("llvm","armv7+llvm",False,System.String[])
llvm
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory379/testApp.app/testApp is modified, timestamp: 2/15/2018 3:07:14 PM > 2/15/2018 3:07:12 PM" >
4) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("debug","",True,System.String[])
debug
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory383/testApp.app/testApp is modified, timestamp: 2/15/2018 3:08:16 PM > 2/15/2018 3:08:13 PM" >
5) Failed : Xamarin.MTouch.RebuildTest_WithExtensions("single-framework","",False,System.String[])
single-framework
Expected: <empty>
But was: < "/Users/builder/data/lanes/5746/4123bf7e/source/xamarin-macios/tests/mtouch/bin/Debug/tmp-test-dir/Xamarin.Tests.BundlerTool.CreateTemporaryDirectory387/testApp.app/testApp is modified, timestamp: 2/15/2018 3:09:18 PM > 2/15/2018 3:09:16 PM" >
Fixes https://github.com/xamarin/maccore/issues/641
2018-02-20 13:43:23 +03:00
}
}
}
public static void Touch ( params string [ ] filenames )
{
Touch ( ( IEnumerable < string > ) filenames ) ;
}
2018-05-29 20:08:34 +03:00
static int watch_level ;
static Stopwatch watch ;
public static int WatchLevel {
get { return watch_level ; }
set {
watch_level = value ;
if ( ( watch_level > 0 ) & & ( watch = = null ) ) {
watch = new Stopwatch ( ) ;
watch . Start ( ) ;
}
}
}
public static void Watch ( string msg , int level )
{
if ( ( watch = = null ) | | ( level > WatchLevel ) )
return ;
for ( int i = 0 ; i < level ; i + + )
Console . Write ( "!" ) ;
Console . WriteLine ( "Timestamp {0}: {1} ms" , msg , watch . ElapsedMilliseconds ) ;
}
2018-11-05 10:16:29 +03:00
internal static PDictionary FromPList ( string name )
{
if ( ! File . Exists ( name ) )
2020-01-31 23:02:52 +03:00
throw ErrorHelper . CreateError ( 24 , Errors . MT0024 , name ) ;
2018-11-05 10:16:29 +03:00
return PDictionary . FromFile ( name ) ;
}
const string XcodeDefault = "/Applications/Xcode.app" ;
static string FindSystemXcode ( )
{
var output = new StringBuilder ( ) ;
2019-10-14 17:18:46 +03:00
if ( Driver . RunCommand ( "xcode-select" , new [ ] { "-p" } , output : output ) ! = 0 ) {
2020-01-31 23:02:52 +03:00
ErrorHelper . Warning ( 59 , Errors . MX0059 , output . ToString ( ) ) ;
2018-11-05 10:16:29 +03:00
return null ;
}
return output . ToString ( ) . Trim ( ) ;
}
static string sdk_root ;
static string developer_directory ;
public static string DeveloperDirectory {
get {
return developer_directory ;
}
}
2020-04-16 15:19:45 +03:00
// This returns the /Applications/Xcode*.app/Contents/Developer/Platforms directory
public static string PlatformsDirectory {
get {
return Path . Combine ( DeveloperDirectory , "Platforms" ) ;
}
}
// This returns the /Applications/Xcode*.app/Contents/Developer/Platforms/*.platform directory
public static string GetPlatformDirectory ( Application app )
{
return Path . Combine ( PlatformsDirectory , GetPlatform ( app ) + ".platform" ) ;
}
2020-02-19 17:23:52 +03:00
static string local_build ;
2020-08-06 17:10:06 +03:00
public static string WalkUpDirHierarchyLookingForLocalBuild ( Application app )
2020-02-19 17:23:52 +03:00
{
if ( local_build = = null ) {
var localPath = Path . GetDirectoryName ( GetFullPath ( ) ) ;
while ( localPath . Length > 1 ) {
if ( File . Exists ( Path . Combine ( localPath , "Make.config" ) ) ) {
2020-08-10 11:47:35 +03:00
local_build = Path . Combine ( localPath , app . LocalBuildDir , "Library" , "Frameworks" , app . ProductName + ".framework" , "Versions" , "Current" ) ;
2020-02-19 17:23:52 +03:00
return local_build ;
}
localPath = Path . GetDirectoryName ( localPath ) ;
}
}
return local_build ;
}
// This is the 'Current' directory of the installed framework
// For XI/XM installed from package it's /Library/Frameworks/Xamarin.iOS.framework/Versions/Current or /Library/Frameworks/Xamarin.Mac.framework/Versions/Current
static string framework_dir ;
2020-08-06 17:10:06 +03:00
public static string GetFrameworkCurrentDirectory ( Application app )
{
if ( framework_dir = = null ) {
2020-08-10 11:47:35 +03:00
var env_framework_dir = Environment . GetEnvironmentVariable ( app . FrameworkLocationVariable ) ;
2020-08-06 17:10:06 +03:00
if ( ! string . IsNullOrEmpty ( env_framework_dir ) ) {
framework_dir = env_framework_dir ;
} else {
2020-04-08 17:20:04 +03:00
#if DEBUG
2020-08-06 17:10:06 +03:00
// when launched from Visual Studio, the executable is not in the final install location,
// so walk the directory hierarchy to find the root source directory.
framework_dir = WalkUpDirHierarchyLookingForLocalBuild ( app ) ;
2020-02-19 17:23:52 +03:00
#else
2020-08-06 17:10:06 +03:00
framework_dir = Path . GetDirectoryName ( Path . GetDirectoryName ( Path . GetDirectoryName ( GetFullPath ( ) ) ) ) ;
2020-02-19 17:23:52 +03:00
#endif
}
2020-08-06 17:10:06 +03:00
framework_dir = Target . GetRealPath ( framework_dir ) ;
2020-02-19 17:23:52 +03:00
}
2020-08-06 17:10:06 +03:00
return framework_dir ;
2020-02-19 17:23:52 +03:00
}
2021-02-09 16:19:12 +03:00
public static void SetFrameworkCurrentDirectory ( string value )
{
framework_dir = value ;
}
2020-04-16 15:19:45 +03:00
// This is the 'Current/bin' directory of the installed framework
// For XI/XM installed from package it's one of these two:
// /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin
// /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/bin
2020-08-06 17:10:06 +03:00
public static string GetFrameworkBinDirectory ( Application app )
{
return Path . Combine ( GetFrameworkCurrentDirectory ( app ) , "bin" ) ;
2020-02-19 17:23:52 +03:00
}
2020-04-16 15:19:45 +03:00
// This is the 'Current/lib' directory of the installed framework
// For XI/XM installed from package it's one of these two:
// /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib
// /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib
2020-08-06 17:10:06 +03:00
public static string GetFrameworkLibDirectory ( Application app )
{
return Path . Combine ( GetFrameworkCurrentDirectory ( app ) , "lib" ) ;
2020-02-19 17:23:52 +03:00
}
2020-05-07 17:20:07 +03:00
// This is the directory where the libxamarin*.[a|dylib] and libxammac*.[a|dylib] libraries are
public static string GetXamarinLibraryDirectory ( Application app )
{
2020-05-08 14:04:32 +03:00
return GetProductSdkLibDirectory ( app ) ;
2020-05-07 17:20:07 +03:00
}
// This is the directory where the Xamarin[-debug].framework frameworks are
public static string GetXamarinFrameworkDirectory ( Application app )
{
return GetProductFrameworksDirectory ( app ) ;
}
public static string GetProductFrameworksDirectory ( Application app )
{
return Path . Combine ( GetProductSdkDirectory ( app ) , "Frameworks" ) ;
}
2020-04-16 15:19:45 +03:00
// This is the directory where the platform assembly (Xamarin.*.dll) can be found
public static string GetPlatformFrameworkDirectory ( Application app )
{
switch ( app . Platform ) {
case ApplePlatform . iOS :
2020-08-06 17:10:06 +03:00
return Path . Combine ( GetFrameworkLibDirectory ( app ) , "mono" , "Xamarin.iOS" ) ;
2020-04-16 15:19:45 +03:00
case ApplePlatform . WatchOS :
2020-08-06 17:10:06 +03:00
return Path . Combine ( GetFrameworkLibDirectory ( app ) , "mono" , "Xamarin.WatchOS" ) ;
2020-04-16 15:19:45 +03:00
case ApplePlatform . TVOS :
2020-08-06 17:10:06 +03:00
return Path . Combine ( GetFrameworkLibDirectory ( app ) , "mono" , "Xamarin.TVOS" ) ;
2020-11-23 16:46:11 +03:00
case ApplePlatform . MacCatalyst :
return Path . Combine ( GetFrameworkLibDirectory ( app ) , "mono" , "Xamarin.MacCatalyst" ) ;
2020-04-16 15:19:45 +03:00
case ApplePlatform . MacOSX :
#if MMP
if ( IsUnifiedMobile )
2020-08-06 17:10:06 +03:00
return Path . Combine ( GetFrameworkLibDirectory ( app ) , "mono" , "Xamarin.Mac" ) ;
return Path . Combine ( GetFrameworkLibDirectory ( app ) , "mono" , "4.5" ) ;
2020-04-16 15:19:45 +03:00
#endif
default :
2020-08-06 17:10:06 +03:00
throw ErrorHelper . CreateError ( 71 , Errors . MX0071 , app . Platform , app . ProductName ) ;
2020-04-16 15:19:45 +03:00
}
}
// This is the directory that contains the native libraries (libmono*.[a|dylib]) that come from mono.
// For Xamarin.Mac it can be:
// * /Library/Frameworks/Mono.framework/Versions/Current/lib/ (when using system mono)
// * /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/SDKs/*.sdk/lib
// For Xamarin.iOS it can be:
// * /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/SDKs/*.sdk/lib
static string mono_lib_directory ;
public static string GetMonoLibraryDirectory ( Application app )
{
if ( mono_lib_directory = = null ) {
#if MMP
if ( IsUnifiedFullSystemFramework ) {
mono_lib_directory = RunPkgConfig ( "--variable=libdir" ) ;
} else {
mono_lib_directory = GetProductSdkLibDirectory ( app ) ;
}
#else
mono_lib_directory = GetProductSdkLibDirectory ( app ) ;
#endif
}
return mono_lib_directory ;
}
// /Library/Frameworks/Xamarin.*.framework/Versions/Current/SDKs/*.sdk/Frameworks
public static string GetMonoFrameworksDirectory ( Application app )
{
#if MMP
if ( IsUnifiedFullSystemFramework )
throw ErrorHelper . CreateError ( 99 , Errors . MX0099 , "Calling 'GetMonoFrameworksDirectory' is not allowed when targetting the full system framework." ) ;
#endif
return Path . Combine ( GetProductSdkDirectory ( app ) , "Frameworks" ) ;
}
// /Library/Frameworks/Xamarin.*.framework/Versions/Current/SDKs/*.sdk/lib
public static string GetProductSdkLibDirectory ( Application app )
{
return Path . Combine ( GetProductSdkDirectory ( app ) , "lib" ) ;
}
// /Library/Frameworks/Xamarin.*.framework/Versions/Current/SDKs/*.sdk/include
public static string GetProductSdkIncludeDirectory ( Application app )
{
return Path . Combine ( GetProductSdkDirectory ( app ) , "include" ) ;
}
// /Library/Frameworks/Xamarin.*.framework/Versions/Current/SDKs/*.sdk/Frameworks
public static string GetProductSdkFrameworksDirectory ( Application app )
{
return Path . Combine ( GetProductSdkDirectory ( app ) , "Frameworks" ) ;
}
// /Library/Frameworks/Xamarin.*.framework/Versions/Current/SDKs/*.sdk
public static string GetProductSdkDirectory ( Application app )
{
2020-08-06 17:10:06 +03:00
var sdksDir = Path . Combine ( GetFrameworkCurrentDirectory ( app ) , "SDKs" ) ;
2020-04-16 15:19:45 +03:00
string sdkName ;
switch ( app . Platform ) {
case ApplePlatform . iOS :
sdkName = app . IsDeviceBuild ? "MonoTouch.iphoneos.sdk" : "MonoTouch.iphonesimulator.sdk" ;
break ;
case ApplePlatform . WatchOS :
sdkName = app . IsDeviceBuild ? "Xamarin.WatchOS.sdk" : "Xamarin.WatchSimulator.sdk" ;
break ;
case ApplePlatform . TVOS :
sdkName = app . IsDeviceBuild ? "Xamarin.AppleTVOS.sdk" : "Xamarin.AppleTVSimulator.sdk" ;
break ;
case ApplePlatform . MacOSX :
sdkName = "Xamarin.macOS.sdk" ;
break ;
2020-11-17 11:30:08 +03:00
case ApplePlatform . MacCatalyst :
sdkName = "Xamarin.MacCatalyst.sdk" ;
break ;
2020-04-16 15:19:45 +03:00
default :
2020-08-06 17:10:06 +03:00
throw ErrorHelper . CreateError ( 71 , Errors . MX0071 , app . Platform , app . ProductName ) ;
2020-04-16 15:19:45 +03:00
}
return Path . Combine ( sdksDir , sdkName ) ;
}
// This returns the platform to use in /Applications/Xcode*.app/Contents/Developer/Platforms/*.platform
public static string GetPlatform ( Application app )
{
switch ( app . Platform ) {
case ApplePlatform . iOS :
return app . IsDeviceBuild ? "iPhoneOS" : "iPhoneSimulator" ;
case ApplePlatform . WatchOS :
return app . IsDeviceBuild ? "WatchOS" : "WatchSimulator" ;
case ApplePlatform . TVOS :
return app . IsDeviceBuild ? "AppleTVOS" : "AppleTVSimulator" ;
case ApplePlatform . MacOSX :
2020-11-17 11:30:08 +03:00
case ApplePlatform . MacCatalyst :
2020-04-16 15:19:45 +03:00
return "MacOSX" ;
default :
2020-08-06 17:10:06 +03:00
throw ErrorHelper . CreateError ( 71 , Errors . MX0071 , app . Platform , app . ProductName ) ;
2020-04-16 15:19:45 +03:00
}
}
// This returns the correct /Applications/Xcode*.app/Contents/Developer/Platforms/*.platform/Developer/SDKs/*X.Y.sdk directory
public static string GetFrameworkDirectory ( Application app )
{
var platform = GetPlatform ( app ) ;
2021-02-17 19:25:36 +03:00
return Path . Combine ( PlatformsDirectory , platform + ".platform" , "Developer" , "SDKs" , platform + app . NativeSdkVersion . ToString ( ) + ".sdk" ) ;
2020-04-16 15:19:45 +03:00
}
public static string GetProductAssembly ( Application app )
{
switch ( app . Platform ) {
case ApplePlatform . iOS :
2022-02-16 23:30:32 +03:00
return IsDotNet ? "Microsoft.iOS" : "Xamarin.iOS" ;
2020-04-16 15:19:45 +03:00
case ApplePlatform . WatchOS :
2022-02-16 23:30:32 +03:00
return IsDotNet ? "Microsoft.watchOS" : "Xamarin.WatchOS" ;
2020-04-16 15:19:45 +03:00
case ApplePlatform . TVOS :
2022-02-16 23:30:32 +03:00
return IsDotNet ? "Microsoft.tvOS" : "Xamarin.TVOS" ;
2020-04-16 15:19:45 +03:00
case ApplePlatform . MacOSX :
2022-02-16 23:30:32 +03:00
return IsDotNet ? "Microsoft.macOS" : "Xamarin.Mac" ;
2020-11-23 16:46:11 +03:00
case ApplePlatform . MacCatalyst :
2022-02-16 23:30:32 +03:00
return IsDotNet ? "Microsoft.MacCatalyst" : "Xamarin.MacCatalyst" ;
2020-04-16 15:19:45 +03:00
default :
2020-08-06 17:10:06 +03:00
throw ErrorHelper . CreateError ( 71 , Errors . MX0071 , app . Platform , app . ProductName ) ;
2020-04-16 15:19:45 +03:00
}
}
2021-02-22 14:29:32 +03:00
public static void ValidateXcode ( Application app , bool accept_any_xcode_version , bool warn_if_not_found )
2018-11-05 10:16:29 +03:00
{
if ( sdk_root = = null ) {
sdk_root = FindSystemXcode ( ) ;
if ( sdk_root = = null ) {
// FindSystemXcode showed a warning in this case. In particular do not use 'string.IsNullOrEmpty' here,
// because FindSystemXcode may return an empty string (with no warning printed) if the xcode-select command
// succeeds, but returns nothing.
sdk_root = null ;
} else if ( ! Directory . Exists ( sdk_root ) ) {
2020-01-31 23:02:52 +03:00
ErrorHelper . Warning ( 60 , Errors . MX0060 , sdk_root ) ;
2018-11-05 10:16:29 +03:00
sdk_root = null ;
} else {
if ( ! accept_any_xcode_version )
2020-01-31 23:02:52 +03:00
ErrorHelper . Warning ( 61 , Errors . MT0061 , sdk_root ) ;
2018-11-05 10:16:29 +03:00
}
if ( sdk_root = = null ) {
sdk_root = XcodeDefault ;
if ( ! Directory . Exists ( sdk_root ) ) {
if ( warn_if_not_found ) {
// mmp: and now we give up, but don't throw like mtouch, because we don't want to change behavior (this sometimes worked it appears)
2020-01-31 23:02:52 +03:00
ErrorHelper . Warning ( 56 , Errors . MX0056 ) ;
2018-11-05 10:16:29 +03:00
return ; // Can't validate the version below if we can't even find Xcode...
}
2020-01-31 23:02:52 +03:00
throw ErrorHelper . CreateError ( 56 , Errors . MX0056 ) ;
2018-11-05 10:16:29 +03:00
}
2020-01-31 23:02:52 +03:00
ErrorHelper . Warning ( 62 , Errors . MT0062 , sdk_root ) ;
2018-11-05 10:16:29 +03:00
}
} else if ( ! Directory . Exists ( sdk_root ) ) {
2020-01-31 23:02:52 +03:00
throw ErrorHelper . CreateError ( 55 , Errors . MT0055 , sdk_root ) ;
2018-11-05 10:16:29 +03:00
}
// Check what kind of path we got
if ( File . Exists ( Path . Combine ( sdk_root , "Contents" , "MacOS" , "Xcode" ) ) ) {
// path to the Xcode.app
developer_directory = Path . Combine ( sdk_root , "Contents" , "Developer" ) ;
} else if ( File . Exists ( Path . Combine ( sdk_root , ".." , "MacOS" , "Xcode" ) ) ) {
// path to Contents/Developer
developer_directory = Path . GetFullPath ( Path . Combine ( sdk_root , ".." , ".." , "Contents" , "Developer" ) ) ;
} else {
2020-01-31 23:02:52 +03:00
throw ErrorHelper . CreateError ( 57 , Errors . MT0057 , sdk_root ) ;
2018-11-05 10:16:29 +03:00
}
2020-09-15 19:33:18 +03:00
2018-11-05 10:16:29 +03:00
var plist_path = Path . Combine ( Path . GetDirectoryName ( DeveloperDirectory ) , "version.plist" ) ;
if ( File . Exists ( plist_path ) ) {
var plist = FromPList ( plist_path ) ;
var version = plist . GetString ( "CFBundleShortVersionString" ) ;
xcode_version = new Version ( version ) ;
xcode_product_version = plist . GetString ( "ProductBuildVersion" ) ;
} else {
2020-01-31 23:02:52 +03:00
throw ErrorHelper . CreateError ( 58 , Errors . MT0058 , Path . GetDirectoryName ( Path . GetDirectoryName ( DeveloperDirectory ) ) , plist_path ) ;
2018-11-05 10:16:29 +03:00
}
if ( ! accept_any_xcode_version ) {
if ( min_xcode_version ! = null & & XcodeVersion < min_xcode_version )
2020-11-10 16:21:47 +03:00
throw ErrorHelper . CreateError ( 51 , Errors . MT0051 , app . ProductConstants . Version , XcodeVersion . ToString ( ) , sdk_root , app . ProductName , min_xcode_version ) ;
2018-11-05 10:16:29 +03:00
if ( XcodeVersion < SdkVersions . XcodeVersion )
2020-11-10 16:21:47 +03:00
ErrorHelper . Warning ( 79 , Errors . MT0079 , app . ProductConstants . Version , XcodeVersion . ToString ( ) , sdk_root , SdkVersions . Xcode , app . ProductName ) ;
2018-11-05 10:16:29 +03:00
}
Driver . Log ( 1 , "Using Xcode {0} ({2}) found in {1}" , XcodeVersion , sdk_root , XcodeProductVersion ) ;
}
2019-10-14 17:18:46 +03:00
2020-02-25 09:00:58 +03:00
internal static bool TryParseBool ( string value , out bool result )
{
if ( string . IsNullOrEmpty ( value ) ) {
result = true ;
return true ;
}
switch ( value . ToLowerInvariant ( ) ) {
case "1" :
case "yes" :
case "true" :
case "enable" :
result = true ;
return true ;
case "0" :
case "no" :
case "false" :
case "disable" :
result = false ;
return true ;
default :
return bool . TryParse ( value , out result ) ;
}
}
internal static bool ParseBool ( string value , string name , bool show_error = true )
{
bool result ;
if ( ! TryParseBool ( value , out result ) )
throw ErrorHelper . CreateError ( 26 , Errors . MX0026 , name , value ) ;
return result ;
}
2020-03-17 17:49:39 +03:00
static readonly Dictionary < string , string > tools = new Dictionary < string , string > ( ) ;
2020-08-06 17:10:06 +03:00
static string FindTool ( Application app , string tool )
2020-03-17 17:49:39 +03:00
{
string path ;
lock ( tools ) {
if ( tools . TryGetValue ( tool , out path ) )
return path ;
}
2020-08-06 17:10:06 +03:00
path = LocateTool ( app , tool ) ;
static string LocateTool ( Application app , string tool )
2020-03-17 17:49:39 +03:00
{
2020-08-06 17:10:06 +03:00
if ( XcrunFind ( app , tool , out var path ) )
2020-03-17 17:49:39 +03:00
return path ;
// either /Developer (Xcode 4.2 and earlier), /Applications/Xcode.app/Contents/Developer (Xcode 4.3) or user override
path = Path . Combine ( DeveloperDirectory , "usr" , "bin" , tool ) ;
if ( File . Exists ( path ) )
return path ;
// Xcode 4.3 (without command-line tools) also has a copy of 'strip'
path = Path . Combine ( DeveloperDirectory , "Toolchains" , "XcodeDefault.xctoolchain" , "usr" , "bin" , tool ) ;
if ( File . Exists ( path ) )
return path ;
// Xcode "Command-Line Tools" install a copy in /usr/bin (and it can be there afterward)
path = Path . Combine ( "/usr" , "bin" , tool ) ;
if ( File . Exists ( path ) )
return path ;
return null ;
}
// We can end up finding the same tool multiple times.
// That's not a problem.
lock ( tools )
tools [ tool ] = path ;
if ( path = = null )
throw ErrorHelper . CreateError ( 5307 , Errors . MX5307 /* Missing '{0}' tool. Please install Xcode 'Command-Line Tools' component */ , tool ) ;
return path ;
}
2020-08-06 17:10:06 +03:00
static bool XcrunFind ( Application app , string tool , out string path )
2020-03-17 17:49:39 +03:00
{
2020-08-06 17:10:06 +03:00
return XcrunFind ( app , ApplePlatform . None , false , tool , out path ) ;
2020-03-17 17:49:39 +03:00
}
2020-08-06 17:10:06 +03:00
static bool XcrunFind ( Application app , ApplePlatform platform , bool is_simulator , string tool , out string path )
2020-03-17 17:49:39 +03:00
{
2020-06-18 13:34:07 +03:00
var env = new Dictionary < string , string > ( ) ;
2020-03-17 17:49:39 +03:00
// Unset XCODE_DEVELOPER_DIR_PATH. See https://github.com/xamarin/xamarin-macios/issues/3931.
2020-06-18 13:34:07 +03:00
env . Add ( "XCODE_DEVELOPER_DIR_PATH" , null ) ;
2020-03-17 17:49:39 +03:00
// Set DEVELOPER_DIR if we have it
2020-06-18 13:34:07 +03:00
if ( ! string . IsNullOrEmpty ( DeveloperDirectory ) )
env . Add ( "DEVELOPER_DIR" , DeveloperDirectory ) ;
2020-03-17 17:49:39 +03:00
path = null ;
var args = new List < string > ( ) ;
if ( platform ! = ApplePlatform . None ) {
args . Add ( "-sdk" ) ;
switch ( platform ) {
case ApplePlatform . iOS :
args . Add ( is_simulator ? "iphonesimulator" : "iphoneos" ) ;
break ;
case ApplePlatform . MacOSX :
args . Add ( "macosx" ) ;
break ;
case ApplePlatform . TVOS :
args . Add ( is_simulator ? "appletvsimulator" : "appletvos" ) ;
break ;
case ApplePlatform . WatchOS :
args . Add ( is_simulator ? "watchsimulator" : "watchos" ) ;
break ;
default :
2020-08-06 17:10:06 +03:00
throw ErrorHelper . CreateError ( 71 , Errors . MX0071 /* Unknown platform: {0}. This usually indicates a bug in {1}; please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new with a test case. */ , platform . ToString ( ) , app . ProductName ) ;
2020-03-17 17:49:39 +03:00
}
}
args . Add ( "-f" ) ;
args . Add ( tool ) ;
2020-03-20 19:46:43 +03:00
var stdout = new StringBuilder ( ) ;
var stderr = new StringBuilder ( ) ;
var both = new StringBuilder ( ) ;
// xcrun can write unrelated stuff to stderr even if it succeeds, so we need to separate stdout and stderr.
// We also want to print out what happened if something went wrong, and in that case we don't want stdout
// and stderr captured separately, because related lines could end up printed far from eachother in time,
// and that's confusing. So capture stdout and stderr by themselves, and also capture both together.
2020-06-18 13:34:07 +03:00
int ret = RunCommand ( "xcrun" , args , env ,
2020-03-20 19:46:43 +03:00
( v ) = > {
lock ( both ) {
both . AppendLine ( v ) ;
stdout . AppendLine ( v ) ;
}
} ,
( v ) = > {
lock ( both ) {
both . AppendLine ( v ) ;
stderr . AppendLine ( v ) ;
}
} ) ;
2020-03-17 17:49:39 +03:00
if ( ret = = 0 ) {
2020-03-20 19:46:43 +03:00
path = stdout . ToString ( ) . Trim ( ) ;
2020-03-23 14:29:23 +03:00
if ( ! File . Exists ( path ) ) {
ErrorHelper . Warning ( 5315 , Errors . MX5315 /* The tool xcrun failed to return a valid result (the file {0} does not exist). Check build log for details. */ , tool , path ) ;
return false ;
}
2020-03-17 17:49:39 +03:00
} else {
2020-03-20 19:46:43 +03:00
Log ( 1 , "Failed to locate the developer tool '{0}', 'xcrun {1}' returned with the exit code {2}:\n{3}" , tool , string . Join ( " " , args ) , ret , both . ToString ( ) ) ;
2020-03-17 17:49:39 +03:00
}
return ret = = 0 ;
}
2022-09-30 10:32:42 +03:00
public static void RunXcodeTool ( Application app , string tool , params string [ ] arguments )
2020-03-17 17:49:39 +03:00
{
2020-08-06 17:10:06 +03:00
RunXcodeTool ( app , tool , ( IList < string > ) arguments ) ;
2020-03-17 17:49:39 +03:00
}
2020-08-06 17:10:06 +03:00
public static void RunXcodeTool ( Application app , string tool , IList < string > arguments )
2020-03-17 17:49:39 +03:00
{
2020-08-06 17:10:06 +03:00
var executable = FindTool ( app , tool ) ;
2020-03-17 17:49:39 +03:00
var rv = RunCommand ( executable , arguments ) ;
if ( rv ! = 0 )
throw ErrorHelper . CreateError ( 5309 , Errors . MX5309 /* Failed to execute the tool '{0}', it failed with an error code '{1}'. Please check the build log for details. */ , tool , rv ) ;
}
2020-08-06 17:10:06 +03:00
public static void RunClang ( Application app , IList < string > arguments )
2020-03-17 17:49:39 +03:00
{
2020-08-06 17:10:06 +03:00
RunXcodeTool ( app , "clang" , arguments ) ;
2020-03-17 17:49:39 +03:00
}
2020-08-06 17:10:06 +03:00
public static void RunInstallNameTool ( Application app , IList < string > arguments )
2020-03-17 17:49:39 +03:00
{
2020-08-06 17:10:06 +03:00
RunXcodeTool ( app , "install_name_tool" , arguments ) ;
2020-03-17 17:49:39 +03:00
}
2020-08-06 17:10:06 +03:00
public static void RunBitcodeStrip ( Application app , IList < string > arguments )
2020-03-17 17:49:39 +03:00
{
2020-08-06 17:10:06 +03:00
RunXcodeTool ( app , "bitcode_strip" , arguments ) ;
2020-03-17 17:49:39 +03:00
}
2020-08-06 17:10:06 +03:00
public static void RunLipo ( Application app , string output , IEnumerable < string > inputs )
2020-03-17 17:49:39 +03:00
{
var sb = new List < string > ( ) ;
sb . AddRange ( inputs ) ;
sb . Add ( "-create" ) ;
sb . Add ( "-output" ) ;
sb . Add ( output ) ;
2020-08-06 17:10:06 +03:00
RunLipo ( app , sb ) ;
2020-03-17 17:49:39 +03:00
}
Xamarin.Mac native Apple Silicon targetting support (#10115)
* Add support for Xamarin.Mac arm64
* Add compile product definition task
Xamarin.Mac can be provided with a ProductDefinition file for the generated pkg. Normally, providing a product definition was optional. However, with Apple Silicon, we have an extra issue : `productbuild` needs to know what architectures your package target. If not provided with them, it will guess to the best of its abilities. However, on Catalina and lower, the guess is x86_64, even if you have an arm64 slice. To fix this, we add a new task to compile the product definition and use this file to create the pkg. If you provide your own Product Definition, we can check and warn if the architectures don't match what we expect. If the file doesn't exist or there is no architecture, we set it ourselves based on our target architectures.
* Don't reference dynamic objC_send on arm64
When building in debug, we currently try to link dynamic objC_send symbols when targeting a 64-bit architecture. However, this is actually only defined on Intel architectures, not on arm64, so we end up failing because we're referring symbols that don't exist. Rework the `GetRequiredSymbols` to take an abi, and tag those symbols to only be valid on i386/x86_64, so they don't get referred at all when building on arm64, but still get referred in x86_64.
* Fix improper delete/move with already existing directories
* Fix stret requirement for Xamarin.Mac in arm64.
The generator supposes that we're running in x64 mode, refactor to take into account the possibility of running in arm64.
* Implement OS version generation in Product.plist, based on MinimumSystemVersion of the app
* Re-generalize some mmp registrar rules
`Microsoft.macOS.registrar` was missed by the current rule set
* Fix mmp tests
* Set E7072 as not translated
Tests were failing otherwise
* Rename Xamarin.Mac lib/x86_64 folder to 64bits (currently all targeted archs are the same)
* Fix style issues
* Fix `ToLower` usage for invariant usage
* Fix xtro-sharpie test
2021-03-18 04:48:02 +03:00
public static void RunLipoAndCreateDsym ( Application app , string output , IEnumerable < string > inputs )
{
RunLipo ( app , output , inputs ) ;
var dsymFolders = inputs . Select ( input = > input + ".dSYM" ) . Where ( Directory . Exists ) . ToArray ( ) ;
if ( dsymFolders . Length > 1 ) {
// Lipo the dSYMs into one big happy dSYM
var dsymLibsDir = dsymFolders . Select ( dsym = > Path . Combine ( dsym , "Contents" , "Resources" , "DWARF" ) ) . ToArray ( ) ;
var allLibs = dsymLibsDir . Where ( Directory . Exists ) . SelectMany ( dir = > Directory . EnumerateFiles ( dir ) ) . Select ( dir = > Path . GetFileName ( dir ) ) . Distinct ( ) . ToArray ( ) ;
foreach ( var lib in allLibs ) {
var outputLib = Path . Combine ( dsymLibsDir [ 0 ] , lib ) ;
var allDsymInputs = dsymLibsDir . Select ( libDir = > Path . Combine ( libDir , lib ) ) . Where ( File . Exists ) . ToArray ( ) ;
Driver . RunLipo ( app , outputLib , allDsymInputs ) ;
}
}
// Move the dSYM next to its executable
if ( dsymFolders . Length > 0 ) {
var outputDsymDir = output + ".dSYM" ;
if ( Directory . Exists ( outputDsymDir ) )
Directory . Delete ( outputDsymDir , true ) ;
Directory . Move ( dsymFolders [ 0 ] , outputDsymDir ) ;
RunCommand ( "/usr/bin/mdimport" , outputDsymDir ) ;
}
}
2020-08-06 17:10:06 +03:00
public static void RunLipo ( Application app , IList < string > options )
2020-03-17 17:49:39 +03:00
{
2020-08-06 17:10:06 +03:00
RunXcodeTool ( app , "lipo" , options ) ;
2020-03-17 17:49:39 +03:00
}
2020-08-06 17:10:06 +03:00
public static void CreateDsym ( Application app , string output_dir , string appname , string dsym_dir )
2020-03-17 17:49:39 +03:00
{
2020-08-06 17:10:06 +03:00
RunDsymUtil ( app , Path . Combine ( output_dir , appname ) , "-num-threads" , "4" , "-z" , "-o" , dsym_dir ) ;
2020-03-17 17:49:39 +03:00
RunCommand ( "/usr/bin/mdimport" , dsym_dir ) ;
}
2020-08-06 17:10:06 +03:00
public static void RunDsymUtil ( Application app , params string [ ] options )
2020-03-17 17:49:39 +03:00
{
2020-08-06 17:10:06 +03:00
RunXcodeTool ( app , "dsymutil" , options ) ;
2020-03-17 17:49:39 +03:00
}
2020-08-06 17:10:06 +03:00
public static void RunStrip ( Application app , IList < string > options )
2020-03-17 17:49:39 +03:00
{
2020-08-06 17:10:06 +03:00
RunXcodeTool ( app , "strip" , options ) ;
2020-03-17 17:49:39 +03:00
}
2020-05-04 19:31:48 +03:00
public static string CorlibName {
get {
if ( IsDotNet )
return "System.Private.CoreLib" ;
return "mscorlib" ;
}
}
2020-05-05 17:52:56 +03:00
public static Frameworks GetFrameworks ( Application app )
{
var rv = Frameworks . GetFrameworks ( app . Platform , app . IsSimulatorBuild ) ;
if ( rv = = null )
2020-08-06 17:10:06 +03:00
throw ErrorHelper . CreateError ( 71 , Errors . MX0071 , app . Platform , app . ProductName ) ;
2020-05-05 17:52:56 +03:00
return rv ;
}
2016-04-21 15:57:02 +03:00
}
}