2222from host import current_os , package_tool
2323from actions .script import Script
2424from toolchain import Toolchain
25+ from util import list_unique
2526
2627
2728class InstallPackages (Action ):
@@ -39,6 +40,7 @@ def run(self, env):
3940 if not packages :
4041 return
4142
43+ packages = list_unique (packages )
4244 pkg_tool = package_tool ()
4345 print ('Installing packages via {}: {}' .format (
4446 pkg_tool .value , ', ' .join (packages )))
@@ -58,7 +60,7 @@ def run(self, env):
5860 if not InstallPackages .pkg_init_done :
5961 pkg_setup = config .get ('pkg_setup' , [])
6062 if pkg_setup :
61- for cmd in pkg_setup :
63+ for cmd in list_unique ( pkg_setup ) :
6264 if isinstance (cmd , str ):
6365 cmd = cmd .split (' ' )
6466 assert isinstance (cmd , list )
@@ -95,16 +97,21 @@ def run(self, env):
9597 assert toolchain
9698
9799 # Cross compile with dockcross
98- if toolchain . cross_compile :
100+ def _install_cross_compile_toolchain ( env ) :
99101 print (
100102 'Installing cross-compile via dockcross for {}' .format (toolchain .platform ))
103+ cross_compile_platform = env .config .get (
104+ 'cross_compile_platform' , toolchain .platform )
101105 result = sh .exec (
102- 'docker' , 'run' , 'dockcross/{}' .format (toolchain .platform ), quiet = True )
103- assert result .returncode == 0
106+ 'docker' , 'run' , 'dockcross/{}' .format (cross_compile_platform ), quiet = True )
104107 # Strip off any output from docker itself
105- script = '#!' + result .output .partition ('#!' )[2 ]
108+ output , shebang , script = result .output .partition ('#!' )
109+ script = shebang + script
110+ print (output )
111+ assert result .returncode == 0
112+
106113 dockcross = os .path .abspath (os .path .join (
107- env .build_dir , 'dockcross-{}' .format (toolchain . platform )))
114+ env .build_dir , 'dockcross-{}' .format (cross_compile_platform )))
108115 Path (dockcross ).touch (0o755 )
109116 with open (dockcross , "w+t" ) as f :
110117 f .write (script )
@@ -118,22 +125,8 @@ def run(self, env):
118125 toolchain .env_file = dockcross_env
119126 toolchain .shell_env = [
120127 dockcross , '-a' , '--env-file={}' .format (dockcross_env )]
121- return
122-
123- # Compiler is local, or should be, so verify/install and export it
124- compiler = env .spec .compiler
125- version = env .spec .compiler_version
126- if version == 'default' :
127- version = None
128-
129- # See if the compiler is already installed
130- compiler_path , found_version = Toolchain .find_compiler (
131- compiler , version )
132- if compiler_path :
133- print ('Compiler {} {} is already installed ({})' .format (
134- compiler , version , compiler_path ))
135- return
136128
129+ # Expose compiler via environment
137130 def _export_compiler (_env ):
138131 if current_os () == 'windows' :
139132 return
@@ -149,5 +142,23 @@ def _export_compiler(_env):
149142 print (
150143 'WARNING: Compiler {} could not be found' .format (exe ))
151144
152- packages = config ['compiler_packages' ]
153- return Script ([InstallPackages (packages ), _export_compiler ])
145+ if not toolchain .cross_compile :
146+ # Compiler is local, or should be, so verify/install and export it
147+ compiler = env .spec .compiler
148+ version = env .spec .compiler_version
149+ if version == 'default' :
150+ version = None
151+
152+ # See if the compiler is already installed
153+ compiler_path , found_version = Toolchain .find_compiler (
154+ compiler , version )
155+ if compiler_path :
156+ print ('Compiler {} {} is already installed ({})' .format (
157+ compiler , version , compiler_path ))
158+ return
159+
160+ packages = list_unique (config .get ('compiler_packages' , []))
161+ after_packages = [_export_compiler ]
162+ if toolchain .cross_compile :
163+ after_packages = [_install_cross_compile_toolchain ]
164+ return Script ([InstallPackages (packages ), * after_packages ])
0 commit comments