@@ -631,9 +631,12 @@ def test(args, expected, moar_expected=None):
631
631
test (['-O1' , '-s' , 'EMULATE_FUNCTION_POINTER_CASTS=1' ], '''my func\n ''' ) # emulate so it works
632
632
633
633
def test_l_link (self ):
634
- # Linking with -lLIBNAME and -L/DIRNAME should work
634
+ # Linking with -lLIBNAME and -L/DIRNAME should work, also should work with spaces
635
635
636
- open (os .path .join (self .get_dir (), 'main.cpp' ), 'w' ).write ('''
636
+ def build (path , args ):
637
+ check_execute ([PYTHON , EMCC , self .in_dir (* path )] + args )
638
+
639
+ open (self .in_dir ('main.cpp' ), 'w' ).write ('''
637
640
extern void printey();
638
641
int main() {
639
642
printey();
@@ -642,21 +645,35 @@ def test_l_link(self):
642
645
''' )
643
646
644
647
try :
645
- os .makedirs (os . path . join ( self .get_dir (), 'libdir' ));
648
+ os .makedirs (self .in_dir ( 'libdir' ))
646
649
except :
647
650
pass
648
651
649
- open (os . path . join ( self .get_dir (), 'libdir' , 'libfile.cpp' ), 'w' ).write ('''
652
+ open (self .in_dir ( 'libdir' , 'libfile.cpp' ), 'w' ).write ('''
650
653
#include <stdio.h>
651
654
void printey() {
652
655
printf("hello from lib\\ n");
653
656
}
654
657
''' )
655
658
656
- Popen ([PYTHON , EMCC , os .path .join (self .get_dir (), 'libdir' , 'libfile.cpp' ), '-c' ]).communicate ()
657
- shutil .move (os .path .join (self .get_dir (), 'libfile.o' ), os .path .join (self .get_dir (), 'libdir' , 'libfile.so' ))
658
- Popen ([PYTHON , EMCC , os .path .join (self .get_dir (), 'main.cpp' ), '-L' + os .path .join (self .get_dir (), 'libdir' ), '-lfile' ]).communicate ()
659
- self .assertContained ('hello from lib' , run_js (os .path .join (self .get_dir (), 'a.out.js' )))
659
+ libfile = self .in_dir ('libdir' , 'libfile.so' )
660
+ aout = self .in_dir ('a.out.js' )
661
+
662
+ # Test linking the library built here by emcc
663
+ build (['libdir' , 'libfile.cpp' ], ['-c' ])
664
+ shutil .move (self .in_dir ('libfile.o' ), libfile )
665
+ build (['main.cpp' ], ['-L' + self .in_dir ('libdir' ), '-lfile' ])
666
+
667
+ self .assertContained ('hello from lib' , run_js (aout ))
668
+
669
+ # Also test execution with `-l c` and space-separated library linking syntax
670
+ os .remove (aout )
671
+ build (['libdir' , 'libfile.cpp' ], ['-c' , '-l' , 'c' ])
672
+ shutil .move (self .in_dir ('libfile.o' ), libfile )
673
+ build (['main.cpp' ], ['-L' , self .in_dir ('libdir' ), '-l' , 'file' ])
674
+
675
+ self .assertContained ('hello from lib' , run_js (aout ))
676
+
660
677
assert not os .path .exists ('a.out' ) and not os .path .exists ('a.exe' ), 'Must not leave unneeded linker stubs'
661
678
662
679
def test_outline (self ):
0 commit comments