<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import os <EOL> from collections import defaultdict <EOL> from pants . backend . jvm . tasks . nailgun_task import NailgunTask <EOL> from pants . base . exceptions import TaskError <EOL> from pants . goal . products import MultipleRootedProducts <EOL> from pants . contrib . scalajs . subsystems . scala_js_platform import ScalaJSPlatform <EOL> from pants . contrib . scalajs . targets . scala_js_binary import ScalaJSBinary <EOL> class ScalaJSLink ( NailgunTask ) : <EOL> """<STR_LIT>""" <EOL> _SCALA_JS_CLI_MAIN = '<STR_LIT>' <EOL> @ classmethod <EOL> def register_options ( cls , register ) : <EOL> super ( ScalaJSLink , cls ) . register_options ( register ) <EOL> register ( '<STR_LIT>' , type = bool , fingerprint = True , <EOL> help = '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , type = bool , fingerprint = True , <EOL> help = '<STR_LIT>' ) <EOL> cls . register_jvm_tool ( register , '<STR_LIT>' , main = cls . _SCALA_JS_CLI_MAIN ) <EOL> @ classmethod <EOL> def prepare ( cls , options , round_manager ) : <EOL> super ( ScalaJSLink , cls ) . prepare ( options , round_manager ) <EOL> round_manager . require_data ( '<STR_LIT>' ) <EOL> @ classmethod <EOL> def product_types ( cls ) : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> @ classmethod <EOL> def global_subsystems ( cls ) : <EOL> return { ScalaJSPlatform } <EOL> @ property <EOL> def cache_target_dirs ( self ) : <EOL> return True <EOL> def _is_linked ( self , target ) : <EOL> return isinstance ( target , ScalaJSBinary ) <EOL> def _target_file ( self , vt ) : <EOL> return os . path . join ( vt . results_dir , "<STR_LIT>" . format ( vt . target . name ) ) <EOL> def execute ( self ) : <EOL> scala_js_binaries = self . context . products . get_data ( '<STR_LIT>' , <EOL> lambda : defaultdict ( MultipleRootedProducts ) ) <EOL> classpaths = self . context . products . get_data ( '<STR_LIT>' ) <EOL> with self . invalidated ( <EOL> self . context . targets ( self . _is_linked ) , <EOL> invalidate_dependents = True ) as invalidation_check : <EOL> for vt in invalidation_check . all_vts : <EOL> if not vt . valid : <EOL> self . context . log . debug ( '<STR_LIT>' . format ( vt . target . address . spec ) ) <EOL> self . _link ( vt . target , self . _target_file ( vt ) , classpaths ) <EOL> else : <EOL> self . context . log . debug ( '<STR_LIT>' . format ( vt . target . address . spec ) ) <EOL> scala_js_binaries [ vt . target ] . add_abs_paths ( vt . results_dir , [ self . _target_file ( vt ) ] ) <EOL> classpaths . add_for_target ( vt . target , [ ( '<STR_LIT:default>' , vt . results_dir ) ] ) <EOL> def _link ( self , target , output_file , classpaths ) : <EOL> args = [ '<STR_LIT>' , output_file ] <EOL> if self . get_options ( ) . level == '<STR_LIT>' : <EOL> args . append ( '<STR_LIT>' ) <EOL> if self . get_options ( ) . full_opt : <EOL> args . append ( '<STR_LIT>' ) <EOL> if self . get_options ( ) . check_ir : <EOL> args . append ( '<STR_LIT>' ) <EOL> args . extend ( jar for _ , jar in classpaths . get_for_targets ( target . closure ( bfs = True ) ) ) <EOL> result = self . runjava ( classpath = self . tool_classpath ( '<STR_LIT>' ) , main = self . _SCALA_JS_CLI_MAIN , <EOL> jvm_options = self . get_options ( ) . jvm_options , <EOL> args = args , workunit_name = '<STR_LIT>' ) <EOL> if result != <NUM_LIT:0> : <EOL> raise TaskError ( <EOL> '<STR_LIT>' . format ( <EOL> main = self . _SCALA_JS_CLI_MAIN , result = result , target = target . address . spec ) , <EOL> failed_targets = [ target ] ) <EOL> if not os . path . exists ( output_file ) : <EOL> raise TaskError ( <EOL> '<STR_LIT>' . format ( <EOL> main = self . _SCALA_JS_CLI_MAIN , target = target . address . spec ) , <EOL> failed_targets = [ target ] ) </s>
