0

I'm using a Makefile for building a lambda extension. It works fine when I run a sam build command from Azure DevOps using Ubuntu. However, sometimes I want to build from my PC and the Makefile doesn't work because commands are different. I suppose I could setup command aliases for dos but that seems treacherous. I'd prefer to use something like OS detecting makefile but when I tried that it didn't work out.

Here's the pertinent snippet from my template:

  TokenCacheLayer:
    Type: AWS::Serverless::LayerVersion
    Metadata:
      BuildMethod: makefile
    Properties:
      LayerName: !Ref TokenCacheLayerName
      Description: AWS Lambda extension to cache tokens aquired from an external API.
      ContentUri: ./token-cache
      LicenseInfo: MIT-0
      CompatibleRuntimes:
        - nodejs12.x
      RetentionPolicy: Retain

Here's my Makefile:

build-TokenCacheLayer:
    cp -R extensions "$(ARTIFACTS_DIR)"
    cp -R token-cache-extension "$(ARTIFACTS_DIR)"

Here's the 2 ways I've tried altering to make it OS independent:

build-TokenCacheLayer:
    ifeq ($(OS),Windows_NT)
        xcopy extensions "$(ARTIFACTS_DIR)\extensions"
        xcopy token-cache-extension "$(ARTIFACTS_DIR)"
    else
        cp -R extensions "$(ARTIFACTS_DIR)"
        cp -R token-cache-extension "$(ARTIFACTS_DIR)"
    endif

and

ifeq ($(OS),Windows_NT)
    build-TokenCacheLayer:
        xcopy extensions "$(ARTIFACTS_DIR)\extensions"
        xcopy token-cache-extension "$(ARTIFACTS_DIR)"
else
    build-TokenCacheLayer:
        cp -R extensions "$(ARTIFACTS_DIR)"
        cp -R token-cache-extension "$(ARTIFACTS_DIR)"
endif

The first way I got the error:

Error: CustomMakeBuilder:MakeBuild - Make Failed: process_begin: CreateProcess(NULL, cp -R extensions D:\Development\AWS.Integration\buildpro\layers\sam-build\TokenCacheLayer, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [D:\Development\AWS.Integration\buildpro\layers\token-cache\Makefile:6: build-TokenCacheLayer] Error 2

The second gave me this:

Error: CustomMakeBuilder:MakeBuild - Make Failed: D:\Development\AWS.Integration\buildpro\layers\token-cache\Makefile:2: *** recipe commences before first target.  Stop.

Update

I went back and tried the first way again and while I'm not getting an error it doesn't copy the files either.

Colin
  • 331
  • 3
  • 19
  • Indenting is usually good to keep track of if-else, but in a Makefile you will probably have to do without that indenting. Also, you will need to make sure that the commands are indented with a tab. – Henrik Carlqvist Jul 27 '21 at 22:16
  • When you say _I want to build from my PC_ I suppose you really mean you want to build on a Windows system? – MadScientist Jul 27 '21 at 22:18
  • In the non-WINDOWS_NT branch, does that OS understand paths where the directory separator is a backslash? – Jens Jul 28 '21 at 06:23
  • @MadScientist - yes. My local machine is Windows 10. When I build in Azure Pipeline I specify Ubuntu. – Colin Jul 29 '21 at 14:00
  • @Jens - I haven't attempted to build in Azure Pipelines with Ubuntu yet. I'll try checking in my code and see what happens. – Colin Jul 29 '21 at 14:01

0 Answers0