;shake: setversion can operate on specified packages
This commit is contained in:
		
							parent
							
								
									fdd346294f
								
							
						
					
					
						commit
						79b532017b
					
				
							
								
								
									
										52
									
								
								Shake.hs
									
									
									
									
									
								
							
							
						
						
									
										52
									
								
								Shake.hs
									
									
									
									
									
								
							| @ -48,7 +48,7 @@ import "base-prelude" BasePrelude | |||||||
| import "base"         Control.Exception as C | import "base"         Control.Exception as C | ||||||
| -- required packages, keep synced with Makefile -> SHAKEDEPS: | -- required packages, keep synced with Makefile -> SHAKEDEPS: | ||||||
| import "directory"    System.Directory as S (getDirectoryContents) | import "directory"    System.Directory as S (getDirectoryContents) | ||||||
| import "extra"        Data.List.Extra | import "extra"        Data.List.Extra hiding (headDef, lastDef) | ||||||
| import "process"      System.Process | import "process"      System.Process | ||||||
| import "regex"        Text.RE.TDFA.String | import "regex"        Text.RE.TDFA.String | ||||||
| import "regex"        Text.RE.Replace | import "regex"        Text.RE.Replace | ||||||
| @ -72,7 +72,7 @@ usage = | |||||||
|   ,"./Shake webmanuals       build web manuals (in site/) for all packages" |   ,"./Shake webmanuals       build web manuals (in site/) for all packages" | ||||||
|   ,"./Shake PKG              build a single hledger package and its embedded docs" |   ,"./Shake PKG              build a single hledger package and its embedded docs" | ||||||
|   ,"./Shake build            build all hledger packages and their embedded docs" |   ,"./Shake build            build all hledger packages and their embedded docs" | ||||||
|   ,"./Shake setversion [VER] set version strings from */.version (or VER)" |   ,"./Shake setversion [VER] [PKGS]  set version strings from */.version (or VER)" | ||||||
|   ,"./Shake changelogs       add any new non-boring commits to */CHANGES.md" |   ,"./Shake changelogs       add any new non-boring commits to */CHANGES.md" | ||||||
|   ,"./Shake [PKG/]CHANGES.md-finalise  add version/date heading in this changelog" |   ,"./Shake [PKG/]CHANGES.md-finalise  add version/date heading in this changelog" | ||||||
|   -- ,"./Shake [PKG/]CHANGES.md[-dry]  update (or preview) one changelog" |   -- ,"./Shake [PKG/]CHANGES.md[-dry]  update (or preview) one changelog" | ||||||
| @ -120,7 +120,10 @@ main = do | |||||||
|   let sitedir = "site" |   let sitedir = "site" | ||||||
|   pages <- map takeBaseName . filter (".md" `isSuffixOf`) <$> S.getDirectoryContents sitedir |   pages <- map takeBaseName . filter (".md" `isSuffixOf`) <$> S.getDirectoryContents sitedir | ||||||
| 
 | 
 | ||||||
|   (target, args) <- splitAt 1 <$> getArgs |   -- The rule that we run can make use of command line opts/args if it wants. | ||||||
|  |   -- We distinguish them by the dash, so option arguments should be adjacent to their flag. | ||||||
|  |   (opts, args') <- partition ("-" `isPrefixOf`) <$> getArgs | ||||||
|  |   let (target, args) = splitAt 1 args' | ||||||
| 
 | 
 | ||||||
|   -- 2. define the shake rules |   -- 2. define the shake rules | ||||||
| 
 | 
 | ||||||
| @ -142,6 +145,8 @@ main = do | |||||||
|           ,"hledger-ui" |           ,"hledger-ui" | ||||||
|           ,"hledger-web" |           ,"hledger-web" | ||||||
|           ] |           ] | ||||||
|  |         pkgdirs = packages | ||||||
|  |         pkgandprojdirs = "" : pkgdirs | ||||||
| 
 | 
 | ||||||
|         changelogs = "CHANGES.md" : map (</> "CHANGES.md") packages |         changelogs = "CHANGES.md" : map (</> "CHANGES.md") packages | ||||||
| 
 | 
 | ||||||
| @ -472,23 +477,27 @@ main = do | |||||||
| 
 | 
 | ||||||
|       -- VERSION NUMBERS |       -- VERSION NUMBERS | ||||||
| 
 | 
 | ||||||
