Create empty .a on Darwin when there is no obj file.

On Darwin ar would fail if there is no object file to add.
We work around by adding a dummy.o.

Port to Soong of build/ 4aaa1a1fd8e7eb23ac5557cd326d1a48efdb54cd

Change-Id: I68bbebea2726058c25863d7026a645a520d05167
diff --git a/cc/builder.go b/cc/builder.go
index b97f29b..cd12635 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -88,7 +88,7 @@
 	darwinAppendAr = pctx.StaticRule("darwinAppendAr",
 		blueprint.RuleParams{
 			Command:     "cp -f ${inAr} ${out}.tmp && ${macArPath} $arFlags ${out}.tmp $in && mv ${out}.tmp ${out}",
-			CommandDeps: []string{"${macArPath}"},
+			CommandDeps: []string{"${macArPath}", "${inAr}"},
 			Description: "ar $out",
 		},
 		"arFlags", "inAr")
@@ -120,6 +120,12 @@
 		},
 		"args", "crossCompile")
 
+	emptyFile = pctx.StaticRule("emptyFile",
+		blueprint.RuleParams{
+			Command:     "rm -f $out && touch $out",
+			Description: "empty file $out",
+		})
+
 	copyGccLibPath = pctx.SourcePathVariable("copyGccLibPath", "build/soong/scripts/copygcclib.sh")
 
 	copyGccLib = pctx.StaticRule("copyGccLib",
@@ -261,6 +267,37 @@
 
 	arFlags := "cqs"
 
+	if len(objFiles) == 0 {
+		dummy := common.PathForModuleOut(ctx, "dummy" + objectExtension)
+		dummyAr := common.PathForModuleOut(ctx, "dummy" + staticLibraryExtension)
+
+		ctx.ModuleBuild(pctx, common.ModuleBuildParams{
+			Rule:   emptyFile,
+			Output: dummy,
+		})
+
+		ctx.ModuleBuild(pctx, common.ModuleBuildParams{
+			Rule:   darwinAr,
+			Output: dummyAr,
+			Input:  dummy,
+			Args: map[string]string{
+				"arFlags": arFlags,
+			},
+		})
+
+		ctx.ModuleBuild(pctx, common.ModuleBuildParams{
+			Rule:   darwinAppendAr,
+			Output: outputPath,
+			Input:  dummy,
+			Args: map[string]string{
+				"arFlags": "d",
+				"inAr":    dummyAr.String(),
+			},
+		})
+
+		return
+	}
+
 	// ARG_MAX on darwin is 262144, use half that to be safe
 	objFilesLists, err := splitListForSize(objFiles.Strings(), 131072)
 	if err != nil {
@@ -291,7 +328,6 @@
 				Rule:      darwinAppendAr,
 				Outputs:   []string{out},
 				Inputs:    l,
-				Implicits: []string{in},
 				Args: map[string]string{
 					"arFlags": arFlags,
 					"inAr":    in,