From 2c24a1a9f609984ecde4c3525521518ecdf50146 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 6 Apr 2007 03:14:58 +0000 Subject: [PATCH] New handy build system feature: It is now possible to pass a command line to jam that contains build targets and that will be executed by the build system after building the targets and replacing their occurrences in the command line by their paths. The keyword indicating such a command line is "run", targets are marked by a leading ":". E.g.: jam -q run ':xres' -l :libtracker.so This builds the xres tool for the host platform and libtracker.so for Haiku, and afterwards lists the resources libtracker.so contains. Note, that this feature requires using Haiku's jam version. The functionality is implemented by the new RunCommandLine rule, which can, of course, also be used in the UserBuildConfig. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20598 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- build/jam/BuildSetup | 21 +++++++++++----- build/jam/MiscRules | 58 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/build/jam/BuildSetup b/build/jam/BuildSetup index 79d2923808..43b48e69f7 100644 --- a/build/jam/BuildSetup +++ b/build/jam/BuildSetup @@ -11,13 +11,22 @@ # directory paths and the like. -# If the target to be built is "all" (i.e. the default) and we're in the output -# directory, the root directory of the build system, or in "src/", we change the -# target to be built to "haiku-image". +# analyze an optionally replace jam's target parameters HAIKU_ORIGINAL_JAM_TARGETS = $(JAM_TARGETS) ; -if $(JAM_TARGETS) = all { - if ! $(INVOCATION_SUBDIR) || $(INVOCATION_SUBDIR) = src { - JAM_TARGETS = haiku-image ; +if $(JAM_TARGETS) { + # If the target to be built is "all" (i.e. the default) and we're in the + # output directory, the root directory of the build system, or in "src/", we + # change the target to be built to "haiku-image". + if $(JAM_TARGETS) = all { + if ! $(INVOCATION_SUBDIR) || $(INVOCATION_SUBDIR) = src { + JAM_TARGETS = haiku-image ; + } + + # The "run" target allows for running arbitrary command lines containing + # build system targets, which are built and replaced accordingly. + } else if $(JAM_TARGETS[1]) = run && $(JAM_TARGETS[2]) { + local run = [ RunCommandLine $(JAM_TARGETS[2-]) ] ; + JAM_TARGETS = $(run) ; } } diff --git a/build/jam/MiscRules b/build/jam/MiscRules index 0246215686..95d7ce1818 100644 --- a/build/jam/MiscRules +++ b/build/jam/MiscRules @@ -159,3 +159,61 @@ rule NewUniqueTarget basename local id = [ NextID ] ; return $(basename[1]:E=_target:G=unique!target)_$(id) ; } + + +# pragma mark - RunCommandLine + + +rule RunCommandLine commandLine +{ + # RunCommandLine + # + # Creates a pseudo target that, when made by jam, causes the supplied shell + # command line to be executed. Elements of with the prefix ":" + # are replaced by the rule. After stripping the prefix such a string specifies + # a build system target and the finally executed command line will contain + # a path to the target instead. + # The pseudo target will depend on all targets thus identified. Each + # invocation of this rule creates a different pseudo target, which is + # returned to the caller. + + # collect the targets in the command line and replace them by $targetX* + # variables + local substitutedCommandLine ; + local targets ; + + local targetVarName = target ; + local i ; + for i in $(commandLine) { + # targets are marked by the ":" prefix + local target = [ Match :(.*) : $(i) ] ; + if $(target) { + targets += $(target) ; + targetVarName = $(targetVarName)X ; + i = "$"$(targetVarName) ; + } + + substitutedCommandLine += $(i) ; + } + + # define the "run" target + local run = [ NewUniqueTarget run ] ; + COMMAND_LINE on $(run) = $(substitutedCommandLine) ; + NotFile $(run) ; + Always $(run) ; + Depends $(run) : $(targets) ; + RunCommandLine1 $(run) : $(targets) ; + + return $(run) ; +} + +actions RunCommandLine1 { + target=target; + for t in $(2) ; do + target+=X + eval "${target}=${t}" + done + $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) + $(COMMAND_LINE) +} +