|       -- Given the desired version string saved in PKG/.version, update |       -- Update all packages' version strings based on the version saved in PKG/.version. | ||||||
|       -- it everywhere needed in the package. See also CONTRIBUTING.md > |       -- If a version number is provided as first argument, save that in the .version files first. | ||||||
|       -- Version numbers. |       -- If one or more subdirectories are provided as arguments, save/update only those. | ||||||
| 
 |       -- See also CONTRIBUTING.md > Version numbers. | ||||||
|       let inAllPackages f = map (</> f) packages |  | ||||||
| 
 |  | ||||||
|       phony "setversion" $ do |       phony "setversion" $ do | ||||||
|         -- if a version number was provided as first argument, save it in all .version files |         let | ||||||
|         case take 1 args of |           (mver, dirargs) = (headMay ver', drop 1 ver' ++ dirs') | ||||||
|           a@(_:_):_ | all (`elem` "0123456789.") a -> liftIO $ |             where (ver',dirs') = span isVersion args | ||||||
|             forM ("" : packages) $ \dir -> writeFile (dir </> ".version") (a++"\n") |           (specifieddirs, specifiedpkgs) = | ||||||
|           _ -> return [] |             case dirargs of [] -> (pkgandprojdirs, pkgdirs) | ||||||
|         -- XXX any problems from laziness here ? seems not |                             ds -> (ds, ds) | ||||||
|         -- liftIO $ forM ("" : packages) $ \dir -> readFileStrictly (dir </> ".version") >>= putStr |         -- if a version was provided, update .version files in the specified directories | ||||||
|  |         case mver of | ||||||
|  |           Just v  -> liftIO $ forM_ specifieddirs $ \d -> writeFile (d </> ".version") (v++"\n") | ||||||
|  |           Nothing -> return () | ||||||
| 
 | 
 | ||||||
|         -- update all files depending on .version |         -- update all files depending on .version in the specified packages | ||||||
|         need $ inAllPackages "defs.m4" ++ inAllPackages "package.yaml" |         need $ concat [ | ||||||
|  |            map (</> "defs.m4")      specifiedpkgs | ||||||
|  |           ,map (</> "package.yaml") specifiedpkgs | ||||||
|  |           ] | ||||||
| 
 | 
 | ||||||
|       -- PKG/defs.m4 <- PKG/.version |       -- PKG/defs.m4 <- PKG/.version | ||||||
|       "hledger*/defs.m4" %> \out -> do |       "hledger*/defs.m4" %> \out -> do | ||||||
| @ -597,7 +606,7 @@ main = do | |||||||
|   -- leaving the other args for the rule to use |   -- leaving the other args for the rule to use | ||||||
| 
 | 
 | ||||||
|   let |   let | ||||||
|     opts = shakeOptions{ |     shakeopts = shakeOptions{ | ||||||
|        shakeVerbosity=Quiet |        shakeVerbosity=Quiet | ||||||
|       -- ,shakeReport=[".shake.html"] |       -- ,shakeReport=[".shake.html"] | ||||||
|       } |       } | ||||||
| @ -609,7 +618,7 @@ main = do | |||||||
|         (a:_) -> want [a] >> withoutActions rules |         (a:_) -> want [a] >> withoutActions rules | ||||||
| 
 | 
 | ||||||
|   -- shakeArgsWith :: ShakeOptions -> [OptDescr (Either String a)] -> ([a] -> [String] -> IO (Maybe (Rules ()))) -> IO ()  |   -- shakeArgsWith :: ShakeOptions -> [OptDescr (Either String a)] -> ([a] -> [String] -> IO (Maybe (Rules ()))) -> IO ()  | ||||||
|   shakeArgsWith opts [] (runWithArgs rules) |   shakeArgsWith shakeopts [] (runWithArgs rules) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| -- Convert numbered man page names to manual names. | -- Convert numbered man page names to manual names. | ||||||
| @ -646,3 +655,6 @@ replaceRe re repl = replaceBy re (\_ _ _ -> Just repl) | |||||||
| -- each matched text with the given function. | -- each matched text with the given function. | ||||||
| replaceBy :: RE -> (Match String -> RELocation -> Capture String -> Maybe String) -> String -> String | replaceBy :: RE -> (Match String -> RELocation -> Capture String -> Maybe String) -> String -> String | ||||||
| replaceBy re f src = replaceAllCaptures TOP f $ src *=~ re | replaceBy re f src = replaceAllCaptures TOP f $ src *=~ re | ||||||
|  | 
 | ||||||
|  | -- | Does this string look like a valid cabal package version ? | ||||||
|  | isVersion s = not (null s) && all (`elem` "0123456789.") s | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user