@@ -62,9 +62,10 @@ public static List<ITaskItem> EmbedBinary (
62
62
TaskLoggingHelper log ,
63
63
ICollection < string > supportedAbis ,
64
64
string androidBinUtilsDirectory ,
65
- string inputFile ,
65
+ string ? inputFile ,
66
66
EmbedItem embedItem ,
67
- string outputDirectory )
67
+ string outputDirectory ,
68
+ bool missingContentOK )
68
69
{
69
70
if ( supportedAbis . Count < 1 ) {
70
71
throw new ArgumentException ( "At least one target ABI must be present" , nameof ( supportedAbis ) ) ;
@@ -80,7 +81,8 @@ public static List<ITaskItem> EmbedBinary (
80
81
abi ,
81
82
inputFile ,
82
83
outputDirectory ,
83
- embedItem
84
+ embedItem ,
85
+ missingContentOK
84
86
) ;
85
87
}
86
88
@@ -91,9 +93,10 @@ public static List<ITaskItem> EmbedBinary (
91
93
TaskLoggingHelper log ,
92
94
string abi ,
93
95
string androidBinUtilsDirectory ,
94
- string inputFile ,
96
+ string ? inputFile ,
95
97
EmbedItem embedItem ,
96
- string outputDirectory )
98
+ string outputDirectory ,
99
+ bool missingContentOK )
97
100
{
98
101
if ( String . IsNullOrEmpty ( abi ) ) {
99
102
throw new ArgumentException ( "Must be a supported ABI name" , nameof ( abi ) ) ;
@@ -107,7 +110,8 @@ public static List<ITaskItem> EmbedBinary (
107
110
abi ,
108
111
inputFile ,
109
112
outputDirectory ,
110
- embedItem
113
+ embedItem ,
114
+ missingContentOK
111
115
) ;
112
116
return ret ;
113
117
}
@@ -119,10 +123,11 @@ static void EmbedBinary (
119
123
string abi ,
120
124
string inputFile ,
121
125
string outputDirectory ,
122
- EmbedItem embedItem )
126
+ EmbedItem embedItem ,
127
+ bool missingContentOK )
123
128
{
124
129
string outputFile = Path . Combine ( outputDirectory , $ "embed_{ embedItem . BaseFileName } .{ abi . ToLowerInvariant ( ) } .o") ;
125
- DoEmbed ( log , MonoAndroidHelper . AbiToTargetArch ( abi ) , llvmMcPath , inputFile , outputFile , embedItem ) ;
130
+ DoEmbed ( log , MonoAndroidHelper . AbiToTargetArch ( abi ) , llvmMcPath , inputFile , outputFile , embedItem , missingContentOK ) ;
126
131
if ( ! File . Exists ( outputFile ) ) {
127
132
return ;
128
133
}
@@ -137,33 +142,54 @@ static void DoEmbed (
137
142
TaskLoggingHelper log ,
138
143
AndroidTargetArch arch ,
139
144
string llvmMcPath ,
140
- string inputFile ,
145
+ string ? inputFile ,
141
146
string outputFile ,
142
- EmbedItem item )
147
+ EmbedItem item ,
148
+ bool missingContentOK )
143
149
{
144
150
if ( ! llvmMcConfigs . TryGetValue ( arch , out LlvmMcTargetConfig cfg ) ) {
145
151
throw new NotSupportedException ( $ "Internal error: unsupported target arch '{ arch } '") ;
146
152
}
147
153
148
- inputFile = Path . GetFullPath ( inputFile ) ;
154
+ bool haveInputFile = ! String . IsNullOrEmpty ( inputFile ) ;
155
+ if ( ! haveInputFile ) {
156
+ if ( ! missingContentOK ) {
157
+ throw new InvalidOperationException ( "Internal error: input file must be specified" ) ;
158
+ }
159
+ } else {
160
+ inputFile = Path . GetFullPath ( inputFile ) ;
161
+ }
149
162
outputFile = Path . GetFullPath ( outputFile ) ;
150
163
151
- var fi = new FileInfo ( inputFile ) ;
152
- long inputFileSize = fi . Length ;
164
+ long inputFileSize = 0 ;
165
+ string ? sanitizedInputFilePath = null ;
166
+
167
+ if ( haveInputFile ) {
168
+ var fi = new FileInfo ( inputFile ) ;
169
+ if ( fi . Exists ) {
170
+ inputFileSize = fi . Length ;
171
+ sanitizedInputFilePath = inputFile . Replace ( "\\ " , "\\ \\ " ) ;
172
+ } else if ( ! missingContentOK ) {
173
+ throw new InvalidOperationException ( $ "Internal error: input file '{ inputFile } ' does not exist") ;
174
+ }
175
+ }
176
+
153
177
string asmInputFile = Path . ChangeExtension ( outputFile , ".s" ) ;
154
- string sanitizedInputFilePath = inputFile . Replace ( "\\ " , "\\ \\ " ) ;
155
178
156
179
using var fs = File . Open ( asmInputFile , FileMode . Create , FileAccess . Write , FileShare . Read ) ;
157
180
using var sw = new StreamWriter ( fs , asmFileEncoding ) ;
158
181
159
182
string symbolName = item . SymbolName ;
160
183
sw . WriteLine ( $ ".section .rodata,\" a\" ,{ cfg . AssemblerDirectivePrefix } progbits") ;
161
- sw . WriteLine ( ".p2align 3, 0x00" ) ; // Put the data at 4k boundary
184
+ sw . WriteLine ( ".p2align 3, 0x00" ) ; // Put the data at the 4k boundary
162
185
sw . WriteLine ( ) ;
163
186
sw . WriteLine ( $ ".global { symbolName } ") ;
164
187
sw . WriteLine ( $ ".type { symbolName } ,{ cfg . AssemblerDirectivePrefix } object") ;
165
188
sw . WriteLine ( $ "{ symbolName } :") ;
166
- sw . WriteLine ( $ "\t .incbin \" { sanitizedInputFilePath } \" ") ;
189
+
190
+ if ( ! String . IsNullOrEmpty ( sanitizedInputFilePath ) ) {
191
+ sw . WriteLine ( $ "\t .incbin \" { sanitizedInputFilePath } \" ") ;
192
+ }
167
193
sw . WriteLine ( $ "\t .size { symbolName } , { inputFileSize } ") ;
168
194
sw . WriteLine ( ) ;
169
195
0 commit comments