@@ -552,20 +552,20 @@ pub const Builder = struct {
552
552
};
553
553
}
554
554
555
- pub fn installCLibrary (self : & Builder , lib : & CLibExeObjStep ) {
556
- self .getInstallStep ().dependOn (& self .addInstallCLibrary ( lib ).step );
555
+ pub fn installArtifact (self : & Builder , artifact : & LibExeObjStep ) {
556
+ self .getInstallStep ().dependOn (& self .addInstallArtifact ( artifact ).step );
557
557
}
558
558
559
- pub fn addInstallCLibrary (self : & Builder , lib : & CLibExeObjStep ) - > & InstallCArtifactStep {
560
- return InstallCArtifactStep .create (self , lib );
559
+ pub fn addInstallArtifact (self : & Builder , artifact : & LibExeObjStep ) - > & InstallArtifactStep ( LibExeObjStep ) {
560
+ return InstallArtifactStep ( LibExeObjStep ) .create (self , artifact );
561
561
}
562
562
563
- pub fn installCExecutable (self : & Builder , exe : & CLibExeObjStep ) {
564
- self .getInstallStep ().dependOn (& self .addInstallCExecutable ( exe ).step );
563
+ pub fn installCArtifact (self : & Builder , artifact : & CLibExeObjStep ) {
564
+ self .getInstallStep ().dependOn (& self .addInstallCArtifact ( artifact ).step );
565
565
}
566
566
567
- pub fn addInstallCExecutable (self : & Builder , exe : & CLibExeObjStep ) - > & InstallCArtifactStep {
568
- return InstallCArtifactStep .create (self , exe );
567
+ pub fn addInstallCArtifact (self : & Builder , artifact : & CLibExeObjStep ) - > & InstallArtifactStep ( CLibExeObjStep ) {
568
+ return InstallArtifactStep ( CLibExeObjStep ) .create (self , artifact );
569
569
}
570
570
571
571
///::dest_rel_path is relative to prefix path or it can be an absolute path
@@ -588,14 +588,24 @@ pub const Builder = struct {
588
588
%% self .installed_files .append (full_path );
589
589
}
590
590
591
- fn copyFile (self : & Builder , source_path : []const u8 , dest_path : []const u8 ) {
591
+ fn copyFile (self : & Builder , source_path : []const u8 , dest_path : []const u8 ) - > % void {
592
+ return self .copyFileMode (source_path , dest_path , 0o666 );
593
+ }
594
+
595
+ fn copyFileMode (self : & Builder , source_path : []const u8 , dest_path : []const u8 , mode : usize ) - > % void {
596
+ if (self .verbose ) {
597
+ %% io .stderr .printf ("cp {} {}\n " , source_path , dest_path );
598
+ }
599
+
592
600
const dirname = os .path .dirname (dest_path );
593
601
const abs_source_path = self .pathFromRoot (source_path );
594
602
os .makePath (self .allocator , dirname ) %% | err | {
595
- debug .panic ("Unable to create path {}: {}" , dirname , @errorName (err ));
603
+ %% io .stderr .printf ("Unable to create path {}: {}\n " , dirname , @errorName (err ));
604
+ return err ;
596
605
};
597
- os .copyFile (self .allocator , abs_source_path , dest_path ) %% | err | {
598
- debug .panic ("Unable to copy {} to {}: {}" , abs_source_path , dest_path , @errorName (err ));
606
+ os .copyFileMode (self .allocator , abs_source_path , dest_path , mode ) %% | err | {
607
+ %% io .stderr .printf ("Unable to copy {} to {}: {}\n " , abs_source_path , dest_path , @errorName (err ));
608
+ return err ;
599
609
};
600
610
}
601
611
@@ -664,8 +674,8 @@ pub const LibExeObjStep = struct {
664
674
version : Version ,
665
675
out_h_filename : []const u8 ,
666
676
out_filename : []const u8 ,
667
- out_filename_major_only : []const u8 ,
668
- out_filename_name_only : []const u8 ,
677
+ major_only_filename : []const u8 ,
678
+ name_only_filename : []const u8 ,
669
679
object_files : List ([]const u8 ),
670
680
assembly_files : List ([]const u8 ),
671
681
@@ -721,8 +731,8 @@ pub const LibExeObjStep = struct {
721
731
.version = * ver ,
722
732
.out_filename = undefined ,
723
733
.out_h_filename = builder .fmt ("{}.h" , name ),
724
- .out_filename_major_only = undefined ,
725
- .out_filename_name_only = undefined ,
734
+ .major_only_filename = undefined ,
735
+ .name_only_filename = undefined ,
726
736
.object_files = List ([]const u8 ).init (builder .allocator ),
727
737
.assembly_files = List ([]const u8 ).init (builder .allocator ),
728
738
};
@@ -744,8 +754,8 @@ pub const LibExeObjStep = struct {
744
754
} else {
745
755
self .out_filename = self .builder .fmt ("lib{}.so.{d}.{d}.{d}" ,
746
756
self .name , self .version .major , self .version .minor , self .version .patch );
747
- self .out_filename_major_only = self .builder .fmt ("lib{}.so.{d}" , self .name , self .version .major );
748
- self .out_filename_name_only = self .builder .fmt ("lib{}.so" , self .name );
757
+ self .major_only_filename = self .builder .fmt ("lib{}.so.{d}" , self .name , self .version .major );
758
+ self .name_only_filename = self .builder .fmt ("lib{}.so" , self .name );
749
759
}
750
760
},
751
761
}
@@ -934,8 +944,8 @@ pub const LibExeObjStep = struct {
934
944
% return builder .spawnChild (builder .zig_exe , zig_args .toSliceConst ());
935
945
936
946
if (self .kind == Kind .Lib and ! self .static ) {
937
- % return doAtomicSymLinks (builder .allocator , output_path , self .out_filename_major_only ,
938
- self .out_filename_name_only );
947
+ % return doAtomicSymLinks (builder .allocator , output_path , self .major_only_filename ,
948
+ self .name_only_filename );
939
949
}
940
950
}
941
951
};
@@ -1424,45 +1434,56 @@ pub const CommandStep = struct {
1424
1434
}
1425
1435
};
1426
1436
1427
- pub const InstallCArtifactStep = struct {
1428
- step : Step ,
1429
- builder : & Builder ,
1430
- artifact : & CLibExeObjStep ,
1431
- dest_file : []const u8 ,
1432
-
1433
- pub fn create (builder : & Builder , artifact : & CLibExeObjStep ) - > & InstallCArtifactStep {
1434
- const self = %% builder .allocator .create (InstallCArtifactStep );
1435
- const dest_dir = switch (artifact .kind ) {
1436
- CLibExeObjStep .Kind .Obj = > unreachable ,
1437
- CLibExeObjStep .Kind .Exe = > builder .exe_dir ,
1438
- CLibExeObjStep .Kind .Lib = > builder .lib_dir ,
1439
- };
1440
- * self = InstallCArtifactStep {
1441
- .builder = builder ,
1442
- .step = Step .init (builder .fmt ("install {}" , artifact .step .name ), builder .allocator , make ),
1443
- .artifact = artifact ,
1444
- .dest_file = %% os .path .join (builder .allocator , builder .lib_dir , artifact .out_filename ),
1445
- };
1446
- self .step .dependOn (& artifact .step );
1447
- builder .pushInstalledFile (self .dest_file );
1448
- if (self .artifact .kind == CLibExeObjStep .Kind .Lib and ! self .artifact .static ) {
1449
- builder .pushInstalledFile (%% os .path .join (builder .allocator , builder .lib_dir , artifact .major_only_filename ));
1450
- builder .pushInstalledFile (%% os .path .join (builder .allocator , builder .lib_dir , artifact .name_only_filename ));
1437
+ fn InstallArtifactStep (comptime Artifact : type ) - > type {
1438
+ struct {
1439
+ step : Step ,
1440
+ builder : & Builder ,
1441
+ artifact : & Artifact ,
1442
+ dest_file : []const u8 ,
1443
+
1444
+ const Self = this ;
1445
+
1446
+ pub fn create (builder : & Builder , artifact : & Artifact ) - > & Self {
1447
+ const self = %% builder .allocator .create (Self );
1448
+ const dest_dir = switch (artifact .kind ) {
1449
+ Artifact .Kind .Obj = > unreachable ,
1450
+ Artifact .Kind .Exe = > builder .exe_dir ,
1451
+ Artifact .Kind .Lib = > builder .lib_dir ,
1452
+ };
1453
+ * self = Self {
1454
+ .builder = builder ,
1455
+ .step = Step .init (builder .fmt ("install {}" , artifact .step .name ), builder .allocator , make ),
1456
+ .artifact = artifact ,
1457
+ .dest_file = %% os .path .join (builder .allocator , dest_dir , artifact .out_filename ),
1458
+ };
1459
+ self .step .dependOn (& artifact .step );
1460
+ builder .pushInstalledFile (self .dest_file );
1461
+ if (self .artifact .kind == Artifact .Kind .Lib and ! self .artifact .static ) {
1462
+ builder .pushInstalledFile (%% os .path .join (builder .allocator , builder .lib_dir ,
1463
+ artifact .major_only_filename ));
1464
+ builder .pushInstalledFile (%% os .path .join (builder .allocator , builder .lib_dir ,
1465
+ artifact .name_only_filename ));
1466
+ }
1467
+ return self ;
1451
1468
}
1452
- return self ;
1453
- }
1454
1469
1455
- fn make (step : & Step ) - > % void {
1456
- const self = @fieldParentPtr (InstallCArtifactStep , "step" , step );
1457
- const builder = self .builder ;
1470
+ fn make (step : & Step ) - > % void {
1471
+ const self = @fieldParentPtr (Self , "step" , step );
1472
+ const builder = self .builder ;
1458
1473
1459
- builder .copyFile (self .artifact .getOutputPath (), self .dest_file );
1460
- if (self .artifact .kind == CLibExeObjStep .Kind .Lib and ! self .artifact .static ) {
1461
- % return doAtomicSymLinks (builder .allocator , self .dest_file ,
1462
- self .artifact .major_only_filename , self .artifact .name_only_filename );
1474
+ const mode = switch (self .artifact .kind ) {
1475
+ Artifact .Kind .Obj = > unreachable ,
1476
+ Artifact .Kind .Exe = > usize (0o755 ),
1477
+ Artifact .Kind .Lib = > if (self .artifact .static ) usize (0o666 ) else usize (0o755 ),
1478
+ };
1479
+ % return builder .copyFileMode (self .artifact .getOutputPath (), self .dest_file , mode );
1480
+ if (self .artifact .kind == Artifact .Kind .Lib and ! self .artifact .static ) {
1481
+ % return doAtomicSymLinks (builder .allocator , self .dest_file ,
1482
+ self .artifact .major_only_filename , self .artifact .name_only_filename );
1483
+ }
1463
1484
}
1464
1485
}
1465
- };
1486
+ }
1466
1487
1467
1488
pub const InstallFileStep = struct {
1468
1489
step : Step ,
@@ -1481,7 +1502,7 @@ pub const InstallFileStep = struct {
1481
1502
1482
1503
fn make (step : & Step ) - > % void {
1483
1504
const self = @fieldParentPtr (InstallFileStep , "step" , step );
1484
- self .builder .copyFile (self .src_path , self .dest_path );
1505
+ % return self .builder .copyFile (self .src_path , self .dest_path );
1485
1506
}
1486
1507
};
1487
1508
0 commit comments